-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdebug_dc.c
More file actions
executable file
·217 lines (186 loc) · 4.46 KB
/
debug_dc.c
File metadata and controls
executable file
·217 lines (186 loc) · 4.46 KB
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
/*
* Licensed under the BSD license
*
* debug_32x.c - Debug screen functions.
*
* Copyright (c) 2005 Marcus R. Brown <mrbrown@ocgnet.org>
* Copyright (c) 2005 James Forshaw <tyranid@gmail.com>
* Copyright (c) 2005 John Kelley <ps2dev@kelley.ca>
*
* Altered for DC by Chilly Willy
*/
#include <kos.h>
#include <dc/video.h>
#include <dc/biosfont.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
static int X = 0, Y = 0;
static int MX = 53, MY = 20;
static int SW = 640, SH = 480;
static int vmode = DM_640x480, pmode = PM_RGB565;
static unsigned int fgc = 0xFFFFFF, bgc = 0x000000;
/* Defines to convert colors */
#define MAKE_RGB555(c) (((c & 0xF80000)>>9)|((c & 0x00F800)>>6)|((c & 0x0000F8)>>3))
#define MAKE_RGB565(c) (((c & 0xF80000)>>8)|((c & 0x00FC00)>>5)|((c & 0x0000F8)>>3))
// pass a generic mode and the pixel mode - it doesn't set the video mode,
// it merely assumes the values describe the mode already set
void DebugDC_Init(int vidmode, int pixmode)
{
if (vmode == vidmode && pmode == pixmode)
return;
if (vidmode == -1)
{
vmode = pmode = -1;
return;
}
switch(vidmode)
{
case DM_320x240:
SW = 320;
SH = 240;
break;
case DM_640x480:
SW = 640;
SH = 480;
break;
case DM_256x256:
SW = 256;
SH = 256;
break;
case DM_768x480:
SW = 768;
SH = 480;
break;
case DM_768x576:
SW = 768;
SH = 576;
break;
}
MX = SW / 12;
MY = SH / 24;
fgc = 0xFFFFFF;
bgc = 0x000000;
X = Y = 0;
vmode = vidmode;
pmode = pixmode;
}
void DebugDC_SetFGColor(int r, int g, int b)
{
if (vmode == -1)
return;
fgc = 0xFF<<24 | r<<16 | g<<8 | b;
if (pmode == PM_RGB888)
bfont_set_foreground_color(fgc);
else if (pmode == PM_RGB565)
bfont_set_foreground_color(MAKE_RGB565(fgc));
else
bfont_set_foreground_color(MAKE_RGB555(fgc));
}
void DebugDC_SetBGColor(int r, int g, int b)
{
if (vmode == -1)
return;
bgc = 0xFF<<24 | r<<16 | g<<8 | b;
if (pmode == PM_RGB888)
bfont_set_background_color(bgc);
else if (pmode == PM_RGB565)
bfont_set_background_color(MAKE_RGB565(bgc));
else
bfont_set_background_color(MAKE_RGB555(bgc));
}
int DebugDC_ScreenGetX()
{
return X;
}
int DebugDC_ScreenGetY()
{
return Y;
}
void DebugDC_ScreenClear()
{
if (vmode == -1)
return;
vid_clear(bgc>>16, (bgc>>8) & 0xFF, bgc & 0xFF);
}
void DebugDC_ScreenSetXY(int x, int y)
{
if(x<MX && x>=0) X = x;
if(y<MY && y>=0) Y = y;
}
static void debug_put_char_16(int x, int y, unsigned char ch)
{
if (vmode == -1)
return;
bfont_draw_thin((uint16 *)((uint32)vram_s + (x * 12 + y * 24 * SW) * 2), SW, 1, ch, 0);
}
static void debug_put_char_32(int x, int y, unsigned char ch)
{
if (vmode == -1)
return;
bfont_draw_thin((uint16 *)((uint32)vram_l + (x * 12 + y * 24 * SW) * 4), SW, 1, ch, 0);
}
void DebugDC_ScreenPutChar(int x, int y, unsigned char ch)
{
if (pmode != PM_RGB888)
debug_put_char_16(x, y, ch);
else
debug_put_char_32(x, y, ch);
}
void DebugDC_ScreenClearLine(int Y)
{
int i;
for (i=0; i < MX; i++)
DebugDC_ScreenPutChar(i, Y, ' ');
}
/* Print non-nul terminated strings */
int DebugDC_ScreenPrintData(const char *buff, int size)
{
int i;
int j;
char c;
for (i=0; i<size; i++)
{
c = buff[i];
switch (c)
{
case '\r':
X = 0;
break;
case '\n':
X = 0;
Y++;
if (Y == MY)
Y = 0;
DebugDC_ScreenClearLine(Y);
break;
case '\t':
for (j=0; j<4; j++)
{
DebugDC_ScreenPutChar(X, Y, ' ');
X++;
}
break;
default:
DebugDC_ScreenPutChar(X, Y, c);
X++;
if (X == MX)
{
X = 0;
Y++;
if (Y == MY)
Y = 0;
DebugDC_ScreenClearLine(Y);
}
}
}
return i;
}
int DebugDC_ScreenPuts(const char *str)
{
return DebugDC_ScreenPrintData(str, strlen(str));
}
void DebugDC_Delay(int ticks)
{
thd_sleep(ticks*20);
}