Skip to content

Commit

Permalink
Added an option for RAM initialization (#276).
Browse files Browse the repository at this point in the history
It's possible to choose between three values:
1) 0x00
2) 0xFF (default)
3) Randomize.
  • Loading branch information
punesemu committed Jan 11, 2023
1 parent 90dd5bc commit ddc05c1
Show file tree
Hide file tree
Showing 20 changed files with 586 additions and 318 deletions.
1 change: 1 addition & 0 deletions src/core/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ enum false_value { FALSE, TRUE };
enum exit_type { EXIT_OK, EXIT_ERROR };
enum lower_value { LOWER, UPPER };
enum machine_mode { AUTO, NTSC, PAL, DENDY, DEFAULT = 255 };
enum initial_ram_value_type { IRV_0X00, IRV_0XFF, IRV_RANDOM };
enum console_type {
REGULAR_NES,
VS_SYSTEM,
Expand Down
1 change: 1 addition & 0 deletions src/core/conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ typedef struct _config {
BYTE ntsc_format;
BYTE palette;
BYTE disable_swap_emphasis_pal;
BYTE initial_ram_value;
BYTE vsync;
BYTE integer_scaling;
BYTE stretch;
Expand Down
2 changes: 1 addition & 1 deletion src/core/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ void cpu_turn_on(void) {
* state of any registers after Power-UP and especially
* not the stack register and WRAM ($0000-$07FF).
*/
memset(mmcpu.ram, 0xFF, sizeof(mmcpu.ram));
emu_initial_ram(mmcpu.ram, sizeof(mmcpu.ram));

/*
* questo workaround serve solo per
Expand Down
16 changes: 14 additions & 2 deletions src/core/emu.c
Original file line number Diff line number Diff line change
Expand Up @@ -667,8 +667,6 @@ BYTE emu_reset(BYTE type) {

info.first_illegal_opcode = FALSE;

srand(time(0));

tas.lag_next_frame = TRUE;
tas.lag_actual_frame = TRUE;

Expand Down Expand Up @@ -1162,6 +1160,20 @@ void emu_info_rom(void) {

log_info_box(uL("CRC32;%08X"), info.crc32.total);
}
void emu_initial_ram(BYTE *ram, unsigned int length) {
unsigned int i;

if (!ram || !length) {
return;
}
for (i = 0; i < length; i++) {
ram[i] = cfg->initial_ram_value == IRV_0X00
? 0x00
: cfg->initial_ram_value == IRV_0XFF
? 0xFF
: rand();
}
}

INLINE static void emu_frame_started(void) {
tas.lag_next_frame = TRUE;
Expand Down
1 change: 1 addition & 0 deletions src/core/emu.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ EXTERNC uTCHAR *emu_rand_str(void);
EXTERNC void emu_ctrl_doublebuffer(void);
EXTERNC void emu_frame_input_and_rewind(void);
EXTERNC void emu_info_rom(void);
EXTERNC void emu_initial_ram(BYTE *ram, unsigned int length);

#undef EXTERNC

Expand Down
8 changes: 3 additions & 5 deletions src/core/mappers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1537,13 +1537,11 @@ BYTE map_prg_ram_malloc(WORD size) {
return (EXIT_OK);
}
void map_prg_ram_memset(void) {
int value = 0x00;

if (info.mapper.id == FDS_MAPPER) {
value = 0xEA;
memset(prg.ram.data, 0xEA, prg.ram.size);
} else {
emu_initial_ram(prg.ram.data, prg.ram.size);
}

memset(prg.ram.data, value, prg.ram.size);
}
void map_prg_ram_battery_save(void) {
/* se c'e' della PRG Ram battery packed la salvo in un file */
Expand Down
4 changes: 3 additions & 1 deletion src/core/mappers/mapper_Namco.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "mem_map.h"
#include "cpu.h"
#include "save_slot.h"
#include "emu.h"

#define n163_prg_rom_8k_update(slot)\
control_bank_with_AND(0x3F, info.prg.rom.max.banks_8k)\
Expand Down Expand Up @@ -96,11 +97,12 @@ void map_init_Namco(BYTE model) {

if (info.reset >= HARD) {
memset(&n163, 0x00, sizeof(n163));
emu_initial_ram(n163.snd_ram, sizeof(n163.snd_ram));
n163.snd_ch_start = 7;
n163.snd_auto_inc = 1;
} else {
memset(&n163.ch, 0x00, sizeof(n163.ch));
memset(&n163.snd_ram, 0x00, sizeof(n163.snd_ram));
emu_initial_ram(n163.snd_ram, sizeof(n163.snd_ram));
memset(&n163.snd_wave, 0x00, sizeof(n163.snd_wave));
n163.irq_delay = FALSE;
n163.snd_ch_start = 7;
Expand Down
Binary file added src/gui/designer/icons/hexadecimal.svgz
Binary file not shown.
1 change: 1 addition & 0 deletions src/gui/designer/resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<file>icons/cassette_tape.svgz</file>
<file>icons/cassette_tape_play.svgz</file>
<file>icons/cassette_tape_record.svgz</file>
<file>icons/hexadecimal.svgz</file>
<file>icons/cassette_tape_stop.svgz</file>
<file>icons/channels.svgz</file>
<file>icons/cheat.svgz</file>
Expand Down
20 changes: 20 additions & 0 deletions src/gui/designer/translations/en_EN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2523,6 +2523,26 @@
<source>German</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>0x00</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Random</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Initial RAM value</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>RAM</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>0xFF</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>wdgSettingsInput</name>
Expand Down
12 changes: 11 additions & 1 deletion src/gui/designer/wdgSettingsAudio.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>573</width>
<width>733</width>
<height>580</height>
</rect>
</property>
Expand Down Expand Up @@ -182,6 +182,11 @@
</item>
<item>
<widget class="QPushButton" name="pushButton_Samplarate_44100">
<property name="font">
<font>
<underline>true</underline>
</font>
</property>
<property name="text">
<string>44100</string>
</property>
Expand Down Expand Up @@ -249,6 +254,11 @@
</item>
<item>
<widget class="QPushButton" name="pushButton_Channels_Stereo_Delay">
<property name="font">
<font>
<underline>true</underline>
</font>
</property>
<property name="text">
<string>Stereo Delay</string>
</property>
Expand Down
5 changes: 5 additions & 0 deletions src/gui/designer/wdgSettingsCheats.ui
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@
</property>
<item>
<widget class="QPushButton" name="pushButton_Cheats_Mode_disabled">
<property name="font">
<font>
<underline>true</underline>
</font>
</property>
<property name="text">
<string>Disabled</string>
</property>
Expand Down
Loading

0 comments on commit ddc05c1

Please sign in to comment.