-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui.cpp
313 lines (258 loc) · 6.67 KB
/
gui.cpp
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
#include <stdio.h>
#include "video.h"
/*
* gui.cpp
*
* Author: Massimiliano Petra <[email protected]> April, 2020
*
*
* 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.
*
*/
#include "gui.h"
#include "system_io.h"
#include "memory.h"
#define DRV1STARTX 10
#define DRV2STARTX 100
#define DRV1STARTY (SCREEN_HEIGHT+30)
#define DRV2STARTY (SCREEN_HEIGHT+30)
#define HRAMSTARTX 180
#define HRAMSTARTY (SCREEN_HEIGHT+30)
drawchar(int x,int y,uint8_t c, uint8_t r, uint8_t g, uint8_t b,uint8_t big)
{
int i,j;
uint8_t char_byte;
SDL_SetRenderDrawColor(Main_Renderer, r, g, b, 255);
// ASCII Translation
if (c >= '@')
{
c = c - '@';
}
else
{
c = c - ' '+32;
}
for (i=0;i<8;i++)
{
char_byte = _CHARROM[c*8+i] & 0b01111110;
for (j = 0; j<8;j++)
{
if (REVERSE_CHAR_ROM)
{
if (char_byte & 0x01)
{
if (big)
{
SDL_RenderDrawPoint(Main_Renderer, x+j*2, y+i*2);
SDL_RenderDrawPoint(Main_Renderer, x+j*2+1, y+i*2);
SDL_RenderDrawPoint(Main_Renderer, x+j*2, y+i*2+1);
SDL_RenderDrawPoint(Main_Renderer, x+j*2+1, y+i*2+1);
}
else
SDL_RenderDrawPoint(Main_Renderer, x+j, y+i);
}
char_byte = char_byte >> 1;
}
else
{
if (char_byte & 0x80)
{
if (big)
{
SDL_RenderDrawPoint(Main_Renderer, x+j*2, y+i*2);
SDL_RenderDrawPoint(Main_Renderer, x+j*2+1, y+i*2);
SDL_RenderDrawPoint(Main_Renderer, x+j*2, y+i*2+1);
SDL_RenderDrawPoint(Main_Renderer, x+j*2+1, y+i*2+1);
}
else
SDL_RenderDrawPoint(Main_Renderer, x+j, y+i);
}
char_byte = char_byte << 1;
}
}
}
}
drawstring(int x,int y,char *s, uint8_t r, uint8_t g, uint8_t b,uint8_t big)
{
int i=0;
while(s[i] != '\0')
{
drawchar(x,y,s[i],r,g,b,big);
if (big)
x += 16;
else
x += 9;
i++;
}
}
void initgui()
{
// Clear GUI
SDL_Rect rect;
rect.x = 0;
rect.y = SCREEN_HEIGHT;
rect.w = SCREEN_WIDTH;
rect.h = SCREEN_HEIGHT_DBG-SCREEN_HEIGHT;
SDL_SetRenderDrawColor(Main_Renderer, 150, 150, 150, 255);
SDL_RenderFillRect(Main_Renderer, &rect);
rect.x = 0+4;
rect.y = SCREEN_HEIGHT+4;
rect.w = SCREEN_WIDTH-8;
rect.h = SCREEN_HEIGHT_DBG-SCREEN_HEIGHT-8;
SDL_SetRenderDrawColor(Main_Renderer, 0, 0, 0, 255);
SDL_RenderDrawRect(Main_Renderer, &rect);
// DISK II
drawstring(DRV1STARTX+20,DRV1STARTY-21,"DISK II",0,0,0,1);
// DRIVE1
rect.x = DRV1STARTX;
rect.y = DRV1STARTY;
rect.w = 60;
rect.h = 20;
SDL_SetRenderDrawColor(Main_Renderer, 80, 80, 80, 255);
SDL_RenderFillRect(Main_Renderer, &rect);
SDL_SetRenderDrawColor(Main_Renderer, 0, 0, 0, 255);
SDL_RenderDrawRect(Main_Renderer, &rect);
rect.x = DRV1STARTX+20;
rect.y = DRV1STARTY+8;
rect.w = 16;
rect.h = 4;
SDL_SetRenderDrawColor(Main_Renderer, 0, 0, 0, 255);
SDL_RenderFillRect(Main_Renderer, &rect);
SDL_RenderDrawLine(Main_Renderer, DRV1STARTX+10,DRV1STARTY+9,DRV1STARTX+50,DRV1STARTY+9);
// DRIVE2
rect.x = DRV2STARTX;
rect.y = DRV2STARTY;
rect.w = 60;
rect.h = 20;
SDL_SetRenderDrawColor(Main_Renderer, 80, 80, 80, 255);
SDL_RenderFillRect(Main_Renderer, &rect);
SDL_SetRenderDrawColor(Main_Renderer, 0, 0, 0, 255);
SDL_RenderDrawRect(Main_Renderer, &rect);
rect.x = DRV2STARTX+20;
rect.y = DRV2STARTY+8;
rect.w = 16;
rect.h = 4;
SDL_SetRenderDrawColor(Main_Renderer, 0, 0, 0, 255);
SDL_RenderFillRect(Main_Renderer, &rect);
SDL_RenderDrawLine(Main_Renderer, DRV2STARTX+10,DRV2STARTY+9,DRV2STARTX+50,DRV2STARTY+9);
// HRAM
drawstring(HRAMSTARTX-2,HRAMSTARTY-21,"HRAM",0,0,0,1);
drawchar(HRAMSTARTX+5,HRAMSTARTY+10,'R',0,0,0,0);
drawchar(HRAMSTARTX+18,HRAMSTARTY+10,'W',0,0,0,0);
drawchar(HRAMSTARTX+31,HRAMSTARTY+10,'1',0,0,0,0);
drawchar(HRAMSTARTX+44,HRAMSTARTY+10,'2',0,0,0,0);
rect.x = HRAMSTARTX;
rect.y = HRAMSTARTY;
rect.w = 62;
rect.h = 20;
SDL_SetRenderDrawColor(Main_Renderer, 0, 0, 0, 255);
SDL_RenderDrawRect(Main_Renderer, &rect);
SDL_UpdateWindowSurface(window);
}
void refreshgui()
{
SDL_Rect rect;
uint8_t _activedrv;
uint8_t _pwr1;
int8_t _halftrk1;
uint16_t _ptr1;
uint8_t _pwr2;
int8_t _halftrk2;
uint16_t _ptr2;
IO->diskdebug(&_activedrv,&_pwr1,&_halftrk1,&_ptr1,&_pwr2,&_halftrk2,&_ptr2);
// DRIVE1 POWER LED
rect.x = DRV1STARTX+50;
rect.y = DRV1STARTY+4;
rect.w = 6;
rect.h = 4;
if (_pwr1)
{
SDL_SetRenderDrawColor(Main_Renderer, 255, 00, 00, 255);
}
else
{
SDL_SetRenderDrawColor(Main_Renderer, 70, 00, 00, 255);
}
SDL_RenderFillRect(Main_Renderer, &rect);
// DRIVE2 POWER LED
rect.x = DRV2STARTX+50;
rect.y = DRV2STARTY+4;
rect.w = 6;
rect.h = 4;
if (_pwr2)
{
SDL_SetRenderDrawColor(Main_Renderer, 255, 00, 00, 255);
}
else
{
SDL_SetRenderDrawColor(Main_Renderer, 70, 00, 00, 255);
}
SDL_RenderFillRect(Main_Renderer, &rect);
// HRAM POWER LED
rect.x = HRAMSTARTX+6;
rect.y = HRAMSTARTY+4;
rect.w = 6;
rect.h = 4;
if (mem->getHRAMRD())
{
SDL_SetRenderDrawColor(Main_Renderer, 00, 255, 00, 255);
}
else
{
SDL_SetRenderDrawColor(Main_Renderer, 00, 70, 00, 255);
}
SDL_RenderFillRect(Main_Renderer, &rect);
rect.x = HRAMSTARTX+19;
rect.y = HRAMSTARTY+4;
rect.w = 6;
rect.h = 4;
if (mem->getHRAMWRT() == 0)
{
SDL_SetRenderDrawColor(Main_Renderer, 00, 255, 00, 255);
}
else
{
SDL_SetRenderDrawColor(Main_Renderer, 00, 70, 00, 255);
}
SDL_RenderFillRect(Main_Renderer, &rect);
rect.x = HRAMSTARTX+32;
rect.y = HRAMSTARTY+4;
rect.w = 6;
rect.h = 4;
if (mem->getBANK1() != 0)
{
SDL_SetRenderDrawColor(Main_Renderer, 255, 00, 00, 255);
}
else
{
SDL_SetRenderDrawColor(Main_Renderer, 70, 00, 00, 255);
}
SDL_RenderFillRect(Main_Renderer, &rect);
rect.x = HRAMSTARTX+45;
rect.y = HRAMSTARTY+4;
rect.w = 6;
rect.h = 4;
if (mem->getBANK1() == 0)
{
SDL_SetRenderDrawColor(Main_Renderer, 255, 00, 00, 255);
}
else
{
SDL_SetRenderDrawColor(Main_Renderer, 70, 00, 00, 255);
}
SDL_RenderFillRect(Main_Renderer, &rect);
SDL_UpdateWindowSurface(window);
}