Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)
You are not logged in.
I made a Key Tester using the stdio header included with GBDK. It works... Until it doesn't. All the keys register and print to the screen, except the Left(5) and Right(4) Directional Keys. Those keys throw the program into a weird state.
Pressing Left shows me this line in the Debugger (BGB):
HRAM: FFAD D3 undefined code ;0 26
Pressing Right shows me this:
HRAM: FF00 10 10 <corrupted stop> ;1 2
HRAM: FF82 B7 or a ;0 26
And this line in the bottom right:
WRA1:DFAB 00A7
I'm not at a point where I understand the debugger. In fact. this code I've written is my first dive into understanding how the Gameboy responds to software.
Here is my code so far. I used the assembly in Tetris as a base:
#include "C:\GBDK\include\stdio.h" #include "C:\GBDK\include\gb\gb.h" #define JOYPAD_REGISTER *(volatile unsigned char *)0xFF00 #define BUTTON_DOWN_REGISTER *(volatile unsigned char *)0xFF80 #define BUTTON_HIT_REGISTER *(volatile unsigned char *)0xFF81 void ReadJoypad() { unsigned char currentButtonState = 0; unsigned char previousButtonState, buttonHitState; JOYPAD_REGISTER = 1 << 5; for (int i = 0; i < 4; i++) { currentButtonState = JOYPAD_REGISTER; } currentButtonState = (~currentButtonState & 0x0F) << 4; JOYPAD_REGISTER = 1 << 4; for (int i = 0; i < 10; i++) { currentButtonState |= ~JOYPAD_REGISTER & 0x0F; } previousButtonState = BUTTON_DOWN_REGISTER; buttonHitState = (previousButtonState ^ currentButtonState) & currentButtonState; BUTTON_HIT_REGISTER = buttonHitState; BUTTON_DOWN_REGISTER = currentButtonState; JOYPAD_REGISTER = 1 << 5 | 1 << 4; } void main() { while (1) { ReadJoypad(); unsigned char buttonHitState = BUTTON_HIT_REGISTER; if (buttonHitState != 0) { for (int i = 0; i < 8; i++) { if (buttonHitState & (1 << i)) { printf("Button %d is being pressed\n", i); } } } delay(100); } }
Last edited by Sarasaworks (2024-01-23 14:12:47)
Offline
The issue was that the default address set for GBDK's OAM refresh function was 0xFF80 which conflicted with code.
Luckily, GBDK offers a solution via LCC during the linker phase:
lcc -Wl-g_refresh_OAM=0xFEFF -o test.gb main.o
This allowed me to change the address used by refresh_OAM to 0xFEFF. Which is commonly used for OAM manipulation in commercial titles.
Now, everything is in working order.
Last edited by Sarasaworks (2024-01-25 14:08:34)
Offline
WHY?!
#include <gbdk/platform.h> #include <stdio.h> uint8_t joy = 0, old_joy = 0; void main(void) { while (TRUE) { joy = joypad(); if (old_joy != joy) { for (uint8_t i = 0, j = 1; i!= 8; i++, j <<= 1) if (joy & j) printf("%hx ", j); if (joy) printf("\n"); old_joy = joy; } wait_vbl_done(); } }
then
lcc -o test.gb test.c
Offline
Because I take joy in taking things apart...
Offline
¯\_(ツ)_/¯
Offline