[cartridge] Fix mapper resolve address

RenDev's latest commit cleaned the 4 bytes of buffer before the
    PRGROM even tho the program already accounted for that when
    calculating the return address by substracting 0x4. I'm leaving his
    way of dealing with the buffer since it saves 4 bytes of memory used
    for nothing in my implementation.

    Also cleaned the code a little, expect another commit that cleans
    the code more vigurously

    + Added debug-tickonclick Make rule for manual clock operation
main
Joaquin 3 years ago
parent f14bfa787f
commit 72cec71303
Signed by: puly
GPG Key ID: 9E9299CD96C65EC6
  1. 3
      Makefile
  2. 68
      bus.c
  3. 20
      cartridge.c
  4. 2
      cartridge.h

@ -15,3 +15,6 @@ clean:
debug: debug:
$(CC) $(CDEBUGFLAGS) bus.c cpu.c ppu.c cartridge.c -o $(OUTFILE) $(CC) $(CDEBUGFLAGS) bus.c cpu.c ppu.c cartridge.c -o $(OUTFILE)
debug-tickonclick:
$(CC) $(CDEBUGFLAGS) -DTICKONKEY bus.c cpu.c ppu.c cartridge.c -o $(OUTFILE)

68
bus.c

@ -107,26 +107,21 @@ void activateCpuNmi(){
} }
int main(int argc, char * argv[]){
#ifdef DEBUG
locationRegister testbit;
testbit.data = 0;
testbit.field.fineY = 0xFF;
printf("%016x", testbit.data);
#endif
activateCpuNmiBool = false;
CPU * cpu = (CPU*)malloc(sizeof(CPU)); //create new CPU
#ifdef DEBUG
if(cpu == NULL){
fprintf(stderr, "ERR: Out of RAM!\n");
exit(EXIT_FAILURE);
}
#endif int main(int argc, char * argv[]){
activateCpuNmiBool = false;
CPU * cpu = (CPU*)malloc(sizeof(CPU)); //create new CPU
initCpu(cpu); //put new CPU in starting mode and dock it to the bus initCpu(cpu); //put new CPU in starting mode and dock it to the bus
@ -137,35 +132,8 @@ int main(int argc, char * argv[]){
//load the CHR and PRG banks from the .nes file (argv[1]), also loads the header for mapper construction //load the CHR and PRG banks from the .nes file (argv[1]), also loads the header for mapper construction
initBanks(argv[1]); initBanks(argv[1]);
cpu->PC = rom_start_address; //cpu->PC = romStartAddress; NOT FUNC YET
cpu->PC = 0xC000;
#ifdef DEBUG
//Test to see if writing to the bus is working correctly
busWrite8(0x0000, 0xFF);
printf("\n---- ---- %02X %02X\n", busRead8(0x0000), bus[0x0000]);
//open debug PC logfile
FILE * PClogFILE;
PClogFILE = fopen("PClogFILE", "w");
#endif
#ifdef DEBUG
//ppu tests
printf("\nCACA\n");
printf("\nt\n");
initPpu();
printf("\nk\n");
ppuRegWrite(0x2006, 0x00);
printf("\nok\n");
ppuRegWrite(0x2006, 0x10);
printf("\nok1\n");
ppuRegWrite(0x2007, 0x22);
printf("\nok2\n");
ppuRegWrite(0x2007, 0x33);
printf("\nok3\n");
dumpPpuBus();
#endif
while(true){ while(true){
@ -180,10 +148,20 @@ int main(int argc, char * argv[]){
cpuNmi(cpu); cpuNmi(cpu);
activateCpuNmiBool = false; activateCpuNmiBool = false;
} }
//
//
//RUN THE CPU CLOCK ONE TIME //RUN THE CPU CLOCK ONE TIME
cpuClock(cpu); cpuClock(cpu);
//
//
//
#ifdef DEBUG #ifdef DEBUG
getchar(); #ifdef TICKONKEY
getchar();
#endif
#endif #endif
} }

@ -7,7 +7,7 @@ byte CHRROM[0xFFFF];
word not_handling_this = 0x100; //0xFF + 1 word not_handling_this = 0x100; //0xFF + 1
word rom_start_address = 0x0; word romStartAddress = 0x0;
void loadRomfileHeader(FILE * romfile){ void loadRomfileHeader(FILE * romfile){
byte verificationToken[3] = "NES"; byte verificationToken[3] = "NES";
@ -24,7 +24,7 @@ void loadRomfileHeader(FILE * romfile){
for(byte i = 0; i < 5; i++){ for(byte i = 0; i < 5; i++){
Header.flags.array[i] = getc(romfile); Header.flags.array[i] = getc(romfile);
} }
for(byte i = 0; i < 5; i++){ //Remove padding for(byte i = 0; i < 4; i++){ //Remove padding
getc(romfile); getc(romfile);
} }
} }
@ -33,12 +33,10 @@ void initBanks(char name[]){
FILE * romfile; FILE * romfile;
romfile = fopen(name, "rb"); romfile = fopen(name, "rb");
#ifdef DEBUG if(romfile == NULL){
if(romfile == NULL){ fprintf(stderr, "ERR: file \"%s\" could not be opened for reading!\n", name);
fprintf(stderr, "ERR: file \"%s\" could not be opened for reading!\n", name); exit(EXIT_FAILURE);
exit(EXIT_FAILURE); }
}
#endif
loadRomfileHeader(romfile); loadRomfileHeader(romfile);
@ -58,7 +56,7 @@ void initBanks(char name[]){
//Read rom start Address //Read rom start Address
#define ROM_START_VECTOR_ADDR (0xFFFC) #define ROM_START_VECTOR_ADDR (0xFFFC)
rom_start_address = busRead16(ROM_START_VECTOR_ADDR); romStartAddress = busRead16(ROM_START_VECTOR_ADDR);
} }
word mapper000_Read(word address, bool ppu){ word mapper000_Read(word address, bool ppu){
@ -67,9 +65,9 @@ word mapper000_Read(word address, bool ppu){
return not_handling_this; //not_handling_this is a 16 bit data integer, no byte will return this ever so this is our "not handling this" return code return not_handling_this; //not_handling_this is a 16 bit data integer, no byte will return this ever so this is our "not handling this" return code
}else{ }else{
if(Header.PRG_BANKS > 1){ //32K model if(Header.PRG_BANKS > 1){ //32K model
return PRGROM[address - 0x8000 + 0x4]; return PRGROM[address - 0x8000];
}else{ //16K model }else{ //16K model
return PRGROM[(address - 0x8000 + 0x4) % 0x3FFF]; return PRGROM[(address - 0x8000) % 0x3FFF];
} }
} }
}else{ //if PPU }else{ //if PPU

@ -4,7 +4,7 @@
//extern? void (*mapper_read)(word); //extern? void (*mapper_read)(word);
//void (*mapper_write)(bool); //void (*mapper_write)(bool);
extern word rom_start_address; extern word romStartAddress;
#define K_SIZE 1024 #define K_SIZE 1024

Loading…
Cancel
Save