worm 0.90.0505: ctf improvements, link development
authorMischa Poslawsky <wormy@shiar.org>
Fri, 5 May 2000 13:14:56 +0000 (15:14 +0200)
committerMischa Poslawsky <wormy@shiar.org>
Sun, 22 Feb 2009 15:19:33 +0000 (16:19 +0100)
worm.z80

index b4b4373104cca44d88adf7a46617005fb310b216..e254d012d063c96727d3aa5d2ee3af3eb4277e19 100644 (file)
--- a/worm.z80
+++ b/worm.z80
@@ -20,9 +20,9 @@
 
 ;  3% * linkplay
 ;  2% * make linkplay available for all gametypes (not just deathmatch)
-;     * 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% * fix pea XOR problem in ctf (+dom?)
+;  1% * domination?: take control points by running over them and hold them
+;     * customizable keys
 ;     * complete readme (+custom level info)
 ;  2% * ... (pollish, &&&)
 
@@ -722,7 +722,7 @@ linkmatch:
   cal _clrWindow
   ld  a,WormVersion
   cal send
-  jr  c,client ;2nd
+  jr  nc,client ;2nd
 
 host:
   ld  hl,txtWaiting
@@ -732,17 +732,18 @@ host:
   jp  nz,LinkBreak
   cal send
 
-  ld  hl,SwapPos
-  ld  (hl),$f6
   jr  multiplayer
 
 client:
   ld  hl,txtReceive
   cal _puts
-  cal receive
+  cal ReceiveByte
+  jp  c,LinkBreak
   cp  WormVersion
   jp  nz,LinkBreak
 
+  ld  hl,SwapPos
+  ld  (hl),$f6
 multiplayer:
   ld  a,2
   ld  (nrworms),a
@@ -1008,7 +1009,7 @@ noboxes:
   ld  (peaspos),hl
   cal DrawPea
   ld  hl,$2010
-  ld  (peaspos+3),hl
+  ld  (peaspos+2),hl
   cal DrawPea
 noctf:
   ld  a,(gameCar)
@@ -1605,37 +1606,65 @@ flagcaptured:
   ld  de,30
   cal IncScore
   pop hl
+sillylabel:
   cal WormDead
 DrawAllPeas:
   ld  hl,(peaspos)
   cal DrawPea
-  ld  hl,(peaspos+3)
+  ld  hl,(peaspos+2)
   jp  DrawPea
 
 multiple_peas:
-  ld  hl,(peaspos)
+  ld  hl,(peaspos) ;1st pea
+  psh hl
   ld  a,(ix+reserv)
   ld  e,a ;push a
   and %01
-  jr  nz,corrrectpea
-  ld  hl,(peaspos+3)
-corrrectpea:
+  jr  nz,sel_ownpea
+  ld  hl,(peaspos+2) ;2nd pea
+sel_ownpea:
   cal chkpeahit
-  jp  nc,WormDead
+  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
-  and %01
-  add a,a
-  ld  b,a
-  ld  a,e
-  and %10
-  cp  b
+  cal flagtoken
   psh af ;safe z-flag
   cal DrawPea ;remove
   pop af
   jr  z,flagcaptured
-  jr  Drawworm
+  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
 
 ;-----------------------------
 
@@ -1699,8 +1728,9 @@ chkworm:
  pop ix
   ret z ;not hit
   pop bc ;call
-previouspos =$+1
+stopworm:
   ld  bc,0
+previouspos =$-2
   ld  de,0
   ld  (ix+pos),c
   ld  (ix+pos+1),b
@@ -2533,6 +2563,7 @@ boxloop:
 ;----------- link ------------
 ;-----------------------------
 
+#ifdef 0
 TIMEOUT = $1000
 
 receive:
@@ -2645,6 +2676,175 @@ CheckLink:
   in  a,(7)
   and %11
   jp  (hl)
