nemu/src/display.c

56 lines
1.5 KiB
C

#include <display.h>
#include <cpu.h>
void display_pixel_on(display_t* display, int x, int y){
SDL_SetRenderDrawColor(display->renderer, 70,65,69,255);
SDL_Rect rect;
rect.h = 3;
rect.w = 3;
rect.x = x * 3;
rect.y = y * 3;
SDL_RenderFillRect(display->renderer,&rect);
}
void display_pixel_off(display_t* display, int x, int y){
SDL_SetRenderDrawColor(display->renderer, 179,204,174,255);
SDL_Rect rect;
rect.h = 3;
rect.w = 3;
rect.x = x * 3;
rect.y = y * 3;
SDL_RenderFillRect(display->renderer,&rect);
}
void display_clear(display_t* display){
SDL_SetRenderDrawColor(display->renderer, 179,204,174,255);
SDL_RenderClear(display->renderer);
}
#define HIGH_BIT(b) ((b & 0x80) >> 7)
void display_update(display_t* display, cpu_status_t* status){
uint8_t screen[8*1024];
for(int i=0; i<1024;i++){
uint8_t byte = status->vram[i];
for(int b=0; b<8;b++){
screen[i*8+b] = HIGH_BIT(byte >> b);
}
}
for(int i=0; i<64;i++){
for(int b=0; b<128;b++){
if(screen[i*128+b] == 1){
display_pixel_on(display, b, i);
} else {
display_pixel_off(display, b, i);
}
}
}
SDL_RenderPresent(display->renderer);
}
void display_init(display_t* display){
SDL_Init( SDL_INIT_VIDEO );
display->window = SDL_CreateWindow("nemu", 100, 100, 3*128, 3*64, SDL_WINDOW_SHOWN);
display->renderer = SDL_CreateRenderer(display->window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
}