Skip to content

Commit be659ed

Browse files
authored
added vram memory access, minor optimizations for volume hacks (#236)
* minor optimization: changed user_volume type to avoid unnecessary casting (#21) * minor refactoring for better performances * added vram memory access --------- Co-authored-by: eadmaster <51NMBsFda0ab1>
1 parent 1524cc6 commit be659ed

File tree

3 files changed

+59
-11
lines changed

3 files changed

+59
-11
lines changed

libretro.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2613,6 +2613,8 @@ void *retro_get_memory_data(unsigned type)
26132613
return (uint8_t*)SaveRAM;
26142614
case RETRO_MEMORY_SYSTEM_RAM:
26152615
return BaseRAM;
2616+
case RETRO_MEMORY_VIDEO_RAM:
2617+
return vdc->VRAM;
26162618
default:
26172619
break;
26182620
}
@@ -2630,6 +2632,8 @@ size_t retro_get_memory_size(unsigned type)
26302632
return 2048;
26312633
case RETRO_MEMORY_SYSTEM_RAM:
26322634
return 8192;
2635+
case RETRO_MEMORY_VIDEO_RAM:
2636+
return 65536;
26332637
default:
26342638
break;
26352639
}

mednafen/pce_fast/psg.cpp

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void PCEFast_PSG::SetVolume(double new_volume)
3131
Blip_Synth_set_volume(&Synth, OutputVolume / 6, 8192);
3232
}
3333

