--- uae/src/custom.c 2018/04/24 16:43:34 1.1.1.5 +++ uae/src/custom.c 2018/04/24 16:44:56 1.1.1.6 @@ -38,6 +38,9 @@ #include "picasso96.h" #include "drawing.h" +static unsigned int n_consecutive_skipped = 0; +static unsigned int total_skipped = 0; + #define SPRITE_COLLISIONS /* Mouse and joystick emulation */ @@ -89,8 +92,8 @@ static int spron[8]; static uaecptr sprpt[8]; static int sprxpos[8], sprvstart[8], sprvstop[8]; -static uae_u32 bpl1dat,bpl2dat,bpl3dat,bpl4dat,bpl5dat,bpl6dat,bpl7dat,bpl8dat; -static uae_s16 bpl1mod,bpl2mod; +static uae_u32 bpl1dat, bpl2dat, bpl3dat, bpl4dat, bpl5dat, bpl6dat, bpl7dat, bpl8dat; +static uae_s16 bpl1mod, bpl2mod; static uaecptr bplpt[8]; #ifndef SMART_UPDATE @@ -100,7 +103,7 @@ static char *real_bplpt[8]; /*static int blitcount[256]; blitter debug */ static struct color_entry current_colors; -static unsigned int bplcon0,bplcon1,bplcon2,bplcon3,bplcon4; +static unsigned int bplcon0, bplcon1, bplcon2, bplcon3, bplcon4; static int nr_planes_from_bplcon0, corrected_nr_planes_from_bplcon0; static unsigned int diwstrt, diwstop, diwhigh; static int diwhigh_written; @@ -109,7 +112,7 @@ static unsigned int sprdata[8], sprdatb[ 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 uae_u16 dsklen, dsksync; static int dsklength; /* The display and data fetch windows */ @@ -119,8 +122,8 @@ enum diw_states DIW_waiting_start, DIW_waiting_stop }; -static int plffirstline,plflastline,plfstrt,plfstop,plflinelen; -int diwfirstword,diwlastword; +static int plffirstline, plflastline, plfstrt, plfstop, plflinelen; +int diwfirstword, diwlastword; static enum diw_states diwstate, hdiwstate; /* Sprite collisions */ @@ -157,7 +160,7 @@ int dskdmaen; /* used in cia.c */ */ /* Used also by bebox.cpp */ -unsigned long int msecs = 0, frametime = 0, timeframes = 0; +unsigned long int msecs = 0, frametime = 0, lastframetime = 0, timeframes = 0; static unsigned long int seconds_base; int bogusframe; @@ -253,8 +256,10 @@ void check_prefs_changed_custom (void) { currprefs.framerate = changed_prefs.framerate; /* Not really the right place... */ - if (currprefs.fake_joystick != changed_prefs.fake_joystick) { - currprefs.fake_joystick = changed_prefs.fake_joystick; + if (currprefs.jport0 != changed_prefs.jport0 + || currprefs.jport1 != changed_prefs.jport1) { + currprefs.jport0 = changed_prefs.jport0; + currprefs.jport1 = changed_prefs.jport1; joystick_setting_changed (); } currprefs.immediate_blits = changed_prefs.immediate_blits; @@ -264,11 +269,10 @@ void check_prefs_changed_custom (void) static __inline__ void setclr (uae_u16 *p, uae_u16 val) { - if (val & 0x8000) { + if (val & 0x8000) *p |= val & 0x7FFF; - } else { + else *p &= ~val; - } } __inline__ int current_hpos (void) @@ -287,7 +291,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; @@ -484,7 +488,7 @@ static __inline__ void post_decide_line { if (thisline_decision.which == 1 && hpos < thisline_decision.plfstrt + thisline_decision.plflinelen - && ((bplcon0 & 0x7000) == 0 || !dmaen (DMA_BITPLANE))) + && (GET_PLANES (bplcon0) == 0 || !dmaen (DMA_BITPLANE))) { /* This is getting gross... */ thisline_decision.plflinelen = hpos - thisline_decision.plfstrt; @@ -497,7 +501,7 @@ static __inline__ void post_decide_line } if (diwstate == DIW_waiting_start - || (bplcon0 & 0x7000) == 0 + || GET_PLANES (bplcon0) == 0 || !dmaen (DMA_BITPLANE) || hpos >= thisline_decision.plfstrt + thisline_decision.plflinelen) return; @@ -509,8 +513,8 @@ static __inline__ void post_decide_line decided_hires = (bplcon0 & 0x8000) == 0x8000; init_broken_program (); decided_nr_planes = nr_planes_from_bplcon0; - thisline_decision.bplcon0 &= 0xFFF; - thisline_decision.bplcon0 |= bplcon0 & 0xF000; + thisline_decision.bplcon0 &= 0xFEF; + thisline_decision.bplcon0 |= bplcon0 & 0xF010; adjust_broken_program (hpos); MARK_LINE_CHANGED; /* Play safe. */ return; @@ -531,8 +535,8 @@ static __inline__ void post_decide_line init_broken_program (); decided_nr_planes = nr_planes_from_bplcon0; - thisline_decision.bplcon0 &= 0xFFF; - thisline_decision.bplcon0 |= bplcon0 & 0xF000; + thisline_decision.bplcon0 &= 0xFEF; + thisline_decision.bplcon0 |= bplcon0 & 0xF010; MARK_LINE_CHANGED; /* Play safe. */ decide_as_playfield (plfstrt, plflinelen); @@ -1467,8 +1471,14 @@ static void BPLCON0 (int hpos, uae_u16 v return; decide_line (hpos); bplcon0 = v; - nr_planes_from_bplcon0 = (bplcon0 >> 12) & 7; - corrected_nr_planes_from_bplcon0 = ((bplcon0 >> 12) & 7) << (bplcon0 & 0x8000 ? 1 : 0); + 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 post_decide_line (hpos); } static __inline__ void BPLCON1 (int hpos, uae_u16 v) @@ -1523,6 +1533,8 @@ static __inline__ void BPL3DAT (uae_u16 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) { @@ -1556,7 +1568,7 @@ static void DIWHIGH (int hpos, uae_u16 v static void DDFSTRT (int hpos, uae_u16 v) { - v &= 0xFF; + v &= AGA_CHIPSET ? 0x1FF : 0xFF; if (ddfstrt == v) return; decide_line (hpos); @@ -1565,7 +1577,7 @@ static void DDFSTRT (int hpos, uae_u16 v } static void DDFSTOP (int hpos, uae_u16 v) { - v &= 0xFF; + v &= AGA_CHIPSET ? 0x1FF : 0xFF; if (ddfstop == v) return; decide_line (hpos); @@ -1843,18 +1855,18 @@ static uae_u16 POTGOR (void) uae_u16 v = (potgo_value | (potgo_value << 1)) & 0xAA00; v |= v >> 1; - if (JSEM_ISMOUSE (0, currprefs.fake_joystick)) { + if (JSEM_ISMOUSE (0, &currprefs)) { if (buttonstate[2]) v &= 0xFBFF; if (buttonstate[1]) v &= 0xFEFF; - } else if (JSEM_ISJOY0 (0, currprefs.fake_joystick) || JSEM_ISJOY1 (0, currprefs.fake_joystick)) { + } else if (JSEM_ISJOY0 (0, &currprefs) || JSEM_ISJOY1 (0, &currprefs)) { if (joy0button & 2) v &= 0xfbff; if (joy0button & 4) v &= 0xfeff; } - if (JSEM_ISJOY0 (1, currprefs.fake_joystick) || JSEM_ISJOY1 (1, currprefs.fake_joystick)) { + if (JSEM_ISJOY0 (1, &currprefs) || JSEM_ISJOY1 (1, &currprefs)) { if (joy1button & 2) v &= 0xbfff; if (joy1button & 4) v &= 0xefff; } @@ -1865,7 +1877,7 @@ static uae_u16 POTGOR (void) static uae_u16 POT0DAT (void) { static uae_u16 cnt = 0; - if (JSEM_ISMOUSE (0, currprefs.fake_joystick)) { + if (JSEM_ISMOUSE (0, &currprefs)) { if (buttonstate[2]) cnt = ((cnt + 1) & 0xFF) | (cnt & 0xFF00); if (buttonstate[1]) @@ -1876,7 +1888,7 @@ static uae_u16 POT0DAT (void) } static uae_u16 JOY0DAT (void) { - if (JSEM_ISMOUSE (0, currprefs.fake_joystick)) { + if (JSEM_ISMOUSE (0, &currprefs)) { do_mouse_hack (); return ((uae_u8)mouse_x) + ((uae_u16)mouse_y << 8); } @@ -1884,7 +1896,7 @@ static uae_u16 JOY0DAT (void) } static uae_u16 JOY1DAT (void) { - if (JSEM_ISMOUSE (1, currprefs.fake_joystick)) { + if (JSEM_ISMOUSE (1, &currprefs)) { do_mouse_hack (); return ((uae_u8)mouse_x) + ((uae_u16)mouse_y << 8); } @@ -1892,7 +1904,7 @@ static uae_u16 JOY1DAT (void) } static void JOYTEST (uae_u16 v) { - if (JSEM_ISMOUSE (0, currprefs.fake_joystick)) { + if (JSEM_ISMOUSE (0, &currprefs)) { mouse_x = v & 0xFC; mouse_y = (v >> 8) & 0xFC; } @@ -1941,6 +1953,10 @@ static __inline__ int copper_cant_read ( if (hpos >= ((maxhpos - 2) & ~1)) return 1; +#if AGA_CHIPSET != 0 + /* FIXME */ + return 0; +#else if (! copper_in_playfield (diw, hpos)) return 0; @@ -1950,6 +1966,7 @@ static __inline__ int copper_cant_read ( abort (); #endif return t; +#endif } static void update_copper_1 (int until_hpos) @@ -1995,7 +2012,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 ? 0x40u : 0x80u)) { + if (cop_state.i1 < (copcon & 2 ? (AGA_CHIPSET ? 0 : 0x40u) : 0x80u)) { cop_state.state = COP_stop; break; } @@ -2187,11 +2204,11 @@ static void prepare_copper_1 (void) if (cst.do_move) { cst.do_move = 0; - if (cst.i1 < (copcon & 2 ? 0x40u : 0x80u)) { + if (cst.i1 < (copcon & 2 ? (AGA_CHIPSET ? 0 : 0x40u) : 0x80u)) { cst.state = COP_stop; eventtab[ev_copper].active = 0; return; - } else if (dangerous_reg (cst.i1)) { + } else if (dangerous_reg (cst.i1)) { eventtab[ev_copper].active = 1; eventtab[ev_copper].oldcycles = cycles; eventtab[ev_copper].evtime = cycles + cst.hpos - current_hpos () + (cst.vpos - cop_state.vpos) * maxhpos; @@ -2592,8 +2609,26 @@ static void vsync_handler (void) newtime = (tv.tv_sec-seconds_base) * 1000 + tv.tv_usec / 1000; if (!bogusframe) { - frametime += newtime - msecs; + lastframetime = newtime - msecs; + +#if 0 /* This doesn't appear to work too well yet... later. */ + if (n_consecutive_skipped > currprefs.sound_pri_cutoff + || lastframetime < currprefs.sound_pri_time) + { + n_consecutive_skipped = 0; + clear_inhibit_frame (IHF_SOUNDADJUST); + } else { + n_consecutive_skipped++; + set_inhibit_frame (IHF_SOUNDADJUST); + total_skipped++; + } +#endif + + frametime += lastframetime; timeframes++; + + if ((timeframes & 127) == 0) + gui_fps (1000 * timeframes / frametime); } msecs = newtime; bogusframe = 0; @@ -2775,12 +2810,14 @@ void customreset (void) void dumpcustom (void) { - fprintf (stderr, "DMACON: %x INTENA: %x INTREQ: %x VPOS: %x HPOS: %x\n", DMACONR(), - (unsigned int)intena, (unsigned int)intreq, (unsigned int)vpos, (unsigned int)current_hpos()); - fprintf (stderr, "COP1LC: %08lx, COP2LC: %08lx\n", (unsigned long)cop1lc, (unsigned long)cop2lc); + write_log ("DMACON: %x INTENA: %x INTREQ: %x VPOS: %x HPOS: %x\n", DMACONR(), + (unsigned int)intena, (unsigned int)intreq, (unsigned int)vpos, (unsigned int)current_hpos()); + write_log ("COP1LC: %08lx, COP2LC: %08lx\n", (unsigned long)cop1lc, (unsigned long)cop2lc); if (timeframes) { - fprintf (stderr, "Average frame time: %d ms [frames: %d time: %d]\n", - frametime/timeframes, timeframes, frametime); + write_log ("Average frame time: %d ms [frames: %d time: %d]\n", + frametime / timeframes, timeframes, frametime); + if (total_skipped) + write_log ("Skipped frames: %d\n", total_skipped); } dump_audio_bench (); /*for (i=0; i<256; i++) if (blitcount[i]) fprintf (stderr, "minterm %x = %d\n",i,blitcount[i]); blitter debug */ @@ -3002,6 +3039,10 @@ void REGPARAM2 custom_wput_1 (int hpos, case 0x0F2: BPLPTL (hpos, value, 4); break; case 0x0F4: BPLPTH (hpos, value, 5); break; case 0x0F6: BPLPTL (hpos, value, 5); break; + case 0x0F8: BPLPTH (hpos, value, 6); break; + case 0x0FA: BPLPTL (hpos, value, 6); break; + case 0x0FC: BPLPTH (hpos, value, 7); break; + case 0x0FE: BPLPTL (hpos, value, 7); break; case 0x100: BPLCON0 (hpos, value); break; case 0x102: BPLCON1 (hpos, value); break; @@ -3017,6 +3058,8 @@ void REGPARAM2 custom_wput_1 (int hpos, case 0x116: BPL4DAT (value); break; case 0x118: BPL5DAT (value); break; case 0x11A: BPL6DAT (value); break; + case 0x11C: BPL7DAT (value); break; + case 0x11E: BPL8DAT (value); break; case 0x180: case 0x182: case 0x184: case 0x186: case 0x188: case 0x18A: case 0x18C: case 0x18E: case 0x190: case 0x192: case 0x194: case 0x196: