summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2021-08-03 20:26:23 +0000
committerIan C <ianc@noddybox.co.uk>2021-08-03 20:26:23 +0000
commitb7e8b634595445325d10f8fcddcb7d6cdaa8a922 (patch)
tree7ecd54e8539cbe1abd37ffda8d3fcd9eb0ddf258 /include
parent30c4591b629bb96e9ff99aca24d0e0e51cedbf23 (diff)
First attempt at sound
Diffstat (limited to 'include')
-rw-r--r--include/config.h1
-rw-r--r--include/spec.h4
-rw-r--r--include/z80.h17
-rw-r--r--include/z80_private.h10
4 files changed, 30 insertions, 2 deletions
diff --git a/include/config.h b/include/config.h
index b57c3ef..800960b 100644
--- a/include/config.h
+++ b/include/config.h
@@ -29,6 +29,7 @@ typedef enum
{
DSSPEC_STICKY_SHIFT,
DSSPEC_LOAD_DEFAULT_SNAPSHOT,
+ DSSPEC_SOUND,
DSSPEC_NUM_CONFIG_ITEMS
} DSSPEC_ConfigItem;
diff --git a/include/spec.h b/include/spec.h
index 47549a3..85fb5e7 100644
--- a/include/spec.h
+++ b/include/spec.h
@@ -32,6 +32,10 @@
#include "z80.h"
#include "keyboard.h"
+/* Sample rate for sound emulation
+*/
+#define SAMPLE_RATE 22050
+
/* Initialise the SPEC
*/
diff --git a/include/z80.h b/include/z80.h
index ef24fd0..ab095d8 100644
--- a/include/z80.h
+++ b/include/z80.h
@@ -134,13 +134,23 @@ typedef int (*Z80Callback)(Z80 *cpu, Z80Val data);
*/
typedef enum
{
- eZ80_Instruction, /* data = no cycles since reset */
+ eZ80_Instruction, /* data = cycles as returned by Z80Cycles */
eZ80_EDHook, /* data = byte after ED opcode (only for NOP opcodes) */
eZ80_Halt, /* data = 1 halt raised, 0 halt cleared by int */
eZ80_RETI, /* data = ignored */
eZ80_NO_CALLBACK /* leave at end */
} Z80CallbackReason;
+/* Defines cycle timers
+*/
+typedef enum
+{
+ Z80_TIMER_1,
+ Z80_TIMER_2,
+ Z80_TIMER_3,
+ Z80_NO_TIMERS
+} Z80Timer;
+
/* Flags in the F register
*/
@@ -235,6 +245,11 @@ void Z80Exec(Z80 *cpu);
Z80Val Z80Cycles(Z80 *cpu);
void Z80ResetCycles(Z80 *cpu, Z80Val cycles);
+/* Timers that count in cycle counts
+*/
+Z80Val Z80GetTimer(Z80 *cpu, Z80Timer timer);
+void Z80SetTimer(Z80 *cpu, Z80Timer timer, Z80Val cycles);
+
/* Set address to label mappings for the disassembler
*/
diff --git a/include/z80_private.h b/include/z80_private.h
index 10cf97e..e0b3381 100644
--- a/include/z80_private.h
+++ b/include/z80_private.h
@@ -48,6 +48,8 @@ struct Z80Private
{
Z80Val cycle;
+ Z80Val timer[Z80_NO_TIMERS];
+
int halt;
Z80Byte shift;
@@ -178,7 +180,13 @@ static inline Z80Word PEEKW(Z80Word addr)
#define IS_IX_IY (PRIV->shift==0xdd || PRIV->shift==0xfd)
#define OFFSET(off) off=(IS_IX_IY ? (Z80Relative)FETCH_BYTE:0)
-#define TSTATE(n) PRIV->cycle+=n
+#define TSTATE(n) do \
+ { \
+ PRIV->cycle+=n; \
+ PRIV->timer[Z80_TIMER_1]+=n; \
+ PRIV->timer[Z80_TIMER_2]+=n; \
+ PRIV->timer[Z80_TIMER_3]+=n; \
+ } while(0)
#define ADD_R(v) cpu->R=((cpu->R&0x80)|((cpu->R+(v))&0x7f))
#define INC_R ADD_R(1)