diff --git a/Makefile b/Makefile index f0b9489..9e723cd 100644 --- a/Makefile +++ b/Makefile @@ -15,3 +15,6 @@ clean: debug: $(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) diff --git a/bus.c b/bus.c index c4aa084..07def55 100644 --- a/bus.c +++ b/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 @@ -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 initBanks(argv[1]); - cpu->PC = rom_start_address; - - #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 + //cpu->PC = romStartAddress; NOT FUNC YET + cpu->PC = 0xC000; while(true){ @@ -180,10 +148,20 @@ int main(int argc, char * argv[]){ cpuNmi(cpu); activateCpuNmiBool = false; } + + // + // //RUN THE CPU CLOCK ONE TIME cpuClock(cpu); + // + // + // + + #ifdef DEBUG - getchar(); + #ifdef TICKONKEY + getchar(); + #endif #endif } diff --git a/cartridge.c b/cartridge.c index 9f2efab..2c5112c 100644 --- a/cartridge.c +++ b/cartridge.c @@ -7,7 +7,7 @@ byte CHRROM[0xFFFF]; word not_handling_this = 0x100; //0xFF + 1 -word rom_start_address = 0x0; +word romStartAddress = 0x0; void loadRomfileHeader(FILE * romfile){ byte verificationToken[3] = "NES"; @@ -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 < 5; i++){ //Remove padding + for(byte i = 0; i < 4; i++){ //Remove padding getc(romfile); } } @@ -33,12 +33,10 @@ void initBanks(char name[]){ FILE * romfile; romfile = fopen(name, "rb"); - #ifdef DEBUG - if(romfile == NULL){ - fprintf(stderr, "ERR: file \"%s\" could not be opened for reading!\n", name); - exit(EXIT_FAILURE); - } - #endif + if(romfile == NULL){ + fprintf(stderr, "ERR: file \"%s\" could not be opened for reading!\n", name); + exit(EXIT_FAILURE); + } loadRomfileHeader(romfile); @@ -58,7 +56,7 @@ void initBanks(char name[]){ //Read rom start Address #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){ @@ -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 }else{ if(Header.PRG_BANKS > 1){ //32K model - return PRGROM[address - 0x8000 + 0x4]; + return PRGROM[address - 0x8000]; }else{ //16K model - return PRGROM[(address - 0x8000 + 0x4) % 0x3FFF]; + return PRGROM[(address - 0x8000) % 0x3FFF]; } } }else{ //if PPU diff --git a/cartridge.h b/cartridge.h index 5478ae4..62b7f3a 100644 --- a/cartridge.h +++ b/cartridge.h @@ -4,7 +4,7 @@ //extern? void (*mapper_read)(word); //void (*mapper_write)(bool); -extern word rom_start_address; +extern word romStartAddress; #define K_SIZE 1024