From bb5452a4a8e50d02efd210c70cb804ce16de9daa Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Wed, 18 Apr 2012 16:32:52 +0000 Subject: keyboard input and preparations for bitmap font --- Makefile | 2 +- gui.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 12c59f8..e062c15 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ PROG= dcpu SRCS= gramar.y lexer.l emu.c main.c tui.c gui.c y.tab.h NOMAN= CFLAGS+=`sdl-config --cflags` -LDADD+= `sdl-config --libs` -lcurses +LDADD+= `sdl-config --libs` -lcurses -lSDL_image DEBUG+= -Wall #DEBUG+= -ggdb -pg #YFLAGS= -dtv diff --git a/gui.c b/gui.c index 90cb7a0..71daf27 100644 --- a/gui.c +++ b/gui.c @@ -16,6 +16,7 @@ */ #include +#include #include #include #include @@ -37,9 +38,6 @@ Uint32 amask = 0xff000000; SDL_Surface *screen; -SDL_Rect disp = { 0, 0, 640, 480 }; -SDL_Rect out = { 64, 48, 640, 480 }; - SDL_Rect draw = { 16, 12, 128, 96 }; SDL_Rect scr = { 0, 0, 160, 120 }; SDL_Rect gl = { 0, 0, 4, 8 }; @@ -77,9 +75,18 @@ setpixel(SDL_Surface *s, int x, int y, SDL_Color *c) { Uint32 *buf = (Uint32 *)s->pixels + y * (s->pitch >> 2) + x; Uint32 pixel = SDL_MapRGB(s->format, c->r, c->g, c->b); + *buf = pixel; } +Uint32 +getpixel(SDL_Surface *s, int x, int y) +{ + Uint32 *buf = (Uint32 *)s->pixels + y * (s->pitch >> 2) + x; + + return *buf; +} + void fillrect(SDL_Surface *s, SDL_Rect *r, SDL_Color *c) { @@ -116,6 +123,31 @@ mkglyph(unsigned char ch, SDL_Color *fg, SDL_Color *bg, unsigned short *m) return g; } +#if 0 +void +loadfont(unsigned short *m, char *font) +{ + int w, h, x, y, ch; + + SDL_Surface *img; + SDL_Rect frame; + + img = IMG_Load(font); + + w = img->w / 4; + h = img->h / 8; + + for (x = 0; x < img->h; x += 8) { + for (y = 0; y < img->w; y += 4) { + ch = y / 4 + x / 8 * w; + //printf("%d\n", ch); + } + } + + SDL_FreeSurface(img); +} +#endif + void setfont(unsigned short *m) { @@ -174,8 +206,26 @@ guiemu(unsigned short *m, unsigned short *r) case SDL_QUIT: goto leave; case SDL_KEYDOWN: - m[KEYB + k] = event.key.keysym.sym; - printf("%x\n", m[KEYB + k]); + switch (event.key.keysym.sym) { + case SDLK_UP: + m[KEYB + k] = 38; + break; + case SDLK_DOWN: + m[KEYB + k] = 40; + break; + case SDLK_LEFT: + m[KEYB + k] = 37; + break; + case SDLK_RIGHT: + m[KEYB + k] = 39; + break; + default: + m[KEYB + k] = event.key.keysym.sym; + if (event.key.keysym.mod & KMOD_SHIFT) + m[KEYB + k] -= 0x20; + break; + } + printf("%d\n", m[KEYB + k]); k = (k + 1) % 0x10; break; } -- cgit v1.2.3