Advertisement
Zeda

linkReceive

Sep 20th, 2017
515
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define bcall(x) rst 28h \ .dw x
  2. saveSScreen = 86ECh
  3. .db $BB,$6D
  4. .org $9D95
  5.     ld hl,saveSScreen
  6.     call getBytes
  7.     ld a,b
  8.     or c
  9.     ret z
  10. _:
  11.     ld a,(hl)
  12.     bcall($4504)
  13.     cpi
  14.     jp pe,-_
  15.     ret
  16. ;============================================================
  17. ;============================================================
  18. ;============================================================
  19. getBytes:
  20. ;Input:
  21. ;   HL points to where the bytes are written
  22. ;Output:
  23. ;   HL points to the received data
  24. ;   BC is the size of the data
  25. ;   nc if the data transferred
  26. ;   c if the connection failed due to an ON-break. BC is then returned as how many bytes were actually read.
  27.  
  28.     push hl
  29.     call getByte_breakable
  30.     push af
  31.     call c,getByte_breakable
  32.     jp nc,getBytes_nullexit
  33.     ld b,a
  34.     pop af
  35.     ld c,a
  36.     pop hl
  37.     ld a,b
  38.     or c
  39.     scf
  40.     ret z
  41.     push hl
  42.     push bc
  43.     call +_
  44.     pop hl
  45.     sbc hl,bc
  46.     ld a,b
  47.     ld b,h
  48.     or c
  49.     ld c,l
  50.     pop hl
  51.     ret nz
  52.     scf
  53.     ret
  54. _:
  55.     push hl
  56.     push bc
  57.     call getByte_breakable
  58.     pop bc
  59.     pop hl
  60.     ret nc
  61.     ld (hl),a
  62.     cpi
  63.     jp pe,-_
  64.     ret
  65. getBytes_nullexit:
  66.     pop af
  67.     pop hl
  68.     ld bc,0
  69.     or a
  70.     ret
  71.    
  72. getByte_breakable:
  73.     in a,(4)
  74.     and 8
  75.     ret z
  76.     call getByte
  77.     jr nz,getByte_breakable
  78.     scf
  79.     ret
  80. getByte:
  81.     di
  82.     ld bc,$0803  ;Bit counter in b, bit mask in c
  83.     ld hl,-1
  84.     xor a
  85.     out (0),a   ;Make sure we are reset
  86.     in a,(0)
  87.     and c   ;Check to see if sender is ready
  88.     dec a
  89.     ret nz   ;If not, then go back
  90.     inc a
  91.     out (0),a   ;Relay a confirmation
  92.     ex (sp),hl   ;Wait at until confirmation is read (59 T-states minimum)
  93.     ex (sp),hl
  94.     ld a,(de)   ;Bit counter in b and bitmask in c
  95.     xor a   ;Store received byte in l
  96.     ld hl,$AA
  97.     out (0),a   ;Reset the ports to receive data
  98. _:
  99.     in a,(0)
  100.     xor l
  101.     rra
  102.     jr c,-_
  103.     in a,(0)
  104.     rra
  105.     rra             ;bits cycled in are masked with 0x55. Need to invert anyways, so mask at the end with 0xAA
  106.     rr l
  107.     djnz -_
  108.     ld a,l
  109.     ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement