Subversion Repositories Shiroi

Rev

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

Rev 1 Rev 2
Line 1... Line 1...
1
/* $Id: shiroi.c 1 2024-08-28 08:10:28Z nishi $ */
1
/* $Id: shiroi.c 2 2024-08-28 08:12:18Z 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 18... Line 18...
18
short psg_addr;
18
short psg_addr;
19
short psg_data;
19
short psg_data;
20
short fpu_addr;
20
short fpu_addr;
21
short fpu_data;
21
short fpu_data;
22
 
22
 
23
void main(void) {
23
void main(void){
24
	int i;
24
	int i;
25
 
25
 
26
	posx = 0;
26
	posx = 0;
27
	posy = 0;
27
	posy = 0;
28
 
28
 
Line 30... Line 30...
30
	psg_addr = -1;
30
	psg_addr = -1;
31
	fpu_addr = -1;
31
	fpu_addr = -1;
32
 
32
 
33
	init_cards();
33
	init_cards();
34
 
34
 
35
	if(vdp_addr == -1) {
35
	if(vdp_addr == -1){
36
		int i;
36
		int i;
37
		for(i = 0; i < 3; i++) {
37
		for(i = 0; i < 3; i++){
38
			_beep(3L * 1024);
38
			_beep(3L * 1024);
39
			unsigned long j;
39
			unsigned long j;
40
			for(j = 0; j < 3L * 1024; j++)
40
			for(j = 0; j < 3L * 1024; j++);
41
				;
-
 
42
		}
41
		}
43
		while(1)
42
		while(1);
44
			;
-
 
45
	}
43
	}
46
 
44
	
47
	outp(vdp_addr, 0x00);
45
	outp(vdp_addr, 0x00);
48
	outp(vdp_addr, 0x80);
46
	outp(vdp_addr, 0x80);
49
 
47
 
50
	outp(vdp_addr, 0xd0);
48
	outp(vdp_addr, 0xd0);
51
	outp(vdp_addr, 0x81);
49
	outp(vdp_addr, 0x81);
Line 63... Line 61...
63
	for(i = 0; i < 0x800; i++) outp(vdp_data, *((unsigned char*)(0x2000 + i)));
61
	for(i = 0; i < 0x800; i++) outp(vdp_data, *((unsigned char*)(0x2000 + i)));
64
 
62
 
65
	beep();
63
	beep();
66
 
64
 
67
	putstr("Shiroi Microcomputer BASIC\r\n");
65
	putstr("Shiroi Microcomputer BASIC\r\n");
68
	if(fpu_addr == -1) {
66
	if(fpu_addr == -1){
69
		putstr("Math Card Mark I not present\r\n");
67
		putstr("Math Card Mark I not present\r\n");
70
	} else {
68
	}else{
71
		putstr("Math Card Mark I present\r\n");
69
		putstr("Math Card Mark I present\r\n");
72
	}
70
	}
73
	if(psg_addr == -1) {
71
	if(psg_addr == -1){
74
		putstr("Sound Card Mark I not present\r\n");
72
		putstr("Sound Card Mark I not present\r\n");
75
	} else {
73
	}else{
76
		putstr("Sound Card Mark I present\r\n");
74
		putstr("Sound Card Mark I present\r\n");
77
	}
75
	}
78
 
76
 
79
	write_vram(0x800 + 40 * 12);
77
	write_vram(0x800 + 40 * 12);
80
	for(i = 0; i < 0x100; i++) outp(vdp_data, i);
78
	for(i = 0; i < 0x100; i++) outp(vdp_data, i);
81
 
79
 
82
	while(1)
80
	while(1);
83
		;
-
 
84
}
81
}
85
 
82
 
86
void init_cards(void) {
83
void init_cards(void){
87
	int i;
84
	int i;
88
	int port = 2;
85
	int port = 2;
89
	for(i = 0; i < 256 / 3; i++) {
86
	for(i = 0; i < 256 / 3; i++){
90
		int t = inp(port);
87
		int t = inp(port);
91
		if(t != 0) {
88
		if(t != 0){
92
			if(t == 0x01) {
89
			if(t == 0x01){
93
				vdp_addr = port - 2;
90
				vdp_addr = port - 2;
94
				vdp_data = port - 1;
91
				vdp_data = port - 1;
95
			} else if(t == 0x11) {
92
			}else if(t == 0x11){
96
				psg_addr = port - 2;
93
				psg_addr = port - 2;
97
				psg_data = port - 1;
94
				psg_data = port - 1;
98
			} else if(t == 0x21) {
95
			}else if(t == 0x21){
99
				fpu_addr = port - 2;
96
				fpu_addr = port - 2;
100
				fpu_data = port - 1;
97
				fpu_data = port - 1;
101
			}
98
			}
102
		}
99
		}
103
		port += 3;
100
		port += 3;
104
	}
101
	}
105
}
102
}
106
 
103
 
-
 
104
void beep(void){
107
void beep(void) { _beep(3L * 1024); }
105
	_beep(3L * 1024);
-
 
106
}
108
 
107
 
109
void _beep(unsigned long howlong) {
108
void _beep(unsigned long howlong){
110
	if(psg_addr == -1) return;
109
	if(psg_addr == -1) return;
111
	unsigned long i;
110
	unsigned long i;
112
 
111
 
113
	outp(psg_addr, 8);
112
	outp(psg_addr, 8);
114
	outp(psg_data, 0x0f);
113
	outp(psg_data, 0x0f);
Line 120... Line 119...
120
	outp(psg_data, 0x0);
119
	outp(psg_data, 0x0);
121
 
120
 
122
	outp(psg_addr, 7);
121
	outp(psg_addr, 7);
123
	outp(psg_data, 0x3e);
122
	outp(psg_data, 0x3e);
124
 
123
 
125
	for(i = 0; i < howlong; i++)
124
	for(i = 0; i < howlong; i++);
126
		;
-
 
127
 
125
 
128
	outp(psg_addr, 7);
126
	outp(psg_addr, 7);
129
	outp(psg_data, 0x3f);
127
	outp(psg_data, 0x3f);
130
}
128
}
131
 
129
 
132
void write_vram(unsigned short addr) {
130
void write_vram(unsigned short addr){
133
	addr |= 0x4000;
131
	addr |= 0x4000;
134
	outp(vdp_addr, addr & 0x00ff);
132
	outp(vdp_addr, addr & 0x00ff);
135
	outp(vdp_addr, ((addr & 0xff00) >> 8));
133
	outp(vdp_addr, ((addr & 0xff00) >> 8));
136
}
134
}
137
 
135
 
138
void read_vram(unsigned short addr) {
136
void read_vram(unsigned short addr){
139
	outp(vdp_addr, addr & 0x00ff);
137
	outp(vdp_addr, addr & 0x00ff);
140
	outp(vdp_addr, ((addr & 0xff00) >> 8));
138
	outp(vdp_addr, ((addr & 0xff00) >> 8));
141
}
139
}
142
 
140
 
143
void scroll_y(void) {
141
void scroll_y(void){
144
	int i;
142
	int i;
145
	for(i = 0; i < 40 * 23; i++) {
143
	for(i = 0; i < 40 * 23; i++){
146
		read_vram(0x800 + i + 40);
144
		read_vram(0x800 + i + 40);
147
		unsigned char ch = inp(vdp_data);
145
		unsigned char ch = inp(vdp_data);
148
		write_vram(0x800 + i);
146
		write_vram(0x800 + i);
149
		outp(vdp_data, ch);
147
		outp(vdp_data, ch);
150
	}
148
	}
151
	for(i = 0; i < 40; i++) {
149
	for(i = 0; i < 40; i++){
152
		outp(vdp_data, 0);
150
		outp(vdp_data, 0);
153
	}
151
	}
154
}
152
}
155
 
153
 
156
void putchar(char c) {
154
void putchar(char c){
157
	if(c == '\r') {
155
	if(c == '\r'){
158
		posx = 0;
156
		posx = 0;
159
	} else if(c == '\n') {
157
	}else if(c == '\n'){
160
		posy++;
158
		posy++;
161
	} else {
159
	}else{
162
		write_vram(0x800 + posy * 40 + posx);
160
		write_vram(0x800 + posy * 40 + posx);
163
		outp(vdp_data, c);
161
		outp(vdp_data, c);
164
		posx++;
162
		posx++;
165
		if(posx == 40) {
163
		if(posx == 40){
166
			posx = 0;
164
			posx = 0;
167
			posy++;
165
			posy++;
168
		}
166
		}
169
	}
167
	}
170
	if(posy == 24) {
168
	if(posy == 24){
171
		scroll_y();
169
		scroll_y();
172
		posy = 23;
170
		posy = 23;
173
		posx = 0;
171
		posx = 0;
174
	}
172
	}
175
}
173
}
176
 
174
 
177
void putstr(char* str) {
175
void putstr(char* str){
178
	int i;
176
	int i;
179
	for(i = 0; str[i] != 0; i++) putchar(str[i]);
177
	for(i = 0; str[i] != 0; i++) putchar(str[i]);
180
}
178
}
181
 
179
 
182
unsigned char inp(unsigned char port) __naked { __asm ld hl, #2 add hl, sp ld c, (hl)in a, (c)ld l, a ld h, #0 ret __endasm; }
180
unsigned char inp(unsigned char port) __naked {
-
 
181
__asm
-
 
182
	ld      hl,#2
-
 
183
	add     hl,sp
-
 
184
	ld      c,(hl)
-
 
185
	in      a,(c)
-
 
186
	ld      l,a
-
 
187
	ld      h,#0
-
 
188
	ret
-
 
189
__endasm;
-
 
190
}
183
 
191
 
184
void outp(unsigned char port, unsigned char data) __naked { __asm push bc ld hl, #4 add hl, sp ld c, (hl)inc hl ld b, (hl)out(c), b pop bc ret __endasm; }
192
void outp(unsigned char port, unsigned char data) __naked {
-
 
193
__asm
-
 
194
	push bc
-
 
195
	ld      hl,#4
-
 
196
	add     hl,sp
-
 
197
	ld      c,(hl)
-
 
198
	inc     hl
-
 
199
	ld      b,(hl)
-
 
200
	out     (c),b
-
 
201
	pop     bc
-
 
202
	ret
-
 
203
__endasm;
-
 
204
}