Subversion Repositories Shiroi

Rev

Rev 22 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 nishi 1
/* $Id: shiroi.c 27 2024-08-31 12:38:59Z nishi $ */
2
 
8 nishi 3
#include "io.h"
12 nishi 4
 
18 nishi 5
#include "dri/math.h"
6
#include "dri/sound.h"
7
#include "dri/video.h"
8
#include "dri/text.h"
9
#include "dri/debug.h"
12 nishi 10
 
8 nishi 11
#include "char.h"
12
 
1 nishi 13
void init_cards(void);
7 nishi 14
void basic(void);
1 nishi 15
 
8 nishi 16
extern short vdp_addr;
17
extern short vdp_data;
18
extern short vdg_addr;
19
extern short vdg_data;
7 nishi 20
 
8 nishi 21
extern short psg_addr;
22
extern short psg_data;
7 nishi 23
 
12 nishi 24
extern short debug_addr;
25
extern short debug_data;
26
 
8 nishi 27
extern short fpu_stack;
28
extern short fpu_command;
7 nishi 29
 
8 nishi 30
extern short text_kbd_data;
1 nishi 31
 
8 nishi 32
extern int scrwidth;
33
extern int scrheight;
1 nishi 34
 
8 nishi 35
extern char caps;
7 nishi 36
 
4 nishi 37
unsigned char keylist[13 * 4];
38
unsigned char keylist_caps[13 * 4];
39
 
