Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.

Commit 05970d5

Browse files
author
demon
committed
switch to font bitmap
1 parent 32e6caa commit 05970d5

File tree

3 files changed

+57
-161
lines changed

3 files changed

+57
-161
lines changed

font.h

-137
This file was deleted.

font.xpm

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/* XPM */
2+
static char *font[] = {
3+
/* width height ncolors chars_per_pixel */
4+
"128 32 2 1",
5+
/* colors */
6+
" c black",
7+
". c white",
8+
/* pixels */
9+
" . . . . . . . . . . . . . . . . . . . . . . . . . .... .. ......",
10+
" . . . . . . . . . . . . . . . . . . . . . . . . . .... .. ......",
11+
" . . . . .... . . ....... ....... ....... ....... . .... . . ... ... . . .... . .... .. ......",
12+
" ........... ........... . . ... . . .... ........ . . ........ . .. ....... .. ......",
13+
" . . . .... . ..... ....... ... ....... ...... ..... . ... .... . . . .... . .......... .. ",
14+
" . . . . . . . . . . . . . . . . . . . . . . . . .......... .. ",
15+
" . . . . . . . . . . . . . . . . . . . . . . . . .......... .. ",
16+
" . . . . . . . . . . . . . . . . . . . . . . . . .......... .. ",
17+
" . . . . . . . . . . . . . . . . . ... . ... . . . . . ",
18+
" . . . . . ... . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . ",
19+
" . ... . . . . . . . . . . . . . . . . .. . . . . . . . . . ... . . ",
20+
" . . . . . . . . ... ... ... . . . . . . ... . .. . . .. . . . ",
21+
" . ... . . . .. . . . . . . . . . . . . . . . . . . . ... . . ",
22+
" . . ... . ... . . . . . . . . . . . . . . . . . . . . . . . . . . . ",
23+
" . . . . .. . . . . . . ... ... . . . . . . . . . . . ",
24+
" ",
25+
" . . .. . .. ... ... . . . ... . . . . . . .. . .. . .. . ... . . . . . . . . . . ... .. . .. . ",
26+
". . . . . . . . . . . . . . . . . . . . . ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ",
27+
". . . . . . . . . . . . . . . . .. . ... . . . . . . . . . . . . . . . . . . . . . . . . . . ",
28+
"... ... .. . . . .. .. ... ... . . .. . . . . . . . .. . . .. . . . . . . . . . . . . . . ",
29+
"... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ... . . . . . . . ",
30+
". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ... . . . . . . . ",
31+
" .. . . .. . .. ... . . . . ... . . . ... . . . . . . . . . . . ... . . . . . . ... .. . .. ",
32+
" . ... ",
33+
" . . . . . . . . .. . . . . . ",
34+
" . . . . . . . . . . . . . ",
35+
" .. .. . .. . . .. .. .. . . . . . . .. . .. .. .. .. ... . . . . . . . . . . ... . . . . ",
36+
" . . . . . . . . . ... . . . . . . . . . ... . . . . . . . . . . . . . . . . . . . . . . . . . . ",
37+
" .. . . . . . ... . .. . . . . .. . ... . . . . .. .. . . . . . . . ... . .. . . . . . . ",
38+
" . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ... . . . . . . . . . ",
39+
" .. .. . .. .. . .. . . ... . . . ... . . . . . . . . .. . .. . . . . . .. ... . . . ... ",
40+
" "
41+
};

gui.c

+16-24
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Id: gui.c,v 1.11 2012/04/23 21:44:33 demon Exp $ */
1+
/* $Id: gui.c,v 1.12 2012/04/25 11:39:12 demon Exp $ */
22
/*
33
* Copyright (c) 2012 Dimitri Sokolyuk <[email protected]>
44
*
@@ -22,7 +22,6 @@
2222
#include <stdlib.h>
2323
#include <unistd.h>
2424
#include "dcpu16.h"
25-
#include "font.h"
2625

2726
SDL_Surface *screen;
2827

@@ -155,7 +154,7 @@ keyboard(unsigned short *m)
155154
void
156155
loadfont(unsigned short *m, char *font)
157156
{
158-
int w, h, x, y, ch, i, p;
157+
int w, h, x, y, ch, i;
159158

160159
SDL_Surface *img;
161160
SDL_Rect frame;
@@ -165,34 +164,27 @@ loadfont(unsigned short *m, char *font)
165164
w = img->w / gl.w;
166165
h = img->h / gl.h;
167166

168-
for (x = 0; x < img->h; x += 8) {
169-
for (y = 0; y < img->w; y += 4) {
170-
ch = 2 * (y / gl.w + x / gl.h * w);
167+
for (x = 0; x < w; ++x) {
168+
for (y = 0; y < h; ++y) {
169+
ch = 2 * (x + y * w);
170+
frame.x = x * gl.w;
171+
frame.y = y * gl.h;
171172
for (i = 0; i < gl.h; i++) {
172-
p = !!getpixel(img, x + i, y + 0);
173-
p = !!getpixel(img, x + i, y + 1);
174-
p = !!getpixel(img, x + i, y + 2);
175-
p = !!getpixel(img, x + i, y + 3);
173+
if (getpixel(img, frame.x + 0, frame.y + i))
174+
m[CHARS + ch + 0] |= (0x0100 << i);
175+
if (getpixel(img, frame.x + 1, frame.y + i))
176+
m[CHARS + ch + 0] |= (0x0001 << i);
177+
if (getpixel(img, frame.x + 2, frame.y + i))
178+
m[CHARS + ch + 1] |= (0x0100 << i);
179+
if (getpixel(img, frame.x + 3, frame.y + i))
180+
m[CHARS + ch + 1] |= (0x0001 << i);
176181
}
177182
}
178183
}
179184

180185
SDL_FreeSurface(img);
181186
}
182187

183-
void
184-
setfont(unsigned short *m)
185-
{
186-
int i;
187-
188-
for (i = 0; i < 0x80; i++) {
189-
m[CHARS + 2 * i] = atari_small[i][0];
190-
m[CHARS + 2 * i + 1] = atari_small[i][1];
191-
}
192-
193-
m[BORDER] = 0; /* set default bg to black */
194-
}
195-
196188
void
197189
guiemu(unsigned short *m, unsigned short *r)
198190
{
@@ -201,7 +193,7 @@ guiemu(unsigned short *m, unsigned short *r)
201193
screen = SDL_SetVideoMode(scr.w, scr.h, 8, SDL_HWSURFACE|SDL_HWPALETTE);
202194
SDL_SetColors(screen, color, 0, 16);
203195

204-
setfont(m);
196+
loadfont(m, "font.xpm");
205197

206198
while ((c = step(m, r)) != -1) {
207199
if ((n += c) < 100)

0 commit comments

Comments
 (0)