From 92da7c45ef7d2aa42d662558a198229f229089b0 Mon Sep 17 00:00:00 2001 From: Peter Veenstra Date: Mon, 11 Nov 2019 17:23:05 +0000 Subject: [PATCH] Switch to a different way to calculate the table offsets. Thanks jmarsh Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@4282 --- src/hardware/dbopl.cpp | 9 +++------ src/hardware/dbopl.h | 8 ++++---- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/hardware/dbopl.cpp b/src/hardware/dbopl.cpp index acbf2b8f..0a616c40 100644 --- a/src/hardware/dbopl.cpp +++ b/src/hardware/dbopl.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include "dosbox.h" #include "dbopl.h" @@ -1430,7 +1431,6 @@ void InitTables( void ) { TremoloTable[TREMOLO_TABLE - 1 - i] = val; } //Create a table with offsets of the channels from the start of the chip - DBOPL::Chip* chip = 0; for ( Bitu i = 0; i < 32; i++ ) { Bitu index = i & 0xf; if ( index >= 9 ) { @@ -1444,8 +1444,7 @@ void InitTables( void ) { //Add back the bits for highest ones if ( i >= 16 ) index += 9; - Bitu blah = reinterpret_cast( &(chip->chan[ index ]) ); - ChanOffsetTable[i] = blah; + ChanOffsetTable[i] = (Bit16u)(index*sizeof(DBOPL::Channel)); } //Same for operators for ( Bitu i = 0; i < 64; i++ ) { @@ -1458,9 +1457,7 @@ void InitTables( void ) { if ( chNum >= 12 ) chNum += 16 - 12; Bitu opNum = ( i % 8 ) / 3; - DBOPL::Channel* chan = 0; - Bitu blah = reinterpret_cast( &(chan->op[opNum]) ); - OpOffsetTable[i] = ChanOffsetTable[ chNum ] + blah; + OpOffsetTable[i] = ChanOffsetTable[chNum]+(Bit16u)(opNum*sizeof(DBOPL::Operator)); } #if 0 //Stupid checks if table's are correct diff --git a/src/hardware/dbopl.h b/src/hardware/dbopl.h index addaed77..97dc7cac 100644 --- a/src/hardware/dbopl.h +++ b/src/hardware/dbopl.h @@ -156,7 +156,7 @@ public: }; struct Channel { - Operator op[2]; + Operator op[2]; //Leave on top of struct for simpler pointer math. inline Operator* Op( Bitu index ) { return &( ( this + (index >> 1) )->op[ index & 1 ]); } @@ -192,6 +192,9 @@ struct Channel { }; struct Chip { + //18 channels with 2 operators each. Leave on top of struct for simpler pointer math. + Channel chan[18]; + //This is used as the base counter for vibrato and tremolo Bit32u lfoCounter; Bit32u lfoAdd; @@ -208,9 +211,6 @@ struct Chip { //Best match attack rates for the rate of this chip Bit32u attackRates[76]; - //18 channels with 2 operators each - Channel chan[18]; - Bit8u reg104; Bit8u reg08; Bit8u reg04;