[comp.windows.x] xbzone diffs

anselmo-ed@cs.yale.edu (Ed Anselmo) (12/12/90)

Things you do when you're on call on a Saturday, and you have to wait
around for the refrigeration guy to come in and repair the machine
room air conditioning system:

	-- hack (in the worst sense of the word) in support for color
	   displays.  The colors were chosen pretty much at random.
	-- enable the high score file
	-- change 'bzonefont' (the game over font), since the
	   default font specification resulted in some Cyrillic font
	   being used (under OW 2.0).

Diffs are to the Fortran sources, and gpr.c.  You might have to rename
bzone_scores.f to bzone_scores.F to get a pre-processor run.

diff -rc f/bzone_graphics_subs.f ../xbzone/f/bzone_graphics_subs.f
*** f/bzone_graphics_subs.f	Sun Jul 29 21:10:04 1990
--- ../xbzone/f/bzone_graphics_subs.f	Tue Dec 11 11:13:52 1990
***************
*** 71,87 ****
  c     next line is almost certainly wrong.
        if (config .ge. 2 .and. config .lt. 100) then
          incolor = .true.
!         write (*, 100) 'Do you want fading colors? (y/n): '
! 100     format ( a, )
!         read (*,'(a)') answer
!         if (answer .eq. 'n' .or. answer .eq. 'N') then
!           do 20 i = 4, 8
!             value(i) = value(3)
!  20       continue
!           do 30 i = 10, 14
!             value(i) = value(9) 
!  30       continue
!         end if
        end if
  c
  c    init screen in borrow mode
--- 71,87 ----
  c     next line is almost certainly wrong.
        if (config .ge. 2 .and. config .lt. 100) then
          incolor = .true.
! c         write (*, 100) 'Do you want fading colors? (y/n): '
! c 100     format ( a, )
! c         read (*,'(a)') answer
! c         if (answer .eq. 'n' .or. answer .eq. 'N') then
! c           do 20 i = 4, 8
! c             value(i) = value(3)
! c  20       continue
! c           do 30 i = 10, 14
! c             value(i) = value(9) 
! c  30       continue
! c         end if
        end if
  c
  c    init screen in borrow mode
***************
*** 211,221 ****
  c
        call gprsettextfont (font2, status)
        call gprmove ((50), (45), status)
        text = 'BATTLE ZONE V.I'
        call gprtext (text, (30), status)
        call gprmove ((850), (503), status)
        text = 'F'
-       call gprsettextvalue (icol(15), status)
        call gprtext (text, (30), status)
        call gprmove ((850), (630), status)
        text = 'B'
--- 211,222 ----
  c
        call gprsettextfont (font2, status)
        call gprmove ((50), (45), status)
+       call gprsettextvalue (icol(2), status)
        text = 'BATTLE ZONE V.I'
        call gprtext (text, (30), status)
        call gprmove ((850), (503), status)
+       call gprsettextvalue (icol(12), status)
        text = 'F'
        call gprtext (text, (30), status)
        call gprmove ((850), (630), status)
        text = 'B'
***************
*** 228,234 ****
        call gprtext (text, (30), status)
        call gprsettextfont (font1, status)
        call gprmove ((595), (590), status)
!       call gprsettextvalue (icol(1), status)
        text = 'Missile'
        call gprtext (text, (7), status)
        call gprmove ((664), (590), status)
--- 229,235 ----
        call gprtext (text, (30), status)
        call gprsettextfont (font1, status)
        call gprmove ((595), (590), status)
!       call gprsettextvalue (icol(4), status)
        text = 'Missile'
        call gprtext (text, (7), status)
        call gprmove ((664), (590), status)
***************
*** 235,240 ****
--- 236,242 ----
        text = 'Lander'
        call gprtext (text, (6), status)
        call gprmove ((920), (608), status)
+       call gprsettextvalue (icol(7), status)
        text = 'H'
        call gprtext (text, (1), status)
        call gprmove ((920), (642), status)
***************
*** 501,507 ****
        sa = sa * cda + sda * temp
        xpt(2) = 60.0 * ca + 500
        ypt(2) = 60.0 * sa + 560    
!       call gprsetdrawvalue (icol(2), status)
        call gprmultiline (xpt, ypt, (2), status)   
  c
  c    note that distances are not squared
--- 503,509 ----
        sa = sa * cda + sda * temp
        xpt(2) = 60.0 * ca + 500
        ypt(2) = 60.0 * sa + 560    
!       call gprsetdrawvalue (icol(6), status)
        call gprmultiline (xpt, ypt, (2), status)   
  c
  c    note that distances are not squared
***************
*** 638,644 ****
        if (moon) then
          call gprcircle (pt, radius, status)
        end if
!       call gprsetdrawvalue (icol(14), status)
  c
  c    draw the new skyline
  c
--- 640,646 ----
        if (moon) then
          call gprcircle (pt, radius, status)
        end if
!       call gprsetdrawvalue (icol(11), status)
  c
  c    draw the new skyline
  c
