[cartridge/main] Fixed warnings and Address decoding

- Fixed mapper 000 by chaning the mod operation to not disinclude 0x3FFF from being turned into 0. This fixes all issues with mapper 000 as it matches other established emulators

- Fixed all warnings other than non-disableable ones.

- Added a way to assign a test rom name so that it can start at a custom location rather than the address vector at 0xFFFC
main
RenDev 3 years ago
parent b9be3f383e
commit 15e558719b
  1. 16
      bus.c
  2. 11
      cartridge.c
  3. 6
      cpu.c
  4. 4
      ppu.c

16
bus.c

@ -1,4 +1,5 @@
#include "bus.h" #include "bus.h"
#include <string.h>
bool debug = true; bool debug = true;
@ -113,8 +114,7 @@ void activateCpuNmi(){
#define ROM_TEST_NAME ("nestest.nes")
int main(int argc, char * argv[]){ int main(int argc, char * argv[]){
@ -132,9 +132,15 @@ 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 = romStartAddress; NOT FUNC YET if(strstr(argv[1], ROM_TEST_NAME)){
cpu->PC = 0xC000; if(strlen(strstr(argv[1], ROM_TEST_NAME)) == strlen(ROM_TEST_NAME)){ //Load test rom at 0xC000
cpu->PC = 0xC000;
}else{
cpu->PC = romStartAddress; //Rom was in a folder called 'ROM_TEST_NAME' rather than loading a file with the same name
}
}else{
cpu->PC = romStartAddress; //Rom was not a test rom. Load normally
}
while(true){ while(true){

@ -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 < 4; i++){ //Remove padding for(byte i = 0; i < 5; i++){ //Remove padding
getc(romfile); getc(romfile);
} }
} }
@ -52,6 +52,13 @@ void initBanks(char name[]){
CHRROM[i] = getc(romfile); CHRROM[i] = getc(romfile);
} }
unsigned long read_size = ftell(romfile);
fseek(romfile, 0, SEEK_END);
unsigned long file_size = ftell(romfile);
if(read_size != file_size){
fprintf(stderr, "WARNING: Bytes read does not match the file size! Nesem Reported = 0x%lX, File Size = 0x%lX!\n", read_size, file_size);
}
fclose(romfile); fclose(romfile);
//Read rom start Address //Read rom start Address
@ -67,7 +74,7 @@ word mapper000_Read(word address, bool ppu){
if(Header.PRG_BANKS > 1){ //32K model if(Header.PRG_BANKS > 1){ //32K model
return PRGROM[address - 0x8000]; return PRGROM[address - 0x8000];
}else{ //16K model }else{ //16K model
return PRGROM[(address - 0x8000) % 0x3FFF]; return PRGROM[(address - 0x8000) % 0x4000];
} }
} }
}else{ //if PPU }else{ //if PPU

@ -1822,14 +1822,14 @@ void raiseError(unsigned int err, CPU * __restrict__ cpu){
"Cycles was allocated but not set", "Cycles was allocated but not set",
}; };
fprintf(stderr, "%s", ERROR_STR[err]); fprintf(stderr, "%s\n", ERROR_STR[err]);
fprintf(stderr, "CRASH!!!!\n\n"); fprintf(stderr, "CRASH!!!!\n\n");
fprintf(stderr, "\tLOCATION: %#06x\n", cpu->PC); fprintf(stderr, "\tLOCATION: %#06x\n", cpu->PC);
fprintf(stderr, "\tOPCODE: %#06x\n", busRead8(cpu->PC)); fprintf(stderr, "\tOPCODE: %#06x\n", busRead8(cpu->PC));
if(err != UNALLOC_NAME && err != UNALLOC_MICRO) if(err != UNALLOC_NAME && err != UNALLOC_MICRO)
fprintf(stderr, "\tNAME: \"%s\"\n", cpu->opcodes[busRead8(cpu->PC)].name); fprintf(stderr, "\tNAME: \"%s\"\n", cpu->opcodes[busRead8(cpu->PC)].name);
else else
fprintf(stderr, "\tNAME: \"%s\"\n", NULL); fprintf(stderr, "\tNAME: \"(NULL)\"\n");
fprintf(stderr, "\tMICRO: %p\n", cpu->opcodes[busRead8(cpu->PC)].microcode); fprintf(stderr, "\tMICRO: %p\n", cpu->opcodes[busRead8(cpu->PC)].microcode);
fprintf(stderr, "\tMODE: %p\n", cpu->opcodes[busRead8(cpu->PC)].mode); fprintf(stderr, "\tMODE: %p\n", cpu->opcodes[busRead8(cpu->PC)].mode);
exit(err); exit(err);
@ -1878,9 +1878,11 @@ void handleErrors(CPU * __restrict__ cpu){
if(cur_inst.bytes == 0){ if(cur_inst.bytes == 0){
raiseError(UNKNOWN_BYTES, cpu); raiseError(UNKNOWN_BYTES, cpu);
} }
/*
if(cur_inst.microcode < ORA || cur_inst.microcode > TYA){ if(cur_inst.microcode < ORA || cur_inst.microcode > TYA){
raiseError(UNKNOWN_MICRO, cpu); raiseError(UNKNOWN_MICRO, cpu);
} }
*/
printf("OP: %x\n", busRead8(cpu->PC)); printf("OP: %x\n", busRead8(cpu->PC));
} }

@ -179,7 +179,7 @@ void ppuRegWrite(word address, byte data){
break; break;
default: default:
fprintf(stderr, "ERR: Invalid write to PPU register of address %llX\n!", address + 0x2000); fprintf(stderr, "ERR: Invalid write to PPU register of address %X\n!", address + 0x2000);
abort(); abort();
break; break;
} }
@ -248,7 +248,7 @@ byte ppuRegRead(word address){ //send the registers to the bus so the components
break; break;
default: default:
fprintf(stderr, "ERR: Invalid read to PPU register of address %llX\n!", address + 0x2000); fprintf(stderr, "ERR: Invalid read to PPU register of address %X\n!", address + 0x2000);
abort(); abort();
break; break;
} }

Loading…
Cancel
Save