diff --git a/src/inc/hgrlib.plh b/src/inc/hgrlib.plh index b09a751..c3f0e6f 100644 --- a/src/inc/hgrlib.plh +++ b/src/inc/hgrlib.plh @@ -5,7 +5,10 @@ import hgrlib predef hgrXorPlot(x, y)#0 predef hgrHLin(x1, x2, y)#0 predef hgrVLin(y1, y2, x)#0 + predef hgrXorHLin(x1, x2, y)#0 + predef hgrXorVLin(y1, y2, x)#0 predef hgrRect(x1, y1, x2, y2)#0 + predef hgrXorRect(x1, y1, x2, y2)#0 predef hgrBLT(x, y, width, height, srcptr)#0 predef hgrCopySrc(ofst, y, w, h, srcptr)#0 predef hgrAndSrc(ofst, y, w, h, srcptr)#0 diff --git a/src/libsrc/apple/hgrlib.pla b/src/libsrc/apple/hgrlib.pla index fa79ca3..9a588e5 100644 --- a/src/libsrc/apple/hgrlib.pla +++ b/src/libsrc/apple/hgrlib.pla @@ -543,8 +543,6 @@ end asm _hgrPlotC LDA $1000,Y ; HBMASK STA TMPL - EOR #$FF - STA TMPH LDA ESTKL+1,X ; HORIZ OFFSET CMP #40 BCS + @@ -553,12 +551,10 @@ asm _hgrPlotC end asm _hgrPlotD LDA $2000,Y ; CURHCLR - AND TMPL - STA TMPL LDY ESTKL+1,X ; HORIZ OFFSET - LDA (DST),Y - AND TMPH - ORA TMPL + EOR (DST),Y + AND TMPL + EOR (DST),Y STA (DST),Y + INX INX @@ -601,8 +597,8 @@ asm _hgrXorPlotC end asm _hgrXorPlotD LDA $2000,Y ; CURHCLR - AND TMPL LDY ESTKL+1,X ; HORIZ OFFSET + AND TMPL EOR (DST),Y STA (DST),Y + INX @@ -646,8 +642,8 @@ asm _hgrOrPlotC end asm _hgrOrPlotD LDA $2000,Y ; CURHCLR - AND TMPL LDY ESTKL+1,X ; HORIZ OFFSET + AND TMPL ORA (DST),Y STA (DST),Y + INX @@ -713,6 +709,8 @@ end asm _hgrHLinD LDA $1000,Y ; HRMASK STA TMPH + LDA ESTKL+1,X ; RIGHT HORIZ OFFSET + STA IPY ; STEAL THIS ZP FOR A MOMENT INX INX INX @@ -739,47 +737,151 @@ asm _hgrHLinG STA SRCH LDA $2001 ; CURHCLRH STA SRCL -++ TYA - CMP ESTKL-1,X ; RIGHT HORIZ OFFSET +++ CPY IPY ; RIGHT HORIZ OFFSET BNE + - LDA TMPL + LDA SRCL + EOR (DST),Y + AND TMPL AND TMPH - STA TMPL - AND SRCL + EOR (DST),Y + STA (DST),Y + INX + INX + RTS ++ LDA SRCL ; CURHCLR + EOR (DST),Y + AND TMPL + EOR (DST),Y +- STA (DST),Y + INY + CPY IPY ; RIGHT HORIZ OFFSET + LDA SRCH + BCS + + STA (DST),Y + INY + CPY IPY ; RIGHT HORIZ OFFSET + LDA SRCL + BCC - ++ EOR (DST),Y + AND TMPH + EOR (DST),Y + STA (DST),Y + INX + INX + RTS +end +//export def hgrXorHLin(x1, x2, y)#0 +// word pixptr, x +// byte lofst, lpixofst, lpmask +// byte rofst, rpixofst, rpmask +// +// if x1 == x2 +// hgrPlot(x1, y) +// else +// lofst, lpixofst = divmod7(x1) +// pixptr = hgrscan[y] + drawbuff + lofst +// rofst, rpixofst = divmod7(x2) +// lpmask = hlmask[lpixofst] +// rpmask = hrmask[rpixofst] +// if lofst == rofst +// lpmask = lpmask & rpmask +// ^pixptr = ^pixptr ^ (curhclr.[pixptr.0 & 1] & lpmask) +// else +// ^pixptr = ^pixptr ^ (curhclr.[pixptr.0 & 1] & lpmask) +// pixptr++ +// for x = lofst + 1 to rofst - 1 +// ^pixptr = ^pixptr ^ curhclr.[pixptr.0 & 1] +// pixptr++ +// next +// ^pixptr = ^pixptr ^ (curhclr.[pixptr.0 & 1] & rpmask) +// fin +// fin +//end +export asm hgrXorHLin(x1, x2, y)#0 + LDA ESTKL+1 + CMP ESTKL+2 + BNE + + LDA ESTKH+1 + CMP ESTKH+2 + BNE + +end +asm _hgrXHLinA + JSR $F000 + INX + RTS ++ LDY ESTKL+0,X ; Y COORD +end +asm _hgrXHLinB + LDA $8000,Y ; HGRSCANL + STA DSTL + LDA $1000 ; DRAWBUFFH + ORA $9000,Y ; HGRSCANH + STA DSTH + LDA ESTKL+1,X + STA ESTKL+0,X + LDA ESTKH+1,X + STA ESTKH+0,X +end +asm _hgrXHLinC + JSR 1000 ; DIVMOD7 + LDY ESTKL+0,X ; RIGHT PIXEL OFFSET +end +asm _hgrXHLinD + LDA $1000,Y ; HRMASK STA TMPH - LDA TMPL - EOR #$FF - AND (DST),Y - ORA TMPH + LDA ESTKL+1,X ; RIGHT HORIZ OFFSET + STA IPY ; STEAL THIS ZP FOR A MOMENT + INX + INX + INX +end +asm _hgrXHLinE + JSR 1000 ; DIVMOD7 + LDY ESTKL+0,X ; LEFT PIXEL OFFSET +end +asm _hgrXHLinF + LDA $1000,Y ; HLMASK + STA TMPL + LDA ESTKL+1,X ; LEFT HORIZ OFFSET + TAY + LSR + BCS + +end +asm _hgrXHLinG + LDA $2000 ; CURHCLRL + STA SRCL + LDA $2001 ; CURHCLRH + STA SRCH + BCC ++ ++ LDA $2000 ; CURHCLRL + STA SRCH + LDA $2001 ; CURHCLRH + STA SRCL +++ CPY IPY ; RIGHT HORIZ OFFSET + BNE + + LDA SRCL + AND TMPL + EOR (DST),Y STA (DST),Y INX INX RTS + LDA SRCL ; CURHCLR AND TMPL - STA ESTKL+0,X - LDA TMPL - EOR #$FF - AND (DST),Y - ORA ESTKL+0,X -- STA (DST),Y - INY - TYA - CMP ESTKL-1,X ; RIGHT HORIZ OFFSET - LDA SRCH - BCS + +- EOR (DST),Y STA (DST),Y INY - TYA - CMP ESTKL-1,X ; RIGHT HORIZ OFFSET + CPY IPY ; RIGHT HORIZ OFFSET + LDA SRCH + BCS + + EOR (DST),Y + STA (DST),Y + INY + CPY IPY ; RIGHT HORIZ OFFSET LDA SRCL BCC - + AND TMPH - STA ESTKL+0,X - LDA TMPH - EOR #$FF - AND (DST),Y - ORA ESTKL+0,X + EOR (DST),Y STA (DST),Y INX INX @@ -845,6 +947,65 @@ asm _hgrVLinC INX RTS end +//export def hgrXVlin(y1, y2, x)#0 +// word pixptr, y, ofst +// byte pixofst, pmask, cmask +// +// if y1 == y2 +// hgrXorPlot(x, y1) +// else +// ofst, pixofst = divmod7(x) +// ofst = ofst + drawbuff +// pmask = hbmask[pixofst] +// cmask = curhclr.[ofst & 1] & pmask +// pmask = ~pmask +// for y = y1 to y2 +// pixptr = hgrscan[y] + ofst +// ^pixptr = ^pixptr ^ cmask +// next +// fin +//end +export asm hgrXorVlin(y1, y2, x)#0 + JSR 1000 ; DIVMOD7 + LDY ESTKL+0,X ; PIXEL OFFSET +end +asm _hgrXVLinA + LDA $1000,Y ; HBMASK + STA TMPL + EOR #$FF + STA TMPH + LDA ESTKL+1,X ; HORIZ OFFSET + AND #$01 + TAY +end +asm _hgrXVLinB + LDA $2000,Y ; CURHCLR + AND TMPL + STA TMPL + LDY ESTKL+3,X ; Y1 COORD +end +asm _hgrXVLinC +- LDA $8000,Y ; HGRSCANL + STA DSTL + LDA $1000 ; DRAWBUFFH + ORA $9000,Y ; HGRSCANH + STA DSTH + LDY ESTKL+1,X ; HORIZ OFFSET + LDA TMPL + EOR (DST),Y + STA (DST),Y + LDY ESTKL+3,X ; Y1 COORD + TYA + INY + STY ESTKL+3,X ; Y1 COORD + CMP ESTKL+2,X ; Y2 COORD + BNE - + INX + INX + INX + INX + RTS +end // // Masked BLT scanline of pixmap // @@ -949,6 +1110,17 @@ export def hgrRect(x1, y1, x2, y2)#0 next fin end +export def hgrXorRect(x1, y1, x2, y2)#0 + word y + + if x1 == x2 + hgrXorVLin(y1, y2, x1) + else + for y = y1 to y2 + hgrXorHLin(x1, x2, y) + next + fin +end export def hgrBLT(x, y, w, h, srcptr)#0 word i, j word saveclr @@ -1068,12 +1240,30 @@ _hgrHLinG:1 = @curhclr _hgrHLinG:6 = @curhclr.1 _hgrHLinG:13 = @curhclr.1 _hgrHLinG:18 = @curhclr +_hgrXHLinA:1 = @hgrXorPlot +_hgrXHLinB:1 = @hgrscanl +_hgrXHLinB:6 = @drawbuff.1 +_hgrXHLinB:9 = @hgrscanh +_hgrXHLinC:1 = @divmod7 +_hgrXHLinD:1 = @hrmask +_hgrXHLinE:1 = @divmod7 +_hgrXHLinF:1 = @hlmask +_hgrXHLinG:1 = @curhclr +_hgrXHLinG:6 = @curhclr.1 +_hgrXHLinG:13 = @curhclr.1 +_hgrXHLinG:18 = @curhclr hgrVLin:1 = @divmod7 _hgrVLinA:1 = @hbmask _hgrVLinB:1 = @curhclr _hgrVLinC:1 = @hgrscanl _hgrVLinC:6 = @drawbuff.1 _hgrVLinC:9 = @hgrscanh +hgrXorVLin:1 = @divmod7 +_hgrXVLinA:1 = @hbmask +_hgrXVLinB:1 = @curhclr +_hgrXVLinC:1 = @hgrscanl +_hgrXVLinC:6 = @drawbuff.1 +_hgrXVLinC:9 = @hgrscanh hgrColor:7 = @hcolor hgrColor:10 = @curhclr hgrColor:13 = @hcolor.1 diff --git a/src/libsrc/apple/hgrsprite.pla b/src/libsrc/apple/hgrsprite.pla index 316bc9b..4b6c03d 100644 --- a/src/libsrc/apple/hgrsprite.pla +++ b/src/libsrc/apple/hgrsprite.pla @@ -129,6 +129,7 @@ export def spriteCompile(w, h, xcenter, ycenter, srcptr)#1 var sprtptr, bytewidth, spritesize, i sprtptr = heapalloc(t_sprite) + if not sprtptr; return 0; fin bytewidth = (w + 13) / 7 sprtptr->s_pitch = bytewidth spritesize = bytewidth * h @@ -136,11 +137,15 @@ export def spriteCompile(w, h, xcenter, ycenter, srcptr)#1 sprtptr->s_height = h sprtptr->s_xcenter = xcenter sprtptr->s_ycenter = ycenter - sprtptr=>s_under[0] = heapalloc(spritesize) - sprtptr=>s_under[1] = heapalloc(spritesize) + sprtptr=>s_under[0] = 0//heapalloc(spritesize) + sprtptr=>s_under[1] = 0//heapalloc(spritesize) for i = 0 to 13 sprtptr=>s_map[i] = heapalloc(spritesize) sprtptr=>s_mask[i] = heapalloc(spritesize) + if not sprtptr=>s_map[i] or not sprtptr=>s_mask[i] + heaprelease(sprtptr) + return 0 + fin hgrColor(7) hgrRect(0, 0, w + 21, h - 1) spriteBLTMask(i, 0, w, h, srcptr) @@ -157,27 +162,33 @@ export def spriteDup(sprtsrc)#1 byte i sprtdup = heapalloc(t_sprite) + if not sprtdup; return 0; fin memcpy(sprtdup, sprtsrc, t_sprite) - spritesize = sprtdup=>s_size - sprtdup=>s_under[0] = heapalloc(spritesize) - sprtdup=>s_under[1] = heapalloc(spritesize) + //spritesize = sprtdup=>s_size + sprtdup=>s_under[0] = 0//heapalloc(spritesize) + sprtdup=>s_under[1] = 0//heapalloc(spritesize) return sprtdup end export def spriteRead(filestr)#1 var sprtptr, spritesize byte refnum, i - sprtptr = 0 + sprtptr = heapalloc(t_sprite) + if not sprtptr; return 0; fin refnum = fileio:open(@filestr) if refnum - sprtptr = heapalloc(t_sprite) if fileio:read(refnum, sprtptr, t_sprite) == t_sprite spritesize = sprtptr=>s_size sprtptr=>s_under[0] = heapalloc(spritesize) sprtptr=>s_under[1] = heapalloc(spritesize) + if not sprtptr=>s_under[0] or not sprtptr=>s_under[1] + heaprelease(sprtptr) + fileio:close(refnum) + return 0 + fin for i = 0 to 13 - sprtptr=>s_map[i] = heapalloc(spritesize) - sprtptr=>s_mask[i] = heapalloc(spritesize) + sprtptr=>s_map[i] = 0//heapalloc(spritesize) + sprtptr=>s_mask[i] = 0//heapalloc(spritesize) fileio:read(refnum, sprtptr=>s_map[i], spritesize) fileio:read(refnum, sprtptr=>s_mask[i], spritesize) next @@ -186,6 +197,9 @@ export def spriteRead(filestr)#1 sprtptr = 0 fin fileio:close(refnum) + else + heaprelease(sprtptr) + sprtptr = 0 fin return sprtptr end @@ -223,12 +237,18 @@ export def spriteDraw(sprtptr)#0 sprtptr=>s_undery[drawpage] = y pitch = sprtptr->s_pitch height = sprtptr->s_height + if not sprtptr=>s_under[drawpage] + sprtptr=>s_under[drawpage] = heapalloc(sprtptr=>s_size) + if not sprtptr=>s_under[drawpage]; return; fin + fin hgrCopyDst(ofst, y, pitch, height, sprtptr=>s_under[drawpage]) hgrAndSrc( ofst, y, pitch, height, sprtptr=>s_mask[map]) hgrXorSrc( ofst, y, pitch, height, sprtptr=>s_map[map]) end export def spriteUnDraw(sprtptr)#0 - hgrCopySrc(sprtptr=>s_underofst[drawpage], sprtptr=>s_undery[drawpage], sprtptr->s_pitch, sprtptr->s_height, sprtptr=>s_under[drawpage]) + if sprtptr=>s_under[drawpage] + hgrCopySrc(sprtptr=>s_underofst[drawpage], sprtptr=>s_undery[drawpage], sprtptr->s_pitch, sprtptr->s_height, sprtptr=>s_under[drawpage]) + fin end export def spriteDrawXor(sprtptr)#0 byte map, pitch, height diff --git a/src/samplesrc/sfm.pla b/src/samplesrc/sfm.pla index d7ce814..33980b9 100644 --- a/src/samplesrc/sfm.pla +++ b/src/samplesrc/sfm.pla @@ -1,57 +1,120 @@ include "inc/cmdsys.plh" include "inc/hgrlib.plh" include "inc/hgrsprite.plh" -include "inc/lines.plh" include "inc/joybuzz.plh" -sysflags reshgr1|reshgr2 // Reserve HGR page 1 and 2 +sysflags reshgr1 // Reserve HGR page 1 -byte egg = $88,$88,$83,$33,$33,$33,$33,$38,$88,$88 -byte = $88,$83,$33,$11,$11,$11,$11,$33,$38,$88 -byte = $83,$31,$11,$11,$11,$11,$11,$11,$13,$38 -byte = $33,$11,$11,$11,$11,$11,$11,$11,$11,$33 -byte = $33,$11,$11,$11,$11,$11,$11,$11,$11,$33 -byte = $33,$11,$11,$11,$11,$11,$11,$11,$11,$33 -byte = $33,$11,$11,$11,$11,$11,$11,$11,$11,$33 -byte = $83,$31,$11,$11,$11,$11,$11,$11,$13,$38 -byte = $88,$83,$33,$11,$11,$11,$11,$33,$38,$88 -byte = $88,$88,$83,$33,$33,$33,$33,$38,$88,$88 -byte spider = $33,$88,$88,$33,$33,$33,$33,$88,$88,$33 -byte = $33,$88,$83,$32,$22,$22,$23,$38,$88,$33 -byte = $83,$38,$83,$32,$22,$22,$23,$38,$83,$38 -byte = $88,$83,$33,$22,$22,$22,$22,$33,$38,$88 -byte = $33,$88,$33,$22,$22,$22,$22,$33,$88,$33 -byte = $88,$33,$38,$33,$22,$22,$33,$83,$33,$88 -byte = $88,$88,$83,$33,$22,$22,$33,$38,$88,$88 -byte = $88,$33,$33,$33,$22,$22,$33,$33,$33,$88 -byte = $33,$88,$88,$88,$33,$33,$88,$88,$88,$33 -byte = $88,$88,$33,$33,$22,$22,$33,$33,$88,$88 -byte = $88,$33,$88,$33,$22,$22,$33,$88,$33,$88 -byte = $33,$88,$88,$83,$32,$23,$38,$88,$88,$33 -byte = $88,$88,$88,$88,$33,$33,$88,$88,$88,$88 -byte web1 = $88,$83,$38,$88 -byte = $88,$38,$83,$88 -byte = $88,$38,$83,$88 -byte = $88,$33,$33,$88 -byte = $83,$38,$83,$38 -byte = $83,$38,$83,$38 -byte = $83,$38,$83,$38 -byte = $33,$33,$33,$33 -byte web2 = $88,$33,$83,$38,$33,$88 -byte = $88,$38,$83,$38,$83,$88 -byte = $83,$38,$83,$38,$83,$38 -byte = $83,$33,$33,$33,$33,$38 -byte = $83,$38,$83,$38,$83,$38 -byte = $83,$38,$83,$38,$83,$38 -byte = $33,$88,$83,$38,$88,$33 -byte = $33,$33,$33,$33,$33,$33 -byte web3 = $88,$83,$38,$88,$88,$88,$88,$83,$38,$88 -byte = $88,$83,$38,$83,$38,$83,$38,$83,$38,$88 -byte = $88,$33,$88,$33,$88,$88,$33,$88,$33,$88 -byte = $88,$33,$33,$33,$33,$33,$33,$33,$33,$88 -byte = $83,$38,$88,$33,$83,$38,$33,$88,$83,$38 -byte = $83,$38,$83,$38,$83,$38,$83,$38,$83,$38 -byte = $33,$88,$83,$38,$83,$38,$83,$38,$88,$33 -byte = $33,$38,$33,$33,$33,$33,$33,$33,$33,$33 +const NUMSTARS = 32 +const SHIP_SPRTNUM = 0 +const MISSLE_SPRTNUM = 1 +const WEB_SPRTBASE = 2 +const SPIDER_SPRTEBASE = 8 +const FULL_CHARGE = 20 +const ATTACK_SPEED = 12 +const SWARM_LIMIT = 52 +const FASTMOVE_LIMIT = 120 +const WEB_LIMIT = 152 +const YSHIP = 180 + +byte egg3 = $88,$88,$83,$33,$38,$88,$88 +byte = $88,$83,$33,$11,$33,$38,$88 +byte = $83,$31,$11,$11,$11,$13,$38 +byte = $33,$11,$11,$11,$11,$11,$33 +byte = $33,$11,$11,$11,$11,$11,$33 +byte = $33,$11,$11,$11,$11,$11,$33 +byte = $33,$11,$11,$11,$11,$11,$33 +byte = $33,$11,$11,$11,$11,$11,$33 +byte = $33,$11,$11,$11,$11,$11,$33 +byte = $83,$31,$11,$11,$11,$13,$38 +byte = $88,$83,$33,$11,$33,$38,$88 +byte = $88,$88,$83,$33,$38,$88,$88 +byte egg2 = $88,$88,$83,$33,$38,$88,$88 +byte = $88,$83,$33,$11,$33,$38,$88 +byte = $83,$30,$11,$00,$11,$13,$38 +byte = $33,$11,$00,$11,$00,$11,$33 +byte = $33,$00,$11,$00,$11,$00,$33 +byte = $33,$11,$00,$11,$00,$11,$33 +byte = $33,$00,$11,$00,$11,$00,$33 +byte = $33,$11,$00,$11,$00,$11,$33 +byte = $33,$00,$11,$00,$11,$00,$33 +byte = $83,$31,$00,$11,$00,$13,$38 +byte = $88,$83,$33,$00,$33,$38,$88 +byte = $88,$88,$83,$33,$38,$88,$88 +byte egg1 = $88,$88,$83,$33,$38,$88,$88 +byte = $88,$83,$33,$00,$33,$38,$88 +byte = $83,$30,$00,$00,$00,$03,$38 +byte = $33,$00,$00,$00,$00,$00,$33 +byte = $33,$00,$00,$00,$00,$00,$33 +byte = $33,$00,$00,$00,$00,$00,$33 +byte = $33,$00,$00,$00,$00,$00,$33 +byte = $33,$00,$00,$00,$00,$00,$33 +byte = $33,$00,$00,$00,$00,$00,$33 +byte = $83,$30,$00,$00,$00,$03,$38 +byte = $88,$83,$33,$11,$33,$38,$88 +byte = $88,$88,$83,$33,$38,$88,$88 +byte spider3 = $33,$88,$88,$33,$33,$33,$33,$88,$88,$33 +byte = $33,$88,$83,$32,$22,$22,$23,$38,$88,$33 +byte = $83,$38,$83,$32,$22,$22,$23,$38,$83,$38 +byte = $88,$83,$33,$22,$22,$22,$22,$33,$38,$88 +byte = $33,$88,$33,$22,$22,$22,$22,$33,$88,$33 +byte = $88,$33,$38,$33,$22,$22,$33,$83,$33,$88 +byte = $88,$88,$83,$33,$22,$22,$33,$38,$88,$88 +byte = $88,$33,$33,$33,$22,$22,$33,$33,$33,$88 +byte = $33,$88,$88,$88,$33,$33,$88,$88,$88,$33 +byte = $88,$88,$33,$33,$22,$22,$33,$33,$88,$88 +byte = $88,$33,$88,$33,$22,$22,$33,$88,$33,$88 +byte = $33,$88,$88,$83,$32,$23,$38,$88,$88,$33 +byte = $88,$88,$88,$88,$33,$33,$88,$88,$88,$88 +byte spider2 = $33,$88,$88,$33,$33,$33,$33,$88,$88,$33 +byte = $33,$88,$83,$30,$02,$20,$03,$38,$88,$33 +byte = $83,$38,$83,$32,$20,$02,$23,$38,$83,$38 +byte = $88,$83,$33,$20,$02,$20,$02,$33,$38,$88 +byte = $33,$88,$33,$02,$20,$02,$20,$33,$88,$33 +byte = $88,$33,$38,$30,$02,$20,$03,$83,$33,$88 +byte = $88,$88,$83,$33,$20,$02,$33,$38,$88,$88 +byte = $88,$33,$33,$30,$02,$20,$03,$33,$33,$88 +byte = $33,$88,$88,$88,$33,$33,$88,$88,$88,$33 +byte = $88,$88,$33,$30,$02,$20,$03,$33,$88,$88 +byte = $88,$33,$88,$33,$20,$02,$33,$88,$33,$88 +byte = $33,$88,$88,$83,$32,$23,$38,$88,$88,$33 +byte = $88,$88,$88,$88,$33,$33,$88,$88,$88,$88 +byte spider1 = $33,$88,$88,$33,$33,$33,$33,$88,$88,$33 +byte = $33,$88,$83,$30,$00,$00,$03,$38,$88,$33 +byte = $83,$38,$83,$30,$00,$00,$03,$38,$83,$38 +byte = $88,$83,$33,$00,$00,$00,$00,$33,$38,$88 +byte = $33,$88,$33,$00,$00,$00,$00,$33,$88,$33 +byte = $88,$33,$38,$33,$00,$00,$33,$83,$33,$88 +byte = $88,$88,$83,$33,$00,$00,$33,$38,$88,$88 +byte = $88,$33,$33,$30,$00,$00,$03,$33,$33,$88 +byte = $33,$88,$88,$88,$33,$33,$88,$88,$88,$33 +byte = $88,$88,$33,$30,$00,$00,$03,$33,$88,$88 +byte = $88,$33,$88,$33,$00,$00,$33,$88,$33,$88 +byte = $33,$88,$88,$83,$30,$03,$38,$88,$88,$33 +byte = $88,$88,$88,$88,$33,$33,$88,$88,$88,$88 +byte web1 = $88,$83,$38,$88 +byte = $88,$38,$83,$88 +byte = $88,$38,$83,$88 +byte = $88,$33,$33,$88 +byte = $83,$38,$83,$38 +byte = $83,$38,$83,$38 +byte = $83,$38,$83,$38 +byte = $33,$33,$33,$33 +byte web2 = $88,$33,$83,$38,$33,$88 +byte = $88,$38,$83,$38,$83,$88 +byte = $83,$38,$83,$38,$83,$38 +byte = $83,$33,$33,$33,$33,$38 +byte = $83,$38,$83,$38,$83,$38 +byte = $83,$38,$83,$38,$83,$38 +byte = $33,$88,$83,$38,$88,$33 +byte = $33,$33,$33,$33,$33,$33 +byte web3 = $88,$83,$38,$88,$88,$88,$88,$83,$38,$88 +byte = $88,$83,$38,$83,$38,$83,$38,$83,$38,$88 +byte = $88,$33,$88,$33,$88,$88,$33,$88,$33,$88 +byte = $88,$33,$33,$33,$33,$33,$33,$33,$33,$88 +byte = $83,$38,$88,$33,$83,$38,$33,$88,$83,$38 +byte = $83,$38,$83,$38,$83,$38,$83,$38,$83,$38 +byte = $33,$88,$83,$38,$83,$38,$83,$38,$88,$33 +byte = $33,$38,$33,$33,$33,$33,$33,$33,$33,$33 byte ship = $CC,$CC,$CC,$77,$CC,$CC,$CC byte = $CC,$CC,$C7,$77,$7C,$CC,$CC byte = $CC,$CC,$C7,$77,$7C,$CC,$CC @@ -82,73 +145,130 @@ byte = $88,$88,$88,$88 byte = $88,$88,$88,$88 byte = $88,$88,$88,$88 byte = $88,$88,$88,$88 -var sprtEgg, sprtSpider, sprtWeb1, sprtWeb2, sprtWeb3 +var sprtEgg1, sprtEgg2, sprtEgg3 +var sprtSpider1, sprtSpider2, sprtSpider3 +var sprtWeb1, sprtWeb2, sprtWeb3 var sprtShip, sprtMissle, sprtDummy - -def moire#0 - var i - - setlinespans(@hgrHlin, @hgrVlin) - setlineplot(@hgrPlot) - hgrColor(7) - for i = 0 to 191 step 8 - linespans(0, i, 279, 191 - i) - next - for i = 0 to 279 step 9 - linespans(i, 0, 279 - i, 191) - next +var[NUMSTARS] xstar +byte[NUMSTARS] ystar +byte won, curstar +def initStars#0 + byte k + + xstar[0] = 99 + ystar[0] = 10 + hgrColor(3) + hgrXorPlot(xstar[0], ystar[0]) + for k = 1 to NUMSTARS-1 + xstar[k] = (xstar[k - 1] + 97 - k) % 280 + ystar[k] = (ystar[k - 1] + 19 + k) % YSHIP + hgrXorPlot(xstar[k], ystar[k]) + next + curstar = 0 end -def game(spdrcnt)#0 - var[14] xspdr, yspdr, ixspdr, iyspdr, hatch - var xship, xmissle, attack - byte yship, ymissle +def updateStars#0 + hgrColor(3) + hgrXorPlot(xstar[curstar], ystar[curstar]) + ystar[curstar]++ + if ystar[curstar] > YSHIP + ystar[curstar] = 0 + fin + hgrXorPlot(xstar[curstar], ystar[curstar]) + curstar++ + if curstar >= NUMSTARS; curstar = 0; fin +end +def game(spdrcnt)#1 + var[8] xspdr, yspdr, ixspdr, iyspdr, hatch + var xship, xmissle, leftxlaser, rightxlaser, attack + byte[8] life + byte lasercharge, misslecnt, ymissle, leftylaser, rightylaser, lefthit, righthit, width byte spdrnum, k, xdelta, ydelta, btn0, btn1, webstate - xship = 140 - ymissle = 255 + xship = 140 + ymissle = 255 // Not active value + misslecnt = 6 + lasercharge = FULL_CHARGE + // + // Initialize the spiders (first is special) + // xspdr[0] = 100 ixspdr[0] = 1 yspdr[0] = 60 iyspdr[0] = -1 hatch[0] = 1 + life[0] = 3 attack = -1 webstate = 0 + // + // Initialize spiders + // spdrnum = spdrcnt - 1 for k = 1 to spdrnum - spriteAdd(k + 8, spriteDup(sprtEgg)) + spriteAdd(k + SPIDER_SPRTEBASE, spriteDup(sprtEgg3)) xspdr[k] = ((xspdr[k - 1] ^ 37) + 97) & 255 ixspdr[k] = -ixspdr[k - 1] yspdr[k] = ((yspdr[k - 1] ^ 29) + 53) & 63 iyspdr[k] = -iyspdr[k - 1] - hatch[k] = hatch[k - 1] + 1 + hatch[k] = k / 2 + 1//hatch[k - 1] + 1 + life[k] = 3 next + // + // Initialize missle display + // + hgrColor(3) + hgrRect(0, YSHIP+3, 279, 191) + for k = 0 to misslecnt-1 + spritePos(k * 16 + 160, 184, sprtMissle) + spriteDrawXor(sprtMissle) + next + hgrColor(1) + hgrRect(4, YSHIP+6, FULL_CHARGE * 4 + 4, 188) + // + // Main game loop + // repeat + // + // Move living spiders + // for k = 0 to spdrnum - if yspdr[k] <> 255 + if life[k] yspdr[k] = yspdr[k] + iyspdr[k] if yspdr[k] < -5 + // + // Above screen + // iyspdr[k] = 1 if hatch[k] hatch[k]-- if hatch[k] == 0 - spriteAdd(k + 8, spriteDup(sprtSpider)) + // + // Hatch this egg into a spider + // + life[k] = 3 // Reset life + spriteAdd(k + SPIDER_SPRTEBASE, spriteDup(sprtSpider3)) fin fin fin - if yspdr[k] > 64 // Attack or not? + if yspdr[k] > SWARM_LIMIT + // + // Attack or not? + // if hatch[k] == 0 and attack < 0 attack = k - iyspdr[k] = 8 + iyspdr[k] = ATTACK_SPEED fin if attack == k - if yspdr[k] > 160 + // + // Attacking + // + if yspdr[k] > WEB_LIMIT // // Iterate through web sequence // when webstate is 10 iyspdr[k] = -8 // Retreat - yspdr[k] = 160 + yspdr[k] = WEB_LIMIT spriteDel(2) spriteDel(3) spriteDel(4) @@ -157,44 +277,64 @@ def game(spdrcnt)#0 is 0 iyspdr[k] = 0 spriteAdd(2, sprtWeb1) - spritePosIndex(xspdr[k], 160, 2) + spritePosIndex(xspdr[k], WEB_LIMIT+7, 2) webstate = 1 break is 1 spriteAdd(3, sprtWeb2) - spritePosIndex(xspdr[k], 168, 3) + spritePosIndex(xspdr[k], WEB_LIMIT+15, 3) webstate = 2 break is 2 spriteAdd(4, sprtWeb3) - spritePosIndex(xspdr[k], 176, 4) + spritePosIndex(xspdr[k], WEB_LIMIT+22, 4) webstate = 3 otherwise - if xship >= xspdr[k] - 10 and xship <= xspdr[k] + 10 - return + // + // States 3..9 just repeat this + // + if xship >= xspdr[k] - 17 and xship <= xspdr[k] + 17 + // + // Capture ship + // + return FALSE fin webstate++ wend - fin - if iyspdr[k] > 0 // Attacking - xspdr[k] = xspdr[k] + (xship - xspdr[k]) / 8 - elsif iyspdr[k] < 0 // Retreating - if ixspdr[k] > 0 - xspdr[k] = xspdr[k] + (160 - yspdr[k]) / 8 + else + if iyspdr[k] > 0 + // + // Move towards player during attack, but not too fast + // + xspdr[k] = xspdr[k] + (xship - xspdr[k]) / (yspdr[k] > FASTMOVE_LIMIT ?? 2 :: 4) else - xspdr[k] = xspdr[k] - (160 - yspdr[k]) / 8 + // + // Retreat at a progressively faster rate + // + if ixspdr[k] > 0 + xspdr[k] = xspdr[k] + (WEB_LIMIT - yspdr[k]) / 8 + else + xspdr[k] = xspdr[k] - (WEB_LIMIT - yspdr[k]) / 8 + fin fin fin else + // + // Just reverse direction towards top of screen + // iyspdr[k] = -1 fin else if attack == k - attack = -1 // Stop attack + // + // Retreated back to swarm zone so stop attack + // + attack = -1 iyspdr[k] = -1 fin - fin - if attack <> k + // + // Swarm movement + // if ixspdr[k] > 0 xspdr[k] = xspdr[k] + yspdr[k] / 8 else @@ -210,75 +350,233 @@ def game(spdrcnt)#0 fin fin fin - spritePosIndex(xspdr[k], yspdr[k], k + 8) + spritePosIndex(xspdr[k], yspdr[k], k+SPIDER_SPRTEBASE) fin next + // + // Move ship + // xdelta, ydelta, btn0, btn1 = joypos(ymissle/4) - xship = xship + (xdelta / 4 - 10) + xship = xship + ((xdelta + 4) / 8 - 5) if xship < 0; xship = 0; fin if xship > 279; xship = 279; fin - if btn0 and ymissle == 255 - spriteAdd(1, sprtMissle) + if btn0 and misslecnt and ymissle == 255 + // + // Fire missle + // xmissle = xship - ymissle = 176 + ymissle = YSHIP+8 + misslecnt-- + spritePos(misslecnt * 16 + 160, 184, sprtMissle) // Erase from armory + spriteDrawXor(sprtMissle) + spriteAdd(1, sprtMissle) fin if ymissle <> 255 if ymissle < 8 + // + // Missle off top of screen + // spriteDel(1) ymissle = 255 else ymissle = ymissle - 8 - spritePosIndex(xmissle, ymissle, 1) + spritePosIndex(xmissle, ymissle, MISSLE_SPRTNUM) for k = 0 to spdrnum - if yspdr[k] <> 255 + if life[k] + // + // Hit test will all living spiders + // if ymissle >= yspdr[k] - 15 and ymissle <= yspdr[k] + 5 - if xmissle >= xspdr[k] - 10 and xmissle <= xspdr[k] + 10 + if hatch[k] + width = 7 // Egg width + else + width = 10 // Spider width + fin + if xmissle >= xspdr[k] - width and xmissle <= xspdr[k] + width // - // Hit + // Hit & kill spider // + life[k] = 0 + spriteAdd(k+SPIDER_SPRTEBASE, spriteDup(sprtDummy)) + spritePosIndex(0, 0, k+SPIDER_SPRTEBASE) if attack == k // Was it attacking? attack = -1 + spriteDel(2) + spriteDel(3) + spriteDel(4) + webstate = 0 fin - yspdr[k] = 255 - ymissle = 255 - spriteAdd(k + 8, spriteDup(sprtDummy)) - spritePosIndex(0, 0, k + 8) - spriteDel(1) spdrcnt-- if not spdrcnt - return + return TRUE fin + // + // Remove missle + // + spriteDel(MISSLE_SPRTNUM) + ymissle = 255 fin fin fin next fin fin - spritePosIndex(xship, 190, 0) -// spriteDrawList() + if lasercharge < FULL_CHARGE + lasercharge++ + hgrColor(1) + hgrRect(4, YSHIP+6, lasercharge * 4 + 4, 188) +// hgrRect((lasercharge - 1) * 4 + 5, YSHIP+6, lasercharge * 4 + 4, 188) + fin + if btn1 and lasercharge == FULL_CHARGE + // + // Fire laser + // + hgrColor(0) + hgrRect(4, YSHIP+6, FULL_CHARGE * 4 + 4, 188) + lasercharge = 0 + leftxlaser = xship - 7 + rightxlaser = xship + 7 + leftylaser = 0 + rightylaser = 0 + lefthit = 255 + righthit = 255 + for k = 0 to spdrnum + if life[k] + // + // Hit test will all living spiders + // + if hatch[k] + width = 7 // Egg width + else + width = 10 // Spider width + fin + if leftxlaser >= xspdr[k] - width and leftxlaser <= xspdr[k] + width + if yspdr[k] > leftylaser + lefthit = k + leftylaser = yspdr[k] + fin + fin + if rightxlaser >= xspdr[k] - width and rightxlaser <= xspdr[k] + width + if yspdr[k] > rightylaser + righthit = k + rightylaser = yspdr[k] + fin + fin + fin + next + // + // Draw Laser beams + // + hgrColor(3) + for k=0 to 1 + if leftxlaser + k >= 0; hgrXorVLin(leftylaser, YSHIP+8, leftxlaser+k); fin + if rightxlaser + k < 280;hgrXorVLin(rightylaser, YSHIP+8, rightxlaser-k); fin + next + if lefthit <> 255 + // + // Hit + // + life[lefthit]-- + if not life[lefthit] + // + // Kill spider + // + spriteAdd(lefthit + SPIDER_SPRTEBASE, spriteDup(sprtDummy)) + spritePosIndex(0, 0, lefthit + SPIDER_SPRTEBASE) + if attack == lefthit // Was it attacking? + spriteDel(2) + spriteDel(3) + spriteDel(4) + webstate = 0 + attack = -1 + fin + spdrcnt-- + if not spdrcnt + return TRUE + fin + else + // + // Dim color to show life status + // + if hatch[lefthit] + spriteAdd(lefthit + SPIDER_SPRTEBASE, spriteDup(life[lefthit] == 2 ?? sprtEgg2 :: sprtEgg1)) + else + spriteAdd(lefthit + SPIDER_SPRTEBASE, spriteDup(life[lefthit] == 2 ?? sprtSpider2 :: sprtSpider1)) + fin + spritePosIndex(xspdr[lefthit], yspdr[lefthit], lefthit+SPIDER_SPRTEBASE) + fin + fin + if righthit <> 255 and life[righthit] + // + // Hit + // + life[righthit]-- + if not life[righthit] + // + // Kill spider + // + spriteAdd(righthit + SPIDER_SPRTEBASE, spriteDup(sprtDummy)) + spritePosIndex(0, 0, righthit + SPIDER_SPRTEBASE) + if attack == righthit // Was it attacking? + spriteDel(2) + spriteDel(3) + spriteDel(4) + webstate = 0 + attack = -1 + fin + spdrcnt-- + if not spdrcnt + return TRUE + fin + else + // + // Dim color to show life status + // + if hatch[righthit] + spriteAdd(righthit + SPIDER_SPRTEBASE, spriteDup(life[righthit] == 2 ?? sprtEgg2 :: sprtEgg1)) + else + spriteAdd(righthit + SPIDER_SPRTEBASE, spriteDup(life[righthit] == 2 ?? sprtSpider2 :: sprtSpider1)) + fin + spritePosIndex(xspdr[righthit], yspdr[righthit], righthit+SPIDER_SPRTEBASE) + fin + fin + // + // Undraw lasers + // + hgrColor(3) + for k=0 to 1 + if leftxlaser + k >= 0; hgrXorVLin(leftylaser, YSHIP+8, leftxlaser+k); fin + if rightxlaser + k < 280;hgrXorVLin(rightylaser, YSHIP+8, rightxlaser-k); fin + next + fin + spritePosIndex(xship, YSHIP, SHIP_SPRTNUM) spriteDrawXorList() - spriteDrawBuf(hgrSwap()) + updateStars until ^$C000 == $9B getc + return FALSE end hgrMode spriteDrawBuf(hgrDrawBuf(0)) // So we can see the compile process sprtShip = spriteCompile(14, 14, 7, 13, @ship) sprtMissle = spriteCompile( 6, 8, 3, 0, @missle) -sprtEgg = spriteCompile(20, 10, 10, 5, @egg) -sprtSpider = spriteCompile(20, 13, 10, 6, @spider) +sprtEgg3 = spriteCompile(14, 12, 7, 6, @egg3) +sprtEgg2 = spriteCompile(14, 12, 7, 6, @egg2) +sprtEgg1 = spriteCompile(14, 12, 7, 6, @egg1) +sprtSpider3= spriteCompile(20, 13, 10, 6, @spider3) +sprtSpider2= spriteCompile(20, 13, 10, 6, @spider2) +sprtSpider1= spriteCompile(20, 13, 10, 6, @spider1) sprtWeb1 = spriteCompile( 8, 8, 4, 0, @web1) sprtWeb2 = spriteCompile(12, 8, 6, 0, @web2) sprtWeb3 = spriteCompile(20, 8, 10, 0, @web3) sprtDummy = spriteCompile( 7, 8, 0, 0, @dummy) hgrColor(0) hgrClear() -//moire -memcpy($4000, $2000, $2000) // Copy to both buffers -spriteDrawBuf(hgrDrawBuf(1)) -spriteAdd(0, sprtShip) -spriteAdd(8, sprtEgg) -game(8) +spriteAdd(SHIP_SPRTNUM, sprtShip) +spriteAdd(SPIDER_SPRTEBASE, sprtEgg3) +initStars +won = game(8) txtMode +puts(won ?? "You won!\n" :: "You lost.\n") done diff --git a/src/tftpbld b/src/tftpbld index 716af76..57f2819 100755 --- a/src/tftpbld +++ b/src/tftpbld @@ -48,10 +48,10 @@ echo "BLD/SAMPLES/HGRTEST.PLA"; atftp $1 --put -l samplesrc/hgrtest.pla -r $ echo "BLD/SAMPLES/PLAYSEQ.PLA"; atftp $1 --put -l samplesrc/playseq.pla -r $2/BLD/SAMPLES/PLAYSEQ.PLA#040000 echo "BLD/SAMPLES/RPNCALC.PLA"; atftp $1 --put -l samplesrc/rpncalc.pla -r $2/BLD/SAMPLES/RPNCALC.PLA#040000 echo "BLD/SAMPLES/SIEVE.PLA"; atftp $1 --put -l samplesrc/sieve.pla -r $2/BLD/SAMPLES/SIEVE.PLA#040000 -echo "BLD/SAMPLES/MON.PLA"; atftp $1 --put -l utilsrc/apple/mon.pla -r $2/BLD/SAMPLES/MON.PLA#040000 echo "BLD/SAMPLES/MEMTEST.PLA"; atftp $1 --put -l samplesrc/memtest.pla -r $2/BLD/SAMPLES/MEMTEST.PLA#040000 echo "BLD/SAMPLES/FATCAT.PLA"; atftp $1 --put -l samplesrc/fatcat.pla -r $2/BLD/SAMPLES/FATCAT.PLA#040000 echo "BLD/SAMPLES/GFXDEMO.PLA"; atftp $1 --put -l samplesrc/gfxdemo.pla -r $2/BLD/SAMPLES/GFXDEMO.PLA#040000 echo "BLD/SAMPLES/LZ4CAT.PLA"; atftp $1 --put -l samplesrc/lz4cat.pla -r $2/BLD/SAMPLES/LZ4CAT.PLA#040000 -echo "BLD/SAMPLES/SFM.PLA"; atftp $1 --put -l samplesrc/sfm.pla -r $2/BLD/SAMPLES/SFM.PLA#040000 +echo "BLD/SAMPLES/SFM.PLA"; atftp $1 --put -l samplesrc/sfm.pla -r $2/BLD/SAMPLES/SFM.PLA#040000 +echo "BLD/SAMPLES/MON.PLA"; atftp $1 --put -l utilsrc/apple/mon.pla -r $2/BLD/SAMPLES/MON.PLA#040000