Skip to content

Commit

Permalink
more init/reset/staticvars cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
toxieainc committed Oct 3, 2023
1 parent 42fb04b commit 9370d24
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 59 deletions.
23 changes: 12 additions & 11 deletions src/cpuexec.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ static int vblank;
static int current_frame;
static INT32 watchdog_counter;

static int timetrig_spin = 0;
static int timetrig_yield = 0;

static int cycles_running;
static int cycles_stolen;

Expand Down Expand Up @@ -349,13 +352,15 @@ static void cpu_pre_run(void)
/* now reset each CPU */
for (cpunum = 0; cpunum < cpu_gettotalcpu(); cpunum++)
#ifdef PINMAME
if (!(Machine->drv->cpu[cpunum].cpu_flags & CPU_AUDIO_CPU) || Machine->sample_rate != 0)
if (!(Machine->drv->cpu[cpunum].cpu_flags & CPU_AUDIO_CPU) || Machine->sample_rate != 0)
#endif /* PINMAME */
cpunum_reset(cpunum, Machine->drv->cpu[cpunum].reset_param, cpu_irq_callbacks[cpunum]);

/* reset the globals */
cpu_vblankreset();
current_frame = 0;
timetrig_spin = 0;
timetrig_yield = 0;
state_save_dump_registry();
}

Expand Down Expand Up @@ -1466,21 +1471,17 @@ void cpu_yield(void)

void cpu_spinuntil_time(double duration)
{
static int timetrig = 0;

cpu_spinuntil_trigger(TRIGGER_SUSPENDTIME + timetrig);
cpu_triggertime(duration, TRIGGER_SUSPENDTIME + timetrig);
timetrig = (timetrig + 1) & 255;
cpu_spinuntil_trigger(TRIGGER_SUSPENDTIME + timetrig_spin);
cpu_triggertime(duration, TRIGGER_SUSPENDTIME + timetrig_spin);
timetrig_spin = (timetrig_spin + 1) & 255;
}


void cpu_yielduntil_time(double duration)
{
static int timetrig = 0;

cpu_yielduntil_trigger(TRIGGER_YIELDTIME + timetrig);
cpu_triggertime(duration, TRIGGER_YIELDTIME + timetrig);
timetrig = (timetrig + 1) & 255;
cpu_yielduntil_trigger(TRIGGER_YIELDTIME + timetrig_yield);
cpu_triggertime(duration, TRIGGER_YIELDTIME + timetrig_yield);
timetrig_yield = (timetrig_yield + 1) & 255;
}


Expand Down
6 changes: 4 additions & 2 deletions src/sndintrf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1296,16 +1296,18 @@ int sound_start(void)
int totalsound = 0;
int i;

cleared_value = 0x00;

/* Verify the order of entries in the sndintf[] array */
for (i = 0;i < SOUND_COUNT;i++)
{
if (sndintf[i].sound_num != i)
{
int j;
int j;
logerror("Sound #%d wrong ID %d: check enum SOUND_... in src/sndintrf.h!\n",i,sndintf[i].sound_num);
for (j = 0; j < i; j++)
logerror("ID %2d: %s\n", j, sndintf[j].name);
return 1;
return 1;
}
}

Expand Down
36 changes: 20 additions & 16 deletions src/wpc/gpsnd.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static struct SN76477interface gpSS1_sn76477Int = { 1, { 50 }, /* mixing level

static WRITE_HANDLER(gpss1_data_w)
{ // tone frequencies C E A A low
static double voltage[16] = {2.8, 3.3, 0, 0, 0, 4.5, 2.2};
static const double voltage[16] = {2.8, 3.3, 0, 0, 0, 4.5, 2.2};
data &= 0x0f;
if (voltage[data]) {
SN76477_set_vco_voltage(0, voltage[data]);
Expand Down Expand Up @@ -228,20 +228,21 @@ static struct SN76477interface gpSS4_sn76477Int = { 4, { 50, 50, 50, 50 }, /* m


static mame_timer *capTimer = NULL;
static int cap_offset = 1;
static int cap_pin18res = 320;

static void capTimer_timer(int n) {
static int offset = 1;
static int pin18res = 320;
pin18res += offset;
if (pin18res > 419)
offset = -1;
else if (pin18res < 321)
offset = 1;
SN76477_set_vco_res(3, RES_K(pin18res)); /* 18 */
cap_pin18res += cap_offset;
if (cap_pin18res > 419)
cap_offset = -1;
else if (cap_pin18res < 321)
cap_offset = 1;
SN76477_set_vco_res(3, RES_K(cap_pin18res)); /* 18 */
}

