Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
snesrev committed Jul 15, 2023
1 parent de17193 commit b3ae9a9
Show file tree
Hide file tree
Showing 38 changed files with 8,353 additions and 8,821 deletions.
10 changes: 5 additions & 5 deletions smb1/smb1_00.c
Original file line number Diff line number Diff line change
Expand Up @@ -1623,17 +1623,17 @@ void UploadStripeImage() {
WriteReg(A1B1, 0);
R6_ = 0;
v0 = 0;
for (i = *IndirPtr(&R0_, 0); i >= 0; i = *IndirPtr(&R0_, v0)) {
for (i = *IndirPtr((LongPtr *)&R0_, 0); i >= 0; i = *IndirPtr((LongPtr *)&R0_, v0)) {
R4_ = i;
v2 = v0 + 1;
R3_ = *IndirPtr(&R0_, v2++);
v3 = *IndirPtr(&R0_, v2) & 0x80;
R3_ = *IndirPtr((LongPtr *)&R0_, v2++);
v3 = *IndirPtr((LongPtr *)&R0_, v2) & 0x80;
R7_ = 4 * v3 + __CFSHL__(v3, 1);
R5_ = *IndirPtr(&R0_, v2) & 0x40;
R5_ = *IndirPtr((LongPtr *)&R0_, v2) & 0x40;
WriteReg(DMAP1, (R5_ >> 3) | 1);
WriteReg(BBAD1, 0x18u);
WriteRegWord(VMADDL, *(uint16 *)&R3_);
v4 = IndirPtr(&R0_, v2);
v4 = IndirPtr((LongPtr *)&R0_, v2);
LOBYTE(v5) = HIBYTE(*(uint16 *)v4);
HIBYTE(v5) = *(uint16 *)v4;
v6 = (v5 & 0x3FFF) + 1;
Expand Down
12 changes: 6 additions & 6 deletions smb1/smb1_01.c
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ void SpawnCastleTilesWithPriority() {
v0 = *(uint16 *)&vram_buffer1_offset;
v1 = 0;
do {
v2 = IndirPtr(&tempF3, v1);
v2 = IndirPtr((LongPtr *)&tempF3, v1);
v3 = *(uint16 *)v2;
*(uint16 *)&vram_buffer1[v0 + 1] = *(uint16 *)v2;
v1 += 2;
Expand Down Expand Up @@ -765,7 +765,7 @@ void DecodeAreaData_Sub2_New(uint16 j) {
tempF3 = area_data_ptr.addr;
tempF4 = area_data_ptr.addr >> 8;
tempF5 = area_data_ptr.bank;
v1 = *IndirPtr(&tempF3, (j + 2)) & 0x7F;
v1 = *IndirPtr((LongPtr *)&tempF3, (j + 2)) & 0x7F;
R0_ = *((uint8 *)kDATA_048E43 + v1);
R1_ = *((uint8 *)kDATA_048E43 + v1 + 1);
v2 = object_index;
Expand Down Expand Up @@ -1014,8 +1014,8 @@ uint8 CODE_0491C0(uint8 k) {
uint16 v1; // di

v1 = area_obj_offset_buffer[(uint16)(2 * k) >> 1] + 1;
R7_ = *IndirPtr(&tempF3, v1) >> 4;
return *IndirPtr(&tempF3, v1) & 0xF;
R7_ = *IndirPtr((LongPtr *)&tempF3, v1) >> 4;
return *IndirPtr((LongPtr *)&tempF3, v1) & 0xF;
}

uint8 CODE_0491DD() {
Expand Down Expand Up @@ -1385,7 +1385,7 @@ PairU16 CODE_049724(uint8 k, uint8 j) {
*(uint16 *)&R4_ = 1;
*(uint16 *)&R0_ = 16;
do {
palette_mirror[k >> 1] = *(uint16 *)IndirPtr(&R2_, j);
palette_mirror[k >> 1] = *(uint16 *)IndirPtr((LongPtr *)&R2_, j);
j += 2;
k += 2;
--*(uint16 *)&R0_;
Expand Down Expand Up @@ -1429,7 +1429,7 @@ void CODE_04973C() {
tempF7 = *((uint8 *)kDATA_04B683 + (uint16)(*(uint16 *)&tempF8 + 1)) & 0x3F;
while (1) {
uint16 t = g_ram[0xf3] | g_ram[0xf4] << 8;
IndirWriteByte(&tempF3, v2, tempF7);
IndirWriteByte((LongPtr *)&tempF3, v2, tempF7);
if (!tempF6 || (v2 & 0xF0) == 0xD0)
break;
LOBYTE(v1) = v2 + 16;
Expand Down
8 changes: 4 additions & 4 deletions smb1/smb1_02.c
Original file line number Diff line number Diff line change
Expand Up @@ -1112,12 +1112,12 @@ void GenerateLayer2Map16() {
v3 = *(uint16 *)&tempE4;
v4 = 8 * (uint8)v2;
v5 = *(uint16 *)&tempE4 >> 1;
layer2_map16_table[v5] = *(uint16 *)IndirPtr(&R0_, v4);
layer2_map16_table[v5] = *(uint16 *)IndirPtr((LongPtr *)&R0_, v4);
v4 += 2;
layer2_map16_table[v5 + 1] = *(uint16 *)IndirPtr(&R0_, v4);
layer2_map16_table[v5 + 1] = *(uint16 *)IndirPtr((LongPtr *)&R0_, v4);
v4 += 2;
layer2_map16_table[v5 + 32] = *(uint16 *)IndirPtr(&R0_, v4);
layer2_map16_table[v5 + 33] = *(uint16 *)IndirPtr(&R0_, v4 + 2);
layer2_map16_table[v5 + 32] = *(uint16 *)IndirPtr((LongPtr *)&R0_, v4);
layer2_map16_table[v5 + 33] = *(uint16 *)IndirPtr((LongPtr *)&R0_, v4 + 2);
v1 = v6 + 1;
if ((v1 & 0xF) == 0) v3 += 64;
v0 = v3 + 4;
Expand Down
8 changes: 4 additions & 4 deletions smb1/smb1_08.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ void HandleSPCUploads_Main() {
LOBYTE(v1) = -52;
while (1) {
v13 = v1;
v9 = IndirPtr(&R0_, v0);
v9 = IndirPtr((LongPtr *)&R0_, v0);
v10 = v0 + 2;
v4 = *(uint16 *)v9;
v11 = *(uint16 *)IndirPtr(&R0_, v10);
v11 = *(uint16 *)IndirPtr((LongPtr *)&R0_, v10);
v12 = v10 + 2;
WriteRegWord(APUI02, v11);
WriteReg(APUI01, v4 != 0);
Expand All @@ -71,14 +71,14 @@ void HandleSPCUploads_Main() {
;
if (Unreachable())
break;
v2 = IndirPtr(&R0_, v12);
v2 = IndirPtr((LongPtr *)&R0_, v12);
v0 = v12 + 1;
HIBYTE(v1) = *v2;
for (LOBYTE(v1) = 0;; LOBYTE(v1) = v1 + 1) {
WriteRegWord(APUI00, v1);
if (!--v4)
break;
v3 = IndirPtr(&R0_, v0++);
v3 = IndirPtr((LongPtr *)&R0_, v0++);
HIBYTE(v1) = *v3;
while ((uint8)v1 != ReadReg(APUI00))
;
Expand Down
4 changes: 4 additions & 0 deletions smb1/smb1_cpu_infra.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ void Smb1RunOneFrameOfGame(void) {
}
}

static void Smb1DrawPpuFrame(void) {

}

const RtlGameInfo kSmb1GameInfo = {
"smb1",
Expand All @@ -164,5 +167,6 @@ const RtlGameInfo kSmb1GameInfo = {
&Smb1CpuInitialize,
&Smb1RunOneFrameOfGame,
&Smb1RunOneFrameOfGame_Emulated,
&Smb1DrawPpuFrame,
&Smb1FixSnapshotForCompare,
};
63 changes: 31 additions & 32 deletions smb1/smb1_spc_player.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ typedef struct SmasSpcPlayer {
SpcPlayer base;
DspRegWriteHistory *reg_write_history;
uint8 new_value_from_snes[4];
uint8 port_to_snes_a[4];
uint8 last_value_from_snes[4];
uint8 var_c;
uint8 last_written_edl; // TODO:persist
Expand Down Expand Up @@ -202,7 +201,7 @@ static const MemMap kChannel_Maps[] = {
};
static const MemMapSized kSpcPlayer_Maps[] = {
{offsetof(SmasSpcPlayer, new_value_from_snes), 0x0, 4},
{offsetof(SmasSpcPlayer, port_to_snes_a), 0x4, 4},
{offsetof(SmasSpcPlayer, base.port_to_snes), 0x4, 4},
{offsetof(SmasSpcPlayer, last_value_from_snes), 0x8, 4},
{offsetof(SmasSpcPlayer, var_c), 0xc, 1},
{offsetof(SmasSpcPlayer, counter_sf0d), 0xd, 1},
Expand Down Expand Up @@ -431,7 +430,7 @@ static void Spc_Loop_Part2(SmasSpcPlayer *p, uint8 ticks) {
ReadPortFromSnes(p, 2);
return;
}
if (p->port_to_snes_a[2]) {
if (p->base.port_to_snes[2]) {
Channel *c = p->channel;
for (p->cur_chan_bit = 1; p->cur_chan_bit != 0; p->cur_chan_bit <<= 1, c++) {
if (HIBYTE(c->pattern_cur_ptr))
Expand Down Expand Up @@ -574,7 +573,7 @@ static void Port2_HandleMusic(SmasSpcPlayer *p) {

if (a == 0) {
handle_cmd_00:
if (p->var_3F8 != 0 || p->port_to_snes_a[2] == 0)
if (p->var_3F8 != 0 || p->base.port_to_snes[2] == 0)
return;
if (p->pause_music_ctr != 0 && --p->pause_music_ctr == 0)
goto HandleCmd_0xf0_PauseMusic;
Expand Down Expand Up @@ -696,7 +695,7 @@ static void Port2_HandleMusic(SmasSpcPlayer *p) {
goto handle_cmd_00;
} else if (a == 0xf0) HandleCmd_0xf0_PauseMusic: {
p->key_OFF = p->is_chan_on ^ 0xff;
p->port_to_snes_a[2] = 0;
p->base.port_to_snes[2] = 0;
p->port_to_snes_b[2] = 0;
p->cur_chan_bit = 0;
} else if (a == 0xf3) {
Expand All @@ -720,10 +719,10 @@ static void Port2_HandleMusic(SmasSpcPlayer *p) {
}
p->pause_music_ctr = 0;
p->some_volume_flag = 0;
p->port_to_snes_a[2] = a;
p->base.port_to_snes[2] = a;
t = WORD(p->ram[0xc000 + (a - 1) * 2]);
if ((t >> 8) == 0) {
p->port_to_snes_a[2] = 0;
p->base.port_to_snes[2] = 0;
return;
}
p->music_ptr_toplevel = t;
Expand Down Expand Up @@ -925,14 +924,14 @@ static void SmasSpcPlayer_Upload(SpcPlayer *p_in, const uint8_t *data) {
} while (--numbytes);
}
p->pause_music_ctr = 0;
p->port_to_snes_a[0] = 0;
p->port_to_snes_a[1] = 0;
p->port_to_snes_a[3] = 0;
p->base.port_to_snes[0] = 0;
p->base.port_to_snes[1] = 0;
p->base.port_to_snes[3] = 0;
p->enable_some_randomstuff = 0;
p->is_chan_on = 0;
p->extra_tempo = 0;
if (!p->var_3F8)
p->port_to_snes_a[2] = 0;
p->base.port_to_snes[2] = 0;
memset(p->base.input_ports, 0, sizeof(p->base.input_ports));
memset(p->last_value_from_snes, 0, sizeof(p->last_value_from_snes));
memset(p->new_value_from_snes, 0, sizeof(p->new_value_from_snes));
Expand Down Expand Up @@ -1131,11 +1130,11 @@ static void HandleEffect(SmasSpcPlayer *p, Channel *c, uint8 effect) {
}

static void Sfx_TerminateSfx4(SmasSpcPlayer *p) {
if (p->port_to_snes_a[0] == 17) {
if (p->base.port_to_snes[0] == 17) {
p->var_3F8 = 0xff;
Dsp_Write(p, KOF, 0xff);
}
p->port_to_snes_a[0] = 0;
p->base.port_to_snes[0] = 0;
p->port_to_snes_b[0] = 0;
p->is_chan_on &= ~0x10;
if (p->echo_channels & 0x10) {
Expand All @@ -1158,7 +1157,7 @@ static void Port0_HandleCmd(SmasSpcPlayer *p) {
}
if (p->new_value_from_snes[0] == 0x43 || p->new_value_from_snes[0] == 0x12 ||
p->new_value_from_snes[0] == 0x11 ||
p->port_to_snes_a[0] != 0x11 && p->port_to_snes_a[0] != 0x1d) {
p->base.port_to_snes[0] != 0x11 && p->base.port_to_snes[0] != 0x1d) {

if (p->new_value_from_snes[0] == 0x7f) {
p->extra_tempo = 10;
Expand All @@ -1172,13 +1171,13 @@ static void Port0_HandleCmd(SmasSpcPlayer *p) {
}
if (p->var_c)
goto label_b;
if (!p->port_to_snes_a[0])
if (!p->base.port_to_snes[0])
return;
goto label_c;

label_a:
p->port_to_snes_a[0] = cmd;
if (p->var_3F8 && p->port_to_snes_a[0] == 18)
p->base.port_to_snes[0] = cmd;
if (p->var_3F8 && p->base.port_to_snes[0] == 18)
p->var_3F8 = 0;
p->var_c = 2;
Dsp_Write(p, KOF, 0x10);
Expand All @@ -1188,7 +1187,7 @@ static void Port0_HandleCmd(SmasSpcPlayer *p) {
p->channel[4].pitch_slide_length = 0;
p->channel[4].fine_tunea = 0;
p->channel[4].channel_transpositionb = 0;
if (p->port_to_snes_a[0] == 0x3b || p->port_to_snes_a[0] == 0x43) {
if (p->base.port_to_snes[0] == 0x3b || p->base.port_to_snes[0] == 0x43) {
p->reg_EON &= ~0x10;
Dsp_Write(p, EON, p->reg_EON);
}
Expand Down Expand Up @@ -1251,7 +1250,7 @@ static void Port0_HandleCmd(SmasSpcPlayer *p) {
goto note_continue;
} else if (cmd == 0xff) {
is_ff:
p->sfx_sound_ptr_cur = WORD(p->ram[0x17D8 + (p->port_to_snes_a[0] - 1) * 2]);
p->sfx_sound_ptr_cur = WORD(p->ram[0x17D8 + (p->base.port_to_snes[0] - 1) * 2]);
} else {
PlayNote(p, &p->channel[4], cmd);
Write_KeyOn(p, 0x10);
Expand All @@ -1273,7 +1272,7 @@ static void Port0_HandleCmd(SmasSpcPlayer *p) {
}

static void Sfx_TerminateSfx6(SmasSpcPlayer *p) {
p->port_to_snes_a[3] = 0;
p->base.port_to_snes[3] = 0;
p->port_to_snes_b[3] = 0;
p->is_chan_on &= ~0x40;
p->reg_NON = 0;
Expand All @@ -1293,18 +1292,18 @@ static void Port3_HandleCmd(SmasSpcPlayer *p) {
p->new_value_from_snes[3] &= 0x7f;
}

if (p->port_to_snes_a[3] == 29 ||
(p->new_value_from_snes[3] != 5 && p->port_to_snes_a[3] == 5) ||
if (p->base.port_to_snes[3] == 29 ||
(p->new_value_from_snes[3] != 5 && p->base.port_to_snes[3] == 5) ||
p->new_value_from_snes[3] == 0) {

if (p->port3_timeout)
goto label_b;
if (p->port_to_snes_a[3])
if (p->base.port_to_snes[3])
goto label_c;
return;
}

p->port_to_snes_a[3] = p->new_value_from_snes[3];
p->base.port_to_snes[3] = p->new_value_from_snes[3];
p->port3_timeout = 2;
Dsp_Write(p, KOF, 0x40);
p->is_chan_on |= 0x40;
Expand All @@ -1317,7 +1316,7 @@ static void Port3_HandleCmd(SmasSpcPlayer *p) {
label_b:
if (--p->port3_timeout)
return;
p->port3_cur_ptr = WORD(p->ram[0x173c + (p->port_to_snes_a[3] - 1) * 2]);
p->port3_cur_ptr = WORD(p->ram[0x173c + (p->base.port_to_snes[3] - 1) * 2]);
goto lbl_begin;


Expand Down Expand Up @@ -1490,24 +1489,24 @@ static void Port1_HandleCmd(SmasSpcPlayer *p) {
p->new_value_from_snes[1] &= 0xf;

if (p->new_value_from_snes[1] == 1) {
p->port_to_snes_a[1] = 1;
p->base.port_to_snes[1] = 1;
p->chan7_timer = 4;
Dsp_Write(p, KOF, 0x80);
p->is_chan_on |= 0x80;
p->channel[7].pitch_envelope_num_ticksa = 0;
p->channel[7].pitch_slide_length = 0;
p->channel[7].fine_tunea = 0;
p->channel[7].channel_transpositionb = 0;
} else if (p->port_to_snes_a[1] != 1 && p->new_value_from_snes[1] == 4) {
p->port_to_snes_a[1] = 4;
} else if (p->base.port_to_snes[1] != 1 && p->new_value_from_snes[1] == 4) {
p->base.port_to_snes[1] = 4;
p->chan7_timer = 2;
Dsp_Write(p, KOF, 0x80);
p->is_chan_on |= 0x80;
p->channel[7].pitch_envelope_num_ticksa = 0;
p->channel[7].pitch_slide_length = 0;
p->channel[7].channel_transpositionb = 0;
p->channel[7].fine_tunea = 0;
} else if (p->port_to_snes_a[1] == 1) {
} else if (p->base.port_to_snes[1] == 1) {
if (p->chan7_timer) {
if (--p->chan7_timer)
return;
Expand All @@ -1527,7 +1526,7 @@ static void Port1_HandleCmd(SmasSpcPlayer *p) {
ComputePitchAdd(&p->channel[7], 0xb9);
}
} else {
p->port_to_snes_a[1] = 0;
p->base.port_to_snes[1] = 0;
p->is_chan_on &= ~0x80;
p->channel[7].pitch_slide_length = 0;
p->channel[7].channel_transpositionb = p->channel[7].channel_transpositiona;
Expand All @@ -1545,7 +1544,7 @@ static void Port1_HandleCmd(SmasSpcPlayer *p) {
p->cur_chan_bit = 0;
WritePitch(p, &p->channel[7], p->channel[7].pitch);
}
} else if (p->port_to_snes_a[1] == 4) {
} else if (p->base.port_to_snes[1] == 4) {
Chan7_Func1605(p);
}
}
Expand All @@ -1569,7 +1568,7 @@ static void Chan7_Func1605(SmasSpcPlayer *p) {
Dsp_Write(p, V7VOLR, 20);
Write_KeyOn(p, 0x80);
} else {
p->port_to_snes_a[1] = 0;
p->base.port_to_snes[1] = 0;
p->is_chan_on &= ~0x80;
p->channel[7].pitch_slide_length = 0;
p->channel[7].channel_transpositionb = p->channel[7].channel_transpositiona;
Expand Down
10 changes: 5 additions & 5 deletions smbll/smbll_00.c
Original file line number Diff line number Diff line change
Expand Up @@ -1594,17 +1594,17 @@ void Smbll_UploadStripeImage() {

R6_ = 0;
v0 = 0;
for (i = *IndirPtr(&R0_, 0); i >= 0; i = *IndirPtr(&R0_, v0)) {
for (i = *IndirPtr((LongPtr *)&R0_, 0); i >= 0; i = *IndirPtr((LongPtr *)&R0_, v0)) {
R4_ = i;
v2 = v0 + 1;
R3_ = *IndirPtr(&R0_, v2++);
v3 = *IndirPtr(&R0_, v2) & 0x80;
R3_ = *IndirPtr((LongPtr *)&R0_, v2++);
v3 = *IndirPtr((LongPtr *)&R0_, v2) & 0x80;
R7_ = 4 * v3 + __CFSHL__(v3, 1);
R5_ = *IndirPtr(&R0_, v2) & 0x40;
R5_ = *IndirPtr((LongPtr *)&R0_, v2) & 0x40;
WriteReg(DMAP1, (R5_ >> 3) | 1);
WriteReg(BBAD1, 0x18u);
WriteRegWord(VMADDL, *(uint16 *)&R3_);
v4 = IndirPtr(&R0_, v2);
v4 = IndirPtr((LongPtr *)&R0_, v2);
LOBYTE(v5) = HIBYTE(*(uint16 *)v4);
HIBYTE(v5) = *(uint16 *)v4;
v6 = (v5 & 0x3FFF) + 1;
Expand Down
Loading

0 comments on commit b3ae9a9

Please sign in to comment.