Subversion Repositories Shiroi

Rev

Rev 5 | Rev 8 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5 Rev 7
Line 1... Line 1...
1
/* $Id: shiroi.c 5 2024-08-28 10:10:03Z nishi $ */
1
/* $Id: shiroi.c 7 2024-08-28 14:02:52Z nishi $ */
2
 
2
 
3
unsigned char inp(unsigned char);
3
unsigned char inp(unsigned char);
4
void outp(unsigned char, unsigned char);
4
void outp(unsigned char, unsigned char);
5
void write_vram(unsigned short);
5
void write_vram(unsigned short);
6
void putchar(char);
6
void putchar(char);
Line 9... Line 9...
9
void beep(void);
9
void beep(void);
10
void _beep(unsigned long howlong);
10
void _beep(unsigned long howlong);
11
void init_cards(void);
11
void init_cards(void);
12
void print_ptr(void*);
12
void print_ptr(void*);
13
char getch(void);
13
char getch(void);
-
 
14
void clear(void);
-
 
15
void basic(void);
-
 
16
int strlen(const char*);
-
 
17
void cursor(void);
-
 
18
void killcursor(void);
-
 
19
char toupper(char c);
-
 
20
long modl(long a, long b);
-
 
21
long divl(long a, long b);
-
 
22
long mull(long a, long b);
-
 
23
 
-
 
24
#define AM_SR       0x80 /* service request on completion */
-
 
25
#define AM_SINGLE   0x60 /* 16 bit integer */
-
 
26
#define AM_DOUBLE   0x20 /* 32 bit integer */
-
 
27
#define AM_FIXED    0x20 /* fixed point */
-
 
28
#define AM_FLOAT    0x00 /* 32 bit float */
-
 
29
 
-
 
30
#define AM_NOP      0x00 /* no operation */
-
 
31
#define AM_SQRT     0x01 /* square root */
-
 
32
#define AM_SIN      0x02 /* sine */
-
 
33
#define AM_COS      0x03 /* cosine */
-
 
34
#define AM_TAN      0x04 /* tangent */
-
 
35
#define AM_ASIN     0x05 /* inverse sine */
-
 
36
#define AM_ACOS     0x06 /* inverse cosine */
-
 
37
#define AM_ATAN     0x07 /* inverse tangent */
-
 
38
#define AM_LOG      0x08 /* common logarithm (base 10) */
-
 
39
#define AM_LN       0x09 /* natural logairth (base e) */
-
 
40
#define AM_EXP      0x0a /* exponential (e^x) */
-
 
41
#define AM_PWR      0x0b /* power nos^tos */
-
 
42
#define AM_ADD      0x0c /* add */
-
 
43
#define AM_SUB      0x0d /* subtract nos-tos */
-
 
44
#define AM_MUL      0x0e /* multiply, lower half */
-
 
45
#define AM_DIV      0x0f /* divide nos/tos */
-
 
46
#define AM_FADD     0x10 /* floating add */
-
 
47
#define AM_FSUB     0x11 /* floating subtract */
-
 
48
#define AM_FMUL     0x12 /* floating multiply */
-
 
49
#define AM_FDIV     0x13 /* floating divide */
-
 
50
#define AM_CHS      0x14 /* change sign */
-
 
51
#define AM_CHSF     0x15 /* floating change sign */ 
-
 
52
#define AM_MUU      0x16 /* multiply, upper half */
-
 
53
#define AM_PTO      0x17 /* push tos to nos (copy) */
-
 
54
#define AM_POP      0x18 /* pop */
-
 
55
#define AM_XCH      0x19 /* exchange tos and nos */
-
 
56
#define AM_PUPI     0x1a /* push pi */
-
 
57
/*                  0x1b */
-
 
58
#define AM_FLTD     0x1c /* 32 bit to float */
-
 
59
#define AM_FLTS     0x1d /* 16 bit to float */
-
 