***************
*** 767,773 ****
  c
  c    draw the cracks
  c
!       call gprsetdrawvalue (icol(1), status)
        call gprmultiline (xpt, ypt, (38), status)
        return
        end
--- 769,775 ----
  c
  c    draw the cracks
  c
!       call gprsetdrawvalue (icol(2), status)
        call gprmultiline (xpt, ypt, (38), status)
        return
        end
***************
*** 3108,3118 ****
--- 3110,3122 ----
        index = iabs(index)
        call gprsetclippingactive (.false., status)
        call gprmove (xpt, ypt(index), status)
+       call gprsettextvalue (2, status)
        call gprtext (text, (40), status)
        call gprsetclippingactive (.true., status)
        if (bell) then
          call tonetime (clock)
        end if
+       call gprsettextvalue (1, status)
        return
        end
  
diff -rc f/bzone_scores.f ../xbzone/f/bzone_scores.f
*** f/bzone_scores.f	Sun Jul 29 21:10:06 1990
--- ../xbzone/f/bzone_scores.f	Sat Dec  8 12:54:49 1990
***************
*** 23,28 ****
--- 23,30 ----
  c % include '/sys/ins/gpr.ins.ftn'   
  c % include '/sys/ins/time.ins.ftn'   
  c
+ #define SCOREFILE '/usr/yale/games/lib/bzoneinfo'
+ c
        integer*4 decodedclock(6), fontid, clock(3)
        integer*4 score, topscores(10), position, status, icol(0:15)
        character*3 topinitials(10), initials
***************
*** 40,47 ****
  c    write game over 
  c
        call gprmove ((165), (300), status)
!       call gprtext ('GAME@OVER', (9), status)
!       call gprloadfontfile('/sys/dm/fonts/f7x13',
       &                         (19), fontid, status)      
        call gprsettextfont (fontid, status)
        call gprsettextvalue (icol(15), status)
--- 42,49 ----
  c    write game over 
  c
        call gprmove ((165), (300), status)
!       call gprtext ('Game Over', (9), status)
!       call gprloadfontfile('/sys/dm/fonts/i.12',
       &                         (19), fontid, status)      
        call gprsettextfont (fontid, status)
        call gprsettextvalue (icol(15), status)
***************
*** 52,66 ****
  c
  c    terminate gpr after 7.5 seconds wait (this is repeated below)
  c
!       call timewait (timerelative, clock, status)
!       call gprterminate (.true., status)
!       return
  
  c
  c    print out player's score
  c
        print*,'Score: ', score
!       open (unit = 1, file = 'bzoneinfo')
  c
  c    read the top ten list
  c
--- 54,68 ----
  c
  c    terminate gpr after 7.5 seconds wait (this is repeated below)
  c
! c     call timewait (timerelative, clock, status)
! c     call gprterminate (.true., status)
! c     return
  
  c
  c    print out player's score
  c
        print*,'Score: ', score
!       open (unit = 1, file = SCOREFILE)
  c
  c    read the top ten list
  c
diff -rc f/gpr.c ../xbzone/f/gpr.c
*** f/gpr.c	Tue Dec 11 16:32:54 1990
--- ../xbzone/f/gpr.c	Tue Dec 11 16:34:16 1990
***************
*** 5,15 ****
   * this is a gross crock, and I make no apologies for it..
   */
  
  #include <sys/types.h>
  #include <sys/time.h>
  #include <X11/Xlib.h>
  
! unsigned int colortrans[2];
  
  typedef long bitmap_desc_t;
  typedef unsigned long plane_t;
--- 5,16 ----
   * this is a gross crock, and I make no apologies for it..
   */
  
+ #include <stdio.h>
  #include <sys/types.h>
  #include <sys/time.h>
  #include <X11/Xlib.h>
  
! unsigned long colortrans[15];
  
  typedef long bitmap_desc_t;
  typedef unsigned long plane_t;
***************
*** 42,47 ****
--- 43,50 ----
  Window w;
  GC FillGC, DrawGC, TextGC, EraseGC;
  
+ #define MAX_COLORS 16
+ 
  void gprinqconfig_ (config, status)
      long *config;
      long *status;
***************
*** 52,57 ****
--- 55,68 ----
      Font f;
      XGCValues xgcv;
      unsigned long fcolor, bcolor;
