worm 0.91.0524: further link improvements
authorMischa Poslawsky <wormy@shiar.org>
Wed, 24 May 2000 20:22:56 +0000 (22:22 +0200)
committerMischa Poslawsky <wormy@shiar.org>
Sun, 22 Feb 2009 15:19:55 +0000 (16:19 +0100)
The work continues.  Documents base send/receive routines.

worm.z80

index 030690327b65b68a5ff414f3233ad6c333732ff9..22e6fec05c517897bfb9482deec68ed6210d3bc1 100644 (file)
--- a/worm.z80
+++ b/worm.z80
@@ -778,14 +778,15 @@ 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  nc,multiplayer
+  jr  multiplayer
 
 linkiniterror:
   pop hl
@@ -802,7 +803,7 @@ sendnameloop:
   cal send
   pop hl
   pop bc
-  dnz sendnameloop
+;  dnz sendnameloop
   ret
 receivename:
   ld  hl,worm2+name
@@ -815,7 +816,7 @@ recvnameloop:
   pop bc
   ld  (hl),a
   inc hl
-  dnz recvnameloop
+;  dnz recvnameloop
   ret
 
 client:
@@ -824,7 +825,7 @@ client:
   cal Qreceive
   jp  c,linkiniterror
   cp  WormVersion
-  jp  nz,linkiniterror
+;  jp  nz,linkiniterror
 
 ;  cal receivename
 ;  cal sendname
@@ -1277,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
@@ -2697,122 +2700,109 @@ boxloop:
 
 TIMEOUT = $1000
 
-receive:
-  cal GET_KEY
-  cp  K_EXIT
-  jp  z,LinkBreak
+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
+  jp  z,Exit
+
   in  a,(7)
   and %11
-;  jr  z,LinkBreak
+  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
   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 ;01
-  jr  c,ReceiveLow
+  ld  d,D0LD1H
+  jr  c,savebit    ;lower white as well
   rra ;ld a,%01
-  ld  d,D0HD1L ;10
-ReceiveLow:
-  rr  c
+  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 ;11
-  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
-
-LinkBreak:
-  ld  a,D0HD1L
-  out (7),a
-  jp  Exit
-
-send:
-  ld  c,a
-  ld  b,8+1
-  jr  SendAcked
-sendloop:
-  rr  c
-  ld  a,D0LD1H ;%01
-  jr  nc,SendLow
-  ld  a,D0HD1L ;%10
-SendLow:
-  out (7),a
-  ld  de,TIMEOUT
-WaitAckSend:
-  cal CheckLink
-  jr  nz,WaitAckSend
-SendAcked:
-  ld  a,D0HD1H ;%11
-  out (7),a
-  ld  de,TIMEOUT
-WaitReadySend:
-  cal CheckLink
-  cp  %11
-  jr  nz,WaitReadySend
-  dnz sendloop
-  ld  a,c
-  ret
-
-LinkSuccess:
- .db  $F6 ;or NN (skip scf)
-LinkFailed:
-  scf
-  ld  a,c
+  jr  nz,waitackrecv
+  ld  a,D0HD1H
+  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,LinkBreak
-
-  in  a,(7)
-  and %11
-  jp  (hl)
-
 ;-----------------------------
 ;---------- levels -----------
 ;-----------------------------