added mappers (not working)
This commit is contained in:
parent
034645154d
commit
9039fa0ccf
14 changed files with 512 additions and 106 deletions
105
NES Emulator/mappers/mapper000.c
Normal file
105
NES Emulator/mappers/mapper000.c
Normal file
|
@ -0,0 +1,105 @@
|
|||
#include "mapper000.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
struct Mapper000* createMapper000(Byte prg_rom_size, Byte chr_rom_size, FILE* fp)
|
||||
{
|
||||
struct Mapper000* mapper = (struct Mapper000*)malloc(sizeof(struct Mapper000));
|
||||
if (mapper == NULL)
|
||||
{
|
||||
fprintf(stderr, "Failed to create Mapper 000. Aborting\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
mapper->prg_rom_size = prg_rom_size;
|
||||
mapper->prg_rom = (Byte*)calloc(prg_rom_size, 0x4000);
|
||||
if (mapper->prg_rom == NULL)
|
||||
{
|
||||
fprintf(stderr, "Failed to allocate cartridge PRG ROM. Aborting\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
mapper->chr_rom_size = chr_rom_size;
|
||||
mapper->chr_rom = (Byte*)calloc(chr_rom_size, 0x2000);
|
||||
if (mapper->chr_rom == NULL)
|
||||
{
|
||||
fprintf(stderr, "Failed to allocate cartridge CHR ROM. Aborting\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
fread(mapper->prg_rom, 0x4000, prg_rom_size, fp);
|
||||
fread(mapper->chr_rom, 0x2000, chr_rom_size, fp);
|
||||
|
||||
return mapper;
|
||||
}
|
||||
|
||||
void destroyMapper000(struct Mapper000* mapper)
|
||||
{
|
||||
free(mapper->chr_rom);
|
||||
free(mapper->prg_rom);
|
||||
|
||||
free(mapper);
|
||||
}
|
||||
|
||||
Byte Mapper000_ReadCPU(struct Mapper000* mapper, Word address)
|
||||
{
|
||||
Byte val = 0x00;
|
||||
|
||||
if (address >= 0x6000 && address < 0x8000)
|
||||
{
|
||||
fprintf(stderr, "This Mapper 000 implementation doesnt support FamilyBasic PRG RAM\n");
|
||||
exit(-1);
|
||||
}
|
||||
else if (address >= 0x8000)
|
||||
{
|
||||
Word effectiveAddress = address - 0x8000;
|
||||
effectiveAddress %= 0x4000 * (mapper->prg_rom_size == 1);
|
||||
|
||||
val = mapper->prg_rom[effectiveAddress];
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "Cartridge read access violation by the CPU at $%04X\n", address);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
Byte Mapper000_ReadPPU(struct Mapper000* mapper, Word address)
|
||||
{
|
||||
Byte val = 0x00;
|
||||
|
||||
if (address >= 0x2000)
|
||||
{
|
||||
fprintf(stderr, "Cartridge read access violation by the PPU at $%04X\n", address);
|
||||
exit(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
val = mapper->chr_rom[address];
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
void Mapper000_WriteCPU(struct Mapper000* mapper, Word address, Byte value)
|
||||
{
|
||||
// nothing
|
||||
}
|
||||
|
||||
|
||||
void Mapper000_WritePPU(struct Mapper000* mapper, Word address, Byte value)
|
||||
{
|
||||
// nothing
|
||||
}
|
||||
|
||||
void Mapper000_GetPatternTableTexture(struct Mapper000* mapper, SDL_Texture* texture, int index)
|
||||
{
|
||||
int pitch;
|
||||
void* pixels;
|
||||
SDL_LockTexture(texture, NULL, &pixels, &pitch);
|
||||
SDL_memcpy(pixels, mapper->chr_rom + 0x1000 * index, 0x1000);
|
||||
SDL_UnlockTexture(texture);
|
||||
}
|
27
NES Emulator/mappers/mapper000.h
Normal file
27
NES Emulator/mappers/mapper000.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
#ifndef _MAPPER_000_
|
||||
#define _MAPPER_000_
|
||||
|
||||
#include <stdio.h>
|
||||
#include "../types.h"
|
||||
#include "SDL.h"
|
||||
|
||||
struct Mapper000
|
||||
{
|
||||
Byte prg_rom_size;
|
||||
Byte chr_rom_size;
|
||||
|
||||
Byte* prg_rom;
|
||||
Byte* chr_rom;
|
||||
};
|
||||
|
||||
struct Mapper000* createMapper000(Byte prg_rom_size, Byte chr_rom_size, FILE* fp);
|
||||
void destroyMapper000(struct Mapper000* mapper);
|
||||
|
||||
Byte Mapper000_ReadCPU(struct Mapper000* mapper, Word address);
|
||||
Byte Mapper000_ReadPPU(struct Mapper000* mapper, Word address);
|
||||
void Mapper000_WriteCPU(struct Mapper000* mapper, Word address, Byte value);
|
||||
void Mapper000_WritePPU(struct Mapper000* mapper, Word address, Byte value);
|
||||
|
||||
void Mapper000_GetPatternTableTexture(struct Mapper000* mapper, SDL_Texture* texture, int index);
|
||||
|
||||
#endif _MAPPER_000_
|
Loading…
Add table
Add a link
Reference in a new issue