3 ** File: ym2151.h -- header file for software implementation of YM-2151
4 ** FM Operator Type-M(OPM).
6 ** (C) Jarek Burczynski (s0246@goblin.pjwstk.waw.pl) September, 1st 1997
8 ** First beta release: December, 16th 1997
9 ** Version 1.0 beta release: March, 16th 1998
12 ** CAUTION !!! CAUTION !!! H E L P W A N T E D !!!
14 ** If you have some very technical information about YM-2151, or possibly you
15 ** own a computer (like X68000) which has YM-2151 built-in (so you could make
16 ** a few samples of real chip), and you would like to help:
17 ** - PLEASE CONTACT ME ASAP!!! -
21 ** I would like to thank to Shigeharu Isoda without whom this project wouldn't
22 ** be possible to finish (possibly even start). He has been so kind and helped
23 ** me by scanning his YM2151 Japanese Manual first, and then by answering MANY
24 ** of questions I've asked (I can't read Japanese still, although I study
25 ** informatics at Polish-Japanese Institute here in Poland).
27 ** I would like to thank to nao (nao@ms6.hinet.net) also - he has been the one
28 ** who gave me some information about YM2151, and pointed me to Shigeharu.
30 ** Big thanks to Aaron Giles and Chris Hardy - they've made some samples of one
31 ** of my favourite arcade games so I could compare it to my emulator. That's
32 ** how I know there's still something I need to know about this chip.
34 ** Greetings to Ishmair (thanks for the datasheet !) who has inspired me to
35 ** write my own 2151 emu by telling me "... maybe with some somes and a lot of
36 ** luck ... in theory it's difficult ... " - wow that really was a challenge :)
47 #define YM_NOISE (0x0F)
49 #define YM_CLOCKA1 (0x10)
50 #define YM_CLOCKA2 (0x11)
51 #define YM_CLOCKB (0x12)
52 #define YM_CLOCKSET (0x14)
54 #define YM_LFRQ (0x18)
55 #define YM_PMD_AMD (0x19)
56 #define YM_CT1_CT2_W (0x1B)
59 #define YM_CONNECT_BASE (0x20) /*1 reg per FM channel*/
60 #define YM_KC_BASE (0x28)
61 #define YM_KF_BASE (0x30)
62 #define YM_PMS_AMS_BASE (0x38)
64 #define YM_DT1_MUL_BASE (0x40) /*1 reg per operator*/
65 #define YM_TL_BASE (0x60)
66 #define YM_KS_AR_BASE (0x80)
67 #define YM_AMS_D1R_BASE (0xA0)
68 #define YM_DT2_D2R_BASE (0xC0)
69 #define YM_D1L_RR_BASE (0xE0)
71 typedef void SAMPLE; /*Yep, 16 bit is supported, at last*/
73 typedef struct{ /*oscillator data */
74 signed int freq; /*oscillator frequency (in indexes per sample) (fixed point)*/
75 signed int phase; /*accumulated oscillator phase (in indexes) (fixed point)*/
77 unsigned int TL; /*this is output level, in fact */
78 signed int volume; /*oscillator volume (fixed point) */
79 signed int attack_volume; /*used for attack phase calculations*/
81 signed int OscilFB; /*oscillator self feedback used only by operators 0*/
88 signed int delta_AR; /*volume delta for attack phase (fixed point)*/
89 signed int delta_D1R; /*volume delta for decay phase (fixed point)*/
90 signed int delta_D2R; /*volume delta for sustain phase (fixed point)*/
91 signed int delta_RR; /*volume delta for release phase (fixed point)*/
92 unsigned char state; /*Envelope state: 0-attack(AR) 1-decay(D1R) 2-sustain(D2R) 3-release(RR) 4-finished*/
96 /* here's the virtual YM2151 */
97 typedef struct ym2151_f {
98 SAMPLE * Buf; /* sound buffer */
100 OscilRec Oscils[32]; /*there are 32 operators in YM2151*/
101 unsigned char Regs[256]; /*table of internal chip registers*/
102 unsigned char FeedBack[8]; /*feedback shift value for operators 0 in each channel*/
103 unsigned char ConnectTab[8]; /*connection algorithm number for each channel*/
104 unsigned char KC[8]; /*KC for each channel*/
105 unsigned char KF[32]; /*KF for each operator*/
106 unsigned char KS[32]; /*KS for each operator*/
108 unsigned char TimA, TimB, TimIRQ;
109 signed int TimAVal, TimBVal;
110 void * TimATimer, * TimBTimer; /* ASG 980324 -- added for tracking timers */
111 void (* handler)(void);
116 ** Initialize YM2151 emulator(s).
118 ** 'num' is the number of virtual YM2151's to allocate
119 ** 'rate' is sampling rate and 'bufsiz' is the size of the
120 ** buffer that should be updated at each interval
122 //int YMInit(int num, int clock, int rate, int sample_bits, int bufsiz); //, SAMPLE ** buffer);
123 int YMInit(int clock, int rate);
126 ** shutdown the YM2151 emulators ...
128 void YMShutdown(void);
131 ** reset all chip registers for YM2151 number 'num'
133 void YMResetChip(int num);
136 ** called to update all chips; should be called about 50 - 70 times per
137 ** second ... (depends on sample rate and buffer size)
139 void YM2151Update(void);
141 //void YM2151UpdateOne(int num, int endp);
142 void YM2151UpdateOne(void * BUF, int endp);
145 ** write 'v' to register 'r' on YM2151 chip number 'n'
147 void YMWriteReg(int n, int r, int v);
150 ** read status register on YM2151 chip number 'n'
152 unsigned char YMReadReg(unsigned char n);
156 ** return pointer to synthesized data
158 SAMPLE * YMBuffer(int n);
160 void YMSetIrqHandler(int n, void (* handler)(void));
164 void YMSaveState(FILE *);
165 void YMLoadState(FILE *);
167 #endif /* _H_YM2151_ */