;-----------------------------
DisplayMenu: ;---draw menu---
+ cal linkok
cal _clrWindow
ld de,$FC40 ;(0,4)
ld hl,wtPicture
ld bc,16*16
ldir
+ ld hl,$FC00+$160
+ cal hr
+ ld hl,$FC00+$3E0
+ cal hr
ld hl,txtMenu
ld ix,posMenu
ld b,0 ;b=menu#
jr _dispmenusets ;mainMenu
+hr: ;draw horizontal line at hl
+ ld b,16
+hrloop:
+ ld (hl),-1
+ inc hl
+ dnz hrloop
+ ret
+
;--- menu loop ---
mainMenu:
cp wormVclient
jr z,client
cp wormVhost
- jr nz,linkiniterror
+ jr z,host
+ pop hl ;error
+ jp DisplayMenu ;return to menu
+
host:
ld c,wormVclient
cal Qsend
ld a,$18
jr multiplayer
-
-linkiniterror:
- pop hl
- jp DisplayMenu
-
client:
ld hl,txtReceive
cal _puts
ld a,$E6
multiplayer:
+; cal linkok
+ ld a,D0LD1L
+ out (7),a
ld (SwapPos),a
ld a,2
ld (nrworms),a
;-----------------------------
GameOver:
- ld a,%11000000
- out (7),a ;link normal
cal _clrLCD
ld hl,worm1set
ld de,worm1
and _datalink
jr z,initfinished ;no link
xor a
- ld (Speed),a ;max.speed
SwapPos: ;$18 xx -> $E6 xx
; jr xx -> and xx
jr sethost
setclient:
- ld (worm1+left),a ;worm 1 via link
+ ld (worm1+left),a ;worm 1...
+ ld (worm3+left),a ;and worm 3 via link
+ cal Crecv
+ ld a,c
+ ld (worm2+name+0),a
+ cal Crecv
+ ld a,c
+ ld (worm2+name+1),a
+ cal Crecv
+ ld a,c
+ ld (worm2+name+2),a
+ cal Crecv
+ ld a,c
+ ld (worm2+name+3),a
+ cal Crecv
+ ld a,c
+ ld (worm2+name+4),a
jr initfinished
sethost:
- ld (worm2+left),a ;worm 2 via link
+ ld (worm2+left),a ;worm 2+4..
+ ld (worm4+left),a ;..over link
+ ld c,'T'
+ cal Qsend
+ ld c,'e'
+ cal Qsend
+ ld c,'s'
+ cal Qsend
+ ld c,'t'
+ cal Qsend
+ ld c,0
+ cal Qsend
initfinished:
ld b,startdelay
jr nz,Delay
NoDelay:
+ ld hl,turn
+ dec (hl)
+ jr nz,nextturnok
+ ld (hl),3 ;2
+nextturnok:
+
ld (handledworm),a ;=0
ld a,0
Exit:
ld sp,0 ;pop all
SpSave = $-2
- ld a,D0HD1H
- out (7),a
+ ld a,D0LD1L
+ out (7),a ;both wires low = game over signal
cal _clrWindow
ld hl,txtGO
cal _puts
;8Snaky @ 00 04820
ExitNoStats:
+ cal linkok
ld hl,_asapvar
rst 20h ;_ABS_MOV10TOOP1
rst 10h ;_FINDSYM
saverespawncounter:
ld (ix+delay),a
jr inputcall
-; ld a,(ix+input)
-; or a
-; jr z,inlink
-; ret
chkkey: ;key=a
dec a
dnz keybit ;check match (cf set)
ret
+turnspeed = 8
inkeys: ;use jp not call!
cal chkkey
jr nc,notright
ld a,l
- add a,8
+ add a,turnspeed
ld l,a
notright:
ld a,(ix+right)
cal chkkey
ret nc
ld a,l
- sub 8
+ sub turnspeed
ld l,a
ret
inputcall:
and _datalink
ret z ;no link
ld c,l ;send our keys
- psh hl
- cal Qsend ;Csend
- pop hl
- ret
+ jp Qsend
inlink:
- psh hl
cal Qrecv ;Crecv
- pop hl
ld l,c
ret
jp nz,respawncheck
ld a,(Gametype)
+ cp gamedeathm ;&&&sub
+ jr nz,nogrow
+ ld a,1 ;xor a
+ cp 0 ;a=0
+turn =$-1
+ jr nz,nogrow
+ inc (ix+grow)
+nogrow:
+
cp gametron
jr nz,notron
ld de,1
-;**** 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 ------------
;-----------------------------
-timeout = $800
+linkok:
+ ld a,D0HD1H
+ out (7),a ;raise both wires = link ok
+ ret
-checklink:
- dec de
+timeout = $8000
+lossout = 20
+
+checklink: ;load wires in A and check for timeout
+ dec de ;decrease timer
ld a,d
or e
- jr z,linkerror
-
- ld a,$BF
- out (1),a
- in a,(1)
- bit 6,a
- jp z,Exit
-
+ jr nz,linkfine ;ok if de>0
+;de==0 = timeout
+ cal linkok
+ ld a,0 ;losses so far
+linklosses =$-1
+ inc a ;and this is another one
+ ld (linklosses),a
+ pop de ;return from link
+ cp lossout ;quit if too many errors
+ ret c ;otherwise just continue
+linkerr:
+ jp Exit
+linkfine:
in a,(7)
and %11
ret
-linkerror:
- scf
- ld a,%11
- pop hl
- ret
-
;--------------
;---- SEND ----
;--------------
-Csend: ;--- send 8 bits in A --- destr:abcdehl ---
- ld c,a
-Csendloop:
+Csend:
+ ld b,32
+csendwait:
+ nop
+ dnz csendwait
cal Qsend
- ret nc ;NC = all ok
- ld a,D0HD1H
- out (7),a ;both high
- jr Csendloop ;CF = error
+ jr c,Csend
+ ret
-Qsend: ;--- try to send 8 bits in C; CF=error --- destr:abcdehl ---
- ld de,timeout
- cal checklink
- cp %11 ;are they?
- scf
- ret nz ;nope, wait
+Qsend: ;try to send 8 bits in C; CF=error --- destr:abcde
+ in a,(7)
+ and %11 ;both wires low = exit signal
+ jr z,linkerr ;error otherwise
ld b,8 ;bits to send
sendloop:
ld de,timeout
cal checklink
cp %11 ;both raised (by other calc)
jr nz,sendfinish
- nop \ nop
+; nop \ nop
dnz sendloop ;repeat for all bits
xor a ;nc...
+ ld (linklosses),a ;reset number of losses
ret ;=ok
;--------------
Crecv: ;--- receive 8 bits into A/C --- destr:abcdehl ---
cal Qrecv
ret nc ;return if all went ok
- ld a,D0HD1H
- out (7),a ;raise both on error
jr Crecv ;and try again
-Qrecv: ;--- receive 8 bits into A/C; CF=error --- destr:abcdehl ---
- ld de,timeout
- cal checklink
- jp z,Exit ;both low = error, quit
- cp %11
- scf
- ret z ;both high = nothing yet, wait
+Qrecv: ;--- receive 8 bits into A/C; CF=error --- destr:abcde ---
+ in a,(7)
+ and %11
+ jr z,linkerr ;both low = error, quit
ld b,8 ;bits to receive
recvloop:
ld de,timeout
recvfinish:
dnz recvloop ;repeat for all bits
xor a ;nc=no error
- ld a,c ;result in a
+ ld (linklosses),a ;reset number of losses
ret
-#endif
+
;-----------------------------
;---------- levels -----------
gamefoodm = 4
datafoodm: .db %11010000,10,2,1 ;10 score limit (=100)
gamelinkm = 5
-datalinkm: .db %01000011,3,2,1
+datalinkm: .db %11010001,3,2,1
gamerace = 6
datarace: .db %10000000,10,2,1
gamectf = 7