1
2
3
4
5
6
7
8
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
/*
ds81 - Nintendo DS ZX81 emulator.
Copyright (C) 2006 Ian Cowburn <ianc@noddybox.co.uk>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
$Id$
*/
#include <nds.h>
#include <string.h>
#include "ds81_global.h"
/* ---------------------------------------- STATIC DATA
*/
#define WIDTH 256
#define HEIGHT 192
static uint16 *buff=0;
static uint8 font[]=
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x08, 0x08, 0x08, 0x08, 0x00, 0x08, 0x00,
0x00, 0x24, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x24, 0x7e, 0x24, 0x24, 0x7e, 0x24, 0x00,
0x00, 0x10, 0x7c, 0x14, 0x7c, 0x50, 0x7c, 0x10,
0x00, 0x46, 0x26, 0x10, 0x08, 0x64, 0x62, 0x00,
0x00, 0x08, 0x14, 0x08, 0x54, 0x22, 0x5c, 0x00,
0x00, 0x10, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x20, 0x10, 0x10, 0x10, 0x10, 0x20, 0x00,
0x00, 0x04, 0x08, 0x08, 0x08, 0x08, 0x04, 0x00,
0x00, 0x00, 0x28, 0x10, 0x7c, 0x10, 0x28, 0x00,
0x00, 0x00, 0x10, 0x10, 0x7c, 0x10, 0x10, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x08,
0x00, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00,
0x00, 0x00, 0x40, 0x20, 0x10, 0x08, 0x04, 0x00,
0x00, 0x3c, 0x62, 0x52, 0x4a, 0x46, 0x3c, 0x00,
0x00, 0x18, 0x14, 0x10, 0x10, 0x10, 0x7c, 0x00,
0x00, 0x3c, 0x42, 0x40, 0x3c, 0x02, 0x7e, 0x00,
0x00, 0x3c, 0x42, 0x30, 0x40, 0x42, 0x3c, 0x00,
0x00, 0x10, 0x18, 0x14, 0x12, 0x7e, 0x10, 0x00,
0x00, 0x7e, 0x02, 0x3e, 0x40, 0x42, 0x3c, 0x00,
0x00, 0x3c, 0x02, 0x3e, 0x42, 0x42, 0x3c, 0x00,
0x00, 0x7e, 0x40, 0x20, 0x10, 0x08, 0x08, 0x00,
0x00, 0x3c, 0x42, 0x3c, 0x42, 0x42, 0x3c, 0x00,
0x00, 0x3c, 0x42, 0x42, 0x7c, 0x40, 0x3c, 0x00,
0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00,
0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x08, 0x04,
0x00, 0x00, 0x20, 0x10, 0x08, 0x10, 0x20, 0x00,
0x00, 0x00, 0x00, 0x7c, 0x00, 0x7c, 0x00, 0x00,
0x00, 0x00, 0x08, 0x10, 0x20, 0x10, 0x08, 0x00,
0x00, 0x3c, 0x42, 0x20, 0x10, 0x00, 0x10, 0x00,
0x00, 0x3c, 0x52, 0x6a, 0x7a, 0x02, 0x3c, 0x00,
0x00, 0x3c, 0x42, 0x42, 0x7e, 0x42, 0x42, 0x00,
0x00, 0x3e, 0x42, 0x3e, 0x42, 0x42, 0x3e, 0x00,
0x00, 0x3c, 0x42, 0x02, 0x02, 0x42, 0x3c, 0x00,
0x00, 0x1e, 0x22, 0x42, 0x42, 0x22, 0x1e, 0x00,
0x00, 0x7e, 0x02, 0x3e, 0x02, 0x02, 0x7e, 0x00,
0x00, 0x7e, 0x02, 0x3e, 0x02, 0x02, 0x02, 0x00,
0x00, 0x3c, 0x42, 0x02, 0x72, 0x42, 0x3c, 0x00,
0x00, 0x42, 0x42, 0x7e, 0x42, 0x42, 0x42, 0x00,
0x00, 0x7c, 0x10, 0x10, 0x10, 0x10, 0x7c, 0x00,
0x00, 0x40, 0x40, 0x40, 0x42, 0x42, 0x3c, 0x00,
0x00, 0x22, 0x12, 0x0e, 0x12, 0x22, 0x42, 0x00,
0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x7e, 0x00,
0x00, 0x42, 0x66, 0x5a, 0x42, 0x42, 0x42, 0x00,
0x00, 0x42, 0x46, 0x4a, 0x52, 0x62, 0x42, 0x00,
0x00, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x00,
0x00, 0x3e, 0x42, 0x42, 0x3e, 0x02, 0x02, 0x00,
0x00, 0x3c, 0x42, 0x42, 0x4a, 0x52, 0x3c, 0x00,
0x00, 0x3e, 0x42, 0x42, 0x3e, 0x22, 0x42, 0x00,
0x00, 0x3c, 0x02, 0x3c, 0x40, 0x42, 0x3c, 0x00,
0x00, 0x7f, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00,
0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x00,
0x00, 0x42, 0x42, 0x42, 0x42, 0x24, 0x18, 0x00,
0x00, 0x42, 0x42, 0x42, 0x42, 0x5a, 0x24, 0x00,
0x00, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x00,
0x00, 0x41, 0x22, 0x14, 0x08, 0x08, 0x08, 0x00,
0x00, 0x7e, 0x20, 0x10, 0x08, 0x04, 0x7e, 0x00,
0x00, 0x70, 0x10, 0x10, 0x10, 0x10, 0x70, 0x00,
0x00, 0x00, 0x02, 0x04, 0x08, 0x10, 0x20, 0x00,
0x00, 0x0e, 0x08, 0x08, 0x08, 0x08, 0x0e, 0x00,
0x00, 0x08, 0x1c, 0x2a, 0x08, 0x08, 0x08, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
0x00, 0x38, 0x44, 0x1e, 0x04, 0x04, 0x7e, 0x00,
0x00, 0x00, 0x1c, 0x20, 0x3c, 0x22, 0x3c, 0x00,
0x00, 0x04, 0x04, 0x3c, 0x44, 0x44, 0x3c, 0x00,
0x00, 0x00, 0x38, 0x04, 0x04, 0x04, 0x38, 0x00,
0x00, 0x20, 0x20, 0x3c, 0x22, 0x22, 0x3c, 0x00,
0x00, 0x00, 0x1c, 0x22, 0x1e, 0x02, 0x3c, 0x00,
0x00, 0x30, 0x08, 0x18, 0x08, 0x08, 0x08, 0x00,
0x00, 0x00, 0x3c, 0x22, 0x22, 0x3c, 0x20, 0x1c,
0x00, 0x02, 0x02, 0x1e, 0x22, 0x22, 0x22, 0x00,
0x00, 0x08, 0x00, 0x0c, 0x08, 0x08, 0x1c, 0x00,
0x00, 0x20, 0x00, 0x20, 0x20, 0x20, 0x24, 0x18,
0x00, 0x04, 0x14, 0x0c, 0x0c, 0x14, 0x24, 0x00,
0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x30, 0x00,
0x00, 0x00, 0x16, 0x2a, 0x2a, 0x2a, 0x2a, 0x00,
0x00, 0x00, 0x1e, 0x22, 0x22, 0x22, 0x22, 0x00,
0x00, 0x00, 0x1c, 0x22, 0x22, 0x22, 0x1c, 0x00,
0x00, 0x00, 0x1e, 0x22, 0x22, 0x1e, 0x02, 0x02,
0x00, 0x00, 0x3c, 0x22, 0x22, 0x3c, 0x20, 0x60,
0x00, 0x00, 0x38, 0x04, 0x04, 0x04, 0x04, 0x00,
0x00, 0x00, 0x1c, 0x02, 0x1c, 0x20, 0x1e, 0x00,
0x00, 0x08, 0x1c, 0x08, 0x08, 0x08, 0x30, 0x00,
0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x1c, 0x00,
0x00, 0x00, 0x22, 0x22, 0x14, 0x14, 0x08, 0x00,
0x00, 0x00, 0x22, 0x2a, 0x2a, 0x2a, 0x14, 0x00,
0x00, 0x00, 0x22, 0x14, 0x08, 0x14, 0x22, 0x00,
0x00, 0x00, 0x22, 0x22, 0x22, 0x3c, 0x20, 0x1c,
0x00, 0x00, 0x3e, 0x10, 0x08, 0x04, 0x3e, 0x00,
0x00, 0x70, 0x10, 0x0c, 0x10, 0x10, 0x70, 0x00,
0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00,
0x00, 0x0e, 0x08, 0x30, 0x08, 0x08, 0x0e, 0x00,
0x00, 0x28, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00,
0x3c, 0x42, 0x99, 0x85, 0x85, 0x99, 0x42, 0x3c
};
/* ---------------------------------------- PUBLIC INTERFACES
*/
void FB_Init(uint16 *vram)
{
buff=vram;
}
void FB_Print(const char *text, int x, int y, int colour, int paper)
{
uint16 *base;
base=buff+y*WIDTH+x;
while(*text)
{
int x,y;
int ch;
ch=((*text)-32)*8;
for(y=0;y<8;y++)
{
for(x=0;x<8;x++)
{
if (font[ch]&(1<<x))
{
*(base+x+y*WIDTH)=colour;
}
else
{
if (paper!=-1)
{
*(base+x+y*WIDTH)=paper;
}
}
}
ch++;
}
base+=8;
text++;
}
}
void FB_Centre(const char *text, int y, int colour, int paper)
{
FB_Print(text,WIDTH/2-strlen(text)*4,y,colour,paper);
}
void FB_HLine(int x1, int x2, int y, int colour)
{
uint16 *line;
line=buff+y*WIDTH+x1;
while(x1<=x2)
{
*line++=colour;
x1++;
}
}
void FB_VLine(int x, int y1, int y2, int colour)
{
uint16 *line;
line=buff+y1*WIDTH+x;
while(y1<=y2)
{
*line=colour;
line+=WIDTH;
y1++;
}
}
void FB_Box(int x, int y, int w, int h, int colour)
{
FB_HLine(x,x+w-1,y,colour);
FB_HLine(x,x+w-1,y+h-1,colour);
FB_VLine(x,y,y+h-1,colour);
FB_VLine(x+w-1,y,y+h-1,colour);
}
void FB_FillBox(int x, int y, int w, int h, int colour)
{
int f;
uint16 *base;
base=buff+x+y*WIDTH;
while(h--)
{
for(f=0;f<w;f++)
{
*(base+f)=colour;
}
base+=WIDTH;
}
}
void FB_Clear(void)
{
uint16 *p;
int f;
f=WIDTH*HEIGHT;
p=buff;
while(f--)
{
*p++=0x8000;
}
}
void FB_Blit(sImage *img, int x, int y)
{
if (img->width==WIDTH && img->height==HEIGHT)
{
dmaCopy(img->data8,buff,SCREEN_WIDTH*SCREEN_HEIGHT*2);
}
else
{
int f;
for(f=0;f<img->height;f++)
{
dmaCopy(img->data16+(f*img->width),
buff+x+(y+f)*WIDTH,img->width*2);
}
}
}
|