Skip to content

gba: add bios interrupt flags#5445

Open
zowhoey wants to merge 2 commits into
tinygo-org:devfrom
zowhoey:bios_interrupt_flag
Open

gba: add bios interrupt flags#5445
zowhoey wants to merge 2 commits into
tinygo-org:devfrom
zowhoey:bios_interrupt_flag

Conversation

@zowhoey
Copy link
Copy Markdown

@zowhoey zowhoey commented Jun 5, 2026

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
Copy link
Copy Markdown
Author

zowhoey commented Jun 5, 2026

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
Copy link
Copy Markdown
Author

zowhoey commented Jun 6, 2026

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.

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