]> Shamusworld >> Repos - thunder/blobdiff - src/v63701.h
Added V63701, YM2151 emulation, more SDL 2 fixes.
[thunder] / src / v63701.h
diff --git a/src/v63701.h b/src/v63701.h
new file mode 100644 (file)
index 0000000..47c5b18
--- /dev/null
@@ -0,0 +1,132 @@
+//
+// Virtual 63701 Header file
+//
+// by James Hammons
+// (C) 2014 Underground Software
+//
+
+#ifndef __V63701_H__
+#define __V63701_H__
+
+#include <stdint.h>
+
+// Useful defines
+
+#define FLAG_H         0x20            // Half carry
+#define FLAG_I         0x10            // IRQ
+#define FLAG_N         0x08            // Negative
+#define FLAG_Z         0x04            // Zero
+#define FLAG_V         0x02            // oVerflow
+#define FLAG_C         0x01            // Carry
+
+#define V63701_ASSERT_LINE_RESET       0x0001  // v63701 RESET line
+#define V63701_ASSERT_LINE_IRQ         0x0002  // v63701 IRQ line
+#define V63701_ASSERT_LINE_NMI         0x0004  // v63701 NMI line
+#define V63701_STATE_WAI                       0x0008  // v63701 wait for IRQ line
+#define V63701_ASSERT_TIMER_OVERFLOW   0x0010
+#define V63701_ASSERT_OUTPUT_COMPARE   0x0020
+#define V63701_ASSERT_INPUT_CAPTURE    0x0040
+#define V63701_ASSERT_TRAP                     0x0080  // Illegal instruction executed flag
+//#define V6809_START_DEBUG_LOG                0x8000  // Debug log go (temporary!)
+
+// Useful structs
+
+union Byte
+{
+       struct
+       {
+               uint8_t b0: 1; uint8_t b1: 1; uint8_t b2: 1; uint8_t b3: 1;
+               uint8_t b4: 1; uint8_t b5: 1; uint8_t b6: 1; uint8_t b7: 1;
+       } bit;
+       uint8_t byte;
+};
+
+union Word
+{
+       struct
+       {
+               uint8_t lo: 8;
+               uint8_t hi: 8;
+       } byte;
+       uint16_t word;
+};
+
+union Flags
+{
+       struct
+       {
+               uint8_t c: 1;
+               uint8_t v: 1;
+               uint8_t z: 1;
+               uint8_t n: 1;
+               uint8_t i: 1;
+               uint8_t h: 1;
+       } flag;
+       uint8_t byte;
+};
+
+union TCSR
+{
+       struct
+       {
+               uint8_t olvl: 1;
+               uint8_t iedg: 1;
+               uint8_t etoi: 1;        // Enable Timer Over
+               uint8_t eoci: 1;        // Enable Output Compare
+               uint8_t eici: 1;        // Enable Input Capture
+               uint8_t tof: 1;         // Timer Over
+               uint8_t ocf: 1;         // Output Compare
+               uint8_t icf: 1;         // Input Capture
+       } bit;
+       uint8_t byte;
+};
+
+union WordReg
+{
+       struct
+       {
+               uint8_t b: 8;
+               uint8_t a: 8;
+       } acc;
+       uint16_t word;
+};
+
+struct V63701REGS
+{
+       uint16_t pc;                                    // 63701 PC register
+       uint16_t x;                                             // 63701 X index register
+       uint16_t s;                                             // 63701 System stack pointer
+       uint8_t cc;                                             // 63701 Condition Code register
+//     uint8_t a;                                              // 63701 A register
+//     uint8_t b;                                              // 63701 B register
+       WordReg d;                                              // 63701 A & B registers (A is hi, B is lo)
+       TCSR tcsr;                                              // 63701 Timer control/Status register
+       Word counter;                                   // 63701 Counter register
+       Word outputCompare;                             // 63701 Output Compare register
+       uint8_t ddr1;
+       uint8_t ddr2;
+       uint8_t port1;
+       uint8_t port2;
+       uint8_t ramCtrl;
+       uint8_t cWriteLatch;                    // Counter write latch
+       uint8_t cReadLatch;                             // Counter read latch
+       bool tcsrWasRead;                               // TCSR was read flag
+       uint64_t clock;                                 // 63701 clock
+       uint8_t (* RdMem)(uint16_t);    // Address of uint8 read routine
+       void (* WrMem)(uint16_t, uint8_t);      // Address of uint8 write routine
+       uint32_t cpuFlags;                              // v63701 IRQ/RESET flags
+       uint32_t clockOverrun;                  // Amount of overflow between runs
+};
+
+// Function prototypes
+
+void Execute63701(V63701REGS *, uint32_t);     // Function to execute 63701 instructions
+uint64_t GetCurrentV63701Clock(void);          // Get the clock of the currently executing CPU
+
+// It's the responsibility of the user to call these from their R/W handlers.
+// These are usually memory mapped at $00-$1F.
+uint8_t InternalRegisterRead(uint16_t);
+void InternalRegisterWrite(uint16_t, uint8_t);
+
+#endif // __V63701_H__
+