rust-console / gba

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

Minimal Manual Interrupt Service Routine #48

Closed Lokathor closed 5 years ago

Lokathor commented 5 years ago

Thanks to a bit of madness and a contribution from @aaaaaa123456789 of the gbdev Discord (ax6 on the Discord), it has been decided that, even if the ability to program an arbitrary ISR that's reusable within the crates ecosystem is not currently easy/possible, we can still hand code a basic ISR for just acknowledging a vblank, which allows us to at least use bios::vblank_interrupt_wait.

This is a stepping stone, not a destination.

But all we have to do is make a static array of u32 values, the raw opcodes of the ARM assembly we want, and then use the pointer to that as our interrupt handling pointer.

They kindly provided the handler code and the u32 values of said code for us:

  mov r0, 0x04000002 @e3a00381
  add r0, 0x200      @e2800f80
  mov r1, -1         @e3e01000
  strh r1, [r0]      @e1c010b0
  bx lr              @e12fff1e
aaaaaa123456789 commented 5 years ago

Do remember that this array has to be aligned (to an address that is a multiple of four), or you'll get a lot of weirdness.

Lokathor commented 5 years ago

Ah, yes. If it's typed as [u32;5] then the fact that they're u32 values will keep it aligned, but very important to keep in mind.

Lokathor commented 5 years ago

Sorted this out with the full interrupt handler update