summaryrefslogtreecommitdiff
path: root/lib/rbcodec/codecs/cRSID/C64/libcRSIDc64.h
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 /lib/rbcodec/codecs/cRSID/C64/libcRSIDc64.h
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
Diffstat (limited to 'lib/rbcodec/codecs/cRSID/C64/libcRSIDc64.h')
-rw-r--r--lib/rbcodec/codecs/cRSID/C64/libcRSIDc64.h172
1 files changed, 172 insertions, 0 deletions
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