60
#define AM_FIXD     0x1e /* float to 32 bit */
-
 
61
#define AM_FIXS     0x1f /* float to 16 bit */
-
 
62
 
-
 
63
#define AM_BUSY     0x80 /* chip is busy */
-
 
64
#define AM_SIGN     0x40 /* tos negative */
-
 
65
#define AM_ZERO     0x20 /* tos zero */
-
 
66
#define AM_ERR_MASK 0x1E /* mask for errors */
-
 
67
#define AM_CARRY    0x01 /* carry/borrow from most significant bit */
14
 
68
 
15
unsigned short posx;
69
unsigned short posx;
16
unsigned short posy;
70
unsigned short posy;
-
 
71
unsigned short curx;
-
 
72
unsigned short cury;
17
 
73
 
18
short vdp_addr;
74
short vdp_addr;
19
short vdp_data;
75
short vdp_data;
-
 
76
short vdg_addr;
-
 
77
short vdg_data;
20
short psg_addr;
78
short psg_addr;
21
short psg_data;
79
short psg_data;
22
short fpu_addr;
80
short fpu_stack;
23
short fpu_data;
81
short fpu_command;
24
short text_kbd_data;
82
short text_kbd_data;
25
 
83
 
-
 
84
int scrwidth;
-
 
85
int scrheight;
-
 
86
 
26
char caps;
87
char caps;
27
 
88
 
28
unsigned char keylist[13 * 4];
89
unsigned char keylist[13 * 4];
29
unsigned char keylist_caps[13 * 4];
90
unsigned char keylist_caps[13 * 4];
30
 
91
 
Line 34... Line 95...
34
	int i;
95
	int i;
35
	caps = 0;
96
	caps = 0;
36
 
97
 
37
/*
98
/*
38
 * / 1 2 3 4 5 6 7 8 9 10 11 12 13
99
 * / 1 2 3 4 5 6 7 8 9 10 11 12 13
39
 * 1 1 2 3 4 5 6 7 8 9 0  -  =  
100
 * 1 1 2 3 4 5 6 7 8 9 0  -  =  bs
40
 * 2 q w e r t y u i o p  [  ]  rt
101
 * 2 q w e r t y u i o p  [  ]  rt
41
 * 3 a s d f g h j k l ;  '  \  cl
102
 * 3 a s d f g h j k l ;  '  \  cl
42
 * 4 z x c v b n m , . /  sp
103
 * 4 z x c v b n m , . /  sp
43
 *
104
 *
44
 * When Caps Lock
105
 * When Caps Lock
45
 *
106
 *
46
 * / 1 2 3 4 5 6 7 8 9 10 11 12 13
107
 * / 1 2 3 4 5 6 7 8 9 10 11 12 13
47
 * 1 ! @ # $ % ^ & * ( )  _  +  
108
 * 1 ! @ # $ % ^ & * ( )  _  +  bs
48
 * 2 Q W E R T Y U I O P  {  }  rt
109
 * 2 Q W E R T Y U I O P  {  }  rt
49
 * 3 A S D F G H J K L :  "  |  cl
110
 * 3 A S D F G H J K L :  "  |  cl
50
 * 4 Z X C V B N M < > ?  sp
111
 * 4 Z X C V B N M < > ?  sp
51
 */
112
 */
52
	const char* keys;
113
	const char* keys;
53
 
114
 
54
	keys = "1234567890-= ";
115
	keys = "1234567890-=\x08";
55
	for(i = 0; i < 13; i++){
116
	for(i = 0; i < 13; i++){
56
		keylist[i] = keys[i];
117
		keylist[i] = keys[i];
57
	}
118
	}
58
	keys = "qwertyuiop[]\n";
119
	keys = "qwertyuiop[]\n";
