-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
gba: add support for mGBA debugging #5443
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
Open
zowhoey
wants to merge
1
commit into
tinygo-org:dev
Choose a base branch
from
zowhoey:mgba-debug-print
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+123
−2
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| //go:build arm7tdmi | ||
| //go:build arm7tdmi && !mgbadebug | ||
|
|
||
| package runtime | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| //go:build gameboyadvance && mgbadebug | ||
|
|
||
| package runtime | ||
|
|
||
| import ( | ||
| _ "runtime/interrupt" // make sure the interrupt handler is defined | ||
| "runtime/volatile" | ||
| "unsafe" | ||
| ) | ||
|
|
||
| var ( | ||
| // Setting this memory address to 0xC0DE enables mGBA's debug printing | ||
| debugEnable = (*volatile.Register16)(unsafe.Pointer(uintptr(0x4FFF780))) | ||
| // mGBA supports log levels from 0x100(fatal) to 0x104(debug) | ||
| logLevel uint16 = 0x104 // use the debug log level | ||
| // Once we are ready to output we set the debug flags register to logLevel | ||
| // mGBA will output the text and then clear the text buffer when set | ||
| debugFlags = (*volatile.Register16)(unsafe.Pointer(uintptr(0x4FFF700))) | ||
|
|
||
| textBuffer = (*[255]byte)(unsafe.Pointer(uintptr(0x4FFF600))) | ||
| index = 0 | ||
| ) | ||
|
|
||
| func putchar(c byte) { | ||
| if c == '\n' || index >= len(textBuffer) { | ||
| debugFlags.Set(logLevel) | ||
| index = 0 | ||
|
|
||
| // mGBA automatically prints a new line so we can ignore it | ||
| if c == '\n' { | ||
| return | ||
| } | ||
| } | ||
|
|
||
| textBuffer[index] = c | ||
| index++ | ||
| } | ||
|
|
||
| func getchar() byte { | ||
| // dummy, TODO | ||
| return 0 | ||
| } | ||
|
|
||
| func buffered() int { | ||
| // dummy, TODO | ||
| return 0 | ||
| } | ||
|
|
||
| //go:extern _sbss | ||
| var _sbss [0]byte | ||
|
|
||
| //go:extern _ebss | ||
| var _ebss [0]byte | ||
|
|
||
| //go:extern _sdata | ||
| var _sdata [0]byte | ||
|
|
||
| //go:extern _sidata | ||
| var _sidata [0]byte | ||
|
|
||
| //go:extern _edata | ||
| var _edata [0]byte | ||
|
|
||
| // Entry point for Go. Initialize all packages and call main.main(). | ||
| // | ||
| //export main | ||
| func main() { | ||
| // Initialize .data and .bss sections. | ||
| preinit() | ||
|
|
||
| // Enable mGBA debugging. | ||
| debugEnable.Set(0xC0DE) | ||
|
|
||
| // Run program. | ||
| run() | ||
| } | ||
|
|
||
| func preinit() { | ||
| // Initialize .bss: zero-initialized global variables. | ||
| ptr := unsafe.Pointer(&_sbss) | ||
| for ptr != unsafe.Pointer(&_ebss) { | ||
| *(*uint32)(ptr) = 0 | ||
| ptr = unsafe.Add(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.Add(dst, 4) | ||
| src = unsafe.Add(src, 4) | ||
| } | ||
| } | ||
|
|
||
| func ticksToNanoseconds(ticks timeUnit) int64 { | ||
| return int64(ticks) | ||
| } | ||
|
|
||
| func nanosecondsToTicks(ns int64) timeUnit { | ||
| return timeUnit(ns) | ||
| } | ||
|
|
||
| func ticks() timeUnit { | ||
| // TODO | ||
| return 0 | ||
| } | ||
|
|
||
| func sleepTicks(d timeUnit) { | ||
| // TODO | ||
| } | ||
|
|
||
| func exit(code int) { | ||
| abort() | ||
| } | ||
|
|
||
| func abort() { | ||
| // TODO | ||
| for { | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just wonder if it might be better to add this to https://github.com/tinygo-org/tinygo/blob/dev/src/device/gba/gba.go what do you think?