summaryrefslogtreecommitdiff
path: root/src/screen.c
diff options
context:
space:
mode:
authorLoic Guegan <loic.guegan@mailbox.org>2023-12-24 19:59:31 +0100
committerLoic Guegan <loic.guegan@mailbox.org>2023-12-24 19:59:31 +0100
commit1f3e1f7f54dab40fef28370f1f0465933366a3c2 (patch)
tree53eb9938636776ce7a7b3d97ab306a485804cf1c /src/screen.c
parentce6f056fa849ba23665cfe4239d2191efd74cb89 (diff)
Minor changes
Diffstat (limited to 'src/screen.c')
-rw-r--r--src/screen.c33
1 files changed, 32 insertions, 1 deletions
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
}