59
	for(i = 0; i < 13; i++){
120
	for(i = 0; i < 13; i++){
Line 66... Line 127...
66
	keys = "zxcvbnm,./    ";
127
	keys = "zxcvbnm,./    ";
67
	for(i = 0; i < 13; i++){
128
	for(i = 0; i < 13; i++){
68
		keylist[39 + i] = keys[i];
129
		keylist[39 + i] = keys[i];
69
	}
130
	}
70
 
131
 
71
	keys = "!@#$%^&*()_+ ";
132
	keys = "!@#$%^&*()_+\x08";
72
	for(i = 0; i < 13; i++){
133
	for(i = 0; i < 13; i++){
73
		keylist_caps[i] = keys[i];
134
		keylist_caps[i] = keys[i];
74
	}
135
	}
75
	keys = "QWERTYUIOP{}\n";
136
	keys = "QWERTYUIOP{}\n";
76
	for(i = 0; i < 13; i++){
137
	for(i = 0; i < 13; i++){
Line 85... Line 146...
85
		keylist_caps[39 + i] = keys[i];
146
		keylist_caps[39 + i] = keys[i];
86
	}
147
	}
87
 
148
 
88
	posx = 0;
149
	posx = 0;
89
	posy = 0;
150
	posy = 0;
-
 
151
	curx = 0;
-
 
152
	cury = 0;
90
 
153
 
91
	vdp_addr = -1;
154
	vdp_addr = -1;
-
 
155
	vdg_addr = -1;
92
	psg_addr = -1;
156
	psg_addr = -1;
93
	fpu_addr = -1;
157
	fpu_stack = -1;
94
	text_kbd_data = -1;
158
	text_kbd_data = -1;
95
 
159
 
96
	init_cards();
160
	init_cards();
97
 
161
 
98
	if(vdp_addr == -1){
162
	if(vdp_addr == -1 && vdg_addr == -1){
99
		int i;
163
		int i;
100
		for(i = 0; i < 3; i++){
164
		for(i = 0; i < 3; i++){
101
			_beep(3L * 1024);
165
			_beep(3L * 1024);
102
			unsigned long j;
166
			unsigned long j;
103
			for(j = 0; j < 3L * 1024; j++);
167
			for(j = 0; j < 3L * 1024; j++);
104
		}
168
		}
105
		while(1);
169
		while(1);
106
	}
170
	}
107
	
-
 
108
	outp(vdp_addr, 0x00);
-
 
109
	outp(vdp_addr, 0x80);
-
 
110
 
171
 
111
	outp(vdp_addr, 0xd0);
172
	if(vdp_addr != -1){	
112
	outp(vdp_addr, 0x81);
173
		scrwidth = 32;
-
 
174
		scrheight = 24;
113
 
175
 
-
 
176
		outp(vdp_addr, 0x00);
-
 
177
		outp(vdp_addr, 0x80);
-
 
178
	
-
 
179
		outp(vdp_addr, 0xd8);
-
 
180
		outp(vdp_addr, 0x81);
-
 
181
	
114
	outp(vdp_addr, 0x02);
182
		outp(vdp_addr, 0x02);
115
	outp(vdp_addr, 0x82);
183
		outp(vdp_addr, 0x82);
-
 
184
	
-
 
185
		outp(vdp_addr, 0x50);
-
 
186
		outp(vdp_addr, 0x83);
116
 
187
	
117
	outp(vdp_addr, 0x00);
188
		outp(vdp_addr, 0x00);
118
	outp(vdp_addr, 0x84);
189
		outp(vdp_addr, 0x84);
-
 
190
	
-
 
191
		outp(vdp_addr, 0x29);
-
 
192
		outp(vdp_addr, 0x85);
-
 
193
	
-
 
194
		outp(vdp_addr, 0x03);
-
 
195
		outp(vdp_addr, 0x86);
119
 
196
	
120
	outp(vdp_addr, 0xf4);
197
		outp(vdp_addr, 0xe4);
121
	outp(vdp_addr, 0x87);
198
		outp(vdp_addr, 0x87);
-
 
199
	}else if(vdg_addr != -1){
-
 
200
		scrwidth = 32;
-
 
201
		scrheight = 16;
-
 
202
	}
-
 
203
 
-
 
204
	if(vdp_addr != -1){
-
 
205
		/*
-
 
206
		 * VDP:
-
 
207
		 * 0x0000-0x0800: font
-
 
208
		 * 0x0800-0x1400: pattern
-
 
209
		 * 0x1400-0x1480: color
-
 
210
		 * 0x1480-0x1500: sprite attr
-
 
211
		 * 0x1800-0x2000: sprite pattern
-
 
212
		 */
-
 
213
	
-
 
214
		write_vram(0);
-
 
215
		for(i = 0; i < 0x800; i++) outp(vdp_data, *((unsigned char*)(0x6000 - 2048 + i)));
-
 
216
	
-
 
217
		write_vram(0x1400);
-
 
218
		for(i = 0; i < 0x20; i++) outp(vdp_data, 0xf0);
-
 
219
		write_vram(0x1400 + 0x10);
-
 
220
		for(i = 0; i < 0x10; i++) outp(vdp_data, ((i & 0xf) << 4) | 0);
-
 
221
	}
122
 
222
 
123
	write_vram(0);
223
	clear();
124
	for(i = 0; i < 0x800; i++) outp(vdp_data, *((unsigned char*)(0x6000 - 2048 + i)));
-
 
125
 
224
 
126
//	beep();
225
//	beep();
127
 
226
 
128
	putstr("Shiroi Microcomputer BASIC\r\n");
-
 
129
	if(psg_addr == -1){
-
 
130
		putstr("Sound Card Mark I not present\r\n");
-
 
131
	}else{
-
 
132
		putstr("Sound Card Mark I     present\r\n");
-
 
133
	}
-
 
134
	if(fpu_addr == -1){
-
 
135
		putstr("Math  Card Mark I not present\r\n");
-
 
136
	}else{
-
 
137
		putstr("Math  Card Mark I     present\r\n");
-
 
138
	}
-
 
139
	if(text_kbd_data == -1){
227
	if(text_kbd_data == -1){
140
		putstr("Text  Card Mark I not present\r\n");
228
		putstr("Text  Card Mark I not present\r\n");
141
		putstr("Text  Card Mark I is required to use the BASIC\r\n");
229
		putstr("Text  Card Mark I is required to use the BASIC\r\n");
142
		putstr("Halted. Get one.\r\n");
230
		putstr("Halted. Get one.\r\n");
143
		while(1);
231
		while(1);
144
	}else{
-
 
145
		putstr("Text  Card Mark I     present\r\n");
-
 
146
	}
232
	}
-
 
233
	if(fpu_stack == -1){
-
 
234
		putstr("Math  Card Mark I not present\r\n");
-
 
235
		putstr("Math  Card Mark I is required to use the BASIC\r\n");
-
 
236
		putstr("Halted. Get one.\r\n");
-
 
237
		while(1);
-
 
238
	}
-
 
239
 
-
 
240
	int incr;
-
 
241
	int move = 0;
-
 
242
	char k;
-
 
243
	int wait = 0;
-
 
244
 
-
 
245
	const char* title;
-
 
246
 
-
 
247
	if(vdp_addr != -1){
-
 
248
		title = "Shiroi Microcomputer";
-
 
249
		write_vram(0x800 + scrwidth / 2 - strlen(title) / 2 + mull(scrheight / 2 - 1, scrwidth));
-
 
250
		for(i = 0; title[i] != 0; i++) outp(vdp_data, title[i] - 0x20);
-
 
251
 
-
 
252
		title = "\x82 2024 Nishi";
-
 
253
		write_vram(0x800 + scrwidth / 2 - strlen(title) / 2 + mull(scrheight - 2, scrwidth));
-
 
254
		for(i = 0; title[i] != 0; i++) outp(vdp_data, title[i] - 0x20);
-
 
255
 
-
 
256
		title = "Press any key to begin";
-
 
257
		write_vram(0x800 + scrwidth / 2 - strlen(title) / 2 + mull(scrheight / 2 + 1, scrwidth));
-
 
258
		for(i = 0; title[i] != 0; i++) outp(vdp_data, title[i] - 0x20);
-
 
259
	}else if(vdg_addr != -1){
-
 
260
		title = "Shiroi Microcomputer";
-
 
261
		write_vram(scrwidth / 2 - strlen(title) / 2 + mull(scrheight / 2 - 1, scrwidth));
-
 
262
		for(i = 0; title[i] != 0; i++) outp(vdg_data, toupper(title[i]) - 'A' + 1);
-
 
263
 
-
 
264
		title = "(C) 2024 Nishi";
-
 
265
		write_vram(scrwidth / 2 - strlen(title) / 2 + mull(scrheight - 2, scrwidth));
-
 
266
		for(i = 0; title[i] != 0; i++) outp(vdg_data, toupper(title[i]) - 'A' + 1);
-
 
267
 
-
 
268
		title = "Press any key to begin";
-
 
269
		write_vram(scrwidth / 2 - strlen(title) / 2 + mull(scrheight / 2 + 1, scrwidth));
-
 
270
		for(i = 0; title[i] != 0; i++) outp(vdg_data, toupper(title[i]) - 'A' + 1);
-
 
271
	}
-
 
272
 
-
 
273
move_bar:
-
 
274
	if(vdp_addr != -1){
-
 
275
	}else if(vdg_addr != -1){
-
 
276
		goto skip;
-
 
277
	}
-
 
278
	incr = move;
-
 
279
	for(i = 0; i < 16; i++){
-
 
280
		int j;
-
 
281
		for(j = 0; j < 3; j++){
-
 
282
			int p = incr;
-
 
283
			if(p >= 15) p = p - 15;
-
 
284
			if(wait == 0){
-
 
285
				write_vram(0x800 + i * 2 + j * 32);
-
 
286
				outp(vdp_data, (p + 1) * 8 + 0x80);
-
 
287
				outp(vdp_data, (p + 1) * 8 + 0x80);
-
 
288
				write_vram(0x800 + i * 2 + 32 * 20 - j * 32);
-
 
289
				outp(vdp_data, (p + 1) * 8 + 0x80);
-
 
290
				outp(vdp_data, (p + 1) * 8 + 0x80);
-
 
291
			}else{
-
 
292
				if(i * 2 - 1 < 0){
-
 
293
					write_vram(0x800 + i * 2 + j * 32);
-
 
294
					outp(vdp_data, (p + 1) * 8 + 0x80);
-
 
295
				}else{
-
 
296
					write_vram(0x800 + i * 2 + j * 32 - 1);
-
 
297
					outp(vdp_data, (p + 1) * 8 + 0x80);
-
 
298
					outp(vdp_data, (p + 1) * 8 + 0x80);
-
 
299
				}
-
 
300
				if(i * 2 - 1 < 0){
-
 
301
					write_vram(0x800 + i * 2 + 32 * 20 - j * 32);
-
 
302
					outp(vdp_data, (p + 1) * 8 + 0x80);
-
 
303
				}else{
-
 
304
					write_vram(0x800 + i * 2 + 32 * 20 - j * 32 - 1);
-
 
305
					outp(vdp_data, (p + 1) * 8 + 0x80);
-
 
306
					outp(vdp_data, (p + 1) * 8 + 0x80);
-
 
307
				}
-
 
308
			}
-
 
309
		}
-
 
310
		incr++;
-
 
311
		if(incr == 15) incr = 0;
-
 
312
	}
-
 
313
	wait++;
-
 
314
	if(wait == 2){
-
 
315
		wait = 0;
-
 
316
		move++;
-
 
317
		if(move == 15) move = 0;
-
 
318
	}
-
 
319
	for(i = 0; i < 3 * 1024; i++);
-
 
320
 
-
 
321
skip:
-
 
322
	if((k = inp(text_kbd_data)) == 0) goto move_bar;
-
 
323
	while(inp(text_kbd_data) != 0);
147
 
324
 
-
 
325
	basic();
-
 
326
}
-
 
327
 
-
 
328
void basic(void){
-
 
329
	clear();
-
 
330
 
-
 
331
	if(vdp_addr == -1){
-
 
332
		outp(vdp_addr, 0xf0);
-
 
333
		outp(vdp_addr, 0x87);
-
 
334
	}
-
 
335
 
-
 
336
	putstr("Shiroi Microcomputer BASIC\r\n");
-
 
337
	cursor();
148
	while(1){
338
	while(1){
-
 
339
		char c = getch();
-
 
340
		killcursor();
-
 
341
		if(c == '\n'){
-
 
342
			putstr("\r\n");
-
 
343
		}else{
149
		putchar(getch());
344
			putchar(c);
-
 
345
		}
-
 
346
		cursor();
-
 
347
	}
-
 
348
}
-
 
349
 
-
 
350
int strlen(const char* str){
-
 
351
	int i;
-
 
352
	for(i = 0; str[i] != 0; i++);
-
 
353
	return i;
-
 
354
}
-
 
355
 
-
 
356
void clear(void){
-
 
357
	int i;
-
 
358
	int size = mull(scrwidth, scrheight);
-
 
359
	if(vdp_addr != -1){
-
 
360
		write_vram(0x800);
-
 
361
		for(i = 0; i < size; i++) outp(vdp_data, 0);
-
 
362
	}else if(vdg_addr != -1){
-
 
363
		write_vram(0);
-
 
364
		for(i = 0; i < size; i++){
-
 
365
			outp(vdg_data, 0x20);
-
 
366
		}
150
	}
367
	}
151
}
368
}
152
 
