Subversion Repositories Shiroi

Rev

Rev 10 | Rev 13 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 nishi 1
/* $Id: shiroi.c 12 2024-08-29 04:19:08Z nishi $ */
2
 
8 nishi 3
#include "io.h"
12 nishi 4
 
9 nishi 5
#include "math.h"
6
#include "sound.h"
8 nishi 7
#include "video.h"
8
#include "text.h"
12 nishi 9
#include "debug.h"
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
48
 * 4 z x c v b n m , . /  sp
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
56
 * 4 Z X C V B N M < > ?  sp
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
	}
72
	keys = "zxcvbnm,./    ";
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
	}
89
	keys = "ZXCVBNM<>?    ";
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
1 nishi 108
		int i;
2 nishi 109
		for(i = 0; i < 3; i++){
12 nishi 110
			_beep(1L * 1024 / 2);
1 nishi 111
			unsigned long j;
12 nishi 112
			for(j = 0; j < 1L * 1024 / 2; j++);
1 nishi 113
		}
2 nishi 114
		while(1);
1 nishi 115
	}
116
 
8 nishi 117
	video_init();
118
	text_init();
1 nishi 119
 
7 nishi 120
	clear();
1 nishi 121
 
10 nishi 122
	beep();
1 nishi 123
 
3 nishi 124
	if(text_kbd_data == -1){
125
		putstr("Text  Card Mark I not present\r\n");
126
		putstr("Text  Card Mark I is required to use the BASIC\r\n");
127
		putstr("Halted. Get one.\r\n");
128
		while(1);
129
	}
7 nishi 130
	if(fpu_stack == -1){
131
		putstr("Math  Card Mark I not present\r\n");
132
		putstr("Math  Card Mark I is required to use the BASIC\r\n");
133
		putstr("Halted. Get one.\r\n");
134
		while(1);
135
	}
1 nishi 136
 
7 nishi 137
	int incr;
138
	int move = 0;
139
	char k;
140
	int wait = 0;
141
 
142
	const char* title;
143
 
8 nishi 144
#ifdef ONLY_VDP
7 nishi 145
	if(vdp_addr != -1){
8 nishi 146
#else
147
	if(vdp_addr != -1 || vdg_addr != -1){
148
#endif
7 nishi 149
		title = "Shiroi Microcomputer";
8 nishi 150
		setvramaddr(scrwidth / 2 - strlen(title) / 2 + mull((scrheight - 9) / 2 - 1 + 3, scrwidth));
151
		for(i = 0; title[i] != 0; i++) vramchar(title[i]);
7 nishi 152
 
8 nishi 153
		if(vdp_addr != -1){
154
			title = "\x82 2024 Nishi";
155
		}else if(vdg_addr != -1){
156
			title = "(C) 2024 Nishi";
157
		}
158
		setvramaddr(scrwidth / 2 - strlen(title) / 2 + mull(scrheight - 2, scrwidth));
159
		for(i = 0; title[i] != 0; i++) vramchar(title[i]);
7 nishi 160
 
161
		title = "Press any key to begin";
8 nishi 162
		setvramaddr(scrwidth / 2 - strlen(title) / 2 + mull((scrheight - 9) / 2 + 1 + 3, scrwidth));
163
		for(i = 0; title[i] != 0; i++) vramchar(title[i]);
7 nishi 164
	}
165
 
166
move_bar:
167
	if(vdp_addr != -1){
8 nishi 168
	}
169
#ifndef ONLY_VDP
170
	else if(vdg_addr != -1){
7 nishi 171
		goto skip;
172
	}
8 nishi 173
#endif
7 nishi 174
	incr = move;
175
	for(i = 0; i < 16; i++){
176
		int j;
177
		for(j = 0; j < 3; j++){
178
			int p = incr;
179
			if(p >= 15) p = p - 15;
180
			if(wait == 0){
8 nishi 181
				setvramaddr(i * 2 + j * 32);
182
				_vramchar((p + 1) * 8 + 0x80);
183
				_vramchar((p + 1) * 8 + 0x80);
184
				setvramaddr(i * 2 + 32 * 20 - j * 32);
185
				_vramchar((p + 1) * 8 + 0x80);
186
				_vramchar((p + 1) * 8 + 0x80);
7 nishi 187
			}else{
188
				if(i * 2 - 1 < 0){
8 nishi 189
					setvramaddr(i * 2 + j * 32);
190
					_vramchar((p + 1) * 8 + 0x80);
7 nishi 191
				}else{
8 nishi 192
					setvramaddr(i * 2 + j * 32 - 1);
193
					_vramchar((p + 1) * 8 + 0x80);
194
					_vramchar((p + 1) * 8 + 0x80);
7 nishi 195
				}
196
				if(i * 2 - 1 < 0){
8 nishi 197
					setvramaddr(i * 2 + 32 * 20 - j * 32);
198
					_vramchar((p + 1) * 8 + 0x80);
7 nishi 199
				}else{
8 nishi 200
					setvramaddr(i * 2 + 32 * 20 - j * 32 - 1);
201
					_vramchar((p + 1) * 8 + 0x80);
202
					_vramchar((p + 1) * 8 + 0x80);
7 nishi 203
				}
204
			}
205
		}
206
		incr++;
207
		if(incr == 15) incr = 0;
208
	}
209
	wait++;
210
	if(wait == 2){
211
		wait = 0;
212
		move++;
213
		if(move == 15) move = 0;
214
	}
12 nishi 215
	for(i = 0; i < 3 * 1024 / 16; i++);
7 nishi 216
 
217
skip:
218
	if((k = inp(text_kbd_data)) == 0) goto move_bar;
219
	while(inp(text_kbd_data) != 0);
220
 
221
	if(vdp_addr == -1){
222
		outp(vdp_addr, 0xf0);
223
		outp(vdp_addr, 0x87);
224
	}
225
 
8 nishi 226
	basic();
3 nishi 227
}
1 nishi 228
 
2 nishi 229
void init_cards(void){
1 nishi 230
	int i;
231
	int port = 2;
2 nishi 232
	for(i = 0; i < 256 / 3; i++){
1 nishi 233
		int t = inp(port);
2 nishi 234
		if(t != 0){
8 nishi 235
			video_card(t, port);
9 nishi 236
			sound_card(t, port);
237
			math_card(t, port);
8 nishi 238
			text_card(t, port);
12 nishi 239
			debug_card(t, port);
1 nishi 240
		}
241
		port += 3;
242
	}
243
}