X-Git-Url: http://git.shiar.nl/wormy.git/blobdiff_plain/8dcbed707c51a18497a464a3a383b82263c76f71..7ec10d8466fbe267a3d0a8fe8fbfaed79adbf07f:/worm.z80 diff --git a/worm.z80 b/worm.z80 index fef817c..a5cdab9 100644 --- a/worm.z80 +++ b/worm.z80 @@ -1,7 +1,7 @@ ; Title : Worm -; Version : 0.986 -; Release Date : april 2000??? -; Filename : worm.86p (4kb) +; Version : 91% +; Release Date : may 2000 +; Filename : worm.86p (5kb) ; Author(s) : Shiar ; Email Address : shiar@mailroom.com ; ICQ UIN : #43840958 @@ -16,17 +16,14 @@ ;----------- TO-DO ----------- ;----------------------------- -; 86% = DONE +; 91% = DONE -; 1% * levelfile select -; 3% * linkplay -; 1% * titlescreen +; 2% * fix deaths linkplay and transmit game/level data ; 2% * make linkplay available for all gametypes (not just deathmatch) -; 1% * two worms collide with heads -> both should die -; * game types: -; 1% * ctf: take enemy flag (right-bottom) and return to your flag (left-top) -; 1% * domination?: take control points by running over them and hold them -; 1% * name change + other options +; 1% * fix pea XOR problem in ctf (+dom?) +; * fix wormstop +; 1% * domination?: take control points by running over them and hold them +; * customizable keys ; * complete readme (+custom level info) ; 2% * ... (pollish, &&&) @@ -40,6 +37,12 @@ ;----------------------------- ;----------------------------- +#define buffer ;use display buffer (otherwise write directly to screen) +#define readymask ;"grays" out the field before starting a level + +;#define readytext ;displays "prepare" before level starts +;#define invincible ;worms cannot die =) + #define cal call #define psh push #define dnz djnz @@ -49,8 +52,9 @@ _SHRACC = $4383 _SHLACC = $438B -_divHLby10 = $4044 -_divAby10 = $4DAF +_divHLby10 = $4044 ;hl=hl/10 +_divAby10 = $4DAF ;a=a/10 +_HLTIMES10 = $41BF ;hl=hl*10 _cphlde = $403C _clrWindow = $4A86 ;clear screen _asapvar = $D6FC ;own name (worm) @@ -61,6 +65,7 @@ _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 @@ -68,29 +73,47 @@ _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 _RAM_PAGE_1 = $47E3 ;set $8000+ to page 1 +_RAM_PAGE_7 = $47F3 +_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 ;----------------------------- ;------- data storage ------- ;----------------------------- -leveldata = $EA00 ;size< $400 -ScrBuffer = $8100 ;size=$2000 (32x256) - ;->mod$800 -DispBuffer = $BC00 ;size= $390 (16x57) -SinCosTable = $B500 ;size= $100 (4x64) - -worm1 = $B400 -worm2 = $B42A -worm3 = $B454 -worm4 = $B47E ;-B4A8 - -resbit = 2 ;and%11111011 -worm1p = $B000 ;%10110000 -$B3FF -worm2p = $B800 ;%10111000 -$BBFF -worm3p = $F000 ;%11110000 -$F3FF -worm4p = $A800 ;$E800=%11101000 ;$D748+$1000+ - -WormVersion = 086 +;--- 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 (4x40) + ;free $AE01 ;-AFFF (1FF) +worm1p = $B000 ;-B7FF (800) %1011O000 +worm3p = $B800 ;-BBFF (400) %10111O00 + ;free $BF91 ;-BFFF (6F) + + ;program $D748 ;-E7FF (106D+4A) + ;free $E800 ;-EFFF (800) +worm4p = $F000 ;-F3FF (400) %11110O00 +leveldata = $F400 ;-FA70 (<=671) + +peaspos = $AE01 + +;--- temporary + +templevels = $BC00 ;(3*strings) @init +namelength = $BC00 ;(1) @menu +#ifdef buffer +DispBuffer = $BC00 ;(10x57d) @game +#else +DispBuffer = $FC70 +#endif ;----------------------------- ;------- program start ------- @@ -98,6 +121,8 @@ WormVersion = 086 .org _asm_exec_ram +WormVersion = 091 + start: nop jp Start @@ -106,7 +131,7 @@ start: .dw WormIcon WormMsg: - .db "WORM by SHIAR -- pre-beta 86%",0 + .db "WORM by SHIAR -- pre-beta 91%",0 WormIcon: .db 9,2 .db %10010110,%01101111 @@ -119,35 +144,72 @@ WormIcon: .db %11101111,%00001111 .db %11000011,%10000000 -levelfile: - .db 7,"wormlvl" -levelhead = 'T' +levelhead = 'w' +levelhead2 = 91 ;worm levels header = "91" Start: ld (SpSave),sp cal _runindicoff cal _flushallmenus - cal _clrLCD - ld hl,levelfile-1 - rst 20h ;_ABS_MOV10TOOP1 - rst 10h ;_FINDSYM - ret c ;not found - ex de,hl - ld a,b ;cal _ex_ahl_bde - cal _AHL_PLUS_2_PG3 + cal _RAM_PAGE_7 + ld hl,$BFFF ;VAT start + ld bc,templevels +searchloop: + ld de,(_PTEMP_END+1) ;VAT end + or a ;nc + sbc hl,de ;hl" + ld hl,$0004 + ld (_curRow),hl + pop hl + ld a,(hl) + cp 255 + jr nz,displevel + ld hl,templevels + ld a,(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) + 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 +levselect: + halt + psh hl + psh de + psh bc + cal GET_KEY + pop bc + pop de + pop hl + cp K_RIGHT + jr z,dispnextlevel + sub K_SECOND + jr z,loadlevel + dec a ;K_EXIT + ret z + cp K_ENTER-K_EXIT+256 + jr nz,levselect + +loadlevel: + ld a,c + ex de,hl ;ahl=cde + inc b ;b=titlesize+1 +skiptitle: + cal _INC_PTR_AHL + dnz skiptitle + + cal _Get_Word_ahl + ld (leveldataSize),de + ld d,8 ;counter + ld bc,datalevels-2 + cal loadgametype + ld (hilvlposa),a + ld (hilvlposhl),hl + ld d,4 + cal loadgametype cal _SET_ABS_SRC_ADDR xor a @@ -180,8 +321,9 @@ leveldataSize =$-2 cal _mm_ldir cal _LOAD_ABS_SRC_ADDR ;->ahl - ld (hisaveposa),a - ld (hisaveposhl),hl +levelloaded: + ld (hiscrposa),a + ld (hiscrposhl),hl cal _RAM_PAGE_1 ;&&& res 2,(iy+13) ;appAutoScroll @@ -219,78 +361,105 @@ NegativeSineWave: ;---------- menu ------------- ;----------------------------- + ld a,1 + ld (curlevel),a DisplayMenu: - ld a,2 - ld (nrworms),a -gomainMenu: cal _clrWindow - ld hl,txtWelcome - cal _puts - ld de,$0205 + ld de,$FC42 ;(10,2) + ld hl,wtPicture + ld a,16 ;height +disptitleloop: + ld bc,8 ;width + ldir + ex de,hl + ld bc,8 ;next line + add hl,bc + ex de,hl + dec a + jr nz,disptitleloop + + ld hl,txtMenu + ld de,$0D5A + ld (_penCol),de + cal _vputs ;by Shiar + ld de,$0207 + ld (_curRow),de + cal _puts ;--- + dec e ;$0206 ld (_curRow),de - cal _puts ;txtOptions + cal _puts ;Level <00> + dec e ;$0205 + ld (_curRow),de + cal _puts ;Worms <2> dec e ;$0204 ld (_curRow),de ld hl,(CURtxtGame) - cal _puts + cal _puts ;Singleplayer xor a + cal menudraw + jr howmanyworms mainMenu: cal menucall jr nz,notselect select: ld a,b - or a - jr nz,gooptionsMenu - jp LetsGetThisPartyOn + dec a ;2nd item + jp z,changeworms + jp LetsGetThisPartyOn ;1/3/4 notselect cp K_EXIT jp z,ExitNoStats + cp K_LEFT + jr z,selleft cp K_RIGHT ld a,b jr nz,mainMenu or a - jr z,Variation + jr z,changegame + dec a + jr z,changenrworms + dec a + jp nz,LetsGetThisPartyOn -gooptionsMenu: - cal _clrWindow - ld hl,txtWelcome - cal _puts - ld hl,txtLevel - ld de,$0205 - ld (_curRow),de - cal _puts ;txtLevel - dec e ;$0204 - ld (_curRow),de - cal _puts ;txtWorms - ld a,(nrworms) - add a,'0' - cal _putc - xor a -optionsMenu: - cal menucall - jr nz,notopselect -opselect: - ld a,b - or a - jr nz,changelevel -changeworms: - ld hl,nrworms - inc (hl) - ld a,4 - cp (hl) - jr nc,gooptionsMenu - ld (hl),2 - jr gooptionsMenu changelevel: - jr optionsMenu -notopselect: - cp K_EXIT - jr z,gomainMenu + 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 + inc a + cp d + jr c,changedlevel + ld a,d +changedlevel: + ld (curlevel),a +_dispcurlevel: + ld hl,$0906 + ld (_curRow),hl + cal showA +_mainMenu: + jr mainMenu + +selleft: ld a,b - jr optionsMenu + dec a + jr z,bchangenrworms + dec a + jr nz,mainMenu + +bchangelevel: + ld a,(curlevel) + dec a + jr nz,changedlevel + jr mainMenu -Variation: +changegame: + ld a,1 + ld (curlevel),a ld a,0 Gametype =$-1 ld hl,txtGame2 @@ -306,53 +475,255 @@ okilydokily: ld (CURtxtGame),hl cal _puts ld (NEXTtxtGame),hl - ld a,b - jp mainMenu +howmanyworms: + ld hl,nrworms + ld a,(Gametype) + cp 2 + ld (hl),1 + jr c,dispnrworms + inc (hl) ;2 + jr dispnrworms ;mainMenu -menucall: - psh af - ld hl,$0004 - ld (_curRow),hl - ld a,' ' - cal _putc - ld hl,$0005 - ld (_curRow),hl - cal _putc - pop af - psh af - ld h,0 - add a,4 - ld l,a +changenrworms: + ld a,(Gametype) + cp 2 ;&& + jr c,_mainMenu ;type 0/1 + ld hl,nrworms + ld a,(hl) + inc a + cp 5 + jr nc,dispcurlevel +changednrworms: + ld (hl),a +dispnrworms: + ld a,(hl) ;hl=nrworms + ld hl,$0905 ld (_curRow),hl - ld a,'*' + add a,'0' cal _putc -menukeys: +dispcurlevel + ld a,(curlevel) + jr _dispcurlevel ;mainMenu + +bchangenrworms: + ld hl,nrworms + ld a,(hl) + dec a + cp 2 ;2-4 + jr nc,changednrworms + jr dispcurlevel + +menucall: + psh bc +menuwaitkey: halt \ halt cal GET_KEY or a - jr z,menukeys + jr z,menuwaitkey pop bc ;pop a as b cp K_UP - jr nz,notup -updown: - ld a,b - xor 1 - ld b,a - inc a ;nz - ret -notup: + cal z,menuup cp K_DOWN - jr z,updown + cal z,menudown cp K_ENTER ret z cp K_SECOND ret ;z=select +menupos: + ld a,b + add a,4 + ld h,0 + ld l,a + ld (_curRow),hl + ret +menuclr: + cal menupos + ld a,' ' + jp _putc +menudown: + cal menuclr + inc b + jr menuupdown +menuup: + cal menuclr + dec b +menuupdown: + ld a,b + and %11 ;4=0;-1=3 +menudraw: + ld b,a + cal menupos + ld a,'*' + jp _putc ;a=K_STO + +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' + + ld d,a ;1x + 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 + add ix,de + ld a,maxnamelength + cal entername + ld (ix),0 + jp DisplayMenu + +entername: + ld h,1 + ld l,h ;) + ld (_curRow),hl + ld (namelength),a +enternameloop: + ld a,'_' + cal _putc + ld hl,_curCol + dec (hl) +nokeypressed: + halt + cal GET_KEY + or a + jr z,nokeypressed + + cp K_DEL + jr nz,continue +backspace: + ld hl,namelength + ld a,(hl) + cp maxnamelength + jr nc,nokeypressed + inc (hl) + + dec ix + ld a,' ' + ld (ix),a + cal _putc + ld hl,_curCol + dec (hl) + dec (hl) + jr enternameloop +continue: + cp K_ENTER + ret z + cp K_EXIT + ret z + + ld hl,namelength + dec (hl) + ret z + + ld hl,chartable + ld e,a + ld d,0 + add hl,de + ld a,(hl) + or a + jr z,nokeypressed + + ld (ix),a + cal _putc + inc ix + cal waitnokeypressed + jr enternameloop + +waitnokeypressed: + halt + cal GET_KEY + or a + jr nz,waitnokeypressed + ret + +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 + +;--proc + +skiplevel: ;@hl - destr:ab - alter:hl + 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 + ld a,c + and _datasingl + jr nz,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 gamectf + jr nz,noflagstoskip + inc hl + inc hl + inc hl + inc hl +noflagstoskip: + + cal skiplines ;lines +skiplines: ;boxes + ld a,(hl) ;lines/boxes + add a,a + add a,a + inc a + ld b,a ;4x(hl)+1 + +skiplb + inc hl + dnz skiplb + ret + ;----------------------------- ;-------- start game --------- ;----------------------------- LetsGetThisPartyOn: + ld a,$17 ;no exit + ld (CheckExit),a ;set exit state + ld hl,gamesdata ld a,(Gametype) ld e,a @@ -365,13 +736,13 @@ LetsGetThisPartyOn: ld e,8 ;=de add hl,de - ld b,a ;psh af + ld c,a and _datasingl jr z,notsingle ld a,1 ld (nrworms),a notsingle: - ld a,b ;pop af \push + ld a,c and _datascore ld de,$FF64 ;virt.infinate jr z,setscorelimit @@ -380,8 +751,18 @@ setscorelimit: ld (scorelimit),de cal _ldHLind ;ld hl,(hl) - psh hl - ld a,b ;pop af + ld a,(curlevel) + ld (Level),a + ld d,a ;begin level +skiplevelloop: + dec d ;levels to skip + jr z,levelsskipped + cal skiplevel + jr skiplevelloop +levelsskipped: + + psh hl ;1st level + ld a,c and _datalink jr z,GameOver @@ -389,27 +770,32 @@ linkmatch: cal _clrWindow ld a,WormVersion cal send - jr c,client ;2nd + jr nc,client ;2nd host: ld hl,txtWaiting cal _puts cal receive cp WormVersion - jp nz,LinkBreak + jp nz,linkiniterror cal send - ld hl,SwapPos - ld (hl),$f6 jr multiplayer +linkiniterror: + pop hl + jp DisplayMenu + client: ld hl,txtReceive cal _puts - cal receive + cal Qreceive + jp c,linkiniterror cp WormVersion - jp nz,LinkBreak + jp nz,linkiniterror + ld hl,SwapPos + ld (hl),$f6 multiplayer: ld a,2 ld (nrworms),a @@ -432,32 +818,25 @@ GameOver: ld (worm2+score+1),hl ld (worm3+score+1),hl ld (worm4+score+1),hl - ld a,l - ld (Level),a - ld hl,worm1set+4 - ld de,worm1+lives -;&&&>* - cal _MOV5B ;9xld(de),(hl) - cal _mov9b - ld hl,worm2set+4 - ld de,worm2+lives - cal _MOV5B - cal _mov9b - ld hl,worm3set+4 - ld de,worm3+lives - cal _MOV5B - cal _mov9b - ld hl,worm4set+4 - ld de,worm4+lives - cal _MOV5B - cal _mov9b + ld hl,worm1set + ld de,worm1+head + ld a,4 ;4x (all worms) +createwormsloop: + ld bc,19 + ldir ;copy 19 bytes + ex de,hl + ld bc,head + add hl,bc + ex de,hl ;de=wormX+head + dec a ;loop + jr nz,createwormsloop ld a,(Gametype) cp 1 ;=peaworm jr nz,worminitdone - ld (worm1+lives),a ;&&&<* + ld (worm1+lives),a worminitdone: - pop hl + pop hl ;begin of current level StartLevel: ld de,Left @@ -474,8 +853,8 @@ waitsomemore: pop hl ;show end msg or smtn ld bc,Exit - psh bc ;where to go afterwards - inc hl ;location of ending-code + psh bc ;where to go afterwards + inc hl ;location of ending-code jp (hl) ;go there ("call") nextlevel: ldi @@ -495,7 +874,6 @@ nextlevel: inc hl or a jr z,defaultsprite - ld (sprsize),a ld d,h ld e,l ;ld de,hl ld c,a @@ -503,8 +881,10 @@ nextlevel: add hl,bc ;hl=behind sprite jr setsprite defaultsprite: + ld a,defsprsize ld de,peasprite setsprite: + ld (sprsize),a ld (spritepos),de ld a,(hl) @@ -512,36 +892,19 @@ setsprite: ld (nrballs),a or a jr z,toobad_noballs - ld de,ballpos - ldi - ldi + ld c,a + add a,a + add a,c + ld c,a + ld b,0 + ld de,balls + ldir toobad_noballs: -#ifdef 0 - ld a,(gameCar) - and _datahunt - jr z,nohunter - ld a,huntersize - ld (worm2+grow),a -nohunter: -#endif - ex de,hl +#ifndef invincible ld (thislevel),de - psh de - ld hl,worm1set - ld de,worm1+head - cal _MOV4B - ld hl,worm2set - ld de,worm2+head - cal _MOV4B - ld hl,worm3set - ld de,worm3+head - cal _MOV4B - ld hl,worm4set - ld de,worm4+head - cal _MOV4B - pop de +#endif ld hl,worm1 ld a,(gameCar) @@ -641,9 +1004,21 @@ NoVertShift: ld c,64 ldir -;-draw lines- pop hl ; << levelp + ld a,(Gametype) + cp gamectf + jr nz,noctf + ld de,peaspos + ld bc,4 + ldir + psh hl + cal DrawAllPeas + pop hl +noctf: + +;-draw lines- + ld a,(hl) inc hl or a @@ -700,6 +1075,27 @@ noboxes: nofood: ld bc,(worm1+pos) cal DisplayField + +#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 @@ -711,6 +1107,7 @@ nofood: ld hl,txtReady cal _puts res 3,(iy+5) +#endif ld a,0 gameCar =$-1 @@ -737,10 +1134,11 @@ SwapPos: ;$18 xx -> $F6 xx ld (worm2+heading),a initfinished: - ld b,0 + ld b,startdelay ReadyDelay: halt dnz ReadyDelay + cal releasekeys ;----------------------------- ;----------- LOOP ------------ @@ -776,7 +1174,10 @@ Delay: jr nz,Delay NoDelay: - cal handlethatneatlittleball + ld a,0 +nrballs =$-1 + or a + cal nz,handlethoseneatlittleballs ld ix,worm1 ld a,(nrworms) @@ -797,55 +1198,27 @@ HandleKeys: ld a,%10111111 out (1),a in a,(1) - rla ;[MORE]? - jr c,NotPaused + rla ;MORE? + jr c,CheckExit ld bc,$0103 out (c),b halt ;pause/off ld b,11 out (c),b -NotPaused: - rla ;[EXIT]? +CheckExit: + rla ;=$17 (c=EXIT-key) + ;or$A7 (c=0) jp c,GameLoop jr Exit WormDead: +#ifdef invincible + jp stopworm +#else ld a,2 ld (flashtime),a - - 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 - res resbit,h - psh hl - cal res4pixels - pop hl - inc (ix+grow) -DoesWormTailEqualsWormHead: - cal _cphlde - jr nz,removewormloop - - ld a,(gameCar) - and _datasingl - jr nz,safewormsizedone - ld a,0 -beginsize =$-1 - ld (ix+grow),a -safewormsizedone: - - ;de=ix+head - ld (ix+tail+1),d - ld (ix+tail),e - ld a,50 - ld (ix+delay),a + ld (ix+delay),respawndelay thislevel =$+1 ld de,0 @@ -868,6 +1241,10 @@ thislevel =$+1 ld a,(gameCar) and _datalivel ret z + ld a,$A7 ;exit@end of turn + ld (CheckExit),a ;set exit state + ret ;finish turn +#endif Exit: ld sp,0 ;pop all @@ -889,8 +1266,8 @@ CURtxtGame =$-2 xor a ld (_curCol),a - ld b,2 -nrworms =$-1 + ld a,(nrworms) + ld b,a ld hl,worm1+died displayWormStats: psh bc @@ -899,7 +1276,7 @@ displayWormStats: ld bc,input-died add hl,bc ;+input xor a - cp (hl) + cp (hl) ;input=0 = link jr nz,NoLinkIndic ld b,7 inc hl ;+left @@ -925,9 +1302,9 @@ NoLinkIndic: ld a,13 ld (_curCol),a ld a,(hl) ;worm+died - psh hl cal showA pop hl + psh hl ld a,16 ld (_curCol),a @@ -941,6 +1318,23 @@ NoLinkIndic: 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,0 +hilvlposhl =$-2 ;save external + cal _writeb_inc_ahl ;ld (ahl),c +hilevelcheckdone: + ld a,(gameCar) and _datasingl jr z,hiscorecheckdone @@ -976,13 +1370,16 @@ NotNewHigh: ;de=current hiscore cal showHL hiscorecheckdone: + cal releasekeys waitkey: halt halt cal GET_KEY cp K_ENTER jp z,DisplayMenu -; cp K_EXIT + cp K_SECOND + jp z,DisplayMenu + cp K_EXIT jr nz,waitkey ;x123456789012345678901 @@ -1012,46 +1409,85 @@ ExitNoStats: cal _SET_MM_NUM_BYTES cal _mm_ldir + cal releasekeys res 4,(iy+9) set 2,(iy+13) jp _clrWindow -loadhiscoreposinahl: - ld a,(Gametype) - dec a - jr nz,externalhiscoresavepos - ld a,0 - ld hl,hipeaworm - ret -externalhiscoresavepos: +loadhiscoreposinahl: + ld a,(Level) + ld b,a + ld a,(Gametype) + or a +externalhiscoresavepos: + ld a,0 +hiscrposa =$-1 + ld hl,0 +hiscrposhl =$-2 + ret z ;(Gametype)=0 +addlevelposition: + cal _AHL_PLUS_2_PG3 + dnz addlevelposition + ret + +;----------------------------- +;----------- 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) +DoesWormTailEqualsWormHead: + cal _cphlde + jr nz,removewormloop + + ld a,(gameCar) + and _datasingl + jr nz,safewormsizedone ld a,0 -hisaveposa =$-1 - ld hl,0 -hisaveposhl =$-2 - ret +beginsize =$-1 + ld (ix+grow),a +safewormsizedone: -;----------------------------- -;----------- worm ------------ -;----------------------------- + ;de=ix+head + ld (ix+tail+1),d + ld (ix+tail),e ;head=tail/size=0 + jr norespawn + ret -inlink: - ld a,0 -sendbyte =$-1 - ld b,(ix+left) - dec b - jr z,receivefirst - cal send - cal receive +unnamedlabel: + cp 1 + ld h,a + jr nz,saverespawncounter +respawndue: ld l,a - ret -receivefirst: - psh af - cal receive - ld l,a - pop af - psh hl - cal send - pop hl + cal inputcall + ld a,h ;previous + cp l ;changed? + ret z +saverespawncounter: + ld (ix+delay),a +norespawn: + ld a,(gameCar) + and _datalink + jr nz,inlink ret inkeys: ;use jp not call! @@ -1072,27 +1508,29 @@ notright: ld l,a ret -chkinput: - ld bc,donediddelydone - psh bc ;ret-dest. inputcall: ld a,(ix+input) or a jr nz,inkeys - jr inlink -respawncheck: - cp 1 - ld h,a - jr nz,saverespawncounter -respawndue: +inlink: + ld a,0 +sendbyte =$-1 + ld b,(ix+left) + dec b + jr z,receivefirst + cal send + cal receive ld l,a - cal inputcall - ld a,h ;previous - cp l ;changed? - ret z -saverespawncounter: - ld (ix+delay),h + ret +receivefirst: + psh af + cal receive + ld l,a + pop af + psh hl + cal send + pop hl ret ;------- handle worm --------- @@ -1100,10 +1538,10 @@ saverespawncounter: HandleWorm: ld a,(ix+delay) dec a - jr nz,respawncheck + jp nz,respawncheck ld l,(ix+heading) - jr chkinput + cal inputcall donediddelydone: ld a,l ld (sendbyte),a @@ -1115,6 +1553,18 @@ donediddelydone: ld e,(ix+pos2) ld d,(ix+pos2+1) + 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 + ;-------- move worm ---------- Wormmove: @@ -1173,27 +1623,19 @@ GotFour: Hitworm: ld a,(gameCar) ld h,a - and _datafood - jp z,WormDead + and _datadie + cal z,checkhitotherworm + ld a,h + and _datamultpeas ;&&bit + jr nz,multiple_peas ld a,h - and _datahunt - cal nz,checkhitotherworm + and _datafood + jp z,WormDead ;no food ld hl,0 PeaY =$-2 PeaX =$-1 - ld a,(sprsize) - inc a - ld d,a - ld a,b - sub h - inc a - cp d ;=(sprsize)+1 - jp nc,WormDead - ld a,c - sub l - inc a - cp d + cal chkpeahit jp nc,WormDead cal DrawPea ;remove pea ld a,(ix+grow) @@ -1207,30 +1649,112 @@ peagrowth =$-1 ld de,10 cal IncScore pop af - jr nz,still_alive_not_dead + jp nz,Drawworm ;continue ld a,(gameCar) and _datafoodl - jr z,still_alive_not_dead + 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 pop hl ; << levelp new - ld a,(gameCar) - and _datanextl - jp nz,StartLevel - jp Exit + jp StartLevel + +chkpeahit: ;hl=peapos + 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 + +flagcaptured: + psh hl + ld de,30 + cal IncScore + pop hl +sillylabel: + cal WormDead +DrawAllPeas: + ld hl,(peaspos) + cal DrawPea + ld hl,(peaspos+2) + jp DrawPea + +multiple_peas: + ld hl,(peaspos) ;1st pea + psh hl + ld a,(ix+reserv) + ld e,a ;push a + and %01 + jr nz,sel_ownpea + ld hl,(peaspos+2) ;2nd pea +sel_ownpea: + cal chkpeahit + pop hl ;(peapos) 1st pea + jp c,stopworm ;own pea hit + + ld a,e ;peek a (that x86 asm for pop\push ;) + and %01 + jr z,sel_otherpea + ld hl,(peaspos+2) ;2nd pea +sel_otherpea: + cal chkpeahit + jp c,hitflag + +;no peas hit + ld a,e + cal flagtoken + jp z,WormDead + ld b,a ;%10 + srl b ;%01 + add a,b ;%11 + ld (ix+reserv),a + cal DrawPea ;restore own flag + jr sillylabel ;inv both\die + +hitflag: ;correct pea hit + ld a,e ;pop a + xor %01 ;0=1;1=0 + ld (ix+reserv),a + cal flagtoken + psh af ;safe z-flag + cal DrawPea ;remove + pop af + jr z,flagcaptured + jr stopworm + +flagtoken: + and %01 ;current + add a,a ;<< for cp + ld b,a ;in b + ld a,e + and %10 ;own + cp b ;same? + ret ;Z=yes: no flag taken ;----------------------------- -checkhitotherworm: - .db $dd,$7d ;ld a,lx - cp worm2&255 - ret nz -ThisIsJustASillyUselessLabel: - ld hl,(worm1+tail) - ld de,(worm1+head) nextotherwormbit: ld a,c sub (hl) @@ -1242,13 +1766,14 @@ nextotherwormbit: sub (hl) inc a cp 4 - jr c,otherwormHIT ;yes + ret c ;nz ;yes nothit1: inc hl - res resbit,h + cal resbit +ChkWorm: cal _cphlde jr nz,nextotherwormbit - ret + ret ;z checkhitlapline: ld a,63 @@ -1271,29 +1796,44 @@ nolap: ld (ix+reserv),a ret -otherwormHIT: - psh ix - ld de,10 - cal IncScore +checkhitotherworm: + .db $dd,$7d ;ld a,lx + cp worm2&255 + psh ix + jr nz,chkworm2 ; ret nz ld ix,worm1 - cal WormDead - pop ix - pop bc -still_alive_not_dead: + 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 ;-------- draw worm ---------- Drawworm: - ld a,(gameCar) - and _datahunt - cal nz,HuntingTimeScore - ld c,(ix+pos) ld b,(ix+pos+1) - ld a,(gameCar) - and _datalaps - cal nz,checkhitlapline + ld a,(Gametype) + cp gamerace + cal z,checkhitlapline ld l,(ix+head) ld h,(ix+head+1) @@ -1301,7 +1841,7 @@ Drawworm: inc hl ld (hl),b inc hl - res resbit,h + cal resbit ld (ix+head),l ld (ix+head+1),h @@ -1320,7 +1860,7 @@ removetail: inc hl ld b,(hl) inc hl - res resbit,h + cal resbit ld (ix+tail),l ld (ix+tail+1),h @@ -1342,34 +1882,68 @@ ResPixel: ;---------- ball ------------- ;----------------------------- -handlethatneatlittleball: - ld a,0 -nrballs =$-1 - or a - ret z -ballpos =$+1 - ld bc,$0503 +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 - ld e,b + ballxmove: - inc b ;=%000100 dec=%000101 + 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,ballxdone - ld b,e - ld hl,ballxmove - cal letsmovetheotherway -ballxdone: - ld e,c + jr z,ballymove + dec b ;back + set 0,d ;>left + ballymove: - inc c ;=%001100 dec=%001101 + bit 1,d ;1=up; 0=down + jr z,balldown +ballup: + dec c cal checkballhit jr z,balldone - ld c,e - ld hl,ballymove - cal letsmovetheotherway + inc c + res 1,d ;go down + jr balldone +balldown: + inc c + cal checkballhit + jr z,balldone + dec c + set 1,d ;up balldone: - ld (ballpos),bc set4pixels: ;@(b,c) cal SetPixel @@ -1391,16 +1965,34 @@ letsmovetheotherway: 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) @@ -1452,30 +2044,37 @@ DrawPea: ;hl=(PeaY) ld c,l ld de,peasprite spritepos =$-2 - cal PutSprite ;||-ed - ret + jp PutSprite ;||-ed ;----------- score ----------- -HuntingTimeScore: - .db $dd,$7d ;ld a,lx - cp worm2&255 - ret z ;=worm#2 - dec (ix+reserv) - ret nz - ld de,10 +_divHLby1000: + psh hl + ld b,3 +divideagain: ;3x + cal _divHLby10 + dnz divideagain + ld a,l ;a=hl/1000 + pop hl + ret IncScore: ld h,(ix+score+1) ld l,(ix+score) + cal _divHLby1000 + ld c,a add hl,de + 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 - ret c + jr c,showstats ;<0=0 scorecommon: ld (ix+score+1),h ld (ix+score),l @@ -1642,10 +2241,10 @@ NotMaxYScroll: jr nc,NotMinXScroll xor a NotMinXScroll: - cp 128 + cp 128 FieldWidth = $-1 - jr c,NotMaxXScroll - ld a,(FieldWidth) + jr c,NotMaxXScroll + ld a,(FieldWidth) NotMaxXScroll: psh af ; >> 3 and %11111000 @@ -1663,7 +2262,7 @@ NotMaxXScroll: inc c CopyScreen: add hl,bc - ld b,57 + ld b,57 CopyScreenLoop: psh bc ; >> 4 ld bc,16 @@ -1718,10 +2317,12 @@ Bit7: 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 @@ -2061,6 +2662,13 @@ boxloop: TIMEOUT = $1000 +LinkBreak: + pop hl + ld a,D0HD1H + out (7),a + jp Exit + + receive: cal GET_KEY cp K_EXIT @@ -2069,13 +2677,17 @@ receive: and %11 cp %11 jr z,receive - cal Qreceive + in a,(7) + and %11 + cp %11 + jr z,receive + ld b,8 + cal ReceiveCont jr c,receive ret Qreceive: ld b,8 - jr ReceiveCont receiveloop: ld de,TIMEOUT WaitRecBit: @@ -2084,16 +2696,16 @@ WaitRecBit: cp %11 jr z,WaitRecBit ReceiveCont: - sub 2 - ld a,2 + sub %10 + ld a,%10 ld d,D0LD1H jr c,ReceiveLow rra ld d,D0HD1L ReceiveLow: - rr c - ld (AckBit),a - ld a,d + rr c + ld (AckBit),a + ld a,d out (7),a ld de,TIMEOUT WaitAckRec: @@ -2112,13 +2724,15 @@ WaitReadyRec: jr nz,WaitReadyRec ReadyRec: dnz receiveloop - jr LinkSuccess + ld a,c + ret send: - ld b,9 ld c,a + ld b,8+1 jr SendAcked -SendBits: + +sendloop: rr c ld a,D0LD1H jr nc,SendLow @@ -2137,19 +2751,13 @@ WaitReadySend: cal CheckLink cp %11 jr nz,WaitReadySend - dnz SendBits + dnz sendloop LinkSuccess: - ld a,c ;pop a - ret - + .db $F6 ;or NN (skip scf) LinkFailed: scf - ld a,c + ld a,c ret -LinkBreak: - ld a,D0HD1H - out (7),a - jp Exit CheckLink: pop hl @@ -2160,19 +2768,19 @@ CheckLink: ld a,$BF out (1),a - nop \ nop +; nop \ nop in a,(1) psh af ld a,%11111111 out (1),a pop af bit 6,a + jr z,LinkFailed in a,(7) and %11 jp (hl) - ;----------------------------- ;---------- levels ----------- ;----------------------------- @@ -2196,6 +2804,41 @@ LevelDefM: ;---------- data ------------- ;----------------------------- +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 "Have fun!",0 ;4th menu item + .db "Level ",$CF,"??",5,0 ;3rd + .db "Worms ",$CF,"?",5,0 ;2nd +txtGame: .db "Singleplayer",0 ;0 (1st) +txtGame2: .db "Peaworm ",0 ;1 (next 1st) + .db "Deathmatch",0 ;2 + .db "Foodmatch ",0 ;3 + .db "LinkMatch",0 ;4 + .db "Race ",0 ;5 + .db "CTF ",0 ;6 + .db "Domination",0 ;7 +txtLevsel: .db $CF," Select levels: ",5,0 +txtName: .db "Enter name player ",0 +txtWaiting: .db "Waiting...",0 +txtReceive: .db "Receiving..." ;,0 + TrigPrecalc: .db 0, 3, 6, 9, 12, 15, 18, 21 .db 24, 27, 30, 33, 36, 39, 42, 45 @@ -2207,21 +2850,6 @@ TrigPrecalc: .db 124,125,125,126,126,126,126,126 .db 127 -txtWelcome: .db "Welcome to Worm!! ", - .db "by Shiar",0 -txtOptions: .db "Options",0 -txtGame: .db "Singleplayer",0 ;0 -txtGame2: .db "Peaworm ",0 ;1 - .db "Deathmatch",0 ;2 - .db "Foodmatch ",0 ;3 - .db "LinkMatch",0 ;4 (>options) - .db "Hunting ",0 ;5 - .db "Race ",0 ;6 - .db "CTF ",0 ;7 - .db "Domination",0 ;(>=8) -txtWaiting: .db "Waiting...",0 -txtReceive: .db "Receiving...",0 - txtLevel: .db "Level ",0 txtWorms: .db "Worms: 0",0 ;follows txtLevel txtDied: .db "Died ",0 @@ -2234,81 +2862,87 @@ txtGO: .db "----- GAME OVER -----",0 gamesdata: -_datalink = %00000001 -_datalivel = %00000010 ;ix+lives=0 limit +_datalink = %00000001 ;linkplay +_datalivel = %00000010 ;lives=0 limit _datafoodl = %00000100 ;left=0 limit _datanextl = %00001000 ;next level if left=0 _datasingl = %00001000 ;singleplayer=1 _datafood = %00010000 ;food present -_datahunt = %00100000 -_datalaps = %01000000 ;give lap score +_________ = %00100000 ; +_datadie = %01000000 ;worm dies on impact _datascore = %10000000 ;score>=100 limit +_datamultpeas = %00100000 + +gamesingle = 0 +datasingle: .db %01011110 +gamepeas = 1 +datapeas: .db %01011010 +gamedeathm = 2 +datadeathm: .db %01000010 +gamefoodm = 3 +datafoodm: .db %11010000 +gamelinkm = 4 +datalinkm: .db %01000011 +gamerace = 5 +datarace: .db %10000000 +gamectf = 6 +datactf: .db %11100000 +gamedomin = 7 +datadomin: .db %01000000 ;==(8 modes) -datasingle: .db %00011110 -datapeas: .db %00011010 -datadeathm: .db %00000010 -datafoodm: .db %10010000 -datalinkm: .db %00000011 -datahuntin: .db %10100000 -datarace: .db %11000000 -datactf: .db %00000000 ;==(8 modes) -;datadomin: .db %00000000 datalevels: .dw LevelDef, LevelDef .dw LevelDefM,LevelDefM .dw LevelDefM,LevelDefM .dw LevelDefM,LevelDefM +nrlevels: .db 2,2,2,2,2,2,2,2 worm1set: .dw worm1p,worm1p - .db 3,0,%01111110,%10,%100 ;< > -worm1name: .db "Worm #1 ",0 + .db %11110111,3,%00,%01111110,%10,%100 ;< > +worm1name: .db "worm #01",0 worm2set: .dw worm2p,worm2p - .db 3,0,%00111111,%10000,%1000 ;f1 f2 -worm2name: .db "Worm #2 ",0 + .db %11111011,3,%11,%00111111,%10000,%1000 ;f1 f2 +worm2name: .db "worm #02",0 worm3set: .dw worm3p,worm3p - .db 3,0,%01011111,%10,%100 ;sto , -worm3name: .db "Worm #3 ",0 + .db %11111011,3,0,%01011111,%10,%100 ;sto , +worm3name: .db "worm #03",0 worm4set: .dw worm4p,worm4p - .db 3,0,%01111101,%10,%1 ;enter + -worm4name: .db "Worm #4 ",0 + .db %11111011,3,0,%01111101,%10,%1 ;enter + +worm4name: .db "worm #04",0 -hipeaworm: .dw 0 end: -;sprsize = 7 -;peasprite: .db %00111000 -; .db %01110100 -; .db %11111010 -; .db %11111110 -; .db %11111110 -; .db %01111100 -; .db %00111000 - -sprsize: .db 5 -peasprite: .db %01110000 - .db %11101000 - .db %11111000 - .db %11111000 - .db %01110000 - - ;set: -heading = 0 ;level* -pos = 2 ;level* -pos2 = 4 ;level -grow = 6 ;level -died = 8 ;game -score = 9 ;game -delay = 11 ;game - -head = 12 ;level -tail = 14 ;level -lives = 16 ;game -reserv = 17 ;loop +defsprsize = 4 +sprsize: .db 4 +peasprite: .db %01100000 + .db %11110000 + .db %11110000 + .db %01100000 + + ;set: +heading = 0 ;level* +pos = 2 ;level* +pos2 = 4 ;level +grow = 6 ;level +died = 8 ;game +score = 9 ;game +delay = 11 ;game + ;19B @game +head = 12 ;4B (head=tail) +tail = 14 ;also@next level +storepos = 16 +lives = 17 +reserv = 18 ;loop ;race:lap - ;hunt:time -input = 18 ;& -left = 19 ;& -right = 20 ;& -name = 21 ;game + ;ctf:pea +input = 19 +left = 20 +right = 21 +name = 22 +wormsize = 31 + +startdelay = 30 +respawndelay = 30 +maxnamelength = 8+1 ;----------------------------- ;----------- end -------------