369
 
153
char getch(void){
370
char getch(void){
154
	char k = 0;
371
	char k = 0;
Line 184... Line 401...
184
		int t = inp(port);
401
		int t = inp(port);
185
		if(t != 0){
402
		if(t != 0){
186
			if(t == 0x01){
403
			if(t == 0x01){
187
				vdp_addr = port - 2;
404
				vdp_addr = port - 2;
188
				vdp_data = port - 1;
405
				vdp_data = port - 1;
-
 
406
			}else if(t == 0x02){
-
 
407
				vdg_addr = port - 2;
-
 
408
				vdg_data = port - 1;
189
			}else if(t == 0x11){
409
			}else if(t == 0x11){
190
				psg_addr = port - 2;
410
				psg_addr = port - 2;
191
				psg_data = port - 1;
411
				psg_data = port - 1;
192
			}else if(t == 0x21){
412
			}else if(t == 0x21){
193
				fpu_addr = port - 2;
413
				fpu_stack = port - 2;
194
				fpu_data = port - 1;
414
				fpu_command = port - 1;
195
			}else if(t == 0x22){
415
			}else if(t == 0x22){
196
				text_kbd_data = port - 2;
416
				text_kbd_data = port - 2;
197
			}
417
			}
198
 
418
 
199
		}
419
		}
Line 226... Line 446...
226
	outp(psg_addr, 7);
446
	outp(psg_addr, 7);
227
	outp(psg_data, 0x3f);
447
	outp(psg_data, 0x3f);
228
}
448
}
229
 
449
 
230
void write_vram(unsigned short addr){
450
void write_vram(unsigned short addr){
-
 
451
	if(vdp_addr != -1){
231
	addr |= 0x4000;
452
		addr |= 0x4000;
232
	outp(vdp_addr, addr & 0x00ff);
453
		outp(vdp_addr, addr & 0x00ff);
233
	outp(vdp_addr, ((addr & 0xff00) >> 8));
454
		outp(vdp_addr, ((addr & 0xff00) >> 8));
-
 
455
	}else if(vdg_addr != -1){
-
 
456
		outp(vdg_addr, addr & 0x00ff);
-
 
457
		outp(vdg_addr, ((addr & 0xff00) >> 8));
-
 
458
	}
234
}
459
}
235
 
460
 
236
void read_vram(unsigned short addr){
461
void read_vram(unsigned short addr){
-
 
462
	if(vdp_addr != -1){
237
	outp(vdp_addr, addr & 0x00ff);
463
		outp(vdp_addr, addr & 0x00ff);
238
	outp(vdp_addr, ((addr & 0xff00) >> 8));
464
		outp(vdp_addr, ((addr & 0xff00) >> 8));
-
 
465
	}else{
-
 
466
		outp(vdg_addr, addr & 0x00ff);
-
 
467
		outp(vdg_addr, ((addr & 0xff00) >> 8));
-
 
468
	}
239
}
469
}
240
 
