1 /********************************************************************* 2 3 common.h 4 5 Generic functions, mostly ROM related. 6 7 *********************************************************************/ 8 9 #ifndef COMMON_H 10 #define COMMON_H 11 12 struct RomModule 13 { 14 const char *name; /* name of the file to load */ 15 UINT32 offset; /* offset to load it to */ 16 UINT32 length; /* length of the file */ 17 UINT32 crc; /* standard CRC-32 checksum */ 18 }; 19 20 /* there are some special cases for the above. name, offset and size all set to 0 */ 21 /* mark the end of the array. If name is 0 and the others aren't, that means "continue */ 22 /* reading the previous rom from this address". If length is 0 and offset is not 0, */ 23 /* that marks the start of a new memory region. Confused? Well, don't worry, just use */ 24 /* the macros below. */ 25 26 #define ROMFLAG_MASK 0xfc000000 /* 6 bits worth of flags in the high nibble */ 27 28 /* Masks for individual ROMs */ 29 #define ROMFLAG_ALTERNATE 0x80000000 /* Alternate bytes, either even or odd, or nibbles, low or high */ 30 #define ROMFLAG_WIDE 0x40000000 /* 16-bit ROM; may need byte swapping */ 31 #define ROMFLAG_SWAP 0x20000000 /* 16-bit ROM with bytes in wrong order */ 32 #define ROMFLAG_NIBBLE 0x10000000 /* Nibble-wide ROM image */ 33 #define ROMFLAG_QUAD 0x08000000 /* 32-bit data arranged as 4 interleaved 8-bit roms */ 34 #define ROMFLAG_OPTIONAL 0x04000000 /* Optional ROM, not needed for basic emulation */ 35 36 /* start of table */ 37 #define ROM_START(name) static struct RomModule rom_##name[] = { 38 /* start of memory region */ 39 #define ROM_REGION(length,type) { 0, length, 0, type }, 40 41 enum { 42 REGION_INVALID = 0x80, 43 REGION_CPU1, 44 REGION_CPU2, 45 REGION_CPU3, 46 REGION_CPU4, 47 REGION_CPU5, 48 REGION_CPU6, 49 REGION_CPU7, 50 REGION_CPU8, 51 REGION_GFX1, 52 REGION_GFX2, 53 REGION_GFX3, 54 REGION_GFX4, 55 REGION_GFX5, 56 REGION_GFX6, 57 REGION_GFX7, 58 REGION_GFX8, 59 REGION_PROMS, 60 REGION_SOUND1, 61 REGION_SOUND2, 62 REGION_SOUND3, 63 REGION_SOUND4, 64 REGION_SOUND5, 65 REGION_SOUND6, 66 REGION_SOUND7, 67 REGION_SOUND8, 68 REGION_USER1, 69 REGION_USER2, 70 REGION_USER3, 71 REGION_USER4, 72 REGION_USER5, 73 REGION_USER6, 74 REGION_USER7, 75 REGION_USER8, 76 REGION_MAX 77 }; 78 79 #define REGIONFLAG_MASK 0xf8000000 80 #define REGIONFLAG_DISPOSE 0x80000000 /* Dispose of this region when done */ 81 #define REGIONFLAG_SOUNDONLY 0x40000000 /* load only if sound emulation is turned on */ 82 83 84 #define BADCRC( crc ) (~(crc)) 85 86 /* ROM to load */ 87 #define ROM_LOAD(name,offset,length,crc) { name, offset, length, crc }, 88 89 /* continue loading the previous ROM to a new address */ 90 #define ROM_CONTINUE(offset,length) { 0, offset, length, 0 }, 91 /* restart loading the previous ROM to a new address */ 92 #define ROM_RELOAD(offset,length) { (char *)-1, offset, length, 0 }, 93 94 /* These are for nibble-wide ROMs, can be used with code or data */ 95 #define ROM_LOAD_NIB_LOW(name,offset,length,crc) { name, offset, (length) | ROMFLAG_NIBBLE, crc }, 96 #define ROM_LOAD_NIB_HIGH(name,offset,length,crc) { name, offset, (length) | ROMFLAG_NIBBLE | ROMFLAG_ALTERNATE, crc }, 97 #define ROM_RELOAD_NIB_LOW(offset,length) { (char *)-1, offset, (length) | ROMFLAG_NIBBLE, 0 }, 98 #define ROM_RELOAD_NIB_HIGH(offset,length) { (char *)-1, offset, (length) | ROMFLAG_NIBBLE | ROMFLAG_ALTERNATE, 0 }, 99 100 /* The following ones are for code ONLY - don't use for graphics data!!! */ 101 /* load the ROM at even/odd addresses. Useful with 16 bit games */ 102 #define ROM_LOAD_EVEN(name,offset,length,crc) { name, (offset) & ~1, (length) | ROMFLAG_ALTERNATE, crc }, 103 #define ROM_RELOAD_EVEN(offset,length) { (char *)-1, (offset) & ~1, (length) | ROMFLAG_ALTERNATE, 0 }, 104 #define ROM_LOAD_ODD(name,offset,length,crc) { name, (offset) | 1, (length) | ROMFLAG_ALTERNATE, crc }, 105 #define ROM_RELOAD_ODD(offset,length) { (char *)-1, (offset) | 1, (length) | ROMFLAG_ALTERNATE, 0 }, 106 /* load the ROM at even/odd addresses. Useful with 16 bit games */ 107 #define ROM_LOAD_WIDE(name,offset,length,crc) { name, offset, (length) | ROMFLAG_WIDE, crc }, 108 #define ROM_RELOAD_WIDE(offset,length) { (char *)-1, offset, (length) | ROMFLAG_WIDE, 0 }, 109 #define ROM_LOAD_WIDE_SWAP(name,offset,length,crc) { name, offset, (length) | ROMFLAG_WIDE | ROMFLAG_SWAP, crc }, 110 #define ROM_RELOAD_WIDE_SWAP(offset,length) { (char *)-1, offset, (length) | ROMFLAG_WIDE | ROMFLAG_SWAP, 0 }, 111 /* Data is split between 4 roms, always use this in groups of 4! */ 112 #define ROM_LOAD_QUAD(name,offset,length,crc) { name, offset, length | ROMFLAG_QUAD, crc }, 113 114 #define ROM_LOAD_OPTIONAL(name,offset,length,crc) { name, offset, length | ROMFLAG_OPTIONAL, crc }, 115 116 #ifdef MSB_FIRST 117 #define ROM_LOAD_V20_EVEN ROM_LOAD_ODD 118 #define ROM_RELOAD_V20_EVEN ROM_RELOAD_ODD 119 #define ROM_LOAD_V20_ODD ROM_LOAD_EVEN 120 #define ROM_RELOAD_V20_ODD ROM_RELOAD_EVEN 121 #define ROM_LOAD_V20_WIDE ROM_LOAD_WIDE_SWAP 122 #else 123 #define ROM_LOAD_V20_EVEN ROM_LOAD_EVEN 124 #define ROM_RELOAD_V20_EVEN ROM_RELOAD_EVEN 125 #define ROM_LOAD_V20_ODD ROM_LOAD_ODD 126 #define ROM_RELOAD_V20_ODD ROM_RELOAD_ODD 127 #define ROM_LOAD_V20_WIDE ROM_LOAD_WIDE 128 #endif 129 130 /* Use THESE ones for graphics data */ 131 #ifdef MSB_FIRST 132 #define ROM_LOAD_GFX_EVEN ROM_LOAD_EVEN 133 #define ROM_LOAD_GFX_ODD ROM_LOAD_ODD 134 #define ROM_LOAD_GFX_SWAP ROM_LOAD_WIDE_SWAP 135 #else 136 #define ROM_LOAD_GFX_EVEN ROM_LOAD_ODD 137 #define ROM_LOAD_GFX_ODD ROM_LOAD_EVEN 138 #define ROM_LOAD_GFX_SWAP ROM_LOAD_WIDE 139 #endif 140 141 /* end of table */ 142 #define ROM_END { 0, 0, 0, 0 } }; 143 144 145 146 struct GameSample 147 { 148 int length; 149 int smpfreq; 150 int resolution; 151 signed char data[1]; /* extendable */ 152 }; 153 154 struct GameSamples 155 { 156 int total; /* total number of samples */ 157 struct GameSample *sample[1]; /* extendable */ 158 }; 159 160 161 162 163 void showdisclaimer(void); 164 165 /* LBO 042898 - added coin counters */ 166 #define COIN_COUNTERS 4 /* total # of coin counters */ 167 WRITE_HANDLER( coin_counter_w ); 168 WRITE_HANDLER( coin_lockout_w ); 169 WRITE_HANDLER( coin_lockout_global_w ); /* Locks out all coin inputs */ 170 171 172 int readroms(void); 173 void printromlist(const struct RomModule *romp,const char *name); 174 175 /* helper function that reads samples from disk - this can be used by other */ 176 /* drivers as well (e.g. a sound chip emulator needing drum samples) */ 177 struct GameSamples *readsamples(const char **samplenames,const char *name); 178 void freesamples(struct GameSamples *samples); 179 180 /* return a pointer to the specified memory region - num can be either an absolute */ 181 /* number, or one of the REGION_XXX identifiers defined above */ 182 unsigned char *memory_region(int num); 183 int memory_region_length(int num); 184 /* allocate a new memory region - num can be either an absolute */ 185 /* number, or one of the REGION_XXX identifiers defined above */ 186 int new_memory_region(int num, int length); 187 void free_memory_region(int num); 188 189 extern data_t flip_screen_x, flip_screen_y; 190 191 WRITE_HANDLER( flip_screen_w ); 192 WRITE_HANDLER( flip_screen_x_w ); 193 WRITE_HANDLER( flip_screen_y_w ); 194 #define flip_screen flip_screen_x 195 196 /* sets a variable and schedules a full screen refresh if it changed */ 197 void set_vh_global_attribute( data_t *addr, data_t data ); 198 199 /* next time vh_screenrefresh is called, full_refresh will be true, 200 thus requesting a redraw of the entire screen */ 201 void schedule_full_refresh(void); 202 203 void set_visible_area(int min_x,int max_x,int min_y,int max_y); 204 205 struct osd_bitmap *bitmap_alloc(int width,int height); 206 struct osd_bitmap *bitmap_alloc_depth(int width,int height,int depth); 207 void bitmap_free(struct osd_bitmap *bitmap); 208 209 void save_screen_snapshot_as(void *fp,struct osd_bitmap *bitmap); 210 void save_screen_snapshot(struct osd_bitmap *bitmap); 211 212 #endif 213