--- uae/src/custom.c 2018/04/24 16:42:15 1.1.1.4 +++ uae/src/custom.c 2018/04/24 16:47:31 1.1.1.7 @@ -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 */ @@ -71,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; @@ -80,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. */ @@ -89,8 +102,12 @@ 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 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; static uaecptr bplpt[8]; #ifndef SMART_UPDATE @@ -100,16 +117,14 @@ 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; 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 uae_u16 dsklen, dsksync; static int dsklength; /* The display and data fetch windows */ @@ -119,8 +134,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 +172,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; @@ -187,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; @@ -202,14 +217,15 @@ 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; -char line_changed[2 * (maxvpos+1)]; #ifdef SMART_UPDATE -#define MARK_LINE_CHANGED(l) do { line_changed[l] = 1; } while (0) +#define MARK_LINE_CHANGED do { thisline_changed = 1; } while (0) #else -#define MARK_LINE_CHANGED(l) do { } while (0) +#define MARK_LINE_CHANGED do { ; } while (0) #endif static struct decision thisline_decision; @@ -250,10 +266,12 @@ 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.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; @@ -263,11 +281,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) @@ -286,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; @@ -305,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); } @@ -341,13 +358,11 @@ static void remember_ctable (void) color_src_match = oldctable; color_dest_match = remembered_color_entry; } - if (changed) { - line_changed[next_lineno] = 1; - } + thisline_changed |= changed; } else { /* We know the result of the comparison */ if (color_compare_result) - line_changed[next_lineno] = 1; + thisline_changed = 1; } } @@ -370,7 +385,7 @@ static void decide_diw (int hpos) * some programs change them after DDF start but before DIW start. */ thisline_decision.bplcon1 = bplcon1; if (thisline_decision.diwfirstword != line_decisions[next_lineno].diwfirstword) - MARK_LINE_CHANGED (next_lineno); + MARK_LINE_CHANGED; thisline_decision.diwlastword = -1; } if (hdiwstate == DIW_waiting_stop && thisline_decision.diwlastword == -1 @@ -379,7 +394,7 @@ static void decide_diw (int hpos) thisline_decision.diwlastword = diwlastword; hdiwstate = DIW_waiting_start; if (thisline_decision.diwlastword != line_decisions[next_lineno].diwlastword) - MARK_LINE_CHANGED (next_lineno); + MARK_LINE_CHANGED; } } @@ -414,7 +429,7 @@ static __inline__ void decide_as_playfie #endif ) #endif /* SMART_UPDATE */ - line_changed[next_lineno] = 1; + thisline_changed = 1; } /* Called when we already decided whether the line is playfield or border, @@ -449,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; @@ -459,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 */ @@ -481,11 +501,20 @@ static void adjust_broken_program (int h } } +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 - && ((bplcon0 & 0x7000) == 0 || !dmaen (DMA_BITPLANE))) + && (GET_PLANES (bplcon0) == 0 || !dmaen (DMA_BITPLANE))) { /* This is getting gross... */ thisline_decision.plflinelen = hpos - thisline_decision.plfstrt; @@ -498,7 +527,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; @@ -507,13 +536,13 @@ 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 &= 0xFFF; - thisline_decision.bplcon0 |= bplcon0 & 0xF000; + thisline_decision.bplcon0 &= 0xFEF; + thisline_decision.bplcon0 |= bplcon0 & 0xF010; adjust_broken_program (hpos); - MARK_LINE_CHANGED (next_lineno); /* Play safe. */ + MARK_LINE_CHANGED; /* Play safe. */ return; } @@ -532,10 +561,10 @@ 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 (next_lineno); /* Play safe. */ + MARK_LINE_CHANGED; /* Play safe. */ decide_as_playfield (plfstrt, plflinelen); adjust_broken_program (hpos); } @@ -566,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; @@ -642,7 +671,7 @@ static void record_color_change (int hpo if (regno == 0 && thisline_decision.color0 == 0xFFFFFFFFul && thisline_decision.diwfirstword < 0) { thisline_decision.color0 = current_colors.color_regs[0]; if (line_decisions[next_lineno].color0 != value) - line_changed[next_lineno] = 1; + thisline_changed = 1; } /* Anything else gets recorded in the color_changes table. */ #ifdef OS_WITHOUT_MEMORY_MANAGEMENT @@ -708,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) { @@ -726,11 +756,11 @@ static void decide_plane (int hpos) real_ptr = pfield_xlateptr(0, 0); #ifdef SMART_UPDATE #if 1 - if (line_changed[next_lineno]) + if (thisline_changed) memcpy (dataptr, real_ptr, bytecount); else #endif - line_changed[next_lineno] |= memcmpy (dataptr, real_ptr, bytecount); + thisline_changed |= memcmpy (dataptr, real_ptr, bytecount); #else real_bplpt[i] = real_ptr; #endif @@ -746,8 +776,8 @@ static void decide_plane (int hpos) if (real_ptr == NULL) real_ptr = pfield_xlateptr(0, 0); #ifdef SMART_UPDATE - if (!line_changed[next_lineno]) - line_changed[next_lineno] |= memcmpy (dataptr, real_ptr, bytecount); + if (!thisline_changed) + thisline_changed |= memcmpy (dataptr, real_ptr, bytecount); else memcpy (dataptr, real_ptr, bytecount); #else @@ -786,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; @@ -827,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) @@ -852,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++; @@ -859,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) @@ -924,17 +954,17 @@ static void finish_decisions (void) if (hdiwstate == DIW_waiting_stop) { thisline_decision.diwlastword = max_diwlastword; if (thisline_decision.diwlastword != line_decisions[next_lineno].diwlastword) - MARK_LINE_CHANGED (next_lineno); + MARK_LINE_CHANGED; } if (line_decisions[next_lineno].which != thisline_decision.which) - line_changed[next_lineno] = 1; + thisline_changed = 1; decide_plane (hpos); dip = curr_drawinfo + next_lineno; dip_old = prev_drawinfo + next_lineno; dp = line_decisions + next_lineno; - changed = line_changed[next_lineno]; + changed = thisline_changed; if (thisline_decision.which == 1) { record_diw_line (diwfirstword, diwlastword); @@ -979,7 +1009,7 @@ static void finish_decisions (void) changed = 1; if (changed) { - line_changed[next_lineno] = 1; + thisline_changed = 1; *dp = thisline_decision; } else /* The only one that may differ: */ @@ -996,18 +1026,18 @@ 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) { thisline_decision.diwfirstword = PIXEL_XPOS (DISPLAY_LEFT_SHIFT/2); if (thisline_decision.diwfirstword != line_decisions[next_lineno].diwfirstword) - MARK_LINE_CHANGED (next_lineno); + MARK_LINE_CHANGED; } thisline_decision.ctable = -1; thisline_decision.color0 = 0xFFFFFFFFul; - line_changed[next_lineno] = 0; + thisline_changed = 0; curr_drawinfo[next_lineno].first_color_change = next_color_change; curr_drawinfo[next_lineno].first_delay_change = next_delay_change; curr_drawinfo[next_lineno].first_sprite_draw = next_sprite_draw; @@ -1029,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; @@ -1076,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) @@ -1141,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; @@ -1259,10 +1377,37 @@ 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 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) @@ -1282,13 +1427,10 @@ static __inline__ uae_u16 ADKCONR (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) { @@ -1398,6 +1540,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; } } @@ -1437,6 +1580,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); @@ -1454,22 +1602,29 @@ 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 = (bplcon0 >> 12) & 7; - corrected_nr_planes_from_bplcon0 = ((bplcon0 >> 12) & 7) << (bplcon0 & 0x8000 ? 1 : 0); + nr_planes_from_bplcon0 = GET_PLANES (v); + + 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) @@ -1482,20 +1637,25 @@ static __inline__ void BPLCON1 (int hpos } 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) { - if (bplcon3 != v) - decide_line (hpos); + if (bplcon3 == v) + return; + decide_line (hpos); bplcon3 = 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; } @@ -1524,6 +1684,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) { @@ -1547,6 +1709,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); @@ -1557,7 +1721,7 @@ static void DIWHIGH (int hpos, uae_u16 v static void DDFSTRT (int hpos, uae_u16 v) { - v &= 0xFF; + v &= (currprefs.chipset_mask & CSMASK_AGA) ? 0x1FC : 0xFC; if (ddfstrt == v) return; decide_line (hpos); @@ -1566,7 +1730,7 @@ static void DDFSTRT (int hpos, uae_u16 v } static void DDFSTOP (int hpos, uae_u16 v) { - v &= 0xFF; + v &= (currprefs.chipset_mask & CSMASK_AGA) ? 0x1FC : 0xFC; if (ddfstop == v) return; decide_line (hpos); @@ -1574,6 +1738,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(); @@ -1605,7 +1777,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; } @@ -1637,19 +1814,23 @@ 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; if (!blt_info.vblitsize) blt_info.vblitsize = 32768; if (!blt_info.hblitsize) blt_info.hblitsize = 0x800; bltstate = BLT_init; - do_blitter(); + do_blitter (); } static __inline__ void SPRxCTL_1 (uae_u16 v, int num) @@ -1738,9 +1919,9 @@ static void COLOR (int hpos, uae_u16 v, r = (v & 0xF00) >> 8; g = (v & 0xF0) >> 4; b = (v & 0xF) >> 0; - cr = color_regs[colreg] >> 16; - cg = (color_regs[colreg] >> 8) & 0xFF; - cb = color_regs[colreg] & 0xFF; + cr = current_colors.color_regs[colreg] >> 16; + cg = (current_colors.color_regs[colreg] >> 8) & 0xFF; + cb = current_colors.color_regs[colreg] & 0xFF; if (bplcon3 & 0x200) { cr &= 0xF0; cr |= r; @@ -1752,10 +1933,14 @@ static void COLOR (int hpos, uae_u16 v, cb = b + (b << 4); } cval = (cr << 16) | (cg << 8) | cb; - if (cval == color_regs[colreg]) + if (cval == current_colors.color_regs[colreg]) return; - color_regs[colreg] = cval; - pfield_may_need_update(1); + + /* Call this with the old table still intact. */ + record_color_change (hpos, colreg, v); + remembered_color_entry = -1; + current_colors.color_regs[colreg] = cval; +/* current_colors.acolors[colreg] = xcolors[v];*/ } #else { @@ -1840,18 +2025,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; } @@ -1862,7 +2047,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]) @@ -1873,7 +2058,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); } @@ -1881,7 +2066,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); } @@ -1889,7 +2074,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; } @@ -1938,6 +2123,10 @@ static __inline__ int copper_cant_read ( if (hpos >= ((maxhpos - 2) & ~1)) return 1; + if (currprefs.chipset_mask & CSMASK_AGA) + /* FIXME */ + return 0; + if (! copper_in_playfield (diw, hpos)) return 0; @@ -1992,7 +2181,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 ? ((currprefs.chipset_mask & CSMASK_AGA) ? 0 : 0x40u) : 0x80u)) { cop_state.state = COP_stop; break; } @@ -2184,11 +2373,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 ? ((currprefs.chipset_mask & CSMASK_AGA) ? 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; @@ -2567,6 +2756,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; @@ -2589,8 +2783,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; @@ -2598,6 +2810,8 @@ static void vsync_handler (void) #endif if (ievent_alive > 0) ievent_alive--; + if (timehack_alive > 0) + timehack_alive--; CIA_vsync_handler(); } @@ -2608,7 +2822,7 @@ static void hsync_handler (void) finish_decisions (); do_modulos (current_hpos ()); - hsync_record_line_state (next_lineno, nextline_how); + hsync_record_line_state (next_lineno, nextline_how, thisline_changed); eventtab[ev_hsync].evtime += cycles - eventtab[ev_hsync].oldcycles; eventtab[ev_hsync].oldcycles = cycles; @@ -2656,7 +2870,7 @@ static void hsync_handler (void) nextline_how = nln_normal; if (currprefs.gfx_linedbl) { lineno *= 2; - nextline_how = nln_doubled; + nextline_how = currprefs.gfx_linedbl == 1 ? nln_doubled : nln_nblack; if (bplcon0 & 4) { if (!lof) { lineno++; @@ -2733,6 +2947,7 @@ void customreset (void) mousestate = normal_mouse; } ievent_alive = 0; + timehack_alive = 0; clx_sprmask = 0xFF; clxdat = 0; @@ -2749,11 +2964,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 (); @@ -2772,12 +2990,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 */ @@ -2819,6 +3039,8 @@ static void gen_custom_tables (void) void custom_init (void) { + uaecptr pos; + #ifdef OS_WITHOUT_MEMORY_MANAGEMENT int num; @@ -2829,6 +3051,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 (); @@ -2877,11 +3111,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; @@ -2999,6 +3229,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; @@ -3014,6 +3248,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: @@ -3049,18 +3285,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; break; -#endif + case 0x1FC: FMODE (value); break; } }