Group assets into the same bank
masterTo ensure multiple assets are allocated into the same bank, wrap their filenames in curly braces { and } on separate lines within the assets2banks.cfg file.
{
some_file.bin
some_other_file.bin
}repository·master·Indexed 43 days ago
https://github.com/sverx/devkitsmsA collection of tools and libraries for developing homebrew software for SEGA Master System, Game Gear, SG-1000/SC-3000, and ColecoVision using C and the SDCC compiler. Includes SMSlib for high-level system tasks, MBMlib for MoonBlaster module playback on FM chips, and PSGlib for PSG music and sound effect management.
To ensure multiple assets are allocated into the same bank, wrap their filenames in curly braces { and } on separate lines within the assets2banks.cfg file.
{
some_file.bin
some_other_file.bin
}When a config file is used, assets2banks processes attributes in a specific sequence. Understanding this order is critical when combining multiple attributes:
:format, :text, :ignore, and :alias are applied first.:segment instructions).:discard attributes are applied to remove unwanted data.:overwrite, :modify, and :replace are applied to the remaining data.:header and :append are applied last to add leading/trailing values.If PSGLIB_MULTIBANK is defined before including PSGlib.h, the library supports song data larger than 16kB by automatically switching ROM banks.
PSGPlay, PSGPlayLoops, or PSGPlayNoRepeat, you provide an initial bank. PSGlib remembers this bank and automatically switches banks during PSGFrame() calls if the song data spans multiple banks.PSGFrame() returns, the current bank in slot 2 may have changed. You should take steps to manage this, such as manually setting the bank again or using SMS_saveROMBank/restoreROMBank to ensure your program's execution context remains correct.If PSGLIB_MULTIBANK is not defined:
PSGFrame().To build a program for the Sega Master System (SMS) or Game Gear using SMSlib, you must follow a three-step compilation and linking process using sdcc and ihx2sms.
sdcc with the -mz80 flag, include the SMSlib source directory with -I, and provide the peep-file rules.crt0_sms.rel), the SMSlib library, and your compiled .rel files. Ensure crt0_sms.rel is the first object in the link command. Use --no-std-crt0 and specify the data location (e.g., --data-loc 0xC000)..ihx file to a .sms file using ihx2sms.When targeting the Game Gear instead of the SMS:
TARGET_GG by adding the -DTARGET_GG flag to the sdcc command.SMSlib_GG.lib instead of SMSlib.lib during the linking step.# Step 1: Compile to .rel
sdcc -mz80 -I../../SMSlib/src --peep-file ../../SMSlib/src/peep-rules.txt -c main.c
# Step 2: Link to .ihx
sdcc -o first.ihx --no-std-crt0 --data-loc 0xC000 ../../crt0/crt0_sms.rel ../../SMSlib/src/SMSlib.lib main.rel
# Step 3: Convert to .sms
ihx2sms first.ihx first.smsTo build a program for the Sega Master System using SMSlib, you must follow a three-step compilation and linking process using sdcc and ihx2sms.
sdcc with the -mz80 target. You must include the SMSlib source directory with the -I flag and provide the peep-rules file using --peep-file to ensure correct Z80 instruction optimization..rel files. The linking order is critical: the startup code (crt0_sms.rel) must come first, followed by the SMSlib library (SMSlib.lib), and finally your application's .rel files. Use --no-std-crt0 and specify the data location (e.g., --data-loc 0xC000)..ihx file to a .sms file using the ihx2sms tool.# Step 1: Compile source files
sdcc -mz80 -I../../SMSlib/src --peep-file ../../SMSlib/src/peep-rules.txt -c main.c
# Step 2: Link files
sdcc -o hello.ihx --no-std-crt0 --data-loc 0xC000 ../../crt0/crt0_sms.rel ../../SMSlib/src/SMSlib.lib main.rel
# Step 3: Convert to .sms
ihx2sms hello.ihx hello.smsUse the makecvmc tool to convert Intel Hex (.ihx) files (typically generated by SDCC) into binary (.rom) files compatible with ColecoVision MegaCart ROMs.
The tool supports specific ROM sizes: 128, 256, 512, or 1024 KiB. Files of any other size are not supported and will not be generated.
makecvmc [options] infile.ihx outfile.romYou can load SGlib software onto an SC-3000 BASIC cartridge via the cassette interface. The program is loaded to address 0x9800 and executed using CALL &H9800 in BASIC.
Steps:
crt0_BASIC.rel and set --code-loc 0x98a0 to place code after the interrupt handler.objcopy to convert the .ihx output to a .bin file.SC-TapeWave to convert the binary into an SC-3000 formatted audio file.Note: Program size is limited by RAM: BASIC IIIa has 12 KiB available after the load address; BASIC IIIb has 26 KiB.
# 1. Link
sdcc -o your_program.ihx -mz80 --no-std-crt0 --code-loc 0x98a0 --data-loc 0xC000 crt0_BASIC.rel your_program.rel SGlib.lib
# 2. Convert to binary
objcopy -Iihex -Obinary your_program.ihx your_program.binThe --firstbank option can be used to allocate a single asset or asset group larger than 16 KB, or to consolidate all assets into a single 32 KiB ROM block.
To create a 32 KiB block for assets:
assets2banks assets --firstbank=1,32768 --compileIf using --compile (Segmented):
Use the -Wl-b_BANK1=0x0000 flag:
sdcc -o output.ihx -mz80 --data-loc 0xC000 -Wl-b_BANK1=0x0000 --no-std-crt0 crt0_sms.rel main.rel SMSlib.lib bank1.relIf compiling bank1.c manually (Non-segmented):
Omit the BANK1 linker instruction:
sdcc -o output.ihx -mz80 --data-loc 0xC000 --no-std-crt0 crt0_sms.rel main.rel SMSlib.lib bank1.relassets2banks assets --firstbank=1,32768 --compileTo build the palette64 example, use the included Makefile. This process assumes that sdcc and ihx2sms are available in your system's PATH. If you have compiled SMSlib yourself, you must edit the Makefile to point to your custom library location instead of the pre-compiled version in the repository.
The compilation workflow follows three steps:
.c files are compiled into .rel objects using sdcc with the -c flag, including the SMSlib source directory and peep-file rules..rel files are linked into an .ihx file. The linker requires crt0_sms.rel to be listed first, followed by the SMSlib.lib library, and finally the individual object files..ihx file is converted to a playable .sms ROM using the ihx2sms tool.# Step 1: Compile to .rel
sdcc -mz80 -I../../SMSlib/src --peep-file ../../SMSlib/src/peep-rules.txt -c main.c
# Step 2: Link to .ihx
sdcc -o palette64.ihx --no-std-crt0 --data-loc 0xC000 ../../crt0/crt0_sms.rel ../../SMSlib/src/SMSlib.lib main.rel
# Step 3: Convert to .sms
ihx2sms palette64.ihx palette64.smsDepending on your target hardware, you must place specific runtime files and libraries in your project root (or in subfolders like crt0/, SMSlib/, etc.).
| Target Platform | Runtime File (in crt0/) | Library Files (in SMSlib/ or SGlib/) |
|---|---|---|
| Master System (SMS) | crt0_sms.rel | SMSlib.h, SMSlib.lib |
| Game Gear (GG) | crt0_sms.rel | SMSlib.h, SMSlib_GG.lib |
| SG-1000/SC-3000 | crt0_sg.rel | SGlib.h, SGlib.lib |
| ColecoVision (CV) | crt0_cv.rel | SGlib.h, SGlib_CV.lib |
Optional Libraries:
PSGlib.h and PSGlib.lib (use PSGlib_CV.lib for ColecoVision).MBMlib.h and MBMlib.rel.To build an SMS program, include SMSlib.h in your source code. The build process involves three steps: compiling, linking, and generating the ROM.
1. Compile:
Use sdcc with the -mz80 flag and the peep-rules.txt file.
2. Link:
Link with crt0_sms.rel first, then your object file, then SMSlib.lib last. Use --no-std-crt0 and specify the data location.
3. Generate ROM:
Use the makesms utility to convert the .ihx file to a .sms file. The utility handles ROM size padding (multiples of 16 KiB) and checksums if a SEGA header is present.
# 1. Compile
sdcc -c -mz80 --peep-file peep-rules.txt your_program.c
# 2. Link (Note order: crt0 first, library last)
sdcc -o your_program.ihx -mz80 --no-std-crt0 --data-loc 0xC000 crt0_sms.rel your_program.rel SMSlib.lib
# 3. Build ROM
makesms your_program.ihx your_program.smsTo use ROMs larger than 48 KiB, you must use bank mapping.
1. Code Constraints:
Your main code must be restricted to the first 32 KiB, as the last 16 KiB is paged out. Use the SMS_mapROMBank(n) or SG_mapROMBank(n) macro to map banks.
2. Data Organization:
Place data into separate .c files for each 16 KiB bank (e.g., bank2.c, bank3.c). Compile each with a unique CONST segment name:
sdcc -c -mz80 --constseg BANK2 bank2.c3. Linking:
Instruct the linker to place data banks at 0x8000 + (bank_number * 0x10000). For example, BANK2 goes to 0x28000. The crt0 file must come first, and bank .rel files must come last in ascending order.
Example Linker Command:
sdcc -o your_program.ihx -mz80 --no-std-crt0 --data-loc 0xC000 -Wl-b_BANK2=0x28000 -Wl-b_BANK3=0x38000 crt0_sms.rel your_program.rel SMSlib.lib bank2.rel bank3.rel# Compile data banks
sdcc -c -mz80 --constseg BANK2 bank2.c
sdcc -c -mz80 --constseg BANK3 bank3.c
# Link everything
sdcc -o your_program.ihx -mz80 --no-std-crt0 --data-loc 0xC000 -Wl-b_BANK2=0x28000 -Wl-b_BANK3=0x38000 crt0_sms.rel your_program.rel SMSlib.lib bank2.rel bank3.rel