84 lines
1.6 KiB
TypeScript
84 lines
1.6 KiB
TypeScript
/** Original test cartridge: no Nintendo logo, boot ROM, graphics, or game code.
|
|
* A tiny CPU loop draws a striped tile and writes joypad reads to battery RAM.
|
|
* This intentionally bypasses the product ROM gate ONLY in the test harness.
|
|
*/
|
|
export function syntheticRom(): Uint8Array {
|
|
const rom = new Uint8Array(32768);
|
|
rom.set([0xc3, 0x50, 0x01], 0x100); // JP $0150
|
|
rom.set(new TextEncoder().encode("CRYSTALTEST"), 0x134);
|
|
rom[0x143] = 0x80; // CGB-capable
|
|
rom[0x147] = 0x10; // MBC3 + RTC + RAM + battery
|
|
rom[0x148] = 0;
|
|
rom[0x149] = 3; // 32 KiB RAM
|
|
const code = [
|
|
0xf3, // DI
|
|
0x31,
|
|
0xfe,
|
|
0xff, // LD SP,$fffe
|
|
0xaf,
|
|
0xe0,
|
|
0x40, // LCD off
|
|
0x3e,
|
|
0x0a,
|
|
0xea,
|
|
0,
|
|
0, // enable cartridge RAM
|
|
0x3e,
|
|
0x80,
|
|
0xe0,
|
|
0x68, // CGB background palette auto-increment
|
|
0x3e,
|
|
0xff,
|
|
0xe0,
|
|
0x69,
|
|
0x3e,
|
|
0x7f,
|
|
0xe0,
|
|
0x69, // white
|
|
0xaf,
|
|
0xe0,
|
|
0x69,
|
|
0xe0,
|
|
0x69, // black
|
|
0x21,
|
|
0,
|
|
0x80,
|
|
0x06,
|
|
0x10,
|
|
0x3e,
|
|
0xaa, // HL=$8000, B=16, A=$aa
|
|
0x22,
|
|
0x05,
|
|
0x20,
|
|
0xfc, // tile pattern
|
|
0x3e,
|
|
0xe4,
|
|
0xe0,
|
|
0x47, // DMG palette
|
|
0x3e,
|
|
0x91,
|
|
0xe0,
|
|
0x40, // LCD on, background tile 0
|
|
];
|
|
const loop = 0x150 + code.length;
|
|
code.push(
|
|
0x3e,
|
|
0x10,
|
|
0xe0,
|
|
0,
|
|
0xf0,
|
|
0,
|
|
0xea,
|
|
0,
|
|
0xa0,
|
|
0xc3,
|
|
loop & 255,
|
|
loop >> 8,
|
|
);
|
|
rom.set(code, 0x150);
|
|
let checksum = 0;
|
|
for (let i = 0x134; i <= 0x14c; i++) checksum = (checksum - rom[i] - 1) & 255;
|
|
rom[0x14d] = checksum;
|
|
return rom;
|
|
}
|