Код: Выделить всё
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'))
Код: Выделить всё
Failed to truncate cookie file: Invalid argumentЯ использую Linux Mint
Код: Выделить всё
MMU.h
#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);
Код: Выделить всё
MMU.c
#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 shit;
}
//how handle error
return 0;
}
Код: Выделить всё
Mapper.c
#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;
}
}
Подробнее здесь: https://stackoverflow.com/questions/798 ... -executing
Мобильная версия