--- uae/src/custom.c 2018/04/24 16:44:56 1.1.1.6 +++ uae/src/custom.c 2018/04/24 16:48:49 1.1.1.8 @@ -74,8 +74,6 @@ static uae_u32 sprtaba[256],sprtabb[256] static void custom_wput_1 (int, uaecptr, uae_u32) REGPARAM; -static int fmode; - static uae_u16 cregs[256]; uae_u16 intena,intreq; @@ -83,6 +81,18 @@ uae_u16 dmacon; uae_u16 adkcon; /* used by audio code */ static uae_u32 cop1lc,cop2lc,copcon; + +int maxhpos = MAXHPOS_PAL; +int maxvpos = MAXVPOS_PAL; +int minfirstline = MINFIRSTLINE_PAL; +int vblank_endline = VBLANK_ENDLINE_PAL; +int vblank_hz = VBLANK_HZ_PAL; +unsigned long syncbase; +static int fmode; +static unsigned int beamcon0, new_beamcon0; +static int ntscmode = 0; + +#define MAX_SPRITES 32 /* This is but an educated guess. It seems to be correct, but this stuff * isn't documented well. */ @@ -92,6 +102,10 @@ static int spron[8]; static uaecptr sprpt[8]; static int sprxpos[8], sprvstart[8], sprvstop[8]; +static unsigned int sprdata[MAX_SPRITES], sprdatb[MAX_SPRITES], sprctl[MAX_SPRITES], sprpos[MAX_SPRITES]; +static int sprarmed[MAX_SPRITES], sprite_last_drawn_at[MAX_SPRITES]; +static int last_sprite_point, nr_armed; + static uae_u32 bpl1dat, bpl2dat, bpl3dat, bpl4dat, bpl5dat, bpl6dat, bpl7dat, bpl8dat; static uae_s16 bpl1mod, bpl2mod; @@ -108,12 +122,10 @@ static int nr_planes_from_bplcon0, corre static unsigned int diwstrt, diwstop, diwhigh; static int diwhigh_written; static unsigned int ddfstrt, ddfstop; -static unsigned int sprdata[8], sprdatb[8], sprctl[8], sprpos[8]; -static int sprarmed[8], sprite_last_drawn_at[8]; -static int last_sprite_point, nr_armed; + static uae_u32 dskpt; static uae_u16 dsklen, dsksync; -static int dsklength; +static int dsklength, syncfound; /* The display and data fetch windows */ @@ -153,7 +165,7 @@ static struct copper cop_state; static void prepare_copper_1 (void); -int dskdmaen; /* used in cia.c */ +static int dskdmaen; /* * Statistics @@ -190,9 +202,9 @@ struct color_change color_changes[2][MAX struct delay_change delay_changes[MAX_REG_CHANGE]; #endif -struct decision line_decisions[2 * (maxvpos+1) + 1]; -struct draw_info line_drawinfo[2][2 * (maxvpos+1) + 1]; -struct color_entry color_tables[2][(maxvpos+1) * 2]; +struct decision line_decisions[2 * (MAXVPOS + 1) + 1]; +struct draw_info line_drawinfo[2][2 * (MAXVPOS + 1) + 1]; +struct color_entry color_tables[2][(MAXVPOS + 1) * 2]; struct sprite_draw *curr_sprite_positions, *prev_sprite_positions; struct color_change *curr_color_changes, *prev_color_changes; @@ -205,7 +217,7 @@ static int color_src_match, color_dest_m /* These few are only needed during/at the end of the scanline, and don't * have to be remembered. */ -static int decided_bpl1mod, decided_bpl2mod, decided_nr_planes, decided_hires; +static int decided_bpl1mod, decided_bpl2mod, decided_nr_planes, decided_res; static char thisline_changed; @@ -241,7 +253,7 @@ void reset_frame_rate_hack (void) write_log ("Resetting frame rate hack\n"); } -static __inline__ void prepare_copper (void) +STATIC_INLINE void prepare_copper (void) { if (cop_state.vpos > vpos || cop_state.state == COP_stop) @@ -254,7 +266,7 @@ static __inline__ void prepare_copper (v void check_prefs_changed_custom (void) { - currprefs.framerate = changed_prefs.framerate; + currprefs.gfx_framerate = changed_prefs.gfx_framerate; /* Not really the right place... */ if (currprefs.jport0 != changed_prefs.jport0 || currprefs.jport1 != changed_prefs.jport1) { @@ -267,7 +279,7 @@ void check_prefs_changed_custom (void) } -static __inline__ void setclr (uae_u16 *p, uae_u16 val) +STATIC_INLINE void setclr (uae_u16 *p, uae_u16 val) { if (val & 0x8000) *p |= val & 0x7FFF; @@ -280,7 +292,7 @@ __inline__ int current_hpos (void) return cycles - eventtab[ev_hsync].oldcycles; } -static __inline__ uae_u8 *pfield_xlateptr (uaecptr plpt, int bytecount) +STATIC_INLINE uae_u8 *pfield_xlateptr (uaecptr plpt, int bytecount) { if (!chipmem_bank.check (plpt, bytecount)) { static int count = 0; @@ -291,7 +303,7 @@ static __inline__ uae_u8 *pfield_xlatept return chipmem_bank.xlateaddr (plpt); } -static __inline__ void docols (struct color_entry *colentry) +STATIC_INLINE void docols (struct color_entry *colentry) { #if AGA_CHIPSET == 0 int i; @@ -310,7 +322,7 @@ void notice_new_xcolors (void) docols(¤t_colors); /* docols(&colors_for_drawing);*/ - for (i = 0; i < (maxvpos+1)*2; i++) { + for (i = 0; i < (MAXVPOS + 1)*2; i++) { docols(color_tables[0]+i); docols(color_tables[1]+i); } @@ -388,7 +400,7 @@ static void decide_diw (int hpos) /* Called when we know that the line is not in the border and we want to draw * it. The data fetch starting position and length are passed as parameters. */ -static __inline__ void decide_as_playfield (int startpos, int len) +STATIC_INLINE void decide_as_playfield (int startpos, int len) { thisline_decision.which = 1; @@ -452,9 +464,12 @@ static void adjust_broken_program (int h { int tmp1, tmp2; int i; - if (decided_hires) { + if (decided_res == RES_HIRES) { tmp1 = hpos & 3; tmp2 = hpos & ~3; + } else if (decided_res == RES_SUPERHIRES) { + tmp1 = hpos & 1; + tmp2 = hpos & ~1; } else { tmp1 = hpos & 7; tmp2 = hpos & ~7; @@ -462,7 +477,9 @@ static void adjust_broken_program (int h for (i = 0; i < decided_nr_planes; i++) { if (broken_plane_sub[i] != -1) continue; - if (decided_hires) { + /* FIXME: superhires, AGA playfields */ + /* Actually, I don't want to support this crap for AGA if we can avoid it. */ + if (decided_res == RES_HIRES) { broken_plane_sub[i] = (tmp2 - thisline_decision.plfstrt) / 4 * 2; switch (i) { case 3: broken_plane_sub[i] += 2; break; /* @@@ break was missing */ @@ -484,7 +501,16 @@ static void adjust_broken_program (int h } } -static __inline__ void post_decide_line (int hpos) +STATIC_INLINE void set_decided_res (void) +{ + decided_res = RES_LORES; + if (bplcon0 & 0x8000) + decided_res = RES_HIRES; + if (bplcon0 & 0x40) + decided_res = RES_SUPERHIRES; +} + +STATIC_INLINE void post_decide_line (int hpos) { if (thisline_decision.which == 1 && hpos < thisline_decision.plfstrt + thisline_decision.plflinelen @@ -510,7 +536,7 @@ static __inline__ void post_decide_line && hpos > thisline_decision.plfstrt && decided_nr_planes < nr_planes_from_bplcon0) { - decided_hires = (bplcon0 & 0x8000) == 0x8000; + set_decided_res (); init_broken_program (); decided_nr_planes = nr_planes_from_bplcon0; thisline_decision.bplcon0 &= 0xFEF; @@ -569,21 +595,21 @@ static void decide_line_1 (int hpos) return; } - decided_hires = (bplcon0 & 0x8000) == 0x8000; + set_decided_res (); decided_nr_planes = nr_planes_from_bplcon0; #if 0 /* The blitter gets slower if there's high bitplane activity. * @@@ but the values must be different. FIXME */ if (bltstate != BLT_done - && ((decided_hires && decided_nr_planes > 2) - || (!decided_hires && decided_nr_planes > 4))) + && ((decided_res == RES_HIRES && decided_nr_planes > 2) + || (decided_res == RES_LORES && decided_nr_planes > 4))) { int pl = decided_nr_planes; unsigned int n = (eventtab[ev_blitter].evtime-cycles); if (n > plflinelen) n = plflinelen; n >>= 1; - if (decided_hires) + if (decided_res == RES_HIRES) pl <<= 1; if (pl == 8) eventtab[ev_blitter].evtime += plflinelen; @@ -599,7 +625,7 @@ static void decide_line_1 (int hpos) /* Main entry point for deciding how to draw a line. May either do * nothing, decide the line as border, or decide the line as playfield. */ -static __inline__ void decide_line (int hpos) +STATIC_INLINE void decide_line (int hpos) { if (thisline_decision.which == 0 && hpos >= plfstrt) decide_line_1 (hpos); @@ -711,13 +737,14 @@ static void decide_plane (int hpos) plane_decided = 1; - bytecount = plflinelen / (decided_hires ? 4 : 8) * 2; + bytecount = plflinelen / RES_SHIFT (decided_res) * 2; if (bytecount > MAX_WORDS_PER_LINE * 2) { /* Can't happen. */ static int warned = 0; if (!warned) write_log ("Mysterious bug in decide_plane(). Please report.\n"); + warned = 1; bytecount = 0; } if (!very_broken_program) { @@ -789,7 +816,7 @@ static void do_modulos (int hpos) if (decided_nr_planes != -1 && plane_decided && !modulos_added && hpos >= thisline_decision.plfstrt + thisline_decision.plflinelen) { - int bytecount = thisline_decision.plflinelen / (decided_hires ? 4 : 8) * 2; + int bytecount = thisline_decision.plflinelen / RES_SHIFT (decided_res) * 2; int add1 = bytecount + decided_bpl1mod; int add2 = bytecount + decided_bpl2mod; @@ -819,7 +846,7 @@ static void do_modulos (int hpos) } } -static __inline__ void record_sprite (int spr, int sprxp) +STATIC_INLINE void record_sprite (int spr, int sprxp) { int pos = next_sprite_draw; unsigned int data, datb; @@ -830,9 +857,6 @@ static __inline__ void record_sprite (in return; } #endif - data = sprdata[spr]; - datb = sprdatb[spr]; - /* XXX FIXME, this isn't very clever, but it might do */ for (;;) { if (pos == curr_drawinfo[next_lineno].first_sprite_draw) @@ -855,6 +879,8 @@ static __inline__ void record_sprite (in curr_sprite_positions[pos].linepos = sprxp; curr_sprite_positions[pos].num = spr; curr_sprite_positions[pos].ctl = sprctl[spr]; + data = sprdata[spr]; + datb = sprdatb[spr]; curr_sprite_positions[pos].datab = ((sprtaba[data & 0xFF] << 16) | sprtaba[data >> 8] | (sprtabb[datb & 0xFF] << 16) | sprtabb[datb >> 8]); next_sprite_draw++; @@ -862,7 +888,8 @@ static __inline__ void record_sprite (in static void decide_sprites (int hpos) { - int nrs[8], posns[8], count, i; + int nrs[MAX_SPRITES], posns[MAX_SPRITES]; + int count, i; int point = PIXEL_XPOS (hpos); if (framecnt != 0 || hpos < 0x14 || nr_armed == 0 || point == last_sprite_point) @@ -999,7 +1026,7 @@ static void reset_decisions (void) decided_bpl2mod = bpl2mod; decided_nr_planes = -1; - /* decided_hires shouldn't be touched before it's initialized by decide_line(). */ + /* decided_res shouldn't be touched before it's initialized by decide_line(). */ thisline_decision.diwfirstword = -1; thisline_decision.diwlastword = -2; if (hdiwstate == DIW_waiting_stop) { @@ -1032,10 +1059,40 @@ static void init_decisions (void) } } +/* set PAL or NTSC timing variables */ + +static void init_hz (void) +{ + int isntsc; + + beamcon0 = new_beamcon0; + init_decisions (); + + isntsc = beamcon0 & 0x20 ? 0 : 1; + if (!isntsc) { + maxvpos = MAXVPOS_PAL; + maxhpos = MAXHPOS_PAL; + minfirstline = MINFIRSTLINE_PAL; + vblank_endline = VBLANK_ENDLINE_PAL; + vblank_hz = VBLANK_HZ_PAL; + } else { + maxvpos = MAXVPOS_NTSC; + maxhpos = MAXHPOS_NTSC; + minfirstline = MINFIRSTLINE_NTSC; + vblank_endline = VBLANK_ENDLINE_NTSC; + vblank_hz = VBLANK_HZ_NTSC; + } + vsynctime = syncbase / vblank_hz; + + write_log ("Using %s timing\n", isntsc ? "NTSC" : "PAL"); +} + /* Calculate display window and data fetch values from the corresponding * hardware registers. */ static void calcdiw (void) { + int mask, add, mask2, add2, plfold; + int hstrt = diwstrt & 0xFF; int hstop = diwstop & 0xFF; int vstrt = diwstrt >> 8; @@ -1079,27 +1136,85 @@ static void calcdiw (void) plflastline = 313; } #endif + plfstrt = ddfstrt; plfstop = ddfstop; + /* @@@ Toni... these ones might be wrong for AGA? */ if (plfstrt < 0x18) plfstrt = 0x18; if (plfstop < 0x18) plfstop = 0x18; if (plfstop > 0xD8) plfstop = 0xD8; - if (plfstrt > plfstop) plfstrt = plfstop; /* ! If the masking operation is changed, the pfield_doline code could break * on some systems (alignment) */ /* This actually seems to be correct now, at least the non-AGA stuff... */ - plfstrt &= ~3; - plfstop &= ~3; - /* @@@ Start looking for AGA bugs here... (or maybe even in the above masking ops) */ - if ((fmode & 3) == 0) - plflinelen = (plfstop-plfstrt+15) & ~7; - else if ((fmode & 3) == 3) - plflinelen = (plfstop-plfstrt+63) & ~31; - else - plflinelen = (plfstop-plfstrt+31) & ~15; + + if ((fmode & 3) == 0) { + /* FMODE=0 */ + mask = ~7; + add = 15; + mask2 = ~3; + add2 = 0; + } else if ((fmode & 3) == 3) { + /* FMODE=3 */ + if(bplcon0 & 0x8000) { + mask = ~15; + add = 31; + mask2 = ~7; + add2 = 4; + } else { + mask = ~31; + add = 63; + mask2 = ~15; + add2 = 8; + } + } else { + /* FMODE=1/2 */ + if(bplcon0 & 0x8000) { + mask = ~15; + add = 31; + mask2 = ~15; + add2 = 4; + } else { + mask = ~15; + add = 31; + mask2 = ~15; + add2 = 8; + + } + } + /* ugh.. This works in every demo and game I have tested, but can't be correct, + * it looks too complex and stupid, does anybody know how this really works? (TW) + */ + plfold = plfstrt; + plfstrt &= mask2; + plfstrt += add2; + /* @@@ This one is different from the pre-AGA version. It shouldn't make + * a difference in OCS modes, though. */ + plfstop += plfstrt - plfold; + plfstop &= mask2; + plfstop += add2; + plflinelen = (plfstop-plfstrt+add) & mask; + + if (plfstrt > plfstop) + plfstrt = plfstop; + +#if 0 + if (plflinelen > 100 && (bplcon0 & 0x8000)) + write_log("vpos: %d fmode: %d, hires %d strt1 %d stop1 %d strt2 %d stop2 %d,plflinelen %d\n", + vpos,fmode&3,(bplcon0&0x8000)?1:0,ddfstrt,ddfstop,plfstrt,plfstop,plflinelen); +#endif } +/* + * lores,fmode=3 24 184 = 192 + * hires,fmode=3 40 200 = 176 + * hires,fmode=3 40 216 = 192 + * hires,fmode=1 56 200 = 160 + * hires,fmode=1 56 208 = 160 + * lores,fmode=1 48 200 = 176 + * lores,fmode=1 72 168 = 112 +*/ + /* Mousehack stuff */ #define defstepx (1<<16) @@ -1144,7 +1259,7 @@ static void mousehack_setfollow (void) mstepx = defstepx; mstepy = defstepy; } -uae_u32 mousehack_helper (void) +static uae_u32 mousehack_helper (void) { int mousexpos, mouseypos; @@ -1182,7 +1297,7 @@ void togglemouse (void) } } -static __inline__ int adjust (int val) +STATIC_INLINE int adjust (int val) { if (val > 127) return 127; @@ -1262,16 +1377,43 @@ static void do_mouse_hack (void) } } +static int timehack_alive = 0; + +static uae_u32 timehack_helper (void) +{ +#ifdef HAVE_GETTIMEOFDAY + struct timeval tv; + if (m68k_dreg (regs, 0) == 0) + return timehack_alive; + + timehack_alive = 10; + + gettimeofday (&tv, NULL); + put_long (m68k_areg (regs, 0), tv.tv_sec - (((365 * 8 + 2) * 24 - 2) * 60 * 60)); + put_long (m68k_areg (regs, 0) + 4, tv.tv_usec); + return 0; +#else + return 2; +#endif +} + /* * register functions */ - -static __inline__ uae_u16 DMACONR (void) +STATIC_INLINE uae_u16 DENISEID (void) +{ + if (currprefs.chipset_mask & CSMASK_AGA) + return 0xF8; + if (currprefs.chipset_mask & CSMASK_ECS_DENISE) + return 0xFC; + return 0xFFFF; +} +STATIC_INLINE uae_u16 DMACONR (void) { return (dmacon | (bltstate==BLT_done ? 0 : 0x4000) | (blt_info.blitzero ? 0x2000 : 0)); } -static __inline__ uae_u16 INTENAR (void) +STATIC_INLINE uae_u16 INTENAR (void) { return intena; } @@ -1279,19 +1421,16 @@ uae_u16 INTREQR (void) { return intreq | (currprefs.use_serial ? 0x0001 : 0); } -static __inline__ uae_u16 ADKCONR (void) +STATIC_INLINE uae_u16 ADKCONR (void) { return adkcon; } -static __inline__ uae_u16 VPOSR (void) +STATIC_INLINE uae_u16 VPOSR (void) { -#if AGA_CHIPSET == 1 - return (vpos >> 8) | lof | 0x2300; -#elif defined (ECS_AGNUS) - return (vpos >> 8) | lof | 0x2000; -#else - return (vpos >> 8) | lof; -#endif + unsigned int csbit = ntscmode ? 0x1000 : 0; + csbit |= (currprefs.chipset_mask & CSMASK_AGA) ? 0x2300 : 0; + csbit |= (currprefs.chipset_mask & CSMASK_ECS_AGNUS) ? 0x2000 : 0; + return (vpos >> 8) | lof | csbit; } static void VPOSW (uae_u16 v) { @@ -1304,15 +1443,15 @@ static void VPOSW (uae_u16 v) */ } -static __inline__ uae_u16 VHPOSR (void) +STATIC_INLINE uae_u16 VHPOSR (void) { return (vpos << 8) | current_hpos(); } -static __inline__ void COP1LCH (uae_u16 v) { cop1lc = (cop1lc & 0xffff) | ((uae_u32)v << 16); } -static __inline__ void COP1LCL (uae_u16 v) { cop1lc = (cop1lc & ~0xffff) | (v & 0xfffe); } -static __inline__ void COP2LCH (uae_u16 v) { cop2lc = (cop2lc & 0xffff) | ((uae_u32)v << 16); } -static __inline__ void COP2LCL (uae_u16 v) { cop2lc = (cop2lc & ~0xffff) | (v & 0xfffe); } +STATIC_INLINE void COP1LCH (uae_u16 v) { cop1lc = (cop1lc & 0xffff) | ((uae_u32)v << 16); } +STATIC_INLINE void COP1LCL (uae_u16 v) { cop1lc = (cop1lc & ~0xffff) | (v & 0xfffe); } +STATIC_INLINE void COP2LCH (uae_u16 v) { cop2lc = (cop2lc & 0xffff) | ((uae_u32)v << 16); } +STATIC_INLINE void COP2LCL (uae_u16 v) { cop2lc = (cop2lc & ~0xffff) | (v & 0xfffe); } static void COPJMP1 (uae_u16 a) { @@ -1344,7 +1483,7 @@ static void COPJMP2 (uae_u16 a) events_schedule (); } -static __inline__ void COPCON (uae_u16 a) +STATIC_INLINE void COPCON (uae_u16 a) { copcon = a; } @@ -1374,6 +1513,10 @@ static void DMACON (uae_u16 v) abort (); need_resched = 1; } + if ((dmacon & DMA_DISK) > (oldcon & DMA_DISK)) { + DISK_reset_cycles (); + } + if ((dmacon & DMA_BLITPRI) > (oldcon & DMA_BLITPRI) && bltstate != BLT_done) { static int count = 0; if (!count) { @@ -1401,6 +1544,7 @@ static void DMACON (uae_u16 v) } else { if (cdp->state == 1 || cdp->state == 5) { cdp->state = 0; + cdp->last_sample = 0; cdp->current_sample = 0; } } @@ -1412,7 +1556,7 @@ static void DMACON (uae_u16 v) /*static int trace_intena = 0;*/ -static __inline__ void INTENA (uae_u16 v) +STATIC_INLINE void INTENA (uae_u16 v) { /* if (trace_intena) fprintf (stderr, "INTENA: %04x\n", v);*/ @@ -1440,6 +1584,11 @@ static void ADKCON (uae_u16 v) audio_channel[3].adk_mask = (((t >> 3) & 1) - 1); } +static void BEAMCON0 (uae_u16 v) +{ + new_beamcon0 = v & 0x20; +} + static void BPLPTH (int hpos, uae_u16 v, int num) { decide_line (hpos); @@ -1457,31 +1606,32 @@ static void BPLPTL (int hpos, uae_u16 v, static void BPLCON0 (int hpos, uae_u16 v) { -#if AGA_CHIPSET == 0 - v &= 0xFF0E; - /* The Sanity WOC demo needs this at one place (at the end of the "Party Effect") - * Disable bitplane DMA if someone tries to do more than 4 Hires bitplanes. */ - if ((v & 0xF000) > 0xC000) - v &= 0xFFF; - /* Don't want 7 lores planes either. */ - if ((v & 0x8000) == 0 && (v & 0x7000) == 0x7000) - v &= 0xEFFF; -#endif + if (! (currprefs.chipset_mask & CSMASK_AGA)) { + v &= 0xFF0E; + /* The Sanity WOC demo needs this at one place (at the end of the "Party Effect") + * Disable bitplane DMA if someone tries to do more than 4 Hires bitplanes. */ + if ((v & 0xF000) > 0xC000) + v &= 0xFFF; + /* Don't want 7 lores planes either. */ + if ((v & 0x8000) == 0 && (v & 0x7000) == 0x7000) + v &= 0xEFFF; + } if (bplcon0 == v) return; decide_line (hpos); bplcon0 = v; nr_planes_from_bplcon0 = GET_PLANES (v); -#if AGA_CHIPSET != 0 - /* It's not clear how the copper timings are affected by the number - * of bitplanes on AGA machines */ - corrected_nr_planes_from_bplcon0 = 4; -#else - corrected_nr_planes_from_bplcon0 = nr_planes_from_bplcon0 << (bplcon0 & 0x8000 ? 1 : 0); -#endif + + if (currprefs.chipset_mask & CSMASK_AGA) + /* It's not clear how the copper timings are affected by the number + * of bitplanes on AGA machines */ + corrected_nr_planes_from_bplcon0 = 4; + else + corrected_nr_planes_from_bplcon0 = nr_planes_from_bplcon0 << (bplcon0 & 0x8000 ? 1 : 0); + post_decide_line (hpos); } -static __inline__ void BPLCON1 (int hpos, uae_u16 v) +STATIC_INLINE void BPLCON1 (int hpos, uae_u16 v) { if (bplcon1 == v) return; @@ -1489,22 +1639,27 @@ static __inline__ void BPLCON1 (int hpos bplcon1 = v; decide_delay (hpos); } -static __inline__ void BPLCON2 (int hpos, uae_u16 v) +STATIC_INLINE void BPLCON2 (int hpos, uae_u16 v) { - if (bplcon2 != v) - decide_line (hpos); + if (bplcon2 == v) + return; + decide_line (hpos); bplcon2 = v; } -static __inline__ void BPLCON3 (int hpos, uae_u16 v) +STATIC_INLINE void BPLCON3 (int hpos, uae_u16 v) { - if (bplcon3 != v) - decide_line (hpos); + if (bplcon3 == v) + return; + decide_line (hpos); bplcon3 = v; } -static __inline__ void BPLCON4 (int hpos, uae_u16 v) +STATIC_INLINE void BPLCON4 (int hpos, uae_u16 v) { - if (bplcon4 != v) - decide_line (hpos); + if (! (currprefs.chipset_mask & CSMASK_AGA)) + return; + if (bplcon4 == v) + return; + decide_line (hpos); bplcon4 = v; } @@ -1527,14 +1682,14 @@ static void BPL2MOD (int hpos, uae_u16 v } /* We could do as well without those... */ -static __inline__ void BPL1DAT (uae_u16 v) { bpl1dat = v; } -static __inline__ void BPL2DAT (uae_u16 v) { bpl2dat = v; } -static __inline__ void BPL3DAT (uae_u16 v) { bpl3dat = v; } -static __inline__ void BPL4DAT (uae_u16 v) { bpl4dat = v; } -static __inline__ void BPL5DAT (uae_u16 v) { bpl5dat = v; } -static __inline__ void BPL6DAT (uae_u16 v) { bpl6dat = v; } -static __inline__ void BPL7DAT (uae_u16 v) { bpl7dat = v; } -static __inline__ void BPL8DAT (uae_u16 v) { bpl8dat = v; } +STATIC_INLINE void BPL1DAT (uae_u16 v) { bpl1dat = v; } +STATIC_INLINE void BPL2DAT (uae_u16 v) { bpl2dat = v; } +STATIC_INLINE void BPL3DAT (uae_u16 v) { bpl3dat = v; } +STATIC_INLINE void BPL4DAT (uae_u16 v) { bpl4dat = v; } +STATIC_INLINE void BPL5DAT (uae_u16 v) { bpl5dat = v; } +STATIC_INLINE void BPL6DAT (uae_u16 v) { bpl6dat = v; } +STATIC_INLINE void BPL7DAT (uae_u16 v) { bpl7dat = v; } +STATIC_INLINE void BPL8DAT (uae_u16 v) { bpl8dat = v; } static void DIWSTRT (int hpos, uae_u16 v) { @@ -1558,6 +1713,8 @@ static void DIWSTOP (int hpos, uae_u16 v static void DIWHIGH (int hpos, uae_u16 v) { + if (! (currprefs.chipset_mask & CSMASK_ECS_DENISE)) + return; if (diwhigh_written && diwhigh == v) return; decide_line (hpos); @@ -1568,7 +1725,7 @@ static void DIWHIGH (int hpos, uae_u16 v static void DDFSTRT (int hpos, uae_u16 v) { - v &= AGA_CHIPSET ? 0x1FF : 0xFF; + v &= (currprefs.chipset_mask & CSMASK_AGA) ? 0x1FC : 0xFC; if (ddfstrt == v) return; decide_line (hpos); @@ -1577,7 +1734,7 @@ static void DDFSTRT (int hpos, uae_u16 v } static void DDFSTOP (int hpos, uae_u16 v) { - v &= AGA_CHIPSET ? 0x1FF : 0xFF; + v &= (currprefs.chipset_mask & CSMASK_AGA) ? 0x1FC : 0xFC; if (ddfstop == v) return; decide_line (hpos); @@ -1585,6 +1742,14 @@ static void DDFSTOP (int hpos, uae_u16 v calcdiw (); } +static void FMODE (uae_u16 v) +{ + if (! (currprefs.chipset_mask & CSMASK_AGA)) + return; + fmode = v; + calcdiw (); +} + static void BLTADAT (uae_u16 v) { maybe_blit(); @@ -1616,7 +1781,12 @@ static void BLTDMOD (uae_u16 v) { maybe_ static void BLTCON0 (uae_u16 v) { maybe_blit (); bltcon0 = v; blinea_shift = v >> 12; } /* The next category is "Most useless hardware register". * And the winner is... */ -static void BLTCON0L (uae_u16 v) { maybe_blit (); bltcon0 = (bltcon0 & 0xFF00) | (v & 0xFF); } +static void BLTCON0L (uae_u16 v) +{ + if (! (currprefs.chipset_mask & CSMASK_ECS_AGNUS)) + return; + maybe_blit (); bltcon0 = (bltcon0 & 0xFF00) | (v & 0xFF); +} static void BLTCON1 (uae_u16 v) { maybe_blit (); bltcon1 = v; } static void BLTAFWM (uae_u16 v) { maybe_blit (); blt_info.bltafwm = v; } @@ -1648,12 +1818,16 @@ static void BLTSIZE (uae_u16 v) static void BLTSIZV (uae_u16 v) { + if (! (currprefs.chipset_mask & CSMASK_ECS_AGNUS)) + return; maybe_blit (); oldvblts = v & 0x7FFF; } static void BLTSIZH (uae_u16 v) { + if (! (currprefs.chipset_mask & CSMASK_ECS_AGNUS)) + return; maybe_blit (); blt_info.hblitsize = v & 0x7FF; blt_info.vblitsize = oldvblts; @@ -1663,7 +1837,7 @@ static void BLTSIZH (uae_u16 v) do_blitter (); } -static __inline__ void SPRxCTL_1 (uae_u16 v, int num) +STATIC_INLINE void SPRxCTL_1 (uae_u16 v, int num) { int sprxp; sprctl[num] = v; @@ -1680,7 +1854,7 @@ static __inline__ void SPRxCTL_1 (uae_u1 sprvstart[num] = (sprpos[num] >> 8) | ((sprctl[num] << 6) & 0x100); sprvstop[num] = (sprctl[num] >> 8) | ((sprctl[num] << 7) & 0x100); } -static __inline__ void SPRxPOS_1 (uae_u16 v, int num) +STATIC_INLINE void SPRxPOS_1 (uae_u16 v, int num) { int sprxp; sprpos[num] = v; @@ -1688,13 +1862,13 @@ static __inline__ void SPRxPOS_1 (uae_u1 sprxpos[num] = sprxp; sprvstart[num] = (sprpos[num] >> 8) | ((sprctl[num] << 6) & 0x100); } -static __inline__ void SPRxDATA_1 (uae_u16 v, int num) +STATIC_INLINE void SPRxDATA_1 (uae_u16 v, int num) { sprdata[num] = v; nr_armed += 1 - sprarmed[num]; sprarmed[num] = 1; } -static __inline__ void SPRxDATB_1 (uae_u16 v, int num) +STATIC_INLINE void SPRxDATB_1 (uae_u16 v, int num) { sprdatb[num] = v; } @@ -1800,36 +1974,73 @@ static void DSKLEN (uae_u16 v) write_log ("warning: Disk DMA aborted!\n"); eventtab[ev_diskblk].active = 0; events_schedule(); - } dsklen = dsklength = v; dsklength &= 0x3fff; if (dskdmaen == 2 && dsksync != 0x4489 && (adkcon & 0x400)) { write_log ("Non-standard sync: %04x len: %x\n", dsksync, dsklength); } - if (dskdmaen > 1) { - if (dsklen & 0x4000) { - eventtab[ev_diskblk].active = 1; - eventtab[ev_diskblk].oldcycles = cycles; - eventtab[ev_diskblk].evtime = 40 + cycles; /* ??? */ - events_schedule(); - } else { - int result = DISK_PrepareReadMFM(dsklength, dsksync, adkcon & 0x400); - if (result) { - eventtab[ev_diskblk].active = 1; - eventtab[ev_diskblk].oldcycles = cycles; - eventtab[ev_diskblk].evtime = result + cycles; - events_schedule(); - } - } + if (dskdmaen <= 1) + return; + + if (dsklen & 0x4000) { + eventtab[ev_diskblk].active = 1; + eventtab[ev_diskblk].oldcycles = cycles; + eventtab[ev_diskblk].evtime = 40 + cycles; /* ??? */ + events_schedule(); + dskdmaen = 3; + } else { + DISK_StartRead (); + syncfound = !(adkcon & 0x400); + } +} + +static int update_disk_reads (void) +{ + int retval = 0; + /* If we get called from DSKBYTR or DSKDATR, we may not actually be + reading from disk, so skip the DMA update. */ + if (dskdmaen != 2) { + DISK_update_reads (0, 0, 0, 0); + return 0; + } + if (dsklength == 0) + write_log ("Bug in disk code: dsklength == 0\n"); + else + retval = DISK_update_reads (&dskpt, &dsklength, &syncfound, dsksync); + + if (dsklength == 0) { + dskdmaen = -1; + /* DISKBLK */ + INTREQ (0x8002); } + return retval; +} + +static void disksync_handler (void) +{ + uae_u16 mfm, byte; + /* If no DMA, something weird happened. It's not clear what to do + about it. */ + if (! dmaen (0x10) || dskdmaen != 2) + return; + + /* Likewise... */ + if (! update_disk_reads ()) + return; + DISK_GetData (&mfm, &byte); + + if (dsksync == mfm) + INTREQ (0x9000); + eventtab[ev_disksync].active = 0; } static uae_u16 DSKBYTR (void) { uae_u16 v = (dsklen >> 1) & 0x6000; uae_u16 mfm, byte; - if (DISK_GetData (&mfm, &byte)) + if (update_disk_reads ()) v |= 0x8000; + DISK_GetData (&mfm, &byte); v |= byte; if (dsksync == mfm) v |= 0x1000; @@ -1839,6 +2050,7 @@ static uae_u16 DSKBYTR (void) static uae_u16 DSKDATR (void) { uae_u16 mfm, byte; + update_disk_reads (); DISK_GetData (&mfm, &byte); return mfm; } @@ -1914,7 +2126,7 @@ static void JOYTEST (uae_u16 v) * Here starts the copper code. Can you believe it used to be worse? */ -static __inline__ void copper_adjust_diw (struct copper *cst) +STATIC_INLINE void copper_adjust_diw (struct copper *cst) { if (cst->vdiw == DIW_waiting_start && vpos == plffirstline) cst->vdiw = DIW_waiting_stop; @@ -1940,23 +2152,23 @@ static unsigned int waitmasktab[256]; #define COP_OFFSET 4 -static __inline__ int copper_in_playfield (enum diw_states diw, int hpos) +STATIC_INLINE int copper_in_playfield (enum diw_states diw, int hpos) { hpos -= COP_OFFSET; return diw == DIW_waiting_stop && hpos >= plfstrt && hpos < plfstrt + plflinelen; } -static __inline__ int copper_cant_read (enum diw_states diw, int hpos, int planes) +STATIC_INLINE int copper_cant_read (enum diw_states diw, int hpos, int planes) { int t; if (hpos >= ((maxhpos - 2) & ~1)) return 1; -#if AGA_CHIPSET != 0 - /* FIXME */ - return 0; -#else + if (currprefs.chipset_mask & CSMASK_AGA) + /* FIXME */ + return 0; + if (! copper_in_playfield (diw, hpos)) return 0; @@ -1966,7 +2178,6 @@ static __inline__ int copper_cant_read ( abort (); #endif return t; -#endif } static void update_copper_1 (int until_hpos) @@ -2012,7 +2223,7 @@ static void update_copper_1 (int until_h if (cop_state.do_move) { cop_state.do_move = 0; - if (cop_state.i1 < (copcon & 2 ? (AGA_CHIPSET ? 0 : 0x40u) : 0x80u)) { + if (cop_state.i1 < (copcon & 2 ? ((currprefs.chipset_mask & CSMASK_AGA) ? 0 : 0x40u) : 0x80u)) { cop_state.state = COP_stop; break; } @@ -2140,7 +2351,7 @@ static void update_copper_1 (int until_h cop_state.vpos = c_vpos; } -static __inline__ void update_copper (int until_hpos) +STATIC_INLINE void update_copper (int until_hpos) { if (cop_state.vpos > vpos || cop_state.hpos > until_hpos @@ -2204,7 +2415,7 @@ static void prepare_copper_1 (void) if (cst.do_move) { cst.do_move = 0; - if (cst.i1 < (copcon & 2 ? (AGA_CHIPSET ? 0 : 0x40u) : 0x80u)) { + if (cst.i1 < (copcon & 2 ? ((currprefs.chipset_mask & CSMASK_AGA) ? 0 : 0x40u) : 0x80u)) { cst.state = COP_stop; eventtab[ev_copper].active = 0; return; @@ -2357,13 +2568,13 @@ static void diskblk_handler (void) void do_disk (void) { - if (dskdmaen != 2 && (regs.spcflags & SPCFLAG_DISK)) { + if (dskdmaen != 3 && (regs.spcflags & SPCFLAG_DISK)) { static int warned = 0; if (!warned) warned++, write_log ("BUG!\n"); return; } - if (dmaen(0x10)){ + if (dmaen (0x10)){ if (dsklen & 0x4000) { if (!chipmem_bank.check (dskpt, 2*dsklength)) { write_log ("warning: Bad disk write DMA pointer\n"); @@ -2379,8 +2590,6 @@ void do_disk (void) } DISK_WriteData(dsklength); } - } else { - DISK_ReadMFM (dskpt); } regs.spcflags &= ~SPCFLAG_DISK; INTREQ(0x9002); @@ -2587,6 +2796,11 @@ static void vsync_handler (void) cnt--; } + /* For now, let's only allow this to change at vsync time. It gets too + * hairy otherwise. */ + if (beamcon0 != new_beamcon0) + init_hz (); + lof_changed = 0; cop_state.ip = cop1lc; @@ -2636,6 +2850,8 @@ static void vsync_handler (void) #endif if (ievent_alive > 0) ievent_alive--; + if (timehack_alive > 0) + timehack_alive--; CIA_vsync_handler(); } @@ -2650,7 +2866,12 @@ static void hsync_handler (void) eventtab[ev_hsync].evtime += cycles - eventtab[ev_hsync].oldcycles; eventtab[ev_hsync].oldcycles = cycles; - CIA_hsync_handler(); + CIA_hsync_handler (); + + if (dskdmaen == 2 && dmaen (0x10)) { + update_disk_reads (); + DISK_search_sync (maxhpos, dsksync); + } if (currprefs.produce_sound > 0) { int nr; @@ -2738,6 +2959,8 @@ static void init_eventtab (void) eventtab[ev_diskblk].active = 0; eventtab[ev_diskindex].handler = diskindex_handler; eventtab[ev_diskindex].active = 0; + eventtab[ev_disksync].handler = disksync_handler; + eventtab[ev_disksync].active = 0; events_schedule (); } @@ -2771,6 +2994,7 @@ void customreset (void) mousestate = normal_mouse; } ievent_alive = 0; + timehack_alive = 0; clx_sprmask = 0xFF; clxdat = 0; @@ -2787,11 +3011,14 @@ void customreset (void) dskdmaen = 0; cycles = 0; - audio_reset (); - bplcon4 = 0x11; /* Get AGA chipset into ECS compatibility mode */ bplcon3 = 0xC00; + new_beamcon0 = ntscmode ? 0x00 : 0x20; + init_hz (); + + audio_reset (); + init_eventtab (); init_sprites (); @@ -2859,6 +3086,8 @@ static void gen_custom_tables (void) void custom_init (void) { + uaecptr pos; + #ifdef OS_WITHOUT_MEMORY_MANAGEMENT int num; @@ -2869,6 +3098,18 @@ void custom_init (void) delay_changes = xmalloc (max_delay_change * sizeof (struct delay_change)); #endif + pos = here (); + + org (0xF0FF70); + calltrap (deftrap (mousehack_helper)); + dw (RTS); + + org (0xF0FFA0); + calltrap (deftrap (timehack_helper)); + dw (RTS); + + org (pos); + init_decisions (); gen_custom_tables (); @@ -2917,11 +3158,7 @@ uae_u32 REGPARAM2 custom_wget (uaecptr a case 0x01A: return DSKBYTR(); case 0x01C: return INTENAR(); case 0x01E: return INTREQR(); -#if AGA_CHIPSET == 1 - case 0x07C: return 0xF8; -#elif defined ECS_DENISE - case 0x07C: return 0xFC; -#endif + case 0x07C: return DENISEID(); default: custom_wput(addr,0); return 0xffff; @@ -3095,18 +3332,12 @@ void REGPARAM2 custom_wput_1 (int hpos, break; case 0x36: JOYTEST (value); break; -#if defined (ECS_AGNUS) || (AGA_CHIPSET == 1) - case 0x5A: BLTCON0L(value); break; + case 0x5A: BLTCON0L (value); break; case 0x5C: BLTSIZV (value); break; case 0x5E: BLTSIZH (value); break; -#endif -#ifdef ECS_DENISE case 0x1E4: DIWHIGH (hpos, value); break; -#endif -#if AGA_CHIPSET == 1 case 0x10C: BPLCON4 (hpos, value); break; - case 0x1FC: fmode = value; calcdiw (); break; -#endif + case 0x1FC: FMODE (value); break; } }