But should be closer to the real thing.
Let's see what this will break...
{
// ~1.63 for NTSC, ~1.645 for PAL
if (Pico.m.pal)
- mcd_m68k_cycle_mult = ((12500000ull << 16) / (50*312*488));
+ mcd_m68k_cycle_mult = ((12500000ull << 16) / (50*313*488));
else
mcd_m68k_cycle_mult = ((12500000ull << 16) / (60*262*488)) + 1;
}
return;
if (Pico.m.pal) {
- lines = 312;
+ lines = 313;
line_sample = 68;
} else {
lines = 262;
\r
pprof_start(draw);\r
\r
- if (rendlines != 240)\r
+ if (rendlines != 240) {\r
offs = 8;\r
+ if (to > 223)\r
+ to = 223;\r
+ }\r
\r
for (line = Pico.est.DrawScanline; line < to; line++)\r
- {\r
PicoLine(line, offs, sh, bgc);\r
- }\r
\r
// last line\r
if (line <= to)\r
}\r
\r
if ((a & 0x4000) == 0x0000) { // z80 RAM\r
- SekCyclesBurnRun(2); // FIXME hack\r
Pico.zram[a & 0x1fff] = (u8)d;\r
return;\r
}\r
\r
struct PicoSRAM SRam;\r
int emustatus; // rapid_ym2612, multi_ym_updates\r
-int scanlines_total;\r
\r
void (*PicoWriteSound)(int len) = NULL; // called at the best time to send sound buffer (PsndOut) to hardware\r
void (*PicoResetHook)(void) = NULL;\r
// force setting possibly changed..\r
Pico.m.pal = (PicoRegionOverride == 2 || PicoRegionOverride == 8) ? 1 : 0;\r
\r
- // FIXME: PAL has 313 scanlines..\r
- scanlines_total = Pico.m.pal ? 312 : 262;\r
-\r
Pico.m.dirtyPal = 1;\r
rendstatus_old = -1;\r
}\r
\r
-\r
-// dma2vram settings are just hacks to unglitch Legend of Galahad (needs <= 104 to work)\r
-// same for Outrunners (92-121, when active is set to 24)\r
-// 96 is VR hack\r
+// this table is wrong and should be removed\r
+// keeping it for now to compensate wrong timing elswhere, mainly for Outrunners\r
static const int dma_timings[] = {\r
- 167, 167, 166, 83, // vblank: 32cell: dma2vram dma2[vs|c]ram vram_fill vram_copy\r
- 102, 205, 204, 102, // vblank: 40cell:\r
- 16, 16, 15, 8, // active: 32cell:\r
- 24, 18, 17, 9 // ...\r
+ 83, 166, 83, 83, // vblank: 32cell: dma2vram dma2[vs|c]ram vram_fill vram_copy\r
+ 102, 204, 102, 102, // vblank: 40cell:\r
+ 8, 16, 8, 8, // active: 32cell:\r
+ 17, 18, 9, 9 // ...\r
};\r
\r
static const int dma_bsycles[] = {\r
- (488<<8)/167, (488<<8)/167, (488<<8)/166, (488<<8)/83,\r
- (488<<8)/102, (488<<8)/233, (488<<8)/204, (488<<8)/102,\r
- (488<<8)/16, (488<<8)/16, (488<<8)/15, (488<<8)/8,\r
- (488<<8)/24, (488<<8)/18, (488<<8)/17, (488<<8)/9\r
+ (488<<8)/83, (488<<8)/166, (488<<8)/83, (488<<8)/83,\r
+ (488<<8)/102, (488<<8)/204, (488<<8)/102, (488<<8)/102,\r
+ (488<<8)/8, (488<<8)/16, (488<<8)/8, (488<<8)/8,\r
+ (488<<8)/9, (488<<8)/18, (488<<8)/9, (488<<8)/9\r
};\r
\r
// grossly inaccurate.. FIXME FIXXXMEE\r
pprof_start(z80);\r
\r
elprintf(EL_BUSREQ, "z80 sync %i (%u|%u -> %u|%u)", cnt,\r
- z80_cycle_cnt, z80_cycle_cnt / 288,\r
- z80_cycle_aim, z80_cycle_aim / 288);\r
+ z80_cycle_cnt, z80_cycle_cnt / 228,\r
+ z80_cycle_aim, z80_cycle_aim / 228);\r
\r
if (cnt > 0)\r
z80_cycle_cnt += z80_run(cnt);\r
{
int rate = guessed_rates[PicoPicohw.r12 & 7];
if (Pico.m.pal)
- fifo_bytes_line = (rate<<16)/50/312/2;
+ fifo_bytes_line = (rate<<16)/50/313/2;
else fifo_bytes_line = (rate<<16)/60/262/2;
PicoPicoPCMRerate(rate);
}
#define CYCLES_M68K_LINE 488 // suitable for both PAL/NTSC
#define CYCLES_M68K_VINT_LAG 68
-#define CYCLES_M68K_ASD 148
// pad delay (for 6 button pads)
#define PAD_DELAY() { \
static inline void SekRunM68k(int cyc)
{
SekCycleAim += cyc;
+ cyc = SekCycleAim - SekCycleCnt;
+ if (cyc <= 0)
+ return;
+ SekCycleCnt += cyc >> 6; // refresh slowdowns
SekSyncM68k();
}
+static void do_hint(struct PicoVideo *pv)
+{
+ pv->pending_ints |= 0x10;
+ if (pv->reg[0] & 0x10) {
+ elprintf(EL_INTS, "hint: @ %06x [%u]", SekPc, SekCyclesDone());
+ SekInterrupt(4);
+ }
+}
+
static int PicoFrameHints(void)
{
- struct PicoVideo *pv=&Pico.video;
- int lines, y, lines_vis = 224, line_sample, skip, vcnt_wrap;
+ struct PicoVideo *pv = &Pico.video;
+ int line_sample = Pico.m.pal ? 68 : 93;
+ int lines, y, lines_vis, skip;
+ int vcnt_wrap, vcnt_adj;
unsigned int cycles;
int hint; // Hint counter
}
else skip=PicoSkipFrame;
- if (Pico.m.pal) {
- line_sample = 68;
- if (pv->reg[1]&8) lines_vis = 240;
- } else {
- line_sample = 93;
- }
-
z80_resetCycles();
PsndStartFrame();
- pv->status&=~0x88; // clear V-Int, come out of vblank
+ // Load H-Int counter
+ hint = (pv->status & PVS_ACTIVE) ? pv->hint_cnt : pv->reg[10];
- hint=pv->reg[10]; // Load H-Int counter
- //dprintf("-hint: %i", hint);
+ pv->status |= PVS_ACTIVE;
- // This is to make active scan longer (needed for Double Dragon 2, mainly)
- CPUS_RUN(CYCLES_M68K_ASD);
-
- for (y = 0; y < lines_vis; y++)
+ for (y = 0; ; y++)
{
pv->v_counter = Pico.m.scanline = y;
if ((pv->reg[12]&6) == 6) { // interlace mode 2
pv->v_counter &= 0xff;
}
+ if ((y == 224 && !(pv->reg[1] & 8)) || y == 240)
+ break;
+
// VDP FIFO
pv->lwrite_cnt -= 12;
if (pv->lwrite_cnt <= 0) {
- pv->lwrite_cnt=0;
- Pico.video.status|=0x200;
+ pv->lwrite_cnt = 0;
+ Pico.video.status |= SR_EMPT;
}
PAD_DELAY();
// H-Interrupts:
- if (--hint < 0) // y <= lines_vis: Comix Zone, Golden Axe
+ if (--hint < 0)
{
- hint=pv->reg[10]; // Reload H-Int counter
- pv->pending_ints|=0x10;
- if (pv->reg[0]&0x10) {
- elprintf(EL_INTS, "hint: @ %06x [%i]", SekPc, SekCyclesDone());
- SekInterrupt(4);
- }
+ hint = pv->reg[10]; // Reload H-Int counter
+ do_hint(pv);
}
// decide if we draw this line
pevt_log_m68k_o(EVT_NEXT_LINE);
}
+ lines_vis = (pv->reg[1] & 8) ? 240 : 224;
+ if (y == lines_vis)
+ pv->status &= ~PVS_ACTIVE;
+
if (!skip)
{
if (Pico.est.DrawScanline < y)
#endif
}
- // V-int line (224 or 240)
- Pico.m.scanline = y;
- pv->v_counter = 0xe0; // bad for 240 mode
- if ((pv->reg[12]&6) == 6) pv->v_counter = 0xc1;
-
// VDP FIFO
- pv->lwrite_cnt=0;
- Pico.video.status|=0x200;
+ pv->lwrite_cnt = 0;
+ Pico.video.status |= SR_EMPT;
memcpy(PicoPadInt, PicoPad, sizeof(PicoPadInt));
PAD_DELAY();
- // Last H-Int:
+ // Last H-Int (normally):
if (--hint < 0)
{
- hint=pv->reg[10]; // Reload H-Int counter
- pv->pending_ints|=0x10;
- //printf("rhint: %i @ %06x [%i|%i]\n", hint, SekPc, y, SekCyclesDone());
- if (pv->reg[0]&0x10) SekInterrupt(4);
+ hint = pv->reg[10]; // Reload H-Int counter
+ do_hint(pv);
}
- pv->status|=0x08; // go into vblank
- pv->pending_ints|=0x20;
+ pv->status |= SR_VB; // go into vblank
+ pv->pending_ints |= 0x20;
// the following SekRun is there for several reasons:
// there must be a delay after vblank bit is set and irq is asserted (Mazin Saga)
if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
CPUS_RUN(CYCLES_M68K_VINT_LAG);
- if (pv->reg[1]&0x20) {
- elprintf(EL_INTS, "vint: @ %06x [%i]", SekPc, SekCyclesDone());
+ if (pv->reg[1] & 0x20) {
+ elprintf(EL_INTS, "vint: @ %06x [%u]", SekPc, SekCyclesDone());
SekInterrupt(6);
}
PsndGetSamples(y);
// Run scanline:
- CPUS_RUN(CYCLES_M68K_LINE - CYCLES_M68K_VINT_LAG - CYCLES_M68K_ASD);
+ CPUS_RUN(CYCLES_M68K_LINE - CYCLES_M68K_VINT_LAG);
if (PicoLineHook) PicoLineHook();
pevt_log_m68k_o(EVT_NEXT_LINE);
- lines = scanlines_total;
- vcnt_wrap = Pico.m.pal ? 0x103 : 0xEB; // based on Gens, TODO: verify
+ if (Pico.m.pal) {
+ lines = 313;
+ vcnt_wrap = 0x103;
+ vcnt_adj = 57;
+ }
+ else {
+ lines = 262;
+ vcnt_wrap = 0xEB;
+ vcnt_adj = 6;
+ }
- for (y++; y < lines; y++)
+ for (y++; y < lines - 1; y++)
{
pv->v_counter = Pico.m.scanline = y;
if (y >= vcnt_wrap)
- pv->v_counter -= Pico.m.pal ? 56 : 6;
+ pv->v_counter -= vcnt_adj;
if ((pv->reg[12]&6) == 6)
pv->v_counter = (pv->v_counter << 1) | 1;
pv->v_counter &= 0xff;
PAD_DELAY();
+ if ((pv->status & PVS_ACTIVE) && --hint < 0)
+ {
+ hint = pv->reg[10]; // Reload H-Int counter
+ do_hint(pv);
+ }
+
// Run scanline:
line_base_cycles = SekCyclesDone();
if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
pevt_log_m68k_o(EVT_NEXT_LINE);
}
+ pv->status &= ~SR_VB;
+
+ // last scanline
+ Pico.m.scanline = y;
+ pv->v_counter = 0xff;
+
+ PAD_DELAY();
+
+ if ((pv->status & PVS_ACTIVE) && --hint < 0)
+ {
+ hint = pv->reg[10]; // Reload H-Int counter
+ do_hint(pv);
+ }
+
+ // Run scanline:
+ line_base_cycles = SekCyclesDone();
+ if (Pico.m.dma_xfers) SekCyclesBurn(CheckDMA());
+ CPUS_RUN(CYCLES_M68K_LINE);
+
+ if (PicoLineHook) PicoLineHook();
+ pevt_log_m68k_o(EVT_NEXT_LINE);
+
// sync cpus
cycles = SekCyclesDone();
if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80))
#endif
timers_cycle();
+ pv->hint_cnt = hint;
+
return 0;
}
#define OSC_NTSC 53693100\r
#define OSC_PAL 53203424\r
\r
+// PicoVideo.debug_p\r
#define PVD_KILL_A (1 << 0)\r
#define PVD_KILL_B (1 << 1)\r
#define PVD_KILL_S_LO (1 << 2)\r
#define PVD_FORCE_B (1 << 6)\r
#define PVD_FORCE_S (1 << 7)\r
\r
+// PicoVideo.status, not part of real SR\r
+#define SR_PAL (1 << 0)\r
+#define SR_DMA (1 << 1)\r
+#define SR_HB (1 << 2)\r
+#define SR_VB (1 << 3)\r
+#define SR_ODD (1 << 4)\r
+#define SR_C (1 << 5)\r
+#define SR_SOVR (1 << 6)\r
+#define SR_F (1 << 7)\r
+#define SR_FULL (1 << 8)\r
+#define SR_EMPT (1 << 9)\r
+// not part of real SR\r
+#define PVS_ACTIVE (1 << 16)\r
+\r
struct PicoVideo\r
{\r
unsigned char reg[0x20];\r
unsigned char pending; // 1 if waiting for second half of 32-bit command\r
unsigned char type; // Command type (v/c/vsram read/write)\r
unsigned short addr; // Read/Write address\r
- int status; // Status bits\r
+ unsigned int status; // Status bits (SR) and extra flags\r
unsigned char pending_ints; // pending interrupts: ??VH????\r
signed char lwrite_cnt; // VDP write count during active display line\r
unsigned short v_counter; // V-counter\r
unsigned short debug; // raw debug register\r
unsigned char debug_p; // ... parsed: PVD_*\r
- unsigned char addr_u;\r
- unsigned char pad[0x0c];\r
+ unsigned char addr_u; // bit16 of .addr\r
+ unsigned char hint_cnt;\r
+ unsigned char pad[0x0b];\r
};\r
\r
struct PicoMisc\r
extern struct PicoSRAM SRam;\r
extern int PicoPadInt[2];\r
extern int emustatus;\r
-extern int scanlines_total;\r
extern void (*PicoResetHook)(void);\r
extern void (*PicoLineHook)(void);\r
PICO_INTERNAL int CheckDMA(void);\r
\r
static void dac_recalculate(void)\r
{\r
- int i, dac_cnt, pos, len, lines = Pico.m.pal ? 312 : 262, mid = Pico.m.pal ? 68 : 93;\r
+ int i, dac_cnt, pos, len, lines = Pico.m.pal ? 313 : 262, mid = Pico.m.pal ? 68 : 93;\r
\r
if (PsndLen <= lines)\r
{\r
int dout = ym2612.dacout;\r
int line_from = PsndDacLine;\r
\r
- if (line_to >= 312)\r
- line_to = 311;\r
+ if (line_to >= 313)\r
+ line_to = 312;\r
\r
pos = dac_info[line_from];\r
pos1 = dac_info[line_to + 1];\r
int pos, pos1, len;\r
int stereo = 0;\r
\r
- if (line_to >= 312)\r
- line_to = 311;\r
+ if (line_to >= 313)\r
+ line_to = 312;\r
\r
pos = dac_info[line_from];\r
pos1 = dac_info[line_to + 1];\r
}\r
\r
Pico.m.dirtyPal = 1;\r
+ Pico.video.status &= ~(SR_VB | SR_F);\r
}\r
\r
return ret;\r