diff --git a/Makefile b/Makefile index baa2aff..acb89df 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -LIBS = +LIBS = -lmingw32 -lSDL2main -lSDL2 CFLAGS = -Wall # Should be equivalent to your list of C files, if you don't build selectively diff --git a/debug.exe b/debug.exe index 2517208..910da48 100644 Binary files a/debug.exe and b/debug.exe differ diff --git a/gbt.exe b/gbt.exe index b051ecf..9b35012 100644 Binary files a/gbt.exe and b/gbt.exe differ diff --git a/src/groups/aritmetic.c b/src/groups/aritmetic.c index bf31638..1cd8eb1 100644 --- a/src/groups/aritmetic.c +++ b/src/groups/aritmetic.c @@ -567,7 +567,11 @@ void Scf37(struct CPU* cpu, struct MMU* mmu) printf("SCF"); #endif // Cycles: 4, (Z N H C): - 0 0 1 - printf("Not implemented! (Scf37)"); + + // update timer + (*cpu).tick+=4; + + (*cpu).F = ((*cpu).F & Z_flag) | C_flag; } void Ccf3F(struct CPU* cpu, struct MMU* mmu) @@ -577,7 +581,12 @@ void Ccf3F(struct CPU* cpu, struct MMU* mmu) printf("CCF"); #endif // Cycles: 4, (Z N H C): - 0 0 C - printf("Not implemented! (Ccf3F)"); + + // update timer + (*cpu).tick+=4; + + unsigned char inv_Cflag = (~((*cpu).F & C_flag) & C_flag); + (*cpu).F = ((*cpu).F & Z_flag) | inv_Cflag; } void Adc_8(unsigned char* A, unsigned char* B, struct CPU* cpu) { diff --git a/src/groups/misc.c b/src/groups/misc.c index 54f837e..378b46f 100644 --- a/src/groups/misc.c +++ b/src/groups/misc.c @@ -9,7 +9,7 @@ void Nop00(struct CPU* cpu, struct MMU* mmu) printf("NOP"); #endif // Cycles: 4, (Z N H C): - - - - - printf("Not implemented! (Nop00)"); + (*cpu).tick += 4; } void Rlca07(struct CPU* cpu, struct MMU* mmu) diff --git a/src/main.c b/src/main.c index 7abb1f1..a764cb7 100644 --- a/src/main.c +++ b/src/main.c @@ -1,3 +1,4 @@ +//#include #include #include #include @@ -5,6 +6,7 @@ #include "tools.h" #include "cpu.h" #include "mmu.h" +#include "ppu.h" #define TETRIS_SIZE 32768 @@ -45,7 +47,7 @@ int main(int argc, char *argv[]) { cpu.tick= 0; ////////////////////////////// - +/* char* var; int instruction_nb = 0; // TESTING instructions @@ -69,5 +71,8 @@ int main(int argc, char *argv[]) { //printf("\tB register: %x\n", cpu.B); patches(&cpu,&mmu); } +*/ + + create_window(); return 0; } diff --git a/src/ppu.c b/src/ppu.c new file mode 100644 index 0000000..0d8c912 --- /dev/null +++ b/src/ppu.c @@ -0,0 +1,63 @@ +#include "ppu.h" + +#define SCALE 5 + +SDL_Window* create_window(){ + + SDL_Window *window; + + SDL_Init(SDL_INIT_VIDEO); // Initialize SDL2 + + // Create an application window with the following settings: + window =SDL_CreateWindow( + "GBT", // window title + SDL_WINDOWPOS_UNDEFINED, // initial x position + SDL_WINDOWPOS_UNDEFINED, // initial y position + 160*SCALE, // width, in pixels + 144*SCALE, // height, in pixels + SDL_WINDOW_OPENGL // flags - see below + ); + unsigned int palette[4] = {0xffe0f8d0, 0xff88c070, 0xff346856, 0xff081820}; + + unsigned int* pixels = calloc(160*144,sizeof(unsigned int)); + +int i, j; for (i = 0; i < 144; ++i) + for (j = 0; j < 160; ++j) + if (j < 40) pixels[i*160+j] = palette[0]; + else if (j < 80) pixels[i*160+j] = palette[1]; + else if (j < 120) pixels[i*160+j] = palette[2]; + else pixels[i*160+j] = palette[3]; + + SDL_Renderer * renderer = SDL_CreateRenderer(window, -1, 0); + + SDL_RenderSetScale(renderer, + SCALE, SCALE); + + SDL_Texture * texture = SDL_CreateTexture(renderer, + SDL_PIXELFORMAT_ARGB8888, + SDL_TEXTUREACCESS_STATIC, + 160, + 144); + + if (window == NULL) { + // In the case that the window could not be made... + printf("Could not create window: %s\n", SDL_GetError()); + return NULL; + } + + SDL_UpdateTexture(texture, NULL, pixels, 160 * sizeof(Uint32)); + + SDL_RenderClear(renderer); + SDL_RenderCopy(renderer, texture, NULL, NULL); + SDL_RenderPresent(renderer); + + SDL_Delay(30000); // Pause execution for 3000 milliseconds, for example + + // Close and destroy the window + SDL_DestroyWindow(window); + + // Clean up + SDL_Quit(); + + return window; +} diff --git a/src/ppu.h b/src/ppu.h new file mode 100644 index 0000000..aef17f8 --- /dev/null +++ b/src/ppu.h @@ -0,0 +1,4 @@ +#define SDL_MAIN_HANDLED +#include + +SDL_Window* create_window();