Subversion Repositories Shiroi

Rev

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

Rev Author Line No. Line
18 nishi 1
/* $Id: video.c 32 2024-09-01 08:51:40Z nishi $ */
2
 
3
#include "video.h"
4
 
19 nishi 5
#include "math.h"
6
 
18 nishi 7
#include "../char.h"
8
#include "../io.h"
9
 
10
int scrwidth;
11
int scrheight;
12
 
13
short vdp_addr;
14
short vdp_data;
15
short vdg_addr;
16
short vdg_data;
17
 
18
void write_vram(unsigned short addr){
19
	if(vdp_addr != -1){
20
		addr |= 0x4000;
21
		outp(vdp_addr, addr & 0x00ff);
22
		outp(vdp_addr, ((addr & 0xff00) >> 8));
23
	}
24
#ifndef ONLY_VDP	
25
	else if(vdg_addr != -1){
26
		outp(vdg_addr, addr & 0x00ff);
27
		outp(vdg_addr, ((addr & 0xff00) >> 8));
28
	}
29
#endif
30
}
31
 
32
void read_vram(unsigned short addr){
33
	if(vdp_addr != -1){
34
		outp(vdp_addr, addr & 0x00ff);
35
		outp(vdp_addr, ((addr & 0xff00) >> 8));
36
	}
37
#ifndef ONLY_VDP
38
	else if(vdg_addr != -1){
39
		outp(vdg_addr, addr & 0x00ff);
40
		outp(vdg_addr, ((addr & 0xff00) >> 8));
41
	}
42
#endif
43
}
44
 
45
void setvramaddr(unsigned short addr){
46
	if(vdp_addr != -1){
47
		write_vram(0x800 + addr);
48
	}
49
#ifndef ONLY_VDP
50
	else if(vdg_addr != -1){
51
		write_vram(addr);
52
	}
53
#endif
54
}
55
 
32 nishi 56
void change_color(unsigned char color){
57
	if(vdp_addr != -1){
58
		outp(vdp_addr, color);
59
		outp(vdp_addr, 0x87);
60
		int i;
61
		write_vram(0x1400);
62
		for(i = 0; i < 0x10; i++) outp(vdp_data, color);
63
		write_vram(0x1400 + 0x10);
64
		for(i = 0; i < 0x10; i++) outp(vdp_data, ((i & 0xf) << 4) | 1);
65
	}
66
#ifndef ONLY_VDP
67
	else if(vdg_addr != -1){
68
	}
69
#endif
70
}
71
 
18 nishi 72
void setreadvramaddr(unsigned short addr){
73
	if(vdp_addr != -1){
74
		read_vram(0x800 + addr);
75
	}
76
#ifndef ONLY_VDP
77
	else if(vdg_addr != -1){
78
		read_vram(addr);
79
	}
80
#endif
81
}
82
 
83
void vramchar(unsigned char c){
84
	if(vdp_addr != -1){
85
		outp(vdp_data, c - 0x20);
86
	}
87
#ifndef ONLY_VDP
88
	else if(vdg_addr != -1){
89
		if(c == 248){
90
			outp(vdg_data, 0);
91
		}else{
92
			outp(vdg_data, toupper(c) - 'A' + 1);
93
		}
94
	}
95
#endif
96
}
97
 
98
void _vramchar(unsigned char c){
99
	if(vdp_addr != -1){
100
		outp(vdp_data, c);
101
	}
102
#ifndef ONLY_VDP
103
	else if(vdg_addr != -1){
104
		outp(vdg_data, c);
105
	}
106
#endif
107
}
108
 
109
unsigned char getvramchar(void){
110
	if(vdp_addr != -1){
19 nishi 111
		return inp(vdp_data) + 0x20;
18 nishi 112
	}
113
#ifndef ONLY_VDP
114
	else if(vdg_addr != -1){
19 nishi 115
		return inp(vdg_data) - 1 + 'A';
18 nishi 116
	}
117
#endif
118
	return 0;
119
}
120
 
27 nishi 121
void thin_char(void){
122
	if(vdp_addr != -1){
123
		scrwidth = 40;
124
		scrheight = 24;
125
 
126
		outp(vdp_addr, 0xd0);
127
		outp(vdp_addr, 0x81);
128
 
129
		outp(vdp_addr, 0xf4);
130
		outp(vdp_addr, 0x87);
131
	}
132
}
133
 
19 nishi 134
void scroll_y(void){
135
	int i;
136
	int size = muli(scrwidth, scrheight - 1);
137
	for(i = 0; i < size; i++){
138
		setreadvramaddr(i + scrwidth);
139
		unsigned char ch = getvramchar();
140
		setvramaddr(i);
141
		vramchar(ch);
142
	}
143
	for(i = 0; i < scrwidth; i++){
144
		vramchar(' ');
145
	}
146
}
147
 
18 nishi 148
void video_init(void){
149
	int i;
150
	if(vdp_addr != -1){
151
		scrwidth = 32;
152
		scrheight = 24;
153
 
154
		outp(vdp_addr, 0x00);
155
		outp(vdp_addr, 0x80);
156
 
157
		outp(vdp_addr, 0xd8);
158
		outp(vdp_addr, 0x81);
159
 
160
		outp(vdp_addr, 0x02);
161
		outp(vdp_addr, 0x82);
162
 
163
		outp(vdp_addr, 0x50);
164
		outp(vdp_addr, 0x83);
165
 
166
		outp(vdp_addr, 0x00);
167
		outp(vdp_addr, 0x84);
168
 
169
		outp(vdp_addr, 0x29);
170
		outp(vdp_addr, 0x85);
171
 
172
		outp(vdp_addr, 0x03);
173
		outp(vdp_addr, 0x86);
174
 
175
		/*
176
		 * VDP:
177
		 * 0x0000-0x0800: font
178
		 * 0x0800-0x1400: pattern
179
		 * 0x1400-0x1480: color
180
		 * 0x1480-0x1500: sprite attr
181
		 * 0x1800-0x2000: sprite pattern
182
		 */
183
 
184
		write_vram(0);
185
		for(i = 0; i < 0x800; i++) outp(vdp_data, *((unsigned char*)(0x6000 - 2048 + i)));
32 nishi 186
 
187
		change_color(0xf4);
18 nishi 188
	}
189
#ifndef ONLY_VDP
190
	else if(vdg_addr != -1){
191
		scrwidth = 32;
192
		scrheight = 16;
193
	}
194
#endif
195
}
196
 
197
void video_card(int t, int port){
198
	if(t == 0x01){
199
		vdp_addr = port - 2;
200
		vdp_data = port - 1;
201
	}else if(t == 0x02){
202
		vdg_addr = port - 2;
203
		vdg_data = port - 1;
204
	}
205
}