Skip to content

gba: add bios interrupt flags#5445

Merged
deadprogram merged 2 commits into
tinygo-org:devfrom
zowhoey:bios_interrupt_flag
Jun 7, 2026
Merged

gba: add bios interrupt flags#5445
deadprogram merged 2 commits into
tinygo-org:devfrom
zowhoey:bios_interrupt_flag

Conversation

@zowhoey

@zowhoey zowhoey commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Adds a new GBA register for interrupt flags, the register is equivalent
to the IF register, but is intended for BIOS functions.

Acknowledging the interrupts with this register allows us to use BIOS
halt functions such as VBlankIntrWait and IntrWait, which we can use to
get rid of busy loops in the GBA code.

Example code:

func vblank(interrupt.Interrupt) {}

func main() {
        // enable vblank interrupt
        gba.DISP.DISPSTAT.ReplaceBits(1, 1, 3)
        // setup a vblank handler
        interrupt.New(machine.IRQ_VBLANK, vblank).Enable()
        for {
                if gba.DISP.VCOUNT.Get() > 160 {
                        println("vblanking")
                } else {
                        println("busy loop")
                }

                // uncomment to get rid of the busy loop
                // call VBlankIntrWait
                // arm.SVCall0(0x05 << 16)
        }
}

Adds a new GBA register for interrupt flags, the register is equivalent
to the IF register, but is intended for BIOS functions.

Acknowledging the interrupts with this register allows us to use BIOS
halt functions such as VBlankIntrWait and IntrWait, which we can use to
get rid of busy loops in the GBA code.
@zowhoey
zowhoey marked this pull request as ready for review June 5, 2026 21:08
@zowhoey

zowhoey commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

Related question: if I were to implement some of the BIOS functions should they go into tinygba or into the device/gba package? Having it in device/gba might be nice as we could use the BIOS halt function in func abort() in the runtime code.

@deadprogram

Copy link
Copy Markdown
Member

if I were to implement some of the BIOS functions should they go into tinygba or into the device/gba package? Having it in device/gba might be nice as we could use the BIOS halt function in func abort() in the runtime code.

Probably in device/gba since they are the actual ROM functions. tinygba tries to provide "tools and helpers".

@deadprogram

Copy link
Copy Markdown
Member
Unformatted:
  src/runtime/interrupt/interrupt_gameboyadvance.go
make: *** [GNUmakefile:213: fmt-check] Error 1

Please run go fmt so this PR can pass the CI tests. Thanks!

@zowhoey

zowhoey commented Jun 6, 2026

Copy link
Copy Markdown
Contributor Author

Woops! I've disabled auto-formatting in my IDE for tinygo as my usual formatting has a lot more rules and was affecting random code unrelated to the change.

Comment thread src/device/gba/gba.go
@deadprogram

Copy link
Copy Markdown
Member

I really wanted this myself, pretty excited to get rid of the looping!

@deadprogram

Copy link
Copy Markdown
Member

OK thank you very much @zowhoey now squash/merging.

@deadprogram
deadprogram merged commit cd364a9 into tinygo-org:dev Jun 7, 2026
28 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants