1 // pce.h
2 #ifndef _INCLUDE_PCE_H
3 #define _INCLUDE_PCE_H
4 
5 #include "config.h"
6 
7 #if defined(HAVE_LIMITS_H)
8 #include <limits.h>
9 #endif
10 
11 #include "sys_dep.h"
12 #include "hard_pce.h"
13 #include "cheat.h"
14 #include "debug.h"
15 #include "gfx.h"
16 
17 #define WIDTH   (360+64)
18 #define HEIGHT  256
19 
20 #include "cleantyp.h"
21 
22 #ifdef MSDOS
23 
24 #include <crt0.h>
25 #include <conio.h>
26 #include <dir.h>
27 #include <dos.h>
28 
29 #elif defined(LINUX)
30 
31 #include <sys/param.h>
32 #include <sys/types.h>
33 #include <sys/ioctl.h>
34 #include <linux/cdrom.h>
35 
36 #elif defined(FREEBSD)
37 
38 #include <sys/param.h>
39 #include <sys/types.h>
40 #include <sys/ioctl.h>
41 
42 #elif defined(WIN32)
43 
44 #define MAX_INPUT 255
45 
46 #endif
47 
48 
49 
50 #ifdef KERNEL_DS
51 
52 #include "h6280.h"
53 #include "globals.h"
54 #include "interupt.h"
55 
56 #else
57 
58 #include "m6502.h"
59 
60 #endif
61 
62 #include <stdarg.h>
63 #include <stdio.h>
64 #include <stdlib.h>
65 #include "cd.h"
66 
67 #ifdef ALLEGRO
68 
69 #undef VGA
70 // Avoid both VGA and ALLEGRO define
71 
72 #define alleg_mouse_unused
73 #define alleg_flic_unused
74 #define alleg_gui_unused
75 
76 #include "allegro.h"
77 #include "info_dat.h"
78 #include "data.h"
79 // Include some informations to correctly use the datafile
80 
81 extern DATAFILE *datafile;
82 
83 #endif
84 
85 #define SERVER_HOSTNAME_MAX_SIZE 256
86 
87 
88 SInt32 CheckSprites (void);
89 void RefreshLine (int Y1, int Y2);
90 void RefreshScreen (void);
91 UInt32 CRC_file (char *);
92 SInt32 CartLoad (char *name);
93 #ifndef KERNEL_DS
94 int ResetPCE (M6502 * M);
95 #else
96 int ResetPCE ();
97 #endif
98 SInt32 InitMachine (void);
99 void TrashMachine (void);
100 SInt32 Joysticks (void);
101 UInt32 msf2nb_sect (UChar min, UChar sec, UChar fra);
102 void fill_cd_info ();
103 void nb_sect2msf (UInt32 lsn, UChar * min, UChar * sec, UChar * frm);
104 void delete_file_tmp (char *name, int dummy, int dummy2);
105 UChar TimerInt ();
106 
107 void init_log_file ();
108 int InitPCE (char *name, char *backmemname);
109 void TrashPCE (char *backmemname);
110 int RunPCE (void);
111 void pce_cd_read_sector (void);
112 void issue_ADPCM_dma (void);
113 
114 char*
115 search_possible_syscard();
116 
117 extern FILE *out_snd;
118 // The file used to put sound into
119 
120 extern SChar volatile key_delay;
121 // are we allowed to press another 'COMMAND' key ?
122 
123 extern volatile UInt32 message_delay;
124 // if different of zero, we must display the message pointed by pmessage
125 
126 extern char short_cart_name[PATH_MAX];
127 // Just the filename without the extension (with a dot)
128 // you just have to add your own extension...
129 
130 extern char short_iso_name[PATH_MAX];
131 // Added for ISO save support
132 
133 extern char cdsystem_path[PATH_MAX];
134 // The path of the cdsystem to launch automaticaly
135 
136 extern char sav_path[PATH_MAX];
137 // The place where to keep saved games
138 // currently a subdir a the EXE path named 'SAV'
139 
140 extern char video_path[PATH_MAX];
141 // The place where to keep output pictures
142 
143 extern char ISO_filename[PATH_MAX];
144 // the name of the ISO file
145 
146 extern char cart_name[PATH_MAX];
147 // the name of the rom to load
148 
149 extern char initial_path[PATH_MAX];
150 // initial path for rom seeking
151 
152 extern char short_exe_name[PATH_MAX];
153 
154 extern char sav_basepath[PATH_MAX];
155 // base path for saved games
156 
157 extern char tmp_basepath[PATH_MAX];
158 // base path for temporary operations
159 
160 extern char log_filename[PATH_MAX];
161 // filename of the log
162 
163 
164 #ifndef KERNEL_DS
165 
166 extern M6502 M;
167 
168 #endif
169 
170 extern UChar populus;
171 
172 extern UChar *PopRAM;
173 // Now dynamicaly allocated
174 // ( size of popRAMsize bytes )
175 // If someone could explain me why we need it
176 // the version I have works well without this trick
177 
178 extern const UInt32 PopRAMsize;
179 // I don't really know if it must be 0x8000 or 0x10000
180 
181 #ifdef ALLEGRO
182 extern BITMAP *XBuf;
183 #endif
184 
185 extern char *server_hostname;
186 // Name of the server to connect to
187 
188 extern SInt32 smode;
189 // what sound card type should we use? (0 means the silent one,
190 // my favorite : the fastest!!! ; and -1 means AUTODETECT;
191 // later will avoid autodetection if wanted)
192 
193 extern SChar silent;
194 // use sound?
195 
196 extern UChar language;
197 // the current language
198 
199 extern int BaseClock, UPeriod;
200 
201 extern UChar US_encoded_card;
202 // Do we have to swap even and odd bytes in the rom
203 
204 extern UChar debug_on_beginning;
205 // Do we have to set a bp on the reset IP
206 
207 extern UChar CD_emulation;
208 // Do we handle CDs
209 
210 extern UChar CDBIOS_replace[0x4d][2];
211 // Used to know what byte do we have replaced
212 
213 extern UChar use_eagle;
214 // Do we use eagle ?
215 
216 extern UInt32 timer_60;
217 // how many times do the interrupt have been called
218 
219 extern UChar bcdbin[0x100];
220 
221 extern UChar binbcd[0x100];
222 
223 extern UInt32 pce_cd_sectoraddy;
224 
225 struct host_video
226 {
227   boolean hardware_scaling;
228 };
229 
230 struct host_sound
231 {
232   boolean stereo;
233   UInt32 freq;
234   UInt16 sample_size;
235   boolean signed_sound;
236 };
237 
238 struct host_machine
239 {
240   struct host_video video;
241   struct host_sound sound;
242 };
243 
244 extern struct host_machine host;
245 
246 struct hugo_options
247 {
248   boolean want_stereo;
249   boolean want_fullscreen;
250   boolean want_fullscreen_aspect;
251   boolean want_hardware_scaling;
252   boolean configure_joypads;
253   boolean want_arcade_card_emulation;
254   boolean want_supergraphx_emulation;
255   boolean want_television_size_emulation;
256   UChar window_size;
257   UInt16 fullscreen_width;
258   UInt16 fullscreen_height;
259   UInt32 want_snd_freq;
260   UInt32 wanted_hardware_format;
261 #if defined(ENABLE_NETPLAY)
262   netplay_type want_netplay;
263   char server_hostname[SERVER_HOSTNAME_MAX_SIZE];
264   UChar local_input_mapping[5];
265 #endif
266 };
267 
268 extern struct hugo_options option;
269 
270 typedef struct
271 {
272 
273   UInt32 offset;
274 
275   UChar new_val;
276 
277 } PatchEntry;
278 
279 typedef struct
280 {
281 
282   UInt32 StartTime;
283   UInt32 Duration;
284   char data[32];
285 
286 } SubtitleEntry;
287 
288 
289 typedef enum
290 {
291   HCD_SOURCE_REGULAR_FILE,
292   HCD_SOURCE_CD_TRACK
293 } hcd_source_type;
294 
295 typedef struct
296 {
297   UChar beg_min;
298   UChar beg_sec;
299   UChar beg_fra;
300 
301   UChar type;
302 
303   UInt32 beg_lsn;
304   UInt32 length;
305 
306   hcd_source_type source_type;
307   char filename[256];
308 
309   UInt32 patch_number;
310   UInt32 subtitle_number;
311 
312   UChar subtitle_synchro_type;
313 
314   PatchEntry *patch;
315   SubtitleEntry *subtitle;
316 
317 } Track;
318 
319 extern Track CD_track[0x100];
320 
321 extern UChar nb_max_track;
322 
323 extern UChar video_driver;
324 
325 extern UChar use_scanline;
326 
327 extern UChar minimum_bios_hooking;
328 
329 extern UChar cart_reload;
330 
331 #define min(a,b) ({__typeof__(a) _a = (a); __typeof__(b) _b = (b);_a < _b ? _a : _b; })
332 
333 #define max(a,b) ({__typeof__(a) _a = (a); __typeof__(b) _b = (b);_a > _b ? _a : _b; })
334 
335 // Video related defines
336 
337 extern UChar can_write_debug;
338 
339 #define SpHitON    (io.VDC[CR].W&0x01)
340 #define OverON     (io.VDC[CR].W&0x02)
341 #define RasHitON   (io.VDC[CR].W&0x04)
342 #define VBlankON   (io.VDC[CR].W&0x08)
343 #define SpriteON   (io.VDC[CR].W&0x40)
344 #define ScreenON   (io.VDC[CR].W&0x80)
345 
346 #define VDC_CR     0x01
347 #define VDC_OR     0x02
348 #define VDC_RR     0x04
349 #define VDC_DS     0x08
350 #define VDC_DV     0x10
351 #define VDC_VD     0x20
352 #define VDC_BSY    0x40
353 #define VDC_SpHit       VDC_CR
354 #define VDC_Over        VDC_OR
355 #define VDC_RasHit      VDC_RR
356 #define VDC_InVBlank    VDC_VD
357 #define VDC_DMAfinish   VDC_DV
358 #define VDC_SATBfinish  VDC_DS
359 
360 #define SATBIntON (io.VDC[DCR].W&0x01)
361 #define DMAIntON  (io.VDC[DCR].W&0x02)
362 
363 #define IRQ2    1
364 #define IRQ1    2
365 #define TIRQ    4
366 
367 // Joystick related defines
368 #ifdef _DO_NOT_DEFINE_
369 #define J_UP      0
370 #define J_DOWN    1
371 #define J_LEFT    2
372 #define J_RIGHT   3
373 #define J_I       4
374 #define J_II      5
375 #define J_SELECT  6
376 #define J_START   7
377 #define J_AUTOI   8
378 #define J_AUTOII  9
379 #define J_PI      10
380 #define J_PII     11
381 #define J_PSELECT 12
382 #define J_PSTART  13
383 #define J_PAUTOI  14
384 #define J_PAUTOII 15
385 #define J_PXAXIS  16
386 #define J_PYAXIS  17
387 #define J_MAX     18
388 #endif
389 
390 // Post include to avoid circular definitions
391 
392 #include "list_rom.h" // List of known rom
393 
394 #include "gui.h"
395 
396 #include "config.h"
397 
398 #include "sprite.h"
399 
400 #include "hcd.h"
401 
402 #if defined(SEAL_SOUND)
403 
404 #include </djgpp/audio/include/audio.h> // SEAL include
405 
406 #endif /* SEAL sound */
407 
408 #include <time.h>
409 
410 #ifdef SOUND
411 #include "sound.h"
412 #endif // SOUND
413 
414 #endif
415