Advertisement
Runer112

16% safe fast link protocol for Axe

Feb 20th, 2012
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. p_GetByte:
  2.     .db __GetByteEnd-$-1
  3.     di
  4.     in  a,(0)
  5.     cp  2           ;Check to see if sender is ready
  6.     ccf
  7.     sbc hl,hl
  8.     ret c           ;If not, then return
  9.     out (0),a           ;Otherwise, relay a confirmation
  10.     ex  (sp),hl         ;Wait for confirmation to be read
  11.     ex  (sp),hl         ;Store received byte in l
  12.     inc l           ;Done signal will be when bit 0 of l is shifted out
  13.     ld  a,h
  14.     out (0),a           ;Reset the port to receive data
  15. __GetByteLoop:
  16.     in  a,(0)           ;Check if a new bit has been sent
  17.     srl a
  18.     jr  z,__GetByteLoop
  19.     rl  l           ;Shift the new bit in and check if done
  20.     jr  nc,__GetByteLoop    ;Keep looping if we haven't got all the bits
  21.     ret             ;Otherwise, we're done
  22. __GetByteEnd:
  23.  
  24. p_SendByte:
  25.     .db __SendByteEnd-$-1
  26.     di              ;Byte to send in e
  27.     ld  bc,$0803        ;Bit counter in b, bit mask in c
  28.     ld  a,2
  29.     out (0),a           ;Indicate we are ready to send
  30. __SendByteTimeout:
  31.     dec hl          ;Wait for confirmation until hl is decreased to 0
  32.     ld  a,h
  33.     or  l
  34.     jr  z,__SendByteDone
  35.     in  a,(0)           ;Check for confirmation
  36.     and c
  37.     jr  nz,__SendByteTimeout    ;Keep looping till we get it
  38. __SendByteLoop:
  39.     sla e           ;Rotate bits left
  40.     ld  a,c
  41.     out (0),a           ;Send bit separation signal
  42.     sbc a,2
  43.     out (0),a           ;Send the bit shifted out
  44.     djnz    __SendByteLoop      ;Loop if there are more bits to send
  45.     xor a
  46. __SendByteDone:
  47.     out (0),a           ;Reset the port
  48.     ret             ;We're done
  49. __SendByteEnd:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement