diff --git a/bus.c b/bus.c index 1928401..6a5c973 100644 --- a/bus.c +++ b/bus.c @@ -1,4 +1,5 @@ #include "bus.h" +#include bool debug = true; @@ -113,8 +114,7 @@ void activateCpuNmi(){ - - +#define ROM_TEST_NAME ("nestest.nes") 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 initBanks(argv[1]); - //cpu->PC = romStartAddress; NOT FUNC YET - cpu->PC = 0xC000; - + if(strstr(argv[1], ROM_TEST_NAME)){ + 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){ diff --git a/cartridge.c b/cartridge.c index 2c5112c..1b116ee 100644 --- a/cartridge.c +++ b/cartridge.c @@ -24,7 +24,7 @@ void loadRomfileHeader(FILE * romfile){ for(byte i = 0; i < 5; i++){ 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); } } @@ -52,6 +52,13 @@ void initBanks(char name[]){ 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); //Read rom start Address @@ -67,7 +74,7 @@ word mapper000_Read(word address, bool ppu){ if(Header.PRG_BANKS > 1){ //32K model return PRGROM[address - 0x8000]; }else{ //16K model - return PRGROM[(address - 0x8000) % 0x3FFF]; + return PRGROM[(address - 0x8000) % 0x4000]; } } }else{ //if PPU diff --git a/cpu.c b/cpu.c index ee4e2f9..4935ff7 100644 --- a/cpu.c +++ b/cpu.c @@ -1822,14 +1822,14 @@ void raiseError(unsigned int err, CPU * __restrict__ cpu){ "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, "\tLOCATION: %#06x\n", cpu->PC); fprintf(stderr, "\tOPCODE: %#06x\n", busRead8(cpu->PC)); if(err != UNALLOC_NAME && err != UNALLOC_MICRO) fprintf(stderr, "\tNAME: \"%s\"\n", cpu->opcodes[busRead8(cpu->PC)].name); 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, "\tMODE: %p\n", cpu->opcodes[busRead8(cpu->PC)].mode); exit(err); @@ -1878,9 +1878,11 @@ void handleErrors(CPU * __restrict__ cpu){ if(cur_inst.bytes == 0){ raiseError(UNKNOWN_BYTES, cpu); } + /* if(cur_inst.microcode < ORA || cur_inst.microcode > TYA){ raiseError(UNKNOWN_MICRO, cpu); } + */ printf("OP: %x\n", busRead8(cpu->PC)); } diff --git a/ppu.c b/ppu.c index 17adb64..ec8e57d 100644 --- a/ppu.c +++ b/ppu.c @@ -179,7 +179,7 @@ void ppuRegWrite(word address, byte data){ break; 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(); break; } @@ -248,7 +248,7 @@ byte ppuRegRead(word address){ //send the registers to the bus so the components break; 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(); break; }