-
Notifications
You must be signed in to change notification settings - Fork 997
Closed
Description
I've been unable to get interrupt handlers working on the gameboy-advance target. Below is a minimal example that changes the color of a pixel based on A or B button presses.
package main
import (
"image/color"
"machine"
"runtime/interrupt"
"runtime/volatile"
"unsafe"
)
var KEYPAD = (*volatile.Register16)(unsafe.Pointer(uintptr(0x04000130)))
var KEYCNT = (*volatile.Register16)(unsafe.Pointer(uintptr(0x04000132)))
var display = machine.Display
func main() {
display.Configure()
display.SetPixel(120, 80, color.RGBA{R: 255})
KEYCNT.Set(0x0003) // generate interrupts for A and B buttons
interrupt.New(machine.IRQ_KEYPAD, keypadIrq).Enable()
for {
//readKeypad()
}
}
func readKeypad() {
if KEYPAD.Get()&1 == 0 {
// A is pushed when bit 0 is cleared
display.SetPixel(120, 80, color.RGBA{G: 255})
} else if KEYPAD.Get()&2 == 0 {
// B is pushed when bit 1 is cleared
display.SetPixel(120, 80, color.RGBA{B: 255})
}
}
func keypadIrq(interrupt.Interrupt) {
readKeypad()
}This builds and runs fine when polling for button pushes with readKeypad(). The KEYCTL, IE, IF, and IME registers all seem to be set correctly, according to the mgba emulator.
Using GDB I can get a breakpoint on handleInterrupt(), but callInterruptHandler() doesn't seem to go anywhere.
Could this be an issue with switching from system mode to user mode, or with the change from Thumb2 to ARM?
Metadata
Metadata
Assignees
Labels
No labels