aboutsummaryrefslogtreecommitdiff
path: root/gui.c
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2012-04-25 11:39:12 +0000
committerDimitri Sokolyuk <demon@dim13.org>2012-04-25 11:39:12 +0000
commitc1be006a577a45153c5da42c9a511fc4d8992967 (patch)
tree09407f18855b6b9b8924d0b6e4493e5483256e08 /gui.c
parent4b59f442f5163de0956d93b7528fec8266939999 (diff)
switch to font bitmap
Diffstat (limited to 'gui.c')
-rw-r--r--gui.c38
1 files changed, 15 insertions, 23 deletions
diff --git a/gui.c b/gui.c
index c1381c8..b9fb29c 100644
--- a/gui.c
+++ b/gui.c
@@ -22,7 +22,6 @@
#include <stdlib.h>
#include <unistd.h>
#include "dcpu16.h"
-#include "font.h"
SDL_Surface *screen;
@@ -155,7 +154,7 @@ keyboard(unsigned short *m)
void
loadfont(unsigned short *m, char *font)
{
- int w, h, x, y, ch, i, p;
+ int w, h, x, y, ch, i;
SDL_Surface *img;
SDL_Rect frame;
@@ -165,14 +164,20 @@ loadfont(unsigned short *m, char *font)
w = img->w / gl.w;
h = img->h / gl.h;
- for (x = 0; x < img->h; x += 8) {
- for (y = 0; y < img->w; y += 4) {
- ch = 2 * (y / gl.w + x / gl.h * w);
+ for (x = 0; x < w; ++x) {
+ for (y = 0; y < h; ++y) {
+ ch = 2 * (x + y * w);
+ frame.x = x * gl.w;
+ frame.y = y * gl.h;
for (i = 0; i < gl.h; i++) {
- p = !!getpixel(img, x + i, y + 0);
- p = !!getpixel(img, x + i, y + 1);
- p = !!getpixel(img, x + i, y + 2);
- p = !!getpixel(img, x + i, y + 3);
+ if (getpixel(img, frame.x + 0, frame.y + i))
+ m[CHARS + ch + 0] |= (0x0100 << i);
+ if (getpixel(img, frame.x + 1, frame.y + i))
+ m[CHARS + ch + 0] |= (0x0001 << i);
+ if (getpixel(img, frame.x + 2, frame.y + i))
+ m[CHARS + ch + 1] |= (0x0100 << i);
+ if (getpixel(img, frame.x + 3, frame.y + i))
+ m[CHARS + ch + 1] |= (0x0001 << i);
}
}
}
@@ -181,19 +186,6 @@ loadfont(unsigned short *m, char *font)
}
void
-setfont(unsigned short *m)
-{
- int i;
-
- for (i = 0; i < 0x80; i++) {
- m[CHARS + 2 * i] = atari_small[i][0];
- m[CHARS + 2 * i + 1] = atari_small[i][1];
- }
-
- m[BORDER] = 0; /* set default bg to black */
-}
-
-void
guiemu(unsigned short *m, unsigned short *r)
{
int c, n = 0;
@@ -201,7 +193,7 @@ guiemu(unsigned short *m, unsigned short *r)
screen = SDL_SetVideoMode(scr.w, scr.h, 8, SDL_HWSURFACE|SDL_HWPALETTE);
SDL_SetColors(screen, color, 0, 16);
- setfont(m);
+ loadfont(m, "font.xpm");
while ((c = step(m, r)) != -1) {
if ((n += c) < 100)