diff options
| author | Loic Guegan <loic.guegan@mailbox.org> | 2023-12-24 19:59:31 +0100 |
|---|---|---|
| committer | Loic Guegan <loic.guegan@mailbox.org> | 2023-12-24 19:59:31 +0100 |
| commit | 1f3e1f7f54dab40fef28370f1f0465933366a3c2 (patch) | |
| tree | 53eb9938636776ce7a7b3d97ab306a485804cf1c | |
| parent | ce6f056fa849ba23665cfe4239d2191efd74cb89 (diff) | |
Minor changes
| -rw-r--r-- | src/main.c | 2 | ||||
| -rw-r--r-- | src/screen.c | 33 | ||||
| -rw-r--r-- | src/screen.h | 14 |
3 files changed, 46 insertions, 3 deletions
@@ -6,6 +6,8 @@ int main(int argc, char *argv[]) ScreenInit(800,400); + ScreenSetPixel(0,1,1); + while (!WindowShouldClose()){ ScreenUpdate(); } diff --git a/src/screen.c b/src/screen.c index 61828b1..727d8ed 100644 --- a/src/screen.c +++ b/src/screen.c @@ -1,17 +1,48 @@ #include "screen.h" +SCREEN_DATA Screen; + void ScreenInit(int width, int height){ + // Init emulated screen: + Screen.width=width; + Screen.height=height; + int px_width=width/64; + int px_height=height/32; + Screen.pixel=(px_width < px_height) ? px_width: px_height; + Screen.originX=(width-64*Screen.pixel)/2; + Screen.originY=(height-32*Screen.pixel)/2; + ScreenClear(); + InitWindow(width, height, "Chip-8 Emulator"); SetTargetFPS(60); // Set game to run at 60 frames-per-second } +void ScreenClear() { + for(int i=0;i<64*32;i++){ + Screen.pixels[i]=0; + } +} + void ScreenUpdate(){ BeginDrawing(); ClearBackground(RAYWHITE); - DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY); + // DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY); + for(int x=0;x<64;x++){ + for(int y=0;y<32;y++){ + if(Screen.pixels[x+y*64] == 0) + DrawRectangle(Screen.originX+Screen.pixel*x,Screen.originY+Screen.pixel*y,Screen.pixel,Screen.pixel,BLACK); + else + DrawRectangle(Screen.originX+Screen.pixel*x,Screen.originY+Screen.pixel*y,Screen.pixel,Screen.pixel,WHITE); + } + } + EndDrawing(); } +void ScreenSetPixel(int x, int y, char state){ + Screen.pixels[x+y*64]=(state==0) ? 0: 1; +} + void ScreenFinish(){ CloseWindow(); // Close window and OpenGL context } diff --git a/src/screen.h b/src/screen.h index 0ea74d1..22f095c 100644 --- a/src/screen.h +++ b/src/screen.h @@ -1,8 +1,18 @@ #include "raylib.h" -#define MODE_CHIP8 0 // Chip-8 -#define MODE_SCHIP 1 // Super-Chip +#define MODE_CHIP8 0 // Chip-8 64x32 +#define MODE_SCHIP 1 // Super-Chip 128x64 + +typedef struct SCREEN_DATA { + int width, height; + int originX; + int originY; + int pixel; + char pixels[64*32]; +} SCREEN_DATA; void ScreenInit(int width, int height); +void ScreenClear(); +void ScreenSetPixel(int x, int y, char state); void ScreenUpdate(); void ScreenFinish(); |
