ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/Frodo4/Src/VIC.h
Revision: 1.4
Committed: 2005-06-27T19:55:48Z (17 years, 5 months ago) by cebix
Content type: text/plain
Branch: MAIN
CVS Tags: VERSION_4_2, HEAD
Changes since 1.3: +1 -1 lines
Log Message:
updated copyright dates

File Contents

# Content
1 /*
2 * VIC.h - 6569R5 emulation (line based)
3 *
4 * Frodo (C) 1994-1997,2002-2005 Christian Bauer
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #ifndef _VIC_H
22 #define _VIC_H
23
24
25 // Define this if you want global variables instead of member variables
26 #if defined(__i386) || defined(mc68000) || defined(__MC68K__)
27 #define GLOBAL_VARS
28 #endif
29
30 // Define this if you have a processor that can do unaligned accesses quickly
31 #if defined(__i386) || defined(mc68000) || defined(__MC68K__)
32 #define CAN_ACCESS_UNALIGNED
33 #endif
34
35
36 // Total number of raster lines (PAL)
37 const unsigned TOTAL_RASTERS = 0x138;
38
39 // Screen refresh frequency (PAL)
40 const unsigned SCREEN_FREQ = 50;
41
42
43 class MOS6510;
44 class C64Display;
45 class C64;
46 struct MOS6569State;
47
48
49 class MOS6569 {
50 public:
51 MOS6569(C64 *c64, C64Display *disp, MOS6510 *CPU, uint8 *RAM, uint8 *Char, uint8 *Color);
52
53 uint8 ReadRegister(uint16 adr);
54 void WriteRegister(uint16 adr, uint8 byte);
55 #ifdef FRODO_SC
56 bool EmulateCycle(void);
57 #else
58 int EmulateLine(void);
59 #endif
60 void ChangedVA(uint16 new_va); // CIA VA14/15 has changed
61 void TriggerLightpen(void); // Trigger lightpen interrupt
62 void ReInitColors(void);
63 void GetState(MOS6569State *vd);
64 void SetState(MOS6569State *vd);
65
66 #ifdef FRODO_SC
67 uint8 LastVICByte;
68 #endif
69
70 private:
71 #ifndef GLOBAL_VARS
72 void vblank(void);
73 void raster_irq(void);
74
75 uint16 mx[8]; // VIC registers
76 uint8 my[8];
77 uint8 mx8;
78 uint8 ctrl1, ctrl2;
79 uint8 lpx, lpy;
80 uint8 me, mxe, mye, mdp, mmc;
81 uint8 vbase;
82 uint8 irq_flag, irq_mask;
83 uint8 clx_spr, clx_bgr;
84 uint8 ec, b0c, b1c, b2c, b3c, mm0, mm1;
85 uint8 sc[8];
86
87 uint8 *ram, *char_rom, *color_ram; // Pointers to RAM and ROM
88 C64 *the_c64; // Pointer to C64
89 C64Display *the_display; // Pointer to C64Display
90 MOS6510 *the_cpu; // Pointer to 6510
91
92 uint8 colors[256]; // Indices of the 16 C64 colors (16 times mirrored to avoid "& 0x0f")
93
94 uint8 ec_color, b0c_color, b1c_color,
95 b2c_color, b3c_color; // Indices for exterior/background colors
96 uint8 mm0_color, mm1_color; // Indices for MOB multicolors
97 uint8 spr_color[8]; // Indices for MOB colors
98
99 uint32 ec_color_long; // ec_color expanded to 32 bits
100
101 uint8 matrix_line[40]; // Buffer for video line, read in Bad Lines
102 uint8 color_line[40]; // Buffer for color line, read in Bad Lines
103
104 #ifdef __POWERPC__
105 double chunky_tmp[0x180/8]; // Temporary line buffer for speedup
106 #endif
107 uint8 *chunky_line_start; // Pointer to start of current line in bitmap buffer
108 int xmod; // Number of bytes per row
109
110 uint16 raster_y; // Current raster line
111 uint16 irq_raster; // Interrupt raster line
112 uint16 dy_start; // Comparison values for border logic
113 uint16 dy_stop;
114 uint16 rc; // Row counter
115 uint16 vc; // Video counter
116 uint16 vc_base; // Video counter base
117 uint16 x_scroll; // X scroll value
118 uint16 y_scroll; // Y scroll value
119 uint16 cia_vabase; // CIA VA14/15 video base
120
121 uint16 mc[8]; // Sprite data counters
122
123 int display_idx; // Index of current display mode
124 int skip_counter; // Counter for frame-skipping
125
126 long pad0; // Keep buffers long-aligned
127 uint8 spr_coll_buf[0x180]; // Buffer for sprite-sprite collisions and priorities
128 uint8 fore_mask_buf[0x180/8]; // Foreground mask for sprite-graphics collisions and priorities
129 #ifndef CAN_ACCESS_UNALIGNED
130 uint8 text_chunky_buf[40*8]; // Line graphics buffer
131 #endif
132
133 bool display_state; // true: Display state, false: Idle state
134 bool border_on; // Flag: Upper/lower border on (Frodo SC: Main border flipflop)
135 bool frame_skipped; // Flag: Frame is being skipped
136 uint8 bad_lines_enabled; // Flag: Bad Lines enabled for this frame
137 bool lp_triggered; // Flag: Lightpen was triggered in this frame
138
139 #ifdef FRODO_SC
140 uint8 read_byte(uint16 adr);
141 void matrix_access(void);
142 void graphics_access(void);
143 void draw_graphics(void);
144 void draw_sprites(void);
145 void draw_background(void);
146
147 int cycle; // Current cycle in line (1..63)
148
149 uint8 *chunky_ptr; // Pointer in chunky bitmap buffer (this is where out output goes)
150 uint8 *fore_mask_ptr; // Pointer in fore_mask_buf
151
152 uint16 matrix_base; // Video matrix base
153 uint16 char_base; // Character generator base
154 uint16 bitmap_base; // Bitmap base
155
156 bool is_bad_line; // Flag: Current line is bad line
157 bool draw_this_line; // Flag: This line is drawn on the screen
158 bool ud_border_on; // Flag: Upper/lower border on
159 bool vblanking; // Flag: VBlank in next cycle
160
161 bool border_on_sample[5]; // Samples of border state at different cycles (1, 17, 18, 56, 57)
162 uint8 border_color_sample[0x180/8]; // Samples of border color at each "displayed" cycle
163
164 uint8 ref_cnt; // Refresh counter
165 uint8 spr_exp_y; // 8 sprite y expansion flipflops
166 uint8 spr_dma_on; // 8 flags: Sprite DMA active
167 uint8 spr_disp_on; // 8 flags: Sprite display active
168 uint8 spr_draw; // 8 flags: Draw sprite in this line
169 uint16 spr_ptr[8]; // Sprite data pointers
170 uint16 mc_base[8]; // Sprite data counter bases
171
172 uint16 raster_x; // Current raster x position
173
174 int ml_index; // Index in matrix/color_line[]
175 uint8 gfx_data, char_data, color_data, last_char_data;
176 uint8 spr_data[8][4]; // Sprite data read
177 uint8 spr_draw_data[8][4]; // Sprite data for drawing
178
179 uint32 first_ba_cycle; // Cycle when BA first went low
180 #else
181 uint8 *get_physical(uint16 adr);
182 void make_mc_table(void);
183 void el_std_text(uint8 *p, uint8 *q, uint8 *r);
184 void el_mc_text(uint8 *p, uint8 *q, uint8 *r);
185 void el_std_bitmap(uint8 *p, uint8 *q, uint8 *r);
186 void el_mc_bitmap(uint8 *p, uint8 *q, uint8 *r);
187 void el_ecm_text(uint8 *p, uint8 *q, uint8 *r);
188 void el_std_idle(uint8 *p, uint8 *r);
189 void el_mc_idle(uint8 *p, uint8 *r);
190 void el_sprites(uint8 *chunky_ptr);
191 int el_update_mc(int raster);
192
193 uint16 mc_color_lookup[4];
194
195 bool border_40_col; // Flag: 40 column border
196 uint8 sprite_on; // 8 flags: Sprite display/DMA active
197
198 uint8 *matrix_base; // Video matrix base
199 uint8 *char_base; // Character generator base
200 uint8 *bitmap_base; // Bitmap base
201 #endif
202 #endif
203 };
204
205
206 // VIC state
207 struct MOS6569State {
208 uint8 m0x; // Sprite coordinates
209 uint8 m0y;
210 uint8 m1x;
211 uint8 m1y;
212 uint8 m2x;
213 uint8 m2y;
214 uint8 m3x;
215 uint8 m3y;
216 uint8 m4x;
217 uint8 m4y;
218 uint8 m5x;
219 uint8 m5y;
220 uint8 m6x;
221 uint8 m6y;
222 uint8 m7x;
223 uint8 m7y;
224 uint8 mx8;
225
226 uint8 ctrl1; // Control registers
227 uint8 raster;
228 uint8 lpx;
229 uint8 lpy;
230 uint8 me;
231 uint8 ctrl2;
232 uint8 mye;
233 uint8 vbase;
234 uint8 irq_flag;
235 uint8 irq_mask;
236 uint8 mdp;
237 uint8 mmc;
238 uint8 mxe;
239 uint8 mm;
240 uint8 md;
241
242 uint8 ec; // Color registers
243 uint8 b0c;
244 uint8 b1c;
245 uint8 b2c;
246 uint8 b3c;
247 uint8 mm0;
248 uint8 mm1;
249 uint8 m0c;
250 uint8 m1c;
251 uint8 m2c;
252 uint8 m3c;
253 uint8 m4c;
254 uint8 m5c;
255 uint8 m6c;
256 uint8 m7c;
257 // Additional registers
258 uint8 pad0;
259 uint16 irq_raster; // IRQ raster line
260 uint16 vc; // Video counter
261 uint16 vc_base; // Video counter base
262 uint8 rc; // Row counter
263 uint8 spr_dma; // 8 Flags: Sprite DMA active
264 uint8 spr_disp; // 8 Flags: Sprite display active
265 uint8 mc[8]; // Sprite data counters
266 uint8 mc_base[8]; // Sprite data counter bases
267 bool display_state; // true: Display state, false: Idle state
268 bool bad_line; // Flag: Bad Line state
269 bool bad_line_enable; // Flag: Bad Lines enabled for this frame
270 bool lp_triggered; // Flag: Lightpen was triggered in this frame
271 bool border_on; // Flag: Upper/lower border on (Frodo SC: Main border flipflop)
272
273 uint16 bank_base; // VIC bank base address
274 uint16 matrix_base; // Video matrix base
275 uint16 char_base; // Character generator base
276 uint16 bitmap_base; // Bitmap base
277 uint16 sprite_base[8]; // Sprite bases
278
279 // Frodo SC:
280 int cycle; // Current cycle in line (1..63)
281 uint16 raster_x; // Current raster x position
282 int ml_index; // Index in matrix/color_line[]
283 uint8 ref_cnt; // Refresh counter
284 uint8 last_vic_byte; // Last byte read by VIC
285 bool ud_border_on; // Flag: Upper/lower border on
286 };
287
288 #endif