470
 
241
void scroll_y(void){
471
void scroll_y(void){
242
	int i;
472
	int i;
-
 
473
	int size = mull(scrwidth, scrheight - 1);
243
	for(i = 0; i < 40 * 23; i++){
474
	for(i = 0; i < size; i++){
-
 
475
		if(vdp_addr != -1){
244
		read_vram(0x800 + i + 40);
476
			read_vram(0x800 + i + 32);
245
		unsigned char ch = inp(vdp_data);
477
			unsigned char ch = inp(vdp_data);
246
		write_vram(0x800 + i);
478
			write_vram(0x800 + i);
247
		outp(vdp_data, ch);
479
			outp(vdp_data, ch);
-
 
480
		}else if(vdg_addr != -1){
-
 
481
			read_vram(i + 32);
-
 
482
			unsigned char ch = inp(vdg_data);
-
 
483
			write_vram(i);
-
 
484
			outp(vdg_data, ch);
-
 
485
		}
-
 
486
	}
-
 
487
	for(i = 0; i < scrwidth; i++){
-
 
488
		if(vdp_addr != -1){
-
 
489
			outp(vdp_data, 0);
-
 
490
		}else if(vdg_addr != -1){
-
 
491
			outp(vdg_data, 0x20);
-
 
492
		}
-
 
493
	}
-
 
494
}
-
 
495
 
-
 
496
void cursor(void){
-
 
497
	if(vdp_addr != -1){
-
 
498
		write_vram(0x800 + mull(posy, scrwidth) + posx);
-
 
499
		outp(vdp_data, 248);
-
 
500
	}else if(vdg_addr != -1){
-
 
501
		write_vram(mull(posy, scrwidth) + posx);
-
 
502
		outp(vdg_data, 0);
-
 
503
	}
-
 
504
	curx = posx;
-
 
505
	cury = posy;
-
 
506
	if(curx == scrwidth){
-
 
507
		curx = 0;
-
 
508
		cury++;
248
	}
509
	}
-
 
510
}
-
 
511
 
-
 
512
void killcursor(void){
249
	for(i = 0; i < 40; i++){
513
	if(vdp_addr != -1){
-
 
514
		write_vram(0x800 + mull(cury, scrwidth) + curx);
250
		outp(vdp_data, 0);
515
		outp(vdp_data, 0);
-
 
516
	}else if(vdg_addr != -1){
-
 
517
		write_vram(mull(cury, scrwidth) + curx);
-
 
518
		outp(vdg_data, 0x20);
251
	}
519
	}
252
}
520
}
253
 
