Advertisement
jbshelton

Jankey-board GB

Feb 10th, 2021 (edited)
888
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;idk if it'll work but it needs to work on GB and GBC and not just GBC with the unused pin and special register
  2. ld a, $01
  3. ldh [rSC], a ;internal clock, don't start transfer yet
  4. ld a, $40 ;01000000
  5. ldh [rSB], a
  6. ;and then...
  7. ld a, $81 ;start the transfer with the internal clock
  8. ldh [rSC], a
  9. waitforstart:
  10. ldh a, [rSB]
  11. bit 6, a ;bit 6 is the bit I set
  12. jr nz, waitforstart ;wait until the bit gets shifted out so we know the keyboard has to resend its stuff
  13. xor a
  14. ldh [rSC], a ;now start the transfer with external clock WITHOUT the transfer bit set
  15. waitforbit:
  16. ldh a, [rSB]
  17. bit 7, a ;since the register shifted left in order to inhibit communication, I check this bit until it shifts again, which means the start bit is shifted in
  18. ld a, $01
  19. ldh [rSB], a ;put a 1 in bit 0 to keep the data line high to idle at the end?
  20. jr nz, waitforbit
  21. ld a, $80
  22. ldh [rSC], a ;set the transfer bit to reset the bit counter
  23. ;*do something here while waiting for the keyboard to send its data*
  24. ;pretend this gets executed when the serial interrupt fires off
  25. serialinterrupt:
  26. ldh a, [rSB]
  27. push af ;just find a way to store it somewhere
  28. ld a, $01
  29. ldh [rSC], a ;the communication shouldn't be inhibited because the clock line is high, so it's idling
  30.  
  31. ;do 1 or 2 keys per frame
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement