Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define bcall(x) rst 28h \ .dw x
- saveSScreen = 86ECh
- .db $BB,$6D
- .org $9D95
- ld hl,saveSScreen
- call getBytes
- ld a,b
- or c
- ret z
- _:
- ld a,(hl)
- bcall($4504)
- cpi
- jp pe,-_
- ret
- ;============================================================
- ;============================================================
- ;============================================================
- getBytes:
- ;Input:
- ; HL points to where the bytes are written
- ;Output:
- ; HL points to the received data
- ; BC is the size of the data
- ; nc if the data transferred
- ; c if the connection failed due to an ON-break. BC is then returned as how many bytes were actually read.
- push hl
- call getByte_breakable
- push af
- call c,getByte_breakable
- jp nc,getBytes_nullexit
- ld b,a
- pop af
- ld c,a
- pop hl
- ld a,b
- or c
- scf
- ret z
- push hl
- push bc
- call +_
- pop hl
- sbc hl,bc
- ld a,b
- ld b,h
- or c
- ld c,l
- pop hl
- ret nz
- scf
- ret
- _:
- push hl
- push bc
- call getByte_breakable
- pop bc
- pop hl
- ret nc
- ld (hl),a
- cpi
- jp pe,-_
- ret
- getBytes_nullexit:
- pop af
- pop hl
- ld bc,0
- or a
- ret
- getByte_breakable:
- in a,(4)
- and 8
- ret z
- call getByte
- jr nz,getByte_breakable
- scf
- ret
- getByte:
- di
- ld bc,$0803 ;Bit counter in b, bit mask in c
- ld hl,-1
- xor a
- out (0),a ;Make sure we are reset
- in a,(0)
- and c ;Check to see if sender is ready
- dec a
- ret nz ;If not, then go back
- inc a
- out (0),a ;Relay a confirmation
- ex (sp),hl ;Wait at until confirmation is read (59 T-states minimum)
- ex (sp),hl
- ld a,(de) ;Bit counter in b and bitmask in c
- xor a ;Store received byte in l
- ld hl,$AA
- out (0),a ;Reset the ports to receive data
- _:
- in a,(0)
- xor l
- rra
- jr c,-_
- in a,(0)
- rra
- rra ;bits cycled in are masked with 0x55. Need to invert anyways, so mask at the end with 0xAA
- rr l
- djnz -_
- ld a,l
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement