src/emu/debug/debugcpu.c
| r6826 | r6827 | |
| 25 | 25 | #include "debugvw.h" |
| 26 | 26 | #include "debugger.h" |
| 27 | 27 | #include "uiinput.h" |
| 28 | | #include "machine/eeprom.h" |
| 29 | 28 | #include <ctype.h> |
| 30 | 29 | |
| 31 | 30 | |
| r6826 | r6827 | |
| 71 | 70 | |
| 72 | 71 | UINT64 wpdata; |
| 73 | 72 | UINT64 wpaddr; |
| 74 | | UINT64 tempvar[NUM_TEMP_VARIABLES]; |
| 73 | UINT64 tempvar[NUM_TEMP_VARIABLES]; |
| 75 | 74 | |
| 76 | 75 | osd_ticks_t last_periodic_update_time; |
| 77 | 76 | }; |
| r6826 | r6827 | |
| 101 | 100 | static UINT64 expression_read_memory(void *param, const char *name, int space, UINT32 address, int size); |
| 102 | 101 | static UINT64 expression_read_program_direct(const address_space *space, int opcode, offs_t address, int size); |
| 103 | 102 | static UINT64 expression_read_memory_region(running_machine *machine, const char *rgntag, offs_t address, int size); |
| 104 | | static UINT64 expression_read_eeprom(running_machine *machine, offs_t address, int size); |
| 105 | 103 | static void expression_write_memory(void *param, const char *name, int space, UINT32 address, int size, UINT64 data); |
| 106 | 104 | static void expression_write_program_direct(const address_space *space, int opcode, offs_t address, int size, UINT64 data); |
| 107 | 105 | static void expression_write_memory_region(running_machine *machine, const char *rgntag, offs_t address, int size, UINT64 data); |
| 108 | | static void expression_write_eeprom(running_machine *machine, offs_t address, int size, UINT64 data); |
| 109 | 106 | static EXPRERR expression_validate(void *param, const char *name, int space); |
| 110 | 107 | |
| 111 | 108 | /* variable getters/setters */ |
| r6826 | r6827 | |
| 2437 | 2434 | ***************************************************************************/ |
| 2438 | 2435 | |
| 2439 | 2436 | /*------------------------------------------------- |
| 2440 | | expression_cpu_index - return the CPU index |
| 2437 | expression_get_device - return a device |
| 2441 | 2438 | based on a case insensitive tag search |
| 2442 | 2439 | -------------------------------------------------*/ |
| 2443 | 2440 | |
| 2444 | | static const device_config *expression_cpu_index(running_machine *machine, const char *tag) |
| 2441 | static const device_config *expression_get_device(running_machine *machine, const char *tag) |
| 2445 | 2442 | { |
| 2446 | | const device_config *cpu; |
| 2443 | const device_config *device; |
| 2447 | 2444 | |
| 2448 | | for (cpu = machine->firstcpu; cpu != NULL; cpu = cpu_next(cpu)) |
| 2449 | | if (mame_stricmp(cpu->tag, tag) == 0) |
| 2450 | | return cpu; |
| 2445 | for (device = machine->config->devicelist.head; device != NULL; device = device->next) |
| 2446 | if (mame_stricmp(device->tag, tag) == 0) |
| 2447 | return device; |
| 2451 | 2448 | |
| 2452 | 2449 | return NULL; |
| 2453 | 2450 | } |
| r6826 | r6827 | |
| 2463 | 2460 | { |
| 2464 | 2461 | running_machine *machine = (running_machine *)param; |
| 2465 | 2462 | UINT64 result = ~(UINT64)0 >> (64 - 8*size); |
| 2466 | | const device_config *cpu = NULL; |
| 2463 | const device_config *device = NULL; |
| 2467 | 2464 | const address_space *space; |
| 2468 | 2465 | |
| 2469 | 2466 | switch (spacenum) |
| r6826 | r6827 | |
| 2473 | 2470 | case EXPSPACE_IO_LOGICAL: |
| 2474 | 2471 | case EXPSPACE_SPACE3_LOGICAL: |
| 2475 | 2472 | if (name != NULL) |
| 2476 | | cpu = expression_cpu_index(machine, name); |
| 2477 | | if (cpu == NULL) |
| 2478 | | cpu = debug_cpu_get_visible_cpu(machine); |
| 2479 | | space = cpu_get_address_space(cpu, ADDRESS_SPACE_PROGRAM + (spacenum - EXPSPACE_PROGRAM_LOGICAL)); |
| 2473 | device = expression_get_device(machine, name); |
| 2474 | if (device == NULL) |
| 2475 | device = debug_cpu_get_visible_cpu(machine); |
| 2476 | space = cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM + (spacenum - EXPSPACE_PROGRAM_LOGICAL)); |
| 2480 | 2477 | if (space != NULL) |
| 2481 | 2478 | result = debug_read_memory(space, memory_address_to_byte(space, address), size, TRUE); |
| 2482 | 2479 | break; |
| r6826 | r6827 | |
| 2486 | 2483 | case EXPSPACE_IO_PHYSICAL: |
| 2487 | 2484 | case EXPSPACE_SPACE3_PHYSICAL: |
| 2488 | 2485 | if (name != NULL) |
| 2489 | | cpu = expression_cpu_index(machine, name); |
| 2490 | | if (cpu == NULL) |
| 2491 | | cpu = debug_cpu_get_visible_cpu(machine); |
| 2492 | | space = cpu_get_address_space(cpu, ADDRESS_SPACE_PROGRAM + (spacenum - EXPSPACE_PROGRAM_PHYSICAL)); |
| 2486 | device = expression_get_device(machine, name); |
| 2487 | if (device == NULL) |
| 2488 | device = debug_cpu_get_visible_cpu(machine); |
| 2489 | space = cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM + (spacenum - EXPSPACE_PROGRAM_PHYSICAL)); |
| 2493 | 2490 | if (space != NULL) |
| 2494 | 2491 | result = debug_read_memory(space, memory_address_to_byte(space, address), size, FALSE); |
| 2495 | 2492 | break; |
| r6826 | r6827 | |
| 2497 | 2494 | case EXPSPACE_OPCODE: |
| 2498 | 2495 | case EXPSPACE_RAMWRITE: |
| 2499 | 2496 | if (name != NULL) |
| 2500 | | cpu = expression_cpu_index(machine, name); |
| 2501 | | if (cpu == NULL) |
| 2502 | | cpu = debug_cpu_get_visible_cpu(machine); |
| 2503 | | result = expression_read_program_direct(cpu_get_address_space(cpu, ADDRESS_SPACE_PROGRAM), (spacenum == EXPSPACE_OPCODE), address, size); |
| 2497 | device = expression_get_device(machine, name); |
| 2498 | if (device == NULL) |
| 2499 | device = debug_cpu_get_visible_cpu(machine); |
| 2500 | result = expression_read_program_direct(cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM), (spacenum == EXPSPACE_OPCODE), address, size); |
| 2504 | 2501 | break; |
| 2505 | 2502 | |
| 2506 | | case EXPSPACE_EEPROM: |
| 2507 | | result = expression_read_eeprom(machine, address, size); |
| 2508 | | break; |
| 2509 | | |
| 2510 | 2503 | case EXPSPACE_REGION: |
| 2511 | 2504 | if (name == NULL) |
| 2512 | 2505 | break; |
| r6826 | r6827 | |
| 2629 | 2622 | |
| 2630 | 2623 | |
| 2631 | 2624 | /*------------------------------------------------- |
| 2632 | | expression_read_eeprom - read EEPROM data |
| 2633 | | -------------------------------------------------*/ |
| 2634 | | |
| 2635 | | static UINT64 expression_read_eeprom(running_machine *machine, offs_t address, int size) |
| 2636 | | { |
| 2637 | | UINT64 result = ~(UINT64)0 >> (64 - 8*size); |
| 2638 | | UINT32 eelength, eesize; |
| 2639 | | void *base; |
| 2640 | | |
| 2641 | | /* make sure we get a valid base before proceeding */ |
| 2642 | | base = eeprom_get_data_pointer(&eelength, &eesize); |
| 2643 | | if (base != NULL && address < eelength) |
| 2644 | | { |
| 2645 | | /* switch off the size */ |
| 2646 | | switch (eesize) |
| 2647 | | { |
| 2648 | | case 1: result &= ((UINT8 *)base)[address]; break; |
| 2649 | | case 2: result &= BIG_ENDIANIZE_INT16(((UINT16 *)base)[address]); break; |
| 2650 | | } |
| 2651 | | } |
| 2652 | | return result; |
| 2653 | | } |
| 2654 | | |
| 2655 | | |
| 2656 | | /*------------------------------------------------- |
| 2657 | 2625 | expression_write_memory - write 1,2,4 or 8 |
| 2658 | 2626 | bytes at the given offset in the given address |
| 2659 | 2627 | space |
| r6826 | r6827 | |
| 2662 | 2630 | static void expression_write_memory(void *param, const char *name, int spacenum, UINT32 address, int size, UINT64 data) |
| 2663 | 2631 | { |
| 2664 | 2632 | running_machine *machine = (running_machine *)param; |
| 2665 | | const device_config *cpu = NULL; |
| 2633 | const device_config *device = NULL; |
| 2666 | 2634 | const address_space *space; |
| 2667 | 2635 | |
| 2668 | 2636 | switch (spacenum) |
| r6826 | r6827 | |
| 2672 | 2640 | case EXPSPACE_IO_LOGICAL: |
| 2673 | 2641 | case EXPSPACE_SPACE3_LOGICAL: |
| 2674 | 2642 | if (name != NULL) |
| 2675 | | cpu = expression_cpu_index(machine, name); |
| 2676 | | if (cpu == NULL) |
| 2677 | | cpu = debug_cpu_get_visible_cpu(machine); |
| 2678 | | space = cpu_get_address_space(cpu, ADDRESS_SPACE_PROGRAM + (spacenum - EXPSPACE_PROGRAM_LOGICAL)); |
| 2643 | device = expression_get_device(machine, name); |
| 2644 | if (device == NULL) |
| 2645 | device = debug_cpu_get_visible_cpu(machine); |
| 2646 | space = cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM + (spacenum - EXPSPACE_PROGRAM_LOGICAL)); |
| 2679 | 2647 | if (space != NULL) |
| 2680 | 2648 | debug_write_memory(space, memory_address_to_byte(space, address), data, size, TRUE); |
| 2681 | 2649 | break; |
| r6826 | r6827 | |
| 2685 | 2653 | case EXPSPACE_IO_PHYSICAL: |
| 2686 | 2654 | case EXPSPACE_SPACE3_PHYSICAL: |
| 2687 | 2655 | if (name != NULL) |
| 2688 | | cpu = expression_cpu_index(machine, name); |
| 2689 | | if (cpu == NULL) |
| 2690 | | cpu = debug_cpu_get_visible_cpu(machine); |
| 2691 | | space = cpu_get_address_space(cpu, ADDRESS_SPACE_PROGRAM + (spacenum - EXPSPACE_PROGRAM_PHYSICAL)); |
| 2656 | device = expression_get_device(machine, name); |
| 2657 | if (device == NULL) |
| 2658 | device = debug_cpu_get_visible_cpu(machine); |
| 2659 | space = cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM + (spacenum - EXPSPACE_PROGRAM_PHYSICAL)); |
| 2692 | 2660 | if (space != NULL) |
| 2693 | 2661 | debug_write_memory(space, memory_address_to_byte(space, address), data, size, FALSE); |
| 2694 | 2662 | break; |
| r6826 | r6827 | |
| 2696 | 2664 | case EXPSPACE_OPCODE: |
| 2697 | 2665 | case EXPSPACE_RAMWRITE: |
| 2698 | 2666 | if (name != NULL) |
| 2699 | | cpu = expression_cpu_index(machine, name); |
| 2700 | | if (cpu == NULL) |
| 2701 | | cpu = debug_cpu_get_visible_cpu(machine); |
| 2702 | | expression_write_program_direct(cpu_get_address_space(cpu, ADDRESS_SPACE_PROGRAM), (spacenum == EXPSPACE_OPCODE), address, size, data); |
| 2667 | device = expression_get_device(machine, name); |
| 2668 | if (device == NULL) |
| 2669 | device = debug_cpu_get_visible_cpu(machine); |
| 2670 | expression_write_program_direct(cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM), (spacenum == EXPSPACE_OPCODE), address, size, data); |
| 2703 | 2671 | break; |
| 2704 | 2672 | |
| 2705 | | case EXPSPACE_EEPROM: |
| 2706 | | expression_write_eeprom(machine, address, size, data); |
| 2707 | | break; |
| 2708 | | |
| 2709 | 2673 | case EXPSPACE_REGION: |
| 2710 | 2674 | if (name == NULL) |
| 2711 | 2675 | break; |
| r6826 | r6827 | |
| 2840 | 2804 | |
| 2841 | 2805 | |
| 2842 | 2806 | /*------------------------------------------------- |
| 2843 | | expression_write_eeprom - write EEPROM data |
| 2844 | | -------------------------------------------------*/ |
| 2845 | | |
| 2846 | | static void expression_write_eeprom(running_machine *machine, offs_t address, int size, UINT64 data) |
| 2847 | | { |
| 2848 | | debugcpu_private *global = machine->debugcpu_data; |
| 2849 | | UINT32 eelength, eesize; |
| 2850 | | void *vbase = eeprom_get_data_pointer(&eelength, &eesize); |
| 2851 | | |
| 2852 | | /* make sure we get a valid base before proceeding */ |
| 2853 | | if (vbase != NULL && address < eelength) |
| 2854 | | { |
| 2855 | | UINT64 mask = ~(UINT64)0 >> (64 - 8*size); |
| 2856 | | |
| 2857 | | /* switch off the size */ |
| 2858 | | switch (eesize) |
| 2859 | | { |
| 2860 | | case 1: |
| 2861 | | { |
| 2862 | | UINT8 *base = (UINT8 *)vbase + address; |
| 2863 | | *base = (*base & ~mask) | (data & mask); |
| 2864 | | break; |
| 2865 | | } |
| 2866 | | |
| 2867 | | case 2: |
| 2868 | | { |
| 2869 | | UINT16 *base = (UINT16 *)vbase + address; |
| 2870 | | UINT16 value = BIG_ENDIANIZE_INT16(*base); |
| 2871 | | value = (value & ~mask) | (data & mask); |
| 2872 | | *base = BIG_ENDIANIZE_INT16(value); |
| 2873 | | break; |
| 2874 | | } |
| 2875 | | } |
| 2876 | | global->memory_modified = TRUE; |
| 2877 | | } |
| 2878 | | } |
| 2879 | | |
| 2880 | | |
| 2881 | | /*------------------------------------------------- |
| 2882 | 2807 | expression_validate - validate that the |
| 2883 | 2808 | provided expression references an |
| 2884 | 2809 | appropriate name |
| r6826 | r6827 | |
| 2887 | 2812 | static EXPRERR expression_validate(void *param, const char *name, int space) |
| 2888 | 2813 | { |
| 2889 | 2814 | running_machine *machine = (running_machine *)param; |
| 2890 | | const device_config *cpu = NULL; |
| 2815 | const device_config *device = NULL; |
| 2891 | 2816 | |
| 2892 | 2817 | switch (space) |
| 2893 | 2818 | { |
| r6826 | r6827 | |
| 2897 | 2822 | case EXPSPACE_SPACE3_LOGICAL: |
| 2898 | 2823 | if (name != NULL) |
| 2899 | 2824 | { |
| 2900 | | cpu = expression_cpu_index(machine, name); |
| 2901 | | if (cpu == NULL) |
| 2825 | device = expression_get_device(machine, name); |
| 2826 | if (device == NULL) |
| 2902 | 2827 | return EXPRERR_INVALID_MEMORY_NAME; |
| 2903 | 2828 | } |
| 2904 | | if (cpu == NULL) |
| 2905 | | cpu = debug_cpu_get_visible_cpu(machine); |
| 2906 | | if (cpu_get_address_space(cpu, ADDRESS_SPACE_PROGRAM + (space - EXPSPACE_PROGRAM_LOGICAL)) == NULL) |
| 2829 | if (device == NULL) |
| 2830 | device = debug_cpu_get_visible_cpu(machine); |
| 2831 | if (cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM + (space - EXPSPACE_PROGRAM_LOGICAL)) == NULL) |
| 2907 | 2832 | return EXPRERR_NO_SUCH_MEMORY_SPACE; |
| 2908 | 2833 | break; |
| 2909 | 2834 | |
| r6826 | r6827 | |
| 2913 | 2838 | case EXPSPACE_SPACE3_PHYSICAL: |
| 2914 | 2839 | if (name != NULL) |
| 2915 | 2840 | { |
| 2916 | | cpu = expression_cpu_index(machine, name); |
| 2917 | | if (cpu == NULL) |
| 2841 | device = expression_get_device(machine, name); |
| 2842 | if (device == NULL) |
| 2918 | 2843 | return EXPRERR_INVALID_MEMORY_NAME; |
| 2919 | 2844 | } |
| 2920 | | if (cpu == NULL) |
| 2921 | | cpu = debug_cpu_get_visible_cpu(machine); |
| 2922 | | if (cpu_get_address_space(cpu, ADDRESS_SPACE_PROGRAM + (space - EXPSPACE_PROGRAM_PHYSICAL)) == NULL) |
| 2845 | if (device == NULL) |
| 2846 | device = debug_cpu_get_visible_cpu(machine); |
| 2847 | if (cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM + (space - EXPSPACE_PROGRAM_PHYSICAL)) == NULL) |
| 2923 | 2848 | return EXPRERR_NO_SUCH_MEMORY_SPACE; |
| 2924 | 2849 | break; |
| 2925 | 2850 | |
| r6826 | r6827 | |
| 2927 | 2852 | case EXPSPACE_RAMWRITE: |
| 2928 | 2853 | if (name != NULL) |
| 2929 | 2854 | { |
| 2930 | | cpu = expression_cpu_index(machine, name); |
| 2931 | | if (cpu == NULL) |
| 2855 | device = expression_get_device(machine, name); |
| 2856 | if (device == NULL) |
| 2932 | 2857 | return EXPRERR_INVALID_MEMORY_NAME; |
| 2933 | 2858 | } |
| 2934 | | if (cpu == NULL) |
| 2935 | | cpu = debug_cpu_get_visible_cpu(machine); |
| 2936 | | if (cpu_get_address_space(cpu, ADDRESS_SPACE_PROGRAM) == NULL) |
| 2859 | if (device == NULL) |
| 2860 | device = debug_cpu_get_visible_cpu(machine); |
| 2861 | if (cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM) == NULL) |
| 2937 | 2862 | return EXPRERR_NO_SUCH_MEMORY_SPACE; |
| 2938 | 2863 | break; |
| 2939 | 2864 | |
| 2940 | | case EXPSPACE_EEPROM: |
| 2941 | | if (name != NULL) |
| 2942 | | return EXPRERR_INVALID_MEMORY_NAME; |
| 2943 | | break; |
| 2944 | | |
| 2945 | 2865 | case EXPSPACE_REGION: |
| 2946 | 2866 | if (name == NULL) |
| 2947 | 2867 | return EXPRERR_MISSING_MEMORY_NAME; |
src/emu/devtempl.h
| r6826 | r6827 | |
| 57 | 57 | DEVTEMPLATE_CREDITS - optional - the device's credit string (default |
| 58 | 58 | is "Copyright Nicola Salmoria and the MAME Team") |
| 59 | 59 | |
| 60 | | DEVTEMPLATE_INLINE_CONFIG - optional - the name of the device's |
| 61 | | inline configuration structure; by default, it is assumed the |
| 62 | | device does not have any inline configuration |
| 63 | | |
| 64 | 60 | ***************************************************************************/ |
| 65 | 61 | |
| 66 | 62 | |
| r6826 | r6827 | |
| 79 | 75 | #define DT_HAS_MACHINE_CONFIG 0x0100 |
| 80 | 76 | #define DT_HAS_INLINE_CONFIG 0x0200 |
| 81 | 77 | #define DT_HAS_CONTRACT_LIST 0x0400 |
| 78 | #define DT_HAS_PROGRAM_SPACE 0x1000 |
| 79 | #define DT_HAS_DATA_SPACE 0x2000 |
| 80 | #define DT_HAS_IO_SPACE 0x4000 |
| 82 | 81 | |
| 83 | 82 | |
| 84 | 83 | /* verify core stuff is specified */ |
| r6826 | r6827 | |
| 90 | 89 | #error DEVTEMPLATE_FEATURES must be specified! |
| 91 | 90 | #endif |
| 92 | 91 | |
| 93 | | #if ((DEVTEMPLATE_FEATURES & DT_HAS_START) == 0) |
| 92 | #if (((DEVTEMPLATE_FEATURES) & DT_HAS_START) == 0) |
| 94 | 93 | #error Device start routine is required! |
| 95 | 94 | #endif |
| 96 | 95 | |
| r6826 | r6827 | |
| 102 | 101 | #error DEVTEMPLATE_FAMILY must be specified! |
| 103 | 102 | #endif |
| 104 | 103 | |
| 104 | #if (((DEVTEMPLATE_FEATURES) & (DT_HAS_PROGRAM_SPACE | DT_HAS_DATA_SPACE | DT_HAS_IO_SPACE)) != 0) |
| 105 | #ifndef DEVTEMPLATE_ENDIANNESS |
| 106 | #error DEVTEMPLATE_ENDIANNESS must be specified if an address space is present! |
| 107 | #endif |
| 108 | #endif |
| 109 | |
| 105 | 110 | #ifdef DEVTEMPLATE_DERIVED_FEATURES |
| 106 | 111 | #ifndef DEVTEMPLATE_DERIVED_NAME |
| 107 | 112 | #error DEVTEMPLATE_DERIVED_NAME must be specified! |
| r6826 | r6827 | |
| 164 | 169 | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = sizeof(DEVTEMPLATE_ID(,_config)); break; |
| 165 | 170 | #endif |
| 166 | 171 | case DEVINFO_INT_CLASS: info->i = DEVTEMPLATE_CLASS; break; |
| 172 | #ifdef DEVTEMPLATE_ENDIANNESS |
| 173 | case DEVINFO_INT_ENDIANNESS: info->i = DEVTEMPLATE_ENDIANNESS; break; |
| 174 | #endif |
| 175 | #if ((DEVTEMPLATE_FEATURES) & DT_HAS_PROGRAM_SPACE) |
| 176 | case DEVINFO_INT_DATABUS_WIDTH_0: info->i = DEVTEMPLATE_PGM_DATAWIDTH; break; |
| 177 | case DEVINFO_INT_ADDRBUS_WIDTH_0: info->i = DEVTEMPLATE_PGM_ADDRWIDTH; break; |
| 178 | #ifdef DEVTEMPLATE_PGM_ADDRSHIFT |
| 179 | case DEVINFO_INT_ADDRBUS_SHIFT_0: info->i = DEVTEMPLATE_PGM_ADDRSHIFT; break; |
| 180 | #endif |
| 181 | #endif |
| 182 | #if ((DEVTEMPLATE_FEATURES) & DT_HAS_DATA_SPACE) |
| 183 | case DEVINFO_INT_DATABUS_WIDTH_1: info->i = DEVTEMPLATE_DATA_DATAWIDTH; break; |
| 184 | case DEVINFO_INT_ADDRBUS_WIDTH_1: info->i = DEVTEMPLATE_DATA_ADDRWIDTH; break; |
| 185 | #ifdef DEVTEMPLATE_DATA_ADDRSHIFT |
| 186 | case DEVINFO_INT_ADDRBUS_SHIFT_1: info->i = DEVTEMPLATE_DATA_ADDRSHIFT; break; |
| 187 | #endif |
| 188 | #endif |
| 189 | #if ((DEVTEMPLATE_FEATURES) & DT_HAS_IO_SPACE) |
| 190 | case DEVINFO_INT_DATABUS_WIDTH_2: info->i = DEVTEMPLATE_IO_DATAWIDTH; break; |
| 191 | case DEVINFO_INT_ADDRBUS_WIDTH_2: info->i = DEVTEMPLATE_IO_ADDRWIDTH; break; |
| 192 | #ifdef DEVTEMPLATE_IO_ADDRSHIFT |
| 193 | case DEVINFO_INT_ADDRBUS_SHIFT_2: info->i = DEVTEMPLATE_IO_ADDRSHIFT; break; |
| 194 | #endif |
| 195 | #endif |
| 167 | 196 | |
| 168 | 197 | /* --- the following bits of info are returned as pointers --- */ |
| 169 | 198 | #if ((DEVTEMPLATE_FEATURES) & DT_HAS_ROM_REGION) |
| r6826 | r6827 | |
| 175 | 204 | #if ((DEVTEMPLATE_FEATURES) & DT_HAS_CONTRACT_LIST) |
| 176 | 205 | case DEVINFO_PTR_CONTRACT_LIST: info->contract_list = DEVTEMPLATE_ID1(DEVICE_CONTRACT_LIST_NAME()); break; |
| 177 | 206 | #endif |
| 207 | #if ((DEVTEMPLATE_FEATURES) & DT_HAS_PROGRAM_SPACE) |
| 208 | #ifdef DEVTEMPLATE_PGM_INTMAP |
| 209 | case DEVINFO_PTR_INTERNAL_MEMORY_MAP_0: info->p = (void *)DEVTEMPLATE_PGM_INTMAP; break; |
| 210 | #endif |
| 211 | #ifdef DEVTEMPLATE_PGM_DEFMAP |
| 212 | case DEVINFO_PTR_DEFAULT_MEMORY_MAP_0: info->p = (void *)DEVTEMPLATE_PGM_DEFMAP; break; |
| 213 | #endif |
| 214 | #endif |
| 215 | #if ((DEVTEMPLATE_FEATURES) & DT_HAS_DATA_SPACE) |
| 216 | #ifdef DEVTEMPLATE_DATA_INTMAP |
| 217 | case DEVINFO_PTR_INTERNAL_MEMORY_MAP_0: info->p = (void *)DEVTEMPLATE_DATA_INTMAP; break; |
| 218 | #endif |
| 219 | #ifdef DEVTEMPLATE_DATA_DEFMAP |
| 220 | case DEVINFO_PTR_DEFAULT_MEMORY_MAP_0: info->p = (void *)DEVTEMPLATE_DATA_DEFMAP; break; |
| 221 | #endif |
| 222 | #endif |
| 223 | #if ((DEVTEMPLATE_FEATURES) & DT_HAS_IO_SPACE) |
| 224 | #ifdef DEVTEMPLATE_IO_INTMAP |
| 225 | case DEVINFO_PTR_INTERNAL_MEMORY_MAP_0: info->p = (void *)DEVTEMPLATE_IO_INTMAP; break; |
| 226 | #endif |
| 227 | #ifdef DEVTEMPLATE_IO_DEFMAP |
| 228 | case DEVINFO_PTR_DEFAULT_MEMORY_MAP_0: info->p = (void *)DEVTEMPLATE_IO_DEFMAP; break; |
| 229 | #endif |
| 230 | #endif |
| 178 | 231 | |
| 232 | |
| 179 | 233 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 180 | 234 | #if ((DEVTEMPLATE_FEATURES) & DT_HAS_START) |
| 181 | 235 | case DEVINFO_FCT_START: info->start = DEVTEMPLATE_ID1(DEVICE_START_NAME()); break; |
| r6826 | r6827 | |
| 184 | 238 | case DEVINFO_FCT_RESET: info->reset = DEVTEMPLATE_ID1(DEVICE_RESET_NAME()); break; |
| 185 | 239 | #endif |
| 186 | 240 | #if ((DEVTEMPLATE_FEATURES) & DT_HAS_STOP) |
| 187 | | case DEVINFO_FCT_STOP: info->stop = DEVTEMPLATE_ID1(DEVICE_STOP_NAME()); break; |
| 241 | case DEVINFO_FCT_STOP: info->stop = DEVTEMPLATE_ID1(DEVICE_STOP_NAME()); break; |
| 188 | 242 | #endif |
| 189 | 243 | #if ((DEVTEMPLATE_FEATURES) & DT_HAS_EXECUTE) |
| 190 | 244 | case DEVINFO_FCT_EXECUTE: info->execute = DEVTEMPLATE_ID1(DEVICE_EXECUTE_NAME()); break; |
| r6826 | r6827 | |
| 204 | 258 | case DEVINFO_STR_FAMILY: strcpy(info->s, DEVTEMPLATE_FAMILY); break; |
| 205 | 259 | case DEVINFO_STR_VERSION: strcpy(info->s, DEVTEMPLATE_VERSION); break; |
| 206 | 260 | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, DEVTEMPLATE_SOURCE); break; |
| 207 | | case DEVINFO_STR_CREDITS: strcpy(info->s, DEVTEMPLATE_CREDITS); break; |
| 261 | case DEVINFO_STR_CREDITS: strcpy(info->s, DEVTEMPLATE_CREDITS); break; |
| 208 | 262 | } |
| 209 | 263 | } |
| 210 | 264 | |
| r6826 | r6827 | |
| 240 | 294 | { |
| 241 | 295 | switch (state) |
| 242 | 296 | { |
| 297 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 298 | #if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_PROGRAM_SPACE) |
| 299 | case DEVINFO_INT_DATABUS_WIDTH_0: info->i = DEVTEMPLATE_DERIVED_PGM_DATAWIDTH; break; |
| 300 | case DEVINFO_INT_ADDRBUS_WIDTH_0: info->i = DEVTEMPLATE_DERIVED_PGM_ADDRWIDTH; break; |
| 301 | #ifdef DEVTEMPLATE_PGM_ADDRSHIFT |
| 302 | case DEVINFO_INT_ADDRBUS_SHIFT_0: info->i = DEVTEMPLATE_DERIVED_PGM_ADDRSHIFT; break; |
| 303 | #endif |
| 304 | #endif |
| 305 | #if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_DATA_SPACE) |
| 306 | case DEVINFO_INT_DATABUS_WIDTH_1: info->i = DEVTEMPLATE_DERIVED_DATA_DATAWIDTH; break; |
| 307 | case DEVINFO_INT_ADDRBUS_WIDTH_1: info->i = DEVTEMPLATE_DERIVED_DATA_ADDRWIDTH; break; |
| 308 | #ifdef DEVTEMPLATE_DATA_ADDRSHIFT |
| 309 | case DEVINFO_INT_ADDRBUS_SHIFT_1: info->i = DEVTEMPLATE_DERIVED_DATA_ADDRSHIFT; break; |
| 310 | #endif |
| 311 | #endif |
| 312 | #if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_IO_SPACE) |
| 313 | case DEVINFO_INT_DATABUS_WIDTH_2: info->i = DEVTEMPLATE_DERIVED_IO_DATAWIDTH; break; |
| 314 | case DEVINFO_INT_ADDRBUS_WIDTH_2: info->i = DEVTEMPLATE_DERIVED_IO_ADDRWIDTH; break; |
| 315 | #ifdef DEVTEMPLATE_IO_ADDRSHIFT |
| 316 | case DEVINFO_INT_ADDRBUS_SHIFT_2: info->i = DEVTEMPLATE_DERIVED_IO_ADDRSHIFT; break; |
| 317 | #endif |
| 318 | #endif |
| 319 | |
| 243 | 320 | /* --- the following bits of info are returned as pointers --- */ |
| 244 | 321 | #if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_ROM_REGION) |
| 245 | 322 | case DEVINFO_PTR_ROM_REGION: info->romregion = DEVTEMPLATE_DERIVED_ID1(ROM_NAME()); break; |
| 246 | 323 | #endif |
| 247 | 324 | #if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_MACHINE_CONFIG) |
| 248 | | case DEVINFO_PTR_MACHINE_CONFIG: info->machine_config = DEVTEMPLATE_DERIVED_ID1(MACHINE_DRIVER_NAME()); break; |
| 325 | case DEVINFO_PTR_MACHINE_CONFIG: info->machine_config = DEVTEMPLATE_DERIVED_ID1(MACHINE_DRIVER_NAME()); break; |
| 249 | 326 | #endif |
| 250 | 327 | #if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_CONTRACT_LIST) |
| 251 | 328 | case DEVINFO_PTR_CONTRACT_LIST: info->contract_list = DEVTEMPLATE_DERIVED_ID1(DEVICE_CONTRACT_LIST_NAME()); break; |
| r6826 | r6827 | |
| 259 | 336 | case DEVINFO_FCT_RESET: info->reset = DEVTEMPLATE_DERIVED_ID1(DEVICE_RESET_NAME()); break; |
| 260 | 337 | #endif |
| 261 | 338 | #if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_STOP) |
| 262 | | case DEVINFO_FCT_STOP: info->stop = DEVTEMPLATE_DERIVED_ID1(DEVICE_STORE_NAME()); break; |
| 339 | case DEVINFO_FCT_STOP: info->stop = DEVTEMPLATE_DERIVED_ID1(DEVICE_STORE_NAME()); break; |
| 263 | 340 | #endif |
| 264 | 341 | #if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_EXECUTE) |
| 265 | 342 | case DEVINFO_FCT_EXECUTE: info->execute = DEVTEMPLATE_DERIVED_ID1(DEVICE_EXECUTE_NAME()); break; |
| r6826 | r6827 | |
| 292 | 369 | #undef DT_HAS_CUSTOM_CONFIG |
| 293 | 370 | #undef DT_HAS_ROM_REGION |
| 294 | 371 | #undef DT_HAS_MACHINE_CONFIG |
| 372 | #undef DT_HAS_INLINE_CONFIG |
| 373 | #undef DT_HAS_CONTRACT_LIST |
| 374 | #undef DT_HAS_PROGRAM_SPACE |
| 375 | #undef DT_HAS_DATA_SPACE |
| 376 | #undef DT_HAS_IO_SPACE |
| 295 | 377 | |
| 296 | 378 | #undef DEVTEMPLATE_DERIVED_ID |
| 297 | 379 | #undef DEVTEMPLATE_DERIVED_FEATURES |
src/emu/machine/eepromdev.c
| r6826 | r6827 | |
| 1 | | /* |
| 2 | | * Serial eeproms |
| 3 | | * |
| 4 | | */ |
| 5 | | |
| 6 | | #include "driver.h" |
| 7 | | #include "machine/eepromdev.h" |
| 8 | | |
| 9 | | #define VERBOSE 0 |
| 10 | | #define LOG(x) do { if (VERBOSE) logerror x; } while (0) |
| 11 | | |
| 12 | | #define SERIAL_BUFFER_LENGTH 40 |
| 13 | | #define MEMORY_SIZE 1024 |
| 14 | | |
| 15 | | /* FIXME: many drivers do not need default_data / default_data_size and put them to 0 in the drivers seems a waste of code */ |
| 16 | | UINT8 *eeprom_empty_default_data = NULL; |
| 17 | | |
| 18 | | typedef struct _eeprom_state eeprom_state; |
| 19 | | struct _eeprom_state |
| 20 | | { |
| 21 | | const eeprom_interface *intf; |
| 22 | | int serial_count; |
| 23 | | UINT8 serial_buffer[SERIAL_BUFFER_LENGTH]; |
| 24 | | UINT8 data[MEMORY_SIZE]; |
| 25 | | int data_bits; |
| 26 | | int read_address; |
| 27 | | int clock_count; |
| 28 | | int latch,reset_line,clock_line,sending; |
| 29 | | int locked; |
| 30 | | int reset_delay; |
| 31 | | }; |
| 32 | | |
| 33 | | /*------------------------------------------------- |
| 34 | | get_safe_token - makes sure that the passed |
| 35 | | in device is, in fact, an I2C memory |
| 36 | | -------------------------------------------------*/ |
| 37 | | |
| 38 | | INLINE eeprom_state *get_safe_token(const device_config *device) |
| 39 | | { |
| 40 | | assert( device != NULL ); |
| 41 | | assert( device->token != NULL ); |
| 42 | | assert( device->type == EEPROM ); |
| 43 | | |
| 44 | | return (eeprom_state *)device->token; |
| 45 | | } |
| 46 | | |
| 47 | | /* |
| 48 | | eeprom_command_match: |
| 49 | | |
| 50 | | Try to match the first (len) digits in the EEPROM serial buffer |
| 51 | | string (*buf) with an EEPROM command string (*cmd). |
| 52 | | Return non zero if a match was found. |
| 53 | | |
| 54 | | The serial buffer only contains '0' or '1' (e.g. "1001"). |
| 55 | | The command can contain: '0' or '1' or these wildcards: |
| 56 | | |
| 57 | | 'x' : match both '0' and '1' |
| 58 | | "*1": match "1", "01", "001", "0001" etc. |
| 59 | | "*0": match "0", "10", "110", "1110" etc. |
| 60 | | |
| 61 | | Note: (cmd) may be NULL. Return 0 (no match) in this case. |
| 62 | | */ |
| 63 | | static int eeprom_command_match(const char *buf, const char *cmd, int len) |
| 64 | | { |
| 65 | | if ( cmd == 0 ) return 0; |
| 66 | | if ( len == 0 ) return 0; |
| 67 | | |
| 68 | | for (;len>0;) |
| 69 | | { |
| 70 | | char b = *buf; |
| 71 | | char c = *cmd; |
| 72 | | |
| 73 | | if ((b==0) || (c==0)) |
| 74 | | return (b==c); |
| 75 | | |
| 76 | | switch ( c ) |
| 77 | | { |
| 78 | | case '0': |
| 79 | | case '1': |
| 80 | | if (b != c) return 0; |
| 81 | | case 'X': |
| 82 | | case 'x': |
| 83 | | buf++; |
| 84 | | len--; |
| 85 | | cmd++; |
| 86 | | break; |
| 87 | | |
| 88 | | case '*': |
| 89 | | c = cmd[1]; |
| 90 | | switch( c ) |
| 91 | | { |
| 92 | | case '0': |
| 93 | | case '1': |
| 94 | | if (b == c) { cmd++; } |
| 95 | | else { buf++; len--; } |
| 96 | | break; |
| 97 | | default: return 0; |
| 98 | | } |
| 99 | | } |
| 100 | | } |
| 101 | | return (*cmd==0); |
| 102 | | } |
| 103 | | |
| 104 | | |
| 105 | | const eeprom_interface eepromdev_interface_93C46 = |
| 106 | | { |
| 107 | | 6, // address bits 6 |
| 108 | | 16, // data bits 16 |
| 109 | | "*110", // read 1 10 aaaaaa |
| 110 | | "*101", // write 1 01 aaaaaa dddddddddddddddd |
| 111 | | "*111", // erase 1 11 aaaaaa |
| 112 | | "*10000xxxx", // lock 1 00 00xxxx |
| 113 | | "*10011xxxx", // unlock 1 00 11xxxx |
| 114 | | 1, |
| 115 | | // "*10001xxxx" // write all 1 00 01xxxx dddddddddddddddd |
| 116 | | // "*10010xxxx" // erase all 1 00 10xxxx |
| 117 | | }; |
| 118 | | |
| 119 | | const eeprom_interface eepromdev_interface_93C66B = |
| 120 | | { |
| 121 | | 8, /* address bits */ |
| 122 | | 16, /* data bits */ |
| 123 | | "*110", /* read command */ |
| 124 | | "*101", /* write command */ |
| 125 | | "*111", /* erase command */ |
| 126 | | "*10000xxxxxx", /* lock command */ |
| 127 | | "*10011xxxxxx", /* unlock command */ |
| 128 | | 1, |
| 129 | | // "*10001xxxxxx", /* write all */ |
| 130 | | // "*10010xxxxxx", /* erase all */ |
| 131 | | }; |
| 132 | | |
| 133 | | static void eeprom_write(eeprom_state *eestate, int bit) |
| 134 | | { |
| 135 | | LOG(("EEPROM write bit %d\n",bit)); |
| 136 | | |
| 137 | | if (eestate->serial_count >= SERIAL_BUFFER_LENGTH-1) |
| 138 | | { |
| 139 | | logerror("error: EEPROM serial buffer overflow\n"); |
| 140 | | return; |
| 141 | | } |
| 142 | | |
| 143 | | eestate->serial_buffer[eestate->serial_count++] = (bit ? '1' : '0'); |
| 144 | | eestate->serial_buffer[eestate->serial_count] = 0; /* nul terminate so we can treat it as a string */ |
| 145 | | |
| 146 | | if ( (eestate->serial_count > eestate->intf->address_bits) && |
| 147 | | eeprom_command_match((char*)(eestate->serial_buffer),eestate->intf->cmd_read,strlen((char*)(eestate->serial_buffer))-eestate->intf->address_bits) ) |
| 148 | | { |
| 149 | | int i,address; |
| 150 | | |
| 151 | | address = 0; |
| 152 | | for (i = eestate->serial_count-eestate->intf->address_bits;i < eestate->serial_count;i++) |
| 153 | | { |
| 154 | | address <<= 1; |
| 155 | | if (eestate->serial_buffer[i] == '1') address |= 1; |
| 156 | | } |
| 157 | | if (eestate->intf->data_bits == 16) |
| 158 | | eestate->data_bits = (eestate->data[2*address+0] << 8) + eestate->data[2*address+1]; |
| 159 | | else |
| 160 | | eestate->data_bits = eestate->data[address]; |
| 161 | | eestate->read_address = address; |
| 162 | | eestate->clock_count = 0; |
| 163 | | eestate->sending = 1; |
| 164 | | eestate->serial_count = 0; |
| 165 | | logerror("EEPROM read %04x from address %02x\n",eestate->data_bits,address); |
| 166 | | } |
| 167 | | else if ( (eestate->serial_count > eestate->intf->address_bits) && |
| 168 | | eeprom_command_match((char*)(eestate->serial_buffer),eestate->intf->cmd_erase,strlen((char*)(eestate->serial_buffer))-eestate->intf->address_bits) ) |
| 169 | | { |
| 170 | | int i,address; |
| 171 | | |
| 172 | | address = 0; |
| 173 | | for (i = eestate->serial_count-eestate->intf->address_bits;i < eestate->serial_count;i++) |
| 174 | | { |
| 175 | | address <<= 1; |
| 176 | | if (eestate->serial_buffer[i] == '1') address |= 1; |
| 177 | | } |
| 178 | | logerror("EEPROM erase address %02x\n",address); |
| 179 | | if (eestate->locked == 0) |
| 180 | | { |
| 181 | | if (eestate->intf->data_bits == 16) |
| 182 | | { |
| 183 | | eestate->data[2*address+0] = 0x00; |
| 184 | | eestate->data[2*address+1] = 0x00; |
| 185 | | } |
| 186 | | else |
| 187 | | eestate->data[address] = 0x00; |
| 188 | | } |
| 189 | | else |
| 190 | | logerror("Error: EEPROM is locked\n"); |
| 191 | | eestate->serial_count = 0; |
| 192 | | } |
| 193 | | else if ( (eestate->serial_count > (eestate->intf->address_bits + eestate->intf->data_bits)) && |
| 194 | | eeprom_command_match((char*)(eestate->serial_buffer),eestate->intf->cmd_write,strlen((char*)(eestate->serial_buffer))-(eestate->intf->address_bits + eestate->intf->data_bits)) ) |
| 195 | | { |
| 196 | | int i,address,data; |
| 197 | | |
| 198 | | address = 0; |
| 199 | | for (i = eestate->serial_count-eestate->intf->data_bits-eestate->intf->address_bits;i < (eestate->serial_count-eestate->intf->data_bits);i++) |
| 200 | | { |
| 201 | | address <<= 1; |
| 202 | | if (eestate->serial_buffer[i] == '1') address |= 1; |
| 203 | | } |
| 204 | | data = 0; |
| 205 | | for (i = eestate->serial_count-eestate->intf->data_bits;i < eestate->serial_count;i++) |
| 206 | | { |
| 207 | | data <<= 1; |
| 208 | | if (eestate->serial_buffer[i] == '1') data |= 1; |
| 209 | | } |
| 210 | | logerror("EEPROM write %04x to address %02x\n",data,address); |
| 211 | | if (eestate->locked == 0) |
| 212 | | { |
| 213 | | if (eestate->intf->data_bits == 16) |
| 214 | | { |
| 215 | | eestate->data[2*address+0] = data >> 8; |
| 216 | | eestate->data[2*address+1] = data & 0xff; |
| 217 | | } |
| 218 | | else |
| 219 | | eestate->data[address] = data; |
| 220 | | } |
| 221 | | else |
| 222 | | logerror("Error: EEPROM is locked\n"); |
| 223 | | eestate->serial_count = 0; |
| 224 | | } |
| 225 | | else if ( eeprom_command_match((char*)(eestate->serial_buffer),eestate->intf->cmd_lock,strlen((char*)(eestate->serial_buffer))) ) |
| 226 | | { |
| 227 | | logerror("EEPROM lock\n"); |
| 228 | | eestate->locked = 1; |
| 229 | | eestate->serial_count = 0; |
| 230 | | } |
| 231 | | else if ( eeprom_command_match((char*)(eestate->serial_buffer),eestate->intf->cmd_unlock,strlen((char*)(eestate->serial_buffer))) ) |
| 232 | | { |
| 233 | | logerror("EEPROM unlock\n"); |
| 234 | | eestate->locked = 0; |
| 235 | | eestate->serial_count = 0; |
| 236 | | } |
| 237 | | } |
| 238 | | |
| 239 | | static void eeprom_reset(eeprom_state *eestate) |
| 240 | | { |
| 241 | | if (eestate->serial_count) |
| 242 | | logerror("EEPROM reset, buffer = %s\n",eestate->serial_buffer); |
| 243 | | |
| 244 | | eestate->serial_count = 0; |
| 245 | | eestate->sending = 0; |
| 246 | | eestate->reset_delay = eestate->intf->reset_delay; /* delay a little before returning setting data to 1 (needed by wbeachvl) */ |
| 247 | | } |
| 248 | | |
| 249 | | |
| 250 | | WRITE_LINE_DEVICE_HANDLER( eepromdev_write_bit ) |
| 251 | | { |
| 252 | | eeprom_state *eestate = get_safe_token(device); |
| 253 | | |
| 254 | | LOG(("write bit %d\n",state)); |
| 255 | | eestate->latch = state; |
| 256 | | } |
| 257 | | |
| 258 | | READ_LINE_DEVICE_HANDLER( eepromdev_read_bit ) |
| 259 | | { |
| 260 | | eeprom_state *eestate = get_safe_token(device); |
| 261 | | int res; |
| 262 | | |
| 263 | | if (eestate->sending) |
| 264 | | res = (eestate->data_bits >> eestate->intf->data_bits) & 1; |
| 265 | | else |
| 266 | | { |
| 267 | | if (eestate->reset_delay > 0) |
| 268 | | { |
| 269 | | /* this is needed by wbeachvl */ |
| 270 | | eestate->reset_delay--; |
| 271 | | res = 0; |
| 272 | | } |
| 273 | | else |
| 274 | | res = 1; |
| 275 | | } |
| 276 | | |
| 277 | | LOG(("read bit %d\n",res)); |
| 278 | | |
| 279 | | return res; |
| 280 | | } |
| 281 | | |
| 282 | | WRITE_LINE_DEVICE_HANDLER( eepromdev_set_cs_line ) |
| 283 | | { |
| 284 | | eeprom_state *eestate = get_safe_token(device); |
| 285 | | |
| 286 | | LOG(("set reset line %d\n",state)); |
| 287 | | eestate->reset_line = state; |
| 288 | | |
| 289 | | if (eestate->reset_line != CLEAR_LINE) |
| 290 | | eeprom_reset(eestate); |
| 291 | | } |
| 292 | | |
| 293 | | WRITE_LINE_DEVICE_HANDLER( eepromdev_set_clock_line ) |
| 294 | | { |
| 295 | | eeprom_state *eestate = get_safe_token(device); |
| 296 | | |
| 297 | | LOG(("set clock line %d\n",state)); |
| 298 | | if (state == PULSE_LINE || (eestate->clock_line == CLEAR_LINE && state != CLEAR_LINE)) |
| 299 | | { |
| 300 | | if (eestate->reset_line == CLEAR_LINE) |
| 301 | | { |
| 302 | | if (eestate->sending) |
| 303 | | { |
| 304 | | if (eestate->clock_count == eestate->intf->data_bits && eestate->intf->enable_multi_read) |
| 305 | | { |
| 306 | | eestate->read_address = (eestate->read_address + 1) & ((1 << eestate->intf->address_bits) - 1); |
| 307 | | if (eestate->intf->data_bits == 16) |
| 308 | | eestate->data_bits = (eestate->data[2*eestate->read_address+0] << 8) + eestate->data[2*eestate->read_address+1]; |
| 309 | | else |
| 310 | | eestate->data_bits = eestate->data[eestate->read_address]; |
| 311 | | eestate->clock_count = 0; |
| 312 | | logerror("EEPROM read %04x from address %02x\n",eestate->data_bits,eestate->read_address); |
| 313 | | } |
| 314 | | eestate->data_bits = (eestate->data_bits << 1) | 1; |
| 315 | | eestate->clock_count++; |
| 316 | | } |
| 317 | | else |
| 318 | | eeprom_write(eestate,eestate->latch); |
| 319 | | } |
| 320 | | } |
| 321 | | |
| 322 | | eestate->clock_line = state; |
| 323 | | } |
| 324 | | |
| 325 | | |
| 326 | | static void eepromdev_load(const device_config *device, mame_file *f) |
| 327 | | { |
| 328 | | eeprom_state *eestate = get_safe_token(device); |
| 329 | | |
| 330 | | mame_fread(f, eestate->data, (1 << eestate->intf->address_bits) * eestate->intf->data_bits / 8); |
| 331 | | } |
| 332 | | |
| 333 | | static void eepromdev_save(const device_config *device, mame_file *f) |
| 334 | | { |
| 335 | | eeprom_state *eestate = get_safe_token(device); |
| 336 | | |
| 337 | | mame_fwrite(f, eestate->data, (1 << eestate->intf->address_bits) * eestate->intf->data_bits / 8); |
| 338 | | } |
| 339 | | |
| 340 | | void eepromdev_set_data(const device_config *device, const UINT8 *data, int length) |
| 341 | | { |
| 342 | | eeprom_state *eestate = get_safe_token(device); |
| 343 | | |
| 344 | | assert(length <= ((1 << eestate->intf->address_bits) * eestate->intf->data_bits / 8)); |
| 345 | | memcpy(eestate->data, data, length); |
| 346 | | /* temporary: write data to eeprom.bin when this happens so we capture it |
| 347 | | for adding to a region */ |
| 348 | | { |
| 349 | | FILE *f = fopen("eeprom.bin", "wb"); |
| 350 | | fwrite(eestate->data, 1, (1 << eestate->intf->address_bits) * eestate->intf->data_bits / 8, f); |
| 351 | | fclose(f); |
| 352 | | } |
| 353 | | } |
| 354 | | |
| 355 | | void *eepromdev_get_data_pointer(const device_config *device, UINT32 *length, UINT32 *size) |
| 356 | | { |
| 357 | | eeprom_state *eestate = get_safe_token(device); |
| 358 | | |
| 359 | | if (length != NULL && eestate->intf != NULL) |
| 360 | | *length = 1 << eestate->intf->address_bits; |
| 361 | | if (size != NULL && eestate->intf != NULL) |
| 362 | | *size = eestate->intf->data_bits / 8; |
| 363 | | |
| 364 | | return eestate->data; |
| 365 | | } |
| 366 | | |
| 367 | | static DEVICE_NVRAM( eeprom ) |
| 368 | | { |
| 369 | | const eeprom_config *config = (const eeprom_config *)device->inline_config; |
| 370 | | |
| 371 | | if (read_or_write) |
| 372 | | eepromdev_save(device, file); |
| 373 | | else |
| 374 | | if (file) |
| 375 | | eepromdev_load(device, file); |
| 376 | | else |
| 377 | | if ((config->default_data != NULL) && (config->default_data_size != 0)) |
| 378 | | eepromdev_set_data(device, config->default_data, config->default_data_size); |
| 379 | | } |
| 380 | | |
| 381 | | static DEVICE_START(eeprom) |
| 382 | | { |
| 383 | | eeprom_state *eestate = get_safe_token(device); |
| 384 | | const eeprom_config *config; |
| 385 | | UINT8 *region_base; |
| 386 | | |
| 387 | | /* validate some basic stuff */ |
| 388 | | assert(device != NULL); |
| 389 | | assert(device->inline_config != NULL); |
| 390 | | assert(device->machine != NULL); |
| 391 | | assert(device->machine->config != NULL); |
| 392 | | |
| 393 | | config = (const eeprom_config *)device->inline_config; |
| 394 | | |
| 395 | | eestate->intf = config->pinterface; |
| 396 | | |
| 397 | | if ((1 << eestate->intf->address_bits) * eestate->intf->data_bits / 8 > MEMORY_SIZE) |
| 398 | | { |
| 399 | | fatalerror("EEPROM larger than eepromdev.c allows"); |
| 400 | | } |
| 401 | | |
| 402 | | memset(eestate->data, 0xff, (1 << eestate->intf->address_bits) * eestate->intf->data_bits / 8); |
| 403 | | if ((config->default_data != NULL) && (config->default_data_size != 0)) |
| 404 | | eepromdev_set_data(device, config->default_data, config->default_data_size); |
| 405 | | |
| 406 | | region_base = memory_region(device->machine, device->tag); |
| 407 | | if (region_base != NULL) |
| 408 | | { |
| 409 | | UINT32 region_length = memory_region_length(device->machine, device->tag); |
| 410 | | UINT32 region_flags = memory_region_flags(device->machine, device->tag); |
| 411 | | |
| 412 | | if (region_length != (1 << eestate->intf->address_bits) * eestate->intf->data_bits / 8) |
| 413 | | fatalerror("eeprom region '%s' wrong size (expected size = 0x%X)", device->tag, (1 << eestate->intf->address_bits) * eestate->intf->data_bits / 8); |
| 414 | | if (eestate->intf->data_bits == 8 && (region_flags & ROMREGION_WIDTHMASK) != ROMREGION_8BIT) |
| 415 | | fatalerror("eeprom region '%s' needs to be an 8-bit region", device->tag); |
| 416 | | if (eestate->intf->data_bits == 16 && ((region_flags & ROMREGION_WIDTHMASK) != ROMREGION_16BIT || (region_flags & ROMREGION_ENDIANMASK) != ROMREGION_BE)) |
| 417 | | fatalerror("eeprom region '%s' needs to be a 16-bit big-endian region (flags=%08x)", device->tag, region_flags); |
| 418 | | memcpy(eestate->data, region_base, region_length); |
| 419 | | } |
| 420 | | |
| 421 | | eestate->serial_count = 0; |
| 422 | | eestate->latch = 0; |
| 423 | | eestate->reset_line = ASSERT_LINE; |
| 424 | | eestate->clock_line = ASSERT_LINE; |
| 425 | | eestate->read_address = 0; |
| 426 | | eestate->sending = 0; |
| 427 | | if (eestate->intf->cmd_unlock) eestate->locked = 1; |
| 428 | | else eestate->locked = 0; |
| 429 | | |
| 430 | | state_save_register_device_item_pointer( device, 0, eestate->data, MEMORY_SIZE); |
| 431 | | state_save_register_device_item_pointer( device, 0, eestate->serial_buffer, SERIAL_BUFFER_LENGTH); |
| 432 | | state_save_register_device_item( device, 0, eestate->clock_line); |
| 433 | | state_save_register_device_item( device, 0, eestate->reset_line); |
| 434 | | state_save_register_device_item( device, 0, eestate->locked); |
| 435 | | state_save_register_device_item( device, 0, eestate->serial_count); |
| 436 | | state_save_register_device_item( device, 0, eestate->latch); |
| 437 | | state_save_register_device_item( device, 0, eestate->reset_delay); |
| 438 | | state_save_register_device_item( device, 0, eestate->clock_count); |
| 439 | | state_save_register_device_item( device, 0, eestate->data_bits); |
| 440 | | state_save_register_device_item( device, 0, eestate->read_address); |
| 441 | | } |
| 442 | | |
| 443 | | static DEVICE_RESET(eeprom) |
| 444 | | { |
| 445 | | } |
| 446 | | |
| 447 | | |
| 448 | | static const char DEVTEMPLATE_SOURCE[] = __FILE__; |
| 449 | | |
| 450 | | #define DEVTEMPLATE_ID(p,s) p##eeprom##s |
| 451 | | #define DEVTEMPLATE_FEATURES DT_HAS_START | DT_HAS_RESET | DT_HAS_NVRAM | DT_HAS_INLINE_CONFIG |
| 452 | | #define DEVTEMPLATE_NAME "EEPROM" |
| 453 | | #define DEVTEMPLATE_FAMILY "EEPROM" |
| 454 | | #include "devtempl.h" |
src/emu/machine/eeprom.c
| r6826 | r6827 | |
| 1 | /* |
| 2 | * Serial eeproms |
| 3 | * |
| 4 | */ |
| 5 | |
| 1 | 6 | #include "driver.h" |
| 2 | | #include "eeprom.h" |
| 7 | #include "machine/eeprom.h" |
| 3 | 8 | |
| 4 | 9 | #define VERBOSE 0 |
| 5 | 10 | #define LOG(x) do { if (VERBOSE) logerror x; } while (0) |
| 6 | 11 | |
| 7 | 12 | #define SERIAL_BUFFER_LENGTH 40 |
| 8 | | #define MEMORY_SIZE 1024 |
| 9 | 13 | |
| 10 | | static const eeprom_interface *intf; |
| 14 | typedef struct _eeprom_state eeprom_state; |
| 15 | struct _eeprom_state |
| 16 | { |
| 17 | const eeprom_interface *intf; |
| 18 | int serial_count; |
| 19 | UINT8 serial_buffer[SERIAL_BUFFER_LENGTH]; |
| 20 | int data_bits; |
| 21 | int read_address; |
| 22 | int clock_count; |
| 23 | int latch,reset_line,clock_line,sending; |
| 24 | int locked; |
| 25 | int reset_delay; |
| 26 | }; |
| 11 | 27 | |
| 12 | | static int serial_count; |
| 13 | | static UINT8 serial_buffer[SERIAL_BUFFER_LENGTH]; |
| 14 | | static UINT8 eeprom_data[MEMORY_SIZE]; |
| 15 | | static int eeprom_data_bits; |
| 16 | | static int eeprom_read_address; |
| 17 | | static int eeprom_clock_count; |
| 18 | | static int latch,reset_line,clock_line,sending; |
| 19 | | static int locked; |
| 20 | | static int reset_delay; |
| 28 | /*------------------------------------------------- |
| 29 | get_safe_token - makes sure that the passed |
| 30 | in device is, in fact, an I2C memory |
| 31 | -------------------------------------------------*/ |
| 21 | 32 | |
| 33 | INLINE eeprom_state *get_safe_token(const device_config *device) |
| 34 | { |
| 35 | assert( device != NULL ); |
| 36 | assert( device->token != NULL ); |
| 37 | assert( device->type == EEPROM ); |
| 38 | |
| 39 | return (eeprom_state *)device->token; |
| 40 | } |
| 41 | |
| 22 | 42 | /* |
| 23 | 43 | eeprom_command_match: |
| 24 | 44 | |
| r6826 | r6827 | |
| 66 | 86 | { |
| 67 | 87 | case '0': |
| 68 | 88 | case '1': |
| 69 | | if (b == c) { cmd++; } |
| 89 | if (b == c) { cmd++; } |
| 70 | 90 | else { buf++; len--; } |
| 71 | 91 | break; |
| 72 | 92 | default: return 0; |
| r6826 | r6827 | |
| 105 | 125 | // "*10010xxxxxx", /* erase all */ |
| 106 | 126 | }; |
| 107 | 127 | |
| 108 | | NVRAM_HANDLER( 93C46 ) |
| 128 | static void eeprom_write(const device_config *device, int bit) |
| 109 | 129 | { |
| 110 | | if (read_or_write) |
| 111 | | eeprom_save(file); |
| 112 | | else |
| 113 | | { |
| 114 | | eeprom_init(machine, &eeprom_interface_93C46); |
| 115 | | if (file) eeprom_load(file); |
| 116 | | } |
| 117 | | } |
| 130 | eeprom_state *eestate = get_safe_token(device); |
| 118 | 131 | |
| 119 | | NVRAM_HANDLER( 93C66B ) |
| 120 | | { |
| 121 | | if (read_or_write) |
| 122 | | eeprom_save(file); |
| 123 | | else |
| 124 | | { |
| 125 | | eeprom_init(machine, &eeprom_interface_93C66B); |
| 126 | | if (file) eeprom_load(file); |
| 127 | | } |
| 128 | | } |
| 129 | | |
| 130 | | void eeprom_init(running_machine *machine, const eeprom_interface *interface) |
| 131 | | { |
| 132 | | intf = interface; |
| 133 | | |
| 134 | | if ((1 << intf->address_bits) * intf->data_bits / 8 > MEMORY_SIZE) |
| 135 | | { |
| 136 | | fatalerror("EEPROM larger than eeprom.c allows"); |
| 137 | | } |
| 138 | | |
| 139 | | memset(eeprom_data,0xff,(1 << intf->address_bits) * intf->data_bits / 8); |
| 140 | | serial_count = 0; |
| 141 | | latch = 0; |
| 142 | | reset_line = ASSERT_LINE; |
| 143 | | clock_line = ASSERT_LINE; |
| 144 | | eeprom_read_address = 0; |
| 145 | | sending = 0; |
| 146 | | if (intf->cmd_unlock) locked = 1; |
| 147 | | else locked = 0; |
| 148 | | |
| 149 | | state_save_register_global_array(machine, eeprom_data); |
| 150 | | state_save_register_global_array(machine, serial_buffer); |
| 151 | | state_save_register_global(machine, clock_line); |
| 152 | | state_save_register_global(machine, reset_line); |
| 153 | | state_save_register_global(machine, locked); |
| 154 | | state_save_register_global(machine, serial_count); |
| 155 | | state_save_register_global(machine, latch); |
| 156 | | state_save_register_global(machine, reset_delay); |
| 157 | | state_save_register_global(machine, eeprom_clock_count); |
| 158 | | state_save_register_global(machine, eeprom_data_bits); |
| 159 | | state_save_register_global(machine, eeprom_read_address); |
| 160 | | } |
| 161 | | |
| 162 | | static void eeprom_write(int bit) |
| 163 | | { |
| 164 | 132 | LOG(("EEPROM write bit %d\n",bit)); |
| 165 | 133 | |
| 166 | | if (serial_count >= SERIAL_BUFFER_LENGTH-1) |
| 134 | if (eestate->serial_count >= SERIAL_BUFFER_LENGTH-1) |
| 167 | 135 | { |
| 168 | 136 | logerror("error: EEPROM serial buffer overflow\n"); |
| 169 | 137 | return; |
| 170 | 138 | } |
| 171 | 139 | |
| 172 | | serial_buffer[serial_count++] = (bit ? '1' : '0'); |
| 173 | | serial_buffer[serial_count] = 0; /* nul terminate so we can treat it as a string */ |
| 140 | eestate->serial_buffer[eestate->serial_count++] = (bit ? '1' : '0'); |
| 141 | eestate->serial_buffer[eestate->serial_count] = 0; /* nul terminate so we can treat it as a string */ |
| 174 | 142 | |
| 175 | | if ( (serial_count > intf->address_bits) && |
| 176 | | eeprom_command_match((char*)serial_buffer,intf->cmd_read,strlen((char*)serial_buffer)-intf->address_bits) ) |
| 143 | if ( (eestate->serial_count > eestate->intf->address_bits) && |
| 144 | eeprom_command_match((char*)(eestate->serial_buffer),eestate->intf->cmd_read,strlen((char*)(eestate->serial_buffer))-eestate->intf->address_bits) ) |
| 177 | 145 | { |
| 178 | 146 | int i,address; |
| 179 | 147 | |
| 180 | 148 | address = 0; |
| 181 | | for (i = serial_count-intf->address_bits;i < serial_count;i++) |
| 149 | for (i = eestate->serial_count-eestate->intf->address_bits;i < eestate->serial_count;i++) |
| 182 | 150 | { |
| 183 | 151 | address <<= 1; |
| 184 | | if (serial_buffer[i] == '1') address |= 1; |
| 152 | if (eestate->serial_buffer[i] == '1') address |= 1; |
| 185 | 153 | } |
| 186 | | if (intf->data_bits == 16) |
| 187 | | eeprom_data_bits = (eeprom_data[2*address+0] << 8) + eeprom_data[2*address+1]; |
| 154 | if (eestate->intf->data_bits == 16) |
| 155 | eestate->data_bits = memory_read_word(device->space[0], address * 2); |
| 188 | 156 | else |
| 189 | | eeprom_data_bits = eeprom_data[address]; |
| 190 | | eeprom_read_address = address; |
| 191 | | eeprom_clock_count = 0; |
| 192 | | sending = 1; |
| 193 | | serial_count = 0; |
| 194 | | logerror("EEPROM read %04x from address %02x\n",eeprom_data_bits,address); |
| 157 | eestate->data_bits = memory_read_byte(device->space[0], address); |
| 158 | eestate->read_address = address; |
| 159 | eestate->clock_count = 0; |
| 160 | eestate->sending = 1; |
| 161 | eestate->serial_count = 0; |
| 162 | logerror("EEPROM read %04x from address %02x\n",eestate->data_bits,address); |
| 195 | 163 | } |
| 196 | | else if ( (serial_count > intf->address_bits) && |
| 197 | | eeprom_command_match((char*)serial_buffer,intf->cmd_erase,strlen((char*)serial_buffer)-intf->address_bits) ) |
| 164 | else if ( (eestate->serial_count > eestate->intf->address_bits) && |
| 165 | eeprom_command_match((char*)(eestate->serial_buffer),eestate->intf->cmd_erase,strlen((char*)(eestate->serial_buffer))-eestate->intf->address_bits) ) |
| 198 | 166 | { |
| 199 | 167 | int i,address; |
| 200 | 168 | |
| 201 | 169 | address = 0; |
| 202 | | for (i = serial_count-intf->address_bits;i < serial_count;i++) |
| 170 | for (i = eestate->serial_count-eestate->intf->address_bits;i < eestate->serial_count;i++) |
| 203 | 171 | { |
| 204 | 172 | address <<= 1; |
| 205 | | if (serial_buffer[i] == '1') address |= 1; |
| 173 | if (eestate->serial_buffer[i] == '1') address |= 1; |
| 206 | 174 | } |
| 207 | 175 | logerror("EEPROM erase address %02x\n",address); |
| 208 | | if (locked == 0) |
| 176 | if (eestate->locked == 0) |
| 209 | 177 | { |
| 210 | | if (intf->data_bits == 16) |
| 211 | | { |
| 212 | | eeprom_data[2*address+0] = 0xff; |
| 213 | | eeprom_data[2*address+1] = 0xff; |
| 214 | | } |
| 178 | if (eestate->intf->data_bits == 16) |
| 179 | memory_write_word(device->space[0], address * 2, 0x0000); |
| 215 | 180 | else |
| 216 | | eeprom_data[address] = 0xff; |
| 181 | memory_write_byte(device->space[0], address, 0x00); |
| 217 | 182 | } |
| 218 | 183 | else |
| 219 | 184 | logerror("Error: EEPROM is locked\n"); |
| 220 | | serial_count = 0; |
| 185 | eestate->serial_count = 0; |
| 221 | 186 | } |
| 222 | | else if ( (serial_count > (intf->address_bits + intf->data_bits)) && |
| 223 | | eeprom_command_match((char*)serial_buffer,intf->cmd_write,strlen((char*)serial_buffer)-(intf->address_bits + intf->data_bits)) ) |
| 187 | else if ( (eestate->serial_count > (eestate->intf->address_bits + eestate->intf->data_bits)) && |
| 188 | eeprom_command_match((char*)(eestate->serial_buffer),eestate->intf->cmd_write,strlen((char*)(eestate->serial_buffer))-(eestate->intf->address_bits + eestate->intf->data_bits)) ) |
| 224 | 189 | { |
| 225 | 190 | int i,address,data; |
| 226 | 191 | |
| 227 | 192 | address = 0; |
| 228 | | for (i = serial_count-intf->data_bits-intf->address_bits;i < (serial_count-intf->data_bits);i++) |
| 193 | for (i = eestate->serial_count-eestate->intf->data_bits-eestate->intf->address_bits;i < (eestate->serial_count-eestate->intf->data_bits);i++) |
| 229 | 194 | { |
| 230 | 195 | address <<= 1; |
| 231 | | if (serial_buffer[i] == '1') address |= 1; |
| 196 | if (eestate->serial_buffer[i] == '1') address |= 1; |
| 232 | 197 | } |
| 233 | 198 | data = 0; |
| 234 | | for (i = serial_count-intf->data_bits;i < serial_count;i++) |
| 199 | for (i = eestate->serial_count-eestate->intf->data_bits;i < eestate->serial_count;i++) |
| 235 | 200 | { |
| 236 | 201 | data <<= 1; |
| 237 | | if (serial_buffer[i] == '1') data |= 1; |
| 202 | if (eestate->serial_buffer[i] == '1') data |= 1; |
| 238 | 203 | } |
| 239 | 204 | logerror("EEPROM write %04x to address %02x\n",data,address); |
| 240 | | if (locked == 0) |
| 205 | if (eestate->locked == 0) |
| 241 | 206 | { |
| 242 | | if (intf->data_bits == 16) |
| 243 | | { |
| 244 | | eeprom_data[2*address+0] = data >> 8; |
| 245 | | eeprom_data[2*address+1] = data & 0xff; |
| 246 | | } |
| 207 | if (eestate->intf->data_bits == 16) |
| 208 | memory_write_word(device->space[0], address * 2, data); |
| 247 | 209 | else |
| 248 | | eeprom_data[address] = data; |
| 210 | memory_write_byte(device->space[0], address, 0x00); |
| 249 | 211 | } |
| 250 | 212 | else |
| 251 | 213 | logerror("Error: EEPROM is locked\n"); |
| 252 | | serial_count = 0; |
| 214 | eestate->serial_count = 0; |
| 253 | 215 | } |
| 254 | | else if ( eeprom_command_match((char*)serial_buffer,intf->cmd_lock,strlen((char*)serial_buffer)) ) |
| 216 | else if ( eeprom_command_match((char*)(eestate->serial_buffer),eestate->intf->cmd_lock,strlen((char*)(eestate->serial_buffer))) ) |
| 255 | 217 | { |
| 256 | 218 | logerror("EEPROM lock\n"); |
| 257 | | locked = 1; |
| 258 | | serial_count = 0; |
| 219 | eestate->locked = 1; |
| 220 | eestate->serial_count = 0; |
| 259 | 221 | } |
| 260 | | else if ( eeprom_command_match((char*)serial_buffer,intf->cmd_unlock,strlen((char*)serial_buffer)) ) |
| 222 | else if ( eeprom_command_match((char*)(eestate->serial_buffer),eestate->intf->cmd_unlock,strlen((char*)(eestate->serial_buffer))) ) |
| 261 | 223 | { |
| 262 | 224 | logerror("EEPROM unlock\n"); |
| 263 | | locked = 0; |
| 264 | | serial_count = 0; |
| 225 | eestate->locked = 0; |
| 226 | eestate->serial_count = 0; |
| 265 | 227 | } |
| 266 | 228 | } |
| 267 | 229 | |
| 268 | | static void eeprom_reset(void) |
| 230 | static void eeprom_reset(eeprom_state *eestate) |
| 269 | 231 | { |
| 270 | | if (serial_count) |
| 271 | | logerror("EEPROM reset, buffer = %s\n",serial_buffer); |
| 232 | if (eestate->serial_count) |
| 233 | logerror("EEPROM reset, buffer = %s\n",eestate->serial_buffer); |
| 272 | 234 | |
| 273 | | serial_count = 0; |
| 274 | | sending = 0; |
| 275 | | reset_delay = intf->reset_delay; /* delay a little before returning setting data to 1 (needed by wbeachvl) */ |
| 235 | eestate->serial_count = 0; |
| 236 | eestate->sending = 0; |
| 237 | eestate->reset_delay = eestate->intf->reset_delay; /* delay a little before returning setting data to 1 (needed by wbeachvl) */ |
| 276 | 238 | } |
| 277 | 239 | |
| 278 | 240 | |
| 279 | | void eeprom_write_bit(int bit) |
| 241 | WRITE_LINE_DEVICE_HANDLER( eeprom_write_bit ) |
| 280 | 242 | { |
| 281 | | LOG(("write bit %d\n",bit)); |
| 282 | | latch = bit; |
| 243 | eeprom_state *eestate = get_safe_token(device); |
| 244 | |
| 245 | LOG(("write bit %d\n",state)); |
| 246 | eestate->latch = state; |
| 283 | 247 | } |
| 284 | 248 | |
| 285 | | int eeprom_read_bit(void) |
| 249 | READ_LINE_DEVICE_HANDLER( eeprom_read_bit ) |
| 286 | 250 | { |
| 251 | eeprom_state *eestate = get_safe_token(device); |
| 287 | 252 | int res; |
| 288 | 253 | |
| 289 | | if (sending) |
| 290 | | res = (eeprom_data_bits >> intf->data_bits) & 1; |
| 254 | if (eestate->sending) |
| 255 | res = (eestate->data_bits >> eestate->intf->data_bits) & 1; |
| 291 | 256 | else |
| 292 | 257 | { |
| 293 | | if (reset_delay > 0) |
| 258 | if (eestate->reset_delay > 0) |
| 294 | 259 | { |
| 295 | 260 | /* this is needed by wbeachvl */ |
| 296 | | reset_delay--; |
| 261 | eestate->reset_delay--; |
| 297 | 262 | res = 0; |
| 298 | 263 | } |
| 299 | 264 | else |
| r6826 | r6827 | |
| 305 | 270 | return res; |
| 306 | 271 | } |
| 307 | 272 | |
| 308 | | CUSTOM_INPUT( eeprom_bit_r ) |
| 273 | WRITE_LINE_DEVICE_HANDLER( eeprom_set_cs_line ) |
| 309 | 274 | { |
| 310 | | return eeprom_read_bit(); |
| 311 | | } |
| 275 | eeprom_state *eestate = get_safe_token(device); |
| 312 | 276 | |
| 313 | | void eeprom_set_cs_line(int state) |
| 314 | | { |
| 315 | 277 | LOG(("set reset line %d\n",state)); |
| 316 | | reset_line = state; |
| 278 | eestate->reset_line = state; |
| 317 | 279 | |
| 318 | | if (reset_line != CLEAR_LINE) |
| 319 | | eeprom_reset(); |
| 280 | if (eestate->reset_line != CLEAR_LINE) |
| 281 | eeprom_reset(eestate); |
| 320 | 282 | } |
| 321 | 283 | |
| 322 | | void eeprom_set_clock_line(int state) |
| 284 | WRITE_LINE_DEVICE_HANDLER( eeprom_set_clock_line ) |
| 323 | 285 | { |
| 286 | eeprom_state *eestate = get_safe_token(device); |
| 287 | |
| 324 | 288 | LOG(("set clock line %d\n",state)); |
| 325 | | if (state == PULSE_LINE || (clock_line == CLEAR_LINE && state != CLEAR_LINE)) |
| 289 | if (state == PULSE_LINE || (eestate->clock_line == CLEAR_LINE && state != CLEAR_LINE)) |
| 326 | 290 | { |
| 327 | | if (reset_line == CLEAR_LINE) |
| 291 | if (eestate->reset_line == CLEAR_LINE) |
| 328 | 292 | { |
| 329 | | if (sending) |
| 293 | if (eestate->sending) |
| 330 | 294 | { |
| 331 | | if (eeprom_clock_count == intf->data_bits && intf->enable_multi_read) |
| 295 | if (eestate->clock_count == eestate->intf->data_bits && eestate->intf->enable_multi_read) |
| 332 | 296 | { |
| 333 | | eeprom_read_address = (eeprom_read_address + 1) & ((1 << intf->address_bits) - 1); |
| 334 | | if (intf->data_bits == 16) |
| 335 | | eeprom_data_bits = (eeprom_data[2*eeprom_read_address+0] << 8) + eeprom_data[2*eeprom_read_address+1]; |
| 297 | eestate->read_address = (eestate->read_address + 1) & ((1 << eestate->intf->address_bits) - 1); |
| 298 | if (eestate->intf->data_bits == 16) |
| 299 | eestate->data_bits = memory_read_word(device->space[0], eestate->read_address * 2); |
| 336 | 300 | else |
| 337 | | eeprom_data_bits = eeprom_data[eeprom_read_address]; |
| 338 | | eeprom_clock_count = 0; |
| 339 | | logerror("EEPROM read %04x from address %02x\n",eeprom_data_bits,eeprom_read_address); |
| 301 | eestate->data_bits = memory_read_byte(device->space[0], eestate->read_address); |
| 302 | eestate->clock_count = 0; |
| 303 | logerror("EEPROM read %04x from address %02x\n",eestate->data_bits,eestate->read_address); |
| 340 | 304 | } |
| 341 | | eeprom_data_bits = (eeprom_data_bits << 1) | 1; |
| 342 | | eeprom_clock_count++; |
| 305 | eestate->data_bits = (eestate->data_bits << 1) | 1; |
| 306 | eestate->clock_count++; |
| 343 | 307 | } |
| 344 | 308 | else |
| 345 | | eeprom_write(latch); |
| 309 | eeprom_write(device,eestate->latch); |
| 346 | 310 | } |
| 347 | 311 | } |
| 348 | 312 | |
| 349 | | clock_line = state; |
| 313 | eestate->clock_line = state; |
| 350 | 314 | } |
| 351 | 315 | |
| 352 | 316 | |
| 353 | | void eeprom_load(mame_file *f) |
| 317 | static DEVICE_NVRAM( eeprom ) |
| 354 | 318 | { |
| 355 | | mame_fread(f,eeprom_data,(1 << intf->address_bits) * intf->data_bits / 8); |
| 319 | eeprom_state *eestate = get_safe_token(device); |
| 320 | UINT32 eeprom_length = 1 << eestate->intf->address_bits; |
| 321 | UINT32 eeprom_bytes = eeprom_length * eestate->intf->data_bits / 8; |
| 322 | UINT32 offs; |
| 323 | |
| 324 | if (read_or_write) |
| 325 | { |
| 326 | UINT8 *buffer = alloc_array_or_die(UINT8, eeprom_bytes); |
| 327 | for (offs = 0; offs < eeprom_bytes; offs++) |
| 328 | buffer[offs] = memory_read_byte(device->space[0], offs); |
| 329 | mame_fwrite(file, buffer, eeprom_bytes); |
| 330 | free(buffer); |
| 331 | } |
| 332 | else if (file != NULL) |
| 333 | { |
| 334 | UINT8 *buffer = alloc_array_or_die(UINT8, eeprom_bytes); |
| 335 | mame_fread(file, buffer, eeprom_bytes); |
| 336 | for (offs = 0; offs < eeprom_bytes; offs++) |
| 337 | memory_write_byte(device->space[0], offs, buffer[offs]); |
| 338 | free(buffer); |
| 339 | } |
| 340 | else |
| 341 | { |
| 342 | const eeprom_config *config = (const eeprom_config *)device->inline_config; |
| 343 | UINT16 default_value = 0xffff; |
| 344 | int offs; |
| 345 | |
| 346 | /* initialize to the default value */ |
| 347 | if (config->default_value != 0) |
| 348 | default_value = config->default_value; |
| 349 | for (offs = 0; offs < eeprom_length; offs++) |
| 350 | if (eestate->intf->data_bits == 8) |
| 351 | memory_write_byte(device->space[0], offs, default_value); |
| 352 | else |
| 353 | memory_write_word(device->space[0], offs * 2, default_value); |
| 354 | |
| 355 | /* handle hard-coded data from the driver */ |
| 356 | if (config->default_data != NULL) |
| 357 | for (offs = 0; offs < config->default_data_size; offs++) |
| 358 | memory_write_byte(device->space[0], offs, config->default_data[offs]); |
| 359 | |
| 360 | /* populate from a memory region if present */ |
| 361 | if (device->region != NULL) |
| 362 | { |
| 363 | UINT32 region_flags = memory_region_flags(device->machine, device->tag); |
| 364 | |
| 365 | if (device->regionbytes != eeprom_bytes) |
| 366 | fatalerror("eeprom region '%s' wrong size (expected size = 0x%X)", device->tag, eeprom_bytes); |
| 367 | if (eestate->intf->data_bits == 8 && (region_flags & ROMREGION_WIDTHMASK) != ROMREGION_8BIT) |
| 368 | fatalerror("eeprom region '%s' needs to be an 8-bit region", device->tag); |
| 369 | if (eestate->intf->data_bits == 16 && ((region_flags & ROMREGION_WIDTHMASK) != ROMREGION_16BIT || (region_flags & ROMREGION_ENDIANMASK) != ROMREGION_BE)) |
| 370 | fatalerror("eeprom region '%s' needs to be a 16-bit big-endian region (flags=%08x)", device->tag, region_flags); |
| 371 | |
| 372 | for (offs = 0; offs < eeprom_length; offs++) |
| 373 | if (eestate->intf->data_bits == 8) |
| 374 | memory_write_byte(device->space[0], offs, device->region[offs]); |
| 375 | else |
| 376 | memory_write_word(device->space[0], offs * 2, ((UINT16 *)device->region)[offs]); |
| 377 | } |
| 378 | } |
| 356 | 379 | } |
| 357 | 380 | |
| 358 | | void eeprom_save(mame_file *f) |
| 381 | static DEVICE_START( eeprom ) |
| 359 | 382 | { |
| 360 | | mame_fwrite(f,eeprom_data,(1 << intf->address_bits) * intf->data_bits / 8); |
| 361 | | } |
| 383 | eeprom_state *eestate = get_safe_token(device); |
| 384 | const eeprom_config *config; |
| 362 | 385 | |
| 363 | | void eeprom_set_data(const UINT8 *data, int length) |
| 364 | | { |
| 365 | | memcpy(eeprom_data, data, length); |
| 386 | /* validate some basic stuff */ |
| 387 | assert(device != NULL); |
| 388 | assert(device->inline_config != NULL); |
| 389 | assert(device->machine != NULL); |
| 390 | assert(device->machine->config != NULL); |
| 391 | |
| 392 | config = (const eeprom_config *)device->inline_config; |
| 393 | |
| 394 | eestate->intf = config->pinterface; |
| 395 | |
| 396 | eestate->serial_count = 0; |
| 397 | eestate->latch = 0; |
| 398 | eestate->reset_line = ASSERT_LINE; |
| 399 | eestate->clock_line = ASSERT_LINE; |
| 400 | eestate->read_address = 0; |
| 401 | eestate->sending = 0; |
| 402 | if (eestate->intf->cmd_unlock) eestate->locked = 1; |
| 403 | else eestate->locked = 0; |
| 404 | |
| 405 | state_save_register_device_item_pointer( device, 0, eestate->serial_buffer, SERIAL_BUFFER_LENGTH); |
| 406 | state_save_register_device_item( device, 0, eestate->clock_line); |
| 407 | state_save_register_device_item( device, 0, eestate->reset_line); |
| 408 | state_save_register_device_item( device, 0, eestate->locked); |
| 409 | state_save_register_device_item( device, 0, eestate->serial_count); |
| 410 | state_save_register_device_item( device, 0, eestate->latch); |
| 411 | state_save_register_device_item( device, 0, eestate->reset_delay); |
| 412 | state_save_register_device_item( device, 0, eestate->clock_count); |
| 413 | state_save_register_device_item( device, 0, eestate->data_bits); |
| 414 | state_save_register_device_item( device, 0, eestate->read_address); |
| 366 | 415 | } |
| 367 | 416 | |
| 368 | | void *eeprom_get_data_pointer(UINT32 *length, UINT32 *size) |
| 369 | | { |
| 370 | | if (length != NULL && intf != NULL) |
| 371 | | *length = 1 << intf->address_bits; |
| 372 | | if (size != NULL && intf != NULL) |
| 373 | | *size = intf->data_bits / 8; |
| 417 | static ADDRESS_MAP_START( eeprom_map8, ADDRESS_SPACE_PROGRAM, 8 ) |
| 418 | AM_RANGE(0x0000, 0x0fff) AM_RAM |
| 419 | ADDRESS_MAP_END |
| 374 | 420 | |
| 375 | | return eeprom_data; |
| 376 | | } |
| 421 | static ADDRESS_MAP_START( eeprom_map16, ADDRESS_SPACE_PROGRAM, 16 ) |
| 422 | AM_RANGE(0x0000, 0x07ff) AM_RAM |
| 423 | ADDRESS_MAP_END |
| 424 | |
| 425 | static const char DEVTEMPLATE_SOURCE[] = __FILE__; |
| 426 | |
| 427 | #define DEVTEMPLATE_ID(p,s) p##eeprom##s |
| 428 | #define DEVTEMPLATE_FEATURES DT_HAS_START | DT_HAS_NVRAM | DT_HAS_INLINE_CONFIG | DT_HAS_PROGRAM_SPACE |
| 429 | #define DEVTEMPLATE_NAME "EEPROM" |
| 430 | #define DEVTEMPLATE_FAMILY "EEPROM" |
| 431 | #define DEVTEMPLATE_ENDIANNESS ENDIANNESS_BIG |
| 432 | #define DEVTEMPLATE_PGM_DATAWIDTH (((const eeprom_config *)device->inline_config)->pinterface->data_bits) |
| 433 | #define DEVTEMPLATE_PGM_ADDRWIDTH (((const eeprom_config *)device->inline_config)->pinterface->address_bits) |
| 434 | #define DEVTEMPLATE_PGM_ADDRSHIFT (((const eeprom_config *)device->inline_config)->pinterface->data_bits == 8 ? 0 : -1) |
| 435 | #define DEVTEMPLATE_PGM_DEFMAP (((const eeprom_config *)device->inline_config)->pinterface->data_bits == 8 ? (const void *)ADDRESS_MAP_NAME(eeprom_map8) : (const void *)ADDRESS_MAP_NAME(eeprom_map16)) |
| 436 | #include "devtempl.h" |
src/mess/drivers/jaguar.c
| r6826 | r6827 | |
| 175 | 175 | * 0xF14000 (read data), F14800 (increment clock, write data), F15000 (reset for next word) |
| 176 | 176 | * |
| 177 | 177 | ********************************************************************/ |
| 178 | | |
| 179 | | |
| 180 | 178 | static mame_file *jaguar_nvram_fopen( running_machine *machine, UINT32 openflags) |
| 181 | 179 | { |
| 182 | 180 | const device_config *image = devtag_get_device(machine, "cart"); |
| r6826 | r6827 | |
| 199 | 197 | mame_file *nvram_file = NULL; |
| 200 | 198 | const device_config *device; |
| 201 | 199 | |
| 202 | | if (machine->config->nvram_handler != NULL) |
| 203 | | { |
| 204 | | nvram_file = jaguar_nvram_fopen(machine, OPEN_FLAG_READ); |
| 205 | | if (nvram_file) eeprom_load(nvram_file); |
| 206 | | } |
| 207 | | |
| 208 | 200 | for (device = (device_config *)machine->config->devicelist.head; device != NULL; device = device->next) |
| 209 | 201 | { |
| 210 | 202 | device_nvram_func nvram = (device_nvram_func)device_get_info_fct(device, DEVINFO_FCT_NVRAM); |
| 211 | 203 | if (nvram != NULL) |
| 212 | 204 | { |
| 213 | 205 | if (nvram_file == NULL) |
| 214 | | nvram_file = nvram_fopen(machine, OPEN_FLAG_READ); |
| 215 | | (*nvram)(device, nvram_file, 0); |
| 206 | nvram_file = jaguar_nvram_fopen(machine, OPEN_FLAG_READ); |
| 207 | if (nvram_file != NULL) |
| 208 | (*nvram)(device, nvram_file, 0); |
| 216 | 209 | } |
| 217 | 210 | } |
| 218 | 211 | |
| r6826 | r6827 | |
| 225 | 218 | { |
| 226 | 219 | mame_file *nvram_file = NULL; |
| 227 | 220 | const device_config *device; |
| 228 | | |
| 229 | | if (machine->config->nvram_handler != NULL) |
| 230 | | { |
| 231 | | nvram_file = jaguar_nvram_fopen(machine, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); |
| 232 | | if (nvram_file) eeprom_save(nvram_file); |
| 233 | | } |
| 234 | | |
| 235 | 221 | for (device = (device_config *)machine->config->devicelist.head; device != NULL; device = device->next) |
| 236 | 222 | { |
| 237 | 223 | device_nvram_func nvram = (device_nvram_func)device_get_info_fct(device, DEVINFO_FCT_NVRAM); |
| 238 | 224 | if (nvram != NULL) |
| 239 | 225 | { |
| 240 | 226 | if (nvram_file == NULL) |
| 241 | | nvram_file = nvram_fopen(machine, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); |
| 242 | | (*nvram)(device, nvram_file, 1); |
| 227 | nvram_file = jaguar_nvram_fopen(machine, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); |
| 228 | if (nvram_file != NULL) |
| 229 | (*nvram)(device, nvram_file, 1); |
| 243 | 230 | } |
| 244 | 231 | } |
| 245 | 232 | |
| r6826 | r6827 | |
| 248 | 235 | } |
| 249 | 236 | |
| 250 | 237 | static NVRAM_HANDLER( jaguar ) |
| 251 | | { |
| 252 | | if (read_or_write) |
| 238 | { |
| 239 | if (read_or_write) { |
| 253 | 240 | jaguar_nvram_save(machine); |
| 241 | } |
| 254 | 242 | else |
| 255 | 243 | { |
| 256 | | eeprom_init(machine, &eeprom_interface_93C46); |
| 257 | | |
| 258 | 244 | if (file) |
| 259 | 245 | jaguar_nvram_load(machine); |
| 260 | 246 | } |
| r6826 | r6827 | |
| 262 | 248 | |
| 263 | 249 | static WRITE32_HANDLER( jaguar_eeprom_w ) |
| 264 | 250 | { |
| 251 | const device_config *eeprom = devtag_get_device(space->machine, "eeprom"); |
| 265 | 252 | eeprom_bit_count++; |
| 266 | 253 | if (eeprom_bit_count != 9) /* kill extra bit at end of address */ |
| 267 | 254 | { |
| 268 | | eeprom_write_bit(data >> 31); |
| 269 | | eeprom_set_clock_line(PULSE_LINE); |
| 255 | eeprom_write_bit(eeprom,data >> 31); |
| 256 | eeprom_set_clock_line(eeprom,PULSE_LINE); |
| 270 | 257 | } |
| 271 | 258 | } |
| 272 | 259 | |
| 273 | 260 | static READ32_HANDLER( jaguar_eeprom_clk ) |
| 274 | 261 | { |
| 275 | | eeprom_set_clock_line(PULSE_LINE); /* get next bit when reading */ |
| 262 | const device_config *eeprom = devtag_get_device(space->machine, "eeprom"); |
| 263 | eeprom_set_clock_line(eeprom,PULSE_LINE); /* get next bit when reading */ |
| 276 | 264 | return 0; |
| 277 | 265 | } |
| 278 | 266 | |
| 279 | 267 | static READ32_HANDLER( jaguar_eeprom_cs ) |
| 280 | 268 | { |
| 281 | | eeprom_set_cs_line(ASSERT_LINE); /* must do at end of an operation */ |
| 282 | | eeprom_set_cs_line(CLEAR_LINE); /* enable chip for next operation */ |
| 283 | | eeprom_write_bit(1); /* write a start bit */ |
| 284 | | eeprom_set_clock_line(PULSE_LINE); |
| 269 | const device_config *eeprom = devtag_get_device(space->machine, "eeprom"); |
| 270 | eeprom_set_cs_line(eeprom,ASSERT_LINE); /* must do at end of an operation */ |
| 271 | eeprom_set_cs_line(eeprom,CLEAR_LINE); /* enable chip for next operation */ |
| 272 | eeprom_write_bit(eeprom,1); /* write a start bit */ |
| 273 | eeprom_set_clock_line(eeprom,PULSE_LINE); |
| 285 | 274 | eeprom_bit_count = 0; |
| 286 | 275 | return 0; |
| 287 | 276 | } |
| r6826 | r6827 | |
| 375 | 364 | } |
| 376 | 365 | } |
| 377 | 366 | |
| 378 | | joystick_result |= eeprom_read_bit(); |
| 367 | joystick_result |= eeprom_read_bit(devtag_get_device(space->machine, "eeprom")); |
| 379 | 368 | joybuts_result |= (input_port_read(space->machine, "CONFIG") & 0x10); |
| 380 | 369 | |
| 381 | 370 | return (joystick_result << 16) | joybuts_result; |
| r6826 | r6827 | |
| 657 | 646 | MDRV_CARTSLOT_ADD("cart") |
| 658 | 647 | MDRV_CARTSLOT_EXTENSION_LIST("jag,abs,rom,j64,j01") |
| 659 | 648 | MDRV_CARTSLOT_LOAD(jaguar) |
| 649 | |
| 650 | MDRV_EEPROM_93C46_ADD("eeprom") |
| 660 | 651 | MACHINE_DRIVER_END |
| 661 | 652 | |
| 662 | 653 | |