X-Git-Url: http://git.shiar.nl/wormy.git/blobdiff_plain/7ec10d8466fbe267a3d0a8fe8fbfaed79adbf07f..c23eda222bb4317abd8f9fd9e197aa6118c503c3:/worm.z80 diff --git a/worm.z80 b/worm.z80 index a5cdab9..22e6fec 100644 --- a/worm.z80 +++ b/worm.z80 @@ -78,6 +78,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 ;----------------------------- ;------- data storage ------- @@ -777,26 +778,61 @@ host: cal _puts cal receive cp WormVersion - jp nz,linkiniterror +; jp nz,linkiniterror cal send + jr c,linkiniterror +; cal sendname +; cal receivename + + ld a,$18 jr multiplayer linkiniterror: pop hl jp DisplayMenu +sendname: + ld hl,worm1+name + ld b,maxnamelength +sendnameloop: + ld a,(hl) + inc hl + psh bc + psh hl + cal send + pop hl + pop bc +; dnz sendnameloop + ret +receivename: + ld hl,worm2+name + ld b,maxnamelength +recvnameloop: + psh bc + psh hl + cal receive + pop hl + pop bc + ld (hl),a + inc hl +; dnz recvnameloop + ret + client: ld hl,txtReceive cal _puts cal Qreceive jp c,linkiniterror cp WormVersion - jp nz,linkiniterror +; jp nz,linkiniterror - ld hl,SwapPos - ld (hl),$f6 +; cal receivename +; cal sendname + + ld a,$f6 multiplayer: + ld (SwapPos),a ld a,2 ld (nrworms),a @@ -806,29 +842,25 @@ multiplayer: GameOver: cal _clrLCD - ld hl,0 - ld (worm1+died),hl -;+died=0 \ +score1=0 - ld (worm2+died),hl - ld (worm3+died),hl - ld (worm4+died),hl - inc h - ld (worm1+score+1),hl -;+score2=0 \ +delay=1 - ld (worm2+score+1),hl - ld (worm3+score+1),hl - ld (worm4+score+1),hl ld hl,worm1set - ld de,worm1+head + ld de,worm1 ld a,4 ;4x (all worms) createwormsloop: - ld bc,19 - ldir ;copy 19 bytes ex de,hl - ld bc,head + ld bc,died add hl,bc - ex de,hl ;de=wormX+head - dec a ;loop + ld (hl),0 ;died=0 + inc hl + ld (hl),0 ;score=0 + inc hl + ld (hl),0 ;score+1=0 + inc hl + ld (hl),2 ;delay=2 + inc hl + ex de,hl ;de=wormX+head + ld bc,19 + ldir ;copy 19 bytes + dec a ;loop jr nz,createwormsloop ld a,(Gametype) @@ -845,10 +877,7 @@ StartLevel: jp nz,nextlevel psh hl - ld b,150 -waitsomemore: - halt - dnz waitsomemore + cal releasekeys cal _clrWindow pop hl ;show end msg or smtn @@ -1112,26 +1141,26 @@ maskline: ld a,0 gameCar =$-1 and _datalink - jr z,SwapPos ;no link + jr z,initfinished ;no link + xor a - ld (worm2+input),a + ld (worm2+input),a ;worm 2 via link ld (worm2+left),a - ld (Speed),a - + ld (Speed),a ;max.speed SwapPos: ;$18 xx -> $F6 xx + ; jr xx -> or xx jr initfinished inc a - ld (worm2+left),a - ld hl,(worm1+pos) - ld de,(worm2+pos) - ld (worm2+pos),hl - ld (worm1+pos),de - ld a,(worm1+heading) - ld b,a - ld a,(worm2+heading) - ld (worm1+heading),a - ld a,b - ld (worm2+heading),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 initfinished: ld b,startdelay @@ -1249,6 +1278,8 @@ thislevel =$+1 Exit: ld sp,0 ;pop all SpSave = $-2 + ld a,D0HD1H + out (7),a cal _clrWindow ld hl,txtGO cal _puts @@ -1278,11 +1309,11 @@ displayWormStats: xor a cp (hl) ;input=0 = link jr nz,NoLinkIndic - ld b,7 + ld b,7 ;{DOWN} inc hl ;+left cp (hl) jr z,hostLinkIndic - dec b + dec b ;{UP} hostLinkIndic: ld a,8 ld (_curCol),a @@ -1469,7 +1500,6 @@ safewormsizedone: ;de=ix+head ld (ix+tail+1),d ld (ix+tail),e ;head=tail/size=0 - jr norespawn ret unnamedlabel: @@ -1479,16 +1509,19 @@ unnamedlabel: respawndue: ld l,a cal inputcall + ld (sendbyte),a ld a,h ;previous cp l ;changed? ret z + ld (ix+delay),a ;=0 + ret saverespawncounter: ld (ix+delay),a -norespawn: - ld a,(gameCar) - and _datalink - jr nz,inlink - ret + jr inputcall +; ld a,(ix+input) +; or a +; jr z,inlink +; ret inkeys: ;use jp not call! out (1),a ;nop\nop @@ -1519,13 +1552,17 @@ sendbyte =$-1 ld b,(ix+left) dec b jr z,receivefirst + psh hl cal send cal receive + pop hl ld l,a ret receivefirst: psh af + psh hl cal receive + pop hl ld l,a pop af psh hl @@ -1671,6 +1708,7 @@ peagrowth =$-1 pop hl ; << call pop hl ; << call pop hl ; << levelp new + ld (ix+delay),2 jp StartLevel chkpeahit: ;hl=peapos @@ -2662,125 +2700,109 @@ boxloop: TIMEOUT = $1000 -LinkBreak: +checklink: pop hl - ld a,D0HD1H - out (7),a - jp Exit + dec de + ld a,d + or e + jr z,LinkFailed + ld a,$BF + out (1),a +; nop \ nop + in a,(1) + psh af + ld a,%11111111 + out (1),a + pop af + bit 6,a + jp z,Exit -receive: - cal GET_KEY - cp K_EXIT - jp z,LinkBreak in a,(7) and %11 - cp %11 + jp (hl) + +;-------------- +;---- SEND ---- 8 bits in a +;-------------- destr:bcdehl +send: + ld c,a + ld b,8+1 ;bits to send + jr checksend +sendloop: + rr c ;bit to send (in cf) + ld a,D0LD1H ;0: lower white + jr nc,sendbit + ld a,D0HD1L ;1: lower red +sendbit: + out (7),a ;lower one (send bit) + ld de,TIMEOUT +waitacksend: + cal checklink ;other calc must lower other whire + jr nz,waitacksend +checksend: + ld a,D0HD1H ;ok to raise both + out (7),a + ld de,TIMEOUT +finishsend: + cal checklink + cp %11 ;both raised (by other calc) + jr nz,finishsend + dnz sendloop ;repeat for all bits + .db $F6 ;or NN ;nc +LinkFailed: + scf ;c=error + ret + +;-------------- +;---- RECV ---- 8 bits to a +;-------------- destr:bcdehl +receive: + halt ;&&& + ld de,TIMEOUT + cal checklink jr z,receive - in a,(7) - and %11 cp %11 jr z,receive - ld b,8 - cal ReceiveCont + cal Qreceive jr c,receive ret Qreceive: - ld b,8 + ld b,8 ;bits to receive receiveloop: ld de,TIMEOUT WaitRecBit: - cal CheckLink - jr z,LinkFailed + cal checklink + jr z,LinkFailed ;both low = error cp %11 - jr z,WaitRecBit -ReceiveCont: - sub %10 + jr z,WaitRecBit ;both on = nothing sent +recvbit: + rra ;received bit in cf ld a,%10 ld d,D0LD1H - jr c,ReceiveLow - rra - ld d,D0HD1L -ReceiveLow: - rr c + jr c,savebit ;lower white as well + rra ;ld a,%01 + ld d,D0HD1L ;lower red +savebit: + rr c ;save bit ld (AckBit),a ld a,d - out (7),a + out (7),a ;lower other (both low) ld de,TIMEOUT -WaitAckRec: - cal CheckLink +waitackrecv: + cal checklink +; jr z,waitackrecv ;wait for one to go high cp 0 AckBit =$-1 - jr nz,WaitAckRec - ld a,D0HD1H - out (7),a - ld d,4 -WaitReadyRec: - dec d - jr z,ReadyRec - in a,(7) - cp %11 - jr nz,WaitReadyRec -ReadyRec: - dnz receiveloop - ld a,c - ret - -send: - ld c,a - ld b,8+1 - jr SendAcked - -sendloop: - rr c - ld a,D0LD1H - jr nc,SendLow - ld a,D0HD1L -SendLow: - out (7),a - ld de,TIMEOUT -WaitAckSend: - cal CheckLink - jr nz,WaitAckSend -SendAcked: + jr nz,waitackrecv ld a,D0HD1H - out (7),a - ld de,TIMEOUT -WaitReadySend: - cal CheckLink - cp %11 - jr nz,WaitReadySend - dnz sendloop -LinkSuccess: - .db $F6 ;or NN (skip scf) -LinkFailed: - scf - ld a,c + out (7),a ;raise both + dnz receiveloop ;repeat for all bits + or a ;nc + ld a,c ;a=byte received ret -CheckLink: - pop hl - dec de - ld a,d - or e - jr z,LinkFailed - - ld a,$BF - out (1),a -; 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 ----------- ;-----------------------------