34-
void PCEFast_PSG::SetChannelUserVolume(int chnum, uint8 new_volume)
34+
void PCEFast_PSG::SetChannelUserVolume(int chnum, int32 new_volume)
3535
{
3636
if(chnum >=6 || new_volume > 100) return; // check valid args
3737
psg_channel *ch = &channel[chnum];
@@ -41,13 +41,24 @@ void PCEFast_PSG::SetChannelUserVolume(int chnum, uint8 new_volume)
4141
void PCEFast_PSG::UpdateOutput_Norm(const int32 timestamp, psg_channel *ch)
4242
{
4343
int32 samp[2];
44+
int delta0;
45+
int delta1;
4446
int sv = ch->dda;
4547

4648
samp[0] = dbtable[ch->vl[0]][sv];
4749
samp[1] = dbtable[ch->vl[1]][sv];
4850

49-
Blip_Synth_offset(&Synth, timestamp, (samp[0] - ch->blip_prev_samp[0]) * ch->user_volume / 100, sbuf[0]);
50-
Blip_Synth_offset(&Synth, timestamp, (samp[1] - ch->blip_prev_samp[1]) * ch->user_volume / 100, sbuf[1]);
51+
if(ch->user_volume < 100)
52+
{
53+
delta0 = (samp[0] - ch->blip_prev_samp[0]) * ch->user_volume / 100;
54+
delta1 = (samp[1] - ch->blip_prev_samp[1]) * ch->user_volume / 100;
55+
} else {
56+
delta0 = samp[0] - ch->blip_prev_samp[0];
57+
delta1 = samp[1] - ch->blip_prev_samp[1];
58+
}
59+
60+
Blip_Synth_offset(&Synth, timestamp, delta0, sbuf[0]);
61+
Blip_Synth_offset(&Synth, timestamp, delta1, sbuf[1]);
5162

5263
ch->blip_prev_samp[0] = samp[0];
5364
ch->blip_prev_samp[1] = samp[1];
@@ -56,13 +67,24 @@ void PCEFast_PSG::UpdateOutput_Norm(const int32 timestamp, psg_channel *ch)
5667
void PCEFast_PSG::UpdateOutput_Noise(const int32 timestamp, psg_channel *ch)
5768
{
5869
int32 samp[2];
70+
int delta0;
71+
int delta1;
5972
int sv = ((ch->lfsr & 1) << 5) - (ch->lfsr & 1); //(ch->lfsr & 0x1) ? 0x1F : 0;
6073

6174
samp[0] = dbtable[ch->vl[0]][sv];
6275
samp[1] = dbtable[ch->vl[1]][sv];
6376

64-
Blip_Synth_offset(&Synth, timestamp, (samp[0] - ch->blip_prev_samp[0]) * ch->user_volume / 100, sbuf[0]);
65-
Blip_Synth_offset(&Synth, timestamp, (samp[1] - ch->blip_prev_samp[1]) * ch->user_volume / 100, sbuf[1]);
77+
if(ch->user_volume < 100)
78+
{
79+
delta0 = (samp[0] - ch->blip_prev_samp[0]) * ch->user_volume / 100;
80+
delta1 = (samp[1] - ch->blip_prev_samp[1]) * ch->user_volume / 100;
81+
} else {
82+
delta0 = samp[0] - ch->blip_prev_samp[0];
83+
delta1 = samp[1] - ch->blip_prev_samp[1];
84+
}
85+
86+
Blip_Synth_offset(&Synth, timestamp, delta0, sbuf[0]);
87+
Blip_Synth_offset(&Synth, timestamp, delta1, sbuf[1]);
6688

6789
ch->blip_prev_samp[0] = samp[0];
6890
ch->blip_prev_samp[1] = samp[1];
@@ -71,11 +93,22 @@ void PCEFast_PSG::UpdateOutput_Noise(const int32 timestamp, psg_channel *ch)
7193
void PCEFast_PSG::UpdateOutput_Off(const int32 timestamp, psg_channel *ch)
7294
{
7395
int32 samp[2];
96+
int delta0;
97+
int delta1;
7498

7599
samp[0] = samp[1] = 0;
76100

77-
Blip_Synth_offset(&Synth, timestamp, (samp[0] - ch->blip_prev_samp[0]) * ch->user_volume / 100, sbuf[0]);
78-
Blip_Synth_offset(&Synth, timestamp, (samp[1] - ch->blip_prev_samp[1]) * ch->user_volume / 100, sbuf[1]);
101+
if(ch->user_volume < 100)
102+
{
103+
delta0 = (samp[0] - ch->blip_prev_samp[0]) * ch->user_volume / 100;
104+
delta1 = (samp[1] - ch->blip_prev_samp[1]) * ch->user_volume / 100;
105+
} else {
106+
delta0 = samp[0] - ch->blip_prev_samp[0];
107+
delta1 = samp[1] - ch->blip_prev_samp[1];
108+
}
109+
110+
Blip_Synth_offset(&Synth, timestamp, delta0, sbuf[0]);
111+
Blip_Synth_offset(&Synth, timestamp, delta1, sbuf[1]);
79112

80113
ch->blip_prev_samp[0] = samp[0];
81114
ch->blip_prev_samp[1] = samp[1];
@@ -85,12 +118,23 @@ void PCEFast_PSG::UpdateOutput_Off(const int32 timestamp, psg_channel *ch)
85118
void PCEFast_PSG::UpdateOutput_Accum(const int32 timestamp, psg_channel *ch)
86119
{
87120
int32 samp[2];
121+
int delta0;
122+
int delta1;
88123

89124
samp[0] = ((int32)dbtable_volonly[ch->vl[0]] * ((int32)ch->samp_accum - 496)) >> (8 + 5);
90125
samp[1] = ((int32)dbtable_volonly[ch->vl[1]] * ((int32)ch->samp_accum - 496)) >> (8 + 5);
91126

92-
Blip_Synth_offset(&Synth, timestamp, (samp[0] - ch->blip_prev_samp[0]) * ch->user_volume / 100, sbuf[0]);
93-
Blip_Synth_offset(&Synth, timestamp, (samp[1] - ch->blip_prev_samp[1]) * ch->user_volume / 100, sbuf[1]);
127+
if(ch->user_volume < 100)
128+
{
129+
delta0 = (samp[0] - ch->blip_prev_samp[0]) * ch->user_volume / 100;
130+
delta1 = (samp[1] - ch->blip_prev_samp[1]) * ch->user_volume / 100;
131+
} else {
132+
delta0 = samp[0] - ch->blip_prev_samp[0];
133+
delta1 = samp[1] - ch->blip_prev_samp[1];
134+
}
135+
136+
Blip_Synth_offset(&Synth, timestamp, delta0, sbuf[0]);
137+
Blip_Synth_offset(&Synth, timestamp, delta1, sbuf[1]);
94138

95139
ch->blip_prev_samp[0] = samp[0];
96140
ch->blip_prev_samp[1] = samp[1];

mednafen/pce_fast/psg.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct psg_channel
3131
uint16 frequency; /* Channel frequency */
3232
uint8 balance; /* Channel balance */
3333

34-
uint8 user_volume;
34+
int32 user_volume;
3535
};
3636

3737
class PCEFast_PSG
@@ -47,7 +47,7 @@ class PCEFast_PSG
4747
void Write(int32 timestamp, uint8 A, uint8 V);
4848

4949
void SetVolume(double new_volume) MDFN_COLD;
50-
void SetChannelUserVolume(int chnum, uint8 new_volume) MDFN_COLD;
50+
void SetChannelUserVolume(int chnum, int32 new_volume) MDFN_COLD;
5151

5252
void EndFrame(int32 timestamp);
5353

0 commit comments

Comments
 (0)