targets: add support for GameBoy Advance

Only tested in an emulator (mGBA). Almost nothing is supported, but
drawing to the screen works.
This commit is contained in:
Ayke van Laethem
2019-08-01 15:25:09 +02:00
committed by Ron Evans
parent 9878f7ebc4
commit 9846c062b3
7 changed files with 301 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
package main
// Draw a red square on the GameBoy Advance screen.
import (
"image/color"
"machine"
)
var display = machine.Display
func main() {
display.Configure()
for x := int16(30); x < 50; x++ {
for y := int16(80); y < 100; y++ {
display.SetPixel(x, y, color.RGBA{255, 0, 0, 255})
}
}
display.Display()
}
+44
View File
@@ -0,0 +1,44 @@
// +build gameboyadvance
package machine
import (
"image/color"
"runtime/volatile"
"unsafe"
)
// Make it easier to directly write to I/O RAM.
var ioram = (*[0x400]volatile.Register8)(unsafe.Pointer(uintptr(0x04000000)))
type PinMode uint8
// Set has not been implemented.
func (p Pin) Set(value bool) {
// do nothing
}
var Display = FramebufDisplay{(*[160][240]volatile.Register16)(unsafe.Pointer(uintptr(0x06000000)))}
type FramebufDisplay struct {
port *[160][240]volatile.Register16
}
func (d FramebufDisplay) Configure() {
// Write into the I/O registers, setting video display parameters.
ioram[0].Set(0x03) // Use video mode 3 (in BG2, a 16bpp bitmap in VRAM)
ioram[1].Set(0x04) // Enable BG2 (BG0 = 1, BG1 = 2, BG2 = 4, ...)
}
func (d FramebufDisplay) Size() (x, y int16) {
return 240, 160
}
func (d FramebufDisplay) SetPixel(x, y int16, c color.RGBA) {
d.port[y][x].Set(uint16(c.R)&0x1f | uint16(c.G)&0x1f<<5 | uint16(c.B)&0x1f<<10)
}
func (d FramebufDisplay) Display() error {
// Nothing to do here.
return nil
}
+101
View File
@@ -0,0 +1,101 @@
// +build arm7tdmi
package runtime
import (
"device/arm"
"unsafe"
)
const TargetBits = 32
const GOARCH = "arm"
type timeUnit int64
const tickMicros = 1
func putchar(c byte) {
// dummy, TODO
}
//go:extern _sbss
var _sbss unsafe.Pointer
//go:extern _ebss
var _ebss unsafe.Pointer
//go:extern _sdata
var _sdata unsafe.Pointer
//go:extern _sidata
var _sidata unsafe.Pointer
//go:extern _edata
var _edata unsafe.Pointer
// Entry point for Go. Initialize all packages and call main.main().
//go:export main
func main() {
// Initialize .data and .bss sections.
preinit()
// Run initializers of all packages.
initAll()
// Compiler-generated call to main.main().
callMain()
}
func preinit() {
// Initialize .bss: zero-initialized global variables.
ptr := unsafe.Pointer(&_sbss)
for ptr != unsafe.Pointer(&_ebss) {
*(*uint32)(ptr) = 0
ptr = unsafe.Pointer(uintptr(ptr) + 4)
}
// Initialize .data: global variables initialized from flash.
src := unsafe.Pointer(&_sidata)
dst := unsafe.Pointer(&_sdata)
for dst != unsafe.Pointer(&_edata) {
*(*uint32)(dst) = *(*uint32)(src)
dst = unsafe.Pointer(uintptr(dst) + 4)
src = unsafe.Pointer(uintptr(src) + 4)
}
}
func ticks() timeUnit {
// TODO
return 0
}
const asyncScheduler = false
func sleepTicks(d timeUnit) {
// TODO
}
func abort() {
// TODO
for {
}
}
func getCurrentStackPointer() uintptr {
return arm.ReadRegister("sp")
}
// Implement memset for LLVM and compiler-rt.
//go:export memset
func libc_memset(ptr unsafe.Pointer, c byte, size uintptr) {
for i := uintptr(0); i < size; i++ {
*(*byte)(unsafe.Pointer(uintptr(ptr) + i)) = c
}
}
// Implement memmove for LLVM and compiler-rt.
//go:export memmove
func libc_memmove(dst, src unsafe.Pointer, size uintptr) {
memmove(dst, src, size)
}