00001
00002
00003
00004
00005
00006
00007 #ifndef _C64_H
00008 #define _C64_H
00009
00010 #ifdef __BEOS__
00011 #include <KernelKit.h>
00012 #include <device/Joystick.h>
00013 #endif
00014
00015 #ifdef AMIGA
00016 #include <devices/timer.h>
00017 #include <devices/gameport.h>
00018 #include <devices/inputevent.h>
00019 #endif
00020
00021 #ifdef __riscos__
00022 #include "ROlib.h"
00023 #endif
00024
00025 #ifdef __SYMBIAN32__
00026 #include "joypad.h"
00027 #ifdef USE_STDLIB
00028 #include <e32std.h>
00029 #endif
00030 #include "sys/time.h"
00031 #endif
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 class Frodo;
00048
00049 class Prefs;
00050 class C64Display;
00051 class MOS6510;
00052 class MOS6569;
00053 class MOS6581;
00054 class MOS6526_1;
00055 class MOS6526_2;
00056 class IEC;
00057 class REU;
00058 class MOS6502_1541;
00059 class Job1541;
00060 class CmdPipe;
00061
00062
00066 class SidDebugData
00067 {
00068 public:
00069 TInt iTickPeriod_ys2;
00070 TUint iCountSamplesCopied;
00071 TUint iPrevCountSamplesCopied;
00072 TUint iCountDuplicatedBlocks;
00073 TUint iCountSkippedBlocks;
00074 TUint iCountNormalBlocks;
00075 TUint iCountExtraBlocks;
00076 TInt iPlayCompleteCounter;
00077 TInt iBufferLengthTooBigCounter;
00078 TUint iPrevTickCount;
00079 TTimeIntervalMicroSeconds iBufferLength;
00080 TInt iLeadInBlocks;
00081 TInt iLastVolumeSet;
00082 };
00083
00084
00088 class C64 {
00089 public:
00090 C64(Frodo* aFrodoPtr);
00091 ~C64();
00092
00093 void Run(void);
00094 void Quit(void);
00095 bool TogglePause(void);
00096 bool Paused(void);
00097 void Reset(void);
00098 void NMI(void);
00099 void VBlank(bool draw_frame);
00100 void NewPrefs(Prefs *prefs);
00101 void PatchKernal(bool fast_reset, bool emul_1541_proc);
00102 void SaveRAM(char *filename);
00103 void SaveSnapshot(char *filename);
00104 bool LoadSnapshot(char *filename);
00105 int SaveCPUState(FILE *f);
00106 int Save1541State(FILE *f);
00107 bool Save1541JobState(FILE *f);
00108 bool SaveVICState(FILE *f);
00109 bool SaveSIDState(FILE *f);
00110 bool SaveCIAState(FILE *f);
00111 bool LoadCPUState(FILE *f);
00112 bool Load1541State(FILE *f);
00113 bool Load1541JobState(FILE *f);
00114 bool LoadVICState(FILE *f);
00115 bool LoadSIDState(FILE *f);
00116 bool LoadCIAState(FILE *f);
00117
00118 uint8 *RAM, *Basic, *Kernal,
00119 *Char, *Color;
00120 uint8 *RAM1541, *ROM1541;
00121
00122 C64Display *TheDisplay;
00123
00124 MOS6510 *TheCPU;
00125 MOS6569 *TheVIC;
00126 MOS6581 *TheSID;
00127 MOS6526_1 *TheCIA1;
00128 MOS6526_2 *TheCIA2;
00129 IEC *TheIEC;
00130 REU *TheREU;
00131
00132 MOS6502_1541 *TheCPU1541;
00133 Job1541 *TheJob1541;
00134 void thread_func();
00135
00136 TBool iIsAudioPending;
00137 TBool iSoundHaveBeenPaused;
00138 bool have_a_break;
00139
00140 #ifdef FRODO_SC
00141 uint32 CycleCounter;
00142 #endif
00143
00144 private:
00145 void c64_ctor1(void);
00146 void c64_ctor2(void);
00147 void c64_dtor(void);
00148 void open_close_joysticks(bool oldjoy1, bool oldjoy2, bool newjoy1, bool newjoy2);
00149 uint8 poll_joystick(int port);
00150
00151 bool thread_running;
00152 bool quit_thyself;
00153
00154 int joy_minx, joy_maxx, joy_miny, joy_maxy;
00155 uint8 joykey;
00156
00157 uint8 orig_kernal_1d84,
00158 orig_kernal_1d85;
00159
00160 #ifdef __BEOS__
00161 public:
00162 void SoundSync(void);
00163
00164 private:
00165 static long thread_invoc(void *obj);
00166
00167 BJoystick *joy[2];
00168 thread_id the_thread;
00169 sem_id pause_sem;
00170 sem_id sound_sync_sem;
00171 double start_time;
00172 #endif
00173
00174 #ifdef AMIGA
00175 struct MsgPort *timer_port;
00176 struct timerequest *timer_io;
00177 struct timeval start_time;
00178 struct MsgPort *game_port;
00179 struct IOStdReq *game_io;
00180 struct GamePortTrigger game_trigger;
00181 struct InputEvent game_event;
00182 UBYTE joy_state;
00183 bool game_open, port_allocated;
00184 #endif
00185
00186 #ifdef __unix
00187 int joyfd[2];
00188 double speed_index;
00189 public:
00190 CmdPipe *gui;
00191 #endif
00192
00193 public:
00194 Frodo* iFrodoPtr;
00195
00196 #ifdef __SYMBIAN32__
00197 int joyfd[2];
00198 double speed_index;
00199 struct timeval tv_start;
00200 CJoyPadObserver* iJoyPadObserver;
00201
00202
00203 #if _DEBUG
00204 #define __D(a) a
00205 public:
00206 struct timeval tick, tock;
00207 long vic_time;
00208 #else
00209 #define __D(a)
00210 #endif
00211
00212 #endif // __SYMBIAN32__
00213
00214
00215 #ifndef GLOBAL_PREFS
00216 public:
00217 Prefs& ThePrefs;
00218 Prefs& ThePrefsOnDisk;
00219 #endif
00220
00221 #ifdef WIN32
00222 private:
00223 void CheckTimerChange();
00224 void StartTimer();
00225 void StopTimer();
00226 static void CALLBACK StaticTimeProc(UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2);
00227 void TimeProc(UINT id);
00228 #ifdef FRODO_SC
00229 void EmulateCyclesWith1541();
00230 void EmulateCyclesWithout1541();
00231 #endif
00232
00233 DWORD ref_time;
00234 int skipped_frames;
00235 int timer_every;
00236 HANDLE timer_semaphore;
00237 MMRESULT timer_id;
00238 int frame;
00239 uint8 joy_state;
00240 bool state_change;
00241 #endif
00242
00243 #ifdef __riscos__
00244 public:
00245 void RequestSnapshot(void);
00246 bool LoadOldSnapshot(FILE *f);
00247 void LoadSystemConfig(const char *filename);
00248 void SaveSystemConfig(const char *filename);
00249 void ReadTimings(int *poll_after, int *speed_after, int *sound_after);
00250 void WriteTimings(int poll_after, int speed_after, int sound_after);
00251
00252 WIMP *TheWIMP;
00253 int PollAfter;
00254 int SpeedAfter;
00255 int PollSoundAfter;
00256 int HostVolume;
00257
00258 private:
00259 bool make_a_snapshot;
00260
00261 uint8 joykey2;
00262
00263 uint8 joystate[2];
00264 bool Poll;
00265 int LastPoll, LastFrame, LastSpeed;
00266 int FramesSince;
00267 int laststate;
00268 int lastptr;
00269 bool SingleTasking;
00270 #endif
00271 };
00272
00273
00274 #endif