521
 
-
 
522
char toupper(char c){
-
 
523
	if('a' <= c && c <= 'z'){
-
 
524
		return c - 'a' + 'A';
-
 
525
	}
-
 
526
	return c;
-
 
527
}
-
 
528
 
254
void putchar(char c){
529
void putchar(char c){
255
	if(c == '\r'){
530
	if(c == '\r'){
256
		posx = 0;
531
		posx = 0;
257
	}else if(c == '\n'){
532
	}else if(c == '\n'){
258
		posy++;
533
		posy++;
259
	}else{
534
	}else{
-
 
535
		if(vdp_addr != -1){
260
		write_vram(0x800 + posy * 40 + posx);
536
			write_vram(0x800 + mull(posy, scrwidth) + posx);
-
 
537
		}else if(vdg_addr != -1){
-
 
538
			write_vram(mull(posy, scrwidth) + posx);
-
 
539
		}
-
 
540
		if(vdp_addr != -1){
261
		outp(vdp_data, c);
541
			outp(vdp_data, c - 0x20);
-
 
542
		}else if(vdg_addr != -1){
-
 
543
			outp(vdg_data, toupper(c) - 'A' + 1);
-
 
544
		}
262
		posx++;
545
		posx++;
263
		if(posx == 40){
546
		if(posx == scrwidth){
264
			posx = 0;
547
			posx = 0;
265
			posy++;
548
			posy++;
266
		}
549
		}
267
	}
550
	}
268
	if(posy == 24){
551
	if(posy == scrheight){
269
		scroll_y();
552
		scroll_y();
270
		posy = 23;
553
		posy = scrheight - 1;
271
		posx = 0;
554
		posx = 0;
272
	}
555
	}
273
}
556
}
274
 
