Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- p_GetByte:
- .db __GetByteEnd-$-1
- 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
- nop
- inc hl
- out (0),a ;Reset the ports to receive data
- __GetByteLoop:
- in a,(0) ;Wait until first bit is sent Max loop wait (49 T-states max)
- and c
- jr z,__GetByteZero ;Go here if we get a zero
- cp c
- jr nz,__GetByteLoop
- __GetByteOne: ;Go here if we get a one
- scf
- __GetByteZero:
- rl l ;Shift the bits left, zero is in the first bit
- ex (sp),hl ;Wait for the sender to change (75 T-states min, 107 max)
- ex (sp),hl
- djnz __GetByteLoop ;Keep looping if we haven't got all the bits
- ret ;Otherwise, we're done.
- __GetByteEnd:
- p_SendByte:
- .db __SendByteEnd-$-1
- di
- LDBC(8,3) ;Bit counter in b, bit mask in c
- ld a,%00000010
- out (0),a ;Indicate we are ready to send
- __SendByteTimeout:
- dec hl
- ld a,h
- or l
- jr z,__SendByteDone
- in a,(0) ;Loop is 59 T-states maximum
- and c
- jr nz,__SendByteTimeout ;Keep looping till we get it
- __SendByteLoop:
- inc a
- out (0),a ;This is the waiting state
- ex (sp),hl ;Wait (115 T-states min)
- ex (sp),hl
- ex (sp),hl
- ex (sp),hl
- xor a
- ld h,0
- ld l,-1
- rl e ;Check the first bit
- jr c,__SendByteSkip
- ld a,c ;Send a one
- __SendByteSkip: ;Send a zero
- out (0),a
- ex (sp),hl ;Wait (59 T-states)
- ex (sp),hl
- 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