Subversion Repositories Shiroi

Rev

Details | Last modification | View Log | RSS feed

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