-
-
Notifications
You must be signed in to change notification settings - Fork 52
Part 2 serial IO lesson #88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| ; :: / `--<[|]= |[ m ]|| :: | ||
| ; :: \ .______ | ```` || :: | ||
| ; :: / !| `````| | + oo|| :: | ||
| ; :: ( ||[ ^u^]| | .. #|| :: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love this!
3a0e30d to
431baff
Compare
This comment was marked as outdated.
This comment was marked as outdated.
Not sure about more significant testing, but I'd start thinking about how to integrate it in Ubricked for the simple "share high scores" case (although I really like @eievui5 idea here, maybe for a further improvement). Maybe start the paragraph explaining sio.asm then hooking the "share high score" routine when e.g. pressing select on the game over screen? To be honest, I don't think having an independent, standalone ROM only to showcase the serial feature is a bad idea, so I'd merge that as well. |
|
Hey @quinnyo do you have any news on this? |
|
Hi! I just lost my momentum on it towards the end of last year, when life things happened. |
|
@quinnyo thanks a lot! Also, since we did put bounties on this issues, if you give us an email address (you can DM me that on Discord or to 'gbcompo' at 'gbdev.io') I can send you an OpenCollective invitation to claim those $ bounties :D |
This comment was marked as outdated.
This comment was marked as outdated.
8a9346b to
84c8f1b
Compare
|
OK so I implemented something in unbricked, which seemed to make more sense than continuing with the demo/test tool. Oh, and just a note to anyone testing this: if you're using Emulicious, expect trouble -- its serial emulation is a bit weird and introduces problems that don't happen on real hardware. GBE+ serial seems good but it's a bit lacking in other areas. |
|
@quinnyo I see this is still in 'Draft'. Would you consider this merge-able now? or what's missing for you that you would still like to add? I guess we "only" miss the lesson text to accompany the code? |
|
I'll take the PR off of 'draft' status, I didn't have any strong intention to leave it on after the last update. Apologies if it being marked as a draft was holding things up or sending the wrong message. The code is done, I have no changes planned. Of course, I'll be happy to fix any issues that come up.
The lesson text needs work, but I'm reluctant to forge ahead with that without knowing that the implementation is locked in.
|
avivace
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, great work @quinnyo ! I'm starting a thorough review of the text and it reads amazingly.
|
|
||
| Before we can transfer any data, we need to configure the *clock source* of both Game Boys. | ||
| To synchronise the two devices, one Game Boy must provide the clock signal that both will use. | ||
| Setting bit 0 of the **Serial Control** register (`SC`) enables the Game Boy's *internal* serial clock, and makes it the clock provider. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can link to https://gbdev.io/pandocs/Serial_Data_Transfer_(Link_Cable).html#ff02--sc-serial-transfer-control here ?
| The other Game Boy must have its clock source set to *external* (`SC` bit 0 cleared). | ||
| The externally clocked Game Boy will receive the clock signal via the link cable. | ||
|
|
||
| Before a transfer, the data to transmit is loaded into the **Serial Buffer** register (`SB`). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| The first byte to send is loaded from `wSioBufferTx` before a jump to the next function starts the first transfer immediately. | ||
|
|
||
| <!-- PortStart --> | ||
| Activating the serial port is a simple matter of setting bit 7 of `rSC`, but we need to do a couple of other things at the same time, so add a function to bundle it all together: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I missing something or this is being called rSC now? but was SC? https://gbdev.io/pandocs/Serial_Data_Transfer_(Link_Cable).html#ff02--sc-serial-transfer-control
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All MMIO register names in hardware.inc are prefixed with r to distinguish them from ROM, SRAM, WRAM, and HRAM labels. See "ASM style guide".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pinobatch thanks Pino. It's just that in other parts of the document it's called SC, so seeing it as rSC after a point may be confusing, so I'd suggest sticking to one name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this was deliberate, but it may be needlessly confusing. It's rSC (with the r) here because it's talking about concrete implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@quinnyo can we try to make it a more deliberate? E.g. make it explicit when the shift to rSC happens?
|
|
||
| ::: | ||
|
|
||
| To check if the internal clock is enabled, read the serial port control register (`rSC`) and check if the clock source bit is set. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as previous, regarding rSC.
| :::tip | ||
|
|
||
| The checksum implemented here has been kept very simple for this tutorial. | ||
| It's probably worth looking into better solutions for real-world projects. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we know some alternatives we can suggest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A good jumping off point to learn more would be Ben Eater's videos:
Reliable data transmission
https://www.youtube.com/watch?v=eq5YpKHXJDM
Error detection: Parity checking
https://www.youtube.com/watch?v=MgkhrBSjhag
Checksums and Hamming distance
https://www.youtube.com/watch?v=ppU41c15Xho
How do CRCs work?
https://www.youtube.com/watch?v=izG7qT0EpBw
| A proper and complete explanation of this is beyond the scope of this lesson. | ||
| You can continue the lesson understanding that: | ||
| - This is the serial interrupt handler. It gets called automatically after each serial transfer. | ||
| - The relevant stuff is in `SioPortEnd` but it's necessary to jump through some hoops to call it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"relevant stuff" here feels a bit confusing
avivace
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing: build script for the new CI/CD
Co-authored-by: Antonio Vivace <avivace4@gmail.com>
Co-authored-by: Antonio Vivace <avivace4@gmail.com>
This PR adds a lesson on the serial port to resolve #42.
Still a draft because the lesson text needs to be updated.
About the implementation:
Sio (
sio.asm) is a kind of multi-byte version of the underlying GB serial API.main.asmis based on the BCD unbricked code.demo.asmis a standalone test rom I used to test and debug the serial transfer implementation. It isn't part of the lesson and can be removed if necessary, but it provides more debug information than the integration with unbricked.