1 /* 2 File: fm.h -- header file for software emulation for FM sound generator 3 4 */ 5 #ifndef _H_FM_FM_ 6 #define _H_FM_FM_ 7 8 /* --- select emulation chips --- */ 9 #define BUILD_YM2203 (HAS_YM2203) /* build YM2203(OPN) emulator */ 10 #define BUILD_YM2608 (HAS_YM2608) /* build YM2608(OPNA) emulator */ 11 #define BUILD_YM2610 (HAS_YM2610) /* build YM2610(OPNB) emulator */ 12 #define BUILD_YM2610B (HAS_YM2610B) /* build YM2610B(OPNB?)emulator */ 13 #define BUILD_YM2612 (HAS_YM2612 || HAS_YM3438) /* build YM2612(OPN2) emulator */ 14 15 /* select bit size of output : 8 or 16 */ 16 #define FM_SAMPLE_BITS 16 17 18 /* select timer system internal or external */ 19 #define FM_INTERNAL_TIMER 0 20 21 /* --- speedup optimize --- */ 22 /* busy flag enulation , The definition of FM_GET_TIME_NOW() is necessary. */ 23 #if 0 /* QUASI88 */ 24 #define FM_BUSY_FLAG_SUPPORT 1 25 #else /* QUASI88 */ 26 #define FM_BUSY_FLAG_SUPPORT 0 27 #endif /* QUASI88 */ 28 29 /* --- external SSG(YM2149/AY-3-8910)emulator interface port */ 30 /* used by YM2203,YM2608,and YM2610 */ 31 struct ssg_callbacks 32 { 33 void (*set_clock)(void *param, int clock); 34 void (*write)(void *param, int address, int data); 35 int (*read)(void *param); 36 void (*reset)(void *param); 37 }; 38 39 /* --- external callback funstions for realtime update --- */ 40 41 /* for busy flag emulation , function FM_GET_TIME_NOW() should */ 42 /* return present time in seconds with "double" precision */ 43 /* in timer.c */ 44 #define FM_GET_TIME_NOW() timer_get_time() 45 46 #if BUILD_YM2203 47 /* in 2203intf.c */ 48 void YM2203UpdateRequest(void *param); 49 #define YM2203UpdateReq(chip) YM2203UpdateRequest(chip) 50 #endif 51 #if BUILD_YM2608 52 /* in 2608intf.c */ 53 void YM2608UpdateRequest(void *param); 54 #define YM2608UpdateReq(chip) YM2608UpdateRequest(chip); 55 #endif 56 #if BUILD_YM2610 57 /* in 2610intf.c */ 58 void YM2610UpdateRequest(void *param); 59 #define YM2610UpdateReq(chip) YM2610UpdateRequest(chip); 60 #endif 61 #if BUILD_YM2612 62 /* in 2612intf.c */ 63 void YM2612UpdateRequest(void *param); 64 #define YM2612UpdateReq(chip) YM2612UpdateRequest(chip); 65 #endif 66 67 /* compiler dependence */ 68 #if 0 69 #ifndef OSD_CPU_H 70 #define OSD_CPU_H 71 typedef unsigned char UINT8; /* unsigned 8bit */ 72 typedef unsigned short UINT16; /* unsigned 16bit */ 73 typedef unsigned int UINT32; /* unsigned 32bit */ 74 typedef signed char INT8; /* signed 8bit */ 75 typedef signed short INT16; /* signed 16bit */ 76 typedef signed int INT32; /* signed 32bit */ 77 #endif 78 #endif 79 80 #ifndef INLINE 81 #define INLINE static __inline__ 82 #endif 83 84 85 86 87 typedef stream_sample_t FMSAMPLE; 88 /* 89 #if (FM_SAMPLE_BITS==16) 90 typedef INT16 FMSAMPLE; 91 #endif 92 #if (FM_SAMPLE_BITS==8) 93 typedef unsigned char FMSAMPLE; 94 #endif 95 */ 96 97 typedef void (*FM_TIMERHANDLER)(void *param,int c,int cnt,double stepTime); 98 typedef void (*FM_IRQHANDLER)(void *param,int irq); 99 /* FM_TIMERHANDLER : Stop or Start timer */ 100 /* int n = chip number */ 101 /* int c = Channel 0=TimerA,1=TimerB */ 102 /* int count = timer count (0=stop) */ 103 /* doube stepTime = step time of one count (sec.)*/ 104 105 /* FM_IRQHHANDLER : IRQ level changing sense */ 106 /* int n = chip number */ 107 /* int irq = IRQ level 0=OFF,1=ON */ 108 109 #if BUILD_YM2203 110 /* -------------------- YM2203(OPN) Interface -------------------- */ 111 112 /* 113 ** Initialize YM2203 emulator(s). 114 ** 115 ** 'num' is the number of virtual YM2203's to allocate 116 ** 'baseclock' 117 ** 'rate' is sampling rate 118 ** 'TimerHandler' timer callback handler when timer start and clear 119 ** 'IRQHandler' IRQ callback handler when changed IRQ level 120 ** return 0 = success 121 */ 122 void * YM2203Init(void *param, int index, int baseclock, int rate, 123 FM_TIMERHANDLER TimerHandler,FM_IRQHANDLER IRQHandler, const struct ssg_callbacks *ssg); 124 125 /* 126 ** shutdown the YM2203 emulators 127 */ 128 void YM2203Shutdown(void *chip); 129 130 /* 131 ** reset all chip registers for YM2203 number 'num' 132 */ 133 void YM2203ResetChip(void *chip); 134 135 /* 136 ** update one of chip 137 */ 138 void YM2203UpdateOne(void *chip, FMSAMPLE *buffer, int length); 139 140 /* 141 ** Write 142 ** return : InterruptLevel 143 */ 144 int YM2203Write(void *chip,int a,unsigned char v); 145 146 /* 147 ** Read 148 ** return : InterruptLevel 149 */ 150 unsigned char YM2203Read(void *chip,int a); 151 152 /* 153 ** Timer OverFlow 154 */ 155 int YM2203TimerOver(void *chip, int c); 156 157 /* 158 ** State Save 159 */ 160 void YM2203Postload(void *chip); 161 #endif /* BUILD_YM2203 */ 162 163 #if BUILD_YM2608 164 /* -------------------- YM2608(OPNA) Interface -------------------- */ 165 void * YM2608Init(void *param, int index, int baseclock, int rate, 166 void *pcmroma,int pcmsizea, 167 FM_TIMERHANDLER TimerHandler,FM_IRQHANDLER IRQHandler, const struct ssg_callbacks *ssg); 168 void YM2608Shutdown(void *chip); 169 void YM2608ResetChip(void *chip); 170 void YM2608UpdateOne(void *chip, FMSAMPLE **buffer, int length); 171 172 int YM2608Write(void *chip, int a,unsigned char v); 173 unsigned char YM2608Read(void *chip,int a); 174 int YM2608TimerOver(void *chip, int c ); 175 void YM2608Postload(void *chip); 176 #endif /* BUILD_YM2608 */ 177 178 #if (BUILD_YM2610||BUILD_YM2610B) 179 /* -------------------- YM2610(OPNB) Interface -------------------- */ 180 void * YM2610Init(void *param, int index, int baseclock, int rate, 181 void *pcmroma,int pcmasize,void *pcmromb,int pcmbsize, 182 FM_TIMERHANDLER TimerHandler,FM_IRQHANDLER IRQHandler, const struct ssg_callbacks *ssg); 183 void YM2610Shutdown(void *chip); 184 void YM2610ResetChip(void *chip); 185 void YM2610UpdateOne(void *chip, FMSAMPLE **buffer, int length); 186 #if BUILD_YM2610B 187 void YM2610BUpdateOne(void *chip, FMSAMPLE **buffer, int length); 188 #endif 189 190 int YM2610Write(void *chip, int a,unsigned char v); 191 unsigned char YM2610Read(void *chip,int a); 192 int YM2610TimerOver(void *chip, int c ); 193 void YM2610Postload(void *chip); 194 #endif /* BUILD_YM2610 */ 195 196 #if BUILD_YM2612 197 void * YM2612Init(void *param, int index, int baseclock, int rate, 198 FM_TIMERHANDLER TimerHandler,FM_IRQHANDLER IRQHandler); 199 void YM2612Shutdown(void *chip); 200 void YM2612ResetChip(void *chip); 201 void YM2612UpdateOne(void *chip, FMSAMPLE **buffer, int length); 202 203 int YM2612Write(void *chip, int a,unsigned char v); 204 unsigned char YM2612Read(void *chip,int a); 205 int YM2612TimerOver(void *chip, int c ); 206 void YM2612Postload(void *chip); 207 #endif /* BUILD_YM2612 */ 208 209 210 #endif /* _H_FM_FM_ */ 211