diff options
Diffstat (limited to 'apps/plugins/zxbox/spscr.c')
-rw-r--r-- | apps/plugins/zxbox/spscr.c | 270 |
1 files changed, 270 insertions, 0 deletions
diff --git a/apps/plugins/zxbox/spscr.c b/apps/plugins/zxbox/spscr.c new file mode 100644 index 0000000000..4cae8654ae --- /dev/null +++ b/apps/plugins/zxbox/spscr.c | |||
@@ -0,0 +1,270 @@ | |||
1 | /* | ||
2 | * Copyright (C) 1996-1998 Szeredi Miklos | ||
3 | * Email: mszeredi@inf.bme.hu | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; either version 2 of the License, or | ||
8 | * (at your option) any later version. See the file COPYING. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
18 | * | ||
19 | */ | ||
20 | |||
21 | #include "spscr_p.h" | ||
22 | #include "spscr.h" | ||
23 | |||
24 | #include "spperif.h" | ||
25 | #include "z80.h" | ||
26 | |||
27 | |||
28 | #include <stdlib.h> | ||
29 | #include <stdio.h> | ||
30 | |||
31 | int color_type = 0; | ||
32 | |||
33 | #define N0 0x04 | ||
34 | #define N1 0x34 | ||
35 | |||
36 | #define B0 0x08 | ||
37 | #define B1 0x3F | ||
38 | |||
39 | |||
40 | struct rgb *spscr_crgb; | ||
41 | |||
42 | static struct rgb norm_colors[COLORNUM]={ | ||
43 | {0,0,0},{N0,N0,N1},{N1,N0,N0},{N1,N0,N1}, | ||
44 | {N0,N1,N0},{N0,N1,N1},{N1,N1,N0},{N1,N1,N1}, | ||
45 | |||
46 | {0x15,0x15,0x15},{B0,B0,B1},{B1,B0,B0},{B1,B0,B1}, | ||
47 | {B0,B1,B0},{B0,B1,B1},{B1,B1,B0},{B1,B1,B1} | ||
48 | }; | ||
49 | |||
50 | static struct rgb gray_colors[COLORNUM]={ | ||
51 | {0,0,0},{20,20,20},{26,26,26},{32,32,32}, | ||
52 | {38,38,38},{44,44,44},{50,50,50},{56,56,56}, | ||
53 | |||
54 | {16,16,16},{23,23,23},{30,30,30},{36,36,36}, | ||
55 | {43,43,43},{50,50,50},{56,56,56},{63,63,63} | ||
56 | }; | ||
57 | |||
58 | struct rgb custom_colors[COLORNUM]={ | ||
59 | {0,0,0},{N0,N0,N1},{N1,N0,N0},{N1,N0,N1}, | ||
60 | {N0,N1,N0},{N0,N1,N1},{N1,N1,N0},{N1,N1,N1}, | ||
61 | |||
62 | {0x15,0x15,0x15},{B0,B0,B1},{B1,B0,B0},{B1,B0,B1}, | ||
63 | {B0,B1,B0},{B0,B1,B1},{B1,B1,B0},{B1,B1,B1} | ||
64 | }; | ||
65 | |||
66 | |||
67 | #define TABOFFS 2 | ||
68 | |||
69 | volatile int screen_visible = 1; | ||
70 | volatile int accept_keys = 1; | ||
71 | |||
72 | |||
73 | byte *update_screen_line(byte *scrp, int coli, int scri, int border, | ||
74 | qbyte *cmarkp) | ||
75 | { | ||
76 | qbyte *scrptr; | ||
77 | qbyte brd_color; | ||
78 | int i; | ||
79 | qbyte *tmptr, *mptr; | ||
80 | qbyte mark, cmark; | ||
81 | |||
82 | cmark = *cmarkp; | ||
83 | scrptr = (qbyte *) scrp; | ||
84 | if(scri >= 0) { /* normal line */ | ||
85 | if(SPNM(border_update)) { | ||
86 | brd_color = SPNM(colors)[border]; | ||
87 | brd_color |= brd_color << 8; | ||
88 | brd_color |= brd_color << 16; | ||
89 | for(i = 8; i; i--) *scrptr++ = brd_color; | ||
90 | scrptr += 0x40; | ||
91 | for(i = 8; i; i--) *scrptr++ = brd_color; | ||
92 | scrptr -= 0x48; | ||
93 | } | ||
94 | else scrptr += 0x08; | ||
95 | tmptr = SPNM(scr_mark) + 0x2C0 + (coli >> 3); | ||
96 | mark = *tmptr; | ||
97 | if(!(coli & 0x07)) { | ||
98 | cmark = mark; | ||
99 | *tmptr = 0; | ||
100 | } | ||
101 | else cmark |= mark; | ||
102 | mptr = SPNM(scr_mark) + scri; | ||
103 | |||
104 | mark = *mptr | cmark; | ||
105 | if(mark) { | ||
106 | byte *spmp, *spcp; | ||
107 | qbyte *scr_tab; | ||
108 | |||
109 | *mptr = 0; | ||
110 | SPNM(imag_mark)[coli] |= mark; | ||
111 | SPNM(imag_horiz) |= mark; | ||
112 | coli >>= 3; | ||
113 | SPNM(imag_vert) |= (1 << coli); | ||
114 | |||
115 | spmp = PRNM(proc).mem + (scri << 5); | ||
116 | spcp = PRNM(proc).mem + 0x5800 + (coli << 5); | ||
117 | |||
118 | if(!SPNM(flash_state)) scr_tab = SPNM(scr_f0_table); | ||
119 | else scr_tab = SPNM(scr_f1_table); | ||
120 | for(i = 32; i; i--) { | ||
121 | register dbyte spcx, spmx; | ||
122 | spcx = (*spcp++) << 6; | ||
123 | spmx = *spmp++; | ||
124 | *scrptr++ = scr_tab[spcx|((spmx & 0xf0) >> 4)]; | ||
125 | *scrptr++ = scr_tab[spcx|((spmx & 0x0f))]; | ||
126 | } | ||
127 | scrptr +=0x08; | ||
128 | } | ||
129 | else scrptr += 0x48; | ||
130 | } | ||
131 | else if(scri == -1) { /* only border */ | ||
132 | if(SPNM(border_update)) { | ||
133 | brd_color = SPNM(colors)[border]; | ||
134 | brd_color |= brd_color << 8; | ||
135 | brd_color |= brd_color << 16; | ||
136 | for(i = 0x50; i; i--) *scrptr++ = brd_color; | ||
137 | } | ||
138 | else scrptr += 0x50; | ||
139 | } | ||
140 | |||
141 | *cmarkp = cmark; | ||
142 | return (byte *) scrptr; | ||
143 | } | ||
144 | |||
145 | void translate_screen(void) | ||
146 | { | ||
147 | int border, scline; | ||
148 | byte *scrptr; | ||
149 | qbyte cmark = 0; | ||
150 | |||
151 | scrptr = (byte *) SPNM(image); | ||
152 | |||
153 | border = DANM(ula_outport) & 0x07; | ||
154 | if(border != SPNM(lastborder)) { | ||
155 | SPNM(border_update) = 2; | ||
156 | SPNM(lastborder) = border; | ||
157 | } | ||
158 | |||
159 | for(scline = 0; scline < (TMNUM / 2); scline++) | ||
160 | scrptr = update_screen_line(scrptr, SPNM(coli)[scline], SPNM(scri)[scline], | ||
161 | border, &cmark); | ||
162 | |||
163 | } | ||
164 | |||
165 | |||
166 | void spscr_init_mask_color(void) | ||
167 | { | ||
168 | int clb; | ||
169 | int bwb; | ||
170 | int hb; | ||
171 | int ix, j; | ||
172 | int bc, fc; | ||
173 | byte *tab_f0, *tab_f1; | ||
174 | |||
175 | sp_scr_f0_table = (qbyte *) (PRNM(proc).mem + 0x10000); | ||
176 | sp_scr_f1_table = (qbyte *) (PRNM(proc).mem + 0x20000); | ||
177 | |||
178 | sp_colors[8] = sp_colors[0]; | ||
179 | |||
180 | for(clb = 0; clb < 256; clb++) | ||
181 | for(hb = 0; hb < 16; hb++) { | ||
182 | |||
183 | bc = (clb & 0x38) >> 3; | ||
184 | fc = clb & 0x07; | ||
185 | |||
186 | if(clb & 0x40) { | ||
187 | fc |= 0x08; | ||
188 | bc |= 0x08; | ||
189 | } | ||
190 | bwb = hb; | ||
191 | |||
192 | ix = (clb << 8) + (hb << TABOFFS); | ||
193 | tab_f0 = ((byte *) sp_scr_f0_table) + ix + 3; | ||
194 | tab_f1 = ((byte *) sp_scr_f1_table) + ix + 3; | ||
195 | |||
196 | for(j = 4; j; bwb >>= 1, j--) { | ||
197 | *tab_f0-- = (byte) sp_colors[(bwb & 0x01) ? fc : bc]; | ||
198 | *tab_f1-- = (byte) sp_colors[(clb & 0x80) ? | ||
199 | ((bwb & 0x01) ? bc : fc) : | ||
200 | ((bwb & 0x01) ? fc : bc)]; | ||
201 | } | ||
202 | } | ||
203 | } | ||
204 | |||
205 | void flash_change(void) | ||
206 | { | ||
207 | int i,j; | ||
208 | byte *scp; | ||
209 | qbyte *mcp; | ||
210 | register unsigned int val; | ||
211 | |||
212 | mcp = sp_scr_mark + 0x2C0; | ||
213 | scp = z80_proc.mem + 0x5800; | ||
214 | |||
215 | for(i = 24; i; mcp++, i--) { | ||
216 | val = 0; | ||
217 | for(j = 32; j; scp++, j--) { | ||
218 | val >>= 1; | ||
219 | if(*scp & 0x80) val |= (1 << 31); | ||
220 | } | ||
221 | *mcp |= val; | ||
222 | } | ||
223 | } | ||
224 | |||
225 | void spscr_init_line_pointers(int lines) | ||
226 | { | ||
227 | int i; | ||
228 | int bs; | ||
229 | int y; | ||
230 | int scline; | ||
231 | |||
232 | bs = (lines - 192) / 2; | ||
233 | |||
234 | for(i = 0; i < PORT_TIME_NUM; i++) { | ||
235 | |||
236 | sp_scri[i] = -2; | ||
237 | |||
238 | if(i < ODDHF) scline = i; | ||
239 | else scline = i - ODDHF; | ||
240 | |||
241 | if(scline >= 64-bs && scline < 256+bs) { | ||
242 | if(scline >= 64 && scline < 256) { | ||
243 | y = scline - 64; | ||
244 | sp_coli[i] = y; | ||
245 | sp_scri[i] = 0x200 + | ||
246 | (y & 0xC0) + ((y & 0x07) << 3) + ((y & 0x38) >> 3); | ||
247 | } | ||
248 | else sp_scri[i] = -1; | ||
249 | } | ||
250 | } | ||
251 | } | ||
252 | |||
253 | void spscr_init_colors(void) | ||
254 | { | ||
255 | spscr_crgb = norm_colors; | ||
256 | |||
257 | switch(color_type) { | ||
258 | case 0: | ||
259 | spscr_crgb = norm_colors; | ||
260 | break; | ||
261 | |||
262 | case 1: | ||
263 | spscr_crgb = gray_colors; | ||
264 | break; | ||
265 | |||
266 | case 2: | ||
267 | spscr_crgb = custom_colors; | ||
268 | break; | ||
269 | } | ||
270 | } | ||