Import Debian changes 1.23-12
[debian-dgen.git] / myfm.cpp
blobb1bdc78b3a9a097dfad0bc71406220d356f02157
1 // DGen v1.06+
2 // MYFM.CPP - interface to YM2612Update
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include "md.h"
8 extern int sound_is_okay;
10 // md.h also has include fm.h
12 // REMEMBER NOT TO USE ANY STATIC variables, because they
13 // will exist thoughout ALL megadrives!
15 int md::flush_fm_to_mame()
17 int sid,r;
18 // If we reset mame's ym2612 code, we need to pass all the values
19 // to it again
20 for (sid=0;sid<2;sid++)
22 for (r=0;r<0x100;r++)
24 if (sound_is_okay)
26 if (fm_reg[sid][r]!=-1)
28 YM2612Write(0,sid*2+0,r); // select reg r
29 YM2612Write(0,sid*2+1,fm_reg[sid][r]); // Write data
35 return 0;
38 int md::myfm_write(int a,int v,int md)
40 int sid=0;
41 int mame_can_have_it=1;
43 (void)md;
45 a&=3;
47 sid=(a&2)?1:0;
49 if ((a&1)==0) fm_sel[sid]=v;
50 else
52 // stash all values
53 fm_reg[sid] [fm_sel[sid]&0xff] = v;
55 if (fm_sel[sid]==0x2a) { dac_submit(v); mame_can_have_it=0; }
56 if (fm_sel[sid]==0x2b) { dac_enable(v); mame_can_have_it=0; }
58 if ((fm_sel[sid]&0xfc)==0x24) { mame_can_have_it=0; }
60 if (fm_sel[sid]==0x27)
62 if (v&0x10) fm_tover[0]&=~1;
63 if (v&0x20) fm_tover[0]&=~2;
64 // timer ack?
69 if (sound_is_okay && mame_can_have_it)
70 YM2612Write(0,a&3,v);
72 return 0;
75 int md::myfm_read(int a)
77 if ((a&1)==0)
78 return fm_tover[0];
79 else
81 if (sound_is_okay) YM2612Read(0,a&3);
83 return 0;
86 int md::mysn_write(int d)
88 if (sound_is_okay) SN76496Write(0,d);
89 return 0;
92 // This called once per raster
93 int md::fm_timer_callback()
95 int amax,bmax, i;
97 // Our raster lasts 63.61323 microseconds
98 for (i=0;i<4;i++) ras_fm_ticker[i]+=64;
100 // if (sound_is_okay) ret=YM2612Read(0,a&3);
102 // period of timer a is
103 // 18 * (1024 - ((fm_reg[0][0x24]<<2)+(fm_reg[0][0x25])&3))) microsecs
105 amax=18 * (1024 - ((fm_reg[0][0x24]<<2)+(fm_reg[0][0x25]&3)) );
106 bmax=288*(256-fm_reg[0][0x26]);
108 if (bmax<=0) bmax=1;
109 if (amax<=0) amax=1;
111 if (ras_fm_ticker[0]>=amax)
113 fm_tover[0]|=1; ras_fm_ticker[0]-=amax;
116 if (ras_fm_ticker[1]>=bmax)
118 fm_tover[0]|=2; ras_fm_ticker[1]-=bmax;
120 return 0;