From f43747b22195bab83f159e61e764d649443d619a Mon Sep 17 00:00:00 2001 From: Aaron Giles Date: Tue, 15 Dec 2009 02:37:46 +0000 Subject: [PATCH] Some misc cleanups: - added warning messages for auto_malloc, timer, and save state allocations done after init time. These should be fixed when detected, as I would eventually like to disallow them entirely. - changed state registration functions to pass through the caller's file and line number to facilitate fixing the above warnings - converted Taito F3 sound to a separate machine driver which is imported into games that use it - converted the balsente driver to driver_data structure - converted harddriv timers into devices - fixed crash in cps2 games due to not configuring the qsound bank - cleaned up initialization in taito_l to allocate at init time instead of reset time --- src/emu/machine/intelfsh.c | 2 +- src/emu/memory.c | 2 +- src/emu/restrack.c | 8 + src/emu/sound/cdp1864.c | 2 +- src/emu/state.c | 8 +- src/emu/state.h | 12 +- src/emu/video/generic.c | 2 +- src/lib/util/pool.c | 4 +- src/mame/audio/taito_en.c | 37 +- src/mame/audio/taito_en.h | 20 +- src/mame/drivers/balsente.c | 67 ++-- src/mame/drivers/cps2.c | 2 + src/mame/drivers/galastrm.c | 12 +- src/mame/drivers/groundfx.c | 11 +- src/mame/drivers/gunbustr.c | 13 +- src/mame/drivers/harddriv.c | 2 + src/mame/drivers/superchs.c | 12 +- src/mame/drivers/taito_f3.c | 7 +- src/mame/drivers/taito_l.c | 33 +- src/mame/drivers/taitojc.c | 8 +- src/mame/drivers/undrfire.c | 18 +- src/mame/includes/balsente.h | 99 ++++- src/mame/includes/harddriv.h | 3 +- src/mame/machine/balsente.c | 676 +++++++++++++++++------------------ src/mame/machine/harddriv.c | 19 +- src/mame/video/atarimo.c | 4 +- src/mame/video/balsente.c | 63 ++-- src/mame/video/psx.c | 2 +- 28 files changed, 584 insertions(+), 564 deletions(-) diff --git a/src/emu/machine/intelfsh.c b/src/emu/machine/intelfsh.c index b56cb7ef4d8..0c985c52f3c 100644 --- a/src/emu/machine/intelfsh.c +++ b/src/emu/machine/intelfsh.c @@ -151,7 +151,7 @@ void intelflash_init(running_machine *machine, int chip, int type, void *data) state_save_register_item( machine, "intelfsh", NULL, chip, c->status ); state_save_register_item( machine, "intelfsh", NULL, chip, c->flash_mode ); state_save_register_item( machine, "intelfsh", NULL, chip, c->flash_master_lock ); - state_save_register_memory( machine, "intelfsh", NULL, chip, "flash_memory", c->flash_memory, c->bits/8, c->size / (c->bits/8) ); + state_save_register_memory( machine, "intelfsh", NULL, chip, "flash_memory", c->flash_memory, c->bits/8, c->size / (c->bits/8), __FILE__, __LINE__ ); } UINT32 intelflash_read(int chip, UINT32 address) diff --git a/src/emu/memory.c b/src/emu/memory.c index dc0be581550..969d219e9f5 100644 --- a/src/emu/memory.c +++ b/src/emu/memory.c @@ -3443,7 +3443,7 @@ static void *block_allocate(const address_space *space, offs_t bytestart, offs_t char name[256]; sprintf(name, "%08x-%08x", bytestart, byteend); - state_save_register_memory(space->machine, "memory", space->cpu->tag, space->spacenum, name, memory, bytes_per_element, (UINT32)(byteend - bytestart + 1) / bytes_per_element); + state_save_register_memory(space->machine, "memory", space->cpu->tag, space->spacenum, name, memory, bytes_per_element, (UINT32)(byteend - bytestart + 1) / bytes_per_element, __FILE__, __LINE__); } /* fill in the tracking block */ diff --git a/src/emu/restrack.c b/src/emu/restrack.c index 72e3704497f..e8002be3f99 100644 --- a/src/emu/restrack.c +++ b/src/emu/restrack.c @@ -13,6 +13,7 @@ #include "pool.h" #include "timer.h" #include "state.h" +#include "mame.h" @@ -188,6 +189,7 @@ static object_pool *current_pool(void) void *restrack_register_object(object_type type, void *ptr, size_t size, const char *file, int line) { +if (resource_tracking_tag == 2) mame_printf_warning("restrack_register_object(%p,%d) called within reset scope by %s, line %d\n", ptr, size, file, line); return pool_object_add_file_line(current_pool(), type, ptr, size, file, line); } @@ -200,6 +202,7 @@ void *restrack_register_object(object_type type, void *ptr, size_t size, const c void *auto_malloc_file_line(running_machine *machine, size_t size, const char *file, int line) { void *result = pool_malloc_file_line(current_pool(), size, file, line); +if (resource_tracking_tag == 2) mame_printf_warning("auto_malloc(%d) called within reset scope by %s, line %d\n", size, file, line); #ifdef MAME_DEBUG rand_memory(result, size); #endif @@ -215,6 +218,7 @@ void *auto_malloc_file_line(running_machine *machine, size_t size, const char *f void *auto_realloc_file_line(running_machine *machine, void *ptr, size_t size, const char *file, int line) { object_pool *pool = current_pool(); +if (resource_tracking_tag == 2) mame_printf_warning("auto_realloc(%p, %d) called within reset scope by %s, line %d\n", ptr, size, file, line); if (ptr != NULL) { int tag = resource_tracking_tag; @@ -238,6 +242,7 @@ void *auto_realloc_file_line(running_machine *machine, void *ptr, size_t size, c char *auto_strdup_file_line(running_machine *machine, const char *str, const char *file, int line) { +if (resource_tracking_tag == 2) mame_printf_warning("auto_strdup() called within reset scope by %s, line %d\n", file, line); return pool_strdup_file_line(current_pool(), str, file, line); } @@ -249,6 +254,7 @@ char *auto_strdup_file_line(running_machine *machine, const char *str, const cha char *auto_strdup_allow_null_file_line(running_machine *machine, const char *str, const char *file, int line) { +if (resource_tracking_tag == 2) mame_printf_warning("auto_strdup_allow_null() called within reset scope by %s, line %d\n", file, line); return (str != NULL) ? auto_strdup_file_line(machine, str, file, line) : NULL; } @@ -260,6 +266,7 @@ char *auto_strdup_allow_null_file_line(running_machine *machine, const char *str astring *auto_astring_alloc_file_line(running_machine *machine, const char *file, int line) { +if (resource_tracking_tag == 2) mame_printf_warning("auto_astring_alloc() called within reset scope by %s, line %d\n", file, line); return (astring *)restrack_register_object(OBJTYPE_ASTRING, astring_alloc(), 0, file, line); } @@ -271,6 +278,7 @@ astring *auto_astring_alloc_file_line(running_machine *machine, const char *file bitmap_t *auto_bitmap_alloc_file_line(running_machine *machine, int width, int height, bitmap_format format, const char *file, int line) { +if (resource_tracking_tag == 2) mame_printf_warning("auto_bitmap_alloc(%d,%d) called within reset scope by %s, line %d\n", width, height, file, line); return (bitmap_t *)restrack_register_object(OBJTYPE_BITMAP, bitmap_alloc(width, height, format), width * height, file, line); } diff --git a/src/emu/sound/cdp1864.c b/src/emu/sound/cdp1864.c index 5b28ceca3b7..d833e9a2ac4 100644 --- a/src/emu/sound/cdp1864.c +++ b/src/emu/sound/cdp1864.c @@ -468,7 +468,7 @@ static DEVICE_START( cdp1864 ) state_save_register_device_item(device, 0, cdp1864->signal); state_save_register_device_item(device, 0, cdp1864->incr); - state_save_register_bitmap(device->machine, "cdp1864", device->tag, 0, "cdp1864->bitmap", cdp1864->bitmap); + state_save_register_device_item_bitmap(device, 0, cdp1864->bitmap); } /*------------------------------------------------- diff --git a/src/emu/state.c b/src/emu/state.c index 1c408a4e0b8..ad6a87a64b8 100644 --- a/src/emu/state.c +++ b/src/emu/state.c @@ -223,7 +223,7 @@ int state_save_registration_allowed(running_machine *machine) array of data in memory -------------------------------------------------*/ -void state_save_register_memory(running_machine *machine, const char *module, const char *tag, UINT32 index, const char *name, void *val, UINT32 valsize, UINT32 valcount) +void state_save_register_memory(running_machine *machine, const char *module, const char *tag, UINT32 index, const char *name, void *val, UINT32 valsize, UINT32 valcount, const char *file, int line) { state_private *global = machine->state_data; state_entry **entryptr, *next; @@ -272,7 +272,7 @@ void state_save_register_memory(running_machine *machine, const char *module, co (*entryptr)->name = totalname; (*entryptr)->typesize = valsize; (*entryptr)->typecount = valcount; - restrack_register_object(OBJTYPE_STATEREG, *entryptr, 0, __FILE__, __LINE__); + restrack_register_object(OBJTYPE_STATEREG, *entryptr, 0, file, line); } @@ -281,9 +281,9 @@ void state_save_register_memory(running_machine *machine, const char *module, co bitmap to be saved -------------------------------------------------*/ -void state_save_register_bitmap(running_machine *machine, const char *module, const char *tag, UINT32 index, const char *name, bitmap_t *val) +void state_save_register_bitmap(running_machine *machine, const char *module, const char *tag, UINT32 index, const char *name, bitmap_t *val, const char *file, int line) { - state_save_register_memory(machine, module, tag, index, name, val->base, val->bpp / 8, val->rowpixels * val->height); + state_save_register_memory(machine, module, tag, index, name, val->base, val->bpp / 8, val->rowpixels * val->height, file, line); } diff --git a/src/emu/state.h b/src/emu/state.h index 3b1df79fce7..06a846a2a9d 100644 --- a/src/emu/state.h +++ b/src/emu/state.h @@ -67,7 +67,7 @@ typedef enum _state_save_error state_save_error; #define state_save_register_generic(_mach, _mod, _tag, _index, _name, _val, _valsize, _count) \ do { \ assert_always(IS_VALID_SAVE_TYPE(_valsize), "Invalid data type supplied for state saving."); \ - state_save_register_memory(_mach, _mod, _tag, _index, _name, _val, sizeof(_valsize), _count); \ + state_save_register_memory(_mach, _mod, _tag, _index, _name, _val, sizeof(_valsize), _count, __FILE__, __LINE__); \ } while (0) @@ -85,7 +85,7 @@ do { \ state_save_register_item_pointer(_mach, _mod, _tag, _index, _val[0], sizeof(_val)/sizeof(_val[0][0])) #define state_save_register_item_bitmap(_mach, _mod, _tag, _index, _val) \ - state_save_register_bitmap(_mach, _mod, _tag, _index, #_val, _val) + state_save_register_bitmap(_mach, _mod, _tag, _index, #_val, _val, __FILE__, __LINE__) @@ -103,7 +103,7 @@ do { \ state_save_register_item_pointer((_dev)->machine, device_get_name(_dev), (_dev)->tag, _index, _val[0], sizeof(_val)/sizeof(_val[0][0])) #define state_save_register_device_item_bitmap(_dev, _index, _val) \ - state_save_register_bitmap((_dev)->machine, device_get_name(_dev), (_dev)->tag, _index, #_val, _val) + state_save_register_bitmap((_dev)->machine, device_get_name(_dev), (_dev)->tag, _index, #_val, _val, __FILE__, __LINE__) @@ -121,7 +121,7 @@ do { \ state_save_register_item_2d_array(_mach, "globals", NULL, 0, _val) #define state_save_register_global_bitmap(_mach, _val) \ - state_save_register_bitmap(_mach, "globals", NULL, 0, #_val, _val) + state_save_register_bitmap(_mach, "globals", NULL, 0, #_val, _val, __FILE__, __LINE__) @@ -149,10 +149,10 @@ void state_save_allow_registration(running_machine *machine, int allowed); int state_save_registration_allowed(running_machine *machine); /* register an array of data in memory */ -void state_save_register_memory(running_machine *machine, const char *module, const char *tag, UINT32 index, const char *name, void *val, UINT32 valsize, UINT32 valcount); +void state_save_register_memory(running_machine *machine, const char *module, const char *tag, UINT32 index, const char *name, void *val, UINT32 valsize, UINT32 valcount, const char *file, int line); /* register a bitmap to be saved */ -void state_save_register_bitmap(running_machine *machine, const char *module, const char *tag, UINT32 index, const char *name, bitmap_t *val); +void state_save_register_bitmap(running_machine *machine, const char *module, const char *tag, UINT32 index, const char *name, bitmap_t *val, const char *file, int line); diff --git a/src/emu/video/generic.c b/src/emu/video/generic.c index 8993215fc76..1c4dc959cad 100644 --- a/src/emu/video/generic.c +++ b/src/emu/video/generic.c @@ -255,7 +255,7 @@ VIDEO_START( generic_bitmapped ) machine->generic.tmpbitmap = video_screen_auto_bitmap_alloc(machine->primary_screen); /* ensure the contents of the bitmap are saved */ - state_save_register_bitmap(machine, "video", NULL, 0, "tmpbitmap", machine->generic.tmpbitmap); + state_save_register_global_bitmap(machine, machine->generic.tmpbitmap); } diff --git a/src/lib/util/pool.c b/src/lib/util/pool.c index 6cc3d33b054..892e1760887 100644 --- a/src/lib/util/pool.c +++ b/src/lib/util/pool.c @@ -138,8 +138,8 @@ INLINE int hash_object(void *object) /*------------------------------------------------- - hash_object - compute the hash for a given - object + get_object_type - return the type entry for + a given object type -------------------------------------------------*/ INLINE objtype_entry *get_object_type(object_pool *pool, object_type type) diff --git a/src/mame/audio/taito_en.c b/src/mame/audio/taito_en.c index 501b1071335..18da5101241 100644 --- a/src/mame/audio/taito_en.c +++ b/src/mame/audio/taito_en.c @@ -7,7 +7,6 @@ static int counter,vector_reg,imr_status; static UINT16 es5510_dsp_ram[0x200]; static UINT32 es5510_gpr[0xc0]; static UINT32 es5510_gpr_latch; -static emu_timer *timer_68681=NULL; static int timer_mode,m68681_imr; //static int es_tmp=1; @@ -17,6 +16,8 @@ static int timer_mode,m68681_imr; enum { TIMER_SINGLESHOT, TIMER_PULSE }; + + static READ16_HANDLER(f3_68000_share_r) { if ((offset&3)==0) return (f3_shared_ram[offset/4]&0xff000000)>>16; @@ -68,22 +69,17 @@ static WRITE16_HANDLER( f3_volume_w ) /* Channels 0, 1, 2, 3 - Unused */ } -static TIMER_CALLBACK( taito_en_timer_callback ) +static TIMER_DEVICE_CALLBACK( taito_en_timer_callback ) { /* Only cause IRQ if the mask is set to allow it */ if (m68681_imr & 0x08) { - cpu_set_input_line_vector(cputag_get_cpu(machine, "audiocpu"), 6, vector_reg); - cputag_set_input_line(machine, "audiocpu", 6, ASSERT_LINE); + cpu_set_input_line_vector(cputag_get_cpu(timer->machine, "audiocpu"), 6, vector_reg); + cputag_set_input_line(timer->machine, "audiocpu", 6, ASSERT_LINE); imr_status |= 0x08; } } -void f3_68681_reset(running_machine *machine) -{ - timer_68681 = timer_alloc(machine, taito_en_timer_callback, NULL); -} - static READ16_HANDLER(f3_68681_r) { if (offset == 0x05) @@ -123,7 +119,7 @@ static WRITE16_HANDLER(f3_68681_w) case 3: logerror("Counter: X1/Clk - divided by 16, counter is %04x, so interrupt every %d cycles\n",counter,(M68000_CLOCK/M68681_CLOCK)*counter*16); timer_mode=TIMER_SINGLESHOT; - timer_adjust_oneshot(timer_68681, cpu_clocks_to_attotime(space->cpu, (M68000_CLOCK/M68681_CLOCK)*counter*16), 0); + timer_device_adjust_oneshot(devtag_get_device(space->machine, "timer_68681"), cpu_clocks_to_attotime(space->cpu, (M68000_CLOCK/M68681_CLOCK)*counter*16), 0); break; case 4: logerror("Timer: Unimplemented external IP2\n"); @@ -134,7 +130,7 @@ static WRITE16_HANDLER(f3_68681_w) case 6: logerror("Timer: X1/Clk, counter is %04x, so interrupt every %d cycles\n",counter,(M68000_CLOCK/M68681_CLOCK)*counter); timer_mode=TIMER_PULSE; - timer_adjust_periodic(timer_68681, cpu_clocks_to_attotime(space->cpu, (M68000_CLOCK/M68681_CLOCK)*counter), 0, cpu_clocks_to_attotime(space->cpu, (M68000_CLOCK/M68681_CLOCK)*counter)); + timer_device_adjust_periodic(devtag_get_device(space->machine, "timer_68681"), cpu_clocks_to_attotime(space->cpu, (M68000_CLOCK/M68681_CLOCK)*counter), 0, cpu_clocks_to_attotime(space->cpu, (M68000_CLOCK/M68681_CLOCK)*counter)); break; case 7: logerror("Timer: Unimplemented X1/Clk - divided by 16\n"); @@ -247,7 +243,7 @@ ADDRESS_MAP_START( f3_sound_map, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0xff0000, 0xffffff) AM_RAM AM_SHARE("share1") // mirror ADDRESS_MAP_END -void taito_f3_soundsystem_reset(running_machine *machine) +static SOUND_RESET( taito_f3_soundsystem_reset ) { /* Sound cpu program loads to 0xc00000 so we use a bank */ UINT16 *ROM = (UINT16 *)memory_region(machine, "audiocpu"); @@ -265,9 +261,24 @@ void taito_f3_soundsystem_reset(running_machine *machine) //cputag_set_input_line(machine, "audiocpu", INPUT_LINE_RESET, ASSERT_LINE); } -const es5505_interface es5505_taito_f3_config = +static const es5505_interface es5505_taito_f3_config = { "ensoniq.0", /* Bank 0: Unused by F3 games? */ "ensoniq.0", /* Bank 1: All games seem to use this */ NULL /* irq */ }; + +MACHINE_DRIVER_START( taito_f3_sound ) + MDRV_TIMER_ADD("timer_68681", taito_en_timer_callback) + + MDRV_SOUND_RESET( taito_f3_soundsystem_reset ) + + MDRV_CPU_ADD("audiocpu", M68000, 16000000) + MDRV_CPU_PROGRAM_MAP(f3_sound_map) + + MDRV_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker") + MDRV_SOUND_ADD("ensoniq", ES5505, 30476100/2) + MDRV_SOUND_CONFIG(es5505_taito_f3_config) + MDRV_SOUND_ROUTE(0, "lspeaker", 1.0) + MDRV_SOUND_ROUTE(1, "rspeaker", 1.0) +MACHINE_DRIVER_END diff --git a/src/mame/audio/taito_en.h b/src/mame/audio/taito_en.h index b74f33580f0..655b6052afb 100644 --- a/src/mame/audio/taito_en.h +++ b/src/mame/audio/taito_en.h @@ -1,22 +1,4 @@ #include "cpu/m68000/m68000.h" #include "sound/es5506.h" -void f3_68681_reset(running_machine *machine); - -void taito_f3_soundsystem_reset(running_machine *machine); - -#define TAITO_F3_SOUND_SYSTEM_CPU(freq) \ - MDRV_CPU_ADD("audiocpu", M68000, freq) \ - MDRV_CPU_PROGRAM_MAP(f3_sound_map) \ - - -#define TAITO_F3_SOUND_SYSTEM_ES5505(freq) \ - MDRV_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker") \ - MDRV_SOUND_ADD("ensoniq", ES5505, freq) \ - MDRV_SOUND_CONFIG(es5505_taito_f3_config) \ - MDRV_SOUND_ROUTE(0, "lspeaker", 1.0) \ - MDRV_SOUND_ROUTE(1, "rspeaker", 1.0) \ - -ADDRESS_MAP_EXTERN(f3_sound_map, 16); - -extern const es5505_interface es5505_taito_f3_config; +MACHINE_DRIVER_EXTERN( taito_f3_sound ); diff --git a/src/mame/drivers/balsente.c b/src/mame/drivers/balsente.c index a5b457f1315..ada201a6153 100644 --- a/src/mame/drivers/balsente.c +++ b/src/mame/drivers/balsente.c @@ -300,8 +300,8 @@ ADDRESS_MAP_END /* CPU 1 read addresses */ static ADDRESS_MAP_START( shrike68k_map, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0x000000, 0x003fff) AM_ROM - AM_RANGE(0x010000, 0x01001f) AM_RAM AM_BASE(&shrike_io) - AM_RANGE(0x018000, 0x018fff) AM_RAM AM_BASE(&shrike_shared) + AM_RANGE(0x010000, 0x01001f) AM_RAM AM_BASE_MEMBER(balsente_state, shrike_io) + AM_RANGE(0x018000, 0x018fff) AM_RAM AM_BASE_MEMBER(balsente_state, shrike_shared) ADDRESS_MAP_END @@ -1191,6 +1191,7 @@ static const cem3394_interface cem_interface = *************************************/ static MACHINE_DRIVER_START( balsente ) + MDRV_DRIVER_DATA(balsente_state) /* basic machine hardware */ MDRV_CPU_ADD("maincpu", M6809, 5000000/4) @@ -1203,8 +1204,14 @@ static MACHINE_DRIVER_START( balsente ) MDRV_QUANTUM_TIME(HZ(600)) + MDRV_MACHINE_START(balsente) MDRV_MACHINE_RESET(balsente) MDRV_NVRAM_HANDLER(generic_0fill) + + MDRV_TIMER_ADD("scan_timer", balsente_interrupt_timer) + MDRV_TIMER_ADD("8253_0_timer", balsente_clock_counter_0_ff) + MDRV_TIMER_ADD("8253_1_timer", balsente_counter_callback) + MDRV_TIMER_ADD("8253_2_timer", balsente_counter_callback) /* video hardware */ MDRV_VIDEO_ATTRIBUTES(VIDEO_UPDATE_BEFORE_VBLANK) @@ -2047,67 +2054,71 @@ static void expand_roms(running_machine *machine, UINT8 cd_rom_mask) } } -static DRIVER_INIT( sentetst ) { expand_roms(machine, EXPAND_ALL); balsente_shooter = 0; /* noanalog */ } -static DRIVER_INIT( cshift ) { expand_roms(machine, EXPAND_ALL); balsente_shooter = 0; /* noanalog */ } -static DRIVER_INIT( gghost ) { expand_roms(machine, EXPAND_ALL); balsente_shooter = 0; balsente_adc_shift = 1; } -static DRIVER_INIT( hattrick ) { expand_roms(machine, EXPAND_ALL); balsente_shooter = 0; /* noanalog */ } -static DRIVER_INIT( otwalls ) { expand_roms(machine, EXPAND_ALL); balsente_shooter = 0; balsente_adc_shift = 0; } -static DRIVER_INIT( snakepit ) { expand_roms(machine, EXPAND_ALL); balsente_shooter = 0; balsente_adc_shift = 1; } -static DRIVER_INIT( snakjack ) { expand_roms(machine, EXPAND_ALL); balsente_shooter = 0; balsente_adc_shift = 1; } -static DRIVER_INIT( stocker ) { expand_roms(machine, EXPAND_ALL); balsente_shooter = 0; balsente_adc_shift = 0; } -static DRIVER_INIT( triviag1 ) { expand_roms(machine, EXPAND_ALL); balsente_shooter = 0; /* noanalog */ } +INLINE void config_shooter_adc(running_machine *machine, UINT8 shooter, UINT8 adc_shift) +{ + balsente_state *state = (balsente_state *)machine->driver_data; + state->shooter = shooter; + state->adc_shift = adc_shift; +} + +static DRIVER_INIT( sentetst ) { expand_roms(machine, EXPAND_ALL); config_shooter_adc(machine, FALSE, 0 /* noanalog */); } +static DRIVER_INIT( cshift ) { expand_roms(machine, EXPAND_ALL); config_shooter_adc(machine, FALSE, 0 /* noanalog */); } +static DRIVER_INIT( gghost ) { expand_roms(machine, EXPAND_ALL); config_shooter_adc(machine, FALSE, 1); } +static DRIVER_INIT( hattrick ) { expand_roms(machine, EXPAND_ALL); config_shooter_adc(machine, FALSE, 0 /* noanalog */); } +static DRIVER_INIT( otwalls ) { expand_roms(machine, EXPAND_ALL); config_shooter_adc(machine, FALSE, 0); } +static DRIVER_INIT( snakepit ) { expand_roms(machine, EXPAND_ALL); config_shooter_adc(machine, FALSE, 1); } +static DRIVER_INIT( snakjack ) { expand_roms(machine, EXPAND_ALL); config_shooter_adc(machine, FALSE, 1); } +static DRIVER_INIT( stocker ) { expand_roms(machine, EXPAND_ALL); config_shooter_adc(machine, FALSE, 0); } +static DRIVER_INIT( triviag1 ) { expand_roms(machine, EXPAND_ALL); config_shooter_adc(machine, FALSE, 0 /* noanalog */); } static DRIVER_INIT( triviag2 ) { UINT8 *rom = memory_region(machine, "maincpu"); memcpy(&rom[0x20000], &rom[0x28000], 0x4000); memcpy(&rom[0x24000], &rom[0x28000], 0x4000); - expand_roms(machine, EXPAND_NONE); balsente_shooter = 0; /* noanalog */ + expand_roms(machine, EXPAND_NONE); config_shooter_adc(machine, FALSE, 0 /* noanalog */); } -static DRIVER_INIT( triviaes ) -{ - expand_roms(machine, EXPAND_NONE | SWAP_HALVES); balsente_shooter = 0; /* noanalog */ -} -static DRIVER_INIT( gimeabrk ) { expand_roms(machine, EXPAND_ALL); balsente_shooter = 0; balsente_adc_shift = 1; } -static DRIVER_INIT( minigolf ) { expand_roms(machine, EXPAND_NONE); balsente_shooter = 0; balsente_adc_shift = 2; } -static DRIVER_INIT( minigol2 ) { expand_roms(machine, 0x0c); balsente_shooter = 0; balsente_adc_shift = 2; } -static DRIVER_INIT( toggle ) { expand_roms(machine, EXPAND_ALL); balsente_shooter = 0; /* noanalog */ } +static DRIVER_INIT( triviaes ) { expand_roms(machine, EXPAND_NONE | SWAP_HALVES); config_shooter_adc(machine, FALSE, 0 /* noanalog */); } +static DRIVER_INIT( gimeabrk ) { expand_roms(machine, EXPAND_ALL); config_shooter_adc(machine, FALSE, 1); } +static DRIVER_INIT( minigolf ) { expand_roms(machine, EXPAND_NONE); config_shooter_adc(machine, FALSE, 2); } +static DRIVER_INIT( minigol2 ) { expand_roms(machine, 0x0c); config_shooter_adc(machine, FALSE, 2); } +static DRIVER_INIT( toggle ) { expand_roms(machine, EXPAND_ALL); config_shooter_adc(machine, FALSE, 0 /* noanalog */); } static DRIVER_INIT( nametune ) { const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); memory_install_write8_handler(space, 0x9f00, 0x9f00, 0, 0, balsente_rombank2_select_w); - expand_roms(machine, EXPAND_NONE | SWAP_HALVES); balsente_shooter = 0; /* noanalog */ + expand_roms(machine, EXPAND_NONE | SWAP_HALVES); config_shooter_adc(machine, FALSE, 0 /* noanalog */); } static DRIVER_INIT( nstocker ) { const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); memory_install_write8_handler(space, 0x9f00, 0x9f00, 0, 0, balsente_rombank2_select_w); - expand_roms(machine, EXPAND_NONE | SWAP_HALVES); balsente_shooter = 1; balsente_adc_shift = 1; + expand_roms(machine, EXPAND_NONE | SWAP_HALVES); config_shooter_adc(machine, TRUE, 1); } static DRIVER_INIT( sfootbal ) { const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); memory_install_write8_handler(space, 0x9f00, 0x9f00, 0, 0, balsente_rombank2_select_w); - expand_roms(machine, EXPAND_ALL | SWAP_HALVES); balsente_shooter = 0; balsente_adc_shift = 0; + expand_roms(machine, EXPAND_ALL | SWAP_HALVES); config_shooter_adc(machine, FALSE, 0); } static DRIVER_INIT( spiker ) { const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); memory_install_readwrite8_handler(space, 0x9f80, 0x9f8f, 0, 0, spiker_expand_r, spiker_expand_w); memory_install_write8_handler(space, 0x9f00, 0x9f00, 0, 0, balsente_rombank2_select_w); - expand_roms(machine, EXPAND_ALL | SWAP_HALVES); balsente_shooter = 0; balsente_adc_shift = 1; + expand_roms(machine, EXPAND_ALL | SWAP_HALVES); config_shooter_adc(machine, FALSE, 1); } static DRIVER_INIT( stompin ) { const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); memory_install_write8_handler(space, 0x9f00, 0x9f00, 0, 0, balsente_rombank2_select_w); - expand_roms(machine, 0x0c | SWAP_HALVES); balsente_shooter = 0; balsente_adc_shift = 32; + expand_roms(machine, 0x0c | SWAP_HALVES); config_shooter_adc(machine, FALSE, 32); } -static DRIVER_INIT( rescraid ) { expand_roms(machine, EXPAND_NONE); balsente_shooter = 0; /* noanalog */ } +static DRIVER_INIT( rescraid ) { expand_roms(machine, EXPAND_NONE); config_shooter_adc(machine, FALSE, 0 /* noanalog */); } static DRIVER_INIT( grudge ) { const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); memory_install_read8_handler(space, 0x9400, 0x9400, 0, 0, grudge_steering_r); - expand_roms(machine, EXPAND_NONE); balsente_shooter = 0; + expand_roms(machine, EXPAND_NONE); config_shooter_adc(machine, FALSE, 0); } static DRIVER_INIT( shrike ) { @@ -2116,7 +2127,7 @@ static DRIVER_INIT( shrike ) memory_install_write8_handler(space, 0x9e01, 0x9e01, 0, 0, shrike_sprite_select_w ); memory_install_readwrite16_handler(cputag_get_address_space(machine, "68k", ADDRESS_SPACE_PROGRAM), 0x10000, 0x1001f, 0, 0, shrike_io_68k_r, shrike_io_68k_w); - expand_roms(machine, EXPAND_ALL); balsente_shooter = 0; balsente_adc_shift = 32; + expand_roms(machine, EXPAND_ALL); config_shooter_adc(machine, FALSE, 32); } diff --git a/src/mame/drivers/cps2.c b/src/mame/drivers/cps2.c index 5bb318b148f..d87702a8d69 100644 --- a/src/mame/drivers/cps2.c +++ b/src/mame/drivers/cps2.c @@ -1191,6 +1191,8 @@ static MACHINE_START( cps2 ) state->audiocpu = devtag_get_device(machine, "audiocpu"); state_save_register_global(machine, state->scancount); + + memory_configure_bank(machine, "bank1", 0, (QSOUND_SIZE - 0x10000) / 0x4000, memory_region(machine, "audiocpu") + 0x10000, 0x4000); } diff --git a/src/mame/drivers/galastrm.c b/src/mame/drivers/galastrm.c index ff590c91ab4..0ab43e5b220 100644 --- a/src/mame/drivers/galastrm.c +++ b/src/mame/drivers/galastrm.c @@ -283,13 +283,6 @@ GFXDECODE_END MACHINE DRIVERS ***********************************************************/ -static MACHINE_RESET( galastrm ) -{ - taito_f3_soundsystem_reset(machine); - f3_68681_reset(machine); -} - - static const UINT8 default_eeprom[128]={ 0x45,0x58,0x00,0x00,0xff,0xff,0x00,0x00,0x00,0x28,0x00,0x01,0x00,0x00,0x00,0xfa, 0x00,0xec,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, @@ -333,9 +326,6 @@ static MACHINE_DRIVER_START( galastrm ) MDRV_CPU_PROGRAM_MAP(galastrm_map) MDRV_CPU_VBLANK_INT("screen", galastrm_interrupt) /* VBL */ - TAITO_F3_SOUND_SYSTEM_CPU(16000000) - - MDRV_MACHINE_RESET(galastrm) MDRV_NVRAM_HANDLER(galastrm) /* video hardware */ @@ -353,7 +343,7 @@ static MACHINE_DRIVER_START( galastrm ) MDRV_VIDEO_UPDATE(galastrm) /* sound hardware */ - TAITO_F3_SOUND_SYSTEM_ES5505(30476100/2) + MDRV_IMPORT_FROM(taito_f3_sound) MACHINE_DRIVER_END /***************************************************************************/ diff --git a/src/mame/drivers/groundfx.c b/src/mame/drivers/groundfx.c index ac817bf9d7e..27651283e4a 100644 --- a/src/mame/drivers/groundfx.c +++ b/src/mame/drivers/groundfx.c @@ -353,12 +353,6 @@ GFXDECODE_END MACHINE DRIVERS ***********************************************************/ -static MACHINE_RESET( groundfx ) -{ - taito_f3_soundsystem_reset(machine); - f3_68681_reset(machine); -} - static INTERRUPT_GEN( groundfx_interrupt ) { frame_counter^=1; @@ -372,9 +366,6 @@ static MACHINE_DRIVER_START( groundfx ) MDRV_CPU_PROGRAM_MAP(groundfx_map) MDRV_CPU_VBLANK_INT("screen", groundfx_interrupt) - TAITO_F3_SOUND_SYSTEM_CPU(16000000) - - MDRV_MACHINE_RESET(groundfx) // MDRV_NVRAM_HANDLER(groundfx) MDRV_EEPROM_ADD("eeprom", groundfx_eeprom_interface, 128, default_eeprom) @@ -393,7 +384,7 @@ static MACHINE_DRIVER_START( groundfx ) MDRV_VIDEO_UPDATE(groundfx) /* sound hardware */ - TAITO_F3_SOUND_SYSTEM_ES5505(30476100/2) + MDRV_IMPORT_FROM(taito_f3_sound) MACHINE_DRIVER_END /*************************************************************************** diff --git a/src/mame/drivers/gunbustr.c b/src/mame/drivers/gunbustr.c index 0dbd33d6d40..2248de3f19c 100644 --- a/src/mame/drivers/gunbustr.c +++ b/src/mame/drivers/gunbustr.c @@ -302,14 +302,6 @@ GFXDECODE_END MACHINE DRIVERS ***********************************************************/ -static MACHINE_RESET( gunbustr ) -{ - taito_f3_soundsystem_reset(machine); - - f3_68681_reset(machine); -} - - static const UINT8 default_eeprom[128]={ 0x00,0x01,0x00,0x85,0x00,0xfd,0x00,0xff,0x00,0x67,0x00,0x02,0x00,0x00,0x00,0x7b, 0x00,0xff,0x00,0xff,0x00,0x78,0x00,0x03,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, @@ -352,9 +344,6 @@ static MACHINE_DRIVER_START( gunbustr ) MDRV_CPU_PROGRAM_MAP(gunbustr_map) MDRV_CPU_VBLANK_INT("screen", gunbustr_interrupt) /* VBL */ - TAITO_F3_SOUND_SYSTEM_CPU(16000000) - - MDRV_MACHINE_RESET(gunbustr) MDRV_NVRAM_HANDLER(gunbustr) /* video hardware */ @@ -372,7 +361,7 @@ static MACHINE_DRIVER_START( gunbustr ) MDRV_VIDEO_UPDATE(gunbustr) /* sound hardware */ - TAITO_F3_SOUND_SYSTEM_ES5505(30476100/2) + MDRV_IMPORT_FROM(taito_f3_sound) MACHINE_DRIVER_END /***************************************************************************/ diff --git a/src/mame/drivers/harddriv.c b/src/mame/drivers/harddriv.c index 83d2d7cf9e6..bfa4cea3204 100644 --- a/src/mame/drivers/harddriv.c +++ b/src/mame/drivers/harddriv.c @@ -1021,6 +1021,8 @@ static MACHINE_DRIVER_START( driver_nomsp ) MDRV_MACHINE_START(harddriv) MDRV_MACHINE_RESET(harddriv) MDRV_NVRAM_HANDLER(atarigen) + + MDRV_TIMER_ADD("duart_timer", hd68k_duart_callback) /* video hardware */ MDRV_VIDEO_ATTRIBUTES(VIDEO_UPDATE_BEFORE_VBLANK) diff --git a/src/mame/drivers/superchs.c b/src/mame/drivers/superchs.c index 1ccba7cd59d..643375664ca 100644 --- a/src/mame/drivers/superchs.c +++ b/src/mame/drivers/superchs.c @@ -348,13 +348,6 @@ GFXDECODE_END MACHINE DRIVERS ***********************************************************/ -static MACHINE_RESET( superchs ) -{ - taito_f3_soundsystem_reset(machine); - - f3_68681_reset(machine); -} - static const eeprom_interface superchs_eeprom_interface = { 6, /* address bits */ @@ -399,15 +392,12 @@ static MACHINE_DRIVER_START( superchs ) MDRV_CPU_PROGRAM_MAP(superchs_map) MDRV_CPU_VBLANK_INT("screen", irq2_line_hold)/* VBL */ - TAITO_F3_SOUND_SYSTEM_CPU(16000000) - MDRV_CPU_ADD("sub", M68000, 16000000) /* 16 MHz */ MDRV_CPU_PROGRAM_MAP(superchs_cpub_map) MDRV_CPU_VBLANK_INT("screen", irq4_line_hold)/* VBL */ MDRV_QUANTUM_TIME(HZ(480)) /* CPU slices - Need to interleave Cpu's 1 & 3 */ - MDRV_MACHINE_RESET(superchs) MDRV_NVRAM_HANDLER(superchs) /* video hardware */ @@ -425,7 +415,7 @@ static MACHINE_DRIVER_START( superchs ) MDRV_VIDEO_UPDATE(superchs) /* sound hardware */ - TAITO_F3_SOUND_SYSTEM_ES5505(30476100/2) + MDRV_IMPORT_FROM(taito_f3_sound) MACHINE_DRIVER_END /***************************************************************************/ diff --git a/src/mame/drivers/taito_f3.c b/src/mame/drivers/taito_f3.c index dfd0f297bc7..807ed6688ba 100644 --- a/src/mame/drivers/taito_f3.c +++ b/src/mame/drivers/taito_f3.c @@ -369,10 +369,7 @@ static INTERRUPT_GEN( f3_interrupt2 ) static MACHINE_RESET( f3 ) { - taito_f3_soundsystem_reset(machine); cputag_set_input_line(machine, "audiocpu", INPUT_LINE_RESET, ASSERT_LINE); - - f3_68681_reset(machine); } @@ -399,8 +396,6 @@ static MACHINE_DRIVER_START( f3 ) MDRV_CPU_PROGRAM_MAP(f3_map) MDRV_CPU_VBLANK_INT("screen", f3_interrupt2) - TAITO_F3_SOUND_SYSTEM_CPU(16000000) - MDRV_MACHINE_START(f3) MDRV_MACHINE_RESET(f3) @@ -422,7 +417,7 @@ static MACHINE_DRIVER_START( f3 ) MDRV_VIDEO_UPDATE(f3) /* sound hardware */ - TAITO_F3_SOUND_SYSTEM_ES5505(30476100/2) + MDRV_IMPORT_FROM(taito_f3_sound) MACHINE_DRIVER_END /* These games reprogram the video output registers to display different scanlines, diff --git a/src/mame/drivers/taito_l.c b/src/mame/drivers/taito_l.c index b28a6469f8c..1334165e439 100644 --- a/src/mame/drivers/taito_l.c +++ b/src/mame/drivers/taito_l.c @@ -136,13 +136,16 @@ logerror("%s:Large palette ? %03x\n", cpuexec_describe_context(machine), addr); } } -static void machine_init(running_machine *machine) +static MACHINE_START( taito_l ) { - int i; - taitol_rambanks = auto_alloc_array(machine, UINT8, 0x1000*12); palette_ram = auto_alloc_array(machine, UINT8, 0x1000); empty_ram = auto_alloc_array(machine, UINT8, 0x1000); +} + +static void machine_reset(running_machine *machine) +{ + int i; for(i=0;i<3;i++) irq_adr_table[i] = 0; @@ -178,7 +181,7 @@ static void machine_init(running_machine *machine) static MACHINE_RESET( fhawk ) { - machine_init(machine); + machine_reset(machine); porte0_tag = NULL; porte1_tag = NULL; portf0_tag = NULL; @@ -187,7 +190,7 @@ static MACHINE_RESET( fhawk ) static MACHINE_RESET( raimais ) { - machine_init(machine); + machine_reset(machine); porte0_tag = NULL; porte1_tag = NULL; portf0_tag = NULL; @@ -196,7 +199,7 @@ static MACHINE_RESET( raimais ) static MACHINE_RESET( champwr ) { - machine_init(machine); + machine_reset(machine); porte0_tag = NULL; porte1_tag = NULL; portf0_tag = NULL; @@ -206,7 +209,7 @@ static MACHINE_RESET( champwr ) static MACHINE_RESET( kurikint ) { - machine_init(machine); + machine_reset(machine); porte0_tag = NULL; porte1_tag = NULL; portf0_tag = NULL; @@ -215,7 +218,7 @@ static MACHINE_RESET( kurikint ) static MACHINE_RESET( evilston ) { - machine_init(machine); + machine_reset(machine); porte0_tag = NULL; porte1_tag = NULL; portf0_tag = NULL; @@ -224,7 +227,7 @@ static MACHINE_RESET( evilston ) static MACHINE_RESET( puzznic ) { - machine_init(machine); + machine_reset(machine); porte0_tag = "DSWA"; porte1_tag = "DSWB"; portf0_tag = "IN0"; @@ -233,7 +236,7 @@ static MACHINE_RESET( puzznic ) static MACHINE_RESET( plotting ) { - machine_init(machine); + machine_reset(machine); porte0_tag = "DSWA"; porte1_tag = "DSWB"; portf0_tag = "IN0"; @@ -242,7 +245,7 @@ static MACHINE_RESET( plotting ) static MACHINE_RESET( palamed ) { - machine_init(machine); + machine_reset(machine); porte0_tag = "DSWA"; porte1_tag = NULL; portf0_tag = "DSWB"; @@ -251,7 +254,7 @@ static MACHINE_RESET( palamed ) static MACHINE_RESET( cachat ) { - machine_init(machine); + machine_reset(machine); porte0_tag = "DSWA"; porte1_tag = NULL; portf0_tag = "DSWB"; @@ -260,7 +263,7 @@ static MACHINE_RESET( cachat ) static MACHINE_RESET( horshoes ) { - machine_init(machine); + machine_reset(machine); porte0_tag = "DSWA"; porte1_tag = "DSWB"; portf0_tag = "IN0"; @@ -1965,6 +1968,7 @@ static MACHINE_DRIVER_START( fhawk ) MDRV_QUANTUM_TIME(HZ(6000)) + MDRV_MACHINE_START(taito_l) MDRV_MACHINE_RESET(fhawk) /* video hardware */ @@ -2061,6 +2065,7 @@ static MACHINE_DRIVER_START( kurikint ) MDRV_QUANTUM_TIME(HZ(6000)) + MDRV_MACHINE_START(taito_l) MDRV_MACHINE_RESET(kurikint) /* video hardware */ @@ -2106,6 +2111,7 @@ static MACHINE_DRIVER_START( plotting ) MDRV_CPU_PROGRAM_MAP(plotting_map) MDRV_CPU_VBLANK_INT_HACK(vbl_interrupt,3) + MDRV_MACHINE_START(taito_l) MDRV_MACHINE_RESET(plotting) /* video hardware */ @@ -2201,6 +2207,7 @@ static MACHINE_DRIVER_START( evilston ) MDRV_QUANTUM_TIME(HZ(6000)) + MDRV_MACHINE_START(taito_l) MDRV_MACHINE_RESET(evilston) /* video hardware */ diff --git a/src/mame/drivers/taitojc.c b/src/mame/drivers/taitojc.c index da319225aef..a09b95a4b65 100644 --- a/src/mame/drivers/taitojc.c +++ b/src/mame/drivers/taitojc.c @@ -1298,10 +1298,6 @@ static MACHINE_RESET( taitojc ) memset(projection_data, 0, sizeof(projection_data)); memset(intersection_data, 0, sizeof(intersection_data)); - taito_f3_soundsystem_reset(machine); - - f3_68681_reset(machine); - // hold the TMS in reset until we have code cputag_set_input_line(machine, "dsp", INPUT_LINE_RESET, ASSERT_LINE); } @@ -1329,8 +1325,6 @@ static MACHINE_DRIVER_START( taitojc ) MDRV_CPU_VBLANK_INT("screen", taitojc_vblank) MDRV_CPU_PERIODIC_INT(taitojc_int6, 1000) - TAITO_F3_SOUND_SYSTEM_CPU(16000000) - MDRV_CPU_ADD("sub", MC68HC11, 4000000) //MC68HC11M0 MDRV_CPU_PROGRAM_MAP(hc11_pgm_map) MDRV_CPU_IO_MAP(hc11_io_map) @@ -1358,7 +1352,7 @@ static MACHINE_DRIVER_START( taitojc ) MDRV_VIDEO_UPDATE(taitojc) /* sound hardware */ - TAITO_F3_SOUND_SYSTEM_ES5505(30476100/2) + MDRV_IMPORT_FROM(taito_f3_sound) MACHINE_DRIVER_END static DRIVER_INIT( taitojc ) diff --git a/src/mame/drivers/undrfire.c b/src/mame/drivers/undrfire.c index 1414f501203..e9c9546f93d 100644 --- a/src/mame/drivers/undrfire.c +++ b/src/mame/drivers/undrfire.c @@ -717,14 +717,6 @@ GFXDECODE_END MACHINE DRIVERS ***********************************************************/ -static MACHINE_RESET( undrfire ) -{ - taito_f3_soundsystem_reset(machine); - - f3_68681_reset(machine); -} - - static INTERRUPT_GEN( undrfire_interrupt ) { frame_counter^=1; @@ -738,9 +730,6 @@ static MACHINE_DRIVER_START( undrfire ) MDRV_CPU_PROGRAM_MAP(undrfire_map) MDRV_CPU_VBLANK_INT("screen", undrfire_interrupt) - TAITO_F3_SOUND_SYSTEM_CPU(16000000) - - MDRV_MACHINE_RESET(undrfire) MDRV_NVRAM_HANDLER(undrfire) /* video hardware */ @@ -758,7 +747,7 @@ static MACHINE_DRIVER_START( undrfire ) MDRV_VIDEO_UPDATE(undrfire) /* sound hardware */ - TAITO_F3_SOUND_SYSTEM_ES5505(30476100/2) + MDRV_IMPORT_FROM(taito_f3_sound) MACHINE_DRIVER_END @@ -769,15 +758,12 @@ static MACHINE_DRIVER_START( cbombers ) MDRV_CPU_PROGRAM_MAP(cbombers_cpua_map) MDRV_CPU_VBLANK_INT("screen", irq4_line_hold) - TAITO_F3_SOUND_SYSTEM_CPU(16000000) - MDRV_CPU_ADD("sub", M68000, 16000000) /* 16 MHz */ MDRV_CPU_PROGRAM_MAP(cbombers_cpub_map) MDRV_CPU_VBLANK_INT("screen", irq4_line_hold) MDRV_QUANTUM_TIME(HZ(480)) /* CPU slices - Need to interleave Cpu's 1 & 3 */ - MDRV_MACHINE_RESET(undrfire) MDRV_NVRAM_HANDLER(undrfire) /* video hardware */ @@ -796,7 +782,7 @@ static MACHINE_DRIVER_START( cbombers ) MDRV_VIDEO_UPDATE(cbombers) /* sound hardware */ - TAITO_F3_SOUND_SYSTEM_ES5505(30476100/2) + MDRV_IMPORT_FROM(taito_f3_sound) MACHINE_DRIVER_END diff --git a/src/mame/includes/balsente.h b/src/mame/includes/balsente.h index 0a3969a0d7a..18605ae5c28 100644 --- a/src/mame/includes/balsente.h +++ b/src/mame/includes/balsente.h @@ -18,13 +18,99 @@ #define BALSENTE_VBSTART (0x100) +#define POLY17_BITS 17 +#define POLY17_SIZE ((1 << POLY17_BITS) - 1) +#define POLY17_SHL 7 +#define POLY17_SHR 10 +#define POLY17_ADD 0x18000 + + +typedef struct _balsente_state balsente_state; +struct _balsente_state +{ + /* global data */ + UINT8 shooter; + UINT8 shooter_x; + UINT8 shooter_y; + UINT8 adc_shift; + UINT16 *shrike_shared; + UINT16 *shrike_io; + + /* 8253 counter state */ + struct + { + const device_config *timer; + UINT8 timer_active; + INT32 initial; + INT32 count; + UINT8 gate; + UINT8 out; + UINT8 mode; + UINT8 readbyte; + UINT8 writebyte; + } counter[3]; + + const device_config *scanline_timer; + + /* manually clocked counter 0 states */ + UINT8 counter_control; + UINT8 counter_0_ff; + const device_config *counter_0_timer; + UINT8 counter_0_timer_active; + + /* random number generator states */ + UINT8 poly17[POLY17_SIZE + 1]; + UINT8 rand17[POLY17_SIZE + 1]; + + /* ADC I/O states */ + INT8 analog_input_data[4]; + UINT8 adc_value; + + /* CEM3394 DAC control states */ + UINT16 dac_value; + UINT8 dac_register; + UINT8 chip_select; + + /* main CPU 6850 states */ + UINT8 m6850_status; + UINT8 m6850_control; + UINT8 m6850_input; + UINT8 m6850_output; + UINT8 m6850_data_ready; + + /* sound CPU 6850 states */ + UINT8 m6850_sound_status; + UINT8 m6850_sound_control; + UINT8 m6850_sound_input; + UINT8 m6850_sound_output; + + /* noise generator states */ + UINT32 noise_position[6]; + const device_config *cem_device[6]; + + /* game-specific states */ + UINT8 nstocker_bits; + UINT8 spiker_expand_color; + UINT8 spiker_expand_bgcolor; + UINT8 spiker_expand_bits; + UINT8 grudge_steering_result; + UINT8 grudge_last_steering[3]; + + /* video data */ + UINT8 videoram[256 * 256]; + UINT8 *sprite_data; + UINT32 sprite_mask; + UINT8 *sprite_bank[2]; + + UINT8 palettebank_vis; +}; + + /*----------- defined in machine/balsente.c -----------*/ -extern UINT8 balsente_shooter; -extern UINT8 balsente_adc_shift; -extern UINT16 *shrike_shared; -extern UINT16 *shrike_io; +TIMER_DEVICE_CALLBACK( balsente_interrupt_timer ); +MACHINE_START( balsente ); MACHINE_RESET( balsente ); void balsente_noise_gen(const device_config *device, int count, short *buffer); @@ -47,9 +133,13 @@ INTERRUPT_GEN( balsente_update_analog_inputs ); READ8_HANDLER( balsente_adc_data_r ); WRITE8_HANDLER( balsente_adc_select_w ); +TIMER_DEVICE_CALLBACK( balsente_counter_callback ); + READ8_HANDLER( balsente_counter_8253_r ); WRITE8_HANDLER( balsente_counter_8253_w ); +TIMER_DEVICE_CALLBACK( balsente_clock_counter_0_ff ); + READ8_HANDLER( balsente_counter_state_r ); WRITE8_HANDLER( balsente_counter_control_w ); @@ -68,6 +158,7 @@ WRITE8_HANDLER( shrike_shared_6809_w ); READ16_HANDLER( shrike_io_68k_r ); WRITE16_HANDLER( shrike_io_68k_w ); + /*----------- defined in video/balsente.c -----------*/ VIDEO_START( balsente ); diff --git a/src/mame/includes/harddriv.h b/src/mame/includes/harddriv.h index 723cefebf4a..a8f7f16378c 100644 --- a/src/mame/includes/harddriv.h +++ b/src/mame/includes/harddriv.h @@ -77,7 +77,7 @@ struct _harddriv_state UINT8 duart_read_data[16]; UINT8 duart_write_data[16]; UINT8 duart_output_port; - emu_timer * duart_timer; + const device_config * duart_timer; UINT8 last_gsp_shiftreg; @@ -193,6 +193,7 @@ WRITE16_HANDLER( hdc68k_wheel_edge_reset_w ); READ16_HANDLER( hd68k_zram_r ); WRITE16_HANDLER( hd68k_zram_w ); +TIMER_DEVICE_CALLBACK( hd68k_duart_callback ); READ16_HANDLER( hd68k_duart_r ); WRITE16_HANDLER( hd68k_duart_w ); diff --git a/src/mame/machine/balsente.c b/src/mame/machine/balsente.c index 0ea3df10d94..3f9ab065c82 100644 --- a/src/mame/machine/balsente.c +++ b/src/mame/machine/balsente.c @@ -18,80 +18,8 @@ /* local prototypes */ static void poly17_init(running_machine *machine); static void counter_set_out(running_machine *machine, int which, int gate); -static TIMER_CALLBACK( counter_callback ); -static TIMER_CALLBACK( clock_counter_0_ff ); static void update_grudge_steering(running_machine *machine); -/* global data */ -UINT8 balsente_shooter; -static UINT8 balsente_shooter_x; -static UINT8 balsente_shooter_y; -UINT8 balsente_adc_shift; -UINT16 *shrike_shared; -UINT16 *shrike_io; - - -/* 8253 counter state */ -struct counter_state -{ - emu_timer *timer; - UINT8 timer_active; - INT32 initial; - INT32 count; - UINT8 gate; - UINT8 out; - UINT8 mode; - UINT8 readbyte; - UINT8 writebyte; -}; - -static struct counter_state counter[3]; - -static emu_timer *scanline_timer; - -/* manually clocked counter 0 states */ -static UINT8 counter_control; -static UINT8 counter_0_ff; -static emu_timer *counter_0_timer; -static UINT8 counter_0_timer_active; - -/* random number generator states */ -static UINT8 *poly17 = NULL; -static UINT8 *rand17 = NULL; - -/* ADC I/O states */ -static INT8 analog_input_data[4]; -static UINT8 adc_value; - -/* CEM3394 DAC control states */ -static UINT16 dac_value; -static UINT8 dac_register; -static UINT8 chip_select; - -/* main CPU 6850 states */ -static UINT8 m6850_status; -static UINT8 m6850_control; -static UINT8 m6850_input; -static UINT8 m6850_output; -static UINT8 m6850_data_ready; - -/* sound CPU 6850 states */ -static UINT8 m6850_sound_status; -static UINT8 m6850_sound_control; -static UINT8 m6850_sound_input; -static UINT8 m6850_sound_output; - -/* noise generator states */ -static UINT32 noise_position[6]; -static const device_config *cem_device[6]; - -/* game-specific states */ -static UINT8 nstocker_bits; -static UINT8 spiker_expand_color; -static UINT8 spiker_expand_bgcolor; -static UINT8 spiker_expand_bits; -static UINT8 grudge_steering_result; -static UINT8 grudge_last_steering[3]; @@ -107,90 +35,144 @@ static TIMER_CALLBACK( irq_off ) } -static TIMER_CALLBACK( interrupt_timer ) +TIMER_DEVICE_CALLBACK( balsente_interrupt_timer ) { + balsente_state *state = (balsente_state *)timer->machine->driver_data; + /* next interrupt after scanline 256 is scanline 64 */ if (param == 256) - timer_adjust_oneshot(scanline_timer, video_screen_get_time_until_pos(machine->primary_screen, 64, 0), 64); + timer_device_adjust_oneshot(state->scanline_timer, video_screen_get_time_until_pos(timer->machine->primary_screen, 64, 0), 64); else - timer_adjust_oneshot(scanline_timer, video_screen_get_time_until_pos(machine->primary_screen, param + 64, 0), param + 64); + timer_device_adjust_oneshot(state->scanline_timer, video_screen_get_time_until_pos(timer->machine->primary_screen, param + 64, 0), param + 64); /* IRQ starts on scanline 0, 64, 128, etc. */ - cputag_set_input_line(machine, "maincpu", M6809_IRQ_LINE, ASSERT_LINE); + cputag_set_input_line(timer->machine, "maincpu", M6809_IRQ_LINE, ASSERT_LINE); /* it will turn off on the next HBLANK */ - timer_set(machine, video_screen_get_time_until_pos(machine->primary_screen, param, BALSENTE_HBSTART), NULL, 0, irq_off); + timer_set(timer->machine, video_screen_get_time_until_pos(timer->machine->primary_screen, param, BALSENTE_HBSTART), NULL, 0, irq_off); /* if this is Grudge Match, update the steering */ - if (grudge_steering_result & 0x80) - update_grudge_steering(machine); + if (state->grudge_steering_result & 0x80) + update_grudge_steering(timer->machine); /* if we're a shooter, we do a little more work */ - if (balsente_shooter) + if (state->shooter) { UINT8 tempx, tempy; /* we latch the beam values on the first interrupt after VBLANK */ - if (param == 64 && balsente_shooter) + if (param == 64) { - balsente_shooter_x = input_port_read(machine, "FAKEX"); - balsente_shooter_y = input_port_read(machine, "FAKEY"); + state->shooter_x = input_port_read(timer->machine, "FAKEX"); + state->shooter_y = input_port_read(timer->machine, "FAKEY"); } /* which bits get returned depends on which scanline we're at */ - tempx = balsente_shooter_x << ((param - 64) / 64); - tempy = balsente_shooter_y << ((param - 64) / 64); - nstocker_bits = ((tempx >> 4) & 0x08) | ((tempx >> 1) & 0x04) | - ((tempy >> 6) & 0x02) | ((tempy >> 3) & 0x01); + tempx = state->shooter_x << ((param - 64) / 64); + tempy = state->shooter_y << ((param - 64) / 64); + state->nstocker_bits = ((tempx >> 4) & 0x08) | ((tempx >> 1) & 0x04) | + ((tempy >> 6) & 0x02) | ((tempy >> 3) & 0x01); } } +MACHINE_START( balsente ) +{ + balsente_state *state = (balsente_state *)machine->driver_data; + int i; + + /* create the polynomial tables */ + poly17_init(machine); + + /* register for saving */ + for (i = 0; i < 3; i++) + { + state_save_register_item(machine, "8253counter", NULL, i, state->counter[i].timer_active); + state_save_register_item(machine, "8253counter", NULL, i, state->counter[i].initial); + state_save_register_item(machine, "8253counter", NULL, i, state->counter[i].count); + state_save_register_item(machine, "8253counter", NULL, i, state->counter[i].gate); + state_save_register_item(machine, "8253counter", NULL, i, state->counter[i].out); + state_save_register_item(machine, "8253counter", NULL, i, state->counter[i].mode); + state_save_register_item(machine, "8253counter", NULL, i, state->counter[i].readbyte); + state_save_register_item(machine, "8253counter", NULL, i, state->counter[i].writebyte); + } + + state_save_register_global(machine, state->counter_control); + state_save_register_global(machine, state->counter_0_ff); + state_save_register_global(machine, state->counter_0_timer_active); + + state_save_register_global_array(machine, state->analog_input_data); + state_save_register_global(machine, state->adc_value); + + state_save_register_global(machine, state->dac_value); + state_save_register_global(machine, state->dac_register); + state_save_register_global(machine, state->chip_select); + + state_save_register_global(machine, state->m6850_status); + state_save_register_global(machine, state->m6850_control); + state_save_register_global(machine, state->m6850_input); + state_save_register_global(machine, state->m6850_output); + state_save_register_global(machine, state->m6850_data_ready); + + state_save_register_global(machine, state->m6850_sound_status); + state_save_register_global(machine, state->m6850_sound_control); + state_save_register_global(machine, state->m6850_sound_input); + state_save_register_global(machine, state->m6850_sound_output); + + state_save_register_global_array(machine, state->noise_position); + + state_save_register_global(machine, state->nstocker_bits); + state_save_register_global(machine, state->spiker_expand_color); + state_save_register_global(machine, state->spiker_expand_bgcolor); + state_save_register_global(machine, state->spiker_expand_bits); + state_save_register_global(machine, state->grudge_steering_result); + state_save_register_global_array(machine, state->grudge_last_steering); +} + + MACHINE_RESET( balsente ) { const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); + balsente_state *state = (balsente_state *)machine->driver_data; int numbanks, i; - /* create the polynomial tables */ - poly17_init(machine); - /* reset counters; counter 2's gate is tied high */ - memset(counter, 0, sizeof(counter)); - counter[1].timer = timer_alloc(machine, counter_callback, NULL); - counter[2].timer = timer_alloc(machine, counter_callback, NULL); - counter[2].gate = 1; + memset(state->counter, 0, sizeof(state->counter)); + state->counter[1].timer = devtag_get_device(machine, "8253_1_timer"); + state->counter[2].timer = devtag_get_device(machine, "8253_2_timer"); + state->counter[2].gate = 1; /* reset the manual counter 0 clock */ - counter_control = 0x00; - counter_0_ff = 0; - counter_0_timer = timer_alloc(machine, clock_counter_0_ff, NULL); - counter_0_timer_active = 0; + state->counter_0_timer = devtag_get_device(machine, "8253_0_timer"); + state->counter_control = 0x00; + state->counter_0_ff = 0; + state->counter_0_timer_active = 0; /* reset the ADC states */ - adc_value = 0; + state->adc_value = 0; /* reset the CEM3394 I/O states */ - dac_value = 0; - dac_register = 0; - chip_select = 0x3f; + state->dac_value = 0; + state->dac_register = 0; + state->chip_select = 0x3f; /* reset game-specific states */ - grudge_steering_result = 0; + state->grudge_steering_result = 0; /* reset the 6850 chips */ balsente_m6850_w(space, 0, 3); balsente_m6850_sound_w(space, 0, 3); /* reset the noise generator */ - memset(noise_position, 0, sizeof(noise_position)); + memset(state->noise_position, 0, sizeof(state->noise_position)); /* find the CEM devices */ - for (i = 0; i < ARRAY_LENGTH(cem_device); i++) + for (i = 0; i < ARRAY_LENGTH(state->cem_device); i++) { char name[10]; sprintf(name, "cem%d", i+1); - cem_device[i] = devtag_get_device(machine, name); - assert(cem_device[i] != NULL); + state->cem_device[i] = devtag_get_device(machine, name); + assert(state->cem_device[i] != NULL); } /* point the banks to bank 0 */ @@ -202,52 +184,8 @@ MACHINE_RESET( balsente ) device_reset(cputag_get_cpu(machine, "maincpu")); /* start a timer to generate interrupts */ - scanline_timer = timer_alloc(machine, interrupt_timer, NULL); - timer_adjust_oneshot(scanline_timer, video_screen_get_time_until_pos(machine->primary_screen, 0, 0), 0); - - /* register for saving */ - for (i = 0; i < 3; i++) - { - state_save_register_item(machine, "8253counter", NULL, i, counter[i].timer_active); - state_save_register_item(machine, "8253counter", NULL, i, counter[i].initial); - state_save_register_item(machine, "8253counter", NULL, i, counter[i].count); - state_save_register_item(machine, "8253counter", NULL, i, counter[i].gate); - state_save_register_item(machine, "8253counter", NULL, i, counter[i].out); - state_save_register_item(machine, "8253counter", NULL, i, counter[i].mode); - state_save_register_item(machine, "8253counter", NULL, i, counter[i].readbyte); - state_save_register_item(machine, "8253counter", NULL, i, counter[i].writebyte); - } - - state_save_register_global(machine, counter_control); - state_save_register_global(machine, counter_0_ff); - state_save_register_global(machine, counter_0_timer_active); - - state_save_register_global_array(machine, analog_input_data); - state_save_register_global(machine, adc_value); - - state_save_register_global(machine, dac_value); - state_save_register_global(machine, dac_register); - state_save_register_global(machine, chip_select); - - state_save_register_global(machine, m6850_status); - state_save_register_global(machine, m6850_control); - state_save_register_global(machine, m6850_input); - state_save_register_global(machine, m6850_output); - state_save_register_global(machine, m6850_data_ready); - - state_save_register_global(machine, m6850_sound_status); - state_save_register_global(machine, m6850_sound_control); - state_save_register_global(machine, m6850_sound_input); - state_save_register_global(machine, m6850_sound_output); - - state_save_register_global_array(machine, noise_position); - - state_save_register_global(machine, nstocker_bits); - state_save_register_global(machine, spiker_expand_color); - state_save_register_global(machine, spiker_expand_bgcolor); - state_save_register_global(machine, spiker_expand_bits); - state_save_register_global(machine, grudge_steering_result); - state_save_register_global_array(machine, grudge_last_steering); + state->scanline_timer = devtag_get_device(machine, "scan_timer"); + timer_device_adjust_oneshot(state->scanline_timer, video_screen_get_time_until_pos(machine->primary_screen, 0, 0), 0); } @@ -261,20 +199,15 @@ MACHINE_RESET( balsente ) * *************************************/ -#define POLY17_BITS 17 -#define POLY17_SIZE ((1 << POLY17_BITS) - 1) -#define POLY17_SHL 7 -#define POLY17_SHR 10 -#define POLY17_ADD 0x18000 - static void poly17_init(running_machine *machine) { + balsente_state *state = (balsente_state *)machine->driver_data; UINT32 i, x = 0; UINT8 *p, *r; /* allocate memory */ - p = poly17 = auto_alloc_array(machine, UINT8, POLY17_SIZE + 1); - r = rand17 = auto_alloc_array(machine, UINT8, POLY17_SIZE + 1); + p = state->poly17; + r = state->rand17; /* generate the polynomial */ for (i = 0; i < POLY17_SIZE; i++) @@ -291,34 +224,35 @@ static void poly17_init(running_machine *machine) void balsente_noise_gen(const device_config *device, int count, short *buffer) { + balsente_state *state = (balsente_state *)device->machine->driver_data; int chip; UINT32 step, noise_counter; /* find the chip we are referring to */ - for (chip = 0; chip < ARRAY_LENGTH(cem_device); chip++) + for (chip = 0; chip < ARRAY_LENGTH(state->cem_device); chip++) { - if (device == cem_device[chip]) + if (device == state->cem_device[chip]) break; - else if (cem_device[chip] == NULL) + else if (state->cem_device[chip] == NULL) { - cem_device[chip] = device; + state->cem_device[chip] = device; break; } } - assert(chip < ARRAY_LENGTH(cem_device)); + assert(chip < ARRAY_LENGTH(state->cem_device)); /* noise generator runs at 100kHz */ step = (100000 << 14) / CEM3394_SAMPLE_RATE; - noise_counter = noise_position[chip]; + noise_counter = state->noise_position[chip]; while (count--) { - *buffer++ = poly17[(noise_counter >> 14) & POLY17_SIZE] << 12; + *buffer++ = state->poly17[(noise_counter >> 14) & POLY17_SIZE] << 12; noise_counter += step; } /* remember the noise position */ - noise_position[chip] = noise_counter; + state->noise_position[chip] = noise_counter; } @@ -337,6 +271,7 @@ WRITE8_HANDLER( balsente_random_reset_w ) READ8_HANDLER( balsente_random_num_r ) { + balsente_state *state = (balsente_state *)space->machine->driver_data; UINT32 cc; /* CPU runs at 1.25MHz, noise source at 100kHz --> multiply by 12.5 */ @@ -344,7 +279,7 @@ READ8_HANDLER( balsente_random_num_r ) /* 12.5 = 8 + 4 + 0.5 */ cc = (cc << 3) + (cc << 2) + (cc >> 1); - return rand17[cc & POLY17_SIZE]; + return state->rand17[cc & POLY17_SIZE]; } @@ -421,85 +356,86 @@ WRITE8_HANDLER( balsente_misc_output_w ) static void m6850_update_io(running_machine *machine) { + balsente_state *state = (balsente_state *)machine->driver_data; UINT8 new_state; /* sound -> main CPU communications */ - if (!(m6850_sound_status & 0x02)) + if (!(state->m6850_sound_status & 0x02)) { /* set the overrun bit if the data in the destination hasn't been read yet */ - if (m6850_status & 0x01) - m6850_status |= 0x20; + if (state->m6850_status & 0x01) + state->m6850_status |= 0x20; /* copy the sound's output to our input */ - m6850_input = m6850_sound_output; + state->m6850_input = state->m6850_sound_output; /* set the receive register full bit */ - m6850_status |= 0x01; + state->m6850_status |= 0x01; /* set the sound's trasmitter register empty bit */ - m6850_sound_status |= 0x02; + state->m6850_sound_status |= 0x02; } /* main -> sound CPU communications */ - if (m6850_data_ready) + if (state->m6850_data_ready) { /* set the overrun bit if the data in the destination hasn't been read yet */ - if (m6850_sound_status & 0x01) - m6850_sound_status |= 0x20; + if (state->m6850_sound_status & 0x01) + state->m6850_sound_status |= 0x20; /* copy the main CPU's output to our input */ - m6850_sound_input = m6850_output; + state->m6850_sound_input = state->m6850_output; /* set the receive register full bit */ - m6850_sound_status |= 0x01; + state->m6850_sound_status |= 0x01; /* set the main CPU's trasmitter register empty bit */ - m6850_status |= 0x02; - m6850_data_ready = 0; + state->m6850_status |= 0x02; + state->m6850_data_ready = 0; } /* check for reset states */ - if ((m6850_control & 3) == 3) + if ((state->m6850_control & 3) == 3) { - m6850_status = 0x02; - m6850_data_ready = 0; + state->m6850_status = 0x02; + state->m6850_data_ready = 0; } - if ((m6850_sound_control & 3) == 3) - m6850_sound_status = 0x02; + if ((state->m6850_sound_control & 3) == 3) + state->m6850_sound_status = 0x02; /* check for transmit/receive IRQs on the main CPU */ new_state = 0; - if ((m6850_control & 0x80) && (m6850_status & 0x21)) new_state = 1; - if ((m6850_control & 0x60) == 0x20 && (m6850_status & 0x02)) new_state = 1; + if ((state->m6850_control & 0x80) && (state->m6850_status & 0x21)) new_state = 1; + if ((state->m6850_control & 0x60) == 0x20 && (state->m6850_status & 0x02)) new_state = 1; /* apply the change */ - if (new_state && !(m6850_status & 0x80)) + if (new_state && !(state->m6850_status & 0x80)) { cputag_set_input_line(machine, "maincpu", M6809_FIRQ_LINE, ASSERT_LINE); - m6850_status |= 0x80; + state->m6850_status |= 0x80; } - else if (!new_state && (m6850_status & 0x80)) + else if (!new_state && (state->m6850_status & 0x80)) { cputag_set_input_line(machine, "maincpu", M6809_FIRQ_LINE, CLEAR_LINE); - m6850_status &= ~0x80; + state->m6850_status &= ~0x80; } /* check for transmit/receive IRQs on the sound CPU */ new_state = 0; - if ((m6850_sound_control & 0x80) && (m6850_sound_status & 0x21)) new_state = 1; - if ((m6850_sound_control & 0x60) == 0x20 && (m6850_sound_status & 0x02)) new_state = 1; - if (!(counter_control & 0x20)) new_state = 0; + if ((state->m6850_sound_control & 0x80) && (state->m6850_sound_status & 0x21)) new_state = 1; + if ((state->m6850_sound_control & 0x60) == 0x20 && (state->m6850_sound_status & 0x02)) new_state = 1; + if (!(state->counter_control & 0x20)) new_state = 0; /* apply the change */ - if (new_state && !(m6850_sound_status & 0x80)) + if (new_state && !(state->m6850_sound_status & 0x80)) { cputag_set_input_line(machine, "audiocpu", INPUT_LINE_NMI, ASSERT_LINE); - m6850_sound_status |= 0x80; + state->m6850_sound_status |= 0x80; } - else if (!new_state && (m6850_sound_status & 0x80)) + else if (!new_state && (state->m6850_sound_status & 0x80)) { cputag_set_input_line(machine, "audiocpu", INPUT_LINE_NMI, CLEAR_LINE); - m6850_sound_status &= ~0x80; + state->m6850_sound_status &= ~0x80; } } @@ -513,21 +449,22 @@ static void m6850_update_io(running_machine *machine) READ8_HANDLER( balsente_m6850_r ) { + balsente_state *state = (balsente_state *)space->machine->driver_data; int result; /* status register is at offset 0 */ if (offset == 0) { - result = m6850_status; + result = state->m6850_status; } /* input register is at offset 1 */ else { - result = m6850_input; + result = state->m6850_input; /* clear the overrun and receive buffer full bits */ - m6850_status &= ~0x21; + state->m6850_status &= ~0x21; m6850_update_io(space->machine); } @@ -537,17 +474,21 @@ READ8_HANDLER( balsente_m6850_r ) static TIMER_CALLBACK( m6850_data_ready_callback ) { + balsente_state *state = (balsente_state *)machine->driver_data; + /* set the output data byte and indicate that we're ready to go */ - m6850_output = param; - m6850_data_ready = 1; + state->m6850_output = param; + state->m6850_data_ready = 1; m6850_update_io(machine); } static TIMER_CALLBACK( m6850_w_callback ) { + balsente_state *state = (balsente_state *)machine->driver_data; + /* indicate that the transmit buffer is no longer empty and update the I/O state */ - m6850_status &= ~0x02; + state->m6850_status &= ~0x02; m6850_update_io(machine); /* set a timer for 500usec later to actually transmit the data */ @@ -558,10 +499,12 @@ static TIMER_CALLBACK( m6850_w_callback ) WRITE8_HANDLER( balsente_m6850_w ) { + balsente_state *state = (balsente_state *)space->machine->driver_data; + /* control register is at offset 0 */ if (offset == 0) { - m6850_control = data; + state->m6850_control = data; /* re-update since interrupt enables could have been modified */ m6850_update_io(space->machine); @@ -582,21 +525,22 @@ WRITE8_HANDLER( balsente_m6850_w ) READ8_HANDLER( balsente_m6850_sound_r ) { + balsente_state *state = (balsente_state *)space->machine->driver_data; int result; /* status register is at offset 0 */ if (offset == 0) { - result = m6850_sound_status; + result = state->m6850_sound_status; } /* input register is at offset 1 */ else { - result = m6850_sound_input; + result = state->m6850_sound_input; /* clear the overrun and receive buffer full bits */ - m6850_sound_status &= ~0x21; + state->m6850_sound_status &= ~0x21; m6850_update_io(space->machine); } @@ -606,15 +550,17 @@ READ8_HANDLER( balsente_m6850_sound_r ) WRITE8_HANDLER( balsente_m6850_sound_w ) { + balsente_state *state = (balsente_state *)space->machine->driver_data; + /* control register is at offset 0 */ if (offset == 0) - m6850_sound_control = data; + state->m6850_sound_control = data; /* output register is at offset 1 */ else { - m6850_sound_output = data; - m6850_sound_status &= ~0x02; + state->m6850_sound_output = data; + state->m6850_sound_status &= ~0x02; } /* re-update since interrupt enables could have been modified */ @@ -631,6 +577,7 @@ WRITE8_HANDLER( balsente_m6850_sound_w ) INTERRUPT_GEN( balsente_update_analog_inputs ) { + balsente_state *state = (balsente_state *)device->machine->driver_data; int i; static const char *const analog[] = { "AN0", "AN1", "AN2", "AN3" }; @@ -639,22 +586,23 @@ INTERRUPT_GEN( balsente_update_analog_inputs ) /* ports are read once a frame, just at varying intervals. To get around this, we */ /* read all the analog inputs at VBLANK time and just return the cached values. */ for (i = 0; i < 4; i++) - analog_input_data[i] = input_port_read(device->machine, analog[i]); + state->analog_input_data[i] = input_port_read(device->machine, analog[i]); } static TIMER_CALLBACK( adc_finished ) { + balsente_state *state = (balsente_state *)machine->driver_data; int which = param; /* analog controls are read in two pieces; the lower port returns the sign */ /* and the upper port returns the absolute value of the magnitude */ - int val = analog_input_data[which / 2] << balsente_adc_shift; + int val = state->analog_input_data[which / 2] << state->adc_shift; /* special case for Stompin'/Shrike Avenger */ - if (balsente_adc_shift == 32) + if (state->adc_shift == 32) { - adc_value = analog_input_data[which]; + state->adc_value = state->analog_input_data[which]; return; } @@ -669,18 +617,20 @@ static TIMER_CALLBACK( adc_finished ) /* return the sign */ if (!(which & 1)) - adc_value = (val < 0) ? 0xff : 0x00; + state->adc_value = (val < 0) ? 0xff : 0x00; /* return the magnitude */ else - adc_value = (val < 0) ? -val : val; + state->adc_value = (val < 0) ? -val : val; } READ8_HANDLER( balsente_adc_data_r ) { + balsente_state *state = (balsente_state *)space->machine->driver_data; + /* just return the last value read */ - return adc_value; + return state->adc_value; } @@ -702,38 +652,38 @@ logerror("adc_select %d\n", offset & 7); * *************************************/ -INLINE void counter_start(int which) +INLINE void counter_start(balsente_state *state, int which) { /* don't start a timer for channel 0; it is clocked manually */ if (which != 0) { /* only start a timer if we're gated and there is none already */ - if (counter[which].gate && !counter[which].timer_active) + if (state->counter[which].gate && !state->counter[which].timer_active) { - counter[which].timer_active = 1; - timer_adjust_oneshot(counter[which].timer, attotime_mul(ATTOTIME_IN_HZ(2000000), counter[which].count), which); + state->counter[which].timer_active = 1; + timer_device_adjust_oneshot(state->counter[which].timer, attotime_mul(ATTOTIME_IN_HZ(2000000), state->counter[which].count), which); } } } -INLINE void counter_stop(int which) +INLINE void counter_stop(balsente_state *state, int which) { /* only stop the timer if it exists */ - if (counter[which].timer_active) - timer_adjust_oneshot(counter[which].timer, attotime_never, 0); - counter[which].timer_active = 0; + if (state->counter[which].timer_active) + timer_device_adjust_oneshot(state->counter[which].timer, attotime_never, 0); + state->counter[which].timer_active = 0; } -INLINE void counter_update_count(int which) +INLINE void counter_update_count(balsente_state *state, int which) { /* only update if the timer is running */ - if (counter[which].timer_active) + if (state->counter[which].timer_active) { /* determine how many 2MHz cycles are remaining */ - int count = attotime_to_double(attotime_mul(timer_timeleft(counter[which].timer), 2000000)); - counter[which].count = (count < 0) ? 0 : count; + int count = attotime_to_double(attotime_mul(timer_device_timeleft(state->counter[which].timer), 2000000)); + state->counter[which].count = (count < 0) ? 0 : count; } } @@ -749,39 +699,42 @@ INLINE void counter_update_count(int which) static void counter_set_gate(running_machine *machine, int which, int gate) { - int oldgate = counter[which].gate; + balsente_state *state = (balsente_state *)machine->driver_data; + int oldgate = state->counter[which].gate; /* remember the gate state */ - counter[which].gate = gate; + state->counter[which].gate = gate; /* if the counter is being halted, update the count and remove the system timer */ if (!gate && oldgate) { - counter_update_count(which); - counter_stop(which); + counter_update_count(state, which); + counter_stop(state, which); } /* if the counter is being started, create the timer */ else if (gate && !oldgate) { /* mode 1 waits for the gate to trigger the counter */ - if (counter[which].mode == 1) + if (state->counter[which].mode == 1) { counter_set_out(machine, which, 0); /* add one to the count; technically, OUT goes low on the next clock pulse */ /* and then starts counting down; it's important that we don't count the first one */ - counter[which].count = counter[which].initial + 1; + state->counter[which].count = state->counter[which].initial + 1; } /* start the counter */ - counter_start(which); + counter_start(state, which); } } static void counter_set_out(running_machine *machine, int which, int out) { + balsente_state *state = (balsente_state *)machine->driver_data; + /* OUT on counter 2 is hooked to the /INT line on the Z80 */ if (which == 2) cputag_set_input_line(machine, "audiocpu", 0, out ? ASSERT_LINE : CLEAR_LINE); @@ -791,20 +744,22 @@ static void counter_set_out(running_machine *machine, int which, int out) counter_set_gate(machine, 1, !out); /* remember the out state */ - counter[which].out = out; + state->counter[which].out = out; } -static TIMER_CALLBACK( counter_callback ) +TIMER_DEVICE_CALLBACK( balsente_counter_callback ) { + balsente_state *state = (balsente_state *)timer->machine->driver_data; + /* reset the counter and the count */ - counter[param].timer_active = 0; - counter[param].count = 0; + state->counter[param].timer_active = 0; + state->counter[param].count = 0; /* set the state of the OUT line */ /* mode 0 and 1: when firing, transition OUT to high */ - if (counter[param].mode == 0 || counter[param].mode == 1) - counter_set_out(machine, param, 1); + if (state->counter[param].mode == 0 || state->counter[param].mode == 1) + counter_set_out(timer->machine, param, 1); /* no other modes handled currently */ } @@ -821,6 +776,7 @@ static TIMER_CALLBACK( counter_callback ) READ8_HANDLER( balsente_counter_8253_r ) { + balsente_state *state = (balsente_state *)space->machine->driver_data; int which; switch (offset & 3) @@ -832,20 +788,20 @@ READ8_HANDLER( balsente_counter_8253_r ) which = offset & 3; /* update the count */ - counter_update_count(which); + counter_update_count(state, which); /* return the LSB */ - if (counter[which].readbyte == 0) + if (state->counter[which].readbyte == 0) { - counter[which].readbyte = 1; - return counter[which].count & 0xff; + state->counter[which].readbyte = 1; + return state->counter[which].count & 0xff; } /* write the MSB and reset the counter */ else { - counter[which].readbyte = 0; - return (counter[which].count >> 8) & 0xff; + state->counter[which].readbyte = 0; + return (state->counter[which].count >> 8) & 0xff; } break; } @@ -855,6 +811,7 @@ READ8_HANDLER( balsente_counter_8253_r ) WRITE8_HANDLER( balsente_counter_8253_w ) { + balsente_state *state = (balsente_state *)space->machine->driver_data; int which; switch (offset & 3) @@ -866,36 +823,36 @@ WRITE8_HANDLER( balsente_counter_8253_w ) which = offset & 3; /* if the counter is in mode 0, a write here will reset the OUT state */ - if (counter[which].mode == 0) + if (state->counter[which].mode == 0) counter_set_out(space->machine, which, 0); /* write the LSB */ - if (counter[which].writebyte == 0) + if (state->counter[which].writebyte == 0) { - counter[which].count = (counter[which].count & 0xff00) | (data & 0x00ff); - counter[which].initial = (counter[which].initial & 0xff00) | (data & 0x00ff); - counter[which].writebyte = 1; + state->counter[which].count = (state->counter[which].count & 0xff00) | (data & 0x00ff); + state->counter[which].initial = (state->counter[which].initial & 0xff00) | (data & 0x00ff); + state->counter[which].writebyte = 1; } /* write the MSB and reset the counter */ else { - counter[which].count = (counter[which].count & 0x00ff) | ((data << 8) & 0xff00); - counter[which].initial = (counter[which].initial & 0x00ff) | ((data << 8) & 0xff00); - counter[which].writebyte = 0; + state->counter[which].count = (state->counter[which].count & 0x00ff) | ((data << 8) & 0xff00); + state->counter[which].initial = (state->counter[which].initial & 0x00ff) | ((data << 8) & 0xff00); + state->counter[which].writebyte = 0; /* treat 0 as $10000 */ - if (counter[which].count == 0) counter[which].count = counter[which].initial = 0x10000; + if (state->counter[which].count == 0) state->counter[which].count = state->counter[which].initial = 0x10000; /* remove any old timer and set a new one */ - counter_stop(which); + counter_stop(state, which); /* note that in mode 1, we have to wait for a rising edge of a gate */ - if (counter[which].mode == 0) - counter_start(which); + if (state->counter[which].mode == 0) + counter_start(state, which); /* if the counter is in mode 1, a write here will set the OUT state */ - if (counter[which].mode == 1) + if (state->counter[which].mode == 1) counter_set_out(space->machine, which, 1); } break; @@ -906,14 +863,14 @@ WRITE8_HANDLER( balsente_counter_8253_w ) if (which == 3) break; /* if the counter was in mode 0, a write here will reset the OUT state */ - if (((counter[which].mode >> 1) & 7) == 0) + if (((state->counter[which].mode >> 1) & 7) == 0) counter_set_out(space->machine, which, 0); /* set the mode */ - counter[which].mode = (data >> 1) & 7; + state->counter[which].mode = (data >> 1) & 7; /* if the counter is in mode 0, a write here will reset the OUT state */ - if (counter[which].mode == 0) + if (state->counter[which].mode == 0) counter_set_out(space->machine, which, 0); break; } @@ -927,56 +884,60 @@ WRITE8_HANDLER( balsente_counter_8253_w ) * *************************************/ -static void set_counter_0_ff(running_machine *machine, int newstate) +static void set_counter_0_ff(const device_config *timer, int newstate) { + balsente_state *state = (balsente_state *)timer->machine->driver_data; + /* the flip/flop output is inverted, so if we went high to low, that's a clock */ - if (counter_0_ff && !newstate) + if (state->counter_0_ff && !newstate) { /* only count if gated and non-zero */ - if (counter[0].count > 0 && counter[0].gate) + if (state->counter[0].count > 0 && state->counter[0].gate) { - counter[0].count--; - if (counter[0].count == 0) - counter_callback(machine, NULL, 0); + state->counter[0].count--; + if (state->counter[0].count == 0) + balsente_counter_callback(timer, NULL, 0); } } /* remember the new state */ - counter_0_ff = newstate; + state->counter_0_ff = newstate; } -static TIMER_CALLBACK( clock_counter_0_ff ) +TIMER_DEVICE_CALLBACK( balsente_clock_counter_0_ff ) { + balsente_state *state = (balsente_state *)timer->machine->driver_data; + /* clock the D value through the flip-flop */ - set_counter_0_ff(machine, (counter_control >> 3) & 1); + set_counter_0_ff(timer, (state->counter_control >> 3) & 1); } -static void update_counter_0_timer(void) +static void update_counter_0_timer(balsente_state *state) { double maxfreq = 0.0; int i; /* if there's already a timer, remove it */ - if (counter_0_timer_active) - timer_adjust_oneshot(counter_0_timer, attotime_never, 0); - counter_0_timer_active = 0; + if (state->counter_0_timer_active) + timer_device_adjust_oneshot(state->counter_0_timer, attotime_never, 0); + state->counter_0_timer_active = 0; /* find the counter with the maximum frequency */ /* this is used to calibrate the timers at startup */ for (i = 0; i < 6; i++) - if (cem3394_get_parameter(cem_device[i], CEM3394_FINAL_GAIN) < 10.0) + if (cem3394_get_parameter(state->cem_device[i], CEM3394_FINAL_GAIN) < 10.0) { double tempfreq; /* if the filter resonance is high, then they're calibrating the filter frequency */ - if (cem3394_get_parameter(cem_device[i], CEM3394_FILTER_RESONANCE) > 0.9) - tempfreq = cem3394_get_parameter(cem_device[i], CEM3394_FILTER_FREQENCY); + if (cem3394_get_parameter(state->cem_device[i], CEM3394_FILTER_RESONANCE) > 0.9) + tempfreq = cem3394_get_parameter(state->cem_device[i], CEM3394_FILTER_FREQENCY); /* otherwise, they're calibrating the VCO frequency */ else - tempfreq = cem3394_get_parameter(cem_device[i], CEM3394_VCO_FREQUENCY); + tempfreq = cem3394_get_parameter(state->cem_device[i], CEM3394_VCO_FREQUENCY); if (tempfreq > maxfreq) maxfreq = tempfreq; } @@ -984,8 +945,8 @@ static void update_counter_0_timer(void) /* reprime the timer */ if (maxfreq > 0.0) { - counter_0_timer_active = 1; - timer_adjust_periodic(counter_0_timer, ATTOTIME_IN_HZ(maxfreq), 0, ATTOTIME_IN_HZ(maxfreq)); + state->counter_0_timer_active = 1; + timer_device_adjust_periodic(state->counter_0_timer, ATTOTIME_IN_HZ(maxfreq), 0, ATTOTIME_IN_HZ(maxfreq)); } } @@ -999,11 +960,13 @@ static void update_counter_0_timer(void) READ8_HANDLER( balsente_counter_state_r ) { + balsente_state *state = (balsente_state *)space->machine->driver_data; + /* bit D0 is the inverse of the flip-flop state */ - int result = !counter_0_ff; + int result = !state->counter_0_ff; /* bit D1 is the OUT value from counter 0 */ - if (counter[0].out) result |= 0x02; + if (state->counter[0].out) result |= 0x02; return result; } @@ -1011,39 +974,40 @@ READ8_HANDLER( balsente_counter_state_r ) WRITE8_HANDLER( balsente_counter_control_w ) { - UINT8 diff_counter_control = counter_control ^ data; + balsente_state *state = (balsente_state *)space->machine->driver_data; + UINT8 diff_counter_control = state->counter_control ^ data; /* set the new global value */ - counter_control = data; + state->counter_control = data; /* bit D0 enables/disables audio */ if (diff_counter_control & 0x01) { int ch; for (ch = 0; ch < 6; ch++) - sound_set_output_gain(cem_device[ch], 0, (data & 0x01) ? 1.0 : 0); + sound_set_output_gain(state->cem_device[ch], 0, (data & 0x01) ? 1.0 : 0); } /* bit D1 is hooked to counter 0's gate */ /* if we gate on, start a pulsing timer to clock it */ - if (!counter[0].gate && (data & 0x02) && !counter_0_timer_active) + if (!state->counter[0].gate && (data & 0x02) && !state->counter_0_timer_active) { - update_counter_0_timer(); + update_counter_0_timer(state); } /* if we gate off, remove the timer */ - else if (counter[0].gate && !(data & 0x02) && counter_0_timer_active) + else if (state->counter[0].gate && !(data & 0x02) && state->counter_0_timer_active) { - timer_adjust_oneshot(counter_0_timer, attotime_never, 0); - counter_0_timer_active = 0; + timer_device_adjust_oneshot(state->counter_0_timer, attotime_never, 0); + state->counter_0_timer_active = 0; } /* set the actual gate afterwards, since we need to know the old value above */ counter_set_gate(space->machine, 0, (data >> 1) & 1); /* bits D2 and D4 control the clear/reset flags on the flip-flop that feeds counter 0 */ - if (!(data & 0x04)) set_counter_0_ff(space->machine, 1); - if (!(data & 0x10)) set_counter_0_ff(space->machine, 0); + if (!(data & 0x04)) set_counter_0_ff(state->counter_0_timer, 1); + if (!(data & 0x10)) set_counter_0_ff(state->counter_0_timer, 0); /* bit 5 clears the NMI interrupt; recompute the I/O state now */ m6850_update_io(space->machine); @@ -1071,12 +1035,13 @@ WRITE8_HANDLER( balsente_chip_select_w ) CEM3394_WAVE_SELECT }; - double voltage = (double)dac_value * (8.0 / 4096.0) - 4.0; - int diffchip = data ^ chip_select, i; - int reg = register_map[dac_register]; + balsente_state *state = (balsente_state *)space->machine->driver_data; + double voltage = (double)state->dac_value * (8.0 / 4096.0) - 4.0; + int diffchip = data ^ state->chip_select, i; + int reg = register_map[state->dac_register]; /* remember the new select value */ - chip_select = data; + state->chip_select = data; /* check all six chip enables */ for (i = 0; i < 6; i++) @@ -1088,14 +1053,14 @@ WRITE8_HANDLER( balsente_chip_select_w ) /* remember the previous value */ temp = #endif - cem3394_get_parameter(cem_device[i], reg); + cem3394_get_parameter(state->cem_device[i], reg); /* set the voltage */ - cem3394_set_voltage(cem_device[i], reg, voltage); + cem3394_set_voltage(state->cem_device[i], reg, voltage); /* only log changes */ #if LOG_CEM_WRITES - if (temp != cem3394_get_parameter(cem_device[i], reg)) + if (temp != cem3394_get_parameter(state->cem_device[i], reg)) { static const char *const names[] = { @@ -1108,30 +1073,32 @@ WRITE8_HANDLER( balsente_chip_select_w ) "PULSE_WIDTH", "WAVE_SELECT" }; - logerror("s%04X: CEM#%d:%s=%f\n", cpu_get_previouspc(space->cpu), i, names[dac_register], voltage); + logerror("s%04X: CEM#%d:%s=%f\n", cpu_get_previouspc(space->cpu), i, names[state->dac_register], voltage); } #endif } /* if a timer for counter 0 is running, recompute */ - if (counter_0_timer_active) - update_counter_0_timer(); + if (state->counter_0_timer_active) + update_counter_0_timer(state); } WRITE8_HANDLER( balsente_dac_data_w ) { + balsente_state *state = (balsente_state *)space->machine->driver_data; + /* LSB or MSB? */ if (offset & 1) - dac_value = (dac_value & 0xfc0) | ((data >> 2) & 0x03f); + state->dac_value = (state->dac_value & 0xfc0) | ((data >> 2) & 0x03f); else - dac_value = (dac_value & 0x03f) | ((data << 6) & 0xfc0); + state->dac_value = (state->dac_value & 0x03f) | ((data << 6) & 0xfc0); /* if there are open channels, force the values in */ - if ((chip_select & 0x3f) != 0x3f) + if ((state->chip_select & 0x3f) != 0x3f) { - UINT8 temp = chip_select; + UINT8 temp = state->chip_select; balsente_chip_select_w(space, 0, 0x3f); balsente_chip_select_w(space, 0, temp); } @@ -1140,7 +1107,8 @@ WRITE8_HANDLER( balsente_dac_data_w ) WRITE8_HANDLER( balsente_register_addr_w ) { - dac_register = data & 7; + balsente_state *state = (balsente_state *)space->machine->driver_data; + state->dac_register = data & 7; } @@ -1153,39 +1121,43 @@ WRITE8_HANDLER( balsente_register_addr_w ) CUSTOM_INPUT( nstocker_bits_r ) { - return nstocker_bits; + balsente_state *state = (balsente_state *)field->port->machine->driver_data; + return state->nstocker_bits; } WRITE8_HANDLER( spiker_expand_w ) { + balsente_state *state = (balsente_state *)space->machine->driver_data; + /* offset 0 is the bit pattern */ if (offset == 0) - spiker_expand_bits = data; + state->spiker_expand_bits = data; /* offset 1 is the background color (cleared on each read) */ else if (offset == 1) - spiker_expand_bgcolor = data; + state->spiker_expand_bgcolor = data; /* offset 2 is the color */ else if (offset == 2) - spiker_expand_color = data; + state->spiker_expand_color = data; } READ8_HANDLER( spiker_expand_r ) { + balsente_state *state = (balsente_state *)space->machine->driver_data; UINT8 left, right; /* first rotate each nibble */ - spiker_expand_bits = ((spiker_expand_bits << 1) & 0xee) | ((spiker_expand_bits >> 3) & 0x11); + state->spiker_expand_bits = ((state->spiker_expand_bits << 1) & 0xee) | ((state->spiker_expand_bits >> 3) & 0x11); /* compute left and right pixels */ - left = (spiker_expand_bits & 0x10) ? spiker_expand_color : spiker_expand_bgcolor; - right = (spiker_expand_bits & 0x01) ? spiker_expand_color : spiker_expand_bgcolor; + left = (state->spiker_expand_bits & 0x10) ? state->spiker_expand_color : state->spiker_expand_bgcolor; + right = (state->spiker_expand_bits & 0x01) ? state->spiker_expand_color : state->spiker_expand_bgcolor; /* reset the background color */ - spiker_expand_bgcolor = 0; + state->spiker_expand_bgcolor = 0; /* return the combined result */ return (left & 0xf0) | (right & 0x0f); @@ -1194,6 +1166,7 @@ READ8_HANDLER( spiker_expand_r ) static void update_grudge_steering(running_machine *machine) { + balsente_state *state = (balsente_state *)machine->driver_data; UINT8 wheel[3]; INT8 diff[3]; @@ -1203,31 +1176,31 @@ static void update_grudge_steering(running_machine *machine) wheel[2] = input_port_read(machine, "AN2"); /* diff the values */ - diff[0] = wheel[0] - grudge_last_steering[0]; - diff[1] = wheel[1] - grudge_last_steering[1]; - diff[2] = wheel[2] - grudge_last_steering[2]; + diff[0] = wheel[0] - state->grudge_last_steering[0]; + diff[1] = wheel[1] - state->grudge_last_steering[1]; + diff[2] = wheel[2] - state->grudge_last_steering[2]; /* update the last values */ - grudge_last_steering[0] += diff[0]; - grudge_last_steering[1] += diff[1]; - grudge_last_steering[2] += diff[2]; + state->grudge_last_steering[0] += diff[0]; + state->grudge_last_steering[1] += diff[1]; + state->grudge_last_steering[2] += diff[2]; /* compute the result */ - grudge_steering_result = 0xff; + state->grudge_steering_result = 0xff; if (diff[0]) { - grudge_steering_result ^= 0x01; - if (diff[0] > 0) grudge_steering_result ^= 0x02; + state->grudge_steering_result ^= 0x01; + if (diff[0] > 0) state->grudge_steering_result ^= 0x02; } if (diff[1]) { - grudge_steering_result ^= 0x04; - if (diff[1] > 0) grudge_steering_result ^= 0x08; + state->grudge_steering_result ^= 0x04; + if (diff[1] > 0) state->grudge_steering_result ^= 0x08; } if (diff[2]) { - grudge_steering_result ^= 0x10; - if (diff[2] > 0) grudge_steering_result ^= 0x20; + state->grudge_steering_result ^= 0x10; + if (diff[2] > 0) state->grudge_steering_result ^= 0x20; } logerror("Recomputed steering\n"); } @@ -1235,9 +1208,10 @@ static void update_grudge_steering(running_machine *machine) READ8_HANDLER( grudge_steering_r ) { + balsente_state *state = (balsente_state *)space->machine->driver_data; logerror("%04X:grudge_steering_r(@%d)\n", cpu_get_pc(space->cpu), video_screen_get_vpos(space->machine->primary_screen)); - grudge_steering_result |= 0x80; - return grudge_steering_result; + state->grudge_steering_result |= 0x80; + return state->grudge_steering_result; } @@ -1250,33 +1224,37 @@ READ8_HANDLER( grudge_steering_r ) READ8_HANDLER( shrike_shared_6809_r ) { - UINT16 mem_mask = offset & 1 ? 0xff00 : 0x00ff; + balsente_state *state = (balsente_state *)space->machine->driver_data; + UINT16 mem_mask = offset & 1 ? 0xff00 : 0x00ff; - switch( offset ) - { - case 6: // return OK for 68k status register until motors hooked up - return 0; - default: - return ( shrike_shared[offset >> 1] & ~mem_mask ) >> ( mem_mask & 8 ); - } + switch( offset ) + { + case 6: // return OK for 68k status register until motors hooked up + return 0; + default: + return ( state->shrike_shared[offset >> 1] & ~mem_mask ) >> ( mem_mask & 8 ); + } } WRITE8_HANDLER( shrike_shared_6809_w ) { - UINT16 mem_mask = offset & 1 ? 0xff00 : 0x00ff; - shrike_shared[offset >> 1] = ( shrike_shared[offset >> 1] & mem_mask ) | ( data << ( mem_mask & 0x8 ) ); + balsente_state *state = (balsente_state *)space->machine->driver_data; + UINT16 mem_mask = offset & 1 ? 0xff00 : 0x00ff; + state->shrike_shared[offset >> 1] = ( state->shrike_shared[offset >> 1] & mem_mask ) | ( data << ( mem_mask & 0x8 ) ); } // uses movep, so writes even 8 bit addresses to odd 16 bit addresses, reads as 16 bit from odd addresses // i.e. write 0xdeadbeef to 10000, read 0xde from 10001, 0xad from 10003, 0xbe from 10005... WRITE16_HANDLER( shrike_io_68k_w ) { - COMBINE_DATA( &shrike_io[offset] ); + balsente_state *state = (balsente_state *)space->machine->driver_data; + COMBINE_DATA( &state->shrike_io[offset] ); } READ16_HANDLER( shrike_io_68k_r ) { - return ( shrike_io[offset] & mem_mask ) >> ( 8 & ~mem_mask ); + balsente_state *state = (balsente_state *)space->machine->driver_data; + return ( state->shrike_io[offset] & mem_mask ) >> ( 8 & ~mem_mask ); } diff --git a/src/mame/machine/harddriv.c b/src/mame/machine/harddriv.c index ddd0207d827..4799000921c 100644 --- a/src/mame/machine/harddriv.c +++ b/src/mame/machine/harddriv.c @@ -38,7 +38,6 @@ static void hd68k_update_interrupts(running_machine *machine); -static TIMER_CALLBACK( duart_callback ); @@ -61,6 +60,9 @@ MACHINE_START( harddriv ) state->sim_memory = (UINT16 *)memory_region(machine, "user1"); state->sim_memory_size = memory_region_length(machine, "user1") / 2; state->adsp_pgm_memory_word = (UINT16 *)((UINT8 *)state->adsp_pgm_memory + 1); + + /* allocate timers */ + state->duart_timer = devtag_get_device(machine, "duart_timer"); } @@ -93,7 +95,6 @@ MACHINE_RESET( harddriv ) memset(state->duart_read_data, 0, sizeof(state->duart_read_data)); memset(state->duart_write_data, 0, sizeof(state->duart_write_data)); state->duart_output_port = 0; - state->duart_timer = timer_alloc(machine, duart_callback, NULL); /* reset the ADSP/DSIII/DSIV boards */ state->adsp_halt = 1; @@ -523,18 +524,18 @@ INLINE attotime duart_clock_period(harddriv_state *state) } -static TIMER_CALLBACK( duart_callback ) +TIMER_DEVICE_CALLBACK( hd68k_duart_callback ) { - harddriv_state *state = (harddriv_state *)machine->driver_data; + harddriv_state *state = (harddriv_state *)timer->machine->driver_data; logerror("DUART timer fired\n"); if (state->duart_write_data[0x05] & 0x08) { logerror("DUART interrupt generated\n"); state->duart_read_data[0x05] |= 0x08; state->duart_irq_state = (state->duart_read_data[0x05] & state->duart_write_data[0x05]) != 0; - atarigen_update_interrupts(machine); + atarigen_update_interrupts(timer->machine); } - timer_adjust_oneshot(state->duart_timer, attotime_mul(duart_clock_period(state), 65536), 0); + timer_device_adjust_oneshot(timer, attotime_mul(duart_clock_period(state), 65536), 0); } @@ -562,14 +563,14 @@ READ16_HANDLER( hd68k_duart_r ) case 0x0e: /* Start-Counter Command 3 */ { int reps = (state->duart_write_data[0x06] << 8) | state->duart_write_data[0x07]; - timer_adjust_oneshot(state->duart_timer, attotime_mul(duart_clock_period(state), reps), 0); + timer_device_adjust_oneshot(state->duart_timer, attotime_mul(duart_clock_period(state), reps), 0); logerror("DUART timer started (period=%f)\n", attotime_to_double(attotime_mul(duart_clock_period(state), reps))); return 0x00ff; } case 0x0f: /* Stop-Counter Command 3 */ { - int reps = attotime_to_double(attotime_mul(timer_timeleft(state->duart_timer), duart_clock(state))); - timer_adjust_oneshot(state->duart_timer, attotime_never, 0); + int reps = attotime_to_double(attotime_mul(timer_device_timeleft(state->duart_timer), duart_clock(state))); + timer_device_adjust_oneshot(state->duart_timer, attotime_never, 0); state->duart_read_data[0x06] = reps >> 8; state->duart_read_data[0x07] = reps & 0xff; logerror("DUART timer stopped (final count=%04X)\n", reps); diff --git a/src/mame/video/atarimo.c b/src/mame/video/atarimo.c index 637cb3c1fc8..e13761d8038 100644 --- a/src/mame/video/atarimo.c +++ b/src/mame/video/atarimo.c @@ -295,9 +295,9 @@ static void init_savestate(running_machine *machine, int index, atarimo_data *mo state_save_register_item(machine, "atarimo", NULL, index, mo->dirtyheight); #endif - state_save_register_bitmap(machine, "atarimo", NULL, index, "bitmap", mo->bitmap); + state_save_register_bitmap(machine, "atarimo", NULL, index, "bitmap", mo->bitmap, __FILE__, __LINE__); - state_save_register_memory(machine, "atarimo", NULL, index, "spriteram", mo->spriteram, sizeof(atarimo_entry), mo->spriteramsize); + state_save_register_memory(machine, "atarimo", NULL, index, "spriteram", mo->spriteram, sizeof(atarimo_entry), mo->spriteramsize, __FILE__, __LINE__); state_save_register_item_pointer(machine, "atarimo", NULL, index, mo->codelookup, round_to_powerof2(mo->codemask.mask)); diff --git a/src/mame/video/balsente.c b/src/mame/video/balsente.c index 44fe7e8ac0f..acd0956ab10 100644 --- a/src/mame/video/balsente.c +++ b/src/mame/video/balsente.c @@ -10,21 +10,6 @@ #include "balsente.h" -/************************************* - * - * Statics - * - *************************************/ - -static UINT8 *local_videoram; -static UINT8 *sprite_data; -static UINT32 sprite_mask; -static UINT8 *sprite_bank[2]; - -static UINT8 palettebank_vis; - - - /************************************* * * Video system start @@ -33,21 +18,20 @@ static UINT8 palettebank_vis; VIDEO_START( balsente ) { - /* reset the system */ - palettebank_vis = 0; - sprite_bank[0] = memory_region(machine, "gfx1"); - sprite_bank[1] = memory_region(machine, "gfx1") + 0x10000; + balsente_state *state = (balsente_state *)machine->driver_data; - /* allocate a local copy of video RAM */ - local_videoram = auto_alloc_array(machine, UINT8, 256 * 256); + /* reset the system */ + state->palettebank_vis = 0; + state->sprite_bank[0] = memory_region(machine, "gfx1"); + state->sprite_bank[1] = memory_region(machine, "gfx1") + 0x10000; /* determine sprite size */ - sprite_data = memory_region(machine, "gfx1"); - sprite_mask = memory_region_length(machine, "gfx1") - 1; + state->sprite_data = memory_region(machine, "gfx1"); + state->sprite_mask = memory_region_length(machine, "gfx1") - 1; /* register for saving */ - state_save_register_global_pointer(machine, local_videoram, 256 * 256); - state_save_register_global(machine, palettebank_vis); + state_save_register_global_array(machine, state->videoram); + state_save_register_global(machine, state->palettebank_vis); } @@ -60,11 +44,13 @@ VIDEO_START( balsente ) WRITE8_HANDLER( balsente_videoram_w ) { + balsente_state *state = (balsente_state *)space->machine->driver_data; + space->machine->generic.videoram.u8[offset] = data; /* expand the two pixel values into two bytes */ - local_videoram[offset * 2 + 0] = data >> 4; - local_videoram[offset * 2 + 1] = data & 15; + state->videoram[offset * 2 + 0] = data >> 4; + state->videoram[offset * 2 + 1] = data & 15; } @@ -77,12 +63,14 @@ WRITE8_HANDLER( balsente_videoram_w ) WRITE8_HANDLER( balsente_palette_select_w ) { + balsente_state *state = (balsente_state *)space->machine->driver_data; + /* only update if changed */ - if (palettebank_vis != (data & 3)) + if (state->palettebank_vis != (data & 3)) { /* update the scanline palette */ video_screen_update_partial(space->machine->primary_screen, video_screen_get_vpos(space->machine->primary_screen) - 1 + BALSENTE_VBEND); - palettebank_vis = data & 3; + state->palettebank_vis = data & 3; } logerror("balsente_palette_select_w(%d) scanline=%d\n", data & 3, video_screen_get_vpos(space->machine->primary_screen)); @@ -119,11 +107,12 @@ WRITE8_HANDLER( balsente_paletteram_w ) WRITE8_HANDLER( shrike_sprite_select_w ) { - if( sprite_data != sprite_bank[(data & 0x80 >> 7) ^ 1 ]) + balsente_state *state = (balsente_state *)space->machine->driver_data; + if( state->sprite_data != state->sprite_bank[(data & 0x80 >> 7) ^ 1 ]) { logerror( "shrike_sprite_select_w( 0x%02x )\n", data ); video_screen_update_partial(space->machine->primary_screen, video_screen_get_vpos(space->machine->primary_screen) - 1 + BALSENTE_VBEND); - sprite_data = sprite_bank[(data & 0x80 >> 7) ^ 1]; + state->sprite_data = state->sprite_bank[(data & 0x80 >> 7) ^ 1]; } shrike_shared_6809_w( space, 1, data ); @@ -139,6 +128,7 @@ WRITE8_HANDLER( shrike_sprite_select_w ) static void draw_one_sprite(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, UINT8 *sprite) { + balsente_state *state = (balsente_state *)machine->driver_data; int flags = sprite[0]; int image = sprite[1] | ((flags & 7) << 8); int ypos = sprite[2] + 17 + BALSENTE_VBEND; @@ -147,7 +137,7 @@ static void draw_one_sprite(running_machine *machine, bitmap_t *bitmap, const re int x, y; /* get a pointer to the source image */ - src = &sprite_data[(64 * image) & sprite_mask]; + src = &state->sprite_data[(64 * image) & state->sprite_mask]; if (flags & 0x80) src += 4 * 15; /* loop over y */ @@ -155,8 +145,8 @@ static void draw_one_sprite(running_machine *machine, bitmap_t *bitmap, const re { if (ypos >= (16 + BALSENTE_VBEND) && ypos >= cliprect->min_y && ypos <= cliprect->max_y) { - const pen_t *pens = &machine->pens[palettebank_vis * 256]; - UINT8 *old = &local_videoram[(ypos - BALSENTE_VBEND) * 256 + xpos]; + const pen_t *pens = &machine->pens[state->palettebank_vis * 256]; + UINT8 *old = &state->videoram[(ypos - BALSENTE_VBEND) * 256 + xpos]; int currx = xpos; /* standard case */ @@ -222,12 +212,13 @@ static void draw_one_sprite(running_machine *machine, bitmap_t *bitmap, const re VIDEO_UPDATE( balsente ) { - const pen_t *pens = &screen->machine->pens[palettebank_vis * 256]; + balsente_state *state = (balsente_state *)screen->machine->driver_data; + const pen_t *pens = &screen->machine->pens[state->palettebank_vis * 256]; int y, i; /* draw scanlines from the VRAM directly */ for (y = cliprect->min_y; y <= cliprect->max_y; y++) - draw_scanline8(bitmap, 0, y, 256, &local_videoram[(y - BALSENTE_VBEND) * 256], pens); + draw_scanline8(bitmap, 0, y, 256, &state->videoram[(y - BALSENTE_VBEND) * 256], pens); /* draw the sprite images */ for (i = 0; i < 40; i++) diff --git a/src/mame/video/psx.c b/src/mame/video/psx.c index e6efd24d7dd..06ea8af433c 100644 --- a/src/mame/video/psx.c +++ b/src/mame/video/psx.c @@ -739,7 +739,7 @@ static void psx_gpu_init( running_machine *machine ) } // icky!!! - state_save_register_memory( machine, "globals", NULL, 0, "m_packet", (UINT8 *)&m_packet, 1, sizeof( m_packet ) ); + state_save_register_memory( machine, "globals", NULL, 0, "m_packet", (UINT8 *)&m_packet, 1, sizeof( m_packet ), __FILE__, __LINE__ ); state_save_register_global_pointer(machine, m_p_vram, m_n_vram_size ); state_save_register_global(machine, m_n_gpu_buffer_offset );