; Title : Wormy ; Version : 96% (0.96.C21) ; Release Date : UUHHhhh... soon?!? ; Filename : wormy.86p (5kb) ; Author(s) : Shiar ; Email Address : wormy@shiar.org ; Web Page : www.shiar.org ; Description : ruling Nibbles-like game 1-4 players ; Where to get this game : www.shiar.org (home of Wormy) ; Other games by author(s) : Nemesis beta ; Additional Credits to : Matthew Shepcar (wrote original Peaworm, end'98) ; Jonah Cohen (helped writing worm) ;----------------------------- ;----------- TO-DO ----------- ;----------------------------- ; 96% = DONE ; * complete readme ; 1% * misc (pollish, bugs, &&&) ; * mem at worm #4 (still 12 bytes or so.....) ; * fix line proc (+large circles) ; * LINK ; 1% * fix transmit game/level data ;100% = bugs fixed + levels done ;>110%: sound, startpos ;>120%: coop (DON'T COUNT ON IT) ;----------------------------- ;----------------------------- ;------- W O R M Y --------- ;----------------------------- ;----------------------------- #define buffer ;use display buffer (otherwise write directly to screen) #define readymask ;"greys" out the field before starting a level #define coolzgfx ;nice graphics for game over screen ;#define intlevels ;internal levels ;#define readytext ;displays "prepare" before level starts ;#define invincible ;worms cannot die =) ;#define optdie ;in race games worms don't die when they run into each other #define cal call #define psh push #define dnz djnz #include "asm86.h" #include "ti86asm.inc" _SHRACC = $4383 ;4x srl a _SHLACC = $438B ;4x sll a _divHLby10 = $4044 ;hl=hl/10 _divAby10 = $4DAF ;a=a/10 _HLTIMES10 = $41BF ;hl=hl*10 _cphlde = $403C ;cp hl,de _clrWindow = $4A86 ;clear screen _asapvar = $D6FC ;own name (worm) _MOV4B = $429B ;4x ld (de),(hl) _MOV5B = $4297 ;5x ld (de),(hl) _mov9b = $4283 ;9x ld (de),(hl) _ldHLind = $4010 ;ld hl,(hl) _swapt_ = $45F3 ;ex_ahl_bde _Get_Word_ahl = $521D ;ld de,(ahl) _Set_Word_ahl = $5221 ;ld (ahl),de _INC_PTR_AHL = $4637 ;ahl=ahl+1 _AHL_PLUS_2_PG3 = $4C3F ;ahl=ahl+2 _SET_ABS_SRC_ADDR = $4647 ;set source for mm.ldir =ahl _LOAD_ABS_SRC_ADDR = $5209 ;ahl = mm.ldir source _SET_ABS_DEST_ADDR = $5285 ;set destination for mm.ldir = ahl _SET_MM_NUM_BYTES = $464F ;number of bytes for mm.ldir = ahl _mm_ldir = $52ED ;24bit ldir _MM_LDIR_SET_SIZE = $524D ;_SET_MM_NUM_BYTES + _mm_ldir _RAM_PAGE_1 = $47E3 ;set $8000+ to page 1 _RAM_PAGE_7 = $47F3 ;"""" 7 _PTEMP_END = $D29A ;end of VAT _load_ram_ahl = $462F ;ahl->page+hl _writeb_inc_ahl = $5567 ;ld (ahl++),c _jforce = $409C ;TI-OS stack restored _EXLP = $4493 ;swap (hl),(de) b times _GETB_AHL = $46C3 ;a=(ahl) \ hl=ahl ;----------------------------- ;------- data storage ------- ;----------------------------- ;--- permanent ScrBuffer = $8820 ;-A7FF (20*FF=1FE0) worm2p = $A800 ;-ABFF (400) %10101O00 worm1 = $AC00 ;-AC1D (31d) worm2 = $AC1F ;-AC3B (1F) worm3 = $AC3E ;-AC59 (1F) worm4 = $AC5D ;-AC77 (1F) balls = $AC7C ;-ACFF (3x43d) SinCosTable = $AD00 ;-AE00 (4*40) turn10 = $AE01 ;-AE01 (1) (counter) peaspos = $AE02 ;-AE05 (4) (peas) ;free = $AE06 ;-AFFF (1FA) worm1p = $B000 ;-B7FF (800) %1011O000 worm3p = $B800 ;-BBFF (400) %10111O00 ;free = $BF91 ;-BFFF (6F) ;program = $D748 ;-EFFF (186D+4A) worm4p = $F000 ;-F3FF (400) %11110O00 leveldata = $F400 ;-FA70 (<=671) ;can you believe i actually left $269 bytes of memory unused?!? ;MEM|8---9---A---B---C---D---E---F---| ; |..[------]||[]|......[-----]|[].| ; | SCREEN 2* 13 PRGM 4LV | ;--- temporary namelength = $BC00 ;(1) @menu datalink = $BC00 ;(8) @init #ifdef buffer DispBuffer = $BC00 ;(10x57d) @game #else DispBuffer = $FC70 #endif ;----------------------------- ;------- program start ------- ;----------------------------- .org %1101011101001000 start: nop jp Start ld bc,42 .org $-1 ;3y3 M 1337! .dw WormTxt .dw WormIcon WormTxt: ld d,a ld c,a ld d,d ld c,l ld e,c jr nz,$+100 ld a,c jr nz,$+$55 ld c,b .dw 16713 .db %1010010 jr nz,$+47 dec l .db " 96% C21",0 WormIcon: .db 8,2 .db %00000000,%00111100 .db %00000000,%01010010 .db %00000000,%01100001 .db %01100011,%10011001 .db %10010100,%01101001 .db %10011001,%00011001 .db %01000010,%11000001 .db %00111100,%00111110 levelhead = 'w' levelhead2 = 95 ;wormy levels header = "95" int_handler: ex af,af' in a,($03) bit 3,a jp z,$0039 res 0,a out ($03),a jp $0039 int_end: Start: ld (SpSave),sp cal _runindicoff cal _flushallmenus im 1 ld a,$D4 ld h,a ld l,0 ;ld hl,$D400 ld d,a ld e,1 ;ld de,$D401 ld b,e ld c,l ;ld bc,$0100 dec a ;ld a,$D3 ld (hl),a ldir ld hl,int_handler ld d,a ld e,a ;ld de,$D3D3 ld bc,int_end-int_handler ldir inc a ;ld a,$D4 ld i,a im 2 ;...it *does* work ;) cal _RAM_PAGE_7 ld hl,$BFFF ;VAT start ld ix,templevels searchloop: ld de,(_PTEMP_END+1) ;VAT end or a ;nc sbc hl,de ;hl" ld hl,$FC00+(2*16) ld b,16*9 cal menuinvloop ld hl,$FC00+(56*16) cal hr ld hl,$0601 ;x=1 ld (_penCol),hl dispnextlevel: ld a,(ix+3) ld b,a inc a ;cp 255 jr z,__levselect displevel: ld hl,_penCol ld (hl),$01 ;x=1 inc hl ld a,(hl) add a,6 ld (hl),a ;y+6 cp 49 ;bottom of screen jr nc,_levselect ld de,3 add ix,de ld hl,availevels inc (hl) ld a,b ;(ix+0) ld h,(ix+1) ld l,(ix+2) ;ahl=(ix) cal _load_ram_ahl ;hl=ahl cal _vputs jr dispnextlevel readylevelfile: ;selected level at ahl ; ld hl,templevels-3/0 ld a,b add a,3 ;sellev+3 (#0==-3) ld e,a add a,a ;*2 add a,e ;*3 ld e,a ld d,0 ;de=sellev*3 add hl,de ld a,(hl) ;ade=(hl) inc hl ld d,(hl) inc hl ld e,(hl) ex de,hl ;ahl=ade skiptitle: ld d,a ;psh ahl psh hl cal _GETB_AHL ;ld a,(ahl) pop hl or a ld a,d ;pop ahl psh af cal _INC_PTR_AHL ;ahl++ pop af ;cp 0 jr nz,skiptitle ;goto #0-terminator ret levup: cal menupos dec b ;up ld a,b cp -3 jr nz,levselect inc b ;undo jr levselect levdown: cal menupos inc b ;down ld a,b cp -2 availevels =$-1 jr nz,levselect dec b ;back up levselect: cal menupos ld hl,$3900 ld (_penCol),hl pop hl psh hl cal readylevelfile cal _load_ram_ahl ;hl=ahl ld de,$FFA0 ;desc.text xor a levdescclearloop: ld (de),a ;empty inc de cp d ;de>$FFFF (offscreen) jr nz,levdescclearloop cal _vputs jr levselectmenu+1 __levselect: #ifdef intlevels ld ix,templevels-6 ;reset 2 1st page #else ld ix,templevels-3 #endif _levselect: ld b,-2 ;level selected jr levselect levselectmenu: psh hl psh bc cal ubergetkey pop bc ;GET_KEY destr. b dec a ;cp K_DOWN jr z,levdown sub K_UP-1 jr z,levup pop hl inc a ;cp K_RIGHT jp z,levelselectmenu cp K_ENTER-K_RIGHT jr z,loadlevel sub K_EXIT-K_RIGHT jp z,ExitNoStats inc a ;cp K_SECOND jr nz,levselectmenu ; jr z,loadlevel loadlevel: cal readylevelfile or a ;levelfile on page 0 (=internal) jr z,levelloaded cal skiptitle ;skip description cal _Get_Word_ahl ld (leveldataSize),de ld d,8 ;counter ld bc,datalevels cal loadgametype ld (hilvlposa),a ;singleplayer levels ld (hilvlposhl),hl ld d,4 cal loadgametype cal _SET_ABS_SRC_ADDR ;levelsstart xor a ld hl,leveldata cal _SET_ABS_DEST_ADDR ;store in mem. ld hl,0 leveldataSize =$-2 cal _MM_LDIR_SET_SIZE cal _LOAD_ABS_SRC_ADDR ;->ahl ld (hiscrposa),a ld (hiscrposhl),hl cal _RAM_PAGE_1 ld hl,leveldata ld de,defsprsize ldi ;(de),(hl)\inc hl ld (defsprite),hl levelloaded: cal _RAM_PAGE_1 res 2,(iy+13) ;appAutoScroll ld a,r ld (Seed),a ld hl,datasingle+3 ld b,8 ld de,8 setdeflevels: ld (hl),1 ;def=level#1 add hl,de ;next dnz setdeflevels ;----------------------------- ;----- build trig tables ----- ;----------------------------- ld hl,TrigPrecalc ld de,SinCosTable psh de ld bc,65 ldir dec hl ld b,63 MirrorSineWave: dec hl ld a,(hl) ld (de),a inc de dnz MirrorSineWave pop hl ;SinCosTable ld b,128+64 NegativeSineWave: xor a sub (hl) ld (de),a inc hl inc de dnz NegativeSineWave ;----------------------------- ;---------- menu ------------- ;----------------------------- DisplayMenu: ;---draw menu--- cal linkok cal _clrWindow ld de,$FC40 ;(0,4) ld hl,wtPicture ld bc,16*16 ldir ld hl,$FC00+$010 ;(*,01) cal hr ld hl,$FC00+$160 ;(*,22) cal hr ld hl,$FC00+$3E0 ;(*,62) cal hr dispmainmenu: ld hl,Gametype ld a,(hl) dec a ;will be inced @changegame and 7 ld (hl),a ld hl,changegame ;dispmenusets ;mainMenu psh hl ;jump here after ret ld hl,txtMenu ld ix,posMenu ;Mode|Level|Limit|Worms|worm #|controls ; jr dispmenucommon ;cal dispmenucommon_: ld b,36*16/4 dispmenucommon: ld de,$FD80 ;begin pos xor a clroldmenuloop: ld (de),a inc de ld (de),a inc de ld (de),a inc de ld (de),a inc de dnz clroldmenuloop ld b,(ix) dispmenuloop: ld d,(ix+1) inc ix ld e,(ix+1) inc ix ld (_penCol),de cal _vputs dnz dispmenuloop ; ld b,0 ;b=menu# ret hr: ;draw horizontal line at hl ld b,16 ; jp menuinvloop ;shorter but not good for pausescreen hrloop: ld (hl),-1 inc hl dnz hrloop ret ;--- menu loop --- dispoptionmenu: ld hl,txtoMenu ld ix,posoMenu ;Back|Lives|Limit|Speed|Rotation|Growth cal dispmenucommon_ dispomenusets: cal clrold ld hl,$1E3E ld (_penCol),hl cal loadgamecar psh hl cal cshowA0 ;lives ld hl,$2A3E ld (_penCol),hl pop hl ;loadgamecar inc hl \ inc hl \ inc hl psh hl ld a,(hl) ;(Speed) inc a ;1..99 jr nz,dispspeed ld hl,txtDef cal _vputs jr dispspeeddone dispspeed: cal cshowA0 dispspeeddone: ld hl,$363E ld (_penCol),hl pop hl ;loadgamecar inc hl psh hl ld a,(hl) ;(growth) inc a ;-1=None; 0..98->1..99 cal cshowA0 ld hl,$303E ld (_penCol),hl pop hl ;loadgamecar inc hl psh hl ld a,(hl) cp 8 jr nz,dispturn ld hl,txtDef cal _vputs jr dispturndone dispturn: cal cshowA0 ;turn speed dispturndone: ld hl,$243E ld (_penCol),hl pop hl ;loadgamecar inc hl ld a,(hl) ;(scorelimit) or a psh af cal cshowA0 ;limit pop af ;a==0? jr z,optionMenu ;do not display 0 behind 'None' ld a,'0' cal _vputmap ;x10 optionMenu: cal menupos cal menucall jr nz,notoselect oselect: cal menupos ld a,b or a ;1st item? jp z,dispmainmenu ;mainMenu jr optionMenu notoselect cp K_EXIT jp z,dispmainmenu psh af cal menupos cal loadgamecar inc hl pop af sub K_LEFT jr z,seloleft dec a ;K_RIGHT ld a,b jr nz,optionMenu seloright: dec a jr z,changelives dec a jr z,changelimit dec a jr z,changespeed dec a jr z,changeturn dec a jr z,changegrowth seloleft: ld a,b dec a jr z,bchangelives dec a jr z,bchangelimit dec a jr z,bchangespeed dec a jr z,bchangeturn dec a jr z,bchangegrowth _optionMenu: jr optionMenu changelives: cal loadgamecar ;a=(hl) inc a cp 100 jr nc,optionMenu ;>99 changedlives: ld (hl),a _dispomenusets: jp dispomenusets ;optionMenu bchangelives: cal loadgamecar sub 1 ;dec does not set cf jr c,optionMenu ;<0 jr changedlives changelimit: cal changelimitInit inc a cp 100 jr nc,optionMenu ;>99 changedlimit: ld (hl),a jr _dispomenusets ;optionMenu bchangelimit: cal changelimitInit sub 1 ;dec does not set cf jr c,optionMenu ;<0 jr changedlimit changelimitInit: cal loadgamecar ld de,6 add hl,de ld a,(hl) ;(scorelimit) ret changespeed: cal changespeedInit inc a cp 20 jr nc,_optionMenu ;>98 changedspeed: dec hl ;(Speed) ld (hl),a jr _dispomenusets ;optionMenu bchangespeed: cal changespeedInit dec a cp -2 __optionMenu: ;w/ zf jr z,_optionMenu ;<-1 jr changedspeed changespeedInit: cal loadgamecar ld de,3 add hl,de ld a,(hl) ;(Speed) inc hl ;=saves 2 bytes :P ret changeturn: cal changespeedInit inc hl ;(turnspeed) ld a,(hl) inc a cp 26 jr nc,_optionMenu ;>25 changedturn: ld (hl),a jr _dispomenusets ;optionMenu bchangeturn: cal changespeedInit inc hl ld a,(hl) dec a cp 3 jr c,_optionMenu ;<3 jr changedturn changegrowth: cal changespeedInit ld a,(hl) inc a cp 99 jr nc,_optionMenu ;>98 changedgrowth: ld (hl),a jr _dispomenusets ;optionMenu bchangegrowth: cal changespeedInit ld a,(hl) dec a cp -2 jr z,__optionMenu ;<-1 jr changedgrowth ;--- mainMenu: cal menupos cal menucall jr nz,notselect select: ;2nd/enter cal menupos ld a,b dec a ;2nd item: level jp z,dispoptionmenu sub 3 ;5th item: wormname jp z,changeworms dec a ;6th: controls jp z,changekeys jp LetsGetThisPartyOn ;otherwise notselect cp K_EXIT jp z,ExitNoStats psh af cal menupos cal loadgamecar inc hl pop af sub K_LEFT jr z,selleft dec a ;K_RIGHT ld a,b jr nz,mainMenu selright: or a jr z,changegame dec a jr z,changelevel dec a jr z,changelink dec a jr z,changenrworms ; dec a ; jr z,changecurworm changecurworm: ; hl=nrworms ld a,(curworm) cp (hl) jr nc,mainMenu ;may not become >(nrworms) inc a changedcurworm: ld (curworm),a jr _dispmenusets ;mainMenu selleft: ld a,b or a jr z,bchangegame dec a jr z,bchangelevel dec a jr z,bchangelink dec a jr z,bchangenrworms ; dec a ; jr z,bchangecurworm bchangecurworm: ld a,(curworm) dec a ;0-3 jr nz,changedcurworm ;save >0 jr mainMenu changenrworms: cal change4spOnly ld a,(hl) ;hl=nrworms inc a cp 5 jr nc,mainMenu ;may not be >4 changednrworms: ld (hl),a jr _dispmenusets ;mainMenu changenrwormsInit: ld a,(Gametype) cp 3 ld a,(hl) ;hl=nrworms ret bchangenrworms: cal change4spOnly ld a,(hl) ;hl=nrworms dec a ;0-3 cp 2 jr nc,changednrworms ;save >=2 _mainMenu: jr mainMenu change4spOnly: ld a,(Gametype) cp 3 ret nc pop hl ;cal jr _mainMenu ;don't change for singleplayer changelink: bchangelink: cal change4spOnly dec hl ;inced earlier dec hl ;gameCar ld a,1 ;change LS-bit (=link) xor (hl) ;0=1; 1=0 ld (hl),a _dispmenusets: jr dispmenusets ;mainMenu changegame: ld a,(Gametype) inc a cal changedgame jr z,changegame jr dispmenusets ;mainMenu changedgame: and 7 ;mod 8 ld (Gametype),a cal getnrlevels xor a cp (hl) ret bchangegame: ld a,(Gametype) dec a cal changedgame jr z,bchangegame jr dispmenusets ;mainMenu changelevel: inc hl ;hl=loadgamecar+2 psh hl ld a,(hl) ;(curlevel) cal getnrlevels cp (hl) ;max level for sel.game pop hl jr z,_mainMenu inc a changedlevel: ld (hl),a jr dispmenusets ;mainMenu bchangelevel: inc hl ld a,(hl) ;(curlevel) dec a jr nz,changedlevel jr _mainMenu getnrlevels: ;for current gametype at hl ld hl,Gametype ld d,0 ld e,(hl) ld hl,nrlevels add hl,de ret getcustomkey: cal _vputs dec ix waitcustomkey: psh hl cal ubergetkey pop hl or a jr z,waitcustomkey cp K_EXIT ret z cp K_MORE jr z,waitcustomkey ld (ix),a ret changekeys: cal getwormname ld hl,txtKeyleft cal getcustomkey ;left cal getcustomkey ;right ; jr dispmenusets ;---display current settings--- dispmenusets: cal clrold ld de,$183E ld (_penCol),de ld d,0 ld a,(Gametype) ld e,a ld hl,posGame add hl,de ;hl=posGame+(Gametype) ld a,(hl) ;str.offset ld e,a ;^d=0^ ld hl,txtGame add hl,de ;txtGameX ld (CURtxtGame),hl ;save for g/o cal _vputs ;Singleplayer ld hl,$2A3E ;worms ld (_penCol),hl cal loadgamecar psh hl inc hl ld a,(hl) add a,'0' cal _vputmap ld hl,$243E ld (_penCol),hl rr c ;(gameCar) ld hl,txtNo jr nc,displink ld hl,txtYes displink: cal _vputs ld hl,$1E3E ;level ld (_penCol),hl pop hl ;loadgamecar psh bc ld d,0 cal hlatlevel ld a,(Gametype) or a ;gamesingle jr nz,displvlname ld a,(Level) cal cshowA0 jr lvldisped displvlname: cal _vputs lvldisped: pop bc ld hl,$3032 ld (_penCol),hl ld a,1 curworm =$-1 add a,'0' cal _vputmap ld hl,$303E ld (_penCol),hl cal getwormname psh ix ;wormNname pop hl ;ld hl,ix cal _vputs ld hl,$363E ;controls ld (_penCol),hl ld hl,txtMenuR cal _vputs jp mainMenu ;--- handle menukeys --- menucall: psh bc menuwaitkey: cal ubergetkey or a jr z,menuwaitkey pop bc ;GET_KEY destr. b cp K_UP cal z,menuup cp K_DOWN cal z,menudown cp K_ENTER ret z cp K_SECOND ret ;z=select menupos: ;highlight #b ld c,b ;psh b ld a,b add a,3 add a,a add a,a sub b add a,a add a,a add a,a ;*24 ld h,$FC/4 ld l,a add hl,hl add hl,hl ;$FD20+item*96 ld b,16*7 menuinvloop: ld a,(hl) cpl ld (hl),a inc hl dnz menuinvloop ld b,c ;pop b ret ;a=-1 menudown: cal menupos inc b jr menuupdown menuup: cal menupos dec b menuupdown: ld a,b cp 6 jr nz,menunewchk xor a ;6=0 menunewchk: inc b jr nz,menunewok ld a,5 ;-1=5 menunewok: ld b,a jr menupos ;--- change name --- ; of worm#(curworm) getwormname: ;of (curworm) ld a,(curworm) add a,a ;2x ld e,a add a,a ;4x add a,a ;8x add a,a ;16x add a,e ;18x ld e,a ld d,0 ;de=a ld ix,worm1name-18 add ix,de ret changeworms: cal getwormname psh ix pop hl ;ld hl,ix psh hl ld b,8 emptyname: ld (hl),' ' inc hl dnz emptyname ld a,maxnamelength ld (namelength),a enternameloop: ld hl,$FF07 ;begin pos ld a,6 ;nr of lines cal clroldcustom ld hl,$303E ld (_penCol),hl pop hl psh hl ld (ix),0 cal __vputs ld (ix),' ' ld a,'_' cal __vputmap nokeypressed: cal ubergetkey or a jr z,nokeypressed ld hl,namelength cp K_DEL jr nz,continue backspace: ld a,(hl) cp maxnamelength jr nc,nokeypressed inc (hl) dec ix jr enternameloop continue: cp K_ENTER jr z,nameentered cp K_EXIT jr z,nameentered dec (hl) ;(namelength) jr z,nameentered ld hl,chartable ld e,a ld d,0 add hl,de ld a,(hl) or a jr z,nokeypressed ld (ix),a inc ix cal releasekeys jr enternameloop chartable: .db 0,".<>!",0,0,0,0 ;down,L,R,up .db 0,"XTOJE0",0 ;enter..clear .db " WSNID9",0 ;(-)..custom .db "ZVRMHC8",0 ;dot..del .db "YUQLGB7#" ;0..xvar .db $D9,"-PKFA6'" ;on..alpha .db "54321*",0,$D0 ;F5..more nameentered: pop ix ;stringbegin ld (ix+8),0 ;end mark jp DisplayMenu ;----------------------------- ;------- procs-n-stuff ------- ;----------------------------- ubergetkey: halt ;woo hoo halt ;save them batteries! yeah! jp GET_KEY clrold: ld hl,$FD97 ;begin pos ld a,35 ;nr of lines clroldcustom: ld de,7 ;bytes to add clroldsettings: ld c,9 ;bytes to clear clroldsetsloop: ld (hl),d ;=0 inc hl dec c jr nz,clroldsetsloop add hl,de dec a jr nz,clroldsettings ret hlatlevel: ;d must be 0 psh hl ;loadgamecar ld a,(Gametype) ;8bytes -> 7bytes ld e,a add a,a ;nc add a,e add a,a ;8->2bytes add a,24+1 ;go to datalevels ld e,a ;=de sbc hl,de ;datalevels cal _ldHLind ;ld hl,(hl) pop de ;de=loadgamecar inc de \ inc de ld a,(de) ;(curlevel) ld (Level),a ld d,a ;begin level skiplevelloop: dec d ;levels to skip ret z cal skiplevel jr skiplevelloop ret ;hl=begin of correct level skiplvltitle: ;zf=singleplayer ld a,(hl) or a ;null-terminator inc hl jr nz,skiplvltitle ret skiplevel: ;@hl - destr:ab - alter:hl ld a,(Gametype) or a ;gamesingle psh af cal nz,skiplvltitle inc hl inc hl inc hl inc hl ;skip 4 ld b,(hl) ;spritesize inc b skipsprite: inc hl dnz skipsprite ld b,(hl) ;balls inc b inc b ;skip 6 pop af ;cp (Gametype),0 jr z,skipworms inc b ;multiplayer lvl inc b inc b ;skip other 3 worms (9 bytes) skipworms: ld a,b add a,a add a,b ld b,a ;3x(balls+2) skipballs: inc hl dnz skipballs skipflags: ld a,(Gametype) cp gamerace jr z,skiplaps cp gamectf jr nz,noflagstoskip inc hl inc hl skiplaps: inc hl inc hl noflagstoskip: skipobjects: xor a or (hl) inc hl ;nf ret z ;0=end inc hl inc hl inc hl inc hl jr skipobjects loadgamecar: ;in: (Gametype) ;out: hl=dataTYPE ;build: c=(gameCar)=(hl-1) ; a=(wormbeglives)=(hl) ;destr: acdehl ld hl,datasingle ld a,(Gametype) add a,a add a,a add a,a ;8 bytes per mode ld e,a ld d,0 add hl,de ld a,(hl) ld (gameCar),a ld c,a inc hl ld a,(hl) ld (wormbeglives),a ret ;----------------------------- ;-------- start game --------- ;----------------------------- LetsGetThisPartyOn: ld a,$17 ;no exit ld (CheckExit),a ;set exit state setupworms: ld hl,worm1set ld de,worm1 ld a,4 ;4x (all worms) createwormsloop: ex de,hl ld bc,died ;0008 add hl,bc ; ld b,0 ld (hl),b ;died=0 inc hl ld (hl),b ;score=0 inc hl ld (hl),b ;score+1=0 inc hl ld (hl),2 ;delay=2 inc hl ld (hl),3 ;lives=x wormbeglives =$-1 inc hl ex de,hl ;de=wormX+head ld bc,18 ldir ;copy 18 bytes dec a ;loop jr nz,createwormsloop OhMyGodItsALabel: ;pj34r my coding skillz cal loadgamecar psh hl ;datatype cal hlatlevel ex (sp),hl ;pop \ psh leveldata psh hl ;psh loadgamecar ld a,0 gameCar =$-1 rra ;and _datalink jp nc,StartLevel ;&&&jr ;--------- link ------------ wormVhost = 095 wormVclient = 195 linkmatch: cal _clrWindow ld c,wormVhost cal Qsend ld hl,txtWaiting cal _puts cal Crecv ld a,c cp wormVclient jr z,client cp wormVhost jr z,host pop hl ;error jp DisplayMenu ;return to menu host: ld c,wormVclient cal Qsend jr sethost client: ld hl,txtReceive cal _puts setclient: ;name/keys: wormy#1 = link = 0 + link (name1) ; 2 = worm #1 = #1 + local(name1) ; 3 = link = 0 + link (name2) ; 4 = worm #2 = #2 + local(name2) ld de,worm2+left ld hl,worm1+left ldi ;keys worm#2 = worm#1 ldi ;+right ld de,worm4+left ldi ;keys worm#4 = worm#2 ldi xor a ld (worm1+left),a ;worm 1... ld (worm3+left),a ;and worm 3 via link ld hl,worm1+name ld b,9 cal recvstuff ld hl,worm2+name ld b,9 cal sendstuff pop hl ;loadgamecar pop de ;leveldata psh de psh hl ;loadgamecar ld b,8 cal sendstuff ld hl,gameCar ld b,1 cal sendstuff ld hl,Gametype ld b,1 cal sendstuff ex de,hl ld b,168 cal sendstuff jr StartLevel sendstuff: psh de sendstuffloop: psh bc ld c,(hl) inc hl cal Qsend pop bc dnz sendstuffloop pop de ret recvstuff: psh de recvstuffloop: psh bc cal Qrecv ld (hl),c inc hl pop bc dnz recvstuffloop pop de ret sethost: ;name/keys: wormy#1 = worm #1 = ok ; 2 = link = 0 + link (name1) ; 3 = worm #2 = #2 + local(name2) ; 4 = link = 0 + link (name2) ld de,worm3+left ld hl,worm2+left ldi ;keys worm#3 = worm#2 ldi ;+right xor a ld (worm2+left),a ;worm 2+4.. ld (worm4+left),a ;..over link ld hl,worm1+name ld b,9 cal sendstuff ld hl,worm2+name ld b,9 cal recvstuff pop hl ;loadgamecar pop de ;leveldata ld hl,templevels ;&&&&&&& ld de,datalink psh de psh hl ;loadgamecar ld b,8 cal recvstuff ld hl,gameCar ld b,1 cal recvstuff ld hl,Gametype ld b,1 cal recvstuff ex de,hl ld b,168 cal recvstuff ;-------- load level --------- StartLevel: pop hl ;loadgamecar ld a,(hl) ld (wormbeglives),a inc hl ;nrworms ld a,(hl) ld (nrworms),a inc hl ;level inc hl ld a,(hl) ld (customspeed),a inc hl ld a,(hl) ld (growspeed),a inc hl ld a,(hl) ld (turnleft),a ld (turnright),a ;more efficient inc hl ld l,(hl) ld h,0 cal _HLTIMES10 ;hl=10*(hl) ld (scorelimit),hl Nextlevel: cal _clrWindow pop hl ;begin of current level ld a,(hl) inc a ;=255? jp nz,donextlevel psh hl ld hl,Level dec (hl) ;curlevel-- (not beyond last lvl) cal releasekeys pop hl ;show end msg or smtn ld bc,Exit psh bc ;where to go afterwards inc hl ;location of ending-code jp (hl) ;go there ("call") donextlevel: ld a,(Gametype) or a ;gamesingle psh af cal nz,skiplvltitle ld de,Left ldi ld de,Speed ld a,0 customspeed =$-1 inc a ;$FF=def jr nz,setspeed ld a,(hl) ;speed from level inc a setspeed: dec a ld (de),a ;custom speed inc hl ld de,peagrowth ldi ld a,(hl) ld (worm1+grow),a ld (worm2+grow),a ld (worm3+grow),a ld (worm4+grow),a ld (beginsize),a inc hl ld a,(hl) inc hl or a jr z,defaultsprite ld d,h ld e,l ;ld de,hl ld c,a ld b,0 ;bc=sprite size add hl,bc ;hl=behind sprite jr setsprite defaultsprite: ld a,defspritesz defsprsize =$-1 defsprite =$+1 ld de,defspriteimg setsprite: ;de=@sprite ;a=sprsize ld (sprsize),a ld (spritepos),de ld a,(hl) inc hl ld (nrballs),a or a jr z,toobad_noballs ld c,a add a,a add a,c ld c,a ld b,0 ld de,balls ldir toobad_noballs: ex de,hl #ifndef invincible ld (thislevel),de #endif ld hl,worm1 pop af ;cp (Gametype),0 ld b,1 jr z,worminit ld b,4 worminit: psh bc ;>1 ex de,hl ldi ;d ld a,SinCosTable/256 ld (de),a inc de ldi ;y ldi ;x ex de,hl xor a ld (hl),a ;y2 inc hl ld (hl),a ;x2 inc hl inc hl ld (hl),a ;growH=0 ld bc,(worm2-worm1)-7 add hl,bc pop bc ;<0 dnz worminit inc a ;ld a,1 ld (turn10),a inc a ;ld a,2 ld (flashtime),a ;-------- draw level --------- initlevel: ld a,(de) inc de sub 128 jr nc,setfieldx xor a ;fieldx<128 setfieldx: ld (FieldWidth),a ld a,(de) inc de ld l,a sub 57 jr nc,setfieldy xor a ;fieldy<57 setfieldy: ld (FieldHeight),a psh de ; >> levelp ld a,l ;pop sub 5 ld l,a ld h,0 add hl,hl add hl,hl add hl,hl add hl,hl add hl,hl ;32=scr.width ex de,hl ld hl,ScrBuffer psh hl ; >> 1 psh de ; >> 2 ld de,ScrBuffer+1 ld bc,63 ;first 2 rows ld (hl),%11111111 ldir ;draw upper border inc hl ld (hl),%11000000 ;first left border inc hl ld b,31 ClearLine: ld (hl),c ;=0 inc hl ;clear rest of line dnz ClearLine psh hl ; >> 3 ld a,(FieldWidth) add a,126 psh af ; >> 4 and %11111000 rra rra rra ld l,a ld h,c ;0 add hl,de pop af ; << 3 and %00000111 ld b,a ; ld c,0 ld a,%11000000 jr z,NoVertShift VertShift: rra rr c dnz VertShift NoVertShift: ld (hl),a inc hl ld (hl),c ex de,hl pop de ; << 2 pop bc ; << 1 ldir pop hl ; << 0k ld c,64 ldir pop hl ; << levelp ld a,(Gametype) cp gamerace ;or gamectf jr c,levelhasbeensetup ld de,peaspos ld c,2 ;ld bc,2 (2 bytes) jr z,loadextralevelstuff ;cp gamerace ld c,4 ;ld bc,4 (2nd flag in ctf) loadextralevelstuff: ldir ld a,1 ;draw delay ld (drawctfpea1),a ld (drawctfpea2),a levelhasbeensetup: cal drawstuff ;--------- prepare ----------- leveldone: psh hl ; >> levelp new cal forceshowstats #ifdef readymask ld hl,$FC70 ld d,%10101010 ld c,56 maskloop: ld a,d xor %11111111 ld d,a ld b,$10 maskline: ld a,(hl) or d ld (hl),a inc hl dnz maskline dec c jr nz,maskloop #endif #ifdef readytext ld hl,$FDE0 ld de,$FDE1 ld (hl),%11111111 ld bc,$BF ldir ld hl,4+(txtposReady*256) ld (_curRow),hl set 3,(iy+5) ld hl,txtReady cal _puts res 3,(iy+5) #endif ld a,(gameCar) and _datafood jr z,nofood ld ix,worm1 cal NewPea nofood: ld bc,(worm1+pos) cal DisplayField ld b,startdelay ReadyDelay: halt dnz ReadyDelay cal releasekeys ;----------------------------- ;----------- LOOP ------------ ;----------------------------- GameLoop: ld bc,(worm1+pos) ;camera worm #1 ld a,(worm1+left) or a ;if #1 not over link jr nz,showfield ld bc,(worm2+pos) ;otherwise view from #2 showfield: cal DisplayField ;display piece of level ld a,1 flashtime =$-1 dec a jr z,noflash ld (flashtime),a ld hl,$fc00+(16*7) screeninvertloop: ld a,(hl) cpl ld (hl),a inc hl xor a cp h ;end at >$FFFF jr nz,screeninvertloop noflash: ld a,0 Speed =$-1 or a jr z,NoDelay Delay: halt dec a jr nz,Delay NoDelay: ld (handledworm),a ;reset ld hl,turn ld a,(hl) inc a ;-1 jr z,nextturnok dec (hl) dec a ;0 (now <0) jr nz,nextturnok growspeed =$+1 ld (hl),$FF nextturnok: ld a,(gameCar) and _datatime jr z,nodispupdate ld hl,turn10 dec (hl) jr nz,nodispupdate ;just once every 10 turns ld (hl),10 ;reset counter cal forceshowstats ;update score nodispupdate: ld a,(Gametype) cp gamectf jr nz,noctfpeas2draw ld de,drawctfpea1 ld hl,(peaspos) cal tryDrawPea ;pea#1 ld de,drawctfpea2 ld hl,(peaspos+2) cal tryDrawPea ;pea#2 noctfpeas2draw: ld a,0 nrballs =$-1 or a cal nz,handlethoseneatlittleballs ld ix,worm1 ld a,1 nrworms =$-1 ld b,a handleworms: psh bc cal HandleWorm ld bc,worm2-worm1 add ix,bc pop bc ld hl,handledworm inc (hl) ;0..nrworms-1 dnz handleworms ;----------------------------- ;---------- keys ------------- ;----------------------------- HandleKeys: ld a,%10111111 out (1),a in a,(1) rla ;MORE? jr nc,disppausemenu CheckExit: rla ;=$17 (c=EXIT-key) ;or$A7 (c=0) jp c,GameLoop jp Exit ;jr? ;------- pause menu ------- disppausemenu: ld hl,txtpMenu ld ix,pospMenu ;Resume|Turn Off|Contrast|Exit|| ld b,25*16/4 cal dispmenucommon ld hl,$FC00+$170 ;(*,23) cal hr ld hl,$FC00+$310 ;(*,49) cal hr cal menupos pauseMenu: psh bc pmenuwaitkey: cal ubergetkey or a jr z,pmenuwaitkey pop bc ;GET_KEY ld d,b ;c=new b cp K_UP jr nz,pmenunotup dec d pmenunotup: cp K_DOWN jr nz,pmenunotdown inc d pmenunotdown: psh af cal menupos ld a,d ;new pos and 3 ;0-3 ld b,a cal menupos pop af cp K_ENTER jr z,pselect cp K_SECOND jr nz,notpselect pselect: ld a,b or a ;1: continue jr z,donepausing dec a ;2: off jr z,turnoff dec a ;3: contrast jr z,pauseMenu jr Exit ;4: exit notpselect cp K_EXIT jr z,donepausing ld hl,CONTRAST sub K_LEFT jr z,contrastdown dec a ;K_RIGHT jr nz,pauseMenu contrastup: inc (hl) jr setcontrast contrastdown: dec (hl) setcontrast: ld a,(hl) out (2),a jr pauseMenu turnoff: ld bc,$0103 out (c),b halt ;pause/off ld b,11 out (c),b ld b,1 jr pauseMenu donepausing: cal releasekeys jp GameLoop Exit: cal releasekeys ld sp,0 ;pop all SpSave = $-2 ld a,D0LD1L out (7),a ;both wires low = game over signal cal _clrWindow #ifdef coolzgfx ld de,$FC30 ;(0,1) ld hl,wtWormy ld bc,16*7 ldir ld hl,$FC10 ld b,16*11 cal menuinvloop ;invert ld hl,$FD80 cal hr ;menuinvloop w/ b=16 ld hl,$FCE0 cal hr ld hl,_curRow ld (hl),2 #else ld hl,txtGO cal _puts ld hl,$FC00 ld b,16*8 cal menuinvloop ;invert inc h ;$FD80 cal hr ;menuinvloop w/ b=16 ld hl,$FCE0 cal hr ld hl,_curRow inc (hl) #endif ld hl,txtGame CURtxtGame =$-2 cal _puts ld a,$0D ;$0D02 ld (_curCol),a cal showLevel ld de,$1901 ld (_penCol),de ld hl,txtName cal _vputs ;Name ld a,$3D ld (_penCol),a cal _vputs ;Died Score ld de,$0004 ld (_curRow),de findwinner: ld hl,(worm1+score) ld (winnerscore),hl ld b,3 ;(nrworms)-1 ld hl,worm2+score findwinnerloop: psh hl cal _ldHLind ld de,(winnerscore) ld a,h cp d jr c,nonewwinner ;hd ld a,e cp l jr nc,nonewwinner ;l$FB) ld hl,worm1+died finddmwinner: cp (hl) jr c,nonewdmwinner ld a,(hl) ;less deaths nonewdmwinner: ld de,worm2-worm1 add hl,de dnz finddmwinner ld (dmwinner),a ;---display worms--- ld a,(nrworms) ld b,a ld hl,worm1+died displayWormStats: psh bc psh hl ld bc,left-died add hl,bc ;+left xor a cp (hl) ;input=0 = link jr nz,NoLinkIndic ld a,9 ld (_curCol),a ld a,$DC ;-O cal _putc xor a ld (_curCol),a NoLinkIndic: inc hl inc hl ;+name cal _puts pop hl psh hl ld a,13 ld (_curCol),a ld a,(hl) ;worm+died cal showA0 pop hl psh hl ld a,(Gametype) cp gamedeathm jr nz,nodmwinner ;deathmatch? ld a,0 ;winner's deaths dmwinner =$-1 cp (hl) ;equals this worm? scf ;jr nz,notwinner cal z,iswinner nodmwinner: jr c,notwinner ;no singleplayer winners inc hl ;worm+score cal _ldHLind ;ld hl,(hl) ld de,0 winnerscore =$-2 cal _cphlde ;==highest score.. cal z,iswinner notwinner: ld a,16 ld (_curCol),a pop hl psh hl inc hl ;worm+score cal _ldHLind cal showHL pop hl ld bc,worm2-worm1 add hl,bc pop bc dnz displayWormStats ld a,(Gametype) or a ;singleplayer (0) only jr nz,hilevelcheckdone checkhilevel: ld hl,nrlevels ld a,(Level) cp (hl) jr c,hilevelcheckdone ld (hl),a ;save local ld c,a ld a,0 hilvlposa =$-1 ld hl,nrlevels hilvlposhl =$-2 ;save external cal _writeb_inc_ahl ;ld (ahl),c hilevelcheckdone: ld a,(gameCar) and _datasingl jr z,hiscorecheckdone ;no SP checkhiscore: cal loadhiscoreposinahl cal _SET_ABS_SRC_ADDR ;from ahl (lvlfile) xor a ld hl,highsave cal _SET_ABS_DEST_ADDR ;to local ld hl,5 ;5 bytes cal _MM_LDIR_SET_SIZE ;get old score+name cal _RAM_PAGE_1 ld de,(highsave) ;de=prev. hiscore ld hl,(worm1+score) ;hl=worm1's score cal _cphlde ;sub hl,de jr c,NotNewHigh ;newOld ld (highsave),hl ;store new hiscore ld de,highsave+2 ;to ld hl,worm1+name ;from ld bc,3 ;3 chars ldir ;store new hiname cal loadhiscoreposinahl cal _SET_ABS_DEST_ADDR ;to ahl xor a ld hl,highsave cal _SET_ABS_SRC_ADDR ;from local ld hl,5 cal _MM_LDIR_SET_SIZE ;save new cal _RAM_PAGE_1 ld hl,_curRow dec (hl) cal iswinner NotNewHigh: ld hl,$3149 ld (_penCol),hl ld hl,txthiscore cal _vputs ld hl,$0C07 ld (_curRow),hl ld hl,highsave+2 cal _puts ld hl,(highsave) cal showHL hiscorecheckdone: waitkey: cal ubergetkey cp K_ENTER jp z,DisplayMenu cp K_SECOND jp z,DisplayMenu cp K_EXIT jr nz,waitkey ;x123456789012345678901 ;>>>>>> GAME OVER <<<<< ;2Multiplayer ;3Level 01 ;4 Died Score: ;5NameName 03 00070 ;6Worm#02 @ 05 00120 ;7Worm#03 15 00030 ;8Snaky @ 00 04820 ExitNoStats: cal linkok ld hl,_asapvar rst 20h ;_ABS_MOV10TOOP1 rst 10h ;_FINDSYM ld hl,savestart-_asm_exec_ram+4 xor a add hl,de adc a,b ;ahl=bde+4 cal _SET_ABS_DEST_ADDR xor a ld hl,savestart cal _SET_ABS_SRC_ADDR ld hl,saveend-savestart cal _MM_LDIR_SET_SIZE cal releasekeys res 4,(iy+9) set 2,(iy+13) im 1 ;remove keyfix jp _clrWindow loadhiscoreposinahl: ld hl,0 ;for peaworm and singleplayer ld a,(Gametype) or a ;Singleplayer? jr z,hi__ dec a ;peaworm? jr z,hi_ ld a,(nrlevels+1) ;skip peaworm slots if tron mode hi_: ld bc,(Level) add a,c ld b,a ;levels to skip (including 1 for singleplayer) ld de,5 ;to add per level addlevelposition: add hl,de ;one word+3 bytes for name dnz addlevelposition hi__: xor a ;ahl=0(+hl) ld bc,defhiscrpos hiscrposhl =$-2 add hl,bc hiscrposa =$+1 adc a,0 ;ahl=saveloc ret highsave: .db 0,0,"WOR ",0 iswinner: ld a,10 ld (_curCol),a ld a,'*' jp _putc ;..then put * ;----------------------------- ;----------- worm ------------ ;----------------------------- respawncheck: cp respawndelay-1 jr nz,unnamedlabel cal saverespawncounter removeworm: ld h,(ix+tail+1) ;& ld l,(ix+tail) ld d,(ix+head+1) ld e,(ix+head) jr DoesWormTailEqualsWormHead ;chk4 size=0 removewormloop: ld c,(hl) inc hl ld b,(hl) inc hl cal resbit psh hl cal res4pixels pop hl inc (ix+grow) jr nz,DoesWormTailEqualsWormHead inc (ix+grow+1) ;+256 DoesWormTailEqualsWormHead: cal _cphlde jr nz,removewormloop ld a,(gameCar) and _datasingl jr nz,safewormsizedone ld a,0 beginsize =$-1 ld (ix+grow),a ld (ix+grow+1),0 ;high safewormsizedone: ;de=ix+head ld (ix+tail+1),d ld (ix+tail),e ;head=tail/size=0 ret unnamedlabel: cp 1 ld h,a jr nz,saverespawncounter respawndue: ld l,a cal inputcall ld a,h ;previous cp l ;changed? ret z ld (ix+delay),a ;=0 ret saverespawncounter: ld (ix+delay),a jr inputcall chkkey: ;key=a dec a ld b,a srl b srl b srl b ;b=a/8 and 7 ;a=a\8 ld c,a ;push keybit ld a,-1 out (1),a inc b ld a,%01111111 ;default bitmask: rlca ;rotate left dnz bitmask ;a/8 times out (1),a ;send bitmask in a,(1) ;input keys ld b,c ;pop keybit inc b keybit: rra dnz keybit ;check match (cf set) ret inkeys: ;use jp not call! cal chkkey jr nc,notright ld a,l add a,8 turnright =$-1 ld l,a notright: ld a,(ix+right) cal chkkey ret nc ld a,l sub 8 turnleft =$-1 ld l,a ret inputcall: ld a,(ix+left) or a jr z,inlink ;input by link cal inkeys ;input by keys ld a,(gameCar) rra ;and _datalink ret nc ;no link ld c,l ;send our keys jp Qsend inlink: cal Qrecv ;Crecv ld l,c ret ;----------------------------- ;------- handle worm --------- ;----------------------------- HandleWorm: xor a cp (ix+lives) jr nz,alive ld a,(wormbeglives) or a ret nz ;live limit alive: ld a,(ix+delay) dec a jp nz,respawncheck xor a cp 0 turn =$-1 jr nz,nogrow inc (ix+grow) nogrow: ld a,(gameCar) and _datatime jr z,notimescore ld e,1 cal IncScore notimescore: ld l,(ix+heading) cal inputcall donediddelydone: ld (ix+heading),l ld h,(ix+heading+1) ld c,(ix+pos) ld b,(ix+pos+1) ld e,(ix+pos2) ld d,(ix+pos2+1) #ifdef optdie psh hl ld hl,previouspos ld (hl),c inc hl ld (hl),b inc hl inc hl ld (hl),e inc hl ld (hl),d pop hl #endif ;-------- move worm ---------- Wormmove: psh bc ; >> pos ld a,(hl) add a,a add a,d ld d,a bit 7,(hl) jr z,notnegX dec b notnegX: jr nc,notmoveX inc b notmoveX: ld a,l add a,$40 ld l,a ld a,(hl) add a,a add a,e ld e,a bit 7,(hl) jr z,notnegY dec c notnegY: jr nc,notmoveY inc c notmoveY: ;bc=newpos ld (ix+pos2),e ld (ix+pos2+1),d ld (ix+pos),c ld (ix+pos+1),b ;-check- pop hl ; << pos (old) ld a,h sub b and 1 ld h,a ld a,l sub c and 1 add a,h ld d,4 jr z,GotFour xor 3 ld d,a GotFour: cal chk4pixels rl d jp nc,Drawworm ;--------- worm hit ---------- Hitworm: ld a,(gameCar) ld h,a #ifdef optdie and _datadie cal z,checkhitotherworm ld a,h #endif and _datamultpeas ;&&bit jr nz,chkctfpeas ld a,h and _datafood jp z,WormDead ;no food ld hl,0 PeaY =$-2 PeaX =$-1 cal chkpeahit jp nc,WormDead cal DrawPea ;remove pea ld a,(ix+grow) add a,15 peagrowth =$-1 ld (ix+grow),a jr nc,wormset2grow inc (ix+grow+1) wormset2grow: cal NewPea ld hl,Left dec (hl) psh af ld e,10 cal IncScore pop af jp nz,Drawworm ;continue ld a,(gameCar) and _datafoodl jp z,Drawworm ld a,(Gametype) or a jp nz,Exit ;stack restored ld hl,Level ld a,(hl) inc (hl) ld l,a ;hl=Level ld h,0 add hl,hl add hl,hl cal _HLTIMES10 ex de,hl cal _IncScore ;score+(40*level) cal removeworm pop hl ; << call pop hl ; << call ld (ix+delay),2 jp Nextlevel chkpeahit: ;bc=ownpos;hl=peapos (destr:ad) ld a,(sprsize) inc a ld d,a ld a,b sub h inc a cp d ;=(sprsize)+1 ret nc ;nc=no pea ld a,c sub l inc a cp d ret ;c=pea chkctfpeas: ld hl,(peaspos) ;1st pea ld a,(ix+reserv) ld e,a ;push a and %01 ;ourpea (0|1) jr z,sel_otherpea ld hl,(peaspos+2) ;2nd pea ;&&&ex de,hl? sel_otherpea: cal chkpeahit jr c,hitflag ;no peas hit: ld a,e ;peek a (that's x86asm for pop\push ;) bit 1,a ;%10 = carrying flag? jp z,WormDead ;if not just die xor %11 ;drop flag ld (ix+reserv),a psh af cal WormDead pop af ;which flag? (=and %1) ld hl,drawctfpea1 ;restore #1 jr z,nottheotherflag ld hl,drawctfpea2 ;restore #2 nottheotherflag: ld (hl),3 ;draw delay 3 turns ret drawctfpea1: .db 0 drawctfpea2: .db 0 hitflag: ;correct pea hit ld a,e ;pop a xor %11 ;invert flag taken + ownflag ld (ix+reserv),a and %10 ;just returned? psh af ;safe z-flag cal DrawPea ;remove pop af jr nz,Drawworm ;flag taken, continue game psh hl ld e,20 ;flag captured+returned cal IncScore pop hl ld a,3 ;draw delay ld (drawctfpea1),a ;redraw.. ld (drawctfpea2),a ;..both flags jr Drawworm ;----------------------------- nextotherwormbit: ld a,c sub (hl) inc hl inc a cp 4 jr nc,nothit1 ;no ld a,b sub (hl) inc a cp 4 ret c ;nz ;yes nothit1: inc hl cal resbit ChkWorm: cal _cphlde jr nz,nextotherwormbit ret ;z checkhitlapline: ld a,(peaspos) ;63 sub b ;x==63 jr z,nextlaphalf inc a ret nz nextlaphalf: ld a,(peaspos+1) ;yline cp c ;ypos ld a,1 jr nc,checklap ;y>yline -> a=1 xor a ;y a=0 checklap: cp (ix+reserv) ret z ;same as before ld (ix+reserv),a ;1st time ld e,a ld a,(handledworm) and 1 ;group 0 (1,3) or 1 (2,4) xor e ret z ;(group 0 and yyline) psh bc ld e,20 cal IncScore ;lap! pop bc ret ;-------- draw worm ---------- Drawworm: ld c,(ix+pos) ld b,(ix+pos+1) ld a,(Gametype) cp gamerace cal z,checkhitlapline cal set4pixels dec c ld a,(growspeed) or a ;0=tron ret z ;keep tail in "Tron" ld l,(ix+head) ld h,(ix+head+1) ld (hl),c inc hl ld (hl),b inc hl cal resbit ld (ix+head),l ld (ix+head+1),h ld l,(ix+grow) ld h,(ix+grow+1) dec hl ld a,h or l jr z,removetail ld (ix+grow),l ld (ix+grow+1),h ret removetail: ld l,(ix+tail) ld h,(ix+tail+1) ld c,(hl) inc hl ld b,(hl) inc hl cal resbit ld (ix+tail),l ld (ix+tail+1),h psh hl cal res4pixels pop hl ld c,(hl) inc hl ld b,(hl) jr set4pixels res4pixels: cal ResPixel inc b cal ResPixel inc c cal ResPixel dec b ResPixel: cal FindPixel cpl and (hl) ld (hl),a ret ;----------------------------- ;---------- ball ------------- ;----------------------------- handlethoseneatlittleballs: ld hl,balls ld b,a ;a=(nrballs) handleballs psh bc psh hl ld c,(hl) inc hl ld b,(hl) inc hl ld d,(hl) cal handleball dec c pop hl ld (hl),c inc hl ld (hl),b inc hl ld (hl),d inc hl pop bc dnz handleballs ret handleball: cal res4pixels dec c ballxmove: bit 0,d ;1=L; 0=R jr z,ballright ballleft: dec b cal checkballhit jr z,ballymove inc b ;undo res 0,d ;go right jr ballymove ballright: inc b cal checkballhit jr z,ballymove dec b ;back set 0,d ;>left ballymove: bit 1,d ;1=up; 0=down jr z,balldown ballup: dec c cal checkballhit jr z,balldone inc c res 1,d ;go down jr balldone balldown: inc c cal checkballhit jr z,balldone dec c set 1,d ;up balldone: set4pixels: ;@(b,c) cal SetPixel inc b cal SetPixel inc c cal SetPixel dec b SetPixel: ;at bc cal FindPixel or (hl) ld (hl),a ret letsmovetheotherway: ld a,1 xor (hl) ld (hl),a ret checkballhit: psh de ld d,0 cal chk4pixels xor a cp d pop de ret ;----------------------------- ;----------- procs ----------- ;----------------------------- releasekeys: halt ld a,%10000000 ;all key-masks out (1),a in a,(1) inc a ;cp %11111111 (no keys pressed) jr nz,releasekeys ;keep waitin cal GET_KEY ;clear buffer ret resbit: ld a,h and (ix+storepos) ld h,a ret randompos: ld b,a Random: ;(2..b+2) ld a,r Seed =$+1 add a,0 ld (Seed),a and %01111110 cp b jr nc,Random add a,2 ret WormDead: #ifdef invincible jp stopworm #endif ld a,2 ld (flashtime),a ld (ix+delay),respawndelay thislevel =$+1 ld hl,0 ld de,0 handledworm =$-2 add hl,de add hl,de add hl,de ld a,(hl) inc hl ld (ix+heading),a ld a,(hl) ld (ix+pos),a ;y inc hl ld a,(hl) ld (ix+pos+1),a ;x xor a ld (ix+pos2),a ;y2 ld (ix+pos2+1),a ;x2 inc (ix+died) dec (ix+lives) psh af ld de,10 ld a,(Gametype) cp gamectf ;ctf no death penalty cal nz,DecScore pop af ret nz ;HandleWorm done ld a,(wormbeglives) or a ;0=no live limit ret z ;don't end game ld a,(gameCar) and _datatime jr z,anyworm ;quit at any worm's death ld a,(nrworms) ;timematch: all worms must've died ld b,a ;# of worms ld hl,worm1+lives-(worm2-worm1) ld de,worm2-worm1 xor a ;check for 0 lives checklives: add hl,de ;next worm cp (hl) ;lives==0? ret nz ;any >0: don't exit dnz checklives anyworm: ld a,$A7 ;exit@end of turn ld (CheckExit),a ;set exit state ret ;finish turn #ifdef optdie checkhitotherworm: .db $dd,$7d ;ld a,lx cp worm2&255 psh ix jr nz,chkworm2 ; ret nz ld ix,worm1 jr chkworm chkworm2: ld ix,worm2 chkworm: ld h,(ix+tail+1) ld l,(ix+tail) ld e,(ix+head) ld d,(ix+head+1) cal ChkWorm pop ix ret z ;not hit pop bc ;call stopworm: ld bc,0 previouspos =$-2 ld de,0 ld (ix+pos),c ld (ix+pos+1),b ld (ix+pos2),e ld (ix+pos2+1),d ret #endif CheckPea: ;@hl; destr:abcde ld c,l ld a,(sprsize) ld e,a chkloopy: ld b,h ld a,(sprsize) ld d,a chkloopx: psh hl cal FindPixel and (hl) pop hl ret nz ;nz=pixel found inc b dec d jr nz,chkloopx inc c dec e jr nz,chkloopy ret ;z=empty space tryDrawPea: ;hl=peapos;bc=dopea ld a,(de) or a ;0=drawn ret z psh de cal CheckPea pop de ret nz ;unsuccesful ex de,hl dec (hl) ;hl=appeartime ex de,hl ;hl=peaspos jr z,DrawPea ret NewPea: ld a,(FieldWidth) add a,127-4 cal randompos ld h,a ld a,(FieldHeight) add a,56-4 cal randompos ld l,a cal CheckPea jr nz,NewPea cal sendnewpeaoverlink ld (PeaY),hl DrawPea: ;hl=(PeaY) ld b,h ld c,l ld de,0 spritepos =$-2 ; jp PutSprite PutSprite: ;||@(b,c) ;by SHIAR only ix saved cal FindPixel ld (beginbit),a ld a,0 sprsize =$-1 ld b,a ;rows sprloopy: psh bc ;rows psh hl ld a,(de) ld c,a inc de ld a,(sprsize) ld b,a ;width beginbit =$+1 ld a,1 sprloopx: sla c ;draw? jr nc,sprnodraw psh af xor (hl) ld (hl),a pop af sprnodraw: rrca ;next bit jp nc,nextbitok inc hl ;next byte nextbitok: dnz sprloopx pop hl ld bc,32 ;next line add hl,bc pop bc dnz sprloopy ret ;----------- score ----------- timematchscore: ;piece of crap checking whether you've already won in timematch ld a,(nrworms) ld b,a ;# of worms dec a ret z ;singleplayer ld hl,worm1+lives ld de,worm2-worm1 ld a,(handledworm) ld c,a ;wormcounter chktimematchover: xor a cp c jr z,nneexxtt ;yourself cp (hl) ret nz ;someone else still alive dec hl ;+del0ay dec hl ;+score+1 ld a,(hl) cp (ix+score+1) jr c,nneexxtt_ ;you>him ret nz ;not highest dec hl ;+score ld a,(hl) cp (ix+score) ret nc ;you<=him inc hl nneexxtt_: inc hl inc hl nneexxtt: dec c add hl,de dnz chktimematchover jp anyworm ;g/o _divHLby1000: psh hl ld b,3 divideagain: ;3x cal _divHLby10 dnz divideagain ld a,l ;a=hl/1000 pop hl ret extralives: cal _divHLby1000 ld c,a add hl,de ;increase score cal _divHLby1000 cp c jr z,scorecommon ;hl/1000 not increased inc (ix+lives) jr scorecommon DecScore: ;&&& ld h,(ix+score+1) ld l,(ix+score) or a sbc hl,de jr c,showstats ;<0=0 jr scorecommon IncScore: ;inc score by e ld d,0 _IncScore ; inc by de ld h,(ix+score+1) ld l,(ix+score) ld a,(Gametype) or a ;if singleplayer... jr z,extralives add hl,de ;score+=de scorecommon: ld (ix+score+1),h ld (ix+score),l ;save ld de,0 scorelimit =$-2 ld a,d or e jr z,showstats ;de=0=no limit cal _cphlde jp nc,Exit showstats: ld a,(gameCar) and _datatime jr nz,timematchscore ;no disp for timematches ld hl,$FC00 ;&&&only necessary in deathmatch ld b,6*16-1 clearstats: ld (hl),a ;=0 inc hl dnz clearstats forceshowstats: psh ix ld h,0 ld l,h ld (_penCol),hl ld a,(nrworms) ld b,a ld ix,worm1 ld a,(gameCar) and _datasingl jr nz,showstatsS showstatloop: psh bc #ifdef longnames ld b,3 psh ix shownameloop: ;1st 3 chars ld a,(ix+name) or a jr z,nameshown cal __vputmap inc ix dnz shownameloop nameshown: ld a,':' cal _vputmap pop ix #else ld a,(ix+name) cal __vputmap ld a,':' cal __vputmap #endif cal showstat ld de,worm2-worm1 add ix,de ;next ld hl,_penCol ld a,(hl) add a,4 ;div ld (hl),a pop bc dnz showstatloop pop ix ret showstat: ;(multiplayer) ld a,(Gametype) cp gamedeathm jr z,showlives showscore: ld h,(ix+score+1) ld l,(ix+score) cal _D_HL_DECI jr __vputs showlives: ld a,(ix+lives) showA: ;small w/o leading 0 (&&&combine w/ cshowA0??) cp 10 jr c,showleastsign ld l,a ld h,0 cal _divHLby10 psh af ld a,l add a,'0' cal __vputmap pop af showleastsign: add a,'0' __vputmap: psh ix cal _vputmap pop ix ret showstatsS: ;(singleplayer) ld hl,txtLevel cal __vputs ld a,0 Level =$-1 cal showA ld a,98 ld (_penCol),a cal showscore ld a,123 ld (_penCol),a cal showlives ld a,(gameCar) and _datafoodl pop ix ret z showleft: ld a,31 ld (_penCol),a ld a,0 Left =$-1 cal cshowA0 ld hl,txtLeft __vputs: psh ix cal _vputs pop ix ret showLevel: ld hl,txtLevel cal _puts ld a,(Level) showA0: ;big w/ leading 0 ld l,a ld h,0 cal _divHLby10 psh af ld a,l add a,'0' cal _putc pop af add a,'0' jp _putc cshowA0: ;small w/ leading 0 or a jr nz,cshowavalue ld hl,txtNone jp _vputs cshowavalue: ld l,a ld h,0 cal _divHLby10 psh af ld a,l add a,'0' cal __vputmap pop af add a,'0' jp __vputmap showHL: cal _D_HL_DECI jp _puts _D_HL_DECI: ld de,savestr+4 ld b,5 ldhld: cal _divHLby10 add a,'0' ld (de),a dec de dnz ldhld ld hl,savestr ret savestr: .db "00000",0 ;----------------------------- DisplayField: ld a,c sub 29 jr nc,NotMinYScroll xor a NotMinYScroll: cp 43 FieldHeight =$-1 jr c,NotMaxYScroll ld a,(FieldHeight) NotMaxYScroll: ld l,a ld h,0 add hl,hl add hl,hl add hl,hl add hl,hl add hl,hl psh bc ; >> 1 psh de ; >> 2 ld de,ScrBuffer add hl,de ld a,b sub 64 jr nc,NotMinXScroll xor a NotMinXScroll: cp 128 FieldWidth = $-1 jr c,NotMaxXScroll ld a,(FieldWidth) NotMaxXScroll: psh af ; >> 3 and %11111000 rra rra rra ld c,a ld b,0 ld de,DispBuffer pop af ; << 2 and %00000111 psh af ; >> 3 cp 6 jr c,CopyScreen inc c CopyScreen: add hl,bc ld b,57 CopyScreenLoop: psh bc ; >> 4 ld bc,16 ldir ld c,16 add hl,bc pop bc ; << 3 dnz CopyScreenLoop pop af ; << 2 ld c,$b7 ;or a Bit0: jr nz,Bit1 halt halt jr AfterShiftDelay Bit1: dec a jr nz,Bit2 cal ShiftRight1 jr AfterShiftDelay Bit2: dec a jr nz,Bit3 ld a,2 cal ShiftRight jr AfterShiftDelay Bit3: dec a jr nz,Bit4 cal Chunk cal ShiftLeft1 jr AfterShift Bit4: dec a jr nz,Bit5 cal Chunk jr AfterShiftDelay Bit5: dec a jr nz,Bit6 cal Chunk cal ShiftRight1 jr AfterShift Bit6: dec a jr nz,Bit7 ld a,2 cal ShiftLeft jr AfterShift Bit7: cal ShiftLeft AfterShiftDelay: halt AfterShift: #ifdef buffer ld hl,DispBuffer ld de,$fc00+$70 ld bc,1024-$70 ldir #endif pop de ; << 1 pop bc ; << 0k ret ShiftRight1: ld a,1 ShiftRight: ld (ShiftRightCounter),a ld a,c ld (ShiftRightChunk),a ld c,16 add hl,bc ld b,57 ShiftRightLoop: psh bc ld bc,-32 add hl,bc ex de,hl ld a,(de) ShiftRightChunk: or a cal c,_SHLACC ld c,0 ShiftRightCounter = $-1 ShiftRowsLeft: psh hl rla ld b,16 ShiftRowLeft: dec hl rl (hl) dnz ShiftRowLeft pop hl dec c jr nz,ShiftRowsLeft ld bc,-16 add hl,bc ex de,hl pop bc dnz ShiftRightLoop ret ShiftLeft1: ld a,1 ShiftLeft: ld (ShiftLeftCounter),a ld a,c ld (ShiftLeftChunk),a rla jr nc,ShiftLeftSameByte dec hl ShiftLeftSameByte: ex de,hl ld bc,-16 add hl,bc NewSprite: ex de,hl ld b,57 ShiftLeftLoop: psh bc ; >> 1 ld bc,-32 add hl,bc ex de,hl ld a,(de) ShiftLeftChunk: or a cal c,_SHRACC ld c,0 ShiftLeftCounter = $-1 ShiftRowsRight: psh hl ; >> 2 rra ld b,16 ShiftRowRight: rr (hl) inc hl dnz ShiftRowRight pop hl ; << 1 dec c jr nz,ShiftRowsRight ld bc,-16 add hl,bc ex de,hl pop bc ; << 0k dnz ShiftLeftLoop ret Chunk: psh hl ; >> 1 psh de ; >> 2 ld c,16 add hl,bc ld b,57 ChunkScreen: psh bc ; >> 3 ld bc,-32 add hl,bc ex de,hl ld a,(de) cal _SHRACC ld b,16 ChunkRow: dec hl rld dnz ChunkRow ex de,hl pop bc ; << 2 dnz ChunkScreen pop de ; << 1 pop hl ; << 0k ld c,$37 ;scf ret ;----------- draw ------------ ;--- pixel --- chk4pixels: ;&& cal CheckPixel inc b cal CheckPixel inc c cal CheckPixel dec b cal CheckPixel dec c ret CheckPixel: ;at bc in d cal FindPixel and (hl) ret z dec d ret ;CLEM's FIND_PIXEL (131+? cycles; 28+4 bytes) ;(b,c) to hl:a; "destroyes" ahl FindPixel: ;(b,c) to hl:a ld h,0 ld l,c ;hl=y add hl,hl add hl,hl ld a,b ;a=x rra add hl,hl rra add hl,hl add hl,hl ;hl=32*y rra ;a=x/8 or l ld l,a ld a,b and 7 cpl rlca rlca rlca ld (FP_Bit),a xor a FP_Bit =$+1 set 0,a psh de ;&&& ld de,ScrBuffer add hl,de pop de ret ;--- objects --- drawstuff: ld a,(hl) inc hl or a ;0 = ret z ;no more ld d,(hl) inc hl ld e,(hl) inc hl ld b,(hl) inc hl psh hl ld l,(hl) ld h,b cal drawsmtn pop hl inc hl jr drawstuff drawsmtn: dec a ;1 = line jr z,drawline dec a ;2 = fatline jr z,drawfatline dec a ;3 = box jr z,drawbox ; dec a ;4 = circle ; jp z,drawcircle drawcircle: ;(d,e),h ;de=x,y; h=z ld c,h ;c=yy=z ld a,h neg ld l,a ;l=-z xor a ld b,a ;b=xx=0 dec a ;-$00** ld h,a ;hl=zz=-z circloop: psh de ;x,y ex (sp),hl ;push zz \ pop x,y cal circledraw ;(x-xx,y+yy)-(x+xx,y+yy) ;(x-xx,y-yy)-(x+xx,y-yy) cal circledraw ;(x-yy,y+xx)-(x+yy,y+xx) ;(x-yy,y-xx)-(x+yy,y-xx) ex (sp),hl ;push x,y \ pop zz xor a ld d,a ;d=0 dec a ;-256=yy inc b ;xx++ jr circloop circledraw: ;destr:de psh hl ld a,h ;hl=x,y sub b ;bc=xx,yy ld d,a ;d=x-xx add hl,bc ;h=x+xx; l=y+yy ld e,l ;e=y+yy cal drawline ;(h-b,l+c)-(h+b,l+c) ld a,l sub c ;a=y again sub c ld l,a ;l=y-yy ld e,l ;e=l=y-yy cal drawline ;(h-b,l-c)-(h+b,l-c) ld a,b ;swap xx and yy ld b,c ld c,a ;ex b,c pop hl ret drawbox: ;(d,e)-(h,l) ld b,l ;Delta-y ld l,e boxloop: cal drawline inc l inc e dnz boxloop ret drawfatline: cal drawline inc d inc h cal drawline inc e inc l cal drawline dec d dec h ; jp drawline ;LINE (d,e)-(h,l) ;destroyes a drawline: ;(d,e)-(h,l) psh bc ;destr: a psh hl psh de ld a,d ;a=d=x cp h ;h=xx jr c,lineXincs ;if x>xx ex de,hl ;make x ld c,a ;c=mask (always) ld a,h ;a=xx sub b ;xx-x ld b,a ;b=deltax (always>0) ld a,l ;a=yy jr nz,lineexists ;deltax!=0 cp e ;yy==y jr nz,lineexists ;deltay!=0 pop hl ; :