Import Debian changes 1.23-11
[debian-dgen.git] / md.h
blob0d47858447645479280750f062d99cf786861508
1 // DGen
3 #ifndef __MD_H__
4 #define __MD_H__
6 #define VER VERSION
8 // You needn't worry about changing the #defines at the beginning of this
9 // header anymore, you can simply edit Makefile.config
11 #ifdef COMPILE_WITH_STAR
12 #ifndef __STARCPU_H__
13 #include "starcpu.h"
14 #endif
15 #endif
17 #ifdef COMPILE_WITH_M68KEM
18 #ifndef M68000__HEADER
19 extern "C" {
20 #include "m68000.h"
22 #endif
23 #endif
25 #ifdef COMPILE_WITH_MUSA
26 #ifndef M68K__HEADER
27 extern "C"
29 #include "m68k.h"
31 #endif
32 #endif
34 #ifndef _MZ80_H_
35 #include "mz80.h"
36 #endif
38 //#define BUILD_YM2612
39 extern "C" {
40 #include "fm.h"
43 extern "C" {
44 int SN76496_init(int chip,int clock,int sample_rate,int sample_bits);
45 void SN76496Write(int chip,int data);
46 void SN76496Update_16(int chip,void *buffer,int length);
49 extern "C" int test_ctv(unsigned char *dest, int len);
50 extern "C" int blur_bitmap_16(unsigned char *dest, int len);
51 extern "C" int blur_bitmap_15(unsigned char *dest, int len);
53 struct bmap { unsigned char *data; int w,h; int pitch; int bpp; };
55 // Info passed to render the screen (possibly line by line)
56 struct dgen_sinfo { unsigned char *vram,*cram,*vsram,*vdp_reg; };
57 // New struct, happily encapsulates all the sound info
58 struct sndinfo { signed short *l, *r; int len; };
60 int draw_md_graphics
61 (struct bmap *bm,unsigned char passpal[256],struct dgen_sinfo *si,
62 int ymin, int ymax, int layer_sel);
63 int get_md_palette(unsigned char pal[256],unsigned char *cram);
65 class md;
66 class md_vdp
68 public:
69 // Next three lines are the state of the VDP
70 // They have to be public so we can save and load states
71 // and draw the screen.
72 unsigned char *mem,*vram,*cram,*vsram;
73 unsigned char reg[0x20];
74 int rw_mode,rw_addr,rw_dma;
75 private:
76 int poke_vram (int addr,unsigned char d);
77 int poke_cram (int addr,unsigned char d);
78 int poke_vsram(int addr,unsigned char d);
79 int dma_len();
80 int dma_addr();
81 unsigned char dma_mem_read(int addr);
82 int putword(unsigned short d);
83 int putbyte(unsigned char d);
84 int ok;
85 // Used by draw_scanline to render the different display components
86 void draw_tile1(int which, int line, unsigned char *where);
87 void draw_tile1_solid(int which, int line, unsigned char *where);
88 void draw_tile2(int which, int line, unsigned char *where);
89 void draw_tile2_solid(int which, int line, unsigned char *where);
90 /* FIXME: do 3 bytes/pixel */
91 void draw_tile3(int which, int line, unsigned char *where);
92 void draw_tile3_solid(int which, int line, unsigned char *where);
93 void draw_tile4(int which, int line, unsigned char *where);
94 void draw_tile4_solid(int which, int line, unsigned char *where);
95 void draw_window(int line, int front);
96 void draw_sprites(int line, int front);
97 void draw_plane_back0(int line);
98 void draw_plane_back1(int line);
99 void draw_plane_front0(int line);
100 void draw_plane_front1(int line);
101 // Working variables for the above
102 unsigned char sprite_order[0x101], *sprite_base;
103 unsigned sprite_count, Bpp, Bpp_times8;
104 unsigned char *dest;
105 public:
106 md_vdp(); ~md_vdp();
107 md *belongs;
108 // These are called by MEM.CPP
109 int command(unsigned int cmd);
110 unsigned short readword();
111 unsigned char readbyte();
112 int writeword(unsigned short d);
113 int writebyte(unsigned char d);
115 int okay() {return ok;}
116 unsigned char *dirt; // Bitfield: what has changed VRAM/CRAM/VSRAM/Reg
117 int get_screen_info(struct dgen_sinfo *si); // For Graph
118 int reset();
120 unsigned int *highpal;
121 // Draw a scanline
122 void draw_scanline(struct bmap *bits, int line);
125 #ifdef COMPILE_WITH_M68KEM
126 // Make sure this gets C linkage
127 extern "C" void cpu_setOPbase24(int pc);
128 #endif
130 class md
132 private:
133 #ifdef COMPILE_WITH_M68KEM
134 // Yuck - had to use friend function :(
135 friend void cpu_setOPbase24(int pc);
136 #endif
137 int romlen;
138 int ok;
139 unsigned char *mem,*rom,*ram,*z80ram;
140 // Saveram stuff:
141 unsigned char *saveram; // The actual saveram buffer
142 unsigned save_start, save_len; // Start address and length
143 int save_prot, save_active; // Flags set from $A130F1
144 public:
145 md_vdp vdp;
146 private:
147 struct mz80context z80;
148 #ifdef COMPILE_WITH_STAR
149 struct S68000CONTEXT cpu;
150 STARSCREAM_PROGRAMREGION *fetch;
151 STARSCREAM_DATAREGION *readbyte,*readword,*writebyte,*writeword;
152 int memory_map();
153 #endif
154 int star_mz80_on();
155 int star_mz80_off();
157 int z80_bank68k; // 9 bits
158 int z80_online;
159 int odo; //,odo_frame_max; // value of odo now/at end of frame
160 int odo_line_start,odo_line_end,odo_line_len,ras,frame;
161 int hint_countdown;
162 int z80_extra_cycles;
164 // Note order is (0) Vblank end -------- Vblank Start -- (HIGH)
165 // So int6 happens in the middle of the count
167 int coo_waiting; // after 04 write which is 0x4xxx or 0x8xxx
168 unsigned int coo_cmd; // The complete command
169 int aoo3_toggle,aoo5_toggle,aoo3_six,aoo5_six;
170 int aoo3_six_timeout, aoo5_six_timeout;
171 int calculate_hcoord();
172 unsigned char calculate_coo8();
173 unsigned char calculate_coo9();
174 int may_want_to_get_pic(struct bmap *bm,unsigned char retpal[256],int mark);
175 int may_want_to_get_sound(struct sndinfo *sndi);
176 int z80_int_pending;
178 void run_to_odo_star(int odo_to);
179 void run_to_odo_musa(int odo_to);
180 void run_to_odo_m68kem(int odo_to);
181 void run_to_odo_z80(int odo_to);
183 int fm_timer_callback();
184 int myfm_read(int a);
185 int mysn_write(int v);
186 int fm_sel[2],fm_tover[2],ras_fm_ticker[4];
187 signed short fm_reg[2][0x100]; // All of them (-1 = not def'd yet)
189 int dac_data[0x138], dac_enabled, dac_last;
190 // Since dac values are normally shifted << 6, 1 is used to mark unchanged
191 // values.
192 void dac_init() { dac_last = 1; dac_enabled = 0; dac_clear(); }
193 void dac_clear() {
194 dac_data[0] = dac_last;
195 for(int i = 1; i < 0x138; ++i)
196 dac_data[i] = 1;
198 void dac_submit(int d) {
199 dac_last = (d - 0x80) << 6; if(dac_enabled) dac_data[ras] = dac_last;
201 void dac_enable(int d) {
202 dac_enabled = d & 0x80;
203 dac_data[ras] = (dac_enabled? dac_last : 1);
206 public:
207 int myfm_write(int a,int v,int md);
208 int flush_fm_to_mame();
209 int pause, layer_sel;
210 // public struct, full with data from the cartridge header
211 struct _carthead_ {
212 char system_name[0x10]; // "SEGA GENESIS ", "SEGA MEGA DRIVE "
213 char copyright[0x10]; // "(C)SEGA 1988.JUL"
214 char domestic_name[0x30]; // Domestic game name
215 char overseas_name[0x30]; // Overseas game name
216 char product_no[0xe]; // "GM XXXXXXXX-XX" or "GM MK-XXXX -00"
217 unsigned short checksum; // ROM checksum
218 char control_data[0x10]; // I/O use data (usually only joystick)
219 unsigned rom_start, rom_end; // ROM start & end addresses
220 unsigned ram_start, ram_end; // RAM start & end addresses
221 unsigned short save_magic; // 0x5241("RA") if saveram, else 0x2020
222 unsigned short save_flags; // Misc saveram info
223 unsigned save_start, save_end; // Saveram start & end
224 unsigned short modem_magic; // 0x4d4f("MO") if uses modem, else 0x2020
225 char modem_firm[4]; // Modem firm name (should be same as (c))
226 char modem_ver[4]; // yy.z, yy=ID number, z=version
227 char memo[0x28]; // Extra data
228 char countries[0x10]; // Country code
229 } cart_head;
230 int snd_mute; // &1=fm &2=psg &4=dac
231 int country_ver;
232 int pal; // 0 = NTSC 1 = PAL
233 int one_frame_star(struct bmap *bm,unsigned char retpal[256],struct sndinfo *sndi);
234 int one_frame_musa(struct bmap *bm,unsigned char retpal[256],struct sndinfo *sndi);
235 int one_frame_m68kem(struct bmap *bm,unsigned char retpal[256],struct sndinfo *sndi);
236 int one_frame(struct bmap *bm,unsigned char retpal[256],struct sndinfo *sndi);
238 int pad[2];
239 // c000004 bit 1 write fifo empty, bit 0 write fifo full (???)
240 // c000005 vint happened, (sprover, coll, oddinint)
241 // invblank, inhblank, dma busy, pal
242 unsigned char coo4,coo5;
243 int okay() {return ok;}
244 md();
245 ~md();
246 int plug_in(unsigned char *cart,int len);
247 int unplug();
248 int load(char *name);
250 int reset();
252 unsigned misc_readbyte(unsigned a);
253 void misc_writebyte(unsigned a,unsigned d);
254 unsigned misc_readword(unsigned a);
255 void misc_writeword(unsigned a,unsigned d);
257 int z80_init();
258 unsigned char z80_read(unsigned int a);
259 void z80_write(unsigned int a,unsigned char v);
260 unsigned short z80_port_read(unsigned short a);
261 void z80_port_write(unsigned short a,unsigned char v);
263 int cpu_emu;// OK to read it but call change_cpu_emu to change it
264 int change_cpu_emu(int to);
265 mz80context& z80_context() {return z80;}
266 int load(FILE *hand,char *desc);
267 int save(FILE *hand,char *desc);
268 int import_gst(FILE *hand);
269 int export_gst(FILE *hand);
271 char romfilename[256]; // If known
273 int get_screen_info(struct dgen_sinfo *si)
274 { return vdp.get_screen_info(si); }
275 int z80dump();
277 // Fix ROM checksum
278 void fix_rom_checksum();
280 // Added by Joe Groff:
281 // Patch the ROM code, using Game Genie/Hex codes
282 void patch(const char *list);
283 // Get/put the battery save RAM
284 int has_save_ram();
285 void get_save_ram(FILE *from);
286 void put_save_ram(FILE *into);
288 // Added by Phillip K. Hornung <redx@pknet.com>
289 // Linux joystick initialization and handling routines
290 void init_joysticks();
291 void read_joysticks();
294 inline int md::has_save_ram()
296 return save_len;
299 #endif // __MD_H__