summaryrefslogtreecommitdiff
path: root/mknes.c
diff options
context:
space:
mode:
Diffstat (limited to 'mknes.c')
-rw-r--r--mknes.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/mknes.c b/mknes.c
index 8169fae..044a612 100644
--- a/mknes.c
+++ b/mknes.c
@@ -273,7 +273,17 @@ int main(int argc, char **argv) {
init_opcode_ud_lut();
// protect_opcode_lut();
- struct nes_state *nstate = aligned_alloc(4096, (sizeof(struct nes_state) + 4095) & ~4095);
+ // Add this line to /etc/sysctl.conf or create a new file /etc/sysctl.d/99-hugepages.conf:
+ // vm.nr_hugepages = 20
+ // Then apply it:
+ // sudo sysctl -p /etc/sysctl.d/99-hugepages.conf
+
+ size_t nstate_size = (sizeof(struct nes_state) + 4095) & ~4095; // Round up to page size
+ struct nes_state *nstate = mmap(0, nstate_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_POPULATE | MAP_LOCKED, -1, 0);
+ if (nstate == MAP_FAILED) {
+ perror("mmap nstate failed");
+ exit(1);
+ }
#ifdef BENCHMARK
// Run benchmark with configurable parameters
@@ -299,9 +309,9 @@ int main(int argc, char **argv) {
// ines2_load(nstate, "data/0000/10-Yard Fight (USA, Europe).nes");
// ines2_load(nstate, "data/0000/Balloon Fight (USA).nes");
// ines2_load(nstate, "data/0000/Excitebike (Japan, USA).nes");
- ines2_load(nstate, "data/0000/Ice Climber (USA, Europe, Korea).nes");
+ // ines2_load(nstate, "data/0000/Ice Climber (USA, Europe, Korea).nes");
// ines2_load(nstate, "data/0000/Kung Fu (Japan, USA).nes");
- // ines2_load(nstate, "data/0000/Super Mario Bros. (World) (HVC-SM).nes");
+ ines2_load(nstate, "data/0000/Super Mario Bros. (World) (HVC-SM).nes");
// ines2_load(nstate, "data/Super Mario Bros. (W) (V1.0) [!].nes");
// ines2_load(nstate, "data/Super Mario Bros. (JU) [!].nes");
// ines2_load(nstate, "data/0000/Urban Champion (World).nes");
@@ -342,8 +352,8 @@ int main(int argc, char **argv) {
// ines2_load(nstate, "data/2002/Best of the Best - Championship Karate (USA).zip");
// ines2_load(nstate, "data/0001/Kid Icarus (UE) (V1.1) [!].nes");
- ines2_load(nstate, "data/0001/Metroid (U) [!].nes");
- ines2_load(nstate, "data/0001/Legend of Zelda, The (U) (V1.1) [!].nes");
+ // ines2_load(nstate, "data/0001/Metroid (U) [!].nes");
+ // ines2_load(nstate, "data/0001/Legend of Zelda, The (U) (V1.1) [!].nes");
// ines2_load(nstate, "data/Blaster Master (USA).zip"); // mapper 1
// ines2_load(nstate, "AccuracyCoin.nes"); // mapper 1
@@ -408,6 +418,7 @@ int main(int argc, char **argv) {
if(window->keyboard_state[MKS_KEY_LEFT]) { input |= (1 << 6); }
if(window->keyboard_state[MKS_KEY_RIGHT]) { input |= (1 << 7); }
nstate->ppu.input[0] = input;
+ // nstate->ppu.input[0] = tas_input[tas_frame++];
// Run NES emulation for one frame
while(!nstate->ppu.frame_ready) {
@@ -422,14 +433,13 @@ int main(int argc, char **argv) {
// }
// nstate->ppu.open_bus = v;
// }
- // nstate->ppu.input[0] = tas_input[tas_frame++];
frames++;
// Dump state every frame starting from 2400
- if(frames >= 2400 && frames <= 3100) {
- dump_state(nstate);
- }
+ // if(frames >= 2400 && frames <= 3100) {
+ // dump_state(nstate);
+ // }
// Convert NES pixels to display buffer
uint32_t * restrict dst = display_buffer;
@@ -456,15 +466,14 @@ int main(int argc, char **argv) {
}
// printf("total frames: %6d total cycles: %12llu\n", frames, (unsigned long long)nstate->cpu.cycles);
- printf("state dumps created: %zu\n", state_dump_count);
+ // printf("state dumps created: %zu\n", state_dump_count);
if(state_dump_file) {
fclose(state_dump_file);
}
timer_destroy(timer);
- free(nstate);
- // free_nes_state(&nstate);
+ munmap(nstate, nstate_size);
timer_shutdown();
mkfw_cleanup(window);