| 1 |
/* |
| 2 |
|
| 3 |
============================================================================ |
| 4 |
|
| 5 |
SM8521 sound emulator |
| 6 |
by cam900 |
| 7 |
|
| 8 |
MODIFIED BY TILDEARROW |
| 9 |
THIS IS NOT THE ORIGINAL VERSION |
| 10 |
|
| 11 |
This file is licensed under zlib license. |
| 12 |
|
| 13 |
============================================================================ |
| 14 |
|
| 15 |
zlib License |
| 16 |
|
| 17 |
(C) 2023-present cam900 and contributors |
| 18 |
|
| 19 |
This software is provided 'as-is', without any express or implied |
| 20 |
warranty. In no event will the authors be held liable for any damages |
| 21 |
arising from the use of this software. |
| 22 |
|
| 23 |
Permission is granted to anyone to use this software for any purpose, |
| 24 |
including commercial applications, and to alter it and redistribute it |
| 25 |
freely, subject to the following restrictions: |
| 26 |
|
| 27 |
1. The origin of this software must not be misrepresented; you must not |
| 28 |
claim that you wrote the original software. If you use this software |
| 29 |
in a product, an acknowledgment in the product documentation would be |
| 30 |
appreciated but is not required. |
| 31 |
2. Altered source versions must be plainly marked as such, and must not be |
| 32 |
misrepresented as being the original software. |
| 33 |
3. This notice may not be removed or altered from any source distribution. |
| 34 |
|
| 35 |
============================================================================ |
| 36 |
|
| 37 |
TODO: |
| 38 |
- needs hardware test |
| 39 |
|
| 40 |
*/ |
| 41 |
|
| 42 |
#ifndef _SM8521_EMU_H |
| 43 |
#define _SM8521_EMU_H |
| 44 |
|
| 45 |
#ifdef __cplusplus |
| 46 |
extern "C" |
| 47 |
{ |
| 48 |
#endif |
| 49 |
|
| 50 |
struct sm8521_sg_t |
| 51 |
{ |
| 52 |
unsigned short t; // Time constant register |
| 53 |
unsigned char level; // Output level control register |
| 54 |
signed short out; // output |
| 55 |
int counter; // clock counter |
| 56 |
}; |
| 57 |
|
| 58 |
struct sm8521_wave_t |
| 59 |
{ |
| 60 |
struct sm8521_sg_t base; |
| 61 |
unsigned char addr; // waveform address |
| 62 |
unsigned char wave[16]; // 4 bit waveform (32 nybbles) |
| 63 |
}; |
| 64 |
|
| 65 |
struct sm8521_noise_t |
| 66 |
{ |
| 67 |
struct sm8521_sg_t base; |
| 68 |
unsigned int lfsr, oldLFSR; // LFSR |
| 69 |
unsigned char out; |
| 70 |
}; |
| 71 |
|
| 72 |
struct sm8521_t |
| 73 |
{ |
| 74 |
struct sm8521_wave_t sg[2]; |
| 75 |
struct sm8521_noise_t noise; |
| 76 |
signed short out; // output |
| 77 |
signed char sgda; // D/A direct output register (write only) |
| 78 |
unsigned char sgc; // Control register |
| 79 |
}; |
| 80 |
|
| 81 |
void sm8521_sg_wave_tick(struct sm8521_wave_t *sg, const int cycle); |
| 82 |
|
| 83 |
void sm8521_noise_tick(struct sm8521_noise_t *noise, const int cycle); |
| 84 |
|
| 85 |
void sm8521_sound_tick(struct sm8521_t *sm8521, const int cycle); |
| 86 |
|
| 87 |
void sm8521_reset(struct sm8521_t *sm8521); |
| 88 |
|
| 89 |
unsigned char sm8521_read(struct sm8521_t *sm8521, const unsigned char a); |
| 90 |
void sm8521_write(struct sm8521_t *sm8521, const unsigned char a, const unsigned char d); |
| 91 |
|
| 92 |
#ifdef __cplusplus |
| 93 |
} // extern "C" |
| 94 |
#endif |
| 95 |
|
| 96 |
#endif // _SM8521_EMU_H |