1 //////////////////////////////////////////////////
2 //                                              //
3 // Emu64                                        //
4 // von Thorsten Kattanek                        //
5 //                                              //
6 // #file: mos6510_class.h                       //
7 //                                              //
8 // Dieser Sourcecode ist Copyright geschützt!   //
9 // Geistiges Eigentum von Th.Kattanek           //
10 //                                              //
11 // Letzte Änderung am 17.09.2019                //
12 // www.emu64.de                                 //
13 //                                              //
14 //////////////////////////////////////////////////
15 
16 #ifndef MOS_6510_CLASS_H
17 #define MOS_6510_CLASS_H
18 
19 #include "./structs.h"
20 #include <functional>
21 
22 #define DEBUG_CART_ADRESS 0xD7FF
23 
24 class MOS6510
25 {
26 public:
27 
28     /// Funktionen ///
29     MOS6510(void);
30     ~MOS6510(void);
31     bool OneZyklus();
32     void Phi1();
33     void ClearJAMFlag(void);
34     void GetRegister(REG_STRUCT *reg);
35     void SetRegister(REG_STRUCT *reg);
36     bool GetInterrupts(int typ);
37     void GetInterneRegister(IREG_STRUCT *ireg);
38     void SetEnableDebugCart(bool enabled);
39     unsigned char GetDebugCartValue();
40     //bool SaveFreez(FILE *File);
41     //bool LoadFreez(FILE *File,unsigned short Version);
42 
43     void TriggerInterrupt(int typ);
44     void ClearInterrupt(int typ);
45 
46     std::function<unsigned char(unsigned short)> *ReadProcTbl;
47     std::function<void(unsigned short,unsigned char)> *WriteProcTbl;
48 
49     /// Variablen ///
50 
51     // Signale von Außen
52     bool *RDY;
53     bool *RESET;
54     bool WRITE_FF00;
55     bool WRITE_DEBUG_CART;
56 
57     bool EnableExtInterrupts;
58 
59     bool *ResetReady;	// Wird bei einem Reset False und beim erreichen einer
60 						// Adresse wird es True
61     unsigned short ResetReadyAdr;
62     bool JAMFlag;
63     unsigned short  *BreakStatus;
64     unsigned short  *Breakpoints;
65     unsigned short  *BreakWerte;
66     unsigned short  *History;
67     unsigned char   *HistoryPointer;
68 private:
69     /// Funktionen ///
70 
71     inline void SET_SR_NZ(unsigned char wert);
72     inline void SET_SIGN(unsigned char wert);
73     inline void SET_ZERO(unsigned char wert);
74     inline void SET_CARRY(unsigned char status);
75     inline bool IF_CARRY(void);
76     inline bool IF_DECIMAL(void);
77     inline void SET_OVERFLOW(bool status);
78     inline unsigned char Read(unsigned short adresse);
79     inline void Write(unsigned short adresse, unsigned char wert);
80 
81     /// Variablen ///
82 
83     unsigned char  *MCT;		// Zeigt immer an die aktuelle stelle in derMicro Code Tabel
84     unsigned char   Pointer;
85     unsigned short  Adresse;
86     unsigned short  BranchAdresse;
87     unsigned short  AktOpcode;
88     unsigned short  AktOpcodePC;
89     bool            CpuWait;
90     unsigned char   TMPByte;
91 
92     unsigned short  PC;
93     unsigned char   AC;
94     unsigned char   XR;
95     unsigned char   YR;
96     unsigned char   SP;
97     unsigned char   SR;
98     bool            Interrupts[IntQuellenC64];
99 
100     unsigned char   irq_state;          // if Größer 0 ist die Leitung low
101     bool            irq_is_low_pegel;
102     bool            irq_is_active;
103 
104     bool            irq_delay;
105     uint8_t         irq_delay_sr_value;
106 
107     bool            nmi_state;
108     bool            nmi_state_old;
109     bool            nmi_fall_edge;
110     bool            nmi_is_active;
111 
112     bool            EnableDebugCart;
113     unsigned char   DebugCartValue;
114 };
115 
116 #define SetAdresseLo(wert) Adresse = ((Adresse&0xFF00)|wert)
117 #define SetAdresseHi(wert) Adresse = ((Adresse&0x00FF)|(wert<<8))
118 
119 #define SetPCLo(wert) PC=((PC&0xFF00)|wert)
120 #define SetPCHi(wert) PC=((PC&0x00FF)|(wert<<8))
121 
122 #define GetPCLo ((unsigned char)PC)
123 #define GetPCHi ((unsigned char)(PC>>8))
124 
125 class MOS6510_PORT
126 {
127 public:
128 
129     /// Funktionen ///
130 
131     MOS6510_PORT(void);
132     ~MOS6510_PORT(void);
133     void Reset(void);
134     void ConfigChanged(int tape_sense, int caps_sense,unsigned char pullup);
135     //bool SaveFreez(FILE               //IRQCounter = 0;* File);
136     //bool LoadFreez(FILE* File,unsigned short Version);
137 
138     /// Variablen ///
139 
140     // Wert zum Prozessor Port schreiben
141     unsigned char DIR;
142     unsigned char DATA;
143 
144     // Wert vom Prozessor Port lesen
145     unsigned char DIR_READ;
146     unsigned char DATA_READ;
147 
148     // Status der Prozessor Port Pins
149     unsigned char DATA_OUT;
150 
151     /* cycle that should invalidate the unused bits of the data port. */
152     unsigned long DATA_SET_CLK_BIT6;
153     unsigned long DATA_SET_CLK_BIT7;
154 
155     /* indicates if the unused bits of the data port are still
156     valid or should be read as 0, 1 = unused bits valid,
157     0 = unused bits should be 0 */
158     unsigned char DATA_SET_BIT6;
159     unsigned char DATA_SET_BIT7;
160 
161     /* indicated if the unused bits are in the process of falling off. */
162     unsigned char DATA_FALLOFF_BIT6;
163     unsigned char DATA_FALLOFF_BIT7;
164 
165     bool TAPE_SENSE;
166     bool DATASETTE_MOTOR;
167 };
168 #endif // MOS_6510_CLASS_H
169