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 :)
45 #define YM_NOISE (0x0F)
47 #define YM_CLOCKA1 (0x10)
48 #define YM_CLOCKA2 (0x11)
49 #define YM_CLOCKB (0x12)
50 #define YM_CLOCKSET (0x14)
52 #define YM_LFRQ (0x18)
53 #define YM_PMD_AMD (0x19)
54 #define YM_CT1_CT2_W (0x1B)
57 #define YM_CONNECT_BASE (0x20) /*1 reg per FM channel*/
58 #define YM_KC_BASE (0x28)
59 #define YM_KF_BASE (0x30)
60 #define YM_PMS_AMS_BASE (0x38)
62 #define YM_DT1_MUL_BASE (0x40) /*1 reg per operator*/
63 #define YM_TL_BASE (0x60)
64 #define YM_KS_AR_BASE (0x80)
65 #define YM_AMS_D1R_BASE (0xA0)
66 #define YM_DT2_D2R_BASE (0xC0)
67 #define YM_D1L_RR_BASE (0xE0)
69 typedef void SAMPLE; /*Yep, 16 bit is supported, at last*/
71 typedef struct{ /*oscillator data */
72 signed int freq; /*oscillator frequency (in indexes per sample) (fixed point)*/
73 signed int phase; /*accumulated oscillator phase (in indexes) (fixed point)*/
75 unsigned int TL; /*this is output level, in fact */
76 signed int volume; /*oscillator volume (fixed point) */
77 signed int attack_volume; /*used for attack phase calculations*/
79 signed int OscilFB; /*oscillator self feedback used only by operators 0*/
86 signed int delta_AR; /*volume delta for attack phase (fixed point)*/
87 signed int delta_D1R; /*volume delta for decay phase (fixed point)*/
88 signed int delta_D2R; /*volume delta for sustain phase (fixed point)*/
89 signed int delta_RR; /*volume delta for release phase (fixed point)*/
90 unsigned char state; /*Envelope state: 0-attack(AR) 1-decay(D1R) 2-sustain(D2R) 3-release(RR) 4-finished*/
94 /* here's the virtual YM2151 */
95 typedef struct ym2151_f {
96 SAMPLE * Buf; /* sound buffer */
98 OscilRec Oscils[32]; /*there are 32 operators in YM2151*/
99 unsigned char Regs[256]; /*table of internal chip registers*/
100 unsigned char FeedBack[8]; /*feedback shift value for operators 0 in each channel*/
101 unsigned char ConnectTab[8]; /*connection algorithm number for each channel*/
102 unsigned char KC[8]; /*KC for each channel*/
103 unsigned char KF[32]; /*KF for each operator*/
104 unsigned char KS[32]; /*KS for each operator*/
106 unsigned char TimA, TimB, TimIRQ;
107 signed int TimAVal, TimBVal;
108 void * TimATimer, * TimBTimer; /* ASG 980324 -- added for tracking timers */
109 void (* handler)(void);
114 ** Initialize YM2151 emulator(s).
116 ** 'num' is the number of virtual YM2151's to allocate
117 ** 'rate' is sampling rate and 'bufsiz' is the size of the
118 ** buffer that should be updated at each interval
120 int YMInit(int num, int clock, int rate, int sample_bits, int bufsiz); //, SAMPLE ** buffer);
123 ** shutdown the YM2151 emulators ...
125 void YMShutdown(void);
128 ** reset all chip registers for YM2151 number 'num'
130 void YMResetChip(int num);
133 ** called to update all chips; should be called about 50 - 70 times per
134 ** second ... (depends on sample rate and buffer size)
136 void YM2151Update(void);
138 //void YM2151UpdateOne(int num, int endp);
139 void YM2151UpdateOne(void * BUF, int endp);
142 ** write 'v' to register 'r' on YM2151 chip number 'n'
144 void YMWriteReg(int n, int r, int v);
147 ** read status register on YM2151 chip number 'n'
149 unsigned char YMReadReg(unsigned char n);
153 ** return pointer to synthesized data
155 SAMPLE * YMBuffer(int n);
157 void YMSetIrqHandler(int n, void (* handler)(void));
159 #endif /* _H_YM2151_ */