rust-console / gba

A crate that helps you make GBA games
https://docs.rs/gba
Apache License 2.0
659 stars 50 forks source link

Add cartridge IO port addresses #179

Closed ids1024 closed 1 year ago

ids1024 commented 1 year ago

Testing in mGBA I'm having trouble getting rumble to work (with a controller and setting it in "game overrides"). But changing IO_PORT_CONTROL does change how reading IO_PORT_DATA behaves, so it seems to work as expected.

ids1024 commented 1 year ago

Hm, I guess writing IO_PORT_CONTROL is unsafe since the linker might put something in this part of the ROM. But the other two should be safe, and reading is safe (but may get whatever data the ROM has at that location if IO_PORT_CONTROL is 0).

Lokathor commented 1 year ago

Those addresses would be within the header region of the ROM, right? Right now we reserve 0xE0 bytes for the header, so all three of these locations should end up within there. Then I think it's safe to try a write, since there's definitely no code there.

ids1024 commented 1 year ago

Ah, I didn't check that. https://problemkaputt.de/gbatek.htm#gbacartridgeheader indicates the header is at 8000000h-80000BFh. So this is just after the header, but if the link script is reserving enough bytes then it isn't an issue.

Lokathor commented 1 year ago

https://github.com/rust-console/gba/blob/main/src/asm_runtime.rs#L34

Yeah right now this reserves the entire multi-boot header region as well. Some older versions of mGBA were getting confused when code showed up in that area and trying to run the rom as a multiboot rom. I can't imagine ever trying to reclaim that space because with 32mb of allowed rom it's not really important to squeeze every last byte out.

Can you add some docs in the source linking to where this IO port stuff is described? I'm not familiar with it myself. I'm assuming GBATEK has a section about it so just a link to that would suffice.