shonumi / gbe-plus

DMG/GBC/GBA emulator and experimental NDS emulator.
GNU General Public License v2.0
501 stars 79 forks source link

Serial port emulation with TCP/IP #82

Closed cyberic99 closed 5 years ago

cyberic99 commented 5 years ago

Hello

Is there a way to emulate a device plugged on the serial port, like the arduinoboy (https://github.com/trash80/Arduinoboy), via TCP/IP?

If the serial network protocol documented somewhere?

Thank you

shonumi commented 5 years ago

Sorry for the late response, got caught up over the past week.

Anyway, the serial port protocol for GBE+ is relatively simple for DMG/GBC communications. GBE+ expects to receive 2 bytes for each TCP transfer. The 1st byte is whatever data you want to send to GBE+. For serial I/O, the 1st byte is basically the 8-bit value shifted out via the Link Cable (the value of 0xFF01 aka SB). The 2nd byte specifies a command (if any) for GBE+ to process. Commands are limited and optional. They are:

Whenever GBE+ sends the 8-bit value for SB, it pauses (regardless if hard sync is enabled or not) until it receives a response. It expects the sender to give it a new value for SB. This is where GBE+ emulates the Game Boy completing a serial data transfer, where the two sides exchange 1 byte of data. During this transfer, there should be no commands used, just put the raw data into the 1st byte of the transfer like 0xAB, 0x00, where 0xAB is what you want to send to GBE+.

Basic communication flow would look something like this (assuming hard sync is on):

For more details, see https://github.com/shonumi/gbe-plus/blob/master/src/dmg/sio.cpp

cyberic99 commented 5 years ago

OK, thanks a lot!