Geekboy

Untitled

Feb 19th, 2012
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. p_GetByte:
  2. .db __GetByteEnd-$-1
  3. di
  4. ld bc,$0803 ;Bit counter in b, bit mask in c
  5. ld hl,-1
  6. xor a
  7. out (0),a ;Make sure we are reset
  8. in a,(0)
  9. and c ;Check to see if sender is ready
  10. dec a
  11. ret nz ;If not, then go back
  12. inc a
  13. out (0),a ;Relay a confirmation
  14. ex (sp),hl ;Wait at until confirmation is read (59 T-states minimum)
  15. ex (sp),hl
  16. ld a,(de) ;Bit counter in b and bitmask in c
  17. xor a ;Store received byte in l
  18. nop
  19. inc hl
  20. out (0),a ;Reset the ports to receive data
  21. __GetByteLoop:
  22. in a,(0) ;Wait until first bit is sent Max loop wait (49 T-states max)
  23. and c
  24. jr z,__GetByteZero ;Go here if we get a zero
  25. cp c
  26. jr nz,__GetByteLoop
  27. __GetByteOne: ;Go here if we get a one
  28. scf
  29. __GetByteZero:
  30. rl l ;Shift the bits left, zero is in the first bit
  31. ex (sp),hl ;Wait for the sender to change (75 T-states min, 107 max)
  32. ex (sp),hl
  33. djnz __GetByteLoop ;Keep looping if we haven't got all the bits
  34. ret ;Otherwise, we're done.
  35. __GetByteEnd:
  36.  
  37. p_SendByte:
  38. .db __SendByteEnd-$-1
  39. di
  40. LDBC(8,3) ;Bit counter in b, bit mask in c
  41. ld a,%00000010
  42. out (0),a ;Indicate we are ready to send
  43. __SendByteTimeout:
  44. dec hl
  45. ld a,h
  46. or l
  47. jr z,__SendByteDone
  48. in a,(0) ;Loop is 59 T-states maximum
  49. and c
  50. jr nz,__SendByteTimeout ;Keep looping till we get it
  51. __SendByteLoop:
  52. inc a
  53. out (0),a ;This is the waiting state
  54. ex (sp),hl ;Wait (115 T-states min)
  55. ex (sp),hl
  56. ex (sp),hl
  57. ex (sp),hl
  58. xor a
  59. ld h,0
  60. ld l,-1
  61. rl e ;Check the first bit
  62. jr c,__SendByteSkip
  63. ld a,c ;Send a one
  64. __SendByteSkip: ;Send a zero
  65. out (0),a
  66. ex (sp),hl ;Wait (59 T-states)
  67. ex (sp),hl
  68. xor a
  69. djnz __SendByteLoop ;Loop if there are more bits to send
  70. __SendByteDone:
  71. out (0),a ;Reset the port
  72. ret ;We're done
  73. __SendByteEnd:
Advertisement
Add Comment
Please, Sign In to add comment