static WRITE_HANDLER(gpss4_data_w)
{ // tone frequencies C' B A
static double voltage[16] = {0, 5.4, 4.8, 4.5};
static const double voltage[16] = {0, 5.4, 4.8, 4.5};
data &= 0x0f;
if (data < 0x0f) SN76477_enable_w(1, 1);
switch (data) {
Expand Down Expand Up @@ -329,6 +330,9 @@ static WRITE_HANDLER(gpss4_data_w)

static void gpss4_init(struct sndbrdData *brdData)
{
cap_offset = 1;
cap_pin18res = 320;

if (capTimer) timer_remove(capTimer);
capTimer = timer_alloc(capTimer_timer);
timer_adjust(capTimer, TIME_NEVER, 0, TIME_NEVER);
Expand Down Expand Up @@ -608,17 +612,17 @@ static void m6840_pulse (int param) {

static void gpsm_init(struct sndbrdData *brdData)
{
int mixing_levels[4] = {25,25,25,25};
const int mixing_levels[4] = {25,25,25,25};
int i;
int s = 0;
memset(&gps_locals, 0x00, sizeof(gps_locals));
gps_locals.brdData = *brdData;
for (i = 0;i < 32000;i++) {
s = (s ? 0 : 1);
if (s) {
sineWaveext[i] = rand();
} else
sineWaveext[i] = 0-rand();
s = (s ? 0 : 1);
if (s) {
sineWaveext[i] = rand();
} else
sineWaveext[i] = 0-rand();
}
pia_config(GPS_PIA0, PIA_STANDARD_ORDERING, &gps_pia[0]);
pia_config(GPS_PIA1, PIA_STANDARD_ORDERING, &gps_pia[1]);
Expand Down
7 changes: 4 additions & 3 deletions src/wpc/gts3.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ struct {
int bitSet;
int vblank_counter;
UINT8 irq;

int modsol_rate_counter;
} GTS3locals;

//We need 2 structures, since Strikes N Spares has 2 DMD Displays
Expand Down Expand Up @@ -912,11 +914,10 @@ static INTERRUPT_GEN(alphanmi) {
#ifdef GTS3_MODSOL
if (options.usemodsol)
{
static int modsol_rate_counter = 0; //!! move to GTS3locals
if (++modsol_rate_counter == GTS3_MODSOL_SAMPLE)
if (++GTS3locals.modsol_rate_counter == GTS3_MODSOL_SAMPLE)
{
int i;
modsol_rate_counter = 0;
GTS3locals.modsol_rate_counter = 0;
for (i = 0; i < 32; i++)
{
core_update_modulated_light(&GTS3locals.solenoidbits[i], GTS3locals.solenoid_seen_pulses & (1 << i));
Expand Down
18 changes: 9 additions & 9 deletions src/wpc/gts3dmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ extern GTS3_DMDlocals GTS3_dmdlocals[2];
extern int crtc6845_start_addr;
#endif

//static int level4_a[9] = { 0, 1, 5, 5, 5, 5, 5, 5, 15 }; // mapping for 4 color roms, mode a
//static int level4_b[16] = { 0, 1, 1, 1, 5, 5, 5, 10, 10, 10, 15, 15, 15, 15, 15, 15 }; // mapping for 4 color roms, mode b
//static int level4_a[16] = { 0, 3, 3, 3, 6, 6, 6, 8, 8, 9, 10, 11, 12, 13, 14, 15 };
static int level4_a[7] = { 0, 1, 2, 2, 2, 2, 3 }; // 4 colors
static int level4_a2[7] = { 0, 1, 1, 2, 2, 2, 3 }; // 4 colors
static int level4_b[9] = { 0, 1, 2, 2, 2, 2, 2, 2, 3 }; // 4 colors
static int level5[13] = { 0, 3, 3, 7, 7, 7, 11, 11, 11, 11, 11, 11, 15 }; // 5 colors
//static int level5[19] = { 0, 3, 3, 4, 5, 5, 5, 7, 8, 9, 11, 11, 11, 12, 13, 14, 15, 15, 15 };
//static int level[25] = { 0, 0, 1, 1, 1, 5, 5, 5, 5, 5, 5, 5, 10, 10, 10, 10, 10, 15, 15, 15, 15, 15, 15, 15, 15 }; // temporary mapping for both 4 and 5 color roms // deprecated
//static const int level4_a[9] = { 0, 1, 5, 5, 5, 5, 5, 5, 15 }; // mapping for 4 color roms, mode a
//static const int level4_b[16] = { 0, 1, 1, 1, 5, 5, 5, 10, 10, 10, 15, 15, 15, 15, 15, 15 }; // mapping for 4 color roms, mode b
//static const int level4_a[16] = { 0, 3, 3, 3, 6, 6, 6, 8, 8, 9, 10, 11, 12, 13, 14, 15 };
static const int level4_a[7] = { 0, 1, 2, 2, 2, 2, 3 }; // 4 colors
static const int level4_a2[7] = { 0, 1, 1, 2, 2, 2, 3 }; // 4 colors
static const int level4_b[9] = { 0, 1, 2, 2, 2, 2, 2, 2, 3 }; // 4 colors
static const int level5[13] = { 0, 3, 3, 7, 7, 7, 11, 11, 11, 11, 11, 11, 15 }; // 5 colors
//static const int level5[19] = { 0, 3, 3, 4, 5, 5, 5, 7, 8, 9, 11, 11, 11, 12, 13, 14, 15, 15, 15 };
//static const int level[25] = { 0, 0, 1, 1, 1, 5, 5, 5, 5, 5, 5, 5, 10, 10, 10, 10, 10, 15, 15, 15, 15, 15, 15, 15, 15 }; // temporary mapping for both 4 and 5 color roms // deprecated

#ifdef VPINMAME
extern UINT8 g_raw_gtswpc_dmd[GTS3DMD_FRAMES_5C*0x200];
Expand Down
43 changes: 25 additions & 18 deletions src/wpc/zac.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ static struct {
void *printfile;
mame_timer *irqtimer;
int irqfreq;

// serial
UINT8 read_byte;
UINT8 read_bitno;

UINT8 write_bitno;
UINT8 write_startbit;
} locals;

static INTERRUPT_GEN(ZAC_vblank_old) {
Expand Down Expand Up @@ -191,6 +198,8 @@ static MACHINE_INIT(ZAC1) {
locals.irqtimer = timer_alloc(timer_callback_old);
locals.irqfreq = core_gameData->hw.gameSpecific1;
timer_adjust(locals.irqtimer, 1.0/(double)locals.irqfreq, 0, 1.0/(double)locals.irqfreq);
locals.read_byte = 0xff;
locals.read_bitno = 7;
/* Set IRQ Vector Routine */
cpu_set_irq_callback(0, irq_callback_old);

Expand All @@ -211,6 +220,8 @@ static MACHINE_INIT(ZAC2) {
locals.irqtimer = timer_alloc(timer_callback);
locals.irqfreq = core_gameData->hw.gameSpecific1;
timer_adjust(locals.irqtimer, 1.0/(double)locals.irqfreq, 0, 1.0/(double)locals.irqfreq);
locals.read_byte = 0xff;
locals.read_bitno = 7;
/* Set IRQ Vector Routine */
cpu_set_irq_callback(0, irq_callback);

Expand Down Expand Up @@ -269,14 +280,12 @@ static READ_HANDLER(data_port_r)
*/
static READ_HANDLER(sense_r)
{
static UINT8 byte = 0xff;
static int bitno = 7;
if (++bitno > 7) {
byte++;
bitno = 0;
if (++locals.read_bitno > 7) {
locals.read_byte++;
locals.read_bitno = 0;
// logerror("%x: Sense Input=%02x\n",activecpu_get_previouspc(),byte);
}
return ((byte >> bitno) & 1) | core_getSw(-8);
return ((locals.read_byte >> locals.read_bitno) & 1) | core_getSw(-8);
}

/*
Expand Down Expand Up @@ -313,26 +322,24 @@ static WRITE_HANDLER(data_port_w)
static WRITE_HANDLER(flag_w)
{
static UINT8 printdata = 0;
static int bitno = 0;
static int startbit = 0;
coreGlobals.diagnosticLed = (coreGlobals.diagnosticLed & 0x03) | (data << 2);
if (locals.printfile == NULL) {
char filename[64];
sprintf(filename,"%s.prt", Machine->gamedrv->name);
locals.printfile = mame_fopen(Machine->gamedrv->name,filename,FILETYPE_PRINTER,2); // APPEND write mode
}
if (data && startbit < 1)
startbit = 1;
else if (data == 0 && startbit == 1)
startbit = 2;
else if (bitno < 8 && startbit > 1)
printdata |= (data << bitno++);
if (bitno == 8 && startbit > 1)
if (data && locals.write_startbit < 1)
locals.write_startbit = 1;
else if (data == 0 && locals.write_startbit == 1)
locals.write_startbit = 2;
else if (locals.write_bitno < 8 && locals.write_startbit > 1)
printdata |= (data << locals.write_bitno++);
if (locals.write_bitno == 8 && locals.write_startbit > 1)
if (locals.printfile) mame_fwrite(locals.printfile, &printdata, 1);
if (bitno > 7) {
if (locals.write_bitno > 7) {
printdata = 0;
bitno = 0;
startbit = 0;
locals.write_bitno = 0;
locals.write_startbit = 0;
}
// logerror("%x: Flag output=%x\n",activecpu_get_previouspc(),data);
}
Expand Down

0 comments on commit 9370d24

Please sign in to comment.