github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/src/machine/machine_gameboyadvance.go (about) 1 //go:build gameboyadvance 2 3 package machine 4 5 import ( 6 "device/gba" 7 8 "image/color" 9 "runtime/volatile" 10 "unsafe" 11 ) 12 13 // Not sure what name to pick here. Not using ARM7TDMI because that's the CPU 14 // name, not the device name. 15 const deviceName = "GBA" 16 17 // Interrupt numbers as used on the GameBoy Advance. Register them with 18 // runtime/interrupt.New. 19 const ( 20 IRQ_VBLANK = gba.IRQ_VBLANK 21 IRQ_HBLANK = gba.IRQ_HBLANK 22 IRQ_VCOUNT = gba.IRQ_VCOUNT 23 IRQ_TIMER0 = gba.IRQ_TIMER0 24 IRQ_TIMER1 = gba.IRQ_TIMER1 25 IRQ_TIMER2 = gba.IRQ_TIMER2 26 IRQ_TIMER3 = gba.IRQ_TIMER3 27 IRQ_COM = gba.IRQ_COM 28 IRQ_DMA0 = gba.IRQ_DMA0 29 IRQ_DMA1 = gba.IRQ_DMA1 30 IRQ_DMA2 = gba.IRQ_DMA2 31 IRQ_DMA3 = gba.IRQ_DMA3 32 IRQ_KEYPAD = gba.IRQ_KEYPAD 33 IRQ_GAMEPAK = gba.IRQ_GAMEPAK 34 ) 35 36 // Set has not been implemented. 37 func (p Pin) Set(value bool) { 38 // do nothing 39 } 40 41 var Display = DisplayMode3{(*[160][240]volatile.Register16)(unsafe.Pointer(uintptr(gba.MEM_VRAM)))} 42 43 type DisplayMode3 struct { 44 port *[160][240]volatile.Register16 45 } 46 47 func (d *DisplayMode3) Configure() { 48 // Use video mode 3 (in BG2, a 16bpp bitmap in VRAM) and Enable BG2 49 gba.DISP.DISPCNT.Set(gba.DISPCNT_BGMODE_3<<gba.DISPCNT_BGMODE_Pos | 50 gba.DISPCNT_SCREENDISPLAY_BG2_ENABLE<<gba.DISPCNT_SCREENDISPLAY_BG2_Pos) 51 } 52 53 func (d *DisplayMode3) Size() (x, y int16) { 54 return 240, 160 55 } 56 57 func (d *DisplayMode3) SetPixel(x, y int16, c color.RGBA) { 58 d.port[y][x].Set((uint16(c.R) >> 3) | ((uint16(c.G) >> 3) << 5) | ((uint16(c.B) >> 3) << 10)) 59 } 60 61 func (d *DisplayMode3) Display() error { 62 // Nothing to do here. 63 return nil 64 }