+#endif
+
+LinkBreak:
+  pop hl
+  ld  a,D0HD1H
+  out (7),a
+  jp  DisplayMenu
+
+
+receive:
+  cal GET_KEY
+  cp  K_EXIT
+  jp  z,LinkBreak
+  cal TryReceiveByte
+  jr  c,receive
+  ret
+
+
+LINKPORT =7
+TIMEOUT =$1000
+LINKMASK =3
+
+LinkPrep:
+        ex (sp),hl
+        push bc
+        push de
+;        ld b,(iy+12h)
+;        push bc
+        set 2,(iy+12h)
+        ld b,8
+        jp (hl)
+
+TryReceiveByte:
+        in a,(LINKPORT)
+        and LINKMASK
+        cp LINKMASK
+        scf
+        ret z
+ReceiveByteCont:
+        call LinkPrep
+        jr ReceiveCont
+ReceiveByte:
+        call LinkPrep
+ReceiveBits:
+        ld de,TIMEOUT
+WaitRecBit:
+        call CheckLink
+        jr z,LinkFailed
+        cp LINKMASK
+        jr z,WaitRecBit
+ReceiveCont:
+        sub LINKMASK/3*2
+        ld a,LINKMASK/3*2
+        ld d,D0LD1H
+        jr c,ReceiveLow
+        rra
+        ld d,D0HD1L
+ReceiveLow:
+        rr c
+        ld (AckBit),a
+        ld a,d
+        out (LINKPORT),a
+        ld de,TIMEOUT
+WaitAckRec:
+        call CheckLink
+        cp 0
+AckBit =$-1
+        jr nz,WaitAckRec
+        ld a,D0HD1H
+        out (LINKPORT),a
+        ld d,4
+WaitReadyRec:
+        dec d
+        jr z,ReadyRec
+        in a,(LINKPORT)
+        cp LINKMASK
+        jr nz,WaitReadyRec
+ReadyRec:
+        djnz ReceiveBits
+        jr LinkSuccess
+  
+send:
+SendByte:
+        call LinkPrep
+        ld c,a
+
+        inc b
+        jr SendAcked
+
+SendBits:
+        rr c
+        ld a,D0LD1H
+        jr nc,SendLow
+        ld a,D0HD1L
+SendLow:
+        out (LINKPORT),a
+        ld de,TIMEOUT
+WaitAckSend:
+        call CheckLink
+        jr nz,WaitAckSend
+SendAcked:
+        ld a,D0HD1H
+        out (LINKPORT),a
+        ld de,TIMEOUT
+WaitReadySend:
+        call CheckLink
+        cp LINKMASK
+        jr nz,WaitReadySend
+        djnz SendBits
+LinkSuccess:
+        or 0
+.org $-1
+LinkFailed:
+        scf
+        ld a,c
+        res 2,(iy+12h)
+        pop de
+        pop bc
+        pop hl
+        ret
+
+CheckLink:
+        pop hl
+        dec de
+        ld a,d
+        or e
+        jr z,LinkFailed
+        ld a,0BFh
+        call _readkeypad
+        bit 6,a
+        jr z,LinkFailed
+        in a,(LINKPORT)
+        and LINKMASK
+        jp (hl)
+
+_readkeypad:
+       out (1),a
+       in a,(1)
+        push af
+       ld a,255
+       out (1),a
+        pop af
+       ret
+
+
+TEST_2:
+  ld b,8
+T2delay:
+  halt
+  dnz T2delay
+  in a,(7)
+  and %11
+  ld b,a
+  ld a,'1'
+  rr b
+  jr c,T2no1
+  ld a,'-'
+T2no1:
+  cal _putc
+  ld a,'2'
+  rr b
+  jr c,T2no2
+  ld a,'-'
+T2no2:
+  cal _putc
+  cal GET_KEY
+  cp K_EXIT
+  jp z,DisplayMenu
+  jr TEST_2
 
 
 ;-----------------------------
@@ -2775,7 +2975,6 @@ worm4set:  .dw worm4p,worm4p
            .db %11111011,3,0,%01111101,%10,%1 ;enter +
 worm4name: .db "worm #04",0
 
-hipeaworm: .dw 0
 end:
 
 defsprsize   = 4