src/mess/devices/messram.c
| r0 | r5769 | |
| 1 | /*************************************************************************
|
| 2 | |
| 3 | MESS RAM device
|
| 4 | |
| 5 | Provides a configurable amount of RAM to drivers
|
| 6 | |
| 7 | **************************************************************************/
|
| 8 | |
| 9 | #include <stdio.h>
|
| 10 | #include <ctype.h>
|
| 11 | |
| 12 | #include "driver.h"
|
| 13 | #include "messram.h"
|
| 14 | |
| 15 | |
| 16 | /***************************************************************************
|
| 17 | CONSTANTS
|
| 18 | ***************************************************************************/
|
| 19 | |
| 20 | #define RAM_STRING_BUFLEN 16
|
| 21 | #define MAX_RAM_OPTIONS 16
|
| 22 | |
| 23 | |
| 24 | /***************************************************************************
|
| 25 | TYPE DEFINITIONS
|
| 26 | ***************************************************************************/
|
| 27 | |
| 28 | typedef struct _messram_state messram_state;
|
| 29 | struct _messram_state
|
| 30 | {
|
| 31 | UINT32 size; /* total amount of ram configured */
|
| 32 | UINT8 *ram; /* pointer to the start of ram */
|
| 33 | };
|
| 34 | |
| 35 | |
| 36 | /*****************************************************************************
|
| 37 | INLINE FUNCTIONS
|
| 38 | *****************************************************************************/
|
| 39 | |
| 40 | INLINE messram_state *get_safe_token(const device_config *device)
|
| 41 | {
|
| 42 | assert(device != NULL);
|
| 43 | assert(device->token != NULL);
|
| 44 | assert(device->type == MESSRAM);
|
| 45 | |
| 46 | return (messram_state *)device->token;
|
| 47 | }
|
| 48 | |
| 49 | |
| 50 | /*****************************************************************************
|
| 51 | HELPER FUNCTIONS
|
| 52 | *****************************************************************************/
|
| 53 | |
| 54 | /*-------------------------------------------------
|
| 55 | parse_string - convert a ram string to an
|
| 56 | integer value
|
| 57 | -------------------------------------------------*/
|
| 58 | |
| 59 | static UINT32 parse_string(const char *s)
|
| 60 | {
|
| 61 | UINT32 ram;
|
| 62 | char suffix = '\0';
|
| 63 | |
| 64 | s += sscanf(s, "%u%c", &ram, &suffix);
|
| 65 | |
| 66 | switch(tolower(suffix))
|
| 67 | {
|
| 68 | case 'k':
|
| 69 | /* kilobytes */
|
| 70 | ram *= 1024;
|
| 71 | break;
|
| 72 | |
| 73 | case 'm':
|
| 74 | /* megabytes */
|
| 75 | ram *= 1024*1024;
|
| 76 | break;
|
| 77 | |
| 78 | case '\0':
|
| 79 | /* no suffix */
|
| 80 | break;
|
| 81 | |
| 82 | default:
|
| 83 | /* parse failure */
|
| 84 | ram = 0;
|
| 85 | break;
|
| 86 | }
|
| 87 | |
| 88 | return ram;
|
| 89 | }
|
| 90 | |
| 91 | |
| 92 | /*****************************************************************************
|
| 93 | DEVICE INTERFACE
|
| 94 | *****************************************************************************/
|
| 95 | |
| 96 | static DEVICE_START( messram )
|
| 97 | {
|
| 98 | messram_state *messram = get_safe_token(device);
|
| 99 | ram_config *config = device->inline_config;
|
| 100 | const char *ramsize_string = options_get_string(mame_options(), OPTION_RAMSIZE);
|
| 101 | |
| 102 | /* if we have a command line option, use it */
|
| 103 | if ((ramsize_string != NULL) && (ramsize_string[0] != '\0'))
|
| 104 | messram->size = parse_string(ramsize_string);
|
| 105 | else
|
| 106 | messram->size = parse_string(config->default_size);
|
| 107 | |
| 108 | /* allocate space for the ram */
|
| 109 | messram->ram = auto_alloc_array(device->machine, UINT8, messram->size);
|
| 110 | |
| 111 | /* register for state saving */
|
| 112 | state_save_register_device_item(device, 0, messram->size);
|
| 113 | state_save_register_device_item_pointer(device, 0, messram->ram, messram->size);
|
| 114 | }
|
| 115 | |
| 116 | |
| 117 | static DEVICE_RESET( messram )
|
| 118 | {
|
| 119 | messram_state *messram = get_safe_token(device);
|
| 120 | ram_config *config = device->inline_config;
|
| 121 | |
| 122 | /* reset ram to the default value */
|
| 123 | memset(messram->ram, config->default_value, messram->size);
|
| 124 | }
|
| 125 | |
| 126 | |
| 127 | static DEVICE_VALIDITY_CHECK( messram )
|
| 128 | {
|
| 129 | ram_config *config = device->inline_config;
|
| 130 | const char *ramsize_string;
|
| 131 | int is_valid = FALSE;
|
| 132 | UINT32 specified_ram = 0;
|
| 133 | int error = FALSE;
|
| 134 | |
| 135 | /* verify default ram value */
|
| 136 | if (parse_string(config->default_size) == 0)
|
| 137 | {
|
| 138 | mame_printf_error("%s: '%s' has an invalid default RAM option: %s\n", driver->source_file, driver->name, config->default_size);
|
| 139 | error = TRUE;
|
| 140 | }
|
| 141 | |
| 142 | /* command line options are only parsed for the device named "messram" */
|
| 143 | if (strcmp(device->tag, "messram") == 0)
|
| 144 | {
|
| 145 | /* verify command line ram option */
|
| 146 | ramsize_string = options_get_string(mame_options(), OPTION_RAMSIZE);
|
| 147 | |
| 148 | if ((ramsize_string != NULL) && (ramsize_string[0] != '\0'))
|
| 149 | {
|
| 150 | specified_ram = ram_parse_string(ramsize_string);
|
| 151 | |
| 152 | if (specified_ram == 0)
|
| 153 | {
|
| 154 | mame_printf_error("%s: '%s' cannot recognize the RAM option %s\n", driver->source_file, driver->name, ramsize_string);
|
| 155 | error = TRUE;
|
| 156 | }
|
| 157 | }
|
| 158 | else
|
| 159 | {
|
| 160 | /* not specifying the ramsize on the command line is valid as well */
|
| 161 | is_valid = TRUE;
|
| 162 | }
|
| 163 | |
| 164 | /* compare command line option to default value */
|
| 165 | if (parse_string(config->default_size) == specified_ram)
|
| 166 | is_valid = TRUE;
|
| 167 | }
|
| 168 | else
|
| 169 | is_valid = TRUE;
|
| 170 | |
| 171 | /* verify extra ram options */
|
| 172 | if (config->extra_options != NULL)
|
| 173 | {
|
| 174 | const char *s;
|
| 175 | |
| 176 | astring *buffer = astring_alloc();
|
| 177 | astring_cpyc(buffer, config->extra_options);
|
| 178 | astring_replacechr(buffer, ',', 0);
|
| 179 | |
| 180 | s = astring_c(buffer);
|
| 181 | |
| 182 | /* try to parse each option */
|
| 183 | while(*s != '\0')
|
| 184 | {
|
| 185 | UINT32 option_ram_size = parse_string(s);
|
| 186 | |
| 187 | if (option_ram_size == 0)
|
| 188 | {
|
| 189 | mame_printf_error("%s: '%s' has an invalid RAM option: %s\n", driver->source_file, driver->name, s);
|
| 190 | error = TRUE;
|
| 191 | }
|
| 192 | |
| 193 | if (option_ram_size == specified_ram)
|
| 194 | is_valid = TRUE;
|
| 195 | |
| 196 | s += strlen(s) + 1;
|
| 197 | }
|
| 198 | |
| 199 | astring_free(buffer);
|
| 200 | }
|
| 201 | |
| 202 | if (!is_valid)
|
| 203 | {
|
| 204 | mame_printf_error("%s: '%s' cannot recognize the RAM option %s", driver->source_file, driver->name, ramsize_string);
|
| 205 | mame_printf_error(" (valid options are %s", config->default_size);
|
| 206 | |
| 207 | if (config->extra_options != NULL)
|
| 208 | mame_printf_error(",%s).\n", config->extra_options);
|
| 209 | else
|
| 210 | mame_printf_error(").\n");
|
| 211 | |
| 212 | error = TRUE;
|
| 213 | }
|
| 214 | |
| 215 | return error;
|
| 216 | }
|
| 217 | |
| 218 | |
| 219 | DEVICE_GET_INFO( messram )
|
| 220 | {
|
| 221 | switch (state)
|
| 222 | {
|
| 223 | /* --- the following bits of info are returned as 64-bit signed integers --- */
|
| 224 | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(messram_state); break;
|
| 225 | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = sizeof(ram_config); break;
|
| 226 | case DEVINFO_INT_CLASS: info->i = DEVICE_CLASS_OTHER; break;
|
| 227 | |
| 228 | /* --- the following bits of info are returned as pointers to data or functions --- */
|
| 229 | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(messram); break;
|
| 230 | case DEVINFO_FCT_STOP: /* Nothing */ break;
|
| 231 | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(messram); break;
|
| 232 | case DEVINFO_FCT_VALIDITY_CHECK: info->validity_check = DEVICE_VALIDITY_CHECK_NAME(messram); break;
|
| 233 | |
| 234 | /* --- the following bits of info are returned as NULL-terminated strings --- */
|
| 235 | case DEVINFO_STR_NAME: strcpy(info->s, "MESS RAM"); break;
|
| 236 | case DEVINFO_STR_FAMILY: strcpy(info->s, "RAM"); break;
|
| 237 | case DEVINFO_STR_VERSION: strcpy(info->s, "1.00"); break;
|
| 238 | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break;
|
| 239 | case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright MESS Team"); break;
|
| 240 | }
|
| 241 | }
|
| 242 | |
| 243 | |
| 244 | /***************************************************************************
|
| 245 | IMPLEMENTATION
|
| 246 | ***************************************************************************/
|
| 247 | |
| 248 | UINT32 messram_get_size(const device_config *device)
|
| 249 | {
|
| 250 | messram_state *messram = get_safe_token(device);
|
| 251 | return messram->size;
|
| 252 | }
|
| 253 | |
| 254 | |
| 255 | UINT8 *messram_get_ptr(const device_config *device)
|
| 256 | {
|
| 257 | messram_state *messram = get_safe_token(device);
|
| 258 | return messram->ram;
|
| 259 | }
|
| 260 | |
| 261 | |
| 262 | void messram_dump(const device_config *device, const char *filename)
|
| 263 | {
|
| 264 | messram_state *messram = get_safe_token(device);
|
| 265 | file_error filerr;
|
| 266 | mame_file *file;
|
| 267 | |
| 268 | /* use a default filename */
|
| 269 | if (!filename)
|
| 270 | filename = "ram.bin";
|
| 271 | |
| 272 | /* open the file */
|
| 273 | filerr = mame_fopen(NULL, filename, OPEN_FLAG_WRITE, &file);
|
| 274 | if (filerr == FILERR_NONE)
|
| 275 | {
|
| 276 | /* write the data */
|
| 277 | mame_fwrite(file, messram->ram, messram->size);
|
| 278 | |
| 279 | /* close file */
|
| 280 | mame_fclose(file);
|
| 281 | }
|
| 282 | }
|
src/mess/devices/messram.h
| r0 | r5769 | |
| 1 | /*************************************************************************
|
| 2 | |
| 3 | MESS RAM device
|
| 4 | |
| 5 | Provides a configurable amount of RAM to drivers
|
| 6 | |
| 7 | **************************************************************************/
|
| 8 | |
| 9 | #ifndef __MESSRAM_H__
|
| 10 | #define __MESSRAM_H__
|
| 11 | |
| 12 | |
| 13 | /***************************************************************************
|
| 14 | CONSTANTS
|
| 15 | ***************************************************************************/
|
| 16 | |
| 17 | #define RAM_DEFAULT_VALUE 0xcd
|
| 18 | |
| 19 | enum
|
| 20 | {
|
| 21 | DEVINFO_STR_MESSRAM_SIZE = DEVINFO_STR_DEVICE_SPECIFIC
|
| 22 | };
|
| 23 | |
| 24 | |
| 25 | /***************************************************************************
|
| 26 | TYPE DEFINITIONS
|
| 27 | ***************************************************************************/
|
| 28 | |
| 29 | typedef struct _ram_config ram_config;
|
| 30 | struct _ram_config
|
| 31 | {
|
| 32 | const char *default_size;
|
| 33 | const char *extra_options;
|
| 34 | UINT8 default_value;
|
| 35 | };
|
| 36 | |
| 37 | |
| 38 | /***************************************************************************
|
| 39 | DEVICE CONFIGURATION MACROS
|
| 40 | ***************************************************************************/
|
| 41 | |
| 42 | #define MESSRAM DEVICE_GET_INFO_NAME(messram)
|
| 43 | |
| 44 | #define MDRV_RAM_ADD(_tag) \
|
| 45 | MDRV_DEVICE_ADD(_tag, MESSRAM, 0) \
|
| 46 | MDRV_DEVICE_CONFIG_DATA32(ram_config, default_value, RAM_DEFAULT_VALUE)
|
| 47 | |
| 48 | #define MDRV_RAM_REMOVE(_tag) \
|
| 49 | MDRV_DEVICE_REMOVE(_tag, MESSRAM)
|
| 50 | |
| 51 | #define MDRV_RAM_MODIFY(_tag) \
|
| 52 | MDRV_DEVICE_MODIFY(_tag, MESSRAM)
|
| 53 | |
| 54 | #define MDRV_RAM_DEFAULT_SIZE(_default_size) \
|
| 55 | MDRV_DEVICE_CONFIG_DATAPTR(ram_config, default_size, _default_size)
|
| 56 | |
| 57 | #define MDRV_RAM_EXTRA_OPTIONS(_extra_options) \
|
| 58 | MDRV_DEVICE_CONFIG_DATAPTR(ram_config, extra_options, _extra_options)
|
| 59 | |
| 60 | #define MDRV_RAM_DEFAULT_VALUE(_default_value) \
|
| 61 | MDRV_DEVICE_CONFIG_DATA32(ram_config, default_value, _default_value)
|
| 62 | |
| 63 | |
| 64 | /***************************************************************************
|
| 65 | FUNCTION PROTOTYPES
|
| 66 | ***************************************************************************/
|
| 67 | |
| 68 | DEVICE_GET_INFO( messram );
|
| 69 | UINT32 messram_get_size(const device_config *device);
|
| 70 | UINT8 *messram_get_ptr(const device_config *device);
|
| 71 | void messram_dump(const device_config *device, const char *filename);
|
| 72 | |
| 73 | |
| 74 | #endif /* __MESSRAM_H__ */
|
src/mess/drivers/px4.c
| r5768 | r5769 | |
| 9 | 9 | |
| 10 | 10 | #include "driver.h" |
| 11 | 11 | #include "cpu/z80/z80.h" |
| 12 | #include "devices/messram.h" |
| 12 | 13 | #include "machine/ctronics.h" |
| 13 | 14 | #include "devices/cartslot.h" |
| 14 | 15 | #include "machine/pf10.h" |
| r5768 | r5769 | |
| 41 | 42 | typedef struct _px4_state px4_state; |
| 42 | 43 | struct _px4_state |
| 43 | 44 | { |
| 45 | /* internal ram */ |
| 46 | const device_config *ram; |
| 47 | |
| 44 | 48 | /* gapnit register */ |
| 45 | 49 | UINT8 bankr; |
| 46 | 50 | UINT8 isr; |
| r5768 | r5769 | |
| 213 | 217 | /* helper function to map rom capsules */ |
| 214 | 218 | static void install_rom_capsule(const address_space *space, int size, const char *region) |
| 215 | 219 | { |
| 220 | px4_state *px4 = space->machine->driver_data; |
| 221 | |
| 216 | 222 | /* ram, part 1 */ |
| 217 | 223 | memory_install_readwrite8_handler(space, 0x0000, 0xdfff - size, 0, 0, SMH_BANK(1), SMH_BANK(1)); |
| 218 | | memory_set_bankptr(space->machine, 1, mess_ram); |
| 224 | memory_set_bankptr(space->machine, 1, messram_get_ptr(px4->ram)); |
| 219 | 225 | |
| 220 | 226 | /* actual rom data, part 1 */ |
| 221 | 227 | memory_install_readwrite8_handler(space, 0xe000 - size, 0xffff - size, 0, 0, SMH_BANK(2), SMH_NOP); |
| r5768 | r5769 | |
| 230 | 236 | |
| 231 | 237 | /* ram, continued */ |
| 232 | 238 | memory_install_readwrite8_handler(space, 0xe000, 0xffff, 0, 0, SMH_BANK(4), SMH_BANK(4)); |
| 233 | | memory_set_bankptr(space->machine, 4, mess_ram + 0xe000); |
| 239 | memory_set_bankptr(space->machine, 4, messram_get_ptr(px4->ram) + 0xe000); |
| 234 | 240 | } |
| 235 | 241 | |
| 236 | 242 | /* bank register */ |
| r5768 | r5769 | |
| 251 | 257 | memory_install_readwrite8_handler(space_program, 0x0000, 0x7fff, 0, 0, SMH_BANK(1), SMH_NOP); |
| 252 | 258 | memory_set_bankptr(space->machine, 1, memory_region(space->machine, "os")); |
| 253 | 259 | memory_install_readwrite8_handler(space_program, 0x8000, 0xffff, 0, 0, SMH_BANK(2), SMH_BANK(2)); |
| 254 | | memory_set_bankptr(space->machine, 2, mess_ram + 0x8000); |
| 260 | memory_set_bankptr(space->machine, 2, messram_get_ptr(px4->ram) + 0x8000); |
| 255 | 261 | break; |
| 256 | 262 | |
| 257 | 263 | case 0x04: |
| 258 | 264 | /* memory */ |
| 259 | 265 | memory_install_readwrite8_handler(space_program, 0x0000, 0xffff, 0, 0, SMH_BANK(1), SMH_BANK(1)); |
| 260 | | memory_set_bankptr(space->machine, 1, mess_ram); |
| 266 | memory_set_bankptr(space->machine, 1, messram_get_ptr(px4->ram)); |
| 261 | 267 | break; |
| 262 | 268 | |
| 263 | 269 | case 0x08: install_rom_capsule(space_program, 0x2000, "capsule1"); break; |
| r5768 | r5769 | |
| 644 | 650 | int y, x; |
| 645 | 651 | |
| 646 | 652 | /* get vram start address */ |
| 647 | | UINT8 *vram = &mess_ram[(px4->vadr & 0xf8) << 8]; |
| 653 | UINT8 *vram = &messram_get_ptr(px4->ram)[(px4->vadr & 0xf8) << 8]; |
| 648 | 654 | |
| 649 | 655 | for (y = 0; y < 64; y++) |
| 650 | 656 | { |
| r5768 | r5769 | |
| 687 | 693 | { |
| 688 | 694 | px4_state *px4 = machine->driver_data; |
| 689 | 695 | |
| 696 | /* find devices */ |
| 697 | px4->ram = devtag_get_device(machine, "messram"); |
| 698 | |
| 690 | 699 | /* init 7508 */ |
| 691 | 700 | px4->one_sec_int_enabled = TRUE; |
| 692 | 701 | px4->key_int_enabled = TRUE; |
| r5768 | r5769 | |
| 694 | 703 | |
| 695 | 704 | /* map os rom and last half of memory */ |
| 696 | 705 | memory_set_bankptr(machine, 1, memory_region(machine, "os")); |
| 697 | | memory_set_bankptr(machine, 2, mess_ram + 0x8000); |
| 706 | memory_set_bankptr(machine, 2, messram_get_ptr(px4->ram) + 0x8000); |
| 698 | 707 | } |
| 699 | 708 | |
| 700 | 709 | static DRIVER_INIT( px4p ) |
| r5768 | r5769 | |
| 949 | 958 | MDRV_TIMER_ADD_PERIODIC("one_sec", upd7508_1sec_callback, SEC(1)) |
| 950 | 959 | MDRV_TIMER_ADD_PERIODIC("frc", frc_tick, NSEC(1600)) |
| 951 | 960 | |
| 961 | /* internal ram */ |
| 962 | MDRV_RAM_ADD("messram") |
| 963 | MDRV_RAM_DEFAULT_SIZE("64k") |
| 964 | |
| 952 | 965 | /* centronics printer */ |
| 953 | 966 | MDRV_CENTRONICS_ADD("centronics", standard_centronics) |
| 954 | 967 | |
| r5768 | r5769 | |
| 1014 | 1027 | |
| 1015 | 1028 | |
| 1016 | 1029 | /*************************************************************************** |
| 1017 | | SYSTEM CONFIG |
| 1018 | | ***************************************************************************/ |
| 1019 | | |
| 1020 | | static SYSTEM_CONFIG_START( px4 ) |
| 1021 | | CONFIG_RAM_DEFAULT(64 * 1024) /* 64KB RAM */ |
| 1022 | | SYSTEM_CONFIG_END |
| 1023 | | |
| 1024 | | |
| 1025 | | /*************************************************************************** |
| 1026 | 1030 | GAME DRIVERS |
| 1027 | 1031 | ***************************************************************************/ |
| 1028 | 1032 | |
| 1029 | 1033 | /* YEAR NAME PARENT COMPAT MACHINE INPUT INIT CONFIG COMPANY FULLNAME FLAGS */ |
| 1030 | | COMP( 1985, px4, 0, 0, px4, px4_h450a, px4, px4, "Epson", "PX-4", 0 ) |
| 1031 | | COMP( 1985, px4p, px4, 0, px4p, px4_h450a, px4p, px4, "Epson", "PX-4+", 0 ) |
| 1034 | COMP( 1985, px4, 0, 0, px4, px4_h450a, px4, 0, "Epson", "PX-4", 0 ) |
| 1035 | COMP( 1985, px4p, px4, 0, px4p, px4_h450a, px4p, 0, "Epson", "PX-4+", 0 ) |