annotate ymz263b.c @ 2460:a4f8fa24764b

Initial work on emulating the YMZ263B in the Copera
author Michael Pavone <pavone@retrodev.com>
date Fri, 23 Feb 2024 01:16:38 -0800
parents
children a25e8f304343
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) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
116 if (ymz->timers[0]) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
117 ymz->timers[0]--;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
118 } else {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
119 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
120 ymz->status |= STATUS_T0;
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 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
123 if (timer_ctrl & BIT_STBC) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
124 if (ymz->timers[3]) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
125 ymz->timers[3]--;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
126 } else {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
127 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
128 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
129
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
130 if (timer_ctrl & BIT_ST1) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
131 if (ymz->timers[1]) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
132 ymz->timers[1]--;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
133 } else {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
134 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
135 ymz->status |= STATUS_T1;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
136 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
137 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
138
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
139 if (timer_ctrl & BIT_ST2) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
140 if (ymz->timers[2]) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
141 ymz->timers[2]--;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
142 } else {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
143 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
144 ymz->status |= STATUS_T2;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
145 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
146 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
147 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
148 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
149 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
150 if (ymz->midi_transmit) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
151 --ymz->midi_transmit;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
152 } else {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
153 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
154 //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
155 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
156 printf("MIDI Transmit: %X\n", byte);
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
157 if (fifo_empty(&ymz->midi_trs)) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
158 ymz->status |= STATUS_TRQ;
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 }
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 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
164
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
165 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
166 {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
167 //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
168 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
169 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
170 enabled_ints |= STATUS_TRQ;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
171 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
172 if (!enabled_ints) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
173 return CYCLE_NEVER;
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 //Handle currently pending interrupts
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
176 if (enabled_ints & ymz->status) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
177 return ymz->cycle;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
178 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
179 uint32_t ret = CYCLE_NEVER;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
180 if (enabled_ints & STATUS_TRQ) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
181 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
182 if (bytes) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
183 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
184 if (bytes > 1) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
185 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
186 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
187 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
188 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
189 enabled_ints >>= 4;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
190 //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
191 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
192 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
193 //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
194 enabled_ints &= 1;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
195 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
196 if (enabled_ints & BIT_ST0) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
197 uint32_t t0 = ymz->cycle + (ymz->timers[0] + 1) * ymz->clock_inc;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
198 if (t0 < ret) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
199 ret = t0;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
200 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
201 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
202 if (enabled_ints & (BIT_ST1|BIT_ST2)) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
203 uint32_t base = ymz->cycle + (ymz->timers[3] + 1) * ymz->clock_inc;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
204 if (base < ret) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
205 uint32_t load = (ymz->base_regs[YMZ_TIMER1] << 8 & 0xF00) | ymz->base_regs[YMZ_TIMER_BASE];
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
206 if (enabled_ints & BIT_ST1) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
207 uint32_t t1 = ymz->timers[1] * (load + 1) * ymz->clock_inc;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
208 if (t1 < ret) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
209 ret = t1;
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 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
212 if (enabled_ints & BIT_ST2) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
213 uint32_t t2 = ymz->timers[2] * (load + 1) * ymz->clock_inc;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
214 if (t2 < ret) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
215 ret = t2;
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 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
220 return ret;
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
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
223 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
224 {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
225 ymz->address = value;
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
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
228 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
229 {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
230 if (channel) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
231 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
232 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
233 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
234 } else {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
235 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
236 ymz->base_regs[ymz->address] = value;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
237 } 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
238 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
239 } else {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
240 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
241 if (ymz->address == YMZ_MIDI_DATA) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
242 ymz->status &= ~STATUS_TRQ;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
243 if (fifo_empty(&ymz->midi_trs)) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
244 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
245 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
246 fifo_write(&ymz->midi_trs, value);
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
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
252 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
253 {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
254 //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
255 if (channel) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
256 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
257 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
258 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
259 } else {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
260 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
261 return ymz->base_regs[ymz->address];
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
262 } 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
263 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
264 } else {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
265 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
266 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
267 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
268 return 0XFF;
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
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
271 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
272 {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
273 uint8_t ret = ymz->status;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
274 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
275 return ret;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
276 }