557
 
275
void putstr(char* str){
558
void putstr(char* str){
276
	int i;
559
	int i;
277
	for(i = 0; str[i] != 0; i++) putchar(str[i]);
560
	for(i = 0; str[i] != 0; i++) putchar(str[i]);
278
}
561
}
279
 
562
 
-
 
563
long modl(long a, long b){
-
 
564
	return a - mull(b, divl(a, b));
-
 
565
}
-
 
566
 
-
 
567
long divl(long a, long b){
-
 
568
	int i;
-
 
569
	for(i = 0; i < 4; i++){
-
 
570
		outp(fpu_stack, a & 0xff);
-
 
571
		a = a >> 8;
-
 
572
	}
-
 
573
	for(i = 0; i < 4; i++){
-
 
574
		outp(fpu_stack, b & 0xff);
-
 
575
		b = b >> 8;
-
 
576
	}
-
 
577
	outp(fpu_command, AM_DOUBLE | AM_DIV);
-
 
578
	unsigned long r = 0;
-
 
579
	for(i = 0; i < 4; i++){
-
 
580
		r = r << 8;
-
 
581
		r |= inp(fpu_stack);
-
 
582
	}
-
 
583
	return r;
-
 
584
}
-
 
585
 
-
 
586
long mull(long a, long b){
-
 
587
	int i;
-
 
588
	for(i = 0; i < 4; i++){
-
 
589
		outp(fpu_stack, a & 0xff);
-
 
590
		a = a >> 8;
-
 
591
	}
-
 
592
	for(i = 0; i < 4; i++){
-
 
593
		outp(fpu_stack, b & 0xff);
-
 
594
		b = b >> 8;
-
 
595
	}
-
 
596
	outp(fpu_command, AM_DOUBLE | AM_MUL);
-
 
597
	long r = 0;
-
 
598
	for(i = 0; i < 4; i++){
-
 
599
		r = r << 8;
-
 
600
		r |= inp(fpu_stack);
-
 
601
	}
-
 
602
	return r;
-
 
603
}
-
 
604
 
-
 
605
 
280
unsigned char inp(unsigned char port) __naked {
606
unsigned char inp(unsigned char port) __naked {
281
__asm
607
__asm
282
	ld      hl,#2
608
	ld      hl,#2
283
	add     hl,sp
609
	add     hl,sp
284
	ld      c,(hl)
610
	ld      c,(hl)