Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- p_GetByte:
- .db __GetByteEnd-$-1
- di
- in a,(0)
- cp 2 ;Check to see if sender is ready
- ccf
- sbc hl,hl
- ret c ;If not, then return
- out (0),a ;Otherwise, relay a confirmation
- nop
- ex (sp),hl ;Wait for confirmation to be read
- ex (sp),hl ;Store received byte in l
- inc l ;Done signal will be when bit 0 of l is shifted out
- ld a,h
- out (0),a ;Reset the port to receive data
- __GetByteLoop:
- in a,(0) ;Check if a new bit has been sent
- srl a
- jr z,__GetByteLoop
- rl l ;Shift the new bit in and check if done
- jr nc,__GetByteLoop ;Keep looping if we haven't got all the bits
- ret ;Otherwise, we're done
- __GetByteEnd:
- p_SendByte:
- .db __SendByteEnd-$-1
- di ;Byte to send in e
- ld bc,$0803 ;Bit counter in b, bit mask in c
- ld a,2
- out (0),a ;Indicate we are ready to send
- __SendByteTimeout:
- dec hl ;Wait for confirmation until hl is decreased to 0
- ld a,h
- or l
- jr z,__SendByteDone
- in a,(0) ;Check for confirmation
- and c
- jr nz,__SendByteTimeout ;Keep looping till we get it
- __SendByteLoop:
- sla e ;Rotate bits left
- ld a,c
- out (0),a ;Send bit separation signal
- sbc a,2
- out (0),a ;Send the bit shifted out
- xor a
- djnz __SendByteLoop ;Loop if there are more bits to send
- __SendByteDone:
- out (0),a ;Reset the port
- ret ;We're done
- __SendByteEnd:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement