int *HighCacheS_ptr;\r
\r
int rendstatus = 0;\r
-int Scanline = 0; // Scanline\r
+int DrawScanline = 0;\r
\r
static int SpriteBlocks;\r
static int skip_next_line=0;\r
{\r
int tilex,dx,code=0,addr=0,cell=0;\r
int oldcode=-1,blank=-1; // The tile we know is blank\r
- int pal=0,scan=Scanline;\r
+ int pal=0,scan=DrawScanline;\r
\r
// Draw tiles across screen:\r
tilex=(-ts->hscroll)>>3;\r
else ts.nametab=(pvid->reg[2]&0x38)<< 9; // A\r
\r
htab=pvid->reg[13]<<9; // Horizontal scroll table address\r
- if ( pvid->reg[11]&2) htab+=Scanline<<1; // Offset by line\r
+ if ( pvid->reg[11]&2) htab+=DrawScanline<<1; // Offset by line\r
if ((pvid->reg[11]&1)==0) htab&=~0xf; // Offset by tile\r
htab+=plane_sh&1; // A or B\r
\r
vscroll=Pico.vsram[plane_sh&1]; // Get vertical scroll value\r
\r
// Find the line in the name table\r
- ts.line=(vscroll+(Scanline<<1))&((ymask<<1)|1);\r
+ ts.line=(vscroll+(DrawScanline<<1))&((ymask<<1)|1);\r
ts.nametab+=(ts.line>>4)<<shift[width];\r
\r
DrawStripInterlace(&ts);\r
vscroll=Pico.vsram[plane_sh&1]; // Get vertical scroll value\r
\r
// Find the line in the name table\r
- ts.line=(vscroll+Scanline)&ymask;\r
+ ts.line=(vscroll+DrawScanline)&ymask;\r
ts.nametab+=(ts.line>>3)<<shift[width];\r
\r
DrawStrip(&ts, plane_sh, cellskip);\r
if (pvid->reg[12]&1)\r
{\r
nametab=(pvid->reg[3]&0x3c)<<9; // 40-cell mode\r
- nametab+=(Scanline>>3)<<6;\r
+ nametab+=(DrawScanline>>3)<<6;\r
}\r
else\r
{\r
nametab=(pvid->reg[3]&0x3e)<<9; // 32-cell mode\r
- nametab+=(Scanline>>3)<<5;\r
+ nametab+=(DrawScanline>>3)<<5;\r
}\r
\r
tilex=tstart<<1;\r
}\r
\r
tend<<=1;\r
- ty=(Scanline&7)<<1; // Y-Offset into tile\r
+ ty=(DrawScanline&7)<<1; // Y-Offset into tile\r
\r
// Draw tiles across screen:\r
if (!sh)\r
height=(sy>>24)&7; // Width and height in tiles\r
sy=(sy<<16)>>16; // Y\r
\r
- row=Scanline-sy; // Row of the sprite we are on\r
+ row=DrawScanline-sy; // Row of the sprite we are on\r
\r
if (code&0x1000) row=(height<<3)-1-row; // Flip Y\r
\r
width=(height>>2)&3; height&=3;\r
width++; height++; // Width and height in tiles\r
\r
- row=(Scanline<<1)-sy; // Row of the sprite we are on\r
+ row=(DrawScanline<<1)-sy; // Row of the sprite we are on\r
\r
code=sprite[1];\r
sx=((code>>16)&0x1ff)-0x78; // X\r
static void DrawAllSpritesInterlace(int *hcache, int maxwidth, int pri, int sh)\r
{\r
struct PicoVideo *pvid=&Pico.video;\r
- int i,u,table,link=0,sline=Scanline<<1;\r
+ int i,u,table,link=0,sline=DrawScanline<<1;\r
unsigned int *sprites[80]; // Sprite index\r
\r
table=pvid->reg[5]&0x7f;\r
int ntiles = 0; // tile counter for sprite limit emulation\r
int *sprites[40]; // Sprites to draw in fast mode\r
int max_line_sprites = 20; // 20 sprites, 40 tiles\r
- int *ps, pack, rs = rendstatus, scan = Scanline;\r
+ int *ps, pack, rs = rendstatus, scan = DrawScanline;\r
\r
if (rs & (PDRAW_SPRITES_MOVED|PDRAW_DIRTY_SPRITES)) {\r
//dprintf("PrepareSprites(%i) [%i]", (rs>>4)&1, scan);\r
int len, rs = rendstatus;\r
static int dirty_count;\r
\r
- if (!sh && !(rs & PDRAW_ACC_SPRITES) && Pico.m.dirtyPal == 1 && Scanline < 222)\r
+ if (!sh && !(rs & PDRAW_ACC_SPRITES) && Pico.m.dirtyPal == 1 && DrawScanline < 222)\r
{\r
// a hack for mid-frame palette changes\r
if (!(rs & PDRAW_SONIC_MODE))\r
\r
static void (*FinalizeLine)(int sh) = FinalizeLineBGR444;\r
\r
-// hblank was enabled early during prev line processng -\r
-// it should have been blanked\r
-static void handle_early_blank(int scanline, int sh)\r
+// --------------------------------------------\r
+\r
+static void DrawBlankedLine(void)\r
{\r
- scanline--;\r
+ int sh=(Pico.video.reg[0xC]&8)>>3; // shadow/hilight?\r
\r
if (PicoScanBegin != NULL)\r
- PicoScanBegin(scanline);\r
+ PicoScanBegin(DrawScanline);\r
\r
BackFill(Pico.video.reg[7], sh);\r
\r
FinalizeLine(sh);\r
\r
if (PicoScanEnd != NULL)\r
- PicoScanEnd(scanline);\r
+ PicoScanEnd(DrawScanline);\r
}\r
\r
-// --------------------------------------------\r
-\r
static int DrawDisplay(int sh, int as)\r
{\r
struct PicoVideo *pvid=&Pico.video;\r
win=pvid->reg[0x12];\r
edge=(win&0x1f)<<3;\r
\r
- if (win&0x80) { if (Scanline>=edge) hvwind=1; }\r
- else { if (Scanline< edge) hvwind=1; }\r
+ if (win&0x80) { if (DrawScanline>=edge) hvwind=1; }\r
+ else { if (DrawScanline< edge) hvwind=1; }\r
\r
if (!hvwind) { // we might have a vertical window here\r
win=pvid->reg[0x11];\r
int *c, a, b;\r
for (a = 0, c = HighCacheA; *c; c++, a++);\r
for (b = 0, c = HighCacheB; *c; c++, b++);\r
- printf("%i:%03i: a=%i, b=%i\n", Pico.m.frame_count, Scanline, a, b);\r
+ printf("%i:%03i: a=%i, b=%i\n", Pico.m.frame_count, DrawScanline, a, b);\r
}\r
#endif\r
\r
\r
PrepareSprites(1);\r
skip_next_line=0;\r
+ DrawScanline=0;\r
}\r
\r
-PICO_INTERNAL int PicoLine(int scan)\r
+static void PicoLine(void)\r
{\r
int sh, as = 0;\r
- if (skip_next_line>0) { skip_next_line--; return 0; } // skip_next_line rendering lines\r
+ if (skip_next_line>0) { skip_next_line--; return; } // skip rendering lines\r
\r
- Scanline=scan;\r
sh=(Pico.video.reg[0xC]&8)>>3; // shadow/hilight?\r
if (rendstatus & PDRAW_ACC_SPRITES) as|=1; // accurate sprites\r
\r
- if (rendstatus & PDRAW_EARLY_BLANK) {\r
- if (scan > 0) handle_early_blank(scan, sh);\r
- rendstatus &= ~PDRAW_EARLY_BLANK;\r
- }\r
-\r
if (PicoScanBegin != NULL)\r
- skip_next_line = PicoScanBegin(scan);\r
+ skip_next_line = PicoScanBegin(DrawScanline);\r
\r
// Draw screen:\r
BackFill(Pico.video.reg[7], sh|as);\r
FinalizeLine(sh);\r
\r
if (PicoScanEnd != NULL)\r
- PicoScanEnd(scan);\r
-\r
- return 0;\r
+ PicoScanEnd(DrawScanline);\r
}\r
\r
+void PicoDrawSync(int to, int blank_last_line)\r
+{\r
+ for (; DrawScanline < to; DrawScanline++)\r
+ {\r
+#if !CAN_HANDLE_240_LINES\r
+ if (DrawScanline >= 224) break;\r
+#endif\r
+ PicoLine();\r
+ }\r
+\r
+#if !CAN_HANDLE_240_LINES\r
+ if (DrawScanline >= 224) DrawScanline = 240, return;\r
+#endif\r
+\r
+ // last line\r
+ if (DrawScanline <= to)\r
+ {\r
+ if (blank_last_line)\r
+ DrawBlankedLine();\r
+ else PicoLine();\r
+ DrawScanline++;\r
+ }\r
+}\r
\r
void PicoDrawSetColorFormat(int which)\r
{\r
.extern Pico\r
.extern PicoOpt\r
.extern HighCol\r
-.extern Scanline\r
+.extern DrawScanline\r
.extern HighSprZ\r
.extern rendstatus\r
.extern DrawLineDest\r
ldreqb r12, [r11, #2]\r
ldrneb r12, [r11, #4]\r
\r
- ldr r2, =Scanline @ trying to make good use of pipeline here\r
+ ldr r2, =DrawScanline @ trying to make good use of pipeline here\r
ldr lr, =(Pico+0x10000) @ lr=Pico.vram\r
\r
moveq r12, r12, lsl #10\r
mov r4, r8, lsr #8 @ pvid->reg[13]\r
mov r4, r4, lsl #10 @ htab=pvid->reg[13]<<9; (halfwords)\r
tst r7, #2\r
- addne r4, r4, r2, lsl #2 @ htab+=Scanline<<1; // Offset by line\r
+ addne r4, r4, r2, lsl #2 @ htab+=DrawScanline<<1; // Offset by line\r
tst r7, #1\r
biceq r4, r4, #0x1f @ htab&=~0xf; // Offset by tile\r
add r4, r4, r0, lsl #1 @ htab+=plane\r
bic r8, r8, #0x3fc00000\r
orr r8, r8, r5, lsl #25 @ r8=(xmask[31:25]|had_output[24]|tilex[21:0])\r
\r
- ldr r4, =Scanline\r
+ ldr r4, =DrawScanline\r
orr r5, r1, r10, lsl #24\r
ldr r4, [r4]\r
sub r1, r3, #1\r
movne r7, r7, lsl #5\r
\r
@ Find the line in the name table\r
- add r2, r7, r2, lsl #22 @ r2=(vscroll+(Scanline<<1))<<21 (11 bits);\r
+ add r2, r7, r2, lsl #22 @ r2=(vscroll+(DrawScanline<<1))<<21 (11 bits);\r
orr r1, r1, #0x80000000\r
and r2, r2, r1, ror #10 @ &((ymask<<1)|1)<<21;\r
mov r2, r2, lsr #21\r
\r
orr r8, r2, r1, lsl #4\r
ldr r3, [r0] @ sprite[0]\r
- ldr r7, =Scanline\r
+ ldr r7, =DrawScanline\r
mov r6, r3, lsr #28\r
sub r6, r6, #1 @ r6=width-1 (inc later)\r
mov r5, r3, lsr #24\r
\r
ldr r7, [r7]\r
ldr r9, [r0, #4]\r
- sub r7, r7, r4, asr #16 @ r7=row=Scanline-sy\r
+ sub r7, r7, r4, asr #16 @ r7=row=DrawScanline-sy\r
\r
mov r2, r9, asr #16 @ r2=sx\r
mov r9, r9, lsl #16\r
stmfd sp!, {r4-r11,lr}\r
\r
ldr r11, =(Pico+0x22228) @ Pico.video\r
- ldr r10, =Scanline\r
+ ldr r10, =DrawScanline\r
ldrb r12, [r11, #3] @ pvid->reg[3]\r
\r
ldr r10, [r10]\r
if (!(PicoOpt&POPT_ALT_RENDERER))\r
{\r
// Draw the screen\r
+#if 0\r
#if CAN_HANDLE_240_LINES\r
if (pv->reg[1]&8) {\r
for (y=0;y<240;y++) PicoLine(y);\r
}\r
#else\r
for (y=0;y<224;y++) PicoLine(y);\r
+#endif\r
#endif\r
}\r
else PicoFrameFull();\r
#define PDRAW_SONIC_MODE (1<<5) // mid-frame palette changes for 8bit renderer\r
#define PDRAW_PLANE_HI_PRIO (1<<6) // have layer with all hi prio tiles (mk3)\r
#define PDRAW_SHHI_DONE (1<<7) // layer sh/hi already processed\r
-#define PDRAW_EARLY_BLANK (1<<8) // blanking enabled at the start of prev line\r
extern int rendstatus;\r
extern unsigned short HighPal[0x100];\r
\r
// This is to make active scan longer (needed for Double Dragon 2, mainly)
CPUS_RUN(CYCLES_M68K_ASD, CYCLES_S68K_ASD);
- for (y=0;y<lines_vis;y++)
+ for (y = 0; y < lines_vis; y++)
{
Pico.m.scanline=(short)y;
}
// decide if we draw this line
- if (!skip)
+ if (!skip && (PicoOpt & POPT_ALT_RENDERER))
{
- if (PicoOpt&POPT_ALT_RENDERER) {
- // find the right moment for fast renderer, when display is no longer blanked
- if ((pv->reg[1]&0x40) || y > 100) {
- PicoFrameFull();
+ // find the right moment for frame renderer, when display is no longer blanked
+ if ((pv->reg[1]&0x40) || y > 100) {
+ PicoFrameFull();
#ifdef DRAW_FINISH_FUNC
- DRAW_FINISH_FUNC();
+ DRAW_FINISH_FUNC();
#endif
- skip = 1;
- }
- }
- else
- {
-#if !CAN_HANDLE_240_LINES
- if (y < 224)
-#endif
- PicoLine(y);
+ skip = 1;
}
}
#endif
}
-#ifdef DRAW_FINISH_FUNC
if (!skip)
+ {
+ if (DrawScanline < y)
+ PicoDrawSync(y - 1, 0);
+#ifdef DRAW_FINISH_FUNC
DRAW_FINISH_FUNC();
#endif
+ }
// V-int line (224 or 240)
Pico.m.scanline=(short)y;
// PAL line count might actually be 313 according to Steve Snake, but that would complicate things.
lines = Pico.m.pal ? 312 : 262;
- for (y++;y<lines;y++)
+ for (y++; y < lines; y++)
{
Pico.m.scanline=(short)y;
int CM_compareRun(int cyc, int is_sub);\r
\r
// Draw.c\r
-PICO_INTERNAL int PicoLine(int scan);\r
PICO_INTERNAL void PicoFrameStart(void);\r
+void PicoDrawSync(int to, int blank_last_line);\r
+extern int DrawScanline;\r
\r
// Draw2.c\r
PICO_INTERNAL void PicoFrameFull();\r
if (cmd&0x80) CommandDma();\r
}\r
\r
+static __inline void DrawSync(int blank_on)\r
+{\r
+ if (Pico.m.scanline < 224 && !(PicoOpt & POPT_ALT_RENDERER) &&\r
+ !PicoSkipFrame && DrawScanline <= Pico.m.scanline) {\r
+ elprintf(EL_ANOMALY, "sync");\r
+ PicoDrawSync(Pico.m.scanline, blank_on);\r
+ }\r
+}\r
+\r
PICO_INTERNAL_ASM void PicoVideoWrite(unsigned int a,unsigned short d)\r
{\r
struct PicoVideo *pvid=&Pico.video;\r
\r
+ if (Pico.m.scanline < 224)\r
+ elprintf(EL_STATUS, "PicoVideoWrite [%06x] %04x", a, d);\r
a&=0x1c;\r
\r
if (a==0x00) // Data port 0 or 2\r
{\r
+ // try avoiding the sync..\r
+ if (Pico.m.scanline < 224 && (pvid->reg[1]&0x40) &&\r
+ !(!pvid->pending &&\r
+ ((pvid->command & 0xc00000f0) == 0x40000010 && Pico.vsram[pvid->addr>>1] == d))\r
+ )\r
+ DrawSync(0);\r
+\r
if (pvid->pending) {\r
CommandChange();\r
pvid->pending=0;\r
else\r
{\r
// preliminary FIFO emulation for Chaos Engine, The (E)\r
- if(!(pvid->status&8) && (pvid->reg[1]&0x40) && Pico.m.scanline!=-1 && !(PicoOpt&POPT_DIS_VDP_FIFO)) // active display, accurate mode?\r
+ if (!(pvid->status&8) && (pvid->reg[1]&0x40) && Pico.m.scanline!=-1 && !(PicoOpt&POPT_DIS_VDP_FIFO)) // active display, accurate mode?\r
{\r
pvid->status&=~0x200; // FIFO no longer empty\r
pvid->lwrite_cnt++;\r
\r
if (a==0x04) // Control (command) port 4 or 6\r
{\r
- if(pvid->pending)\r
+ if (pvid->pending)\r
{\r
+ if (d & 0x80) DrawSync(0); // only need sync for DMA\r
// Low word of command:\r
pvid->command&=0xffff0000;\r
pvid->command|=d;\r
// Register write:\r
int num=(d>>8)&0x1f;\r
int dold=pvid->reg[num];\r
+ int update_irq = 0, blank_on = 0;\r
pvid->type=0; // register writes clear command (else no Sega logo in Golden Axe II)\r
if (num > 0x0a && !(pvid->reg[1]&4)) {\r
elprintf(EL_ANOMALY, "%02x written to reg %02x in SMS mode @ %06x", d, num, SekPc);\r
return;\r
- } else\r
- pvid->reg[num]=(unsigned char)d;\r
+ }\r
\r
switch (num)\r
{\r
case 0x00:\r
elprintf(EL_INTSW, "hint_onoff: %i->%i [%i] pend=%i @ %06x", (dold&0x10)>>4,\r
(d&0x10)>>4, SekCyclesDone(), (pvid->pending_ints&0x10)>>4, SekPc);\r
- goto update_irq;\r
+ update_irq = 1;\r
+ break;\r
case 0x01:\r
elprintf(EL_INTSW, "vint_onoff: %i->%i [%i] pend=%i @ %06x", (dold&0x20)>>5,\r
(d&0x20)>>5, SekCyclesDone(), (pvid->pending_ints&0x20)>>5, SekPc);\r
- if (!(d&0x40) && SekCyclesLeft > 390) rendstatus |= PDRAW_EARLY_BLANK;\r
- goto update_irq;\r
+ if (!(d&0x40) && SekCyclesLeft > 390) blank_on = 1;\r
+ update_irq = 1;\r
+ break;\r
case 0x05:\r
if (d^dold) rendstatus |= PDRAW_SPRITES_MOVED;\r
break;\r
if ((d^dold)&8) Pico.m.dirtyPal = 2;\r
break;\r
}\r
- return;\r
+ DrawSync(blank_on);\r
+ pvid->reg[num]=(unsigned char)d;\r
+ if (!update_irq) return;\r
\r
-update_irq:;\r
#ifndef EMU_CORE_DEBUG\r
- // update IRQ level (Lemmings, Wiz 'n' Liz intro, ... )\r
- // may break if done improperly:\r
- // International Superstar Soccer Deluxe (crash), Street Racer (logos), Burning Force (gfx),\r
- // Fatal Rewind (crash), Sesame Street Counting Cafe\r
+ // update IRQ level\r
if (!SekShouldInterrupt) // hack\r
{\r
int lines, pints, irq=0;\r
lines = (pvid->reg[1] & 0x20) | (pvid->reg[0] & 0x10);\r
pints = (pvid->pending_ints&lines);\r
- if(pints & 0x20) irq = 6;\r
- else if(pints & 0x10) irq = 4;\r
+ if (pints & 0x20) irq = 6;\r
+ else if (pints & 0x10) irq = 4;\r
SekInterrupt(irq); // update line\r
\r
if (irq && Pico.m.scanline!=-1) SekEndRun(24); // make it delayed\r
\r
PICO_INTERNAL_ASM unsigned int PicoVideoRead(unsigned int a)\r
{\r
- unsigned int d=0;\r
-\r
a&=0x1c;\r
\r
-\r
if (a==0x00) // data port\r
{\r
- d=VideoRead();\r
- goto end;\r
+ return VideoRead();\r
}\r
\r
if (a==0x04) // control port\r
{\r
struct PicoVideo *pv=&Pico.video;\r
+ unsigned int d;\r
d=pv->status;\r
if (PicoOpt&POPT_ALT_RENDERER) d|=0x0020; // sprite collision (Shadow of the Beast)\r
if (!(pv->reg[1]&0x40)) d|=0x0008; // set V-Blank if display is disabled\r
pv->pending=0; // ctrl port reads clear write-pending flag (Charles MacDonald)\r
\r
elprintf(EL_SR, "SR read: %04x @ %06x", d, SekPc);\r
- goto end;\r
+ return d;\r
}\r
\r
// H-counter info (based on Generator):\r
// check: Sonic 3D Blast bonus, Cannon Fodder, Chase HQ II, 3 Ninjas kick back, Road Rash 3, Skitchin', Wheel of Fortune\r
if ((a&0x1c)==0x08)\r
{\r
- unsigned int hc;\r
+ unsigned int hc, d;\r
\r
- if(Pico.m.scanline != -1) {\r
+ if (Pico.m.scanline != -1)\r
+ {\r
int lineCycles=(488-SekCyclesLeft)&0x1ff;\r
d=Pico.m.scanline; // V-Counter\r
\r
}\r
\r
if(Pico.m.pal) {\r
- if(d >= 0x103) d-=56; // based on Gens\r
+ if (d >= 0x103) d-=56; // based on Gens\r
} else {\r
- if(d >= 0xEB) d-=6;\r
+ if (d >= 0xEB) d-=6;\r
}\r
\r
if((Pico.video.reg[12]&6) == 6) {\r
elprintf(EL_HVCNT, "hv: %02x %02x (%i) @ %06x", hc, d, SekCyclesDone(), SekPc);\r
d&=0xff; d<<=8;\r
d|=hc;\r
- goto end;\r
+ return d;\r
}\r
\r
-end:\r
-\r
- return d;\r
+ return 0;\r
}\r
ret = OPNWriteReg(addr, v);\r
break;\r
}\r
-/*\r
- if(ret) {\r
- extern int Scanline;\r
- dprintf("ymw [%i]", Scanline);\r
- }\r
-*/\r
+\r
return ret;\r
}\r
\r