X-Git-Url: http://git.shiar.nl/wormy.git/blobdiff_plain/9ab1a608dddf3b6161db1cade9284c4ffe8bc0a2..1be4b87255fd59f1f29438afb6a43a1c81e51d2b:/wormy.z80 diff --git a/wormy.z80 b/wormy.z80 index 22711b9..a2c919b 100644 --- a/wormy.z80 +++ b/wormy.z80 @@ -1,6 +1,6 @@ ; Title : Wormy -; Version : 92.5% -; Release Date : february 2001 +; Version : 93% +; Release Date : summer 2001 ; Filename : wormy.86p (5kb) ; Author(s) : Shiar ; Email Address : shiar0@hotmail.com @@ -16,10 +16,8 @@ ;----------- TO-DO ----------- ;----------------------------- -; 92% = DONE +; 93% = DONE -; * implement circle-routine! -; 1% * customizable keys ; * internal levels ; * check levels/gametype ; * enough hiscore saves! @@ -42,7 +40,8 @@ ;----------------------------- #define buffer ;use display buffer (otherwise write directly to screen) -#define readymask ;"grays" out the field before starting a level +#define readymask ;"greys" out the field before starting a level +;#define hlines ;horizontal-line routine for more speed drawing boxes ;#define readytext ;displays "prepare" before level starts ;#define invincible ;worms cannot die =) @@ -83,6 +82,7 @@ _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 ------- @@ -125,8 +125,8 @@ DispBuffer = $FC70 .org _asm_exec_ram -wormVhost = 092 -wormVclient = 192 +wormVhost = 093 +wormVclient = 193 start: nop @@ -136,7 +136,7 @@ start: .dw WormIcon WormTxt: - .db "WORMY by SHIAR -- alpha 92.5%",0 + .db "WORMY by SHIAR -- beta 93%",0 WormIcon: .db 9,2 .db %10010110,%01101111 @@ -150,7 +150,7 @@ WormIcon: .db %11000011,%10000000 levelhead = 'w' -levelhead2 = 92 ;wormy levels header = "92" +levelhead2 = 93 ;wormy levels header = "93" int_handler: ex af,af' @@ -189,7 +189,7 @@ Start: cal _RAM_PAGE_7 ld hl,$BFFF ;VAT start - ld bc,templevels + ld ix,templevels searchloop: ld de,(_PTEMP_END+1) ;VAT end or a ;nc @@ -201,20 +201,17 @@ searchloop: cp $0C ;string jr z,stringfound searchnext: - cal _RAM_PAGE_7 pop hl dec hl ;5x dec hl dec hl dec hl dec hl - psh bc ld b,(hl) ;name size inc b skipname: dec hl dnz skipname - pop bc jr searchloop stringfound: @@ -227,23 +224,23 @@ stringfound: ex de,hl ;ld ahl,(hl) cal _AHL_PLUS_2_PG3 ;string id cal _Get_Word_ahl ;ld de,(ahl) - cal _RAM_PAGE_1 - ld (bc),a + ld (ix),a ld a,levelhead cp e - jr nz,searchnext ;not worm + jr nz,_searchnext ;not worm ld a,levelhead2 cp d - jr nz,searchnext - - inc bc - ld a,h - ld (bc),a - inc bc - ld a,l - ld (bc),a - inc bc - jr searchnext + jr nz,_searchnext + inc ix ;save level's ahl + ld a,h + ld (ix),a + inc ix + ld a,l + ld (ix),a + inc ix +_searchnext: + cal _RAM_PAGE_7 + jr searchnext loadgametype: psh de @@ -268,70 +265,115 @@ defaultlevels: ret searchcomplete: - cal _RAM_PAGE_1 ld a,255 - ld (bc),a ;end mark + ld (ix),a ;end mark + + cal _clrWindow ld hl,templevels-3 -dispnextlevel: - cal _RAM_PAGE_1 psh hl - cal _clrWindow - ld a,2 - ld (_curRow),a + ld hl,$0020 + ld (_penCol),hl ld hl,txtLevsel - cal _puts ;"< Select levels: >" - ld hl,$0004 - ld (_curRow),hl + cal _vputs ;"< Select levels: >" + ld hl,$0601 ;x=1 + ld (_penCol),hl pop hl +dispnextlevel: ld a,(hl) - cp 255 ;&& - jr nz,displevel - ld hl,templevels-3 - ld a,(hl) + inc a ;cp 255 + jr z,_levselect + ld a,(hl) ;ade=(hl) displevel: inc hl ld d,(hl) inc hl ld e,(hl) - inc hl ;ade=(hl) - psh hl ;HL - ld c,a - ld h,d - ld l,e ;cde=ahl=(hl) + inc hl + psh hl + ex de,hl ;ahl=ade=(hl) cal _load_ram_ahl ;hl=ahl ld b,(hl) ;b=title size - psh bc - cal _putps ;destr=abchl - pop bc ;cde=hl - pop hl ;HL + cal _vputs + ld hl,_penCol + ld (hl),$01 ;x=1 + inc hl + ld a,(hl) + add a,6 + ld (hl),a ;y+6 + ld hl,availevels + inc (hl) + pop hl + jr dispnextlevel + +levup: + cal menupos + dec b ;up + ld a,b + cp -4 + jr nz,levselected + inc b ;undo + jr levselected +levdown: + cal menupos + inc b ;down + ld a,b + cp -3 +availevels =$-1 + jr nz,levselected + dec b ;back up +levselected: + jp menupos + +_levselect: + ld b,-3 ;level selected + cal menupos levselect: - halt - psh hl - psh de + halt \ halt psh bc cal GET_KEY - pop bc - pop de - pop hl - cp K_RIGHT - jr z,dispnextlevel - sub K_SECOND + pop bc ;GET_KEY destr. b + cp K_UP + cal z,levup + dec a ;K_DOWN + cal z,levdown + cp K_SECOND-1 jr z,loadlevel - dec a ;K_EXIT + cp K_EXIT-1 ret z - cp K_ENTER-K_EXIT+256 + cp K_ENTER-1 jr nz,levselect +; jr z,loadlevel loadlevel: - ld a,c + 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 + ld hl,templevels-3 + add hl,de + ld a,(hl) ;ade=(hl) or a ;levelfile on page 0 (=internal) jr z,levelloaded - ex de,hl ;ahl=cde - inc b ;b=titlesize+1 + inc hl + ld d,(hl) + inc hl + ld e,(hl) + ex de,hl ;ahl=ade skiptitle: - cal _INC_PTR_AHL - dnz skiptitle + ld b,a ;psh ahl + psh hl + cal _GETB_AHL ;ld a,(ahl) + pop hl + or a + ld a,b ;pop ahl + psh af + cal _INC_PTR_AHL ;ahl++ + pop af ;cp 0 + jr nz,skiptitle ;goto #0-terminator cal _Get_Word_ahl ld (leveldataSize),de @@ -368,6 +410,16 @@ levelloaded: ld a,r ld (Seed),a + ld hl,datasingle+3 + ld b,8 +setdeflevels: + ld (hl),1 ;def=level#1 + inc hl + inc hl + inc hl + inc hl + dnz setdeflevels + ;----------------------------- ;----- build trig tables ----- ;----------------------------- @@ -401,33 +453,25 @@ NegativeSineWave: DisplayMenu: ;---draw menu--- cal _clrWindow - ld de,$FC42 ;(10,2) + ld de,$FC40 ;(0,4) ld hl,wtPicture - ld a,16 ;height -disptitleloop: - ld bc,8 ;width + ld bc,16*16 ldir - ex de,hl - ld bc,8 ;next line - add hl,bc - ex de,hl - dec a - jr nz,disptitleloop ld hl,txtMenu ld ix,posMenu - ld b,5 + ld b,6 dispmenuloop: ld d,(ix) inc ix ld e,(ix) inc ix ld (_penCol),de - cal _vputs ;by Shiar \ Mode \ Level \ Limit \ Worms + cal _vputs ;Mode \ Level \ Limit \ Worms \ worm # \ controls dnz dispmenuloop ld b,0 ;b=menu# - jr setgame ;> dispmenusets > mainMenu + jr _dispmenusets ;mainMenu ;--- menu loop --- @@ -436,15 +480,20 @@ mainMenu: cal menucall jr nz,notselect select: ;2nd/enter + cal menupos ld a,b - dec a ;2nd item? + sub 4 ;4th item? jp z,changeworms - jp LetsGetThisPartyOn ;1/3/4 + dec a ;5th? + jp z,changekeys + jp LetsGetThisPartyOn ;1/2/3/5 notselect cp K_EXIT jp z,ExitNoStats psh af cal menupos + cal loadgamecar + inc hl pop af cp K_LEFT jr z,selleft @@ -456,25 +505,23 @@ selright: or a jr z,changegame dec a - jr z,changelevel + jp z,changelevel ;&&&jr?? dec a jr z,changelives + dec a + jr z,changenrworms ; dec a -; jr z,changenrworms +; jr z,changecurworm -changenrworms: - ld a,(Gametype) - cp 2 - jr c,mainMenu ;type 0/1 - ld hl,nrworms - ld a,(hl) +changecurworm: +; hl=nrworms + ld a,(curworm) + cp (hl) + jr nc,mainMenu ;may not become >(nrworms) inc a - cp 5 - jr nc,mainMenu ;may not be >4 -changednrworms: - ld (hl),a - jr dispmenusets ;mainMenu - +changedcurworm: + ld (curworm),a + jr _dispmenusets ;mainMenu selleft: ld a,b @@ -484,11 +531,32 @@ selleft: jr z,bchangelevel dec a jr z,bchangelives + dec a + jr z,bchangenrworms ; dec a -; jr z,bchangenrworms +; jr z,bchangecurworm + +bchangecurworm: + ld a,(curworm) + dec a ;0-3 + jr nz,changedcurworm ;save >0 + jr mainMenu +changenrworms: + ld a,(Gametype) + cp 2 + jr c,mainMenu ;type 0/1 + ;hl=nrworms + ld a,(hl) + inc a + cp 5 + jr nc,mainMenu ;may not be >4 +changednrworms: + ld (hl),a +_dispmenusets: + jr dispmenusets ;mainMenu bchangenrworms: - ld hl,nrworms + ;hl=nrworms ld a,(hl) dec a ;0-3 jr nz,changednrworms ;save >0 @@ -502,15 +570,6 @@ Gametype =$-1 changedgame: and 7 ;mod 8 ld (Gametype),a -setgame: - ld a,1 - ld (curlevel),a ;reset level# - ld hl,nrworms ;reset #worms - ld a,(Gametype) - cp 2 - ld (hl),1 - jr c,dispmenusets ;<2=singleplayer - inc (hl) ;2 jr dispmenusets ;mainMenu bchangegame: ld a,(Gametype) @@ -521,7 +580,7 @@ changelives: cal changelivesInit inc a cp 100 - jr nc,mainMenu + jr nc,_mainMenu ;&& _? changedlives: ld (hl),a jr dispmenusets ;mainMenu @@ -541,35 +600,60 @@ changelivesInit: jr _mainMenu ;singleplayer (no limit) changelevel: + inc hl ;hl=loadgamecar+2 + psh hl + ld a,(hl) ;(curlevel) ld hl,Gametype ld d,0 ld e,(hl) ld hl,nrlevels add hl,de - ld d,(hl) ;max level for sel.game -curlevel =$+1 - ld a,1 - cp d + cp (hl) ;max level for sel.game + pop hl jr z,_mainMenu inc a changedlevel: - ld (curlevel),a + ld (hl),a jr dispmenusets ;mainMenu bchangelevel: - ld a,(curlevel) + inc hl + ld a,(hl) ;(curlevel) dec a jr nz,changedlevel -__mainMenu: jr _mainMenu +getcustomkey: + cal _vputs + dec ix +waitcustomkey: + halt \ halt + psh hl + cal GET_KEY + 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: - ld hl,$FD95 - ld de,5 - ld a,23 + ld hl,$FD97 ;begin pos + ld de,7 ;bytes to add + ld a,35 ;nr of lines clroldsettings: - ld c,11 + ld c,9 ;bytes to clear clroldsetsloop: ld (hl),d ;=0 inc hl @@ -579,7 +663,7 @@ clroldsetsloop: dec a jr nz,clroldsettings - ld de,$182E + ld de,$183E ld (_penCol),de ld d,0 ld a,(Gametype) @@ -593,19 +677,9 @@ clroldsetsloop: ld (CURtxtGame),hl ;save for g/o cal _vputs ;Singleplayer - ld hl,$1E2E ;level - ld (_penCol),hl - ld a,(curlevel) - cal cshowA - - ld hl,$2A2E ;worms - ld (_penCol),hl - ld a,(nrworms) - add a,'0' - cal _vputmap - cal loadgamecar - ld hl,$242E + psh hl + ld hl,$243E ld (_penCol),hl cal cshowA ;liveslimit sub '0' ;original A @@ -617,7 +691,40 @@ clroldsetsloop: ld a,'0' limitok: cal _vputmap ;x10 - jr __mainMenu + + ld hl,$2A3E ;worms + ld (_penCol),hl + pop hl ;cal loadgamecar + inc hl + psh hl + ld a,(hl) + add a,'0' + cal _vputmap + + ld hl,$1E3E ;level + ld (_penCol),hl + pop hl ;loadgamecar; hl++ + inc hl + ld a,(hl) ;(curlevel) + cal cshowA + + ld hl,$3032 + ld (_penCol),hl + ld a,1 +curworm =$-1 + add a,'0' + cal _vputmap + ld hl,$303E + ld (_penCol),hl + cal getwormname + ld hl,worm1name-18 + add hl,de + cal _vputs + ld hl,$363E ;controls + ld (_penCol),hl +; ld hl,txtMenu +; cal _vputs + jp mainMenu ;--- handle menukeys --- @@ -670,45 +777,47 @@ menuup: dec b menuupdown: ld a,b - and %11 ;4=0;-1=3 + 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#(nrworms) -;or #1 if Gametype<2 - -changeworms: - cal _clrWindow - ld hl,txtName - cal _puts ;"Enter name player " - ld a,(Gametype) - cp 2 - ld a,1 - jr c,wormnrname -nrworms =$+1 - ld a,1 -wormnrname: - add a,'0' - cal _putc - sub '0' +; of worm#(curworm) - ld d,a ;1x +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 - add a,d ;19x ld e,a ld d,0 ;de=a - ld ix,worm1name-19 + ld ix,worm1name-18 add ix,de + ret + +changeworms: + cal _clrWindow + ld hl,txtEName + cal _puts ;"Enter name player " + ld a,(curworm) + add a,'0' + cal _putc + + cal getwormname ld a,maxnamelength cal entername - ld (ix),0 + ld (ix),0 ;end mark jp DisplayMenu entername: @@ -838,6 +947,7 @@ loadgamecar: ld hl,datasingle ld a,(Gametype) add a,a + add a,a ld e,a ld d,0 add hl,de @@ -858,22 +968,24 @@ LetsGetThisPartyOn: ld (CheckExit),a ;set exit state cal loadgamecar - ld l,a + ld b,a ;psh a + inc hl ;nrworms + ld a,(hl) + ld (nrworms),a + ld l,b ;pop a ld h,0 ;hl=a cal _HLTIMES10 ;hl=10*(hl) ld (scorelimit),hl ;set limit cal loadgamecar ;nc - ld e,24+1 ;=de + psh hl + ld a,(Gametype) ;4bytes -> 3bytes + add a,a ;3->2bytes + add a,24+1 ;go to datalevels + ld e,a ;=de sbc hl,de ;datalevels ld a,c ;(gameCar) - and _datasingl - jr z,notsingle - ld a,1 - ld (nrworms),a -notsingle: - ld a,c and _datascore jr nz,scorelimitset dec a ;ld a,$FF ;=no_limit @@ -881,7 +993,9 @@ notsingle: scorelimitset: cal _ldHLind ;ld hl,(hl) - ld a,(curlevel) + pop de ;de=loadgamecar + inc de \ inc de + ld a,(de) ;(curlevel) ld (Level),a ld d,a ;begin level skiplevelloop: @@ -903,12 +1017,11 @@ linkmatch: ld hl,txtWaiting cal _puts cal Crecv -; ld a,c + ld a,c cp wormVclient jr z,client cp wormVhost jr nz,linkiniterror - host: ld c,wormVclient cal Qsend @@ -922,8 +1035,7 @@ linkiniterror: client: ld hl,txtReceive cal _puts - - ld a,$f6 + ld a,$E6 multiplayer: ld (SwapPos),a ld a,2 @@ -934,6 +1046,8 @@ multiplayer: ;----------------------------- GameOver: + ld a,%11000000 + out (7),a ;link normal cal _clrLCD ld hl,worm1set ld de,worm1 @@ -967,6 +1081,8 @@ StartLevel: inc a ;=255? jp nz,nextlevel + ld hl,Level + dec (hl) ;curlevel-- (not beyond last lvl) psh hl cal releasekeys cal _clrWindow @@ -1060,13 +1176,21 @@ worminit: 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 - add a,57-5 psh de ; >> levelp + ld a,l ;pop + sub 5 ld l,a ld h,0 add hl,hl @@ -1190,25 +1314,16 @@ maskline: gameCar =$-1 and _datalink jr z,initfinished ;no link - xor a - ld (worm2+input),a ;worm 2 via link - ld (worm2+left),a ld (Speed),a ;max.speed -SwapPos: ;$18 xx -> $F6 xx - ; jr xx -> or xx +SwapPos: ;$18 xx -> $E6 xx + ; jr xx -> and xx + jr sethost +setclient: + ld (worm1+left),a ;worm 1 via link jr initfinished - inc a - ld (worm2+left),a ;1 - ld hl,worm1 - ld de,worm2 - ld b,4 ;+heading +pos - cal _EXLP ;swap positions -;&&& over link - ld hl,worm1+name - ld de,worm2+name - ld b,maxnamelength - cal _EXLP ;swap positions +sethost: + ld (worm2+left),a ;worm 2 via link initfinished: ld b,startdelay @@ -1251,13 +1366,16 @@ Delay: jr nz,Delay NoDelay: + ld (handledworm),a ;=0 + ld a,0 nrballs =$-1 or a cal nz,handlethoseneatlittleballs ld ix,worm1 - ld a,(nrworms) + ld a,1 +nrworms =$-1 ld b,a handleworms: psh bc @@ -1265,6 +1383,8 @@ handleworms: ld bc,worm2-worm1 add ix,bc pop bc + ld hl,handledworm + inc (hl) ;1..nrworms dnz handleworms ;----------------------------- @@ -1298,14 +1418,19 @@ WormDead: ld (ix+delay),respawndelay thislevel =$+1 + ld hl,0 ld de,0 - ld a,(de) - inc de +handledworm =$-2 + add hl,de + add hl,de + add hl,de + ld a,(hl) + inc hl ld (ix+heading),a - ld a,(de) + ld a,(hl) ld (ix+pos),a - inc de - ld a,(de) + inc hl + ld a,(hl) ld (ix+pos+1),a inc (ix+died) @@ -1317,7 +1442,21 @@ thislevel =$+1 ret nz ;HandleWorm done ld a,(gameCar) and _datalivel - ret z + ret z ;don't end game + ld a,(Gametype) + cp gametron + jr nz,anyworm ;if not Tron, quit at any worm's death + ld a,(nrworms) + 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 @@ -1331,19 +1470,36 @@ SpSave = $-2 cal _clrWindow ld hl,txtGO cal _puts + ld hl,$FC00 + ld b,16*8 + cal menuinvloop ;invert + inc h ;$FD80 + ld b,16 + cal menuinvloop ;
+ ld hl,$FCE0 + ld b,16 + cal menuinvloop ;
+; ld l,$74 +; ld b,8 +; cal menuinvloop + ld hl,_curRow + inc (hl) ld hl,txtGame CURtxtGame =$-2 cal _puts - ld de,0002 - ld (_curRow),de + ld a,$0D ;$0D02 + ld (_curCol),a cal showLevel - ld de,$0B03 + + ld de,$1901 + ld (_penCol),de + ld hl,txtName + cal _vputs ;Name + ld a,$4F + ld (_penCol),a + cal _vputs ;Died Score + ld de,$0004 ld (_curRow),de - ld hl,txtDied - cal _puts - cal _puts ;txtScore - xor a - ld (_curCol),a ld a,(nrworms) ld b,a @@ -1352,26 +1508,18 @@ displayWormStats: psh bc psh hl - ld bc,input-died - add hl,bc ;+input + ld bc,left-died + add hl,bc ;+left xor a cp (hl) ;input=0 = link jr nz,NoLinkIndic - ld b,7 ;{DOWN} - inc hl ;+left - cp (hl) - jr z,hostLinkIndic - dec b ;{UP} -hostLinkIndic: ld a,8 ld (_curCol),a - ld a,b + ld a,$DC ;-O cal _putc xor a ld (_curCol),a - dec hl NoLinkIndic: - inc hl inc hl inc hl ;+name cal _puts @@ -1405,7 +1553,7 @@ checkhilevel: ld a,(Level) cp (hl) jr c,hilevelcheckdone - ld (hl),a ;save local + ld (hl),a ;save local ld c,a ld a,0 hilvlposa =$-1 @@ -1463,7 +1611,7 @@ waitkey: jr nz,waitkey ;x123456789012345678901 -;1----- GAME OVER ----- +;>>>>>> GAME OVER <<<<< ;2Multiplayer ;3Level 01 ;4 Died Score: @@ -1576,7 +1724,6 @@ unnamedlabel: respawndue: ld l,a cal inputcall - ld (sendbyte),a ld a,h ;previous cp l ;changed? ret z @@ -1590,56 +1737,73 @@ saverespawncounter: ; jr z,inlink ; ret -inkeys: ;use jp not call! - out (1),a ;nop\nop - in a,(1) +chkkey: ;key=a + dec a ld b,a - and (ix+right) - jr z,notright + 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 ld l,a notright: - ld a,b - and (ix+left) - ret z + ld a,(ix+right) + cal chkkey + ret nc ld a,l sub 8 ld l,a ret - inputcall: - ld a,(ix+input) + ld a,(ix+left) or a - jr nz,inkeys - -inlink: - ld b,(ix+left) - dec b - jr z,receivefirst + jr z,inlink ;input by link + cal inkeys ;input by keys + ld a,(gameCar) + and _datalink + ret z ;no link + ld c,l ;send our keys psh hl - ld c,0 -sendbyte =$-1 - cal Csend - cal Crecv + cal Qsend ;Csend pop hl - ld l,c ret -receivefirst: +inlink: psh hl - cal Crecv + cal Qrecv ;Crecv pop hl ld l,c - psh hl - ld a,(sendbyte) - ld c,a - cal Csend - pop hl ret ;------- handle worm --------- HandleWorm: + ld a,(gameCar) + cpl + and _datalivel + add a,(ix+lives) + or a + ret z ;dead ld a,(ix+delay) dec a jp nz,respawncheck @@ -1654,8 +1818,6 @@ notron: ld l,(ix+heading) cal inputcall donediddelydone: - ld a,l - ld (sendbyte),a ld (ix+heading),l ld h,(ix+heading+1) @@ -1824,9 +1986,9 @@ multiple_peas: sel_ownpea: cal chkpeahit pop hl ;(peapos) 1st pea - jp c,stopworm ;own pea hit + jp c,WormDead ;stopworm ;own pea hit - ld a,e ;peek a (that x86 asm for pop\push ;) + ld a,e ;peek a (that's x86 asm for pop\push ;) and %01 jr z,sel_otherpea ld hl,(peaspos+2) ;2nd pea @@ -2204,6 +2366,10 @@ scorelimit =$-2 jp nc,Exit showstats: + ld a,(Gametype) + cp gametron + ret z +showstatsEven4tron: psh ix ld h,0 ld l,h @@ -2683,6 +2849,14 @@ drawstuff: cal z,drawfatline dec a ;3 = box cal z,drawbox + dec a ;4 = circle + cal z,drawcircle + dec a ;5 = hline +#ifdef hlines + cal z,drawhline +#else + cal z,drawline +#endif pop hl inc hl @@ -2690,6 +2864,36 @@ drawstuff: drawbox: ;(d,e)-(h,l) ld b,l ;Delta-y +#ifdef hlines +boxloop: + cal drawhline + inc e + dnz boxloop + ret +drawhline: ;(d,e)-(h,e) + psh bc + ld b,d + ld c,e + psh hl + cal FindPixel + ld c,a ;starting mask + ld a,h + sub b + ld b,a + inc b ;1+x2-x1 +hlineloop: + ld a,(hl) + or c + ld (hl),a + rrc c ;mask >> + jr nc,hlinenext + inc hl ;next byte +hlinenext: + dnz hlineloop + pop hl + pop bc + ret +#else ld l,e boxloop: cal drawline @@ -2697,6 +2901,7 @@ boxloop: inc e dnz boxloop ret +#endif drawfatline: cal drawline @@ -2713,8 +2918,8 @@ drawfatline: ;LINE (d,e)-(h,l) ;destroyes a -drawline: - psh bc +drawline: ;(d,e)-(h,l) + psh bc ;destr: a psh hl psh de ld a,d @@ -2814,6 +3019,196 @@ line4sm: dnz LineLoopSteep jr DoneLine +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 + + + + + +;**** link routines **** +;these are identical in concept to the routines used in ZTetris, ZPong, and probably +;every other link game out there. However, these are commented :) +losses: .dw 0 +Csend: + ld b,32 +csendwait: + nop + dnz csendwait + cal Qsend + jr c,Csend + ret +Qsend: +send: +;inputs: c=byte to send, both wires must be high by default +;outputs: b=8-number of bits sent, both wires high, goes to game over on certain conditions +;destroys: af,bc,de + in a,(7) + and %11 + jr z,killlink ;if both lines low, get out of here (game over signal) + ld b,8 ;sending 8 bits +sendloop: + ld de,$8000 ;error timer + rl c ;force high bit into carry + ld a,%11010100 ;lower the red wire by default (sending 0) ($d4) + jr nc,selected ;if high bit was 0, use above value + ld a,%11101000 ;if 1, lower the white wire instead ($e8) +selected: + out (7),a ;put it out the link port +waitconfirm: + call linktimer + in a,(7) ;see what the wires are doing + and %00000011 ;check lower 2 bits + jr nz,waitconfirm ;if both bits 0, data was received ok (both wires low) + ld a,%11000000 + out (7),a ;give the ok to raise both wires (one will be done automatically) ($c0) +waitconfirm2: + call linktimer + in a,(7) + and %00000011 + cp 3 + jr nz,waitconfirm2 ;wait for other calc to raise the other wire + djnz sendloop ;continue sending + xor a ;reset c; ld a,0 + ld (losses),a ;reset number of losses + ret + + +Crecv: + cal receive + jr c,Crecv + ret +Qrecv: +receive: +;inputs: both wires must be high by default +;outputs: c=byte received, b=8-number of bits received, both wires high +; goes to game over on certain conditions +;destroys: af,bc,de + in a,(7) + and %00000011 + jr z,killlink ;game over signal applies to receiving too + ld b,8 ;receiving 8 bits +receiveloop: + ld de,$8000 ;error timer +waitreceive: + call linktimer + in a,(7) + and %11 + cp 3 ;if bits 0 and 1 set, both wires are high + jr z,waitreceive ;wait for one of the wires to go low + rra ;check red wire status + rl c ;if set, red is high (thus white is low), so put the correct bit into c + rra ;now check white wire (since the flags are destroyed) + ld a,%11010100 ;$d4 + jr nc,selected2 ;if white is low, lower red and vice versa + ld a,%11101000 ;$e8 +selected2: + out (7),a ;so now both wires are low +waitreceive2: + call linktimer + in a,(7) + and %11 + jr z,waitreceive2 ;wait for the wire we didn't lower to go high again (the other will remain low) + ld a,%11000000 ;$c0 + out (7),a ;raise both wires since the other calc will have given the ok sign + djnz receiveloop ;if not done, wait for next bit + xor a ;reset c + ld (losses),a ;reset number of losses + ret + +linktimer: ;leave if we have to wait too long (and return an error) + dec de + ld a,d + or e ;see if de is 0 + ret nz ;if not, keep going as usual + ;otherwise we have to deal with a link failure + ld a,%11000000 ;$c0 + out (7),a ;reset link status (both high) + ld a,(losses) ;see how many consecutive losses we have + inc a + ld (losses),a ;add this loss to it + pop de ;fix the stack to leave the link routine (de is ok to destroy) + cp 20 ;see if this is the 20th consecutive failure + ret c ;if not, keep playing + ;otherwise, all is probably lost... + +killlink2: + jr linkend +killlink: +linkend: + jp z,Exit + + + + + + + + + +#ifdef 0 ;----------------------------- ;----------- link ------------ ;----------------------------- @@ -2926,6 +3321,7 @@ recvfinish: xor a ;nc=no error ld a,c ;result in a ret +#endif ;----------------------------- ;---------- levels ----------- @@ -2936,7 +3332,6 @@ LevelDef: .db 0,2,63 ;start d, y, x .db 128,57 ;field width (128-255), height (57-255) .db 0 ;no additional lines, boxes - .db 255 ret @@ -2952,60 +3347,78 @@ LevelDefM: .db 128,57 .db 0 -LevelDefT: + .db 8,5,18,12,0,0 + .db $40,30,2,$C0,30,125, $00,2,64,$80,54,64 + .db 128,57 + .db 4,40,26,20,0 + .db 4,90,40,11,0,0 + +LevelDefT: ;tron=no delay + .db 8,4,18,12,5 + .db %1110000,%10001000,%10001000,%10001000,%1110000,0 + .db $40,30,64,$C0,30,64, $00,30,64,$80,30,64 + .db 128,57 + .db 0 + +LevelDefC: ;ctf .db 8,4,18,12,5 .db %1110000,%10001000,%10001000,%10001000,%1110000,0 .db $40,30,64,$C0,30,64, $00,30,64,$80,30,64 .db 128,57 + .db 10,10,50,50 .db 0 ;----------------------------- ;---------- data ------------- ;----------------------------- +wdPicture = 16 wtPicture: -.db %00011110,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000 -.db %00111110,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000 -.db %01110000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000 -.db %01100000,%01111100,%00000001,%11111111,%00000000,%11110000,%01111001,%11100000 -.db %11100000,%11111110,%00000011,%11111111,%10000011,%11111000,%11111111,%11110000 -.db %11000001,%11000111,%00000111,%00000001,%11000111,%10011001,%11001111,%00111000 -.db %11000001,%10000011,%00000110,%00000000,%11100110,%00000001,%10011111,%10011000 -.db %11000001,%10000011,%00000110,%11000000,%01101110,%00000011,%10111001,%11011100 -.db %11000001,%11000111,%00000110,%11000000,%01101100,%00000011,%00110000,%11001100 -.db %11000000,%11000110,%00000110,%11000000,%01101100,%00000011,%00110000,%11001100 -.db %11100000,%11101110,%00001110,%11000000,%01101100,%00000011,%00111001,%11001100 -.db %01100000,%01111100,%00001100,%11000000,%01101100,%00000011,%00011111,%10001100 -.db %01110000,%00111000,%00011100,%11100000,%11101110,%00000011,%00001111,%00001100 -.db %00111000,%11111110,%00111000,%01110001,%11000110,%00000011,%10000000,%00011100 -.db %00011111,%11101111,%11110000,%00111111,%10000111,%00000001,%10000000,%00011000 -.db %00001111,%10000011,%11100000,%00011111,%00000011,%00000001,%10000000,%00011000 - -txtMenu: .db "by Shiar",0 - .db "Mode",0 - .db "Level",0 ;4th menu item - .db "Limit",0 ;3rd - .db "Worms",0 ;2nd -posMenu: .dw $0D5A,$1418,$131E,$1524,$0F2A -txtGame: .db "Singleplayer",0 ;0 (1st) -txtGame1: .db "Peaworm",0 ;1 (next 1st) -txtGame2: .db "Tron",0 ;2 -txtGame3: .db "Deathmatch",0 ;3 -txtGame4: .db "Foodmatch",0 ;4 -txtGame5: .db "LinkMatch",0 ;5 -txtGame6: .db "Race",0 ;6 -txtGame7: .db "CTF",0 ;7 +.db %00000000,%00000000,%00000111,%10000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%01110000,%00000000,%00000000,%00000000,%00000000,%00000000 +.db %00000000,%00000000,%00001111,%10000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%01111000,%00000000,%00000000,%00000110,%01111011,%00100000 +.db %00000000,%00000000,%00011100,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00011100,%00001110,%00000000,%00001001,%00010011,%01000000 +.db %00000000,%00000000,%00011000,%00011111,%00000000,%01111111,%11000000,%00111100,%00011110,%01111000,%00001100,%00011111,%00000000,%10100111,%00110000,%10000000 +.db %00000000,%00000000,%00111000,%00111111,%10000000,%11111111,%11100000,%11111110,%00111111,%11111100,%00001100,%00111011,%00000000,%10100001,%00001001,%01100000 +.db %00000000,%00000000,%00110000,%01110001,%11000001,%11000000,%01110001,%11100110,%01110011,%11001110,%00001100,%00110001,%10000000,%01001110,%01110010,%01100000 +.db %00000000,%00000000,%00110000,%01100000,%11000001,%10000000,%00111001,%10000000,%01100111,%11100110,%00001110,%01110001,%10000000,%00000000,%00000000,%00000000 +.db %00000000,%00000000,%00110000,%01100000,%11000001,%10110000,%00011011,%10000000,%11101110,%01110111,%00001110,%01110001,%10000000,%00000000,%00000000,%00000000 +.db %00000000,%00000000,%00110000,%01110001,%11000001,%10110000,%00011011,%00000000,%11001100,%00110011,%00000111,%11100001,%10000000,%00000000,%00000000,%00000000 +.db %00000000,%00000000,%00110000,%00110001,%10000001,%10110000,%00011011,%00000000,%11001100,%00110011,%00000011,%11000011,%10000000,%00000000,%00000000,%00000000 +.db %00000000,%00000000,%00111000,%00111011,%10000011,%10110000,%00011011,%00000000,%11001110,%01110011,%00000000,%00000011,%00110101,%01001001,%10000000,%00000000 +.db %00000000,%00000000,%00011000,%00011111,%00000011,%00110000,%00011011,%00000000,%11000111,%11100011,%10000000,%00000011,%01000101,%00010101,%01000011,%01100011 +.db %00000000,%00000000,%00011100,%00001110,%00000111,%00111000,%00111011,%10000000,%11000011,%11000001,%10000000,%00000111,%01100101,%01010101,%01000101,%01010100 +.db %00000000,%00000000,%00001110,%00111111,%10001110,%00011100,%01110001,%10000000,%11100000,%00000001,%11100000,%00001110,%00110111,%01011101,%10010101,%01100101 +.db %00000000,%00000000,%00000111,%11111011,%11111100,%00001111,%11100001,%11000000,%01100000,%00000000,%11111111,%11111100,%00010101,%01010101,%01000101,%01010101 +.db %00000000,%00000000,%00000011,%11100000,%11111000,%00000111,%11000000,%11000000,%01100000,%00000000,%00111111,%11111000,%01100101,%01010101,%01000110,%01010011 + +txtMenu: .db "Mode",0 ;1st menu item + .db "Level",0 ;2nd + .db "Limit",0 ;... + .db "Worms",0 + .db "worm #",0 + .db "controls",0 +posMenu: .dw $$2418,$231E,$2524,$1F2A,$1730,$1936 +txtGame: .db "Singleplayer",0 +txtGame1: .db "Peaworm",0 +txtGame2: .db "Tron",0 +txtGame3: .db "Deathmatch",0 +txtGame4: .db "Foodmatch",0 +txtGame5: .db "LinkMatch",0 +txtGame6: .db "Race",0 +txtGame7: .db "CTF",0 ; .db "Domination",0 ;8 -posGame: .db 0,txtGame1-txtGame - .db txtGame2-txtGame - .db txtGame3-txtGame - .db txtGame4-txtGame - .db txtGame5-txtGame - .db txtGame6-txtGame - .db txtGame7-txtGame - +posGame: .db 0,txtGame1-txtGame + .db txtGame2-txtGame + .db txtGame3-txtGame + .db txtGame4-txtGame + .db txtGame5-txtGame + .db txtGame6-txtGame + .db txtGame7-txtGame + +txtKeyleft: .db "Left",0 +txtKeyright:.db " | Right",0 txtLevsel: .db $CF," Select levels: ",5,0 -txtName: .db "Enter name player ",0 +txtEName: .db "Enter name player ",0 txtWaiting: .db "Waiting...",0 txtReceive: .db "Receiving..." ;,0 @@ -3021,14 +3434,15 @@ TrigPrecalc: .db 127 txtLevel: .db "Level ",0 -txtWorms: .db "Worms: 0",0 ;follows txtLevel -txtDied: .db "Died ",0 -txtScore: .db "Score",0 ;follows txtDied -txtLeft: .db " left",0 ;follows txtScore +txtWorms: .db "Worms: 0",0 ;follows txtLevel +txtName: .db "Name",0 +txtDied: .db "Died " ;follows txtName +txtScore: .db "Score",0 ;follows txtDied +txtLeft: .db " left",0 ;follows txtScore txthiscore:.db "HiScore:",0 txtReady: .db "Prepare!",0 txtposReady = 7 -txtGO: .db "----- GAME OVER -----",0 +txtGO: .db 5,5,5,5,5," GAME OVER ",$CF,$CF,$CF,$CF,$CF,0 _datalink = %00000001 ;linkplay _datalivel = %00000010 ;lives=0 limit @@ -3045,45 +3459,45 @@ _datasp = %01011110 datalevels: .dw LevelDef, LevelDefM .dw LevelDefT,LevelDefM .dw LevelDefM,LevelDefM - .dw LevelDefM,LevelDefM -nrlevels: .db 1,2,2,2,2,2,2,1 ;=defaults + .dw LevelDefM,LevelDefC +nrlevels: .db 1,3,1,3,3,3,3,1 ;=defaults savestart: gamesingle = 0 -datasingle: .db %01011110,3 ;3 lives ( -worm1name: .db "worm #01",0 + .db %11110111,%00,-01,K_RIGHT,K_LEFT +worm1name: .db "Wormy ",0 worm2set: .dw worm2p,worm2p - .db %11111011,%11,%00111111,%10000,%1000 ;f1 f2 -worm2name: .db "worm #02",0 + .db %11111011,%11,-01,K_F2,K_F1 +worm2name: .db "Viper ",0 worm3set: .dw worm3p,worm3p - .db %11111011,0,%01011111,%10,%100 ;sto , -worm3name: .db "worm #03",0 + .db %11111011,%00,-01,K_COMMA,K_STO +worm3name: .db "Nibbler ",0 worm4set: .dw worm4p,worm4p - .db %11111011,0,%01111101,%10,%1 ;enter + -worm4name: .db "worm #04",0 + .db %11111011,%00,-01,K_PLUS,K_ENTER +worm4name: .db "Jim ",0 defhiscrpos: - .dw 0,0,0,0,0 + .dw 0,0,0,0,0,0 saveend: @@ -3100,9 +3514,7 @@ lives = 12 head = 13 ;4B (head=tail) tail = 15 ;also@next level storepos = 17 -reserv = 18 ;loop - ;race:lap - ;ctf:pea +reserv = 18 ;loop (race:lap|ctf:pea) input = 19 left = 20 right = 21 @@ -3125,13 +3537,13 @@ maxnamelength = 8+1 .db " shiar0@hotmail.com",0 defspritesz = 4 -defspriteimg: .db %01100000 - .db %11110000 - .db %11110000 - .db %01100000 +defspriteimg: .db %01100000 + .db %11110000 + .db %11110000 + .db %01100000 deflevels: - .db 15,"Internal Levels" + .db "Internal Levels" ;,0 .db 0,deflevels/256,deflevels&255 templevels: