|
|
1.1 root 1: //
2: // nono
3: // Copyright (C) 2024 nono project
4: // Licensed under nono-license.txt
5: //
6:
7: //
8: // SSG (YM2149)
9: //
10:
11: #pragma once
12:
13: #include "device.h"
14: #include "monitor.h"
15:
16: // レジスタ
17: struct SSG
18: {
19: // 7 6 5 4 3 2 1 0
20: // +---+---+---+---+---+---+---+---+
21: // R0 | Low |
22: // +---------------+---------------+ Frequency of channel A
23: // R1 | - | High |
24: // +---+---+---+---+---+---+---+---+
25: //
26: // +---+---+---+---+---+---+---+---+
27: // R2 | Low |
28: // +---------------+---------------+ Frequency of channel B
29: // R3 | - | High |
30: // +---+---+---+---+---+---+---+---+
31: //
32: // +---+---+---+---+---+---+---+---+
33: // R4 | Low |
34: // +---------------+---------------+ Frequency of channel C
35: // R5 | - | High |
36: // +---+---+---+---+---+---+---+---+
37: //
38: // +-----------+---+---+---+---+---+
39: // R6 | - | freq | Frequency of noise
40: // +-----------+---+---+---+---+---+
41: //
42: // +---+---+---+---+---+---+---+---+
43: // R7 | I/O | Noise | Tone | I/O port and mixer settings
44: // | B | A | C | B | A | C | B | A |
45: // +---+---+---+---+---+---+---+---+
46: //
47: // +-----------+---+---+---+---+---+
48: // R8 | - | M | level | Level of channel A
49: // +-----------+---+---+---+---+---+
50: // +-----------+---+---+---+---+---+
51: // R9 | - | M | level | Level of channel B
52: // +-----------+---+---+---+---+---+
53: // +-----------+---+---+---+---+---+
54: // RA | - | M | level | Level of channel C
55: // +-----------+---+---+---+---+---+
56: //
57: // +-------------------------------+
58: // RB | freq (Low) | Frequency of envelope
59: // RC | freq (High) |
60: // +-------------------------------+
61: //
62: // +---------------+---+---+---+---+
63: // RD | - |CNT|ATT|ALT|HLD| Shape of envelope
64: // +---------------+---+---+---+---+
65: //
66: // +-------------------------------+
67: // RE | 8 bit data | Data of I/O port A
68: // +-------------------------------+
69: // RF | 8 bit data | Data of I/O port B
70: // +-------------------------------+
71:
72: uint freq[3];
73: uint noise_freq;
74: uint settings;
75: bool ampmode[3];
76: uint amplevel[3];
77: uint envelope_freq;
78: uint envelope_shape;
79: uint dataA;
80: uint dataB;
81:
82: // Rn の値を返す
83: uint32 Get(uint n) const;
84:
85: // レベルレジスタの値を返す
86: uint32 GetLevelReg(int n) const {
87: return (ampmode[n] ? 0x10 : 0) | amplevel[n];
88: }
89: };
90:
91: class SSGDevice : public IODevice
92: {
93: using inherited = IODevice;
94:
95: // マスタークロック (1.536MHz)
96: static const uint fMaster = 1536000;
97:
98: public:
99: SSGDevice();
100: ~SSGDevice() override;
101:
102: void ResetHard(bool poweron) override;
103:
104: busdata Read1(uint32 addr) override;
105: busdata Write1(uint32 addr, uint32 data) override;
106: busdata Peek1(uint32 addr) override;
107:
108: private:
109: DECLARE_MONITOR_CALLBACK(MonitorUpdate);
110:
111: uint32 GetReg(uint32 n) const;
112:
113: uint32 regno {};
114: SSG reg {};
115:
116: Monitor monitor { this };
117: };
118:
119: static inline SSGDevice *GetSSGDevice() {
120: return Object::GetObject<SSGDevice>(OBJ_SSG);
121: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.