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.
Hello.
I would like to convert my current RGBASM code for the classic Game Boy to the Game Boy Color code.
https://dl.dropboxusercontent.com/s/zsi … ne_test.gb
Video:
https://www.youtube.com/watch?v=XBu2Ot5yiqc
I can't find any information or any GBC "INIT" for RGBASM.
The question is whether the current code for MBC1 will work after changes to GBC? Do I need to change it to e.g. MBC5?
Generally, what changes do I need to add to the current RGBASM code for GB Classic - are there any registers that need to be set at the beginning of the code? Of course, I understand that I also need to change the color palette code.
The code compiles using these arguments:
@echo off set name="demo" set path=rgbds\ rgbasm -o %name%.o %name%.asm rgblink -o %name%.gbc %name%.o rgbfix -c -C -v -p 0 %name%.gbc echo Done. del *.o pause
In the RGBFIX documentation I have:
-C, --color-only
Set the Game Boy Color–only flag: 0x143 = 0xC0. If both this and the -c flag are set, this takes precedence.
-c, --color-compatible
Set the Game Boy Color–compatible flag: 0x143 = 0x80. If both this and the -C flag are set, -C takes precedence.
Cartridge Header code:
"0143 - CGB Flag
In older cartridges this byte has been part of the Title (see above). In CGB cartridges the upper bit is used to enable CGB functions.
This is required, otherwise the CGB switches itself into Non-CGB-Mode. Typical values are:
80h - Game supports CGB functions, but works on old gameboys also.
C0h - Game works on CGB only (physically the same as 80h)."
When I use it, compilation gives an error:
"error: Unable to place "Cartridge Header" (ROM0 section) at address $0100: section overlaps with "Program Start"
;---------------------------------------------------------- INCLUDE "hardware.inc" ;---------------------------------------------------------- ; RESTART VECTORS: ;---------------------------------------------------------- SECTION "RST_00",ROM0[$0000] RET SECTION "RST_08",ROM0[$0008] RET SECTION "RST_10",ROM0[$0010] RET SECTION "RST_18",ROM0[$0018] RET SECTION "RST_20",ROM0[$0020] RET SECTION "RST_28",ROM0[$0028] RET SECTION "RST_30",ROM0[$0030] RET SECTION "RST_38",ROM0[$0038] RET ;---------------------------------------------------------- ; INTERRUPT VECTORS: ;---------------------------------------------------------- SECTION "VBL Interrupt Vector",ROM0[$0040] JP VBlank_Handler SECTION "LCD Interrupt Vector",ROM0[$0048] RETI SECTION "TIM Interrupt Vector",ROM0[$0050] RETI SECTION "SIO Interrupt Vector",ROM0[$0058] RETI SECTION "JOY Interrupt Vector",ROM0[$0060] RETI ;---------------------------------------------------------- ; CARTRIDGE HEADER: ;---------------------------------------------------------- SECTION "Cartridge Header",ROM0[$0100] NOP JP StartPoint NINTENDO_LOGO ; 134 DB "0123456789ABCDEF" ; DB $C0 ; Gbc flag ; 144 DB 0,0 ; LICENCEE DB 0 ; SGB FLaG DB 1 ; CaRTTYPE ; 1=MBC1 DB 0 ; ROMSIZE DB 0 ; RaMSIZE DB $01 ; destination (0 = Japan, 1 = Non Japan) DB $00 ; Manufacturer DB 0 ; Version DB 0 ; Complement check DW 0 ; Checksum ;---------------------------------------------------------- ; INITIALIZE THE GAMEBOY: ;---------------------------------------------------------- SECTION "Program Start",ROM0[$0150] StartPoint: (...)
Last edited by siudym (2024-04-01 14:00:20)
Offline
Hi. The error happens because the GBC compatibility field reused the last byte of the name field. So when you add the flag you need to remove one character from the name. Otherwise everything after that is pushed forward and collides with the next section at $150. Even if it didn't collide, all the values would be in the wrong place now. For example:
DB "0123456789ABCDE" DB $C0 ; Gbc flag
But it's probably even better to just fill the header with zeros and let rgbfix fill it in. This is its job after all.
SECTION "Cartridge Header",ROM0[$0100] NOP JP StartPoint ds $150 - @, 0 ; Fill with zeros up to $150.
Then:
rgbfix -C -v -p 0 -t "0123456789ABCDE" -m 0x01 --non-japanese %name%.gbc
You can see in the rgbfix manual what each flag means.
If the GBC flag is correct, you can now check if the CPU register is $11 on startup.
If you want the game to be GBC only, it's still nice to the player if you show a small error screen if the game detects is not running on a GBC.
If you want the game to be compatible with both GBC and earlier hardware, check if A==$11 on startup and store the result in a variable. You can then check this later whenever some code is different between GBC and other models.
Other things you can do with GBC:
Set the palette. When the GBC starts, all background palettes are set to white, and all sprite palettes are random. You should really set the palettes if you want to see something on the screen.
Set attribute map and additional tiles. The attribute map can be activated by writing 1 to rVBK ($FF4F) and deactivated by writing 0. This lets you access the attributes for each tiles in the $9800-$9BFF or $9C00-$9FFF. The address is the same, if your tile was located at address $9814, the attribute is also located at $9814 after writing 1 to rVBK. But you can also just fill the whole attribute map with 0 to start with. This will select palette 0 and no special attributes.
Set double speed mode. If you want to. Don't do this unless you need to, if you want to save batteries when running on real hardware.
There are more things as well that are unique to GBC, but you that's the most important to get you started.
You can read more in Pan Docs.
https://gbdev.io/pandocs/
Offline
I've already managed to figure it out, not tested on a real console, but it runs on emulicious and bgb - it can run on both GBC classic and GBC with colors (I think so) :
https://www.dropbox.com/scl/fi/nmhhk7t3 … or.gb?dl=1
Last edited by siudym (2024-04-04 05:52:29)
Offline