/* * Licensed under the BSD license * * debug_32x.c - Debug screen functions. * * Copyright (c) 2005 Marcus R. Brown * Copyright (c) 2005 James Forshaw * Copyright (c) 2005 John Kelley * * Altered for 32X by Chilly Willy */ #include "32x.h" #include #include #include static int init = 0; static unsigned short fgc = 0, bgc = 0; static unsigned char fgs = 0, bgs = 0; static unsigned short currentFB = 0; void Hw32xSetFGColor(int s, int r, int g, int b) { volatile unsigned short *palette = &MARS_CRAM; fgs = s; fgc = COLOR(r, g, b); palette[fgs] = fgc; } void Hw32xSetBGColor(int s, int r, int g, int b) { volatile unsigned short *palette = &MARS_CRAM; bgs = s; bgc = COLOR(r, g, b); palette[bgs] = bgc; } void Hw32xInit(int vmode, int lineskip) { volatile unsigned short *frameBuffer16 = &MARS_FRAMEBUFFER; int i; // Wait for the SH2 to gain access to the VDP while ((MARS_SYS_INTMSK & MARS_SH2_ACCESS_VDP) == 0) ; if (vmode == MARS_VDP_MODE_32K) { // Set 16-bit direct mode, 224 lines MARS_VDP_DISPMODE = MARS_224_LINES | MARS_VDP_MODE_32K; // init both framebuffers // Flip the framebuffer selection bit and wait for it to take effect MARS_VDP_FBCTL = currentFB ^ 1; while ((MARS_VDP_FBCTL & MARS_VDP_FS) == currentFB) ; currentFB ^= 1; // rewrite line table for (i=0; i<224/(lineskip+1); i++) { if (lineskip) { int j = lineskip + 1; while (j) { frameBuffer16[i*(lineskip+1) + (lineskip + 1 - j)] = i*320 + 0x100; /* word offset of line */ j--; } } else { if (i<200) frameBuffer16[i] = i*320 + 0x100; /* word offset of line */ else frameBuffer16[i] = 200*320 + 0x100; /* word offset of line */ } } // clear screen for (i=0x100; i<0x10000; i++) frameBuffer16[i] = 0; // Flip the framebuffer selection bit and wait for it to take effect MARS_VDP_FBCTL = currentFB ^ 1; while ((MARS_VDP_FBCTL & MARS_VDP_FS) == currentFB) ; currentFB ^= 1; // rewrite line table for (i=0; i<224/(lineskip+1); i++) { if (lineskip) { int j = lineskip + 1; while (j) { frameBuffer16[i*(lineskip+1) + (lineskip + 1 - j)] = i*320 + 0x100; /* word offset of line */ j--; } } else { if (i<200) frameBuffer16[i] = i*320 + 0x100; /* word offset of line */ else frameBuffer16[i] = 200*320 + 0x100; /* word offset of line */ } } // clear screen for (i=0x100; i<0x10000; i++) frameBuffer16[i] = 0; } Hw32xSetFGColor(255,31,31,31); Hw32xSetBGColor(0,0,0,0); init = vmode; } void Hw32xScreenClear() { int i; int l = (init == MARS_VDP_MODE_256) ? 320*224/2 + 0x100 : 320*200 + 0x100; volatile unsigned short *frameBuffer16 = &MARS_FRAMEBUFFER; // clear screen for (i=0x100; i