]> Shamusworld >> Repos - thunder/blob - src/v63701.h
47c5b1802d386f164b380f06e42b433e9b8dcc84
[thunder] / src / v63701.h
1 //
2 // Virtual 63701 Header file
3 //
4 // by James Hammons
5 // (C) 2014 Underground Software
6 //
7
8 #ifndef __V63701_H__
9 #define __V63701_H__
10
11 #include <stdint.h>
12
13 // Useful defines
14
15 #define FLAG_H          0x20            // Half carry
16 #define FLAG_I          0x10            // IRQ
17 #define FLAG_N          0x08            // Negative
18 #define FLAG_Z          0x04            // Zero
19 #define FLAG_V          0x02            // oVerflow
20 #define FLAG_C          0x01            // Carry
21
22 #define V63701_ASSERT_LINE_RESET        0x0001  // v63701 RESET line
23 #define V63701_ASSERT_LINE_IRQ          0x0002  // v63701 IRQ line
24 #define V63701_ASSERT_LINE_NMI          0x0004  // v63701 NMI line
25 #define V63701_STATE_WAI                        0x0008  // v63701 wait for IRQ line
26 #define V63701_ASSERT_TIMER_OVERFLOW    0x0010
27 #define V63701_ASSERT_OUTPUT_COMPARE    0x0020
28 #define V63701_ASSERT_INPUT_CAPTURE     0x0040
29 #define V63701_ASSERT_TRAP                      0x0080  // Illegal instruction executed flag
30 //#define V6809_START_DEBUG_LOG         0x8000  // Debug log go (temporary!)
31
32 // Useful structs
33
34 union Byte
35 {
36         struct
37         {
38                 uint8_t b0: 1; uint8_t b1: 1; uint8_t b2: 1; uint8_t b3: 1;
39                 uint8_t b4: 1; uint8_t b5: 1; uint8_t b6: 1; uint8_t b7: 1;
40         } bit;
41         uint8_t byte;
42 };
43
44 union Word
45 {
46         struct
47         {
48                 uint8_t lo: 8;
49                 uint8_t hi: 8;
50         } byte;
51         uint16_t word;
52 };
53
54 union Flags
55 {
56         struct
57         {
58                 uint8_t c: 1;
59                 uint8_t v: 1;
60                 uint8_t z: 1;
61                 uint8_t n: 1;
62                 uint8_t i: 1;
63                 uint8_t h: 1;
64         } flag;
65         uint8_t byte;
66 };
67
68 union TCSR
69 {
70         struct
71         {
72                 uint8_t olvl: 1;
73                 uint8_t iedg: 1;
74                 uint8_t etoi: 1;        // Enable Timer Over
75                 uint8_t eoci: 1;        // Enable Output Compare
76                 uint8_t eici: 1;        // Enable Input Capture
77                 uint8_t tof: 1;         // Timer Over
78                 uint8_t ocf: 1;         // Output Compare
79                 uint8_t icf: 1;         // Input Capture
80         } bit;
81         uint8_t byte;
82 };
83
84 union WordReg
85 {
86         struct
87         {
88                 uint8_t b: 8;
89                 uint8_t a: 8;
90         } acc;
91         uint16_t word;
92 };
93
94 struct V63701REGS
95 {
96         uint16_t pc;                                    // 63701 PC register
97         uint16_t x;                                             // 63701 X index register
98         uint16_t s;                                             // 63701 System stack pointer
99         uint8_t cc;                                             // 63701 Condition Code register
100 //      uint8_t a;                                              // 63701 A register
101 //      uint8_t b;                                              // 63701 B register
102         WordReg d;                                              // 63701 A & B registers (A is hi, B is lo)
103         TCSR tcsr;                                              // 63701 Timer control/Status register
104         Word counter;                                   // 63701 Counter register
105         Word outputCompare;                             // 63701 Output Compare register
106         uint8_t ddr1;
107         uint8_t ddr2;
108         uint8_t port1;
109         uint8_t port2;
110         uint8_t ramCtrl;
111         uint8_t cWriteLatch;                    // Counter write latch
112         uint8_t cReadLatch;                             // Counter read latch
113         bool tcsrWasRead;                               // TCSR was read flag
114         uint64_t clock;                                 // 63701 clock
115         uint8_t (* RdMem)(uint16_t);    // Address of uint8 read routine
116         void (* WrMem)(uint16_t, uint8_t);      // Address of uint8 write routine
117         uint32_t cpuFlags;                              // v63701 IRQ/RESET flags
118         uint32_t clockOverrun;                  // Amount of overflow between runs
119 };
120
121 // Function prototypes
122
123 void Execute63701(V63701REGS *, uint32_t);      // Function to execute 63701 instructions
124 uint64_t GetCurrentV63701Clock(void);           // Get the clock of the currently executing CPU
125
126 // It's the responsibility of the user to call these from their R/W handlers.
127 // These are usually memory mapped at $00-$1F.
128 uint8_t InternalRegisterRead(uint16_t);
129 void InternalRegisterWrite(uint16_t, uint8_t);
130
131 #endif  // __V63701_H__
132