Improved Chipset Vsync to audio

This commit is contained in:
Dimitris Panokostas 2017-01-25 14:44:29 +01:00
parent 1547d5673d
commit 3ee52daf1f
11 changed files with 6191 additions and 6110 deletions

View file

@ -88,10 +88,10 @@ int sound_available = 0;
void(*sample_handler)(void);
static void(*sample_prehandler)(unsigned long best_evtime);
unsigned long scaled_sample_evtime;
float scaled_sample_evtime;
static unsigned long last_cycles;
static unsigned long next_sample_evtime;
static float next_sample_evtime;
typedef uae_s8 sample8_t;
#define DO_CHANNEL_1(v, c) do { (v) *= audio_channel[c].vol; } while (0)

View file

@ -2344,7 +2344,7 @@ static int cfgfile_parse_hardware(struct uae_prefs *p, const TCHAR *option, TCHA
return 1;
if (cfgfile_intval(option, value, _T("cachesize"), &p->cachesize, 1)
|| cfgfile_intval(option, value, _T("chipset_refreshrate"), &p->chipset_refreshrate, 1)
|| cfgfile_doubleval (option, value, _T("chipset_refreshrate"), &p->chipset_refreshrate)
|| cfgfile_intval(option, value, _T("fastmem_size"), &p->fastmem_size, 0x100000)
|| cfgfile_intval(option, value, _T("z3mem_size"), &p->z3fastmem_size, 0x100000)
|| cfgfile_intval(option, value, _T("z3mem_start"), &p->z3fastmem_start, 1)

View file

@ -10,6 +10,7 @@
#include "sysconfig.h"
#include "sysdeps.h"
#include <ctype.h>
#include <assert.h>
@ -40,7 +41,12 @@
#define SPR0_HPOS 0x15
#define MAX_SPRITES 8
#define nocustom() (picasso_on)
STATIC_INLINE bool nocustom(void)
{
if (picasso_on)
return true;
return false;
}
extern int screen_is_picasso;
@ -93,6 +99,7 @@ static uae_u32 last_custom_value1;
static uae_u32 cop1lc,cop2lc,copcon;
int maxhpos = MAXHPOS_PAL;
int maxhpos_short = MAXHPOS_PAL;
int maxvpos = MAXVPOS_PAL;
int maxvpos_nom = MAXVPOS_PAL; // nominal value (same as maxvpos but "faked" maxvpos in fake 60hz modes)
int maxvpos_display = MAXVPOS_PAL; // value used for display size
@ -100,7 +107,8 @@ static int maxvpos_total = 511;
int minfirstline = VBLANK_ENDLINE_PAL;
static int equ_vblank_endline = EQU_ENDLINE_PAL;
static bool equ_vblank_toggle = true;
int vblank_hz = VBLANK_HZ_PAL;
double vblank_hz = VBLANK_HZ_PAL, fake_vblank_hz, vblank_hz_stored, vblank_hz_nom;
static int vblank_hz_mult, vblank_hz_state;
int syncbase;
static int fmode;
static uae_u16 beamcon0;
@ -650,6 +658,18 @@ STATIC_INLINE void update_denise (int hpos)
}
}
static int islinetoggle(void)
{
int linetoggle = 0;
if (!(beamcon0 & 0x0800) && !(beamcon0 & 0x0020) && (currprefs.chipset_mask & CSMASK_ECS_AGNUS)) {
linetoggle = 1; // NTSC and !LOLDIS -> LOL toggles every line
}
else if (!(currprefs.chipset_mask & CSMASK_ECS_AGNUS) && currprefs.ntscmode) {
linetoggle = 1; // hardwired NTSC Agnus
}
return linetoggle;
}
/* Expand bplcon0/bplcon1 into the toscr_xxx variables. */
STATIC_INLINE void compute_toscr_delay_1 (int bplcon1)
{
@ -680,44 +700,44 @@ static bool shres_warned = false;
#endif
/* set currently active Agnus bitplane DMA sequence */
static void setup_fmodes (int hpos)
static void setup_fmodes(int hpos)
{
switch (fmode & 3)
{
case 0:
fetchmode = 0;
delaymask = 15; // (16 << fetchmode) - 1;
break;
case 1:
case 2:
fetchmode = 1;
delaymask = 31; // (16 << fetchmode) - 1;
break;
case 3:
fetchmode = 2;
delaymask = 63; // (16 << fetchmode) - 1;
break;
}
bplcon0_res = GET_RES_AGNUS (bplcon0);
if(bplcon0_res == RES_SUPERHIRES) {
switch (fmode & 3)
{
case 0:
fetchmode = 0;
delaymask = 15; // (16 << fetchmode) - 1;
break;
case 1:
case 2:
fetchmode = 1;
delaymask = 31; // (16 << fetchmode) - 1;
break;
case 3:
fetchmode = 2;
delaymask = 63; // (16 << fetchmode) - 1;
break;
}
bplcon0_res = GET_RES_AGNUS(bplcon0);
if (bplcon0_res == RES_SUPERHIRES) {
#ifdef WITH_INGAME_WARNING
if(!shres_warned) {
InGameMessage("Superhires resolution requested.\nNot supported in UAE4ARM.");
shres_warned = true;
}
if (!shres_warned) {
InGameMessage("Superhires resolution requested.\nNot supported in UAE4ARM.");
shres_warned = true;
}
#endif
bplcon0_res == RES_LORES;
}
bplcon0_planes = GET_PLANES (bplcon0);
bplcon0_planes_limit = GET_PLANES_LIMIT ();
fetchunit = fetchunits[fetchmode * 4 + bplcon0_res];
fetchunit_mask = fetchunit - 1;
int fetchstart_shift = fetchstarts[fetchmode * 4 + bplcon0_res];
fetchstart = 1 << fetchstart_shift;
fetchstart_mask = fetchstart - 1;
int fm_maxplane_shift = fm_maxplanes[fetchmode * 4 + bplcon0_res];
fm_maxplane = 1 << fm_maxplane_shift;
fetch_modulo_cycle = fetchunit - fetchstart;
bplcon0_res == RES_LORES;
}
bplcon0_planes = GET_PLANES(bplcon0);
bplcon0_planes_limit = GET_PLANES_LIMIT();
fetchunit = fetchunits[fetchmode * 4 + bplcon0_res];
fetchunit_mask = fetchunit - 1;
int fetchstart_shift = fetchstarts[fetchmode * 4 + bplcon0_res];
fetchstart = 1 << fetchstart_shift;
fetchstart_mask = fetchstart - 1;
int fm_maxplane_shift = fm_maxplanes[fetchmode * 4 + bplcon0_res];
fm_maxplane = 1 << fm_maxplane_shift;
fetch_modulo_cycle = fetchunit - fetchstart;
if (thisline_decision.plfleft < 0) {
thisline_decision.bplres = bplcon0_res;
@ -725,8 +745,8 @@ static void setup_fmodes (int hpos)
thisline_decision.nr_planes = bplcon0_planes;
}
curr_diagram = cycle_diagram_table[fetchmode][bplcon0_res][bplcon0_planes_limit];
estimate_last_fetch_cycle (hpos);
curr_diagram = cycle_diagram_table[fetchmode][bplcon0_res][bplcon0_planes_limit];
estimate_last_fetch_cycle(hpos);
bpldmasetuphpos = -1;
bpldmasetupphase = 0;
line_cyclebased = vpos;
@ -2374,29 +2394,53 @@ static void reset_decisions (void)
thisline_decision.bplcon4 = bplcon4;
}
int vsynctimebase_orig;
void compute_vsynctime (void)
{
vblank_hz = currprefs.chipset_refreshrate;
vsynctimebase = (int)(syncbase / vblank_hz);
if (screen_is_picasso) {
beamcon0 = new_beamcon0 = currprefs.ntscmode ? 0x00 : 0x20;
}
if (currprefs.produce_sound > 1) {
float svpos = maxvpos_nom;
float shpos = maxhpos;
if (currprefs.ntscmode) {
fake_vblank_hz = 0;
vblank_hz_mult = 0;
vblank_hz_state = 1;
if (fabs(currprefs.chipset_refreshrate) > 0.1) {
vblank_hz = currprefs.chipset_refreshrate;
if (isvsync_chipset()) {
int mult = 0;
if (getvsyncrate(vblank_hz, &mult) != vblank_hz) {
vblank_hz = getvsyncrate(vblank_hz, &vblank_hz_mult);
if (vblank_hz_mult > 0)
vblank_hz_state = 0;
}
}
}
if (!fake_vblank_hz)
fake_vblank_hz = vblank_hz;
// if (currprefs.turbo_emulation)
// vsynctimebase = vsynctimebase_orig = 1;
// else
vsynctimebase = vsynctimebase_orig = (int)(syncbase / fake_vblank_hz);
#if 0
if (!picasso_on) {
updatedisplayarea();
}
#endif
if (currprefs.produce_sound > 1) {
double svpos = maxvpos_nom;
double shpos = maxhpos_short;
if (islinetoggle()) {
shpos += 0.5;
}
// if (interlace_seen) {
if ((bplcon0 & 4)) {
svpos += 0.5;
} else if (lof_current) {
}
else if (lof_current) {
svpos += 1.0;
}
float clk = svpos * shpos * vblank_hz;
update_sound (clk);
}
double clk = svpos * shpos * fake_vblank_hz;
//write_log (_T("SNDRATE %.1f*%.1f*%.6f=%.6f\n"), svpos, shpos, fake_vblank_hz, clk);
update_sound(clk);
}
}
int current_maxvpos (void)
@ -2409,7 +2453,7 @@ static void compute_framesync (void)
int v;
if (!picasso_on && !picasso_requested_on) {
if (abs (vblank_hz - 50) < 1 || abs (vblank_hz - 60) < 1) {
if (fabs (vblank_hz - 50) < 1 || fabs (vblank_hz - 60) < 1) {
vsync_switchmode (vblank_hz);
}
v = (vblank_hz >= 55) ? 60 : 50;
@ -2468,8 +2512,6 @@ static void init_hz (bool fullinit)
equ_vblank_endline = EQU_ENDLINE_NTSC;
equ_vblank_toggle = false;
}
// long/short field refresh rate adjustment
// vblank_hz = vblank_hz * (maxvpos * 2 + 1) / ((maxvpos + lof_current) * 2);
maxvpos_nom = maxvpos;
maxvpos_display = maxvpos;
@ -2548,6 +2590,7 @@ static void init_hz (bool fullinit)
vblank_hz = 10;
if (vblank_hz > 300)
vblank_hz = 300;
maxhpos_short = maxhpos;
eventtab[ev_hsync].oldcycles = get_cycles();
eventtab[ev_hsync].evtime = get_cycles() + HSYNCTIME;
events_schedule();

View file

@ -2210,3 +2210,25 @@ void drawing_init(void)
reset_drawing();
}
int isvsync_chipset(void)
{
if (picasso_on)
return 0;
return 1;
}
int isvsync_rtg(void)
{
if (!picasso_on)
return 0;
return 1;
}
int isvsync(void)
{
if (picasso_on)
return isvsync_rtg();
else
return isvsync_chipset();
}

View file

@ -13,11 +13,31 @@
#include "rtgmodes.h"
#include "xwin.h"
#define RED 0
double getvsyncrate(double hz, int *mult)
{
// struct apmode *ap = picasso_on ? &currprefs.gfx_apmode[1] : &currprefs.gfx_apmode[0];
if (hz < 0)
return 0;
if (hz > 85) {
*mult = -1;
return hz / 2;
}
if (hz < 35 && hz > 0) {
// if (ap->gfx_interlaced)
// *mult = 0;
// else
*mult = 1;
return hz * 2;
}
*mult = 0;
return hz;
}
#define RED 0
#define GRN 1
#define BLU 2
unsigned int doMask (int p, int bits, int shift)
{
/* p is a value from 0 to 15 (Amiga color value)

View file

@ -30,7 +30,7 @@ extern void update_audio (void);
extern void audio_evhandler (void);
extern void audio_hsync (void);
extern void audio_update_adkmasks (void);
extern void update_sound (float clk);
extern void update_sound (double clk);
extern void led_filter_audio (void);
extern void set_audio(void);
extern int audio_activate(void);

View file

@ -115,10 +115,13 @@ STATIC_INLINE uae_u16 INTREQR (void)
#define EQU_ENDLINE_PAL 8
#define EQU_ENDLINE_NTSC 10
extern int maxhpos;
extern int maxhpos, maxhpos_short;
extern int maxvpos, maxvpos_nom, maxvpos_display;
extern int minfirstline;
extern int vblank_hz;
extern int hsyncstartpos, hsyncendpos;
extern int minfirstline, vblank_endline, numscrlines;
extern double vblank_hz, fake_vblank_hz;
extern int vblank_skip, doublescan;
extern bool programmedmode;
#define DMA_AUD0 0x0001
#define DMA_AUD1 0x0002

View file

@ -12,7 +12,7 @@ extern int sound_available;
extern void (*sample_handler) (void);
/* sample_evtime is in normal Amiga cycles; scaled_sample_evtime is in our
event cycles. */
extern unsigned long scaled_sample_evtime;
extern float scaled_sample_evtime;
/* Determine if we can produce any sound at all. This can be only a guess;
* if unsure, say yes. Any call to init_sound may change the value. */

View file

@ -185,7 +185,7 @@ struct uae_prefs {
int waiting_blits;
unsigned int chipset_mask;
bool ntscmode;
int chipset_refreshrate;
double chipset_refreshrate;
int collision_level;
int leds_on_screen;
int fast_copper;

View file

@ -10,9 +10,12 @@
typedef uae_u32 xcolnr;
typedef int (*allocfunc_type)(int, int, int, xcolnr *);
typedef int(*allocfunc_type)(int, int, int, xcolnr *);
extern xcolnr xcolors[4096];
extern xcolnr xcolors_16[4096];
extern xcolnr xcolors_32[4096];
extern uae_u32 p96_rgbx16[65536];
extern int graphics_setup (void);
extern int graphics_init (bool);
@ -21,21 +24,10 @@ extern void graphics_leave (void);
extern int handle_msgpump (void);
extern void setup_brkhandler (void);
extern bool vsync_switchmode (int);
STATIC_INLINE int isvsync_chipset (void)
{
if (picasso_on)
return 0;
return 1;
}
STATIC_INLINE int isvsync_rtg (void)
{
if (!picasso_on)
return 0;
return 1;
}
extern void flush_screen (void);
extern int isvsync_chipset(void);
extern int isvsync_rtg(void);
extern int isvsync(void);
extern int lockscr (void);
extern void unlockscr (void);
@ -49,6 +41,7 @@ extern unsigned int doMask (int p, int bits, int shift);
extern unsigned int doMask256 (int p, int bits, int shift);
extern void alloc_colors64k (int, int, int, int, int, int, int);
extern void alloc_colors_picasso (int rw, int gw, int bw, int rs, int gs, int bs, int rgbfmt);
extern double getvsyncrate(double hz, int *mult);
extern int max_uae_width, max_uae_height;

View file

@ -71,7 +71,7 @@ void pause_sound(void) {}
void resume_sound(void) {}
void update_sound(float) {}
void update_sound(double) {}
void reset_sound(void) {}
@ -91,12 +91,12 @@ void restart_sound_buffer(void) {}
static int have_sound = 0;
static int lastfreq;
void update_sound(float clk)
void update_sound(double clk)
{
float evtime;
evtime = clk * CYCLE_UNIT / (float)currprefs.sound_freq;
scaled_sample_evtime = (int)evtime;
scaled_sample_evtime = evtime;
}
static int s_oldrate = 0, s_oldbits = 0, s_oldstereo = 0;