src/emu/debug/debugcmt.c
| r9050 | r9051 | |
| 1 | | /*************************************************************************** |
| 2 | | |
| 3 | | debugcmt.c |
| 4 | | |
| 5 | | Debugger code-comment management functions. |
| 6 | | |
| 7 | | Copyright Nicola Salmoria and the MAME Team. |
| 8 | | Visit http://mamedev.org for licensing and usage restrictions. |
| 9 | | |
| 10 | | **************************************************************************** |
| 11 | | |
| 12 | | Debugger comment file format: |
| 13 | | |
| 14 | | (from comment struct - assuming (MAX_COMMENT_LINE_LENGTH == 128)) |
| 15 | | 0 - valid byte |
| 16 | | 1:4 - address |
| 17 | | 5:133 - comment |
| 18 | | 134:138 - color |
| 19 | | 139:142 - instruction crc |
| 20 | | |
| 21 | | ***************************************************************************/ |
| 22 | | |
| 23 | | #include "emu.h" |
| 24 | | #include "emuopts.h" |
| 25 | | #include "xmlfile.h" |
| 26 | | #include "debugcmt.h" |
| 27 | | #include "debugcpu.h" |
| 28 | | #include "debugvw.h" |
| 29 | | #include "info.h" |
| 30 | | #include <zlib.h> |
| 31 | | |
| 32 | | |
| 33 | | |
| 34 | | /*************************************************************************** |
| 35 | | DEBUGGING |
| 36 | | ***************************************************************************/ |
| 37 | | |
| 38 | | #define VERBOSE 0 |
| 39 | | #define LOG(x) do { if (VERBOSE) logerror x; } while (0) |
| 40 | | |
| 41 | | |
| 42 | | |
| 43 | | /*************************************************************************** |
| 44 | | CONSTANTS |
| 45 | | ***************************************************************************/ |
| 46 | | |
| 47 | | #define COMMENT_VERSION (1) |
| 48 | | |
| 49 | | |
| 50 | | |
| 51 | | /*************************************************************************** |
| 52 | | TYPE DEFINITIONS |
| 53 | | ***************************************************************************/ |
| 54 | | |
| 55 | | typedef struct _debug_comment debug_comment; |
| 56 | | struct _debug_comment |
| 57 | | { |
| 58 | | UINT8 is_valid; |
| 59 | | UINT32 address; |
| 60 | | char text[DEBUG_COMMENT_MAX_LINE_LENGTH]; |
| 61 | | rgb_t color; |
| 62 | | UINT32 crc; |
| 63 | | }; |
| 64 | | |
| 65 | | |
| 66 | | class debug_cpu_comment_group |
| 67 | | { |
| 68 | | public: |
| 69 | | int comment_count; |
| 70 | | UINT32 change_count; |
| 71 | | debug_comment * comment_info[DEBUG_COMMENT_MAX_NUM]; |
| 72 | | }; |
| 73 | | |
| 74 | | |
| 75 | | |
| 76 | | /*************************************************************************** |
| 77 | | FUNCTION PROTOTYPES |
| 78 | | ***************************************************************************/ |
| 79 | | |
| 80 | | static int debug_comment_load_xml(running_machine *machine, mame_file *file); |
| 81 | | static void debug_comment_exit(running_machine &machine); |
| 82 | | |
| 83 | | |
| 84 | | |
| 85 | | /*************************************************************************** |
| 86 | | INITIALIZATION |
| 87 | | ***************************************************************************/ |
| 88 | | |
| 89 | | /*------------------------------------------------------------------------- |
| 90 | | debug_comment_init - initializes the comment memory and |
| 91 | | loads any existing comment file |
| 92 | | -------------------------------------------------------------------------*/ |
| 93 | | |
| 94 | | int debug_comment_init(running_machine *machine) |
| 95 | | { |
| 96 | | /* allocate memory for the comments */ |
| 97 | | device_disasm_interface *disasm; |
| 98 | | for (device_t *device = machine->m_devicelist.first(); device != NULL; device = device->next()) |
| 99 | | if (device->interface(disasm)) |
| 100 | | device->debug()->m_comments = auto_alloc_clear(machine, debug_cpu_comment_group); |
| 101 | | |
| 102 | | /* automatically load em up */ |
| 103 | | debug_comment_load(machine); |
| 104 | | machine->add_notifier(MACHINE_NOTIFY_EXIT, debug_comment_exit); |
| 105 | | return 1; |
| 106 | | } |
| 107 | | |
| 108 | | |
| 109 | | /*------------------------------------------------------------------------- |
| 110 | | debug_comment_add - adds a comment to the list at the given address. |
| 111 | | use debug_comment_get_opcode_crc32(addr) to get |
| 112 | | the proper crc32 |
| 113 | | -------------------------------------------------------------------------*/ |
| 114 | | |
| 115 | | int debug_comment_add(device_t *device, offs_t addr, const char *comment, rgb_t color, UINT32 c_crc) |
| 116 | | { |
| 117 | | debug_cpu_comment_group *comments = device->debug()->m_comments; |
| 118 | | int insert_point = comments->comment_count; |
| 119 | | int match = 0; |
| 120 | | int i = 0; |
| 121 | | |
| 122 | | /* Create a new item to insert into the list */ |
| 123 | | debug_comment *insert_me = auto_alloc(device->machine, debug_comment); |
| 124 | | insert_me->color = color; |
| 125 | | insert_me->is_valid = 1; |
| 126 | | insert_me->address = addr; |
| 127 | | insert_me->crc = c_crc; |
| 128 | | strcpy(insert_me->text, comment); |
| 129 | | |
| 130 | | /* Find the insert point */ |
| 131 | | for (i = 0; i < comments->comment_count; i++) |
| 132 | | { |
| 133 | | if (insert_me->address < comments->comment_info[i]->address) |
| 134 | | { |
| 135 | | insert_point = i; |
| 136 | | break; |
| 137 | | } |
| 138 | | else if (insert_me->address == comments->comment_info[i]->address && |
| 139 | | insert_me->crc == comments->comment_info[i]->crc) |
| 140 | | { |
| 141 | | insert_point = i; |
| 142 | | match = 1; |
| 143 | | break; |
| 144 | | } |
| 145 | | } |
| 146 | | |
| 147 | | /* Got an exact match? Just replace */ |
| 148 | | if (match == 1) |
| 149 | | { |
| 150 | | auto_free(device->machine, comments->comment_info[insert_point]); |
| 151 | | comments->comment_info[insert_point] = insert_me; |
| 152 | | comments->change_count++; |
| 153 | | |
| 154 | | /* force an update of disassembly views */ |
| 155 | | device->machine->m_debug_view->update_all(DVT_DISASSEMBLY); |
| 156 | | return 1; |
| 157 | | } |
| 158 | | |
| 159 | | /* Otherwise insert */ |
| 160 | | /* First, shift the list down */ |
| 161 | | for (i = comments->comment_count; i >= insert_point; i--) |
| 162 | | comments->comment_info[i] = comments->comment_info[i-1]; |
| 163 | | |
| 164 | | /* do the insertion */ |
| 165 | | comments->comment_info[insert_point] = insert_me; |
| 166 | | comments->comment_count++; |
| 167 | | comments->change_count++; |
| 168 | | |
| 169 | | /* force an update of disassembly views */ |
| 170 | | device->machine->m_debug_view->update_all(DVT_DISASSEMBLY); |
| 171 | | |
| 172 | | return 1; |
| 173 | | } |
| 174 | | |
| 175 | | |
| 176 | | /*------------------------------------------------------------------------- |
| 177 | | debug_comment_remove - removes a comment at a given address |
| 178 | | use debug_comment_get_opcode_crc32(addr) to get |
| 179 | | the proper crc32 |
| 180 | | -------------------------------------------------------------------------*/ |
| 181 | | |
| 182 | | int debug_comment_remove(device_t *device, offs_t addr, UINT32 c_crc) |
| 183 | | { |
| 184 | | debug_cpu_comment_group *comments = device->debug()->m_comments; |
| 185 | | int remove_index = -1; |
| 186 | | int i; |
| 187 | | |
| 188 | | for (i = 0; i < comments->comment_count; i++) |
| 189 | | if (comments->comment_info[i]->address == addr) /* got an address match */ |
| 190 | | if (comments->comment_info[i]->crc == c_crc) |
| 191 | | remove_index = i; |
| 192 | | |
| 193 | | /* The comment doesn't exist? */ |
| 194 | | if (remove_index == -1) |
| 195 | | return 0; |
| 196 | | |
| 197 | | /* Okay, it's there, now remove it */ |
| 198 | | auto_free(device->machine, comments->comment_info[remove_index]); |
| 199 | | |
| 200 | | for (i = remove_index; i < comments->comment_count-1; i++) |
| 201 | | comments->comment_info[i] = comments->comment_info[i+1]; |
| 202 | | |
| 203 | | comments->comment_count--; |
| 204 | | comments->change_count++; |
| 205 | | |
| 206 | | /* force an update of disassembly views */ |
| 207 | | device->machine->m_debug_view->update_all(DVT_DISASSEMBLY); |
| 208 | | |
| 209 | | return 1; |
| 210 | | } |
| 211 | | |
| 212 | | |
| 213 | | /*------------------------------------------------------------------------- |
| 214 | | debug_comment_get_text - returns the comment for a given addresses |
| 215 | | use debug_comment_get_opcode_crc32(addr) to get |
| 216 | | the proper crc32 |
| 217 | | -------------------------------------------------------------------------*/ |
| 218 | | |
| 219 | | const char *debug_comment_get_text(device_t *device, offs_t addr, UINT32 c_crc) |
| 220 | | { |
| 221 | | debug_cpu_comment_group *comments = device->debug()->m_comments; |
| 222 | | int i; |
| 223 | | |
| 224 | | /* inefficient - should use bsearch - but will be a little tricky with multiple comments per addr */ |
| 225 | | for (i = 0; i < comments->comment_count; i++) |
| 226 | | if (comments->comment_info[i]->address == addr) /* got an address match */ |
| 227 | | { |
| 228 | | /* now check the bank information to be sure */ |
| 229 | | if (comments->comment_info[i]->crc == c_crc) |
| 230 | | return comments->comment_info[i]->text; |
| 231 | | } |
| 232 | | |
| 233 | | return 0x00; |
| 234 | | } |
| 235 | | |
| 236 | | |
| 237 | | /*------------------------------------------------------------------------- |
| 238 | | debug_comment_get_count - returns the number of comments |
| 239 | | for a given cpu number |
| 240 | | -------------------------------------------------------------------------*/ |
| 241 | | |
| 242 | | int debug_comment_get_count(device_t *device) |
| 243 | | { |
| 244 | | debug_cpu_comment_group *comments = device->debug()->m_comments; |
| 245 | | return comments->comment_count; |
| 246 | | } |
| 247 | | |
| 248 | | |
| 249 | | /*------------------------------------------------------------------------- |
| 250 | | debug_comment_get_change_count - returns the change counter |
| 251 | | for a given cpu number |
| 252 | | -------------------------------------------------------------------------*/ |
| 253 | | |
| 254 | | UINT32 debug_comment_get_change_count(device_t *device) |
| 255 | | { |
| 256 | | debug_cpu_comment_group *comments = device->debug()->m_comments; |
| 257 | | return comments->change_count; |
| 258 | | } |
| 259 | | |
| 260 | | /*------------------------------------------------------------------------- |
| 261 | | debug_comment_all_change_count - returns the change counter |
| 262 | | for all cpu's |
| 263 | | -------------------------------------------------------------------------*/ |
| 264 | | |
| 265 | | UINT32 debug_comment_all_change_count(running_machine *machine) |
| 266 | | { |
| 267 | | UINT32 retVal = 0; |
| 268 | | |
| 269 | | for (device_t *device = machine->m_devicelist.first(); device != NULL; device = device->next()) |
| 270 | | if (device->debug()->m_comments != NULL) |
| 271 | | retVal += device->debug()->m_comments->change_count; |
| 272 | | |
| 273 | | return retVal; |
| 274 | | } |
| 275 | | |
| 276 | | /*------------------------------------------------------------------------- |
| 277 | | debug_comment_get_opcode_crc32 - magic function that takes all the |
| 278 | | current state of the debugger and returns a crc32 |
| 279 | | for the opcode at the requested address. |
| 280 | | -------------------------------------------------------------------------*/ |
| 281 | | |
| 282 | | UINT32 debug_comment_get_opcode_crc32(device_t *device, offs_t address) |
| 283 | | { |
| 284 | | address_space *space = cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM); |
| 285 | | int i; |
| 286 | | UINT32 crc; |
| 287 | | UINT8 opbuf[64], argbuf[64]; |
| 288 | | char buff[256]; |
| 289 | | offs_t numbytes; |
| 290 | | cpu_device *cpudevice = downcast<cpu_device *>(device); |
| 291 | | int maxbytes = cpudevice->max_opcode_bytes(); |
| 292 | | UINT32 addrmask = space->logaddrmask(); |
| 293 | | |
| 294 | | memset(opbuf, 0x00, sizeof(opbuf)); |
| 295 | | memset(argbuf, 0x00, sizeof(argbuf)); |
| 296 | | |
| 297 | | // fetch the bytes up to the maximum |
| 298 | | for (i = 0; i < maxbytes; i++) |
| 299 | | { |
| 300 | | opbuf[i] = debug_read_opcode(space, address + i, 1, FALSE); |
| 301 | | argbuf[i] = debug_read_opcode(space, address + i, 1, TRUE); |
| 302 | | } |
| 303 | | |
| 304 | | numbytes = device->debug()->disassemble(buff, address & addrmask, opbuf, argbuf) & DASMFLAG_LENGTHMASK; |
| 305 | | numbytes = space->address_to_byte(numbytes); |
| 306 | | |
| 307 | | crc = crc32(0, argbuf, numbytes); |
| 308 | | |
| 309 | | return crc; |
| 310 | | } |
| 311 | | |
| 312 | | |
| 313 | | /*------------------------------------------------------------------------- |
| 314 | | debug_comment_dump - debugging function to dump junk to the command line |
| 315 | | -------------------------------------------------------------------------*/ |
| 316 | | |
| 317 | | void debug_comment_dump(device_t *device, offs_t addr) |
| 318 | | { |
| 319 | | debug_cpu_comment_group *comments = device->debug()->m_comments; |
| 320 | | int i; |
| 321 | | int ff = 0; |
| 322 | | |
| 323 | | if (addr == -1) |
| 324 | | { |
| 325 | | for (i = 0; i < comments->comment_count; i++) |
| 326 | | if (comments->comment_info[i]->is_valid) |
| 327 | | logerror("%d : %s (%d %d)\n", i, comments->comment_info[i]->text, |
| 328 | | comments->comment_info[i]->address, |
| 329 | | comments->comment_info[i]->crc); |
| 330 | | } |
| 331 | | else |
| 332 | | { |
| 333 | | UINT32 c_crc = debug_comment_get_opcode_crc32(device, addr); |
| 334 | | |
| 335 | | for (i = 0; i < comments->comment_count; i++) |
| 336 | | if (comments->comment_info[i]->address == addr) /* got an address match */ |
| 337 | | { |
| 338 | | /* now check the bank information to be sure */ |
| 339 | | if (comments->comment_info[i]->crc == c_crc) |
| 340 | | { |
| 341 | | logerror("%d : %s (%d %d)\n", addr, |
| 342 | | comments->comment_info[addr]->text, |
| 343 | | comments->comment_info[addr]->address, |
| 344 | | comments->comment_info[addr]->crc); |
| 345 | | ff = 1; |
| 346 | | } |
| 347 | | } |
| 348 | | |
| 349 | | if (!ff) logerror("No comment exists for address : 0x%x\n", addr); |
| 350 | | } |
| 351 | | } |
| 352 | | |
| 353 | | |
| 354 | | /*------------------------------------------------------------------------- |
| 355 | | debug_comment_save - comment file saving |
| 356 | | -------------------------------------------------------------------------*/ |
| 357 | | |
| 358 | | int debug_comment_save(running_machine *machine) |
| 359 | | { |
| 360 | | int j; |
| 361 | | char crc_buf[20]; |
| 362 | | xml_data_node *root = xml_file_create(); |
| 363 | | xml_data_node *commentnode, *systemnode; |
| 364 | | int total_comments = 0; |
| 365 | | |
| 366 | | /* if we don't have a root, bail */ |
| 367 | | if (root == NULL) |
| 368 | | return 0; |
| 369 | | |
| 370 | | /* create a comment node */ |
| 371 | | commentnode = xml_add_child(root, "mamecommentfile", NULL); |
| 372 | | if (commentnode == NULL) |
| 373 | | goto error; |
| 374 | | xml_set_attribute_int(commentnode, "version", COMMENT_VERSION); |
| 375 | | |
| 376 | | /* create a system node */ |
| 377 | | systemnode = xml_add_child(commentnode, "system", NULL); |
| 378 | | if (systemnode == NULL) |
| 379 | | goto error; |
| 380 | | xml_set_attribute(systemnode, "name", machine->gamedrv->name); |
| 381 | | |
| 382 | | /* for each cpu */ |
| 383 | | for (device_t *device = machine->m_devicelist.first(); device != NULL; device = device->next()) |
| 384 | | { |
| 385 | | debug_cpu_comment_group *comments = device->debug()->m_comments; |
| 386 | | if (comments != NULL) |
| 387 | | { |
| 388 | | xml_data_node *curnode = xml_add_child(systemnode, "cpu", NULL); |
| 389 | | if (curnode == NULL) |
| 390 | | goto error; |
| 391 | | xml_set_attribute(curnode, "tag", device->tag()); |
| 392 | | |
| 393 | | for (j = 0; j < comments->comment_count; j++) |
| 394 | | { |
| 395 | | xml_data_node *datanode = xml_add_child(curnode, "comment", xml_normalize_string(comments->comment_info[j]->text)); |
| 396 | | if (datanode == NULL) |
| 397 | | goto error; |
| 398 | | xml_set_attribute_int(datanode, "address", comments->comment_info[j]->address); |
| 399 | | xml_set_attribute_int(datanode, "color", comments->comment_info[j]->color); |
| 400 | | sprintf(crc_buf, "%08X", comments->comment_info[j]->crc); |
| 401 | | xml_set_attribute(datanode, "crc", crc_buf); |
| 402 | | total_comments++; |
| 403 | | } |
| 404 | | } |
| 405 | | } |
| 406 | | |
| 407 | | /* flush the file */ |
| 408 | | if (total_comments > 0) |
| 409 | | { |
| 410 | | file_error filerr; |
| 411 | | mame_file *fp; |
| 412 | | |
| 413 | | astring fname(machine->basename(), ".cmt"); |
| 414 | | filerr = mame_fopen(SEARCHPATH_COMMENT, fname, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &fp); |
| 415 | | |
| 416 | | if (filerr == FILERR_NONE) |
| 417 | | { |
| 418 | | xml_file_write(root, mame_core_file(fp)); |
| 419 | | mame_fclose(fp); |
| 420 | | } |
| 421 | | } |
| 422 | | |
| 423 | | /* free and get out of here */ |
| 424 | | xml_file_free(root); |
| 425 | | return 1; |
| 426 | | |
| 427 | | error: |
| 428 | | xml_file_free(root); |
| 429 | | return 0; |
| 430 | | } |
| 431 | | |
| 432 | | |
| 433 | | /*------------------------------------------------------------------------- |
| 434 | | debug_comment_load(_xml) - comment file loading |
| 435 | | -------------------------------------------------------------------------*/ |
| 436 | | |
| 437 | | int debug_comment_load(running_machine *machine) |
| 438 | | { |
| 439 | | file_error filerr; |
| 440 | | mame_file *fp; |
| 441 | | |
| 442 | | astring fname(machine->basename(), ".cmt"); |
| 443 | | filerr = mame_fopen(SEARCHPATH_COMMENT, fname, OPEN_FLAG_READ, &fp); |
| 444 | | |
| 445 | | if (filerr != FILERR_NONE) return 0; |
| 446 | | debug_comment_load_xml(machine, fp); |
| 447 | | mame_fclose(fp); |
| 448 | | |
| 449 | | return 1; |
| 450 | | } |
| 451 | | |
| 452 | | static int debug_comment_load_xml(running_machine *machine, mame_file *fp) |
| 453 | | { |
| 454 | | int j; |
| 455 | | xml_data_node *root, *commentnode, *systemnode, *cpunode, *datanode; |
| 456 | | const char *name; |
| 457 | | int version; |
| 458 | | |
| 459 | | /* read the file */ |
| 460 | | root = xml_file_read(mame_core_file(fp), NULL); |
| 461 | | if (root == NULL) |
| 462 | | goto error; |
| 463 | | |
| 464 | | /* find the config node */ |
| 465 | | commentnode = xml_get_sibling(root->child, "mamecommentfile"); |
| 466 | | if (commentnode == NULL) |
| 467 | | goto error; |
| 468 | | |
| 469 | | /* validate the config data version */ |
| 470 | | version = xml_get_attribute_int(commentnode, "version", 0); |
| 471 | | if (version != COMMENT_VERSION) |
| 472 | | goto error; |
| 473 | | |
| 474 | | /* check to make sure the file is applicable */ |
| 475 | | systemnode = xml_get_sibling(commentnode->child, "system"); |
| 476 | | name = xml_get_attribute_string(systemnode, "name", ""); |
| 477 | | if (strcmp(name, machine->gamedrv->name) != 0) |
| 478 | | goto error; |
| 479 | | |
| 480 | | for (cpunode = xml_get_sibling(systemnode->child, "cpu"); cpunode; cpunode = xml_get_sibling(cpunode->next, "cpu")) |
| 481 | | { |
| 482 | | device_t *cpu = machine->device(xml_get_attribute_string(cpunode, "tag", "")); |
| 483 | | if (cpu != NULL) |
| 484 | | { |
| 485 | | debug_cpu_comment_group *comments = cpu->debug()->m_comments; |
| 486 | | j = 0; |
| 487 | | |
| 488 | | for (datanode = xml_get_sibling(cpunode->child, "comment"); datanode; datanode = xml_get_sibling(datanode->next, "comment")) |
| 489 | | { |
| 490 | | /* Malloc the comment */ |
| 491 | | comments->comment_info[j] = auto_alloc(machine, debug_comment); |
| 492 | | |
| 493 | | comments->comment_info[j]->address = xml_get_attribute_int(datanode, "address", 0); |
| 494 | | comments->comment_info[j]->color = xml_get_attribute_int(datanode, "color", 0); |
| 495 | | sscanf(xml_get_attribute_string(datanode, "crc", 0), "%08X", &comments->comment_info[j]->crc); |
| 496 | | strcpy(comments->comment_info[j]->text, datanode->value); |
| 497 | | comments->comment_info[j]->is_valid = 1; |
| 498 | | |
| 499 | | j++; |
| 500 | | } |
| 501 | | |
| 502 | | comments->comment_count = j; |
| 503 | | } |
| 504 | | } |
| 505 | | |
| 506 | | /* free the parser */ |
| 507 | | xml_file_free(root); |
| 508 | | |
| 509 | | return 1; |
| 510 | | |
| 511 | | error: |
| 512 | | if (root) |
| 513 | | xml_file_free(root); |
| 514 | | return 0; |
| 515 | | } |
| 516 | | |
| 517 | | |
| 518 | | /*------------------------------------------------------------------------- |
| 519 | | debug_comment_exit - saves the comments and frees memory |
| 520 | | -------------------------------------------------------------------------*/ |
| 521 | | |
| 522 | | static void debug_comment_exit(running_machine &machine) |
| 523 | | { |
| 524 | | debug_comment_save(&machine); |
| 525 | | } |
src/emu/debug/debugcpu.c
| r9050 | r9051 | |
| 38 | 38 | ***************************************************************************/ |
| 39 | 39 | |
| 40 | 40 | #include "emu.h" |
| 41 | #include "emuopts.h" |
| 41 | 42 | #include "osdepend.h" |
| 42 | 43 | #include "debugcpu.h" |
| 43 | 44 | #include "debugcmd.h" |
| 44 | | #include "debugcmt.h" |
| 45 | 45 | #include "debugcon.h" |
| 46 | 46 | #include "express.h" |
| 47 | 47 | #include "debugvw.h" |
| 48 | 48 | #include "debugger.h" |
| 49 | 49 | #include "debugint/debugint.h" |
| 50 | 50 | #include "uiinput.h" |
| 51 | #include "xmlfile.h" |
| 51 | 52 | #include <ctype.h> |
| 53 | #include <zlib.h> |
| 52 | 54 | |
| 53 | 55 | |
| 54 | 56 | |
| r9050 | r9051 | |
| 96 | 98 | UINT64 tempvar[NUM_TEMP_VARIABLES]; |
| 97 | 99 | |
| 98 | 100 | osd_ticks_t last_periodic_update_time; |
| 101 | |
| 102 | bool comments_loaded; |
| 99 | 103 | }; |
| 100 | 104 | |
| 101 | 105 | |
| r9050 | r9051 | |
| 184 | 188 | symtable_add_register(global->symtable, symname, &global->tempvar[regnum], get_tempvar, set_tempvar); |
| 185 | 189 | } |
| 186 | 190 | |
| 187 | | /* loop over devices and build up their info */ |
| 188 | | for (device_t *device = machine->m_devicelist.first(); device != NULL; device = device->next()) |
| 189 | | device->set_debug(*auto_alloc(machine, device_debug(*device, global->symtable))); |
| 190 | | |
| 191 | 191 | /* first CPU is visible by default */ |
| 192 | 192 | global->visiblecpu = machine->firstcpu; |
| 193 | 193 | |
| r9050 | r9051 | |
| 313 | 313 | |
| 314 | 314 | |
| 315 | 315 | |
| 316 | //************************************************************************** |
| 317 | // MEMORY AND DISASSEMBLY HELPERS |
| 318 | //************************************************************************** |
| 319 | |
| 320 | //------------------------------------------------- |
| 321 | // debug_comment_save - save all comments for |
| 322 | // the given machine |
| 323 | //------------------------------------------------- |
| 324 | |
| 325 | bool debug_comment_save(running_machine *machine) |
| 326 | { |
| 327 | // if we don't have a root, bail |
| 328 | xml_data_node *root = xml_file_create(); |
| 329 | if (root == NULL) |
| 330 | return false; |
| 331 | |
| 332 | // wrap in a try/catch to handle errors |
| 333 | try |
| 334 | { |
| 335 | // create a comment node |
| 336 | xml_data_node *commentnode = xml_add_child(root, "mamecommentfile", NULL); |
| 337 | if (commentnode == NULL) |
| 338 | throw emu_exception(); |
| 339 | xml_set_attribute_int(commentnode, "version", COMMENT_VERSION); |
| 340 | |
| 341 | // create a system node |
| 342 | xml_data_node *systemnode = xml_add_child(commentnode, "system", NULL); |
| 343 | if (systemnode == NULL) |
| 344 | throw emu_exception(); |
| 345 | xml_set_attribute(systemnode, "name", machine->gamedrv->name); |
| 346 | |
| 347 | // for each device |
| 348 | bool found_comments = false; |
| 349 | for (device_t *device = machine->m_devicelist.first(); device != NULL; device = device->next()) |
| 350 | if (device->debug()->comment_count() > 0) |
| 351 | { |
| 352 | // create a node for this device |
| 353 | xml_data_node *curnode = xml_add_child(systemnode, "cpu", NULL); |
| 354 | if (curnode == NULL) |
| 355 | throw emu_exception(); |
| 356 | xml_set_attribute(curnode, "tag", device->tag()); |
| 357 | |
| 358 | // export the comments |
| 359 | if (!device->debug()->comment_export(*curnode)) |
| 360 | throw emu_exception(); |
| 361 | found_comments = true; |
| 362 | } |
| 363 | |
| 364 | // flush the file |
| 365 | if (found_comments) |
| 366 | { |
| 367 | astring fname(machine->basename(), ".cmt"); |
| 368 | mame_file *fp; |
| 369 | file_error filerr = mame_fopen(SEARCHPATH_COMMENT, fname, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &fp); |
| 370 | |
| 371 | if (filerr == FILERR_NONE) |
| 372 | { |
| 373 | xml_file_write(root, mame_core_file(fp)); |
| 374 | mame_fclose(fp); |
| 375 | } |
| 376 | } |
| 377 | } |
| 378 | catch (emu_exception &) |
| 379 | { |
| 380 | xml_file_free(root); |
| 381 | return false; |
| 382 | } |
| 383 | |
| 384 | // free and get out of here |
| 385 | xml_file_free(root); |
| 386 | return true; |
| 387 | } |
| 388 | |
| 389 | |
| 390 | //------------------------------------------------- |
| 391 | // debug_comment_load - load all comments for |
| 392 | // the given machine |
| 393 | //------------------------------------------------- |
| 394 | |
| 395 | bool debug_comment_load(running_machine *machine) |
| 396 | { |
| 397 | // open the file |
| 398 | astring fname(machine->basename(), ".cmt"); |
| 399 | mame_file *fp; |
| 400 | file_error filerr = mame_fopen(SEARCHPATH_COMMENT, fname, OPEN_FLAG_READ, &fp); |
| 401 | |
| 402 | // if an error, just return false |
| 403 | if (filerr != FILERR_NONE) |
| 404 | return false; |
| 405 | |
| 406 | // wrap in a try/catch to handle errors |
| 407 | xml_data_node *root = xml_file_read(mame_core_file(fp), NULL); |
| 408 | try |
| 409 | { |
| 410 | // read the file |
| 411 | if (root == NULL) |
| 412 | throw emu_exception(); |
| 413 | |
| 414 | // find the config node |
| 415 | xml_data_node *commentnode = xml_get_sibling(root->child, "mamecommentfile"); |
| 416 | if (commentnode == NULL) |
| 417 | throw emu_exception(); |
| 418 | |
| 419 | // validate the config data version |
| 420 | int version = xml_get_attribute_int(commentnode, "version", 0); |
| 421 | if (version != COMMENT_VERSION) |
| 422 | throw emu_exception(); |
| 423 | |
| 424 | // check to make sure the file is applicable |
| 425 | xml_data_node *systemnode = xml_get_sibling(commentnode->child, "system"); |
| 426 | const char *name = xml_get_attribute_string(systemnode, "name", ""); |
| 427 | if (strcmp(name, machine->gamedrv->name) != 0) |
| 428 | throw emu_exception(); |
| 429 | |
| 430 | // iterate over devices |
| 431 | for (xml_data_node *cpunode = xml_get_sibling(systemnode->child, "cpu"); cpunode; cpunode = xml_get_sibling(cpunode->next, "cpu")) |
| 432 | { |
| 433 | device_t *device = machine->device(xml_get_attribute_string(cpunode, "tag", "")); |
| 434 | if (device != NULL) |
| 435 | if (!device->debug()->comment_import(*cpunode)) |
| 436 | throw emu_exception(); |
| 437 | } |
| 438 | } |
| 439 | catch (emu_exception &) |
| 440 | { |
| 441 | // clean up in case of error |
| 442 | if (root != NULL) |
| 443 | xml_file_free(root); |
| 444 | mame_fclose(fp); |
| 445 | return false; |
| 446 | } |
| 447 | |
| 448 | // free the parser |
| 449 | xml_file_free(root); |
| 450 | mame_fclose(fp); |
| 451 | return true; |
| 452 | } |
| 453 | |
| 454 | |
| 455 | |
| 316 | 456 | /*************************************************************************** |
| 317 | 457 | MEMORY AND DISASSEMBLY HELPERS |
| 318 | 458 | ***************************************************************************/ |
| r9050 | r9051 | |
| 1562 | 1702 | // device_debug - constructor |
| 1563 | 1703 | //------------------------------------------------- |
| 1564 | 1704 | |
| 1565 | | device_debug::device_debug(device_t &device, symbol_table *globalsyms) |
| 1705 | device_debug::device_debug(device_t &device) |
| 1566 | 1706 | : m_device(device), |
| 1567 | 1707 | m_exec(NULL), |
| 1568 | 1708 | m_memory(NULL), |
| 1569 | 1709 | m_state(NULL), |
| 1570 | 1710 | m_disasm(NULL), |
| 1571 | 1711 | m_flags(0), |
| 1572 | | m_symtable(symtable_alloc(globalsyms, (void *)&device)), |
| 1712 | m_symtable(symtable_alloc(debug_cpu_get_global_symtable(device.machine), (void *)&device)), |
| 1573 | 1713 | m_instrhook(NULL), |
| 1574 | 1714 | m_dasm_override(NULL), |
| 1575 | 1715 | m_opwidth(0), |
| r9050 | r9051 | |
| 1585 | 1725 | m_trace(NULL), |
| 1586 | 1726 | m_hotspots(NULL), |
| 1587 | 1727 | m_hotspot_count(0), |
| 1588 | | m_hotspot_threshhold(0), |
| 1589 | | m_comments(NULL) |
| 1728 | m_hotspot_threshhold(0) |
| 1590 | 1729 | { |
| 1591 | 1730 | memset(m_pc_history, 0, sizeof(m_pc_history)); |
| 1592 | 1731 | memset(m_wplist, 0, sizeof(m_wplist)); |
| r9050 | r9051 | |
| 1843 | 1982 | if (global->execution_state == EXECUTION_STATE_STOPPED) |
| 1844 | 1983 | { |
| 1845 | 1984 | int firststop = true; |
| 1985 | |
| 1986 | // load comments if we haven't yet |
| 1987 | if (!global->comments_loaded) |
| 1988 | { |
| 1989 | debug_comment_load(m_device.machine); |
| 1990 | global->comments_loaded = true; |
| 1991 | } |
| 1846 | 1992 | |
| 1847 | 1993 | // reset any transient state |
| 1848 | 1994 | reset_transient_flags(*m_device.machine); |
| r9050 | r9051 | |
| 1949 | 2095 | // PC on a given device |
| 1950 | 2096 | //------------------------------------------------- |
| 1951 | 2097 | |
| 1952 | | offs_t device_debug::disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram) |
| 2098 | offs_t device_debug::disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram) const |
| 1953 | 2099 | { |
| 1954 | 2100 | offs_t result = 0; |
| 1955 | 2101 | |
| r9050 | r9051 | |
| 2415 | 2561 | |
| 2416 | 2562 | |
| 2417 | 2563 | //------------------------------------------------- |
| 2564 | // comment_add - adds a comment to the list at |
| 2565 | // the given address |
| 2566 | //------------------------------------------------- |
| 2567 | |
| 2568 | void device_debug::comment_add(offs_t addr, const char *comment, rgb_t color) |
| 2569 | { |
| 2570 | // create a new item for the list |
| 2571 | UINT32 crc = compute_opcode_crc32(addr); |
| 2572 | dasm_comment *newcomment = auto_alloc(m_device.machine, dasm_comment(comment, addr, color, crc)); |
| 2573 | |
| 2574 | // figure out where to insert it |
| 2575 | dasm_comment *prev = NULL; |
| 2576 | dasm_comment *curr; |
| 2577 | for (curr = m_comment_list.first(); curr != NULL; prev = curr, curr = curr->next()) |
| 2578 | if (curr->m_address >= addr) |
| 2579 | break; |
| 2580 | |
| 2581 | // we could be the new head |
| 2582 | if (prev == NULL) |
| 2583 | m_comment_list.prepend(*newcomment); |
| 2584 | |
| 2585 | // or else we just insert ourselves here |
| 2586 | else |
| 2587 | { |
| 2588 | newcomment->m_next = prev->m_next; |
| 2589 | prev->m_next = newcomment; |
| 2590 | } |
| 2591 | |
| 2592 | // scan forward from here to delete any exact matches |
| 2593 | for ( ; curr != NULL && curr->m_address == addr; curr = curr->next()) |
| 2594 | if (curr->m_crc == crc) |
| 2595 | { |
| 2596 | m_comment_list.remove(*curr); |
| 2597 | break; |
| 2598 | } |
| 2599 | |
| 2600 | // force an update |
| 2601 | m_comment_change++; |
| 2602 | } |
| 2603 | |
| 2604 | |
| 2605 | //------------------------------------------------- |
| 2606 | // comment_remove - removes a comment at the |
| 2607 | // given address with a matching CRC |
| 2608 | //------------------------------------------------- |
| 2609 | |
| 2610 | bool device_debug::comment_remove(offs_t addr) |
| 2611 | { |
| 2612 | // scan the list for a match |
| 2613 | UINT32 crc = compute_opcode_crc32(addr); |
| 2614 | for (dasm_comment *curr = m_comment_list.first(); curr != NULL; curr = curr->next()) |
| 2615 | { |
| 2616 | // if we're past the address, we failed |
| 2617 | if (curr->m_address > addr) |
| 2618 | break; |
| 2619 | |
| 2620 | // find an exact match |
| 2621 | if (curr->m_address == addr && curr->m_crc == crc) |
| 2622 | { |
| 2623 | // remove it and force an update |
| 2624 | m_comment_list.remove(*curr); |
| 2625 | m_comment_change++; |
| 2626 | return true; |
| 2627 | } |
| 2628 | } |
| 2629 | |
| 2630 | // failure is an option |
| 2631 | return false; |
| 2632 | } |
| 2633 | |
| 2634 | |
| 2635 | //------------------------------------------------- |
| 2636 | // comment_text - return the text of a comment |
| 2637 | //------------------------------------------------- |
| 2638 | |
| 2639 | const char *device_debug::comment_text(offs_t addr) const |
| 2640 | { |
| 2641 | // scan the list for a match |
| 2642 | UINT32 crc = compute_opcode_crc32(addr); |
| 2643 | for (dasm_comment *curr = m_comment_list.first(); curr != NULL; curr = curr->next()) |
| 2644 | { |
| 2645 | // if we're past the address, we failed |
| 2646 | if (curr->m_address > addr) |
| 2647 | break; |
| 2648 | |
| 2649 | // find an exact match |
| 2650 | if (curr->m_address == addr && curr->m_crc == crc) |
| 2651 | return curr->m_text; |
| 2652 | } |
| 2653 | |
| 2654 | // failure is an option |
| 2655 | return NULL; |
| 2656 | } |
| 2657 | |
| 2658 | |
| 2659 | //------------------------------------------------- |
| 2660 | // comment_export - export the comments to the |
| 2661 | // given XML data node |
| 2662 | //------------------------------------------------- |
| 2663 | |
| 2664 | bool device_debug::comment_export(xml_data_node &curnode) |
| 2665 | { |
| 2666 | // iterate through the comments |
| 2667 | astring crc_buf; |
| 2668 | for (dasm_comment *curr = m_comment_list.first(); curr != NULL; curr = curr->next()) |
| 2669 | { |
| 2670 | xml_data_node *datanode = xml_add_child(&curnode, "comment", xml_normalize_string(curr->m_text)); |
| 2671 | if (datanode == NULL) |
| 2672 | return false; |
| 2673 | xml_set_attribute_int(datanode, "address", curr->m_address); |
| 2674 | xml_set_attribute_int(datanode, "color", curr->m_color); |
| 2675 | crc_buf.printf("%08X", curr->m_crc); |
| 2676 | xml_set_attribute(datanode, "crc", crc_buf); |
| 2677 | } |
| 2678 | return true; |
| 2679 | } |
| 2680 | |
| 2681 | |
| 2682 | //------------------------------------------------- |
| 2683 | // comment_import - import the comments from the |
| 2684 | // given XML data node |
| 2685 | //------------------------------------------------- |
| 2686 | |
| 2687 | bool device_debug::comment_import(xml_data_node &cpunode) |
| 2688 | { |
| 2689 | // iterate through nodes |
| 2690 | for (xml_data_node *datanode = xml_get_sibling(cpunode.child, "comment"); datanode; datanode = xml_get_sibling(datanode->next, "comment")) |
| 2691 | { |
| 2692 | // extract attributes |
| 2693 | offs_t address = xml_get_attribute_int(datanode, "address", 0); |
| 2694 | rgb_t color = xml_get_attribute_int(datanode, "color", 0); |
| 2695 | UINT32 crc; |
| 2696 | sscanf(xml_get_attribute_string(datanode, "crc", 0), "%08X", &crc); |
| 2697 | |
| 2698 | // add the new comment; we assume they were saved ordered |
| 2699 | m_comment_list.append(*auto_alloc(m_device.machine, dasm_comment(datanode->value, address, color, crc))); |
| 2700 | } |
| 2701 | return true; |
| 2702 | } |
| 2703 | |
| 2704 | |
| 2705 | //------------------------------------------------- |
| 2706 | // comment_dump - logs comments to the error.log |
| 2707 | // at a given address |
| 2708 | //------------------------------------------------- |
| 2709 | |
| 2710 | void device_debug::comment_dump(offs_t addr) |
| 2711 | { |
| 2712 | // determine the CRC at the given address (if valid) |
| 2713 | UINT32 crc = (addr == ~0) ? 0 : compute_opcode_crc32(addr); |
| 2714 | |
| 2715 | // dump everything that matches |
| 2716 | bool found = false; |
| 2717 | for (dasm_comment *curr = m_comment_list.first(); curr != NULL; curr = curr->next()) |
| 2718 | if (addr == ~0 || (curr->m_address == addr && curr->m_crc == crc)) |
| 2719 | { |
| 2720 | found = true; |
| 2721 | logerror("%08X %08X - %s\n", curr->m_address, curr->m_crc, curr->m_text.cstr()); |
| 2722 | } |
| 2723 | |
| 2724 | // if nothing found, indicate as much |
| 2725 | if (!found) |
| 2726 | logerror("No comment exists for address : 0x%x\n", addr); |
| 2727 | } |
| 2728 | |
| 2729 | |
| 2730 | //------------------------------------------------- |
| 2731 | // compute_opcode_crc32 - determine the CRC of |
| 2732 | // the opcode bytes at the given address |
| 2733 | //------------------------------------------------- |
| 2734 | |
| 2735 | UINT32 device_debug::compute_opcode_crc32(offs_t address) const |
| 2736 | { |
| 2737 | // no memory interface, just fail |
| 2738 | if (m_memory == NULL) |
| 2739 | return 0; |
| 2740 | |
| 2741 | // no program interface, just fail |
| 2742 | address_space *space = m_memory->space(AS_PROGRAM); |
| 2743 | if (space == NULL) |
| 2744 | return 0; |
| 2745 | |
| 2746 | // zero out the buffers |
| 2747 | UINT8 opbuf[64], argbuf[64]; |
| 2748 | memset(opbuf, 0x00, sizeof(opbuf)); |
| 2749 | memset(argbuf, 0x00, sizeof(argbuf)); |
| 2750 | |
| 2751 | // fetch the bytes up to the maximum |
| 2752 | int maxbytes = m_disasm->max_opcode_bytes(); |
| 2753 | for (int index = 0; index < maxbytes; index++) |
| 2754 | { |
| 2755 | opbuf[index] = debug_read_opcode(space, address + index, 1, false); |
| 2756 | argbuf[index] = debug_read_opcode(space, address + index, 1, true); |
| 2757 | } |
| 2758 | |
| 2759 | // disassemble and then convert to bytes |
| 2760 | char buff[256]; |
| 2761 | int numbytes = disassemble(buff, address & space->logaddrmask(), opbuf, argbuf) & DASMFLAG_LENGTHMASK; |
| 2762 | numbytes = space->address_to_byte(numbytes); |
| 2763 | |
| 2764 | // return a CRC of the resulting bytes |
| 2765 | return crc32(0, argbuf, numbytes); |
| 2766 | } |
| 2767 | |
| 2768 | |
| 2769 | //------------------------------------------------- |
| 2418 | 2770 | // trace - trace execution of a given device |
| 2419 | 2771 | //------------------------------------------------- |
| 2420 | 2772 | |
| r9050 | r9051 | |
| 3067 | 3419 | fflush(&m_file); |
| 3068 | 3420 | } |
| 3069 | 3421 | |
| 3422 | |
| 3423 | //------------------------------------------------- |
| 3424 | // dasm_comment - constructor |
| 3425 | //------------------------------------------------- |
| 3426 | |
| 3427 | device_debug::dasm_comment::dasm_comment(const char *text, offs_t address, rgb_t color, UINT32 crc) |
| 3428 | : m_next(NULL), |
| 3429 | m_address(address), |
| 3430 | m_color(color), |
| 3431 | m_crc(crc), |
| 3432 | m_text(text) |
| 3433 | { |
| 3434 | } |
src/emu/debug/debugcpu.h
| r9050 | r9051 | |
| 53 | 53 | const UINT8 WATCHPOINT_WRITE = 2; |
| 54 | 54 | const UINT8 WATCHPOINT_READWRITE = WATCHPOINT_READ | WATCHPOINT_WRITE; |
| 55 | 55 | |
| 56 | const int COMMENT_VERSION = 1; |
| 56 | 57 | |
| 57 | 58 | |
| 59 | |
| 58 | 60 | //************************************************************************** |
| 59 | 61 | // TYPE DEFINITIONS |
| 60 | 62 | //************************************************************************** |
| r9050 | r9051 | |
| 62 | 64 | typedef int (*debug_instruction_hook_func)(device_t &device, offs_t curpc); |
| 63 | 65 | |
| 64 | 66 | |
| 65 | | class debug_cpu_comment_group; |
| 67 | typedef struct _xml_data_node xml_data_node; |
| 66 | 68 | |
| 67 | 69 | |
| 68 | 70 | class device_debug |
| r9050 | r9051 | |
| 126 | 128 | bool hit(int type, offs_t address, int size); |
| 127 | 129 | |
| 128 | 130 | watchpoint * m_next; // next in the list |
| 129 | | address_space &m_space; // address space |
| 131 | address_space & m_space; // address space |
| 130 | 132 | int m_index; // user reported index |
| 131 | 133 | bool m_enabled; // enabled? |
| 132 | 134 | UINT8 m_type; // type (read/write) |
| r9050 | r9051 | |
| 138 | 140 | |
| 139 | 141 | public: |
| 140 | 142 | // construction/destruction |
| 141 | | device_debug(device_t &device, symbol_table *globalsyms); |
| 143 | device_debug(device_t &device); |
| 142 | 144 | ~device_debug(); |
| 143 | 145 | |
| 144 | 146 | // getters |
| r9050 | r9051 | |
| 164 | 166 | void set_dasm_override(dasm_override_func dasm_override) { m_dasm_override = dasm_override; } |
| 165 | 167 | |
| 166 | 168 | // disassembly |
| 167 | | offs_t disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram); |
| 169 | offs_t disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram) const; |
| 168 | 170 | |
| 169 | 171 | // debugger focus |
| 170 | 172 | void ignore(bool ignore = true); |
| r9050 | r9051 | |
| 203 | 205 | // hotspots |
| 204 | 206 | bool hotspot_tracking_enabled() const { return (m_hotspots != NULL); } |
| 205 | 207 | void hotspot_track(int numspots, int threshhold); |
| 208 | |
| 209 | // comments |
| 210 | void comment_add(offs_t address, const char *comment, rgb_t color); |
| 211 | bool comment_remove(offs_t addr); |
| 212 | const char *comment_text(offs_t addr) const; |
| 213 | UINT32 comment_count() const { return m_comment_list.count(); } |
| 214 | UINT32 comment_change_count() const { return m_comment_change; } |
| 215 | bool comment_export(xml_data_node &node); |
| 216 | bool comment_import(xml_data_node &node); |
| 217 | void comment_dump(offs_t addr = ~0); |
| 218 | UINT32 compute_opcode_crc32(offs_t address) const; |
| 206 | 219 | |
| 207 | 220 | // history |
| 208 | 221 | offs_t history_pc(int index) const; |
| r9050 | r9051 | |
| 304 | 317 | { |
| 305 | 318 | offs_t m_access; // access address |
| 306 | 319 | offs_t m_pc; // PC of the access |
| 307 | | address_space *m_space; // space where the access occurred |
| 320 | address_space * m_space; // space where the access occurred |
| 308 | 321 | UINT32 m_count; // number of hits |
| 309 | 322 | }; |
| 310 | 323 | hotspot_entry * m_hotspots; // hotspot list |
| 311 | 324 | int m_hotspot_count; // number of hotspots |
| 312 | 325 | int m_hotspot_threshhold; // threshhold for the number of hits to print |
| 313 | 326 | |
| 327 | // comments |
| 328 | class dasm_comment |
| 329 | { |
| 330 | public: |
| 331 | dasm_comment(const char *text, offs_t address, rgb_t color, UINT32 crc); |
| 332 | |
| 333 | dasm_comment *next() const { return m_next; } |
| 334 | |
| 335 | dasm_comment * m_next; // next comment in the list |
| 336 | offs_t m_address; // address in question |
| 337 | rgb_t m_color; // color to use |
| 338 | UINT32 m_crc; // CRC of code |
| 339 | astring m_text; // text |
| 340 | }; |
| 341 | simple_list<dasm_comment> m_comment_list; // list of comments |
| 342 | UINT32 m_comment_change; // change counter for comments |
| 343 | |
| 314 | 344 | // internal flag values |
| 315 | 345 | static const UINT32 DEBUG_FLAG_OBSERVING = 0x00000001; // observing this CPU |
| 316 | 346 | static const UINT32 DEBUG_FLAG_HISTORY = 0x00000002; // tracking this CPU's history |
| r9050 | r9051 | |
| 332 | 362 | static const UINT32 DEBUG_FLAG_TRACING_ANY = DEBUG_FLAG_TRACING | DEBUG_FLAG_TRACING_OVER; |
| 333 | 363 | static const UINT32 DEBUG_FLAG_TRANSIENT = DEBUG_FLAG_STEPPING_ANY | DEBUG_FLAG_STOP_PC | DEBUG_FLAG_STOP_CONTEXT | |
| 334 | 364 | DEBUG_FLAG_STOP_INTERRUPT | DEBUG_FLAG_STOP_EXCEPTION | DEBUG_FLAG_STOP_VBLANK | DEBUG_FLAG_STOP_TIME; |
| 335 | | |
| 336 | | public: // until comments get folded in |
| 337 | | debug_cpu_comment_group *m_comments; // disassembly comments |
| 338 | 365 | }; |
| 339 | 366 | |
| 340 | 367 | |
| r9050 | r9051 | |
| 391 | 418 | |
| 392 | 419 | |
| 393 | 420 | |
| 421 | /* ----- debugger comment helpers ----- */ |
| 422 | |
| 423 | // save all comments for a given machine |
| 424 | bool debug_comment_save(running_machine *machine); |
| 425 | |
| 426 | // load all comments for a given machine |
| 427 | bool debug_comment_load(running_machine *machine); |
| 428 | |
| 429 | |
| 430 | |
| 394 | 431 | /* ----- debugger memory accessors ----- */ |
| 395 | 432 | |
| 396 | 433 | /* return the physical address corresponding to the given logical address */ |
src/emu/devcb.h
| r9050 | r9051 | |
| 61 | 61 | MACROS |
| 62 | 62 | ***************************************************************************/ |
| 63 | 63 | |
| 64 | // static template for a read8 stub function that calls through a given READ8_MEMBER |
| 65 | template<class _Class, UINT8 (_Class::*_Function)(address_space &, offs_t, UINT8)> |
| 66 | UINT8 devcb_stub(device_t *device, offs_t offset) |
| 67 | { |
| 68 | _Class *target = downcast<_Class *>(device); |
| 69 | return (target->*_Function)(*device->machine->m_nonspecific_space, offset, 0xff); |
| 70 | } |
| 71 | |
| 72 | // static template for a write8 stub function that calls through a given WRITE8_MEMBER |
| 73 | template<class _Class, void (_Class::*_Function)(address_space &, offs_t, UINT8, UINT8)> |
| 74 | void devcb_stub(device_t *device, offs_t offset, UINT8 data) |
| 75 | { |
| 76 | _Class *target = downcast<_Class *>(device); |
| 77 | (target->*_Function)(*device->machine->m_nonspecific_space, offset, data, 0xff); |
| 78 | } |
| 79 | |
| 64 | 80 | #define DEVCB_NULL { DEVCB_TYPE_NULL } |
| 65 | 81 | |
| 66 | 82 | /* standard line or read/write handlers with the calling device passed */ |
| r9050 | r9051 | |
| 72 | 88 | /* line or read/write handlers for another device */ |
| 73 | 89 | #define DEVCB_DEVICE_LINE(tag,func) { DEVCB_TYPE_DEVICE, tag, (func), NULL, NULL } |
| 74 | 90 | #define DEVCB_DEVICE_HANDLER(tag,func) { DEVCB_TYPE_DEVICE, tag, NULL, (func), NULL } |
| 91 | #define DEVCB_DEVICE_MEMBER(tag,cls,memb) { DEVCB_TYPE_DEVICE, tag, NULL, &devcb_stub<cls, &cls::memb>, NULL } |
| 75 | 92 | |
| 76 | 93 | /* read/write handlers for a given CPU's address space */ |
| 77 | 94 | #define DEVCB_MEMORY_HANDLER(cpu,space,func) { DEVCB_TYPE_MEMORY(ADDRESS_SPACE_##space), (cpu), NULL, NULL, (func) } |
| r9050 | r9051 | |
| 102 | 119 | #define MDRV_DEVICE_CONFIG_READ_HANDLER(_struct, _entry, _tag, _func) MDRV_DEVICE_CONFIG_DEVCB_GENERIC(read, _struct, _entry, _tag, DEVCB_TYPE_DEVICE, NULL, _func, NULL) |
| 103 | 120 | #define MDRV_DEVICE_CONFIG_WRITE_HANDLER(_struct, _entry, _tag, _func) MDRV_DEVICE_CONFIG_DEVCB_GENERIC(write, _struct, _entry, _tag, DEVCB_TYPE_DEVICE, NULL, _func, NULL) |
| 104 | 121 | |
| 122 | |
| 123 | |
| 105 | 124 | /*************************************************************************** |
| 106 | 125 | TYPE DEFINITIONS |
| 107 | 126 | ***************************************************************************/ |
| r9050 | r9051 | |
| 110 | 129 | class device_config; |
| 111 | 130 | |
| 112 | 131 | |
| 113 | | /* read/write types for I/O lines (similar to read/write handlers but no offset) */ |
| 114 | | typedef int (*read_line_device_func)(device_t *device); |
| 115 | | typedef void (*write_line_device_func)(device_t *device, int state); |
| 116 | | |
| 117 | | |
| 118 | 132 | /* static structure used for device configuration when the desired callback type is a read_line_device_func */ |
| 119 | 133 | typedef struct _devcb_read_line devcb_read_line; |
| 120 | 134 | struct _devcb_read_line |
src/emu/machine.h
| r9050 | r9051 | |
| 278 | 278 | // holds generic pointers that are commonly used |
| 279 | 279 | struct generic_pointers |
| 280 | 280 | { |
| 281 | | generic_ptr nvram; // generic NVRAM |
| 282 | | UINT32 nvram_size; |
| 283 | 281 | generic_ptr videoram; // videoram |
| 284 | 282 | UINT32 videoram_size; |
| 285 | 283 | generic_ptr spriteram; // spriteram |
| r9050 | r9051 | |
| 617 | 615 | |
| 618 | 616 | protected: |
| 619 | 617 | // helpers called at startup |
| 620 | | virtual void find_devices(); |
| 621 | 618 | virtual void driver_start(); |
| 622 | 619 | virtual void machine_start(); |
| 623 | 620 | virtual void sound_start(); |
| r9050 | r9051 | |
| 633 | 630 | virtual void device_start(); |
| 634 | 631 | virtual void device_reset(); |
| 635 | 632 | |
| 636 | | // device locators |
| 637 | | template<class T> |
| 638 | | bool optional_device(T *&device, const char *tag) |
| 633 | // helper class to request auto-object discovery in the constructor of a derived class |
| 634 | class auto_finder_base |
| 639 | 635 | { |
| 640 | | device = downcast<T *>(m_machine.device<T>(tag)); |
| 641 | | return (device != NULL); |
| 642 | | } |
| 636 | public: |
| 637 | // construction/destruction |
| 638 | auto_finder_base(driver_device &base, const char *tag); |
| 639 | virtual ~auto_finder_base(); |
| 643 | 640 | |
| 644 | | template<class T> |
| 645 | | void required_device(T *&device, const char *tag) |
| 641 | // getters |
| 642 | virtual void findit(driver_device &base) = 0; |
| 643 | |
| 644 | // internal state |
| 645 | auto_finder_base *m_next; |
| 646 | const char *m_tag; |
| 647 | }; |
| 648 | |
| 649 | // templated version bound to a specific type |
| 650 | template<typename _TargetType, bool _Required> |
| 651 | class auto_finder_type : public auto_finder_base |
| 646 | 652 | { |
| 647 | | if (!optional_device(device, tag)) |
| 648 | | throw emu_fatalerror("Unable to find device '%s'", tag); |
| 649 | | } |
| 653 | public: |
| 654 | // construction/destruction |
| 655 | auto_finder_type(driver_device &base, const char *tag) |
| 656 | : auto_finder_base(base, tag), |
| 657 | m_target(NULL) { } |
| 650 | 658 | |
| 659 | // operators to make use transparent |
| 660 | operator _TargetType() { return m_target; } |
| 661 | operator _TargetType() const { return m_target; } |
| 662 | _TargetType operator->() { return m_target; } |
| 663 | |
| 664 | // setter for setting the object |
| 665 | void set_target(_TargetType target) |
| 666 | { |
| 667 | m_target = target; |
| 668 | if (target == 0 && _Required) |
| 669 | throw emu_fatalerror("Unable to find required object '%s'", this->m_tag); |
| 670 | } |
| 671 | |
| 672 | // internal state |
| 673 | _TargetType m_target; |
| 674 | }; |
| 675 | |
| 676 | // optional device finder |
| 677 | template<class _DeviceClass> |
| 678 | class optional_device : public auto_finder_type<_DeviceClass *, false> |
| 679 | { |
| 680 | public: |
| 681 | optional_device(driver_device &base, const char *tag) : auto_finder_type<_DeviceClass *, false>(base, tag) { } |
| 682 | virtual void findit(driver_device &base) { set_target(base.m_machine.device<_DeviceClass>(this->m_tag)); } |
| 683 | }; |
| 684 | |
| 685 | // required devices are similar but throw an error if they are not found |
| 686 | template<class _DeviceClass> |
| 687 | class required_device : public auto_finder_type<_DeviceClass *, true> |
| 688 | { |
| 689 | public: |
| 690 | required_device(driver_device &base, const char *tag) : auto_finder_type<_DeviceClass *, true>(base, tag) { } |
| 691 | virtual void findit(driver_device &base) { set_target(base.m_machine.device<_DeviceClass>(this->m_tag)); } |
| 692 | }; |
| 693 | |
| 694 | // optional shared pointer finder |
| 695 | template<typename _PointerType> |
| 696 | class optional_shared_ptr : public auto_finder_type<_PointerType *, false> |
| 697 | { |
| 698 | public: |
| 699 | optional_shared_ptr(driver_device &base, const char *tag) : auto_finder_type<_PointerType *, false>(base, tag) { } |
| 700 | virtual void findit(driver_device &base) { set_target(reinterpret_cast<_PointerType *>(memory_get_shared(base.m_machine, this->m_tag))); } |
| 701 | }; |
| 702 | |
| 703 | // required shared pointer finder |
| 704 | template<typename _PointerType> |
| 705 | class required_shared_ptr : public auto_finder_type<_PointerType *, true> |
| 706 | { |
| 707 | public: |
| 708 | required_shared_ptr(driver_device &base, const char *tag) : auto_finder_type<_PointerType *, true>(base, tag) { } |
| 709 | virtual void findit(driver_device &base) { set_target(reinterpret_cast<_PointerType *>(memory_get_shared(base.m_machine, this->m_tag))); } |
| 710 | }; |
| 711 | |
| 712 | // optional shared pointer size finder |
| 713 | class optional_shared_size : public auto_finder_type<size_t, false> |
| 714 | { |
| 715 | public: |
| 716 | optional_shared_size(driver_device &base, const char *tag) : auto_finder_type<size_t, false>(base, tag) { } |
| 717 | virtual void findit(driver_device &base) { size_t size; memory_get_shared(base.m_machine, this->m_tag, size); set_target(size); } |
| 718 | }; |
| 719 | |
| 720 | // required shared pointer size finder |
| 721 | class required_shared_size : public auto_finder_type<size_t, true> |
| 722 | { |
| 723 | public: |
| 724 | required_shared_size(driver_device &base, const char *tag) : auto_finder_type<size_t, true>(base, tag) { } |
| 725 | virtual void findit(driver_device &base) { size_t size; memory_get_shared(base.m_machine, this->m_tag, size); set_target(size); } |
| 726 | }; |
| 727 | |
| 728 | // internal helpers |
| 729 | void register_auto_finder(auto_finder_base &autodev); |
| 730 | |
| 651 | 731 | // internal state |
| 652 | 732 | const driver_device_config_base &m_config; |
| 733 | auto_finder_base *m_auto_finder_list; |
| 653 | 734 | }; |
| 654 | 735 | |
| 655 | 736 | |
src/emu/memory.c
| r9050 | r9051 | |
| 224 | 224 | // banking constants |
| 225 | 225 | const int BANK_ENTRY_UNSPECIFIED = -1; |
| 226 | 226 | |
| 227 | | // shares are initially mapped to this invalid pointer |
| 228 | | static void *UNMAPPED_SHARE_PTR = ((void *)-1); |
| 229 | | |
| 230 | 227 | // other address map constants |
| 231 | 228 | const int MEMORY_BLOCK_CHUNK = 65536; // minimum chunk size of allocated memory blocks |
| 232 | 229 | |
| r9050 | r9051 | |
| 392 | 389 | }; |
| 393 | 390 | |
| 394 | 391 | |
| 392 | // ======================> memory_share |
| 393 | |
| 394 | // a memory share contains information about shared memory region |
| 395 | class memory_share |
| 396 | { |
| 397 | public: |
| 398 | // construction/destruction |
| 399 | memory_share(size_t size, void *ptr = NULL) |
| 400 | : m_ptr(ptr), |
| 401 | m_size(size) { } |
| 402 | |
| 403 | // getters |
| 404 | void *ptr() const { return m_ptr; } |
| 405 | size_t size() const { return m_size; } |
| 406 | |
| 407 | // setters |
| 408 | void set_ptr(void *ptr) { m_ptr = ptr; } |
| 409 | |
| 410 | private: |
| 411 | // internal state |
| 412 | void * m_ptr; // pointer to the memory backing the region |
| 413 | size_t m_size; // size of the shared region |
| 414 | }; |
| 415 | |
| 416 | |
| 395 | 417 | // ======================> handler_entry |
| 396 | 418 | |
| 397 | 419 | // a handler entry contains information about a memory handler |
| r9050 | r9051 | |
| 1499 | 1521 | tagmap_t<memory_bank *> bankmap; // map for fast bank lookups |
| 1500 | 1522 | UINT8 banknext; // next bank to allocate |
| 1501 | 1523 | |
| 1502 | | tagmap_t<void *> sharemap; // map for share lookups |
| 1524 | tagmap_t<memory_share *> sharemap; // map for share lookups |
| 1503 | 1525 | }; |
| 1504 | 1526 | |
| 1505 | 1527 | |
| r9050 | r9051 | |
| 1676 | 1698 | |
| 1677 | 1699 | |
| 1678 | 1700 | //------------------------------------------------- |
| 1701 | // memory_get_shared - get a pointer to a shared |
| 1702 | // memory region by tag |
| 1703 | //------------------------------------------------- |
| 1704 | |
| 1705 | void *memory_get_shared(running_machine &machine, const char *tag) |
| 1706 | { |
| 1707 | size_t size; |
| 1708 | return memory_get_shared(machine, tag, size); |
| 1709 | } |
| 1710 | |
| 1711 | void *memory_get_shared(running_machine &machine, const char *tag, size_t &length) |
| 1712 | { |
| 1713 | memory_share *share = machine.memory_data->sharemap.find(tag); |
| 1714 | if (share == NULL) |
| 1715 | return NULL; |
| 1716 | length = share->size(); |
| 1717 | return share->ptr(); |
| 1718 | } |
| 1719 | |
| 1720 | |
| 1721 | //------------------------------------------------- |
| 1679 | 1722 | // memory_dump - dump the internal memory tables |
| 1680 | 1723 | // to the given file |
| 1681 | 1724 | //------------------------------------------------- |
| r9050 | r9051 | |
| 1908 | 1951 | // make a pass over the address map, adjusting for the device and getting memory pointers |
| 1909 | 1952 | for (address_map_entry *entry = m_map->m_entrylist.first(); entry != NULL; entry = entry->next()) |
| 1910 | 1953 | { |
| 1911 | | // if we have a share entry, add it to our map |
| 1912 | | if (entry->m_share != NULL) |
| 1913 | | m_machine.memory_data->sharemap.add(entry->m_share, UNMAPPED_SHARE_PTR, false); |
| 1914 | | |
| 1915 | 1954 | // computed adjusted addresses first |
| 1916 | 1955 | entry->m_bytestart = entry->m_addrstart; |
| 1917 | 1956 | entry->m_byteend = entry->m_addrend; |
| r9050 | r9051 | |
| 1919 | 1958 | entry->m_bytemask = entry->m_addrmask; |
| 1920 | 1959 | adjust_addresses(entry->m_bytestart, entry->m_byteend, entry->m_bytemask, entry->m_bytemirror); |
| 1921 | 1960 | |
| 1961 | // if we have a share entry, add it to our map |
| 1962 | if (entry->m_share != NULL && m_machine.memory_data->sharemap.find(entry->m_share) == NULL) |
| 1963 | { |
| 1964 | memory_share *share = auto_alloc(&m_machine, memory_share(entry->m_byteend + 1 - entry->m_bytestart)); |
| 1965 | m_machine.memory_data->sharemap.add(entry->m_share, share, false); |
| 1966 | } |
| 1967 | |
| 1922 | 1968 | // if this is a ROM handler without a specified region, attach it to the implicit region |
| 1923 | 1969 | if (m_spacenum == ADDRESS_SPACE_0 && entry->m_read.m_type == AMH_ROM && entry->m_region == NULL) |
| 1924 | 1970 | { |
| r9050 | r9051 | |
| 2274 | 2320 | // if we haven't assigned this block yet, see if we have a mapped shared pointer for it |
| 2275 | 2321 | if (entry->m_memory == NULL && entry->m_share != NULL) |
| 2276 | 2322 | { |
| 2277 | | void *shareptr = memdata->sharemap.find(entry->m_share); |
| 2278 | | if (shareptr != UNMAPPED_SHARE_PTR) |
| 2323 | memory_share *share = memdata->sharemap.find(entry->m_share); |
| 2324 | if (share != NULL && share->ptr() != NULL) |
| 2279 | 2325 | { |
| 2280 | | entry->m_memory = shareptr; |
| 2326 | entry->m_memory = share->ptr(); |
| 2281 | 2327 | VPRINTF(("memory range %08X-%08X -> shared_ptr '%s' [%p]\n", entry->m_addrstart, entry->m_addrend, entry->m_share, entry->m_memory)); |
| 2282 | 2328 | } |
| 2283 | 2329 | } |
| r9050 | r9051 | |
| 2292 | 2338 | // if we're the first match on a shared pointer, assign it now |
| 2293 | 2339 | if (entry->m_memory != NULL && entry->m_share != NULL) |
| 2294 | 2340 | { |
| 2295 | | void *shareptr = memdata->sharemap.find(entry->m_share); |
| 2296 | | if (shareptr == UNMAPPED_SHARE_PTR) |
| 2297 | | memdata->sharemap.add(entry->m_share, entry->m_memory, TRUE); |
| 2341 | memory_share *share = memdata->sharemap.find(entry->m_share); |
| 2342 | if (share != NULL && share->ptr() == NULL) |
| 2343 | share->set_ptr(entry->m_memory); |
| 2298 | 2344 | } |
| 2299 | 2345 | |
| 2300 | 2346 | // keep track of the first unassigned entry |
| r9050 | r9051 | |
| 2956 | 3002 | // if we are asked to provide a base pointer, then yes, we do need backing |
| 2957 | 3003 | if (entry->m_baseptr != NULL || entry->m_baseptroffs_plus1 != 0 || entry->m_genbaseptroffs_plus1 != 0) |
| 2958 | 3004 | return true; |
| 3005 | |
| 3006 | // if we are sharing, and we don't have a pointer yet, create one |
| 3007 | if (entry->m_share != NULL) |
| 3008 | { |
| 3009 | memory_share *share = m_machine.memory_data->sharemap.find(entry->m_share); |
| 3010 | if (share != NULL && share->ptr() == NULL) |
| 3011 | return true; |
| 3012 | } |
| 2959 | 3013 | |
| 2960 | 3014 | // if we're writing to any sort of bank or RAM, then yes, we do need backing |
| 2961 | 3015 | if (entry->m_write.m_type == AMH_BANK || entry->m_write.m_type == AMH_RAM) |
src/emu/machine/nvram.c
| r0 | r9051 | |
| 1 | /*************************************************************************** |
| 2 | |
| 3 | nvram.c |
| 4 | |
| 5 | Generic non-volatile RAM. |
| 6 | |
| 7 | **************************************************************************** |
| 8 | |
| 9 | Copyright Aaron Giles |
| 10 | All rights reserved. |
| 11 | |
| 12 | Redistribution and use in source and binary forms, with or without |
| 13 | modification, are permitted provided that the following conditions are |
| 14 | met: |
| 15 | |
| 16 | * Redistributions of source code must retain the above copyright |
| 17 | notice, this list of conditions and the following disclaimer. |
| 18 | * Redistributions in binary form must reproduce the above copyright |
| 19 | notice, this list of conditions and the following disclaimer in |
| 20 | the documentation and/or other materials provided with the |
| 21 | distribution. |
| 22 | * Neither the name 'MAME' nor the names of its contributors may be |
| 23 | used to endorse or promote products derived from this software |
| 24 | without specific prior written permission. |
| 25 | |
| 26 | THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR |
| 27 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 28 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 29 | DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT, |
| 30 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 31 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 32 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 33 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 34 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 35 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 36 | POSSIBILITY OF SUCH DAMAGE. |
| 37 | |
| 38 | ***************************************************************************/ |
| 39 | |
| 40 | #include "emu.h" |
| 41 | #include "machine/nvram.h" |
| 42 | |
| 43 | |
| 44 | |
| 45 | //************************************************************************** |
| 46 | // DEVICE CONFIGURATION |
| 47 | //************************************************************************** |
| 48 | |
| 49 | //------------------------------------------------- |
| 50 | // nvram_device_config - constructor |
| 51 | //------------------------------------------------- |
| 52 | |
| 53 | nvram_device_config::nvram_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 54 | : device_config(mconfig, static_alloc_device_config, "NVRAM", tag, owner, clock), |
| 55 | device_config_nvram_interface(mconfig, *this), |
| 56 | m_default_value(DEFAULT_ALL_1) |
| 57 | { |
| 58 | } |
| 59 | |
| 60 | |
| 61 | //------------------------------------------------- |
| 62 | // static_alloc_device_config - allocate a new |
| 63 | // configuration object |
| 64 | //------------------------------------------------- |
| 65 | |
| 66 | device_config *nvram_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 67 | { |
| 68 | return global_alloc(nvram_device_config(mconfig, tag, owner, clock)); |
| 69 | } |
| 70 | |
| 71 | |
| 72 | //------------------------------------------------- |
| 73 | // alloc_device - allocate a new device object |
| 74 | //------------------------------------------------- |
| 75 | |
| 76 | device_t *nvram_device_config::alloc_device(running_machine &machine) const |
| 77 | { |
| 78 | return auto_alloc(&machine, nvram_device(machine, *this)); |
| 79 | } |
| 80 | |
| 81 | |
| 82 | //------------------------------------------------- |
| 83 | // static_set_interface - configuration helper |
| 84 | // to set the interface |
| 85 | //------------------------------------------------- |
| 86 | |
| 87 | void nvram_device_config::static_set_default_value(device_config *device, default_value value) |
| 88 | { |
| 89 | nvram_device_config *nvram = downcast<nvram_device_config *>(device); |
| 90 | nvram->m_default_value = value; |
| 91 | } |
| 92 | |
| 93 | |
| 94 | //------------------------------------------------- |
| 95 | // static_set_custom_handler - configuration |
| 96 | // helper to set a custom callback |
| 97 | //------------------------------------------------- |
| 98 | |
| 99 | void nvram_device_config::static_set_custom_handler(device_config *device, nvram_init_proto_delegate handler) |
| 100 | { |
| 101 | nvram_device_config *nvram = downcast<nvram_device_config *>(device); |
| 102 | nvram->m_custom_handler = handler; |
| 103 | } |
| 104 | |
| 105 | |
| 106 | |
| 107 | //************************************************************************** |
| 108 | // LIVE DEVICE |
| 109 | //************************************************************************** |
| 110 | |
| 111 | //------------------------------------------------- |
| 112 | // nvram_device - constructor |
| 113 | //------------------------------------------------- |
| 114 | |
| 115 | nvram_device::nvram_device(running_machine &_machine, const nvram_device_config &config) |
| 116 | : device_t(_machine, config), |
| 117 | device_nvram_interface(_machine, config, *this), |
| 118 | m_config(config), |
| 119 | m_base(NULL), |
| 120 | m_length(0) |
| 121 | { |
| 122 | } |
| 123 | |
| 124 | |
| 125 | //------------------------------------------------- |
| 126 | // device_start - device-specific startup |
| 127 | //------------------------------------------------- |
| 128 | |
| 129 | void nvram_device::device_start() |
| 130 | { |
| 131 | // bind our handler |
| 132 | if (!m_config.m_custom_handler.isnull()) |
| 133 | m_custom_handler = nvram_init_delegate(m_config.m_custom_handler, *m_owner); |
| 134 | |
| 135 | // find our shared pointer with the target RAM |
| 136 | m_base = memory_get_shared(m_machine, tag(), m_length); |
| 137 | if (m_base == NULL) |
| 138 | throw emu_fatalerror("NVRAM device '%s' has no corresponding AM_SHARE region", tag()); |
| 139 | |
| 140 | // if we are region-backed for the default, find it now and make sure it's the right size |
| 141 | if (m_region != NULL && m_region->bytes() != m_length) |
| 142 | throw emu_fatalerror("NVRAM device '%s' has a default region, but it should be 0x%X bytes", tag(), m_length); |
| 143 | } |
| 144 | |
| 145 | |
| 146 | //------------------------------------------------- |
| 147 | // nvram_default - called to initialize NVRAM to |
| 148 | // its default state |
| 149 | //------------------------------------------------- |
| 150 | |
| 151 | void nvram_device::nvram_default() |
| 152 | { |
| 153 | // region always wins |
| 154 | if (m_region != NULL) |
| 155 | { |
| 156 | memcpy(m_base, *m_region, m_length); |
| 157 | return; |
| 158 | } |
| 159 | |
| 160 | // default values for other cases |
| 161 | switch (m_config.m_default_value) |
| 162 | { |
| 163 | // all-0's |
| 164 | case nvram_device_config::DEFAULT_ALL_0: |
| 165 | memset(m_base, 0, m_length); |
| 166 | break; |
| 167 | |
| 168 | // all 1's |
| 169 | default: |
| 170 | case nvram_device_config::DEFAULT_ALL_1: |
| 171 | memset(m_base, 0xff, m_length); |
| 172 | break; |
| 173 | |
| 174 | // random values |
| 175 | case nvram_device_config::DEFAULT_RANDOM: |
| 176 | { |
| 177 | UINT8 *nvram = reinterpret_cast<UINT8 *>(m_base); |
| 178 | for (int index = 0; index < m_length; index++) |
| 179 | nvram[index] = mame_rand(&m_machine); |
| 180 | break; |
| 181 | } |
| 182 | |
| 183 | // custom handler |
| 184 | case nvram_device_config::DEFAULT_CUSTOM: |
| 185 | m_custom_handler(*this, m_base, m_length); |
| 186 | break; |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | |
| 191 | //------------------------------------------------- |
| 192 | // nvram_read - called to read NVRAM from the |
| 193 | // .nv file |
| 194 | //------------------------------------------------- |
| 195 | |
| 196 | void nvram_device::nvram_read(mame_file &file) |
| 197 | { |
| 198 | mame_fread(&file, m_base, m_length); |
| 199 | } |
| 200 | |
| 201 | |
| 202 | //------------------------------------------------- |
| 203 | // nvram_write - called to write NVRAM to the |
| 204 | // .nv file |
| 205 | //------------------------------------------------- |
| 206 | |
| 207 | void nvram_device::nvram_write(mame_file &file) |
| 208 | { |
| 209 | mame_fwrite(&file, m_base, m_length); |
| 210 | } |
| 211 | |
| 212 | |
| 213 | const device_type NVRAM = nvram_device_config::static_alloc_device_config; |
src/emu/machine/nvram.h
| r0 | r9051 | |
| 1 | /*************************************************************************** |
| 2 | |
| 3 | nvram.h |
| 4 | |
| 5 | Generic non-volatile RAM. |
| 6 | |
| 7 | **************************************************************************** |
| 8 | |
| 9 | Copyright Aaron Giles |
| 10 | All rights reserved. |
| 11 | |
| 12 | Redistribution and use in source and binary forms, with or without |
| 13 | modification, are permitted provided that the following conditions are |
| 14 | met: |
| 15 | |
| 16 | * Redistributions of source code must retain the above copyright |
| 17 | notice, this list of conditions and the following disclaimer. |
| 18 | * Redistributions in binary form must reproduce the above copyright |
| 19 | notice, this list of conditions and the following disclaimer in |
| 20 | the documentation and/or other materials provided with the |
| 21 | distribution. |
| 22 | * Neither the name 'MAME' nor the names of its contributors may be |
| 23 | used to endorse or promote products derived from this software |
| 24 | without specific prior written permission. |
| 25 | |
| 26 | THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR |
| 27 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 28 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 29 | DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT, |
| 30 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 31 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 32 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 33 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 34 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 35 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 36 | POSSIBILITY OF SUCH DAMAGE. |
| 37 | |
| 38 | ***************************************************************************/ |
| 39 | |
| 40 | #pragma once |
| 41 | |
| 42 | #ifndef __NVRAM_H__ |
| 43 | #define __NVRAM_H__ |
| 44 | |
| 45 | |
| 46 | |
| 47 | //************************************************************************** |
| 48 | // INTERFACE CONFIGURATION MACROS |
| 49 | //************************************************************************** |
| 50 | |
| 51 | #define MDRV_NVRAM_ADD_0FILL(_tag) \ |
| 52 | MDRV_DEVICE_ADD(_tag, NVRAM, 0) \ |
| 53 | nvram_device_config::static_set_default_value(device, nvram_device_config::DEFAULT_ALL_0); \ |
| 54 | |
| 55 | #define MDRV_NVRAM_ADD_1FILL(_tag) \ |
| 56 | MDRV_DEVICE_ADD(_tag, NVRAM, 0) \ |
| 57 | nvram_device_config::static_set_default_value(device, nvram_device_config::DEFAULT_ALL_1); \ |
| 58 | |
| 59 | #define MDRV_NVRAM_ADD_RANDOM_FILL(_tag) \ |
| 60 | MDRV_DEVICE_ADD(_tag, NVRAM, 0) \ |
| 61 | nvram_device_config::static_set_default_value(device, nvram_device_config::DEFAULT_RANDOM); \ |
| 62 | |
| 63 | #define MDRV_NVRAM_ADD_CUSTOM(_tag, _class, _method) \ |
| 64 | MDRV_DEVICE_ADD(_tag, NVRAM, 0) \ |
| 65 | nvram_device_config::static_set_custom_handler(device, nvram_init_proto_delegate::_create_member<_class, &_class::_method>(#_class "::" #_method)); \ |
| 66 | |
| 67 | |
| 68 | #define MDRV_NVRAM_REPLACE_0FILL(_tag) \ |
| 69 | MDRV_DEVICE_REPLACE(_tag, NVRAM, 0) \ |
| 70 | nvram_device_config::static_set_default_value(device, nvram_device_config::DEFAULT_ALL_0); \ |
| 71 | |
| 72 | #define MDRV_NVRAM_REPLACE_1FILL(_tag) \ |
| 73 | MDRV_DEVICE_REPLACE(_tag, NVRAM, 0) \ |
| 74 | nvram_device_config::static_set_default_value(device, nvram_device_config::DEFAULT_ALL_1); \ |
| 75 | |
| 76 | #define MDRV_NVRAM_REPLACE_RANDOM_FILL(_tag) \ |
| 77 | MDRV_DEVICE_REPLACE(_tag, NVRAM, 0) \ |
| 78 | nvram_device_config::static_set_default_value(device, nvram_device_config::DEFAULT_RANDOM); \ |
| 79 | |
| 80 | #define MDRV_NVRAM_REPLACE_CUSTOM(_tag, _class, _method) \ |
| 81 | MDRV_DEVICE_REPLACE(_tag, NVRAM, 0) \ |
| 82 | nvram_device_config::static_set_custom_handler(device, nvram_init_proto_delegate::_create_member<_class, &_class::_method>(#_class "::" #_method)); \ |
| 83 | |
| 84 | |
| 85 | |
| 86 | //************************************************************************** |
| 87 | // TYPE DEFINITIONS |
| 88 | //************************************************************************** |
| 89 | |
| 90 | class nvram_device; |
| 91 | |
| 92 | |
| 93 | // custom initialization for default state |
| 94 | typedef proto_delegate_3param<void, nvram_device &, void *, size_t> nvram_init_proto_delegate; |
| 95 | typedef delegate_3param<void, nvram_device &, void *, size_t> nvram_init_delegate; |
| 96 | |
| 97 | |
| 98 | // ======================> nvram_device_config |
| 99 | |
| 100 | class nvram_device_config : public device_config, |
| 101 | public device_config_nvram_interface |
| 102 | { |
| 103 | friend class nvram_device; |
| 104 | |
| 105 | // construction/destruction |
| 106 | nvram_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); |
| 107 | |
| 108 | public: |
| 109 | // values |
| 110 | enum default_value |
| 111 | { |
| 112 | DEFAULT_ALL_0, |
| 113 | DEFAULT_ALL_1, |
| 114 | DEFAULT_RANDOM, |
| 115 | DEFAULT_CUSTOM |
| 116 | }; |
| 117 | |
| 118 | // allocators |
| 119 | static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); |
| 120 | virtual device_t *alloc_device(running_machine &machine) const; |
| 121 | |
| 122 | // inline configuration helpers |
| 123 | static void static_set_default_value(device_config *device, default_value value); |
| 124 | static void static_set_custom_handler(device_config *device, nvram_init_proto_delegate callback); |
| 125 | |
| 126 | protected: |
| 127 | // internal state |
| 128 | default_value m_default_value; |
| 129 | nvram_init_proto_delegate m_custom_handler; |
| 130 | }; |
| 131 | |
| 132 | |
| 133 | // ======================> nvram_device |
| 134 | |
| 135 | class nvram_device : public device_t, |
| 136 | public device_nvram_interface |
| 137 | { |
| 138 | friend class nvram_device_config; |
| 139 | |
| 140 | // construction/destruction |
| 141 | nvram_device(running_machine &_machine, const nvram_device_config &config); |
| 142 | |
| 143 | public: |
| 144 | // controls |
| 145 | void set_base(void *base, size_t length) { m_base = base; m_length = length; } |
| 146 | |
| 147 | protected: |
| 148 | // device-level overrides |
| 149 | virtual void device_start(); |
| 150 | |
| 151 | // device_nvram_interface overrides |
| 152 | virtual void nvram_default(); |
| 153 | virtual void nvram_read(mame_file &file); |
| 154 | virtual void nvram_write(mame_file &file); |
| 155 | |
| 156 | // internal state |
| 157 | const nvram_device_config & m_config; |
| 158 | void * m_base; |
| 159 | size_t m_length; |
| 160 | nvram_init_delegate m_custom_handler; |
| 161 | }; |
| 162 | |
| 163 | |
| 164 | // device type definition |
| 165 | extern const device_type NVRAM; |
| 166 | |
| 167 | |
| 168 | #endif |
src/emu/addrmap.h
| r9050 | r9051 | |
| 586 | 586 | curentry->set_handler(devconfig, _tag, _rhandler, #_rhandler, _whandler, #_whandler, _unitmask); \ |
| 587 | 587 | |
| 588 | 588 | |
| 589 | // device reads |
| 590 | #define AM_DEVREAD_MODERN(_tag, _class, _handler) \ |
| 591 | curentry->set_handler(devconfig, _tag, read_proto_delegate::_create_member<_class, &_class::_handler>(#_class "::" #_handler)); \ |
| 592 | |
| 593 | #define AM_DEVREAD8_MODERN(_tag, _class, _handler, _unitmask) \ |
| 594 | curentry->set_handler(devconfig, _tag, read8_proto_delegate::_create_member<_class, &_class::_handler>(#_class "::" #_handler), _unitmask); \ |
| 595 | |
| 596 | #define AM_DEVREAD16_MODERN(_tag, _class, _handler, _unitmask) \ |
| 597 | curentry->set_handler(devconfig, _tag, read16_proto_delegate::_create_member<_class, &_class::_handler>(#_class "::" #_handler), _unitmask); \ |
| 598 | |
| 599 | #define AM_DEVREAD32_MODERN(_tag, _class, _handler, _unitmask) \ |
| 600 | curentry->set_handler(devconfig, _tag, read32_proto_delegate::_create_member<_class, &_class::_handler>(#_class "::" #_handler), _unitmask); \ |
| 601 | |
| 602 | |
| 603 | // device writes |
| 604 | #define AM_DEVWRITE_MODERN(_tag, _class, _handler) \ |
| 605 | curentry->set_handler(devconfig, _tag, write_proto_delegate::_create_member<_class, &_class::_handler>(#_class "::" #_handler)); \ |
| 606 | |
| 607 | #define AM_DEVWRITE8_MODERN(_tag, _class, _handler, _unitmask) \ |
| 608 | curentry->set_handler(devconfig, _tag, write8_proto_delegate::_create_member<_class, &_class::_handler>(#_class "::" #_handler), _unitmask); \ |
| 609 | |
| 610 | #define AM_DEVWRITE16_MODERN(_tag, _class, _handler, _unitmask) \ |
| 611 | curentry->set_handler(devconfig, _tag, write16_proto_delegate::_create_member<_class, &_class::_handler>(#_class "::" #_handler), _unitmask); \ |
| 612 | |
| 613 | #define AM_DEVWRITE32_MODERN(_tag, _class, _handler, _unitmask) \ |
| 614 | curentry->set_handler(devconfig, _tag, write32_proto_delegate::_create_member<_class, &_class::_handler>(#_class "::" #_handler), _unitmask); \ |
| 615 | |
| 616 | |
| 617 | // device reads/writes |
| 618 | #define AM_DEVREADWRITE_MODERN(_tag, _class, _rhandler, _whandler) \ |
| 619 | curentry->set_handler(devconfig, _tag, read_proto_delegate::_create_member<_class, &_class::_rhandler>(#_class "::" #_rhandler), write_proto_delegate::_create_member<_class, &_class::_whandler>(#_class "::" #_whandler)); \ |
| 620 | |
| 621 | #define AM_DEVREADWRITE8_MODERN(_tag, _class, _rhandler, _whandler, _unitmask) \ |
| 622 | curentry->set_handler(devconfig, _tag, read8_proto_delegate::_create_member<_class, &_class::_rhandler>(#_class "::" #_rhandler), write8_proto_delegate::_create_member<_class, &_class::_whandler>(#_class "::" #_whandler), _unitmask); \ |
| 623 | |
| 624 | #define AM_DEVREADWRITE16_MODERN(_tag, _class, _rhandler, _whandler, _unitmask) \ |
| 625 | curentry->set_handler(devconfig, _tag, read16_proto_delegate::_create_member<_class, &_class::_rhandler>(#_class "::" #_rhandler), write16_proto_delegate::_create_member<_class, &_class::_whandler>(#_class "::" #_whandler), _unitmask); \ |
| 626 | |
| 627 | #define AM_DEVREADWRITE32_MODERN(_tag, _class, _rhandler, _whandler, _unitmask) \ |
| 628 | curentry->set_handler(devconfig, _tag, read32_proto_delegate::_create_member<_class, &_class::_rhandler>(#_class "::" #_rhandler), write32_proto_delegate::_create_member<_class, &_class::_whandler>(#_class "::" #_whandler), _unitmask); \ |
| 629 | |
| 630 | |
| 589 | 631 | // special-case accesses |
| 590 | 632 | #define AM_ROM \ |
| 591 | 633 | curentry->set_read_type(AMH_ROM); \ |
src/mess/drivers/fmtowns.c
| r9050 | r9051 | |
| 125 | 125 | #include "machine/upd71071.h" |
| 126 | 126 | #include "devices/messram.h" |
| 127 | 127 | #include "includes/fmtowns.h" |
| 128 | #include "machine/nvram.h" |
| 128 | 129 | |
| 129 | 130 | // CD controller IRQ types |
| 130 | 131 | #define TOWNS_CD_IRQ_MPU 1 |
| r9050 | r9051 | |
| 957 | 958 | static READ8_HANDLER( towns_cmos8_r ) |
| 958 | 959 | { |
| 959 | 960 | towns_state* state = space->machine->driver_data<towns_state>(); |
| 960 | | return state->towns_cmos[offset]; |
| 961 | return state->m_nvram[offset]; |
| 961 | 962 | } |
| 962 | 963 | |
| 963 | 964 | static WRITE8_HANDLER( towns_cmos8_w ) |
| 964 | 965 | { |
| 965 | 966 | towns_state* state = space->machine->driver_data<towns_state>(); |
| 966 | | state->towns_cmos[offset] = data; |
| 967 | state->m_nvram[offset] = data; |
| 967 | 968 | } |
| 968 | 969 | |
| 969 | 970 | static READ8_HANDLER( towns_cmos_low_r ) |
| r9050 | r9051 | |
| 972 | 973 | if(state->towns_mainmem_enable != 0) |
| 973 | 974 | return messram_get_ptr(state->messram)[offset + 0xd8000]; |
| 974 | 975 | |
| 975 | | return state->towns_cmos[offset]; |
| 976 | return state->m_nvram[offset]; |
| 976 | 977 | } |
| 977 | 978 | |
| 978 | 979 | static WRITE8_HANDLER( towns_cmos_low_w ) |
| r9050 | r9051 | |
| 981 | 982 | if(state->towns_mainmem_enable != 0) |
| 982 | 983 | messram_get_ptr(state->messram)[offset+0xd8000] = data; |
| 983 | 984 | else |
| 984 | | state->towns_cmos[offset] = data; |
| 985 | state->m_nvram[offset] = data; |
| 985 | 986 | } |
| 986 | 987 | |
| 987 | 988 | static READ8_HANDLER( towns_cmos_r ) |
| 988 | 989 | { |
| 989 | 990 | towns_state* state = space->machine->driver_data<towns_state>(); |
| 990 | | return state->towns_cmos[offset]; |
| 991 | return state->m_nvram[offset]; |
| 991 | 992 | } |
| 992 | 993 | |
| 993 | 994 | static WRITE8_HANDLER( towns_cmos_w ) |
| 994 | 995 | { |
| 995 | 996 | towns_state* state = space->machine->driver_data<towns_state>(); |
| 996 | | state->towns_cmos[offset] = data; |
| 997 | state->m_nvram[offset] = data; |
| 997 | 998 | } |
| 998 | 999 | |
| 999 | 1000 | void towns_update_video_banks(address_space* space) |
| r9050 | r9051 | |
| 1837 | 1838 | AM_RANGE(0x000cc000, 0x000cff7f) AM_RAM |
| 1838 | 1839 | AM_RANGE(0x000cff80, 0x000cffff) AM_READWRITE8(towns_video_cff80_mem_r,towns_video_cff80_mem_w,0xffffffff) |
| 1839 | 1840 | AM_RANGE(0x000d0000, 0x000d7fff) AM_RAM |
| 1840 | | AM_RANGE(0x000d8000, 0x000d9fff) AM_READWRITE8(towns_cmos_low_r,towns_cmos_low_w,0xffffffff) AM_BASE_SIZE_GENERIC(nvram) // CMOS? RAM |
| 1841 | AM_RANGE(0x000d8000, 0x000d9fff) AM_READWRITE8(towns_cmos_low_r,towns_cmos_low_w,0xffffffff) AM_SHARE("nvram") // CMOS? RAM |
| 1841 | 1842 | AM_RANGE(0x000da000, 0x000effff) AM_RAM //READWRITE(SMH_BANK(11),SMH_BANK(11)) |
| 1842 | 1843 | AM_RANGE(0x000f0000, 0x000f7fff) AM_RAM //READWRITE(SMH_BANK(12),SMH_BANK(12)) |
| 1843 | 1844 | AM_RANGE(0x000f8000, 0x000fffff) AM_READ_BANK("bank11") AM_WRITE_BANK("bank12") |
| r9050 | r9051 | |
| 1861 | 1862 | AM_RANGE(0x000cc000, 0x000cff7f) AM_RAM |
| 1862 | 1863 | AM_RANGE(0x000cff80, 0x000cffff) AM_READWRITE8(towns_video_cff80_r,towns_video_cff80_w,0xffffffff) |
| 1863 | 1864 | AM_RANGE(0x000d0000, 0x000d7fff) AM_RAM |
| 1864 | | AM_RANGE(0x000d8000, 0x000d9fff) AM_READWRITE8(towns_cmos_low_r,towns_cmos_low_w,0xffffffff) AM_BASE_SIZE_GENERIC(nvram) // CMOS? RAM |
| 1865 | AM_RANGE(0x000d8000, 0x000d9fff) AM_READWRITE8(towns_cmos_low_r,towns_cmos_low_w,0xffffffff) AM_SHARE("nvram") // CMOS? RAM |
| 1865 | 1866 | AM_RANGE(0x000da000, 0x000effff) AM_RAM //READWRITE(SMH_BANK(11),SMH_BANK(11)) |
| 1866 | 1867 | AM_RANGE(0x000f0000, 0x000f7fff) AM_RAM //READWRITE(SMH_BANK(12),SMH_BANK(12)) |
| 1867 | 1868 | AM_RANGE(0x000f8000, 0x000fffff) AM_READ_BANK("bank11") AM_WRITE_BANK("bank12") |
| r9050 | r9051 | |
| 2148 | 2149 | state->pic_master = machine->device("pic8259_master"); |
| 2149 | 2150 | state->pic_slave = machine->device("pic8259_slave"); |
| 2150 | 2151 | state->towns_vram = auto_alloc_array(machine,UINT32,0x20000); |
| 2151 | | state->towns_cmos = machine->generic.nvram.u8; |
| 2152 | 2152 | state->towns_gfxvram = auto_alloc_array(machine,UINT8,0x80000); |
| 2153 | 2153 | state->towns_txtvram = auto_alloc_array(machine,UINT8,0x20000); |
| 2154 | 2154 | //towns_sprram = auto_alloc_array(machine,UINT8,0x20000); |
| r9050 | r9051 | |
| 2354 | 2354 | MDRV_UPD71071_ADD("dma_1",towns_dma_config) |
| 2355 | 2355 | MDRV_UPD71071_ADD("dma_2",towns_dma_config) |
| 2356 | 2356 | |
| 2357 | | MDRV_NVRAM_HANDLER( generic_0fill ) |
| 2357 | MDRV_NVRAM_ADD_0FILL("nvram") |
| 2358 | 2358 | |
| 2359 | 2359 | MDRV_VIDEO_START(towns) |
| 2360 | 2360 | MDRV_VIDEO_UPDATE(towns) |
src/mess/drivers/x68k.c
| r9050 | r9051 | |
| 135 | 135 | #include "machine/x68k_hdc.h" |
| 136 | 136 | #include "includes/x68k.h" |
| 137 | 137 | #include "devices/messram.h" |
| 138 | #include "machine/nvram.h" |
| 138 | 139 | #include "x68000.lh" |
| 139 | 140 | |
| 141 | |
| 142 | class x68000_state : public driver_device |
| 143 | { |
| 144 | public: |
| 145 | x68000_state(running_machine &machine, const driver_device_config_base &config) |
| 146 | : driver_device(machine, config), |
| 147 | m_nvram(*this, "nvram") { } |
| 148 | |
| 149 | required_shared_ptr<UINT16> m_nvram; |
| 150 | }; |
| 151 | |
| 152 | |
| 140 | 153 | struct x68k_system x68k_sys; |
| 141 | 154 | |
| 142 | 155 | static UINT16* sram; // SRAM |
| r9050 | r9051 | |
| 1506 | 1519 | |
| 1507 | 1520 | static WRITE16_HANDLER( x68k_sram_w ) |
| 1508 | 1521 | { |
| 1522 | x68000_state *state = space->machine->driver_data<x68000_state>(); |
| 1523 | |
| 1509 | 1524 | if(x68k_sys.sysport.sram_writeprotect == 0x31) |
| 1510 | 1525 | { |
| 1511 | | COMBINE_DATA(space->machine->generic.nvram.u16+offset); |
| 1526 | COMBINE_DATA(state->m_nvram + offset); |
| 1512 | 1527 | } |
| 1513 | 1528 | } |
| 1514 | 1529 | |
| 1515 | 1530 | static READ16_HANDLER( x68k_sram_r ) |
| 1516 | 1531 | { |
| 1532 | x68000_state *state = space->machine->driver_data<x68000_state>(); |
| 1517 | 1533 | // HACKS! |
| 1518 | 1534 | // if(offset == 0x5a/2) // 0x5a should be 0 if no SASI HDs are present. |
| 1519 | 1535 | // return 0x0000; |
| r9050 | r9051 | |
| 1527 | 1543 | if(offset == 0x70/2) |
| 1528 | 1544 | return 0x0700; |
| 1529 | 1545 | #endif |
| 1530 | | return space->machine->generic.nvram.u16[offset]; |
| 1546 | return state->m_nvram[offset]; |
| 1531 | 1547 | } |
| 1532 | 1548 | |
| 1533 | 1549 | static READ32_HANDLER( x68k_sram32_r ) |
| 1534 | 1550 | { |
| 1551 | x68000_state *state = space->machine->driver_data<x68000_state>(); |
| 1535 | 1552 | if(offset == 0x08/4) |
| 1536 | 1553 | return (messram_get_size(space->machine->device("messram")) & 0xffff0000); // RAM size |
| 1537 | 1554 | #if 0 |
| r9050 | r9051 | |
| 1542 | 1559 | if(offset == 0x70/2) |
| 1543 | 1560 | return 0x0700; |
| 1544 | 1561 | #endif |
| 1545 | | return space->machine->generic.nvram.u32[offset]; |
| 1562 | return state->m_nvram[offset]; |
| 1546 | 1563 | } |
| 1547 | 1564 | |
| 1548 | 1565 | static WRITE32_HANDLER( x68k_sram32_w ) |
| 1549 | 1566 | { |
| 1567 | x68000_state *state = space->machine->driver_data<x68000_state>(); |
| 1550 | 1568 | if(x68k_sys.sysport.sram_writeprotect == 0x31) |
| 1551 | 1569 | { |
| 1552 | | COMBINE_DATA(space->machine->generic.nvram.u32+offset); |
| 1570 | COMBINE_DATA(state->m_nvram + offset); |
| 1553 | 1571 | } |
| 1554 | 1572 | } |
| 1555 | 1573 | |
| r9050 | r9051 | |
| 1937 | 1955 | AM_RANGE(0xeb8000, 0xebffff) AM_READWRITE(x68k_spriteram_r, x68k_spriteram_w) |
| 1938 | 1956 | AM_RANGE(0xec0000, 0xecffff) AM_NOP // User I/O |
| 1939 | 1957 | // AM_RANGE(0xed0000, 0xed3fff) AM_READWRITE(sram_r, sram_w) AM_BASE(&generic_nvram16) AM_SIZE(&generic_nvram_size) |
| 1940 | | AM_RANGE(0xed0000, 0xed3fff) AM_RAMBANK("bank4") AM_BASE_SIZE_GENERIC(nvram) |
| 1958 | AM_RANGE(0xed0000, 0xed3fff) AM_RAMBANK("bank4") AM_SHARE("nvram") |
| 1941 | 1959 | AM_RANGE(0xed4000, 0xefffff) AM_NOP |
| 1942 | 1960 | AM_RANGE(0xf00000, 0xfbffff) AM_ROM |
| 1943 | 1961 | // AM_RANGE(0xfc0000, 0xfdffff) AM_READWRITE(x68k_rom0_r, x68k_rom0_w) |
| r9050 | r9051 | |
| 1972 | 1990 | AM_RANGE(0xeb8000, 0xebffff) AM_READWRITE16(x68k_spriteram_r, x68k_spriteram_w,0xffffffff) |
| 1973 | 1991 | AM_RANGE(0xec0000, 0xecffff) AM_NOP // User I/O |
| 1974 | 1992 | // AM_RANGE(0xed0000, 0xed3fff) AM_READWRITE(sram_r, sram_w) AM_BASE(&generic_nvram16) AM_SIZE(&generic_nvram_size) |
| 1975 | | AM_RANGE(0xed0000, 0xed3fff) AM_RAMBANK("bank4") AM_BASE_SIZE_GENERIC(nvram) |
| 1993 | AM_RANGE(0xed0000, 0xed3fff) AM_RAMBANK("bank4") AM_SHARE("nvram") |
| 1976 | 1994 | AM_RANGE(0xed4000, 0xefffff) AM_NOP |
| 1977 | 1995 | AM_RANGE(0xf00000, 0xfbffff) AM_ROM |
| 1978 | 1996 | // AM_RANGE(0xfc0000, 0xfdffff) AM_READWRITE16(x68k_rom0_r, x68k_rom0_w,0xffffffff) |
| r9050 | r9051 | |
| 2482 | 2500 | static MACHINE_START( x68000 ) |
| 2483 | 2501 | { |
| 2484 | 2502 | address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 2503 | x68000_state *state = machine->driver_data<x68000_state>(); |
| 2485 | 2504 | /* Install RAM handlers */ |
| 2486 | 2505 | x68k_spriteram = (UINT16*)memory_region(machine, "user1"); |
| 2487 | 2506 | memory_install_read16_handler(space,0x000000,0xbffffb,0xffffffff,0,(read16_space_func)x68k_emptyram_r); |
| r9050 | r9051 | |
| 2496 | 2515 | memory_set_bankptr(machine, "bank3",x68k_tvram); // so that code in VRAM is executable - needed for Terra Cresta |
| 2497 | 2516 | memory_install_read16_handler(space,0xed0000,0xed3fff,0xffffffff,0,x68k_sram_r); |
| 2498 | 2517 | memory_install_write16_handler(space,0xed0000,0xed3fff,0xffffffff,0,x68k_sram_w); |
| 2499 | | memory_set_bankptr(machine, "bank4",space->machine->generic.nvram.u16); // so that code in SRAM is executable, there is an option for booting from SRAM |
| 2518 | memory_set_bankptr(machine, "bank4",state->m_nvram); // so that code in SRAM is executable, there is an option for booting from SRAM |
| 2500 | 2519 | |
| 2501 | 2520 | // start keyboard timer |
| 2502 | 2521 | timer_adjust_periodic(kb_timer, attotime_zero, 0, ATTOTIME_IN_MSEC(5)); // every 5ms |
| r9050 | r9051 | |
| 2512 | 2531 | static MACHINE_START( x68030 ) |
| 2513 | 2532 | { |
| 2514 | 2533 | address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 2534 | x68000_state *state = machine->driver_data<x68000_state>(); |
| 2515 | 2535 | /* Install RAM handlers */ |
| 2516 | 2536 | x68k_spriteram = (UINT16*)memory_region(machine, "user1"); |
| 2517 | 2537 | memory_install_read32_handler(space,0x000000,0xbffffb,0xffffffff,0,(read32_space_func)x68k_rom0_r); |
| r9050 | r9051 | |
| 2529 | 2549 | memory_set_bankptr(machine, "bank3",x68k_tvram); // so that code in VRAM is executable - needed for Terra Cresta |
| 2530 | 2550 | memory_install_read32_handler(space,0xed0000,0xed3fff,0xffffffff,0,x68k_sram32_r); |
| 2531 | 2551 | memory_install_write32_handler(space,0xed0000,0xed3fff,0xffffffff,0,x68k_sram32_w); |
| 2532 | | memory_set_bankptr(machine, "bank4",machine->generic.nvram.u32); // so that code in SRAM is executable, there is an option for booting from SRAM |
| 2552 | memory_set_bankptr(machine, "bank4",state->m_nvram); // so that code in SRAM is executable, there is an option for booting from SRAM |
| 2533 | 2553 | |
| 2534 | 2554 | // start keyboard timer |
| 2535 | 2555 | timer_adjust_periodic(kb_timer, attotime_zero, 0, ATTOTIME_IN_MSEC(5)); // every 5ms |
| r9050 | r9051 | |
| 2596 | 2616 | x68k_sys.sysport.cputype = 0xdc; // 68030, 25MHz |
| 2597 | 2617 | } |
| 2598 | 2618 | |
| 2599 | | static MACHINE_CONFIG_START( x68000, driver_device ) |
| 2619 | static MACHINE_CONFIG_START( x68000, x68000_state ) |
| 2600 | 2620 | /* basic machine hardware */ |
| 2601 | 2621 | MDRV_CPU_ADD("maincpu", M68000, 10000000) /* 10 MHz */ |
| 2602 | 2622 | MDRV_CPU_PROGRAM_MAP(x68k_map) |
| r9050 | r9051 | |
| 2646 | 2666 | MDRV_SOUND_ROUTE(ALL_OUTPUTS, "lspeaker", 0.50) |
| 2647 | 2667 | MDRV_SOUND_ROUTE(ALL_OUTPUTS, "rspeaker", 0.50) |
| 2648 | 2668 | |
| 2649 | | MDRV_NVRAM_HANDLER( generic_0fill ) |
| 2669 | MDRV_NVRAM_ADD_0FILL("nvram") |
| 2650 | 2670 | |
| 2651 | 2671 | MDRV_UPD72065_ADD("upd72065", fdc_interface) |
| 2652 | 2672 | MDRV_FLOPPY_4_DRIVES_ADD(x68k_floppy_config) |