Code: Select all
project('NESt', 'c')
source_files=files('src/main.c',
'src/App.h', 'src/App.c',
'src/Emulator.h', 'src/Emulator.c',
'src/Mapper.h', 'src/Mapper.c',
'src/CPU.h', 'src/CPU.c',
'src/MMU.h', 'src/MMU.c'
)
executable('NESt', source_files, dependencies: dependency('sdl2'))
Code: Select all
Failed to truncate cookie file: Invalid argumentIch verwende Linux Mint.
MMU.h
Code: Select all
#include
typedef struct
{
//either we can have 64kb virtual mem or in my case original 2kb memory
uint8_t memory[2*1024];
} MMU;
void write(MMU *mmu, uint16_t addr, uint8_t data);
uint8_t read(MMU *mmu, uint16_t addr);
Code: Select all
#include "MMU.h"
#include "Mapper.h"
void write(MMU *mmu, uint16_t addr, uint8_t data)
{
//(mmu->memory)[addr]=data;
}
uint8_t read(MMU *mmu, uint16_t addr)
{
if (addrmemory)[(addr%(2*1024))];
else if (addr>(1024*32))
{
//call the mapper and then do stuff;
}
//how handle error
return 0;
}
Mapper.c
Code: Select all
#include "Mapper.h"
#include
#include
#include
//maybe better error handling or just bool is fine?
bool load_ROM(Mapper *mapper, const char* filepath)
{
FILE *file = fopen(filepath, "rb");
if(!file)
{
//log the error
perror("");
return false;
}
char header[16];
if(!fread(header, 1, 16, file))
{
perror("Error Reading File");
return false;
}
if (memcmp(header, "NES\x1A", 4)!=0)
{
perror("Invalid ROM");
return false;
}
//16kb units
mapper->PRG_ROM.size=header[4]*16*1024;
//8kb units
mapper->CHR_ROM.size=header[5]*8*1024;
//read the prg and chr rom data
mapper->PRG_ROM.data = malloc(mapper->PRG_ROM.size);
if(!mapper->PRG_ROM.data)
{
perror("1");
return false;
}
if(!fread(mapper->PRG_ROM.data, 1, mapper->PRG_ROM.size, file))
{
perror("2");
return false;
}
mapper->CHR_ROM.data = malloc(mapper->CHR_ROM.size);
if(!mapper->CHR_ROM.data)
{
perror("3");
return false;
}
if(!fread(mapper->CHR_ROM.data, 1, mapper->CHR_ROM.size, file))
{
perror("4");
return false;
}
fclose(file);
//can this fail?
//for now
free(mapper->CHR_ROM.data);
free(mapper->PRG_ROM.data);
return true;
}
void init_mapper(Mapper *mapper)
{
if(!load_ROM(mapper, "test.nes"))
{
perror("Failed to load ROM");
return;
}
}
Ich habe versucht, es zu debuggen. Wenn ich das Programm dort beende, wo es hängen bleibt,
erhalte ich Folgendes:
Code: Select all
Failed to truncate cookie file: Invalid argument
^C
Thread 1 "NESt" received signal SIGINT, Interrupt.
0x00007ffff7a98d71 in __futex_abstimed_wait_common64 (private=0, cancel=true,
abstime=0x0, op=393, expected=0, futex_word=0x555555596c8c)
at ./nptl/futex-internal.c:57
warning: 57 ./nptl/futex-internal.c: No such file or directory
(gdb) where
#0 0x00007ffff7a98d71 in __futex_abstimed_wait_common64 (private=0,
cancel=true, abstime=0x0, op=393, expected=0, futex_word=0x555555596c8c)
at ./nptl/futex-internal.c:57
#1 __futex_abstimed_wait_common (cancel=true, private=0, abstime=0x0,
clockid=0, expected=0, futex_word=0x555555596c8c)
at ./nptl/futex-internal.c:87
#2 __GI___futex_abstimed_wait_cancelable64 (
futex_word=futex_word@entry=0x555555596c8c, expected=expected@entry=0,
clockid=clockid@entry=0, abstime=abstime@entry=0x0,
private=private@entry=0) at ./nptl/futex-internal.c:139
#3 0x00007ffff7a9b7ed in __pthread_cond_wait_common (abstime=0x0, clockid=0,
mutex=0x55555558ca30, cond=0x555555596c60)
at ./nptl/pthread_cond_wait.c:503
#4 ___pthread_cond_wait (cond=0x555555596c60, mutex=0x55555558ca30)
at ./nptl/pthread_cond_wait.c:627
#5 0x00007ffff7c9d604 in pa_threaded_mainloop_wait ()
from /lib/x86_64-linux-gnu/libpulse.so.0
#6 0x00007ffff7ec81fd in ?? () from /lib/x86_64-linux-gnu/libSDL2-2.0.so.0
#7 0x00007ffff7ec9b37 in ?? () from /lib/x86_64-linux-gnu/libSDL2-2.0.so.0
#8 0x00007ffff7df9ec4 in ?? () from /lib/x86_64-linux-gnu/libSDL2-2.0.so.0
#9 0x00007ffff7dfa567 in ?? () from /lib/x86_64-linux-gnu/libSDL2-2.0.so.0
#10 0x00005555555553e4 in app_init (app=0x7fffffffdd10, argc=1,
argv=0x7fffffffde78) at ../src/App.c:291
Code: Select all
`if (SDL_Init(SDL_INIT_EVERYTHING)){....}`
Ich weiß nicht, wie ich diesen Fehler reproduzieren kann, vielleicht ist er maschinenspezifisch oder spezifisch für das Buildsystem oder die Codebasis. Ich weiß nicht, warum es dort ist und deshalb bin ich hier.
Mobile version