SHOW:
|
|
- or go back to the newest paste.
| 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 | nop | |
| 11 | ex (sp),hl ;Wait for confirmation to be read | |
| 12 | ex (sp),hl ;Store received byte in l | |
| 13 | inc l ;Done signal will be when bit 0 of l is shifted out | |
| 14 | ld a,h | |
| 15 | out (0),a ;Reset the port to receive data | |
| 16 | __GetByteLoop: | |
| 17 | in a,(0) ;Check if a new bit has been sent | |
| 18 | srl a | |
| 19 | jr z,__GetByteLoop | |
| 20 | rl l ;Shift the new bit in and check if done | |
| 21 | jr nc,__GetByteLoop ;Keep looping if we haven't got all the bits | |
| 22 | ret ;Otherwise, we're done | |
| 23 | __GetByteEnd: | |
| 24 | ||
| 25 | p_SendByte: | |
| 26 | .db __SendByteEnd-$-1 | |
| 27 | di ;Byte to send in e | |
| 28 | ld bc,$0803 ;Bit counter in b, bit mask in c | |
| 29 | ld a,2 | |
| 30 | out (0),a ;Indicate we are ready to send | |
| 31 | __SendByteTimeout: | |
| 32 | dec hl ;Wait for confirmation until hl is decreased to 0 | |
| 33 | ld a,h | |
| 34 | or l | |
| 35 | jr z,__SendByteDone | |
| 36 | in a,(0) ;Check for confirmation | |
| 37 | and c | |
| 38 | jr nz,__SendByteTimeout ;Keep looping till we get it | |
| 39 | __SendByteLoop: | |
| 40 | sla e ;Rotate bits left | |
| 41 | ld a,c | |
| 42 | out (0),a ;Send bit separation signal | |
| 43 | sbc a,2 | |
| 44 | out (0),a ;Send the bit shifted out | |
| 45 | xor a | |
| 46 | djnz __SendByteLoop ;Loop if there are more bits to send | |
| 47 | __SendByteDone: | |
| 48 | out (0),a ;Reset the port | |
| 49 | ret ;We're done | |
| 50 | __SendByteEnd: |