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 $ */
2
2
/*
3
3
* Copyright (c) 2012 Dimitri Sokolyuk <[email protected] >
4
4
*
22
22
#include <stdlib.h>
23
23
#include <unistd.h>
24
24
#include "dcpu16.h"
25
- #include "font.h"
26
25
27
26
SDL_Surface * screen ;
28
27
@@ -155,7 +154,7 @@ keyboard(unsigned short *m)
155
154
void
156
155
loadfont (unsigned short * m , char * font )
157
156
{
158
- int w , h , x , y , ch , i , p ;
157
+ int w , h , x , y , ch , i ;
159
158
160
159
SDL_Surface * img ;
161
160
SDL_Rect frame ;
@@ -165,34 +164,27 @@ loadfont(unsigned short *m, char *font)
165
164
w = img -> w / gl .w ;
166
165
h = img -> h / gl .h ;
167
166
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 ;
171
172
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 );
176
181
}
177
182
}
178
183
}
179
184
180
185
SDL_FreeSurface (img );
181
186
}
182
187
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
-
196
188
void
197
189
guiemu (unsigned short * m , unsigned short * r )
198
190
{
@@ -201,7 +193,7 @@ guiemu(unsigned short *m, unsigned short *r)
201
193
screen = SDL_SetVideoMode (scr .w , scr .h , 8 , SDL_HWSURFACE |SDL_HWPALETTE );
202
194
SDL_SetColors (screen , color , 0 , 16 );
203
195
204
- setfont ( m );
196
+ loadfont ( m , "font.xpm" );
205
197
206
198
while ((c = step (m , r )) != -1 ) {
207
199
if ((n += c ) < 100 )
0 commit comments