Main Page | Class Hierarchy | Compound List | File List | Compound Members | File Members | Related Pages

VIC.h

Go to the documentation of this file.
00001 /*
00002  *  VIC.h - 6569R5 emulation (line based)
00003  *
00004  *  Frodo (C) 1994-1997 Christian Bauer
00005  */
00006 
00007 #ifndef _VIC_H
00008 #define _VIC_H
00009 
00010 #include "sysdeps.h"
00011 
00012 #if COLOR_DEPTH == 4    // modified here:
00013 #define CD4(a) a
00014 #else 
00015 #define CD4(a)
00016 #endif
00017 
00018 // Define this if you want global variables instead of member variables
00019 #if !defined (__SYMBIAN32__)
00020 #if defined(__i386) || defined(mc68000) || defined(__MC68K__)
00021 #define GLOBAL_VARS
00022 #endif
00023 
00024 // Define this if you have a processor that can do unaligned accesses quickly
00025 #if defined(__i386) || defined(mc68000) || defined(__MC68K__)
00026 #define CAN_ACCESS_UNALIGNED
00027 #endif
00028 #endif // !__SYMBIAN32__
00029 
00030 
00032 const int TOTAL_RASTERS = 0x138;
00033 
00034 // Screen refresh frequency (PAL)
00035 const int SCREEN_FREQ = 50;
00036 
00037 
00038 class MOS6510;
00039 class C64Display;
00040 class C64;
00041 class Prefs;            //AEH 991202
00042 struct MOS6569State;
00043 
00044 
00045 class MOS6569 {
00046 public:
00047         MOS6569(C64 *c64, C64Display *disp, MOS6510 *CPU, uint8 *RAM, uint8 *Char, uint8 *Color);
00048         ~MOS6569();
00049 
00050         uint8 ReadRegister(uint16 adr);
00051         void WriteRegister(uint16 adr, uint8 byte);
00052 #ifdef FRODO_SC
00053         bool EmulateCycle(void);
00054 #else
00055         int EmulateLine(void);
00056 #endif
00057         void ChangedVA(uint16 new_va);  // CIA VA14/15 has changed
00058         void TriggerLightpen(void);             // Trigger lightpen interrupt
00059         void ReInitColors(void);
00060         void GetState(MOS6569State *vd);
00061         void SetState(MOS6569State *vd);
00062 
00063 #ifdef FRODO_SC
00064         uint8 LastVICByte;
00065 #endif
00066 
00067 private:
00068 
00069         void vblank(void);
00070 
00071 #ifndef GLOBAL_VARS
00072         void init_text_color_table(uint8 *colors);      //AEH 991130 
00073         void raster_irq(void);
00074 
00075 #ifdef __POWERPC__
00076         union {
00077                 struct {
00078                         uint8 a,b,c,d,e,f,g,h;
00079                 } a;
00080                 double b;
00081         } TextColorTable[16][16][256];
00082 #else
00083         union {
00084                 struct {
00085                         uint8 a,b,c,d;
00086                 } a;
00087                 uint32 b;
00088         }
00089 #if COLOR_DEPTH == 4    // modified here:
00090         TextColorTable[16][16][256];
00091         bool nibble_next;
00092 #elif COLOR_DEPTH == 8
00093         TextColorTable[16][16][256][2];
00094 #endif
00095         
00096 #endif // __POWERPC__
00097 
00098         uint16 mx[8];                           // VIC registers
00099         uint8 my[8];
00100         uint8 mx8;
00101         uint8 ctrl1, ctrl2;
00102         uint8 lpx, lpy;
00103         uint8 me, mxe, mye, mdp, mmc;
00104         uint8 vbase;
00105         uint8 irq_flag, irq_mask;
00106         uint8 clx_spr, clx_bgr;
00107         uint8 ec, b0c, b1c, b2c, b3c, mm0, mm1;
00108         uint8 sc[8];
00109 
00110         uint8 *ram, *char_rom, *color_ram; // Pointers to RAM and ROM
00111         C64 *the_c64;                           // Pointer to C64
00112         C64Display *the_display;        // Pointer to C64Display
00113         MOS6510 *the_cpu;                       // Pointer to 6510
00114 
00115         uint8 colors[256];                      // Indices of the 16 C64 colors (16 times mirrored to avoid "& 0x0f")
00116 
00117         uint8 ec_color, b0c_color, b1c_color,
00118               b2c_color, b3c_color;     // Indices for exterior/background colors
00119         uint8 mm0_color, mm1_color;     // Indices for MOB multicolors
00120         uint8 spr_color[8];                     // Indices for MOB colors
00121 
00122         uint32 ec_color_long;           // ec_color expanded to 32 bits
00123 
00124         uint8 matrix_line[40];          // Buffer for video line, read in Bad Lines
00125         uint8 color_line[40];           // Buffer for color line, read in Bad Lines
00126 
00127 #ifdef __POWERPC__
00128         double chunky_tmp[0x180/8];     // Temporary line buffer for speedup
00129 #endif
00130 
00131 #ifdef __SYMBIAN32__
00132         uint8* chunky_base;                     
00133 #endif
00134         uint8 *chunky_line_start;       // Pointer to start of current line in bitmap buffer
00135         int xmod;                                       // Number of bytes per row
00136 
00137         uint16 raster_y;                                // Current raster line
00138         uint16 irq_raster;                      // Interrupt raster line
00139         uint16 dy_start;                                // Comparison values for border logic
00140         uint16 dy_stop;
00141         uint16 rc;                                      // Row counter
00142         uint16 vc;                                      // Video counter
00143         uint16 vc_base;                         // Video counter base
00144         uint16 x_scroll;                                // X scroll value
00145         uint16 y_scroll;                                // Y scroll value
00146         uint16 cia_vabase;                      // CIA VA14/15 video base
00147 
00148         uint16 mc[8];                           // Sprite data counters
00149 
00150         int display_idx;                        // Index of current display mode
00151         int skip_counter;                       // Counter for frame-skipping
00152 
00153         long pad0;      // Keep buffers long-aligned
00154         uint8 spr_coll_buf[0x180];      // Buffer for sprite-sprite collisions and priorities
00155         uint8 fore_mask_buf[0x180/8];   // Foreground mask for sprite-graphics collisions and priorities
00156 #ifndef CAN_ACCESS_UNALIGNED
00157         uint8 text_chunky_buf[40*8];    // Line graphics buffer
00158 #endif
00159 
00160         bool display_state;                     // true: Display state, false: Idle state
00161         bool border_on;                         // Flag: Upper/lower border on (Frodo SC: Main border flipflop)
00162         bool frame_skipped;                     // Flag: Frame is being skipped
00163         uint8 bad_lines_enabled;        // Flag: Bad Lines enabled for this frame
00164         bool lp_triggered;                      // Flag: Lightpen was triggered in this frame
00165 
00166 #ifdef FRODO_SC
00167         uint8 read_byte(uint16 adr);
00168         void matrix_access(void);
00169         void graphics_access(void);
00170         void draw_graphics(void);
00171         void draw_sprites(void);
00172         void draw_background(void);
00173 
00174         int cycle;                                      // Current cycle in line (1..63)
00175 
00176         uint8 *chunky_ptr;                      // Pointer in chunky bitmap buffer (this is where out output goes)
00177         uint8 *fore_mask_ptr;           // Pointer in fore_mask_buf
00178 
00179         uint16 matrix_base;                     // Video matrix base
00180         uint16 char_base;                       // Character generator base
00181         uint16 bitmap_base;                     // Bitmap base
00182 
00183         bool is_bad_line;                       // Flag: Current line is bad line
00184         bool draw_this_line;            // Flag: This line is drawn on the screen
00185         bool ud_border_on;                      // Flag: Upper/lower border on
00186         bool vblanking;                         // Flag: VBlank in next cycle
00187 
00188         bool border_on_sample[5];       // Samples of border state at different cycles (1, 17, 18, 56, 57)
00189         uint8 border_color_sample[0x180/8];     // Samples of border color at each "displayed" cycle
00190 
00191         uint8 ref_cnt;                          // Refresh counter
00192         uint8 spr_exp_y;                        // 8 sprite y expansion flipflops
00193         uint8 spr_dma_on;                       // 8 flags: Sprite DMA active
00194         uint8 spr_disp_on;                      // 8 flags: Sprite display active
00195         uint8 spr_draw;                         // 8 flags: Draw sprite in this line
00196         uint16 spr_ptr[8];                      // Sprite data pointers
00197         uint16 mc_base[8];                      // Sprite data counter bases
00198 
00199         uint16 raster_x;                        // Current raster x position
00200 
00201         int ml_index;                           // Index in matrix/color_line[]
00202         uint8 gfx_data, char_data, color_data, last_char_data;
00203         uint8 spr_data[8][4];           // Sprite data read
00204         uint8 spr_draw_data[8][4];      // Sprite data for drawing
00205 
00206         uint32 first_ba_cycle;          // Cycle when BA first went low
00207 
00208 #else // FRODO_SC
00209 
00210         uint8 *get_physical(uint16 adr);
00211         void el_std_text(uint8 *p, uint8 *q, uint8 *r);
00212         void el_mc_text(uint8 *p, uint8 *q, uint8 *r);
00213         void el_std_bitmap(uint8 *p, uint8 *q, uint8 *r);
00214         void el_mc_bitmap(uint8 *p, uint8 *q, uint8 *r);
00215         void el_ecm_text(uint8 *p, uint8 *q, uint8 *r);
00216         void el_std_idle(uint8 *p, uint8 *r);
00217         void el_mc_idle(uint8 *p, uint8 *r);
00218         int el_update_mc(int raster);
00219 
00220         uint16 mc_color_lookup[4];
00221 
00222         bool border_40_col;                     // Flag: 40 column border
00223         uint8 sprite_on;                        // 8 flags: Sprite display/DMA active
00224 
00225         uint8 *matrix_base;                     // Video matrix base
00226         uint8 *char_base;                       // Character generator base
00227         uint8 *bitmap_base;                     // Bitmap base
00228 
00229 #endif // FRODO_SC
00230 
00231 #endif // GLOBAL_VARS
00232 
00233         void make_mc_table(void);
00234         void el_sprites(uint8 *chunky_ptr);
00235 
00236 #ifndef GLOBAL_PREFS
00237 public:
00238         Prefs& ThePrefs;
00239 #endif
00240 
00241 #ifdef BACKGND_UPDATE
00242 public:
00243         int ec_changed;
00244 #endif
00245 
00246 };
00247 
00248 
00249 // VIC state
00250 struct MOS6569State {
00251         uint8 m0x;                              // Sprite coordinates
00252         uint8 m0y;
00253         uint8 m1x;
00254         uint8 m1y;
00255         uint8 m2x;
00256         uint8 m2y;
00257         uint8 m3x;
00258         uint8 m3y;
00259         uint8 m4x;
00260         uint8 m4y;
00261         uint8 m5x;
00262         uint8 m5y;
00263         uint8 m6x;
00264         uint8 m6y;
00265         uint8 m7x;
00266         uint8 m7y;
00267         uint8 mx8;
00268 
00269         uint8 ctrl1;                    // Control registers
00270         uint8 raster;
00271         uint8 lpx;
00272         uint8 lpy;
00273         uint8 me;
00274         uint8 ctrl2;
00275         uint8 mye;
00276         uint8 vbase;
00277         uint8 irq_flag;
00278         uint8 irq_mask;
00279         uint8 mdp;
00280         uint8 mmc;
00281         uint8 mxe;
00282         uint8 mm;
00283         uint8 md;
00284 
00285         uint8 ec;                               // Color registers
00286         uint8 b0c;
00287         uint8 b1c;
00288         uint8 b2c;
00289         uint8 b3c;
00290         uint8 mm0;
00291         uint8 mm1;
00292         uint8 m0c;
00293         uint8 m1c;
00294         uint8 m2c;
00295         uint8 m3c;
00296         uint8 m4c;
00297         uint8 m5c;
00298         uint8 m6c;
00299         uint8 m7c;
00300                                                         // Additional registers
00301         uint8 pad0;
00302         uint16 irq_raster;              // IRQ raster line
00303         uint16 vc;                              // Video counter
00304         uint16 vc_base;                 // Video counter base
00305         uint8 rc;                               // Row counter
00306         uint8 spr_dma;                  // 8 Flags: Sprite DMA active
00307         uint8 spr_disp;                 // 8 Flags: Sprite display active
00308         uint8 mc[8];                    // Sprite data counters
00309         uint8 mc_base[8];               // Sprite data counter bases
00310         bool display_state;             // true: Display state, false: Idle state
00311         bool bad_line;                  // Flag: Bad Line state
00312         bool bad_line_enable;   // Flag: Bad Lines enabled for this frame
00313         bool lp_triggered;              // Flag: Lightpen was triggered in this frame
00314         bool border_on;                 // Flag: Upper/lower border on (Frodo SC: Main border flipflop)
00315 
00316         uint16 bank_base;               // VIC bank base address
00317         uint16 matrix_base;             // Video matrix base
00318         uint16 char_base;               // Character generator base
00319         uint16 bitmap_base;             // Bitmap base
00320         uint16 sprite_base[8];  // Sprite bases
00321 
00322                                                         // Frodo SC:
00323         int cycle;                              // Current cycle in line (1..63)
00324         uint16 raster_x;                // Current raster x position
00325         int ml_index;                   // Index in matrix/color_line[]
00326         uint8 ref_cnt;                  // Refresh counter
00327         uint8 last_vic_byte;    // Last byte read by VIC
00328         bool ud_border_on;              // Flag: Upper/lower border on
00329 };
00330 
00331 #endif

Generated on Tue Feb 8 04:08:15 2005 for E32frodo by doxygen 1.3.3