2 nishi 40
void main(void){
1 nishi 41
	int i;
42
 
4 nishi 43
/*
44
 * / 1 2 3 4 5 6 7 8 9 10 11 12 13
7 nishi 45
 * 1 1 2 3 4 5 6 7 8 9 0  -  =  bs
4 nishi 46
 * 2 q w e r t y u i o p  [  ]  rt
47
 * 3 a s d f g h j k l ;  '  \  cl
20 nishi 48
 * 4 z x c v b n m , . /  sp bk
5 nishi 49
 *
50
 * When Caps Lock
51
 *
52
 * / 1 2 3 4 5 6 7 8 9 10 11 12 13
7 nishi 53
 * 1 ! @ # $ % ^ & * ( )  _  +  bs
5 nishi 54
 * 2 Q W E R T Y U I O P  {  }  rt
55
 * 3 A S D F G H J K L :  "  |  cl
20 nishi 56
 * 4 Z X C V B N M < > ?  sp bk
4 nishi 57
 */
58
	const char* keys;
59
 
7 nishi 60
	keys = "1234567890-=\x08";
4 nishi 61
	for(i = 0; i < 13; i++){
62
		keylist[i] = keys[i];
63
	}
64
	keys = "qwertyuiop[]\n";
65
	for(i = 0; i < 13; i++){
66
		keylist[13 + i] = keys[i];
67
	}
68
	keys = "asdfghjkl;'\\!";
69
	for(i = 0; i < 13; i++){
70
		keylist[26 + i] = keys[i];
71
	}
20 nishi 72
	keys = "zxcvbnm,./ ?  ";
4 nishi 73
	for(i = 0; i < 13; i++){
74
		keylist[39 + i] = keys[i];
75
	}
76
 
7 nishi 77
	keys = "!@#$%^&*()_+\x08";
4 nishi 78
	for(i = 0; i < 13; i++){
79
		keylist_caps[i] = keys[i];
80
	}
81
	keys = "QWERTYUIOP{}\n";
82
	for(i = 0; i < 13; i++){
83
		keylist_caps[13 + i] = keys[i];
84
	}
85
	keys = "ASDFGHJKL:\"|!";
86
	for(i = 0; i < 13; i++){
87
		keylist_caps[26 + i] = keys[i];
88
	}
20 nishi 89
	keys = "ZXCVBNM<>? ?  ";
4 nishi 90
	for(i = 0; i < 13; i++){
91
		keylist_caps[39 + i] = keys[i];
92
	}
93
 
1 nishi 94
	vdp_addr = -1;
7 nishi 95
	vdg_addr = -1;
1 nishi 96
	psg_addr = -1;
12 nishi 97
	debug_addr = -1;
7 nishi 98
	fpu_stack = -1;
3 nishi 99
	text_kbd_data = -1;
1 nishi 100
 
101
	init_cards();
102
 
8 nishi 103
#ifdef ONLY_VDP
104
	if(vdp_addr == -1){
105
#else
7 nishi 106
	if(vdp_addr == -1 && vdg_addr == -1){
8 nishi 107
#endif
13 nishi 108
		debug_number(0x0001);
2 nishi 109
		while(1);
1 nishi 110
	}
111
 
8 nishi 112
	video_init();
113
	text_init();
1 nishi 114
 
7 nishi 115
	clear();
1 nishi 116
 
10 nishi 117
	beep();
1 nishi 118
 
27 nishi 119
	char hlt = 0;
3 nishi 120
	if(text_kbd_data == -1){
13 nishi 121
		debug_number(0x0002);
27 nishi 122
		thin_char();
3 nishi 123
		putstr("Text  Card Mark I not present\r\n");
27 nishi 124
		putstr("Text  Card Mark I is required to use\r\nthe BASIC\r\n\r\n");
125
		hlt = 1;
3 nishi 126
	}
7 nishi 127
	if(fpu_stack == -1){
27 nishi 128
		debug_number(hlt == 1 ? 0x0023 : 0x0003);
129
		thin_char();
7 nishi 130
		putstr("Math  Card Mark I not present\r\n");
27 nishi 131
		putstr("Math  Card Mark I is required to use\r\nthe BASIC\r\n\r\n");
132
		hlt = 1;
133
	}
134
	if(hlt == 1){
135
		putstr("Halted.\r\n");
7 nishi 136
		while(1);
137
	}
1 nishi 138
 
7 nishi 139
	int incr;
140
	int move = 0;
141
	char k;
142
	int wait = 0;
143
 
144
	const char* title;
145
 
8 nishi 146
#ifdef ONLY_VDP
7 nishi 147
	if(vdp_addr != -1){
8 nishi 148
#else
149
	if(vdp_addr != -1 || vdg_addr != -1){
150
#endif
7 nishi 151
		title = "Shiroi Microcomputer";
8 nishi 152
		setvramaddr(scrwidth / 2 - strlen(title) / 2 + mull((scrheight - 9) / 2 - 1 + 3, scrwidth));
153
		for(i = 0; title[i] != 0; i++) vramchar(title[i]);
7 nishi 154
 
8 nishi 155
		if(vdp_addr != -1){
156
			title = "\x82 2024 Nishi";
157
		}else if(vdg_addr != -1){
158
			title = "(C) 2024 Nishi";
159
		}
160
		setvramaddr(scrwidth / 2 - strlen(title) / 2 + mull(scrheight - 2, scrwidth));
161
		for(i = 0; title[i] != 0; i++) vramchar(title[i]);
7 nishi 162
 
163
		title = "Press any key to begin";
8 nishi 164
		setvramaddr(scrwidth / 2 - strlen(title) / 2 + mull((scrheight - 9) / 2 + 1 + 3, scrwidth));
165
		for(i = 0; title[i] != 0; i++) vramchar(title[i]);
7 nishi 166
	}
167
 
168
move_bar:
169
	if(vdp_addr != -1){
8 nishi 170
	}
171
#ifndef ONLY_VDP
172
	else if(vdg_addr != -1){
7 nishi 173
		goto skip;
174
	}
8 nishi 175
#endif
7 nishi 176
	incr = move;
177
	for(i = 0; i < 16; i++){
178
		int j;
179
		for(j = 0; j < 3; j++){
180
			int p = incr;
181
			if(p >= 15) p = p - 15;
182
			if(wait == 0){
8 nishi 183
				setvramaddr(i * 2 + j * 32);
184
				_vramchar((p + 1) * 8 + 0x80);
185
				_vramchar((p + 1) * 8 + 0x80);
186
				setvramaddr(i * 2 + 32 * 20 - j * 32);
187
				_vramchar((p + 1) * 8 + 0x80);
188
				_vramchar((p + 1) * 8 + 0x80);
7 nishi 189
			}else{
190
				if(i * 2 - 1 < 0){
8 nishi 191
					setvramaddr(i * 2 + j * 32);
192
					_vramchar((p + 1) * 8 + 0x80);
7 nishi 193
				}else{
8 nishi 194
					setvramaddr(i * 2 + j * 32 - 1);
195
					_vramchar((p + 1) * 8 + 0x80);
196
					_vramchar((p + 1) * 8 + 0x80);
7 nishi 197
				}
198
				if(i * 2 - 1 < 0){
8 nishi 199
					setvramaddr(i * 2 + 32 * 20 - j * 32);
200
					_vramchar((p + 1) * 8 + 0x80);
7 nishi 201
				}else{
8 nishi 202
					setvramaddr(i * 2 + 32 * 20 - j * 32 - 1);
203
					_vramchar((p + 1) * 8 + 0x80);
204
					_vramchar((p + 1) * 8 + 0x80);
7 nishi 205
				}
206
			}
207
		}
208
		incr++;
209
		if(incr == 15) incr = 0;
210
	}
211
	wait++;
212
	if(wait == 2){
213
		wait = 0;
214
		move++;
215
		if(move == 15) move = 0;
216
	}
12 nishi 217
	for(i = 0; i < 3 * 1024 / 16; i++);
7 nishi 218
 
219
skip:
220
	if((k = inp(text_kbd_data)) == 0) goto move_bar;
221
	while(inp(text_kbd_data) != 0);
222
 
223
	if(vdp_addr == -1){
224
		outp(vdp_addr, 0xf0);
225
		outp(vdp_addr, 0x87);
226
	}
227
 
8 nishi 228
	basic();
3 nishi 229
}
1 nishi 230
 
2 nishi 231
void init_cards(void){
1 nishi 232
	int i;
233
	int port = 2;
2 nishi 234
	for(i = 0; i < 256 / 3; i++){
1 nishi 235
		int t = inp(port);
2 nishi 236
		if(t != 0){
8 nishi 237
			video_card(t, port);
9 nishi 238
			sound_card(t, port);
239
			math_card(t, port);
8 nishi 240
			text_card(t, port);
12 nishi 241
			debug_card(t, port);
1 nishi 242
		}
243
		port += 3;
244
	}
245
}