BlitterStudio / amiberry

Optimized Amiga emulator for Linux/macOS
https://amiberry.com
GNU General Public License v3.0
644 stars 86 forks source link

SERIAL_PORT support? #682

Closed BleuLlama closed 3 years ago

BleuLlama commented 4 years ago

It would be really useful to have serial port support for Amiberry. I want to control various real-world devices from my emulated amiga environment. UAE supports this by connecting the emulated serial.device through to a real-world serial port defined via the config.

Specifically, I'd love to be able to control my actual LaserDisc player from AmigaVision, or even AmigaBASIC.

Currently Amiberry does not support connections to a serial port.

The #define is "SERIAL_PORT" and it is not currently DEFINE'd, although the general code is in the UAE source, although no specifics for this particular port. (as far as i can tell).

Would it be possible to get this feature added to Amiberry?

midwan commented 4 years ago

Yes, this is planned to be added in a future update :)

BleuLlama commented 4 years ago

Excellent. Is there anything I can do to help? (I haven't installed necessary toolchains etc to cross-compile Amiberry, etc. but I certainly could...)

midwan commented 4 years ago

@BleuLlama Thanks for offerring to help. Since this feature is already available in WinUAE and FS-UAE, we'd have to look into those implementations (probably more on FS-UAE since it has a Linux target) and merge what we can from there. Perhaps adapting some parts accordingly in the process.

If you want to start with that, feel free to clone this repo and play around with it. Pull requests are welcome! 👍

BleuLlama commented 4 years ago

Cool. I'll try to poke at it. Is there a guide to getting started for building? (ie what tools/toolchains, support libs, etc) need to be installed?

midwan commented 4 years ago

I usually use VisualGDB and work on Visual Studio, but that product is commercial. Some alternatives would be:

You would need the -dev libraries mentioned in the Readme installed, and a compiler/linker that can output ARM-eabhf binaries (for 32-bit targets) or aarch64 (for 64-bit ones). This can be done either by cross-compiling (faster but requires more setup) or editing the code on one side and compiling on the remote host directly (slower but easier).

gsfare commented 3 years ago

@BleuLlama

Hey, did you have any success yet? I've been playing around with this myself as it happens and "I think" I have something working. I need to fully test with a terminal on the emulated side (Workbench + some tool like minicom that I don't know yet I guess!). I am getting serial data from games when they're trying to link at least. Tested with a USB to serial adaptor and NULL modem cable.

The changes were somewhat more complex that I'd hoped so I wondered if you'd had any measured success too?

My goal is to have two raspberry pis running Stunt Car Racer with a multiplayer link. I've tested the theory using WinUAE and have that working well between two PC's....so it's possible at least. No success with FS-UAE though so defintely some debugging to do on the Amiberry changes....hence my previous question :-)

BleuLlama commented 3 years ago

I have not had time to even look at any amiberry source further... I have messed around with serial port stuff on FS-UAE on my desktop Mac previously though, setting it up as a tcp socket.

For a terminal on the Amiga side, I've used JR-Comm, and VLT. For the Mac side, I've just used telnet to the localhost port. My FS-UAE conf has this line to open the tcp port: (directly from the fs-uae docs)

serial_port = tcp://127.0.0.1:1234

For your multiplayer link, I think you could probably have both systems expose their serial port similarly via TCP, then use a tool like nc (netcat) to connect them together.... maybe?

gsfare commented 3 years ago

Thank you for the input, appreciate it, I'll try one of those just to check full communication is okay. I did manage to do a simple shell command from Workbench, "echo Hello >SER:" which worked from amiberry to my laptop so that's a good start at least.

gsfare commented 3 years ago

Just a quick FYI. I got NComm working between two raspberry pi's running Workbench via Amiberry. There are still some issues though, feels like a blocking read on the serial device but not sure). I also don't particularly like the FS-UAE implementation (which in fact does not actually work correctly via a real serial device).

I'm continuing to debug and do some work on this.

gsfare commented 3 years ago

Okay. I got it working this weekend. Two RPi4's linked with Stunt Car Racer playing head to head ;-) Also tested file transfers from Linux(minicom) to RPi and RPi to RPi using NComm. There's still some improvements to be made but I'll clean it up what I have and raise a PR then it's there if anyone wants it.

midwan commented 3 years ago

Sounds good! Looking foward to that PR, when it's ready.] Could you please make it towards the "dev" branch? I'm already working on that one for v3.4, so it would be great to integrate this as well in that version.

On Sun, Oct 25, 2020, 21:20 Gareth Fare notifications@github.com wrote:

Okay. I got it working this weekend. Two RPi4's linked with Stunt Car Racer playing head to head ;-) Also tested file transfers from Linux(minicom) to RPi and RPi to RPi using NComm. There's still some improvements to be made but I'll clean it up what I have and raise a PR then it's there if anyone wants it.

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/midwan/amiberry/issues/682#issuecomment-716205840, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA5ST5JM644PPN6DRUFLK4TSMSCALANCNFSM4QAR6WVQ .

