From 26d62ef100d60e41bfc001888d789097da77a20f Mon Sep 17 00:00:00 2001 From: Alcaro Date: Sun, 7 Dec 2014 20:44:57 +0100 Subject: Properly fix that aggressive loop opt bug. That kind of overflow is undefined behaviour no matter what you do with it.--- source/apu_blargg.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'source') diff --git a/source/apu_blargg.c b/source/apu_blargg.c index 0a1c334..e06f2b6 100644 --- a/source/apu_blargg.c +++ b/source/apu_blargg.c @@ -1566,7 +1566,7 @@ static void spc_cpu_write_smp_reg_( int data, int time, int addr ) static int const bits_in_int = CHAR_BIT * sizeof (int); -static void spc_cpu_write( int data, int addr, int time ) +static void spc_cpu_write( int data, uint16_t addr, int time ) { int reg; /* RAM */ @@ -1601,17 +1601,9 @@ static void spc_cpu_write( int data, int addr, int time ) reg -= ROM_ADDR - 0xF0; if ( reg >= 0 ) /* 1% in IPL ROM area or address wrapped around */ { - if ( reg < ROM_SIZE ) - { - m.hi_ram [reg] = (uint8_t) data; - if ( m.rom_enabled ) - m.ram.ram[reg + ROM_ADDR] = m.rom [reg]; /* restore overwritten ROM */ - } - else - { - *(&(m.ram.ram[0]) + reg + ROM_ADDR) = CPU_PAD_FILL; /* restore overwritten padding */ - spc_cpu_write( data, addr & 0xFFFF, time ); - } + m.hi_ram [reg] = (uint8_t) data; + if ( m.rom_enabled ) + m.ram.ram[reg + ROM_ADDR] = m.rom [reg]; /* restore overwritten ROM */ } } } @@ -1619,7 +1611,7 @@ static void spc_cpu_write( int data, int addr, int time ) /* CPU read */ -static int spc_cpu_read( int addr, int time ) +static int spc_cpu_read( uint16_t addr, int time ) { int result, reg; @@ -1644,7 +1636,7 @@ static int spc_cpu_read( int addr, int time ) t->counter = 0; } /* Other registers */ - else if ( reg < 0 ) /* 10% */ + else /* 10% */ { int reg_tmp; @@ -1663,8 +1655,6 @@ static int spc_cpu_read( int addr, int time ) } } } - else /* 1% */ - result = spc_cpu_read( reg + (R_T0OUT + 0xF0 - 0x10000), time ); } } -- cgit v1.2.3