/* graphics and game i/o */›/* */›#define RAMTOP 0x6A›#define PMCOLOR 0x2C0›#define SDMCTL 0x22F›#define GRACTL 0xD01D›#define CHBASE 0x2F4›#define PMBASE 0xD407›#define PLSIZE 0xD008›#define HPOSPL 0xD000›#define PLTOPF 0xD004›#define PLTOPL 0xD00C›#define HITCLR 0xD01E›#define OLDCHSET 0xE000›#define GRAF 0xD00D›char *playbase,*charbase,playsize;›/* */›/* initialize players */›/* */›pminit() /* this must be called before any use of the following PM functions */›$(›  int i;›  charbase=(peek(RAMTOP)-12)<<8;›  poke(PMBASE,peek(RAMTOP)-8);›  playbase=(peek(RAMTOP)-8)<<8;›  poke(RAMTOP,peek(RAMTOP)-16);›  graphics(0);›  pmgraphics(0);›  move(OLDCHSET,charbase,1024);›  poke(CHBASE,charbase>>8);›$)›pmflush() /* call this before returning to DOS to turn off PM graphics */›$(›  pmgraphics(0);›  poke(CHBASE,OLDCHSET>>8);›  poke(RAMTOP,peek(RAMTOP)+16);›  graphics(0);›$)›/* Set up PM graphics */›/* i=0 > inhibits PM graphics */›/* i=1 > single line resolution */›/* i=2 > double line resolution */›pmgraphics(i)›int i;›$(›  int j;›  if(i) $(›    poke(SDMCTL,i==1 ? 0x3E : 0x2E); /* enable DMA */›    poke(GRACTL,3);›    playsize= (i==1) ? 8 : 7;›    clear(playbase,2048);›    playbase += (i==1) ? 1024 : 512;›    for(j=0;j<4;++j) poke(HPOSPL+j,0);›  $)›  else $(›    poke(SDMCTL,0x22);›    poke(GRACTL,0);›    for(j=0;j<4;++j) $(›      poke(HPOSPL+j,0);›      poke(GRAF+j,0);›    $)›  $)›$)›hitclear() /* clears the collision registers */›$(›  poke(HITCLR,0);›$)›pmcolor(n,hue,intensity) /* works like setcolor(), defines color of player n */›char n,hue,intensity;›$(›  poke(PMCOLOR+n,(hue<<4)+intensity);›$)›/* define player width */›/* width=0 > normal width */›/* width=1 > double normal width */›/* width=3 > four times normal width */›pmwidth(n,width)›char n,width;›$(›  poke(PLSIZE+n,width);›$)›/* */›/* hitpf() and hitpl() return a 1 if who collided with hitwho, otherwise it will return 0. */›/* if hitwho is minus, a collision with any hitwho will return a 1 */›/* */›hitpf(who,hitwho) /* player-playfield collisions */›int who,hitwho;›$(›  if(hitwho<0) return peek(PLTOPF+who); /* if hitwho is minus, check for any collision */›  return (1<<hitwho) & peek(PLTOPF+who) ? 1 : 0;›$)›hitpl(who,hitwho) /* player-player collisions›int who,hitwho;›$(›  if(hitwho<0) return peek(PLTOPL+who); /* if hitwho is minus, check for any collision */›  return (1<<hitwho) & peek(PLTOPL+who) ? 1 : 0;›$)›pmclear(n) /* clear the player n */›char n;›$(›  clear(playbase+(n<<playsize), 1<<playsize);›$)›chget(c,s) /* get the character definition for c and put it in string s */›char c,*s;›$(›  move((c<<3)+charbase,s,8);›$)›chaget(c,s) /* get the atari character definition for c and put it in string s */›char c,*s;›$(›  move((c<<3)+OLDCHSET,s,8);›$)›chput(c,s) /* put string s into the character definition of c */›char c,*s;›$(›  move(s,(c<<3)+charbase,8);›$)›/* used for defining and moving a player shape */›/* The first value of shape should contain the length. */›/* The second and last values should be \0 to clear previous value when moving the shape */›plmove(n,x,y,shape) /* move shape into player n, position (x,y). */›char n,x,y,*shape;›$(›  move(shape+1,playbase+(n<<playsize)+y,*shape);›  poke(HPOSPL+n,x);›$)›pladdr(n) /* returns the address of player n */›char n;›$(›  return playbase+(n<<playsize);›$)›/* setcolor(reg,hue,lum)›/* -- set color reg to hue & lum combo›/* same as Basic */›setcolor(reg,hue,lum)›int reg;›char hue,lum;›$(›  poke(708+reg,(hue<<4)+(lum & 14));›$)›/* */›/* fill(x,y,c)›/* returns positive if successful›/* */›fill(x,y,c)›int x;›char y,c;›$(›  poke(765,c);›  dpoke(85,x);›  poke(84,y);›  return ciov(6,18,-1,-1,-1,-1); ›$)›paddle(n) /* return position of paddle n */›char n;›$(›  return peek(624+(n&7));›$)›ptrig(n) /* return paddle trigger n */›char n;›$(›  return peek(636+(n&7));›$)›/* */›/* vstick(n) -- -1 if up, +1 if dn›/* */›vstick(n)›char n;›$(›  switch(stick(n)&3) $(›    case 1:›      return 1;›    case 2:›      return -1;›    default:›      return 0;›      break;›  $)›$)›/* */›/* hstick(n) -- +1 if right, -1 if left›/* */›hstick(n)›char n;›$(›  switch(stick(n)&0xC) $(›    case 4:›      return 1;›    case 8:›      return -1;›    default:›      return 0;›      break;›  $)›$)›