gsfare commented 3 years ago

That was going to be my next question, dev branch confirmed 👍

BleuLlama commented 3 years ago

Y'all are awesome!

On Mon, Oct 26, 2020 at 9:01 AM Gareth Fare notifications@github.com wrote:

That was going to be my next question, dev branch confirmed 👍

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/midwan/amiberry/issues/682#issuecomment-716530378, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAQ7GGBCIQQAALMEEBFE7TSMVXLPANCNFSM4QAR6WVQ .

-- Scott Lawrence yorgle@gmail.com

gsfare commented 3 years ago

I finally got the PR done,

https://github.com/midwan/amiberry/pull/710

Happy to make any modifications as required to get the additions in-line with any standards/code reviews as required. Just let me know. You won't hurt my feelings if there is some terrible code in there ;-)

midwan commented 3 years ago

@gsfare Could you please help me write some small wiki page about this also? With a few examples on how one could set up 2 instances of Amiberry to play a game (e.g. Stunt Car Racer), or hook up real serial devices. I'm guessing it will come up as a question in the future, so it would be good to have some page to redirect people to...

gsfare commented 3 years ago

Yes, I can have a go at roughing something out, there are a few points worth documenting such as how 9-bit data framing is emulated etc. and maybe even a slightly more technical section (for the curious as I ended up needing to source a copy of the Amiga Hardware Reference Manual and a oscilloscope...) on how it actual works at a low level with CIAB. SERPER etc. registers.

What's the best way for me to proceed to help you?

midwan commented 3 years ago

@gsfare Great! I've created a new wiki page for this here: https://github.com/midwan/amiberry/wiki/Serial-Port-support

You should be able to edit it and add any information you want. We can enrich it going forward with any more details we might think of, that could be useful to have around.

Thanks again!

midwan commented 3 years ago

@gsfare Also, please let me know how you want to be added in the Credits page (nickname, real name?) :)

gsfare commented 3 years ago

@midwan Cool. I'll start this weekend and see how far I get. It'll probably take me some days to build it to where we need but I'll certainly make a good start at it.

Nickname or Real name is absolutely fine. You can use either :-) I'd also like to thank you and the contributors for maintaining such an awesome project. I can attribute my career to learning programming on my Amiga back in the day so it's great to see projects like this doing well!

midwan commented 3 years ago

@gsfare Hope you're doing well! I've started implementing support for uaeserial.device also, and I think ENET Serial would be great to have at some point. Would you have some time to help out? I'm almost done with the uaeserial stuff, but I'm not very familiar with the Linux specific implementation, so the FS-UAE stubs need to be filled in... :)

gsfare commented 3 years ago

@midwan Hope you are doing well too? I am good thanks. My work suddenly got super busy...run up to Christmas I think.

I can have a look this weekend. Is it the ENET you would like help with? If so those stubs aren't even used I believe. It's a bit convoluted again. When I looked last time I think all that needed to be done was to link with libenet.so and enable SERIAL_ENET in sysconfig.h. The latest version that comes with raspbian though has a different API so probably some changes required there.

I can look into it though and see if I can get it working. I'm not sure its useful for anything but debugging because of the cache in the Ethernet HW. We shall see though :-)

midwan commented 3 years ago

@gsfare Don't worry about the ethernet part for now, that will take more time to implement I guess (and if you're busy, it can wait). I was thinking about a simpler step first, just the uaeserial.device part. I've already added uaeserial.cpp and uaeserial.h which needed almost no changes from WinUAE, so the only part that needs to be implemented are the relevant calls in parser.cpp now. FS-UAE had those as stubs, and you had them disabled.

I've added all the above in a separate branch, to avoid anything breaking in the dev. I can upload the branch on Github if you want to take a peek at it.

midwan commented 3 years ago

I've pushed the uaeserial branch with the changes mentioned above. It won't compile currently, because I've left the stubs failing on purpose (easier to notice what's missing). :)

midwan commented 3 years ago

@gsfare Also, let's move this to a new issue: https://github.com/midwan/amiberry/issues/723

vincentvermeer commented 11 months ago

@gsfare "Okay. I got it working this weekend. Two RPi4's linked with Stunt Car Racer playing head to head ;-) "

Sorry for my stupied question: How have you connected the two rasperry pis? Via USB?

gsfare commented 11 months ago

@vincentvermeer I used two USB to serial dongles and, I cant't remember now, but I think a NULL modem serial cable. when you plugin the dongle it'll show up as /dev/ttyUSB0 or something like that which you have to set in the config.

vincentvermeer commented 11 months ago

@gsfare Thank you for your quick response! I will try it - after buying two dongles... ;)