/* Phase 1, "Hello, 32X": one 8bpp packed-pixel frame from the cartridge, shown. * * The data come from study/hello_frame.py: frame_pal.bin (256 big-endian RGB555 words, * COLOR(r,g,b) = r | g<<5 | b<<10) and frame_pix.bin (320 x 224 palette indices). * Exit criterion (PLAN.md phase 1): the 32X-only picture is pixel-identical to * expected.png in sega32x-python. * * Pixels are written as 16-bit words: a $00 byte write to the frame buffer is ignored * (Manual 3.3), a word write is not. */ #include "mars.h" extern const uint16_t frame_pal[256]; extern const uint16_t frame_pix[320 * 224 / 2]; static void fill_back_buffer(void) { volatile uint16_t *fb = &MARS_FRAMEBUFFER; const uint16_t *src = frame_pix; /* Hw32xInit wrote the line table: line y starts at word 0x100 + y * 160. */ for (int i = 0; i < 320 * 224 / 2; i++) fb[0x100 + i] = src[i]; } static void swap(void) { uint16_t shown = MARS_VDP_FBCTL & MARS_VDP_FS; MARS_VDP_FBCTL = shown ^ 1; while ((MARS_VDP_FBCTL & MARS_VDP_FS) == shown); } int m_main(void) { Hw32xInit(MARS_VDP_MODE_256, 0); volatile uint16_t *cram = &MARS_CRAM; for (int i = 0; i < 256; i++) cram[i] = frame_pal[i]; /* Both buffers carry the frame, so either FS state shows it. */ fill_back_buffer(); swap(); fill_back_buffer(); swap(); MARS_SYS_COMM4 = 0x4F4B; /* "OK": the picture is up (read by the harness) */ for (;;); return 0; }