summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWolfram Sang <wsa@the-dreams.de>2022-04-13 23:34:39 +0200
committerSolomon Peachy <pizza@shaftnet.org>2023-02-07 09:19:32 -0500
commit15c0f0576e73d714a09bcc9c09e93e80e330237d (patch)
tree1aa15bb62adef07a064b4d1dc7e5af7fbbd0d9ac
parente8135fea5a10dba25fefe991bf6bc36f351e2919 (diff)
downloadrockbox-15c0f0576e73d714a09bcc9c09e93e80e330237d.tar.gz
rockbox-15c0f0576e73d714a09bcc9c09e93e80e330237d.zip
codec: sid: split cRSID header into a public and a private header
Needed to compile cRSID as a proper library. Change-Id: I276967f46037bd65db1ff38985a781183fc26a00
-rw-r--r--lib/rbcodec/codecs/cRSID/C64/C64.c1
-rw-r--r--lib/rbcodec/codecs/cRSID/C64/libcRSIDc64.h172
-rw-r--r--lib/rbcodec/codecs/cRSID/host/audio.c2
-rw-r--r--lib/rbcodec/codecs/cRSID/libcRSID.h166
4 files changed, 176 insertions, 165 deletions
diff --git a/lib/rbcodec/codecs/cRSID/C64/C64.c b/lib/rbcodec/codecs/cRSID/C64/C64.c
index 81dca35542..f8e7a9a116 100644
--- a/lib/rbcodec/codecs/cRSID/C64/C64.c
+++ b/lib/rbcodec/codecs/cRSID/C64/C64.c
@@ -3,6 +3,7 @@
3 3
4 4
5#include "../libcRSID.h" 5#include "../libcRSID.h"
6#include "libcRSIDc64.h"
6 7
7#include "MEM.c" 8#include "MEM.c"
8#include "CPU.c" 9#include "CPU.c"
diff --git a/lib/rbcodec/codecs/cRSID/C64/libcRSIDc64.h b/lib/rbcodec/codecs/cRSID/C64/libcRSIDc64.h
new file mode 100644
index 0000000000..5100680768
--- /dev/null
+++ b/lib/rbcodec/codecs/cRSID/C64/libcRSIDc64.h
@@ -0,0 +1,172 @@
1// cRSID lightweight RealSID (integer-only) library-header (with API-calls) by Hermit (Mihaly Horvath)
2
3#ifndef LIBCRSIDC64_HEADER
4#define LIBCRSIDC64_HEADER //used to prevent double inclusion of this header-file
5
6typedef struct cRSID_CPUinstance cRSID_CPUinstance;
7typedef struct cRSID_SIDinstance cRSID_SIDinstance;
8typedef struct cRSID_CIAinstance cRSID_CIAinstance;
9typedef struct cRSID_VICinstance cRSID_VICinstance;
10
11
12//Internal functions
13
14// C64/C64.c
15cRSID_C64instance* cRSID_createC64 (cRSID_C64instance* C64, unsigned short samplerate);
16void cRSID_setC64 (cRSID_C64instance* C64); //configure hardware (SIDs) for SID-tune
17void cRSID_initC64 (cRSID_C64instance* C64); //hard-reset
18int cRSID_emulateC64 (cRSID_C64instance* C64);
19static inline short cRSID_playPSIDdigi (cRSID_C64instance* C64);
20// C64/MEM.c
21static inline unsigned char* cRSID_getMemReadPtr (register unsigned short address); //for global cSID_C64 fast-access
22static inline unsigned char* cRSID_getMemReadPtrC64 (cRSID_C64instance* C64, register unsigned short address); //maybe slower
23static inline unsigned char* cRSID_getMemWritePtr (register unsigned short address); //for global cSID_C64 fast-access
24static inline unsigned char* cRSID_getMemWritePtrC64 (cRSID_C64instance* C64, register unsigned short address); //maybe slower
25static inline unsigned char cRSID_readMem (register unsigned short address); //for global cSID_C64 fast-access
26static inline unsigned char cRSID_readMemC64 (cRSID_C64instance* C64, register unsigned short address); //maybe slower
27static inline void cRSID_writeMem (register unsigned short address, register unsigned char data); //for global cSID_C64 fast-access
28static inline void cRSID_writeMemC64 (cRSID_C64instance* C64, register unsigned short address, register unsigned char data); //maybe slower
29void cRSID_setROMcontent (cRSID_C64instance* C64); //KERNAL, BASIC
30void cRSID_initMem (cRSID_C64instance* C64);
31// C64/CPU.c
32void cRSID_initCPU (cRSID_CPUinstance* CPU, unsigned short mempos);
33unsigned char cRSID_emulateCPU (void); //direct instances inside for hopefully faster operation
34static inline char cRSID_handleCPUinterrupts (cRSID_CPUinstance* CPU);
35// C64/SID.c
36void cRSID_createSIDchip (cRSID_C64instance* C64, cRSID_SIDinstance* SID, unsigned short model, unsigned short baseaddress);
37void cRSID_initSIDchip (cRSID_SIDinstance* SID);
38void cRSID_emulateADSRs (cRSID_SIDinstance *SID, char cycles);
39int cRSID_emulateWaves (cRSID_SIDinstance* SID);
40// C64/CIA.c
41void cRSID_createCIAchip (cRSID_C64instance* C64, cRSID_CIAinstance* CIA, unsigned short baseaddress);
42void cRSID_initCIAchip (cRSID_CIAinstance* CIA);
43static inline char cRSID_emulateCIA (cRSID_CIAinstance* CIA, char cycles);
44static inline void cRSID_writeCIAIRQmask (cRSID_CIAinstance* CIA, unsigned char value);
45static inline void cRSID_acknowledgeCIAIRQ (cRSID_CIAinstance* CIA);
46// C64/VIC.c
47void cRSID_createVICchip (cRSID_C64instance* C64, cRSID_VICinstance* VIC, unsigned short baseaddress);
48void cRSID_initVICchip (cRSID_VICinstance* VIC);
49static inline char cRSID_emulateVIC (cRSID_VICinstance* VIC, char cycles);
50static inline void cRSID_acknowledgeVICrasterIRQ (cRSID_VICinstance* VIC);
51
52// host/file.c
53#ifdef CRSID_PLATFORM_PC
54int cRSID_loadSIDfile (unsigned char* SIDfileData, char* filename, int maxlen); //load SID-file to a memory location (and return size)
55#endif
56// host/audio.c
57#ifdef CRSID_PLATFORM_PC
58void* cRSID_initSound (cRSID_C64instance* C64, unsigned short samplerate, unsigned short buflen);
59void cRSID_startSound (void);
60void cRSID_stopSound (void);
61void cRSID_closeSound (void);
62void cRSID_generateSound (cRSID_C64instance* C64, unsigned char* buf, unsigned short len);
63#endif
64
65
66struct cRSID_CPUinstance {
67 cRSID_C64instance* C64; //reference to the containing C64
68 unsigned int PC;
69 short int A, SP;
70 unsigned char X, Y, ST; //STATUS-flags: N V - B D I Z C
71 unsigned char PrevNMI; //used for NMI leading edge detection
72};
73
74
75struct cRSID_SIDinstance {
76 //SID-chip data:
77 cRSID_C64instance* C64; //reference to the containing C64
78 unsigned short ChipModel; //values: 8580 / 6581
79 unsigned short BaseAddress; //SID-baseaddress location in C64-memory (IO)
80 unsigned char* BasePtr; //SID-baseaddress location in host's memory
81 //ADSR-related:
82 unsigned char ADSRstate[15];
83 unsigned short RateCounter[15];
84 unsigned char EnvelopeCounter[15];
85 unsigned char ExponentCounter[15];
86 //Wave-related:
87 int PhaseAccu[15]; //28bit precision instead of 24bit
88 int PrevPhaseAccu[15]; //(integerized ClockRatio fractionals, WebSID has similar solution)
89 unsigned char SyncSourceMSBrise;
90 unsigned int RingSourceMSB;
91 unsigned int NoiseLFSR[15];
92 unsigned int PrevWavGenOut[15];
93 unsigned char PrevWavData[15];
94 //Filter-related:
95 int PrevLowPass;
96 int PrevBandPass;
97 //Output-stage:
98 signed int PrevVolume; //lowpass-filtered version of Volume-band register
99};
100
101
102struct cRSID_CIAinstance {
103 cRSID_C64instance* C64; //reference to the containing C64
104 char ChipModel; //old or new CIA? (have 1 cycle difference in cases)
105 unsigned short BaseAddress; //CIA-baseaddress location in C64-memory (IO)
106 unsigned char* BasePtrWR; //CIA-baseaddress location in host's memory for writing
107 unsigned char* BasePtrRD; //CIA-baseaddress location in host's memory for reading
108};
109
110
111struct cRSID_VICinstance {
112 cRSID_C64instance* C64; //reference to the containing C64
113 char ChipModel; //(timing differences between models?)
114 unsigned short BaseAddress; //VIC-baseaddress location in C64-memory (IO)
115 unsigned char* BasePtrWR; //VIC-baseaddress location in host's memory for writing
116 unsigned char* BasePtrRD; //VIC-baseaddress location in host's memory for reading
117 unsigned short RasterLines;
118 unsigned char RasterRowCycles;
119 unsigned char RowCycleCnt;
120};
121
122
123struct cRSID_C64instance {
124 //platform-related:
125 unsigned short SampleRate;
126 //C64-machine related:
127 unsigned char VideoStandard; //0:NTSC, 1:PAL (based on the SID-header field)
128 unsigned int CPUfrequency;
129 unsigned short SampleClockRatio; //ratio of CPU-clock and samplerate
130 //SID-file related:
131 union {
132 cRSID_SIDheader* SIDheader;
133 char* SIDfileData;
134 };
135 unsigned short Attenuation;
136 char RealSIDmode;
137 char PSIDdigiMode;
138 unsigned char SubTune;
139 unsigned short LoadAddress;
140 unsigned short InitAddress;
141 unsigned short PlayAddress;
142 unsigned short EndAddress;
143 char TimerSource; //for current subtune, 0:VIC, 1:CIA (as in SID-header)
144 //PSID-playback related:
145 //char CIAisSet; //for dynamic CIA setting from player-routine (RealSID substitution)
146 int FrameCycles;
147 int FrameCycleCnt; //this is a substitution in PSID-mode for CIA/VIC counters
148 short PrevRasterLine;
149 short SampleCycleCnt;
150 short TenthSecondCnt;
151 char Finished;
152 char Returned;
153 unsigned char IRQ; //collected IRQ line from devices
154 unsigned char NMI; //collected NMI line from devices
155
156 //Hardware-elements:
157 cRSID_CPUinstance CPU;
158 cRSID_SIDinstance SID[CRSID_SIDCOUNT_MAX+1];
159 cRSID_CIAinstance CIA[CRSID_CIACOUNT+1];
160 cRSID_VICinstance VIC;
161 //Overlapping system memories, which one is read/written in an address region depends on CPU-port bankselect-bits)
162 //Address $00 and $01 - data-direction and data-register of port built into CPU (used as bank-selection) (overriding RAM on C64)
163 unsigned char RAMbank[0x10100]; //$0000..$FFFF RAM (and RAM under IO/ROM/CPUport)
164 unsigned char IObankWR[0x10100]; //$D000..$DFFF IO-RAM (registers) to write (VIC/SID/CIA/ColorRAM/IOexpansion)
165 unsigned char IObankRD[0x10100]; //$D000..$DFFF IO-RAM (registers) to read from (VIC/SID/CIA/ColorRAM/IOexpansion)
166 unsigned char ROMbanks[0x10100]; //$1000..$1FFF/$9000..$9FFF (CHARGEN), $A000..$BFFF (BASIC), $E000..$FFFF (KERNAL)
167};
168
169cRSID_C64instance cRSID_C64; //the only global object (for faster & simpler access than with struct-pointers, in some places)
170
171
172#endif //LIBCRSIDC64_HEADER
diff --git a/lib/rbcodec/codecs/cRSID/host/audio.c b/lib/rbcodec/codecs/cRSID/host/audio.c
index 2e06279113..2cfd5dac0b 100644
--- a/lib/rbcodec/codecs/cRSID/host/audio.c
+++ b/lib/rbcodec/codecs/cRSID/host/audio.c
@@ -52,7 +52,7 @@ void cRSID_generateSound(cRSID_C64instance* C64instance, unsigned char *buf, uns
52#endif 52#endif
53 53
54 54
55static inline signed short cRSID_generateSample (cRSID_C64instance* C64) { //call this from custom buffer-filler 55signed short cRSID_generateSample (cRSID_C64instance* C64) { //call this from custom buffer-filler
56 static int Output; 56 static int Output;
57 Output=cRSID_emulateC64(C64); 57 Output=cRSID_emulateC64(C64);
58 if (C64->PSIDdigiMode) Output += cRSID_playPSIDdigi(C64); 58 if (C64->PSIDdigiMode) Output += cRSID_playPSIDdigi(C64);
diff --git a/lib/rbcodec/codecs/cRSID/libcRSID.h b/lib/rbcodec/codecs/cRSID/libcRSID.h
index 23c8dbcd28..18dadc4a58 100644
--- a/lib/rbcodec/codecs/cRSID/libcRSID.h
+++ b/lib/rbcodec/codecs/cRSID/libcRSID.h
@@ -10,13 +10,9 @@ enum cRSID_StatusCodes { CRSID_STATUS_OK=0, CRSID_ERROR_INIT=-1, CRSID_ERROR_
10 10
11typedef struct cRSID_SIDheader cRSID_SIDheader; 11typedef struct cRSID_SIDheader cRSID_SIDheader;
12typedef struct cRSID_C64instance cRSID_C64instance; 12typedef struct cRSID_C64instance cRSID_C64instance;
13typedef struct cRSID_CPUinstance cRSID_CPUinstance;
14typedef struct cRSID_SIDinstance cRSID_SIDinstance;
15typedef struct cRSID_CIAinstance cRSID_CIAinstance;
16typedef struct cRSID_VICinstance cRSID_VICinstance;
17 13
18 14
19cRSID_C64instance cRSID_C64; //the only global object (for faster & simpler access than with struct-pointers, in some places) 15extern cRSID_C64instance cRSID_C64; //the only global object (for faster & simpler access than with struct-pointers, in some places)
20 16
21 17
22// Main API functions (mainly in libcRSID.c) 18// Main API functions (mainly in libcRSID.c)
@@ -30,61 +26,7 @@ void cRSID_close (void); //close sound etc.
30#endif 26#endif
31cRSID_SIDheader* cRSID_processSIDfile (cRSID_C64instance* C64, unsigned char* filedata, int filesize); //in host/file.c, copy SID-data to C64 memory 27cRSID_SIDheader* cRSID_processSIDfile (cRSID_C64instance* C64, unsigned char* filedata, int filesize); //in host/file.c, copy SID-data to C64 memory
32void cRSID_initSIDtune (cRSID_C64instance* C64, cRSID_SIDheader* SIDheader, char subtune); //init tune/subtune 28void cRSID_initSIDtune (cRSID_C64instance* C64, cRSID_SIDheader* SIDheader, char subtune); //init tune/subtune
33static inline signed short cRSID_generateSample (cRSID_C64instance* C64); //in host/audio.c, calculate a single sample 29signed short cRSID_generateSample (cRSID_C64instance* C64); //in host/audio.c, calculate a single sample
34
35
36//Internal functions
37
38// C64/C64.c
39cRSID_C64instance* cRSID_createC64 (cRSID_C64instance* C64, unsigned short samplerate);
40void cRSID_setC64 (cRSID_C64instance* C64); //configure hardware (SIDs) for SID-tune
41void cRSID_initC64 (cRSID_C64instance* C64); //hard-reset
42int cRSID_emulateC64 (cRSID_C64instance* C64);
43static inline short cRSID_playPSIDdigi (cRSID_C64instance* C64);
44// C64/MEM.c
45static inline unsigned char* cRSID_getMemReadPtr (register unsigned short address); //for global cSID_C64 fast-access
46static inline unsigned char* cRSID_getMemReadPtrC64 (cRSID_C64instance* C64, register unsigned short address); //maybe slower
47static inline unsigned char* cRSID_getMemWritePtr (register unsigned short address); //for global cSID_C64 fast-access
48static inline unsigned char* cRSID_getMemWritePtrC64 (cRSID_C64instance* C64, register unsigned short address); //maybe slower
49static inline unsigned char cRSID_readMem (register unsigned short address); //for global cSID_C64 fast-access
50static inline unsigned char cRSID_readMemC64 (cRSID_C64instance* C64, register unsigned short address); //maybe slower
51static inline void cRSID_writeMem (register unsigned short address, register unsigned char data); //for global cSID_C64 fast-access
52static inline void cRSID_writeMemC64 (cRSID_C64instance* C64, register unsigned short address, register unsigned char data); //maybe slower
53void cRSID_setROMcontent (cRSID_C64instance* C64); //KERNAL, BASIC
54void cRSID_initMem (cRSID_C64instance* C64);
55// C64/CPU.c
56void cRSID_initCPU (cRSID_CPUinstance* CPU, unsigned short mempos);
57unsigned char cRSID_emulateCPU (void); //direct instances inside for hopefully faster operation
58static inline char cRSID_handleCPUinterrupts (cRSID_CPUinstance* CPU);
59// C64/SID.c
60void cRSID_createSIDchip (cRSID_C64instance* C64, cRSID_SIDinstance* SID, unsigned short model, unsigned short baseaddress);
61void cRSID_initSIDchip (cRSID_SIDinstance* SID);
62void cRSID_emulateADSRs (cRSID_SIDinstance *SID, char cycles);
63int cRSID_emulateWaves (cRSID_SIDinstance* SID);
64// C64/CIA.c
65void cRSID_createCIAchip (cRSID_C64instance* C64, cRSID_CIAinstance* CIA, unsigned short baseaddress);
66void cRSID_initCIAchip (cRSID_CIAinstance* CIA);
67static inline char cRSID_emulateCIA (cRSID_CIAinstance* CIA, char cycles);
68static inline void cRSID_writeCIAIRQmask (cRSID_CIAinstance* CIA, unsigned char value);
69static inline void cRSID_acknowledgeCIAIRQ (cRSID_CIAinstance* CIA);
70// C64/VIC.c
71void cRSID_createVICchip (cRSID_C64instance* C64, cRSID_VICinstance* VIC, unsigned short baseaddress);
72void cRSID_initVICchip (cRSID_VICinstance* VIC);
73static inline char cRSID_emulateVIC (cRSID_VICinstance* VIC, char cycles);
74static inline void cRSID_acknowledgeVICrasterIRQ (cRSID_VICinstance* VIC);
75
76// host/file.c
77#ifdef CRSID_PLATFORM_PC
78int cRSID_loadSIDfile (unsigned char* SIDfileData, char* filename, int maxlen); //load SID-file to a memory location (and return size)
79#endif
80// host/audio.c
81#ifdef CRSID_PLATFORM_PC
82void* cRSID_initSound (cRSID_C64instance* C64, unsigned short samplerate, unsigned short buflen);
83void cRSID_startSound (void);
84void cRSID_stopSound (void);
85void cRSID_closeSound (void);
86void cRSID_generateSound (cRSID_C64instance* C64, unsigned char* buf, unsigned short len);
87#endif
88 30
89 31
90struct cRSID_SIDheader { //Offset: default/info: 32struct cRSID_SIDheader { //Offset: default/info:
@@ -114,108 +56,4 @@ struct cRSID_SIDheader { //Offset: default/info:
114}; //music-program follows right after the header 56}; //music-program follows right after the header
115 57
116 58
117struct cRSID_CPUinstance {
118 cRSID_C64instance* C64; //reference to the containing C64
119 unsigned int PC;
120 short int A, SP;
121 unsigned char X, Y, ST; //STATUS-flags: N V - B D I Z C
122 unsigned char PrevNMI; //used for NMI leading edge detection
123};
124
125
126struct cRSID_SIDinstance {
127 //SID-chip data:
128 cRSID_C64instance* C64; //reference to the containing C64
129 unsigned short ChipModel; //values: 8580 / 6581
130 unsigned short BaseAddress; //SID-baseaddress location in C64-memory (IO)
131 unsigned char* BasePtr; //SID-baseaddress location in host's memory
132 //ADSR-related:
133 unsigned char ADSRstate[15];
134 unsigned short RateCounter[15];
135 unsigned char EnvelopeCounter[15];
136 unsigned char ExponentCounter[15];
137 //Wave-related:
138 int PhaseAccu[15]; //28bit precision instead of 24bit
139 int PrevPhaseAccu[15]; //(integerized ClockRatio fractionals, WebSID has similar solution)
140 unsigned char SyncSourceMSBrise;
141 unsigned int RingSourceMSB;
142 unsigned int NoiseLFSR[15];
143 unsigned int PrevWavGenOut[15];
144 unsigned char PrevWavData[15];
145 //Filter-related:
146 int PrevLowPass;
147 int PrevBandPass;
148 //Output-stage:
149 signed int PrevVolume; //lowpass-filtered version of Volume-band register
150};
151
152
153struct cRSID_CIAinstance {
154 cRSID_C64instance* C64; //reference to the containing C64
155 char ChipModel; //old or new CIA? (have 1 cycle difference in cases)
156 unsigned short BaseAddress; //CIA-baseaddress location in C64-memory (IO)
157 unsigned char* BasePtrWR; //CIA-baseaddress location in host's memory for writing
158 unsigned char* BasePtrRD; //CIA-baseaddress location in host's memory for reading
159};
160
161
162struct cRSID_VICinstance {
163 cRSID_C64instance* C64; //reference to the containing C64
164 char ChipModel; //(timing differences between models?)
165 unsigned short BaseAddress; //VIC-baseaddress location in C64-memory (IO)
166 unsigned char* BasePtrWR; //VIC-baseaddress location in host's memory for writing
167 unsigned char* BasePtrRD; //VIC-baseaddress location in host's memory for reading
168 unsigned short RasterLines;
169 unsigned char RasterRowCycles;
170 unsigned char RowCycleCnt;
171};
172
173
174struct cRSID_C64instance {
175 //platform-related:
176 unsigned short SampleRate;
177 //C64-machine related:
178 unsigned char VideoStandard; //0:NTSC, 1:PAL (based on the SID-header field)
179 unsigned int CPUfrequency;
180 unsigned short SampleClockRatio; //ratio of CPU-clock and samplerate
181 //SID-file related:
182 union {
183 cRSID_SIDheader* SIDheader;
184 char* SIDfileData;
185 };
186 unsigned short Attenuation;
187 char RealSIDmode;
188 char PSIDdigiMode;
189 unsigned char SubTune;
190 unsigned short LoadAddress;
191 unsigned short InitAddress;
192 unsigned short PlayAddress;
193 unsigned short EndAddress;
194 char TimerSource; //for current subtune, 0:VIC, 1:CIA (as in SID-header)
195 //PSID-playback related:
196 //char CIAisSet; //for dynamic CIA setting from player-routine (RealSID substitution)
197 int FrameCycles;
198 int FrameCycleCnt; //this is a substitution in PSID-mode for CIA/VIC counters
199 short PrevRasterLine;
200 short SampleCycleCnt;
201 short TenthSecondCnt;
202 char Finished;
203 char Returned;
204 unsigned char IRQ; //collected IRQ line from devices
205 unsigned char NMI; //collected NMI line from devices
206
207 //Hardware-elements:
208 cRSID_CPUinstance CPU;
209 cRSID_SIDinstance SID[CRSID_SIDCOUNT_MAX+1];
210 cRSID_CIAinstance CIA[CRSID_CIACOUNT+1];
211 cRSID_VICinstance VIC;
212 //Overlapping system memories, which one is read/written in an address region depends on CPU-port bankselect-bits)
213 //Address $00 and $01 - data-direction and data-register of port built into CPU (used as bank-selection) (overriding RAM on C64)
214 unsigned char RAMbank[0x10100]; //$0000..$FFFF RAM (and RAM under IO/ROM/CPUport)
215 unsigned char IObankWR[0x10100]; //$D000..$DFFF IO-RAM (registers) to write (VIC/SID/CIA/ColorRAM/IOexpansion)
216 unsigned char IObankRD[0x10100]; //$D000..$DFFF IO-RAM (registers) to read from (VIC/SID/CIA/ColorRAM/IOexpansion)
217 unsigned char ROMbanks[0x10100]; //$1000..$1FFF/$9000..$9FFF (CHARGEN), $A000..$BFFF (BASIC), $E000..$FFFF (KERNAL)
218};
219
220
221#endif //LIBCRSID_HEADER 59#endif //LIBCRSID_HEADER