+     Colormap cmap;
+     XColor exact, closest;
+     int i, ncolors = MAX_COLORS;
+ 
+     /* These colors chosen at random */
+     static char *ColorName[] = {"Black", "White", "Red", "Blue","Yellow",
+ 	"Green", "Orange", "Sea Green", "Coral", "Maroon",
+ 	"Orange Red", "Sky Blue", "Violet Red", "Brown", "Lime Green", "Gold"};
      
      d = XOpenDisplay (0);
      if (d == 0) {
***************
*** 61,66 ****
--- 72,95 ----
  
      colortrans[1] = fcolor = WhitePixelOfScreen(DefaultScreenOfDisplay(d));
      colortrans[0] = bcolor = BlackPixelOfScreen(DefaultScreenOfDisplay(d));
+     
+     *config = DisplayPlanes(d,0);
+     if (*config != 1) {
+ 	cmap = XDefaultColormap(d,0);
+ 	for (i = 0; i < MAX_COLORS; i++) {
+ 		if (!XParseColor(d, cmap, ColorName[i], &exact)) {
+ 			fprintf(stderr,"XParseColor: color name %s \
+ 			is not in database\n", ColorName[i]);
+ 			exit(1);
+ 		}
+ 		if (!XAllocColor(d,cmap, &exact)) {
+ 			fprintf(stderr, "XAllocColor: Couldn't allocate %s\n",
+ 				ColorName[i]);
+ 			exit(1);
+ 		}
+ 		colortrans[i] = exact.pixel;
+ 	}
+     }
  
      
      w = XCreateSimpleWindow (d, DefaultRootWindow(d),
***************
*** 68,75 ****
  			     WidthOfScreen(DefaultScreenOfDisplay(d))-4,
  			     HeightOfScreen(DefaultScreenOfDisplay(d))-4,
  			     2,
! 			     BlackPixelOfScreen(DefaultScreenOfDisplay(d)),
! 			     BlackPixelOfScreen(DefaultScreenOfDisplay(d)));
      attr.override_redirect = True;
      XChangeWindowAttributes (d, w, CWOverrideRedirect, &attr);
      xgcv.background = bcolor;
--- 97,104 ----
  			     WidthOfScreen(DefaultScreenOfDisplay(d))-4,
  			     HeightOfScreen(DefaultScreenOfDisplay(d))-4,
  			     2,
! 			     fcolor,
! 			     bcolor);
      attr.override_redirect = True;
      XChangeWindowAttributes (d, w, CWOverrideRedirect, &attr);
      xgcv.background = bcolor;
***************
*** 89,97 ****
      XSetGraphicsExposures (d, FillGC, False);
      XSetGraphicsExposures (d, DrawGC, False);
      XSetGraphicsExposures (d, TextGC, False);    
-     
-     *config = 1;		/* XXX should kludge depending on number
- 				 * of planes */
      *status = 0;
  }
  
--- 118,123 ----
***************
*** 130,136 ****
  void caldecodelocaltime_ (array)
      long *array;
  {
!     /* XXX fill in stuff here */
  }
  
  void gprsettextfont_ (font, status)
--- 156,169 ----
  void caldecodelocaltime_ (array)
      long *array;
  {
!     time_t clock;
!     struct tm *lt;
! 
!     (void) time(&clock);
!     lt = localtime(&clock);
!     array[0] = lt->tm_year + 1900;
!     array[1] = lt->tm_mon;
!     array[2] = lt->tm_mday;
  }
  
  void gprsettextfont_ (font, status)
***************
*** 423,429 ****
      long *values;
      long *status;
  {
!     printf("setcolormap\n");
  }
  
  void gprloadfontfile_ (path, pnlen, fontid, status)
--- 456,463 ----
      long *values;
      long *status;
  {
! 	Colormap cmap;
! 	XColor exact, closest;
  }
  
  void gprloadfontfile_ (path, pnlen, fontid, status)
***************
*** 440,446 ****
      } fontmap[] = { {	"/sys/dm/fonts/f5x9", "6x10" },
        {     "/sys/dm/fonts/i.12", "-*-*-medium-i-*-*-14-*-*-*-*-*-*-*"},
        {	    "/sys/dm/fonts/f7x13", "8x13" },
!       {     "bzonefont", "-*-*-medium-r-*-*-24-*-*-*-*-*-*-*"},
  	  {     0, 0 }};
  
      for (i=0; fontmap[i].gprname; i++) {
--- 474,480 ----
      } fontmap[] = { {	"/sys/dm/fonts/f5x9", "6x10" },
        {     "/sys/dm/fonts/i.12", "-*-*-medium-i-*-*-14-*-*-*-*-*-*-*"},
        {	    "/sys/dm/fonts/f7x13", "8x13" },
!       {     "bzonefont", "-*-times-medium-r-*-*-24-*-*-*-*-*-*-*"},
  	  {     0, 0 }};
  
      for (i=0; fontmap[i].gprname; i++) {
***************
*** 499,505 ****
      long *status;
  {
      long size = *radius;
!     extern long moon;
      if (moon) {
  	if ((strncmp(ServerVendor(d), "MIT", 3) == 0) &&
  	    VendorRelease(d) < 4)
--- 533,539 ----
      long *status;
  {
      long size = *radius;
!     long moon = 1;
      if (moon) {
  	if ((strncmp(ServerVendor(d), "MIT", 3) == 0) &&
  	    VendorRelease(d) < 4)
-- 
Ed Anselmo   anselmo-ed@cs.yale.edu   {harvard,cmcl2}!yale!anselmo-ed