Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"time" appears completely useless for target gameboy-advance #1578

Closed
xen0bit opened this issue Jan 15, 2021 · 1 comment
Closed

"time" appears completely useless for target gameboy-advance #1578

xen0bit opened this issue Jan 15, 2021 · 1 comment

Comments

@xen0bit
Copy link

xen0bit commented Jan 15, 2021

package main

// Draw a red square on the GameBoy Advance screen after waiting for a period of time

import (
	"image/color"
	"machine"
	"time"
)

var display = machine.Display

func main() {
	display.Configure()

	//Try to sleep with function
	time.Sleep(10 * time.Second)
	//Try to sleep with while
	now := time.Now().Unix()
	for (time.Now().Unix() - now) < 1000000 {
		_ = 0
	}

	//Draw a red square
	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()
}

tinygo build -target gameboy-advance -o .\timetest.gba timetest.go

Expected result: There is some sort of delay before drawing the red square
Actual result: The red square is drawn immediately

Tested behavior in m-gba, visualboy advance, iodine, gbajs, and even on a legitimate Gameboy Advance SP using a flash cart.

It seems like I must be missing something obvious because this should be extremely straightforward to perform. Is time just not working for this target?

@xen0bit
Copy link
Author

xen0bit commented Jan 19, 2021

While the "time" import still doesn't seem to be working, you can reference my example code here to make a basic timer:

xen0bit/gbablog@276e29c

In the example I hook machine.IRQ_VBLANK which fires the interrupt handler roughly 59.71540070833901659232620059483728860926694 times a second. Working backward from that, you can make your own timer.

I may submit a PR to hook the actual IRQ_TIMER0 in a way that "time" will work, but for now this is a valid workaround and I'm closing this. Thanks to all who worked on the interrupts API.

@xen0bit xen0bit closed this as completed Jan 19, 2021
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

No branches or pull requests

1 participant