minimacplus/disp.c

44 lines
1.1 KiB
C
Raw Normal View History

2017-03-03 07:47:14 +00:00
#include <stdio.h>
#include <stdlib.h>
2017-03-03 08:29:47 +00:00
#include <SDL2/SDL.h>
2017-03-03 07:47:14 +00:00
const int SCREEN_WIDTH = 512;
const int SCREEN_HEIGHT = 342;
SDL_Window* win = NULL;
SDL_Surface* surf = NULL;
SDL_Surface* drwsurf=NULL;
void sdlDie() {
printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError() );
exit(0);
}
void dispInit() {
if (SDL_Init( SDL_INIT_VIDEO ) < 0 ) sdlDie();
win=SDL_CreateWindow( "TME", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
if (win==0) sdlDie();
surf=SDL_GetWindowSurface(win);
drwsurf=SDL_CreateRGBSurfaceWithFormat(0, SCREEN_WIDTH, SCREEN_HEIGHT, 32, SDL_PIXELFORMAT_RGBA32);
}
void dispDraw(char *mem) {
int x, y, z;
SDL_LockSurface(drwsurf);
2017-03-03 08:29:47 +00:00
uint32_t *pixels=(uint32_t*)drwsurf->pixels;
2017-03-03 07:47:14 +00:00
for (y=0; y<SCREEN_HEIGHT; y++) {
for (x=0; x<SCREEN_WIDTH; x+=8) {
2017-03-03 08:29:47 +00:00
for (z=0x80; z!=0; z>>=1) {
if (*mem&z) *pixels=0xFF000000; else *pixels=0xFFFFFFFF;
2017-03-03 07:47:14 +00:00
pixels++;
}
mem++;
}
}
SDL_UnlockSurface(drwsurf);
SDL_BlitSurface(drwsurf, NULL, surf, NULL);
SDL_UpdateWindowSurface(win);
}