-
Notifications
You must be signed in to change notification settings - Fork 0
/
machina.c
326 lines (275 loc) · 6.33 KB
/
machina.c
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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
/*
BSD 3-Clause License
Copyright (c) 2023, Thomas DiModica
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "machina.h"
#define BASE_PAGE_RESERVED 8;
#define BASE_PAGE_NORMAL 10;
#ifdef __GNUC__
static int storePage;
static char store [8192 * 63]; // The whole 512K available to the X16.
void setStorePageReserved(byte pageNo)
{
storePage = pageNo + BASE_PAGE_RESERVED;
storePage <<= 13;
}
void setStorePage(byte pageNo)
{
storePage = pageNo + BASE_PAGE_NORMAL;
storePage <<= 13;
}
char* getStore(byte indexInCurrentPage)
{
int location = indexInCurrentPage;
location <<= 7;
location |= storePage;
return &store[location];
}
#ifndef __MINGW32__
#include <curses.h>
void platformInitializeScreen (void)
{
initscr();
start_color();
cbreak();
keypad(stdscr, TRUE);
noecho();
nonl();
init_pair(COLOR_HEADER, COLOR_BLACK, COLOR_WHITE);
init_pair(COLOR_NORMAL, COLOR_WHITE, COLOR_BLUE);
init_pair(COLOR_HIGHLIGHT, COLOR_BLUE, COLOR_BLACK);
}
void platformScreensize (byte* x, byte* y)
{
int X, Y;
getmaxyx(stdscr, Y, X);
*x = X;
*y = Y;
}
void platformGotoxy (byte x, byte y)
{
move(y, x);
}
void platformColors (byte pair)
{
attron(COLOR_PAIR(pair));
}
byte platformGetch (void)
{
// I just noticed that I never call refresh in the main UpdateScreen loop.
// It gets called implicitly here, because the window has been modified. The more you know.
// I don't particularly like this, but I don't want to add another phony function to waste
// RAM on the CX16.
int ch = getch();
switch (ch)
{
case KEY_BACKSPACE:
ch = '\b';
break;
case KEY_UP:
ch = 145;
break;
case KEY_DOWN:
ch = 17;
break;
case KEY_LEFT:
ch = 157;
break;
case KEY_RIGHT:
ch = 29;
break;
case KEY_HOME:
ch = 19;
break;
case KEY_END:
ch = 148;
break;
case KEY_DC:
ch = 25;
break;
}
return ch;
}
void platformPutch (byte ch)
{
addch(ch);
}
void platformPuts (char* s)
{
printw(s);
}
void platformCloseScreen (void)
{
endwin();
}
#else /* __MINGW32__ */
#include "external/conio2.h"
void platformInitializeScreen (void)
{
}
void platformScreensize (byte* x, byte* y)
{
struct text_info info;
gettextinfo(&info);
*x = info.screenwidth;
*y = info.screenheight;
}
void platformGotoxy (byte x, byte y)
{
gotoxy(x + 1, y + 1);
}
void platformColors (byte pair)
{
switch (pair)
{
case COLOR_HEADER:
textcolor(BLACK);
textbackground(LIGHTGRAY);
break;
case COLOR_NORMAL:
textcolor(LIGHTGRAY);
textbackground(BLUE);
break;
case COLOR_HIGHLIGHT:
textcolor(BLUE);
textbackground(BLACK);
break;
}
}
byte platformGetch (void)
{
int ch = getch();
if ((0 == ch) || (224 == ch))
{
switch (getch())
{
case 72: // Cursor Up
ch = 145;
break;
case 80: // Cursor Down
ch = 17;
break;
case 75: // Cursor Left
ch = 157;
break;
case 77: // Cursor Right
ch = 29;
break;
case 71: // Home Key
ch = 19;
break;
case 79: // End Key
ch = 148;
break;
case 83: // Delete Key
ch = 25;
break;
}
}
return ch;
}
void platformPutch (byte ch)
{
struct text_info info;
gettextinfo(&info);
if ((info.curx != info.screenwidth) || (info.cury != info.screenheight))
{
putch(ch);
}
}
void platformPuts (char* s)
{
cputs(s);
}
void platformCloseScreen (void)
{
}
#endif /* ! __MINGW32__ */
#endif /* __GNUC__ */
#ifdef __CC65__
void setStorePageReserved(byte pageNo)
{
*((byte*)0) = pageNo + BASE_PAGE_RESERVED;
}
void setStorePage(byte pageNo)
{
*((byte*)0) = pageNo + BASE_PAGE_NORMAL;
}
char* getStore(byte indexInCurrentPage)
{
int location = indexInCurrentPage;
location <<= 7;
location += 0xA000;
return (char*)location;
}
#include <conio.h>
void platformInitializeScreen (void)
{
// This is graphically glitchy, but I rather it is on.
cursor(1U);
videomode(VIDEOMODE_80x30); // Hiding a graphical problem that only occurs in 80x60 mode.
}
void platformScreensize (byte* x, byte* y)
{
screensize(x, y);
}
void platformGotoxy (byte x, byte y)
{
gotoxy(x, y);
}
void platformColors (byte pair)
{
switch (pair)
{
case COLOR_HEADER:
textcolor(COLOR_BLACK);
bgcolor(COLOR_GRAY3);
break;
case COLOR_NORMAL:
textcolor(COLOR_GRAY3);
bgcolor(COLOR_BLUE);
break;
case COLOR_HIGHLIGHT:
textcolor(COLOR_BLUE);
bgcolor(COLOR_BLACK);
break;
}
}
byte platformGetch (void)
{
return cgetc();
}
void platformPutch (byte ch)
{
cputc(ch);
}
void platformPuts (char* s)
{
cputs(s);
}
void platformCloseScreen (void)
{
videomode(VIDEOMODE_80COL);
}
#endif /* __CC65__ */