annotate ymz263b.c @ 2461:a25e8f304343

Fix handling of zero timer value
author Michael Pavone <pavone@retrodev.com>
date Fri, 23 Feb 2024 20:22:00 -0800
parents a4f8fa24764b
children b5640ac9aea9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2460
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1 #include <string.h>
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2 #include "ymz263b.h"
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
3 #include "backend.h"
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
4
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
5 enum {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
6 YMZ_SELT,
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
7 YMZ_LSI_TEST,
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
8 YMZ_TIMER0_LOW,
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
9 YMZ_TIMER0_HIGH,
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
10 YMZ_TIMER_BASE,
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
11 YMZ_TIMER1,
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
12 YMZ_TIMER2_LOW,
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
13 YMZ_TIMER2_HIGH,
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
14 YMZ_TIMER_CTRL,
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
15 YMZ_PCM_PLAY_CTRL,
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
16 YMZ_PCM_VOL,
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
17 YMZ_PCM_DATA,
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
18 YMZ_PCM_CTRL,
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
19 YMZ_MIDI_CTRL,
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
20 YMZ_MIDI_DATA
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
21 };
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
22
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
23 //YMZ_SELT
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
24 #define BIT_SELT 0x01
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
25
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
26 //YMZ_TIMER_CTRL
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
27 #define BIT_ST0 0x01
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
28 #define BIT_ST1 0x02
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
29 #define BIT_ST2 0x04
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
30 #define BIT_STBC 0x08
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
31 #define BIT_T0_MSK 0x10
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
32 #define BIT_T1_MSK 0x20
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
33 #define BIT_T2_MSK 0x40
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
34
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
35 #define TIMER_RUN_MASK (BIT_ST0|BIT_ST1|BIT_ST2)
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
36 #define TIMER_INT_MASK (BIT_T0_MSK|BIT_T1_MSK|BIT_T2_MSK)
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
37
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
38 //YMZ_PCM_PLAY_CTRL
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
39 #define BIT_ADP_RST 0x80
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
40
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
41 //YMZ_MIDI_CTRL
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
42 #define BIT_MSK_RRQ 0x01
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
43 #define BIT_MRC_RST 0x02
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
44 #define BIT_MSK_TRQ 0x04
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
45 #define BIT_MTR_RST 0x08
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
46 #define BIT_MSK_MOV 0x10
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
47 #define BIT_MSK_POV 0x20
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
48
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
49 #define STATUS_FIF1 0x01
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
50 #define STATUS_FIF2 0x02
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
51 #define STATUS_RRQ 0x04
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
52 #define STATUS_TRQ 0x08
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
53 #define STATUS_T0 0x10
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
54 #define STATUS_T1 0x20
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
55 #define STATUS_T2 0x40
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
56 #define STATUS_OV 0x80
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
57
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
58 #define MIDI_BYTE_DIVIDER 170
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
59
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
60 #define FIFO_EMPTY 255
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
61 void ymz263b_init(ymz263b *ymz, uint32_t clock_divider)
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
62 {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
63 memset(ymz, 0, sizeof(*ymz));
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
64 ymz->clock_inc = clock_divider * 32;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
65 ymz->base_regs[YMZ_SELT] = 1;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
66 ymz->pcm[0].regs[0] = BIT_ADP_RST;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
67 ymz->pcm[1].regs[0] = BIT_ADP_RST;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
68 ymz->midi_regs[0] = BIT_MTR_RST | BIT_MRC_RST;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
69 ymz->midi_trs.read = ymz->midi_rcv.read = FIFO_EMPTY;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
70 ymz->status = 0;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
71 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
72
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
73 static uint8_t fifo_empty(ymz_midi_fifo *fifo)
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
74 {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
75 return fifo->read == FIFO_EMPTY;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
76 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
77
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
78 static uint8_t fifo_read(ymz_midi_fifo *fifo)
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
79 {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
80 uint8_t ret = fifo->fifo[fifo->read++];
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
81 fifo->read &= 15;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
82 if (fifo->read == fifo->write) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
83 fifo->read = FIFO_EMPTY;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
84 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
85 return ret;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
86 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
87
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
88 static uint8_t fifo_write(ymz_midi_fifo *fifo, uint8_t value)
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
89 {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
90 uint8_t overflow = fifo->read == fifo->write;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
91 if (fifo->read == FIFO_EMPTY) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
92 fifo->read = fifo->write;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
93 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
94 fifo->fifo[fifo->write++] = value;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
95 fifo->write &= 15;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
96 return overflow;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
97 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
98
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
99 static uint8_t fifo_size(ymz_midi_fifo *fifo)
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
100 {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
101 if (fifo->read == FIFO_EMPTY) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
102 return 0;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
103 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
104 if (fifo->read == fifo->write) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
105 return 16;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
106 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
107 return (fifo->write - fifo->read) & 15;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
108 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
109
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
110 void ymz263b_run(ymz263b *ymz, uint32_t target_cycle)
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
111 {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
112 uint8_t timer_ctrl = ymz->base_regs[YMZ_TIMER_CTRL];
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
113 for (; ymz->cycle < target_cycle; ymz->cycle += ymz->clock_inc)
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
114 {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
115 if (timer_ctrl & BIT_ST0) {
2461
a25e8f304343 Fix handling of zero timer value
Michael Pavone <pavone@retrodev.com>
parents: 2460
diff changeset
116 ymz->timers[0]--;
a25e8f304343 Fix handling of zero timer value
Michael Pavone <pavone@retrodev.com>
parents: 2460
diff changeset
117 if (!ymz->timers[0]) {
2460
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
118 ymz->timers[0] = ymz->base_regs[YMZ_TIMER0_HIGH] << 8 | ymz->base_regs[YMZ_TIMER0_LOW];
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
119 ymz->status |= STATUS_T0;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
120 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
121 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
122 if (timer_ctrl & BIT_STBC) {
2461
a25e8f304343 Fix handling of zero timer value
Michael Pavone <pavone@retrodev.com>
parents: 2460
diff changeset
123 ymz->timers[3]--;
a25e8f304343 Fix handling of zero timer value
Michael Pavone <pavone@retrodev.com>
parents: 2460
diff changeset
124 if (!ymz->timers[3]) {
2460
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
125 ymz->timers[3] = ymz->base_regs[YMZ_TIMER1] << 8 & 0xF00;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
126 ymz->timers[3] |= ymz->base_regs[YMZ_TIMER_BASE];
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
127
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
128 if (timer_ctrl & BIT_ST1) {
2461
a25e8f304343 Fix handling of zero timer value
Michael Pavone <pavone@retrodev.com>
parents: 2460
diff changeset
129 ymz->timers[1]--;
a25e8f304343 Fix handling of zero timer value
Michael Pavone <pavone@retrodev.com>
parents: 2460
diff changeset
130 if (!ymz->timers[1]) {
2460
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
131 ymz->timers[1] = ymz->base_regs[YMZ_TIMER1] >> 4;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
132 ymz->status |= STATUS_T1;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
133 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
134 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
135
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
136 if (timer_ctrl & BIT_ST2) {
2461
a25e8f304343 Fix handling of zero timer value
Michael Pavone <pavone@retrodev.com>
parents: 2460
diff changeset
137 ymz->timers[2]--;
a25e8f304343 Fix handling of zero timer value
Michael Pavone <pavone@retrodev.com>
parents: 2460
diff changeset
138 if (!ymz->timers[2]) {
2460
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
139 ymz->timers[2] = ymz->base_regs[YMZ_TIMER2_HIGH] << 8 | ymz->base_regs[YMZ_TIMER2_LOW];
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
140 ymz->status |= STATUS_T2;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
141 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
142 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
143 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
144 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
145 if (!(ymz->midi_regs[0] & BIT_MTR_RST) && !fifo_empty(&ymz->midi_trs)) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
146 if (ymz->midi_transmit) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
147 --ymz->midi_transmit;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
148 } else {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
149 ymz->midi_transmit = MIDI_BYTE_DIVIDER - 1;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
150 //TODO: send this byte to MIDI device
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
151 uint8_t byte = fifo_read(&ymz->midi_trs);
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
152 printf("MIDI Transmit: %X\n", byte);
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
153 if (fifo_empty(&ymz->midi_trs)) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
154 ymz->status |= STATUS_TRQ;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
155 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
156 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
157 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
158 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
159 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
160
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
161 uint32_t ymz263b_next_int(ymz263b *ymz)
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
162 {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
163 //TODO: Handle FIFO and MIDI receive interrupts
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
164 uint8_t enabled_ints = (~ymz->base_regs[YMZ_TIMER_CTRL]) & TIMER_INT_MASK;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
165 if (!(ymz->base_regs[YMZ_MIDI_CTRL] & (BIT_MTR_RST|BIT_MSK_TRQ))) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
166 enabled_ints |= STATUS_TRQ;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
167 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
168 if (!enabled_ints) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
169 return CYCLE_NEVER;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
170 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
171 //Handle currently pending interrupts
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
172 if (enabled_ints & ymz->status) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
173 return ymz->cycle;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
174 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
175 uint32_t ret = CYCLE_NEVER;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
176 if (enabled_ints & STATUS_TRQ) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
177 uint8_t bytes = fifo_size(&ymz->midi_trs);
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
178 if (bytes) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
179 ret = ymz->cycle + (ymz->midi_transmit + 1) * ymz->clock_inc;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
180 if (bytes > 1) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
181 ret += MIDI_BYTE_DIVIDER * ymz->clock_inc * (bytes - 1);
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
182 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
183 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
184 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
185 enabled_ints >>= 4;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
186 //If timers aren't already expired, interrupts can't fire unless the timers are enabled
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
187 enabled_ints &= ymz->base_regs[YMZ_TIMER_CTRL];
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
188 if (!(ymz->base_regs[YMZ_TIMER_CTRL] & BIT_STBC)) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
189 //Timer 1 and Timer 2 depend on the base timer
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
190 enabled_ints &= 1;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
191 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
192 if (enabled_ints & BIT_ST0) {
2461
a25e8f304343 Fix handling of zero timer value
Michael Pavone <pavone@retrodev.com>
parents: 2460
diff changeset
193 uint32_t t0 = ymz->cycle + (ymz->timers[0] ? ymz->timers[0] : 0x10000) * ymz->clock_inc;
2460
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
194 if (t0 < ret) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
195 ret = t0;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
196 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
197 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
198 if (enabled_ints & (BIT_ST1|BIT_ST2)) {
2461
a25e8f304343 Fix handling of zero timer value
Michael Pavone <pavone@retrodev.com>
parents: 2460
diff changeset
199 uint32_t base = ymz->cycle + (ymz->timers[3] ? ymz->timers[3] : 0x1000) * ymz->clock_inc;
2460
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
200 if (base < ret) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
201 uint32_t load = (ymz->base_regs[YMZ_TIMER1] << 8 & 0xF00) | ymz->base_regs[YMZ_TIMER_BASE];
2461
a25e8f304343 Fix handling of zero timer value
Michael Pavone <pavone@retrodev.com>
parents: 2460
diff changeset
202 if (!load) {
a25e8f304343 Fix handling of zero timer value
Michael Pavone <pavone@retrodev.com>
parents: 2460
diff changeset
203 load = 0x1000;
a25e8f304343 Fix handling of zero timer value
Michael Pavone <pavone@retrodev.com>
parents: 2460
diff changeset
204 }
2460
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
205 if (enabled_ints & BIT_ST1) {
2461
a25e8f304343 Fix handling of zero timer value
Michael Pavone <pavone@retrodev.com>
parents: 2460
diff changeset
206 uint32_t t1 = (ymz->timers[1] ? ymz->timers[1] - 1 : 0xF) * load * ymz->clock_inc;
2460
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
207 if (t1 < ret) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
208 ret = t1;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
209 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
210 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
211 if (enabled_ints & BIT_ST2) {
2461
a25e8f304343 Fix handling of zero timer value
Michael Pavone <pavone@retrodev.com>
parents: 2460
diff changeset
212 uint32_t t2 = (ymz->timers[2] ? ymz->timers[2] - 1 : 0xFFFF) * load * ymz->clock_inc;
2460
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
213 if (t2 < ret) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
214 ret = t2;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
215 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
216 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
217 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
218 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
219 return ret;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
220 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
221
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
222 void ymz263b_address_write(ymz263b *ymz, uint8_t value)
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
223 {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
224 ymz->address = value;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
225 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
226
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
227 void ymz263b_data_write(ymz263b *ymz, uint32_t channel, uint8_t value)
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
228 {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
229 if (channel) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
230 if (ymz->address >= YMZ_PCM_PLAY_CTRL && ymz->address < YMZ_MIDI_CTRL) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
231 ymz->pcm[1].regs[ymz->address - YMZ_PCM_PLAY_CTRL] = value;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
232 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
233 } else {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
234 if (ymz->address < YMZ_PCM_PLAY_CTRL) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
235 ymz->base_regs[ymz->address] = value;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
236 } else if (ymz->address < YMZ_MIDI_CTRL) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
237 ymz->pcm[0].regs[ymz->address - YMZ_PCM_PLAY_CTRL] = value;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
238 } else {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
239 ymz->midi_regs[ymz->address - YMZ_MIDI_CTRL] = value;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
240 if (ymz->address == YMZ_MIDI_DATA) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
241 ymz->status &= ~STATUS_TRQ;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
242 if (fifo_empty(&ymz->midi_trs)) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
243 ymz->midi_transmit = MIDI_BYTE_DIVIDER - 1;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
244 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
245 fifo_write(&ymz->midi_trs, value);
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
246 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
247 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
248 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
249 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
250
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
251 uint8_t ymz263b_data_read(ymz263b *ymz, uint32_t channel)
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
252 {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
253 //TODO: Supposedly only a few registers are actually readable
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
254 if (channel) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
255 if (ymz->address >= YMZ_PCM_PLAY_CTRL && ymz->address < YMZ_MIDI_CTRL) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
256 return ymz->pcm[1].regs[ymz->address - YMZ_PCM_PLAY_CTRL];
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
257 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
258 } else {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
259 if (ymz->address < YMZ_PCM_PLAY_CTRL) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
260 return ymz->base_regs[ymz->address];
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
261 } else if (ymz->address < YMZ_MIDI_CTRL) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
262 return ymz->pcm[0].regs[ymz->address - YMZ_PCM_PLAY_CTRL];
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
263 } else {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
264 return ymz->midi_regs[ymz->address - YMZ_MIDI_CTRL];
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
265 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
266 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
267 return 0XFF;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
268 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
269
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
270 uint8_t ymz263b_status_read(ymz263b *ymz)
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
271 {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
272 uint8_t ret = ymz->status;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
273 ymz->status = 0;//&= ~(STATUS_T0|STATUS_T1|STATUS_T2);
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
274 return ret;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
275 }