1 /* 2 * C64.h - Put the pieces together 3 * 4 * Frodo (C) 1994-1997,2002 Christian Bauer 5 */ 6 7 #ifndef _C64_H 8 #define _C64_H 9 10 #ifdef __BEOS__ 11 #include <KernelKit.h> 12 #include <device/Joystick.h> 13 #endif 14 15 #ifdef AMIGA 16 #include <devices/timer.h> 17 #include <devices/gameport.h> 18 #include <devices/inputevent.h> 19 #endif 20 21 #ifdef __riscos__ 22 #include "ROlib.h" 23 #endif 24 25 26 // false: Frodo, true: FrodoSC 27 extern bool IsFrodoSC; 28 29 30 class Prefs; 31 class C64Display; 32 class MOS6510; 33 class MOS6569; 34 class MOS6581; 35 class MOS6526_1; 36 class MOS6526_2; 37 class IEC; 38 class REU; 39 class MOS6502_1541; 40 class Job1541; 41 class CmdPipe; 42 43 class C64 { 44 public: 45 C64(); 46 ~C64(); 47 48 void Run(void); 49 void Quit(void); 50 void Pause(void); 51 void Resume(void); 52 void Reset(void); 53 void NMI(void); 54 void VBlank(bool draw_frame); 55 void NewPrefs(Prefs *prefs); 56 void PatchKernal(bool fast_reset, bool emul_1541_proc); 57 void SaveRAM(char *filename); 58 void SaveSnapshot(char *filename); 59 bool LoadSnapshot(char *filename); 60 int SaveCPUState(FILE *f); 61 int Save1541State(FILE *f); 62 bool Save1541JobState(FILE *f); 63 bool SaveVICState(FILE *f); 64 bool SaveSIDState(FILE *f); 65 bool SaveCIAState(FILE *f); 66 bool LoadCPUState(FILE *f); 67 bool Load1541State(FILE *f); 68 bool Load1541JobState(FILE *f); 69 bool LoadVICState(FILE *f); 70 bool LoadSIDState(FILE *f); 71 bool LoadCIAState(FILE *f); 72 73 uint8 *RAM, *Basic, *Kernal, 74 *Char, *Color; // C64 75 uint8 *RAM1541, *ROM1541; // 1541 76 77 C64Display *TheDisplay; 78 79 MOS6510 *TheCPU; // C64 80 MOS6569 *TheVIC; 81 MOS6581 *TheSID; 82 MOS6526_1 *TheCIA1; 83 MOS6526_2 *TheCIA2; 84 IEC *TheIEC; 85 REU *TheREU; 86 87 MOS6502_1541 *TheCPU1541; // 1541 88 Job1541 *TheJob1541; 89 90 #ifdef FRODO_SC 91 uint32 CycleCounter; 92 #endif 93 94 private: 95 void c64_ctor1(void); 96 void c64_ctor2(void); 97 void c64_dtor(void); 98 void open_close_joysticks(bool oldjoy1, bool oldjoy2, bool newjoy1, bool newjoy2); 99 uint8 poll_joystick(int port); 100 void thread_func(void); 101 102 bool thread_running; // Emulation thread is running 103 bool quit_thyself; // Emulation thread shall quit 104 bool have_a_break; // Emulation thread shall pause 105 106 int joy_minx, joy_maxx, joy_miny, joy_maxy; // For dynamic joystick calibration 107 uint8 joykey; // Joystick keyboard emulation mask value 108 109 uint8 orig_kernal_1d84, // Original contents of kernal locations $1d84 and $1d85 110 orig_kernal_1d85; // (for undoing the Fast Reset patch) 111 112 #ifdef __BEOS__ 113 public: 114 void SoundSync(void); 115 116 private: 117 static long thread_invoc(void *obj); 118 119 BJoystick *joy[2]; // Joystick objects 120 thread_id the_thread; 121 sem_id pause_sem; 122 sem_id sound_sync_sem; 123 double start_time; 124 #endif 125 126 #ifdef AMIGA 127 struct MsgPort *timer_port; // For speed limiter 128 struct timerequest *timer_io; 129 struct timeval start_time; 130 struct MsgPort *game_port; // For joystick 131 struct IOStdReq *game_io; 132 struct GamePortTrigger game_trigger; 133 struct InputEvent game_event; 134 UBYTE joy_state; // Current state of joystick 135 bool game_open, port_allocated; // Flags: gameport.device opened, game port allocated 136 #endif 137 138 #ifdef __unix 139 int joyfd[2]; // File descriptors for joysticks 140 double speed_index; 141 public: 142 CmdPipe *gui; 143 #endif 144 145 #ifdef WIN32 146 private: 147 void CheckTimerChange(); 148 void StartTimer(); 149 void StopTimer(); 150 static void CALLBACK StaticTimeProc(UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2); 151 void TimeProc(UINT id); 152 #ifdef FRODO_SC 153 void EmulateCyclesWith1541(); 154 void EmulateCyclesWithout1541(); 155 #endif 156 157 DWORD ref_time; // when frame count was reset 158 int skipped_frames; // number of skipped frames 159 int timer_every; // frequency of timer in frames 160 HANDLE timer_semaphore; // Timer semaphore for synch 161 MMRESULT timer_id; // Timer identifier 162 int frame; // current frame number 163 uint8 joy_state; // Current state of joystick 164 bool state_change; 165 #endif 166 167 #ifdef __riscos__ 168 public: 169 void RequestSnapshot(void); 170 bool LoadOldSnapshot(FILE *f); 171 void LoadSystemConfig(const char *filename); // loads timing vals and keyboard joys 172 void SaveSystemConfig(const char *filename); // saves timing vals and keyboard joys 173 void ReadTimings(int *poll_after, int *speed_after, int *sound_after); 174 void WriteTimings(int poll_after, int speed_after, int sound_after); 175 176 WIMP *TheWIMP; 177 int PollAfter; // centiseconds before polling 178 int SpeedAfter; // centiseconds before updating speedometer 179 int PollSoundAfter; // *rasterlines* after which DigitalRenderer is polled 180 int HostVolume; // sound volume of host machine 181 182 private: 183 bool make_a_snapshot; 184 185 uint8 joykey2; // two keyboard joysticks possible here 186 187 uint8 joystate[2]; // Joystick state 188 bool Poll; // TRUE if polling should take place 189 int LastPoll, LastFrame, LastSpeed; // time of last poll / last frame / speedom (cs) 190 int FramesSince; 191 int laststate; // last keyboard state (-> scroll lock) 192 int lastptr; // last mouse pointer shape 193 bool SingleTasking; 194 #endif 195 }; 196 197 198 #endif 199