void PDebugShowPalette(unsigned short *screen, int stride)
{
- unsigned int *spal=(void *)Pico.cram;
- unsigned int *dpal=(void *)HighPal;
- int x, y, i;
+ int x, y;
- for (i = 0x3f/2; i >= 0; i--)
-#ifdef USE_BGR555
- dpal[i] = ((spal[i]&0x000f000f)<< 1)|((spal[i]&0x00f000f0)<<3)|((spal[i]&0x0f000f00)<<4);
-#else
- dpal[i] = ((spal[i]&0x000f000f)<<12)|((spal[i]&0x00f000f0)<<3)|((spal[i]&0x0f000f00)>>7);
-#endif
- for (i = 0x3f; i >= 0; i--)
- HighPal[0x40|i] = (unsigned short)((HighPal[i]>>1)&0x738e);
- for (i = 0x3f; i >= 0; i--) {
- int t=HighPal[i]&0xe71c;t+=0x4208;if(t&0x20)t|=0x1c;if(t&0x800)t|=0x700;if(t&0x10000)t|=0xe000;t&=0xe71c;
- HighPal[0x80|i] = (unsigned short)t;
- }
+ Pico.m.dirtyPal = 1;
+ if (PicoAHW & PAHW_SMS)
+ PicoDoHighPal555M4();
+ else
+ PicoDoHighPal555(1);
+ Pico.m.dirtyPal = 1;
screen += 16*stride+8;
for (y = 0; y < 8*4; y++)
for (y = 0; y < 8*4; y++)
for (x = 0; x < 8*16; x++)
screen[x + y*stride] = HighPal[(x/8 + (y/8)*16) | 0x80];
-
- Pico.m.dirtyPal = 1;
}
#if defined(DRAW2_OVERRIDE_LINE_WIDTH)
// stuff available in asm:\r
#ifdef _ASM_DRAW_C\r
void DrawWindow(int tstart, int tend, int prio, int sh);\r
-void BackFill(int reg7, int sh);\r
void DrawAllSprites(unsigned char *sprited, int prio, int sh);\r
void DrawTilesFromCache(int *hc, int sh, int rlim);\r
void DrawSpritesSHi(unsigned char *sprited);\r
\r
// --------------------------------------------\r
\r
-static void BackFill(int reg7, int sh)\r
+void BackFill(int reg7, int sh)\r
{\r
unsigned int back;\r
\r
}\r
}\r
\r
-static void (*FinalizeLine)(int sh) = FinalizeLineBGR444;\r
+static void (*FinalizeLine)(int sh);\r
\r
// --------------------------------------------\r
\r
--- /dev/null
+#include "pico_int.h"
+
+static void (*FinalizeLineM4)(void);
+static int skip_next_line;
+
+#define PLANAR_PIXEL(x,p) \
+ t = pack & (0x80808080 >> p); \
+ if (t) { \
+ t = ((t >> (7-p)) | (t >> (14-p)) | (t >> (21-p)) | (t >> (28-p))) & 0x0f; \
+ pd[x] = pal|t; \
+ }
+
+static int TileNormM4(int sx, int addr, int pal)
+{
+ unsigned char *pd = HighCol + sx;
+ unsigned int pack, t;
+
+ pack = *(unsigned int *)(Pico.vram + addr); /* Get 4 bitplanes / 8 pixels */
+ if (pack)
+ {
+ PLANAR_PIXEL(0, 0)
+ PLANAR_PIXEL(1, 1)
+ PLANAR_PIXEL(2, 2)
+ PLANAR_PIXEL(3, 3)
+ PLANAR_PIXEL(4, 4)
+ PLANAR_PIXEL(5, 5)
+ PLANAR_PIXEL(6, 6)
+ PLANAR_PIXEL(7, 7)
+ return 0;
+ }
+
+ return 1; /* Tile blank */
+}
+
+static int TileFlipM4(int sx,int addr,int pal)
+{
+ unsigned char *pd = HighCol + sx;
+ unsigned int pack, t;
+
+ pack = *(unsigned int *)(Pico.vram + addr); /* Get 4 bitplanes / 8 pixels */
+ if (pack)
+ {
+ PLANAR_PIXEL(0, 7)
+ PLANAR_PIXEL(1, 6)
+ PLANAR_PIXEL(2, 5)
+ PLANAR_PIXEL(3, 4)
+ PLANAR_PIXEL(4, 3)
+ PLANAR_PIXEL(5, 2)
+ PLANAR_PIXEL(6, 1)
+ PLANAR_PIXEL(7, 0)
+ return 0;
+ }
+
+ return 1; /* Tile blank */
+}
+
+struct TileStrip
+{
+ int nametab; // Position in VRAM of name table (for this tile line)
+ int line; // Line number in pixels 0x000-0x3ff within the virtual tilemap
+ int hscroll; // Horizontal scroll value in pixels for the line
+ int xmask; // X-Mask (0x1f - 0x7f) for horizontal wraparound in the tilemap
+ int *hc; // cache for high tile codes and their positions
+ int cells; // cells (tiles) to draw (32 col mode doesn't need to update whole 320)
+};
+
+static void DrawStrip(struct TileStrip *ts, int cellskip)
+{
+ int tilex,dx,ty,code=0,addr=0,cells;
+ int oldcode=-1,blank=-1; // The tile we know is blank
+ int pal=0;
+
+ // Draw tiles across screen:
+ tilex=((-ts->hscroll)>>3)+cellskip;
+ ty=(ts->line&7)<<1; // Y-Offset into tile
+ dx=((ts->hscroll-1)&7)+1;
+ cells = ts->cells - cellskip;
+ if (dx != 8) cells++; // have hscroll, need to draw 1 cell more
+ dx+=cellskip<<3;
+
+ for (; cells > 0; dx+=8,tilex++,cells--)
+ {
+ int zero;
+
+ code=Pico.vram[ts->nametab + (tilex & 0x1f)];
+ if (code==blank) continue;
+
+ if (code!=oldcode) {
+ oldcode = code;
+ // Get tile address/2:
+ addr=(code&0x1ff)<<4;
+ addr+=ty;
+ if (code&0x0400) addr^=0xe; // Y-flip
+
+ pal=((code>>7)&0x10);
+ }
+
+ if (code&0x0200) zero=TileFlipM4(dx,addr,pal);
+ else zero=TileNormM4(dx,addr,pal);
+
+ if (zero) blank=code; // We know this tile is blank now
+ }
+}
+
+static void DrawLayer(int cellskip, int maxcells)
+{
+ struct PicoVideo *pvid=&Pico.video;
+ struct TileStrip ts;
+ int vscroll;
+
+ ts.cells=maxcells;
+
+ // Find name table:
+ ts.nametab=(pvid->reg[2]&0x0e) << (10-1);
+
+ // Get horizontal scroll value, will be masked later
+ ts.hscroll=0;//pvid->reg[8];
+ vscroll=0;//pvid->reg[9]; // Get vertical scroll value
+
+ // Find the line in the name table
+ ts.line=(vscroll+DrawScanline)&0xff;
+ ts.nametab+=(ts.line>>3) << (6-1);
+
+ DrawStrip(&ts, cellskip);
+}
+
+static void DrawDisplayM4(void)
+{
+ DrawLayer(0, 32);
+}
+
+void PicoFrameStartMode4(void)
+{
+ DrawScanline = 0;
+ skip_next_line = 0;
+}
+
+void PicoLineMode4(int line)
+{
+ if (skip_next_line > 0) {
+ skip_next_line--;
+ return;
+ }
+
+ DrawScanline = line;
+
+ if (PicoScanBegin != NULL)
+ skip_next_line = PicoScanBegin(DrawScanline);
+
+ // Draw screen:
+ BackFill((Pico.video.reg[7] & 0x0f) | 0x10, 0);
+ if (Pico.video.reg[1] & 0x40)
+ DrawDisplayM4();
+
+ if (FinalizeLineM4 != NULL)
+ FinalizeLineM4();
+
+ if (PicoScanEnd != NULL)
+ skip_next_line = PicoScanEnd(DrawScanline);
+}
+
+void PicoDoHighPal555M4(void)
+{
+ unsigned int *spal=(void *)Pico.cram;
+ unsigned int *dpal=(void *)HighPal;
+ unsigned int t;
+ int i;
+
+ Pico.m.dirtyPal = 0;
+
+ /* cram is always stored as shorts, even though real hardware probably uses bytes */
+ for (i = 0x20/2; i > 0; i--, spal++, dpal++) {
+ t = *spal;
+#ifdef USE_BGR555
+ t = ((t & 0x00030003)<< 3) | ((t & 0x000c000c)<<7) | ((t & 0x00300030)<<10);
+#else
+ t = ((t & 0x00030003)<<14) | ((t & 0x000c000c)<<7) | ((t & 0x00300030)>>1);
+#endif
+ t |= t >> 2;
+ t |= (t >> 4) & 0x08610861;
+ *dpal = t;
+ }
+}
+
+static void FinalizeLineRGB555M4(void)
+{
+ unsigned short *pd=DrawLineDest;
+ unsigned char *ps=HighCol+8;
+ unsigned short *pal=HighPal;
+ int i;
+
+ if (Pico.m.dirtyPal)
+ PicoDoHighPal555M4();
+
+ if (!(PicoOpt & POPT_DIS_32C_BORDER))
+ pd += 32;
+
+ for (i = 256/4; i > 0; i--) {
+ *pd++ = pal[*ps++];
+ *pd++ = pal[*ps++];
+ *pd++ = pal[*ps++];
+ *pd++ = pal[*ps++];
+ }
+}
+
+void PicoDrawSetColorFormatMode4(int which)
+{
+ switch (which)
+ {
+ case 1: FinalizeLineM4 = FinalizeLineRGB555M4; break;
+ default:FinalizeLineM4 = NULL; break;
+ }
+#if OVERRIDE_HIGHCOL
+ if (which)
+ HighCol = DefHighCol;
+#endif
+}
+
extern unsigned short *PicoCramHigh; // pointer to CRAM buff (0x40 shorts), converted to native device color (works only with 16bit for now)\r
extern void (*PicoPrepareCram)(); // prepares PicoCramHigh for renderer to use\r
\r
+// mode4.c\r
+void PicoDrawSetColorFormatMode4(int which);\r
+\r
// sound.c\r
extern int PsndRate,PsndLen;\r
extern short *PsndOut;\r
struct Pico\r
{\r
unsigned char ram[0x10000]; // 0x00000 scratch ram\r
- union {\r
+ union { // vram is byteswapped for easier reads when drawing\r
unsigned short vram[0x8000]; // 0x10000\r
unsigned char vramb[0x4000]; // VRAM in SMS mode\r
};\r
// draw.c\r
PICO_INTERNAL void PicoFrameStart(void);\r
void PicoDrawSync(int to, int blank_last_line);\r
+void BackFill(int reg7, int sh);\r
extern int DrawScanline;\r
#define MAX_LINE_SPRITES 29\r
extern unsigned char HighLnSpr[240][3 + MAX_LINE_SPRITES];\r
// draw2.c\r
PICO_INTERNAL void PicoFrameFull();\r
\r
+// mode4.c\r
+void PicoFrameStartMode4(void);\r
+void PicoLineMode4(int line);\r
+void PicoDoHighPal555M4(void);\r
+\r
// memory.c\r
PICO_INTERNAL void PicoInitPc(unsigned int pc);\r
PICO_INTERNAL unsigned int PicoCheckPc(unsigned int pc);\r
if (pv->type == 3) {
Pico.cram[pv->addr & 0x1f] = d;
+ Pico.m.dirtyPal = 1;
} else {
Pico.vramb[pv->addr] = d;
}
pv->addr = (pv->addr + 1) & 0x3fff;
- elprintf(EL_ANOMALY, " addr=%04x", pv->addr);
pv->pending = 0;
}
if (pv->pending) {
if ((d >> 6) == 2) {
pv->reg[d & 0x0f] = pv->addr;
- elprintf(EL_ANOMALY, " VDP r%02x=%02x", d & 0x0f, pv->addr & 0xff);
+ elprintf(EL_IO, " VDP r%02x=%02x", d & 0x0f, pv->addr & 0xff);
}
pv->type = d >> 6;
pv->addr &= 0x00ff;
{
unsigned char d = 0;
- elprintf(EL_ANOMALY, "z80 port %04x read", a);
+ elprintf(EL_IO, "z80 port %04x read", a);
a &= 0xc1;
switch (a)
{
break;
}
- elprintf(EL_ANOMALY, "ret = %02x", d);
+ elprintf(EL_IO, "ret = %02x", d);
return d;
}
static void z80_sms_out(unsigned short a, unsigned char d)
{
- elprintf(EL_ANOMALY, "z80 port %04x write %02x", a, d);
+ elprintf(EL_IO, "z80 port %04x write %02x", a, d);
a &= 0xc1;
switch (a)
{
}
}
-static unsigned char MEMH_FUNC xread(unsigned short a)
-{
- elprintf(EL_ANOMALY, "z80 read [%04x]", a);
- return Pico.zram[a & 0x1fff];
-}
-
static void MEMH_FUNC xwrite(unsigned int a, unsigned char d)
{
- elprintf(EL_ANOMALY, "z80 write [%04x] %02x", a, d);
+ elprintf(EL_IO, "z80 write [%04x] %02x", a, d);
if (a >= 0xc000)
Pico.zram[a & 0x1fff] = d;
if (a >= 0xfff0)
{
z80_map_set(z80_read_map, 0x0000, 0xbfff, Pico.rom, 0);
z80_map_set(z80_read_map, 0xc000, 0xdfff, Pico.zram, 0);
- z80_map_set(z80_read_map, 0xe000, 0xffff, xread, 1);
+ z80_map_set(z80_read_map, 0xe000, 0xffff, Pico.zram, 0);
z80_map_set(z80_write_map, 0x0000, 0xbfff, xwrite, 1);
z80_map_set(z80_write_map, 0xc000, 0xdfff, Pico.zram, 0);
int lines_vis = 192;
int y;
+ PicoFrameStartMode4();
+
for (y = 0; y < lines; y++)
{
pv->v_counter = Pico.m.scanline = y;
- if (y == lines_vis + 1) {
+ if (y < lines_vis)
+ PicoLineMode4(y);
+ else if (y == lines_vis + 1) {
Pico.video.pending_ints |= 1;
if (Pico.video.reg[1] & 0x20) {
elprintf(EL_INTS, "vint");
}
PsndGetSamplesMS();
- elprintf(EL_ANOMALY, "frame end");
}
}\r
else if (currentConfig.EmuOpt & EOPT_16BPP) {\r
PicoDrawSetColorFormat(1);\r
+ PicoDrawSetColorFormatMode4(1);\r
if (currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX) {\r
gp2x_video_changemode(-16);\r
PicoScanBegin = EmuScanBegin16_rot;\r
# Pico
OBJS += pico/area.o pico/cart.o pico/memory.o pico/misc.o pico/pico.o pico/sek.o \
pico/videoport.o pico/draw2.o pico/draw.o pico/z80if.o pico/patch.o \
- pico/sms.o pico/debug.o
+ pico/mode4.o pico/sms.o pico/debug.o
# Pico - CD
OBJS += pico/cd/pico.o pico/cd/memory.o pico/cd/sek.o pico/cd/LC89510.o \
pico/cd/cd_sys.o pico/cd/cd_file.o pico/cd/cue.o pico/cd/gfx_cd.o \