tiboyce icon indicating copy to clipboard operation
tiboyce copied to clipboard

Add Link Capabilities

Open decaby7e opened this issue 5 years ago • 13 comments

I'm not sure if this would be fairly simple or enormously difficult to implement, but it would be awesome for games like Pokémon where calculators can be linked together for trading and what not.

decaby7e avatar Jul 19 '18 04:07 decaby7e

This would indeed be cool to implement, however I expect it was already a planned feature for @calc84maniac. I would not expect results soon, however.

LAX18 avatar Jul 19 '18 16:07 LAX18

I know, right? USB is still being documented for the CE, so I guess we'll have to wait and see!

If this is implemented, it'd make the CE basically into a GameBoy 😝 .

josheewa avatar Jul 20 '18 00:07 josheewa

Still leaves out sound. Nothing we can do about that.

gplastic avatar Aug 27 '18 23:08 gplastic

USB audio is being implemented (earlier than linking anyway)

adriweb avatar Aug 28 '18 00:08 adriweb

That's amazing.

gplastic avatar Aug 28 '18 00:08 gplastic

If speed is not an issue, it may be possible to use the calculator's built in Send and Get. I'm no GameBoy developer but according to https://gbdev.gg8.se/wiki/articles/Serial_Data_Transfer_(Link_Cable) it's very likely that the process could look sort of like this:

A: 127  ->  TIBoyLink1  // Equivalent of GB A storing 0x7F to SB
B:     Get (TIBoyLink1) // Equivalent of GB B storing 0x80 to SC
A:     Send(TIBoyLink1) // Equivalent of GB A storing 0x81 to SC
                        // GB B now has received TIBoyLink1
B:     Send(TIBoyLink2) // GB B's return transfer
A:     Get (TIBoyLink2) // GB A receives whatever GB B had in SB
                        // GB A and GB B have stored TIBoyLink2 and
                        // TIBoyLink1 respectively into their SBs

in a case where GB A wanted to send a 0x7F byte and GB B was just receiving.

It might happen that GB B hasn't marked 0x80 to SC (explained in the above document) and is only checking for changes in SB. This means that it will not be explicitly looking for link transfers. As an effect, TI A might be Send(ing and never have a Get( to send to on TI B (as it is not explicitly looking for one).

Alternatively, it might happen that GB A marks 0x81 to SC and TI A doesn't find another calculator to Send( to. Send( doesn't have a timeout, only Get(, so these calls would have to somehow execute asynchronously.

s5bug avatar Jun 22 '19 04:06 s5bug

The tricky part is making the game recognize it as a linkup between the two calcs when it is looking for another gameboy.

ecdye avatar Jun 24 '19 00:06 ecdye

Not really. Theoretically, TI Boy CE looks if the Game Boy is asking for a link, and if it is, asks for a calculator. That's as simple as checking when values are changed in SC and calling the appropriate calculator function. Game Boy linking is nothing more than a serial transmission; sending bits in and out.

The only difference I could foresee (unless the transmission should be 8 times slower) is that TI Boy CE would transmit the entire byte in and out of SB instead of bits at a time. Unless a game is specifically checking for this functionality (which makes no sense outside of anti-emulation purposes) this should not be any issue.

The lack of a serial port on the CE makes transmitting data that should be, well, serial, a much harder process than for other calculators.

s5bug avatar Jun 24 '19 05:06 s5bug

For the record, it's not even remotely that simple because OS code (particularly interrupts) won't even run properly during TI Boy CE emulation due to the many cool tricks being used to make emulation fast. In any case, GetCalc takes over 1.5 seconds for some reason so you won't get anywhere close to the expected 8Kb/s transfer rate. Luckily, the Universal Serial Bus hardware is well enough understood that it is actually simpler to use it directly than to try to go through OS routines, so the only issue is getting the time and/or motivation to actually implement everything.

jacobly0 avatar Jun 24 '19 06:06 jacobly0

Ah, ok. Makes sense. I didn't know what the lower bound on sending and getting data via those functions was.

How would I go about helping document the calculator's USB stuff?

s5bug avatar Jun 24 '19 15:06 s5bug

You could look at all the USB stuff in here: https://github.com/CE-Programming/CEmu/tree/usb-host and here: https://github.com/CE-Programming/toolchain/tree/usbdrvce and see if you can find out anything else - but it's not an easy task :P

adriweb avatar Jun 24 '19 16:06 adriweb

Interesting that there's plenty of code for the USB but very little documentation of it. I'm pretty busy this week but having link battles in Pokemon Red on calculators is something I want to see, so I'll work on it when I can.

Is there enough in the toolchain (on that branch at least) to get started on something in TI Boy CE? Or does more work need to be done on usbdrvce?

s5bug avatar Jun 24 '19 17:06 s5bug

This may help for serial and sound: https://github.com/commandblockguy/CE-serial https://github.com/MCJack123/ticesnd Cheers

MrKOSMOS avatar Jun 01 '22 00:06 MrKOSMOS