1 #ifndef DRIVER_H 2 #define DRIVER_H 3 4 #include <retro_inline.h> 5 6 #include "osd_cpu.h" 7 #include "memory.h" 8 #include "osdepend.h" 9 #include "mame.h" 10 #include "common.h" 11 #include "drawgfx.h" 12 #include "palette.h" 13 #include "cpuintrf.h" 14 #include "sndintrf.h" 15 #include "input.h" 16 #include "inptport.h" 17 #include "usrintrf.h" 18 #include "cheat.h" 19 #include "tilemap.h" 20 #include "sprite.h" 21 #include "gfxobj.h" 22 #include "profiler.h" 23 24 #ifdef MAME_NET 25 #include "network.h" 26 #endif /* MAME_NET */ 27 28 struct MachineCPU 29 { 30 int cpu_type; /* see #defines below. */ 31 int cpu_clock; /* in Hertz */ 32 const struct MemoryReadAddress *memory_read; 33 const struct MemoryWriteAddress *memory_write; 34 const struct IOReadPort *port_read; 35 const struct IOWritePort *port_write; 36 int (*vblank_interrupt)(void); 37 int vblank_interrupts_per_frame; /* usually 1 */ 38 /* use this for interrupts which are not tied to vblank */ 39 /* usually frequency in Hz, but if you need */ 40 /* greater precision you can give the period in nanoseconds */ 41 int (*timed_interrupt)(void); 42 int timed_interrupts_per_second; 43 /* pointer to a parameter to pass to the CPU cores reset function */ 44 void *reset_param; 45 }; 46 47 enum 48 { 49 CPU_DUMMY, 50 #if (HAS_Z80) 51 CPU_Z80, 52 #endif 53 #if (HAS_DRZ80) 54 CPU_DRZ80, 55 #endif 56 #if (HAS_Z80GB) 57 CPU_Z80GB, 58 #endif 59 #if (HAS_8080) 60 CPU_8080, 61 #endif 62 #if (HAS_8085A) 63 CPU_8085A, 64 #endif 65 #if (HAS_M6502) 66 CPU_M6502, 67 #endif 68 #if (HAS_M65C02) 69 CPU_M65C02, 70 #endif 71 #if (HAS_M65SC02) 72 CPU_M65SC02, 73 #endif 74 #if (HAS_M65CE02) 75 CPU_M65CE02, 76 #endif 77 #if (HAS_M6509) 78 CPU_M6509, 79 #endif 80 #if (HAS_M6510) 81 CPU_M6510, 82 #endif 83 #if (HAS_M6510T) 84 CPU_M6510T, 85 #endif 86 #if (HAS_M7501) 87 CPU_M7501, 88 #endif 89 #if (HAS_M8502) 90 CPU_M8502, 91 #endif 92 #if (HAS_N2A03) 93 CPU_N2A03, 94 #endif 95 #if (HAS_M4510) 96 CPU_M4510, 97 #endif 98 #if (HAS_H6280) 99 CPU_H6280, 100 #endif 101 #if (HAS_I86) 102 CPU_I86, 103 #endif 104 #if (HAS_I88) 105 CPU_I88, 106 #endif 107 #if (HAS_I186) 108 CPU_I186, 109 #endif 110 #if (HAS_I188) 111 CPU_I188, 112 #endif 113 #if (HAS_I286) 114 CPU_I286, 115 #endif 116 #if (HAS_V20) 117 CPU_V20, 118 #endif 119 #if (HAS_V30) 120 CPU_V30, 121 #endif 122 #if (HAS_V33) 123 CPU_V33, 124 #endif 125 #if (HAS_ARMNEC) 126 CPU_ARMV30, 127 CPU_ARMV33, 128 #endif 129 #if (HAS_I8035) 130 CPU_I8035, /* same as CPU_I8039 */ 131 #endif 132 #if (HAS_I8039) 133 CPU_I8039, 134 #endif 135 #if (HAS_I8048) 136 CPU_I8048, /* same as CPU_I8039 */ 137 #endif 138 #if (HAS_N7751) 139 CPU_N7751, /* same as CPU_I8039 */ 140 #endif 141 #if (HAS_M6800) 142 CPU_M6800, /* same as CPU_M6802/CPU_M6808 */ 143 #endif 144 #if (HAS_M6801) 145 CPU_M6801, /* same as CPU_M6803 */ 146 #endif 147 #if (HAS_M6802) 148 CPU_M6802, /* same as CPU_M6800/CPU_M6808 */ 149 #endif 150 #if (HAS_M6803) 151 CPU_M6803, /* same as CPU_M6801 */ 152 #endif 153 #if (HAS_M6808) 154 CPU_M6808, /* same as CPU_M6800/CPU_M6802 */ 155 #endif 156 #if (HAS_HD63701) 157 CPU_HD63701, /* 6808 with some additional opcodes */ 158 #endif 159 #if (HAS_NSC8105) 160 CPU_NSC8105, /* same(?) as CPU_M6802(?) with scrambled opcodes. There is at least one new opcode. */ 161 #endif 162 #if (HAS_M6805) 163 CPU_M6805, 164 #endif 165 #if (HAS_M68705) 166 CPU_M68705, /* same as CPU_M6805 */ 167 #endif 168 #if (HAS_HD63705) 169 CPU_HD63705, /* M6805 family but larger address space, different stack size */ 170 #endif 171 #if (HAS_HD6309) 172 CPU_HD6309, /* same as CPU_M6809 (actually it's not 100% compatible) */ 173 #endif 174 #if (HAS_M6809) 175 CPU_M6809, 176 #endif 177 #if (HAS_KONAMI) 178 CPU_KONAMI, 179 #endif 180 #if (HAS_M68000) 181 CPU_M68000, 182 #endif 183 #if (HAS_CYCLONE) 184 CPU_CYCLONE, 185 #endif 186 #if (HAS_M68010) 187 CPU_M68010, 188 #endif 189 #if (HAS_M68EC020) 190 CPU_M68EC020, 191 #endif 192 #if (HAS_M68020) 193 CPU_M68020, 194 #endif 195 #if (HAS_T11) 196 CPU_T11, 197 #endif 198 #if (HAS_S2650) 199 CPU_S2650, 200 #endif 201 #if (HAS_TMS34010) 202 CPU_TMS34010, 203 #endif 204 #if (HAS_TMS9900) 205 CPU_TMS9900, 206 #endif 207 #if (HAS_TMS9940) 208 CPU_TMS9940, 209 #endif 210 #if (HAS_TMS9980) 211 CPU_TMS9980, 212 #endif 213 #if (HAS_TMS9985) 214 CPU_TMS9985, 215 #endif 216 #if (HAS_TMS9989) 217 CPU_TMS9989, 218 #endif 219 #if (HAS_TMS9995) 220 CPU_TMS9995, 221 #endif 222 #if (HAS_TMS99105A) 223 CPU_TMS99105A, 224 #endif 225 #if (HAS_TMS99110A) 226 CPU_TMS99110A, 227 #endif 228 #if (HAS_Z8000) 229 CPU_Z8000, 230 #endif 231 #if (HAS_TMS320C10) 232 CPU_TMS320C10, 233 #endif 234 #if (HAS_CCPU) 235 CPU_CCPU, 236 #endif 237 #if (HAS_PDP1) 238 CPU_PDP1, 239 #endif 240 #if (HAS_ADSP2100) 241 CPU_ADSP2100, 242 #endif 243 #if (HAS_ADSP2105) 244 CPU_ADSP2105, 245 #endif 246 #if (HAS_MIPS) 247 CPU_MIPS, 248 #endif 249 #if (HAS_SC61860) 250 CPU_SC61860, 251 #endif 252 #if (HAS_ARM) 253 CPU_ARM, 254 #endif 255 CPU_COUNT 256 }; 257 258 /* set this if the CPU is used as a slave for audio. It will not be emulated if */ 259 /* sound is disabled, therefore speeding up a lot the emulation. */ 260 #define CPU_AUDIO_CPU 0x8000 261 262 /* the Z80 can be wired to use 16 bit addressing for I/O ports */ 263 #define CPU_16BIT_PORT 0x4000 264 265 #define CPU_FLAGS_MASK 0xff00 266 267 268 #define MAX_CPU 8 /* MAX_CPU is the maximum number of CPUs which cpuintrf.c */ 269 /* can run at the same time. Currently, 8 is enough. */ 270 271 272 #define MAX_SOUND 5 /* MAX_SOUND is the maximum number of sound subsystems */ 273 /* which can run at the same time. Currently, 5 is enough. */ 274 275 276 277 struct MachineDriver 278 { 279 /* basic machine hardware */ 280 struct MachineCPU cpu[MAX_CPU]; 281 float frames_per_second; 282 int vblank_duration; /* in microseconds - see description below */ 283 int cpu_slices_per_frame; /* for multicpu games. 1 is the minimum, meaning */ 284 /* that each CPU runs for the whole video frame */ 285 /* before giving control to the others. The higher */ 286 /* this setting, the more closely CPUs are interleaved */ 287 /* and therefore the more accurate the emulation is. */ 288 /* However, an higher setting also means slower */ 289 /* performance. */ 290 void (*init_machine)(void); 291 #ifdef MESS 292 void (*stop_machine)(void); /* needed for MESS */ 293 #endif 294 295 /* video hardware */ 296 int screen_width,screen_height; 297 struct rectangle default_visible_area; /* the visible area can be changed at */ 298 /* run time, but it should never be larger than the */ 299 /* one specified here, in order not to force the */ 300 /* OS dependant code to resize the display window. */ 301 struct GfxDecodeInfo *gfxdecodeinfo; 302 unsigned int total_colors; /* palette is 3*total_colors bytes long */ 303 unsigned int color_table_len; /* length in shorts of the color lookup table */ 304 void (*vh_init_palette)(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom); 305 306 int video_attributes; /* ASG 081897 */ 307 308 void (*vh_eof_callback)(void); /* called every frame after osd_update_video_and_audio() */ 309 /* This is useful when there are operations that need */ 310 /* to be performed every frame regardless of frameskip, */ 311 /* e.g. sprite buffering or collision detection. */ 312 int (*vh_start)(void); 313 void (*vh_stop)(void); 314 void (*vh_update)(struct osd_bitmap *bitmap,int full_refresh); 315 316 /* sound hardware */ 317 int sound_attributes; 318 int obsolete1; 319 int obsolete2; 320 int obsolete3; 321 struct MachineSound sound[MAX_SOUND]; 322 323 /* 324 use this to manage nvram/eeprom/cmos/etc. 325 It is called before the emulation starts and after it ends. Note that it is 326 NOT called when the game is reset, since it is not needed. 327 file == 0, read_or_write == 0 -> first time the game is run, initialize nvram 328 file != 0, read_or_write == 0 -> load nvram from disk 329 file == 0, read_or_write != 0 -> not allowed 330 file != 0, read_or_write != 0 -> save nvram to disk 331 */ 332 void (*nvram_handler)(void *file,int read_or_write); 333 }; 334 335 336 337 /* VBlank is the period when the video beam is outside of the visible area and */ 338 /* returns from the bottom to the top of the screen to prepare for a new video frame. */ 339 /* VBlank duration is an important factor in how the game renders itself. MAME */ 340 /* generates the vblank_interrupt, lets the game run for vblank_duration microseconds, */ 341 /* and then updates the screen. This faithfully reproduces the behaviour of the real */ 342 /* hardware. In many cases, the game does video related operations both in its vblank */ 343 /* interrupt, and in the normal game code; it is therefore important to set up */ 344 /* vblank_duration accurately to have everything properly in sync. An example of this */ 345 /* is Commando: if you set vblank_duration to 0, therefore redrawing the screen BEFORE */ 346 /* the vblank interrupt is executed, sprites will be misaligned when the screen scrolls. */ 347 348 /* Here are some predefined, TOTALLY ARBITRARY values for vblank_duration, which should */ 349 /* be OK for most cases. I have NO IDEA how accurate they are compared to the real */ 350 /* hardware, they could be completely wrong. */ 351 #define DEFAULT_60HZ_VBLANK_DURATION 0 352 #define DEFAULT_30HZ_VBLANK_DURATION 0 353 /* If you use IPT_VBLANK, you need a duration different from 0. */ 354 #define DEFAULT_REAL_60HZ_VBLANK_DURATION 2500 355 #define DEFAULT_REAL_30HZ_VBLANK_DURATION 2500 356 357 358 359 /* flags for video_attributes */ 360 361 /* bit 0 of the video attributes indicates raster or vector video hardware */ 362 #define VIDEO_TYPE_RASTER 0x0000 363 #define VIDEO_TYPE_VECTOR 0x0001 364 365 /* bit 1 of the video attributes indicates whether or not dirty rectangles will work */ 366 #define VIDEO_SUPPORTS_DIRTY 0x0002 367 368 /* bit 2 of the video attributes indicates whether or not the driver modifies the palette */ 369 #define VIDEO_MODIFIES_PALETTE 0x0004 370 371 /* bit 3 of the video attributes indicates that the game's palette has 6 or more bits */ 372 /* per gun, and would therefore require a 24-bit display. This is entirely up to */ 373 /* the OS dpeendant layer, the bitmap will still be 16-bit. */ 374 #define VIDEO_NEEDS_6BITS_PER_GUN 0x0008 375 376 /* ASG 980417 - added: */ 377 /* bit 4 of the video attributes indicates that the driver wants its refresh after */ 378 /* the VBLANK instead of before. */ 379 #define VIDEO_UPDATE_BEFORE_VBLANK 0x0000 380 #define VIDEO_UPDATE_AFTER_VBLANK 0x0010 381 382 /* In most cases we assume pixels are square (1:1 aspect ratio) but some games need */ 383 /* different proportions, e.g. 1:2 for Blasteroids */ 384 #define VIDEO_PIXEL_ASPECT_RATIO_MASK 0x0020 385 #define VIDEO_PIXEL_ASPECT_RATIO_1_1 0x0000 386 #define VIDEO_PIXEL_ASPECT_RATIO_1_2 0x0020 387 388 #define VIDEO_DUAL_MONITOR 0x0040 389 390 /* Mish 181099: See comments in vidhrdw/generic.c for details */ 391 #define VIDEO_BUFFERS_SPRITERAM 0x0080 392 393 /* flags for sound_attributes */ 394 #define SOUND_SUPPORTS_STEREO 0x0001 395 396 397 398 struct GameDriver 399 { 400 const char *source_file; /* set this to __FILE__ */ 401 const struct GameDriver *clone_of; /* if this is a clone, point to */ 402 /* the main version of the game */ 403 const char *name; 404 const char *description; 405 const char *year; 406 const char *manufacturer; 407 const struct MachineDriver *drv; 408 const struct InputPortTiny *input_ports; 409 void (*driver_init)(void); /* optional function to be called during initialization */ 410 /* This is called ONCE, unlike Machine->init_machine */ 411 /* which is called every time the game is reset. */ 412 413 const struct RomModule *rom; 414 #ifdef MESS 415 const struct IODevice *dev; 416 #endif 417 418 UINT32 flags; /* orientation and other flags; see defines below */ 419 }; 420 421 422 /* values for the flags field */ 423 424 #define ORIENTATION_MASK 0x0007 425 #define ORIENTATION_FLIP_X 0x0001 /* mirror everything in the X direction */ 426 #define ORIENTATION_FLIP_Y 0x0002 /* mirror everything in the Y direction */ 427 #define ORIENTATION_SWAP_XY 0x0004 /* mirror along the top-left/bottom-right diagonal */ 428 429 #define GAME_NOT_WORKING 0x0008 430 #define GAME_WRONG_COLORS 0x0010 /* colors are totally wrong */ 431 #define GAME_IMPERFECT_COLORS 0x0020 /* colors are not 100% accurate, but close */ 432 #define GAME_NO_SOUND 0x0040 /* sound is missing */ 433 #define GAME_IMPERFECT_SOUND 0x0080 /* sound is known to be wrong */ 434 #define GAME_REQUIRES_16BIT 0x0100 /* cannot fit in 256 colors */ 435 #define GAME_NO_COCKTAIL 0x0200 /* screen flip support is missing */ 436 #define GAME_UNEMULATED_PROTECTION 0x0400 /* game's protection not fully emulated */ 437 #define NOT_A_DRIVER 0x4000 /* set by the fake "root" driver_ and by "containers" */ 438 /* e.g. driver_neogeo. */ 439 #ifdef MESS 440 #define GAME_COMPUTER 0x8000 /* Driver is a computer (needs full keyboard) */ 441 #define GAME_COMPUTER_MODIFIED 0x0800 /* Official? Hack */ 442 #define GAME_ALIAS NOT_A_DRIVER /* Driver is only an alias for an existing model */ 443 #endif 444 445 446 #define GAME(YEAR,NAME,PARENT,MACHINE,INPUT,INIT,MONITOR,COMPANY,FULLNAME) \ 447 extern struct GameDriver driver_##PARENT; \ 448 struct GameDriver driver_##NAME = \ 449 { \ 450 __FILE__, \ 451 &driver_##PARENT, \ 452 #NAME, \ 453 FULLNAME, \ 454 #YEAR, \ 455 COMPANY, \ 456 &machine_driver_##MACHINE, \ 457 input_ports_##INPUT, \ 458 init_##INIT, \ 459 rom_##NAME, \ 460 MONITOR, \ 461 }; 462 463 #define GAMEX(YEAR,NAME,PARENT,MACHINE,INPUT,INIT,MONITOR,COMPANY,FULLNAME,FLAGS) \ 464 extern struct GameDriver driver_##PARENT; \ 465 struct GameDriver driver_##NAME = \ 466 { \ 467 __FILE__, \ 468 &driver_##PARENT, \ 469 #NAME, \ 470 FULLNAME, \ 471 #YEAR, \ 472 COMPANY, \ 473 &machine_driver_##MACHINE, \ 474 input_ports_##INPUT, \ 475 init_##INIT, \ 476 rom_##NAME, \ 477 (MONITOR)|(FLAGS), \ 478 }; 479 480 481 /* monitor parameters to be used with the GAME() macro */ 482 #define ROT0 0x0000 483 #define ROT90 (ORIENTATION_SWAP_XY|ORIENTATION_FLIP_X) /* rotate clockwise 90 degrees */ 484 #define ROT180 (ORIENTATION_FLIP_X|ORIENTATION_FLIP_Y) /* rotate 180 degrees */ 485 #define ROT270 (ORIENTATION_SWAP_XY|ORIENTATION_FLIP_Y) /* rotate counter-clockwise 90 degrees */ 486 #define ROT0_16BIT (ROT0|GAME_REQUIRES_16BIT) 487 #define ROT90_16BIT (ROT90|GAME_REQUIRES_16BIT) 488 #define ROT180_16BIT (ROT180|GAME_REQUIRES_16BIT) 489 #define ROT270_16BIT (ROT270|GAME_REQUIRES_16BIT) 490 491 /* this allows to leave the INIT field empty in the GAME() macro call */ 492 #define init_0 0 493 494 495 extern const struct GameDriver *drivers[]; 496 497 #endif 498