worm 0.92.0907: link improvements
authorMischa Poslawsky <wormy@shiar.org>
Thu, 7 Sep 2000 16:36:00 +0000 (18:36 +0200)
committerMischa Poslawsky <wormy@shiar.org>
Sun, 22 Feb 2009 15:19:55 +0000 (16:19 +0100)
worm.z80

index fa7b79604eabe0f2062a384499d9cb317eebdacf..af6b84aa3132cacbf22cbbb1fe8682a7dde596d3 100644 (file)
--- a/worm.z80
+++ b/worm.z80
@@ -124,7 +124,8 @@ DispBuffer  = $FC70
 
 .org _asm_exec_ram
 
-WormVersion = 092
+wormVhost   = 092
+wormVclient = 192
 
 start:
   nop
@@ -867,19 +868,20 @@ levelsskipped:
 
 linkmatch:
   cal _clrWindow
-  ld  a,WormVersion
+  ld  c,wormVhost
   cal Qsend
-  jr  nc,client ;2nd
-
-host:
   ld  hl,txtWaiting
   cal _puts
-  cal receive
-  cp  WormVersion
-  jp  nz,linkiniterror
-  cal Qsend
- jr c,linkiniterror
+  cal Crecv
+;  ld  a,c
+  cp  wormVclient
+  jr  z,client
+  cp  wormVhost
+  jr  nz,linkiniterror
 
+host:
+  ld  c,wormVclient
+  cal Qsend
   ld  a,$18
   jr  multiplayer
 
@@ -890,10 +892,6 @@ linkiniterror:
 client:
   ld  hl,txtReceive
   cal _puts
-  cal Qreceive
-  jp  c,linkiniterror
-  cp  WormVersion
-  jp  nz,linkiniterror
 
   ld  a,$f6
 multiplayer:
@@ -1586,30 +1584,26 @@ inputcall:
   jr  nz,inkeys
 
 inlink:
-  ld  a,D0HD1H
-  out (7),a
-  halt
-
-  ld  a,0
-sendbyte =$-1
   ld  b,(ix+left)
   dec b
   jr  z,receivefirst
   psh hl
-  cal send
-  cal receive
+  ld  c,0
+sendbyte =$-1
+  cal Csend
+  cal Crecv
   pop hl
-  ld  l,a
+  ld  l,c
   ret
 receivefirst:
-  psh af
   psh hl
-  cal receive
+  cal Crecv
   pop hl
-  ld  l,a
-  pop af
+  ld  l,c
   psh hl
-  cal send
+  ld  a,(sendbyte)
+  ld  c,a
+  cal Csend
   pop hl
   ret
 
@@ -2791,107 +2785,113 @@ line4sm:
 ;----------- link ------------
 ;-----------------------------
 
-TIMEOUT = $2000
+timeout = $800
 
 checklink:
-  pop hl
   dec de
   ld  a,d
   or  e
-  scf   ;cf=error
-  ret z
+  jr  z,linkerror
 
   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
 
   in  a,(7)
   and %11
-  jp  (hl)
+  ret
+
+linkerror:
+  scf
+  ld  a,%11
+  pop hl
+  ret
 
 ;--------------
-;---- SEND ---- 8 bits in a
-;-------------- destr:bcdehl
-send:
- halt
-  cal Qsend
-  ret nc
-  jr  send
+;---- SEND ----
+;--------------
 
-Qsend:
+Csend:         ;--- send 8 bits in A --- destr:abcdehl ---
   ld  c,a
-  ld  b,8+1        ;bits to send
-  jr  checksend
+Csendloop:
+  cal Qsend
+  ret nc               ;NC = all ok
+  ld  a,D0HD1H
+  out (7),a            ;both high
+  jr  Csendloop        ;CF = error
+
+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
+  ld  b,8              ;bits to send
 sendloop:
-  rr  c            ;bit to send (in cf)
-  ld  a,D0LD1H     ;0: lower white
+  ld  de,timeout
+  rl  c                        ;bit to send in cf
+  ld  a,D0LD1H         ;0: lower white
   jr  nc,sendbit
-  ld  a,D0HD1L     ;1: lower red
+  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     ;raise one, ok to raise other
+  out (7),a            ;lower one (send bit)
+sendwaitack:
+  cal checklink                ;other calc must lower other wire
+  jr  nz,sendwaitack
+  ld  a,D0HD1H         ;raise one, ok to raise other
   out (7),a
-  ld  de,TIMEOUT
-finishsend:
+sendfinish:
   cal checklink
-  cp  %11          ;both raised (by other calc)
-  jr  nz,finishsend
-  dnz sendloop     ;repeat for all bits
-  ret              ;nc=ok
+  cp  %11              ;both raised (by other calc)
+  jr  nz,sendfinish
+  nop \ nop
+  dnz sendloop         ;repeat for all bits
+  xor a                        ;nc...
+  ret                  ;=ok
 
 ;--------------
-;---- RECV ---- 8 bits to a
-;-------------- destr:bcdehl
-receive:
-  cal Qreceive
-  ret nc
-  jr  receive
-
-Qreceive:
-  ld  b,8          ;bits to receive
-receiveloop:
-  ld  de,TIMEOUT
-WaitRecBit:
+;---- RECV ----
+;--------------
+
+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 low = error
+  ret z                        ;both high = nothing yet, wait
+  ld  b,8              ;bits to receive
+recvloop:
+  ld  de,timeout
+recvwait:
+  cal checklink
   cp  %11
-  jr  z,WaitRecBit ;both on = nothing sent
-recvbit:
-  rra              ;received bit in cf
-  ld  a,%10
-  ld  d,D0LD1H
-  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        ;lower other (both low)
-  ld  de,TIMEOUT
-waitackrecv:       ;same will be raised again by other calc
+  jr  z,recvwait       ;both high = nothing sent (yet)
+  rra                  ;received bit in cf
+  ld  a,D0LD1H
+  jr  c,received       ;lower white wire as well
+  ld  a,D0HD1L         ;lower red
+received:
+  rl  c                        ;save bit in c
+  out (7),a            ;both wires low
+recvwaitack:
   cal checklink
-  cp  0
-AckBit =$-1
-  jr  nz,waitackrecv
+  jr  z,recvwaitack    ;same wire will be raised again by other calc
   ld  a,D0HD1H
-  out (7),a        ;raise both
-  dnz receiveloop  ;repeat for all bits
-  or  a            ;nc
-  ld  a,c          ;a=byte received
+  out (7),a            ;raise both
+recvfinish:
+  dnz recvloop         ;repeat for all bits
+  xor a                        ;nc=no error
+  ld  a,c              ;result in a
   ret
 
 ;-----------------------------