src/emu/cpu/mips/mips3drc.c
| r2762 | r2763 | |
| 97 | 97 | #define LOPTR(x) ((UINT32 *)(x) + 1) |
| 98 | 98 | #endif |
| 99 | 99 | |
| 100 | | #define R32(reg) mips3.regmaplo[reg].type, mips3.regmaplo[reg].value |
| 100 | #define R32(reg) mips3->impstate->regmaplo[reg].type, mips3->impstate->regmaplo[reg].value |
| 101 | 101 | #define LO32 R32(REG_LO) |
| 102 | 102 | #define HI32 R32(REG_HI) |
| 103 | | #define CPR032(reg) MEM(LOPTR(&mips3.core->cpr[0][reg])) |
| 104 | | #define CCR032(reg) MEM(LOPTR(&mips3.core->ccr[0][reg])) |
| 105 | | #define FPR32(reg) MEM(((mips3.cstate->mode & 1) == 0) ? &((float *)&mips3.core->cpr[1][0])[reg] : (float *)&mips3.core->cpr[1][reg]) |
| 106 | | #define CCR132(reg) MEM(LOPTR(&mips3.core->ccr[1][reg])) |
| 107 | | #define CPR232(reg) MEM(LOPTR(&mips3.core->cpr[2][reg])) |
| 108 | | #define CCR232(reg) MEM(LOPTR(&mips3.core->ccr[2][reg])) |
| 103 | #define CPR032(reg) MEM(LOPTR(&mips3->cpr[0][reg])) |
| 104 | #define CCR032(reg) MEM(LOPTR(&mips3->ccr[0][reg])) |
| 105 | #define FPR32(reg) MEM(((mips3->impstate->mode & 1) == 0) ? &((float *)&mips3->cpr[1][0])[reg] : (float *)&mips3->cpr[1][reg]) |
| 106 | #define CCR132(reg) MEM(LOPTR(&mips3->ccr[1][reg])) |
| 107 | #define CPR232(reg) MEM(LOPTR(&mips3->cpr[2][reg])) |
| 108 | #define CCR232(reg) MEM(LOPTR(&mips3->ccr[2][reg])) |
| 109 | 109 | |
| 110 | | #define R64(reg) mips3.regmap[reg].type, mips3.regmap[reg].value |
| 110 | #define R64(reg) mips3->impstate->regmap[reg].type, mips3->impstate->regmap[reg].value |
| 111 | 111 | #define LO64 R64(REG_LO) |
| 112 | 112 | #define HI64 R64(REG_HI) |
| 113 | | #define CPR064(reg) MEM(&mips3.core->cpr[0][reg]) |
| 114 | | #define CCR064(reg) MEM(&mips3.core->ccr[0][reg]) |
| 115 | | #define FPR64(reg) MEM(((mips3.cstate->mode & 1) == 0) ? (double *)&mips3.core->cpr[1][(reg)/2] : (double *)&mips3.core->cpr[1][reg]) |
| 116 | | #define CCR164(reg) MEM(&mips3.core->ccr[1][reg]) |
| 117 | | #define CPR264(reg) MEM(&mips3.core->cpr[2][reg]) |
| 118 | | #define CCR264(reg) MEM(&mips3.core->ccr[2][reg]) |
| 113 | #define CPR064(reg) MEM(&mips3->cpr[0][reg]) |
| 114 | #define CCR064(reg) MEM(&mips3->ccr[0][reg]) |
| 115 | #define FPR64(reg) MEM(((mips3->impstate->mode & 1) == 0) ? (double *)&mips3->cpr[1][(reg)/2] : (double *)&mips3->cpr[1][reg]) |
| 116 | #define CCR164(reg) MEM(&mips3->ccr[1][reg]) |
| 117 | #define CPR264(reg) MEM(&mips3->cpr[2][reg]) |
| 118 | #define CCR264(reg) MEM(&mips3->ccr[2][reg]) |
| 119 | 119 | |
| 120 | | #define FCCMASK(which) fcc_mask[(mips3.core->flavor < MIPS3_TYPE_MIPS_IV) ? 0 : ((which) & 7)] |
| 120 | #define FCCMASK(which) fcc_mask[(mips3->flavor < MIPS3_TYPE_MIPS_IV) ? 0 : ((which) & 7)] |
| 121 | 121 | |
| 122 | 122 | |
| 123 | 123 | |
| r2762 | r2763 | |
| 157 | 157 | }; |
| 158 | 158 | |
| 159 | 159 | |
| 160 | | /* cache-based state */ |
| 161 | | typedef struct _mips3_cache_state mips3_cache_state; |
| 162 | | struct _mips3_cache_state |
| 160 | /* MIPS3 registers */ |
| 161 | struct _mips3imp_state |
| 163 | 162 | { |
| 163 | /* core state */ |
| 164 | drccache * cache; /* pointer to the DRC code cache */ |
| 165 | drcuml_state * drcuml; /* DRC UML generator state */ |
| 166 | drcfe_state * drcfe; /* pointer to the DRC front-end state */ |
| 167 | UINT32 drcoptions; /* configurable DRC options */ |
| 168 | |
| 169 | /* internal stuff */ |
| 170 | UINT8 cache_dirty; /* true if we need to flush the cache */ |
| 171 | |
| 164 | 172 | /* parameters for subroutines */ |
| 165 | 173 | UINT64 numcycles; /* return value from gettotalcycles */ |
| 166 | 174 | UINT32 mode; /* current global mode */ |
| r2762 | r2763 | |
| 178 | 186 | UINT32 c_ult_table[32]; /* FLAGS table for c_ult */ |
| 179 | 187 | UINT32 c_ole_table[32]; /* FLAGS table for c_ole */ |
| 180 | 188 | UINT32 c_ule_table[32]; /* FLAGS table for c_ule */ |
| 181 | | }; |
| 182 | 189 | |
| 183 | | |
| 184 | | /* MIPS3 registers */ |
| 185 | | typedef struct _mips3_regs mips3_regs; |
| 186 | | struct _mips3_regs |
| 187 | | { |
| 188 | | /* core state */ |
| 189 | | drccache * cache; /* pointer to the DRC code cache */ |
| 190 | | drcuml_state * drcuml; /* DRC UML generator state */ |
| 191 | | drcfe_state * drcfe; /* pointer to the DRC front-end state */ |
| 192 | | UINT32 drcoptions; /* configurable DRC options */ |
| 193 | | mips3_state * core; /* pointer to the core MIPS3 state */ |
| 194 | | mips3_cache_state * cstate; /* state that needs to live in the cache */ |
| 195 | | |
| 196 | | /* internal stuff */ |
| 197 | | UINT8 cache_dirty; /* true if we need to flush the cache */ |
| 198 | | |
| 199 | 190 | /* register mappings */ |
| 200 | 191 | drcuml_parameter regmap[34]; /* parameter to register mappings for all 32 integer registers */ |
| 201 | 192 | drcuml_parameter regmaplo[34]; /* parameter to register mappings for all 32 integer registers */ |
| r2762 | r2763 | |
| 275 | 266 | PRIVATE GLOBAL VARIABLES |
| 276 | 267 | ***************************************************************************/ |
| 277 | 268 | |
| 278 | | static mips3_regs mips3; |
| 269 | static mips3_state *mips3; |
| 279 | 270 | |
| 280 | 271 | |
| 281 | 272 | /* bit indexes for various FCCs */ |
| r2762 | r2763 | |
| 661 | 652 | { |
| 662 | 653 | int regnum; |
| 663 | 654 | |
| 664 | | for (regnum = 0; regnum < ARRAY_LENGTH(mips3.regmap); regnum++) |
| 665 | | if (mips3.regmap[regnum].type == DRCUML_PTYPE_INT_REGISTER) |
| 666 | | UML_DMOV(block, IREG(mips3.regmap[regnum].value - DRCUML_REG_I0), MEM(&mips3.core->r[regnum])); |
| 655 | for (regnum = 0; regnum < ARRAY_LENGTH(mips3->impstate->regmap); regnum++) |
| 656 | if (mips3->impstate->regmap[regnum].type == DRCUML_PTYPE_INT_REGISTER) |
| 657 | UML_DMOV(block, IREG(mips3->impstate->regmap[regnum].value - DRCUML_REG_I0), MEM(&mips3->r[regnum])); |
| 667 | 658 | } |
| 668 | 659 | |
| 669 | 660 | |
| r2762 | r2763 | |
| 676 | 667 | { |
| 677 | 668 | int regnum; |
| 678 | 669 | |
| 679 | | for (regnum = 0; regnum < ARRAY_LENGTH(mips3.regmap); regnum++) |
| 680 | | if (mips3.regmap[regnum].type == DRCUML_PTYPE_INT_REGISTER) |
| 681 | | UML_DMOV(block, MEM(&mips3.core->r[regnum]), IREG(mips3.regmap[regnum].value - DRCUML_REG_I0)); |
| 670 | for (regnum = 0; regnum < ARRAY_LENGTH(mips3->impstate->regmap); regnum++) |
| 671 | if (mips3->impstate->regmap[regnum].type == DRCUML_PTYPE_INT_REGISTER) |
| 672 | UML_DMOV(block, MEM(&mips3->r[regnum]), IREG(mips3->impstate->regmap[regnum].value - DRCUML_REG_I0)); |
| 682 | 673 | } |
| 683 | 674 | |
| 684 | 675 | |
| r2762 | r2763 | |
| 691 | 682 | mips3_init - initialize the processor |
| 692 | 683 | -------------------------------------------------*/ |
| 693 | 684 | |
| 694 | | static void mips3_init(mips3_flavor flavor, int bigendian, int index, int clock, const struct mips3_config *config, int (*irqcallback)(int)) |
| 685 | static void mips3_init(mips3_flavor flavor, int bigendian, int index, int clock, const mips3_config *config, int (*irqcallback)(int)) |
| 695 | 686 | { |
| 696 | 687 | drcfe_config feconfig = |
| 697 | 688 | { |
| r2762 | r2763 | |
| 700 | 691 | COMPILE_MAX_SEQUENCE, /* maximum instructions to include in a sequence */ |
| 701 | 692 | mips3fe_describe /* callback to describe a single instruction */ |
| 702 | 693 | }; |
| 694 | drccache *cache; |
| 703 | 695 | drcbe_info beinfo; |
| 704 | 696 | UINT32 flags = 0; |
| 705 | 697 | size_t extrasize; |
| r2762 | r2763 | |
| 710 | 702 | extrasize = mips3com_init(NULL, flavor, bigendian, index, clock, config, irqcallback, NULL); |
| 711 | 703 | |
| 712 | 704 | /* allocate enough space for the cache and the core */ |
| 713 | | mips3.cache = drccache_alloc(CACHE_SIZE + sizeof(*mips3.core) + extrasize); |
| 714 | | if (mips3.cache == NULL) |
| 715 | | fatalerror("Unable to allocate cache of size %d", (UINT32)(CACHE_SIZE + sizeof(*mips3.core) + extrasize)); |
| 705 | cache = drccache_alloc(CACHE_SIZE + sizeof(*mips3) + extrasize); |
| 706 | if (cache == NULL) |
| 707 | fatalerror("Unable to allocate cache of size %d", (UINT32)(CACHE_SIZE + sizeof(*mips3) + extrasize)); |
| 716 | 708 | |
| 717 | 709 | /* allocate the core and the extra memory */ |
| 718 | | mips3.core = drccache_memory_alloc_near(mips3.cache, sizeof(*mips3.core)); |
| 719 | | extramem = drccache_memory_alloc(mips3.cache, extrasize); |
| 710 | mips3 = drccache_memory_alloc_near(cache, sizeof(*mips3)); |
| 711 | memset(mips3, 0, sizeof(*mips3)); |
| 712 | extramem = drccache_memory_alloc(cache, extrasize); |
| 713 | memset(extramem, 0, extrasize); |
| 720 | 714 | |
| 721 | 715 | /* initialize the core */ |
| 722 | | mips3com_init(mips3.core, flavor, bigendian, index, clock, config, irqcallback, extramem); |
| 716 | mips3com_init(mips3, flavor, bigendian, index, clock, config, irqcallback, extramem); |
| 723 | 717 | |
| 724 | | /* allocate memory for cache-local state and initialize it */ |
| 725 | | mips3.cstate = drccache_memory_alloc_near(mips3.cache, sizeof(*mips3.cstate)); |
| 726 | | memset(mips3.cstate, 0, sizeof(*mips3.cstate)); |
| 727 | | memcpy(mips3.cstate->fpmode, fpmode_source, sizeof(fpmode_source)); |
| 728 | | memcpy(mips3.cstate->slt_table, slt_table_source, sizeof(slt_table_source)); |
| 729 | | memcpy(mips3.cstate->sltu_table, sltu_table_source, sizeof(sltu_table_source)); |
| 730 | | memcpy(mips3.cstate->c_un_table, c_un_table_source, sizeof(c_un_table_source)); |
| 731 | | memcpy(mips3.cstate->c_eq_table, c_eq_table_source, sizeof(c_eq_table_source)); |
| 732 | | memcpy(mips3.cstate->c_ueq_table, c_ueq_table_source, sizeof(c_ueq_table_source)); |
| 733 | | memcpy(mips3.cstate->c_olt_table, c_olt_table_source, sizeof(c_olt_table_source)); |
| 734 | | memcpy(mips3.cstate->c_ult_table, c_ult_table_source, sizeof(c_ult_table_source)); |
| 735 | | memcpy(mips3.cstate->c_ole_table, c_ole_table_source, sizeof(c_ole_table_source)); |
| 736 | | memcpy(mips3.cstate->c_ule_table, c_ule_table_source, sizeof(c_ule_table_source)); |
| 718 | /* allocate the implementation-specific state from the full cache */ |
| 719 | mips3->impstate = drccache_memory_alloc_near(cache, sizeof(*mips3->impstate)); |
| 720 | memset(mips3->impstate, 0, sizeof(*mips3->impstate)); |
| 721 | mips3->impstate->cache = cache; |
| 737 | 722 | |
| 738 | 723 | /* initialize the UML generator */ |
| 739 | 724 | if (FORCE_C_BACKEND) |
| r2762 | r2763 | |
| 742 | 727 | flags |= DRCUML_OPTION_LOG_UML; |
| 743 | 728 | if (LOG_NATIVE) |
| 744 | 729 | flags |= DRCUML_OPTION_LOG_NATIVE; |
| 745 | | mips3.drcuml = drcuml_alloc(mips3.cache, flags, 8, 32, 2); |
| 746 | | if (mips3.drcuml == NULL) |
| 730 | mips3->impstate->drcuml = drcuml_alloc(cache, flags, 8, 32, 2); |
| 731 | if (mips3->impstate->drcuml == NULL) |
| 747 | 732 | fatalerror("Error initializing the UML"); |
| 748 | 733 | |
| 749 | 734 | /* initialize the front-end helper */ |
| 750 | 735 | if (SINGLE_INSTRUCTION_MODE) |
| 751 | 736 | feconfig.max_sequence = 1; |
| 752 | | mips3.drcfe = drcfe_init(&feconfig, mips3.core); |
| 737 | mips3->impstate->drcfe = drcfe_init(&feconfig, mips3); |
| 753 | 738 | |
| 739 | /* allocate memory for cache-local state and initialize it */ |
| 740 | memcpy(mips3->impstate->fpmode, fpmode_source, sizeof(fpmode_source)); |
| 741 | memcpy(mips3->impstate->slt_table, slt_table_source, sizeof(slt_table_source)); |
| 742 | memcpy(mips3->impstate->sltu_table, sltu_table_source, sizeof(sltu_table_source)); |
| 743 | memcpy(mips3->impstate->c_un_table, c_un_table_source, sizeof(c_un_table_source)); |
| 744 | memcpy(mips3->impstate->c_eq_table, c_eq_table_source, sizeof(c_eq_table_source)); |
| 745 | memcpy(mips3->impstate->c_ueq_table, c_ueq_table_source, sizeof(c_ueq_table_source)); |
| 746 | memcpy(mips3->impstate->c_olt_table, c_olt_table_source, sizeof(c_olt_table_source)); |
| 747 | memcpy(mips3->impstate->c_ult_table, c_ult_table_source, sizeof(c_ult_table_source)); |
| 748 | memcpy(mips3->impstate->c_ole_table, c_ole_table_source, sizeof(c_ole_table_source)); |
| 749 | memcpy(mips3->impstate->c_ule_table, c_ule_table_source, sizeof(c_ule_table_source)); |
| 750 | |
| 754 | 751 | /* compute the register parameters */ |
| 755 | 752 | for (regnum = 0; regnum < 34; regnum++) |
| 756 | 753 | { |
| 757 | | mips3.regmap[regnum].type = (regnum == 0) ? DRCUML_PTYPE_IMMEDIATE : DRCUML_PTYPE_MEMORY; |
| 758 | | mips3.regmap[regnum].value = (regnum == 0) ? 0 : (FPTR)&mips3.core->r[regnum]; |
| 759 | | mips3.regmaplo[regnum].type = (regnum == 0) ? DRCUML_PTYPE_IMMEDIATE : DRCUML_PTYPE_MEMORY; |
| 760 | | mips3.regmaplo[regnum].value = (regnum == 0) ? 0 : (FPTR)LOPTR(&mips3.core->r[regnum]); |
| 754 | mips3->impstate->regmap[regnum].type = (regnum == 0) ? DRCUML_PTYPE_IMMEDIATE : DRCUML_PTYPE_MEMORY; |
| 755 | mips3->impstate->regmap[regnum].value = (regnum == 0) ? 0 : (FPTR)&mips3->r[regnum]; |
| 756 | mips3->impstate->regmaplo[regnum].type = (regnum == 0) ? DRCUML_PTYPE_IMMEDIATE : DRCUML_PTYPE_MEMORY; |
| 757 | mips3->impstate->regmaplo[regnum].value = (regnum == 0) ? 0 : (FPTR)LOPTR(&mips3->r[regnum]); |
| 761 | 758 | } |
| 762 | 759 | |
| 763 | 760 | /* if we have registers to spare, assign r2, r3, r4 to leftovers */ |
| 764 | 761 | if (!DISABLE_FAST_REGISTERS) |
| 765 | 762 | { |
| 766 | | drcuml_get_backend_info(mips3.drcuml, &beinfo); |
| 763 | drcuml_get_backend_info(mips3->impstate->drcuml, &beinfo); |
| 767 | 764 | if (beinfo.direct_iregs > 4) |
| 768 | 765 | { |
| 769 | | mips3.regmap[2].type = mips3.regmaplo[2].type = DRCUML_PTYPE_INT_REGISTER; |
| 770 | | mips3.regmap[2].value = mips3.regmaplo[2].value = DRCUML_REG_I4; |
| 766 | mips3->impstate->regmap[2].type = mips3->impstate->regmaplo[2].type = DRCUML_PTYPE_INT_REGISTER; |
| 767 | mips3->impstate->regmap[2].value = mips3->impstate->regmaplo[2].value = DRCUML_REG_I4; |
| 771 | 768 | } |
| 772 | 769 | if (beinfo.direct_iregs > 5) |
| 773 | 770 | { |
| 774 | | mips3.regmap[3].type = mips3.regmaplo[3].type = DRCUML_PTYPE_INT_REGISTER; |
| 775 | | mips3.regmap[3].value = mips3.regmaplo[3].value = DRCUML_REG_I5; |
| 771 | mips3->impstate->regmap[3].type = mips3->impstate->regmaplo[3].type = DRCUML_PTYPE_INT_REGISTER; |
| 772 | mips3->impstate->regmap[3].value = mips3->impstate->regmaplo[3].value = DRCUML_REG_I5; |
| 776 | 773 | } |
| 777 | 774 | if (beinfo.direct_iregs > 6) |
| 778 | 775 | { |
| 779 | | mips3.regmap[4].type = mips3.regmaplo[4].type = DRCUML_PTYPE_INT_REGISTER; |
| 780 | | mips3.regmap[4].value = mips3.regmaplo[4].value = DRCUML_REG_I6; |
| 776 | mips3->impstate->regmap[4].type = mips3->impstate->regmaplo[4].type = DRCUML_PTYPE_INT_REGISTER; |
| 777 | mips3->impstate->regmap[4].value = mips3->impstate->regmaplo[4].value = DRCUML_REG_I6; |
| 781 | 778 | } |
| 782 | 779 | } |
| 783 | 780 | |
| 784 | 781 | /* mark the cache dirty so it is updated on next execute */ |
| 785 | | mips3.cache_dirty = TRUE; |
| 782 | mips3->impstate->cache_dirty = TRUE; |
| 786 | 783 | } |
| 787 | 784 | |
| 788 | 785 | |
| r2762 | r2763 | |
| 793 | 790 | static void mips3_reset(void) |
| 794 | 791 | { |
| 795 | 792 | /* reset the common code and mark the cache dirty */ |
| 796 | | mips3com_reset(mips3.core); |
| 797 | | mips3.cstate->mode = (MODE_KERNEL << 1) | 0; |
| 798 | | mips3.cache_dirty = TRUE; |
| 793 | mips3com_reset(mips3); |
| 794 | mips3->impstate->mode = (MODE_KERNEL << 1) | 0; |
| 795 | mips3->impstate->cache_dirty = TRUE; |
| 799 | 796 | } |
| 800 | 797 | |
| 801 | 798 | |
| r2762 | r2763 | |
| 806 | 803 | |
| 807 | 804 | static int mips3_execute(int cycles) |
| 808 | 805 | { |
| 809 | | drcuml_state *drcuml = mips3.drcuml; |
| 806 | drcuml_state *drcuml = mips3->impstate->drcuml; |
| 810 | 807 | int execute_result; |
| 811 | 808 | |
| 812 | 809 | /* reset the cache if dirty */ |
| 813 | | if (mips3.cache_dirty) |
| 810 | if (mips3->impstate->cache_dirty) |
| 814 | 811 | code_flush_cache(drcuml); |
| 815 | | mips3.cache_dirty = FALSE; |
| 812 | mips3->impstate->cache_dirty = FALSE; |
| 816 | 813 | |
| 817 | 814 | /* execute */ |
| 818 | | mips3.core->icount = cycles; |
| 815 | mips3->icount = cycles; |
| 819 | 816 | do |
| 820 | 817 | { |
| 821 | 818 | /* run as much as we can */ |
| 822 | | execute_result = drcuml_execute(drcuml, mips3.entry); |
| 819 | execute_result = drcuml_execute(drcuml, mips3->impstate->entry); |
| 823 | 820 | |
| 824 | 821 | /* if we need to recompile, do it */ |
| 825 | 822 | if (execute_result == EXECUTE_MISSING_CODE) |
| 826 | | code_compile_block(drcuml, mips3.cstate->mode, mips3.core->pc); |
| 823 | code_compile_block(drcuml, mips3->impstate->mode, mips3->pc); |
| 827 | 824 | else if (execute_result == EXECUTE_UNMAPPED_CODE) |
| 828 | | fatalerror("Attempted to execute unmapped code at PC=%08X\n", mips3.core->pc); |
| 825 | fatalerror("Attempted to execute unmapped code at PC=%08X\n", mips3->pc); |
| 829 | 826 | else if (execute_result == EXECUTE_RESET_CACHE) |
| 830 | 827 | code_flush_cache(drcuml); |
| 831 | 828 | |
| 832 | 829 | } while (execute_result != EXECUTE_OUT_OF_CYCLES); |
| 833 | 830 | |
| 834 | 831 | /* return the number of cycles executed */ |
| 835 | | return cycles - mips3.core->icount; |
| 832 | return cycles - mips3->icount; |
| 836 | 833 | } |
| 837 | 834 | |
| 838 | 835 | |
| r2762 | r2763 | |
| 843 | 840 | static void mips3_exit(void) |
| 844 | 841 | { |
| 845 | 842 | /* clean up the DRC */ |
| 846 | | drcfe_exit(mips3.drcfe); |
| 847 | | drcuml_free(mips3.drcuml); |
| 848 | | drccache_free(mips3.cache); |
| 843 | drcfe_exit(mips3->impstate->drcfe); |
| 844 | drcuml_free(mips3->impstate->drcuml); |
| 845 | drccache_free(mips3->impstate->cache); |
| 849 | 846 | } |
| 850 | 847 | |
| 851 | 848 | |
| r2762 | r2763 | |
| 857 | 854 | static void mips3_get_context(void *dst) |
| 858 | 855 | { |
| 859 | 856 | if (dst != NULL) |
| 860 | | *(mips3_regs *)dst = mips3; |
| 857 | *(mips3_state **)dst = mips3; |
| 861 | 858 | } |
| 862 | 859 | |
| 863 | 860 | |
| r2762 | r2763 | |
| 869 | 866 | static void mips3_set_context(void *src) |
| 870 | 867 | { |
| 871 | 868 | if (src != NULL) |
| 872 | | mips3 = *(mips3_regs *)src; |
| 869 | mips3 = *(mips3_state **)src; |
| 873 | 870 | } |
| 874 | 871 | |
| 875 | 872 | |
| r2762 | r2763 | |
| 878 | 875 | address translation |
| 879 | 876 | -------------------------------------------------*/ |
| 880 | 877 | |
| 881 | | static int mips3_translate(int space, offs_t *address) |
| 878 | static int mips3_translate(int space, int intention, offs_t *address) |
| 882 | 879 | { |
| 883 | | return mips3com_translate_address(mips3.core, space, address); |
| 880 | return mips3com_translate_address(mips3, space, intention, address); |
| 884 | 881 | } |
| 885 | 882 | |
| 886 | 883 | |
| r2762 | r2763 | |
| 891 | 888 | #ifdef ENABLE_DEBUGGER |
| 892 | 889 | static offs_t mips3_dasm(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram) |
| 893 | 890 | { |
| 894 | | return mips3com_dasm(mips3.core, buffer, pc, oprom, opram); |
| 891 | return mips3com_dasm(mips3, buffer, pc, oprom, opram); |
| 895 | 892 | } |
| 896 | 893 | #endif /* ENABLE_DEBUGGER */ |
| 897 | 894 | |
| 898 | 895 | |
| 899 | 896 | |
| 897 | /*------------------------------------------------- |
| 898 | mips3_set_info - set information about a given |
| 899 | CPU instance |
| 900 | -------------------------------------------------*/ |
| 900 | 901 | |
| 902 | static void mips3_set_info(UINT32 state, cpuinfo *info) |
| 903 | { |
| 904 | switch (state) |
| 905 | { |
| 906 | /* --- the following bits of info are set as 64-bit signed integers --- */ |
| 907 | case CPUINFO_INT_MIPS3_DRC_OPTIONS: mips3->impstate->drcoptions = info->i; break; |
| 908 | |
| 909 | case CPUINFO_INT_MIPS3_FASTRAM_SELECT: if (info->i >= 0 && info->i < MIPS3_MAX_FASTRAM) mips3->impstate->fastram_select = info->i; mips3->impstate->cache_dirty = TRUE; break; |
| 910 | case CPUINFO_INT_MIPS3_FASTRAM_START: mips3->impstate->fastram[mips3->impstate->fastram_select].start = info->i; mips3->impstate->cache_dirty = TRUE; break; |
| 911 | case CPUINFO_INT_MIPS3_FASTRAM_END: mips3->impstate->fastram[mips3->impstate->fastram_select].end = info->i; mips3->impstate->cache_dirty = TRUE; break; |
| 912 | case CPUINFO_INT_MIPS3_FASTRAM_READONLY: mips3->impstate->fastram[mips3->impstate->fastram_select].readonly = info->i; mips3->impstate->cache_dirty = TRUE; break; |
| 913 | |
| 914 | case CPUINFO_INT_MIPS3_HOTSPOT_SELECT: if (info->i >= 0 && info->i < MIPS3_MAX_HOTSPOTS) mips3->impstate->hotspot_select = info->i; mips3->impstate->cache_dirty = TRUE; break; |
| 915 | case CPUINFO_INT_MIPS3_HOTSPOT_PC: mips3->impstate->hotspot[mips3->impstate->hotspot_select].pc = info->i; mips3->impstate->cache_dirty = TRUE; break; |
| 916 | case CPUINFO_INT_MIPS3_HOTSPOT_OPCODE: mips3->impstate->hotspot[mips3->impstate->hotspot_select].opcode = info->i; mips3->impstate->cache_dirty = TRUE; break; |
| 917 | case CPUINFO_INT_MIPS3_HOTSPOT_CYCLES: mips3->impstate->hotspot[mips3->impstate->hotspot_select].cycles = info->i; mips3->impstate->cache_dirty = TRUE; break; |
| 918 | |
| 919 | /* --- the following bits of info are set as pointers to data or functions --- */ |
| 920 | case CPUINFO_PTR_MIPS3_FASTRAM_BASE: mips3->impstate->fastram[mips3->impstate->fastram_select].base = info->p; break; |
| 921 | |
| 922 | /* --- everything else is handled generically --- */ |
| 923 | default: mips3com_set_info(mips3, state, info); break; |
| 924 | } |
| 925 | } |
| 926 | |
| 927 | |
| 928 | /*------------------------------------------------- |
| 929 | mips3_get_info - return information about a |
| 930 | given CPU instance |
| 931 | -------------------------------------------------*/ |
| 932 | |
| 933 | static void mips3_get_info(UINT32 state, cpuinfo *info) |
| 934 | { |
| 935 | switch (state) |
| 936 | { |
| 937 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 938 | case CPUINFO_INT_CONTEXT_SIZE: info->i = sizeof(mips3); break; |
| 939 | case CPUINFO_INT_PREVIOUSPC: /* not implemented */ break; |
| 940 | |
| 941 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 942 | case CPUINFO_PTR_SET_INFO: info->setinfo = mips3_set_info; break; |
| 943 | case CPUINFO_PTR_GET_CONTEXT: info->getcontext = mips3_get_context; break; |
| 944 | case CPUINFO_PTR_SET_CONTEXT: info->setcontext = mips3_set_context; break; |
| 945 | case CPUINFO_PTR_INIT: /* provided per-CPU */ break; |
| 946 | case CPUINFO_PTR_RESET: info->reset = mips3_reset; break; |
| 947 | case CPUINFO_PTR_EXIT: info->exit = mips3_exit; break; |
| 948 | case CPUINFO_PTR_EXECUTE: info->execute = mips3_execute; break; |
| 949 | #ifdef ENABLE_DEBUGGER |
| 950 | case CPUINFO_PTR_DISASSEMBLE: info->disassemble = mips3_dasm; break; |
| 951 | #endif /* ENABLE_DEBUGGER */ |
| 952 | case CPUINFO_PTR_TRANSLATE: info->translate = mips3_translate; break; |
| 953 | |
| 954 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 955 | case CPUINFO_STR_CORE_FILE: strcpy(info->s, __FILE__); break; |
| 956 | |
| 957 | /* --- everything else is handled generically --- */ |
| 958 | default: mips3com_get_info(mips3, state, info); break; |
| 959 | } |
| 960 | } |
| 961 | |
| 962 | |
| 963 | |
| 901 | 964 | /*************************************************************************** |
| 902 | 965 | CACHE MANAGEMENT |
| 903 | 966 | ***************************************************************************/ |
| r2762 | r2763 | |
| 940 | 1003 | /* add subroutines for memory accesses */ |
| 941 | 1004 | for (mode = 0; mode < 3; mode++) |
| 942 | 1005 | { |
| 943 | | static_generate_memory_accessor(drcuml, mode, 1, FALSE, FALSE, "read8", &mips3.read8[mode]); |
| 944 | | static_generate_memory_accessor(drcuml, mode, 1, TRUE, FALSE, "write8", &mips3.write8[mode]); |
| 945 | | static_generate_memory_accessor(drcuml, mode, 2, FALSE, FALSE, "read16", &mips3.read16[mode]); |
| 946 | | static_generate_memory_accessor(drcuml, mode, 2, TRUE, FALSE, "write16", &mips3.write16[mode]); |
| 947 | | static_generate_memory_accessor(drcuml, mode, 4, FALSE, FALSE, "read32", &mips3.read32[mode]); |
| 948 | | static_generate_memory_accessor(drcuml, mode, 4, FALSE, TRUE, "read32mask", &mips3.read32mask[mode]); |
| 949 | | static_generate_memory_accessor(drcuml, mode, 4, TRUE, FALSE, "write32", &mips3.write32[mode]); |
| 950 | | static_generate_memory_accessor(drcuml, mode, 4, TRUE, TRUE, "write32mask", &mips3.write32mask[mode]); |
| 951 | | static_generate_memory_accessor(drcuml, mode, 8, FALSE, FALSE, "read64", &mips3.read64[mode]); |
| 952 | | static_generate_memory_accessor(drcuml, mode, 8, FALSE, TRUE, "read64mask", &mips3.read64mask[mode]); |
| 953 | | static_generate_memory_accessor(drcuml, mode, 8, TRUE, FALSE, "write64", &mips3.write64[mode]); |
| 954 | | static_generate_memory_accessor(drcuml, mode, 8, TRUE, TRUE, "write64mask", &mips3.write64mask[mode]); |
| 1006 | static_generate_memory_accessor(drcuml, mode, 1, FALSE, FALSE, "read8", &mips3->impstate->read8[mode]); |
| 1007 | static_generate_memory_accessor(drcuml, mode, 1, TRUE, FALSE, "write8", &mips3->impstate->write8[mode]); |
| 1008 | static_generate_memory_accessor(drcuml, mode, 2, FALSE, FALSE, "read16", &mips3->impstate->read16[mode]); |
| 1009 | static_generate_memory_accessor(drcuml, mode, 2, TRUE, FALSE, "write16", &mips3->impstate->write16[mode]); |
| 1010 | static_generate_memory_accessor(drcuml, mode, 4, FALSE, FALSE, "read32", &mips3->impstate->read32[mode]); |
| 1011 | static_generate_memory_accessor(drcuml, mode, 4, FALSE, TRUE, "read32mask", &mips3->impstate->read32mask[mode]); |
| 1012 | static_generate_memory_accessor(drcuml, mode, 4, TRUE, FALSE, "write32", &mips3->impstate->write32[mode]); |
| 1013 | static_generate_memory_accessor(drcuml, mode, 4, TRUE, TRUE, "write32mask", &mips3->impstate->write32mask[mode]); |
| 1014 | static_generate_memory_accessor(drcuml, mode, 8, FALSE, FALSE, "read64", &mips3->impstate->read64[mode]); |
| 1015 | static_generate_memory_accessor(drcuml, mode, 8, FALSE, TRUE, "read64mask", &mips3->impstate->read64mask[mode]); |
| 1016 | static_generate_memory_accessor(drcuml, mode, 8, TRUE, FALSE, "write64", &mips3->impstate->write64[mode]); |
| 1017 | static_generate_memory_accessor(drcuml, mode, 8, TRUE, TRUE, "write64mask", &mips3->impstate->write64mask[mode]); |
| 955 | 1018 | } |
| 956 | 1019 | } |
| 957 | 1020 | |
| r2762 | r2763 | |
| 971 | 1034 | jmp_buf errorbuf; |
| 972 | 1035 | |
| 973 | 1036 | /* get a description of this sequence */ |
| 974 | | desclist = drcfe_describe_code(mips3.drcfe, pc); |
| 1037 | desclist = drcfe_describe_code(mips3->impstate->drcfe, pc); |
| 975 | 1038 | if (LOG_UML || LOG_NATIVE) |
| 976 | 1039 | log_opcode_desc(drcuml, desclist, 0); |
| 977 | 1040 | |
| r2762 | r2763 | |
| 1014 | 1077 | else |
| 1015 | 1078 | { |
| 1016 | 1079 | UML_LABEL(block, seqhead->pc | 0x80000000); // label seqhead->pc | 0x80000000 |
| 1017 | | UML_HASHJMP(block, IMM(mips3.cstate->mode), IMM(seqhead->pc), mips3.nocode); |
| 1080 | UML_HASHJMP(block, IMM(mips3->impstate->mode), IMM(seqhead->pc), mips3->impstate->nocode); |
| 1018 | 1081 | // hashjmp <mode>,seqhead->pc,nocode |
| 1019 | 1082 | continue; |
| 1020 | 1083 | } |
| r2762 | r2763 | |
| 1044 | 1107 | |
| 1045 | 1108 | /* if the last instruction can change modes, use a variable mode; otherwise, assume the same mode */ |
| 1046 | 1109 | if (seqlast->flags & OPFLAG_CAN_CHANGE_MODES) |
| 1047 | | UML_HASHJMP(block, MEM(&mips3.cstate->mode), IMM(nextpc), mips3.nocode);// hashjmp <mode>,nextpc,nocode |
| 1110 | UML_HASHJMP(block, MEM(&mips3->impstate->mode), IMM(nextpc), mips3->impstate->nocode); |
| 1111 | // hashjmp <mode>,nextpc,nocode |
| 1048 | 1112 | else if (seqlast->next == NULL || seqlast->next->pc != nextpc) |
| 1049 | | UML_HASHJMP(block, IMM(mips3.cstate->mode), IMM(nextpc), mips3.nocode); // hashjmp <mode>,nextpc,nocode |
| 1113 | UML_HASHJMP(block, IMM(mips3->impstate->mode), IMM(nextpc), mips3->impstate->nocode); |
| 1114 | // hashjmp <mode>,nextpc,nocode |
| 1050 | 1115 | } |
| 1051 | 1116 | |
| 1052 | 1117 | /* end the sequence */ |
| r2762 | r2763 | |
| 1078 | 1143 | |
| 1079 | 1144 | static void cfunc_printf_exception(void *param) |
| 1080 | 1145 | { |
| 1081 | | printf("Exception: EPC=%08X Cause=%08X BadVAddr=%08X Jmp=%08X\n", (UINT32)mips3.core->cpr[0][COP0_EPC], (UINT32)mips3.core->cpr[0][COP0_Cause], (UINT32)mips3.core->cpr[0][COP0_BadVAddr], mips3.core->pc); |
| 1082 | | cfunc_printf_probe((void *)(FPTR)mips3.core->cpr[0][COP0_EPC]); |
| 1146 | printf("Exception: EPC=%08X Cause=%08X BadVAddr=%08X Jmp=%08X\n", (UINT32)mips3->cpr[0][COP0_EPC], (UINT32)mips3->cpr[0][COP0_Cause], (UINT32)mips3->cpr[0][COP0_BadVAddr], mips3->pc); |
| 1147 | cfunc_printf_probe((void *)(FPTR)mips3->cpr[0][COP0_EPC]); |
| 1083 | 1148 | } |
| 1084 | 1149 | |
| 1085 | 1150 | |
| r2762 | r2763 | |
| 1091 | 1156 | static void cfunc_printf_debug(void *param) |
| 1092 | 1157 | { |
| 1093 | 1158 | const char *format = param; |
| 1094 | | printf(format, mips3.cstate->arg0, mips3.cstate->arg1); |
| 1159 | printf(format, mips3->impstate->arg0, mips3->impstate->arg1); |
| 1095 | 1160 | } |
| 1096 | 1161 | |
| 1097 | 1162 | |
| r2762 | r2763 | |
| 1106 | 1171 | |
| 1107 | 1172 | printf(" PC=%08X r1=%08X%08X r2=%08X%08X r3=%08X%08X\n", |
| 1108 | 1173 | pc, |
| 1109 | | (UINT32)(mips3.core->r[1] >> 32), (UINT32)mips3.core->r[1], |
| 1110 | | (UINT32)(mips3.core->r[2] >> 32), (UINT32)mips3.core->r[2], |
| 1111 | | (UINT32)(mips3.core->r[3] >> 32), (UINT32)mips3.core->r[3]); |
| 1174 | (UINT32)(mips3->r[1] >> 32), (UINT32)mips3->r[1], |
| 1175 | (UINT32)(mips3->r[2] >> 32), (UINT32)mips3->r[2], |
| 1176 | (UINT32)(mips3->r[3] >> 32), (UINT32)mips3->r[3]); |
| 1112 | 1177 | printf(" r4=%08X%08X r5=%08X%08X r6=%08X%08X r7=%08X%08X\n", |
| 1113 | | (UINT32)(mips3.core->r[4] >> 32), (UINT32)mips3.core->r[4], |
| 1114 | | (UINT32)(mips3.core->r[5] >> 32), (UINT32)mips3.core->r[5], |
| 1115 | | (UINT32)(mips3.core->r[6] >> 32), (UINT32)mips3.core->r[6], |
| 1116 | | (UINT32)(mips3.core->r[7] >> 32), (UINT32)mips3.core->r[7]); |
| 1178 | (UINT32)(mips3->r[4] >> 32), (UINT32)mips3->r[4], |
| 1179 | (UINT32)(mips3->r[5] >> 32), (UINT32)mips3->r[5], |
| 1180 | (UINT32)(mips3->r[6] >> 32), (UINT32)mips3->r[6], |
| 1181 | (UINT32)(mips3->r[7] >> 32), (UINT32)mips3->r[7]); |
| 1117 | 1182 | printf(" r8=%08X%08X r9=%08X%08X r10=%08X%08X r11=%08X%08X\n", |
| 1118 | | (UINT32)(mips3.core->r[8] >> 32), (UINT32)mips3.core->r[8], |
| 1119 | | (UINT32)(mips3.core->r[9] >> 32), (UINT32)mips3.core->r[9], |
| 1120 | | (UINT32)(mips3.core->r[10] >> 32), (UINT32)mips3.core->r[10], |
| 1121 | | (UINT32)(mips3.core->r[11] >> 32), (UINT32)mips3.core->r[11]); |
| 1183 | (UINT32)(mips3->r[8] >> 32), (UINT32)mips3->r[8], |
| 1184 | (UINT32)(mips3->r[9] >> 32), (UINT32)mips3->r[9], |
| 1185 | (UINT32)(mips3->r[10] >> 32), (UINT32)mips3->r[10], |
| 1186 | (UINT32)(mips3->r[11] >> 32), (UINT32)mips3->r[11]); |
| 1122 | 1187 | printf("r12=%08X%08X r13=%08X%08X r14=%08X%08X r15=%08X%08X\n", |
| 1123 | | (UINT32)(mips3.core->r[12] >> 32), (UINT32)mips3.core->r[12], |
| 1124 | | (UINT32)(mips3.core->r[13] >> 32), (UINT32)mips3.core->r[13], |
| 1125 | | (UINT32)(mips3.core->r[14] >> 32), (UINT32)mips3.core->r[14], |
| 1126 | | (UINT32)(mips3.core->r[15] >> 32), (UINT32)mips3.core->r[15]); |
| 1188 | (UINT32)(mips3->r[12] >> 32), (UINT32)mips3->r[12], |
| 1189 | (UINT32)(mips3->r[13] >> 32), (UINT32)mips3->r[13], |
| 1190 | (UINT32)(mips3->r[14] >> 32), (UINT32)mips3->r[14], |
| 1191 | (UINT32)(mips3->r[15] >> 32), (UINT32)mips3->r[15]); |
| 1127 | 1192 | printf("r16=%08X%08X r17=%08X%08X r18=%08X%08X r19=%08X%08X\n", |
| 1128 | | (UINT32)(mips3.core->r[16] >> 32), (UINT32)mips3.core->r[16], |
| 1129 | | (UINT32)(mips3.core->r[17] >> 32), (UINT32)mips3.core->r[17], |
| 1130 | | (UINT32)(mips3.core->r[18] >> 32), (UINT32)mips3.core->r[18], |
| 1131 | | (UINT32)(mips3.core->r[19] >> 32), (UINT32)mips3.core->r[19]); |
| 1193 | (UINT32)(mips3->r[16] >> 32), (UINT32)mips3->r[16], |
| 1194 | (UINT32)(mips3->r[17] >> 32), (UINT32)mips3->r[17], |
| 1195 | (UINT32)(mips3->r[18] >> 32), (UINT32)mips3->r[18], |
| 1196 | (UINT32)(mips3->r[19] >> 32), (UINT32)mips3->r[19]); |
| 1132 | 1197 | printf("r20=%08X%08X r21=%08X%08X r22=%08X%08X r23=%08X%08X\n", |
| 1133 | | (UINT32)(mips3.core->r[20] >> 32), (UINT32)mips3.core->r[20], |
| 1134 | | (UINT32)(mips3.core->r[21] >> 32), (UINT32)mips3.core->r[21], |
| 1135 | | (UINT32)(mips3.core->r[22] >> 32), (UINT32)mips3.core->r[22], |
| 1136 | | (UINT32)(mips3.core->r[23] >> 32), (UINT32)mips3.core->r[23]); |
| 1198 | (UINT32)(mips3->r[20] >> 32), (UINT32)mips3->r[20], |
| 1199 | (UINT32)(mips3->r[21] >> 32), (UINT32)mips3->r[21], |
| 1200 | (UINT32)(mips3->r[22] >> 32), (UINT32)mips3->r[22], |
| 1201 | (UINT32)(mips3->r[23] >> 32), (UINT32)mips3->r[23]); |
| 1137 | 1202 | printf("r24=%08X%08X r25=%08X%08X r26=%08X%08X r27=%08X%08X\n", |
| 1138 | | (UINT32)(mips3.core->r[24] >> 32), (UINT32)mips3.core->r[24], |
| 1139 | | (UINT32)(mips3.core->r[25] >> 32), (UINT32)mips3.core->r[25], |
| 1140 | | (UINT32)(mips3.core->r[26] >> 32), (UINT32)mips3.core->r[26], |
| 1141 | | (UINT32)(mips3.core->r[27] >> 32), (UINT32)mips3.core->r[27]); |
| 1203 | (UINT32)(mips3->r[24] >> 32), (UINT32)mips3->r[24], |
| 1204 | (UINT32)(mips3->r[25] >> 32), (UINT32)mips3->r[25], |
| 1205 | (UINT32)(mips3->r[26] >> 32), (UINT32)mips3->r[26], |
| 1206 | (UINT32)(mips3->r[27] >> 32), (UINT32)mips3->r[27]); |
| 1142 | 1207 | printf("r28=%08X%08X r29=%08X%08X r30=%08X%08X r31=%08X%08X\n", |
| 1143 | | (UINT32)(mips3.core->r[28] >> 32), (UINT32)mips3.core->r[28], |
| 1144 | | (UINT32)(mips3.core->r[29] >> 32), (UINT32)mips3.core->r[29], |
| 1145 | | (UINT32)(mips3.core->r[30] >> 32), (UINT32)mips3.core->r[30], |
| 1146 | | (UINT32)(mips3.core->r[31] >> 32), (UINT32)mips3.core->r[31]); |
| 1208 | (UINT32)(mips3->r[28] >> 32), (UINT32)mips3->r[28], |
| 1209 | (UINT32)(mips3->r[29] >> 32), (UINT32)mips3->r[29], |
| 1210 | (UINT32)(mips3->r[30] >> 32), (UINT32)mips3->r[30], |
| 1211 | (UINT32)(mips3->r[31] >> 32), (UINT32)mips3->r[31]); |
| 1147 | 1212 | printf(" hi=%08X%08X lo=%08X%08X\n", |
| 1148 | | (UINT32)(mips3.core->r[REG_HI] >> 32), (UINT32)mips3.core->r[REG_HI], |
| 1149 | | (UINT32)(mips3.core->r[REG_LO] >> 32), (UINT32)mips3.core->r[REG_LO]); |
| 1213 | (UINT32)(mips3->r[REG_HI] >> 32), (UINT32)mips3->r[REG_HI], |
| 1214 | (UINT32)(mips3->r[REG_LO] >> 32), (UINT32)mips3->r[REG_LO]); |
| 1150 | 1215 | } |
| 1151 | 1216 | |
| 1152 | 1217 | |
| r2762 | r2763 | |
| 1158 | 1223 | static void cfunc_unimplemented(void *param) |
| 1159 | 1224 | { |
| 1160 | 1225 | UINT32 opcode = (FPTR)param; |
| 1161 | | fatalerror("PC=%08X: Unimplemented op %08X (%02X,%02X)", mips3.core->pc, opcode, opcode >> 26, opcode & 0x3f); |
| 1226 | fatalerror("PC=%08X: Unimplemented op %08X (%02X,%02X)", mips3->pc, opcode, opcode >> 26, opcode & 0x3f); |
| 1162 | 1227 | } |
| 1163 | 1228 | |
| 1164 | 1229 | |
| r2762 | r2763 | |
| 1186 | 1251 | block = drcuml_block_begin(drcuml, 20, &errorbuf); |
| 1187 | 1252 | |
| 1188 | 1253 | /* forward references */ |
| 1189 | | alloc_handle(drcuml, &mips3.exception_norecover[EXCEPTION_INTERRUPT], "interrupt_norecover"); |
| 1190 | | alloc_handle(drcuml, &mips3.nocode, "nocode"); |
| 1254 | alloc_handle(drcuml, &mips3->impstate->exception_norecover[EXCEPTION_INTERRUPT], "interrupt_norecover"); |
| 1255 | alloc_handle(drcuml, &mips3->impstate->nocode, "nocode"); |
| 1191 | 1256 | |
| 1192 | | alloc_handle(drcuml, &mips3.entry, "entry"); |
| 1193 | | UML_HANDLE(block, mips3.entry); // handle entry |
| 1257 | alloc_handle(drcuml, &mips3->impstate->entry, "entry"); |
| 1258 | UML_HANDLE(block, mips3->impstate->entry); // handle entry |
| 1194 | 1259 | |
| 1195 | 1260 | /* reset the FPU mode */ |
| 1196 | 1261 | UML_AND(block, IREG(0), CCR132(31), IMM(3)); // and i0,ccr1[31],3 |
| 1197 | | UML_LOAD1U(block, IREG(0), &mips3.cstate->fpmode[0], IREG(0)); // load1u i0,fpmode,i0 |
| 1262 | UML_LOAD1U(block, IREG(0), &mips3->impstate->fpmode[0], IREG(0)); // load1u i0,fpmode,i0 |
| 1198 | 1263 | UML_SETFMOD(block, IREG(0)); // setfmod i0 |
| 1199 | 1264 | |
| 1200 | 1265 | /* load fast integer registers */ |
| r2762 | r2763 | |
| 1208 | 1273 | UML_JMPc(block, IF_Z, skip); // jmp skip,Z |
| 1209 | 1274 | UML_TEST(block, CPR032(COP0_Status), IMM(SR_EXL | SR_ERL)); // test [Status],SR_EXL | SR_ERL |
| 1210 | 1275 | UML_JMPc(block, IF_NZ, skip); // jmp skip,NZ |
| 1211 | | UML_MOV(block, IREG(0), MEM(&mips3.core->pc)); // mov i0,pc |
| 1276 | UML_MOV(block, IREG(0), MEM(&mips3->pc)); // mov i0,pc |
| 1212 | 1277 | UML_MOV(block, IREG(1), IMM(0)); // mov i1,0 |
| 1213 | | UML_CALLH(block, mips3.exception_norecover[EXCEPTION_INTERRUPT]); // callh exception_norecover |
| 1278 | UML_CALLH(block, mips3->impstate->exception_norecover[EXCEPTION_INTERRUPT]); // callh exception_norecover |
| 1214 | 1279 | UML_LABEL(block, skip); // skip: |
| 1215 | 1280 | |
| 1216 | 1281 | /* generate a hash jump via the current mode and PC */ |
| 1217 | | UML_HASHJMP(block, MEM(&mips3.cstate->mode), MEM(&mips3.core->pc), mips3.nocode);// hashjmp <mode>,<pc>,nocode |
| 1218 | | |
| 1282 | UML_HASHJMP(block, MEM(&mips3->impstate->mode), MEM(&mips3->pc), mips3->impstate->nocode); |
| 1283 | // hashjmp <mode>,<pc>,nocode |
| 1219 | 1284 | drcuml_block_end(block); |
| 1220 | 1285 | } |
| 1221 | 1286 | |
| r2762 | r2763 | |
| 1238 | 1303 | block = drcuml_block_begin(drcuml, 10, &errorbuf); |
| 1239 | 1304 | |
| 1240 | 1305 | /* generate a hash jump via the current mode and PC */ |
| 1241 | | alloc_handle(drcuml, &mips3.nocode, "nocode"); |
| 1242 | | UML_HANDLE(block, mips3.nocode); // handle nocode |
| 1306 | alloc_handle(drcuml, &mips3->impstate->nocode, "nocode"); |
| 1307 | UML_HANDLE(block, mips3->impstate->nocode); // handle nocode |
| 1243 | 1308 | UML_GETEXP(block, IREG(0)); // getexp i0 |
| 1244 | | UML_MOV(block, MEM(&mips3.core->pc), IREG(0)); // mov [pc],i0 |
| 1309 | UML_MOV(block, MEM(&mips3->pc), IREG(0)); // mov [pc],i0 |
| 1245 | 1310 | save_fast_iregs(block); |
| 1246 | 1311 | UML_EXIT(block, IMM(EXECUTE_MISSING_CODE)); // exit EXECUTE_MISSING_CODE |
| 1247 | 1312 | |
| r2762 | r2763 | |
| 1267 | 1332 | block = drcuml_block_begin(drcuml, 10, &errorbuf); |
| 1268 | 1333 | |
| 1269 | 1334 | /* generate a hash jump via the current mode and PC */ |
| 1270 | | alloc_handle(drcuml, &mips3.out_of_cycles, "out_of_cycles"); |
| 1271 | | UML_HANDLE(block, mips3.out_of_cycles); // handle out_of_cycles |
| 1335 | alloc_handle(drcuml, &mips3->impstate->out_of_cycles, "out_of_cycles"); |
| 1336 | UML_HANDLE(block, mips3->impstate->out_of_cycles); // handle out_of_cycles |
| 1272 | 1337 | UML_GETEXP(block, IREG(0)); // getexp i0 |
| 1273 | | UML_MOV(block, MEM(&mips3.core->pc), IREG(0)); // mov <pc>,i0 |
| 1338 | UML_MOV(block, MEM(&mips3->pc), IREG(0)); // mov <pc>,i0 |
| 1274 | 1339 | save_fast_iregs(block); |
| 1275 | 1340 | UML_EXIT(block, IMM(EXECUTE_OUT_OF_CYCLES)); // exit EXECUTE_OUT_OF_CYCLES |
| 1276 | 1341 | |
| r2762 | r2763 | |
| 1293 | 1358 | fatalerror("Unrecoverable error in static_generate_tlb_mismatch"); |
| 1294 | 1359 | |
| 1295 | 1360 | /* forward references */ |
| 1296 | | alloc_handle(drcuml, &mips3.exception[EXCEPTION_TLBLOAD], "exception_tlbload"); |
| 1297 | | alloc_handle(drcuml, &mips3.exception[EXCEPTION_TLBLOAD_FILL], "exception_tlbload_fill"); |
| 1361 | alloc_handle(drcuml, &mips3->impstate->exception[EXCEPTION_TLBLOAD], "exception_tlbload"); |
| 1362 | alloc_handle(drcuml, &mips3->impstate->exception[EXCEPTION_TLBLOAD_FILL], "exception_tlbload_fill"); |
| 1298 | 1363 | |
| 1299 | 1364 | /* begin generating */ |
| 1300 | 1365 | block = drcuml_block_begin(drcuml, 20, &errorbuf); |
| 1301 | 1366 | |
| 1302 | 1367 | /* generate a hash jump via the current mode and PC */ |
| 1303 | | alloc_handle(drcuml, &mips3.tlb_mismatch, "tlb_mismatch"); |
| 1304 | | UML_HANDLE(block, mips3.tlb_mismatch); // handle tlb_mismatch |
| 1368 | alloc_handle(drcuml, &mips3->impstate->tlb_mismatch, "tlb_mismatch"); |
| 1369 | UML_HANDLE(block, mips3->impstate->tlb_mismatch); // handle tlb_mismatch |
| 1305 | 1370 | UML_RECOVER(block, IREG(0), MAPVAR_PC); // recover i0,PC |
| 1306 | | UML_MOV(block, MEM(&mips3.core->pc), IREG(0)); // mov <pc>,i0 |
| 1371 | UML_MOV(block, MEM(&mips3->pc), IREG(0)); // mov <pc>,i0 |
| 1307 | 1372 | UML_SHR(block, IREG(1), IREG(0), IMM(12)); // shr i1,i0,12 |
| 1308 | | UML_LOAD4(block, IREG(1), mips3.core->tlb_table, IREG(1)); // load4 i1,[tlb_table],i1 |
| 1373 | UML_LOAD4(block, IREG(1), mips3->tlb_table, IREG(1)); // load4 i1,[tlb_table],i1 |
| 1309 | 1374 | if (PRINTF_MMU) |
| 1310 | 1375 | { |
| 1311 | | UML_MOV(block, MEM(&mips3.cstate->arg0), IREG(0)); // mov [arg0],i0 |
| 1312 | | UML_MOV(block, MEM(&mips3.cstate->arg1), IREG(1)); // mov [arg1],i1 |
| 1376 | UML_MOV(block, MEM(&mips3->impstate->arg0), IREG(0)); // mov [arg0],i0 |
| 1377 | UML_MOV(block, MEM(&mips3->impstate->arg1), IREG(1)); // mov [arg1],i1 |
| 1313 | 1378 | UML_CALLC(block, cfunc_printf_debug, "TLB mismatch @ %08X (ent=%08X)\n"); // callc printf_debug |
| 1314 | 1379 | } |
| 1315 | 1380 | UML_TEST(block, IREG(1), IMM(TLB_VALID)); // test i1,TLB_VALID |
| 1316 | 1381 | UML_JMPc(block, IF_NZ, 1); // jmp 1,nz |
| 1317 | 1382 | UML_TEST(block, IREG(1), IMM(TLB_PRESENT)); // test i1,TLB_PRESENT |
| 1318 | | UML_EXHc(block, IF_NZ, mips3.exception[EXCEPTION_TLBLOAD], IREG(0)); // exh exception[TLBLOAD],i0,nz |
| 1319 | | UML_EXH(block, mips3.exception[EXCEPTION_TLBLOAD_FILL], IREG(0)); // exh exception[TLBLOAD_FILL],i0 |
| 1383 | UML_EXHc(block, IF_NZ, mips3->impstate->exception[EXCEPTION_TLBLOAD], IREG(0)); // exh exception[TLBLOAD],i0,nz |
| 1384 | UML_EXH(block, mips3->impstate->exception[EXCEPTION_TLBLOAD_FILL], IREG(0)); // exh exception[TLBLOAD_FILL],i0 |
| 1320 | 1385 | UML_LABEL(block, 1); // 1: |
| 1321 | 1386 | save_fast_iregs(block); |
| 1322 | 1387 | UML_EXIT(block, IMM(EXECUTE_MISSING_CODE)); // exit EXECUTE_MISSING_CODE |
| r2762 | r2763 | |
| 1332 | 1397 | |
| 1333 | 1398 | static void static_generate_exception(drcuml_state *drcuml, UINT8 exception, int recover, const char *name) |
| 1334 | 1399 | { |
| 1335 | | drcuml_codehandle **exception_handle = recover ? &mips3.exception[exception] : &mips3.exception_norecover[exception]; |
| 1400 | drcuml_codehandle **exception_handle = recover ? &mips3->impstate->exception[exception] : &mips3->impstate->exception_norecover[exception]; |
| 1336 | 1401 | UINT32 offset = 0x180; |
| 1337 | 1402 | drcuml_codelabel next = 1; |
| 1338 | 1403 | drcuml_block *block; |
| r2762 | r2763 | |
| 1405 | 1470 | UML_MOVc(block, IF_Z, IREG(0), IMM(0x80000000 + offset)); // mov i0,0x80000000 + offset,z |
| 1406 | 1471 | |
| 1407 | 1472 | /* adjust cycles */ |
| 1408 | | UML_SUBf(block, MEM(&mips3.core->icount), MEM(&mips3.core->icount), IREG(1), FLAGS_S); // sub icount,icount,cycles,S |
| 1409 | | UML_EXHc(block, IF_S, mips3.out_of_cycles, IREG(0)); // exh out_of_cycles,i0 |
| 1473 | UML_SUBf(block, MEM(&mips3->icount), MEM(&mips3->icount), IREG(1), FLAGS_S); // sub icount,icount,cycles,S |
| 1474 | UML_EXHc(block, IF_S, mips3->impstate->out_of_cycles, IREG(0)); // exh out_of_cycles,i0 |
| 1410 | 1475 | |
| 1411 | | UML_HASHJMP(block, MEM(&mips3.cstate->mode), IREG(0), mips3.nocode); // hashjmp <mode>,i0,nocode |
| 1476 | UML_HASHJMP(block, MEM(&mips3->impstate->mode), IREG(0), mips3->impstate->nocode);// hashjmp <mode>,i0,nocode |
| 1412 | 1477 | |
| 1413 | 1478 | drcuml_block_end(block); |
| 1414 | 1479 | } |
| r2762 | r2763 | |
| 1423 | 1488 | /* on entry, address is in I0; data for writes is in I1; mask for accesses is in I2 */ |
| 1424 | 1489 | /* on exit, read result is in I0 */ |
| 1425 | 1490 | /* routine trashes I0-I3 */ |
| 1426 | | drcuml_codehandle *exception_tlb = mips3.exception[iswrite ? EXCEPTION_TLBSTORE : EXCEPTION_TLBLOAD]; |
| 1427 | | drcuml_codehandle *exception_tlbfill = mips3.exception[iswrite ? EXCEPTION_TLBSTORE_FILL : EXCEPTION_TLBLOAD_FILL]; |
| 1428 | | drcuml_codehandle *exception_addrerr = mips3.exception[iswrite ? EXCEPTION_ADDRSTORE : EXCEPTION_ADDRLOAD]; |
| 1491 | drcuml_codehandle *exception_tlb = mips3->impstate->exception[iswrite ? EXCEPTION_TLBSTORE : EXCEPTION_TLBLOAD]; |
| 1492 | drcuml_codehandle *exception_tlbfill = mips3->impstate->exception[iswrite ? EXCEPTION_TLBSTORE_FILL : EXCEPTION_TLBLOAD_FILL]; |
| 1493 | drcuml_codehandle *exception_addrerr = mips3->impstate->exception[iswrite ? EXCEPTION_ADDRSTORE : EXCEPTION_ADDRLOAD]; |
| 1429 | 1494 | drcuml_block *block; |
| 1430 | 1495 | jmp_buf errorbuf; |
| 1431 | 1496 | int tlbmiss = 0; |
| r2762 | r2763 | |
| 1464 | 1529 | |
| 1465 | 1530 | /* general case: assume paging and perform a translation */ |
| 1466 | 1531 | UML_SHR(block, IREG(3), IREG(0), IMM(12)); // shr i3,i0,12 |
| 1467 | | UML_LOAD4(block, IREG(3), mips3.core->tlb_table, IREG(3)); // load4 i3,[tlb_table],i3 |
| 1532 | UML_LOAD4(block, IREG(3), mips3->tlb_table, IREG(3)); // load4 i3,[tlb_table],i3 |
| 1468 | 1533 | UML_TEST(block, IREG(3), IMM(iswrite ? TLB_DIRTY : TLB_VALID)); // test i3,iswrite ? TLB_DIRTY : TLB_VALID |
| 1469 | 1534 | UML_JMPc(block, IF_Z, tlbmiss = label++); // jmp tlbmiss,z |
| 1470 | 1535 | UML_INSERT(block, IREG(0), IREG(3), IMM(0), IMM(0xfffff000)); // insert i0,i3,0,0xfffff000 |
| 1471 | 1536 | |
| 1472 | 1537 | for (ramnum = 0; ramnum < MIPS3_MAX_FASTRAM; ramnum++) |
| 1473 | | if (!Machine->debug_mode && mips3.fastram[ramnum].base != NULL && (!iswrite || !mips3.fastram[ramnum].readonly)) |
| 1538 | if (!Machine->debug_mode && mips3->impstate->fastram[ramnum].base != NULL && (!iswrite || !mips3->impstate->fastram[ramnum].readonly)) |
| 1474 | 1539 | { |
| 1475 | | void *fastbase = (UINT8 *)mips3.fastram[ramnum].base - mips3.fastram[ramnum].start; |
| 1540 | void *fastbase = (UINT8 *)mips3->impstate->fastram[ramnum].base - mips3->impstate->fastram[ramnum].start; |
| 1476 | 1541 | UINT32 skip = label++; |
| 1477 | | if (mips3.fastram[ramnum].end != 0xffffffff) |
| 1542 | if (mips3->impstate->fastram[ramnum].end != 0xffffffff) |
| 1478 | 1543 | { |
| 1479 | | UML_CMP(block, IREG(0), IMM(mips3.fastram[ramnum].end)); // cmp i0,end |
| 1544 | UML_CMP(block, IREG(0), IMM(mips3->impstate->fastram[ramnum].end)); // cmp i0,end |
| 1480 | 1545 | UML_JMPc(block, IF_A, skip); // ja skip |
| 1481 | 1546 | } |
| 1482 | | if (mips3.fastram[ramnum].start != 0x00000000) |
| 1547 | if (mips3->impstate->fastram[ramnum].start != 0x00000000) |
| 1483 | 1548 | { |
| 1484 | | UML_CMP(block, IREG(0), IMM(mips3.fastram[ramnum].start)); // cmp i0,fastram_start |
| 1549 | UML_CMP(block, IREG(0), IMM(mips3->impstate->fastram[ramnum].start));// cmp i0,fastram_start |
| 1485 | 1550 | UML_JMPc(block, IF_B, skip); // jb skip |
| 1486 | 1551 | } |
| 1487 | 1552 | |
| r2762 | r2763 | |
| 1489 | 1554 | { |
| 1490 | 1555 | if (size == 1) |
| 1491 | 1556 | { |
| 1492 | | UML_XOR(block, IREG(0), IREG(0), IMM(mips3.core->bigendian ? BYTE4_XOR_BE(0) : BYTE4_XOR_LE(0))); |
| 1557 | UML_XOR(block, IREG(0), IREG(0), IMM(mips3->bigendian ? BYTE4_XOR_BE(0) : BYTE4_XOR_LE(0))); |
| 1493 | 1558 | // xor i0,i0,bytexor |
| 1494 | 1559 | UML_LOAD1U(block, IREG(0), fastbase, IREG(0)); // load1u i0,fastbase,i0 |
| 1495 | 1560 | } |
| 1496 | 1561 | else if (size == 2) |
| 1497 | 1562 | { |
| 1498 | 1563 | UML_SHR(block, IREG(0), IREG(0), IMM(1)); // shr i0,i0,1 |
| 1499 | | UML_XOR(block, IREG(0), IREG(0), IMM(mips3.core->bigendian ? BYTE_XOR_BE(0) : BYTE_XOR_LE(0))); |
| 1564 | UML_XOR(block, IREG(0), IREG(0), IMM(mips3->bigendian ? BYTE_XOR_BE(0) : BYTE_XOR_LE(0))); |
| 1500 | 1565 | // xor i0,i0,bytexor |
| 1501 | 1566 | UML_LOAD2U(block, IREG(0), fastbase, IREG(0)); // load2u i0,fastbase,i0 |
| 1502 | 1567 | } |
| r2762 | r2763 | |
| 1509 | 1574 | { |
| 1510 | 1575 | UML_SHR(block, IREG(0), IREG(0), IMM(3)); // shr i0,i0,3 |
| 1511 | 1576 | UML_DLOAD8(block, IREG(0), fastbase, IREG(0)); // dload8 i0,fastbase,i0 |
| 1512 | | UML_DROR(block, IREG(0), IREG(0), IMM(32 * (mips3.core->bigendian ? BYTE_XOR_BE(0) : BYTE_XOR_LE(0)))); |
| 1577 | UML_DROR(block, IREG(0), IREG(0), IMM(32 * (mips3->bigendian ? BYTE_XOR_BE(0) : BYTE_XOR_LE(0)))); |
| 1513 | 1578 | // dror i0,i0,32*bytexor |
| 1514 | 1579 | } |
| 1515 | 1580 | UML_RET(block); // ret |
| r2762 | r2763 | |
| 1518 | 1583 | { |
| 1519 | 1584 | if (size == 1) |
| 1520 | 1585 | { |
| 1521 | | UML_XOR(block, IREG(0), IREG(0), IMM(mips3.core->bigendian ? BYTE4_XOR_BE(0) : BYTE4_XOR_LE(0))); |
| 1586 | UML_XOR(block, IREG(0), IREG(0), IMM(mips3->bigendian ? BYTE4_XOR_BE(0) : BYTE4_XOR_LE(0))); |
| 1522 | 1587 | // xor i0,i0,bytexor |
| 1523 | 1588 | UML_STORE1(block, fastbase, IREG(0), IREG(1)); // store1 fastbase,i0,i1 |
| 1524 | 1589 | } |
| 1525 | 1590 | else if (size == 2) |
| 1526 | 1591 | { |
| 1527 | 1592 | UML_SHR(block, IREG(0), IREG(0), IMM(1)); // shr i0,i0,1 |
| 1528 | | UML_XOR(block, IREG(0), IREG(0), IMM(mips3.core->bigendian ? BYTE_XOR_BE(0) : BYTE_XOR_LE(0))); |
| 1593 | UML_XOR(block, IREG(0), IREG(0), IMM(mips3->bigendian ? BYTE_XOR_BE(0) : BYTE_XOR_LE(0))); |
| 1529 | 1594 | // xor i0,i0,bytexor |
| 1530 | 1595 | UML_STORE2(block, fastbase, IREG(0), IREG(1)); // store2 fastbase,i0,i1 |
| 1531 | 1596 | } |
| r2762 | r2763 | |
| 1544 | 1609 | else if (size == 8) |
| 1545 | 1610 | { |
| 1546 | 1611 | UML_SHR(block, IREG(0), IREG(0), IMM(3)); // shr i0,i0,3 |
| 1547 | | UML_DROR(block, IREG(1), IREG(1), IMM(32 * (mips3.core->bigendian ? BYTE_XOR_BE(0) : BYTE_XOR_LE(0)))); |
| 1612 | UML_DROR(block, IREG(1), IREG(1), IMM(32 * (mips3->bigendian ? BYTE_XOR_BE(0) : BYTE_XOR_LE(0)))); |
| 1548 | 1613 | // dror i1,i1,32*bytexor |
| 1549 | 1614 | if (ismasked) |
| 1550 | 1615 | { |
| 1551 | | UML_DROR(block, IREG(2), IREG(2), IMM(32 * (mips3.core->bigendian ? BYTE_XOR_BE(0) : BYTE_XOR_LE(0)))); |
| 1616 | UML_DROR(block, IREG(2), IREG(2), IMM(32 * (mips3->bigendian ? BYTE_XOR_BE(0) : BYTE_XOR_LE(0)))); |
| 1552 | 1617 | // dror i2,i2,32*bytexor |
| 1553 | 1618 | UML_DLOAD8(block, IREG(3), fastbase, IREG(0)); // dload8 i3,fastbase,i0 |
| 1554 | 1619 | UML_DINSERT(block, IREG(3), IREG(1), IMM(0), IREG(2)); // dinsert i3,i1,0,i2 |
| r2762 | r2763 | |
| 1621 | 1686 | if (iswrite) |
| 1622 | 1687 | { |
| 1623 | 1688 | UML_TEST(block, IREG(3), IMM(TLB_VALID)); // test i3,TLB_VALID |
| 1624 | | UML_EXHc(block, IF_NZ, mips3.exception[EXCEPTION_TLBMOD], IREG(0)); // exh tlbmod,i0,nz |
| 1689 | UML_EXHc(block, IF_NZ, mips3->impstate->exception[EXCEPTION_TLBMOD], IREG(0)); |
| 1690 | // exh tlbmod,i0,nz |
| 1625 | 1691 | } |
| 1626 | 1692 | UML_TEST(block, IREG(3), IMM(TLB_PRESENT)); // test i3,TLB_PRESENT |
| 1627 | 1693 | UML_EXHc(block, IF_NZ, exception_tlb, IREG(0)); // exh tlb,i0,nz |
| r2762 | r2763 | |
| 1648 | 1714 | UML_TEST(block, IREG(0), IMM(SR_EXL | SR_ERL)); // test i0,SR_EXL | SR_ERL |
| 1649 | 1715 | UML_MOVc(block, IF_NZ, IREG(2), IMM(0)); // mov i2,0,nz |
| 1650 | 1716 | UML_INSERT(block, IREG(2), IREG(0), IMM(32-26), IMM(0x01)); // insert i2,i0,32-26,0x01 |
| 1651 | | UML_MOV(block, MEM(&mips3.cstate->mode), IREG(2)); // mov [mode],i2 |
| 1717 | UML_MOV(block, MEM(&mips3->impstate->mode), IREG(2)); // mov [mode],i2 |
| 1652 | 1718 | } |
| 1653 | 1719 | |
| 1654 | 1720 | |
| r2762 | r2763 | |
| 1671 | 1737 | UML_JMPc(block, IF_Z, skip = compiler->labelnum++); // jmp skip,Z |
| 1672 | 1738 | UML_MOV(block, IREG(0), PARAM(ptype, pvalue)); // mov i0,nextpc |
| 1673 | 1739 | UML_MOV(block, IREG(1), IMM(compiler->cycles)); // mov i1,cycles |
| 1674 | | UML_CALLH(block, mips3.exception_norecover[EXCEPTION_INTERRUPT]); // callh interrupt_norecover |
| 1740 | UML_CALLH(block, mips3->impstate->exception_norecover[EXCEPTION_INTERRUPT]);// callh interrupt_norecover |
| 1675 | 1741 | UML_LABEL(block, skip); // skip: |
| 1676 | 1742 | } |
| 1677 | 1743 | |
| r2762 | r2763 | |
| 1690 | 1756 | UML_JMPc(block, IF_NZ, skip); // jmp skip,NZ |
| 1691 | 1757 | UML_MOV(block, IREG(0), PARAM(ptype, pvalue)); // mov i0,nextpc |
| 1692 | 1758 | UML_MOV(block, IREG(1), IMM(compiler->cycles)); // mov i1,cycles |
| 1693 | | UML_CALLH(block, mips3.exception_norecover[EXCEPTION_INTERRUPT]); // callh interrupt_norecover |
| 1759 | UML_CALLH(block, mips3->impstate->exception_norecover[EXCEPTION_INTERRUPT]);// callh interrupt_norecover |
| 1694 | 1760 | UML_LABEL(block, skip); // skip: |
| 1695 | 1761 | } |
| 1696 | 1762 | |
| 1697 | 1763 | /* account for cycles */ |
| 1698 | 1764 | if (compiler->cycles > 0) |
| 1699 | 1765 | { |
| 1700 | | UML_SUBf(block, MEM(&mips3.core->icount), MEM(&mips3.core->icount), MAPVAR_CYCLES, allow_exception ? FLAGS_S : 0); |
| 1766 | UML_SUBf(block, MEM(&mips3->icount), MEM(&mips3->icount), MAPVAR_CYCLES, allow_exception ? FLAGS_S : 0); |
| 1701 | 1767 | // sub icount,icount,cycles,S |
| 1702 | 1768 | UML_MAPVAR(block, MAPVAR_CYCLES, 0); // mapvar cycles,0 |
| 1703 | 1769 | if (allow_exception) |
| 1704 | | UML_EXHc(block, IF_S, mips3.out_of_cycles, PARAM(ptype, pvalue)); // exh out_of_cycles,nextpc |
| 1770 | UML_EXHc(block, IF_S, mips3->impstate->out_of_cycles, PARAM(ptype, pvalue)); |
| 1771 | // exh out_of_cycles,nextpc |
| 1705 | 1772 | } |
| 1706 | 1773 | compiler->cycles = 0; |
| 1707 | 1774 | } |
| r2762 | r2763 | |
| 1719 | 1786 | UML_COMMENT(block, "[Validation for %08X]", seqhead->pc); // comment |
| 1720 | 1787 | |
| 1721 | 1788 | /* loose verify or single instruction: just compare and fail */ |
| 1722 | | if (!(mips3.drcoptions & MIPS3DRC_STRICT_VERIFY) || seqhead->next == NULL) |
| 1789 | if (!(mips3->impstate->drcoptions & MIPS3DRC_STRICT_VERIFY) || seqhead->next == NULL) |
| 1723 | 1790 | { |
| 1724 | 1791 | if (!(seqhead->flags & OPFLAG_VIRTUAL_NOOP)) |
| 1725 | 1792 | { |
| 1726 | 1793 | UML_LOAD4(block, IREG(0), seqhead->opptr.l, IMM(0)); // load4 i0,*opptr |
| 1727 | 1794 | UML_CMP(block, IREG(0), IMM(*seqhead->opptr.l)); // cmp i0,*opptr |
| 1728 | | UML_EXHc(block, IF_NE, mips3.nocode, IMM(epc(seqhead))); // exne nocode,seqhead->pc |
| 1795 | UML_EXHc(block, IF_NE, mips3->impstate->nocode, IMM(epc(seqhead))); // exne nocode,seqhead->pc |
| 1729 | 1796 | } |
| 1730 | 1797 | } |
| 1731 | 1798 | |
| r2762 | r2763 | |
| 1736 | 1803 | for (curdesc = seqhead->next; curdesc != seqlast->next; curdesc = curdesc->next) |
| 1737 | 1804 | if (!(curdesc->flags & OPFLAG_VIRTUAL_NOOP)) |
| 1738 | 1805 | { |
| 1739 | | UML_LOAD4(block, IREG(0), curdesc->opptr.l, IMM(0)); // load4 i0,*opptr |
| 1740 | | UML_CMP(block, IREG(0), IMM(*curdesc->opptr.l)); // cmp i0,*opptr |
| 1741 | | UML_EXHc(block, IF_NE, mips3.nocode, IMM(epc(seqhead))); // exne nocode,seqhead->pc |
| 1806 | UML_LOAD4(block, IREG(0), curdesc->opptr.l, IMM(0)); // load4 i0,*opptr |
| 1807 | UML_CMP(block, IREG(0), IMM(*curdesc->opptr.l)); // cmp i0,*opptr |
| 1808 | UML_EXHc(block, IF_NE, mips3->impstate->nocode, IMM(epc(seqhead))); // exne nocode,seqhead->pc |
| 1742 | 1809 | } |
| 1743 | 1810 | #else |
| 1744 | 1811 | UINT32 sum = 0; |
| r2762 | r2763 | |
| 1747 | 1814 | for (curdesc = seqhead->next; curdesc != seqlast->next; curdesc = curdesc->next) |
| 1748 | 1815 | if (!(curdesc->flags & OPFLAG_VIRTUAL_NOOP)) |
| 1749 | 1816 | { |
| 1750 | | UML_LOAD4(block, IREG(1), curdesc->opptr.l, IMM(0)); // load4 i1,*opptr |
| 1751 | | UML_ADD(block, IREG(0), IREG(0), IREG(1)); // add i0,i0,i1 |
| 1817 | UML_LOAD4(block, IREG(1), curdesc->opptr.l, IMM(0)); // load4 i1,*opptr |
| 1818 | UML_ADD(block, IREG(0), IREG(0), IREG(1)); // add i0,i0,i1 |
| 1752 | 1819 | sum += *curdesc->opptr.l; |
| 1753 | 1820 | } |
| 1754 | 1821 | UML_CMP(block, IREG(0), IMM(sum)); // cmp i0,sum |
| 1755 | | UML_EXHc(block, IF_NE, mips3.nocode, IMM(epc(seqhead))); // exne nocode,seqhead->pc |
| 1822 | UML_EXHc(block, IF_NE, mips3->impstate->nocode, IMM(epc(seqhead))); // exne nocode,seqhead->pc |
| 1756 | 1823 | #endif |
| 1757 | 1824 | } |
| 1758 | 1825 | } |
| r2762 | r2763 | |
| 1781 | 1848 | |
| 1782 | 1849 | /* is this a hotspot? */ |
| 1783 | 1850 | for (hotnum = 0; hotnum < MIPS3_MAX_HOTSPOTS; hotnum++) |
| 1784 | | if (mips3.hotspot[hotnum].pc != 0 && desc->pc == mips3.hotspot[hotnum].pc && *desc->opptr.l == mips3.hotspot[hotnum].opcode) |
| 1851 | if (mips3->impstate->hotspot[hotnum].pc != 0 && desc->pc == mips3->impstate->hotspot[hotnum].pc && *desc->opptr.l == mips3->impstate->hotspot[hotnum].opcode) |
| 1785 | 1852 | { |
| 1786 | | compiler->cycles += mips3.hotspot[hotnum].cycles; |
| 1853 | compiler->cycles += mips3->impstate->hotspot[hotnum].cycles; |
| 1787 | 1854 | break; |
| 1788 | 1855 | } |
| 1789 | 1856 | |
| r2762 | r2763 | |
| 1797 | 1864 | /* if we are debugging, call the debugger */ |
| 1798 | 1865 | if (Machine->debug_mode) |
| 1799 | 1866 | { |
| 1800 | | UML_MOV(block, MEM(&mips3.core->pc), IMM(desc->pc)); // mov [pc],desc->pc |
| 1867 | UML_MOV(block, MEM(&mips3->pc), IMM(desc->pc)); // mov [pc],desc->pc |
| 1801 | 1868 | save_fast_iregs(block); |
| 1802 | 1869 | UML_DEBUG(block, IMM(desc->pc)); // debug desc->pc |
| 1803 | 1870 | } |
| r2762 | r2763 | |
| 1805 | 1872 | /* if we hit an unmapped address, fatal error */ |
| 1806 | 1873 | if (desc->flags & OPFLAG_COMPILER_UNMAPPED) |
| 1807 | 1874 | { |
| 1808 | | UML_MOV(block, MEM(&mips3.core->pc), IMM(desc->pc)); // mov [pc],desc->pc |
| 1875 | UML_MOV(block, MEM(&mips3->pc), IMM(desc->pc)); // mov [pc],desc->pc |
| 1809 | 1876 | save_fast_iregs(block); |
| 1810 | 1877 | UML_EXIT(block, IMM(EXECUTE_UNMAPPED_CODE)); // exit EXECUTE_UNMAPPED_CODE |
| 1811 | 1878 | } |
| r2762 | r2763 | |
| 1815 | 1882 | { |
| 1816 | 1883 | if (PRINTF_MMU) |
| 1817 | 1884 | { |
| 1818 | | UML_MOV(block, MEM(&mips3.cstate->arg0), IMM(desc->pc)); // mov [arg0],desc->pc |
| 1885 | UML_MOV(block, MEM(&mips3->impstate->arg0), IMM(desc->pc)); // mov [arg0],desc->pc |
| 1819 | 1886 | UML_CALLC(block, cfunc_printf_debug, "Compiler page fault @ %08X\n"); // callc printf_debug |
| 1820 | 1887 | } |
| 1821 | | UML_EXH(block, mips3.tlb_mismatch, IMM(0)); // exh tlb_mismatch,0 |
| 1888 | UML_EXH(block, mips3->impstate->tlb_mismatch, IMM(0)); // exh tlb_mismatch,0 |
| 1822 | 1889 | } |
| 1823 | 1890 | |
| 1824 | 1891 | /* validate our TLB entry at this PC; if we fail, we need to handle it */ |
| 1825 | 1892 | if ((desc->flags & OPFLAG_VALIDATE_TLB) && (desc->pc < 0x80000000 || desc->pc >= 0xc0000000)) |
| 1826 | 1893 | { |
| 1827 | 1894 | /* if we currently have a valid TLB read entry, we just verify */ |
| 1828 | | if (mips3.core->tlb_table[desc->pc >> 12] & TLB_VALID) |
| 1895 | if (mips3->tlb_table[desc->pc >> 12] & TLB_VALID) |
| 1829 | 1896 | { |
| 1830 | 1897 | if (PRINTF_MMU) |
| 1831 | 1898 | { |
| 1832 | | UML_MOV(block, MEM(&mips3.cstate->arg0), IMM(desc->pc)); // mov [arg0],desc->pc |
| 1899 | UML_MOV(block, MEM(&mips3->impstate->arg0), IMM(desc->pc)); // mov [arg0],desc->pc |
| 1833 | 1900 | UML_CALLC(block, cfunc_printf_debug, "Checking TLB at @ %08X\n"); // callc printf_debug |
| 1834 | 1901 | } |
| 1835 | | UML_LOAD4(block, IREG(0), &mips3.core->tlb_table[desc->pc >> 12], IMM(0));// load4 i0,tlb_table[desc->pc >> 12] |
| 1836 | | UML_CMP(block, IREG(0), IMM(mips3.core->tlb_table[desc->pc >> 12])); // cmp i0,*tlbentry |
| 1837 | | UML_EXHc(block, IF_NE, mips3.tlb_mismatch, IMM(0)); // exh tlb_mismatch,0,NE |
| 1902 | UML_LOAD4(block, IREG(0), &mips3->tlb_table[desc->pc >> 12], IMM(0)); // load4 i0,tlb_table[desc->pc >> 12] |
| 1903 | UML_CMP(block, IREG(0), IMM(mips3->tlb_table[desc->pc >> 12])); // cmp i0,*tlbentry |
| 1904 | UML_EXHc(block, IF_NE, mips3->impstate->tlb_mismatch, IMM(0)); // exh tlb_mismatch,0,NE |
| 1838 | 1905 | } |
| 1839 | 1906 | |
| 1840 | 1907 | /* otherwise, we generate an unconditional exception */ |
| r2762 | r2763 | |
| 1842 | 1909 | { |
| 1843 | 1910 | if (PRINTF_MMU) |
| 1844 | 1911 | { |
| 1845 | | UML_MOV(block, MEM(&mips3.cstate->arg0), IMM(desc->pc)); // mov [arg0],desc->pc |
| 1912 | UML_MOV(block, MEM(&mips3->impstate->arg0), IMM(desc->pc)); // mov [arg0],desc->pc |
| 1846 | 1913 | UML_CALLC(block, cfunc_printf_debug, "No valid TLB @ %08X\n"); // callc printf_debug |
| 1847 | 1914 | } |
| 1848 | | UML_EXH(block, mips3.tlb_mismatch, IMM(0)); // exh tlb_mismatch,0 |
| 1915 | UML_EXH(block, mips3->impstate->tlb_mismatch, IMM(0)); // exh tlb_mismatch,0 |
| 1849 | 1916 | } |
| 1850 | 1917 | } |
| 1851 | 1918 | |
| 1852 | 1919 | /* if this is an invalid opcode, generate the exception now */ |
| 1853 | 1920 | if (desc->flags & OPFLAG_INVALID_OPCODE) |
| 1854 | | UML_EXH(block, mips3.exception[EXCEPTION_INVALIDOP], IMM(0)); // exh invalidop,0 |
| 1921 | UML_EXH(block, mips3->impstate->exception[EXCEPTION_INVALIDOP], IMM(0)); // exh invalidop,0 |
| 1855 | 1922 | |
| 1856 | 1923 | /* otherwise, unless this is a virtual no-op, it's a regular instruction */ |
| 1857 | 1924 | else if (!(desc->flags & OPFLAG_VIRTUAL_NOOP)) |
| r2762 | r2763 | |
| 1859 | 1926 | /* compile the instruction */ |
| 1860 | 1927 | if (!generate_opcode(block, compiler, desc)) |
| 1861 | 1928 | { |
| 1862 | | UML_MOV(block, MEM(&mips3.core->pc), IMM(desc->pc)); // mov [pc],desc->pc |
| 1863 | | UML_CALLC(block, cfunc_unimplemented, (void *)(FPTR)*desc->opptr.l); // callc cfunc_unimplemented |
| 1929 | UML_MOV(block, MEM(&mips3->pc), IMM(desc->pc)); // mov [pc],desc->pc |
| 1930 | UML_CALLC(block, cfunc_unimplemented, (void *)(FPTR)*desc->opptr.l); // callc cfunc_unimplemented |
| 1864 | 1931 | } |
| 1865 | 1932 | } |
| 1866 | 1933 | } |
| r2762 | r2763 | |
| 1890 | 1957 | if (desc->flags & OPFLAG_INTRABLOCK_BRANCH) |
| 1891 | 1958 | UML_JMP(block, desc->targetpc | 0x80000000); // jmp desc->targetpc | 0x80000000 |
| 1892 | 1959 | else |
| 1893 | | UML_HASHJMP(block, IMM(mips3.cstate->mode), IMM(desc->targetpc), mips3.nocode); |
| 1960 | UML_HASHJMP(block, IMM(mips3->impstate->mode), IMM(desc->targetpc), mips3->impstate->nocode); |
| 1894 | 1961 | // hashjmp <mode>,desc->targetpc,nocode |
| 1895 | 1962 | } |
| 1896 | 1963 | else |
| 1897 | 1964 | { |
| 1898 | 1965 | generate_update_cycles(block, &compiler_temp, R32(RSREG), TRUE); |
| 1899 | 1966 | // <subtract cycles> |
| 1900 | | UML_HASHJMP(block, IMM(mips3.cstate->mode), R32(RSREG), mips3.nocode); // hashjmp <mode>,<rsreg>,nocode |
| 1967 | UML_HASHJMP(block, IMM(mips3->impstate->mode), R32(RSREG), mips3->impstate->nocode); |
| 1968 | // hashjmp <mode>,<rsreg>,nocode |
| 1901 | 1969 | } |
| 1902 | 1970 | |
| 1903 | 1971 | /* update the label */ |
| r2762 | r2763 | |
| 1990 | 2058 | return TRUE; |
| 1991 | 2059 | |
| 1992 | 2060 | case 0x08: /* ADDI - MIPS I */ |
| 1993 | | if (mips3.drcoptions & MIPS3DRC_CHECK_OVERFLOWS) |
| 2061 | if (mips3->impstate->drcoptions & MIPS3DRC_CHECK_OVERFLOWS) |
| 1994 | 2062 | { |
| 1995 | 2063 | UML_ADDf(block, IREG(0), R32(RSREG), IMM(SIMMVAL), FLAGS_V); // add i0,<rsreg>,SIMMVAL,V |
| 1996 | | UML_EXHc(block, IF_V, mips3.exception[EXCEPTION_OVERFLOW], IMM(0)); // exh overflow,0 |
| 2064 | UML_EXHc(block, IF_V, mips3->impstate->exception[EXCEPTION_OVERFLOW], IMM(0)); |
| 2065 | // exh overflow,0 |
| 1997 | 2066 | } |
| 1998 | 2067 | else |
| 1999 | 2068 | UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL)); // add i0,<rsreg>,SIMMVAL |
| r2762 | r2763 | |
| 2010 | 2079 | return TRUE; |
| 2011 | 2080 | |
| 2012 | 2081 | case 0x18: /* DADDI - MIPS III */ |
| 2013 | | if (mips3.drcoptions & MIPS3DRC_CHECK_OVERFLOWS) |
| 2082 | if (mips3->impstate->drcoptions & MIPS3DRC_CHECK_OVERFLOWS) |
| 2014 | 2083 | { |
| 2015 | 2084 | UML_DADDf(block, IREG(0), R64(RSREG), IMM(SIMMVAL), FLAGS_V); // dadd i0,<rsreg>,SIMMVAL,V |
| 2016 | | UML_EXHc(block, IF_V, mips3.exception[EXCEPTION_OVERFLOW], IMM(0)); // exh overflow,0 |
| 2085 | UML_EXHc(block, IF_V, mips3->impstate->exception[EXCEPTION_OVERFLOW], IMM(0)); |
| 2086 | // exh overflow,0 |
| 2017 | 2087 | } |
| 2018 | 2088 | else |
| 2019 | 2089 | UML_DADD(block, IREG(0), R64(RSREG), IMM(SIMMVAL)); // dadd i0,<rsreg>,SIMMVAL |
| r2762 | r2763 | |
| 2045 | 2115 | if (RTREG != 0) |
| 2046 | 2116 | { |
| 2047 | 2117 | UML_DCMP(block, R64(RSREG), IMM(SIMMVAL)); // dcmp <rsreg>,SIMMVAL |
| 2048 | | UML_DFLAGS(block, R64(RTREG), (UINT64)~0, mips3.cstate->slt_table); // dflags <rtreg>,~0,slt_table |
| 2118 | UML_DFLAGS(block, R64(RTREG), (UINT64)~0, mips3->impstate->slt_table); |
| 2119 | // dflags <rtreg>,~0,slt_table |
| 2049 | 2120 | } |
| 2050 | 2121 | return TRUE; |
| 2051 | 2122 | |
| r2762 | r2763 | |
| 2053 | 2124 | if (RTREG != 0) |
| 2054 | 2125 | { |
| 2055 | 2126 | UML_DCMP(block, R64(RSREG), IMM(SIMMVAL)); // dcmp <rsreg>,SIMMVAL |
| 2056 | | UML_DFLAGS(block, R64(RTREG), (UINT64)~0, mips3.cstate->sltu_table);// dflags <rtreg>,~0,sltu_table |
| 2127 | UML_DFLAGS(block, R64(RTREG), (UINT64)~0, mips3->impstate->sltu_table); |
| 2128 | // dflags <rtreg>,~0,sltu_table |
| 2057 | 2129 | } |
| 2058 | 2130 | return TRUE; |
| 2059 | 2131 | |
| r2762 | r2763 | |
| 2062 | 2134 | |
| 2063 | 2135 | case 0x20: /* LB - MIPS I */ |
| 2064 | 2136 | UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL)); // add i0,<rsreg>,SIMMVAL |
| 2065 | | UML_CALLH(block, mips3.read8[mips3.cstate->mode >> 1]); // callh read8 |
| 2137 | UML_CALLH(block, mips3->impstate->read8[mips3->impstate->mode >> 1]); // callh read8 |
| 2066 | 2138 | if (RTREG != 0) |
| 2067 | 2139 | UML_DSEXT1(block, R64(RTREG), IREG(0)); // dsext1 <rtreg>,i0 |
| 2068 | 2140 | if (!in_delay_slot) |
| r2762 | r2763 | |
| 2071 | 2143 | |
| 2072 | 2144 | case 0x21: /* LH - MIPS I */ |
| 2073 | 2145 | UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL)); // add i0,<rsreg>,SIMMVAL |
| 2074 | | UML_CALLH(block, mips3.read16[mips3.cstate->mode >> 1]); // callh read16 |
| 2146 | UML_CALLH(block, mips3->impstate->read16[mips3->impstate->mode >> 1]); // callh read16 |
| 2075 | 2147 | if (RTREG != 0) |
| 2076 | 2148 | UML_DSEXT2(block, R64(RTREG), IREG(0)); // dsext2 <rtreg>,i0 |
| 2077 | 2149 | if (!in_delay_slot) |
| r2762 | r2763 | |
| 2080 | 2152 | |
| 2081 | 2153 | case 0x23: /* LW - MIPS I */ |
| 2082 | 2154 | UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL)); // add i0,<rsreg>,SIMMVAL |
| 2083 | | UML_CALLH(block, mips3.read32[mips3.cstate->mode >> 1]); // callh read32 |
| 2155 | UML_CALLH(block, mips3->impstate->read32[mips3->impstate->mode >> 1]); // callh read32 |
| 2084 | 2156 | if (RTREG != 0) |
| 2085 | 2157 | UML_DSEXT4(block, R64(RTREG), IREG(0)); // dsext4 <rtreg>,i0 |
| 2086 | 2158 | if (!in_delay_slot) |
| r2762 | r2763 | |
| 2089 | 2161 | |
| 2090 | 2162 | case 0x24: /* LBU - MIPS I */ |
| 2091 | 2163 | UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL)); // add i0,<rsreg>,SIMMVAL |
| 2092 | | UML_CALLH(block, mips3.read8[mips3.cstate->mode >> 1]); // callh read8 |
| 2164 | UML_CALLH(block, mips3->impstate->read8[mips3->impstate->mode >> 1]); // callh read8 |
| 2093 | 2165 | if (RTREG != 0) |
| 2094 | 2166 | UML_DZEXT1(block, R64(RTREG), IREG(0)); // dzext1 <rtreg>,i0 |
| 2095 | 2167 | if (!in_delay_slot) |
| r2762 | r2763 | |
| 2098 | 2170 | |
| 2099 | 2171 | case 0x25: /* LHU - MIPS I */ |
| 2100 | 2172 | UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL)); // add i0,<rsreg>,SIMMVAL |
| 2101 | | UML_CALLH(block, mips3.read16[mips3.cstate->mode >> 1]); // callh read16 |
| 2173 | UML_CALLH(block, mips3->impstate->read16[mips3->impstate->mode >> 1]); // callh read16 |
| 2102 | 2174 | if (RTREG != 0) |
| 2103 | 2175 | UML_DZEXT2(block, R64(RTREG), IREG(0)); // dzext2 <rtreg>,i0 |
| 2104 | 2176 | if (!in_delay_slot) |
| r2762 | r2763 | |
| 2107 | 2179 | |
| 2108 | 2180 | case 0x27: /* LWU - MIPS III */ |
| 2109 | 2181 | UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL)); // add i0,<rsreg>,SIMMVAL |
| 2110 | | UML_CALLH(block, mips3.read32[mips3.cstate->mode >> 1]); // callh read32 |
| 2182 | UML_CALLH(block, mips3->impstate->read32[mips3->impstate->mode >> 1]); // callh read32 |
| 2111 | 2183 | if (RTREG != 0) |
| 2112 | 2184 | UML_DZEXT4(block, R64(RTREG), IREG(0)); // dzext4 <rtreg>,i0 |
| 2113 | 2185 | if (!in_delay_slot) |
| r2762 | r2763 | |
| 2116 | 2188 | |
| 2117 | 2189 | case 0x37: /* LD - MIPS III */ |
| 2118 | 2190 | UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL)); // add i0,<rsreg>,SIMMVAL |
| 2119 | | UML_CALLH(block, mips3.read64[mips3.cstate->mode >> 1]); // callh read64 |
| 2191 | UML_CALLH(block, mips3->impstate->read64[mips3->impstate->mode >> 1]); // callh read64 |
| 2120 | 2192 | if (RTREG != 0) |
| 2121 | 2193 | UML_DMOV(block, R64(RTREG), IREG(0)); // dmov <rtreg>,i0 |
| 2122 | 2194 | if (!in_delay_slot) |
| r2762 | r2763 | |
| 2126 | 2198 | case 0x22: /* LWL - MIPS I */ |
| 2127 | 2199 | UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL)); // add i0,<rsreg>,SIMMVAL |
| 2128 | 2200 | UML_SHL(block, IREG(1), IREG(0), IMM(3)); // shl i1,i0,3 |
| 2129 | | if (!mips3.core->bigendian) |
| 2201 | if (!mips3->bigendian) |
| 2130 | 2202 | UML_XOR(block, IREG(1), IREG(1), IMM(0x18)); // xor i1,i1,0x18 |
| 2131 | 2203 | UML_SHR(block, IREG(2), IMM(~0), IREG(1)); // shr i2,~0,i1 |
| 2132 | | UML_CALLH(block, mips3.read32mask[mips3.cstate->mode >> 1]); // callh read32mask |
| 2204 | UML_CALLH(block, mips3->impstate->read32mask[mips3->impstate->mode >> 1]); |
| 2205 | // callh read32mask |
| 2133 | 2206 | if (RTREG != 0) |
| 2134 | 2207 | { |
| 2135 | 2208 | UML_SHL(block, IREG(2), IMM(~0), IREG(1)); // shl i2,~0,i1 |
| r2762 | r2763 | |
| 2144 | 2217 | case 0x26: /* LWR - MIPS I */ |
| 2145 | 2218 | UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL)); // add i0,<rsreg>,SIMMVAL |
| 2146 | 2219 | UML_SHL(block, IREG(1), IREG(0), IMM(3)); // shl i1,i0,3 |
| 2147 | | if (mips3.core->bigendian) |
| 2220 | if (mips3->bigendian) |
| 2148 | 2221 | UML_XOR(block, IREG(1), IREG(1), IMM(0x18)); // xor i1,i1,0x18 |
| 2149 | 2222 | UML_SHL(block, IREG(2), IMM(~0), IREG(1)); // shl i2,~0,i1 |
| 2150 | | UML_CALLH(block, mips3.read32mask[mips3.cstate->mode >> 1]); // callh read32mask |
| 2223 | UML_CALLH(block, mips3->impstate->read32mask[mips3->impstate->mode >> 1]); |
| 2224 | // callh read32mask |
| 2151 | 2225 | if (RTREG != 0) |
| 2152 | 2226 | { |
| 2153 | 2227 | UML_SHR(block, IREG(2), IMM(~0), IREG(1)); // shr i2,~0,i1 |
| r2762 | r2763 | |
| 2163 | 2237 | case 0x1a: /* LDL - MIPS III */ |
| 2164 | 2238 | UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL)); // add i0,<rsreg>,SIMMVAL |
| 2165 | 2239 | UML_SHL(block, IREG(1), IREG(0), IMM(3)); // shl i1,i0,3 |
| 2166 | | if (!mips3.core->bigendian) |
| 2240 | if (!mips3->bigendian) |
| 2167 | 2241 | UML_XOR(block, IREG(1), IREG(1), IMM(0x38)); // xor i1,i1,0x38 |
| 2168 | 2242 | UML_DSHR(block, IREG(2), IMM((UINT64)~0), IREG(1)); // dshr i2,~0,i1 |
| 2169 | | UML_CALLH(block, mips3.read64mask[mips3.cstate->mode >> 1]); // callh read64mask |
| 2243 | UML_CALLH(block, mips3->impstate->read64mask[mips3->impstate->mode >> 1]); |
| 2244 | // callh read64mask |
| 2170 | 2245 | if (RTREG != 0) |
| 2171 | 2246 | { |
| 2172 | 2247 | UML_DSHL(block, IREG(2), IMM((UINT64)~0), IREG(1)); // dshl i2,~0,i1 |
| r2762 | r2763 | |
| 2179 | 2254 | case 0x1b: /* LDR - MIPS III */ |
| 2180 | 2255 | UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL)); // add i0,<rsreg>,SIMMVAL |
| 2181 | 2256 | UML_SHL(block, IREG(1), IREG(0), IMM(3)); // shl i1,i0,3 |
| 2182 | | if (mips3.core->bigendian) |
| 2257 | if (mips3->bigendian) |
| 2183 | 2258 | UML_XOR(block, IREG(1), IREG(1), IMM(0x38)); // xor i1,i1,0x38 |
| 2184 | 2259 | UML_DSHL(block, IREG(2), IMM((UINT64)~0), IREG(1)); // dshl i2,~0,i1 |
| 2185 | | UML_CALLH(block, mips3.read64mask[mips3.cstate->mode >> 1]); // callh read64mask |
| 2260 | UML_CALLH(block, mips3->impstate->read64mask[mips3->impstate->mode >> 1]); |
| 2261 | // callh read64mask |
| 2186 | 2262 | if (RTREG != 0) |
| 2187 | 2263 | { |
| 2188 | 2264 | UML_DSHR(block, IREG(2), IMM((UINT64)~0), IREG(1)); // dshr i2,~0,i1 |
| r2762 | r2763 | |
| 2195 | 2271 | |
| 2196 | 2272 | case 0x31: /* LWC1 - MIPS I */ |
| 2197 | 2273 | UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL)); // add i0,<rsreg>,SIMMVAL |
| 2198 | | UML_CALLH(block, mips3.read32[mips3.cstate->mode >> 1]); // callh read32 |
| 2274 | UML_CALLH(block, mips3->impstate->read32[mips3->impstate->mode >> 1]); // callh read32 |
| 2199 | 2275 | UML_MOV(block, FPR32(RTREG), IREG(0)); // mov <cpr1_rt>,i0 |
| 2200 | 2276 | if (!in_delay_slot) |
| 2201 | 2277 | generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE); |
| r2762 | r2763 | |
| 2203 | 2279 | |
| 2204 | 2280 | case 0x35: /* LDC1 - MIPS III */ |
| 2205 | 2281 | UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL)); // add i0,<rsreg>,SIMMVAL |
| 2206 | | UML_CALLH(block, mips3.read64[mips3.cstate->mode >> 1]); // callh read64 |
| 2282 | UML_CALLH(block, mips3->impstate->read64[mips3->impstate->mode >> 1]); // callh read64 |
| 2207 | 2283 | UML_DMOV(block, FPR64(RTREG), IREG(0)); // dmov <cpr1_rt>,i0 |
| 2208 | 2284 | if (!in_delay_slot) |
| 2209 | 2285 | generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE); |
| r2762 | r2763 | |
| 2211 | 2287 | |
| 2212 | 2288 | case 0x32: /* LWC2 - MIPS I */ |
| 2213 | 2289 | UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL)); // add i0,<rsreg>,SIMMVAL |
| 2214 | | UML_CALLH(block, mips3.read32[mips3.cstate->mode >> 1]); // callh read32 |
| 2290 | UML_CALLH(block, mips3->impstate->read32[mips3->impstate->mode >> 1]); // callh read32 |
| 2215 | 2291 | UML_DZEXT4(block, CPR264(RTREG), IREG(0)); // dzext4 <cpr2_rt>,i0 |
| 2216 | 2292 | if (!in_delay_slot) |
| 2217 | 2293 | generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE); |
| r2762 | r2763 | |
| 2219 | 2295 | |
| 2220 | 2296 | case 0x36: /* LDC2 - MIPS II */ |
| 2221 | 2297 | UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL)); // add i0,<rsreg>,SIMMVAL |
| 2222 | | UML_CALLH(block, mips3.read64[mips3.cstate->mode >> 1]); // callh read64 |
| 2298 | UML_CALLH(block, mips3->impstate->read64[mips3->impstate->mode >> 1]); // callh read64 |
| 2223 | 2299 | UML_DMOV(block, CPR264(RTREG), IREG(0)); // dmov <cpr2_rt>,i0 |
| 2224 | 2300 | if (!in_delay_slot) |
| 2225 | 2301 | generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE); |
| r2762 | r2763 | |
| 2231 | 2307 | case 0x28: /* SB - MIPS I */ |
| 2232 | 2308 | UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL)); // add i0,<rsreg>,SIMMVAL |
| 2233 | 2309 | UML_MOV(block, IREG(1), R32(RTREG)); // mov i1,<rtreg> |
| 2234 | | UML_CALLH(block, mips3.write8[mips3.cstate->mode >> 1]); // callh write8 |
| 2310 | UML_CALLH(block, mips3->impstate->write8[mips3->impstate->mode >> 1]); // callh write8 |
| 2235 | 2311 | if (!in_delay_slot) |
| 2236 | 2312 | generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE); |
| 2237 | 2313 | return TRUE; |
| r2762 | r2763 | |
| 2239 | 2315 | case 0x29: /* SH - MIPS I */ |
| 2240 | 2316 | UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL)); // add i0,<rsreg>,SIMMVAL |
| 2241 | 2317 | UML_MOV(block, IREG(1), R32(RTREG)); // mov i1,<rtreg> |
| 2242 | | UML_CALLH(block, mips3.write16[mips3.cstate->mode >> 1]); // callh write16 |
| 2318 | UML_CALLH(block, mips3->impstate->write16[mips3->impstate->mode >> 1]); // callh write16 |
| 2243 | 2319 | if (!in_delay_slot) |
| 2244 | 2320 | generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE); |
| 2245 | 2321 | return TRUE; |
| r2762 | r2763 | |
| 2247 | 2323 | case 0x2b: /* SW - MIPS I */ |
| 2248 | 2324 | UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL)); // add i0,<rsreg>,SIMMVAL |
| 2249 | 2325 | UML_MOV(block, IREG(1), R32(RTREG)); // mov i1,<rtreg> |
| 2250 | | UML_CALLH(block, mips3.write32[mips3.cstate->mode >> 1]); // callh write32 |
| 2326 | UML_CALLH(block, mips3->impstate->write32[mips3->impstate->mode >> 1]); // callh write32 |
| 2251 | 2327 | if (!in_delay_slot) |
| 2252 | 2328 | generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE); |
| 2253 | 2329 | return TRUE; |
| r2762 | r2763 | |
| 2255 | 2331 | case 0x3f: /* SD - MIPS III */ |
| 2256 | 2332 | UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL)); // add i0,<rsreg>,SIMMVAL |
| 2257 | 2333 | UML_DMOV(block, IREG(1), R64(RTREG)); // dmov i1,<rtreg> |
| 2258 | | UML_CALLH(block, mips3.write64[mips3.cstate->mode >> 1]); // callh write64 |
| 2334 | UML_CALLH(block, mips3->impstate->write64[mips3->impstate->mode >> 1]); // callh write64 |
| 2259 | 2335 | if (!in_delay_slot) |
| 2260 | 2336 | generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE); |
| 2261 | 2337 | return TRUE; |
| r2762 | r2763 | |
| 2264 | 2340 | UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL)); // add i0,<rsreg>,SIMMVAL |
| 2265 | 2341 | UML_SHL(block, IREG(3), IREG(0), IMM(3)); // shl i3,i0,3 |
| 2266 | 2342 | UML_MOV(block, IREG(1), R32(RTREG)); // mov i1,<rtreg> |
| 2267 | | if (!mips3.core->bigendian) |
| 2343 | if (!mips3->bigendian) |
| 2268 | 2344 | UML_XOR(block, IREG(3), IREG(3), IMM(0x18)); // xor i3,i3,0x18 |
| 2269 | 2345 | UML_SHR(block, IREG(2), IMM(~0), IREG(3)); // shr i2,~0,i3 |
| 2270 | 2346 | UML_SHR(block, IREG(1), IREG(1), IREG(3)); // shr i1,i1,i3 |
| 2271 | | UML_CALLH(block, mips3.write32mask[mips3.cstate->mode >> 1]); // callh write32mask |
| 2347 | UML_CALLH(block, mips3->impstate->write32mask[mips3->impstate->mode >> 1]); |
| 2348 | // callh write32mask |
| 2272 | 2349 | if (!in_delay_slot) |
| 2273 | 2350 | generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE); |
| 2274 | 2351 | return TRUE; |
| r2762 | r2763 | |
| 2277 | 2354 | UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL)); // add i0,<rsreg>,SIMMVAL |
| 2278 | 2355 | UML_SHL(block, IREG(3), IREG(0), IMM(3)); // shl i3,i0,3 |
| 2279 | 2356 | UML_MOV(block, IREG(1), R32(RTREG)); // mov i1,<rtreg> |
| 2280 | | if (mips3.core->bigendian) |
| 2357 | if (mips3->bigendian) |
| 2281 | 2358 | UML_XOR(block, IREG(3), IREG(3), IMM(0x18)); // xor i3,i3,0x18 |
| 2282 | 2359 | UML_SHL(block, IREG(2), IMM(~0), IREG(3)); // shl i2,~0,i3 |
| 2283 | 2360 | UML_SHL(block, IREG(1), IREG(1), IREG(3)); // shl i1,i1,i3 |
| 2284 | | UML_CALLH(block, mips3.write32mask[mips3.cstate->mode >> 1]); // callh write32mask |
| 2361 | UML_CALLH(block, mips3->impstate->write32mask[mips3->impstate->mode >> 1]); |
| 2362 | // callh write32mask |
| 2285 | 2363 | if (!in_delay_slot) |
| 2286 | 2364 | generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE); |
| 2287 | 2365 | return TRUE; |
| r2762 | r2763 | |
| 2290 | 2368 | UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL)); // add i0,<rsreg>,SIMMVAL |
| 2291 | 2369 | UML_SHL(block, IREG(3), IREG(0), IMM(3)); // shl i3,i0,3 |
| 2292 | 2370 | UML_DMOV(block, IREG(1), R64(RTREG)); // dmov i1,<rtreg> |
| 2293 | | if (!mips3.core->bigendian) |
| 2371 | if (!mips3->bigendian) |
| 2294 | 2372 | UML_XOR(block, IREG(3), IREG(3), IMM(0x38)); // xor i3,i3,0x38 |
| 2295 | 2373 | UML_DSHR(block, IREG(2), IMM((UINT64)~0), IREG(3)); // dshr i2,~0,i3 |
| 2296 | 2374 | UML_DSHR(block, IREG(1), IREG(1), IREG(3)); // dshr i1,i1,i3 |
| 2297 | | UML_CALLH(block, mips3.write64mask[mips3.cstate->mode >> 1]); // callh write64mask |
| 2375 | UML_CALLH(block, mips3->impstate->write64mask[mips3->impstate->mode >> 1]); |
| 2376 | // callh write64mask |
| 2298 | 2377 | if (!in_delay_slot) |
| 2299 | 2378 | generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE); |
| 2300 | 2379 | return TRUE; |
| r2762 | r2763 | |
| 2303 | 2382 | UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL)); // add i0,<rsreg>,SIMMVAL |
| 2304 | 2383 | UML_SHL(block, IREG(3), IREG(0), IMM(3)); // shl i3,i0,3 |
| 2305 | 2384 | UML_DMOV(block, IREG(1), R64(RTREG)); // dmov i1,<rtreg> |
| 2306 | | if (mips3.core->bigendian) |
| 2385 | if (mips3->bigendian) |
| 2307 | 2386 | UML_XOR(block, IREG(3), IREG(3), IMM(0x38)); // xor i3,i3,0x38 |
| 2308 | 2387 | UML_DSHL(block, IREG(2), IMM((UINT64)~0), IREG(3)); // dshl i2,~0,i3 |
| 2309 | 2388 | UML_DSHL(block, IREG(1), IREG(1), IREG(3)); // dshl i1,i1,i3 |
| 2310 | | UML_CALLH(block, mips3.write64mask[mips3.cstate->mode >> 1]); // callh write64mask |
| 2389 | UML_CALLH(block, mips3->impstate->write64mask[mips3->impstate->mode >> 1]); |
| 2390 | // callh write64mask |
| 2311 | 2391 | if (!in_delay_slot) |
| 2312 | 2392 | generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE); |
| 2313 | 2393 | return TRUE; |
| r2762 | r2763 | |
| 2315 | 2395 | case 0x39: /* SWC1 - MIPS I */ |
| 2316 | 2396 | UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL)); // add i0,<rsreg>,SIMMVAL |
| 2317 | 2397 | UML_MOV(block, IREG(1), FPR32(RTREG)); // mov i1,<cpr1_rt> |
| 2318 | | UML_CALLH(block, mips3.write32[mips3.cstate->mode >> 1]); // callh write32 |
| 2398 | UML_CALLH(block, mips3->impstate->write32[mips3->impstate->mode >> 1]); // callh write32 |
| 2319 | 2399 | if (!in_delay_slot) |
| 2320 | 2400 | generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE); |
| 2321 | 2401 | return TRUE; |
| r2762 | r2763 | |
| 2323 | 2403 | case 0x3d: /* SDC1 - MIPS III */ |
| 2324 | 2404 | UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL)); // add i0,<rsreg>,SIMMVAL |
| 2325 | 2405 | UML_DMOV(block, IREG(1), FPR64(RTREG)); // dmov i1,<cpr1_rt> |
| 2326 | | UML_CALLH(block, mips3.write64[mips3.cstate->mode >> 1]); // callh write64 |
| 2406 | UML_CALLH(block, mips3->impstate->write64[mips3->impstate->mode >> 1]); // callh write64 |
| 2327 | 2407 | if (!in_delay_slot) |
| 2328 | 2408 | generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE); |
| 2329 | 2409 | return TRUE; |
| r2762 | r2763 | |
| 2331 | 2411 | case 0x3a: /* SWC2 - MIPS I */ |
| 2332 | 2412 | UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL)); // add i0,<rsreg>,SIMMVAL |
| 2333 | 2413 | UML_MOV(block, IREG(1), CPR232(RTREG)); // mov i1,<cpr2_rt> |
| 2334 | | UML_CALLH(block, mips3.write32[mips3.cstate->mode >> 1]); // callh write32 |
| 2414 | UML_CALLH(block, mips3->impstate->write32[mips3->impstate->mode >> 1]); // callh write32 |
| 2335 | 2415 | if (!in_delay_slot) |
| 2336 | 2416 | generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE); |
| 2337 | 2417 | return TRUE; |
| r2762 | r2763 | |
| 2339 | 2419 | case 0x3e: /* SDC2 - MIPS II */ |
| 2340 | 2420 | UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL)); // add i0,<rsreg>,SIMMVAL |
| 2341 | 2421 | UML_DMOV(block, IREG(1), CPR264(RTREG)); // dmov i1,<cpr2_rt> |
| 2342 | | UML_CALLH(block, mips3.write64[mips3.cstate->mode >> 1]); // callh write64 |
| 2422 | UML_CALLH(block, mips3->impstate->write64[mips3->impstate->mode >> 1]); // callh write64 |
| 2343 | 2423 | if (!in_delay_slot) |
| 2344 | 2424 | generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE); |
| 2345 | 2425 | return TRUE; |
| r2762 | r2763 | |
| 2364 | 2444 | return generate_cop1x(block, compiler, desc); |
| 2365 | 2445 | |
| 2366 | 2446 | case 0x12: /* COP2 - MIPS I */ |
| 2367 | | UML_EXH(block, mips3.exception[EXCEPTION_INVALIDOP], IMM(0)); // exh invalidop,0 |
| 2447 | UML_EXH(block, mips3->impstate->exception[EXCEPTION_INVALIDOP], IMM(0));// exh invalidop,0 |
| 2368 | 2448 | return TRUE; |
| 2369 | 2449 | |
| 2370 | 2450 | |
| r2762 | r2763 | |
| 2492 | 2572 | /* ----- basic arithmetic ----- */ |
| 2493 | 2573 | |
| 2494 | 2574 | case 0x20: /* ADD - MIPS I */ |
| 2495 | | if (mips3.drcoptions & MIPS3DRC_CHECK_OVERFLOWS) |
| 2575 | if (mips3->impstate->drcoptions & MIPS3DRC_CHECK_OVERFLOWS) |
| 2496 | 2576 | { |
| 2497 | 2577 | UML_ADDf(block, IREG(0), R32(RSREG), R32(RTREG), FLAGS_V); // add i0,<rsreg>,<rtreg>,V |
| 2498 | | UML_EXHc(block, IF_V, mips3.exception[EXCEPTION_OVERFLOW], IMM(0)); // exh overflow,0,V |
| 2578 | UML_EXHc(block, IF_V, mips3->impstate->exception[EXCEPTION_OVERFLOW], IMM(0)); |
| 2579 | // exh overflow,0,V |
| 2499 | 2580 | if (RDREG != 0) |
| 2500 | 2581 | UML_DSEXT4(block, R64(RDREG), IREG(0)); // dsext4 <rdreg>,i0 |
| 2501 | 2582 | } |
| r2762 | r2763 | |
| 2515 | 2596 | return TRUE; |
| 2516 | 2597 | |
| 2517 | 2598 | case 0x2c: /* DADD - MIPS III */ |
| 2518 | | if (mips3.drcoptions & MIPS3DRC_CHECK_OVERFLOWS) |
| 2599 | if (mips3->impstate->drcoptions & MIPS3DRC_CHECK_OVERFLOWS) |
| 2519 | 2600 | { |
| 2520 | 2601 | UML_DADDf(block, IREG(0), R64(RSREG), R64(RTREG), FLAGS_V); // dadd i0,<rsreg>,<rtreg>,V |
| 2521 | | UML_EXHc(block, IF_V, mips3.exception[EXCEPTION_OVERFLOW], IMM(0)); // exh overflow,0,V |
| 2602 | UML_EXHc(block, IF_V, mips3->impstate->exception[EXCEPTION_OVERFLOW], IMM(0)); |
| 2603 | // exh overflow,0,V |
| 2522 | 2604 | if (RDREG != 0) |
| 2523 | 2605 | UML_DMOV(block, R64(RDREG), IREG(0)); // dmov <rdreg>,i0 |
| 2524 | 2606 | } |
| r2762 | r2763 | |
| 2532 | 2614 | return TRUE; |
| 2533 | 2615 | |
| 2534 | 2616 | case 0x22: /* SUB - MIPS I */ |
| 2535 | | if (mips3.drcoptions & MIPS3DRC_CHECK_OVERFLOWS) |
| 2617 | if (mips3->impstate->drcoptions & MIPS3DRC_CHECK_OVERFLOWS) |
| 2536 | 2618 | { |
| 2537 | 2619 | UML_SUBf(block, IREG(0), R32(RSREG), R32(RTREG), FLAGS_V); // sub i0,<rsreg>,<rtreg>,V |
| 2538 | | UML_EXHc(block, IF_V, mips3.exception[EXCEPTION_OVERFLOW], IMM(0)); // exh overflow,0,V |
| 2620 | UML_EXHc(block, IF_V, mips3->impstate->exception[EXCEPTION_OVERFLOW], IMM(0)); |
| 2621 | // exh overflow,0,V |
| 2539 | 2622 | if (RDREG != 0) |
| 2540 | 2623 | UML_DSEXT4(block, R64(RDREG), IREG(0)); // dsext4 <rdreg>,i0 |
| 2541 | 2624 | } |
| r2762 | r2763 | |
| 2555 | 2638 | return TRUE; |
| 2556 | 2639 | |
| 2557 | 2640 | case 0x2e: /* DSUB - MIPS III */ |
| 2558 | | if (mips3.drcoptions & MIPS3DRC_CHECK_OVERFLOWS) |
| 2641 | if (mips3->impstate->drcoptions & MIPS3DRC_CHECK_OVERFLOWS) |
| 2559 | 2642 | { |
| 2560 | 2643 | UML_DSUBf(block, IREG(0), R64(RSREG), R64(RTREG), FLAGS_V); // dsub i0,<rsreg>,<rtreg>,V |
| 2561 | | UML_EXHc(block, IF_V, mips3.exception[EXCEPTION_OVERFLOW], IMM(0)); // exh overflow,0,V |
| 2644 | UML_EXHc(block, IF_V, mips3->impstate->exception[EXCEPTION_OVERFLOW], IMM(0)); |
| 2645 | // exh overflow,0,V |
| 2562 | 2646 | if (RDREG != 0) |
| 2563 | 2647 | UML_DMOV(block, R64(RDREG), IREG(0)); // dmov <rdreg>,i0 |
| 2564 | 2648 | } |
| r2762 | r2763 | |
| 2644 | 2728 | if (RDREG != 0) |
| 2645 | 2729 | { |
| 2646 | 2730 | UML_DCMP(block, R64(RSREG), R64(RTREG)); // dcmp <rsreg>,<rtreg> |
| 2647 | | UML_DFLAGS(block, R64(RDREG), (UINT64)~0, mips3.cstate->slt_table); // dflags <rdreg>,~0,slt_table |
| 2731 | UML_DFLAGS(block, R64(RDREG), (UINT64)~0, mips3->impstate->slt_table);// dflags <rdreg>,~0,slt_table |
| 2648 | 2732 | } |
| 2649 | 2733 | return TRUE; |
| 2650 | 2734 | |
| r2762 | r2763 | |
| 2652 | 2736 | if (RDREG != 0) |
| 2653 | 2737 | { |
| 2654 | 2738 | UML_DCMP(block, R64(RSREG), R64(RTREG)); // dcmp <rsreg>,<rtreg> |
| 2655 | | UML_DFLAGS(block, R64(RDREG), (UINT64)~0, mips3.cstate->sltu_table);// dflags <rdreg>,~0,sltu_table |
| 2739 | UML_DFLAGS(block, R64(RDREG), (UINT64)~0, mips3->impstate->sltu_table);// dflags <rdreg>,~0,sltu_table |
| 2656 | 2740 | } |
| 2657 | 2741 | return TRUE; |
| 2658 | 2742 | |
| r2762 | r2763 | |
| 2661 | 2745 | |
| 2662 | 2746 | case 0x30: /* TGE - MIPS II */ |
| 2663 | 2747 | UML_DCMP(block, R64(RSREG), R64(RTREG)); // dcmp <rsreg>,<rtreg> |
| 2664 | | UML_EXHc(block, IF_GE, mips3.exception[EXCEPTION_TRAP], IMM(0)); // exh trap,0,GE |
| 2748 | UML_EXHc(block, IF_GE, mips3->impstate->exception[EXCEPTION_TRAP], IMM(0));// exh trap,0,GE |
| 2665 | 2749 | return TRUE; |
| 2666 | 2750 | |
| 2667 | 2751 | case 0x31: /* TGEU - MIPS II */ |
| 2668 | 2752 | UML_DCMP(block, R64(RSREG), R64(RTREG)); // dcmp <rsreg>,<rtreg> |
| 2669 | | UML_EXHc(block, IF_AE, mips3.exception[EXCEPTION_TRAP], IMM(0)); // exh trap,0,AE |
| 2753 | UML_EXHc(block, IF_AE, mips3->impstate->exception[EXCEPTION_TRAP], IMM(0));// exh trap,0,AE |
| 2670 | 2754 | return TRUE; |
| 2671 | 2755 | |
| 2672 | 2756 | case 0x32: /* TLT - MIPS II */ |
| 2673 | 2757 | UML_DCMP(block, R64(RSREG), R64(RTREG)); // dcmp <rsreg>,<rtreg> |
| 2674 | | UML_EXHc(block, IF_L, mips3.exception[EXCEPTION_TRAP], IMM(0)); // exh trap,0,LT |
| 2758 | UML_EXHc(block, IF_L, mips3->impstate->exception[EXCEPTION_TRAP], IMM(0));// exh trap,0,LT |
| 2675 | 2759 | return TRUE; |
| 2676 | 2760 | |
| 2677 | 2761 | case 0x33: /* TLTU - MIPS II */ |
| 2678 | 2762 | UML_DCMP(block, R64(RSREG), R64(RTREG)); // dcmp <rsreg>,<rtreg> |
| 2679 | | UML_EXHc(block, IF_B, mips3.exception[EXCEPTION_TRAP], IMM(0)); // exh trap,0,B |
| 2763 | UML_EXHc(block, IF_B, mips3->impstate->exception[EXCEPTION_TRAP], IMM(0));// exh trap,0,B |
| 2680 | 2764 | return TRUE; |
| 2681 | 2765 | |
| 2682 | 2766 | case 0x34: /* TEQ - MIPS II */ |
| 2683 | 2767 | UML_DCMP(block, R64(RSREG), R64(RTREG)); // dcmp <rsreg>,<rtreg> |
| 2684 | | UML_EXHc(block, IF_E, mips3.exception[EXCEPTION_TRAP], IMM(0)); // exh trap,0,E |
| 2768 | UML_EXHc(block, IF_E, mips3->impstate->exception[EXCEPTION_TRAP], IMM(0));// exh trap,0,E |
| 2685 | 2769 | return TRUE; |
| 2686 | 2770 | |
| 2687 | 2771 | case 0x36: /* TNE - MIPS II */ |
| 2688 | 2772 | UML_DCMP(block, R64(RSREG), R64(RTREG)); // dcmp <rsreg>,<rtreg> |
| 2689 | | UML_EXHc(block, IF_NE, mips3.exception[EXCEPTION_TRAP], IMM(0)); // exh trap,0,NE |
| 2773 | UML_EXHc(block, IF_NE, mips3->impstate->exception[EXCEPTION_TRAP], IMM(0));// exh trap,0,NE |
| 2690 | 2774 | return TRUE; |
| 2691 | 2775 | |
| 2692 | 2776 | |
| r2762 | r2763 | |
| 2732 | 2816 | /* ----- system calls ----- */ |
| 2733 | 2817 | |
| 2734 | 2818 | case 0x0c: /* SYSCALL - MIPS I */ |
| 2735 | | UML_EXH(block, mips3.exception[EXCEPTION_SYSCALL], IMM(0)); // exh syscall,0 |
| 2819 | UML_EXH(block, mips3->impstate->exception[EXCEPTION_SYSCALL], IMM(0)); // exh syscall,0 |
| 2736 | 2820 | return TRUE; |
| 2737 | 2821 | |
| 2738 | 2822 | case 0x0d: /* BREAK - MIPS I */ |
| 2739 | | UML_EXH(block, mips3.exception[EXCEPTION_BREAK], IMM(0)); // exh break,0 |
| 2823 | UML_EXH(block, mips3->impstate->exception[EXCEPTION_BREAK], IMM(0)); // exh break,0 |
| 2740 | 2824 | return TRUE; |
| 2741 | 2825 | |
| 2742 | 2826 | |
| r2762 | r2763 | |
| 2816 | 2900 | |
| 2817 | 2901 | case 0x08: /* TGEI */ |
| 2818 | 2902 | UML_DCMP(block, R64(RSREG), IMM(SIMMVAL)); // dcmp <rsreg>,SIMMVAL |
| 2819 | | UML_EXHc(block, IF_GE, mips3.exception[EXCEPTION_TRAP], IMM(0)); // exh trap,0,GE |
| 2903 | UML_EXHc(block, IF_GE, mips3->impstate->exception[EXCEPTION_TRAP], IMM(0));// exh trap,0,GE |
| 2820 | 2904 | return TRUE; |
| 2821 | 2905 | |
| 2822 | 2906 | case 0x09: /* TGEIU */ |
| 2823 | 2907 | UML_DCMP(block, R64(RSREG), IMM(SIMMVAL)); // dcmp <rsreg>,SIMMVAL |
| 2824 | | UML_EXHc(block, IF_AE, mips3.exception[EXCEPTION_TRAP], IMM(0)); // exh trap,0,AE |
| 2908 | UML_EXHc(block, IF_AE, mips3->impstate->exception[EXCEPTION_TRAP], IMM(0));// exh trap,0,AE |
| 2825 | 2909 | return TRUE; |
| 2826 | 2910 | |
| 2827 | 2911 | case 0x0a: /* TLTI */ |
| 2828 | 2912 | UML_DCMP(block, R64(RSREG), IMM(SIMMVAL)); // dcmp <rsreg>,SIMMVAL |
| 2829 | | UML_EXHc(block, IF_L, mips3.exception[EXCEPTION_TRAP], IMM(0)); // exh trap,0,L |
| 2913 | UML_EXHc(block, IF_L, mips3->impstate->exception[EXCEPTION_TRAP], IMM(0));// exh trap,0,L |
| 2830 | 2914 | return TRUE; |
| 2831 | 2915 | |
| 2832 | 2916 | case 0x0b: /* TLTIU */ |
| 2833 | 2917 | UML_DCMP(block, R64(RSREG), IMM(SIMMVAL)); // dcmp <rsreg>,SIMMVAL |
| 2834 | | UML_EXHc(block, IF_B, mips3.exception[EXCEPTION_TRAP], IMM(0)); // exh trap,0,B |
| 2918 | UML_EXHc(block, IF_B, mips3->impstate->exception[EXCEPTION_TRAP], IMM(0));// exh trap,0,B |
| 2835 | 2919 | return TRUE; |
| 2836 | 2920 | |
| 2837 | 2921 | case 0x0c: /* TEQI */ |
| 2838 | 2922 | UML_DCMP(block, R64(RSREG), IMM(SIMMVAL)); // dcmp <rsreg>,SIMMVAL |
| 2839 | | UML_EXHc(block, IF_E, mips3.exception[EXCEPTION_TRAP], IMM(0)); // exh trap,0,E |
| 2923 | UML_EXHc(block, IF_E, mips3->impstate->exception[EXCEPTION_TRAP], IMM(0));// exh trap,0,E |
| 2840 | 2924 | return TRUE; |
| 2841 | 2925 | |
| 2842 | 2926 | case 0x0e: /* TNEI */ |
| 2843 | 2927 | UML_DCMP(block, R64(RSREG), IMM(SIMMVAL)); // dcmp <rsreg>,SIMMVAL |
| 2844 | | UML_EXHc(block, IF_NE, mips3.exception[EXCEPTION_TRAP], IMM(0)); // exh trap,0,NE |
| 2928 | UML_EXHc(block, IF_NE, mips3->impstate->exception[EXCEPTION_TRAP], IMM(0));// exh trap,0,NE |
| 2845 | 2929 | return TRUE; |
| 2846 | 2930 | } |
| 2847 | 2931 | return FALSE; |
| r2762 | r2763 | |
| 2859 | 2943 | UINT8 opswitch = op & 0x1f; |
| 2860 | 2944 | |
| 2861 | 2945 | /* only enabled on IDT processors */ |
| 2862 | | if (mips3.core->flavor != MIPS3_TYPE_R4650) |
| 2946 | if (mips3->flavor != MIPS3_TYPE_R4650) |
| 2863 | 2947 | return FALSE; |
| 2864 | 2948 | |
| 2865 | 2949 | switch (opswitch) |
| r2762 | r2763 | |
| 2924 | 3008 | generate_update_mode(block); |
| 2925 | 3009 | UML_XOR(block, IREG(0), IREG(0), IREG(1)); // xor i0,i0,i1 |
| 2926 | 3010 | UML_TEST(block, IREG(0), IMM(0x8000)); // test i0,0x8000 |
| 2927 | | UML_CALLCc(block, IF_NZ, mips3com_update_cycle_counting, mips3.core); // callc mips3com_update_cycle_counting,mips.core,NZ |
| 3011 | UML_CALLCc(block, IF_NZ, mips3com_update_cycle_counting, mips3); // callc mips3com_update_cycle_counting,mips.core,NZ |
| 2928 | 3012 | compiler->checkints = TRUE; |
| 2929 | 3013 | if (!in_delay_slot) |
| 2930 | 3014 | generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE); |
| r2762 | r2763 | |
| 2933 | 3017 | case COP0_Count: |
| 2934 | 3018 | generate_update_cycles(block, compiler, IMM(desc->pc), !in_delay_slot); // <subtract cycles> |
| 2935 | 3019 | UML_MOV(block, CPR032(COP0_Count), IREG(0)); // mov [Count],i0 |
| 2936 | | UML_CALLC(block, cfunc_get_cycles, &mips3.cstate->numcycles); // callc cfunc_get_cycles,&mips3.numcycles |
| 3020 | UML_CALLC(block, cfunc_get_cycles, &mips3->impstate->numcycles); // callc cfunc_get_cycles,&mips3->impstate->numcycles |
| 2937 | 3021 | UML_DZEXT4(block, IREG(0), IREG(0)); // dzext4 i0,i0 |
| 2938 | 3022 | UML_DADD(block, IREG(0), IREG(0), IREG(0)); // dadd i0,i0,i0 |
| 2939 | | UML_DSUB(block, MEM(&mips3.core->count_zero_time), MEM(&mips3.cstate->numcycles), IREG(0)); |
| 2940 | | // dsub [count_zero_time],[mips3.numcycles],i0 |
| 2941 | | UML_CALLC(block, mips3com_update_cycle_counting, mips3.core); // callc mips3com_update_cycle_counting,mips.core |
| 3023 | UML_DSUB(block, MEM(&mips3->count_zero_time), MEM(&mips3->impstate->numcycles), IREG(0)); |
| 3024 | // dsub [count_zero_time],[mips3->impstate->numcycles],i0 |
| 3025 | UML_CALLC(block, mips3com_update_cycle_counting, mips3); // callc mips3com_update_cycle_counting,mips.core |
| 2942 | 3026 | return TRUE; |
| 2943 | 3027 | |
| 2944 | 3028 | case COP0_Compare: |
| 2945 | 3029 | generate_update_cycles(block, compiler, IMM(desc->pc), !in_delay_slot); // <subtract cycles> |
| 2946 | 3030 | UML_MOV(block, CPR032(COP0_Compare), IREG(0)); // mov [Compare],i0 |
| 2947 | 3031 | UML_AND(block, CPR032(COP0_Cause), CPR032(COP0_Cause), IMM(~0x8000)); // and [Cause],[Cause],~0x8000 |
| 2948 | | UML_CALLC(block, mips3com_update_cycle_counting, mips3.core); // callc mips3com_update_cycle_counting,mips.core |
| 3032 | UML_CALLC(block, mips3com_update_cycle_counting, mips3); // callc mips3com_update_cycle_counting,mips.core |
| 2949 | 3033 | return TRUE; |
| 2950 | 3034 | |
| 2951 | 3035 | case COP0_PRId: |
| r2762 | r2763 | |
| 2960 | 3044 | UML_MOV(block, CPR032(reg), IREG(0)); // mov cpr0[reg],i0 |
| 2961 | 3045 | UML_TEST(block, IREG(1), IMM(0xff)); // test i1,0xff |
| 2962 | 3046 | UML_JMPc(block, IF_Z, link = compiler->labelnum++); // jmp link,z |
| 2963 | | UML_CALLC(block, mips3com_unmap_tlb_entries, mips3.core); // callc mips3com_unmap_tlb_entries |
| 2964 | | UML_CALLC(block, mips3com_map_tlb_entries, mips3.core); // callc mips3com_map_tlb_entries |
| 3047 | UML_CALLC(block, mips3com_unmap_tlb_entries, mips3); // callc mips3com_unmap_tlb_entries |
| 3048 | UML_CALLC(block, mips3com_map_tlb_entries, mips3); // callc mips3com_map_tlb_entries |
| 2965 | 3049 | UML_LABEL(block, link); // link: |
| 2966 | 3050 | return TRUE; |
| 2967 | 3051 | |
| r2762 | r2763 | |
| 2985 | 3069 | { |
| 2986 | 3070 | case COP0_Count: |
| 2987 | 3071 | generate_update_cycles(block, compiler, IMM(desc->pc), FALSE); // <subtract cycles> |
| 2988 | | UML_CALLC(block, cfunc_get_cycles, &mips3.cstate->numcycles); // callc cfunc_get_cycles,&mips3.numcycles |
| 2989 | | UML_DSUB(block, IREG(0), MEM(&mips3.cstate->numcycles), MEM(&mips3.core->count_zero_time)); |
| 3072 | UML_CALLC(block, cfunc_get_cycles, &mips3->impstate->numcycles); // callc cfunc_get_cycles,&mips3->impstate->numcycles |
| 3073 | UML_DSUB(block, IREG(0), MEM(&mips3->impstate->numcycles), MEM(&mips3->count_zero_time)); |
| 2990 | 3074 | // dsub i0,[numcycles],[count_zero_time] |
| 2991 | 3075 | UML_DSHR(block, IREG(0), IREG(0), IMM(1)); // dshr i0,i0,1 |
| 2992 | 3076 | UML_DSEXT4(block, IREG(0), IREG(0)); // dsext4 i0,i0 |
| r2762 | r2763 | |
| 2994 | 3078 | |
| 2995 | 3079 | case COP0_Random: |
| 2996 | 3080 | generate_update_cycles(block, compiler, IMM(desc->pc), FALSE); // <subtract cycles> |
| 2997 | | UML_CALLC(block, cfunc_get_cycles, &mips3.cstate->numcycles); // callc cfunc_get_cycles,&mips3.numcycles |
| 2998 | | UML_DSUB(block, IREG(0), MEM(&mips3.cstate->numcycles), MEM(&mips3.core->count_zero_time)); |
| 3081 | UML_CALLC(block, cfunc_get_cycles, &mips3->impstate->numcycles); // callc cfunc_get_cycles,&mips3->impstate->numcycles |
| 3082 | UML_DSUB(block, IREG(0), MEM(&mips3->impstate->numcycles), MEM(&mips3->count_zero_time)); |
| 2999 | 3083 | // dsub i0,[numcycles],[count_zero_time] |
| 3000 | 3084 | UML_AND(block, IREG(1), CPR032(COP0_Wired), IMM(0x3f)); // and i1,[Wired],0x3f |
| 3001 | 3085 | UML_SUBf(block, IREG(2), IMM(48), IREG(1), FLAGS_BE); // sub i2,48,i1,ALL |
| r2762 | r2763 | |
| 3025 | 3109 | { |
| 3026 | 3110 | UINT32 op = *desc->opptr.l; |
| 3027 | 3111 | UINT8 opswitch = RSREG; |
| 3028 | | drcuml_codelabel okay; |
| 3029 | 3112 | int skip; |
| 3030 | 3113 | |
| 3031 | | /* generate an exception if COP0 is disabled or we are not in kernel mode */ |
| 3032 | | UML_TEST(block, CPR032(COP0_Status), IMM(SR_KSU_MASK)); // test [Status],SR_KSU_MASK |
| 3033 | | UML_JMPc(block, IF_Z, okay = compiler->labelnum++); // jmp okay,Z |
| 3034 | | UML_TEST(block, CPR032(COP0_Status), IMM(SR_COP0)); // test [Status],SR_COP0 |
| 3035 | | UML_EXHc(block, IF_Z, mips3.exception[EXCEPTION_BADCOP], IMM(0)); // exh cop,0,Z |
| 3036 | | UML_LABEL(block, okay); // okay: |
| 3114 | /* generate an exception if COP0 is disabled unless we are in kernel mode */ |
| 3115 | if ((mips3->impstate->mode >> 1) != MODE_KERNEL) |
| 3116 | { |
| 3117 | UML_TEST(block, CPR032(COP0_Status), IMM(SR_COP0)); // test [Status],SR_COP0 |
| 3118 | UML_EXHc(block, IF_Z, mips3->impstate->exception[EXCEPTION_BADCOP], IMM(0));// exh cop,0,Z |
| 3119 | } |
| 3037 | 3120 | |
| 3038 | 3121 | switch (opswitch) |
| 3039 | 3122 | { |
| r2762 | r2763 | |
| 3091 | 3174 | switch (op & 0x01ffffff) |
| 3092 | 3175 | { |
| 3093 | 3176 | case 0x01: /* TLBR */ |
| 3094 | | UML_CALLC(block, mips3com_tlbr, mips3.core); // callc mips3com_tlbr,mips3.core |
| 3177 | UML_CALLC(block, mips3com_tlbr, mips3); // callc mips3com_tlbr,mips3 |
| 3095 | 3178 | return TRUE; |
| 3096 | 3179 | |
| 3097 | 3180 | case 0x02: /* TLBWI */ |
| 3098 | | UML_CALLC(block, mips3com_tlbwi, mips3.core); // callc mips3com_tlbwi,mips3.core |
| 3181 | UML_CALLC(block, mips3com_tlbwi, mips3); // callc mips3com_tlbwi,mips3 |
| 3099 | 3182 | return TRUE; |
| 3100 | 3183 | |
| 3101 | 3184 | case 0x06: /* TLBWR */ |
| 3102 | | UML_CALLC(block, mips3com_tlbwr, mips3.core); // callc mips3com_tlbwr,mips3.core |
| 3185 | UML_CALLC(block, mips3com_tlbwr, mips3); // callc mips3com_tlbwr,mips3 |
| 3103 | 3186 | return TRUE; |
| 3104 | 3187 | |
| 3105 | 3188 | case 0x08: /* TLBP */ |
| 3106 | | UML_CALLC(block, mips3com_tlbp, mips3.core); // callc mips3com_tlbp,mips3.core |
| 3189 | UML_CALLC(block, mips3com_tlbp, mips3); // callc mips3com_tlbp,mips3 |
| 3107 | 3190 | return TRUE; |
| 3108 | 3191 | |
| 3109 | 3192 | case 0x18: /* ERET */ |
| r2762 | r2763 | |
| 3115 | 3198 | generate_update_mode(block); |
| 3116 | 3199 | compiler->checkints = TRUE; |
| 3117 | 3200 | generate_update_cycles(block, compiler, CPR032(COP0_EPC), TRUE);// <subtract cycles> |
| 3118 | | UML_HASHJMP(block, MEM(&mips3.cstate->mode), CPR032(COP0_EPC), mips3.nocode); |
| 3201 | UML_HASHJMP(block, MEM(&mips3->impstate->mode), CPR032(COP0_EPC), mips3->impstate->nocode); |
| 3119 | 3202 | // hashjmp <mode>,[EPC],nocode |
| 3120 | 3203 | UML_LABEL(block, skip); // skip: |
| 3121 | 3204 | UML_AND(block, IREG(0), IREG(0), IMM(~SR_ERL)); // and i0,i0,~SR_ERL |
| r2762 | r2763 | |
| 3124 | 3207 | compiler->checkints = TRUE; |
| 3125 | 3208 | generate_update_cycles(block, compiler, CPR032(COP0_ErrorPC), TRUE); |
| 3126 | 3209 | // <subtract cycles> |
| 3127 | | UML_HASHJMP(block, MEM(&mips3.cstate->mode), CPR032(COP0_ErrorPC), mips3.nocode); |
| 3210 | UML_HASHJMP(block, MEM(&mips3->impstate->mode), CPR032(COP0_ErrorPC), mips3->impstate->nocode); |
| 3128 | 3211 | // hashjmp <mode>,[EPC],nocode |
| 3129 | 3212 | return TRUE; |
| 3130 | 3213 | |
| r2762 | r2763 | |
| 3154 | 3237 | int condition; |
| 3155 | 3238 | |
| 3156 | 3239 | /* generate an exception if COP1 is disabled */ |
| 3157 | | if (mips3.drcoptions & MIPS3DRC_STRICT_COP1) |
| 3240 | if (mips3->impstate->drcoptions & MIPS3DRC_STRICT_COP1) |
| 3158 | 3241 | { |
| 3159 | 3242 | UML_TEST(block, CPR032(COP0_Status), IMM(SR_COP1)); // test [Status],SR_COP1 |
| 3160 | | UML_EXHc(block, IF_Z, mips3.exception[EXCEPTION_BADCOP], IMM(0)); // exh cop,0,Z |
| 3243 | UML_EXHc(block, IF_Z, mips3->impstate->exception[EXCEPTION_BADCOP], IMM(0));// exh cop,0,Z |
| 3161 | 3244 | } |
| 3162 | 3245 | |
| 3163 | 3246 | switch (RSREG) |
| r2762 | r2763 | |
| 3195 | 3278 | UML_TEST(block, IREG(0), IMM(3)); // test i0,3 |
| 3196 | 3279 | UML_JMPc(block, IF_Z, skip = compiler->labelnum++); // jmp skip,Z |
| 3197 | 3280 | UML_AND(block, IREG(0), CCR132(31), IMM(3)); // and i0,ccr1[31],3 |
| 3198 | | UML_LOAD1U(block, IREG(0), &mips3.cstate->fpmode[0], IREG(0)); // load1u i0,fpmode,i0 |
| 3281 | UML_LOAD1U(block, IREG(0), &mips3->impstate->fpmode[0], IREG(0)); // load1u i0,fpmode,i0 |
| 3199 | 3282 | UML_SETFMOD(block, IREG(0)); // setfmod i0 |
| 3200 | 3283 | UML_LABEL(block, skip); // skip: |
| 3201 | 3284 | } |
| r2762 | r2763 | |
| 3425 | 3508 | UML_FSCMP(block, FPR32(FSREG), FPR32(FTREG)); // fscmp <fsreg>,<ftreg> |
| 3426 | 3509 | else /* C.UN.D - MIPS I */ |
| 3427 | 3510 | UML_FDCMP(block, FPR64(FSREG), FPR64(FTREG)); // fdcmp <fsreg>,<ftreg> |
| 3428 | | UML_FLAGS(block, CCR132(31), FCCMASK(op >> 8), mips3.cstate->c_un_table); |
| 3511 | UML_FLAGS(block, CCR132(31), FCCMASK(op >> 8), mips3->impstate->c_un_table); |
| 3429 | 3512 | // flags ccr31,fccmask[op],c_eq_table |
| 3430 | 3513 | return TRUE; |
| 3431 | 3514 | |
| r2762 | r2763 | |
| 3435 | 3518 | UML_FSCMP(block, FPR32(FSREG), FPR32(FTREG)); // fscmp <fsreg>,<ftreg> |
| 3436 | 3519 | else /* C.EQ.D - MIPS I */ |
| 3437 | 3520 | UML_FDCMP(block, FPR64(FSREG), FPR64(FTREG)); // fdcmp <fsreg>,<ftreg> |
| 3438 | | UML_FLAGS(block, CCR132(31), FCCMASK(op >> 8), mips3.cstate->c_eq_table); |
| 3521 | UML_FLAGS(block, CCR132(31), FCCMASK(op >> 8), mips3->impstate->c_eq_table); |
| 3439 | 3522 | // flags ccr31,fccmask[op],c_eq_table |
| 3440 | 3523 | return TRUE; |
| 3441 | 3524 | |
| r2762 | r2763 | |
| 3445 | 3528 | UML_FSCMP(block, FPR32(FSREG), FPR32(FTREG)); // fscmp <fsreg>,<ftreg> |
| 3446 | 3529 | else /* C.UEQ.D - MIPS I */ |
| 3447 | 3530 | UML_FDCMP(block, FPR64(FSREG), FPR64(FTREG)); // fdcmp <fsreg>,<ftreg> |
| 3448 | | UML_FLAGS(block, CCR132(31), FCCMASK(op >> 8), mips3.cstate->c_ueq_table); |
| 3531 | UML_FLAGS(block, CCR132(31), FCCMASK(op >> 8), mips3->impstate->c_ueq_table); |
| 3449 | 3532 | // flags ccr31,fccmask[op],c_eq_table |
| 3450 | 3533 | return TRUE; |
| 3451 | 3534 | |
| r2762 | r2763 | |
| 3455 | 3538 | UML_FSCMP(block, FPR32(FSREG), FPR32(FTREG)); // fscmp <fsreg>,<ftreg> |
| 3456 | 3539 | else /* C.OLT.D - MIPS I */ |
| 3457 | 3540 | UML_FDCMP(block, FPR64(FSREG), FPR64(FTREG)); // fdcmp <fsreg>,<ftreg> |
| 3458 | | UML_FLAGS(block, CCR132(31), FCCMASK(op >> 8), mips3.cstate->c_olt_table); |
| 3541 | UML_FLAGS(block, CCR132(31), FCCMASK(op >> 8), mips3->impstate->c_olt_table); |
| 3459 | 3542 | // flags ccr31,fccmask[op],c_lt_table |
| 3460 | 3543 | return TRUE; |
| 3461 | 3544 | |
| r2762 | r2763 | |
| 3465 | 3548 | UML_FSCMP(block, FPR32(FSREG), FPR32(FTREG)); // fscmp <fsreg>,<ftreg> |
| 3466 | 3549 | else /* C.ULT.D - MIPS I */ |
| 3467 | 3550 | UML_FDCMP(block, FPR64(FSREG), FPR64(FTREG)); // fdcmp <fsreg>,<ftreg> |
| 3468 | | UML_FLAGS(block, CCR132(31), FCCMASK(op >> 8), mips3.cstate->c_ult_table); |
| 3551 | UML_FLAGS(block, CCR132(31), FCCMASK(op >> 8), mips3->impstate->c_ult_table); |
| 3469 | 3552 | // flags ccr31,fccmask[op],c_lt_table |
| 3470 | 3553 | return TRUE; |
| 3471 | 3554 | |
| r2762 | r2763 | |
| 3475 | 3558 | UML_FSCMP(block, FPR32(FSREG), FPR32(FTREG)); // fscmp <fsreg>,<ftreg> |
| 3476 | 3559 | else /* C.OLE.D - MIPS I */ |
| 3477 | 3560 | UML_FDCMP(block, FPR64(FSREG), FPR64(FTREG)); // fdcmp <fsreg>,<ftreg> |
| 3478 | | UML_FLAGS(block, CCR132(31), FCCMASK(op >> 8), mips3.cstate->c_ole_table); |
| 3561 | UML_FLAGS(block, CCR132(31), FCCMASK(op >> 8), mips3->impstate->c_ole_table); |
| 3479 | 3562 | // flags ccr31,fccmask[op],c_le_table |
| 3480 | 3563 | return TRUE; |
| 3481 | 3564 | |
| r2762 | r2763 | |
| 3485 | 3568 | UML_FSCMP(block, FPR32(FSREG), FPR32(FTREG)); // fscmp <fsreg>,<ftreg> |
| 3486 | 3569 | else /* C.ULE.D - MIPS I */ |
| 3487 | 3570 | UML_FDCMP(block, FPR64(FSREG), FPR64(FTREG)); // fdcmp <fsreg>,<ftreg> |
| 3488 | | UML_FLAGS(block, CCR132(31), FCCMASK(op >> 8), mips3.cstate->c_ule_table); |
| 3571 | UML_FLAGS(block, CCR132(31), FCCMASK(op >> 8), mips3->impstate->c_ule_table); |
| 3489 | 3572 | // flags ccr31,fccmask[op],c_le_table |
| 3490 | 3573 | return TRUE; |
| 3491 | 3574 | } |
| r2762 | r2763 | |
| 3509 | 3592 | int in_delay_slot = ((desc->flags & OPFLAG_IN_DELAY_SLOT) != 0); |
| 3510 | 3593 | UINT32 op = *desc->opptr.l; |
| 3511 | 3594 | |
| 3512 | | if (mips3.drcoptions & MIPS3DRC_STRICT_COP1) |
| 3595 | if (mips3->impstate->drcoptions & MIPS3DRC_STRICT_COP1) |
| 3513 | 3596 | { |
| 3514 | 3597 | UML_TEST(block, CPR032(COP0_Status), IMM(SR_COP1)); // test [Status],SR_COP1 |
| 3515 | | UML_EXHc(block, IF_Z, mips3.exception[EXCEPTION_BADCOP], IMM(0)); // exh cop,0,Z |
| 3598 | UML_EXHc(block, IF_Z, mips3->impstate->exception[EXCEPTION_BADCOP], IMM(0));// exh cop,0,Z |
| 3516 | 3599 | } |
| 3517 | 3600 | |
| 3518 | 3601 | switch (op & 0x3f) |
| 3519 | 3602 | { |
| 3520 | 3603 | case 0x00: /* LWXC1 - MIPS IV */ |
| 3521 | 3604 | UML_ADD(block, IREG(0), R32(RSREG), R32(RTREG)); // add i0,<rsreg>,<rtreg> |
| 3522 | | UML_CALLH(block, mips3.read32[mips3.cstate->mode >> 1]); // callh read32 |
| 3605 | UML_CALLH(block, mips3->impstate->read32[mips3->impstate->mode >> 1]); // callh read32 |
| 3523 | 3606 | UML_MOV(block, FPR32(RDREG), IREG(0)); // mov <cpr1_rd>,i0 |
| 3524 | 3607 | if (!in_delay_slot) |
| 3525 | 3608 | generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE); |
| r2762 | r2763 | |
| 3527 | 3610 | |
| 3528 | 3611 | case 0x01: /* LDXC1 - MIPS IV */ |
| 3529 | 3612 | UML_ADD(block, IREG(0), R32(RSREG), R32(RTREG)); // add i0,<rsreg>,<rtreg> |
| 3530 | | UML_CALLH(block, mips3.read64[mips3.cstate->mode >> 1]); // callh read64 |
| 3613 | UML_CALLH(block, mips3->impstate->read64[mips3->impstate->mode >> 1]); // callh read64 |
| 3531 | 3614 | UML_DMOV(block, FPR64(RDREG), IREG(0)); // dmov <cpr1_rd>,i0 |
| 3532 | 3615 | if (!in_delay_slot) |
| 3533 | 3616 | generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE); |
| r2762 | r2763 | |
| 3536 | 3619 | case 0x08: /* SWXC1 - MIPS IV */ |
| 3537 | 3620 | UML_ADD(block, IREG(0), R32(RSREG), R32(RTREG)); // add i0,<rsreg>,<rtreg> |
| 3538 | 3621 | UML_MOV(block, IREG(1), FPR32(RTREG)); // mov i1,<cpr1_rt> |
| 3539 | | UML_CALLH(block, mips3.write32[mips3.cstate->mode >> 1]); // callh write32 |
| 3622 | UML_CALLH(block, mips3->impstate->write32[mips3->impstate->mode >> 1]); // callh write32 |
| 3540 | 3623 | if (!in_delay_slot) |
| 3541 | 3624 | generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE); |
| 3542 | 3625 | return TRUE; |
| r2762 | r2763 | |
| 3544 | 3627 | case 0x09: /* SDXC1 - MIPS IV */ |
| 3545 | 3628 | UML_ADD(block, IREG(0), R32(RSREG), R32(RTREG)); // add i0,<rsreg>,<rtreg> |
| 3546 | 3629 | UML_DMOV(block, IREG(1), FPR64(RTREG)); // dmov i1,<cpr1_rt> |
| 3547 | | UML_CALLH(block, mips3.write64[mips3.cstate->mode >> 1]); // callh write64 |
| 3630 | UML_CALLH(block, mips3->impstate->write64[mips3->impstate->mode >> 1]); // callh write64 |
| 3548 | 3631 | if (!in_delay_slot) |
| 3549 | 3632 | generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE); |
| 3550 | 3633 | return TRUE; |
| r2762 | r2763 | |
| 3756 | 3839 | |
| 3757 | 3840 | |
| 3758 | 3841 | /*************************************************************************** |
| 3759 | | GENERIC GET/SET INFO |
| 3760 | | ***************************************************************************/ |
| 3761 | | |
| 3762 | | static void mips3_set_info(UINT32 state, cpuinfo *info) |
| 3763 | | { |
| 3764 | | switch (state) |
| 3765 | | { |
| 3766 | | /* --- the following bits of info are set as 64-bit signed integers --- */ |
| 3767 | | case CPUINFO_INT_MIPS3_DRC_OPTIONS: mips3.drcoptions = info->i; break; |
| 3768 | | |
| 3769 | | case CPUINFO_INT_MIPS3_FASTRAM_SELECT: if (info->i >= 0 && info->i < MIPS3_MAX_FASTRAM) mips3.fastram_select = info->i; mips3.cache_dirty = TRUE; break; |
| 3770 | | case CPUINFO_INT_MIPS3_FASTRAM_START: mips3.fastram[mips3.fastram_select].start = info->i; mips3.cache_dirty = TRUE; break; |
| 3771 | | case CPUINFO_INT_MIPS3_FASTRAM_END: mips3.fastram[mips3.fastram_select].end = info->i; mips3.cache_dirty = TRUE; break; |
| 3772 | | case CPUINFO_INT_MIPS3_FASTRAM_READONLY: mips3.fastram[mips3.fastram_select].readonly = info->i; mips3.cache_dirty = TRUE; break; |
| 3773 | | |
| 3774 | | case CPUINFO_INT_MIPS3_HOTSPOT_SELECT: if (info->i >= 0 && info->i < MIPS3_MAX_HOTSPOTS) mips3.hotspot_select = info->i; mips3.cache_dirty = TRUE; break; |
| 3775 | | case CPUINFO_INT_MIPS3_HOTSPOT_PC: mips3.hotspot[mips3.hotspot_select].pc = info->i; mips3.cache_dirty = TRUE; break; |
| 3776 | | case CPUINFO_INT_MIPS3_HOTSPOT_OPCODE: mips3.hotspot[mips3.hotspot_select].opcode = info->i; mips3.cache_dirty = TRUE; break; |
| 3777 | | case CPUINFO_INT_MIPS3_HOTSPOT_CYCLES: mips3.hotspot[mips3.hotspot_select].cycles = info->i; mips3.cache_dirty = TRUE; break; |
| 3778 | | |
| 3779 | | /* --- the following bits of info are set as pointers to data or functions --- */ |
| 3780 | | case CPUINFO_PTR_MIPS3_FASTRAM_BASE: mips3.fastram[mips3.fastram_select].base = info->p; break; |
| 3781 | | |
| 3782 | | /* --- everything else is handled generically --- */ |
| 3783 | | default: mips3com_set_info(mips3.core, state, info); break; |
| 3784 | | } |
| 3785 | | } |
| 3786 | | |
| 3787 | | |
| 3788 | | static void mips3_get_info(UINT32 state, cpuinfo *info) |
| 3789 | | { |
| 3790 | | switch (state) |
| 3791 | | { |
| 3792 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 3793 | | case CPUINFO_INT_CONTEXT_SIZE: info->i = sizeof(mips3); break; |
| 3794 | | case CPUINFO_INT_PREVIOUSPC: /* not implemented */ break; |
| 3795 | | |
| 3796 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 3797 | | case CPUINFO_PTR_SET_INFO: info->setinfo = mips3_set_info; break; |
| 3798 | | case CPUINFO_PTR_GET_CONTEXT: info->getcontext = mips3_get_context; break; |
| 3799 | | case CPUINFO_PTR_SET_CONTEXT: info->setcontext = mips3_set_context; break; |
| 3800 | | case CPUINFO_PTR_INIT: /* provided per-CPU */ break; |
| 3801 | | case CPUINFO_PTR_RESET: info->reset = mips3_reset; break; |
| 3802 | | case CPUINFO_PTR_EXIT: info->exit = mips3_exit; break; |
| 3803 | | case CPUINFO_PTR_EXECUTE: info->execute = mips3_execute; break; |
| 3804 | | #ifdef ENABLE_DEBUGGER |
| 3805 | | case CPUINFO_PTR_DISASSEMBLE: info->disassemble = mips3_dasm; break; |
| 3806 | | #endif /* ENABLE_DEBUGGER */ |
| 3807 | | case CPUINFO_PTR_TRANSLATE: info->translate = mips3_translate; break; |
| 3808 | | |
| 3809 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 3810 | | case CPUINFO_STR_CORE_FILE: strcpy(info->s, __FILE__); break; |
| 3811 | | |
| 3812 | | /* --- everything else is handled generically --- */ |
| 3813 | | default: mips3com_get_info(mips3.core, state, info); break; |
| 3814 | | } |
| 3815 | | } |
| 3816 | | |
| 3817 | | |
| 3818 | | |
| 3819 | | /*************************************************************************** |
| 3820 | 3842 | R4600 VARIANTS |
| 3821 | 3843 | ***************************************************************************/ |
| 3822 | 3844 | |
src/emu/cheat.c
| r2762 | r2763 | |
| 39 | 39 | k##name##_ShiftedMask = (int)(0xFFFFFFFF >> (32 - (start - end + 1))), \ |
| 40 | 40 | k##name##_Mask = (int)(k##name##_ShiftedMask << k##name##_Shift) |
| 41 | 41 | |
| 42 | | #define kRegionListLength (REGION_MAX - REGION_INVALID) |
| 42 | #define REGION_LIST_LENGTH (REGION_MAX - REGION_INVALID) |
| 43 | #define VALID_CPU(cpu) (cpu < cpu_gettotalcpu()) |
| 43 | 44 | |
| 45 | #define ADD_MENU_2_ITEMS(name, sub_name) do { menu_item[total] = name; menu_sub_item[total] = sub_name; total++; } while(0) |
| 46 | #define TERMINATE_MENU_2_ITEMS do { menu_item[total] = NULL; menu_sub_item[total] = NULL; } while(0) |
| 47 | |
| 48 | #define ADD_MENU_3_ITEMS(name, sub_name, enum) do { menu_item[total] = name; menu_sub_item[total] = sub_name; menu_index[total] = enum; total++; } while(0) |
| 49 | |
| 50 | #define ADJUST_CURSOR(sel, total) if(sel < 0) sel = 0; else if(sel > (total - 1)) sel = (total - 1); |
| 51 | #define CURSOR_TO_NEXT(sel, total) if(++sel > (total - 1)) sel = 0; |
| 52 | #define CURSOR_TO_PREVIOUS(sel, total) if(--sel < 0) sel = (total - 1); |
| 53 | #define CURSOR_PAGE_UP(sel) sel -= visible_items; if(sel < 0) sel = 0; |
| 54 | #define CURSOR_PAGE_DOWN(sel, total) sel += visible_items; if(sel >= total) sel = (total - 1); |
| 55 | |
| 44 | 56 | /*************************************************************************** |
| 45 | 57 | CONSTANTS |
| 46 | 58 | ***************************************************************************/ |
| 47 | 59 | |
| 48 | | #define CHEAT_FILENAME_MAX_LEN 255 |
| 60 | #define CHEAT_FILENAME_MAX_LEN (255) |
| 61 | #define CHEAT_MENU_DEPTH (8) |
| 62 | #ifdef MESS |
| 63 | #define DEFAULT_CHEAT_OPTIONS (0x4F) |
| 64 | #else |
| 65 | #define DEFAULT_CHEAT_OPTIONS (0xF) |
| 66 | #endif |
| 67 | #define DEFAULT_MESSAGE_TIME (50) |
| 68 | #define VARIABLE_MAX_ARRAY (0x0F) // NOTE : Move code can accept max 16 variables as destination |
| 69 | #define CHEAT_RETURN_VALUE (0xFF) |
| 70 | #define CUSTOM_CODE (0xFF) |
| 49 | 71 | |
| 50 | 72 | /********** BIT FIELD **********/ |
| 51 | 73 | |
| 52 | 74 | enum |
| 53 | 75 | { |
| 54 | | /* cheat code */ |
| 76 | /* type field */ |
| 55 | 77 | DEFINE_BITFIELD_ENUM(OneShot, 0, 0), |
| 78 | DEFINE_BITFIELD_ENUM(DelayEnable, 1, 1), |
| 79 | DEFINE_BITFIELD_ENUM(PrefillEnable, 2, 2), |
| 80 | DEFINE_BITFIELD_ENUM(Return, 3, 3), |
| 81 | DEFINE_BITFIELD_ENUM(RestoreValue, 4, 4), |
| 82 | DEFINE_BITFIELD_ENUM(DataRead, 5, 5), // 0 = field, 1 = variable |
| 83 | DEFINE_BITFIELD_ENUM(AddressRead, 6, 7), // 0 = field, 1 = indirect address from variable, 2 = variable |
| 84 | DEFINE_BITFIELD_ENUM(CodeParameter, 8, 11), |
| 85 | DEFINE_BITFIELD_ENUM(CodeType, 12, 15), |
| 86 | DEFINE_BITFIELD_ENUM(Link, 16, 17), // 0 = master, 1 = link, 2 = sub link for label-selection, 3 = copy link for VWrite, VRWrite |
| 87 | DEFINE_BITFIELD_ENUM(LinkValueSelectBCD, 18, 18), // used by VWrite (link) |
| 88 | DEFINE_BITFIELD_ENUM(LinkValueSelectNegative, 19, 19), // used by VWrite (link) |
| 89 | DEFINE_BITFIELD_ENUM(PopupParameter, 18, 19), // used by Popup |
| 90 | DEFINE_BITFIELD_ENUM(AddressSize, 20, 21), |
| 91 | DEFINE_BITFIELD_ENUM(IndexSize, 22, 23), // used by IWrite, VWrite, Move, Popup |
| 92 | DEFINE_BITFIELD_ENUM(CPURegion, 24, 31), // extract to CPU/Region field |
| 93 | |
| 94 | /* extend field */ |
| 95 | DEFINE_BITFIELD_ENUM(LSB16, 0, 15), // lower 4 bytes |
| 96 | DEFINE_BITFIELD_ENUM(MSB16, 16, 31), // upper 4 bytes |
| 97 | |
| 98 | /* value-select master code */ |
| 99 | DEFINE_BITFIELD_ENUM(ValueSelectMinimumDisplay, 8, 8), |
| 100 | DEFINE_BITFIELD_ENUM(ValueSelectMinimum, 9, 9), |
| 101 | DEFINE_BITFIELD_ENUM(ValueSelectBCD, 10, 10), |
| 102 | DEFINE_BITFIELD_ENUM(ValueSelectNegative, 11, 11), |
| 103 | |
| 104 | /* watch code */ |
| 105 | DEFINE_BITFIELD_ENUM(WatchDisplayFormat, 8, 9), // from type field |
| 106 | DEFINE_BITFIELD_ENUM(WatchShowLabel, 10, 10), // |
| 107 | DEFINE_BITFIELD_ENUM(WatchNumElements, 0, 7), // from data field |
| 108 | DEFINE_BITFIELD_ENUM(WatchSkip, 8, 15), // |
| 109 | DEFINE_BITFIELD_ENUM(WatchElementsPerLine, 16, 23), // |
| 110 | DEFINE_BITFIELD_ENUM(WatchAddValue, 24, 31), // |
| 111 | |
| 112 | /* label-selection */ |
| 113 | DEFINE_BITFIELD_ENUM(LabelSelectUseSelector, 4, 4), |
| 114 | DEFINE_BITFIELD_ENUM(LabelSelectQuickClose, 5, 5), |
| 115 | |
| 116 | /* cpu/region field */ |
| 117 | DEFINE_BITFIELD_ENUM(CPUIndex, 0, 3), // cpu region |
| 118 | DEFINE_BITFIELD_ENUM(AddressSpace, 4, 6), // cpu region |
| 119 | DEFINE_BITFIELD_ENUM(RegionIndex, 0, 6), // non-cpu region |
| 120 | DEFINE_BITFIELD_ENUM(RegionFlag, 7, 7), // 0 = cpu, 1 = non-cpu |
| 121 | |
| 122 | /* old code */ |
| 123 | // DEFINE_BITFIELD_ENUM(OneShot, 0, 0), |
| 56 | 124 | DEFINE_BITFIELD_ENUM(Type, 1, 2), |
| 57 | 125 | DEFINE_BITFIELD_ENUM(Operation, 3, 4), |
| 58 | 126 | DEFINE_BITFIELD_ENUM(TypeParameter, 5, 7), |
| r2762 | r2763 | |
| 73 | 141 | DEFINE_BITFIELD_ENUM(LocationParameter, 24, 28), |
| 74 | 142 | DEFINE_BITFIELD_ENUM(LocationType, 29, 31), |
| 75 | 143 | |
| 76 | | /* watch (unused ?) */ |
| 77 | | // DEFINE_BITFIELD_ENUM(Watch_AddValue, 0, 15), |
| 78 | | // DEFINE_BITFIELD_ENUM(Watch_Label, 16, 17), |
| 79 | | // DEFINE_BITFIELD_ENUM(Watch_DisplayType, 18, 19), |
| 144 | /* location parameter extention (relative address, memory accessor) */ |
| 145 | DEFINE_BITFIELD_ENUM(LocationParameterOption, 24, 25), |
| 146 | DEFINE_BITFIELD_ENUM(LocationParameterCPU, 26, 28), |
| 80 | 147 | |
| 81 | 148 | /* command */ |
| 82 | | DEFINE_BITFIELD_ENUM(AutoSaveEnabled, 0, 0), |
| 83 | | DEFINE_BITFIELD_ENUM(SearchBox, 1, 2), // 0 = Minimum, 1 = Classic, 2 = Advanced |
| 84 | | DEFINE_BITFIELD_ENUM(DontPrintNewLabels, 3, 3), // in options menu, it is reverted. |
| 149 | DEFINE_BITFIELD_ENUM(SearchBox, 0, 1), |
| 150 | DEFINE_BITFIELD_ENUM(DontPrintNewLabels, 2, 2), // in options menu, it is reversed display |
| 151 | DEFINE_BITFIELD_ENUM(AutoSaveEnabled, 3, 3), |
| 85 | 152 | DEFINE_BITFIELD_ENUM(ActivationKeyMessage, 4, 4), |
| 86 | 153 | DEFINE_BITFIELD_ENUM(LoadOldFormat, 5, 5), |
| 87 | | DEFINE_BITFIELD_ENUM(Debug, 6, 6) |
| 154 | #ifdef MESS |
| 155 | DEFINE_BITFIELD_ENUM(SharedCode, 6, 6) |
| 156 | #endif |
| 88 | 157 | }; |
| 89 | 158 | |
| 90 | 159 | /********** OPERATION **********/ |
| 91 | 160 | |
| 161 | enum{ // address space for RAM region |
| 162 | kAddressSpace_Program = 0, |
| 163 | kAddressSpace_DataSpace, |
| 164 | kAddressSpace_IOSpace, |
| 165 | kAddressSpace_OpcodeRAM, |
| 166 | kAddressSpace_MappedMemory, |
| 167 | kAddressSpace_DirectMemory, |
| 168 | kAddressSpace_EEPROM }; |
| 169 | |
| 170 | enum{ // code types |
| 171 | kCodeType_Write = 0, // EF = Mask |
| 172 | kCodeType_IWrite, // EF = Index |
| 173 | kCodeType_RWrite, // EF = Count/Skip |
| 174 | kCodeType_CWrite, // EF = Condition |
| 175 | kCodeType_VWrite, // EF = Index |
| 176 | kCodeType_VRWrite, // EF = Count/Skip |
| 177 | kCodeType_PDWWrite, // EF = 2nd Data |
| 178 | kCodeType_Move, // EF = Index |
| 179 | kCodeType_Branch, // EF = Jump Code |
| 180 | kCodeType_Loop, // EF = Index |
| 181 | kCodeType_Unused1, |
| 182 | kCodeType_Unused2, |
| 183 | kCodeType_Unused3, |
| 184 | kCodeType_Unused4, |
| 185 | kCodeType_Popup, // EF = Index |
| 186 | kCodeType_Watch }; // EF = X and Y Position |
| 187 | |
| 188 | enum{ // parameter for IWrite |
| 189 | kIWrite_Write = 0, |
| 190 | kIWrite_BitSet, |
| 191 | kIWrite_BitClear, |
| 192 | kIWrite_LimitedMask }; |
| 193 | |
| 194 | enum{ // conditions for CWrite, Branch, Popup |
| 195 | kCondition_Equal = 0, |
| 196 | kCondition_NotEqual, |
| 197 | kCondition_Less, |
| 198 | kCondition_LessOrEqual, |
| 199 | kCondition_Greater, |
| 200 | kCondition_GreaterOrEqual, |
| 201 | kCondition_BitSet, |
| 202 | kCondition_BitClear, |
| 203 | kCondition_Unused1, |
| 204 | kCondition_Unused2, |
| 205 | kCondition_Unused3, |
| 206 | kCondition_Unused4, |
| 207 | kCondition_PreviousValue, |
| 208 | kCondition_KeyPressedOnce, |
| 209 | kCondition_KeyPressedRepeat, |
| 210 | kCondition_True }; |
| 211 | |
| 212 | enum{ // popup parameter |
| 213 | kPopup_Label = 0, |
| 214 | kPopup_Value, |
| 215 | kPopup_LabelValue, |
| 216 | kPopup_ValueLabel }; |
| 217 | |
| 218 | enum{ // parameter for custom |
| 219 | kCustomCode_NoAction = 0, |
| 220 | kCustomCode_Comment, |
| 221 | kCustomCode_Separator, |
| 222 | kCustomCode_LabelSelect, |
| 223 | kCustomCode_Layer, |
| 224 | kCustomCode_Unused1, |
| 225 | kCustomCode_Unused2, |
| 226 | kCustomCode_Unused3, |
| 227 | kCustomCode_ActivationKey1, |
| 228 | kCustomCode_ActivationKey2, |
| 229 | kCustomCode_PreEnable, |
| 230 | kCustomCode_OverClock, |
| 231 | kCustomCode_RefreshRate }; |
| 232 | |
| 233 | enum{ // link level |
| 234 | kLink_Master = 0, |
| 235 | kLink_Link, |
| 236 | kLink_SubLink, |
| 237 | kLink_CopyLink }; |
| 238 | |
| 239 | enum{ // address read from |
| 240 | kReadFrom_Address = 0, // $xxxx |
| 241 | kReadFrom_Index, // $Vx |
| 242 | kReadFrom_Variable }; // Vx |
| 243 | |
| 92 | 244 | enum // types |
| 93 | 245 | { |
| 94 | 246 | kType_NormalOrDelay = 0, |
| r2762 | r2763 | |
| 103 | 255 | kOperation_AddSubtract, |
| 104 | 256 | kOperation_ForceRange, |
| 105 | 257 | kOperation_SetOrClearBits, |
| 106 | | kOperation_WriteMatch, |
| 107 | | // kOperation_Unused5, |
| 108 | | // kOperation_Unused6, |
| 109 | | kOperation_None = 7 |
| 258 | kOperation_Unused4, |
| 259 | kOperation_Unused5, |
| 260 | kOperation_Unused6, |
| 261 | kOperation_None |
| 110 | 262 | }; |
| 111 | 263 | |
| 112 | 264 | //enum // prefills (unused?) |
| r2762 | r2763 | |
| 124 | 276 | kLocation_HandlerMemory, |
| 125 | 277 | kLocation_Custom, |
| 126 | 278 | kLocation_IndirectIndexed, |
| 127 | | kLocation_ProgramSpace |
| 279 | kLocation_Unused5, |
| 280 | kLocation_Unused6, |
| 281 | kLocation_Unused7 |
| 128 | 282 | }; |
| 129 | 283 | |
| 130 | 284 | enum // location parameters |
| r2762 | r2763 | |
| 138 | 292 | kCustomLocation_RefreshRate |
| 139 | 293 | }; |
| 140 | 294 | |
| 141 | | enum // flags for action |
| 295 | enum // memory accessor parameters |
| 142 | 296 | { |
| 143 | | /* set for wait for modification or ignore if decrementing cheats when |
| 144 | | the targeted value has changed |
| 145 | | cleared after the operation is performed */ |
| 146 | | kActionFlag_WasModified = 1 << 0, |
| 297 | kMemoryLocation_DirectAccess = 0, |
| 298 | kMemoryLocation_DataSpace, |
| 299 | kMemoryLocation_IOSpace, |
| 300 | kMemoryLocation_OpbaseRAM |
| 301 | }; |
| 147 | 302 | |
| 303 | enum // action flags |
| 304 | { |
| 305 | /* set if this code is not the newest format */ |
| 306 | kActionFlag_OldFormat = 1 << 0, |
| 307 | |
| 308 | /* set if this code doesn't need to read/write a value */ |
| 309 | kActionFlag_NoAction = 1 << 1, |
| 310 | |
| 311 | /* set if this code is custom cheat */ |
| 312 | kActionFlag_Custom = 1 << 2, |
| 313 | |
| 148 | 314 | /* set for one shot cheats after the operation is performed */ |
| 149 | | kActionFlag_OperationDone = 1 << 1, |
| 315 | kActionFlag_OperationDone = 1 << 3, |
| 150 | 316 | |
| 151 | | /* set if the extendData field is being used by something other than a mask value */ |
| 152 | | kActionFlag_IgnoreMask = 1 << 2, |
| 317 | /* set if the extendData field is being used by index adress reading (IWrite, VWrite, Move, Loop, Popup)*/ |
| 318 | kActionFlag_IndexAddress = 1 << 4, |
| 153 | 319 | |
| 320 | /* set if the code needs to check the condition (CWrite, Branch, Popup) */ |
| 321 | kActionFlag_CheckCondition = 1 << 5, |
| 322 | |
| 323 | /* set if the code needs to repeat writing (RWrite, VRWrite) */ |
| 324 | kActionFlag_Repeat = 1 << 6, |
| 325 | |
| 326 | /* set if the extendData field is being used by 2nd data (PDWWrite) */ |
| 327 | kActionFlag_PDWWrite = 1 << 7, |
| 328 | |
| 154 | 329 | /* set if the lastValue field contains valid data and can be restored if needed */ |
| 155 | | kActionFlag_LastValueGood = 1 << 3, |
| 330 | kActionFlag_LastValueGood = 1 << 8, |
| 156 | 331 | |
| 157 | 332 | /* set after value changes from prefill value */ |
| 158 | | kActionFlag_PrefillDone = 1 << 4, |
| 333 | kActionFlag_PrefillDone = 1 << 9, |
| 159 | 334 | |
| 160 | 335 | /* set after prefill value written */ |
| 161 | | kActionFlag_PrefillWritten = 1 << 5, |
| 336 | kActionFlag_PrefillWritten = 1 << 10, |
| 162 | 337 | |
| 338 | /* set if the code is a label for label-selection code */ |
| 339 | kActionFlag_IsLabel = 1 << 11, |
| 340 | |
| 341 | /* set when read/write a data after 1st read/write and clear after 2nd read/write (PDWWrite) */ |
| 342 | kActionFlag_IsFirst = 1 << 12, |
| 343 | |
| 163 | 344 | /* masks */ |
| 164 | | kActionFlag_StateMask = kActionFlag_OperationDone | |
| 345 | kActionFlag_StateMask = kActionFlag_OperationDone | // used in ResetAction() to clear specified flags |
| 165 | 346 | kActionFlag_LastValueGood | |
| 166 | 347 | kActionFlag_PrefillDone | |
| 167 | 348 | kActionFlag_PrefillWritten, |
| 168 | | kActionFlag_InfoMask = kActionFlag_WasModified | |
| 169 | | kActionFlag_IgnoreMask, |
| 170 | | kActionFlag_PersistentMask = kActionFlag_LastValueGood |
| 349 | kActionFlag_InfoMask = kActionFlag_IndexAddress, // ??? unused ??? |
| 350 | kActionFlag_PersistentMask = kActionFlag_OldFormat | // used in UpdateCheatInfo() to clear other flags |
| 351 | kActionFlag_LastValueGood |
| 171 | 352 | }; |
| 172 | 353 | |
| 173 | | enum // flags for entry |
| 354 | enum // entry flags |
| 174 | 355 | { |
| 175 | 356 | /* true when the cheat is active */ |
| 176 | 357 | kCheatFlag_Active = 1 << 0, |
| r2762 | r2763 | |
| 178 | 359 | /* true if the cheat is entirely one shot */ |
| 179 | 360 | kCheatFlag_OneShot = 1 << 1, |
| 180 | 361 | |
| 181 | | /* true if the cheat will work with one shot in special case */ |
| 182 | | kCheatFlag_DoOneShot = 1 << 2, |
| 183 | | |
| 184 | 362 | /* true if the cheat is entirely null (ex. a comment) */ |
| 185 | | kCheatFlag_Null = 1 << 3, |
| 363 | kCheatFlag_Null = 1 << 2, |
| 186 | 364 | |
| 365 | /* true if the cheat is multi-comment code */ |
| 366 | kCheatFlag_ExtendComment = 1 << 3, |
| 367 | |
| 368 | /* true if the cheat is specified separator */ |
| 369 | kCheatFlag_Separator = 1 << 4, |
| 370 | |
| 187 | 371 | /* true if the cheat contains a user-select element */ |
| 188 | | kCheatFlag_UserSelect = 1 << 4, |
| 372 | kCheatFlag_UserSelect = 1 << 5, |
| 189 | 373 | |
| 190 | 374 | /* true if the cheat is a select cheat */ |
| 191 | | kCheatFlag_Select = 1 << 5, |
| 375 | kCheatFlag_Select = 1 << 6, |
| 192 | 376 | |
| 377 | /* true if the cheat is layer index cheat */ |
| 378 | kCheatFlag_LayerIndex = 1 << 7, |
| 379 | |
| 380 | /* true if selected code is layer index cheat */ |
| 381 | kCheatFlag_LayerSelected = 1 << 8, |
| 382 | |
| 193 | 383 | /* true if the cheat has been assigned an 1st activation key */ |
| 194 | | kCheatFlag_HasActivationKey1 = 1 << 6, |
| 384 | kCheatFlag_HasActivationKey1 = 1 << 9, |
| 195 | 385 | |
| 196 | 386 | /* true if the cheat has been assigned an 2nd activation key */ |
| 197 | | kCheatFlag_HasActivationKey2 = 1 << 7, |
| 387 | kCheatFlag_HasActivationKey2 = 1 << 10, |
| 198 | 388 | |
| 199 | | /* true if the activation key is being pressed */ |
| 200 | | kCheatFlag_ActivationKeyPressed = 1 << 8, |
| 389 | /* true if the cheat is not the newest format */ |
| 390 | kCheatFlag_OldFormat = 1 << 11, |
| 201 | 391 | |
| 202 | | /* true if the cheat has been edited or is a new cheat */ |
| 203 | | kCheatFlag_Dirty = 1 << 9, |
| 392 | /* true if wrong cheat code */ |
| 393 | kCheatFlag_HasWrongCode = 1 << 12, |
| 204 | 394 | |
| 395 | /* true if the cheat has been edited or is a new cheat |
| 396 | checked at auto-save then save the code if true */ |
| 397 | kCheatFlag_Dirty = 1 << 13, |
| 398 | |
| 205 | 399 | /* masks */ |
| 206 | | kCheatFlag_StateMask = kCheatFlag_Active | |
| 207 | | kCheatFlag_DoOneShot, |
| 208 | | kCheatFlag_InfoMask = kCheatFlag_OneShot | |
| 209 | | kCheatFlag_DoOneShot | |
| 400 | kCheatFlag_StateMask = kCheatFlag_Active, // used in ResetAction() and DeactivateCheat() to clear specified flag |
| 401 | kCheatFlag_InfoMask = kCheatFlag_OneShot | // used in UpdateCheatInfo() to detect specified flags |
| 210 | 402 | kCheatFlag_Null | |
| 403 | kCheatFlag_ExtendComment | |
| 404 | kCheatFlag_Separator | |
| 211 | 405 | kCheatFlag_UserSelect | |
| 212 | 406 | kCheatFlag_Select | |
| 407 | kCheatFlag_LayerIndex | |
| 408 | kCheatFlag_OldFormat, |
| 409 | kCheatFlag_PersistentMask = kCheatFlag_Active | // used in UpdateCheatInfo() to extract specified flags |
| 213 | 410 | kCheatFlag_HasActivationKey1 | |
| 214 | 411 | kCheatFlag_HasActivationKey2 | |
| 215 | | kCheatFlag_ActivationKeyPressed, |
| 216 | | kCheatFlag_PersistentMask = kCheatFlag_Active | |
| 217 | | kCheatFlag_DoOneShot | |
| 218 | | kCheatFlag_HasActivationKey1 | |
| 219 | | kCheatFlag_HasActivationKey2 | |
| 220 | | kCheatFlag_ActivationKeyPressed | |
| 221 | 412 | kCheatFlag_Dirty |
| 222 | 413 | }; |
| 223 | 414 | |
| r2762 | r2763 | |
| 261 | 452 | |
| 262 | 453 | enum // default search regions |
| 263 | 454 | { |
| 264 | | kSearchSpeed_Fast = 0, // RAM + some banks |
| 265 | | kSearchSpeed_Medium, // RAM + BANKx |
| 266 | | kSearchSpeed_Slow, // all memory areas except ROM, NOP, and custom handlers |
| 267 | | kSearchSpeed_VerySlow, // all memory areas except ROM and NOP |
| 268 | | kSearchSpeed_AllMemory, // entire CPU address space |
| 455 | ksearch_speed_Fast = 0, // RAM + some banks |
| 456 | ksearch_speed_Medium, // RAM + BANKx |
| 457 | ksearch_speed_Slow, // all memory areas except ROM, NOP, and custom handlers |
| 458 | ksearch_speed_VerySlow, // all memory areas except ROM and NOP |
| 459 | ksearch_speed_AllMemory, // entire CPU address space |
| 460 | ksearch_speed_UserDefined, // user defined region |
| 269 | 461 | |
| 270 | | kSearchSpeed_Max = kSearchSpeed_AllMemory |
| 462 | ksearch_speed_Max |
| 271 | 463 | }; |
| 272 | 464 | |
| 273 | 465 | /********** SEARCH **********/ |
| r2762 | r2763 | |
| 282 | 474 | kSearchOperand_Max = kSearchOperand_Value |
| 283 | 475 | }; |
| 284 | 476 | |
| 285 | | enum // bits |
| 477 | enum // length |
| 286 | 478 | { |
| 287 | 479 | kSearchSize_8Bit = 0, |
| 288 | 480 | kSearchSize_16Bit, |
| r2762 | r2763 | |
| 316 | 508 | kHorizontalSlowKeyRepeatRate = 8 |
| 317 | 509 | }; |
| 318 | 510 | |
| 319 | | enum |
| 511 | enum // search menu |
| 320 | 512 | { |
| 321 | 513 | kSearchBox_Minimum = 0, |
| 322 | | kSearchBox_Classic, |
| 514 | kSearchBox_Standard, |
| 323 | 515 | kSearchBox_Advanced |
| 324 | 516 | }; |
| 325 | 517 | |
| 518 | enum // load flags |
| 519 | { |
| 520 | kLoadFlag_CheatOption = 1, |
| 521 | kLoadFlag_CheatCode = 1 << 1, |
| 522 | kLoadFlag_UserRegion = 1 << 2 |
| 523 | }; |
| 524 | |
| 525 | enum // message types |
| 526 | { |
| 527 | kCheatMessage_None = 0, |
| 528 | kCheatMessage_ReloadCheatOption, |
| 529 | kCheatMessage_ReloadCheatCode, |
| 530 | kCheatMessage_ReloadUserRegion, |
| 531 | kCheatMessage_FailedToLoadDatabase, |
| 532 | kCheatMessage_CheatFound, |
| 533 | kCheatMessage_1CheatFound, |
| 534 | kCheatMessage_SucceededToSave, |
| 535 | kCheatMessage_FailedToSave, |
| 536 | kCheatMessage_AllCheatSaved, |
| 537 | kCheatMessage_ActivationKeySaved, |
| 538 | kCheatMessage_NoActivationKey, |
| 539 | kCheatMessage_PreEnableSaved, |
| 540 | kCheatMessage_SucceededToAdd, |
| 541 | kCheatMessage_FailedToAdd, |
| 542 | kCheatMessage_SucceededToDelete, |
| 543 | kCheatMessage_FailedToDelete, |
| 544 | kCheatMessage_NoSearchRegion, |
| 545 | kCheatMessage_RestoreValue, |
| 546 | kCheatMessage_NoOldValue, |
| 547 | kCheatMessage_InitializeMemory, |
| 548 | kCheatMessage_InvalidatedRegion, |
| 549 | kCheatMessage_DebugOnly, |
| 550 | kCheatMessage_WrongCode, |
| 551 | |
| 552 | kCheatMessage_Max |
| 553 | }; |
| 554 | |
| 555 | enum{ // error flags |
| 556 | kErrorFlag_InvalidLocationType = 1, // old |
| 557 | kErrorFlag_InvalidOperation = 1 << 1, // old |
| 558 | kErrorFlag_InvalidCodeType = 1 << 2, // new |
| 559 | kErrorFlag_InvalidCondition = 1 << 3, // new |
| 560 | kErrorFlag_InvalidCodeOption = 1 << 4, // new |
| 561 | kErrorFlag_ConflictedExtendField = 1 << 5, // old |
| 562 | kErrorFlag_InvalidRange = 1 << 6, |
| 563 | kErrorFlag_NoRestorePreviousValue = 1 << 7, |
| 564 | kErrorFlag_NoLabel = 1 << 8, |
| 565 | kErrorFlag_ConflictedSelects = 1 << 9, |
| 566 | kErrorFlag_CopyLinkWithoutSelect = 1 << 10, // new |
| 567 | kErrorFlag_InvalidDataField = 1 << 11, |
| 568 | kErrorFlag_InvalidExtendDataField = 1 << 12, |
| 569 | kErrorFlag_ForbittenVariable = 1 << 13, // new |
| 570 | kErrorFlag_NoSelectableValue = 1 << 14, |
| 571 | kErrorFlag_NoRepeatCount = 1 << 15, // new |
| 572 | kErrorFlag_UndefinedAddressRead = 1 << 16, // new |
| 573 | kErrorFlag_AddressVariableOutRange = 1 << 17, // new |
| 574 | kErrorFlag_DataVariableOutRange = 1 << 18, // new |
| 575 | kErrorFlag_OutOfCPURegion = 1 << 19, |
| 576 | kErrorFlag_InvalidCPURegion = 1 << 20, |
| 577 | kErrorFlag_InvalidAddressSpace = 1 << 21, // new |
| 578 | kErrorFlag_RegionOutOfRange = 1 << 22, |
| 579 | kErrorFlag_InvalidCustomCode = 1 << 23, // new |
| 580 | |
| 581 | kErrorFlag_Max = 24 }; |
| 582 | |
| 326 | 583 | /*************************************************************************** |
| 327 | 584 | TYPE DEFINITIONS |
| 328 | 585 | ***************************************************************************/ |
| r2762 | r2763 | |
| 331 | 588 | |
| 332 | 589 | struct CheatAction |
| 333 | 590 | { |
| 334 | | UINT32 type; |
| 335 | | UINT32 address; |
| 336 | | UINT32 data; |
| 337 | | UINT32 extendData; |
| 338 | | UINT32 originalDataField; |
| 591 | UINT32 type; // packed several information (cpu/region, address size, operation and parameters and so on) |
| 592 | UINT8 region; // the number of cpu or region. in case of cpu, it has a kind of an address space together |
| 593 | UINT32 address; // address. it is changeable by RWrite in the cheat core |
| 594 | UINT32 originalAddress; // address. it is for edit/view/save |
| 595 | UINT32 data; // data. it is changeable by VWrite/VRWrite in the cheat core |
| 596 | UINT32 originalDataField; // data. it is for edit/view/save |
| 597 | UINT32 extendData; // extend parameter. it is different using by each operations |
| 339 | 598 | |
| 340 | | INT32 frameTimer; |
| 341 | | UINT32 lastValue; |
| 599 | INT32 frameTimer; // timer for delay, keep |
| 600 | UINT32 * lastValue; // back up value before cheating to restore value. PDWWrite uses 2 and RWrite uses about a counter |
| 342 | 601 | |
| 343 | | UINT32 flags; |
| 602 | UINT32 flags; // internal flags |
| 344 | 603 | |
| 345 | | UINT8 ** cachedPointer; |
| 346 | | UINT32 cachedOffset; |
| 604 | UINT8 ** cachedPointer; // pointer for data, I/O space or non-cpu region |
| 605 | UINT32 cachedOffset; // offset for mapped memory |
| 347 | 606 | |
| 348 | | char * optionalName; |
| 607 | char * optionalName; // name to display in edit/view menu. Action doesn't have a comment |
| 349 | 608 | }; |
| 350 | 609 | |
| 351 | 610 | typedef struct CheatAction CheatAction; |
| r2762 | r2763 | |
| 354 | 613 | |
| 355 | 614 | struct CheatEntry |
| 356 | 615 | { |
| 357 | | char * name; |
| 358 | | char * comment; |
| 616 | char * name; // name to display in list menu |
| 617 | char * comment; // comment |
| 359 | 618 | |
| 360 | | INT32 actionListLength; |
| 619 | INT32 actionListLength; // minimum length = 1 |
| 361 | 620 | CheatAction * actionList; |
| 362 | 621 | |
| 363 | | int activationKey1; |
| 364 | | int activationKey2; |
| 622 | int activationKey1; // activation key index for 1st key |
| 623 | int activationKey2; // activation key index for 2nd key |
| 365 | 624 | |
| 366 | | UINT32 flags; |
| 367 | | int selection; |
| 625 | int selection; // for label-select to set selected label number |
| 626 | int labelIndexLength; // minimum length = 1 |
| 627 | int * labelIndex; // label index table |
| 628 | int layerIndex; // layer index for enable/disable menu |
| 629 | |
| 630 | UINT32 flags; // internal flags |
| 368 | 631 | }; |
| 369 | 632 | |
| 370 | 633 | typedef struct CheatEntry CheatEntry; |
| r2762 | r2763 | |
| 386 | 649 | INT8 dataShift; |
| 387 | 650 | UINT32 xor; |
| 388 | 651 | |
| 389 | | UINT8 locationType; |
| 390 | | |
| 391 | 652 | float x, y; |
| 392 | 653 | |
| 393 | 654 | CheatEntry * linkedCheat; |
| r2762 | r2763 | |
| 399 | 660 | |
| 400 | 661 | /********** REGION **********/ |
| 401 | 662 | |
| 402 | | struct SearchRegion |
| 663 | typedef struct _search_region search_region; |
| 664 | struct _search_region |
| 403 | 665 | { |
| 404 | 666 | UINT32 address; |
| 405 | 667 | UINT32 length; |
| 406 | 668 | |
| 407 | | UINT8 targetType; |
| 408 | | UINT8 targetIdx; |
| 669 | UINT8 target_type; |
| 670 | UINT8 target_idx; |
| 409 | 671 | |
| 410 | 672 | UINT8 flags; |
| 411 | 673 | |
| 412 | | UINT8 * cachedPointer; |
| 674 | UINT8 ** cached_pointer; |
| 413 | 675 | const address_map_entry |
| 414 | | * writeHandler; |
| 676 | * write_handler; |
| 415 | 677 | |
| 416 | 678 | UINT8 * first; |
| 417 | 679 | UINT8 * last; |
| 418 | 680 | |
| 419 | 681 | UINT8 * status; |
| 420 | 682 | |
| 421 | | UINT8 * backupLast; |
| 422 | | UINT8 * backupStatus; |
| 683 | UINT8 * backup_last; |
| 684 | UINT8 * backup_status; |
| 423 | 685 | |
| 424 | | char name[32]; // 12345678 - 12345678 BANK31 |
| 686 | char name[64]; |
| 425 | 687 | |
| 426 | | UINT32 numResults; |
| 427 | | UINT32 oldNumResults; |
| 688 | UINT32 num_results; |
| 689 | UINT32 old_num_results; |
| 428 | 690 | }; |
| 429 | 691 | |
| 430 | | typedef struct SearchRegion SearchRegion; |
| 431 | | |
| 432 | 692 | /********** SEARCH **********/ |
| 433 | 693 | |
| 434 | | struct OldSearchOptions |
| 694 | typedef struct _old_search_options old_search_options; |
| 695 | struct _old_search_options |
| 435 | 696 | { |
| 436 | | UINT8 status; |
| 437 | | UINT8 energy; |
| 438 | | UINT8 operand; |
| 697 | INT8 comparison; |
| 439 | 698 | UINT32 value; |
| 699 | INT8 sign; |
| 440 | 700 | UINT32 delta; |
| 441 | 701 | }; |
| 442 | 702 | |
| 443 | | typedef struct OldSearchOptions OldSearchOptions; |
| 444 | | |
| 445 | | struct SearchInfo |
| 703 | typedef struct _search_info search_info; |
| 704 | struct _search_info |
| 446 | 705 | { |
| 447 | | INT32 regionListLength; |
| 448 | | SearchRegion * regionList; |
| 706 | INT32 region_list_length; |
| 707 | search_region *region_list; |
| 449 | 708 | |
| 450 | | char * name; |
| 709 | char *name; /* search info name used in select_region() */ |
| 451 | 710 | |
| 452 | | INT8 bytes; // 0 = 1, 1 = 2, 2 = 3, 3 = 4, 4 = bit |
| 711 | INT8 bytes; /* 0 = 1, 1 = 2, 2 = 3, 3 = 4, 4 = bit */ |
| 453 | 712 | UINT8 swap; |
| 454 | 713 | UINT8 sign; |
| 455 | 714 | INT8 lhs; |
| 456 | 715 | INT8 rhs; |
| 457 | 716 | INT8 comparison; |
| 458 | 717 | |
| 459 | | UINT8 targetType; // cpu/region |
| 460 | | UINT8 targetIdx; // cpu or region index |
| 718 | UINT8 target_type; /* is cpu or region? */ |
| 719 | UINT8 target_idx; /* index for cpu or region */ |
| 461 | 720 | |
| 462 | 721 | UINT32 value; |
| 463 | 722 | |
| 464 | | UINT8 searchSpeed; |
| 723 | INT8 search_speed; |
| 465 | 724 | |
| 466 | | UINT32 numResults; |
| 467 | | UINT32 oldNumResults; |
| 725 | UINT32 num_results; |
| 726 | UINT32 old_num_results; |
| 468 | 727 | |
| 469 | | INT32 currentRegionIdx; |
| 470 | | INT32 currentResultsPage; |
| 728 | INT32 current_region_idx; |
| 729 | INT32 current_results_page; |
| 471 | 730 | |
| 472 | | UINT8 backupValid; |
| 731 | UINT8 backup_valid; |
| 473 | 732 | |
| 474 | | OldSearchOptions oldOptions; |
| 733 | old_search_options old_options; |
| 475 | 734 | }; |
| 476 | 735 | |
| 477 | | typedef struct SearchInfo SearchInfo; |
| 478 | | |
| 479 | 736 | /********** CPU **********/ |
| 480 | 737 | |
| 481 | | struct CPUInfo |
| 738 | typedef struct _cpu_region_info cpu_region_info; |
| 739 | struct _cpu_region_info |
| 482 | 740 | { |
| 483 | | UINT8 type; |
| 484 | | UINT8 dataBits; |
| 485 | | UINT8 addressBits; |
| 486 | | UINT8 addressCharsNeeded; |
| 487 | | UINT32 addressMask; |
| 488 | | UINT8 endianness; |
| 489 | | UINT8 addressShift; |
| 741 | UINT8 type; /* cpu or region type */ |
| 742 | UINT8 data_bits; /* data bits */ |
| 743 | UINT8 address_bits; /* address bits */ |
| 744 | UINT8 address_chars_needed; /* length of address */ |
| 745 | UINT32 address_mask; /* address mask */ |
| 746 | UINT8 endianness; /* endianness */ |
| 747 | UINT8 address_shift; /* address shift */ |
| 490 | 748 | }; |
| 491 | 749 | |
| 492 | | typedef struct CPUInfo CPUInfo; |
| 750 | /********** STRINGS **********/ |
| 493 | 751 | |
| 494 | | /********** MENU **********/ |
| 495 | | |
| 496 | | struct MenuStringList |
| 752 | typedef struct _menu_string_list menu_string_list; |
| 753 | struct _menu_string_list |
| 497 | 754 | { |
| 498 | | const char ** mainList; // editable menu item lists |
| 499 | | const char ** subList; |
| 500 | | char * flagList; |
| 755 | const char **main_list; /* main item field in menu items */ |
| 756 | const char **sub_list; /* sub item field in menu items */ |
| 757 | char *flag_list; /* flag of highlight for sub menu field */ |
| 501 | 758 | |
| 502 | | char ** mainStrings; // lists of useable strings |
| 503 | | char ** subStrings; |
| 759 | char **main_strings; /* strings buffer 1 */ |
| 760 | char **sub_strings; /* strings buffer 2 */ |
| 504 | 761 | |
| 505 | | char * buf; // string storage |
| 762 | char *buf; /* internal buffer? (only used in rebuild_string_tables()) */ |
| 506 | 763 | |
| 507 | | UINT32 length; // number of menu items supported |
| 508 | | UINT32 numStrings; // number of strings supported |
| 509 | | UINT32 mainStringLength; // max length of main string |
| 510 | | UINT32 subStringLength; // max length of sub string |
| 764 | UINT32 length; /* number of total menu items */ |
| 765 | UINT32 num_strings; /* number of strings buffer */ |
| 766 | UINT32 main_string_length; /* length of string in strings buffer 1 */ |
| 767 | UINT32 sub_string_length; /* length of string in strings buffer 2 */ |
| 511 | 768 | }; |
| 512 | 769 | |
| 513 | | typedef struct MenuStringList MenuStringList; |
| 770 | /********** MENUS **********/ |
| 514 | 771 | |
| 515 | | struct MenuItemInfoStruct |
| 772 | /* NOTE : _cheat_menu_item_info is used in the edit menu right now */ |
| 773 | typedef struct _cheat_menu_item_info cheat_menu_item_info; |
| 774 | struct _cheat_menu_item_info |
| 516 | 775 | { |
| 517 | | UINT32 subcheat; |
| 518 | | UINT32 fieldType; |
| 519 | | UINT32 extraData; |
| 776 | UINT32 sub_cheat; /* the number of an item */ |
| 777 | UINT32 field_type; /* field type of an item */ |
| 778 | UINT32 extra_data; /* it stores an extra data but NOT read (so I don't know how to use)*/ |
| 520 | 779 | }; |
| 521 | 780 | |
| 522 | | typedef struct MenuItemInfoStruct MenuItemInfoStruct; |
| 781 | typedef struct _cheat_menu_stack cheat_menu_stack; |
| 782 | typedef int (*cheat_menu_handler)(running_machine *machine, cheat_menu_stack *menu); |
| 783 | struct _cheat_menu_stack |
| 784 | { |
| 785 | cheat_menu_handler handler; /* menu handler for cheat */ |
| 786 | cheat_menu_handler return_handler; /* menu handler to return menu */ |
| 787 | int sel; /* current cursor position */ |
| 788 | int pre_sel; /* selected item in previous menu */ |
| 789 | UINT8 first_time; /* flags to first setting (1 = first, 0 = not first) */ |
| 790 | }; |
| 523 | 791 | |
| 792 | /********** FORMAT **********/ |
| 793 | typedef const struct _cheat_format cheat_format; |
| 794 | struct _cheat_format |
| 795 | { |
| 796 | const char * format_string; /* string templete of a format */ |
| 797 | UINT8 arguments_matched; /* valid arguments of a format */ |
| 798 | UINT8 length_matched; /* valid length of a parameter */ |
| 799 | UINT8 comment_matched; /* valid argument to add comment */ |
| 800 | }; |
| 801 | |
| 802 | static const struct _cheat_format cheat_format_table[] = |
| 803 | { |
| 804 | /* option - :_command:TYPE */ |
| 805 | { ":_command:%[^:\n\r]", 1, 8, 0 }, |
| 806 | #ifdef MESS |
| 807 | /* code (new) - >MACHINE_NAME:CRC:TYPE:ADDRESS:DATA:EXTEND_DATA:(DESCRIPTION:COMMENT) */ |
| 808 | { ">%8[^:\n\r]:%8X:%8X:%X:%8[^:\n\r]:%8[^:\n\r]:%[^:\n\r]:%[^:\n\r]", 6, 8, 8 }, |
| 809 | /* code (old) - :MACHINE_NAME:CRC:TYPE:ADDRESS:DATA:EXTEND_DATA:(DESCRIPTION:COMMENT) */ |
| 810 | { ":%8s:%8X:%8X:%X:%8[^:\n\r]:%8[^:\n\r]:%[^:\n\r]:%[^:\n\r]", 6, 8, 0 }, |
| 811 | /* code (older) - :MACHINE_NAME:CRC:CPU:ADDRESS:DATA:TYPE:(DESCRIPTION:COMMENT) */ |
| 812 | { "%8[^:\n\r]:%8X:%d:%X:%X:%d:%[^:\n\r]:%[^:\n\r]", 5, 0, 8 }, |
| 813 | /* user region - :MACHINE_NAME:CRC:CPU:ADDRESS_SPACE:START_ADDRESS:END_ADDRESS:STATUS:(DESCRIPTION) */ |
| 814 | { ">%8[^:\n\r]:%8X:%2X:%2X:%X:%X:%1X:%[^:\n\r]", 7, 0, 0 }, |
| 815 | #else |
| 816 | /* code (new) - >GAME_NAME:TYPE:ADDRESS:DATA:EXTEND_DATA:(DESCRIPTION:COMMENT) */ |
| 817 | { ">%8[^:\n\r]:%8X:%X:%8[^:\n\r]:%8[^:\n\r]:%[^:\n\r]:%[^:\n\r]", 5, 8, 7 }, |
| 818 | /* code (old) - :GAME_NAME:TYPE:ADDRESS:DATA:EXTEND_DATA:(DESCRIPTION:COMMENT) */ |
| 819 | { ":%8s:%8X:%X:%8[^:\n\r]:%8[^:\n\r]:%[^:\n\r]:%[^:\n\r]", 5, 8, 0 }, |
| 820 | /* code (older) - :GAME_NAME:CPU:ADDRESS:DATA:TYPE:(DESCRIPTION:COMMENT) */ |
| 821 | { "%8[^:\n\r]:%d:%X:%X:%d:%[^:\n\r]:%[^:\n\r]", 4, 0, 7 }, |
| 822 | /* user region - :GAME_NAME:CPU:ADDRESS_SPACE:START_ADDRESS:END_ADDRESS:STATUS:(DESCRIPTION) */ |
| 823 | { ">%8[^:\n\r]:%2X:%2X:%X:%X:%1X:%[^:\n\r]", 6, 0, 0 }, |
| 824 | #endif /* MESS */ |
| 825 | /* end of table */ |
| 826 | { 0 } |
| 827 | }; |
| 828 | |
| 524 | 829 | /*************************************************************************** |
| 525 | 830 | EXPORTED VARIABLES |
| 526 | 831 | ***************************************************************************/ |
| r2762 | r2763 | |
| 534 | 839 | static emu_timer * periodic_timer; |
| 535 | 840 | |
| 536 | 841 | static CheatEntry * cheatList = NULL; |
| 537 | | static INT32 cheatListLength = 0; |
| 842 | static INT32 cheatListLength = 0; // NOTE : 0 means no cheat entry and error |
| 538 | 843 | |
| 539 | 844 | static WatchInfo * watchList = NULL; |
| 540 | 845 | static INT32 watchListLength = 0; |
| 541 | 846 | |
| 542 | | static SearchInfo * searchList = NULL; |
| 543 | | static INT32 searchListLength = 0; |
| 544 | | static INT32 currentSearchIdx = 0; |
| 847 | static search_info *search_list = NULL; |
| 848 | static INT32 search_list_length = 0; |
| 849 | static INT32 current_search_idx = 0; |
| 545 | 850 | |
| 546 | | static CPUInfo cpuInfoList[MAX_CPU]; |
| 547 | | static CPUInfo regionInfoList[kRegionListLength]; |
| 851 | static cpu_region_info cpu_info_list[MAX_CPU]; |
| 852 | static cpu_region_info region_info_list[REGION_LIST_LENGTH]; |
| 548 | 853 | |
| 549 | | //static int cheatEngineWasActive = 0; |
| 550 | 854 | static int foundCheatDatabase = 0; |
| 551 | 855 | static int cheatsDisabled = 0; |
| 552 | 856 | static int watchesDisabled = 0; |
| 553 | 857 | |
| 554 | | static int fullMenuPageHeight = 0; |
| 858 | static int fullMenuPageHeight; |
| 859 | static int visible_items; |
| 555 | 860 | |
| 556 | 861 | static char mainDatabaseName[CHEAT_FILENAME_MAX_LEN + 1]; |
| 557 | 862 | |
| 558 | | static MenuStringList menuStrings; |
| 863 | static menu_string_list menu_strings; |
| 559 | 864 | |
| 560 | | static MenuItemInfoStruct * menuItemInfo; |
| 865 | static cheat_menu_item_info * menu_item_info; |
| 561 | 866 | static INT32 menuItemInfoLength = 0; |
| 562 | 867 | |
| 563 | | static UINT32 cheatOptions = 2; |
| 868 | static UINT8 editActive; |
| 869 | static INT8 editCursor; |
| 564 | 870 | |
| 565 | | static const char *const kCheatNameTemplates[] = |
| 566 | | { |
| 567 | | "Infinite Credits", |
| 568 | | "Infinite Time", |
| 569 | | "Infinite Lives", |
| 570 | | "Infinite Energy", |
| 571 | | "Invincibility", |
| 572 | | "Infinite Time PL1", |
| 573 | | "Infinite Lives PL1", |
| 574 | | "Infinite Energy PL1", |
| 575 | | "Drain all Energy Now! PL1", |
| 576 | | "Invincibility PL1", |
| 577 | | "Infinite Time PL2", |
| 578 | | "Infinite Lives PL2", |
| 579 | | "Infinite Energy PL2", |
| 580 | | "Drain all Energy Now! PL2", |
| 581 | | "Invincibility PL2", |
| 582 | | "Infinite Ammo", |
| 583 | | "Infinite Bombs", |
| 584 | | "Select starting level", |
| 585 | | "Rapid Fire", |
| 586 | | "Infinite Ammo PL1", |
| 587 | | "Infinite Bombs PL1", |
| 588 | | "Select Score PL1", |
| 589 | | "Rapid Fire PL1", |
| 590 | | "Infinite Ammo PL2", |
| 591 | | "Infinite Bombs PL2", |
| 592 | | "Select Score PL2", |
| 593 | | "Rapid Fire PL2", |
| 594 | | "Display the Correct Answer", |
| 595 | | "Infinite ", |
| 596 | | "Always have ", |
| 597 | | "Get ", |
| 598 | | "Lose ", |
| 599 | | "Finish this ", |
| 600 | | "---> <ENTER> To Edit <---", |
| 601 | | "\0" |
| 602 | | }; |
| 871 | static INT8 stack_index; |
| 872 | static cheat_menu_stack menu_stack[CHEAT_MENU_DEPTH]; |
| 603 | 873 | |
| 604 | | static CPUInfo rawCPUInfo = |
| 874 | static int cheatVariable[VARIABLE_MAX_ARRAY] = { 0 }; |
| 875 | |
| 876 | static UINT32 cheatOptions; |
| 877 | static UINT32 driverSpecifiedFlag; |
| 878 | static UINT8 messageType; |
| 879 | static UINT8 messageTimer; |
| 880 | |
| 881 | static cpu_region_info raw_cpu_info = |
| 605 | 882 | { |
| 606 | | 0, // type |
| 607 | | 8, // dataBits |
| 608 | | 8, // addressBits |
| 609 | | 1, // addressCharsNeeded |
| 610 | | CPU_IS_BE // endianness |
| 883 | 0, /* type */ |
| 884 | 8, /* data_bits */ |
| 885 | 8, /* address_bits */ |
| 886 | 1, /* address_chars_needed */ |
| 887 | CPU_IS_BE, /* endianness */ |
| 888 | 0, /* address_shift */ |
| 611 | 889 | }; |
| 612 | 890 | |
| 613 | 891 | static const int kSearchByteIncrementTable[] = |
| r2762 | r2763 | |
| 723 | 1001 | 0x01 |
| 724 | 1002 | }; |
| 725 | 1003 | |
| 1004 | static const UINT32 kIncrementValueTable[] = |
| 1005 | { |
| 1006 | 0x00000001, |
| 1007 | 0x00000010, |
| 1008 | 0x00000100, |
| 1009 | 0x00001000, |
| 1010 | 0x00010000, |
| 1011 | 0x00100000, |
| 1012 | 0x01000000, |
| 1013 | 0x10000000 |
| 1014 | }; |
| 1015 | |
| 1016 | static const UINT32 kIncrementMaskTable[] = |
| 1017 | { |
| 1018 | 0x0000000F, |
| 1019 | 0x000000F0, |
| 1020 | 0x00000F00, |
| 1021 | 0x0000F000, |
| 1022 | 0x000F0000, |
| 1023 | 0x00F00000, |
| 1024 | 0x0F000000, |
| 1025 | 0xF0000000 |
| 1026 | }; |
| 1027 | |
| 1028 | static const UINT32 kIncrementDecTable[] = |
| 1029 | { |
| 1030 | 0x00000009, |
| 1031 | 0x00000090, |
| 1032 | 0x00000900, |
| 1033 | 0x00009000, |
| 1034 | 0x00090000, |
| 1035 | 0x00900000, |
| 1036 | 0x09000000, |
| 1037 | 0x90000000 |
| 1038 | }; |
| 1039 | |
| 1040 | static const char *const kRegionNames[] = { |
| 1041 | "INVALID", |
| 1042 | "CPU1", "CPU2", "CPU3", "CPU4", "CPU5", "CPU6", "CPU7", "CPU8", // 01-08 [01-08] : CPU |
| 1043 | "GFX1", "GFX2", "GFX3", "GFX4", "GFX5", "GFX6", "GFX7", "GFX8", // 09-16 [08-10] : GFX |
| 1044 | "PROMS", // 17 [11] : PROMS |
| 1045 | "SOUND1", "SOUND2", "SOUND3", "SOUND4", "SOUND5", "SOUND6", "SOUND7", "SOUND8", // 18-25 [12-19] : SOUND |
| 1046 | "USER1", "USER2", "USER3", "USER4", "USER5", "USER6", "USER7", "USER8", // 26-45 [1A-2D] : USER |
| 1047 | /* USER9 - PLDS are undefined in old format */ |
| 1048 | "USER9", "USER10", "USER11", "USER12", "USER13", "USER14", "USER15", "USER16", |
| 1049 | "USER17", "USER18", "USER19", "USER20", |
| 1050 | "DISKS", // 46 [2E] : DISKS |
| 1051 | "PLDS" }; // 47 [2F] : PLDS |
| 1052 | |
| 1053 | static const char *const kNumbersTable[] = { |
| 1054 | "0", "1", "2", "3", "4", "5", "6", "7", |
| 1055 | "8", "9", "10", "11", "12", "13", "14", "15", |
| 1056 | "16", "17", "18", "19", "20", "21", "22", "23", |
| 1057 | "24", "25", "26", "27", "28", "29", "30", "31" }; |
| 1058 | |
| 1059 | static const char *const kByteSizeStringList[] = |
| 1060 | { |
| 1061 | "8 Bit", |
| 1062 | "16 Bit", |
| 1063 | "24 Bit", |
| 1064 | "32 Bit" |
| 1065 | }; |
| 1066 | |
| 726 | 1067 | static const char *const kWatchLabelStringList[] = |
| 727 | 1068 | { |
| 728 | 1069 | "None", |
| r2762 | r2763 | |
| 742 | 1083 | FUNCTION PROTOTYPES |
| 743 | 1084 | ***************************************************************************/ |
| 744 | 1085 | |
| 745 | | /********** MAIN **********/ |
| 746 | 1086 | static TIMER_CALLBACK( cheat_periodic ); |
| 747 | 1087 | static void cheat_exit(running_machine *machine); |
| 748 | 1088 | |
| r2762 | r2763 | |
| 751 | 1091 | static int ControlKeyPressed(void); |
| 752 | 1092 | static int AltKeyPressed(void); |
| 753 | 1093 | |
| 754 | | static int UIPressedRepeatThrottle(running_machine *machine, int code, int baseSpeed); |
| 1094 | static int ui_pressed_repeat_throttle(running_machine *machine, int code, int base_speed); |
| 755 | 1095 | |
| 756 | | /********** DIRECT KEY INPUT **********/ |
| 757 | | static int ReadHexInput(void); |
| 758 | | |
| 759 | | static char * DoDynamicEditTextField(char * buf); |
| 1096 | /********** KEY INPUT **********/ |
| 1097 | static int read_hex_input(void); |
| 1098 | #if 0 |
| 1099 | static char *DoDynamicEditTextField(char * buf); |
| 1100 | #endif |
| 760 | 1101 | static void DoStaticEditTextField(char * buf, int size); |
| 761 | | static UINT32 DoEditHexField(running_machine *machine, UINT32 data); |
| 1102 | static UINT32 do_edit_hex_field(running_machine *machine, UINT32 data); |
| 762 | 1103 | static UINT32 DoEditHexFieldSigned(UINT32 data, UINT32 mask); |
| 763 | 1104 | static INT32 DoEditDecField(INT32 data, INT32 min, INT32 max); |
| 1105 | static UINT32 DoIncrementHexField(UINT32 data, UINT8 digits); |
| 1106 | static UINT32 DoDecrementHexField(UINT32 data, UINT8 digits); |
| 1107 | static UINT32 DoIncrementHexFieldSigned(UINT32 data, UINT8 digits, UINT8 bytes); |
| 1108 | static UINT32 DoDecrementHexFieldSigned(UINT32 data, UINT8 digits, UINT8 bytes); |
| 1109 | static UINT32 DoIncrementDecField(UINT32 data, UINT8 digits); |
| 1110 | static UINT32 DoDecrementDecField(UINT32 data, UINT8 digits); |
| 764 | 1111 | |
| 765 | | /********** VALUE SHIFT OR CONVERTION **********/ |
| 766 | | static UINT32 DoShift(UINT32 input, INT8 shift); |
| 767 | | |
| 1112 | /********** VALUE CONVERTER **********/ |
| 768 | 1113 | static UINT32 BCDToDecimal(UINT32 value); |
| 769 | 1114 | static UINT32 DecimalToBCD(UINT32 value); |
| 770 | 1115 | |
| 771 | 1116 | /********** STRINGS **********/ |
| 772 | | static void RebuildStringTables(void); |
| 773 | | static void RequestStrings(UINT32 length, UINT32 numStrings, UINT32 mainStringLength, UINT32 subStringLength); |
| 774 | | static void InitStringTable(void); |
| 775 | | static void FreeStringTable(void); |
| 1117 | static void rebuild_string_tables(void); |
| 1118 | static void request_strings(UINT32 length, UINT32 num_strings, UINT32 main_string_length, UINT32 sub_string_length); |
| 1119 | static void init_string_table(void); |
| 1120 | static void free_string_table(void); |
| 776 | 1121 | |
| 777 | | static char * CreateStringCopy(char * buf); |
| 1122 | static char *create_string_copy(char *buf); |
| 778 | 1123 | |
| 1124 | /********** MENU EXPORTER **********/ |
| 1125 | static void old_style_menu(const char **items, const char **sub_items, char *flag, int selected, int arrowize_subitem); |
| 1126 | |
| 1127 | /********** MENU STACK **********/ |
| 1128 | static void init_cheat_menu_stack(void); |
| 1129 | static void cheat_menu_stack_push(cheat_menu_handler new_handler, cheat_menu_handler ret_handler, int selection); |
| 1130 | static void cheat_menu_stack_pop(void); |
| 1131 | static void free_cheat_menu_stack(void); |
| 1132 | |
| 779 | 1133 | /********** ADDITIONAL MENU FOR CHEAT **********/ |
| 780 | | static INT32 UserSelectValueMenu(running_machine *machine, int selection, CheatEntry * entry); |
| 1134 | static int user_select_value_menu(running_machine *machine, cheat_menu_stack *menu); |
| 1135 | static int user_select_label_menu(running_machine *machine, cheat_menu_stack *menu); |
| 1136 | static int comment_menu(running_machine *machine, cheat_menu_stack *menu); |
| 1137 | static int extend_comment_menu(running_machine *machine, cheat_menu_stack *menu); |
| 781 | 1138 | |
| 782 | 1139 | /********** CHEAT MENU **********/ |
| 783 | | static int EnableDisableCheatMenu(running_machine *machine, int selection, int firstTime); |
| 784 | | static int AddEditCheatMenu(running_machine *machine, int selection); |
| 785 | | static int EditCheatMenu(running_machine *machine, CheatEntry * entry, int index, int selection); |
| 1140 | static int cheat_main_menu(running_machine *machine, cheat_menu_stack *menu); |
| 1141 | static int enable_disable_cheat_menu(running_machine *machine, cheat_menu_stack *menu); |
| 1142 | static int add_edit_cheat_menu(running_machine *machine, cheat_menu_stack *menu); |
| 1143 | static int command_add_edit_menu(running_machine *machine, cheat_menu_stack *menu); |
| 1144 | static int edit_cheat_menu(running_machine *machine, cheat_menu_stack *menu); |
| 1145 | static int view_cheat_menu(running_machine *machine, cheat_menu_stack *menu); |
| 1146 | static int analyse_cheat_menu(running_machine *machine, cheat_menu_stack *menu); |
| 786 | 1147 | |
| 787 | | static int DoSearchMenuMinimum(running_machine *machine, int selection); // minimum mode |
| 788 | | static int DoSearchMenuClassic(running_machine *machine, int selection); // classic mode |
| 789 | | static int DoSearchMenu(running_machine *machine, int selection); // advanced mode |
| 790 | | static int SelectSearchRegions(running_machine *machine, int selection, SearchInfo * search); |
| 791 | | static int ViewSearchResults(running_machine *machine, int selection, int firstTime); |
| 1148 | static int search_minimum_menu(running_machine *machine, cheat_menu_stack *menu); |
| 1149 | static int search_standard_menu(running_machine *machine, cheat_menu_stack *menu); |
| 1150 | static int search_advanced_menu(running_machine *machine, cheat_menu_stack *menu); |
| 1151 | static int select_search_region_menu(running_machine *machine, cheat_menu_stack *menu); |
| 1152 | static int view_search_result_menu(running_machine *machine, cheat_menu_stack *menu); |
| 792 | 1153 | |
| 793 | | static int ChooseWatch(running_machine *machine, int selection); |
| 794 | | static int EditWatch(running_machine *machine, WatchInfo * entry, int selection); |
| 1154 | static int choose_watch_menu(running_machine *machine, cheat_menu_stack *menu); |
| 1155 | static int command_watch_menu(running_machine *machine, cheat_menu_stack *menu); |
| 1156 | static int edit_watch_menu(running_machine *machine, cheat_menu_stack *menu); |
| 795 | 1157 | |
| 796 | | static int SelectOptions(running_machine *machine, int selection); |
| 797 | | static int SelectSearch(running_machine *machine, int selection); |
| 1158 | static int select_option_menu(running_machine *machine, cheat_menu_stack *menu); |
| 1159 | static int select_search_menu(running_machine *machine, cheat_menu_stack *menu); |
| 798 | 1160 | |
| 1161 | #ifdef MAME_DEBUG |
| 1162 | static int check_activation_key_code_menu(running_machine *machine, cheat_menu_stack *menu); |
| 1163 | static int view_cpu_region_info_list_menu(running_machine *machine, cheat_menu_stack *menu); |
| 1164 | static int debug_cheat_menu(running_machine *machine, cheat_menu_stack *menu); |
| 1165 | #endif |
| 1166 | |
| 799 | 1167 | /********** ENTRY LIST **********/ |
| 800 | 1168 | static void ResizeCheatList(UINT32 newLength); |
| 801 | 1169 | static void ResizeCheatListNoDispose(UINT32 newLength); |
| r2762 | r2763 | |
| 804 | 1172 | static void DeleteCheatAt(UINT32 idx); |
| 805 | 1173 | |
| 806 | 1174 | static void DisposeCheat(CheatEntry * entry); |
| 807 | | static CheatEntry * GetNewCheat(void); |
| 1175 | static CheatEntry |
| 1176 | *GetNewCheat(void); |
| 808 | 1177 | |
| 809 | 1178 | /********** ACTION LIST **********/ |
| 810 | 1179 | static void ResizeCheatActionList(CheatEntry * entry, UINT32 newLength); |
| 1180 | #if 0 |
| 811 | 1181 | static void ResizeCheatActionListNoDispose(CheatEntry * entry, UINT32 newLength); |
| 812 | 1182 | |
| 813 | 1183 | static void AddActionBefore(CheatEntry * entry, UINT32 idx); |
| 814 | 1184 | static void DeleteActionAt(CheatEntry * entry, UINT32 idx); |
| 1185 | #endif |
| 815 | 1186 | static void DisposeAction(CheatAction * action); |
| 816 | 1187 | |
| 817 | 1188 | /********** WATCH LIST **********/ |
| r2762 | r2763 | |
| 822 | 1193 | static void AddWatchBefore(UINT32 idx); |
| 823 | 1194 | static void DeleteWatchAt(UINT32 idx); |
| 824 | 1195 | static void DisposeWatch(WatchInfo * watch); |
| 825 | | static WatchInfo * GetUnusedWatch(void); |
| 1196 | static WatchInfo |
| 1197 | *GetUnusedWatch(void); |
| 826 | 1198 | |
| 827 | 1199 | static void AddCheatFromWatch(WatchInfo * watch); |
| 828 | 1200 | static void SetupCheatFromWatchAsWatch(CheatEntry * entry, WatchInfo * watch); |
| 829 | 1201 | |
| 1202 | static void ResetWatch(WatchInfo * watch); |
| 1203 | |
| 830 | 1204 | /********** SEARCH LIST **********/ |
| 831 | | static void ResizeSearchList(UINT32 newLength); |
| 832 | | static void ResizeSearchListNoDispose(UINT32 newLength); |
| 1205 | static void resize_search_list(UINT32 newLength); |
| 1206 | #if 0 |
| 1207 | static void resize_search_list_no_dispose(UINT32 new_length); |
| 1208 | static void add_search_before(UINT32 idx); |
| 1209 | static void delete_search_at(UINT32 idx); |
| 1210 | #endif |
| 1211 | static void init_search(search_info *info); |
| 833 | 1212 | |
| 834 | | static void AddSearchBefore(UINT32 idx); |
| 835 | | static void DeleteSearchAt(UINT32 idx); |
| 1213 | static void dispose_search_reigons(search_info *info); |
| 1214 | static void dispose_search(search_info *info); |
| 1215 | static search_info |
| 1216 | *get_current_search(void); |
| 836 | 1217 | |
| 837 | | static void InitSearch(SearchInfo * info); |
| 1218 | static void fill_buffer_from_region(search_region *region, UINT8 *buf); |
| 1219 | static UINT32 read_region_data(search_region *region, UINT32 offset, UINT8 size, UINT8 swap); |
| 838 | 1220 | |
| 839 | | static void DisposeSearchRegions(SearchInfo * info); |
| 840 | | static void DisposeSearch(UINT32 idx); |
| 841 | | static SearchInfo * GetCurrentSearch(void); |
| 1221 | static void backup_search(search_info *info); |
| 1222 | static void restore_search_backup(search_info *info); |
| 1223 | static void backup_region(search_region *region); |
| 1224 | static void restore_region_backup(search_region *region); |
| 1225 | static UINT8 default_enable_region(running_machine *machine, search_region *region, search_info *info); |
| 1226 | static void set_search_region_default_name(search_region *region); |
| 1227 | static void allocate_search_regions(search_info *info); |
| 1228 | static void build_search_regions(running_machine *machine, search_info *info); |
| 842 | 1229 | |
| 843 | | static void FillBufferFromRegion(SearchRegion * region, UINT8 * buf); |
| 844 | | static UINT32 ReadRegionData(SearchRegion * region, UINT32 offset, UINT8 size, UINT8 swap); |
| 845 | | |
| 846 | | static void BackupSearch(SearchInfo * info); |
| 847 | | static void RestoreSearchBackup(SearchInfo * info); |
| 848 | | static void BackupRegion(SearchRegion * region); |
| 849 | | static void RestoreRegionBackup(SearchRegion * region); |
| 850 | | static void SetSearchRegionDefaultName(SearchRegion * region); |
| 851 | | static void AllocateSearchRegions(SearchInfo * info); |
| 852 | | static void BuildSearchRegions(running_machine *machine, SearchInfo * info); |
| 853 | | |
| 854 | | /********** CODE LOADER **********/ |
| 1230 | /********** LOADER **********/ |
| 855 | 1231 | static int ConvertOldCode(int code, int cpu, int * data, int * extendData); |
| 856 | | static void HandleLocalCommandCheat(running_machine *machine, UINT32 type, UINT32 address, UINT32 data, UINT32 extendData, char * name, char * description); |
| 1232 | static int ConvertToNewCode(CheatAction * action); |
| 1233 | static void HandleLocalCommandCheat(running_machine *machine, int cpu, int type, int address, int data, UINT8 format); |
| 857 | 1234 | |
| 858 | | static void LoadCheatFile(running_machine *machine, char * fileName); |
| 859 | | static void LoadCheatDatabase(running_machine *machine); |
| 1235 | static void LoadCheatOption(char * fileName); |
| 1236 | static void LoadCheatCode(running_machine *machine, char * fileName); |
| 1237 | static void LoadUserDefinedSearchRegion(running_machine *machine, char * fileName); |
| 1238 | static void LoadCheatDatabase(running_machine *machine, UINT8 flags); |
| 860 | 1239 | |
| 861 | 1240 | static void DisposeCheatDatabase(void); |
| 862 | 1241 | static void ReloadCheatDatabase(running_machine *machine); |
| 863 | 1242 | |
| 864 | | static void SaveCheat(running_machine *machine, CheatEntry * entry, int selection, int saveCode); |
| 1243 | /********** SAVER **********/ |
| 1244 | static void SaveCheatCode(running_machine *machine, CheatEntry * entry); |
| 1245 | static void SaveActivationKey(running_machine *machine, CheatEntry * entry, int entryIndex); |
| 1246 | static void SavePreEnable(running_machine *machine, CheatEntry * entry, int entryIndex); |
| 1247 | static void SaveCheatOptions(void); |
| 1248 | static void SaveDescription(running_machine *machine); |
| 865 | 1249 | static void DoAutoSaveCheats(running_machine *machine); |
| 866 | 1250 | |
| 867 | 1251 | /********** CODE ADDITION **********/ |
| 868 | | static void AddCheatFromResult(SearchInfo * search, SearchRegion * region, UINT32 address); |
| 869 | | static void AddCheatFromFirstResult(SearchInfo * search); |
| 870 | | static void AddWatchFromResult(SearchInfo * search, SearchRegion * region, UINT32 address); |
| 1252 | static void AddCheatFromResult(search_info *search, search_region *region, UINT32 address); |
| 1253 | static void AddCheatFromFirstResult(search_info *search); |
| 1254 | static void AddWatchFromResult(search_info *search, search_region *region, UINT32 address); |
| 871 | 1255 | |
| 872 | 1256 | /********** SEARCH **********/ |
| 873 | | static UINT32 SearchSignExtend(SearchInfo * search, UINT32 value); |
| 874 | | static UINT32 ReadSearchOperand(UINT8 type, SearchInfo * search, SearchRegion * region, UINT32 address); |
| 875 | | static UINT32 ReadSearchOperandBit(UINT8 type, SearchInfo * search, SearchRegion * region, UINT32 address); |
| 876 | | static UINT8 DoSearchComparison(SearchInfo * search, UINT32 lhs, UINT32 rhs); |
| 877 | | static UINT32 DoSearchComparisonBit(SearchInfo * search, UINT32 lhs, UINT32 rhs); |
| 878 | | //static UINT8 IsRegionOffsetValid(SearchInfo * search, SearchRegion * region, UINT32 offset); |
| 1257 | static UINT32 search_sign_extend(search_info *search, UINT32 value); |
| 1258 | static UINT32 read_search_operand(UINT8 type, search_info *search, search_region *region, UINT32 address); |
| 1259 | static UINT32 read_search_operand_bit(UINT8 type, search_info *search, search_region *region, UINT32 address); |
| 1260 | static UINT8 do_search_comparison(search_info *search, UINT32 lhs, UINT32 rhs); |
| 1261 | static UINT32 do_search_comparison_bit(search_info *search, UINT32 lhs, UINT32 rhs); |
| 1262 | #if 0 |
| 1263 | static UINT8 is_region_offset_valid(search_info *search, search_region *region, UINT32 offset); |
| 1264 | #else |
| 1265 | #define is_region_offset_valid is_region_offset_valid_bit /* ????? */ |
| 1266 | #endif |
| 1267 | static UINT8 is_region_offset_valid_bit(search_info *search, search_region *region, UINT32 offset); |
| 1268 | static void invalidate_region_offset(search_info *search, search_region *region, UINT32 offset); |
| 1269 | static void invalidate_region_offset_bit(search_info *search, search_region *region, UINT32 offset, UINT32 invalidate); |
| 1270 | static void invalidate_entire_region(search_info *search, search_region *region); |
| 879 | 1271 | |
| 880 | | #define IsRegionOffsetValid IsRegionOffsetValidBit |
| 1272 | static void init_new_search(search_info *search); |
| 1273 | static void update_search(search_info *search); |
| 881 | 1274 | |
| 882 | | static UINT8 IsRegionOffsetValidBit(SearchInfo * search, SearchRegion * region, UINT32 offset); |
| 883 | | static void InvalidateRegionOffset(SearchInfo * search, SearchRegion * region, UINT32 offset); |
| 884 | | static void InvalidateRegionOffsetBit(SearchInfo * search, SearchRegion * region, UINT32 offset, UINT32 invalidate); |
| 885 | | static void InvalidateEntireRegion(SearchInfo * search, SearchRegion * region); |
| 1275 | static void do_search(search_info *search); |
| 886 | 1276 | |
| 887 | | static void InitializeNewSearch(SearchInfo * search); |
| 888 | | static void UpdateSearch(SearchInfo * search); |
| 889 | | |
| 890 | | static void DoSearch(SearchInfo * search); |
| 891 | | |
| 892 | | /********** MEMORY ACCESSORS **********/ |
| 1277 | /********** MEMORY ACCESSOR **********/ |
| 893 | 1278 | static UINT8 ** LookupHandlerMemory(UINT8 cpu, UINT32 address, UINT32 * outRelativeAddress); |
| 1279 | static UINT8 ** GetMemoryRegionBasePointer(UINT8 cpu, UINT8 space, UINT32 address); |
| 894 | 1280 | |
| 895 | 1281 | static UINT32 DoCPURead(UINT8 cpu, UINT32 address, UINT8 bytes, UINT8 swap); |
| 896 | | static UINT32 DoMemoryRead(UINT8 * buf, UINT32 address, UINT8 bytes, UINT8 swap, CPUInfo * info); |
| 1282 | static UINT32 DoMemoryRead(UINT8 * buf, UINT32 address, UINT8 bytes, UINT8 swap, cpu_region_info *info); |
| 897 | 1283 | static void DoCPUWrite(UINT32 data, UINT8 cpu, UINT32 address, UINT8 bytes, UINT8 swap); |
| 898 | | static void DoMemoryWrite(UINT32 data, UINT8 * buf, UINT32 address, UINT8 bytes, UINT8 swap, CPUInfo * info); |
| 1284 | static void DoMemoryWrite(UINT32 data, UINT8 * buf, UINT32 address, UINT8 bytes, UINT8 swap, cpu_region_info *info); |
| 899 | 1285 | |
| 900 | | /********** CPU **********/ |
| 901 | | static UINT8 CPUNeedsSwap(UINT8 cpu); |
| 902 | | static UINT8 RegionNeedsSwap(UINT8 region); |
| 903 | | |
| 904 | | static CPUInfo * GetCPUInfo(UINT8 cpu); |
| 905 | | static CPUInfo * GetRegionCPUInfo(UINT8 region); |
| 906 | | |
| 907 | | static UINT32 SwapAddress(UINT32 address, UINT8 dataSize, CPUInfo * info); |
| 908 | | |
| 909 | 1286 | static UINT32 ReadData(CheatAction * action); |
| 910 | 1287 | static void WriteData(CheatAction * action, UINT32 data); |
| 911 | 1288 | |
| r2762 | r2763 | |
| 914 | 1291 | static void AddActionWatch(CheatAction * action, CheatEntry * entry); |
| 915 | 1292 | static void RemoveAssociatedWatches(CheatEntry * entry); |
| 916 | 1293 | |
| 1294 | /********** ACTIVE/DEACTIVE ENTRY **********/ |
| 917 | 1295 | static void ResetAction(CheatAction * action); |
| 918 | 1296 | static void ActivateCheat(CheatEntry * entry); |
| 919 | 1297 | static void DeactivateCheat(CheatEntry * entry); |
| 920 | 1298 | static void TempDeactivateCheat(CheatEntry * entry); |
| 921 | 1299 | |
| 1300 | /********** OPERATION CORE **********/ |
| 922 | 1301 | static void cheat_periodicOperation(CheatAction * action); |
| 923 | | static void cheat_periodicAction(running_machine *machine, CheatAction * action); |
| 1302 | static UINT8 cheat_periodicCondition(CheatAction * action); |
| 1303 | static int cheat_periodicAction(running_machine *machine, CheatAction * action, int selection); |
| 924 | 1304 | static void cheat_periodicEntry(running_machine *machine, CheatEntry * entry); |
| 925 | 1305 | |
| 1306 | /********** CONFIGURE ENTRY **********/ |
| 926 | 1307 | static void UpdateAllCheatInfo(void); |
| 927 | 1308 | static void UpdateCheatInfo(CheatEntry * entry, UINT8 isLoadTime); |
| 1309 | static UINT32 AnalyseCodeFormat(CheatEntry * entry, CheatAction * action); |
| 1310 | static void CheckCodeFormat(CheatEntry * entry); |
| 1311 | static void BuildLabelIndexTable(CheatEntry *entry); |
| 1312 | static void SetLayerIndex(void); |
| 928 | 1313 | |
| 929 | | static int IsAddressInRange(CheatAction * action, UINT32 length); |
| 1314 | /********** OTHER STUFF **********/ |
| 1315 | static void DisplayCheatMessage(void); |
| 1316 | static UINT8 get_address_length(UINT8 region); |
| 1317 | static char * get_region_name(UINT8 region); |
| 1318 | static void build_cpu_region_info_list(running_machine *machine); |
| 930 | 1319 | |
| 931 | | static void BuildCPUInfoList(running_machine *machine); |
| 1320 | /*************************************************************************** |
| 1321 | INLINE FUNCTIONS |
| 1322 | ***************************************************************************/ |
| 932 | 1323 | |
| 1324 | /*------------- |
| 1325 | GetCPUInfo |
| 1326 | -------------*/ |
| 1327 | |
| 1328 | INLINE cpu_region_info *get_cpu_info(UINT8 cpu) |
| 1329 | { |
| 1330 | if(VALID_CPU(EXTRACT_FIELD(cpu, CPUIndex))) |
| 1331 | return &cpu_info_list[cpu]; |
| 1332 | |
| 1333 | return NULL; |
| 1334 | } |
| 1335 | |
| 1336 | /*------------------- |
| 1337 | GetRegionCPUInfo |
| 1338 | -------------------*/ |
| 1339 | |
| 1340 | INLINE cpu_region_info *get_region_info(UINT8 region) |
| 1341 | { |
| 1342 | if(region >= REGION_CPU1 && region < REGION_MAX) |
| 1343 | return ®ion_info_list[region - REGION_INVALID]; |
| 1344 | |
| 1345 | return NULL; |
| 1346 | } |
| 1347 | |
| 1348 | /*------------------------- |
| 1349 | get_cpu_or_region_info |
| 1350 | -------------------------*/ |
| 1351 | |
| 1352 | INLINE cpu_region_info *get_cpu_or_region_info(UINT8 cpu_region) |
| 1353 | { |
| 1354 | if(TEST_FIELD(cpu_region, RegionFlag)) |
| 1355 | return get_region_info(cpu_region); |
| 1356 | else |
| 1357 | return get_cpu_info(cpu_region); |
| 1358 | } |
| 1359 | |
| 1360 | /*----------------- |
| 1361 | cpu_needs_swap |
| 1362 | -----------------*/ |
| 1363 | |
| 1364 | INLINE UINT8 cpu_needs_swap(UINT8 cpu) |
| 1365 | { |
| 1366 | return cpu_info_list[cpu].endianness | 1; |
| 1367 | } |
| 1368 | |
| 1369 | /*-------------------- |
| 1370 | region_needs_swap |
| 1371 | --------------------*/ |
| 1372 | |
| 1373 | INLINE UINT8 region_needs_swap(UINT8 region) |
| 1374 | { |
| 1375 | cpu_region_info *temp = get_region_info(region); |
| 1376 | |
| 1377 | if(temp) |
| 1378 | return temp->endianness | 1; |
| 1379 | |
| 1380 | return 0; |
| 1381 | } |
| 1382 | |
| 1383 | /*-------------- |
| 1384 | SwapAddress |
| 1385 | --------------*/ |
| 1386 | |
| 1387 | INLINE UINT32 SwapAddress(UINT32 address, UINT8 dataSize, cpu_region_info *info) |
| 1388 | { |
| 1389 | switch(info->data_bits) |
| 1390 | { |
| 1391 | case 16: |
| 1392 | if(info->endianness == CPU_IS_BE) |
| 1393 | return BYTE_XOR_BE(address); |
| 1394 | else |
| 1395 | return BYTE_XOR_LE(address); |
| 1396 | |
| 1397 | case 32: |
| 1398 | if(info->endianness == CPU_IS_BE) |
| 1399 | return BYTE4_XOR_BE(address); |
| 1400 | else |
| 1401 | return BYTE4_XOR_LE(address); |
| 1402 | } |
| 1403 | |
| 1404 | return address; |
| 1405 | } |
| 1406 | |
| 1407 | /*------------------- |
| 1408 | IsAddressInRange |
| 1409 | -------------------*/ |
| 1410 | |
| 1411 | INLINE int IsAddressInRange(CheatAction * action, UINT32 length) |
| 1412 | { |
| 1413 | return ((action->address + EXTRACT_FIELD(action->type, AddressSize) + 1) <= length); |
| 1414 | } |
| 1415 | |
| 1416 | /*---------- |
| 1417 | DoShift |
| 1418 | ----------*/ |
| 1419 | |
| 1420 | INLINE UINT32 DoShift(UINT32 input, INT8 shift) |
| 1421 | { |
| 1422 | if(shift > 0) |
| 1423 | return input >> shift; |
| 1424 | else |
| 1425 | return input << -shift; |
| 1426 | } |
| 1427 | |
| 1428 | /*************************************************************************** |
| 1429 | KEY HANDLER |
| 1430 | ***************************************************************************/ |
| 1431 | |
| 933 | 1432 | /*-------------------------------------------------------------- |
| 934 | 1433 | special key handler - check pressing shift, ctrl or alt key |
| 935 | 1434 | --------------------------------------------------------------*/ |
| r2762 | r2763 | |
| 1156 | 1655 | |
| 1157 | 1656 | #endif |
| 1158 | 1657 | |
| 1159 | | /*------------------------------------- |
| 1160 | | old_style_menu - export menu items |
| 1161 | | -------------------------------------*/ |
| 1658 | /*--------------------------------------------------- |
| 1659 | ui_pressed_repeat_throttle - key repeat handling |
| 1660 | ---------------------------------------------------*/ |
| 1162 | 1661 | |
| 1163 | | static void old_style_menu(const char **items, const char **subitems, char *flag, int selected, int arrowize_subitem) |
| 1662 | static int ui_pressed_repeat_throttle(running_machine *machine, int code, int base_speed) |
| 1164 | 1663 | { |
| 1165 | | static ui_menu_item item_list[1000]; |
| 1166 | | int menu_items; |
| 1664 | int pressed = 0; |
| 1665 | const int delay_ramp_timer = 10; |
| 1666 | static int last_code = -1; |
| 1667 | static int last_speed = -1; |
| 1668 | static int increment_timer = 0; |
| 1167 | 1669 | |
| 1168 | | for (menu_items = 0; items[menu_items]; menu_items++) |
| 1169 | | { |
| 1170 | | item_list[menu_items].text = items[menu_items]; |
| 1171 | | item_list[menu_items].subtext = subitems ? subitems[menu_items] : NULL; |
| 1172 | | item_list[menu_items].flags = 0; |
| 1173 | | if (flag && flag[menu_items]) |
| 1174 | | item_list[menu_items].flags |= MENU_FLAG_INVERT; |
| 1175 | | if (menu_items == selected) |
| 1176 | | { |
| 1177 | | if (arrowize_subitem & 1) |
| 1178 | | item_list[menu_items].flags |= MENU_FLAG_LEFT_ARROW; |
| 1179 | | if (arrowize_subitem & 2) |
| 1180 | | item_list[menu_items].flags |= MENU_FLAG_RIGHT_ARROW; |
| 1181 | | } |
| 1182 | | } |
| 1183 | | ui_menu_draw(item_list, menu_items, selected, NULL); |
| 1184 | | } |
| 1185 | | |
| 1186 | | /*------------------------------------------------- |
| 1187 | | UIPressedRepoeatThrottle - key repeat handling |
| 1188 | | -------------------------------------------------*/ |
| 1189 | | |
| 1190 | | static int UIPressedRepeatThrottle(running_machine *machine, int code, int baseSpeed) |
| 1191 | | { |
| 1192 | | static int lastCode = -1; |
| 1193 | | static int lastSpeed = -1; |
| 1194 | | static int incrementTimer = 0; |
| 1195 | | int pressed = 0; |
| 1196 | | |
| 1197 | | const int kDelayRampTimer = 10; |
| 1198 | | |
| 1199 | 1670 | if(input_type_pressed(machine, code, 0)) |
| 1200 | 1671 | { |
| 1201 | | if(lastCode != code) // different key pressed |
| 1672 | if(last_code != code) |
| 1202 | 1673 | { |
| 1203 | | lastCode = code; |
| 1204 | | lastSpeed = baseSpeed; |
| 1205 | | incrementTimer = kDelayRampTimer * lastSpeed; |
| 1674 | /* pressed different key */ |
| 1675 | last_code = code; |
| 1676 | last_speed = base_speed; |
| 1677 | increment_timer = delay_ramp_timer * last_speed; |
| 1206 | 1678 | } |
| 1207 | | else // same key pressed |
| 1679 | else |
| 1208 | 1680 | { |
| 1209 | | incrementTimer--; |
| 1681 | /* hold the same key */ |
| 1682 | increment_timer--; |
| 1210 | 1683 | |
| 1211 | | if(incrementTimer <= 0) |
| 1684 | if(increment_timer <= 0) |
| 1212 | 1685 | { |
| 1213 | | incrementTimer = kDelayRampTimer * lastSpeed; |
| 1686 | increment_timer = delay_ramp_timer * last_speed; |
| 1214 | 1687 | |
| 1215 | | lastSpeed /= 2; |
| 1688 | last_speed /= 2; |
| 1216 | 1689 | |
| 1217 | | if(lastSpeed < 1) |
| 1218 | | lastSpeed = 1; |
| 1690 | if(last_speed < 1) |
| 1691 | last_speed = 1; |
| 1219 | 1692 | |
| 1220 | 1693 | pressed = 1; |
| 1221 | 1694 | } |
| r2762 | r2763 | |
| 1223 | 1696 | } |
| 1224 | 1697 | else |
| 1225 | 1698 | { |
| 1226 | | if(lastCode == code) |
| 1227 | | lastCode = -1; |
| 1699 | if(last_code == code) |
| 1700 | last_code = -1; |
| 1228 | 1701 | } |
| 1229 | 1702 | |
| 1230 | | return input_ui_pressed_repeat(machine, code, lastSpeed); |
| 1703 | return input_ui_pressed_repeat(machine, code, last_speed); |
| 1231 | 1704 | } |
| 1232 | 1705 | |
| 1233 | | /*--------------------------------- |
| 1234 | | ReadHexInput - check hex input |
| 1235 | | ---------------------------------*/ |
| 1706 | /*----------------------------------- |
| 1707 | read_hex_input - check hex input |
| 1708 | -----------------------------------*/ |
| 1236 | 1709 | |
| 1237 | | static int ReadHexInput(void) |
| 1710 | static int read_hex_input(void) |
| 1238 | 1711 | { |
| 1239 | | int i; |
| 1712 | int i; |
| 1240 | 1713 | |
| 1241 | 1714 | for(i = 0; i < 10; i++) |
| 1242 | 1715 | { |
| r2762 | r2763 | |
| 1262 | 1735 | /*----------------------------------------------------------------- |
| 1263 | 1736 | DoDynamicEditTextField - edit text field with direct key input |
| 1264 | 1737 | -----------------------------------------------------------------*/ |
| 1265 | | |
| 1738 | #if 0 |
| 1266 | 1739 | static char * DoDynamicEditTextField(char * buf) |
| 1267 | 1740 | { |
| 1268 | | char code = osd_readkey_unicode(0) & 0xFF; |
| 1741 | char code = osd_readkey_unicode(0) & 0xFF; |
| 1269 | 1742 | |
| 1270 | 1743 | if(code == 0x08) |
| 1271 | 1744 | { |
| 1272 | | /* ----- backspace ----- */ |
| 1745 | /* backspace */ |
| 1273 | 1746 | if(buf) |
| 1274 | 1747 | { |
| 1275 | 1748 | size_t length = strlen(buf); |
| r2762 | r2763 | |
| 1295 | 1768 | { |
| 1296 | 1769 | if(buf) |
| 1297 | 1770 | { |
| 1298 | | size_t length = strlen(buf); |
| 1771 | size_t length = strlen(buf); |
| 1299 | 1772 | |
| 1300 | 1773 | buf = realloc(buf, length + 2); |
| 1301 | 1774 | |
| r2762 | r2763 | |
| 1314 | 1787 | |
| 1315 | 1788 | return buf; |
| 1316 | 1789 | } |
| 1317 | | |
| 1790 | #endif |
| 1318 | 1791 | /*------------------------ |
| 1319 | 1792 | DoStaticEditTextField |
| 1320 | 1793 | ------------------------*/ |
| r2762 | r2763 | |
| 1331 | 1804 | |
| 1332 | 1805 | if(code == 0x08) |
| 1333 | 1806 | { |
| 1807 | /* back space */ |
| 1334 | 1808 | if(length > 0) |
| 1335 | | { |
| 1336 | 1809 | buf[length - 1] = 0; |
| 1337 | | } |
| 1338 | 1810 | } |
| 1339 | 1811 | else if(isprint(code)) |
| 1340 | 1812 | { |
| r2762 | r2763 | |
| 1346 | 1818 | } |
| 1347 | 1819 | } |
| 1348 | 1820 | |
| 1349 | | /*------------------------------------------------------------------ |
| 1350 | | DoEditHexField - edit hex field with direct key input (unsigned) |
| 1351 | | ------------------------------------------------------------------*/ |
| 1821 | /*---------------------------------------------------------------------- |
| 1822 | do_edit_hex_field - edit hex field with direct key input (unsigned) |
| 1823 | ----------------------------------------------------------------------*/ |
| 1352 | 1824 | |
| 1353 | | static UINT32 DoEditHexField(running_machine *machine, UINT32 data) |
| 1825 | static UINT32 do_edit_hex_field(running_machine *machine, UINT32 data) |
| 1354 | 1826 | { |
| 1355 | | INT8 key; |
| 1827 | INT8 key; |
| 1356 | 1828 | |
| 1357 | 1829 | if(input_code_pressed_once(KEYCODE_BACKSPACE)) |
| 1358 | 1830 | { |
| 1359 | | /* ----- backspace ----- */ |
| 1831 | /* back space */ |
| 1360 | 1832 | data >>= 4; |
| 1361 | | |
| 1362 | 1833 | return data; |
| 1363 | 1834 | } |
| 1364 | | else |
| 1835 | else if(input_ui_pressed(machine, IPT_UI_CLEAR)) |
| 1365 | 1836 | { |
| 1366 | | if(input_ui_pressed(machine, IPT_UI_CLEAR)) |
| 1367 | | { |
| 1368 | | data = 0; |
| 1369 | | |
| 1370 | | return data; |
| 1371 | | } |
| 1837 | /* data clear */ |
| 1838 | data = 0; |
| 1839 | return data; |
| 1372 | 1840 | } |
| 1373 | 1841 | |
| 1374 | | key = ReadHexInput(); |
| 1842 | key = read_hex_input(); |
| 1375 | 1843 | |
| 1376 | 1844 | if(key != -1) |
| 1377 | 1845 | { |
| r2762 | r2763 | |
| 1394 | 1862 | if(isNegative) |
| 1395 | 1863 | data |= mask; |
| 1396 | 1864 | |
| 1397 | | key = ReadHexInput(); |
| 1865 | key = read_hex_input(); |
| 1398 | 1866 | |
| 1399 | 1867 | if(key != -1) |
| 1400 | 1868 | { |
| r2762 | r2763 | |
| 1422 | 1890 | |
| 1423 | 1891 | static INT32 DoEditDecField(INT32 data, INT32 min, INT32 max) |
| 1424 | 1892 | { |
| 1425 | | char code = osd_readkey_unicode(0) & 0xFF; |
| 1893 | char code = osd_readkey_unicode(0) & 0xFF; |
| 1426 | 1894 | |
| 1427 | 1895 | if((code >= '0') && (code <= '9')) |
| 1428 | 1896 | { |
| r2762 | r2763 | |
| 1435 | 1903 | data = -data; |
| 1436 | 1904 | else |
| 1437 | 1905 | { |
| 1438 | | /* ----- backspace ----- */ |
| 1906 | /* backspace */ |
| 1439 | 1907 | if(code == 0x08) |
| 1440 | 1908 | data /= 10; |
| 1441 | 1909 | } |
| 1442 | 1910 | } |
| 1443 | 1911 | |
| 1444 | | /* ----- adjust value ----- */ |
| 1912 | /* adjust value */ |
| 1445 | 1913 | if(data < min) |
| 1446 | 1914 | data = min; |
| 1447 | 1915 | if(data > max) |
| r2762 | r2763 | |
| 1450 | 1918 | return data; |
| 1451 | 1919 | } |
| 1452 | 1920 | |
| 1453 | | /*************************************************************************** |
| 1454 | | INITIALIZATION |
| 1455 | | ***************************************************************************/ |
| 1921 | /*-------------------------------------------------------------------------------- |
| 1922 | DoIncrementHexField - increment a specified value in hex field with arrow key |
| 1923 | --------------------------------------------------------------------------------*/ |
| 1456 | 1924 | |
| 1457 | | /*--------------------------------------- |
| 1458 | | cheat_init - initialize cheat system |
| 1459 | | ---------------------------------------*/ |
| 1460 | | |
| 1461 | | void cheat_init(running_machine *machine) |
| 1925 | static UINT32 DoIncrementHexField(UINT32 data, UINT8 digits) |
| 1462 | 1926 | { |
| 1463 | | /* ----- initialize lists ----- */ |
| 1464 | | cheatList = NULL; |
| 1465 | | cheatListLength = 0; |
| 1927 | data = ((data & ~kIncrementMaskTable[digits]) | |
| 1928 | (((data & kIncrementMaskTable[digits]) + kIncrementValueTable[digits]) & |
| 1929 | kIncrementMaskTable[digits])); |
| 1466 | 1930 | |
| 1467 | | watchList = NULL; |
| 1468 | | watchListLength = 0; |
| 1931 | return data; |
| 1932 | } |
| 1469 | 1933 | |
| 1470 | | searchList = NULL; |
| 1471 | | searchListLength = 0; |
| 1934 | /*-------------------------------------------------------------------------------- |
| 1935 | DoDecrementHexField - decrement a specified value in hex field with arrow key |
| 1936 | --------------------------------------------------------------------------------*/ |
| 1472 | 1937 | |
| 1473 | | #ifdef MESS |
| 1474 | | InitMessCheats(machine); |
| 1475 | | #endif |
| 1938 | static UINT32 DoDecrementHexField(UINT32 data, UINT8 digits) |
| 1939 | { |
| 1940 | data = ((data & ~kIncrementMaskTable[digits]) | |
| 1941 | (((data & kIncrementMaskTable[digits]) - kIncrementValueTable[digits]) & |
| 1942 | kIncrementMaskTable[digits])); |
| 1476 | 1943 | |
| 1477 | | /* ----- initialize flags ----- */ |
| 1478 | | currentSearchIdx = 0; |
| 1479 | | foundCheatDatabase = 0; |
| 1480 | | cheatsDisabled = 0; |
| 1481 | | watchesDisabled = 0; |
| 1482 | | cheatOptions = 2; |
| 1944 | return data; |
| 1945 | } |
| 1483 | 1946 | |
| 1484 | | fullMenuPageHeight = floor(1.0f / ui_get_line_height()) - 1; |
| 1947 | /*-------------------------------------------------------------------------------------- |
| 1948 | DoIncrementHexFieldSigned - increment a specified value in hex field with arrow key |
| 1949 | --------------------------------------------------------------------------------------*/ |
| 1485 | 1950 | |
| 1486 | | /* ----- initialize CPU info for cheat system ----- */ |
| 1487 | | BuildCPUInfoList(machine); |
| 1951 | static UINT32 DoIncrementHexFieldSigned(UINT32 data, UINT8 digits, UINT8 bytes) |
| 1952 | { |
| 1953 | UINT32 newData = data; |
| 1488 | 1954 | |
| 1489 | | /* ----- load cheat database ----- */ |
| 1490 | | LoadCheatDatabase(machine); |
| 1955 | if(data & kSearchByteSignBitTable[bytes]) |
| 1956 | { |
| 1957 | /* MINUS */ |
| 1958 | newData = ((newData & ~kIncrementMaskTable[digits]) | |
| 1959 | (((newData & kIncrementMaskTable[digits]) - kIncrementValueTable[digits]) & |
| 1960 | kIncrementMaskTable[digits])); |
| 1491 | 1961 | |
| 1492 | | ResizeSearchList(1); |
| 1493 | | ResizeWatchList(20); |
| 1962 | if(newData & kSearchByteSignBitTable[bytes]) |
| 1963 | newData = ((data & ~kIncrementMaskTable[digits]) | (newData & kIncrementMaskTable[digits])); |
| 1964 | } |
| 1965 | else |
| 1966 | { |
| 1967 | /* PLUS */ |
| 1968 | newData = ((newData & ~kIncrementMaskTable[digits]) | |
| 1969 | (((newData & kIncrementMaskTable[digits]) + kIncrementValueTable[digits]) & |
| 1970 | kIncrementMaskTable[digits])); |
| 1494 | 1971 | |
| 1495 | | /* ----- initialize search regions ----- */ |
| 1496 | | BuildSearchRegions(machine, GetCurrentSearch()); |
| 1497 | | AllocateSearchRegions(GetCurrentSearch()); |
| 1972 | if(!(newData & kSearchByteSignBitTable[bytes])) |
| 1973 | newData = ((data & ~kIncrementMaskTable[digits]) | (newData & kIncrementMaskTable[digits])); |
| 1974 | } |
| 1498 | 1975 | |
| 1499 | | /* ----- initialize string table ----- */ |
| 1500 | | InitStringTable(); |
| 1501 | | |
| 1502 | | periodic_timer = timer_alloc(cheat_periodic, NULL); |
| 1503 | | timer_adjust_periodic(periodic_timer, video_screen_get_frame_period(machine->primary_screen), 0, video_screen_get_frame_period(machine->primary_screen)); |
| 1504 | | |
| 1505 | | add_exit_callback(machine, cheat_exit); |
| 1976 | return newData; |
| 1506 | 1977 | } |
| 1507 | 1978 | |
| 1508 | | /*--------------------------------- |
| 1509 | | cheat_exit - free cheat system |
| 1510 | | ---------------------------------*/ |
| 1979 | /*-------------------------------------------------------------------------------------- |
| 1980 | DoDecrementHexFieldSigned - decrement a specified value in hex field with arrow key |
| 1981 | --------------------------------------------------------------------------------------*/ |
| 1511 | 1982 | |
| 1512 | | static void cheat_exit(running_machine *machine) |
| 1983 | static UINT32 DoDecrementHexFieldSigned(UINT32 data, UINT8 digits, UINT8 bytes) |
| 1513 | 1984 | { |
| 1514 | | int i; |
| 1985 | UINT32 newData = data; |
| 1515 | 1986 | |
| 1516 | | /* ----- save all cheats automatically if needed ----- */ |
| 1517 | | if(TEST_FIELD(cheatOptions, AutoSaveEnabled)) |
| 1518 | | DoAutoSaveCheats(machine); |
| 1519 | | |
| 1520 | | /* ----- free database ----- */ |
| 1521 | | DisposeCheatDatabase(); |
| 1522 | | |
| 1523 | | /* ----- free watch lists ----- */ |
| 1524 | | if(watchList) |
| 1987 | if(data & kSearchByteSignBitTable[bytes]) |
| 1525 | 1988 | { |
| 1526 | | for(i = 0; i < watchListLength; i++) |
| 1527 | | DisposeWatch(&watchList[i]); |
| 1989 | /* MINUS */ |
| 1990 | newData = ((newData & ~kIncrementMaskTable[digits]) | |
| 1991 | (((newData & kIncrementMaskTable[digits]) + kIncrementValueTable[digits]) & |
| 1992 | kIncrementMaskTable[digits])); |
| 1528 | 1993 | |
| 1529 | | free(watchList); |
| 1530 | | |
| 1531 | | watchList = NULL; |
| 1994 | if(newData & kSearchByteSignBitTable[bytes]) |
| 1995 | newData = ((data & ~kIncrementMaskTable[digits]) | (newData & kIncrementMaskTable[digits])); |
| 1532 | 1996 | } |
| 1533 | | |
| 1534 | | /* ----- free search lists ----- */ |
| 1535 | | if(searchList) |
| 1997 | else |
| 1536 | 1998 | { |
| 1537 | | for(i = 0; i < searchListLength; i++) |
| 1538 | | DisposeSearch(i); |
| 1999 | /* PLUS */ |
| 2000 | newData = ((newData & ~kIncrementMaskTable[digits]) | |
| 2001 | (((newData & kIncrementMaskTable[digits]) - kIncrementValueTable[digits]) & |
| 2002 | kIncrementMaskTable[digits])); |
| 1539 | 2003 | |
| 1540 | | free(searchList); |
| 1541 | | |
| 1542 | | searchList = NULL; |
| 2004 | if(!(newData & kSearchByteSignBitTable[bytes])) |
| 2005 | newData = ((data & ~kIncrementMaskTable[digits]) | (newData & kIncrementMaskTable[digits])); |
| 1543 | 2006 | } |
| 1544 | 2007 | |
| 1545 | | /* ----- free string table ----- */ |
| 1546 | | FreeStringTable(); |
| 2008 | return newData; |
| 2009 | } |
| 1547 | 2010 | |
| 1548 | | free(menuItemInfo); |
| 1549 | | menuItemInfo = NULL; |
| 2011 | /*-------------------------------------------------------------------------------- |
| 2012 | DoIncrementDecField - increment a specified value in dec field with arrow key |
| 2013 | --------------------------------------------------------------------------------*/ |
| 1550 | 2014 | |
| 1551 | | #ifdef MESS |
| 1552 | | StopMessCheats(); |
| 1553 | | #endif |
| 2015 | static UINT32 DoIncrementDecField(UINT32 data, UINT8 digits) |
| 2016 | { |
| 2017 | UINT32 value = data & kIncrementMaskTable[digits]; |
| 1554 | 2018 | |
| 1555 | | /* ----- free flags ----- */ |
| 1556 | | cheatListLength = 0; |
| 1557 | | watchListLength = 0; |
| 1558 | | searchListLength = 0; |
| 1559 | | currentSearchIdx = 0; |
| 1560 | | // cheatEngineWasActive = 0; |
| 1561 | | foundCheatDatabase = 0; |
| 1562 | | cheatsDisabled = 0; |
| 1563 | | watchesDisabled = 0; |
| 1564 | | mainDatabaseName[0] = 0; |
| 1565 | | menuItemInfoLength = 0; |
| 1566 | | cheatOptions = 0; |
| 2019 | if(value >= kIncrementDecTable[digits]) |
| 2020 | value = 0; |
| 2021 | else |
| 2022 | value += kIncrementValueTable[digits]; |
| 2023 | |
| 2024 | return ((data & ~kIncrementMaskTable[digits]) | value); |
| 1567 | 2025 | } |
| 1568 | 2026 | |
| 1569 | | /*----------------------------------------------------- |
| 1570 | | cheat_menu - management for the cheat general menu |
| 1571 | | -----------------------------------------------------*/ |
| 2027 | /*-------------------------------------------------------------------------------- |
| 2028 | DoDecrementDecField - increment a specified value in dec field with arrow key |
| 2029 | --------------------------------------------------------------------------------*/ |
| 1572 | 2030 | |
| 1573 | | int cheat_menu(running_machine *machine, int selection) |
| 2031 | static UINT32 DoDecrementDecField(UINT32 data, UINT8 digits) |
| 1574 | 2032 | { |
| 1575 | | enum |
| 1576 | | { |
| 1577 | | kMenu_EnableDisable = 0, |
| 1578 | | kMenu_AddEdit, |
| 1579 | | kMenu_Search, |
| 1580 | | kMenu_ChooseWatch, |
| 1581 | | kMenu_ReloadDatabase, |
| 1582 | | kMenu_Options, |
| 1583 | | kMenu_Return, |
| 2033 | UINT32 value = data & kIncrementMaskTable[digits]; |
| 1584 | 2034 | |
| 1585 | | kMenu_Max |
| 1586 | | }; |
| 2035 | if(!value) |
| 2036 | value = kIncrementDecTable[digits]; |
| 2037 | else |
| 2038 | value -= kIncrementValueTable[digits]; |
| 1587 | 2039 | |
| 1588 | | ui_menu_item menu_item[kMenu_Max]; |
| 2040 | return ((data & ~kIncrementMaskTable[digits]) | value); |
| 2041 | } |
| 1589 | 2042 | |
| 1590 | | INT32 sel; |
| 1591 | | UINT8 total = 0; |
| 2043 | /*************************************************************************** |
| 2044 | INITIALIZATION |
| 2045 | ***************************************************************************/ |
| 1592 | 2046 | |
| 1593 | | static INT32 submenu_choice = 0; |
| 1594 | | static int firstEntry = 0; |
| 1595 | | static int lastPstn = 0; |
| 2047 | /*--------------------------------------- |
| 2048 | cheat_init - initialize cheat system |
| 2049 | ---------------------------------------*/ |
| 1596 | 2050 | |
| 1597 | | /* ----- allocate memory for item list ----- */ |
| 1598 | | memset(menu_item, 0, sizeof(menu_item)); |
| 2051 | void cheat_init(running_machine *machine) |
| 2052 | { |
| 2053 | /* initialize lists */ |
| 2054 | cheatList = NULL; |
| 2055 | cheatListLength = 0; |
| 1599 | 2056 | |
| 1600 | | // cheatEngineWasActive = 1; |
| 2057 | watchList = NULL; |
| 2058 | watchListLength = 0; |
| 1601 | 2059 | |
| 1602 | | sel = lastPstn; |
| 2060 | search_list = NULL; |
| 2061 | search_list_length = 0; |
| 1603 | 2062 | |
| 1604 | | /********** SUB MENU **********/ |
| 1605 | | if(submenu_choice) |
| 1606 | | { |
| 1607 | | switch(sel) |
| 1608 | | { |
| 1609 | | case kMenu_EnableDisable: |
| 1610 | | submenu_choice = EnableDisableCheatMenu(machine, submenu_choice, firstEntry); |
| 1611 | | break; |
| 2063 | #ifdef MESS |
| 2064 | InitMessCheats(machine); |
| 2065 | #endif |
| 1612 | 2066 | |
| 1613 | | case kMenu_AddEdit: |
| 1614 | | submenu_choice = AddEditCheatMenu(machine, submenu_choice); |
| 1615 | | break; |
| 2067 | /* initialize flags */ |
| 2068 | current_search_idx = 0; |
| 2069 | foundCheatDatabase = 0; |
| 2070 | cheatsDisabled = 0; |
| 2071 | watchesDisabled = 0; |
| 2072 | editActive = 0; |
| 2073 | editCursor = 0; |
| 2074 | cheatOptions = DEFAULT_CHEAT_OPTIONS; |
| 2075 | driverSpecifiedFlag = 0; |
| 1616 | 2076 | |
| 1617 | | case kMenu_Search: |
| 1618 | | switch(EXTRACT_FIELD(cheatOptions, SearchBox)) |
| 1619 | | { |
| 1620 | | case kSearchBox_Minimum: |
| 1621 | | submenu_choice = DoSearchMenuMinimum(machine, submenu_choice); |
| 1622 | | break; |
| 2077 | fullMenuPageHeight = visible_items = floor(1.0f / ui_get_line_height()) - 1; |
| 1623 | 2078 | |
| 1624 | | case kSearchBox_Classic: |
| 1625 | | submenu_choice = DoSearchMenuClassic(machine, submenu_choice); |
| 1626 | | break; |
| 2079 | /* initialize CPU/Region info for cheat system */ |
| 2080 | build_cpu_region_info_list(machine); |
| 1627 | 2081 | |
| 1628 | | case kSearchBox_Advanced: |
| 1629 | | submenu_choice = DoSearchMenu(machine, submenu_choice); |
| 1630 | | break; |
| 1631 | | } |
| 1632 | | break; |
| 2082 | /* set cheat list from database */ |
| 2083 | LoadCheatDatabase(machine, kLoadFlag_CheatOption | kLoadFlag_CheatCode); |
| 1633 | 2084 | |
| 1634 | | case kMenu_ChooseWatch: |
| 1635 | | submenu_choice = ChooseWatch(machine, submenu_choice); |
| 1636 | | break; |
| 2085 | /* set default search and watch lists */ |
| 2086 | resize_search_list(1); |
| 2087 | ResizeWatchList(fullMenuPageHeight - 1); |
| 1637 | 2088 | |
| 1638 | | case kMenu_Options: |
| 1639 | | submenu_choice = SelectOptions(machine, submenu_choice); |
| 1640 | | break; |
| 1641 | | } |
| 2089 | /* build search region */ |
| 2090 | { |
| 2091 | search_info *info = get_current_search(); |
| 1642 | 2092 | |
| 1643 | | firstEntry = 0; |
| 2093 | /* attemp to load user region */ |
| 2094 | LoadCheatDatabase(machine, kLoadFlag_UserRegion); |
| 1644 | 2095 | |
| 1645 | | /* ----- quick menu switching ------ */ |
| 1646 | | if(submenu_choice < 0) |
| 2096 | /* if no user region or fail to load the database, attempt to build default region */ |
| 2097 | if(info->region_list_length) |
| 2098 | info->search_speed = ksearch_speed_UserDefined; |
| 2099 | else |
| 1647 | 2100 | { |
| 1648 | | switch(submenu_choice) |
| 1649 | | { |
| 1650 | | case -1: |
| 1651 | | lastPstn = kMenu_EnableDisable; |
| 1652 | | break; |
| 1653 | | |
| 1654 | | case -2: |
| 1655 | | lastPstn = kMenu_AddEdit; |
| 1656 | | break; |
| 1657 | | |
| 1658 | | case -3: |
| 1659 | | lastPstn = kMenu_Search; |
| 1660 | | break; |
| 1661 | | |
| 1662 | | case -4: |
| 1663 | | lastPstn = kMenu_ChooseWatch; |
| 1664 | | break; |
| 1665 | | |
| 1666 | | default: |
| 1667 | | ui_popup_time(1, "undefined menu switching : %x", submenu_choice); |
| 1668 | | } |
| 1669 | | |
| 1670 | | submenu_choice = 1; |
| 2101 | info->search_speed = ksearch_speed_VerySlow; |
| 2102 | build_search_regions(machine, info); |
| 1671 | 2103 | } |
| 1672 | 2104 | |
| 1673 | | return sel + 1; |
| 2105 | /* memory allocation for search region */ |
| 2106 | allocate_search_regions(info); |
| 1674 | 2107 | } |
| 1675 | 2108 | |
| 1676 | | /********** MENU CONSTRUCION **********/ |
| 1677 | | menu_item[total++].text = "Enable/Disable a Cheat"; // Enable/Disable a Cheat |
| 2109 | /* initialize string table */ |
| 2110 | init_string_table(); |
| 1678 | 2111 | |
| 1679 | | menu_item[total++].text = "Add/Edit a Cheat"; // Add/Edit a Cheat |
| 2112 | /* initialize cheat menu stack */ |
| 2113 | init_cheat_menu_stack(); |
| 1680 | 2114 | |
| 1681 | | switch(EXTRACT_FIELD(cheatOptions, SearchBox)) // Search a Cheat |
| 1682 | 2115 | { |
| 1683 | | case kSearchBox_Minimum: |
| 1684 | | menu_item[total++].text = "Search a Cheat (Minimum Mode)"; |
| 1685 | | break; |
| 2116 | astring * sourceName; |
| 1686 | 2117 | |
| 1687 | | case kSearchBox_Classic: |
| 1688 | | menu_item[total++].text = "Search a Cheat (Classic Mode)"; |
| 1689 | | break; |
| 2118 | sourceName = core_filename_extract_base(astring_alloc(), machine->gamedrv->source_file, TRUE); |
| 1690 | 2119 | |
| 1691 | | case kSearchBox_Advanced: |
| 1692 | | menu_item[total++].text = "Search a Cheat (Advanced Mode)"; |
| 1693 | | break; |
| 2120 | if(!strcmp(astring_c(sourceName), "neodrvr")) |
| 2121 | driverSpecifiedFlag |= 1; |
| 2122 | else if(!strcmp(astring_c(sourceName), "cps2")) |
| 2123 | driverSpecifiedFlag |= 2; |
| 2124 | else if(!strcmp(astring_c(sourceName), "cps3")) |
| 2125 | driverSpecifiedFlag |= 4; |
| 2126 | |
| 2127 | astring_free(sourceName); |
| 1694 | 2128 | } |
| 1695 | 2129 | |
| 1696 | | menu_item[total++].text = "Configure Watchpoints"; // Configure Watchpoints |
| 2130 | /* NOTE : disable all cheat messages in initializing so that message parameters should be initialized here */ |
| 2131 | messageType = 0; |
| 2132 | messageTimer = 0; |
| 1697 | 2133 | |
| 1698 | | menu_item[total++].text = "Reload Database"; // Reload Cheat Database |
| 2134 | periodic_timer = timer_alloc(cheat_periodic, NULL); |
| 2135 | timer_adjust_periodic(periodic_timer, video_screen_get_frame_period(machine->primary_screen), 0, video_screen_get_frame_period(machine->primary_screen)); |
| 1699 | 2136 | |
| 1700 | | menu_item[total++].text = "Options"; // Options |
| 2137 | add_exit_callback(machine, cheat_exit); |
| 2138 | } |
| 1701 | 2139 | |
| 1702 | | menu_item[total++].text = "Return to Main Menu"; // return to the MAME general menu |
| 2140 | /*--------------------------------- |
| 2141 | cheat_exit - free cheat system |
| 2142 | ---------------------------------*/ |
| 1703 | 2143 | |
| 1704 | | menu_item[total].text = NULL; // terminate array |
| 2144 | static void cheat_exit(running_machine *machine) |
| 2145 | { |
| 2146 | int i; |
| 1705 | 2147 | |
| 1706 | | /* ----- adjust cursor postion ----- */ |
| 1707 | | if(sel < 0) |
| 1708 | | sel = 0; |
| 1709 | | if(sel > (total - 1)) |
| 1710 | | sel = total - 1; |
| 2148 | /* save all cheats automatically if needed */ |
| 2149 | if(TEST_FIELD(cheatOptions, AutoSaveEnabled)) |
| 2150 | DoAutoSaveCheats(machine); |
| 1711 | 2151 | |
| 1712 | | /* ----- print it ----- */ |
| 1713 | | ui_menu_draw(menu_item, total, sel, NULL); |
| 2152 | /* free database */ |
| 2153 | DisposeCheatDatabase(); |
| 1714 | 2154 | |
| 1715 | | /********** KEY HANDLING **********/ |
| 1716 | | if(UIPressedRepeatThrottle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate)) |
| 2155 | /* free watch lists */ |
| 2156 | if(watchList) |
| 1717 | 2157 | { |
| 1718 | | if(sel < (total - 1)) |
| 1719 | | sel++; |
| 1720 | | else |
| 1721 | | sel = 0; |
| 1722 | | } |
| 2158 | for(i = 0; i < watchListLength; i++) |
| 2159 | DisposeWatch(&watchList[i]); |
| 1723 | 2160 | |
| 1724 | | if(UIPressedRepeatThrottle(machine, IPT_UI_UP, kVerticalKeyRepeatRate)) |
| 1725 | | { |
| 1726 | | if(sel > 0) |
| 1727 | | sel--; |
| 1728 | | else |
| 1729 | | sel = total - 1; |
| 2161 | free(watchList); |
| 2162 | |
| 2163 | watchList = NULL; |
| 1730 | 2164 | } |
| 1731 | 2165 | |
| 1732 | | if(input_ui_pressed(machine, IPT_UI_SELECT)) |
| 2166 | /* free search lists */ |
| 2167 | if(search_list) |
| 1733 | 2168 | { |
| 1734 | | switch(sel) |
| 1735 | | { |
| 1736 | | case kMenu_Return: |
| 1737 | | submenu_choice = 0; |
| 1738 | | sel = -1; |
| 1739 | | lastPstn = 0; // if cursor is now on the return item, adjust cursor keeper |
| 1740 | | break; |
| 2169 | for(i = 0; i < search_list_length; i++) |
| 2170 | dispose_search(&search_list[i]); |
| 1741 | 2171 | |
| 1742 | | case kMenu_ReloadDatabase: |
| 1743 | | ReloadCheatDatabase(machine); |
| 1744 | | break; |
| 2172 | free(search_list); |
| 1745 | 2173 | |
| 1746 | | default: |
| 1747 | | firstEntry = 1; |
| 1748 | | submenu_choice = 1; |
| 1749 | | break; |
| 1750 | | } |
| 2174 | search_list = NULL; |
| 1751 | 2175 | } |
| 1752 | 2176 | |
| 1753 | | if(input_ui_pressed(machine, IPT_UI_RELOAD_CHEAT)) |
| 1754 | | ReloadCheatDatabase(machine); |
| 2177 | /* free string table */ |
| 2178 | free_string_table(); |
| 1755 | 2179 | |
| 1756 | | if(input_ui_pressed(machine, IPT_UI_CANCEL)) |
| 1757 | | { |
| 1758 | | if(sel == kMenu_Return) |
| 1759 | | lastPstn = 0; // if cursor is now on the return item, adjust cursor keeper |
| 2180 | /* free cheat menu stack */ |
| 2181 | free_cheat_menu_stack(); |
| 1760 | 2182 | |
| 1761 | | sel = -1; |
| 1762 | | } |
| 2183 | free(menu_item_info); |
| 2184 | menu_item_info = NULL; |
| 1763 | 2185 | |
| 1764 | | /* ----- keep current cursor position ----- */ |
| 1765 | | if(sel >= 0) |
| 1766 | | lastPstn = sel; |
| 2186 | #ifdef MESS |
| 2187 | StopMessCheats(); |
| 2188 | #endif |
| 1767 | 2189 | |
| 1768 | | return sel + 1; |
| 2190 | /* free flags */ |
| 2191 | cheatListLength = 0; |
| 2192 | watchListLength = 0; |
| 2193 | search_list_length = 0; |
| 2194 | current_search_idx = 0; |
| 2195 | foundCheatDatabase = 0; |
| 2196 | cheatsDisabled = 0; |
| 2197 | watchesDisabled = 0; |
| 2198 | mainDatabaseName[0] = 0; |
| 2199 | menuItemInfoLength = 0; |
| 2200 | cheatVariable[0] = 0; |
| 2201 | cheatOptions = 0; |
| 2202 | driverSpecifiedFlag = 0; |
| 2203 | messageType = 0; |
| 2204 | messageTimer = 0; |
| 1769 | 2205 | } |
| 1770 | 2206 | |
| 1771 | | /*---------- |
| 1772 | | DoShift |
| 1773 | | ----------*/ |
| 2207 | /*---------------------------------- |
| 2208 | cheat_menu - handle cheat menus |
| 2209 | ----------------------------------*/ |
| 1774 | 2210 | |
| 1775 | | static UINT32 DoShift(UINT32 input, INT8 shift) |
| 2211 | int cheat_menu(running_machine *machine, int selection) |
| 1776 | 2212 | { |
| 1777 | | if(shift > 0) |
| 1778 | | return input >> shift; |
| 1779 | | else |
| 1780 | | return input << -shift; |
| 2213 | cheat_menu_stack *menu = &menu_stack[stack_index]; |
| 2214 | |
| 2215 | /* handle cheat message */ |
| 2216 | DisplayCheatMessage(); |
| 2217 | |
| 2218 | /* handle cheat menu */ |
| 2219 | selection = (*menu->handler)(machine, menu); |
| 2220 | |
| 2221 | if(selection == 0) |
| 2222 | { |
| 2223 | if(stack_index) |
| 2224 | /* return previous "cheat" menu */ |
| 2225 | cheat_menu_stack_pop(); |
| 2226 | else |
| 2227 | /* return MAME general menu */ |
| 2228 | return selection; |
| 2229 | } |
| 2230 | |
| 2231 | return selection + 1; |
| 1781 | 2232 | } |
| 1782 | 2233 | |
| 1783 | 2234 | /*---------------------------------------- |
| r2762 | r2763 | |
| 1786 | 2237 | |
| 1787 | 2238 | static UINT32 BCDToDecimal(UINT32 value) |
| 1788 | 2239 | { |
| 1789 | | UINT32 accumulator = 0; |
| 1790 | | UINT32 multiplier = 1; |
| 1791 | 2240 | int i; |
| 2241 | UINT32 accumulator = 0; |
| 2242 | UINT32 multiplier = 1; |
| 1792 | 2243 | |
| 1793 | 2244 | for(i = 0; i < 8; i++) |
| 1794 | 2245 | { |
| r2762 | r2763 | |
| 1807 | 2258 | |
| 1808 | 2259 | static UINT32 DecimalToBCD(UINT32 value) |
| 1809 | 2260 | { |
| 1810 | | UINT32 accumulator = 0; |
| 1811 | | UINT32 divisor = 10; |
| 1812 | 2261 | int i; |
| 2262 | UINT32 accumulator = 0; |
| 2263 | UINT32 divisor = 10; |
| 1813 | 2264 | |
| 1814 | 2265 | for(i = 0; i < 8; i++) |
| 1815 | 2266 | { |
| r2762 | r2763 | |
| 1827 | 2278 | return accumulator; |
| 1828 | 2279 | } |
| 1829 | 2280 | |
| 1830 | | /*---------------------- |
| 1831 | | RebuildStringTables |
| 1832 | | ----------------------*/ |
| 2281 | /*----------------------------------------------------------------- |
| 2282 | rebuild_string_tables - memory allocation for menu string list |
| 2283 | -----------------------------------------------------------------*/ |
| 1833 | 2284 | |
| 1834 | | static void RebuildStringTables(void) |
| 2285 | static void rebuild_string_tables(void) |
| 1835 | 2286 | { |
| 1836 | | UINT32 storageNeeded, i; |
| 1837 | | char * traverse; |
| 2287 | UINT32 i; |
| 2288 | UINT32 storage_needed; |
| 2289 | char *traverse; |
| 1838 | 2290 | |
| 1839 | | storageNeeded = (menuStrings.mainStringLength + menuStrings.subStringLength) * menuStrings.numStrings; |
| 2291 | /* calculate length of total buffer */ |
| 2292 | storage_needed = (menu_strings.main_string_length + menu_strings.sub_string_length) * menu_strings.num_strings; |
| 1840 | 2293 | |
| 1841 | | menuStrings.mainList = (const char **) realloc((char *) menuStrings.mainList, sizeof(char *) * menuStrings.length); |
| 1842 | | menuStrings.subList = (const char **) realloc((char *) menuStrings.subList, sizeof(char *) * menuStrings.length); |
| 1843 | | menuStrings.flagList = realloc( menuStrings.flagList, sizeof(char) * menuStrings.length); |
| 1844 | | menuStrings.mainStrings = realloc( menuStrings.mainStrings, sizeof(char *) * menuStrings.numStrings); |
| 1845 | | menuStrings.subStrings = realloc( menuStrings.subStrings, sizeof(char *) * menuStrings.numStrings); |
| 1846 | | menuStrings.buf = realloc( menuStrings.buf, sizeof(char) * storageNeeded); |
| 2294 | /* allocate memory for all items */ |
| 2295 | menu_strings.main_list = (const char **) realloc((char *) menu_strings.main_list, sizeof(char *) * menu_strings.length); |
| 2296 | menu_strings.sub_list = (const char **) realloc((char *) menu_strings.sub_list, sizeof(char *) * menu_strings.length); |
| 2297 | menu_strings.flag_list = realloc( menu_strings.flag_list, sizeof(char) * menu_strings.length); |
| 2298 | menu_strings.main_strings = realloc( menu_strings.main_strings, sizeof(char *) * menu_strings.num_strings); |
| 2299 | menu_strings.sub_strings = realloc( menu_strings.sub_strings, sizeof(char *) * menu_strings.num_strings); |
| 2300 | menu_strings.buf = realloc( menu_strings.buf, sizeof(char) * storage_needed); |
| 1847 | 2301 | |
| 1848 | | if( (!menuStrings.mainList && menuStrings.length) || |
| 1849 | | (!menuStrings.subList && menuStrings.length) || |
| 1850 | | (!menuStrings.flagList && menuStrings.length) || |
| 1851 | | (!menuStrings.mainStrings && menuStrings.numStrings) || |
| 1852 | | (!menuStrings.subStrings && menuStrings.numStrings) || |
| 1853 | | (!menuStrings.buf && storageNeeded)) |
| 2302 | if( (menu_strings.main_list == NULL && menu_strings.length) || |
| 2303 | (menu_strings.sub_list == NULL && menu_strings.length) || |
| 2304 | (menu_strings.flag_list == NULL && menu_strings.length) || |
| 2305 | (menu_strings.main_strings == NULL && menu_strings.num_strings) || |
| 2306 | (menu_strings.sub_strings == NULL && menu_strings.num_strings) || |
| 2307 | (menu_strings.buf == NULL && storage_needed)) |
| 1854 | 2308 | { |
| 1855 | | fatalerror( "cheat: memory allocation error\n" |
| 2309 | fatalerror( "cheat: [string table] memory allocation error\n" |
| 1856 | 2310 | " length = %.8X\n" |
| 1857 | | " numStrings = %.8X\n" |
| 1858 | | " mainStringLength = %.8X\n" |
| 1859 | | " subStringLength = %.8X\n" |
| 2311 | " num_strings = %.8X\n" |
| 2312 | " main_stringLength = %.8X\n" |
| 2313 | " sub_string_length = %.8X\n" |
| 1860 | 2314 | "%p %p %p %p %p %p\n", |
| 1861 | | menuStrings.length, |
| 1862 | | menuStrings.numStrings, |
| 1863 | | menuStrings.mainStringLength, |
| 1864 | | menuStrings.subStringLength, |
| 2315 | menu_strings.length, |
| 2316 | menu_strings.num_strings, |
| 2317 | menu_strings.main_string_length, |
| 2318 | menu_strings.sub_string_length, |
| 1865 | 2319 | |
| 1866 | | menuStrings.mainList, |
| 1867 | | menuStrings.subList, |
| 1868 | | menuStrings.flagList, |
| 1869 | | menuStrings.mainStrings, |
| 1870 | | menuStrings.subStrings, |
| 1871 | | menuStrings.buf); |
| 2320 | menu_strings.main_list, |
| 2321 | menu_strings.sub_list, |
| 2322 | menu_strings.flag_list, |
| 2323 | menu_strings.main_strings, |
| 2324 | menu_strings.sub_strings, |
| 2325 | menu_strings.buf); |
| 1872 | 2326 | } |
| 1873 | 2327 | |
| 1874 | | traverse = menuStrings.buf; |
| 2328 | traverse = menu_strings.buf; |
| 1875 | 2329 | |
| 1876 | | for(i = 0; i < menuStrings.numStrings; i++) |
| 2330 | /* allocate string buffer to list */ |
| 2331 | for(i = 0; i < menu_strings.num_strings; i++) |
| 1877 | 2332 | { |
| 1878 | | menuStrings.mainStrings[i] = traverse; |
| 1879 | | traverse += menuStrings.mainStringLength; |
| 1880 | | |
| 1881 | | menuStrings.subStrings[i] = traverse; |
| 1882 | | traverse += menuStrings.subStringLength; |
| 2333 | menu_strings.main_strings[i] = traverse; |
| 2334 | traverse += menu_strings.main_string_length; |
| 2335 | menu_strings.sub_strings[i] = traverse; |
| 2336 | traverse += menu_strings.sub_string_length; |
| 1883 | 2337 | } |
| 1884 | 2338 | } |
| 1885 | 2339 | |
| 1886 | | /*----------------------------------------------------------- |
| 1887 | | RequestStrings - check list length and rebuild if needed |
| 1888 | | -----------------------------------------------------------*/ |
| 2340 | /*------------------------------------------------------------ |
| 2341 | request_strings - check string list and rebuild if needed |
| 2342 | ------------------------------------------------------------*/ |
| 1889 | 2343 | |
| 1890 | | static void RequestStrings(UINT32 length, UINT32 numStrings, UINT32 mainStringLength, UINT32 subStringLength) |
| 2344 | static void request_strings(UINT32 length, UINT32 num_strings, UINT32 main_string_length, UINT32 sub_string_length) |
| 1891 | 2345 | { |
| 1892 | | UINT8 changed = 0; |
| 2346 | UINT8 changed = 0; |
| 1893 | 2347 | |
| 1894 | | if(menuStrings.length < length) |
| 2348 | /* total items */ |
| 2349 | if(menu_strings.length < length) |
| 1895 | 2350 | { |
| 1896 | | menuStrings.length = length; |
| 1897 | | |
| 2351 | menu_strings.length = length; |
| 1898 | 2352 | changed = 1; |
| 1899 | 2353 | } |
| 1900 | 2354 | |
| 1901 | | if(menuStrings.numStrings < numStrings) |
| 2355 | /* total buffer items */ |
| 2356 | if(menu_strings.num_strings < num_strings) |
| 1902 | 2357 | { |
| 1903 | | menuStrings.numStrings = numStrings; |
| 1904 | | |
| 2358 | menu_strings.num_strings = num_strings; |
| 1905 | 2359 | changed = 1; |
| 1906 | 2360 | } |
| 1907 | 2361 | |
| 1908 | | if(menuStrings.mainStringLength < mainStringLength) |
| 2362 | /* length of buffer 1*/ |
| 2363 | if(menu_strings.main_string_length < main_string_length) |
| 1909 | 2364 | { |
| 1910 | | menuStrings.mainStringLength = mainStringLength; |
| 1911 | | |
| 2365 | menu_strings.main_string_length = main_string_length; |
| 1912 | 2366 | changed = 1; |
| 1913 | 2367 | } |
| 1914 | 2368 | |
| 1915 | | if(menuStrings.subStringLength < subStringLength) |
| 2369 | /* length of buffer 2 */ |
| 2370 | if(menu_strings.sub_string_length < sub_string_length) |
| 1916 | 2371 | { |
| 1917 | | menuStrings.subStringLength = subStringLength; |
| 1918 | | |
| 2372 | menu_strings.sub_string_length = sub_string_length; |
| 1919 | 2373 | changed = 1; |
| 1920 | 2374 | } |
| 1921 | 2375 | |
| 1922 | 2376 | if(changed) |
| 1923 | | RebuildStringTables(); |
| 2377 | rebuild_string_tables(); |
| 1924 | 2378 | } |
| 1925 | 2379 | |
| 1926 | | /*------------------ |
| 1927 | | InitStringTable |
| 1928 | | ------------------*/ |
| 2380 | /*---------------------------------------------- |
| 2381 | init_string_table - initialize string table |
| 2382 | ----------------------------------------------*/ |
| 1929 | 2383 | |
| 1930 | | static void InitStringTable(void) |
| 2384 | static void init_string_table(void) |
| 1931 | 2385 | { |
| 1932 | | memset(&menuStrings, 0, sizeof(MenuStringList)); |
| 2386 | memset(&menu_strings, 0, sizeof(menu_string_list)); |
| 1933 | 2387 | } |
| 1934 | 2388 | |
| 1935 | | /*------------------ |
| 1936 | | FreeStringTable |
| 1937 | | ------------------*/ |
| 2389 | /*---------------------------------------- |
| 2390 | free_string_table - free string table |
| 2391 | ----------------------------------------*/ |
| 1938 | 2392 | |
| 1939 | | static void FreeStringTable(void) |
| 2393 | static void free_string_table(void) |
| 1940 | 2394 | { |
| 1941 | | free((char *)menuStrings.mainList); |
| 1942 | | free((char *)menuStrings.subList); |
| 1943 | | free(menuStrings.flagList); |
| 1944 | | free(menuStrings.mainStrings); |
| 1945 | | free(menuStrings.subStrings); |
| 1946 | | free(menuStrings.buf); |
| 2395 | free((char *) menu_strings.main_list); |
| 2396 | free((char *) menu_strings.sub_list); |
| 2397 | free( menu_strings.flag_list); |
| 2398 | free( menu_strings.main_strings); |
| 2399 | free( menu_strings.sub_strings); |
| 2400 | free( menu_strings.buf); |
| 1947 | 2401 | |
| 1948 | | memset(&menuStrings, 0, sizeof(MenuStringList)); |
| 2402 | memset(&menu_strings, 0, sizeof(menu_string_list)); |
| 1949 | 2403 | } |
| 1950 | 2404 | |
| 1951 | | /*--------------------------------------------------------------------------- |
| 1952 | | CreateStringCopy - copy stirng. It is only called on LoadCheatFile() now |
| 1953 | | ---------------------------------------------------------------------------*/ |
| 2405 | /*----------------------------------- |
| 2406 | create_string_copy - copy stirng |
| 2407 | -----------------------------------*/ |
| 1954 | 2408 | |
| 1955 | | static char * CreateStringCopy(char * buf) |
| 2409 | static char *create_string_copy(char *buf) |
| 1956 | 2410 | { |
| 1957 | | char * temp = NULL; |
| 2411 | char *temp = NULL; |
| 1958 | 2412 | |
| 1959 | 2413 | if(buf) |
| 1960 | 2414 | { |
| 1961 | | size_t length = strlen(buf) + 1; |
| 2415 | /* allocate memory */ |
| 2416 | size_t length = strlen(buf) + 1; |
| 2417 | temp = malloc_or_die(length); |
| 1962 | 2418 | |
| 1963 | | temp = malloc(length); |
| 1964 | | |
| 2419 | /* copy memory for string */ |
| 1965 | 2420 | if(temp) |
| 1966 | 2421 | memcpy(temp, buf, length); |
| 1967 | 2422 | } |
| r2762 | r2763 | |
| 1969 | 2424 | return temp; |
| 1970 | 2425 | } |
| 1971 | 2426 | |
| 1972 | | /*------------------------------------------------------------ |
| 1973 | | UserSelectValueMenu - management for value-selection menu |
| 1974 | | ------------------------------------------------------------*/ |
| 2427 | /*-------------------------------------------------- |
| 2428 | old_style_menu - export menu items to draw menu |
| 2429 | --------------------------------------------------*/ |
| 1975 | 2430 | |
| 1976 | | static INT32 UserSelectValueMenu(running_machine *machine, int selection, CheatEntry * entry) |
| 2431 | static void old_style_menu(const char **items, const char **sub_items, char *flag, int selected, int arrowize_subitem) |
| 1977 | 2432 | { |
| 1978 | | char buf[2048]; |
| 1979 | | int sel; |
| 1980 | | CheatAction * action; |
| 1981 | | static INT32 value = -1; |
| 1982 | | static int firstTime = 1; |
| 1983 | | int delta = 0; |
| 1984 | | int displayValue; |
| 1985 | | int keyValue; |
| 1986 | | int forceUpdate = 0; |
| 2433 | int menu_items; |
| 2434 | static ui_menu_item item_list[1000]; |
| 1987 | 2435 | |
| 1988 | | sel = selection - 1; |
| 2436 | for(menu_items = 0; items[menu_items]; menu_items++) |
| 2437 | { |
| 2438 | item_list[menu_items].text = items[menu_items]; |
| 2439 | item_list[menu_items].subtext = sub_items ? sub_items[menu_items] : NULL; |
| 2440 | item_list[menu_items].flags = 0; |
| 1989 | 2441 | |
| 1990 | | action = &entry->actionList[0]; |
| 2442 | /* set a highlight for sub-item */ |
| 2443 | if(flag && flag[menu_items]) |
| 2444 | item_list[menu_items].flags |= MENU_FLAG_INVERT; |
| 1991 | 2445 | |
| 1992 | | /* ----- if we're just entering, save the value ----- */ |
| 1993 | | if(firstTime) |
| 2446 | /* set an arrow for sub-item */ |
| 2447 | if(menu_items == selected) |
| 2448 | { |
| 2449 | if (arrowize_subitem & 1) |
| 2450 | item_list[menu_items].flags |= MENU_FLAG_LEFT_ARROW; |
| 2451 | if (arrowize_subitem & 2) |
| 2452 | item_list[menu_items].flags |= MENU_FLAG_RIGHT_ARROW; |
| 2453 | } |
| 2454 | } |
| 2455 | |
| 2456 | visible_items = ui_menu_draw(item_list, menu_items, selected, NULL); |
| 2457 | } |
| 2458 | |
| 2459 | /*------------------------------------------------------- |
| 2460 | init_cheat_menu_stack - initilalize cheat menu stack |
| 2461 | -------------------------------------------------------*/ |
| 2462 | |
| 2463 | static void init_cheat_menu_stack(void) |
| 2464 | { |
| 2465 | cheat_menu_stack *menu = &menu_stack[stack_index = 0]; |
| 2466 | |
| 2467 | menu->handler = cheat_main_menu; |
| 2468 | menu->sel = 0; |
| 2469 | menu->pre_sel = 0; |
| 2470 | menu->first_time = 1; |
| 2471 | } |
| 2472 | |
| 2473 | /*----------------------------------------------------- |
| 2474 | cheat_menu_stack_push - push a menu onto the stack |
| 2475 | -----------------------------------------------------*/ |
| 2476 | |
| 2477 | static void cheat_menu_stack_push(cheat_menu_handler new_handler, cheat_menu_handler ret_handler, int selection) |
| 2478 | { |
| 2479 | cheat_menu_stack *menu = &menu_stack[++stack_index]; |
| 2480 | |
| 2481 | assert(stack_index < CHEAT_MENU_DEPTH); |
| 2482 | |
| 2483 | menu->handler = new_handler; |
| 2484 | menu->return_handler = ret_handler; |
| 2485 | menu->sel = 0; |
| 2486 | menu->pre_sel = selection; |
| 2487 | menu->first_time = 1; |
| 2488 | editActive = 0; |
| 2489 | } |
| 2490 | |
| 2491 | /*--------------------------------------------------- |
| 2492 | cheat_menu_stack_pop - pop a menu from the stack |
| 2493 | ---------------------------------------------------*/ |
| 2494 | |
| 2495 | static void cheat_menu_stack_pop(void) |
| 2496 | { |
| 2497 | int i; |
| 2498 | |
| 2499 | assert(stack_index > 0); |
| 2500 | |
| 2501 | /* NOTE : cheat menu supports deep-return */ |
| 2502 | for(i = stack_index; i > 0; i--) |
| 2503 | if(menu_stack[stack_index].return_handler == menu_stack[i].handler) |
| 2504 | break; |
| 2505 | |
| 2506 | stack_index = i; |
| 2507 | } |
| 2508 | |
| 2509 | /*----------------------------------------------------- |
| 2510 | free_cheat_menu_stack - reset the cheat menu stack |
| 2511 | -----------------------------------------------------*/ |
| 2512 | |
| 2513 | static void free_cheat_menu_stack(void) |
| 2514 | { |
| 2515 | int i; |
| 2516 | cheat_menu_stack *menu; |
| 2517 | |
| 2518 | for(i = 0; i < CHEAT_MENU_DEPTH; i++) |
| 1994 | 2519 | { |
| 1995 | | UINT32 min = EXTRACT_FIELD(action->type, UserSelectMinimum); |
| 1996 | | UINT32 max = action->originalDataField + min; |
| 2520 | menu = &menu_stack[i]; |
| 1997 | 2521 | |
| 1998 | | value = ReadData(action); |
| 2522 | menu->handler = NULL; |
| 2523 | menu->return_handler = NULL; |
| 2524 | menu->pre_sel = 0; |
| 2525 | menu->first_time = 0; |
| 2526 | } |
| 1999 | 2527 | |
| 2000 | | /* ----- and check for valid BCD values ----- */ |
| 2001 | | if(TEST_FIELD(action->type, UserSelectBCD)) |
| 2528 | stack_index = 0; |
| 2529 | } |
| 2530 | |
| 2531 | /*--------------------------------------------------------------- |
| 2532 | user_select_value_menu - management for value-selection menu |
| 2533 | ---------------------------------------------------------------*/ |
| 2534 | |
| 2535 | static int user_select_value_menu(running_machine *machine, cheat_menu_stack *menu) |
| 2536 | { |
| 2537 | int i; |
| 2538 | UINT8 isBCD; |
| 2539 | UINT32 min; |
| 2540 | UINT32 max; |
| 2541 | static int master = 0; |
| 2542 | static int displayValue = -1; |
| 2543 | char buf[256]; |
| 2544 | char * stringsBuf = buf; |
| 2545 | CheatEntry * entry = &cheatList[menu->pre_sel]; |
| 2546 | CheatAction * action = NULL; |
| 2547 | |
| 2548 | /* first setting 1 : search master code of value-selection */ |
| 2549 | if(menu->first_time) |
| 2550 | { |
| 2551 | for(i = 0; i < entry->actionListLength; i++) |
| 2002 | 2552 | { |
| 2003 | | value = BCDToDecimal(value); |
| 2004 | | value = DecimalToBCD(value); |
| 2553 | /* get value selection master code */ |
| 2554 | if( EXTRACT_FIELD(entry->actionList[i].type, CodeType) == kCodeType_VWrite || |
| 2555 | EXTRACT_FIELD(entry->actionList[i].type, CodeType) == kCodeType_VRWrite) |
| 2556 | { |
| 2557 | master = i; |
| 2558 | break; |
| 2559 | } |
| 2005 | 2560 | } |
| 2561 | } |
| 2006 | 2562 | |
| 2007 | | if(value < min) |
| 2008 | | value = max; |
| 2009 | | if(value > max) |
| 2010 | | value = min; |
| 2563 | action = &entry->actionList[master]; |
| 2011 | 2564 | |
| 2012 | | action->data = value; |
| 2013 | | firstTime = 0; |
| 2014 | | } |
| 2565 | if(TEST_FIELD(action->type, ValueSelectMinimumDisplay) || TEST_FIELD(action->type, ValueSelectMinimum)) |
| 2566 | min = 1; |
| 2567 | else |
| 2568 | min = 0; |
| 2015 | 2569 | |
| 2016 | | displayValue = value; |
| 2570 | max = action->originalDataField + min; |
| 2571 | isBCD = EXTRACT_FIELD(action->type, ValueSelectBCD); |
| 2017 | 2572 | |
| 2018 | | /* ----- if the minimum display value is one, add one to the display value ----- */ |
| 2019 | | if(TEST_FIELD(action->type, UserSelectMinimumDisplay)) |
| 2573 | /* first setting 2 : save the value */ |
| 2574 | if(menu->first_time) |
| 2020 | 2575 | { |
| 2021 | | if(TEST_FIELD(action->type, UserSelectBCD)) |
| 2022 | | displayValue = BCDToDecimal(displayValue); // bcd -> dec |
| 2576 | displayValue = isBCD ? DecimalToBCD(BCDToDecimal(ReadData(action))) : ReadData(action); |
| 2023 | 2577 | |
| 2024 | | displayValue++; |
| 2578 | if(displayValue < min) |
| 2579 | displayValue = min; |
| 2580 | else if(displayValue > max) |
| 2581 | displayValue = max; |
| 2582 | else if(TEST_FIELD(action->type, ValueSelectMinimumDisplay)) |
| 2583 | displayValue++; |
| 2025 | 2584 | |
| 2026 | | if(TEST_FIELD(action->type, UserSelectBCD)) |
| 2027 | | displayValue = DecimalToBCD(displayValue); // dec -> bcd |
| 2585 | menu->first_time = 0; |
| 2028 | 2586 | } |
| 2029 | 2587 | |
| 2030 | | /* ----- print it ----- */ |
| 2031 | | if(TEST_FIELD(action->type, UserSelectBCD)) |
| 2032 | | sprintf(buf, "\tSelect a value\n\t%.2X\n", displayValue); |
| 2588 | /* ##### MENU CONSTRACTION ##### */ |
| 2589 | stringsBuf += sprintf(stringsBuf, "\t%s\n\t", entry->name); |
| 2590 | |
| 2591 | if(editActive) |
| 2592 | { |
| 2593 | for(i = kSearchByteDigitsTable[EXTRACT_FIELD(action->type, AddressSize)] - 1; i >= 0; i--) |
| 2594 | { |
| 2595 | if(i == editCursor) |
| 2596 | stringsBuf += sprintf(stringsBuf, "[%X]", (displayValue & kIncrementMaskTable[i]) / kIncrementValueTable[i]); |
| 2597 | else |
| 2598 | stringsBuf += sprintf(stringsBuf, "%X", (displayValue & kIncrementMaskTable[i]) / kIncrementValueTable[i]); |
| 2599 | } |
| 2600 | } |
| 2033 | 2601 | else |
| 2034 | | sprintf(buf, "\tSelect a value\n\t%.2X (%d)\n", displayValue, displayValue); |
| 2602 | stringsBuf += sprintf(stringsBuf, "%.*X", kSearchByteDigitsTable[EXTRACT_FIELD(action->type, AddressSize)], displayValue); |
| 2035 | 2603 | |
| 2036 | | /* ----- create fake menu strings ----- */ |
| 2037 | | strcat(buf, "\t OK "); |
| 2604 | if(TEST_FIELD(action->type, ValueSelectNegative)) |
| 2605 | stringsBuf += sprintf( stringsBuf, " <%.*X>", |
| 2606 | kSearchByteDigitsTable[EXTRACT_FIELD(action->type, AddressSize)], |
| 2607 | (~displayValue + 1) & kSearchByteMaskTable[EXTRACT_FIELD(action->type, AddressSize)]); |
| 2038 | 2608 | |
| 2039 | | /* ----- print it ----- */ |
| 2609 | if(!isBCD) |
| 2610 | stringsBuf += sprintf(stringsBuf, " (%d)", displayValue); |
| 2611 | |
| 2612 | stringsBuf += sprintf(stringsBuf, "\n\t OK "); |
| 2613 | |
| 2614 | /* print it */ |
| 2040 | 2615 | ui_draw_message_window(buf); |
| 2041 | 2616 | |
| 2042 | 2617 | /********** KEY HANDLING **********/ |
| 2043 | | if(UIPressedRepeatThrottle(machine, IPT_UI_LEFT, kHorizontalFastKeyRepeatRate)) |
| 2044 | | delta = -1; |
| 2618 | if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kHorizontalFastKeyRepeatRate)) |
| 2619 | { |
| 2620 | if(editActive) |
| 2621 | { |
| 2622 | if(displayValue == max) |
| 2623 | displayValue = min; |
| 2624 | else |
| 2625 | { |
| 2626 | displayValue = isBCD ? DoIncrementDecField(displayValue, editCursor) : DoIncrementHexField(displayValue, editCursor); |
| 2045 | 2627 | |
| 2046 | | if(UIPressedRepeatThrottle(machine, IPT_UI_RIGHT, kHorizontalFastKeyRepeatRate)) |
| 2047 | | delta = 1; |
| 2048 | | |
| 2049 | | if(input_ui_pressed(machine, IPT_UI_SELECT)) |
| 2628 | if(displayValue > max) |
| 2629 | displayValue = max; |
| 2630 | } |
| 2631 | } |
| 2632 | } |
| 2633 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kHorizontalFastKeyRepeatRate)) |
| 2050 | 2634 | { |
| 2051 | | /* ### redundant?? probably can be removed ### */ |
| 2052 | | if(!firstTime) |
| 2635 | if(editActive) |
| 2053 | 2636 | { |
| 2054 | | int i; |
| 2637 | if(displayValue == min) |
| 2638 | displayValue = max; |
| 2055 | 2639 | |
| 2056 | | /* ----- copy data field if copy previous value ----- */ |
| 2057 | | for(i = 0; i < entry->actionListLength; i++) |
| 2640 | else |
| 2058 | 2641 | { |
| 2059 | | CheatAction * traverse = &entry->actionList[i]; |
| 2642 | displayValue = isBCD ? DoDecrementDecField(displayValue, editCursor) : DoDecrementHexField(displayValue, editCursor); |
| 2060 | 2643 | |
| 2061 | | INT32 copyValue = value; |
| 2644 | if(displayValue > max) |
| 2645 | displayValue = max; |
| 2646 | } |
| 2647 | } |
| 2648 | } |
| 2649 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_LEFT, kHorizontalFastKeyRepeatRate)) |
| 2650 | { |
| 2651 | if(editActive) |
| 2652 | { |
| 2653 | if(++editCursor > kSearchByteDigitsTable[EXTRACT_FIELD(action->type, AddressSize)] - 1) |
| 2654 | editCursor = 0; |
| 2655 | } |
| 2656 | else |
| 2657 | { |
| 2658 | if(displayValue-- == min) |
| 2659 | displayValue = max; |
| 2062 | 2660 | |
| 2063 | | if(TEST_FIELD(traverse->type, LinkEnable) && TEST_FIELD(traverse->type, LinkCopyPreviousValue)) |
| 2064 | | { |
| 2065 | | INT32 newData = traverse->originalDataField; |
| 2661 | if(isBCD) |
| 2662 | displayValue = DecimalToBCD(BCDToDecimal(displayValue)); |
| 2663 | } |
| 2664 | } |
| 2665 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_RIGHT, kHorizontalFastKeyRepeatRate)) |
| 2666 | { |
| 2667 | if(editActive) |
| 2668 | { |
| 2669 | if(--editCursor < 0) |
| 2670 | editCursor = kSearchByteDigitsTable[EXTRACT_FIELD(action->type, AddressSize)] - 1; |
| 2671 | } |
| 2672 | else |
| 2673 | { |
| 2674 | if(++displayValue > max) |
| 2675 | displayValue = min; |
| 2066 | 2676 | |
| 2067 | | if(TEST_FIELD(traverse->type, UserSelectBCD)) |
| 2068 | | { |
| 2069 | | copyValue = BCDToDecimal(value); |
| 2070 | | copyValue = DecimalToBCD(value); |
| 2677 | if(isBCD) |
| 2678 | displayValue = DecimalToBCD(BCDToDecimal(displayValue)); |
| 2679 | } |
| 2680 | } |
| 2681 | else if(input_ui_pressed(machine, IPT_UI_SELECT)) |
| 2682 | { |
| 2683 | int i; |
| 2071 | 2684 | |
| 2072 | | newData = BCDToDecimal(newData); |
| 2073 | | newData = DecimalToBCD(newData); |
| 2074 | | } |
| 2685 | if(editActive) |
| 2686 | editActive = 0; |
| 2075 | 2687 | |
| 2076 | | copyValue += newData; |
| 2688 | /* adjust a value */ |
| 2689 | if(TEST_FIELD(action->type, ValueSelectMinimumDisplay)) |
| 2690 | displayValue--; |
| 2077 | 2691 | |
| 2078 | | if(TEST_FIELD(traverse->type, UserSelectBCD)) |
| 2079 | | { |
| 2080 | | copyValue = BCDToDecimal(copyValue); |
| 2081 | | copyValue = DecimalToBCD(copyValue); |
| 2082 | | } |
| 2692 | if(TEST_FIELD(action->type, ValueSelectMinimum) && !displayValue) |
| 2693 | displayValue = 1; |
| 2694 | |
| 2695 | if(TEST_FIELD(action->type, ValueSelectNegative) && displayValue) |
| 2696 | displayValue = (~displayValue + 1) & kSearchByteMaskTable[EXTRACT_FIELD(action->type, AddressSize)]; |
| 2697 | |
| 2698 | /* copy value */ |
| 2699 | for(i = 0; i < entry->actionListLength; i++) |
| 2700 | { |
| 2701 | CheatAction * destination = &entry->actionList[i]; |
| 2702 | |
| 2703 | int copyValue = displayValue; |
| 2704 | |
| 2705 | if( EXTRACT_FIELD(destination->type, CodeType) == kCodeType_VWrite || |
| 2706 | EXTRACT_FIELD(destination->type, CodeType) == kCodeType_VRWrite) |
| 2707 | { |
| 2708 | destination->data = displayValue; |
| 2709 | } |
| 2710 | else if(EXTRACT_FIELD(destination->type, Link) == kLink_CopyLink) |
| 2711 | { |
| 2712 | int newData = destination->originalDataField; |
| 2713 | |
| 2714 | if(TEST_FIELD(destination->type, LinkValueSelectBCD)) |
| 2715 | { |
| 2716 | copyValue = BCDToDecimal(DecimalToBCD(copyValue)); |
| 2717 | newData = BCDToDecimal(DecimalToBCD(newData)); |
| 2083 | 2718 | } |
| 2084 | 2719 | |
| 2085 | | if(!i || TEST_FIELD(traverse->type, LinkCopyPreviousValue)) |
| 2086 | | traverse->data = copyValue; |
| 2720 | copyValue += newData; |
| 2721 | |
| 2722 | if(TEST_FIELD(destination->type, LinkValueSelectBCD)) |
| 2723 | copyValue = DecimalToBCD(BCDToDecimal(copyValue)); |
| 2724 | |
| 2725 | if(TEST_FIELD(destination->type, LinkValueSelectNegative)) |
| 2726 | copyValue = (~copyValue + 1) & kSearchByteMaskTable[EXTRACT_FIELD(destination->type, AddressSize)]; |
| 2727 | |
| 2728 | destination->data = copyValue; |
| 2087 | 2729 | } |
| 2088 | | |
| 2089 | | ActivateCheat(entry); |
| 2090 | 2730 | } |
| 2091 | 2731 | |
| 2092 | | firstTime = 1; |
| 2093 | | sel = -1; |
| 2732 | ActivateCheat(entry); |
| 2733 | |
| 2734 | menu->sel = -1; |
| 2094 | 2735 | } |
| 2736 | else if(input_ui_pressed(machine, IPT_UI_EDIT_CHEAT)) |
| 2737 | { |
| 2738 | editActive ^= 1; |
| 2739 | editCursor = 0; |
| 2740 | } |
| 2741 | else if(input_ui_pressed(machine, IPT_UI_CANCEL)) |
| 2742 | { |
| 2743 | if(editActive) |
| 2744 | editActive = 0; |
| 2745 | else |
| 2746 | menu->sel = -1; |
| 2747 | } |
| 2095 | 2748 | |
| 2096 | | if(input_ui_pressed(machine, IPT_UI_CANCEL)) |
| 2749 | /* ##### EDIT ##### */ |
| 2750 | if(!editActive) |
| 2097 | 2751 | { |
| 2098 | | firstTime = 1; |
| 2099 | | sel = -1; |
| 2752 | UINT32 temp; |
| 2753 | |
| 2754 | temp = displayValue; |
| 2755 | displayValue = do_edit_hex_field(machine, displayValue) & kCheatSizeMaskTable[EXTRACT_FIELD(action->type, AddressSize)]; |
| 2756 | |
| 2757 | if(displayValue != temp) |
| 2758 | { |
| 2759 | if(isBCD) |
| 2760 | displayValue = DecimalToBCD(BCDToDecimal(displayValue)); |
| 2761 | |
| 2762 | if(displayValue < min) displayValue = max; |
| 2763 | if(displayValue > max) displayValue = min; |
| 2764 | } |
| 2100 | 2765 | } |
| 2101 | 2766 | |
| 2102 | | /* ----- get other key inputs ----- */ |
| 2103 | | keyValue = ReadHexInput(); |
| 2767 | return menu->sel + 1; |
| 2768 | } |
| 2104 | 2769 | |
| 2105 | | /* ----- BCD check for input key ----- */ |
| 2106 | | if((keyValue != -1) && TEST_FIELD(action->type, UserSelectBCD) && ((keyValue < 0 ) || (keyValue > 9))) |
| 2107 | | keyValue = -1; |
| 2770 | /*------------------------------------------------------------ |
| 2771 | user_select_label_menu - management for label-select menu |
| 2772 | ------------------------------------------------------------*/ |
| 2108 | 2773 | |
| 2109 | | /* ----- if we got a key ----- */ |
| 2110 | | if(keyValue != -1) |
| 2774 | static int user_select_label_menu(running_machine *machine, cheat_menu_stack *menu) |
| 2775 | { |
| 2776 | int i; |
| 2777 | UINT8 total = 0; |
| 2778 | const char ** menuItem; |
| 2779 | char ** buf; |
| 2780 | CheatEntry * entry = &cheatList[menu->pre_sel]; |
| 2781 | |
| 2782 | /* required items = (total items + return + terminator) & (strings buf * total items [max chars = 100]) */ |
| 2783 | request_strings(entry->actionListLength + 2, entry->actionListLength, 100, 0); |
| 2784 | menuItem = menu_strings.main_list; |
| 2785 | buf = menu_strings.main_strings; |
| 2786 | |
| 2787 | /* first setting : compute cursor position from previous menu */ |
| 2788 | if(menu->first_time) |
| 2111 | 2789 | { |
| 2112 | | /* ----- add it ----- */ |
| 2113 | | value <<= 4; |
| 2790 | menu->sel = entry->flags & kCheatFlag_OneShot ? entry->selection - 1 : entry->selection; |
| 2791 | menu->first_time = 0; |
| 2792 | } |
| 2114 | 2793 | |
| 2115 | | switch(EXTRACT_FIELD(action->type, BytesUsed)) |
| 2794 | /********** MENU CONSTRUCTION **********/ |
| 2795 | for(i = 0; i < entry->labelIndexLength; i++) |
| 2796 | { |
| 2797 | if(!i) |
| 2116 | 2798 | { |
| 2117 | | case 0: // 8 bit |
| 2118 | | value &= 0xF0; |
| 2119 | | break; |
| 2120 | | case 1: // 16 bit |
| 2121 | | value &= 0xFFF0; |
| 2122 | | break; |
| 2123 | | case 2: // 24 bit |
| 2124 | | value &= 0xFFFFF0; |
| 2125 | | break; |
| 2126 | | case 3: // 32 bit |
| 2127 | | value &= 0xFFFFFFF0; |
| 2128 | | break; |
| 2799 | if(!(entry->flags & kCheatFlag_OneShot)) |
| 2800 | { |
| 2801 | /* add "OFF" item if not one shot at the first time */ |
| 2802 | if(!entry->selection) |
| 2803 | sprintf(buf[total], "[ Off ]"); |
| 2804 | else |
| 2805 | sprintf(buf[total], "Off"); |
| 2806 | |
| 2807 | menuItem[total] = buf[total]; |
| 2808 | total++; |
| 2809 | } |
| 2810 | |
| 2811 | continue; |
| 2129 | 2812 | } |
| 2813 | else if(i == entry->selection) |
| 2814 | sprintf(buf[total], "[ %s ]", entry->actionList[entry->labelIndex[i]].optionalName); |
| 2815 | else |
| 2816 | sprintf(buf[total], "%s", entry->actionList[entry->labelIndex[i]].optionalName); |
| 2130 | 2817 | |
| 2131 | | value |= keyValue & 0x0F; |
| 2132 | | |
| 2133 | | delta = 0; |
| 2134 | | forceUpdate = 1; |
| 2818 | menuItem[total] = buf[total]; |
| 2819 | total++; |
| 2135 | 2820 | } |
| 2136 | 2821 | |
| 2137 | | /* ----- wrap-around with BCD stuff. ### this is a really bad way to do this ----- */ |
| 2138 | | if(delta || forceUpdate) |
| 2139 | | { |
| 2140 | | INT32 min = EXTRACT_FIELD(action->type, UserSelectMinimum); |
| 2141 | | INT32 max = action->originalDataField + min; |
| 2822 | /* ##### RETURN ##### */ |
| 2823 | menuItem[total++] = "Return to Prior Menu"; |
| 2142 | 2824 | |
| 2143 | | if(TEST_FIELD(action->type, UserSelectBCD)) |
| 2144 | | value = BCDToDecimal(value); |
| 2825 | /* ##### TERMINATE ARRAY ##### */ |
| 2826 | menuItem[total] = NULL; |
| 2145 | 2827 | |
| 2146 | | value += delta; |
| 2828 | /* adjust current cursor position */ |
| 2829 | ADJUST_CURSOR(menu->sel, total) |
| 2147 | 2830 | |
| 2148 | | if(TEST_FIELD(action->type, UserSelectBCD)) |
| 2149 | | value = DecimalToBCD(value); |
| 2831 | /* draw it */ |
| 2832 | old_style_menu(menuItem, NULL, NULL, menu->sel, 0); |
| 2150 | 2833 | |
| 2151 | | if(value < min) |
| 2152 | | value = max; |
| 2153 | | if(value > max) |
| 2154 | | value = min; |
| 2834 | /********** KEY HANDLING **********/ |
| 2835 | if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate)) |
| 2836 | { |
| 2837 | CURSOR_TO_PREVIOUS(menu->sel, total) |
| 2155 | 2838 | } |
| 2839 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate)) |
| 2840 | { |
| 2841 | CURSOR_TO_NEXT(menu->sel, total) |
| 2842 | } |
| 2843 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate)) |
| 2844 | { |
| 2845 | CURSOR_PAGE_UP(menu->sel); |
| 2846 | } |
| 2847 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate)) |
| 2848 | { |
| 2849 | CURSOR_PAGE_DOWN(menu->sel, total) |
| 2850 | } |
| 2851 | else if(input_ui_pressed(machine, IPT_UI_SELECT)) |
| 2852 | { |
| 2853 | if(menu->sel != total - 1) |
| 2854 | { |
| 2855 | entry->selection = entry->flags & kCheatFlag_OneShot ? menu->sel + 1 : menu->sel; |
| 2156 | 2856 | |
| 2157 | | return sel + 1; |
| 2857 | /* set new label index */ |
| 2858 | if(entry->selection) |
| 2859 | ActivateCheat(entry); |
| 2860 | else |
| 2861 | DeactivateCheat(entry); |
| 2862 | |
| 2863 | /* NOTE : the index number of master code should be stored into 1st table */ |
| 2864 | if(TEST_FIELD(entry->actionList[entry->labelIndex[0]].type, LabelSelectQuickClose)) |
| 2865 | menu->sel = -1; |
| 2866 | } |
| 2867 | else |
| 2868 | menu->sel = -1; |
| 2869 | } |
| 2870 | else if(input_ui_pressed(machine, IPT_UI_CANCEL)) |
| 2871 | menu->sel = -1; |
| 2872 | |
| 2873 | return menu->sel + 1; |
| 2158 | 2874 | } |
| 2159 | 2875 | |
| 2160 | | /*------------------------------------------------- |
| 2161 | | CommentMenu - management comment for code menu |
| 2162 | | -------------------------------------------------*/ |
| 2876 | /*------------------------------------------------ |
| 2877 | comment_menu - management simple comment menu |
| 2878 | ------------------------------------------------*/ |
| 2163 | 2879 | |
| 2164 | | static INT32 CommentMenu(running_machine *machine, int selection, CheatEntry * entry) |
| 2880 | static int comment_menu(running_machine *machine, cheat_menu_stack *menu) |
| 2165 | 2881 | { |
| 2166 | | char buf[2048]; |
| 2167 | | int sel; |
| 2882 | char buf[2048]; |
| 2168 | 2883 | const char * comment; |
| 2884 | CheatEntry * entry = &cheatList[menu->pre_sel]; |
| 2169 | 2885 | |
| 2170 | | if(!entry) |
| 2171 | | return 0; |
| 2886 | /* first setting : NONE */ |
| 2887 | if(menu->first_time) |
| 2888 | menu->first_time = 0; |
| 2172 | 2889 | |
| 2173 | | sel = selection - 1; |
| 2174 | | |
| 2175 | 2890 | /********** MENU CONSTRUCTION **********/ |
| 2176 | 2891 | if(entry->comment && entry->comment[0]) |
| 2177 | 2892 | comment = entry->comment; |
| 2178 | 2893 | else |
| 2179 | | comment = "(none)"; |
| 2894 | comment = "this code doesn't have a comment"; |
| 2180 | 2895 | |
| 2181 | 2896 | sprintf(buf, "%s\n\t OK ", comment); |
| 2182 | 2897 | |
| 2183 | | /* ----- print it ----- */ |
| 2898 | /* print it */ |
| 2184 | 2899 | ui_draw_message_window(buf); |
| 2185 | 2900 | |
| 2186 | 2901 | /********** KEY HANDLING **********/ |
| 2187 | 2902 | if(input_ui_pressed(machine, IPT_UI_SELECT) || input_ui_pressed(machine, IPT_UI_CANCEL)) |
| 2188 | | sel = -1; |
| 2903 | menu->sel = -1; |
| 2189 | 2904 | |
| 2190 | | return sel + 1; |
| 2905 | return menu->sel + 1; |
| 2191 | 2906 | } |
| 2192 | 2907 | |
| 2193 | | /*-------------------------------------------------------------- |
| 2194 | | EnableDisableCheatMenu - management for Enable/Disable menu |
| 2195 | | --------------------------------------------------------------*/ |
| 2908 | /*----------------------------------------------------------- |
| 2909 | extend_comment_menu - management multi-line comment menu |
| 2910 | -----------------------------------------------------------*/ |
| 2196 | 2911 | |
| 2197 | | static int EnableDisableCheatMenu(running_machine *machine, int selection, int firstTime) |
| 2912 | static int extend_comment_menu(running_machine *machine, cheat_menu_stack *menu) |
| 2198 | 2913 | { |
| 2199 | | INT32 sel; |
| 2200 | | static INT32 submenu_choice = 0; |
| 2201 | | static INT32 submenu_id = 0; // 0 = none, 1 = comment, 2 = value-selection, 3 = editCheat |
| 2202 | | const char ** menu_item; |
| 2203 | | const char ** menu_subitem; |
| 2204 | | char * flagBuf; |
| 2205 | | INT32 i; |
| 2206 | | INT32 total = 0; |
| 2914 | int i; |
| 2915 | UINT8 total = 0; |
| 2916 | const char ** menuItem; |
| 2917 | char ** buf; |
| 2918 | CheatEntry * entry = &cheatList[menu->pre_sel]; |
| 2207 | 2919 | |
| 2208 | | CheatEntry * entry; |
| 2920 | if(!entry->actionListLength) |
| 2921 | return 0; |
| 2209 | 2922 | |
| 2210 | | RequestStrings(cheatListLength + 5, 0, 0, 0); |
| 2923 | /* first setting : NONE */ |
| 2924 | if(menu->first_time) |
| 2925 | menu->first_time = 0; |
| 2211 | 2926 | |
| 2212 | | menu_item = menuStrings.mainList; |
| 2213 | | menu_subitem = menuStrings.subList; |
| 2214 | | flagBuf = menuStrings.flagList; |
| 2927 | /* required items = (display comment lines + return + terminator) & (strings buf * display comment lines [max char = 100]) */ |
| 2928 | request_strings(entry->actionListLength + 1, entry->actionListLength - 1, 100, 0); |
| 2929 | menuItem = menu_strings.main_list; |
| 2930 | buf = menu_strings.main_strings; |
| 2215 | 2931 | |
| 2216 | | sel = selection - 1; |
| 2932 | /********** MENU CONSTRUCTION **********/ |
| 2933 | for(i = 1; i < entry->actionListLength; i++) |
| 2934 | { |
| 2935 | CheatAction * action = &entry->actionList[i]; |
| 2217 | 2936 | |
| 2218 | | /********** SUB MENU **********/ |
| 2219 | | if(submenu_choice) |
| 2937 | /* NOTE : don't display the comment in master code */ |
| 2938 | if(i) |
| 2939 | { |
| 2940 | sprintf(buf[total], "%s", action->optionalName); |
| 2941 | menuItem[total] = buf[total]; |
| 2942 | total++; |
| 2943 | } |
| 2944 | } |
| 2945 | |
| 2946 | /* ##### OK ##### */ |
| 2947 | menuItem[total++] = "OK"; |
| 2948 | |
| 2949 | /* ##### TERMINATE ARRAY ##### */ |
| 2950 | menuItem[total] = NULL; |
| 2951 | |
| 2952 | /* adjust cursor position */ |
| 2953 | ADJUST_CURSOR(menu->sel, total) |
| 2954 | |
| 2955 | /* draw it */ |
| 2956 | old_style_menu(menuItem, NULL, NULL, menu->sel, 0); |
| 2957 | |
| 2958 | /********** KEY HANDLING **********/ |
| 2959 | if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate)) |
| 2220 | 2960 | { |
| 2221 | | switch(submenu_id) |
| 2961 | CURSOR_TO_PREVIOUS(menu->sel, total) |
| 2962 | } |
| 2963 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate)) |
| 2964 | { |
| 2965 | CURSOR_TO_NEXT(menu->sel, total) |
| 2966 | } |
| 2967 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate)) |
| 2968 | { |
| 2969 | CURSOR_PAGE_UP(menu->sel) |
| 2970 | } |
| 2971 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate)) |
| 2972 | { |
| 2973 | CURSOR_PAGE_DOWN(menu->sel, total) |
| 2974 | } |
| 2975 | else if(input_ui_pressed(machine, IPT_UI_SELECT) || input_ui_pressed(machine, IPT_UI_CANCEL)) |
| 2976 | menu->sel = -1; |
| 2977 | |
| 2978 | return menu->sel + 1; |
| 2979 | } |
| 2980 | |
| 2981 | /*------------------------------------------------------ |
| 2982 | cheat_main_menu - management for cheat general menu |
| 2983 | ------------------------------------------------------*/ |
| 2984 | |
| 2985 | static int cheat_main_menu(running_machine *machine, cheat_menu_stack *menu) |
| 2986 | { |
| 2987 | enum |
| 2988 | { |
| 2989 | kMenu_EnableDisable = 0, |
| 2990 | kMenu_AddEdit, |
| 2991 | kMenu_Search, |
| 2992 | kMenu_ViewResult, |
| 2993 | kMenu_ChooseWatch, |
| 2994 | kMenu_Options, |
| 2995 | #ifdef MAME_DEBUG |
| 2996 | kMenu_Debug, |
| 2997 | #endif |
| 2998 | kMenu_Return, |
| 2999 | kMenu_Max |
| 3000 | }; |
| 3001 | |
| 3002 | UINT8 total = 0; |
| 3003 | ui_menu_item menu_item[kMenu_Max + 1]; |
| 3004 | |
| 3005 | /* allocate memory for item list */ |
| 3006 | memset(menu_item, 0, sizeof(menu_item)); |
| 3007 | |
| 3008 | /* first setting : NONE */ |
| 3009 | if(menu->first_time) |
| 3010 | menu->first_time = 0; |
| 3011 | |
| 3012 | /********** MENU CONSTRUCION **********/ |
| 3013 | /* ##### Enable/Disable a Cheat ##### */ |
| 3014 | menu_item[total++].text = "Enable/Disable a Cheat"; |
| 3015 | |
| 3016 | /* ##### Add/Edit a Cheat ##### */ |
| 3017 | menu_item[total++].text = "Add/Edit a Cheat"; |
| 3018 | |
| 3019 | /* ##### Search a Cheat ##### */ |
| 3020 | switch(EXTRACT_FIELD(cheatOptions, SearchBox)) |
| 3021 | { |
| 3022 | case kSearchBox_Minimum: |
| 3023 | menu_item[total++].text = "Search a Cheat (Minimum Mode)"; |
| 3024 | break; |
| 3025 | |
| 3026 | case kSearchBox_Standard: |
| 3027 | menu_item[total++].text = "Search a Cheat (Standard Mode)"; |
| 3028 | break; |
| 3029 | |
| 3030 | case kSearchBox_Advanced: |
| 3031 | menu_item[total++].text = "Search a Cheat (Advanced Mode)"; |
| 3032 | break; |
| 3033 | |
| 3034 | default: |
| 3035 | menu_item[total++].text = "Unknown Search Menu"; |
| 3036 | } |
| 3037 | |
| 3038 | /* ##### View Last Result ##### */ |
| 3039 | menu_item[total++].text = "View Last Results"; |
| 3040 | |
| 3041 | /* ##### Configure Watchpoints ##### */ |
| 3042 | menu_item[total++].text = "Configure Watchpoints"; |
| 3043 | |
| 3044 | /* ##### Options ##### */ |
| 3045 | menu_item[total++].text = "Options"; |
| 3046 | |
| 3047 | #ifdef MAME_DEBUG |
| 3048 | /* ##### Debug ##### */ |
| 3049 | menu_item[total++].text = "Debug Viewer"; |
| 3050 | #endif |
| 3051 | |
| 3052 | /* ##### Return to the MAME general menu ##### */ |
| 3053 | menu_item[total++].text = "Return to Main Menu"; |
| 3054 | |
| 3055 | /* ##### Terminate Array ##### */ |
| 3056 | menu_item[total].text = NULL; |
| 3057 | |
| 3058 | ADJUST_CURSOR(menu->sel, total) |
| 3059 | |
| 3060 | /* print it */ |
| 3061 | ui_menu_draw(menu_item, total, menu->sel, NULL); |
| 3062 | |
| 3063 | /********** KEY HANDLING **********/ |
| 3064 | if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate)) |
| 3065 | { |
| 3066 | CURSOR_TO_PREVIOUS(menu->sel, total) |
| 3067 | } |
| 3068 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate)) |
| 3069 | { |
| 3070 | CURSOR_TO_NEXT(menu->sel, total) |
| 3071 | } |
| 3072 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate)) |
| 3073 | { |
| 3074 | CURSOR_PAGE_UP(menu->sel) |
| 3075 | } |
| 3076 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate)) |
| 3077 | { |
| 3078 | CURSOR_PAGE_DOWN(menu->sel, total) |
| 3079 | } |
| 3080 | else if(input_ui_pressed(machine, IPT_UI_SELECT)) |
| 3081 | { |
| 3082 | switch(menu->sel) |
| 2222 | 3083 | { |
| 2223 | | case 1: |
| 2224 | | submenu_choice = CommentMenu(machine, submenu_choice, &cheatList[sel]); |
| 3084 | case kMenu_EnableDisable: |
| 3085 | cheat_menu_stack_push(enable_disable_cheat_menu, cheat_main_menu, menu->sel); |
| 2225 | 3086 | break; |
| 2226 | 3087 | |
| 2227 | | case 2: |
| 2228 | | submenu_choice = UserSelectValueMenu(machine, submenu_choice, &cheatList[sel]); |
| 3088 | case kMenu_AddEdit: |
| 3089 | cheat_menu_stack_push(add_edit_cheat_menu, cheat_main_menu, 0); |
| 2229 | 3090 | break; |
| 2230 | 3091 | |
| 2231 | | case 3: |
| 2232 | | submenu_choice = EditCheatMenu(machine, &cheatList[sel], sel, submenu_choice); |
| 3092 | case kMenu_Search: |
| 3093 | switch(EXTRACT_FIELD(cheatOptions, SearchBox)) |
| 3094 | { |
| 3095 | case kSearchBox_Minimum: |
| 3096 | cheat_menu_stack_push(search_minimum_menu, menu->handler, menu->sel); |
| 3097 | break; |
| 3098 | |
| 3099 | case kSearchBox_Standard: |
| 3100 | cheat_menu_stack_push(search_standard_menu, menu->handler, menu->sel); |
| 3101 | break; |
| 3102 | |
| 3103 | case kSearchBox_Advanced: |
| 3104 | cheat_menu_stack_push(search_advanced_menu, menu->handler, menu->sel); |
| 3105 | } |
| 2233 | 3106 | break; |
| 2234 | 3107 | |
| 2235 | | default: |
| 2236 | | submenu_choice = 0; |
| 3108 | case kMenu_ViewResult: |
| 3109 | cheat_menu_stack_push(view_search_result_menu, menu->handler, menu->sel); |
| 3110 | break; |
| 3111 | |
| 3112 | case kMenu_ChooseWatch: |
| 3113 | cheat_menu_stack_push(choose_watch_menu, menu->handler, menu->sel); |
| 3114 | break; |
| 3115 | |
| 3116 | case kMenu_Options: |
| 3117 | cheat_menu_stack_push(select_option_menu, menu->handler, menu->sel); |
| 3118 | break; |
| 3119 | |
| 3120 | #ifdef MAME_DEBUG |
| 3121 | case kMenu_Debug: |
| 3122 | cheat_menu_stack_push(debug_cheat_menu, menu->handler, menu->sel); |
| 3123 | break; |
| 3124 | #endif |
| 3125 | case kMenu_Return: |
| 3126 | menu->sel = -1; |
| 2237 | 3127 | } |
| 3128 | } |
| 3129 | else if(input_ui_pressed(machine, IPT_UI_RELOAD_CHEAT)) |
| 3130 | { |
| 3131 | ReloadCheatDatabase(machine); |
| 3132 | } |
| 3133 | else if(input_ui_pressed(machine, IPT_UI_CANCEL)) |
| 3134 | { |
| 3135 | menu->sel = -1; |
| 3136 | } |
| 2238 | 3137 | |
| 2239 | | /* ----- meaningless ? because no longer return with sel = -1 (pressed UI_CONFIG in submenu) ----- */ |
| 2240 | | // if(submenu_choice == -1) |
| 2241 | | // { |
| 2242 | | // submenu_choice = 0; |
| 2243 | | // sel = -2; |
| 2244 | | // } |
| 3138 | return menu->sel + 1; |
| 3139 | } |
| 2245 | 3140 | |
| 2246 | | return sel + 1; |
| 3141 | /*----------------------------------------------------------------- |
| 3142 | enable_disable_cheat_menu - management for Enable/Disable menu |
| 3143 | -----------------------------------------------------------------*/ |
| 3144 | |
| 3145 | static int enable_disable_cheat_menu(running_machine *machine, cheat_menu_stack *menu) |
| 3146 | { |
| 3147 | int i; |
| 3148 | UINT8 total = 0; |
| 3149 | UINT8 length = cheatListLength ? cheatListLength : 2; |
| 3150 | UINT8 isEmpty = 0; |
| 3151 | UINT8 * menuIndex; |
| 3152 | static INT8 currentLayer; |
| 3153 | const char ** menu_item; |
| 3154 | const char ** menu_subitem; |
| 3155 | char * flagBuf; |
| 3156 | CheatEntry * entry; |
| 3157 | |
| 3158 | /* first setting : always starts with root layer level */ |
| 3159 | if(menu->first_time) |
| 3160 | { |
| 3161 | currentLayer = 0; |
| 3162 | menu->first_time = 0; |
| 2247 | 3163 | } |
| 2248 | 3164 | |
| 3165 | /* required items = total codes + return + terminator */ |
| 3166 | request_strings(length + 2, 0, 0, 0); |
| 3167 | |
| 3168 | menu_item = menu_strings.main_list; |
| 3169 | menu_subitem = menu_strings.sub_list; |
| 3170 | flagBuf = menu_strings.flag_list; |
| 3171 | |
| 3172 | menuIndex = malloc_or_die(sizeof(INT8) * (length + 1)); |
| 3173 | memset(menuIndex, 0, sizeof(INT8) * (length + 1)); |
| 3174 | |
| 2249 | 3175 | /********** MENU CONSTRUCTION **********/ |
| 2250 | 3176 | for(i = 0; i < cheatListLength; i++) |
| 2251 | 3177 | { |
| 2252 | | CheatEntry * traverse = &cheatList[i]; |
| 3178 | CheatEntry * traverse = &cheatList[i]; |
| 2253 | 3179 | |
| 2254 | | /* ----- get code title ----- */ |
| 2255 | | if(traverse->name) |
| 2256 | | menu_item[total] = traverse->name; |
| 2257 | | else |
| 2258 | | menu_item[total] = "null name"; |
| 3180 | if(total >= fullMenuPageHeight) break; |
| 2259 | 3181 | |
| 2260 | | menu_subitem[total] = NULL; |
| 2261 | | |
| 2262 | | /* ----- get subitem ----- */ |
| 2263 | | if(traverse->flags & kCheatFlag_Select) // label-selection gets sub-lebel name or "OFF" |
| 3182 | /* when return to previous layer, set cursor position to previous layer label code */ |
| 3183 | if(traverse->flags & kCheatFlag_LayerSelected) |
| 2264 | 3184 | { |
| 2265 | | /* ----- no "OFF" item if one shot ----- */ |
| 2266 | | if((traverse->flags & kCheatFlag_OneShot) && !traverse->selection) |
| 2267 | | traverse->selection = 1; // adjust to 1st linked-code |
| 3185 | menu->sel = total; |
| 3186 | traverse->flags &= ~kCheatFlag_LayerSelected; |
| 3187 | } |
| 2268 | 3188 | |
| 2269 | | /* ----- set sub-label name or "OFF" to subitem ----- */ |
| 2270 | | if(traverse->selection && (traverse->selection < traverse->actionListLength)) |
| 2271 | | menu_subitem[total] = traverse->actionList[traverse->selection].optionalName; |
| 2272 | | else |
| 2273 | | menu_subitem[total] = "Off"; |
| 2274 | | } |
| 2275 | | else // others get "ON" or "OFF" |
| 3189 | if(traverse->layerIndex == currentLayer) |
| 2276 | 3190 | { |
| 2277 | | /* ----- add subitems for all cheats that are not comments ----- */ |
| 2278 | | if(!(traverse->flags & kCheatFlag_Null)) |
| 3191 | /* ##### SEPARAOTR ##### */ |
| 3192 | if(traverse->flags & kCheatFlag_Separator) |
| 2279 | 3193 | { |
| 2280 | | if(traverse->flags & kCheatFlag_OneShot) |
| 2281 | | menu_subitem[total] = "Set"; |
| 3194 | menu_item[total] = MENU_SEPARATOR_ITEM; |
| 3195 | menu_subitem[total] = NULL; |
| 3196 | menuIndex[total++] = i; |
| 3197 | } |
| 3198 | else |
| 3199 | { |
| 3200 | /* ##### NAME ##### */ |
| 3201 | if(traverse->name) |
| 3202 | menu_item[total] = traverse->name; |
| 2282 | 3203 | else |
| 3204 | menu_item[total] = "null name"; |
| 3205 | |
| 3206 | /* ##### SUB ITEM ##### */ |
| 3207 | if(traverse->flags & kCheatFlag_HasWrongCode) |
| 2283 | 3208 | { |
| 2284 | | if(traverse->flags & kCheatFlag_Active) |
| 3209 | /* "LOCKED" if wrong code */ |
| 3210 | menu_subitem[total] = "Locked"; |
| 3211 | traverse->selection = 0; |
| 3212 | } |
| 3213 | else if(traverse->flags & kCheatFlag_Select) |
| 3214 | { |
| 3215 | /* label or "OFF" if label-selection though one-shot should ignore "OFF" */ |
| 3216 | if(traverse->selection) |
| 3217 | menu_subitem[total] = traverse->actionList[traverse->labelIndex[traverse->selection]].optionalName; |
| 3218 | else |
| 3219 | menu_subitem[total] = "Off"; |
| 3220 | } |
| 3221 | else if(traverse->flags & kCheatFlag_ExtendComment) |
| 3222 | { |
| 3223 | /* "READ" if extend comment code */ |
| 3224 | menu_subitem[total] = "Read"; |
| 3225 | } |
| 3226 | else if(traverse->flags & kCheatFlag_LayerIndex) |
| 3227 | { |
| 3228 | /* ">>>" (next layer) if layer label code */ |
| 3229 | menu_subitem[total] = ">>>"; |
| 3230 | } |
| 3231 | else if(!(traverse->flags & kCheatFlag_Null)) |
| 3232 | { |
| 3233 | /* otherwise, add sub-items */ |
| 3234 | if(traverse->flags & kCheatFlag_OneShot) |
| 3235 | menu_subitem[total] = "Set"; |
| 3236 | else if(traverse->flags & kCheatFlag_Active) |
| 2285 | 3237 | menu_subitem[total] = "On"; |
| 2286 | 3238 | else |
| 2287 | 3239 | menu_subitem[total] = "Off"; |
| 2288 | 3240 | } |
| 3241 | |
| 3242 | /* set highlight flag if comment is set */ |
| 3243 | if(traverse->comment && traverse->comment[0]) |
| 3244 | flagBuf[total] = 1; |
| 3245 | else |
| 3246 | flagBuf[total] = 0; |
| 3247 | menuIndex[total++] = i; |
| 2289 | 3248 | } |
| 2290 | 3249 | } |
| 2291 | | |
| 2292 | | /* ----- get comment flag ----- */ |
| 2293 | | if(traverse->comment && traverse->comment[0]) |
| 2294 | | flagBuf[total++] = 1; |
| 2295 | | else |
| 2296 | | flagBuf[total++] = 0; |
| 3250 | else if(traverse->flags & kCheatFlag_LayerIndex) |
| 3251 | { |
| 3252 | if(currentLayer == traverse->actionList[0].data) |
| 3253 | { |
| 3254 | /* specified handling previous layer label code with "<<<" (previous layer) */ |
| 3255 | if(traverse->comment) |
| 3256 | menu_item[total] = traverse->comment; |
| 3257 | else |
| 3258 | menu_item[total] = "Return to Prior Layer"; |
| 3259 | menu_subitem[total] = "<<<"; |
| 3260 | flagBuf[total] = 0; |
| 3261 | menuIndex[total++] = i; |
| 3262 | } |
| 3263 | } |
| 2297 | 3264 | } |
| 2298 | 3265 | |
| 2299 | | /* ----- if no code, set special message ----- */ |
| 2300 | | if(cheatListLength == 0) |
| 3266 | /* if no code, set special message */ |
| 3267 | if(!cheatListLength) |
| 2301 | 3268 | { |
| 2302 | | if(foundCheatDatabase) // the database found but no code |
| 3269 | if(foundCheatDatabase) |
| 2303 | 3270 | { |
| 2304 | | menu_item[total] = "there are no cheats for this game"; |
| 2305 | | menu_subitem[total] = NULL; |
| 2306 | | flagBuf[total++] = 0; |
| 3271 | /* the database is found but no code */ |
| 3272 | menu_item[total] = "there are no cheats for this game"; |
| 3273 | menu_subitem[total] = NULL; |
| 3274 | menuIndex[total] = total; |
| 3275 | flagBuf[total++] = 0; |
| 3276 | isEmpty = 1; |
| 2307 | 3277 | } |
| 2308 | | else // the database itself not found |
| 3278 | else |
| 2309 | 3279 | { |
| 2310 | | menu_item[total] = "cheat database not found"; |
| 2311 | | menu_subitem[total] = NULL; |
| 2312 | | flagBuf[total++] = 0; |
| 3280 | /* the database itself is not found */ |
| 3281 | menu_item[total] = "cheat database not found"; |
| 3282 | menu_subitem[total] = NULL; |
| 3283 | menuIndex[total] = total; |
| 3284 | flagBuf[total++] = 0; |
| 2313 | 3285 | |
| 2314 | | menu_item[total] = "unzip it and place it in the MAME directory"; |
| 2315 | | menu_subitem[total] = NULL; |
| 2316 | | flagBuf[total++] = 0; |
| 3286 | menu_item[total] = "unzip it and place it in the MAME directory"; |
| 3287 | menu_subitem[total] = NULL; |
| 3288 | menuIndex[total] = total; |
| 3289 | flagBuf[total++] = 0; |
| 3290 | isEmpty = 2; |
| 2317 | 3291 | } |
| 2318 | 3292 | } |
| 3293 | else if(currentLayer && total == 1) |
| 3294 | { |
| 3295 | /* selected layer doesn't have code */ |
| 3296 | menu_item[total] = "selected layer doesn't have sub code"; |
| 3297 | menu_subitem[total] = NULL; |
| 3298 | menuIndex[total] = menuIndex[total - 1]; |
| 3299 | flagBuf[total++] = 0; |
| 3300 | isEmpty = 3; |
| 3301 | } |
| 2319 | 3302 | |
| 2320 | | /* ----- set return item ----- */ |
| 2321 | | menu_item[total] = "Return to Prior Menu"; |
| 3303 | /* ##### RETURN ##### */ |
| 3304 | if(currentLayer) |
| 3305 | menu_item[total] = "Return to Root Layer"; |
| 3306 | else |
| 3307 | menu_item[total] = "Return to Prior Menu"; |
| 2322 | 3308 | menu_subitem[total] = NULL; |
| 2323 | 3309 | flagBuf[total++] = 0; |
| 2324 | 3310 | |
| 2325 | | menu_item[total] = 0; // terminate array |
| 2326 | | menu_subitem[total] = 0; |
| 3311 | /* ##### TERMINATE ARRAY ##### */ |
| 3312 | menu_item[total] = NULL; |
| 3313 | menu_subitem[total] = NULL; |
| 2327 | 3314 | flagBuf[total] = 0; |
| 2328 | 3315 | |
| 2329 | | /* ----- adjust cursor position ----- */ |
| 2330 | | if(sel < 0) |
| 2331 | | sel = 0; |
| 2332 | | if(sel > (total - 1)) |
| 2333 | | sel = total - 1; |
| 3316 | /* adjust cursor position */ |
| 3317 | switch(isEmpty) |
| 3318 | { |
| 3319 | default: |
| 3320 | ADJUST_CURSOR(menu->sel, total) |
| 2334 | 3321 | |
| 2335 | | /* ----- if cursor is on comment code, skip it ----- */ |
| 2336 | | if(cheatListLength && firstTime) |
| 2337 | | { |
| 2338 | | while((sel < total - 1) && (cheatList[sel].flags & kCheatFlag_Null)) |
| 2339 | | sel++; |
| 3322 | /* if cursor is on comment code, skip it */ |
| 3323 | while(menu->sel < total - 1 && (cheatList[menuIndex[menu->sel]].flags & kCheatFlag_Null)) |
| 3324 | menu->sel++; |
| 3325 | break; |
| 3326 | |
| 3327 | case 1: |
| 3328 | case 2: |
| 3329 | /* no database or code, unselectable message line */ |
| 3330 | menu->sel = total - 1; |
| 3331 | break; |
| 3332 | |
| 3333 | case 3: |
| 3334 | /* no code in sub layer, unselectable message line */ |
| 3335 | if(menu->sel == 1) |
| 3336 | menu->sel = 0; |
| 2340 | 3337 | } |
| 2341 | 3338 | |
| 2342 | | /* ----- draw it ----- */ |
| 2343 | | old_style_menu(menu_item, menu_subitem, flagBuf, sel, 0); |
| 3339 | /* draw it */ |
| 3340 | old_style_menu(menu_item, menu_subitem, flagBuf, menu->sel, 3); |
| 2344 | 3341 | |
| 2345 | 3342 | /********** KEY HANDLING **********/ |
| 2346 | | if(UIPressedRepeatThrottle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate)) |
| 3343 | if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate)) |
| 2347 | 3344 | { |
| 2348 | | sel++; |
| 3345 | switch(isEmpty) |
| 3346 | { |
| 3347 | default: |
| 3348 | CURSOR_TO_PREVIOUS(menu->sel, total) |
| 3349 | if(cheatListLength) |
| 3350 | { |
| 3351 | /* if cursor is on comment code, skip it */ |
| 3352 | for(i = 0; (i < fullMenuPageHeight / 2) && menu->sel != total - 1 && (cheatList[menuIndex[menu->sel]].flags & kCheatFlag_Null); i++) |
| 3353 | { |
| 3354 | if(--menu->sel < 0) |
| 3355 | menu->sel = total - 1; |
| 3356 | } |
| 3357 | } |
| 3358 | break; |
| 2349 | 3359 | |
| 2350 | | if(sel >= total) |
| 2351 | | sel = 0; |
| 3360 | case 1: |
| 3361 | break; |
| 2352 | 3362 | |
| 2353 | | if(cheatListLength) |
| 2354 | | { |
| 2355 | | /* ----- if cursor is on comment code, skip it ----- */ |
| 2356 | | for(i = 0; (i < fullMenuPageHeight / 2) && (sel < total - 1) && (cheatList[sel].flags & kCheatFlag_Null); i++) |
| 2357 | | sel++; |
| 3363 | case 2: |
| 3364 | if(menu->sel) |
| 3365 | menu->sel = 0; |
| 3366 | else |
| 3367 | menu->sel = 2; |
| 2358 | 3368 | } |
| 2359 | 3369 | } |
| 2360 | | |
| 2361 | | if(UIPressedRepeatThrottle(machine, IPT_UI_UP, kVerticalKeyRepeatRate)) |
| 3370 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate)) |
| 2362 | 3371 | { |
| 2363 | | sel--; |
| 2364 | | |
| 2365 | | if(sel < 0) |
| 2366 | | sel = total - 1; |
| 2367 | | else |
| 3372 | switch(isEmpty) |
| 2368 | 3373 | { |
| 2369 | | if(cheatListLength) |
| 2370 | | { |
| 2371 | | /* ----- if cursor is on comment code, skip it ----- */ |
| 2372 | | for(i = 0; (i < fullMenuPageHeight / 2) && (sel != total - 1) && (cheatList[sel].flags & kCheatFlag_Null); i++) |
| 3374 | default: |
| 3375 | CURSOR_TO_NEXT(menu->sel, total) |
| 3376 | if(cheatListLength) |
| 2373 | 3377 | { |
| 2374 | | sel--; |
| 3378 | /* if cursor is on comment code, skip it */ |
| 3379 | for(i = 0; (i < fullMenuPageHeight / 2) && menu->sel < total - 1 && (cheatList[menuIndex[menu->sel]].flags & kCheatFlag_Null); i++) |
| 3380 | menu->sel++; |
| 3381 | } |
| 2375 | 3382 | |
| 2376 | | if(sel < 0) |
| 2377 | | sel = total - 1; |
| 2378 | | } |
| 2379 | | } |
| 3383 | case 1: |
| 3384 | break; |
| 3385 | |
| 3386 | case 2: |
| 3387 | if(menu->sel) |
| 3388 | menu->sel = 0; |
| 3389 | else |
| 3390 | menu->sel = 2; |
| 2380 | 3391 | } |
| 2381 | 3392 | } |
| 2382 | | |
| 2383 | | if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate)) |
| 3393 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate)) |
| 2384 | 3394 | { |
| 2385 | | sel -= fullMenuPageHeight; |
| 2386 | | |
| 2387 | | if(sel < 0) |
| 2388 | | sel = 0; |
| 3395 | CURSOR_PAGE_UP(menu->sel) |
| 2389 | 3396 | } |
| 2390 | | |
| 2391 | | if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate)) |
| 3397 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate)) |
| 2392 | 3398 | { |
| 2393 | | sel += fullMenuPageHeight; |
| 2394 | | |
| 2395 | | if(sel >= total) |
| 2396 | | sel = total - 1; |
| 3399 | CURSOR_PAGE_DOWN(menu->sel, total) |
| 2397 | 3400 | } |
| 2398 | 3401 | |
| 2399 | | if((sel >= 0) && (sel < cheatListLength)) |
| 2400 | | entry = &cheatList[sel]; |
| 3402 | if(menu->sel >= 0 && menu->sel < total - 1) |
| 3403 | entry = &cheatList[menuIndex[menu->sel]]; |
| 2401 | 3404 | else |
| 2402 | 3405 | entry = NULL; |
| 2403 | 3406 | |
| 2404 | | if(UIPressedRepeatThrottle(machine, IPT_UI_LEFT, kHorizontalSlowKeyRepeatRate)) |
| 3407 | if(entry && !(entry->flags & kCheatFlag_Null) && !(entry->flags & kCheatFlag_ExtendComment) && !(entry->flags & kCheatFlag_HasWrongCode)) |
| 2405 | 3408 | { |
| 2406 | | if((sel < (total - 1)) && entry) |
| 3409 | UINT8 toggle = 0; |
| 3410 | |
| 3411 | if(ui_pressed_repeat_throttle(machine, IPT_UI_LEFT, kHorizontalSlowKeyRepeatRate)) |
| 2407 | 3412 | { |
| 2408 | | if(entry->flags & kCheatFlag_Select) // label-selection |
| 3413 | if(entry->flags & kCheatFlag_Select) |
| 2409 | 3414 | { |
| 2410 | | /* ----- move selection to unLinkExtension code or last linked-code ----- */ |
| 2411 | | do{ |
| 2412 | | entry->selection--; |
| 3415 | if(TEST_FIELD(entry->actionList[entry->labelIndex[0]].type, LabelSelectUseSelector)) |
| 3416 | { |
| 3417 | /* activate label selector */ |
| 3418 | cheat_menu_stack_push(user_select_label_menu, menu->handler, menu->sel); |
| 3419 | } |
| 3420 | else |
| 3421 | { |
| 3422 | /* select previous label */ |
| 3423 | if(--entry->selection < 0) |
| 3424 | entry->selection = entry->labelIndexLength - 1; |
| 2413 | 3425 | |
| 2414 | | if(entry->flags & kCheatFlag_OneShot) |
| 2415 | | { |
| 2416 | | if(entry->selection <= 0) |
| 2417 | | entry->selection = entry->actionListLength - 1; // first -> last |
| 2418 | | |
| 2419 | | /* ----- no action when press arrow key ----- */ |
| 2420 | | entry->flags &= ~kCheatFlag_DoOneShot; |
| 2421 | | } |
| 2422 | | else |
| 2423 | | { |
| 2424 | | if(entry->selection < 0) |
| 2425 | | entry->selection = entry->actionListLength - 1; // OFF -> last |
| 2426 | | |
| 2427 | | if(entry->selection == 0) |
| 2428 | | DeactivateCheat(entry); // OFF |
| 2429 | | else |
| 2430 | | { |
| 2431 | | if(!TEST_FIELD(entry->actionList[entry->selection].type, LinkExtension)) |
| 2432 | | ActivateCheat(entry); // ON |
| 2433 | | } |
| 2434 | | } |
| 2435 | | }while(entry->selection && TEST_FIELD(entry->actionList[entry->selection].type, LinkExtension)); |
| 3426 | /* NOTE : one shot cheat should not be activated by changing label */ |
| 3427 | if(!entry->labelIndex[entry->selection]) |
| 3428 | DeactivateCheat(entry); |
| 3429 | else if(!(entry->flags & kCheatFlag_OneShot) && !(entry->flags & kCheatFlag_Active)) |
| 3430 | ActivateCheat(entry); |
| 3431 | } |
| 2436 | 3432 | } |
| 2437 | | else // others |
| 3433 | else if(entry->flags & kCheatFlag_LayerIndex) |
| 2438 | 3434 | { |
| 2439 | | if(!(entry->flags & kCheatFlag_Null) && !(entry->flags & kCheatFlag_OneShot)) |
| 3435 | /* change layer level */ |
| 3436 | toggle = 2; |
| 3437 | } |
| 3438 | else if(!(entry->flags & kCheatFlag_OneShot)) |
| 3439 | { |
| 3440 | /* toggle ON/OFF */ |
| 3441 | toggle = 1; |
| 3442 | } |
| 3443 | } |
| 3444 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_RIGHT, kHorizontalSlowKeyRepeatRate)) |
| 3445 | { |
| 3446 | if(entry->flags & kCheatFlag_Select) |
| 3447 | { |
| 3448 | /* label-selection special handling */ |
| 3449 | if(TEST_FIELD(entry->actionList[entry->labelIndex[0]].type, LabelSelectUseSelector)) |
| 2440 | 3450 | { |
| 2441 | | int active = entry->flags & kCheatFlag_Active; |
| 3451 | /* activate label selector */ |
| 3452 | cheat_menu_stack_push(user_select_label_menu, menu->handler, menu->sel); |
| 3453 | } |
| 3454 | else |
| 3455 | { |
| 3456 | /* select next label index */ |
| 3457 | if(++entry->selection >= entry->labelIndexLength) |
| 3458 | entry->selection = 0; |
| 2442 | 3459 | |
| 2443 | | active ^= 0x01; |
| 2444 | | |
| 2445 | | /* ----- get the user's selected value if needed ----- */ |
| 2446 | | if((entry->flags & kCheatFlag_UserSelect) && active) |
| 2447 | | { |
| 2448 | | submenu_id = 2; |
| 2449 | | submenu_choice = 1; |
| 2450 | | } |
| 2451 | | else |
| 2452 | | { |
| 2453 | | if(active) |
| 2454 | | ActivateCheat(entry); // ON |
| 2455 | | else |
| 2456 | | DeactivateCheat(entry); // OFF |
| 2457 | | } |
| 3460 | /* NOTE : one shot cheat should not be activated by changing label */ |
| 3461 | if(!entry->labelIndex[entry->selection]) |
| 3462 | DeactivateCheat(entry); |
| 3463 | else if(!(entry->flags & kCheatFlag_OneShot) && !(entry->flags & kCheatFlag_Active)) |
| 3464 | ActivateCheat(entry); |
| 2458 | 3465 | } |
| 2459 | 3466 | } |
| 3467 | else if(entry->flags & kCheatFlag_LayerIndex) |
| 3468 | { |
| 3469 | /* change layer level */ |
| 3470 | toggle = 2; |
| 3471 | } |
| 3472 | else if(!(entry->flags & kCheatFlag_OneShot)) |
| 3473 | { |
| 3474 | /* toggle ON/OFF */ |
| 3475 | toggle = 1; |
| 3476 | } |
| 2460 | 3477 | } |
| 2461 | | } |
| 2462 | 3478 | |
| 2463 | | if(UIPressedRepeatThrottle(machine, IPT_UI_RIGHT, kHorizontalSlowKeyRepeatRate)) |
| 2464 | | { |
| 2465 | | if((sel < (total - 1)) && entry) |
| 3479 | switch(toggle) |
| 2466 | 3480 | { |
| 2467 | | if(entry->flags & kCheatFlag_Select) // label-selection |
| 2468 | | { |
| 2469 | | /* ----- move selection to unLinkExtension code or 1st code ----- */ |
| 2470 | | do{ |
| 2471 | | entry->selection++; |
| 2472 | | |
| 2473 | | if(entry->flags & kCheatFlag_OneShot) |
| 2474 | | { |
| 2475 | | if(entry->selection >= entry->actionListLength) |
| 2476 | | { |
| 2477 | | entry->selection = 1; // last -> first |
| 2478 | | |
| 2479 | | if(entry->selection >= entry->actionListLength) |
| 2480 | | entry->selection = 0; |
| 2481 | | } |
| 2482 | | /* ----- no action when press arrow key ----- */ |
| 2483 | | entry->flags &= ~kCheatFlag_DoOneShot; |
| 2484 | | } |
| 2485 | | else // others |
| 2486 | | { |
| 2487 | | if(entry->selection >= entry->actionListLength) |
| 2488 | | { |
| 2489 | | entry->selection = 0; // last -> OFF |
| 2490 | | |
| 2491 | | DeactivateCheat(entry); // OFF |
| 2492 | | } |
| 2493 | | else |
| 2494 | | { |
| 2495 | | if(!TEST_FIELD(entry->actionList[entry->selection].type, LinkExtension)) |
| 2496 | | ActivateCheat(entry); // ON |
| 2497 | | } |
| 2498 | | } |
| 2499 | | }while(entry->selection && TEST_FIELD(entry->actionList[entry->selection].type, LinkExtension)); |
| 2500 | | } |
| 2501 | | else |
| 2502 | | { |
| 2503 | | if(!(entry->flags & kCheatFlag_Null) && !(entry->flags & kCheatFlag_OneShot)) |
| 3481 | case 1: |
| 2504 | 3482 | { |
| 2505 | | int active = entry->flags & kCheatFlag_Active; |
| 3483 | int active = (entry->flags & kCheatFlag_Active) ^ 1; |
| 2506 | 3484 | |
| 2507 | | active ^= 0x01; // toggle On and OFF |
| 2508 | | |
| 2509 | | /* ----- get the user's selected value if needed ----- */ |
| 2510 | 3485 | if((entry->flags & kCheatFlag_UserSelect) && active) |
| 2511 | 3486 | { |
| 2512 | | submenu_id = 2; |
| 2513 | | submenu_choice = 1; |
| 3487 | /* activate value-selection menu */ |
| 3488 | cheat_menu_stack_push(user_select_value_menu, menu->handler, menu->sel); |
| 2514 | 3489 | } |
| 2515 | 3490 | else |
| 2516 | 3491 | { |
| 2517 | 3492 | if(active) |
| 2518 | | ActivateCheat(entry); // ON |
| 3493 | ActivateCheat(entry); |
| 2519 | 3494 | else |
| 2520 | | DeactivateCheat(entry); // OFF |
| 3495 | DeactivateCheat(entry); |
| 2521 | 3496 | } |
| 2522 | 3497 | } |
| 2523 | | } |
| 3498 | break; |
| 3499 | |
| 3500 | case 2: |
| 3501 | { |
| 3502 | /* go to next/previous layer level */ |
| 3503 | if(entry->actionList[0].data == currentLayer) |
| 3504 | currentLayer = entry->actionList[0].address; |
| 3505 | else |
| 3506 | currentLayer = entry->actionList[0].data; |
| 3507 | |
| 3508 | entry->flags |= kCheatFlag_LayerSelected; |
| 3509 | } |
| 3510 | break; |
| 3511 | |
| 3512 | default: |
| 3513 | break; |
| 2524 | 3514 | } |
| 2525 | 3515 | } |
| 2526 | 3516 | |
| 2527 | 3517 | if(input_ui_pressed(machine, IPT_UI_SELECT)) |
| 2528 | 3518 | { |
| 2529 | | if(sel == (total - 1)) |
| 3519 | if(!entry) |
| 2530 | 3520 | { |
| 2531 | | /* ----- return to prior menu ----- */ |
| 2532 | | submenu_choice = 0; |
| 2533 | | sel = -1; |
| 3521 | if(currentLayer) |
| 3522 | currentLayer = menu->sel = 0; |
| 3523 | else |
| 3524 | menu->sel = -1; |
| 2534 | 3525 | } |
| 2535 | | else |
| 3526 | else if(!(entry->flags & kCheatFlag_Null)) |
| 2536 | 3527 | { |
| 2537 | | if((sel < (total - 1)) && entry) |
| 3528 | if(ShiftKeyPressed() && (entry->comment && entry->comment[0])) |
| 2538 | 3529 | { |
| 2539 | | if(ShiftKeyPressed()) |
| 2540 | | { |
| 2541 | | if(entry->comment && entry->comment[0]) |
| 2542 | | { |
| 2543 | | /* ----- display comment ------ */ |
| 2544 | | submenu_id = 1; |
| 2545 | | submenu_choice = 1; |
| 2546 | | } |
| 2547 | | else |
| 2548 | | goto doActivate; |
| 2549 | | } |
| 3530 | /* display comment */ |
| 3531 | cheat_menu_stack_push(comment_menu, menu->handler, menu->sel); |
| 3532 | } |
| 3533 | else if(entry->flags & kCheatFlag_ExtendComment) |
| 3534 | { |
| 3535 | /* activate extend comment menu */ |
| 3536 | cheat_menu_stack_push(extend_comment_menu, menu->handler, menu->sel); |
| 3537 | } |
| 3538 | else if(entry->flags & kCheatFlag_UserSelect) |
| 3539 | { |
| 3540 | /* activate value-selection menu */ |
| 3541 | cheat_menu_stack_push(user_select_value_menu, menu->handler, menu->sel); |
| 3542 | } |
| 3543 | else if((entry->flags & kCheatFlag_Select) && TEST_FIELD(entry->actionList[entry->labelIndex[0]].type, LabelSelectUseSelector)) |
| 3544 | { |
| 3545 | /* activate label selector */ |
| 3546 | cheat_menu_stack_push(user_select_label_menu, menu->handler, menu->sel); |
| 3547 | } |
| 3548 | else if(entry->flags & kCheatFlag_LayerIndex) |
| 3549 | { |
| 3550 | /* go to next/previous layer level */ |
| 3551 | if(entry->actionList[0].data == currentLayer) |
| 3552 | currentLayer = entry->actionList[0].address; |
| 2550 | 3553 | else |
| 2551 | | { |
| 2552 | | doActivate: |
| 3554 | currentLayer = entry->actionList[0].data; |
| 2553 | 3555 | |
| 2554 | | if(entry->flags & kCheatFlag_UserSelect) |
| 2555 | | { |
| 2556 | | /* ----- value-selection menu ----- */ |
| 2557 | | submenu_id = 2; |
| 2558 | | submenu_choice = 1; |
| 2559 | | } |
| 2560 | | else |
| 2561 | | { |
| 2562 | | ActivateCheat(entry); // ON |
| 2563 | | |
| 2564 | | /* ----- set do one shot flag if label-selection ----- */ |
| 2565 | | if((entry->flags & kCheatFlag_Select) && (entry->flags & kCheatFlag_OneShot)) |
| 2566 | | entry->flags |= kCheatFlag_DoOneShot; |
| 2567 | | |
| 2568 | | /* ----- display one shot message if one shot ----- */ |
| 2569 | | if(entry->flags & kCheatFlag_OneShot) |
| 2570 | | ui_popup_time(1, "%s activated", entry->name); |
| 2571 | | } |
| 2572 | | } |
| 3556 | entry->flags |= kCheatFlag_LayerSelected; |
| 2573 | 3557 | } |
| 3558 | else if(entry->flags & kCheatFlag_HasWrongCode) |
| 3559 | { |
| 3560 | /* analyse wrong format code */ |
| 3561 | cheat_menu_stack_push(analyse_cheat_menu, menu->handler, menu->sel); |
| 3562 | } |
| 3563 | else |
| 3564 | { |
| 3565 | /* activate selected code */ |
| 3566 | ActivateCheat(entry); |
| 3567 | } |
| 2574 | 3568 | } |
| 2575 | 3569 | } |
| 2576 | | |
| 2577 | | if(input_ui_pressed(machine, IPT_UI_WATCH_VALUE)) |
| 2578 | | WatchCheatEntry(entry, 0); |
| 2579 | | |
| 2580 | | if(ShiftKeyPressed()) |
| 3570 | else if(input_ui_pressed(machine, IPT_UI_SAVE_CHEAT)) |
| 2581 | 3571 | { |
| 2582 | | if(input_ui_pressed(machine, IPT_UI_SAVE_CHEAT)) // shift + save = save all codes |
| 3572 | if(ShiftKeyPressed()) |
| 2583 | 3573 | { |
| 3574 | /* shift + save : save all codes */ |
| 2584 | 3575 | for(i = 0; i < cheatListLength; i++) |
| 2585 | | SaveCheat(machine, &cheatList[i], 0, 0); |
| 3576 | SaveCheatCode(machine, &cheatList[i]); |
| 2586 | 3577 | |
| 2587 | | ui_popup_time(1, "%d cheats saved", cheatListLength); |
| 3578 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 3579 | messageType = kCheatMessage_AllCheatSaved; |
| 2588 | 3580 | } |
| 2589 | | |
| 2590 | | if(input_ui_pressed(machine, IPT_UI_ADD_CHEAT)) // shift + add = add new emypty code |
| 2591 | | AddCheatBefore(sel); |
| 2592 | | |
| 2593 | | if(input_ui_pressed(machine, IPT_UI_DELETE_CHEAT)) // shift + delete = delete selected code |
| 2594 | | DeleteCheatAt(sel); |
| 3581 | else if(ControlKeyPressed()) |
| 3582 | { |
| 3583 | /* ctrl + save : save activation key */ |
| 3584 | SaveActivationKey(machine, entry, menuIndex[menu->sel]); |
| 3585 | } |
| 3586 | else if(AltKeyPressed()) |
| 3587 | { |
| 3588 | /* alt + save : save pre-enable */ |
| 3589 | SavePreEnable(machine, entry, menuIndex[menu->sel]); |
| 3590 | } |
| 2595 | 3591 | } |
| 2596 | | else |
| 3592 | else if(input_ui_pressed(machine, IPT_UI_ADD_CHEAT)) |
| 2597 | 3593 | { |
| 2598 | | if(ControlKeyPressed()) |
| 3594 | AddCheatBefore(menuIndex[menu->sel]); |
| 3595 | } |
| 3596 | else if(input_ui_pressed(machine, IPT_UI_DELETE_CHEAT)) |
| 3597 | { |
| 3598 | if(entry) |
| 3599 | DeleteCheatAt(menuIndex[menu->sel]); |
| 3600 | else |
| 2599 | 3601 | { |
| 2600 | | if(input_ui_pressed(machine, IPT_UI_SAVE_CHEAT)) // ctrl + save = save activation key |
| 2601 | | { |
| 2602 | | if((entry->flags & kCheatFlag_HasActivationKey1) || (entry->flags & kCheatFlag_HasActivationKey2)) |
| 2603 | | { |
| 2604 | | SaveCheat(machine, entry, sel, 1); |
| 2605 | | |
| 2606 | | ui_popup_time(1, "activation key saved"); |
| 2607 | | } |
| 2608 | | else |
| 2609 | | ui_popup_time(1, "no activation key"); |
| 2610 | | } |
| 3602 | messageType = kCheatMessage_FailedToDelete; |
| 3603 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 2611 | 3604 | } |
| 2612 | | else |
| 3605 | } |
| 3606 | else if(input_ui_pressed(machine, IPT_UI_EDIT_CHEAT)) |
| 3607 | { |
| 3608 | if(entry) |
| 2613 | 3609 | { |
| 2614 | | if(input_ui_pressed(machine, IPT_UI_SAVE_CHEAT)) |
| 2615 | | SaveCheat(machine, entry, 0, 0); // save current entry |
| 3610 | cheat_menu_stack_push(command_add_edit_menu, menu->handler, menu->sel); |
| 2616 | 3611 | } |
| 2617 | 3612 | } |
| 2618 | | |
| 2619 | | if(input_ui_pressed(machine, IPT_UI_EDIT_CHEAT) && entry) // edit selected code |
| 3613 | else if(input_ui_pressed(machine, IPT_UI_WATCH_VALUE)) |
| 2620 | 3614 | { |
| 2621 | | submenu_id = 3; |
| 2622 | | submenu_choice = 1; |
| 3615 | WatchCheatEntry(entry, 0); |
| 2623 | 3616 | } |
| 2624 | | |
| 2625 | | if(input_ui_pressed(machine, IPT_UI_RELOAD_CHEAT)) |
| 3617 | else if(input_ui_pressed(machine, IPT_UI_RELOAD_CHEAT)) |
| 3618 | { |
| 2626 | 3619 | ReloadCheatDatabase(machine); |
| 3620 | } |
| 3621 | else if(input_ui_pressed(machine, IPT_UI_CANCEL)) |
| 3622 | { |
| 3623 | /* NOTE : cancel button return cheat main menu directly */ |
| 3624 | menu->sel = -1; |
| 3625 | } |
| 2627 | 3626 | |
| 2628 | | if(UIPressedRepeatThrottle(machine, IPT_UI_ZOOM_IN, kVerticalKeyRepeatRate)) |
| 2629 | | /* ----- quick menu switch : enable/disable -> add/edit ----- */ |
| 2630 | | sel = -3; |
| 3627 | free(menuIndex); |
| 2631 | 3628 | |
| 2632 | | if(UIPressedRepeatThrottle(machine, IPT_UI_ZOOM_OUT, kVerticalKeyRepeatRate)) |
| 2633 | | /* ----- quick menu switch : enable/disable -> watchpoint list ----- */ |
| 2634 | | sel = -5; |
| 2635 | | |
| 2636 | | if(input_ui_pressed(machine, IPT_UI_CANCEL)) |
| 2637 | | sel = -1; |
| 2638 | | |
| 2639 | | return sel + 1; |
| 3629 | return menu->sel + 1; |
| 2640 | 3630 | } |
| 2641 | 3631 | |
| 2642 | | /*-------------------------------------------------------- |
| 2643 | | AddEditCheatMenu - management for Add/Edit cheat menu |
| 2644 | | --------------------------------------------------------*/ |
| 3632 | /*----------------------------------------------------------- |
| 3633 | add_edit_cheat_menu - management for Add/Edit cheat menu |
| 3634 | -----------------------------------------------------------*/ |
| 2645 | 3635 | |
| 2646 | | static int AddEditCheatMenu(running_machine *machine, int selection) |
| 3636 | static int add_edit_cheat_menu(running_machine *machine, cheat_menu_stack *menu) |
| 2647 | 3637 | { |
| 2648 | | INT32 sel; |
| 2649 | | static INT32 submenuChoice = 0; |
| 2650 | | static INT32 submenuCheat = 0; |
| 3638 | int i; |
| 3639 | UINT8 total = 0; |
| 2651 | 3640 | const char ** menu_item; |
| 2652 | | INT32 i; |
| 2653 | | INT32 total = 0; |
| 2654 | 3641 | CheatEntry * entry; |
| 2655 | 3642 | |
| 2656 | | sel = selection - 1; |
| 3643 | /* first setting : NONE */ |
| 3644 | if(menu->first_time) |
| 3645 | menu->first_time = 0; |
| 2657 | 3646 | |
| 2658 | | RequestStrings(cheatListLength + 2, 0, 0, 0); |
| 3647 | /* required items = total codes + return + terminator */ |
| 3648 | request_strings(cheatListLength + 2, 0, 0, 0); |
| 3649 | menu_item = menu_strings.main_list; |
| 2659 | 3650 | |
| 2660 | | menu_item = menuStrings.mainList; |
| 2661 | | |
| 2662 | | /********** SUB MENU **********/ |
| 2663 | | if(submenuChoice) |
| 2664 | | { |
| 2665 | | submenuChoice = EditCheatMenu(machine, &cheatList[submenuCheat], submenuCheat, submenuChoice); |
| 2666 | | |
| 2667 | | /* ----- meaningless ? because no longer return with sel = -1 (pressed UI_CONFIG in submenu) ----- */ |
| 2668 | | // if(submenuChoice == -1) |
| 2669 | | // { |
| 2670 | | // submenuChoice = 0; |
| 2671 | | // sel = -2; |
| 2672 | | // } |
| 2673 | | |
| 2674 | | return sel + 1; |
| 2675 | | } |
| 2676 | | |
| 2677 | 3651 | /********** MENU CONSTRUCTION **********/ |
| 2678 | 3652 | for(i = 0; i < cheatListLength; i++) |
| 2679 | 3653 | { |
| 2680 | | CheatEntry * traverse = &cheatList[i]; |
| 3654 | CheatEntry * traverse = &cheatList[i]; |
| 2681 | 3655 | |
| 3656 | /* ##### NAME ##### */ |
| 2682 | 3657 | if(traverse->name) |
| 2683 | | menu_item[total++] = traverse->name; // code title |
| 3658 | menu_item[total++] = traverse->name; |
| 2684 | 3659 | else |
| 2685 | 3660 | menu_item[total++] = "(none)"; |
| 2686 | 3661 | } |
| 2687 | 3662 | |
| 2688 | | menu_item[total++] = "Return to Prior Menu"; // return |
| 3663 | /* ##### RETURN ##### */ |
| 3664 | menu_item[total++] = "Return to Prior Menu"; |
| 2689 | 3665 | |
| 2690 | | menu_item[total] = NULL; // terminate array |
| 3666 | /* ##### TERMINATE ARRAY ##### */ |
| 3667 | menu_item[total] = NULL; |
| 2691 | 3668 | |
| 2692 | | /* ----- adjust current cursor position ----- */ |
| 2693 | | if(sel < 0) |
| 2694 | | sel = 0; |
| 2695 | | if(sel >= total) |
| 2696 | | sel = total - 1; |
| 3669 | /* adjust cursor position */ |
| 3670 | ADJUST_CURSOR(menu->sel, total) |
| 2697 | 3671 | |
| 2698 | | /* ----- draw it ----- */ |
| 2699 | | old_style_menu(menu_item, NULL, NULL, sel, 0); |
| 3672 | /* draw it */ |
| 3673 | old_style_menu(menu_item, NULL, NULL, menu->sel, 0); |
| 2700 | 3674 | |
| 3675 | if(menu->sel < total - 1) |
| 3676 | entry = &cheatList[menu->sel]; |
| 3677 | else |
| 3678 | entry = NULL; |
| 3679 | |
| 2701 | 3680 | /********** KEY HANDLING **********/ |
| 2702 | | if(UIPressedRepeatThrottle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate)) |
| 3681 | if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate)) |
| 2703 | 3682 | { |
| 2704 | | sel++; |
| 2705 | | |
| 2706 | | if(sel >= total) |
| 2707 | | sel = 0; |
| 3683 | CURSOR_TO_PREVIOUS(menu->sel, total) |
| 2708 | 3684 | } |
| 2709 | | |
| 2710 | | if(UIPressedRepeatThrottle(machine, IPT_UI_UP, kVerticalKeyRepeatRate)) |
| 3685 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate)) |
| 2711 | 3686 | { |
| 2712 | | sel--; |
| 2713 | | |
| 2714 | | if(sel < 0) |
| 2715 | | sel = total - 1; |
| 3687 | CURSOR_TO_NEXT(menu->sel, total) |
| 2716 | 3688 | } |
| 2717 | | |
| 2718 | | if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate)) |
| 3689 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate)) |
| 2719 | 3690 | { |
| 2720 | | sel -= fullMenuPageHeight; |
| 2721 | | |
| 2722 | | if(sel < 0) |
| 2723 | | sel = 0; |
| 3691 | CURSOR_PAGE_UP(menu->sel) |
| 2724 | 3692 | } |
| 2725 | | |
| 2726 | | if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate)) |
| 3693 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate)) |
| 2727 | 3694 | { |
| 2728 | | sel += fullMenuPageHeight; |
| 2729 | | |
| 2730 | | if(sel >= total) |
| 2731 | | sel = total - 1; |
| 3695 | CURSOR_PAGE_DOWN(menu->sel, total) |
| 2732 | 3696 | } |
| 2733 | | |
| 2734 | | if(sel < (total - 1)) |
| 2735 | | entry = &cheatList[sel]; |
| 2736 | | else |
| 2737 | | entry = NULL; |
| 2738 | | |
| 2739 | | if(input_ui_pressed(machine, IPT_UI_SAVE_CHEAT)) |
| 3697 | else if(input_ui_pressed(machine, IPT_UI_SELECT)) |
| 2740 | 3698 | { |
| 2741 | | if(ShiftKeyPressed()) |
| 3699 | if(entry) |
| 2742 | 3700 | { |
| 2743 | | for(i = 0; i < cheatListLength; i++) // shift + save = save all codes |
| 2744 | | SaveCheat(machine, &cheatList[i], 0, 0); |
| 2745 | | |
| 2746 | | ui_popup_time(1, "%d cheats saved", cheatListLength); |
| 3701 | if(entry->flags & kCheatFlag_HasWrongCode) |
| 3702 | { |
| 3703 | cheat_menu_stack_push(analyse_cheat_menu, menu->handler, menu->sel); |
| 3704 | } |
| 3705 | else |
| 3706 | cheat_menu_stack_push(command_add_edit_menu, menu->handler, menu->sel); |
| 2747 | 3707 | } |
| 2748 | 3708 | else |
| 3709 | menu->sel = -1; |
| 3710 | } |
| 3711 | else if(input_ui_pressed(machine, IPT_UI_RELOAD_CHEAT)) |
| 3712 | { |
| 3713 | ReloadCheatDatabase(machine); |
| 3714 | } |
| 3715 | else if(input_ui_pressed(machine, IPT_UI_EDIT_CHEAT)) |
| 3716 | { |
| 3717 | if(entry) |
| 2749 | 3718 | { |
| 2750 | | if(ControlKeyPressed()) |
| 3719 | if(entry->flags & kCheatFlag_HasWrongCode) |
| 2751 | 3720 | { |
| 2752 | | if((entry->flags & kCheatFlag_HasActivationKey1) || (entry->flags & kCheatFlag_HasActivationKey2)) |
| 2753 | | { |
| 2754 | | SaveCheat(machine, entry, sel, 1); // ctrl + save = save activation key |
| 2755 | | |
| 2756 | | ui_popup_time(1, "activation key saved"); |
| 2757 | | } |
| 2758 | | else |
| 2759 | | ui_popup_time(1, "no activation key"); |
| 3721 | cheat_menu_stack_push(analyse_cheat_menu, menu->handler, menu->sel); |
| 2760 | 3722 | } |
| 2761 | 3723 | else |
| 2762 | | SaveCheat(machine, entry, 0, 0); // save current entry |
| 3724 | cheat_menu_stack_push(command_add_edit_menu, menu->handler, menu->sel); |
| 2763 | 3725 | } |
| 2764 | 3726 | } |
| 2765 | | |
| 2766 | | if(input_ui_pressed(machine, IPT_UI_ADD_CHEAT)) |
| 2767 | | AddCheatBefore(sel); // insert empty code |
| 2768 | | |
| 2769 | | if(input_ui_pressed(machine, IPT_UI_DELETE_CHEAT)) |
| 2770 | | DeleteCheatAt(sel); // delete selected code |
| 2771 | | |
| 2772 | | if(input_ui_pressed(machine, IPT_UI_WATCH_VALUE)) |
| 2773 | | WatchCheatEntry(entry, 0); // watch selected code |
| 2774 | | |
| 2775 | | if(input_ui_pressed(machine, IPT_UI_EDIT_CHEAT)) // edit selected code |
| 3727 | else if(input_ui_pressed(machine, IPT_UI_ADD_CHEAT)) |
| 2776 | 3728 | { |
| 2777 | | /* ----- if selected item is not return, go to edit menu ----- */ |
| 2778 | | if(sel < (total - 1)) |
| 2779 | | { |
| 2780 | | submenuCheat = sel; |
| 2781 | | submenuChoice = 1; |
| 2782 | | } |
| 3729 | AddCheatBefore(menu->sel); |
| 2783 | 3730 | } |
| 2784 | | |
| 2785 | | if(input_ui_pressed(machine, IPT_UI_SELECT)) |
| 3731 | else if(input_ui_pressed(machine, IPT_UI_DELETE_CHEAT)) |
| 2786 | 3732 | { |
| 2787 | | /* ----- if selected item is return, return previous menu ----- */ |
| 2788 | | if(sel >= (total - 1)) |
| 3733 | DeleteCheatAt(menu->sel); |
| 3734 | } |
| 3735 | else if(input_ui_pressed(machine, IPT_UI_SAVE_CHEAT)) |
| 3736 | { |
| 3737 | if(ShiftKeyPressed()) |
| 2789 | 3738 | { |
| 2790 | | submenuChoice = 0; |
| 2791 | | sel = -1; |
| 3739 | /* shift + save = save all codes */ |
| 3740 | for(i = 0; i < cheatListLength; i++) |
| 3741 | SaveCheatCode(machine, &cheatList[i]); |
| 3742 | |
| 3743 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 3744 | messageType = kCheatMessage_AllCheatSaved; |
| 2792 | 3745 | } |
| 2793 | | /* ----- otherwise, go to edit menu (same as pressing edit key) ----- */ |
| 3746 | else if(ControlKeyPressed()) |
| 3747 | { |
| 3748 | if((entry->flags & kCheatFlag_HasActivationKey1) || (entry->flags & kCheatFlag_HasActivationKey2)) |
| 3749 | /* ctrl + save = save activation key */ |
| 3750 | SaveActivationKey(machine, entry, menu->sel); |
| 3751 | } |
| 3752 | else if(AltKeyPressed()) |
| 3753 | { |
| 3754 | /* alt + save = save pre-enable code */ |
| 3755 | SavePreEnable(machine, entry, menu->sel); |
| 3756 | } |
| 2794 | 3757 | else |
| 2795 | 3758 | { |
| 2796 | | submenuCheat = sel; |
| 2797 | | submenuChoice = 1; |
| 3759 | SaveCheatCode(machine, entry); |
| 2798 | 3760 | } |
| 2799 | 3761 | } |
| 3762 | else if(input_ui_pressed(machine, IPT_UI_WATCH_VALUE)) |
| 3763 | { |
| 3764 | WatchCheatEntry(entry, 0); |
| 3765 | } |
| 3766 | else if(input_ui_pressed(machine, IPT_UI_CANCEL)) |
| 3767 | { |
| 3768 | menu->sel = -1; |
| 3769 | } |
| 2800 | 3770 | |
| 2801 | | if(input_ui_pressed(machine, IPT_UI_RELOAD_CHEAT)) |
| 2802 | | ReloadCheatDatabase(machine); |
| 3771 | return menu->sel + 1; |
| 3772 | } |
| 2803 | 3773 | |
| 2804 | | if(UIPressedRepeatThrottle(machine, IPT_UI_ZOOM_IN, kVerticalKeyRepeatRate)) |
| 2805 | | /* ----- quick menu switch : add/edit -> search ----- */ |
| 2806 | | sel = -4; |
| 3774 | /*----------------------------------------------------------- |
| 3775 | command_add_edit_menu - management for code command menu |
| 3776 | -----------------------------------------------------------*/ |
| 2807 | 3777 | |
| 2808 | | if(UIPressedRepeatThrottle(machine, IPT_UI_ZOOM_OUT, kVerticalKeyRepeatRate)) |
| 2809 | | /* ----- quick menu switch : add/edit -> enable/disable ----- */ |
| 2810 | | sel = -2; |
| 3778 | static int command_add_edit_menu(running_machine *machine, cheat_menu_stack *menu) |
| 3779 | { |
| 3780 | enum{ |
| 3781 | kMenu_EditCheat = 0, |
| 3782 | kMenu_ReloadDatabase, |
| 3783 | kMenu_WatchCheat, |
| 3784 | kMenu_SaveCheat, |
| 3785 | kMenu_SaveActivationKey, |
| 3786 | kMenu_SavePreEnable, |
| 3787 | kMenu_SaveAllCodes, |
| 3788 | kMenu_AddCode, |
| 3789 | kMenu_DeleteCode, |
| 3790 | #ifdef MAME_DEBUG |
| 3791 | kMenu_ConvertFormat, |
| 3792 | kMenu_AnalyseCode, |
| 3793 | #endif |
| 3794 | kMenu_Return, |
| 3795 | kMenu_Max }; |
| 2811 | 3796 | |
| 2812 | | if(input_ui_pressed(machine, IPT_UI_CANCEL)) |
| 2813 | | sel = -1; |
| 3797 | int i; |
| 3798 | UINT8 total = 0; |
| 3799 | ui_menu_item menu_item[kMenu_Max + 1]; |
| 3800 | CheatEntry *entry = &cheatList[menu->pre_sel]; |
| 2814 | 3801 | |
| 2815 | | return sel + 1; |
| 3802 | memset(menu_item, 0, sizeof(menu_item)); |
| 3803 | |
| 3804 | /* first setting : NONE */ |
| 3805 | if(menu->first_time) |
| 3806 | menu->first_time = 0; |
| 3807 | |
| 3808 | /********** MENU CONSTRUCION **********/ |
| 3809 | if(entry->flags & kCheatFlag_OldFormat) |
| 3810 | menu_item[total++].text = "Edit Code"; |
| 3811 | else |
| 3812 | menu_item[total++].text = "View Code"; |
| 3813 | menu_item[total++].text = "Reload Database"; |
| 3814 | menu_item[total++].text = "Watch Code"; |
| 3815 | menu_item[total++].text = "Save Code"; |
| 3816 | menu_item[total++].text = "Save Activation Key"; |
| 3817 | menu_item[total++].text = "Save PreEnable"; |
| 3818 | menu_item[total++].text = "Save All Codes"; |
| 3819 | menu_item[total++].text = "Add New Code"; |
| 3820 | menu_item[total++].text = "Delete Code"; |
| 3821 | #ifdef MAME_DEBUG |
| 3822 | if(entry->flags & kCheatFlag_OldFormat) |
| 3823 | menu_item[total++].text = "Convert To New Format"; |
| 3824 | else |
| 3825 | menu_item[total++].text = "Convert To Old Format"; |
| 3826 | menu_item[total++].text = "Analyse Code"; |
| 3827 | #endif |
| 3828 | menu_item[total++].text = "Return to Prior Menu"; |
| 3829 | menu_item[total].text = NULL; |
| 3830 | |
| 3831 | /* adjust cursor position */ |
| 3832 | ADJUST_CURSOR(menu->sel, total) |
| 3833 | |
| 3834 | /* print it */ |
| 3835 | ui_menu_draw(menu_item, total, menu->sel, NULL); |
| 3836 | |
| 3837 | /********** KEY HANDLING **********/ |
| 3838 | if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate)) |
| 3839 | { |
| 3840 | CURSOR_TO_PREVIOUS(menu->sel, total) |
| 3841 | } |
| 3842 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate)) |
| 3843 | { |
| 3844 | CURSOR_TO_NEXT(menu->sel, total) |
| 3845 | } |
| 3846 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate)) |
| 3847 | { |
| 3848 | CURSOR_PAGE_UP(menu->sel) |
| 3849 | } |
| 3850 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate)) |
| 3851 | { |
| 3852 | CURSOR_PAGE_DOWN(menu->sel, total) |
| 3853 | } |
| 3854 | else if(input_ui_pressed(machine, IPT_UI_SELECT)) |
| 3855 | { |
| 3856 | switch(menu->sel) |
| 3857 | { |
| 3858 | case kMenu_EditCheat: |
| 3859 | if(entry->flags & kCheatFlag_OldFormat) |
| 3860 | cheat_menu_stack_push(edit_cheat_menu, menu->return_handler, menu->pre_sel); |
| 3861 | else |
| 3862 | cheat_menu_stack_push(view_cheat_menu, menu->return_handler, menu->pre_sel); |
| 3863 | break; |
| 3864 | |
| 3865 | case kMenu_ReloadDatabase: |
| 3866 | ReloadCheatDatabase(machine); |
| 3867 | cheat_menu_stack_pop(); |
| 3868 | break; |
| 3869 | |
| 3870 | case kMenu_WatchCheat: |
| 3871 | WatchCheatEntry(entry, 0); |
| 3872 | break; |
| 3873 | |
| 3874 | case kMenu_SaveCheat: |
| 3875 | SaveCheatCode(machine, entry); |
| 3876 | break; |
| 3877 | |
| 3878 | case kMenu_SaveActivationKey: |
| 3879 | SaveActivationKey(machine, entry, menu->pre_sel); |
| 3880 | break; |
| 3881 | |
| 3882 | case kMenu_SavePreEnable: |
| 3883 | SavePreEnable(machine, entry, menu->pre_sel); |
| 3884 | break; |
| 3885 | |
| 3886 | case kMenu_SaveAllCodes: |
| 3887 | { |
| 3888 | for(i = 0; i < cheatListLength; i++) |
| 3889 | SaveCheatCode(machine, &cheatList[i]); |
| 3890 | |
| 3891 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 3892 | messageType = kCheatMessage_AllCheatSaved; |
| 3893 | } |
| 3894 | break; |
| 3895 | |
| 3896 | case kMenu_AddCode: |
| 3897 | AddCheatBefore(menu->pre_sel); |
| 3898 | menu->sel = -1; |
| 3899 | break; |
| 3900 | |
| 3901 | case kMenu_DeleteCode: |
| 3902 | DeleteCheatAt(menu->pre_sel); |
| 3903 | menu->sel = -1; |
| 3904 | break; |
| 3905 | |
| 3906 | #ifdef MAME_DEBUG |
| 3907 | case kMenu_ConvertFormat: |
| 3908 | if(!(entry->flags & kCheatFlag_OldFormat)) |
| 3909 | { |
| 3910 | for(i = 0; i < entry->actionListLength; i++) |
| 3911 | { |
| 3912 | entry->actionList[i].flags |= kActionFlag_OldFormat; |
| 3913 | UpdateCheatInfo(entry, 0); |
| 3914 | } |
| 3915 | } |
| 3916 | else |
| 3917 | { |
| 3918 | for(i = 0; i < entry->actionListLength; i++) |
| 3919 | { |
| 3920 | entry->actionList[i].flags &= ~kActionFlag_OldFormat; |
| 3921 | UpdateCheatInfo(entry, 0); |
| 3922 | } |
| 3923 | } |
| 3924 | break; |
| 3925 | |
| 3926 | case kMenu_AnalyseCode: |
| 3927 | cheat_menu_stack_push(analyse_cheat_menu, menu->return_handler, menu->pre_sel); |
| 3928 | break; |
| 3929 | #endif |
| 3930 | case kMenu_Return: |
| 3931 | menu->sel = -1; |
| 3932 | break; |
| 3933 | } |
| 3934 | } |
| 3935 | else if(input_ui_pressed(machine, IPT_UI_RELOAD_CHEAT)) |
| 3936 | { |
| 3937 | ReloadCheatDatabase(machine); |
| 3938 | } |
| 3939 | else if(input_ui_pressed(machine, IPT_UI_CANCEL) || input_ui_pressed(machine, IPT_UI_LEFT) || input_ui_pressed(machine, IPT_UI_RIGHT)) |
| 3940 | { |
| 3941 | menu->sel = -1; |
| 3942 | } |
| 3943 | |
| 3944 | return menu->sel + 1; |
| 2816 | 3945 | } |
| 2817 | 3946 | |
| 2818 | | /*------------------------------------------------ |
| 2819 | | EditCheatMenu - management for edit code menu |
| 2820 | | ------------------------------------------------*/ |
| 3947 | /*-------------------------------------------------- |
| 3948 | edit_cheat_menu - management for edit code menu |
| 3949 | --------------------------------------------------*/ |
| 2821 | 3950 | |
| 2822 | | static int EditCheatMenu(running_machine *machine, CheatEntry * entry, int index, int selection) |
| 3951 | static int edit_cheat_menu(running_machine *machine, cheat_menu_stack *menu) |
| 2823 | 3952 | { |
| 3953 | #if 0 |
| 2824 | 3954 | static const char *const kTypeNames[] = |
| 2825 | 3955 | { |
| 2826 | 3956 | "Normal/Delay", |
| r2762 | r2763 | |
| 2831 | 3961 | "Select" |
| 2832 | 3962 | }; |
| 2833 | 3963 | |
| 2834 | | static const char *const kNumbersTable[] = |
| 2835 | | { |
| 2836 | | "0", "1", "2", "3", "4", "5", "6", "7", |
| 2837 | | "8", "9", "10", "11", "12", "13", "14", "15", |
| 2838 | | "16", "17", "18", "19", "20", "21", "22", "23", |
| 2839 | | "24", "25", "26", "27", "28", "29", "30", "31" |
| 2840 | | }; |
| 2841 | | |
| 2842 | 3964 | static const char *const kOperationNames[] = |
| 2843 | 3965 | { |
| 2844 | 3966 | "Write", |
| 2845 | 3967 | "Add/Subtract", |
| 2846 | 3968 | "Force Range", |
| 2847 | 3969 | "Set/Clear Bits", |
| 2848 | | "Write If Match", |
| 3970 | "Unused (4)", |
| 2849 | 3971 | "Unused (5)", |
| 2850 | 3972 | "Unused (6)", |
| 2851 | 3973 | "Null" |
| r2762 | r2763 | |
| 2877 | 3999 | "Swap" |
| 2878 | 4000 | }; |
| 2879 | 4001 | |
| 2880 | | static const char *const kRegionNames[] = |
| 2881 | | { |
| 2882 | | "CPU1", "CPU2", "CPU3", "CPU4", "CPU5", "CPU6", "CPU7", "CPU8", |
| 2883 | | "GFX1", "GFX2", "GFX3", "GFX4", "GFX5", "GFX6", "GFX7", "GFX8", |
| 2884 | | "PROMS", |
| 2885 | | "SOUND1", "SOUND2", "SOUND3", "SOUND4", "SOUND5", "SOUND6", "SOUND7", "SOUND8", |
| 2886 | | "USER1", "USER2", "USER3", "USER4", "USER5", "USER6", "USER7", "USER8" |
| 2887 | | }; |
| 2888 | | |
| 2889 | 4002 | static const char *const kLocationNames[] = |
| 2890 | 4003 | { |
| 2891 | 4004 | "Normal", |
| r2762 | r2763 | |
| 2893 | 4006 | "Mapped Memory", |
| 2894 | 4007 | "Custom", |
| 2895 | 4008 | "Relative Address", |
| 2896 | | "Program Space", |
| 2897 | | "Unused (6)", |
| 2898 | | "Unused (7)" |
| 4009 | "Unused (5)", "Unused (6)", "Unused (7)" |
| 2899 | 4010 | }; |
| 2900 | 4011 | |
| 2901 | 4012 | static const char *const kCustomLocationNames[] = |
| r2762 | r2763 | |
| 2911 | 4022 | "Unused (28)", "Unused (29)", "Unused (30)", "Unused (31)" |
| 2912 | 4023 | }; |
| 2913 | 4024 | |
| 2914 | | static const char *const kSizeNames[] = |
| 2915 | | { |
| 2916 | | "8 Bit", |
| 2917 | | "16 Bit", |
| 2918 | | "24 Bit", |
| 2919 | | "32 Bit" |
| 2920 | | }; |
| 2921 | | |
| 2922 | 4025 | enum |
| 2923 | 4026 | { |
| 2924 | 4027 | kType_Name = 0, // text name |
| r2762 | r2763 | |
| 2931 | 4034 | // NOTE: read from base cheat (for idx == 0) |
| 2932 | 4035 | kType_ActivationKey2, // key 2nd activationKey |
| 2933 | 4036 | // NOTE: read from base cheat (for idx == 0) |
| 2934 | | // if(idx > 0 && (cheat[0].type == Select)) |
| 2935 | | kType_LinkExtension, // select LinkExtension Off - On |
| 2936 | | kType_Type, // select Type Normal/Delay - Wait - Ignore Decrement - Watch - |
| 2937 | | // Comment - Select |
| 2938 | | // NOTE: also uses location type field for comment and select |
| 2939 | | // if((Type != Comment) && (Type != Select)) |
| 2940 | | // if(Type != Watch) |
| 2941 | | kType_OneShot, // select OneShot Off - On |
| 2942 | | kType_RestorePreviousValue, |
| 2943 | | // select RestorePreviousValue |
| 2944 | | // Off - On |
| 2945 | | // if((Type == Normal/Delay) || (Type == Wait)) |
| 2946 | | kType_Delay, // value TypeParameter 0 - 7 |
| 2947 | | // if(Type == Ignore Decrement) |
| 2948 | | kType_IgnoreDecrementBy,// value TypeParameter 0 - 7 |
| 4037 | kType_Code, // value Type Field |
| 4038 | // NOTE: it's debug display so that must not modify directly |
| 4039 | kType_Link, // select Link Off - On |
| 4040 | kType_LinkExtension, // select Link Extension Off - On |
| 4041 | kType_Type, // select Type Normal/Delay - Watch - Comment - (label) Select |
| 4042 | kType_OneShot, // select OneShot Off - On |
| 4043 | kType_RestorePreviousValue, // select RestorePreviousValue Off - On |
| 4044 | // if(Type != Ignore Decrement) |
| 4045 | kType_Delay, // value TypeParameter 0 - 7 |
| 4046 | // else |
| 4047 | kType_IgnoreDecrementBy, // value TypeParameter 0 - 7 |
| 2949 | 4048 | // if(Type == Watch) |
| 2950 | | kType_WatchSize, // value Data 0x01 - 0xFF (stored as 0x00 - 0xFE) |
| 4049 | kType_WatchSize, // value Data 0x01 - 0xFF (stored as 0x00 - 0xFE) |
| 2951 | 4050 | // NOTE: value is packed in to 0x000000FF |
| 2952 | | kType_WatchSkip, // value Data 0x00 - 0xFF |
| 4051 | kType_WatchSkip, // value Data 0x00 - 0xFF |
| 2953 | 4052 | // NOTE: value is packed in to 0x0000FF00 |
| 2954 | | kType_WatchPerLine, // value Data 0x00 - 0xFF |
| 4053 | kType_WatchPerLine, // value Data 0x00 - 0xFF |
| 2955 | 4054 | // NOTE: value is packed in to 0x00FF0000 |
| 2956 | | kType_WatchAddValue, // value Data -0x80 - 0x7F |
| 4055 | kType_WatchAddValue, // value Data -0x80 - 0x7F |
| 2957 | 4056 | // NOTE: value is packed in to 0xFF000000 |
| 2958 | | kType_WatchFormat, // select TypeParameter Hex - Decimal - Binary - ASCII |
| 4057 | kType_WatchFormat, // select TypeParameter Hex - Decimal - Binary - ASCII |
| 2959 | 4058 | // NOTE: value is packed in to 0x03 |
| 2960 | | kType_WatchLabel, // select TypeParameter Off - On |
| 4059 | kType_WatchLabel, // select TypeParameter Off - On |
| 2961 | 4060 | // NOTE: value is packed in to 0x04 |
| 2962 | | // and set operation to null |
| 2963 | | // else |
| 2964 | | kType_Operation, // select Operation Write - Add/Subtract - Force Range - Set/Clear Bits - Match to Write - |
| 2965 | | // Null |
| 2966 | | // if((Operation == Write) && (LocationType != Relative Address)) |
| 2967 | | kType_WriteMask, // value extendData 0x00000000 - 0xFFFFFFFF |
| 2968 | | // if(Operation == Add/Subtract) |
| 2969 | | kType_AddSubtract, // select OperationParameter Add - Subtract |
| 2970 | | // if(LocationType != Relative Address) |
| 2971 | | // if(OperationParameter == Add) |
| 2972 | | kType_AddMaximum, |
| 2973 | | // value extendData 0x00000000 - 0xFFFFFFFF |
| 2974 | | // else |
| 2975 | | kType_SubtractMinimum, |
| 2976 | | // value extendData 0x00000000 - 0xFFFFFFFF |
| 2977 | | // if((Operation == Force Range) && (LocationType != Relative Address)) |
| 2978 | | kType_RangeMinimum, // value extendData 0x00 - 0xFF / 0xFFFF |
| 4061 | kType_Operation, // select Operation Write - Add/Subtract - Force Range - Set/Clear Bits |
| 4062 | kType_OperationExtend, // select Operation Extend Off - On |
| 4063 | // NOTE: Operation Extend is unused right now |
| 4064 | // if(LocationType != Relative Address && Operation == Write) |
| 4065 | kType_WriteMask, // value extendData 0x00000000 - 0xFFFFFFFF |
| 4066 | // if(LocationType != Relative Address && Operation == Add/Subtract) |
| 4067 | kType_AddSubtract, // select OperationParameter Add - Subtract |
| 4068 | // if(OperationParameter == Add) |
| 4069 | kType_AddMaximum, // value extendData 0x00000000 - 0xFFFFFFFF |
| 4070 | // else |
| 4071 | kType_SubtractMinimum, // value extendData 0x00000000 - 0xFFFFFFFF |
| 4072 | // if(LocationType != Relative Address && Operation == Force Range) |
| 4073 | kType_RangeMinimum, // value extendData 0x00 - 0xFF / 0xFFFF |
| 2979 | 4074 | // NOTE: value is packed in to upper byte of extendData (as a word) |
| 2980 | | kType_RangeMaximum, // value extendData 0x00 - 0xFF / 0xFFFF |
| 4075 | kType_RangeMaximum, // value extendData 0x00 - 0xFF / 0xFFFF |
| 2981 | 4076 | // NOTE: value is packed in to lower byte of extendData (as a word) |
| 2982 | 4077 | // if(Operation == Set/Clear) |
| 2983 | | kType_SetClear, // select OperationParameter Set - Clear |
| 2984 | | // if(Operation == Match to Write) |
| 2985 | | kType_WriteMatch, // value extendData 0x00000000 - 0xFFFFFFFF |
| 2986 | | // if((Operation != Null) || (Type == Watch)) |
| 2987 | | // if(Type != Watch) |
| 2988 | | kType_Data, |
| 2989 | | kType_UserSelect, // select UserSelectEnable Off - On |
| 2990 | | // if(UserSelect == On) |
| 2991 | | kType_UserSelectMinimumDisp, |
| 2992 | | // value UserSelectMinimumDisplay |
| 2993 | | // 0 - 1 |
| 2994 | | kType_UserSelectMinimum, |
| 2995 | | // value UserSelectMinimum 0 - 1 |
| 2996 | | kType_UserSelectBCD,// select UserSelectBCD Off - On |
| 2997 | | kType_Prefill, // select UserSelectPrefill None - FF - 00 - 01 |
| 2998 | | // if(idx > 0) |
| 2999 | | kType_CopyPrevious, // select LinkCopyPreviousValue |
| 3000 | | // Off - On |
| 3001 | | kType_ByteLength, // value BytesUsed 1 - 4 |
| 3002 | | // if(bytesUsed > 0) |
| 3003 | | kType_Endianness, // select Endianness Normal - Swap |
| 3004 | | kType_LocationType, // select LocationType Normal - Region - Mapped Memory - EEPROM - |
| 3005 | | // Relative Address - Program Space |
| 3006 | | // NOTE: also uses LocationParameter for EEPROM type |
| 3007 | | // if((LocationType == Normal) || (LocationType == HandlerMemory) || (LocationType == ProgramSpace) |
| 3008 | | kType_CPU, // value LocationParameter 0 - 31 |
| 3009 | | // if(LocationType == Region) |
| 3010 | | kType_Region, // select LocationParameter CPU1 - CPU2 - CPU3 - CPU4 - CPU5 - CPU6 - CPU7 - |
| 3011 | | // CPU8 - GFX1 - GFX2 - GFX3 - GFX4 - GFX5 - GFX6 - |
| 3012 | | // GFX7 - GFX8 - PROMS - SOUND1 - SOUND2 - SOUND3 - |
| 3013 | | // SOUND4 - SOUND5 - SOUND6 - SOUND7 - SOUND8 - |
| 3014 | | // USER1 - USER2 - USER3 - USER4 - USER5 - USER6 - |
| 3015 | | // USER7 |
| 3016 | | // if(LocationType == RelativeAddress) |
| 3017 | | kType_PackedCPU, // value LocationParameter 0 - 7 |
| 4078 | kType_SetClear, // select OperationParameter Set - Clear |
| 4079 | kType_Data, |
| 4080 | kType_UserSelect, // select UserSelectEnable Off - On |
| 4081 | kType_UserSelectMinimumDisp, // value UserSelectMinimumDisplay Off - On |
| 4082 | kType_UserSelectMinimum, // value UserSelectMinimum 0 - 1 |
| 4083 | kType_UserSelectBCD, // select UserSelectBCD Off - On |
| 4084 | kType_CopyPrevious, // select LinkCopyPreviousValue Off - On |
| 4085 | kType_Prefill, // select UserSelectPrefill None - FF - 00 - 01 |
| 4086 | kType_ByteLength, // value BytesUsed 1 - 4 |
| 4087 | kType_Endianness, // select Endianness Normal - Swap |
| 4088 | kType_LocationType, // select LocationType Normal - Region - Mapped Memory - EEPROM - Relative Address |
| 4089 | // if(LocationType != Region && LocationType != Relative Address) |
| 4090 | kType_CPU, // value LocationParameter 0 - 31 |
| 4091 | // if(LocationType == Region) |
| 4092 | kType_Region, // select LocationParameter CPU1 - CPU2 - CPU3 - CPU4 - CPU5 - CPU6 - CPU7 - |
| 4093 | // CPU8 - GFX1 - GFX2 - GFX3 - GFX4 - GFX5 - GFX6 - |
| 4094 | // GFX7 - GFX8 - PROMS - SOUND1 - SOUND2 - SOUND3 - |
| 4095 | // SOUND4 - SOUND5 - SOUND6 - SOUND7 - SOUND8 - |
| 4096 | // USER1 - USER2 - USER3 - USER4 - USER5 - USER6 - |
| 4097 | // USER7 |
| 4098 | // NOTE: old format doesn't support USER8 - PLDS |
| 4099 | // if(LocationType == Relative Address) |
| 4100 | kType_PackedCPU, // value LocationParameter 0 - 7 |
| 3018 | 4101 | // NOTE: packed in to upper three bits of LocationParameter |
| 3019 | | kType_PackedSize, // value LocationParameter 1 - 4 |
| 4102 | kType_PackedSize, // value LocationParameter 1 - 4 |
| 3020 | 4103 | // NOTE: packed in to lower two bits of LocationParameter |
| 3021 | | kType_AddressIndex, // value extendData -0x80000000 - 0x7FFFFFFF |
| 3022 | | kType_Address, |
| 4104 | kType_AddressIndex, // value extendData -0x80000000 - 0x7FFFFFFF |
| 4105 | kType_Address, |
| 3023 | 4106 | |
| 3024 | 4107 | kType_Return, |
| 3025 | 4108 | kType_Divider, |
| r2762 | r2763 | |
| 3027 | 4110 | kType_Max |
| 3028 | 4111 | }; |
| 3029 | 4112 | |
| 3030 | | INT32 sel; |
| 4113 | int i; |
| 4114 | int sel = selection - 1; |
| 4115 | int total = 0; |
| 4116 | UINT8 dirty = 0; |
| 4117 | static UINT8 editActive = 0; |
| 3031 | 4118 | const char ** menuItem; |
| 3032 | 4119 | const char ** menuSubItem; |
| 3033 | 4120 | char * flagBuf; |
| 3034 | 4121 | char ** extendDataBuf; // FFFFFFFF (-80000000) |
| 3035 | 4122 | char ** addressBuf; // FFFFFFFF |
| 3036 | 4123 | char ** dataBuf; // 80000000 (-2147483648) |
| 4124 | char ** typeBuf; // FFFFFFFF |
| 3037 | 4125 | char ** watchSizeBuf; // FF |
| 3038 | 4126 | char ** watchSkipBuf; // FF |
| 3039 | 4127 | char ** watchPerLineBuf; // FF |
| 3040 | 4128 | char ** watchAddValueBuf; // FF |
| 3041 | | INT32 i; |
| 3042 | | INT32 total = 0; |
| 3043 | | MenuItemInfoStruct * info = NULL; |
| 3044 | | CheatAction * action = NULL; |
| 3045 | | UINT8 isSelect = 0; |
| 3046 | | static UINT8 editActive = 0; |
| 3047 | | UINT32 increment = 1; |
| 3048 | | UINT8 dirty = 0; |
| 3049 | | static INT32 currentNameTemplate = 0; |
| 3050 | 4129 | |
| 3051 | | astring * temp_string_1 = astring_alloc(); |
| 3052 | | astring * temp_string_2 = astring_alloc(); |
| 4130 | menu_item_info * info = NULL; |
| 4131 | CheatAction * action = NULL; |
| 4132 | astring * tempString1 = astring_alloc(); // activation key 1 |
| 4133 | astring * tempString2 = astring_alloc(); // activation key 2 |
| 3053 | 4134 | |
| 3054 | 4135 | if(!entry) |
| 3055 | 4136 | return 0; |
| 3056 | 4137 | |
| 3057 | | /********** MENU CONSTRUCTION **********/ |
| 3058 | 4138 | if(menuItemInfoLength < (kType_Max * entry->actionListLength) + 2) |
| 3059 | 4139 | { |
| 3060 | 4140 | menuItemInfoLength = (kType_Max * entry->actionListLength) + 2; |
| 3061 | 4141 | |
| 3062 | | menuItemInfo = realloc(menuItemInfo, menuItemInfoLength * sizeof(MenuItemInfoStruct)); |
| 4142 | menuItemInfo = realloc(menuItemInfo, menuItemInfoLength * sizeof(menu_item_info)); |
| 3063 | 4143 | } |
| 3064 | 4144 | |
| 3065 | | RequestStrings((kType_Max * entry->actionListLength) + 2, 7 * entry->actionListLength, 24, 0); |
| 4145 | request_strings((kType_Max * entry->actionListLength) + 2, 8 * entry->actionListLength, 32, 0); |
| 3066 | 4146 | |
| 3067 | | menuItem = menuStrings.mainList; |
| 3068 | | menuSubItem = menuStrings.subList; |
| 3069 | | flagBuf = menuStrings.flagList; |
| 3070 | | extendDataBuf = &menuStrings.mainStrings[entry->actionListLength * 0]; |
| 3071 | | addressBuf = &menuStrings.mainStrings[entry->actionListLength * 1]; |
| 3072 | | dataBuf = &menuStrings.mainStrings[entry->actionListLength * 2]; |
| 3073 | | watchSizeBuf = &menuStrings.mainStrings[entry->actionListLength * 3]; // these fields are wasteful |
| 3074 | | watchSkipBuf = &menuStrings.mainStrings[entry->actionListLength * 4]; // but the alternative is even more ugly |
| 3075 | | watchPerLineBuf = &menuStrings.mainStrings[entry->actionListLength * 5]; |
| 3076 | | watchAddValueBuf = &menuStrings.mainStrings[entry->actionListLength * 6]; |
| 4147 | menuItem = menu_strings.main_list; |
| 4148 | menuSubItem = menu_strings.sub_list; |
| 4149 | flagBuf = menu_strings.flag_list; |
| 4150 | extendDataBuf = &menu_strings.main_strings[entry->actionListLength * 0]; |
| 4151 | addressBuf = &menu_strings.main_strings[entry->actionListLength * 1]; |
| 4152 | dataBuf = &menu_strings.main_strings[entry->actionListLength * 2]; |
| 4153 | typeBuf = &menu_strings.main_strings[entry->actionListLength * 3]; |
| 4154 | watchSizeBuf = &menu_strings.main_strings[entry->actionListLength * 4]; // these fields are wasteful |
| 4155 | watchSkipBuf = &menu_strings.main_strings[entry->actionListLength * 5]; // but the alternative is even more ugly |
| 4156 | watchPerLineBuf = &menu_strings.main_strings[entry->actionListLength * 6]; // |
| 4157 | watchAddValueBuf = &menu_strings.main_strings[entry->actionListLength * 7]; // |
| 3077 | 4158 | |
| 3078 | | sel = selection - 1; |
| 3079 | | |
| 3080 | 4159 | memset(flagBuf, 0, (kType_Max * entry->actionListLength) + 2); |
| 3081 | 4160 | |
| 3082 | | /* ----- create menu items ----- */ |
| 4161 | /********** MENU CONSTRUCTION **********/ |
| 4162 | /* create menu items */ |
| 3083 | 4163 | for(i = 0; i < entry->actionListLength; i++) |
| 3084 | 4164 | { |
| 3085 | 4165 | CheatAction * traverse = &entry->actionList[i]; |
| 3086 | 4166 | |
| 3087 | | UINT32 type = EXTRACT_FIELD(traverse->type, Type); |
| 3088 | | UINT32 typeParameter = EXTRACT_FIELD(traverse->type, TypeParameter); |
| 3089 | | UINT32 operation = EXTRACT_FIELD(traverse->type, Operation) | |
| 3090 | | EXTRACT_FIELD(traverse->type, OperationExtend) << 2; |
| 3091 | | UINT32 operationParameter = EXTRACT_FIELD(traverse->type, OperationParameter); |
| 3092 | | UINT32 locationType = EXTRACT_FIELD(traverse->type, LocationType); |
| 3093 | | UINT32 locationParameter = EXTRACT_FIELD(traverse->type, LocationParameter); |
| 4167 | UINT32 type = EXTRACT_FIELD(traverse->type, Type); |
| 4168 | UINT32 typeParameter = EXTRACT_FIELD(traverse->type, TypeParameter); |
| 4169 | UINT32 operation = EXTRACT_FIELD(traverse->type, Operation) | EXTRACT_FIELD(traverse->type, OperationExtend) << 2; |
| 4170 | UINT32 operationParameter = EXTRACT_FIELD(traverse->type, OperationParameter); |
| 4171 | UINT32 locationType = EXTRACT_FIELD(traverse->type, LocationType); |
| 4172 | UINT32 locationParameter = EXTRACT_FIELD(traverse->type, LocationParameter); |
| 3094 | 4173 | |
| 3095 | | UINT8 wasCommentOrSelect = 0; |
| 4174 | /* create item if label-select, extend comment or condition */ |
| 4175 | if(!i) |
| 4176 | { |
| 4177 | /* do name field */ |
| 4178 | menuItemInfo[total].sub_cheat = i; |
| 4179 | menuItemInfo[total].field_type = kType_Name; |
| 4180 | menuItem[total] = "Name"; |
| 3096 | 4181 | |
| 3097 | | if(isSelect) |
| 4182 | if(entry->name) |
| 4183 | menuSubItem[total++] = entry->name; |
| 4184 | else |
| 4185 | menuSubItem[total++] = "(none)"; |
| 4186 | } |
| 4187 | else |
| 3098 | 4188 | { |
| 3099 | | /* ----- do extend name field ----- */ |
| 3100 | | menuItemInfo[total].subcheat = i; |
| 3101 | | menuItemInfo[total].fieldType = kType_ExtendName; |
| 4189 | /* do label name field */ |
| 4190 | menuItemInfo[total].sub_cheat = i; |
| 4191 | menuItemInfo[total].field_type = kType_ExtendName; |
| 3102 | 4192 | menuItem[total] = "Name"; |
| 3103 | 4193 | |
| 3104 | 4194 | if(traverse->optionalName) |
| r2762 | r2763 | |
| 3107 | 4197 | menuSubItem[total++] = "(none)"; |
| 3108 | 4198 | } |
| 3109 | 4199 | |
| 3110 | | /* ----- create items if 1st code ----- */ |
| 3111 | | if(i == 0) |
| 4200 | if(!i) |
| 3112 | 4201 | { |
| 3113 | | { |
| 3114 | | /* ----- do name field ----- */ |
| 3115 | | menuItemInfo[total].subcheat = i; |
| 3116 | | menuItemInfo[total].fieldType = kType_Name; |
| 3117 | | menuItem[total] = "Name"; |
| 4202 | /* do comment field */ |
| 4203 | menuItemInfo[total].sub_cheat = i; |
| 4204 | menuItemInfo[total].field_type = kType_Comment; |
| 4205 | menuItem[total] = "Comment"; |
| 3118 | 4206 | |
| 3119 | | if(entry->name) |
| 3120 | | menuSubItem[total++] = entry->name; |
| 3121 | | else |
| 3122 | | menuSubItem[total++] = "(none)"; |
| 3123 | | } |
| 4207 | if(entry->comment) |
| 4208 | menuSubItem[total++] = entry->comment; |
| 4209 | else |
| 4210 | menuSubItem[total++] = "(none)"; |
| 4211 | } |
| 3124 | 4212 | |
| 3125 | | { |
| 3126 | | /* ----- do comment field ----- */ |
| 3127 | | menuItemInfo[total].subcheat = i; |
| 3128 | | menuItemInfo[total].fieldType = kType_Comment; |
| 3129 | | menuItem[total] = "Comment"; |
| 4213 | { |
| 4214 | /* do 1st (previous-selection) activation key field */ |
| 4215 | menuItemInfo[total].sub_cheat = i; |
| 4216 | menuItemInfo[total].field_type = kType_ActivationKey1; |
| 3130 | 4217 | |
| 3131 | | if(entry->comment) |
| 3132 | | menuSubItem[total++] = entry->comment; |
| 3133 | | else |
| 3134 | | menuSubItem[total++] = "(none)"; |
| 3135 | | } |
| 4218 | if(locationType == kLocation_Custom && locationParameter == kCustomLocation_Select) |
| 4219 | menuItem[total] = "Activation Key - Prev"; |
| 4220 | else |
| 4221 | menuItem[total] = "Activation Key - 1st"; |
| 3136 | 4222 | |
| 3137 | | { |
| 3138 | | /* ----- do 1st activation key field ----- */ |
| 3139 | | menuItemInfo[total].subcheat = i; |
| 3140 | | menuItemInfo[total].fieldType = kType_ActivationKey1; |
| 3141 | | menuItem[total] = "Activation Key (1st)"; |
| 4223 | if(entry->flags & kCheatFlag_HasActivationKey1) |
| 4224 | menuSubItem[total++] = astring_c(input_code_name(tempString1, entry->activationKey1)); |
| 4225 | else |
| 4226 | menuSubItem[total++] = "(none)"; |
| 4227 | } |
| 3142 | 4228 | |
| 3143 | | if((entry->flags & kCheatFlag_HasActivationKey1)) |
| 3144 | | menuSubItem[total++] = astring_c(input_code_name(temp_string_1, entry->activationKey1)); |
| 3145 | | else |
| 3146 | | menuSubItem[total++] = "(none)"; |
| 3147 | | } |
| 4229 | { |
| 4230 | /* do 2nd (next-selection) activation key field */ |
| 4231 | menuItemInfo[total].sub_cheat = i; |
| 4232 | menuItemInfo[total].field_type = kType_ActivationKey2; |
| 3148 | 4233 | |
| 3149 | | { |
| 3150 | | /* ----- do 2nd activation key field ----- */ |
| 3151 | | menuItemInfo[total].subcheat = i; |
| 3152 | | menuItemInfo[total].fieldType = kType_ActivationKey2; |
| 3153 | | menuItem[total] = "Activation Key (2nd)"; |
| 4234 | if(locationType == kLocation_Custom && locationParameter == kCustomLocation_Select) |
| 4235 | menuItem[total] = "Activation Key - Next"; |
| 4236 | else |
| 4237 | menuItem[total] = "Activation Key - 2nd"; |
| 3154 | 4238 | |
| 3155 | | if((entry->flags & kCheatFlag_HasActivationKey2)) |
| 3156 | | menuSubItem[total++] = astring_c(input_code_name(temp_string_2, entry->activationKey2)); |
| 3157 | | else |
| 3158 | | menuSubItem[total++] = "(none)"; |
| 3159 | | } |
| 4239 | if(entry->flags & kCheatFlag_HasActivationKey2) |
| 4240 | menuSubItem[total++] = astring_c(input_code_name(tempString2, entry->activationKey2)); |
| 4241 | else |
| 4242 | menuSubItem[total++] = "(none)"; |
| 4243 | } |
| 3160 | 4244 | |
| 3161 | | /* ----- is this label-selection cheat ? ----- */ |
| 3162 | | if((locationType == kLocation_Custom) && (locationParameter == kCustomLocation_Select)) |
| 3163 | | isSelect = 1; |
| 4245 | { |
| 4246 | /* do type code field */ |
| 4247 | menuItemInfo[total].sub_cheat = i; |
| 4248 | menuItemInfo[total].field_type = kType_Code; |
| 4249 | menuItem[total] = "Code"; |
| 4250 | |
| 4251 | sprintf(typeBuf[i], "%8.8X", traverse->type); |
| 4252 | menuSubItem[total++] = typeBuf[i]; |
| 3164 | 4253 | } |
| 3165 | 4254 | |
| 3166 | | /* ----- create item if linked code on label-selection ----- */ |
| 3167 | | if(i && isSelect) |
| 3168 | 4255 | { |
| 3169 | | /* ----- do link extension field ----- */ |
| 3170 | | menuItemInfo[total].subcheat = i; |
| 3171 | | menuItemInfo[total].fieldType = kType_LinkExtension; |
| 4256 | /* do link field */ |
| 4257 | menuItemInfo[total].sub_cheat = i; |
| 4258 | menuItemInfo[total].field_type = kType_Link; |
| 4259 | menuItem[total] = "Link"; |
| 4260 | menuSubItem[total++] = TEST_FIELD(traverse->type, LinkEnable) ? "On" : "Off"; |
| 4261 | } |
| 4262 | |
| 4263 | { |
| 4264 | /* do link extension field */ |
| 4265 | menuItemInfo[total].sub_cheat = i; |
| 4266 | menuItemInfo[total].field_type = kType_LinkExtension; |
| 3172 | 4267 | menuItem[total] = "Link Extension"; |
| 3173 | 4268 | menuSubItem[total++] = TEST_FIELD(traverse->type, LinkExtension) ? "On" : "Off"; |
| 3174 | 4269 | } |
| 3175 | 4270 | |
| 3176 | 4271 | { |
| 3177 | | /* ----- do type field ----- */ |
| 3178 | | menuItemInfo[total].subcheat = i; |
| 3179 | | menuItemInfo[total].fieldType = kType_Type; |
| 4272 | /* do type field */ |
| 4273 | menuItemInfo[total].sub_cheat = i; |
| 4274 | menuItemInfo[total].field_type = kType_Type; |
| 3180 | 4275 | menuItem[total] = "Type"; |
| 3181 | 4276 | |
| 3182 | | if(locationType == kLocation_Custom) |
| 3183 | | { |
| 3184 | | if(locationParameter == kCustomLocation_Comment) |
| 3185 | | { |
| 3186 | | /* ----- comment ----- */ |
| 3187 | | wasCommentOrSelect = 1; |
| 3188 | | |
| 3189 | | menuSubItem[total++] = kTypeNames[4]; |
| 3190 | | } |
| 3191 | | else |
| 3192 | | { |
| 3193 | | if(locationParameter == kCustomLocation_Select) |
| 3194 | | { |
| 3195 | | /* ----- label-selection ----- */ |
| 3196 | | wasCommentOrSelect = 1; |
| 3197 | | |
| 3198 | | menuSubItem[total++] = kTypeNames[5]; |
| 3199 | | } |
| 3200 | | else |
| 3201 | | menuSubItem[total++] = kTypeNames[type & 3]; |
| 3202 | | } |
| 3203 | | } |
| 4277 | if(locationType == kLocation_Custom && locationParameter == kCustomLocation_Comment) |
| 4278 | menuSubItem[total++] = kTypeNames[4]; |
| 4279 | else if(locationType == kLocation_Custom && locationParameter == kCustomLocation_Select) |
| 4280 | menuSubItem[total++] = kTypeNames[5]; |
| 3204 | 4281 | else |
| 3205 | 4282 | menuSubItem[total++] = kTypeNames[type & 3]; |
| 3206 | 4283 | } |
| 3207 | 4284 | |
| 3208 | | /* ----- create items if not comment or label-selection ----- */ |
| 3209 | | if(!wasCommentOrSelect) |
| 3210 | 4285 | { |
| 3211 | | if(type != kType_Watch) |
| 3212 | | { |
| 3213 | | { |
| 3214 | | /* ----- do one shot field ----- */ |
| 3215 | | menuItemInfo[total].subcheat = i; |
| 3216 | | menuItemInfo[total].fieldType = kType_OneShot; |
| 3217 | | menuItem[total] = "One Shot"; |
| 3218 | | menuSubItem[total++] = TEST_FIELD(traverse->type, OneShot) ? "On" : "Off"; |
| 3219 | | } |
| 4286 | /* do one shot field */ |
| 4287 | menuItemInfo[total].sub_cheat = i; |
| 4288 | menuItemInfo[total].field_type = kType_OneShot; |
| 4289 | menuItem[total] = "One Shot"; |
| 4290 | menuSubItem[total++] = TEST_FIELD(traverse->type, OneShot) ? "On" : "Off"; |
| 4291 | } |
| 3220 | 4292 | |
| 3221 | | { |
| 3222 | | /* ----- do restore previous value field ----- */ |
| 3223 | | menuItemInfo[total].subcheat = i; |
| 3224 | | menuItemInfo[total].fieldType = kType_RestorePreviousValue; |
| 3225 | | menuItem[total] = "Restore Previous Value"; |
| 3226 | | menuSubItem[total++] = TEST_FIELD(traverse->type, RestorePreviousValue) ? "On" : "Off"; |
| 3227 | | } |
| 3228 | | } |
| 4293 | { |
| 4294 | /* do restore previous value field */ |
| 4295 | menuItemInfo[total].sub_cheat = i; |
| 4296 | menuItemInfo[total].field_type = kType_RestorePreviousValue; |
| 4297 | menuItem[total] = "Restore Previous Value"; |
| 4298 | menuSubItem[total++] = TEST_FIELD(traverse->type, RestorePreviousValue) ? "On" : "Off"; |
| 4299 | } |
| 3229 | 4300 | |
| 3230 | | if((type == kType_NormalOrDelay) || (type == kType_WaitForModification)) |
| 4301 | switch(type) |
| 4302 | { |
| 4303 | default: |
| 3231 | 4304 | { |
| 3232 | | /* ----- do delay field ----- */ |
| 3233 | | menuItemInfo[total].subcheat = i; |
| 3234 | | menuItemInfo[total].fieldType = kType_Delay; |
| 4305 | /* do delay field */ |
| 4306 | menuItemInfo[total].sub_cheat = i; |
| 4307 | menuItemInfo[total].field_type = kType_Delay; |
| 3235 | 4308 | |
| 3236 | | if( TEST_FIELD(traverse->type, OneShot) && TEST_FIELD(traverse->type, RestorePreviousValue) && |
| 3237 | | EXTRACT_FIELD(traverse->type, TypeParameter)) |
| 4309 | if(TEST_FIELD(traverse->type, OneShot) && TEST_FIELD(traverse->type, RestorePreviousValue) && EXTRACT_FIELD(traverse->type, TypeParameter)) |
| 3238 | 4310 | menuItem[total] = "Keep"; |
| 3239 | 4311 | else |
| 3240 | 4312 | menuItem[total] = "Delay"; |
| 3241 | 4313 | |
| 3242 | 4314 | menuSubItem[total++] = kNumbersTable[typeParameter]; |
| 3243 | 4315 | } |
| 4316 | break; |
| 3244 | 4317 | |
| 3245 | | if(type == kType_IgnoreIfDecrementing) |
| 4318 | case kType_IgnoreIfDecrementing: |
| 3246 | 4319 | { |
| 3247 | | /* ----- do ignore decrement by field ----- */ |
| 3248 | | menuItemInfo[total].subcheat = i; |
| 3249 | | menuItemInfo[total].fieldType = kType_IgnoreDecrementBy; |
| 4320 | /* do ignore decrement by field */ |
| 4321 | menuItemInfo[total].sub_cheat = i; |
| 4322 | menuItemInfo[total].field_type = kType_IgnoreDecrementBy; |
| 3250 | 4323 | menuItem[total] = "Ignore Decrement By"; |
| 3251 | 4324 | menuSubItem[total++] = kNumbersTable[typeParameter]; |
| 3252 | 4325 | } |
| 4326 | break; |
| 3253 | 4327 | |
| 3254 | | if(type == kType_Watch) |
| 4328 | case kType_Watch: |
| 3255 | 4329 | { |
| 3256 | | { |
| 3257 | | /* ----- do watch size field ----- */ |
| 3258 | | sprintf(watchSizeBuf[i], "%d", (traverse->originalDataField & 0xFF) + 1); |
| 4330 | /* do watch size field */ |
| 4331 | sprintf(watchSizeBuf[i], "%d", (traverse->originalDataField & 0xFF) + 1); |
| 3259 | 4332 | |
| 3260 | | menuItemInfo[total].subcheat = i; |
| 3261 | | menuItemInfo[total].fieldType = kType_WatchSize; |
| 3262 | | menuItem[total] = "Watch Size"; |
| 3263 | | menuSubItem[total++] = watchSizeBuf[i]; |
| 3264 | | } |
| 4333 | menuItemInfo[total].sub_cheat = i; |
| 4334 | menuItemInfo[total].field_type = kType_WatchSize; |
| 4335 | menuItem[total] = "Watch Size"; |
| 4336 | menuSubItem[total++] = watchSizeBuf[i]; |
| 4337 | } |
| 3265 | 4338 | |
| 3266 | | { |
| 3267 | | /* ----- do watch skip field ----- */ |
| 3268 | | sprintf(watchSkipBuf[i], "%d", (traverse->data >> 8) & 0xFF); |
| 4339 | { |
| 4340 | /* do watch skip field */ |
| 4341 | sprintf(watchSkipBuf[i], "%d", (traverse->data >> 8) & 0xFF); |
| 3269 | 4342 | |
| 3270 | | menuItemInfo[total].subcheat = i; |
| 3271 | | menuItemInfo[total].fieldType = kType_WatchSkip; |
| 3272 | | menuItem[total] = "Watch Skip"; |
| 3273 | | menuSubItem[total++] = watchSkipBuf[i]; |
| 3274 | | } |
| 4343 | menuItemInfo[total].sub_cheat = i; |
| 4344 | menuItemInfo[total].field_type = kType_WatchSkip; |
| 4345 | menuItem[total] = "Watch Skip"; |
| 4346 | menuSubItem[total++] = watchSkipBuf[i]; |
| 4347 | } |
| 3275 | 4348 | |
| 3276 | | { |
| 3277 | | /* ----- do watch per line field ----- */ |
| 3278 | | sprintf(watchPerLineBuf[i], "%d", (traverse->data >> 16) & 0xFF); |
| 4349 | { |
| 4350 | /* do watch per line field */ |
| 4351 | sprintf(watchPerLineBuf[i], "%d", (traverse->data >> 16) & 0xFF); |
| 3279 | 4352 | |
| 3280 | | menuItemInfo[total].subcheat = i; |
| 3281 | | menuItemInfo[total].fieldType = kType_WatchPerLine; |
| 3282 | | menuItem[total] = "Watch Per Line"; |
| 3283 | | menuSubItem[total++] = watchPerLineBuf[i]; |
| 3284 | | } |
| 4353 | menuItemInfo[total].sub_cheat = i; |
| 4354 | menuItemInfo[total].field_type = kType_WatchPerLine; |
| 4355 | menuItem[total] = "Watch Per Line"; |
| 4356 | menuSubItem[total++] = watchPerLineBuf[i]; |
| 4357 | } |
| 3285 | 4358 | |
| 3286 | | { |
| 3287 | | /* ----- do watch add value field ----- */ |
| 3288 | | { |
| 3289 | | INT8 temp = (traverse->data >> 24) & 0xFF; |
| 4359 | { |
| 4360 | /* do watch add value field */ |
| 4361 | INT8 temp = (traverse->data >> 24) & 0xFF; |
| 3290 | 4362 | |
| 3291 | | if(temp < 0) |
| 3292 | | sprintf(watchAddValueBuf[i], "-%.2X", -temp); |
| 3293 | | else |
| 3294 | | sprintf(watchAddValueBuf[i], "%.2X", temp); |
| 3295 | | } |
| 4363 | if(temp < 0) |
| 4364 | sprintf(watchAddValueBuf[i], "-%.2X", -temp); |
| 4365 | else |
| 4366 | sprintf(watchAddValueBuf[i], "%.2X", temp); |
| 3296 | 4367 | |
| 3297 | | menuItemInfo[total].subcheat = i; |
| 3298 | | menuItemInfo[total].fieldType = kType_WatchAddValue; |
| 3299 | | menuItem[total] = "Watch Add Value"; |
| 3300 | | menuSubItem[total++] = watchAddValueBuf[i]; |
| 3301 | | } |
| 4368 | menuItemInfo[total].sub_cheat = i; |
| 4369 | menuItemInfo[total].field_type = kType_WatchAddValue; |
| 4370 | menuItem[total] = "Watch Add Value"; |
| 4371 | menuSubItem[total++] = watchAddValueBuf[i]; |
| 4372 | } |
| 3302 | 4373 | |
| 3303 | | { |
| 3304 | | /* ----- do watch format field ----- */ |
| 3305 | | menuItemInfo[total].subcheat = i; |
| 3306 | | menuItemInfo[total].fieldType = kType_WatchFormat; |
| 3307 | | menuItem[total] = "Watch Format"; |
| 3308 | | menuSubItem[total++] = kWatchDisplayTypeStringList[(typeParameter >> 0) & 0x03]; |
| 3309 | | } |
| 4374 | { |
| 4375 | /* do watch format field */ |
| 4376 | menuItemInfo[total].sub_cheat = i; |
| 4377 | menuItemInfo[total].field_type = kType_WatchFormat; |
| 4378 | menuItem[total] = "Watch Format"; |
| 4379 | menuSubItem[total++] = kWatchDisplayTypeStringList[(typeParameter >> 0) & 0x03]; |
| 4380 | } |
| 3310 | 4381 | |
| 3311 | | { |
| 3312 | | /* ----- do watch label field ----- */ |
| 3313 | | menuItemInfo[total].subcheat = i; |
| 3314 | | menuItemInfo[total].fieldType = kType_WatchLabel; |
| 3315 | | menuItem[total] = "Watch Label"; |
| 3316 | | menuSubItem[total++] = ((typeParameter >> 2) & 0x01) ? "On" : "Off"; |
| 3317 | | } |
| 4382 | { |
| 4383 | /* do watch label field */ |
| 4384 | menuItemInfo[total].sub_cheat = i; |
| 4385 | menuItemInfo[total].field_type = kType_WatchLabel; |
| 4386 | menuItem[total] = "Watch Label"; |
| 4387 | menuSubItem[total++] = typeParameter >> 2 & 0x01 ? "On" : "Off"; |
| 3318 | 4388 | } |
| 3319 | | else |
| 3320 | | { |
| 3321 | | /* ----- do operation field ----- */ |
| 3322 | | menuItemInfo[total].subcheat = i; |
| 3323 | | menuItemInfo[total].fieldType = kType_Operation; |
| 3324 | | menuItem[total] = "Operation"; |
| 4389 | break; |
| 4390 | } |
| 3325 | 4391 | |
| 3326 | | if((locationType != kLocation_IndirectIndexed) && (operation == kOperation_SetOrClearBits)) |
| 3327 | | { |
| 3328 | | /* ----- ignore Set/Clear Bit item if not relative address ----- */ |
| 3329 | | operation = kOperation_WriteMask; |
| 4392 | { |
| 4393 | /* do operation field */ |
| 4394 | menuItemInfo[total].sub_cheat = i; |
| 4395 | menuItemInfo[total].field_type = kType_Operation; |
| 4396 | menuItem[total] = "Operation"; |
| 3330 | 4397 | |
| 3331 | | CLEAR_MASK_FIELD(traverse->type, OperationExtend); |
| 3332 | | SET_FIELD(traverse->type, Operation, operation); |
| 3333 | | } |
| 4398 | menuSubItem[total++] = kOperationNames[operation]; |
| 4399 | } |
| 3334 | 4400 | |
| 3335 | | menuSubItem[total++] = kOperationNames[operation]; |
| 3336 | | } |
| 4401 | { |
| 4402 | /* do operation extend field */ |
| 4403 | menuItemInfo[total].sub_cheat = i; |
| 4404 | menuItemInfo[total].field_type = kType_OperationExtend; |
| 4405 | menuItem[total] = "Operation Extend"; |
| 4406 | menuSubItem[total++] = TEST_FIELD(traverse->type, OperationExtend) ? "On" : "Off"; |
| 4407 | } |
| 3337 | 4408 | |
| 3338 | | if((operation == kOperation_WriteMask) && (locationType != kLocation_IndirectIndexed)) |
| 4409 | if(locationType != kLocation_IndirectIndexed) |
| 4410 | { |
| 4411 | switch(operation) |
| 3339 | 4412 | { |
| 3340 | | /* ----- do mask field ----- */ |
| 3341 | | int numChars; |
| 3342 | | |
| 3343 | | if(traverse->flags & kActionFlag_IgnoreMask) |
| 4413 | default: |
| 3344 | 4414 | { |
| 3345 | | menuItemInfo[total].extraData = 0xFFFFFFFF; |
| 3346 | | numChars = 8; |
| 3347 | | } |
| 3348 | | else |
| 3349 | | { |
| 3350 | | menuItemInfo[total].extraData = kCheatSizeMaskTable[EXTRACT_FIELD(traverse->type, BytesUsed)]; |
| 3351 | | numChars = kCheatSizeDigitsTable[EXTRACT_FIELD(traverse->type, BytesUsed)]; |
| 3352 | | } |
| 4415 | /* do mask field */ |
| 4416 | int numChars; |
| 3353 | 4417 | |
| 3354 | | sprintf(extendDataBuf[i], "%.*X", numChars, traverse->extendData); |
| 4418 | if(traverse->flags & kActionFlag_IndexAddress) |
| 4419 | { |
| 4420 | menuItemInfo[total].extra_data = 0xFFFFFFFF; |
| 4421 | numChars = 8; |
| 4422 | } |
| 4423 | else |
| 4424 | { |
| 4425 | menuItemInfo[total].extra_data = kCheatSizeMaskTable[EXTRACT_FIELD(traverse->type, BytesUsed)]; |
| 4426 | numChars = kCheatSizeDigitsTable[EXTRACT_FIELD(traverse->type, BytesUsed)]; |
| 4427 | } |
| 3355 | 4428 | |
| 3356 | | menuItemInfo[total].subcheat = i; |
| 3357 | | menuItemInfo[total].fieldType = kType_WriteMask; |
| 3358 | | menuItem[total] = "Mask"; |
| 3359 | | menuSubItem[total++] = extendDataBuf[i]; |
| 3360 | | } |
| 4429 | sprintf(extendDataBuf[i], "%.*X", numChars, traverse->extendData & kCheatSizeMaskTable[EXTRACT_FIELD(traverse->type, BytesUsed)]); |
| 3361 | 4430 | |
| 3362 | | if(operation == kOperation_AddSubtract) |
| 3363 | | { |
| 3364 | | { |
| 3365 | | /* ----- do add/subtract field ----- */ |
| 3366 | | menuItemInfo[total].subcheat = i; |
| 3367 | | menuItemInfo[total].fieldType = kType_AddSubtract; |
| 3368 | | menuItem[total] = "Add/Subtract"; |
| 3369 | | menuSubItem[total++] = kAddSubtractNames[operationParameter]; |
| 4431 | menuItemInfo[total].sub_cheat = i; |
| 4432 | menuItemInfo[total].field_type = kType_WriteMask; |
| 4433 | menuItem[total] = "Mask"; |
| 4434 | menuSubItem[total++] = extendDataBuf[i]; |
| 3370 | 4435 | } |
| 4436 | break; |
| 3371 | 4437 | |
| 3372 | | if(locationType != kLocation_IndirectIndexed) |
| 4438 | case kOperation_AddSubtract: |
| 3373 | 4439 | { |
| 4440 | { |
| 4441 | /* do add/subtract field */ |
| 4442 | menuItemInfo[total].sub_cheat = i; |
| 4443 | menuItemInfo[total].field_type = kType_AddSubtract; |
| 4444 | menuItem[total] = "Add/Subtract"; |
| 4445 | menuSubItem[total++] = kAddSubtractNames[operationParameter]; |
| 4446 | } |
| 4447 | |
| 3374 | 4448 | if(operationParameter) |
| 3375 | 4449 | { |
| 3376 | | /* ----- do subtract minimum field ----- */ |
| 4450 | /* do subtract minimum field */ |
| 3377 | 4451 | sprintf(extendDataBuf[i], "%.8X", traverse->extendData); |
| 3378 | 4452 | |
| 3379 | | menuItemInfo[total].subcheat = i; |
| 3380 | | menuItemInfo[total].fieldType = kType_SubtractMinimum; |
| 4453 | menuItemInfo[total].sub_cheat = i; |
| 4454 | menuItemInfo[total].field_type = kType_SubtractMinimum; |
| 3381 | 4455 | menuItem[total] = "Minimum Boundary"; |
| 3382 | 4456 | menuSubItem[total++] = extendDataBuf[i]; |
| 3383 | 4457 | } |
| 3384 | 4458 | else |
| 3385 | 4459 | { |
| 3386 | | /* ----- do add maximum field ----- */ |
| 4460 | /* do add maximum field */ |
| 3387 | 4461 | sprintf(extendDataBuf[i], "%.8X", traverse->extendData); |
| 3388 | 4462 | |
| 3389 | | menuItemInfo[total].subcheat = i; |
| 3390 | | menuItemInfo[total].fieldType = kType_AddMaximum; |
| 4463 | menuItemInfo[total].sub_cheat = i; |
| 4464 | menuItemInfo[total].field_type = kType_AddMaximum; |
| 3391 | 4465 | menuItem[total] = "Maximum Boundary"; |
| 3392 | 4466 | menuSubItem[total++] = extendDataBuf[i]; |
| 3393 | 4467 | } |
| 3394 | 4468 | } |
| 3395 | | } |
| 4469 | break; |
| 3396 | 4470 | |
| 3397 | | if((operation == kOperation_ForceRange) && (locationType != kLocation_IndirectIndexed)) |
| 3398 | | { |
| 3399 | | /* ----- do range minimum field ----- */ |
| 3400 | | if(!EXTRACT_FIELD(traverse->type, BytesUsed)) |
| 3401 | | sprintf(extendDataBuf[i], "%.2X", (traverse->extendData >> 8) & 0xFF); |
| 3402 | | else |
| 3403 | | sprintf(extendDataBuf[i], "%.4X", (traverse->extendData >> 16) & 0xFFFF); |
| 3404 | | |
| 3405 | | menuItemInfo[total].subcheat = i; |
| 3406 | | menuItemInfo[total].fieldType = kType_RangeMinimum; |
| 3407 | | menuItem[total] = "Range Minimum"; |
| 3408 | | menuSubItem[total++] = extendDataBuf[i]; |
| 3409 | | |
| 3410 | | /* ----- do range maximum field ----- */ |
| 3411 | | if(!EXTRACT_FIELD(traverse->type, BytesUsed)) |
| 4471 | case kOperation_ForceRange: |
| 3412 | 4472 | { |
| 3413 | | sprintf(extendDataBuf[i] + 3, "%.2X", (traverse->extendData >> 0) & 0xFF); |
| 3414 | | menuSubItem[total] = extendDataBuf[i] + 3; |
| 3415 | | } |
| 3416 | | else |
| 3417 | | { |
| 3418 | | sprintf(extendDataBuf[i] + 7, "%.4X", (traverse->extendData >> 0) & 0xFFFF); |
| 3419 | | menuSubItem[total] = extendDataBuf[i] + 7; |
| 3420 | | } |
| 3421 | | |
| 3422 | | menuItemInfo[total].subcheat = i; |
| 3423 | | menuItemInfo[total].fieldType = kType_RangeMaximum; |
| 3424 | | menuItem[total++] = "Range Maximum"; |
| 3425 | | } |
| 3426 | | |
| 3427 | | if(operation == kOperation_SetOrClearBits) |
| 3428 | | { |
| 3429 | | /* ----- do set/clear field ----- */ |
| 3430 | | menuItemInfo[total].subcheat = i; |
| 3431 | | menuItemInfo[total].fieldType = kType_SetClear; |
| 3432 | | menuItem[total] = "Set/Clear"; |
| 3433 | | menuSubItem[total++] = kSetClearNames[operationParameter]; |
| 3434 | | } |
| 3435 | | |
| 3436 | | if(operation == kOperation_WriteMatch) |
| 3437 | | { |
| 3438 | | /* ----- do match value field ----- */ |
| 3439 | | menuItemInfo[total].subcheat = i; |
| 3440 | | menuItemInfo[total].fieldType = kType_WriteMatch; |
| 3441 | | menuItem[total] = "Match to Write"; |
| 3442 | | |
| 3443 | | { |
| 3444 | | int numChars; |
| 3445 | | |
| 3446 | | if(traverse->flags & kActionFlag_IgnoreMask) |
| 3447 | 4473 | { |
| 3448 | | menuItemInfo[total].extraData = 0xFFFFFFFF; |
| 3449 | | numChars = 8; |
| 3450 | | } |
| 3451 | | else |
| 3452 | | { |
| 3453 | | menuItemInfo[total].extraData = kCheatSizeMaskTable[EXTRACT_FIELD(traverse->type, BytesUsed)]; |
| 3454 | | numChars = kCheatSizeDigitsTable[EXTRACT_FIELD(traverse->type, BytesUsed)]; |
| 3455 | | } |
| 4474 | /* do range minimum field */ |
| 4475 | if(!EXTRACT_FIELD(traverse->type, BytesUsed)) |
| 4476 | sprintf(extendDataBuf[i], "%.2X", (traverse->extendData >> 8) & 0xFF); |
| 4477 | else |
| 4478 | sprintf(extendDataBuf[i], "%.4X", (traverse->extendData >> 16) & 0xFFFF); |
| 3456 | 4479 | |
| 3457 | | sprintf(extendDataBuf[i], "%.*X", numChars, traverse->extendData); |
| 3458 | | } |
| 3459 | | |
| 3460 | | menuSubItem[total++] = extendDataBuf[i]; |
| 3461 | | } |
| 3462 | | |
| 3463 | | if((operation != kOperation_None) || (type == kType_Watch)) |
| 3464 | | { |
| 3465 | | UINT32 userSelect = TEST_FIELD(entry->actionList[0].type, UserSelectEnable); |
| 3466 | | UINT32 bytesUsed = EXTRACT_FIELD(traverse->type, BytesUsed); |
| 3467 | | |
| 3468 | | if(type != kType_Watch) |
| 3469 | | { |
| 3470 | | { |
| 3471 | | /* ----- do data field ----- */ |
| 3472 | | |
| 3473 | | sprintf(dataBuf[i], "%.*X (%d)", (int)kCheatSizeDigitsTable[bytesUsed], traverse->originalDataField, traverse->originalDataField); |
| 3474 | | |
| 3475 | | menuItemInfo[total].subcheat = i; |
| 3476 | | menuItemInfo[total].fieldType = kType_Data; |
| 3477 | | menuItemInfo[total].extraData = kCheatSizeMaskTable[bytesUsed]; |
| 3478 | | menuItem[total] = "Data"; |
| 3479 | | menuSubItem[total++] = dataBuf[i]; |
| 4480 | menuItemInfo[total].sub_cheat = i; |
| 4481 | menuItemInfo[total].field_type = kType_RangeMinimum; |
| 4482 | menuItem[total] = "Range Minimum"; |
| 4483 | menuSubItem[total++] = extendDataBuf[i]; |
| 3480 | 4484 | } |
| 3481 | 4485 | |
| 3482 | | if(!i) |
| 3483 | 4486 | { |
| 3484 | | /* ----- do user select field ----- */ |
| 3485 | | menuItemInfo[total].subcheat = i; |
| 3486 | | menuItemInfo[total].fieldType = kType_UserSelect; |
| 3487 | | menuItem[total] = "User Select"; |
| 3488 | | menuSubItem[total++] = userSelect ? "On" : "Off"; |
| 3489 | | } |
| 3490 | | |
| 3491 | | if(!i && userSelect) |
| 3492 | | { |
| 4487 | /* do range maximum field */ |
| 4488 | if(!EXTRACT_FIELD(traverse->type, BytesUsed)) |
| 3493 | 4489 | { |
| 3494 | | /* ----- do user select minimum displayed value field ----- */ |
| 3495 | | menuItemInfo[total].subcheat = i; |
| 3496 | | menuItemInfo[total].fieldType = kType_UserSelectMinimumDisp; |
| 3497 | | menuItem[total] = "Minimum Displayed Value"; |
| 3498 | | menuSubItem[total++] = kNumbersTable[EXTRACT_FIELD(traverse->type, UserSelectMinimumDisplay)]; |
| 4490 | sprintf(extendDataBuf[i] + 3, "%.2X", (traverse->extendData >> 0) & 0xFF); |
| 4491 | menuSubItem[total] = extendDataBuf[i] + 3; |
| 3499 | 4492 | } |
| 3500 | | |
| 4493 | else |
| 3501 | 4494 | { |
| 3502 | | /* ----- do user select minimum value field ----- */ |
| 3503 | | menuItemInfo[total].subcheat = i; |
| 3504 | | menuItemInfo[total].fieldType = kType_UserSelectMinimum; |
| 3505 | | menuItem[total] = "Minimum Value"; |
| 3506 | | menuSubItem[total++] = kNumbersTable[EXTRACT_FIELD(traverse->type, UserSelectMinimum)]; |
| 4495 | sprintf(extendDataBuf[i] + 7, "%.4X", (traverse->extendData >> 0) & 0xFFFF); |
| 4496 | menuSubItem[total] = extendDataBuf[i] + 7; |
| 3507 | 4497 | } |
| 3508 | | } |
| 3509 | 4498 | |
| 3510 | | if(userSelect) |
| 3511 | | { |
| 3512 | | /* ----- do user select BCD field ----- */ |
| 3513 | | menuItemInfo[total].subcheat = i; |
| 3514 | | menuItemInfo[total].fieldType = kType_UserSelectBCD; |
| 3515 | | menuItem[total] = "BCD"; |
| 3516 | | menuSubItem[total++] = TEST_FIELD(traverse->type, UserSelectBCD) ? "On" : "Off"; |
| 4499 | menuItemInfo[total].sub_cheat = i; |
| 4500 | menuItemInfo[total].field_type = kType_RangeMaximum; |
| 4501 | menuItem[total++] = "Range Maximum"; |
| 3517 | 4502 | } |
| 3518 | | |
| 3519 | | if(userSelect || isSelect) |
| 3520 | | { |
| 3521 | | /* ----- do prefill field ----- */ |
| 3522 | | menuItemInfo[total].subcheat = i; |
| 3523 | | menuItemInfo[total].fieldType = kType_Prefill; |
| 3524 | | menuItem[total] = "Prefill"; |
| 3525 | | menuSubItem[total++] = kPrefillNames[EXTRACT_FIELD(traverse->type, Prefill)]; |
| 3526 | | } |
| 3527 | | |
| 3528 | | if(i && userSelect) |
| 3529 | | { |
| 3530 | | /* ----- do copy previous value field ----- */ |
| 3531 | | menuItemInfo[total].subcheat = i; |
| 3532 | | menuItemInfo[total].fieldType = kType_CopyPrevious; |
| 3533 | | menuItem[total] = "Copy Previous Value"; |
| 3534 | | menuSubItem[total++] = TEST_FIELD(traverse->type, LinkCopyPreviousValue) ? "On" : "Off"; |
| 3535 | | } |
| 3536 | 4503 | } |
| 4504 | break; |
| 3537 | 4505 | |
| 4506 | case kOperation_SetOrClearBits: |
| 3538 | 4507 | { |
| 3539 | | /* ----- do byte length field ----- */ |
| 3540 | | menuItemInfo[total].subcheat = i; |
| 3541 | | menuItemInfo[total].fieldType = kType_ByteLength; |
| 3542 | | menuItem[total] = "Byte Length"; |
| 3543 | | menuSubItem[total++] = kSizeNames[bytesUsed]; |
| 4508 | /* do set/clear field */ |
| 4509 | menuItemInfo[total].sub_cheat = i; |
| 4510 | menuItemInfo[total].field_type = kType_SetClear; |
| 4511 | menuItem[total] = "Set/Clear"; |
| 4512 | menuSubItem[total++] = kSetClearNames[operationParameter]; |
| 3544 | 4513 | } |
| 4514 | break; |
| 4515 | } |
| 4516 | } |
| 3545 | 4517 | |
| 3546 | | if(bytesUsed > 0) |
| 3547 | | { |
| 3548 | | /* ----- do endianness field ----- */ |
| 3549 | | menuItemInfo[total].subcheat = i; |
| 3550 | | menuItemInfo[total].fieldType = kType_Endianness; |
| 3551 | | menuItem[total] = "Endianness"; |
| 3552 | | menuSubItem[total++] = kEndiannessNames[EXTRACT_FIELD(traverse->type, Endianness)]; |
| 3553 | | } |
| 4518 | { |
| 4519 | /* do data field */ |
| 4520 | sprintf(dataBuf[i], "%.*X (%d)", |
| 4521 | (int)kCheatSizeDigitsTable[EXTRACT_FIELD(traverse->type, BytesUsed)], |
| 4522 | traverse->originalDataField, |
| 4523 | traverse->originalDataField); |
| 3554 | 4524 | |
| 3555 | | { |
| 3556 | | /* ----- do location type field ----- */ |
| 3557 | | menuItemInfo[total].subcheat = i; |
| 3558 | | menuItemInfo[total].fieldType = kType_LocationType; |
| 3559 | | menuItem[total] = "Location"; |
| 4525 | menuItemInfo[total].sub_cheat = i; |
| 4526 | menuItemInfo[total].field_type = kType_Data; |
| 4527 | menuItemInfo[total].extra_data = kCheatSizeMaskTable[EXTRACT_FIELD(traverse->type, BytesUsed)]; |
| 4528 | menuItem[total] = "Data"; |
| 4529 | menuSubItem[total++] = dataBuf[i]; |
| 4530 | } |
| 3560 | 4531 | |
| 3561 | | if(locationType == kLocation_Custom) |
| 3562 | | menuSubItem[total++] = kCustomLocationNames[locationParameter]; |
| 3563 | | else |
| 3564 | | menuSubItem[total++] = kLocationNames[locationType]; |
| 3565 | | } |
| 4532 | { |
| 4533 | /* do user select field */ |
| 4534 | menuItemInfo[total].sub_cheat = i; |
| 4535 | menuItemInfo[total].field_type = kType_UserSelect; |
| 4536 | menuItem[total] = "User Select"; |
| 4537 | menuSubItem[total++] = EXTRACT_FIELD(traverse->type, UserSelectEnable) ? "On" : "Off"; |
| 4538 | } |
| 3566 | 4539 | |
| 3567 | | if( (locationType == kLocation_Standard) || (locationType == kLocation_HandlerMemory) || |
| 3568 | | (locationType == kLocation_ProgramSpace)) |
| 3569 | | { |
| 3570 | | /* ----- do cpu field ----- */ |
| 3571 | | menuItemInfo[total].subcheat = i; |
| 3572 | | menuItemInfo[total].fieldType = kType_CPU; |
| 3573 | | menuItem[total] = "CPU"; |
| 3574 | | menuSubItem[total++] = kNumbersTable[locationParameter]; |
| 3575 | | } |
| 4540 | { |
| 4541 | /* do user select minimum displayed value field */ |
| 4542 | menuItemInfo[total].sub_cheat = i; |
| 4543 | menuItemInfo[total].field_type = kType_UserSelectMinimumDisp; |
| 4544 | menuItem[total] = "Minimum Displayed Value"; |
| 4545 | menuSubItem[total++] = kNumbersTable[EXTRACT_FIELD(traverse->type, UserSelectMinimumDisplay)]; |
| 4546 | } |
| 3576 | 4547 | |
| 3577 | | if(locationType == kLocation_MemoryRegion) |
| 3578 | | { |
| 3579 | | /* ----- do region field ----- */ |
| 3580 | | menuItemInfo[total].subcheat = i; |
| 3581 | | menuItemInfo[total].fieldType = kType_Region; |
| 3582 | | menuItem[total] = "Region"; |
| 3583 | | menuSubItem[total++] = kRegionNames[locationParameter]; |
| 3584 | | } |
| 4548 | { |
| 4549 | /* do user select minimum value field */ |
| 4550 | menuItemInfo[total].sub_cheat = i; |
| 4551 | menuItemInfo[total].field_type = kType_UserSelectMinimum; |
| 4552 | menuItem[total] = "Minimum Value"; |
| 4553 | menuSubItem[total++] = kNumbersTable[EXTRACT_FIELD(traverse->type, UserSelectMinimum)]; |
| 4554 | } |
| 3585 | 4555 | |
| 3586 | | if(locationType == kLocation_IndirectIndexed) |
| 3587 | | { |
| 3588 | | { |
| 3589 | | /* ----- do packed CPU field ----- */ |
| 3590 | | menuItemInfo[total].subcheat = i; |
| 3591 | | menuItemInfo[total].fieldType = kType_PackedCPU; |
| 3592 | | menuItem[total] = "CPU"; |
| 3593 | | menuSubItem[total++] = kNumbersTable[(locationParameter >> 2) & 7]; |
| 3594 | | } |
| 4556 | { |
| 4557 | /* do user select BCD field */ |
| 4558 | menuItemInfo[total].sub_cheat = i; |
| 4559 | menuItemInfo[total].field_type = kType_UserSelectBCD; |
| 4560 | menuItem[total] = "BCD"; |
| 4561 | menuSubItem[total++] = TEST_FIELD(traverse->type, UserSelectBCD) ? "On" : "Off"; |
| 4562 | } |
| 3595 | 4563 | |
| 3596 | | { |
| 3597 | | /* ----- do packed size field ----- */ |
| 3598 | | menuItemInfo[total].subcheat = i; |
| 3599 | | menuItemInfo[total].fieldType = kType_PackedSize; |
| 3600 | | menuItem[total] = "Address Size"; |
| 3601 | | menuSubItem[total++] = kNumbersTable[(locationParameter & 3) + 1]; |
| 3602 | | } |
| 4564 | { |
| 4565 | /* do copy previous value field */ |
| 4566 | menuItemInfo[total].sub_cheat = i; |
| 4567 | menuItemInfo[total].field_type = kType_CopyPrevious; |
| 4568 | menuItem[total] = "Copy Previous Value"; |
| 4569 | menuSubItem[total++] = TEST_FIELD(traverse->type, LinkCopyPreviousValue) ? "On" : "Off"; |
| 4570 | } |
| 3603 | 4571 | |
| 3604 | | { |
| 3605 | | /* ----- do address index field ----- */ |
| 4572 | { |
| 4573 | /* do prefill field */ |
| 4574 | menuItemInfo[total].sub_cheat = i; |
| 4575 | menuItemInfo[total].field_type = kType_Prefill; |
| 4576 | menuItem[total] = "Prefill"; |
| 4577 | menuSubItem[total++] = kPrefillNames[EXTRACT_FIELD(traverse->type, Prefill)]; |
| 4578 | } |
| 3606 | 4579 | |
| 3607 | | /* ---- swap if negative ----- */ |
| 3608 | | if(traverse->extendData & 0x80000000) |
| 3609 | | { |
| 3610 | | int temp = traverse->extendData; |
| 4580 | { |
| 4581 | /* do byte length field */ |
| 4582 | menuItemInfo[total].sub_cheat = i; |
| 4583 | menuItemInfo[total].field_type = kType_ByteLength; |
| 4584 | menuItem[total] = "Byte Length"; |
| 4585 | menuSubItem[total++] = kByteSizeStringList[EXTRACT_FIELD(traverse->type, BytesUsed)]; |
| 4586 | } |
| 3611 | 4587 | |
| 3612 | | temp = -temp; |
| 4588 | { |
| 4589 | /* do endianness field */ |
| 4590 | menuItemInfo[total].sub_cheat = i; |
| 4591 | menuItemInfo[total].field_type = kType_Endianness; |
| 4592 | menuItem[total] = "Endianness"; |
| 4593 | menuSubItem[total++] = kEndiannessNames[EXTRACT_FIELD(traverse->type, Endianness)]; |
| 4594 | } |
| 3613 | 4595 | |
| 3614 | | sprintf(extendDataBuf[i], "-%.8X", temp); |
| 3615 | | } |
| 3616 | | else |
| 3617 | | sprintf(extendDataBuf[i], "%.8X", traverse->extendData); |
| 4596 | { |
| 4597 | /* do location type field */ |
| 4598 | menuItemInfo[total].sub_cheat = i; |
| 4599 | menuItemInfo[total].field_type = kType_LocationType; |
| 4600 | menuItem[total] = "Location"; |
| 3618 | 4601 | |
| 3619 | | menuItemInfo[total].subcheat = i; |
| 3620 | | menuItemInfo[total].fieldType = kType_AddressIndex; |
| 3621 | | menuItem[total] = "Address Index"; |
| 3622 | | menuSubItem[total++] = extendDataBuf[i]; |
| 3623 | | } |
| 3624 | | } |
| 4602 | if(locationType == kLocation_Custom) |
| 4603 | /* "Comment", "EEPROM", "Select" */ |
| 4604 | menuSubItem[total++] = kCustomLocationNames[locationParameter]; |
| 4605 | else |
| 4606 | /* "Normal", "Region", "Mapped Memory", "Relative Address" */ |
| 4607 | menuSubItem[total++] = kLocationNames[locationType]; |
| 4608 | } |
| 3625 | 4609 | |
| 4610 | if(locationType != kLocation_IndirectIndexed) |
| 4611 | { |
| 4612 | if(locationType != kLocation_MemoryRegion) |
| 4613 | { |
| 4614 | /* do cpu field */ |
| 4615 | menuItemInfo[total].sub_cheat = i; |
| 4616 | menuItemInfo[total].field_type = kType_CPU; |
| 4617 | menuItem[total] = "CPU"; |
| 4618 | menuSubItem[total++] = kNumbersTable[locationParameter]; |
| 4619 | } |
| 4620 | else |
| 4621 | { |
| 4622 | /* do region field */ |
| 4623 | menuItemInfo[total].sub_cheat = i; |
| 4624 | menuItemInfo[total].field_type = kType_Region; |
| 4625 | menuItem[total] = "Region"; |
| 4626 | menuSubItem[total++] = kRegionNames[locationParameter]; |
| 4627 | } |
| 4628 | } |
| 4629 | else |
| 4630 | { |
| 4631 | { |
| 4632 | /* do packed CPU field */ |
| 4633 | menuItemInfo[total].sub_cheat = i; |
| 4634 | menuItemInfo[total].field_type = kType_PackedCPU; |
| 4635 | menuItem[total] = "CPU"; |
| 4636 | menuSubItem[total++] = kNumbersTable[EXTRACT_FIELD(traverse->type, LocationParameterCPU)]; |
| 4637 | } |
| 4638 | |
| 4639 | { |
| 4640 | /* do packed size field */ |
| 4641 | menuItemInfo[total].sub_cheat = i; |
| 4642 | menuItemInfo[total].field_type = kType_PackedSize; |
| 4643 | menuItem[total] = "Address Size"; |
| 4644 | menuSubItem[total++] = kNumbersTable[(locationParameter & 3) + 1]; |
| 4645 | } |
| 4646 | |
| 4647 | { |
| 4648 | /* do address index field */ |
| 4649 | if(traverse->extendData & 0x80000000) |
| 3626 | 4650 | { |
| 3627 | | /* ----- do address field ----- */ |
| 3628 | | int charsToPrint = 8; |
| 4651 | /* swap if negative */ |
| 4652 | int temp = traverse->extendData; |
| 3629 | 4653 | |
| 3630 | | switch(EXTRACT_FIELD(traverse->type, LocationType)) |
| 3631 | | { |
| 3632 | | case kLocation_Standard: |
| 3633 | | case kLocation_HandlerMemory: |
| 3634 | | case kLocation_ProgramSpace: |
| 3635 | | { |
| 3636 | | CPUInfo * cpuInfo = &cpuInfoList[EXTRACT_FIELD(traverse->type, LocationParameter)]; |
| 4654 | temp = -temp; |
| 3637 | 4655 | |
| 3638 | | charsToPrint = cpuInfo->addressCharsNeeded; |
| 3639 | | menuItemInfo[total].extraData = cpuInfo->addressMask; |
| 3640 | | } |
| 3641 | | break; |
| 4656 | sprintf(extendDataBuf[i], "-%.8X", temp); |
| 4657 | } |
| 4658 | else |
| 4659 | sprintf(extendDataBuf[i], "%.8X", traverse->extendData); |
| 3642 | 4660 | |
| 3643 | | case kLocation_IndirectIndexed: |
| 3644 | | { |
| 3645 | | CPUInfo * cpuInfo = &cpuInfoList[(EXTRACT_FIELD(traverse->type, LocationParameter) >> 2) & 7]; |
| 4661 | menuItemInfo[total].sub_cheat = i; |
| 4662 | menuItemInfo[total].field_type = kType_AddressIndex; |
| 4663 | menuItem[total] = "Address Index"; |
| 4664 | menuSubItem[total++] = extendDataBuf[i]; |
| 4665 | } |
| 4666 | } |
| 3646 | 4667 | |
| 3647 | | charsToPrint = cpuInfo->addressCharsNeeded; |
| 3648 | | menuItemInfo[total].extraData = cpuInfo->addressMask; |
| 3649 | | } |
| 3650 | | break; |
| 4668 | { |
| 4669 | /* do address field */ |
| 4670 | cpu_region_info *info = get_cpu_info(0); |
| 3651 | 4671 | |
| 3652 | | default: |
| 3653 | | menuItemInfo[total].extraData = 0xFFFFFFFF; |
| 3654 | | } |
| 4672 | switch(EXTRACT_FIELD(traverse->type, LocationType)) |
| 4673 | { |
| 4674 | case kLocation_Standard: |
| 4675 | case kLocation_HandlerMemory: |
| 4676 | case kLocation_MemoryRegion: |
| 4677 | case kLocation_IndirectIndexed: |
| 4678 | menuItemInfo[total].extra_data = info->addressMask; |
| 4679 | break; |
| 3655 | 4680 | |
| 3656 | | sprintf(addressBuf[i], "%.*X", charsToPrint, traverse->address); |
| 4681 | default: |
| 4682 | menuItemInfo[total].extra_data = 0xFFFFFFFF; |
| 4683 | } |
| 3657 | 4684 | |
| 3658 | | menuItemInfo[total].subcheat = i; |
| 3659 | | menuItemInfo[total].fieldType = kType_Address; |
| 3660 | | menuItem[total] = "Address"; |
| 3661 | | menuSubItem[total++] = addressBuf[i]; |
| 3662 | | } |
| 3663 | | } |
| 4685 | sprintf(addressBuf[i], "%.*X", get_address_length(EXTRACT_FIELD(traverse->type, LocationParameter)), traverse->address); |
| 4686 | |
| 4687 | menuItemInfo[total].sub_cheat = i; |
| 4688 | menuItemInfo[total].field_type = kType_Address; |
| 4689 | menuItem[total] = "Address"; |
| 4690 | menuSubItem[total++] = addressBuf[i]; |
| 3664 | 4691 | } |
| 3665 | 4692 | |
| 3666 | | if(i < (entry->actionListLength - 1)) |
| 4693 | if(i < entry->actionListLength - 1) |
| 3667 | 4694 | { |
| 3668 | | menuItemInfo[total].subcheat = i; |
| 3669 | | menuItemInfo[total].fieldType = kType_Divider; |
| 3670 | | menuItem[total] = "=========="; |
| 4695 | /* do divider */ |
| 4696 | menuItemInfo[total].sub_cheat = i; |
| 4697 | menuItemInfo[total].field_type = kType_Divider; |
| 4698 | menuItem[total] = MENU_SEPARATOR_ITEM; |
| 3671 | 4699 | menuSubItem[total++] = NULL; |
| 3672 | 4700 | } |
| 3673 | 4701 | } |
| 3674 | 4702 | |
| 3675 | | menuItemInfo[total].subcheat = 0; // return |
| 3676 | | menuItemInfo[total].fieldType = kType_Return; |
| 3677 | | menuItem[total] = "Return to Prior Menu"; |
| 3678 | | menuSubItem[total++] = NULL; |
| 4703 | /* ##### RETURN ##### */ |
| 4704 | menuItemInfo[total].sub_cheat = 0; |
| 4705 | menuItemInfo[total].field_type = kType_Return; |
| 4706 | menuItem[total] = "Return to Prior Menu"; |
| 4707 | menuSubItem[total++] = NULL; |
| 3679 | 4708 | |
| 3680 | | menuItemInfo[total].subcheat = 0; // terminate arrey |
| 3681 | | menuItemInfo[total].fieldType = kType_Return; |
| 3682 | | menuItem[total] = NULL; |
| 3683 | | menuSubItem[total] = NULL; |
| 4709 | /* ##### TERMINATE ARREY ##### */ |
| 4710 | menuItemInfo[total].sub_cheat = 0; |
| 4711 | menuItemInfo[total].field_type = kType_Return; |
| 4712 | menuItem[total] = NULL; |
| 4713 | menuSubItem[total] = NULL; |
| 3684 | 4714 | |
| 3685 | | /* ----- adjuste cursor position ----- */ |
| 4715 | /* adjust cursor position */ |
| 3686 | 4716 | if(sel < 0) |
| 3687 | 4717 | sel = 0; |
| 3688 | 4718 | if(sel >= total) |
| 3689 | 4719 | sel = total - 1; |
| 3690 | 4720 | |
| 3691 | 4721 | info = &menuItemInfo[sel]; |
| 3692 | | action = &entry->actionList[info->subcheat]; |
| 4722 | action = &entry->actionList[info->sub_cheat]; |
| 3693 | 4723 | |
| 3694 | | /* ----- higlighted sub-item if edit mode ----- */ |
| 4724 | /* higlighted sub-item if edit mode */ |
| 3695 | 4725 | if(editActive) |
| 3696 | 4726 | flagBuf[sel] = 1; |
| 3697 | 4727 | |
| 3698 | | /* ---- draw it ----- */ |
| 4728 | /* draw it */ |
| 3699 | 4729 | old_style_menu(menuItem, menuSubItem, flagBuf, sel, 0); |
| 3700 | 4730 | |
| 3701 | 4731 | /********** KEY HANDLING **********/ |
| 3702 | | if(AltKeyPressed()) |
| 3703 | | increment <<= 4; |
| 3704 | | if(ControlKeyPressed()) |
| 3705 | | increment <<= 8; |
| 3706 | | if(ShiftKeyPressed()) |
| 3707 | | increment <<= 16; |
| 3708 | | |
| 3709 | | if(UIPressedRepeatThrottle(machine, IPT_UI_LEFT, kHorizontalSlowKeyRepeatRate)) |
| 4732 | if(ui_pressed_repeat_throttle(machine, IPT_UI_LEFT, kHorizontalSlowKeyRepeatRate)) |
| 3710 | 4733 | { |
| 3711 | 4734 | editActive = 0; |
| 3712 | 4735 | dirty = 1; |
| 3713 | 4736 | |
| 3714 | 4737 | switch(info->fieldType) |
| 3715 | 4738 | { |
| 3716 | | case kType_Name: |
| 3717 | | currentNameTemplate--; |
| 3718 | | |
| 3719 | | if(currentNameTemplate < 0) |
| 3720 | | { |
| 3721 | | currentNameTemplate = 0; |
| 3722 | | |
| 3723 | | while(kCheatNameTemplates[currentNameTemplate + 1][0]) |
| 3724 | | { |
| 3725 | | currentNameTemplate++; |
| 3726 | | } |
| 3727 | | } |
| 3728 | | |
| 3729 | | entry->name = realloc(entry->name, strlen(kCheatNameTemplates[currentNameTemplate]) + 1); |
| 3730 | | strcpy(entry->name, kCheatNameTemplates[currentNameTemplate]); |
| 3731 | | break; |
| 3732 | | /* |
| 3733 | | case kType_ActivationKey1: |
| 4739 | /* case kType_ActivationKey1: |
| 3734 | 4740 | case kType_ActivationKey2: |
| 3735 | 4741 | if(info->fieldType == kType_ActivationKey1) |
| 3736 | 4742 | { |
| 3737 | 4743 | entry->activationKey1--; |
| 3738 | 4744 | |
| 3739 | | if(entry->activationKey1 < 0) |
| 4745 | if(entry->activationKey1 < 0) |
| 3740 | 4746 | entry->activationKey1 = __code_max - 1; |
| 3741 | 4747 | if(entry->activationKey1 >= __code_max) |
| 3742 | 4748 | entry->activationKey1 = 0; |
| r2762 | r2763 | |
| 3756 | 4762 | } |
| 3757 | 4763 | break; |
| 3758 | 4764 | */ |
| 4765 | case kType_Link: |
| 4766 | TOGGLE_MASK_FIELD(action->type, LinkEnable); |
| 4767 | break; |
| 4768 | |
| 3759 | 4769 | case kType_LinkExtension: |
| 3760 | 4770 | TOGGLE_MASK_FIELD(action->type, LinkExtension); |
| 3761 | 4771 | break; |
| 3762 | 4772 | |
| 3763 | 4773 | case kType_Type: |
| 3764 | 4774 | { |
| 3765 | | UINT8 handled = 0; |
| 4775 | UINT8 handled = 0; |
| 3766 | 4776 | |
| 3767 | | CLEAR_MASK_FIELD(action->type, OperationExtend); |
| 3768 | | |
| 3769 | 4777 | if(EXTRACT_FIELD(action->type, LocationType) == kLocation_Custom) |
| 3770 | 4778 | { |
| 3771 | | UINT32 locationParameter = EXTRACT_FIELD(action->type, LocationParameter); |
| 4779 | UINT32 locationParameter = EXTRACT_FIELD(action->type, LocationParameter); |
| 3772 | 4780 | |
| 3773 | 4781 | if(locationParameter == kCustomLocation_Comment) |
| 3774 | 4782 | { |
| 4783 | /* "Comment" -> "Watch" */ |
| 3775 | 4784 | SET_FIELD(action->type, LocationParameter, 0); |
| 3776 | 4785 | SET_FIELD(action->type, LocationType, kLocation_Standard); |
| 3777 | 4786 | SET_FIELD(action->type, Type, kType_Watch); |
| 3778 | 4787 | SET_FIELD(action->type, Operation, kOperation_None); |
| 3779 | | SET_MASK_FIELD(action->type, OperationExtend); |
| 3780 | 4788 | |
| 3781 | 4789 | handled = 1; |
| 3782 | 4790 | } |
| 3783 | 4791 | else if(locationParameter == kCustomLocation_Select) |
| 3784 | 4792 | { |
| 4793 | /* "Select" -> "Comment" */ |
| 3785 | 4794 | SET_FIELD(action->type, LocationParameter, kCustomLocation_Comment); |
| 3786 | 4795 | SET_FIELD(action->type, LocationType, kLocation_Custom); |
| 3787 | 4796 | SET_FIELD(action->type, Type, 0); |
| r2762 | r2763 | |
| 3792 | 4801 | |
| 3793 | 4802 | if(!handled) |
| 3794 | 4803 | { |
| 3795 | | UINT32 type = EXTRACT_FIELD(action->type, Type); |
| 4804 | UINT32 type = EXTRACT_FIELD(action->type, Type); |
| 3796 | 4805 | |
| 3797 | 4806 | if(type == kType_NormalOrDelay) |
| 3798 | 4807 | { |
| 4808 | /* "Normal/Delay" -> "Select" */ |
| 4809 | SET_FIELD(action->type, LocationType, kLocation_Custom); |
| 3799 | 4810 | SET_FIELD(action->type, LocationParameter, kCustomLocation_Select); |
| 3800 | | SET_FIELD(action->type, LocationType, kLocation_Custom); |
| 3801 | 4811 | SET_FIELD(action->type, Type, 0); |
| 3802 | 4812 | } |
| 3803 | 4813 | else |
| 3804 | | { |
| 3805 | 4814 | SET_FIELD(action->type, Type, type - 1); |
| 3806 | | } |
| 3807 | 4815 | } |
| 3808 | 4816 | } |
| 3809 | 4817 | break; |
| r2762 | r2763 | |
| 3817 | 4825 | break; |
| 3818 | 4826 | |
| 3819 | 4827 | case kType_Delay: |
| 3820 | | case kType_IgnoreDecrementBy: |
| 3821 | 4828 | { |
| 3822 | | UINT32 delay = (EXTRACT_FIELD(action->type, TypeParameter) - 1) & 7; |
| 4829 | UINT32 delay = (EXTRACT_FIELD(action->type, TypeParameter) - 1) & 7; |
| 3823 | 4830 | |
| 3824 | 4831 | SET_FIELD(action->type, TypeParameter, delay); |
| 3825 | 4832 | } |
| r2762 | r2763 | |
| 3847 | 4854 | |
| 3848 | 4855 | case kType_WatchFormat: |
| 3849 | 4856 | { |
| 3850 | | UINT32 typeParameter = EXTRACT_FIELD(action->type, TypeParameter); |
| 4857 | UINT32 typeParameter = EXTRACT_FIELD(action->type, TypeParameter); |
| 3851 | 4858 | |
| 3852 | 4859 | typeParameter = (typeParameter & 0xFFFFFFFC) | ((typeParameter - 0x00000001) & 0x0000003); |
| 3853 | 4860 | SET_FIELD(action->type, TypeParameter, typeParameter); |
| r2762 | r2763 | |
| 3859 | 4866 | break; |
| 3860 | 4867 | |
| 3861 | 4868 | case kType_Operation: |
| 3862 | | { |
| 3863 | | UINT32 operation = ((EXTRACT_FIELD(action->type, Operation) | EXTRACT_FIELD(action->type, OperationExtend) << 2) - 1) & 7; |
| 3864 | | |
| 3865 | | if(operation == kOperation_None) |
| 3866 | | operation = kOperation_WriteMatch; |
| 3867 | | |
| 3868 | | if( (operation == kOperation_SetOrClearBits) && |
| 3869 | | !(EXTRACT_FIELD(action->type, LocationType) == kLocation_IndirectIndexed)) |
| 3870 | | operation = (operation - 1) & 7; |
| 3871 | | |
| 3872 | | if(operation >> 2) |
| 3873 | | SET_MASK_FIELD(action->type, OperationExtend); |
| 4869 | if(EXTRACT_FIELD(action->type, Operation) == kOperation_WriteMask) |
| 4870 | { |
| 4871 | if(EXTRACT_FIELD(action->type, LocationType) == kLocation_IndirectIndexed) |
| 4872 | SET_FIELD(action->type, Operation, kOperation_SetOrClearBits); |
| 4873 | else |
| 4874 | SET_FIELD(action->type, Operation, kOperation_ForceRange); |
| 4875 | } |
| 3874 | 4876 | else |
| 3875 | | CLEAR_MASK_FIELD(action->type, OperationExtend); |
| 4877 | SET_FIELD(action->type, Operation, EXTRACT_FIELD(action->type, Operation) - 1); |
| 4878 | break; |
| 3876 | 4879 | |
| 3877 | | SET_FIELD(action->type, Operation, operation); |
| 3878 | | } |
| 3879 | | break; |
| 4880 | case kType_OperationExtend: |
| 4881 | TOGGLE_MASK_FIELD(action->type, OperationExtend); |
| 4882 | break; |
| 3880 | 4883 | |
| 3881 | 4884 | case kType_WriteMask: |
| 3882 | | case kType_WriteMatch: |
| 3883 | | action->extendData -= increment; |
| 4885 | action->extendData -= 1; |
| 3884 | 4886 | action->extendData &= info->extraData; |
| 3885 | 4887 | break; |
| 3886 | 4888 | |
| r2762 | r2763 | |
| 3898 | 4900 | action->extendData = (action->extendData & 0xFFFF0000) | ((action->extendData - 0x00000001) & 0x0000FFFF); |
| 3899 | 4901 | break; |
| 3900 | 4902 | |
| 3901 | | case kType_AddressIndex: |
| 3902 | 4903 | case kType_SubtractMinimum: |
| 3903 | 4904 | case kType_AddMaximum: |
| 3904 | | action->extendData -= increment; |
| 4905 | case kType_AddressIndex: |
| 4906 | action->extendData -= 1; |
| 3905 | 4907 | break; |
| 3906 | 4908 | |
| 3907 | 4909 | case kType_AddSubtract: |
| r2762 | r2763 | |
| 3910 | 4912 | break; |
| 3911 | 4913 | |
| 3912 | 4914 | case kType_Data: |
| 3913 | | action->originalDataField -= increment; |
| 4915 | action->originalDataField -= 1; |
| 3914 | 4916 | action->originalDataField &= info->extraData; |
| 3915 | 4917 | action->data = action->originalDataField; |
| 3916 | 4918 | break; |
| r2762 | r2763 | |
| 3931 | 4933 | TOGGLE_MASK_FIELD(action->type, UserSelectBCD); |
| 3932 | 4934 | break; |
| 3933 | 4935 | |
| 4936 | case kType_CopyPrevious: |
| 4937 | TOGGLE_MASK_FIELD(action->type, LinkCopyPreviousValue); |
| 4938 | break; |
| 4939 | |
| 3934 | 4940 | case kType_Prefill: |
| 3935 | 4941 | { |
| 3936 | | UINT32 prefill = (EXTRACT_FIELD(action->type, Prefill) - 1) & 3; |
| 4942 | UINT32 prefill = (EXTRACT_FIELD(action->type, Prefill) - 1) & 3; |
| 3937 | 4943 | |
| 3938 | 4944 | SET_FIELD(action->type, Prefill, prefill); |
| 3939 | 4945 | } |
| 3940 | | break; |
| 4946 | break; |
| 3941 | 4947 | |
| 3942 | | case kType_CopyPrevious: |
| 3943 | | TOGGLE_MASK_FIELD(action->type, LinkCopyPreviousValue); |
| 3944 | | break; |
| 3945 | | |
| 3946 | 4948 | case kType_ByteLength: |
| 3947 | 4949 | { |
| 3948 | | UINT32 length = (EXTRACT_FIELD(action->type, BytesUsed) - 1) & 3; |
| 4950 | UINT32 length = (EXTRACT_FIELD(action->type, BytesUsed) - 1) & 3; |
| 3949 | 4951 | |
| 3950 | 4952 | SET_FIELD(action->type, BytesUsed, length); |
| 3951 | 4953 | } |
| r2762 | r2763 | |
| 3957 | 4959 | |
| 3958 | 4960 | case kType_LocationType: |
| 3959 | 4961 | { |
| 3960 | | UINT32 locationType = EXTRACT_FIELD(action->type, LocationType); |
| 3961 | | UINT32 locationParameter = EXTRACT_FIELD(action->type, LocationParameter); |
| 4962 | UINT32 locationType = EXTRACT_FIELD(action->type, LocationType); |
| 3962 | 4963 | |
| 3963 | | if(locationType == kLocation_Standard) |
| 4964 | switch(locationType) |
| 3964 | 4965 | { |
| 3965 | | SET_FIELD(action->type, LocationType, kLocation_ProgramSpace); |
| 3966 | | SET_FIELD(action->type, LocationParameter, (locationParameter << 2) & 0x1C); |
| 3967 | | } |
| 3968 | | else if(locationType == kLocation_Custom) |
| 3969 | | { |
| 3970 | | SET_FIELD(action->type, LocationType, kLocation_HandlerMemory); |
| 3971 | | SET_FIELD(action->type, LocationParameter, 0); |
| 3972 | | } |
| 3973 | | else if(locationType == kLocation_IndirectIndexed) |
| 3974 | | { |
| 3975 | | SET_FIELD(action->type, LocationType, kLocation_Custom); |
| 3976 | | SET_FIELD(action->type, LocationParameter, kCustomLocation_EEPROM); |
| 3977 | | } |
| 3978 | | else |
| 3979 | | { |
| 3980 | | locationType--; |
| 4966 | case kLocation_Standard: |
| 4967 | /* "Normal" -> "Relative Address" */ |
| 4968 | SET_FIELD(action->type, LocationType, kLocation_IndirectIndexed); |
| 4969 | SET_FIELD(action->type, LocationParameter, 0); |
| 4970 | break; |
| 3981 | 4971 | |
| 3982 | | SET_FIELD(action->type, LocationType, locationType); |
| 4972 | case kLocation_Custom: |
| 4973 | /* "EEPROM" -> "Mapped Memory" */ |
| 4974 | SET_FIELD(action->type, LocationType, kLocation_HandlerMemory); |
| 4975 | SET_FIELD(action->type, LocationParameter, 0); |
| 4976 | break; |
| 4977 | |
| 4978 | case kLocation_IndirectIndexed: |
| 4979 | /* "Relative Address" -> "EEPROM" */ |
| 4980 | SET_FIELD(action->type, LocationType, kLocation_Custom); |
| 4981 | SET_FIELD(action->type, LocationParameter, kCustomLocation_EEPROM); |
| 4982 | break; |
| 4983 | |
| 4984 | default: |
| 4985 | locationType--; |
| 4986 | SET_FIELD(action->type, LocationType, locationType); |
| 3983 | 4987 | } |
| 3984 | 4988 | } |
| 3985 | 4989 | break; |
| r2762 | r2763 | |
| 3987 | 4991 | case kType_CPU: |
| 3988 | 4992 | case kType_Region: |
| 3989 | 4993 | { |
| 3990 | | UINT32 locationParameter = EXTRACT_FIELD(action->type, LocationParameter); |
| 4994 | UINT32 locationParameter = EXTRACT_FIELD(action->type, LocationParameter); |
| 3991 | 4995 | |
| 3992 | 4996 | locationParameter = (locationParameter - 1) & 31; |
| 3993 | 4997 | |
| r2762 | r2763 | |
| 3997 | 5001 | |
| 3998 | 5002 | case kType_PackedCPU: |
| 3999 | 5003 | { |
| 4000 | | UINT32 locationParameter = EXTRACT_FIELD(action->type, LocationParameter); |
| 5004 | UINT32 locationParameter = EXTRACT_FIELD(action->type, LocationParameterCPU); |
| 4001 | 5005 | |
| 4002 | | locationParameter = ((locationParameter - 0x04) & 0x1C) | (locationParameter & 0x03); |
| 5006 | locationParameter = (locationParameter - 1) & 7; |
| 4003 | 5007 | |
| 4004 | | SET_FIELD(action->type, LocationParameter, locationParameter); |
| 5008 | SET_FIELD(action->type, LocationParameterCPU, locationParameter); |
| 4005 | 5009 | } |
| 4006 | 5010 | break; |
| 4007 | 5011 | |
| 4008 | 5012 | case kType_PackedSize: |
| 4009 | 5013 | { |
| 4010 | | UINT32 locationParameter = EXTRACT_FIELD(action->type, LocationParameter); |
| 5014 | UINT32 locationParameter = EXTRACT_FIELD(action->type, LocationParameterOption); |
| 4011 | 5015 | |
| 4012 | | locationParameter = ((locationParameter - 0x01) & 0x03) | (locationParameter & 0x1C); |
| 5016 | locationParameter = (locationParameter - 1) & 3; |
| 4013 | 5017 | |
| 4014 | | SET_FIELD(action->type, LocationParameter, locationParameter); |
| 5018 | SET_FIELD(action->type, LocationParameterOption, locationParameter); |
| 4015 | 5019 | } |
| 4016 | 5020 | break; |
| 4017 | 5021 | |
| 4018 | 5022 | case kType_Address: |
| 4019 | | action->address -= increment; |
| 5023 | action->address -= 1; |
| 4020 | 5024 | action->address &= info->extraData; |
| 4021 | 5025 | break; |
| 4022 | 5026 | |
| r2762 | r2763 | |
| 4025 | 5029 | break; |
| 4026 | 5030 | } |
| 4027 | 5031 | } |
| 4028 | | |
| 4029 | | if(UIPressedRepeatThrottle(machine, IPT_UI_RIGHT, kHorizontalSlowKeyRepeatRate)) |
| 5032 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_RIGHT, kHorizontalSlowKeyRepeatRate)) |
| 4030 | 5033 | { |
| 4031 | 5034 | editActive = 0; |
| 4032 | 5035 | dirty = 1; |
| 4033 | 5036 | |
| 4034 | 5037 | switch(info->fieldType) |
| 4035 | 5038 | { |
| 4036 | | case kType_Name: |
| 4037 | | currentNameTemplate++; |
| 4038 | | |
| 4039 | | if((currentNameTemplate < 0) || !kCheatNameTemplates[currentNameTemplate][0]) |
| 4040 | | { |
| 4041 | | currentNameTemplate = 0; |
| 4042 | | } |
| 4043 | | |
| 4044 | | entry->name = realloc(entry->name, strlen(kCheatNameTemplates[currentNameTemplate]) + 1); |
| 4045 | | strcpy(entry->name, kCheatNameTemplates[currentNameTemplate]); |
| 4046 | | break; |
| 4047 | | /* |
| 4048 | | case kType_ActivationKey1: |
| 5039 | /* case kType_ActivationKey1: |
| 4049 | 5040 | case kType_ActivationKey2: |
| 4050 | 5041 | if(info->fieldType == kType_ActivationKey1) |
| 4051 | 5042 | { |
| r2762 | r2763 | |
| 4071 | 5062 | } |
| 4072 | 5063 | break; |
| 4073 | 5064 | */ |
| 5065 | case kType_Link: |
| 5066 | TOGGLE_MASK_FIELD(action->type, LinkEnable); |
| 5067 | break; |
| 5068 | |
| 4074 | 5069 | case kType_LinkExtension: |
| 4075 | 5070 | TOGGLE_MASK_FIELD(action->type, LinkExtension); |
| 4076 | 5071 | break; |
| 4077 | 5072 | |
| 4078 | 5073 | case kType_Type: |
| 4079 | 5074 | { |
| 4080 | | UINT8 handled = 0; |
| 5075 | UINT8 handled = 0; |
| 4081 | 5076 | |
| 4082 | | CLEAR_MASK_FIELD(action->type, OperationExtend); |
| 4083 | | |
| 4084 | 5077 | if(EXTRACT_FIELD(action->type, LocationType) == kLocation_Custom) |
| 4085 | 5078 | { |
| 4086 | | UINT32 locationParameter = EXTRACT_FIELD(action->type, LocationParameter); |
| 5079 | UINT32 locationParameter = EXTRACT_FIELD(action->type, LocationParameter); |
| 4087 | 5080 | |
| 4088 | 5081 | if(locationParameter == kCustomLocation_Comment) |
| 4089 | 5082 | { |
| 5083 | /* "Comment" -> "Select" */ |
| 4090 | 5084 | SET_FIELD(action->type, LocationParameter, kCustomLocation_Select); |
| 4091 | 5085 | SET_FIELD(action->type, LocationType, kLocation_Custom); |
| 4092 | 5086 | SET_FIELD(action->type, Type, 0); |
| 4093 | 5087 | |
| 4094 | 5088 | handled = 1; |
| 4095 | 5089 | } |
| 4096 | | else if(locationParameter == kCustomLocation_Select) |
| 4097 | | { |
| 4098 | | SET_FIELD(action->type, LocationParameter, 0); |
| 4099 | | SET_FIELD(action->type, LocationType, kLocation_Standard); |
| 4100 | | SET_FIELD(action->type, Type, 0); |
| 5090 | } |
| 5091 | else if((EXTRACT_FIELD(action->type, LocationType) == kLocation_Custom) && |
| 5092 | (EXTRACT_FIELD(action->type, LocationParameter) == kCustomLocation_Select)) |
| 5093 | { |
| 5094 | /* "Select" -> "Normal/Delay" */ |
| 5095 | SET_FIELD(action->type, LocationParameter, 0); |
| 5096 | SET_FIELD(action->type, LocationType, kLocation_Standard); |
| 5097 | SET_FIELD(action->type, Type, 0); |
| 4101 | 5098 | |
| 4102 | | handled = 1; |
| 4103 | | } |
| 5099 | handled = 1; |
| 4104 | 5100 | } |
| 4105 | 5101 | |
| 4106 | 5102 | if(!handled) |
| 4107 | 5103 | { |
| 4108 | | UINT32 type = EXTRACT_FIELD(action->type, Type); |
| 5104 | UINT32 type = EXTRACT_FIELD(action->type, Type); |
| 4109 | 5105 | |
| 4110 | 5106 | if(type == kType_Watch) |
| 4111 | 5107 | { |
| 5108 | /* "Watch" -> "Comment" */ |
| 4112 | 5109 | SET_FIELD(action->type, LocationParameter, kCustomLocation_Comment); |
| 4113 | 5110 | SET_FIELD(action->type, LocationType, kLocation_Custom); |
| 4114 | 5111 | SET_FIELD(action->type, Type, 0); |
| 4115 | 5112 | } |
| 4116 | 5113 | else |
| 4117 | | { |
| 4118 | 5114 | SET_FIELD(action->type, Type, type + 1); |
| 4119 | | |
| 4120 | | if((type + 1) == kType_Watch) |
| 4121 | | { |
| 4122 | | SET_FIELD(action->type, Operation, kOperation_None); |
| 4123 | | SET_MASK_FIELD(action->type, OperationExtend); |
| 4124 | | } |
| 4125 | | } |
| 4126 | 5115 | } |
| 4127 | 5116 | } |
| 4128 | 5117 | break; |
| r2762 | r2763 | |
| 4136 | 5125 | break; |
| 4137 | 5126 | |
| 4138 | 5127 | case kType_Delay: |
| 4139 | | case kType_IgnoreDecrementBy: |
| 4140 | 5128 | { |
| 4141 | | UINT32 delay = (EXTRACT_FIELD(action->type, TypeParameter) + 1) & 7; |
| 5129 | UINT32 delay = (EXTRACT_FIELD(action->type, TypeParameter) + 1) & 7; |
| 4142 | 5130 | |
| 4143 | 5131 | SET_FIELD(action->type, TypeParameter, delay); |
| 4144 | 5132 | } |
| r2762 | r2763 | |
| 4166 | 5154 | |
| 4167 | 5155 | case kType_WatchFormat: |
| 4168 | 5156 | { |
| 4169 | | UINT32 typeParameter = EXTRACT_FIELD(action->type, TypeParameter); |
| 5157 | UINT32 typeParameter = EXTRACT_FIELD(action->type, TypeParameter); |
| 4170 | 5158 | |
| 4171 | 5159 | typeParameter = (typeParameter & 0xFFFFFFFC) | ((typeParameter + 0x00000001) & 0x0000003); |
| 4172 | 5160 | SET_FIELD(action->type, TypeParameter, typeParameter); |
| r2762 | r2763 | |
| 4179 | 5167 | |
| 4180 | 5168 | case kType_Operation: |
| 4181 | 5169 | { |
| 4182 | | UINT32 operation = ((EXTRACT_FIELD(action->type, Operation) | EXTRACT_FIELD(action->type, OperationExtend) << 2) + 1) & 7; |
| 5170 | CLEAR_MASK_FIELD(action->type, OperationExtend); |
| 4183 | 5171 | |
| 4184 | | if(operation > kOperation_WriteMatch) |
| 4185 | | operation = kOperation_WriteMask; |
| 4186 | | |
| 4187 | | if( (operation == kOperation_SetOrClearBits) && |
| 4188 | | !(EXTRACT_FIELD(action->type, LocationType) == kLocation_IndirectIndexed)) |
| 4189 | | operation = (operation + 1) & 7; |
| 4190 | | |
| 4191 | | if(operation >> 2) |
| 4192 | | SET_MASK_FIELD(action->type, OperationExtend); |
| 5172 | if(EXTRACT_FIELD(action->type, LocationType) == kLocation_IndirectIndexed) |
| 5173 | { |
| 5174 | if(EXTRACT_FIELD(action->type, Type) >= kOperation_SetOrClearBits) |
| 5175 | SET_FIELD(action->type, Operation, 0); |
| 5176 | else |
| 5177 | SET_FIELD(action->type, Operation, EXTRACT_FIELD(action->type, Operation) + 1); |
| 5178 | } |
| 5179 | else if(EXTRACT_FIELD(action->type, Operation) >= kOperation_ForceRange) |
| 5180 | SET_FIELD(action->type, Operation, 0); |
| 4193 | 5181 | else |
| 4194 | | CLEAR_MASK_FIELD(action->type, OperationExtend); |
| 4195 | | |
| 4196 | | SET_FIELD(action->type, Operation, operation); |
| 5182 | SET_FIELD(action->type, Operation, EXTRACT_FIELD(action->type, Operation) + 1); |
| 4197 | 5183 | } |
| 4198 | 5184 | break; |
| 4199 | 5185 | |
| 5186 | case kType_OperationExtend: |
| 5187 | TOGGLE_MASK_FIELD(action->type, OperationExtend); |
| 5188 | break; |
| 5189 | |
| 4200 | 5190 | case kType_WriteMask: |
| 4201 | | case kType_WriteMatch: |
| 4202 | | action->extendData += increment; |
| 5191 | action->extendData += 1; |
| 4203 | 5192 | action->extendData &= info->extraData; |
| 4204 | 5193 | break; |
| 4205 | 5194 | |
| r2762 | r2763 | |
| 4220 | 5209 | case kType_AddressIndex: |
| 4221 | 5210 | case kType_SubtractMinimum: |
| 4222 | 5211 | case kType_AddMaximum: |
| 4223 | | action->extendData += increment; |
| 5212 | action->extendData += 1; |
| 4224 | 5213 | break; |
| 4225 | 5214 | |
| 4226 | 5215 | case kType_AddSubtract: |
| r2762 | r2763 | |
| 4229 | 5218 | break; |
| 4230 | 5219 | |
| 4231 | 5220 | case kType_Data: |
| 4232 | | action->originalDataField += increment; |
| 5221 | action->originalDataField += 1; |
| 4233 | 5222 | action->originalDataField &= info->extraData; |
| 4234 | 5223 | action->data = action->originalDataField; |
| 4235 | 5224 | break; |
| r2762 | r2763 | |
| 4250 | 5239 | TOGGLE_MASK_FIELD(action->type, UserSelectBCD); |
| 4251 | 5240 | break; |
| 4252 | 5241 | |
| 5242 | case kType_CopyPrevious: |
| 5243 | TOGGLE_MASK_FIELD(action->type, LinkCopyPreviousValue); |
| 5244 | break; |
| 5245 | |
| 4253 | 5246 | case kType_Prefill: |
| 4254 | 5247 | { |
| 4255 | | UINT32 prefill = (EXTRACT_FIELD(action->type, Prefill) + 1) & 3; |
| 5248 | UINT32 prefill = (EXTRACT_FIELD(action->type, Prefill) + 1) & 3; |
| 4256 | 5249 | |
| 4257 | 5250 | SET_FIELD(action->type, Prefill, prefill); |
| 4258 | 5251 | } |
| 4259 | 5252 | break; |
| 4260 | 5253 | |
| 4261 | | case kType_CopyPrevious: |
| 4262 | | TOGGLE_MASK_FIELD(action->type, LinkCopyPreviousValue); |
| 4263 | | break; |
| 4264 | | |
| 4265 | 5254 | case kType_ByteLength: |
| 4266 | 5255 | { |
| 4267 | | UINT32 length = (EXTRACT_FIELD(action->type, BytesUsed) + 1) & 3; |
| 5256 | UINT32 length = (EXTRACT_FIELD(action->type, BytesUsed) + 1) & 3; |
| 4268 | 5257 | |
| 4269 | 5258 | SET_FIELD(action->type, BytesUsed, length); |
| 4270 | 5259 | } |
| r2762 | r2763 | |
| 4276 | 5265 | |
| 4277 | 5266 | case kType_LocationType: |
| 4278 | 5267 | { |
| 4279 | | UINT32 locationType = EXTRACT_FIELD(action->type, LocationType); |
| 4280 | | UINT32 locationParameter = EXTRACT_FIELD(action->type, LocationParameter); |
| 5268 | UINT32 locationType = EXTRACT_FIELD(action->type, LocationType); |
| 4281 | 5269 | |
| 4282 | | if(locationType == kLocation_ProgramSpace) |
| 5270 | switch(locationType) |
| 4283 | 5271 | { |
| 4284 | | SET_FIELD(action->type, LocationType, kLocation_Standard); |
| 4285 | | SET_FIELD(action->type, LocationParameter, (locationParameter >> 2) & 7); |
| 4286 | | } |
| 4287 | | else if(locationType == kLocation_Custom) |
| 4288 | | { |
| 4289 | | SET_FIELD(action->type, LocationType, kLocation_IndirectIndexed); |
| 4290 | | SET_FIELD(action->type, LocationParameter, 0); |
| 4291 | | } |
| 4292 | | else if(locationType == kLocation_HandlerMemory) |
| 4293 | | { |
| 4294 | | SET_FIELD(action->type, LocationType, kLocation_Custom); |
| 4295 | | SET_FIELD(action->type, LocationParameter, kCustomLocation_EEPROM); |
| 4296 | | } |
| 4297 | | else |
| 4298 | | { |
| 4299 | | locationType++; |
| 5272 | case kLocation_HandlerMemory: |
| 5273 | /* "Mapped Memory" -> "EEPROM" */ |
| 5274 | SET_FIELD(action->type, LocationType, kLocation_Custom); |
| 5275 | SET_FIELD(action->type, LocationParameter, kCustomLocation_EEPROM); |
| 5276 | break; |
| 4300 | 5277 | |
| 4301 | | SET_FIELD(action->type, LocationType, locationType); |
| 5278 | case kLocation_Custom: |
| 5279 | /* "EEPROM" -> "Relative Address" */ |
| 5280 | SET_FIELD(action->type, LocationType, kLocation_IndirectIndexed); |
| 5281 | SET_FIELD(action->type, LocationParameter, 0); |
| 5282 | break; |
| 5283 | |
| 5284 | case kLocation_IndirectIndexed: |
| 5285 | /* "Relative Address" -> "Normal" */ |
| 5286 | SET_FIELD(action->type, LocationType, kLocation_Standard); |
| 5287 | SET_FIELD(action->type, LocationParameter, 0); |
| 5288 | break; |
| 5289 | |
| 5290 | default: |
| 5291 | locationType++; |
| 5292 | SET_FIELD(action->type, LocationType, locationType); |
| 4302 | 5293 | } |
| 4303 | 5294 | } |
| 4304 | 5295 | break; |
| r2762 | r2763 | |
| 4306 | 5297 | case kType_CPU: |
| 4307 | 5298 | case kType_Region: |
| 4308 | 5299 | { |
| 4309 | | UINT32 locationParameter = EXTRACT_FIELD(action->type, LocationParameter); |
| 5300 | UINT32 locationParameter = EXTRACT_FIELD(action->type, LocationParameter); |
| 4310 | 5301 | |
| 4311 | 5302 | locationParameter = (locationParameter + 1) & 31; |
| 4312 | 5303 | |
| r2762 | r2763 | |
| 4316 | 5307 | |
| 4317 | 5308 | case kType_PackedCPU: |
| 4318 | 5309 | { |
| 4319 | | UINT32 locationParameter = EXTRACT_FIELD(action->type, LocationParameter); |
| 5310 | UINT32 locationParameter = EXTRACT_FIELD(action->type, LocationParameterCPU); |
| 4320 | 5311 | |
| 4321 | | locationParameter = ((locationParameter + 0x04) & 0x1C) | (locationParameter & 0x03); |
| 5312 | locationParameter = (locationParameter + 1) & 7; |
| 4322 | 5313 | |
| 4323 | | SET_FIELD(action->type, LocationParameter, locationParameter); |
| 5314 | SET_FIELD(action->type, LocationParameterCPU, locationParameter); |
| 4324 | 5315 | } |
| 4325 | 5316 | break; |
| 4326 | 5317 | |
| 4327 | 5318 | case kType_PackedSize: |
| 4328 | 5319 | { |
| 4329 | | UINT32 locationParameter = EXTRACT_FIELD(action->type, LocationParameter); |
| 5320 | UINT32 locationParameter = EXTRACT_FIELD(action->type, LocationParameterOption); |
| 4330 | 5321 | |
| 4331 | | locationParameter = ((locationParameter + 0x01) & 0x03) | (locationParameter & 0x1C); |
| 5322 | locationParameter = (locationParameter + 1) & 3; |
| 4332 | 5323 | |
| 4333 | | SET_FIELD(action->type, LocationParameter, locationParameter); |
| 5324 | SET_FIELD(action->type, LocationParameterOption, locationParameter); |
| 4334 | 5325 | } |
| 4335 | 5326 | break; |
| 4336 | 5327 | |
| 4337 | 5328 | case kType_Address: |
| 4338 | | action->address += increment; |
| 5329 | action->address += 1; |
| 4339 | 5330 | action->address &= info->extraData; |
| 4340 | 5331 | break; |
| 4341 | 5332 | |
| r2762 | r2763 | |
| 4344 | 5335 | break; |
| 4345 | 5336 | } |
| 4346 | 5337 | } |
| 4347 | | |
| 4348 | | if(UIPressedRepeatThrottle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate)) |
| 5338 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate)) |
| 4349 | 5339 | { |
| 4350 | | sel++; |
| 5340 | if(--sel < 0) |
| 5341 | sel = total - 1; |
| 4351 | 5342 | |
| 4352 | | if(sel >= total) |
| 4353 | | sel = 0; |
| 4354 | | |
| 4355 | 5343 | editActive = 0; |
| 4356 | 5344 | } |
| 4357 | | |
| 4358 | | if(UIPressedRepeatThrottle(machine, IPT_UI_UP, kVerticalKeyRepeatRate)) |
| 5345 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate)) |
| 4359 | 5346 | { |
| 4360 | | sel--; |
| 5347 | if(++sel >= total) |
| 5348 | sel = 0; |
| 4361 | 5349 | |
| 4362 | | if(sel < 0) |
| 4363 | | sel = total - 1; |
| 4364 | | |
| 4365 | 5350 | editActive = 0; |
| 4366 | 5351 | } |
| 4367 | | |
| 4368 | | if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate)) |
| 5352 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate)) |
| 4369 | 5353 | { |
| 4370 | 5354 | sel -= fullMenuPageHeight; |
| 4371 | 5355 | |
| r2762 | r2763 | |
| 4374 | 5358 | |
| 4375 | 5359 | editActive = 0; |
| 4376 | 5360 | } |
| 4377 | | |
| 4378 | | if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate)) |
| 5361 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate)) |
| 4379 | 5362 | { |
| 4380 | 5363 | sel += fullMenuPageHeight; |
| 4381 | 5364 | |
| r2762 | r2763 | |
| 4384 | 5367 | |
| 4385 | 5368 | editActive = 0; |
| 4386 | 5369 | } |
| 4387 | | |
| 4388 | | if(input_ui_pressed(machine, IPT_UI_SELECT)) |
| 5370 | else if(input_ui_pressed(machine, IPT_UI_SELECT)) |
| 4389 | 5371 | { |
| 4390 | 5372 | if(editActive) |
| 4391 | | { |
| 4392 | 5373 | editActive = 0; |
| 4393 | | } |
| 4394 | 5374 | else |
| 4395 | 5375 | { |
| 4396 | 5376 | switch(info->fieldType) |
| r2762 | r2763 | |
| 4409 | 5389 | case kType_SubtractMinimum: |
| 4410 | 5390 | case kType_RangeMinimum: |
| 4411 | 5391 | case kType_RangeMaximum: |
| 4412 | | case kType_WriteMatch: |
| 4413 | 5392 | case kType_Data: |
| 4414 | 5393 | case kType_Address: |
| 4415 | 5394 | osd_readkey_unicode(1); |
| r2762 | r2763 | |
| 4423 | 5402 | } |
| 4424 | 5403 | } |
| 4425 | 5404 | } |
| 5405 | else if(input_ui_pressed(machine, IPT_UI_CANCEL)) |
| 5406 | { |
| 5407 | if(editActive) |
| 5408 | editActive = 0; |
| 5409 | else |
| 5410 | sel = -1; |
| 5411 | } |
| 4426 | 5412 | |
| 4427 | 5413 | /********** EDIT MODE **********/ |
| 4428 | 5414 | if(editActive) |
| 4429 | 5415 | { |
| 4430 | | /* ----- do edit text ----- */ |
| 5416 | /* do edit text */ |
| 4431 | 5417 | dirty = 1; |
| 4432 | 5418 | |
| 4433 | 5419 | switch(info->fieldType) |
| r2762 | r2763 | |
| 4464 | 5450 | } |
| 4465 | 5451 | else |
| 4466 | 5452 | { |
| 4467 | | int code = input_code_poll_switches(FALSE); |
| 5453 | int code = input_code_poll_switches(FALSE); |
| 4468 | 5454 | |
| 4469 | 5455 | if(code == KEYCODE_ESC) |
| 4470 | 5456 | { |
| r2762 | r2763 | |
| 4505 | 5491 | |
| 4506 | 5492 | case kType_WatchSize: |
| 4507 | 5493 | { |
| 4508 | | UINT32 temp = (action->originalDataField >> 0) & 0xFF; |
| 5494 | UINT32 temp = (action->originalDataField >> 0) & 0xFF; |
| 4509 | 5495 | |
| 4510 | 5496 | temp++; |
| 4511 | | temp = DoEditHexField(machine, temp) & 0xFF; |
| 5497 | temp = do_edit_hex_field(machine, temp) & 0xFF; |
| 4512 | 5498 | temp--; |
| 4513 | 5499 | |
| 4514 | 5500 | action->originalDataField = (action->originalDataField & 0xFFFFFF00) | ((temp << 0) & 0x000000FF); |
| r2762 | r2763 | |
| 4518 | 5504 | |
| 4519 | 5505 | case kType_WatchSkip: |
| 4520 | 5506 | { |
| 4521 | | UINT32 temp = (action->originalDataField >> 8) & 0xFF; |
| 5507 | UINT32 temp = (action->originalDataField >> 8) & 0xFF; |
| 4522 | 5508 | |
| 4523 | | temp = DoEditHexField(machine, temp) & 0xFF; |
| 5509 | temp = do_edit_hex_field(machine, temp) & 0xFF; |
| 4524 | 5510 | |
| 4525 | 5511 | action->originalDataField = (action->originalDataField & 0xFFFF00FF) | ((temp << 8) & 0x0000FF00); |
| 4526 | 5512 | action->data = action->originalDataField; |
| r2762 | r2763 | |
| 4529 | 5515 | |
| 4530 | 5516 | case kType_WatchPerLine: |
| 4531 | 5517 | { |
| 4532 | | UINT32 temp = (action->originalDataField >> 16) & 0xFF; |
| 5518 | UINT32 temp = (action->originalDataField >> 16) & 0xFF; |
| 4533 | 5519 | |
| 4534 | | temp = DoEditHexField(machine, temp) & 0xFF; |
| 5520 | temp = do_edit_hex_field(machine, temp) & 0xFF; |
| 4535 | 5521 | |
| 4536 | 5522 | action->originalDataField = (action->originalDataField & 0xFF00FFFF) | ((temp << 16) & 0x00FF0000); |
| 4537 | 5523 | action->data = action->originalDataField; |
| r2762 | r2763 | |
| 4540 | 5526 | |
| 4541 | 5527 | case kType_WatchAddValue: |
| 4542 | 5528 | { |
| 4543 | | UINT32 temp = (action->originalDataField >> 24) & 0xFF; |
| 5529 | UINT32 temp = (action->originalDataField >> 24) & 0xFF; |
| 4544 | 5530 | |
| 4545 | 5531 | temp = DoEditHexFieldSigned(temp, 0xFFFFFF80) & 0xFF; |
| 4546 | 5532 | |
| r2762 | r2763 | |
| 4550 | 5536 | break; |
| 4551 | 5537 | |
| 4552 | 5538 | case kType_WriteMask: |
| 4553 | | action->extendData = DoEditHexField(machine, action->extendData); |
| 5539 | action->extendData = do_edit_hex_field(machine, action->extendData); |
| 4554 | 5540 | action->extendData &= info->extraData; |
| 4555 | 5541 | break; |
| 4556 | 5542 | |
| 4557 | 5543 | case kType_AddMaximum: |
| 4558 | 5544 | case kType_SubtractMinimum: |
| 4559 | | case kType_WriteMatch: |
| 4560 | | action->extendData = DoEditHexField(machine, action->extendData); |
| 5545 | action->extendData = do_edit_hex_field(machine, action->extendData); |
| 4561 | 5546 | break; |
| 4562 | 5547 | |
| 4563 | 5548 | case kType_RangeMinimum: |
| 4564 | 5549 | { |
| 4565 | | UINT32 temp; |
| 5550 | UINT32 temp; |
| 4566 | 5551 | |
| 4567 | 5552 | if(!TEST_FIELD(action->type, BytesUsed)) |
| 4568 | 5553 | { |
| 4569 | 5554 | temp = (action->extendData >> 8) & 0xFF; |
| 4570 | | temp = DoEditHexField(machine, temp) & 0xFF; |
| 5555 | temp = do_edit_hex_field(machine, temp) & 0xFF; |
| 4571 | 5556 | |
| 4572 | 5557 | action->extendData = (action->extendData & 0xFF) | ((temp << 8) & 0xFF00); |
| 4573 | 5558 | } |
| 4574 | 5559 | else |
| 4575 | 5560 | { |
| 4576 | 5561 | temp = (action->extendData >> 16) & 0xFFFF; |
| 4577 | | temp = DoEditHexField(machine, temp) & 0xFFFF; |
| 5562 | temp = do_edit_hex_field(machine, temp) & 0xFFFF; |
| 4578 | 5563 | |
| 4579 | 5564 | action->extendData = (action->extendData & 0x0000FFFF) | ((temp << 16) & 0xFFFF0000); |
| 4580 | 5565 | } |
| r2762 | r2763 | |
| 4583 | 5568 | |
| 4584 | 5569 | case kType_RangeMaximum: |
| 4585 | 5570 | { |
| 4586 | | UINT32 temp; |
| 5571 | UINT32 temp; |
| 4587 | 5572 | |
| 4588 | 5573 | if(!TEST_FIELD(action->type, BytesUsed)) |
| 4589 | 5574 | { |
| 4590 | 5575 | temp = action->extendData & 0xFF; |
| 4591 | | temp = DoEditHexField(machine, temp) & 0xFF; |
| 5576 | temp = do_edit_hex_field(machine, temp) & 0xFF; |
| 4592 | 5577 | |
| 4593 | 5578 | action->extendData = (action->extendData & 0xFF00) | (temp & 0x00FF); |
| 4594 | 5579 | } |
| 4595 | 5580 | else |
| 4596 | 5581 | { |
| 4597 | 5582 | temp = action->extendData & 0xFFFF; |
| 4598 | | temp = DoEditHexField(machine, temp) & 0xFFFF; |
| 5583 | temp = do_edit_hex_field(machine, temp) & 0xFFFF; |
| 4599 | 5584 | |
| 4600 | 5585 | action->extendData = (action->extendData & 0xFFFF0000) | (temp & 0x0000FFFF); |
| 4601 | 5586 | } |
| r2762 | r2763 | |
| 4603 | 5588 | break; |
| 4604 | 5589 | |
| 4605 | 5590 | case kType_Data: |
| 4606 | | action->originalDataField = DoEditHexField(machine, action->originalDataField); |
| 5591 | action->originalDataField = do_edit_hex_field(machine, action->originalDataField); |
| 4607 | 5592 | action->originalDataField &= info->extraData; |
| 4608 | 5593 | action->data = action->originalDataField; |
| 4609 | 5594 | break; |
| 4610 | 5595 | |
| 4611 | 5596 | case kType_Address: |
| 4612 | | action->address = DoEditHexField(machine, action->address); |
| 5597 | action->address = do_edit_hex_field(machine, action->address); |
| 4613 | 5598 | action->address &= info->extraData; |
| 4614 | 5599 | break; |
| 4615 | 5600 | } |
| 4616 | | |
| 4617 | | if(input_ui_pressed(machine, IPT_UI_CANCEL)) |
| 4618 | | editActive = 0; |
| 4619 | 5601 | } |
| 4620 | 5602 | else |
| 4621 | 5603 | { |
| 4622 | 5604 | if(input_ui_pressed(machine, IPT_UI_SAVE_CHEAT)) |
| 4623 | 5605 | { |
| 4624 | | if(ControlKeyPressed()) |
| 4625 | | if((entry->flags & kCheatFlag_HasActivationKey1) || (entry->flags & kCheatFlag_HasActivationKey2)) |
| 4626 | | { |
| 4627 | | SaveCheat(machine, entry, index, 1); // save activation key |
| 4628 | | |
| 4629 | | ui_popup_time(1, "activation key saved"); |
| 4630 | | } |
| 4631 | | else |
| 4632 | | ui_popup_time(1, "no activation key"); |
| 4633 | | else |
| 4634 | | SaveCheat(machine, entry, 0, 0); // save current entry |
| 5606 | SaveCheatCode(machine, entry); |
| 4635 | 5607 | } |
| 4636 | | |
| 4637 | | if(input_ui_pressed(machine, IPT_UI_WATCH_VALUE)) |
| 5608 | else if(input_ui_pressed(machine, IPT_UI_WATCH_VALUE)) |
| 5609 | { |
| 4638 | 5610 | WatchCheatEntry(entry, 0); |
| 5611 | } |
| 5612 | else if(input_ui_pressed(machine, IPT_UI_ADD_CHEAT)) |
| 5613 | { |
| 5614 | AddActionBefore(entry, info->sub_cheat); |
| 4639 | 5615 | |
| 4640 | | if(input_ui_pressed(machine, IPT_UI_ADD_CHEAT)) |
| 4641 | | AddActionBefore(entry, info->subcheat); |
| 5616 | entry->actionList[info->sub_cheat].extendData = ~0; |
| 4642 | 5617 | |
| 4643 | | if(input_ui_pressed(machine, IPT_UI_DELETE_CHEAT)) |
| 4644 | | { |
| 4645 | | if(!info->subcheat) |
| 5618 | for(i = 0; i < entry->actionListLength; i++) |
| 4646 | 5619 | { |
| 4647 | | /* ----- if selected entry is master, delete current entry then return to previous menu ----- */ |
| 4648 | | DeleteCheatAt(index); |
| 5620 | CheatAction * action = &entry->actionList[i]; |
| 4649 | 5621 | |
| 4650 | | return 0; |
| 5622 | if(i) |
| 5623 | SET_MASK_FIELD(action->type, LinkEnable); |
| 5624 | else |
| 5625 | CLEAR_MASK_FIELD(action->type, LinkEnable); |
| 4651 | 5626 | } |
| 5627 | } |
| 5628 | else if(input_ui_pressed(machine, IPT_UI_DELETE_CHEAT)) |
| 5629 | { |
| 5630 | if(!info->sub_cheat) |
| 5631 | { |
| 5632 | /* don't delete MASTER Action due to crash */ |
| 5633 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 5634 | messageType = kCheatMessage_FailedToDelete; |
| 5635 | } |
| 4652 | 5636 | else |
| 4653 | | DeleteActionAt(entry, info->subcheat); |
| 5637 | DeleteActionAt(entry, info->sub_cheat); |
| 4654 | 5638 | } |
| 4655 | 5639 | } |
| 4656 | 5640 | |
| 4657 | | if(input_ui_pressed(machine, IPT_UI_CANCEL)) |
| 5641 | if(dirty) |
| 4658 | 5642 | { |
| 4659 | | sel = -1; |
| 4660 | | editActive = 0; |
| 5643 | UpdateCheatInfo(entry, 0); |
| 5644 | |
| 5645 | entry->flags |= kCheatFlag_Dirty; |
| 4661 | 5646 | } |
| 4662 | 5647 | |
| 4663 | 5648 | if(sel == -1) |
| 4664 | 5649 | { |
| 5650 | /* NOTE : building label index table should be done when exit the edit menu */ |
| 5651 | if(entry->flags & kCheatFlag_Select) |
| 5652 | BuildLabelIndexTable(entry); |
| 5653 | |
| 5654 | CheckCodeFormat(entry); |
| 5655 | |
| 4665 | 5656 | editActive = 0; |
| 4666 | 5657 | dirty = 1; |
| 4667 | 5658 | } |
| 4668 | 5659 | |
| 4669 | | if(dirty) |
| 4670 | | { |
| 4671 | | UpdateCheatInfo(entry, 0); |
| 5660 | /* free astrings used by displaying the name of activation key */ |
| 5661 | astring_free(tempString1); |
| 5662 | astring_free(tempString2); |
| 5663 | #endif |
| 5664 | return menu->sel; |
| 5665 | } |
| 4672 | 5666 | |
| 4673 | | entry->flags |= kCheatFlag_Dirty; |
| 4674 | | } |
| 5667 | /*-------------------------------------------------------------- |
| 5668 | view_cheat_menu - management for code viewer for new format |
| 5669 | --------------------------------------------------------------*/ |
| 4675 | 5670 | |
| 4676 | | astring_free(temp_string_1); |
| 4677 | | astring_free(temp_string_2); |
| 5671 | static int view_cheat_menu(running_machine *machine, cheat_menu_stack *menu) |
| 5672 | { |
| 5673 | static const char *const kAddressSpaceNames[] = { |
| 5674 | "Program", "Data Space", "I/O Space", "Opcode RAM", "Mapped Memory", "Direct Memory", "EEPROM" }; |
| 4678 | 5675 | |
| 4679 | | return sel + 1; |
| 4680 | | } |
| 5676 | static const char *const kCodeTypeNames[] = { |
| 5677 | "Write", "PDWWrite", "RWrite", "IWrite", "CWrite", "VWrite", "VRWrite", "Move", "Branch", "Loop", |
| 5678 | "Unused 1", "Unused 2", "Unused 3", "Unused 4", |
| 5679 | "Popup", "Watch" }; |
| 4681 | 5680 | |
| 4682 | | /*----------------------------------------------------------- |
| 4683 | | DoSearchMenuMinimum - management for minimum search menu |
| 4684 | | -----------------------------------------------------------*/ |
| 5681 | static const char *const kCustomCodeTypeNames[] = { |
| 5682 | "No Action", "Comment", "Separator", "Label Select", "Layer", |
| 5683 | "Unused 1", "Unused2", "Unused 3", |
| 5684 | /* NOTE : the following command codes should be removed when database is loaded */ |
| 5685 | "Activation Key 1", "Activation Key 2", "Pre-enable", "Overclock", "Refresh Rate" }; |
| 4685 | 5686 | |
| 4686 | | static int DoSearchMenuMinimum(running_machine *machine, int selection) |
| 4687 | | { |
| 4688 | | /* main */ |
| 4689 | | enum |
| 5687 | static const char *const kConditionNames[] = { |
| 5688 | "EQ", "NE", "LS", "LSEQ", "GR", "GREQ", "BSET", "BCLR", |
| 5689 | "Unused 1", "Unused 2", "Unused 3", "Unused 4", |
| 5690 | "PVAL", "KEY", "KEYR", "TRUE" }; |
| 5691 | |
| 5692 | static const char *const kDataNames[] = { |
| 5693 | "Data", "1st Data", "Data", "Data", "Data", "Max Data", "Max Data", "Add Value", "Comparison", "Count", |
| 5694 | "-----", "-----", "-----", "-----", |
| 5695 | "Comparison", "-----" }; |
| 5696 | |
| 5697 | static const char *const kPopupOptionNames[] = { |
| 5698 | "Label", "Value", "Label + Value", "Value + Label" }; |
| 5699 | |
| 5700 | enum{ |
| 5701 | kViewMenu_Header = 1, // format : total index / current index |
| 5702 | kViewMenu_CodeLayer, // internal value of code and layer index |
| 5703 | kViewMenu_Name, // master code = entry->name, linked code = action->optionalName |
| 5704 | kViewMenu_Comment, |
| 5705 | kViewMenu_ActivationKey1, |
| 5706 | kViewMenu_ActivationKey2, |
| 5707 | // if(!CustomCode) |
| 5708 | kViewMenu_CodeType, // CodeType - CodeParameter / Return |
| 5709 | kViewMenu_CPURegion, // add Address Space if CPU region |
| 5710 | kViewMenu_Address, |
| 5711 | kViewMenu_Size, // address size / index size |
| 5712 | kViewMenu_Data, |
| 5713 | kViewMenu_Extend, |
| 5714 | // if(ValueSelect) |
| 5715 | kViewMenu_ValueSelectOptions, |
| 5716 | // if(Popup) |
| 5717 | kViewMenu_PopupOptions, |
| 5718 | // if(CopyLink) |
| 5719 | kViewMenu_CopyLinkOptions, |
| 5720 | kViewMenu_Options, // One-shot, Delay, Prefill, RestoreValue |
| 5721 | // if(CustomCode) |
| 5722 | //if(LayerIndex) |
| 5723 | kViewMenu_LayerDisplayLevel, |
| 5724 | kViewMenu_LayerSetLevel, |
| 5725 | kViewMenu_LayerSetLength, |
| 5726 | kViewMenu_Return, |
| 5727 | kViewMenu_Max }; |
| 5728 | |
| 5729 | int total = 0; |
| 5730 | int menu_index[kViewMenu_Max] = { 0 }; |
| 5731 | static int page_index = 0; |
| 5732 | UINT8 address_length = 0; |
| 5733 | UINT8 address_size = 0; |
| 5734 | const char ** menu_item; |
| 5735 | const char ** menu_sub_item; |
| 5736 | char * flag_buf; |
| 5737 | char * header; |
| 5738 | char * buf_code; |
| 5739 | char * buf_type; |
| 5740 | char * buf_cpu; |
| 5741 | char * buf_address; |
| 5742 | char * buf_size; |
| 5743 | char * buf_data; |
| 5744 | char * buf_extend; |
| 5745 | char * buf_options; |
| 5746 | char * buf_code_type_options; |
| 5747 | CheatEntry * entry = &cheatList[menu->pre_sel]; |
| 5748 | CheatAction * action = NULL; |
| 5749 | astring * activation_key_string1 = NULL; |
| 5750 | astring * activation_key_string2 = NULL; |
| 5751 | |
| 5752 | /* first setting : forced set page as 0 when first open */ |
| 5753 | if(menu->first_time) |
| 4690 | 5754 | { |
| 4691 | | kMenu_CPU = 0, |
| 4692 | | kMenu_SearchItem, |
| 5755 | page_index = 0; |
| 5756 | menu->first_time = 0; |
| 5757 | } |
| 4693 | 5758 | |
| 4694 | | kMenu_Divider, |
| 5759 | action = &entry->actionList[page_index]; |
| 5760 | address_length = get_address_length(action->region); |
| 5761 | address_size = EXTRACT_FIELD(action->type, AddressSize); |
| 4695 | 5762 | |
| 4696 | | kMenu_Memory, |
| 4697 | | kMenu_ViewResult, |
| 4698 | | kMenu_RestoreSearch, |
| 5763 | /* required items = (total items + return + terminator) & (strings buf * 10) */ |
| 5764 | request_strings(kViewMenu_Max + 2, 0x0A, 32, 0); |
| 5765 | menu_item = menu_strings.main_list; |
| 5766 | menu_sub_item = menu_strings.sub_list; |
| 5767 | flag_buf = menu_strings.flag_list; |
| 5768 | header = menu_strings.main_strings[0]; |
| 5769 | buf_code = menu_strings.main_strings[1]; |
| 5770 | buf_type = menu_strings.main_strings[2]; |
| 5771 | buf_cpu = menu_strings.main_strings[3]; |
| 5772 | buf_address = menu_strings.main_strings[4]; |
| 5773 | buf_size = menu_strings.main_strings[5]; |
| 5774 | buf_data = menu_strings.main_strings[6]; |
| 5775 | buf_extend = menu_strings.main_strings[7]; |
| 5776 | buf_options = menu_strings.main_strings[8]; |
| 5777 | buf_code_type_options = menu_strings.main_strings[9]; |
| 4699 | 5778 | |
| 4700 | | kMenu_Return, |
| 4701 | | }; |
| 5779 | memset(flag_buf, 0, kViewMenu_Max + 2); |
| 4702 | 5780 | |
| 4703 | | /* search item */ |
| 4704 | | enum |
| 5781 | /********** MENU CONSTRUCTION **********/ |
| 5782 | /* ##### HEADER ##### */ |
| 5783 | sprintf(header, "[%2.2d/%2.2d]", page_index + 1, entry->actionListLength); |
| 5784 | ADD_MENU_3_ITEMS("Page", header, kViewMenu_Header); |
| 5785 | |
| 5786 | /* ##### CODE / LAYER INDEX ##### */ |
| 5787 | sprintf(buf_code, "%8.8X / %2.2X", action->type, entry->layerIndex); |
| 5788 | ADD_MENU_3_ITEMS("Code / Layer", buf_code, kViewMenu_CodeLayer); |
| 5789 | |
| 5790 | /* ##### NAME ##### */ |
| 5791 | if(entry->name) |
| 4705 | 5792 | { |
| 4706 | | kItem_Value, |
| 4707 | | kItem_Timer, |
| 4708 | | kItem_Equal, |
| 4709 | | kItem_NotEqual, |
| 4710 | | kItem_Less, |
| 4711 | | kItem_Greater, |
| 5793 | if(page_index) |
| 5794 | ADD_MENU_3_ITEMS("Name", action->optionalName, kViewMenu_Name); |
| 5795 | else |
| 5796 | ADD_MENU_3_ITEMS("Name", entry->name, kViewMenu_Name); |
| 5797 | } |
| 5798 | else |
| 5799 | ADD_MENU_3_ITEMS("Name", "< none >", kViewMenu_Name); |
| 4712 | 5800 | |
| 4713 | | kItem_Max = kItem_Greater, |
| 4714 | | }; |
| 5801 | /* ##### COMMENT ##### */ |
| 5802 | if(page_index == 0 && entry->comment) |
| 5803 | ADD_MENU_3_ITEMS("Comment", entry->comment, kViewMenu_Comment); |
| 4715 | 5804 | |
| 4716 | | const char * menuItem[kMenu_Return + 2] = { 0 }; |
| 4717 | | const char * menuSubItem[kMenu_Return + 2] = { 0 }; |
| 5805 | /* ##### ACTIVATION KEY ##### */ |
| 5806 | if(entry->flags & kCheatFlag_Select) |
| 5807 | { |
| 5808 | if(entry->flags & kCheatFlag_HasActivationKey1) |
| 5809 | { |
| 5810 | activation_key_string1 = astring_alloc(); |
| 5811 | ADD_MENU_3_ITEMS("Activation Key", astring_c(input_code_name(activation_key_string1, entry->activationKey1)), kViewMenu_ActivationKey1); |
| 5812 | } |
| 5813 | } |
| 5814 | else |
| 5815 | { |
| 5816 | if(entry->flags & kCheatFlag_HasActivationKey1) |
| 5817 | { |
| 5818 | activation_key_string1 = astring_alloc(); |
| 5819 | ADD_MENU_3_ITEMS("Activation Key - Prev", astring_c(input_code_name(activation_key_string1, entry->activationKey1)), kViewMenu_ActivationKey1); |
| 5820 | } |
| 4718 | 5821 | |
| 4719 | | char valueBuffer[60]; |
| 4720 | | char valueSignedBuffer[60]; |
| 4721 | | char cpuBuffer[20]; |
| 4722 | | char flagBuf[kMenu_Return + 2] = { 0 }; |
| 5822 | if(entry->flags & kCheatFlag_HasActivationKey2) |
| 5823 | { |
| 5824 | activation_key_string2 = astring_alloc(); |
| 5825 | ADD_MENU_3_ITEMS("Activation Key - Next", astring_c(input_code_name(activation_key_string2, entry->activationKey2)), kViewMenu_ActivationKey2); |
| 5826 | } |
| 5827 | } |
| 4723 | 5828 | |
| 4724 | | SearchInfo * search = GetCurrentSearch(); |
| 5829 | /* ##### CODE TYPE ##### */ |
| 5830 | if(action->flags & kActionFlag_Custom) |
| 5831 | { |
| 5832 | ADD_MENU_3_ITEMS("Custom Type", kCustomCodeTypeNames[EXTRACT_FIELD(action->type, CodeType)], kViewMenu_CodeType); |
| 5833 | } |
| 5834 | else |
| 5835 | { |
| 5836 | char * type_strings = buf_type; |
| 4725 | 5837 | |
| 4726 | | INT32 sel = selection - 1; |
| 4727 | | INT32 total = 0; |
| 4728 | | UINT8 doSearch = 0; |
| 5838 | type_strings += sprintf(type_strings, "%s", kCodeTypeNames[EXTRACT_FIELD(action->type, CodeType)]); |
| 4729 | 5839 | |
| 4730 | | static INT8 searchItem = 0; |
| 4731 | | static INT8 submenuChoice = 0; |
| 4732 | | static UINT8 doneSaveMemory = 0; |
| 4733 | | static UINT8 firstEntry = 0; |
| 4734 | | static UINT8 editActive = 0; |
| 4735 | | static UINT8 posnKeep = kMenu_SearchItem; |
| 4736 | | static UINT32 increment = 1; |
| 5840 | if(action->flags & kActionFlag_CheckCondition) |
| 5841 | type_strings += sprintf(type_strings, "-%s", kConditionNames[EXTRACT_FIELD(action->type, CodeParameter)]); |
| 4737 | 5842 | |
| 4738 | | /********** SUB MENU **********/ |
| 4739 | | if(submenuChoice) |
| 5843 | if(TEST_FIELD(action->type, Return)) |
| 5844 | type_strings += sprintf(type_strings, "/Ret"); |
| 5845 | |
| 5846 | ADD_MENU_3_ITEMS("Type", buf_type, kViewMenu_CodeType); |
| 5847 | } |
| 5848 | |
| 5849 | if((action->flags & kActionFlag_Custom) == 0) |
| 4740 | 5850 | { |
| 4741 | | switch(sel) |
| 5851 | /* ##### CPU/REGION ##### */ |
| 5852 | if(TEST_FIELD(action->region, RegionFlag)) |
| 4742 | 5853 | { |
| 4743 | | case kMenu_CPU: |
| 4744 | | submenuChoice = SelectSearchRegions(machine, submenuChoice, GetCurrentSearch()); |
| 5854 | ADD_MENU_3_ITEMS("Region", kRegionNames[EXTRACT_FIELD(action->region, RegionIndex)], kViewMenu_CPURegion); |
| 5855 | } |
| 5856 | else |
| 5857 | { |
| 5858 | sprintf(buf_cpu, "%s (%s)", kRegionNames[EXTRACT_FIELD(action->region, CPUIndex) + 1], kAddressSpaceNames[EXTRACT_FIELD(action->region, AddressSpace)]); |
| 5859 | ADD_MENU_3_ITEMS("CPU", buf_cpu, kViewMenu_CPURegion); |
| 5860 | } |
| 5861 | |
| 5862 | /* ##### ADDRESS ##### */ |
| 5863 | switch(EXTRACT_FIELD(action->type, AddressRead)) |
| 5864 | { |
| 5865 | case kReadFrom_Address: |
| 5866 | sprintf(buf_address, "%*.*X", address_length, address_length, action->originalAddress); |
| 4745 | 5867 | break; |
| 4746 | 5868 | |
| 4747 | | case kMenu_ViewResult: |
| 4748 | | submenuChoice = ViewSearchResults(machine, submenuChoice, firstEntry); |
| 5869 | case kReadFrom_Index: |
| 5870 | sprintf(buf_address, "(V%s)", kNumbersTable[action->originalAddress]); |
| 4749 | 5871 | break; |
| 5872 | |
| 5873 | case kReadFrom_Variable: |
| 5874 | sprintf(buf_address, "V%s", kNumbersTable[action->originalAddress]); |
| 4750 | 5875 | } |
| 4751 | 5876 | |
| 4752 | | firstEntry = 0; |
| 5877 | ADD_MENU_3_ITEMS("Address", buf_address, kViewMenu_Address); |
| 4753 | 5878 | |
| 4754 | | posnKeep = sel; |
| 5879 | /* ##### SIZE ##### */ |
| 5880 | if(action->flags & kActionFlag_PDWWrite) |
| 5881 | { |
| 5882 | sprintf(buf_size, "%s / %s", kByteSizeStringList[address_size], kByteSizeStringList[EXTRACT_FIELD(action->type, IndexSize)]); |
| 5883 | ADD_MENU_3_ITEMS("Size 1st / 2nd", buf_size, kViewMenu_Size); |
| 5884 | } |
| 5885 | else if(action->flags & kActionFlag_IndexAddress) |
| 5886 | { |
| 5887 | if(action->extendData != ~0) |
| 5888 | { |
| 5889 | sprintf(buf_size, "%s / %s", kByteSizeStringList[address_size], kByteSizeStringList[EXTRACT_FIELD(action->type, IndexSize)]); |
| 5890 | } |
| 5891 | else |
| 5892 | sprintf(buf_size, "%s / < None >", kByteSizeStringList[address_size]); |
| 4755 | 5893 | |
| 4756 | | /* ----- meaningless ? because no longer return with sel = -1 (pressed UI_CONFIG in submenu) ----- */ |
| 4757 | | // if(submenuChoice == -1) |
| 4758 | | // submenuChoice = 0; |
| 5894 | ADD_MENU_3_ITEMS("Size Adr / Idx", buf_size, kViewMenu_Size); |
| 5895 | } |
| 5896 | else |
| 5897 | { |
| 5898 | sprintf(buf_size, "%s", kByteSizeStringList[address_size]); |
| 5899 | ADD_MENU_3_ITEMS("Size", buf_size, kViewMenu_Size); |
| 5900 | } |
| 4759 | 5901 | |
| 4760 | | return sel + 1; |
| 5902 | /* ##### DATA ##### */ |
| 5903 | if(EXTRACT_FIELD(action->type, CodeType) != kCodeType_Watch) |
| 5904 | { |
| 5905 | if(TEST_FIELD(action->type, DataRead)) |
| 5906 | { |
| 5907 | sprintf(buf_data, "V%s", kNumbersTable[action->originalDataField]); |
| 5908 | } |
| 5909 | else |
| 5910 | { |
| 5911 | sprintf(buf_data, "%*.*X", kCheatSizeDigitsTable[address_size], kCheatSizeDigitsTable[address_size], action->originalDataField); |
| 5912 | } |
| 5913 | |
| 5914 | if(EXTRACT_FIELD(action->type, Link) != kLink_CopyLink) |
| 5915 | ADD_MENU_3_ITEMS(kDataNames[EXTRACT_FIELD(action->type, CodeType)], buf_data, kViewMenu_Data); |
| 5916 | else |
| 5917 | ADD_MENU_3_ITEMS("Add Value", buf_data, kViewMenu_Data); |
| 5918 | } |
| 5919 | |
| 5920 | /* ##### EXTEND DATA ##### */ |
| 5921 | if(action->flags & kActionFlag_IndexAddress) |
| 5922 | { |
| 5923 | if(action->extendData != ~0) |
| 5924 | sprintf(buf_extend, "%*.8X", address_length, action->extendData); |
| 5925 | else |
| 5926 | sprintf(buf_extend, "< none >"); |
| 5927 | |
| 5928 | ADD_MENU_3_ITEMS("Index", buf_extend, kViewMenu_Extend); |
| 5929 | } |
| 5930 | else if(action->flags & kActionFlag_PDWWrite) |
| 5931 | { |
| 5932 | sprintf(buf_extend, "%*.*X", |
| 5933 | kCheatSizeDigitsTable[EXTRACT_FIELD(action->type, IndexSize)], |
| 5934 | kCheatSizeDigitsTable[EXTRACT_FIELD(action->type, IndexSize)], |
| 5935 | action->extendData); |
| 5936 | ADD_MENU_3_ITEMS("2nd Data", buf_extend, kViewMenu_Extend); |
| 5937 | } |
| 5938 | else if(action->flags & kActionFlag_Repeat) |
| 5939 | { |
| 5940 | sprintf(buf_extend, "%4.4X / %4.4X", |
| 5941 | EXTRACT_FIELD(action->extendData, LSB16), |
| 5942 | EXTRACT_FIELD(action->extendData, MSB16)); |
| 5943 | ADD_MENU_3_ITEMS("Count / Skip", buf_extend, kViewMenu_Extend); |
| 5944 | } |
| 5945 | else |
| 5946 | { |
| 5947 | switch(EXTRACT_FIELD(action->type, CodeType)) |
| 5948 | { |
| 5949 | case kCodeType_Write: |
| 5950 | case kCodeType_IWrite: |
| 5951 | case kCodeType_VWrite: |
| 5952 | sprintf(buf_extend, "%*.*X", address_size, address_size, action->extendData); |
| 5953 | ADD_MENU_3_ITEMS("Mask", buf_extend, kViewMenu_Extend); |
| 5954 | break; |
| 5955 | |
| 5956 | case kCodeType_CWrite: |
| 5957 | sprintf(buf_extend, "%*.*X", address_size, address_size, action->extendData); |
| 5958 | ADD_MENU_3_ITEMS("Comparison", buf_extend, kViewMenu_Extend); |
| 5959 | break; |
| 5960 | |
| 5961 | case kCodeType_Branch: |
| 5962 | sprintf(buf_extend, "%2.2d", action->extendData + 1); |
| 5963 | ADD_MENU_3_ITEMS("Jump Index", buf_extend, kViewMenu_Extend); |
| 5964 | break; |
| 5965 | |
| 5966 | default: |
| 5967 | ADD_MENU_3_ITEMS("UNKNOWN", "?????", kViewMenu_Extend); |
| 5968 | } |
| 5969 | } |
| 5970 | |
| 5971 | /* ##### OPTIONS ##### */ |
| 5972 | sprintf(buf_options, "%s %s %s %s", |
| 5973 | TEST_FIELD(action->type, OneShot) ? "O" : "-", |
| 5974 | TEST_FIELD(action->type, DelayEnable) ? "D" : "-", |
| 5975 | TEST_FIELD(action->type, PrefillEnable) ? "P" : "-", |
| 5976 | TEST_FIELD(action->type, RestoreValue) ? "R" : "-"); |
| 5977 | ADD_MENU_3_ITEMS("Options", buf_options, kViewMenu_Options); |
| 5978 | |
| 5979 | /* ##### CODE TYPE OPTIONS ##### */ |
| 5980 | if( EXTRACT_FIELD(action->type, CodeType) == kCodeType_VWrite || |
| 5981 | EXTRACT_FIELD(action->type, CodeType) == kCodeType_VRWrite) |
| 5982 | { |
| 5983 | sprintf(buf_code_type_options, "%s %s %s %s", |
| 5984 | TEST_FIELD(action->type, ValueSelectMinimumDisplay) ? "D" : "-", |
| 5985 | TEST_FIELD(action->type, ValueSelectMinimum) ? "M" : "-", |
| 5986 | TEST_FIELD(action->type, ValueSelectBCD) ? "B" : "-", |
| 5987 | TEST_FIELD(action->type, ValueSelectNegative) ? "N" : "-"); |
| 5988 | ADD_MENU_3_ITEMS("Value Select Options", buf_code_type_options, kViewMenu_ValueSelectOptions); |
| 5989 | } |
| 5990 | else if(EXTRACT_FIELD(action->type, CodeType) == kCodeType_Popup) |
| 5991 | { |
| 5992 | ADD_MENU_3_ITEMS("Popup Options", kPopupOptionNames[EXTRACT_FIELD(action->type, PopupParameter)], kViewMenu_PopupOptions); |
| 5993 | } |
| 5994 | else if(EXTRACT_FIELD(action->type, Link) == kLink_CopyLink) |
| 5995 | { |
| 5996 | sprintf(buf_code_type_options, "%s %s", |
| 5997 | TEST_FIELD(action->type, LinkValueSelectBCD) ? "B" : "-", |
| 5998 | TEST_FIELD(action->type, LinkValueSelectNegative) ? "N" : "-"); |
| 5999 | ADD_MENU_3_ITEMS("Copy Link Options", buf_code_type_options, kViewMenu_CopyLinkOptions); |
| 6000 | } |
| 4761 | 6001 | } |
| 6002 | else |
| 6003 | { |
| 6004 | if(EXTRACT_FIELD(action->type, CodeType) == kCustomCode_Layer) |
| 6005 | { |
| 6006 | /* ##### LAYER ##### */ |
| 6007 | sprintf(buf_address, "%2.2X", action->originalAddress); |
| 6008 | ADD_MENU_3_ITEMS("Display Level", buf_address, kViewMenu_LayerDisplayLevel); |
| 4762 | 6009 | |
| 4763 | | sel = posnKeep; |
| 6010 | sprintf(buf_data, "%2.2X", action->originalDataField); |
| 6011 | ADD_MENU_3_ITEMS("Set Level", buf_data, kViewMenu_LayerSetLevel); |
| 4764 | 6012 | |
| 4765 | | /* ----- unselectable comparison search item if no save ----- */ |
| 4766 | | if(!doneSaveMemory) |
| 4767 | | searchItem = kItem_Value; |
| 6013 | sprintf(buf_extend, "%2.2X", action->extendData); |
| 6014 | ADD_MENU_3_ITEMS("Set Length", buf_extend, kViewMenu_LayerSetLength); |
| 6015 | } |
| 6016 | } |
| 4768 | 6017 | |
| 6018 | /* ##### RETURN ##### */ |
| 6019 | ADD_MENU_3_ITEMS("Return to Prior Menu", NULL, kViewMenu_Return); |
| 6020 | |
| 6021 | /* ##### TERMINATE ARRAY ##### */ |
| 6022 | TERMINATE_MENU_2_ITEMS; |
| 6023 | |
| 6024 | /* adjust current cursor position */ |
| 6025 | ADJUST_CURSOR(menu->sel, total) |
| 6026 | |
| 6027 | /* draw it */ |
| 6028 | old_style_menu(menu_item, menu_sub_item, flag_buf, menu->sel, 0); |
| 6029 | |
| 6030 | /********** KEY HANDLING **********/ |
| 6031 | if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate)) |
| 6032 | { |
| 6033 | CURSOR_TO_PREVIOUS(menu->sel, total) |
| 6034 | } |
| 6035 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate)) |
| 6036 | { |
| 6037 | CURSOR_TO_NEXT(menu->sel, total) |
| 6038 | } |
| 6039 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_LEFT, kHorizontalSlowKeyRepeatRate)) |
| 6040 | { |
| 6041 | if(--page_index < 0) |
| 6042 | page_index = entry->actionListLength - 1; |
| 6043 | } |
| 6044 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_RIGHT, kHorizontalSlowKeyRepeatRate)) |
| 6045 | { |
| 6046 | if(++page_index > entry->actionListLength - 1) |
| 6047 | page_index = 0; |
| 6048 | } |
| 6049 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate)) |
| 6050 | { |
| 6051 | CURSOR_PAGE_UP(menu->sel) |
| 6052 | } |
| 6053 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate)) |
| 6054 | { |
| 6055 | CURSOR_PAGE_DOWN(menu->sel, total) |
| 6056 | } |
| 6057 | else if(input_ui_pressed(machine, IPT_UI_SELECT) || input_ui_pressed(machine, IPT_UI_CANCEL)) |
| 6058 | { |
| 6059 | menu->sel = -1; |
| 6060 | } |
| 6061 | else if(input_ui_pressed(machine, IPT_UI_SAVE_CHEAT)) |
| 6062 | { |
| 6063 | SaveCheatCode(machine, entry); |
| 6064 | } |
| 6065 | |
| 6066 | if(activation_key_string1) |
| 6067 | astring_free(activation_key_string1); |
| 6068 | if(activation_key_string2) |
| 6069 | astring_free(activation_key_string2); |
| 6070 | |
| 6071 | return menu->sel + 1; |
| 6072 | } |
| 6073 | |
| 6074 | /*--------------------------------------------------------- |
| 6075 | analyse_cheat_menu - management for code analizer menu |
| 6076 | ---------------------------------------------------------*/ |
| 6077 | |
| 6078 | static int analyse_cheat_menu(running_machine *machine, cheat_menu_stack *menu) |
| 6079 | { |
| 6080 | static const char *const kAnalyseItemName[] = { |
| 6081 | "Invalid Location Type", |
| 6082 | "Invalid Operation", |
| 6083 | "Invalid Code Type", |
| 6084 | "Invalid Condition", |
| 6085 | "Invalid Code Option", |
| 6086 | "Relative Address conflicts other operations", |
| 6087 | "Maximum range is smaller than minimum", |
| 6088 | "Missing Restore Previous Value flag", |
| 6089 | "Missing label link code", |
| 6090 | "Both Value and Label Select are defined", |
| 6091 | "Copy Link is defined though no value-select code", |
| 6092 | "Invalid Data Field", |
| 6093 | "Invalid Extend Data Field", |
| 6094 | "Don't set Variable in this type", |
| 6095 | "Value Select can't select any value", |
| 6096 | "RWrite doesn't have counter", |
| 6097 | "Invalid Address Read", |
| 6098 | "Invalid Variable in address field", |
| 6099 | "Invalid Variable in extend data field", |
| 6100 | "CPU/Region is out of range", |
| 6101 | "Invalid CPU/Region number", |
| 6102 | "Invalid Address Space", |
| 6103 | "An address is out of range", |
| 6104 | "Invalid Custom Code" }; |
| 6105 | |
| 6106 | int i, j; |
| 6107 | int total = 0; |
| 6108 | UINT8 isEdit = 0; |
| 6109 | const char ** menuItem; |
| 6110 | CheatEntry * entry = &cheatList[menu->pre_sel]; |
| 6111 | |
| 6112 | /* first setting : NONE */ |
| 6113 | if(menu->first_time) |
| 6114 | menu->first_time = 0; |
| 6115 | |
| 6116 | /* required items = ((items + header + 2 separators) * total_actions) + edit + return + terminator) */ |
| 6117 | request_strings(((kErrorFlag_Max + 3) * entry->actionListLength) + 3, 0, 0, 0); |
| 6118 | menuItem = menu_strings.main_list; |
| 6119 | |
| 4769 | 6120 | /********** MENU CONSTRUCTION **********/ |
| 4770 | | sprintf(cpuBuffer, "%d", search->targetIdx); // CPU |
| 6121 | for(i = 0; i < entry->actionListLength; i++) |
| 6122 | { |
| 6123 | CheatAction * action = &entry->actionList[i]; |
| 6124 | |
| 6125 | UINT32 flags = AnalyseCodeFormat(entry, action); |
| 6126 | |
| 6127 | menuItem[total++] = action->optionalName ? action->optionalName : "(Null)"; |
| 6128 | menuItem[total++] = MENU_SEPARATOR_ITEM; |
| 6129 | |
| 6130 | if(flags) |
| 6131 | { |
| 6132 | for(j = 0; j < kErrorFlag_Max; j++) |
| 6133 | { |
| 6134 | if((flags >> j) & 1) |
| 6135 | menuItem[total++] = kAnalyseItemName[j]; |
| 6136 | } |
| 6137 | } |
| 6138 | else |
| 6139 | menuItem[total++] = "No Problem"; |
| 6140 | |
| 6141 | menuItem[total++] = MENU_SEPARATOR_ITEM; |
| 6142 | } |
| 6143 | |
| 6144 | menuItem[total++] = "Edit This Entry"; |
| 6145 | menuItem[total++] = "Return to Prior Menu"; |
| 6146 | menuItem[total] = NULL; |
| 6147 | |
| 6148 | /* adjust cursor position */ |
| 6149 | ADJUST_CURSOR(menu->sel, total) |
| 6150 | |
| 6151 | old_style_menu(menuItem, NULL, NULL, menu->sel, 0); |
| 6152 | |
| 6153 | if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate)) |
| 6154 | { |
| 6155 | CURSOR_TO_PREVIOUS(menu->sel, total) |
| 6156 | } |
| 6157 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate)) |
| 6158 | { |
| 6159 | CURSOR_TO_NEXT(menu->sel, total) |
| 6160 | } |
| 6161 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate)) |
| 6162 | { |
| 6163 | CURSOR_PAGE_UP(menu->sel) |
| 6164 | } |
| 6165 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate)) |
| 6166 | { |
| 6167 | CURSOR_PAGE_DOWN(menu->sel, total) |
| 6168 | } |
| 6169 | else if(input_ui_pressed(machine, IPT_UI_EDIT_CHEAT)) |
| 6170 | { |
| 6171 | isEdit = 1; |
| 6172 | } |
| 6173 | else if(input_ui_pressed(machine, IPT_UI_SELECT)) |
| 6174 | { |
| 6175 | if(menu->sel == total - 2) |
| 6176 | isEdit = 1; |
| 6177 | else |
| 6178 | menu->sel = -1; |
| 6179 | } |
| 6180 | else if(input_ui_pressed(machine, IPT_UI_CANCEL)) |
| 6181 | { |
| 6182 | menu->sel = -1; |
| 6183 | } |
| 6184 | |
| 6185 | if(isEdit) |
| 6186 | { |
| 6187 | if(entry->flags & kCheatFlag_OldFormat) |
| 6188 | cheat_menu_stack_push(edit_cheat_menu, menu->return_handler, menu->pre_sel); |
| 6189 | else |
| 6190 | cheat_menu_stack_push(view_cheat_menu, menu->return_handler, menu->pre_sel); |
| 6191 | } |
| 6192 | |
| 6193 | return menu->sel + 1; |
| 6194 | } |
| 6195 | |
| 6196 | /*----------------------------------------------------------- |
| 6197 | search_minimum_menu - management for minimum search menu |
| 6198 | limited size, operand, comparison |
| 6199 | -----------------------------------------------------------*/ |
| 6200 | |
| 6201 | static int search_minimum_menu(running_machine *machine, cheat_menu_stack *menu) |
| 6202 | { |
| 6203 | enum{ |
| 6204 | kMenu_CPU = 0, |
| 6205 | kMenu_Memory, |
| 6206 | kMenu_Divider1, |
| 6207 | kMenu_Value, |
| 6208 | kMenu_Timer, |
| 6209 | kMenu_Greater, |
| 6210 | kMenu_Less, |
| 6211 | kMenu_Equal, |
| 6212 | kMenu_NotEqual, |
| 6213 | kMenu_Divider2, |
| 6214 | kMenu_Result, |
| 6215 | kMenu_RestoreSearch, |
| 6216 | kMenu_Return, |
| 6217 | kMenu_Max }; |
| 6218 | |
| 6219 | INT8 i; |
| 6220 | UINT8 total = 0; |
| 6221 | UINT8 doSearch = 0; |
| 6222 | static UINT8 doneSaveMemory = 0; |
| 6223 | const char * menuItem[kMenu_Max + 1] = { 0 }; |
| 6224 | const char * menuSubItem[kMenu_Max + 1] = { 0 }; |
| 6225 | char flagBuf[kMenu_Max + 1] = { 0 }; |
| 6226 | char cpuBuf[4]; |
| 6227 | char valueBuf[32]; // "FFFFFFF[F] (4294967295)" 23 chars |
| 6228 | char timerBuf[32]; // "-FFFFFFF[F] (4294967295)" 24 chars |
| 6229 | char numResultsBuf[16]; |
| 6230 | char * stringsBuf; |
| 6231 | search_info *search = get_current_search(); |
| 6232 | |
| 6233 | /* first setting : NONE */ |
| 6234 | if(menu->first_time) |
| 6235 | menu->first_time = 0; |
| 6236 | |
| 6237 | /* NOTE : in this mode, search bytes is always fixed with 1 byte right now */ |
| 6238 | search->old_options.value &= kSearchByteMaskTable[search->bytes]; |
| 6239 | search->old_options.delta &= kSearchByteMaskTable[search->bytes]; |
| 6240 | |
| 6241 | /********** MENU CONSTRUCTION **********/ |
| 6242 | /* ##### CPU ##### */ |
| 4771 | 6243 | menuItem[total] = "CPU"; |
| 4772 | | menuSubItem[total++] = cpuBuffer; |
| 6244 | sprintf(cpuBuf, "%d", search->target_idx); |
| 6245 | menuSubItem[total++] = cpuBuf; |
| 4773 | 6246 | |
| 4774 | | if(search->sign && (search->oldOptions.value & kSearchByteSignBitTable[search->bytes])) |
| 6247 | /* ##### MEMORY ##### */ |
| 6248 | if(doneSaveMemory) |
| 6249 | menuItem[total] = "Initialize Memory"; |
| 6250 | else |
| 6251 | menuItem[total] = "Save Memory"; |
| 6252 | menuSubItem[total++] = NULL; |
| 6253 | |
| 6254 | /* ##### DIVIDER ##### */ |
| 6255 | menuItem[total] = MENU_SEPARATOR_ITEM; |
| 6256 | menuSubItem[total++] = NULL; |
| 6257 | |
| 6258 | /* ##### VALUE ##### */ |
| 6259 | menuItem[total] = "Value"; |
| 6260 | |
| 6261 | if(editActive && menu->sel == kMenu_Value) |
| 4775 | 6262 | { |
| 4776 | | UINT32 tempValue; |
| 6263 | stringsBuf = valueBuf; |
| 4777 | 6264 | |
| 4778 | | tempValue = ~search->oldOptions.value + 1; |
| 4779 | | tempValue &= kSearchByteUnsignedMaskTable[search->bytes]; |
| 6265 | for(i = 1; i >= 0; i--) |
| 6266 | { |
| 6267 | if(i == editCursor) |
| 6268 | stringsBuf += sprintf(stringsBuf, "[%X]", (search->old_options.value & kIncrementMaskTable[i]) / kIncrementValueTable[i]); |
| 6269 | else |
| 6270 | stringsBuf += sprintf(stringsBuf, "%X", (search->old_options.value & kIncrementMaskTable[i]) / kIncrementValueTable[i]); |
| 6271 | } |
| 4780 | 6272 | |
| 4781 | | sprintf(valueBuffer, "-%.*X (-%d)", kSearchByteDigitsTable[search->bytes], tempValue, tempValue); |
| 6273 | stringsBuf += sprintf(stringsBuf, " (%d)", search->old_options.value); |
| 4782 | 6274 | } |
| 4783 | 6275 | else |
| 4784 | | sprintf(valueBuffer, "%.*X (%d)", kSearchByteDigitsTable[search->bytes], |
| 4785 | | search->oldOptions.value & kSearchByteMaskTable[search->bytes], |
| 4786 | | search->oldOptions.value & kSearchByteMaskTable[search->bytes]); |
| 6276 | sprintf(valueBuf, "%.*X (%d)", |
| 6277 | kSearchByteDigitsTable[search->bytes], search->old_options.value, search->old_options.value); |
| 4787 | 6278 | |
| 4788 | | switch(searchItem) |
| 6279 | menuSubItem[total++] = valueBuf; |
| 6280 | |
| 6281 | /* ##### TIMER ##### */ |
| 6282 | menuItem[total] = "Timer"; |
| 6283 | |
| 6284 | if(!(search->old_options.delta & kSearchByteSignBitTable[search->bytes])) |
| 4789 | 6285 | { |
| 4790 | | case kItem_Value: // value |
| 4791 | | menuItem[total] = "Value"; |
| 4792 | | menuSubItem[total++] = valueBuffer; |
| 4793 | | break; |
| 6286 | /* PLUS */ |
| 6287 | if(editActive && menu->sel == kMenu_Timer) |
| 6288 | { |
| 6289 | stringsBuf = timerBuf; |
| 4794 | 6290 | |
| 4795 | | case kItem_Timer: |
| 4796 | | menuItem[total] = "Timer (+ or -)"; // timer |
| 4797 | | |
| 4798 | | /* ----- if memory has been saved, set sub-item for timer ----- */ |
| 4799 | | if(doneSaveMemory) |
| 6291 | for(i = 2; i >= 0; i--) |
| 4800 | 6292 | { |
| 4801 | | if(search->oldOptions.delta & kSearchByteSignBitTable[search->bytes]) |
| 6293 | if(i == editCursor) |
| 4802 | 6294 | { |
| 4803 | | UINT32 tempValue; |
| 6295 | if(i == 2) |
| 6296 | stringsBuf += sprintf(stringsBuf, "[+]"); |
| 6297 | else |
| 6298 | stringsBuf += sprintf(stringsBuf, "[%X]", (search->old_options.delta & kIncrementMaskTable[i]) / kIncrementValueTable[i]); |
| 6299 | } |
| 6300 | else |
| 6301 | { |
| 6302 | if(i == 2) |
| 6303 | stringsBuf += sprintf(stringsBuf, "+"); |
| 6304 | else |
| 6305 | stringsBuf += sprintf(stringsBuf, "%X", (search->old_options.delta & kIncrementMaskTable[i]) / kIncrementValueTable[i]); |
| 6306 | } |
| 6307 | } |
| 4804 | 6308 | |
| 4805 | | tempValue = ~search->oldOptions.delta + 1; |
| 4806 | | tempValue &= kSearchByteUnsignedMaskTable[search->bytes]; |
| 6309 | stringsBuf += sprintf(stringsBuf, " (+%d)", search->old_options.delta); |
| 6310 | } |
| 6311 | else |
| 6312 | sprintf(timerBuf, "+%.2X (+%d)", search->old_options.delta, search->old_options.delta); |
| 6313 | } |
| 6314 | else |
| 6315 | { |
| 6316 | UINT32 deltaDisp = (~search->old_options.delta + 1) & 0x7F; |
| 4807 | 6317 | |
| 4808 | | sprintf(valueSignedBuffer, "-%.*X (-%d)", kSearchByteDigitsTable[search->bytes], tempValue, tempValue); |
| 6318 | /* MINUS */ |
| 6319 | if(editActive && menu->sel == kMenu_Timer) |
| 6320 | { |
| 6321 | stringsBuf = timerBuf; |
| 6322 | |
| 6323 | for(i = 2; i >= 0; i--) |
| 6324 | { |
| 6325 | if(i == editCursor) |
| 6326 | { |
| 6327 | if(i == 2) |
| 6328 | stringsBuf += sprintf(stringsBuf, "[-]"); |
| 6329 | else |
| 6330 | stringsBuf += sprintf(stringsBuf, "[%X]", (deltaDisp & kIncrementMaskTable[i]) / kIncrementValueTable[i]); |
| 4809 | 6331 | } |
| 4810 | 6332 | else |
| 4811 | | sprintf(valueSignedBuffer, "%.*X (%d)", kSearchByteDigitsTable[search->bytes], |
| 4812 | | search->oldOptions.delta & kSearchByteMaskTable[search->bytes], |
| 4813 | | search->oldOptions.delta & kSearchByteMaskTable[search->bytes]); |
| 4814 | | |
| 4815 | | menuSubItem[total++] = valueSignedBuffer; |
| 6333 | { |
| 6334 | if(i == 2) |
| 6335 | stringsBuf += sprintf(stringsBuf, "-"); |
| 6336 | else |
| 6337 | stringsBuf += sprintf(stringsBuf, "%X", (deltaDisp & kIncrementMaskTable[i]) / kIncrementValueTable[i]); |
| 6338 | } |
| 4816 | 6339 | } |
| 4817 | | break; |
| 4818 | 6340 | |
| 4819 | | case kItem_Equal: |
| 4820 | | menuItem[total] = "Comparison"; // equal |
| 4821 | | menuSubItem[total++] = "Equal"; |
| 4822 | | break; |
| 6341 | #ifdef MAME_DEBUG |
| 6342 | stringsBuf += sprintf(stringsBuf, " = %.2X (-%d)", search->old_options.delta, deltaDisp); |
| 6343 | #else |
| 6344 | stringsBuf += sprintf(stringsBuf, " (-%d)", deltaDisp); |
| 6345 | #endif |
| 6346 | } |
| 6347 | else |
| 4823 | 6348 | |
| 4824 | | case kItem_NotEqual: |
| 4825 | | menuItem[total] = "Comparison"; // not equal |
| 4826 | | menuSubItem[total++] = "Not Equal"; |
| 4827 | | break; |
| 6349 | #ifdef MAME_DEBUG |
| 6350 | sprintf(timerBuf, "-%.2X = %.2X (-%d)", deltaDisp, search->old_options.delta, deltaDisp); |
| 6351 | #else |
| 6352 | sprintf(timerBuf, "-%.2X (-%d)", deltaDisp, deltaDisp); |
| 6353 | #endif |
| 6354 | } |
| 6355 | menuSubItem[total++] = timerBuf; |
| 4828 | 6356 | |
| 4829 | | case kItem_Less: |
| 4830 | | menuItem[total] = "Comparison"; // less |
| 4831 | | menuSubItem[total++] = "Less"; |
| 4832 | | break; |
| 6357 | /* ##### GREATER ##### */ |
| 6358 | menuItem[total] = "Greater"; |
| 6359 | menuSubItem[total++] = "A > B"; |
| 4833 | 6360 | |
| 4834 | | case kItem_Greater: |
| 4835 | | menuItem[total] = "Comparison"; // greater |
| 4836 | | menuSubItem[total++] = "Greater"; |
| 4837 | | break; |
| 4838 | | } |
| 6361 | /* ##### LESS ##### */ |
| 6362 | menuItem[total] = "Less"; |
| 6363 | menuSubItem[total++] = "A < B"; |
| 4839 | 6364 | |
| 4840 | | menuItem[total] = "--------------------"; // divider |
| 6365 | /* ##### EQUAL ##### */ |
| 6366 | menuItem[total] = "Equal"; |
| 6367 | menuSubItem[total++] = "A = B"; |
| 6368 | |
| 6369 | /* ##### NOT EQUAL ##### */ |
| 6370 | menuItem[total] = "Not Equal"; |
| 6371 | menuSubItem[total++] = "A != B"; |
| 6372 | |
| 6373 | /* ##### DIVIDER ##### */ |
| 6374 | menuItem[total] = MENU_SEPARATOR_ITEM; |
| 4841 | 6375 | menuSubItem[total++] = NULL; |
| 4842 | 6376 | |
| 4843 | | if(doneSaveMemory) // memory |
| 4844 | | menuItem[total] = "Initialize Memory"; |
| 6377 | /* ##### RESULT ##### */ |
| 6378 | menuItem[total] = "Results"; |
| 6379 | if(search->num_results) |
| 6380 | { |
| 6381 | sprintf(numResultsBuf, "%d", search->num_results); |
| 6382 | } |
| 4845 | 6383 | else |
| 4846 | | menuItem[total] = "Save Memory"; |
| 4847 | | menuSubItem[total++] = NULL; |
| 6384 | { |
| 6385 | if(!doneSaveMemory) |
| 6386 | sprintf(numResultsBuf, "No Memory Save"); |
| 6387 | else |
| 6388 | sprintf(numResultsBuf, "No Result"); |
| 6389 | } |
| 6390 | menuSubItem[total++] = numResultsBuf; |
| 4848 | 6391 | |
| 4849 | | menuItem[total] = "View Last Results"; // view result |
| 6392 | /* ##### RESULT RESTORE ##### */ |
| 6393 | menuItem[total] = "Restore Previous Results"; |
| 4850 | 6394 | menuSubItem[total++] = NULL; |
| 4851 | 6395 | |
| 4852 | | menuItem[total] = "Restore Previous Results"; // restore result |
| 6396 | /* ##### RETURN ##### */ |
| 6397 | menuItem[total] = "Return to Prior Menu"; |
| 4853 | 6398 | menuSubItem[total++] = NULL; |
| 4854 | 6399 | |
| 4855 | | menuItem[total] = "Return to Prior Menu"; // return |
| 4856 | | menuSubItem[total++] = NULL; |
| 4857 | | |
| 4858 | | menuItem[total] = NULL; // terminate array |
| 6400 | /* ##### TERMINATE ARRAY ##### */ |
| 6401 | menuItem[total] = NULL; |
| 4859 | 6402 | menuSubItem[total] = NULL; |
| 4860 | 6403 | |
| 4861 | | /* ----- adjust current cursor position ----- */ |
| 4862 | | if((sel < 0) || (sel >= total)) |
| 4863 | | sel = kMenu_SearchItem; |
| 6404 | /* adjust current cursor position */ |
| 6405 | if(menu->sel < 0 || menu->sel >= total) |
| 6406 | menu->sel = kMenu_Memory; |
| 6407 | if(!doneSaveMemory) |
| 6408 | { |
| 6409 | if(menu->sel >= kMenu_Timer && menu->sel <= kMenu_NotEqual) |
| 6410 | menu->sel = kMenu_Memory; |
| 6411 | } |
| 4864 | 6412 | |
| 4865 | | /* ----- higlighted sub-item if edit mode ----- */ |
| 4866 | 6413 | if(editActive) |
| 4867 | | flagBuf[sel] = 1; |
| 6414 | flagBuf[menu->sel] = 1; |
| 4868 | 6415 | |
| 4869 | | /* ----- draw it ----- */ |
| 4870 | | old_style_menu(menuItem, menuSubItem, flagBuf, sel, 0); |
| 6416 | /* draw it */ |
| 6417 | old_style_menu(menuItem, menuSubItem, flagBuf, menu->sel, 0); |
| 4871 | 6418 | |
| 4872 | 6419 | /********** KEY HANDLING **********/ |
| 4873 | | if(UIPressedRepeatThrottle(machine, IPT_UI_UP, kVerticalKeyRepeatRate)) |
| 6420 | if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate)) |
| 4874 | 6421 | { |
| 4875 | 6422 | if(editActive) |
| 4876 | 6423 | { |
| 4877 | | increment <<= 4; |
| 4878 | | |
| 4879 | | switch(searchItem) |
| 6424 | switch(menu->sel) |
| 4880 | 6425 | { |
| 4881 | | case kItem_Value: |
| 4882 | | search->oldOptions.value += increment; |
| 4883 | | search->oldOptions.value &= kSearchByteMaskTable[search->bytes]; |
| 6426 | case kMenu_Value: |
| 6427 | search->old_options.value = DoIncrementHexField(search->old_options.value, editCursor); |
| 4884 | 6428 | break; |
| 4885 | 6429 | |
| 4886 | | case kItem_Timer: |
| 4887 | | search->oldOptions.delta += increment; |
| 4888 | | search->oldOptions.delta &= kSearchByteMaskTable[search->bytes]; |
| 6430 | case kMenu_Timer: |
| 6431 | switch(editCursor) |
| 6432 | { |
| 6433 | default: |
| 6434 | search->old_options.delta = DoIncrementHexFieldSigned(search->old_options.delta, editCursor, search->bytes); |
| 6435 | break; |
| 6436 | |
| 6437 | case 2: |
| 6438 | if(!search->old_options.delta || search->old_options.delta == 0x80) |
| 6439 | search->old_options.delta ^= 0x80; |
| 6440 | else |
| 6441 | search->old_options.delta = ~search->old_options.delta + 1; |
| 6442 | break; |
| 6443 | } |
| 4889 | 6444 | break; |
| 4890 | 6445 | } |
| 4891 | | |
| 4892 | | increment >>= 4; |
| 4893 | 6446 | } |
| 4894 | 6447 | else |
| 4895 | 6448 | { |
| 4896 | | sel--; |
| 6449 | CURSOR_TO_PREVIOUS(menu->sel, total) |
| 4897 | 6450 | |
| 4898 | | /* ----- if divider, skip it ----- */ |
| 4899 | | if(sel == kMenu_Divider) |
| 4900 | | sel--; |
| 4901 | | |
| 4902 | | if(sel < 0) |
| 4903 | | sel = total - 1; |
| 6451 | if(menu->sel == kMenu_Divider1 || menu->sel == kMenu_Divider2) |
| 6452 | { |
| 6453 | if(--menu->sel == kMenu_NotEqual && !doneSaveMemory) |
| 6454 | menu->sel = kMenu_Value; |
| 6455 | } |
| 4904 | 6456 | } |
| 4905 | 6457 | } |
| 4906 | | |
| 4907 | | if(UIPressedRepeatThrottle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate)) |
| 6458 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate)) |
| 4908 | 6459 | { |
| 4909 | 6460 | if(editActive) |
| 4910 | 6461 | { |
| 4911 | | increment <<= 4; |
| 4912 | | |
| 4913 | | switch(searchItem) |
| 6462 | switch(menu->sel) |
| 4914 | 6463 | { |
| 4915 | | case kItem_Value: |
| 4916 | | search->oldOptions.value -= increment; |
| 4917 | | search->oldOptions.value &= kSearchByteMaskTable[search->bytes]; |
| 6464 | case kMenu_Value: |
| 6465 | search->old_options.value = DoDecrementHexField(search->old_options.value, editCursor); |
| 4918 | 6466 | break; |
| 4919 | 6467 | |
| 4920 | | case kItem_Timer: |
| 4921 | | search->oldOptions.delta -= increment; |
| 4922 | | search->oldOptions.delta &= kSearchByteMaskTable[search->bytes]; |
| 6468 | case kMenu_Timer: |
| 6469 | switch(editCursor) |
| 6470 | { |
| 6471 | default: |
| 6472 | search->old_options.delta = DoDecrementHexFieldSigned(search->old_options.delta, editCursor, search->bytes); |
| 6473 | break; |
| 6474 | |
| 6475 | case 2: |
| 6476 | if(!search->old_options.delta || search->old_options.delta == 0x80) |
| 6477 | search->old_options.delta ^= 0x80; |
| 6478 | else |
| 6479 | search->old_options.delta = ~search->old_options.delta + 1; |
| 6480 | break; |
| 6481 | } |
| 4923 | 6482 | break; |
| 4924 | 6483 | } |
| 4925 | | |
| 4926 | | increment >>= 4; |
| 4927 | 6484 | } |
| 4928 | 6485 | else |
| 4929 | 6486 | { |
| 4930 | | sel++; |
| 6487 | CURSOR_TO_NEXT(menu->sel, total) |
| 4931 | 6488 | |
| 4932 | | /* ----- if divider, skip it ----- */ |
| 4933 | | if(sel == kMenu_Divider) |
| 4934 | | sel++; |
| 4935 | | |
| 4936 | | if(sel >= total) |
| 4937 | | sel = 0; |
| 6489 | if(menu->sel == kMenu_Divider1 || menu->sel == kMenu_Divider2) |
| 6490 | menu->sel++; |
| 6491 | if(!doneSaveMemory && menu->sel == kMenu_Timer) |
| 6492 | menu->sel = kMenu_Result; |
| 4938 | 6493 | } |
| 4939 | 6494 | } |
| 4940 | | |
| 4941 | | if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate)) |
| 6495 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_LEFT, kHorizontalFastKeyRepeatRate)) |
| 4942 | 6496 | { |
| 4943 | | sel -= fullMenuPageHeight; |
| 4944 | | |
| 4945 | | if(sel < 0) |
| 4946 | | sel = 0; |
| 4947 | | } |
| 4948 | | |
| 4949 | | if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate)) |
| 4950 | | { |
| 4951 | | sel += fullMenuPageHeight; |
| 4952 | | |
| 4953 | | if(sel >= total) |
| 4954 | | sel = total - 1; |
| 4955 | | } |
| 4956 | | |
| 4957 | | if(UIPressedRepeatThrottle(machine, IPT_UI_LEFT, kHorizontalFastKeyRepeatRate)) |
| 4958 | | { |
| 4959 | 6497 | if(editActive) |
| 4960 | 6498 | { |
| 4961 | | switch(searchItem) |
| 6499 | switch(menu->sel) |
| 4962 | 6500 | { |
| 4963 | | case kItem_Value: |
| 4964 | | search->oldOptions.value -= increment; |
| 4965 | | search->oldOptions.value &= kSearchByteMaskTable[search->bytes]; |
| 6501 | case kMenu_Value: |
| 6502 | editCursor ^= 1; |
| 4966 | 6503 | break; |
| 4967 | 6504 | |
| 4968 | | case kItem_Timer: |
| 4969 | | search->oldOptions.delta -= increment; |
| 4970 | | search->oldOptions.delta &= kSearchByteMaskTable[search->bytes]; |
| 6505 | case kMenu_Timer: |
| 6506 | if(++editCursor > 2) |
| 6507 | editCursor = 0; |
| 4971 | 6508 | break; |
| 4972 | 6509 | } |
| 4973 | 6510 | } |
| 4974 | 6511 | else |
| 4975 | 6512 | { |
| 4976 | | switch(sel) |
| 6513 | switch(menu->sel) |
| 4977 | 6514 | { |
| 4978 | 6515 | case kMenu_CPU: |
| 4979 | | if(search->targetIdx > 0) |
| 6516 | if(search->target_idx > 0) |
| 4980 | 6517 | { |
| 4981 | | search->targetIdx--; |
| 6518 | search->target_idx--; |
| 4982 | 6519 | |
| 4983 | | BuildSearchRegions(machine, search); |
| 4984 | | AllocateSearchRegions(search); |
| 6520 | build_search_regions(machine, search); |
| 6521 | allocate_search_regions(search); |
| 4985 | 6522 | |
| 4986 | 6523 | doneSaveMemory = 0; |
| 4987 | 6524 | } |
| 4988 | 6525 | break; |
| 4989 | 6526 | |
| 4990 | | case kMenu_SearchItem: |
| 4991 | | if(doneSaveMemory) |
| 4992 | | searchItem--; |
| 6527 | case kMenu_Value: |
| 6528 | search->old_options.value = (search->old_options.value - 1) & 0xFF; |
| 6529 | break; |
| 4993 | 6530 | |
| 4994 | | if(searchItem < 0) |
| 4995 | | searchItem = kItem_Max; |
| 6531 | case kMenu_Timer: |
| 6532 | search->old_options.delta = (search->old_options.delta - 1) & 0xFF; |
| 4996 | 6533 | break; |
| 6534 | |
| 6535 | default: |
| 6536 | menu->sel = kMenu_Memory; |
| 4997 | 6537 | } |
| 4998 | 6538 | } |
| 4999 | 6539 | } |
| 5000 | | |
| 5001 | | if(UIPressedRepeatThrottle(machine, IPT_UI_RIGHT, kHorizontalFastKeyRepeatRate)) |
| 6540 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_RIGHT, kHorizontalFastKeyRepeatRate)) |
| 5002 | 6541 | { |
| 5003 | 6542 | if(editActive) |
| 5004 | 6543 | { |
| 5005 | | switch(searchItem) |
| 6544 | switch(menu->sel) |
| 5006 | 6545 | { |
| 5007 | | case kItem_Value: |
| 5008 | | search->oldOptions.value += increment; |
| 5009 | | search->oldOptions.value &= kSearchByteMaskTable[search->bytes]; |
| 6546 | case kMenu_Value: |
| 6547 | editCursor ^= 1; |
| 5010 | 6548 | break; |
| 5011 | 6549 | |
| 5012 | | case kItem_Timer: |
| 5013 | | search->oldOptions.delta += increment; |
| 5014 | | search->oldOptions.delta &= kSearchByteMaskTable[search->bytes]; |
| 6550 | case kMenu_Timer: |
| 6551 | if(--editCursor < 0) |
| 6552 | editCursor = 2; |
| 5015 | 6553 | break; |
| 5016 | 6554 | } |
| 5017 | 6555 | } |
| 5018 | 6556 | else |
| 5019 | 6557 | { |
| 5020 | | switch(sel) |
| 6558 | switch(menu->sel) |
| 5021 | 6559 | { |
| 5022 | 6560 | case kMenu_CPU: |
| 5023 | | if(search->targetIdx < cpu_gettotalcpu() - 1) |
| 6561 | if(search->target_idx < cpu_gettotalcpu() - 1) |
| 5024 | 6562 | { |
| 5025 | | search->targetIdx++; |
| 6563 | search->target_idx++; |
| 5026 | 6564 | |
| 5027 | | BuildSearchRegions(machine, search); |
| 5028 | | AllocateSearchRegions(search); |
| 6565 | build_search_regions(machine, search); |
| 6566 | allocate_search_regions(search); |
| 5029 | 6567 | |
| 5030 | 6568 | doneSaveMemory = 0; |
| 5031 | 6569 | } |
| 5032 | 6570 | break; |
| 5033 | 6571 | |
| 5034 | | case kMenu_SearchItem: |
| 5035 | | if(doneSaveMemory) |
| 5036 | | searchItem++; |
| 6572 | case kMenu_Value: |
| 6573 | search->old_options.value = (search->old_options.value + 1) & 0xFF; |
| 6574 | break; |
| 5037 | 6575 | |
| 5038 | | if(searchItem > kItem_Max) |
| 5039 | | searchItem = kItem_Value; |
| 6576 | case kMenu_Timer: |
| 6577 | search->old_options.delta = (search->old_options.delta + 1) & 0xFF; |
| 6578 | break; |
| 5040 | 6579 | |
| 5041 | | break; |
| 6580 | default: |
| 6581 | menu->sel = kMenu_Result; |
| 5042 | 6582 | } |
| 5043 | 6583 | } |
| 5044 | 6584 | } |
| 5045 | | |
| 5046 | | if(input_ui_pressed(machine, IPT_UI_SELECT)) |
| 6585 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate)) |
| 5047 | 6586 | { |
| 6587 | CURSOR_PAGE_UP(menu->sel) |
| 6588 | } |
| 6589 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate)) |
| 6590 | { |
| 6591 | CURSOR_PAGE_DOWN(menu->sel, total) |
| 6592 | } |
| 6593 | else if(input_ui_pressed(machine, IPT_UI_SELECT)) |
| 6594 | { |
| 5048 | 6595 | if(editActive) |
| 5049 | 6596 | { |
| 5050 | | switch(searchItem) |
| 6597 | switch(menu->sel) |
| 5051 | 6598 | { |
| 5052 | | case kItem_Value: |
| 6599 | case kMenu_Value: |
| 5053 | 6600 | search->bytes = kSearchSize_8Bit; |
| 5054 | 6601 | search->lhs = kSearchOperand_Current; |
| 5055 | 6602 | search->rhs = kSearchOperand_Value; |
| 5056 | 6603 | search->comparison = kSearchComparison_EqualTo; |
| 5057 | | search->value = search->oldOptions.value; |
| 5058 | | |
| 6604 | search->value = search->old_options.value; |
| 5059 | 6605 | doSearch = 1; |
| 5060 | 6606 | break; |
| 5061 | 6607 | |
| 5062 | | case kItem_Timer: |
| 6608 | case kMenu_Timer: |
| 5063 | 6609 | search->bytes = kSearchSize_8Bit; |
| 5064 | 6610 | search->lhs = kSearchOperand_Current; |
| 5065 | 6611 | search->rhs = kSearchOperand_Previous; |
| 5066 | 6612 | search->comparison = kSearchComparison_IncreasedBy; |
| 5067 | | search->value = search->oldOptions.delta; |
| 5068 | | |
| 6613 | search->value = search->old_options.delta; |
| 5069 | 6614 | doSearch = 1; |
| 5070 | 6615 | break; |
| 5071 | 6616 | } |
| 5072 | | |
| 5073 | | /* ----- finish edit mode then do search ----- */ |
| 5074 | 6617 | editActive = 0; |
| 5075 | 6618 | } |
| 5076 | 6619 | else |
| 5077 | 6620 | { |
| 5078 | | switch(sel) |
| 6621 | switch(menu->sel) |
| 5079 | 6622 | { |
| 5080 | 6623 | case kMenu_CPU: |
| 5081 | | submenuChoice = 1; // go to region selection menu |
| 6624 | cheat_menu_stack_push(select_search_region_menu, menu->handler, menu->sel); |
| 5082 | 6625 | break; |
| 5083 | 6626 | |
| 5084 | | case kMenu_SearchItem: |
| 5085 | | { |
| 6627 | case kMenu_Memory: |
| 6628 | doneSaveMemory = 0; |
| 6629 | doSearch = 1; |
| 6630 | break; |
| 5086 | 6631 | |
| 5087 | | switch(searchItem) |
| 5088 | | { |
| 5089 | | case kItem_Value: |
| 5090 | | case kItem_Timer: |
| 5091 | | editActive = 1; |
| 5092 | | break; |
| 6632 | case kMenu_Value: |
| 6633 | search->bytes = kSearchSize_8Bit; |
| 6634 | search->lhs = kSearchOperand_Current; |
| 6635 | search->rhs = kSearchOperand_Value; |
| 6636 | search->comparison = kSearchComparison_EqualTo; |
| 6637 | search->value = search->old_options.value; |
| 6638 | doSearch = 1; |
| 6639 | break; |
| 5093 | 6640 | |
| 5094 | | case kItem_Equal: |
| 5095 | | search->bytes = kSearchSize_8Bit; |
| 5096 | | search->lhs = kSearchOperand_Current; |
| 5097 | | search->rhs = kSearchOperand_Previous; |
| 5098 | | search->comparison = kSearchComparison_EqualTo; |
| 6641 | case kMenu_Timer: |
| 6642 | search->bytes = kSearchSize_8Bit; |
| 6643 | search->lhs = kSearchOperand_Current; |
| 6644 | search->rhs = kSearchOperand_Previous; |
| 6645 | search->comparison = kSearchComparison_IncreasedBy; |
| 6646 | search->value = search->old_options.delta; |
| 6647 | doSearch = 1; |
| 6648 | break; |
| 5099 | 6649 | |
| 5100 | | doSearch = 1; |
| 5101 | | break; |
| 6650 | case kMenu_Equal: |
| 6651 | search->bytes = kSearchSize_8Bit; |
| 6652 | search->lhs = kSearchOperand_Current; |
| 6653 | search->rhs = kSearchOperand_Previous; |
| 6654 | search->comparison = kSearchComparison_EqualTo; |
| 6655 | doSearch = 1; |
| 6656 | break; |
| 5102 | 6657 | |
| 5103 | | case kItem_NotEqual: |
| 5104 | | search->bytes = kSearchSize_8Bit; |
| 5105 | | search->lhs = kSearchOperand_Current; |
| 5106 | | search->rhs = kSearchOperand_Previous; |
| 5107 | | search->comparison = kSearchComparison_NotEqual; |
| 6658 | case kMenu_NotEqual: |
| 6659 | search->bytes = kSearchSize_8Bit; |
| 6660 | search->lhs = kSearchOperand_Current; |
| 6661 | search->rhs = kSearchOperand_Previous; |
| 6662 | search->comparison = kSearchComparison_NotEqual; |
| 6663 | doSearch = 1; |
| 6664 | break; |
| 5108 | 6665 | |
| 5109 | | doSearch = 1; |
| 5110 | | break; |
| 6666 | case kMenu_Less: |
| 6667 | search->bytes = kSearchSize_8Bit; |
| 6668 | search->lhs = kSearchOperand_Current; |
| 6669 | search->rhs = kSearchOperand_Previous; |
| 6670 | search->comparison = kSearchComparison_LessThan; |
| 6671 | doSearch = 1; |
| 6672 | break; |
| 5111 | 6673 | |
| 5112 | | case kItem_Less: |
| 5113 | | search->bytes = kSearchSize_8Bit; |
| 5114 | | search->lhs = kSearchOperand_Current; |
| 5115 | | search->rhs = kSearchOperand_Previous; |
| 5116 | | search->comparison = kSearchComparison_LessThan; |
| 5117 | | |
| 5118 | | doSearch = 1; |
| 5119 | | break; |
| 5120 | | |
| 5121 | | case kItem_Greater: |
| 5122 | | search->bytes = kSearchSize_8Bit; |
| 5123 | | search->lhs = kSearchOperand_Current; |
| 5124 | | search->rhs = kSearchOperand_Previous; |
| 5125 | | search->comparison = kSearchComparison_GreaterThan; |
| 5126 | | |
| 5127 | | doSearch = 1; |
| 5128 | | break; |
| 5129 | | } |
| 5130 | | } |
| 5131 | | break; |
| 5132 | | |
| 5133 | | case kMenu_Memory: // save memory to search newly |
| 5134 | | doneSaveMemory = 0; |
| 5135 | | |
| 6674 | case kMenu_Greater: |
| 6675 | search->bytes = kSearchSize_8Bit; |
| 6676 | search->lhs = kSearchOperand_Current; |
| 6677 | search->rhs = kSearchOperand_Previous; |
| 6678 | search->comparison = kSearchComparison_GreaterThan; |
| 5136 | 6679 | doSearch = 1; |
| 5137 | 6680 | break; |
| 5138 | 6681 | |
| 5139 | | case kMenu_ViewResult: |
| 5140 | | if(search->regionListLength) |
| 6682 | case kMenu_Result: |
| 6683 | if(search->region_list_length) |
| 6684 | cheat_menu_stack_push(view_search_result_menu, menu->handler, menu->sel); |
| 6685 | else |
| 5141 | 6686 | { |
| 5142 | | /* ----- go to result viewer ----- */ |
| 5143 | | firstEntry = 1; |
| 5144 | | submenuChoice = 1; |
| 6687 | /* if no search region (eg, sms.c in HazeMD), don't open result viewer to avoid the crash */ |
| 6688 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 6689 | messageType = kCheatMessage_NoSearchRegion; |
| 5145 | 6690 | } |
| 5146 | | else |
| 5147 | | /* ----- if no search region (eg, sms.c in HazeMD), don't open result viewer to avoid the crash ----- */ |
| 5148 | | ui_popup_time(1, "no search regions"); |
| 5149 | 6691 | break; |
| 5150 | 6692 | |
| 5151 | 6693 | case kMenu_RestoreSearch: |
| 5152 | | RestoreSearchBackup(search); |
| 6694 | restore_search_backup(search); |
| 5153 | 6695 | break; |
| 5154 | 6696 | |
| 5155 | 6697 | case kMenu_Return: |
| 5156 | | posnKeep = kMenu_SearchItem; |
| 5157 | | sel = -1; |
| 6698 | menu->sel = -1; |
| 5158 | 6699 | break; |
| 5159 | 6700 | } |
| 5160 | 6701 | } |
| 5161 | 6702 | } |
| 5162 | | |
| 5163 | | if(UIPressedRepeatThrottle(machine, IPT_UI_ZOOM_IN, kVerticalKeyRepeatRate)) |
| 5164 | | /* ----- quick menu switch : search -> watchpoint list ----- */ |
| 5165 | | sel = -5; |
| 5166 | | |
| 5167 | | if(UIPressedRepeatThrottle(machine, IPT_UI_ZOOM_OUT, kVerticalKeyRepeatRate)) |
| 5168 | | /* ----- quick menu switch : search -> add/edit ----- */ |
| 5169 | | sel = -3; |
| 5170 | | |
| 5171 | | /* ----- edit mode ON/OFF ----- */ |
| 5172 | | if(input_ui_pressed(machine, IPT_UI_EDIT_CHEAT)) |
| 6703 | else if(input_ui_pressed(machine, IPT_UI_EDIT_CHEAT)) |
| 5173 | 6704 | { |
| 5174 | 6705 | if(editActive) |
| 5175 | 6706 | editActive = 0; |
| 5176 | 6707 | else |
| 5177 | 6708 | { |
| 5178 | | if((searchItem == kItem_Value) || (kItem_Timer)) |
| 6709 | if(menu->sel == kMenu_Value || menu->sel == kMenu_Timer) |
| 6710 | { |
| 5179 | 6711 | editActive = 1; |
| 6712 | editCursor = 0; |
| 6713 | } |
| 5180 | 6714 | } |
| 5181 | 6715 | } |
| 5182 | | |
| 5183 | | /* ----- memory save ----- */ |
| 5184 | | if(input_ui_pressed(machine, IPT_UI_CLEAR)) |
| 6716 | else if(input_ui_pressed(machine, IPT_UI_RELOAD_CHEAT)) |
| 5185 | 6717 | { |
| 5186 | | doneSaveMemory = 0; |
| 5187 | | |
| 5188 | | doSearch = 1; |
| 6718 | restore_search_backup(search); |
| 5189 | 6719 | } |
| 5190 | | |
| 5191 | | if(input_ui_pressed(machine, IPT_UI_CANCEL)) |
| 6720 | else if(input_ui_pressed(machine, IPT_UI_CANCEL)) |
| 5192 | 6721 | { |
| 5193 | 6722 | if(editActive) |
| 5194 | 6723 | editActive = 0; |
| 5195 | 6724 | else |
| 5196 | | { |
| 5197 | | posnKeep = kMenu_Memory; |
| 5198 | | sel = -1; |
| 5199 | | } |
| 6725 | menu->sel = -1; |
| 5200 | 6726 | } |
| 5201 | 6727 | |
| 5202 | 6728 | /********** SEARCH **********/ |
| 5203 | 6729 | if(doSearch) |
| 5204 | 6730 | { |
| 5205 | 6731 | if(!doneSaveMemory) |
| 5206 | | /* ----- initialize search ----- */ |
| 5207 | | InitializeNewSearch(search); |
| 6732 | init_new_search(search); |
| 5208 | 6733 | |
| 5209 | | if(((sel == kMenu_SearchItem) && (searchItem == kItem_Value)) || doneSaveMemory) |
| 6734 | if(doneSaveMemory || menu->sel == kMenu_Value) |
| 5210 | 6735 | { |
| 5211 | | /* ----- do search ----- */ |
| 5212 | | BackupSearch(search); |
| 5213 | | |
| 5214 | | DoSearch(search); |
| 6736 | backup_search(search); |
| 6737 | do_search(search); |
| 5215 | 6738 | } |
| 5216 | 6739 | |
| 5217 | | UpdateSearch(search); |
| 6740 | update_search(search); |
| 5218 | 6741 | |
| 5219 | | /* ----- display message ----- */ |
| 5220 | | if(((sel == kMenu_SearchItem) && (searchItem == kItem_Value)) || doneSaveMemory) |
| 5221 | | popmessage("%d results found", search->numResults); |
| 6742 | if(doneSaveMemory || menu->sel == kMenu_Value) |
| 6743 | messageType = kCheatMessage_CheatFound; |
| 5222 | 6744 | else |
| 5223 | | popmessage("saved all memory regions"); |
| 6745 | messageType = kCheatMessage_InitializeMemory; |
| 5224 | 6746 | |
| 6747 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 6748 | |
| 5225 | 6749 | doneSaveMemory = 1; |
| 5226 | 6750 | |
| 5227 | | if(search->numResults == 1) |
| 6751 | if(search->num_results == 1) |
| 5228 | 6752 | { |
| 5229 | 6753 | AddCheatFromFirstResult(search); |
| 5230 | 6754 | |
| 5231 | | popmessage("1 result found, added to list"); |
| 6755 | messageType = kCheatMessage_1CheatFound; |
| 5232 | 6756 | } |
| 5233 | 6757 | } |
| 5234 | 6758 | |
| 5235 | 6759 | /********** EDIT **********/ |
| 5236 | | if((sel == kMenu_SearchItem) && editActive) |
| 6760 | if(editActive) |
| 5237 | 6761 | { |
| 5238 | | if(searchItem == kItem_Value) |
| 6762 | switch(menu->sel) |
| 5239 | 6763 | { |
| 5240 | | search->oldOptions.value = DoEditHexField(machine, search->oldOptions.value); |
| 6764 | case kMenu_Value: |
| 6765 | search->old_options.value = do_edit_hex_field(machine, search->old_options.value); |
| 6766 | search->old_options.value &= 0xFF; |
| 6767 | break; |
| 5241 | 6768 | |
| 5242 | | search->oldOptions.value &= kSearchByteMaskTable[search->bytes]; |
| 6769 | case kMenu_Timer: |
| 6770 | search->old_options.delta = do_edit_hex_field(machine, search->old_options.delta); |
| 6771 | search->old_options.delta &= 0xFF; |
| 6772 | break; |
| 5243 | 6773 | } |
| 5244 | | else |
| 5245 | | { |
| 5246 | | if(searchItem == kItem_Timer) |
| 5247 | | { |
| 5248 | | search->oldOptions.delta = DoEditHexField(machine, search->oldOptions.delta); |
| 5249 | | |
| 5250 | | search->oldOptions.delta &= kSearchByteMaskTable[search->bytes]; |
| 5251 | | } |
| 5252 | | } |
| 5253 | 6774 | } |
| 5254 | 6775 | |
| 5255 | | if(sel >= 0) |
| 5256 | | posnKeep = sel; |
| 5257 | | |
| 5258 | | return sel + 1; |
| 6776 | return menu->sel + 1; |
| 5259 | 6777 | } |
| 5260 | 6778 | |
| 5261 | | /*----------------------------------------------------------- |
| 5262 | | DoSearchMenuClassic - management for classic search menu |
| 5263 | | -----------------------------------------------------------*/ |
| 6779 | /*------------------------------------------------------------- |
| 6780 | search_standard_menu - management for standard search menu |
| 6781 | fixed bit and operand |
| 6782 | -------------------------------------------------------------*/ |
| 5264 | 6783 | |
| 5265 | | static int DoSearchMenuClassic(running_machine *machine, int selection) |
| 6784 | static int search_standard_menu(running_machine *machine, cheat_menu_stack *menu) |
| 5266 | 6785 | { |
| 5267 | | static const char *const energyStrings[] = |
| 5268 | | { |
| 6786 | static const char *const kComparisonNameTable[] = { |
| 6787 | "Equal", |
| 6788 | "Not Equal", |
| 5269 | 6789 | "Less", |
| 6790 | "Less or Equal", |
| 5270 | 6791 | "Greater", |
| 5271 | | "Less or Equal", |
| 5272 | | "Greater or Equal", |
| 5273 | | }; |
| 6792 | "Greater or Equal" }; |
| 5274 | 6793 | |
| 5275 | | static const char *const equalOrNotStrings[] = |
| 5276 | | { |
| 5277 | | "Equal", |
| 5278 | | "Not Equal", |
| 5279 | | }; |
| 6794 | static const char *const kIncrementNameTable[] = { |
| 6795 | "Increment", |
| 6796 | "Decrement" }; |
| 5280 | 6797 | |
| 5281 | | static const char *const operandStrings[] = |
| 5282 | | { |
| 5283 | | "Previous Data", |
| 5284 | | "First Data", |
| 5285 | | }; |
| 5286 | | |
| 5287 | | /* conversion table */ |
| 5288 | | static const int kEnergyComparisonConversionTable[] = |
| 5289 | | { |
| 6798 | static const int kComparisonConversionTable[] = { |
| 6799 | kSearchComparison_EqualTo, |
| 6800 | kSearchComparison_NotEqual, |
| 5290 | 6801 | kSearchComparison_LessThan, |
| 6802 | kSearchComparison_LessThanOrEqualTo, |
| 5291 | 6803 | kSearchComparison_GreaterThan, |
| 5292 | | kSearchComparison_LessThanOrEqualTo, |
| 5293 | | kSearchComparison_GreaterThanOrEqualTo |
| 5294 | | }; |
| 6804 | kSearchComparison_GreaterThanOrEqualTo }; |
| 5295 | 6805 | |
| 5296 | | static const int kEqualOrNotConversionTable[] = |
| 5297 | | { |
| 5298 | | kSearchComparison_EqualTo, |
| 5299 | | kSearchComparison_NotEqual |
| 5300 | | }; |
| 5301 | | |
| 5302 | | static const int kOperandConversionTable[] = |
| 5303 | | { |
| 5304 | | kSearchOperand_Previous, |
| 5305 | | kSearchOperand_First |
| 5306 | | }; |
| 5307 | | |
| 5308 | | enum |
| 5309 | | { |
| 5310 | | kMenu_DoMemorySave = 0, |
| 5311 | | |
| 5312 | | kMenu_Divider, |
| 5313 | | |
| 6806 | enum{ |
| 6807 | kMenu_Comparison, |
| 6808 | kMenu_Value, |
| 6809 | kMenu_NearTo, |
| 6810 | kMenu_Increment, |
| 6811 | kMenu_Bit, |
| 6812 | kMenu_Separator, |
| 5314 | 6813 | kMenu_CPU, |
| 5315 | | kMenu_ValueEqual, |
| 5316 | | kMenu_ValueNearTo, |
| 5317 | | kMenu_Time, |
| 5318 | | kMenu_Energy, |
| 5319 | | kMenu_Status, |
| 5320 | | kMenu_Operand, |
| 5321 | | |
| 5322 | | kMenu_Divider2, |
| 5323 | | |
| 6814 | kMenu_Memory, |
| 5324 | 6815 | kMenu_ViewResult, |
| 5325 | | kMenu_RestoreSearch, |
| 5326 | | |
| 6816 | kMenu_RestoreResult, |
| 5327 | 6817 | kMenu_Return, |
| 5328 | | }; |
| 5329 | 6818 | |
| 5330 | | enum |
| 5331 | | { |
| 5332 | | kEnergy_Less = 0, |
| 5333 | | kEnergy_Greater, |
| 5334 | | kEnergy_LessOrEqual, |
| 5335 | | kEnergy_GreaterOrEqual, |
| 5336 | | }; |
| 6819 | kMenu_Max }; |
| 5337 | 6820 | |
| 5338 | | const char * menuItem[kMenu_Return + 2] = { 0 }; |
| 5339 | | const char * menuSubItem[kMenu_Return + 2] = { 0 }; |
| 6821 | enum{ |
| 6822 | kComparison_Equal = 0, |
| 6823 | kComparison_NotEqual, |
| 6824 | kComparison_Less, |
| 6825 | kComparison_LessOrEqual, |
| 6826 | kComparison_Greater, |
| 6827 | kComparison_GreaterOrEqual, |
| 6828 | kComparison_Max = kComparison_GreaterOrEqual }; |
| 5340 | 6829 | |
| 5341 | | char valueBuffer[60]; |
| 5342 | | char valueSignedBuffer[60]; |
| 5343 | | char cpuBuffer[20]; |
| 6830 | INT8 total = 0; |
| 6831 | INT8 doSearch = 0; |
| 6832 | static INT8 doneSaveMemory = 0; |
| 6833 | const char * menuItem[kMenu_Max + 1] = { 0 }; |
| 6834 | const char * menuSubItem[kMenu_Max + 1] = { 0 }; |
| 6835 | char valueBuf[32]; |
| 6836 | char incrementBuf[16]; |
| 6837 | search_info *search = get_current_search(); |
| 5344 | 6838 | |
| 5345 | | SearchInfo * search = GetCurrentSearch(); |
| 6839 | /* first setting : adjust search items */ |
| 6840 | if(menu->first_time) |
| 6841 | { |
| 6842 | search->lhs = kSearchOperand_Current; |
| 5346 | 6843 | |
| 5347 | | INT32 sel = selection - 1; |
| 5348 | | INT32 total = 0; |
| 5349 | | UINT32 increment = 1; |
| 5350 | | UINT8 doSearch = 0; |
| 6844 | if(!search->old_options.delta) |
| 6845 | search->old_options.delta = 1; |
| 5351 | 6846 | |
| 5352 | | static INT8 submenuChoice = 0; |
| 5353 | | static UINT8 doneSaveMemory = 0; |
| 5354 | | static UINT8 firstEntry = 0; |
| 5355 | | static int lastPos = 0; |
| 6847 | menu->first_time = 0; |
| 6848 | } |
| 5356 | 6849 | |
| 5357 | | sel = lastPos; |
| 6850 | /********** MENU CONSTRUCTION **********/ |
| 6851 | /* ##### COMPARISON ##### */ |
| 6852 | menuItem[total] = "Comparison"; |
| 6853 | if(menu->sel == kMenu_Comparison || menu->sel == kMenu_Value) |
| 6854 | menuSubItem[total++] = kComparisonNameTable[search->old_options.comparison]; |
| 6855 | else |
| 6856 | menuSubItem[total++] = " "; |
| 5358 | 6857 | |
| 5359 | | /********** SUB MENU **********/ |
| 5360 | | if(submenuChoice) |
| 6858 | /* ##### VALUE ##### */ |
| 6859 | menuItem[total] = "Value"; |
| 6860 | if(menu->sel == kMenu_Value) |
| 5361 | 6861 | { |
| 5362 | | switch(sel) |
| 6862 | if(editActive) |
| 5363 | 6863 | { |
| 5364 | | case kMenu_CPU: |
| 5365 | | submenuChoice = SelectSearchRegions(machine, submenuChoice, GetCurrentSearch()); |
| 5366 | | break; |
| 6864 | INT8 i; |
| 6865 | char * stringsBuf = valueBuf; |
| 5367 | 6866 | |
| 5368 | | case kMenu_ViewResult: |
| 5369 | | submenuChoice = ViewSearchResults(machine, submenuChoice, firstEntry); |
| 5370 | | break; |
| 6867 | for(i = 1; i >= 0; i--) |
| 6868 | { |
| 6869 | if(i == editCursor) |
| 6870 | stringsBuf += sprintf(stringsBuf, "[%X]", (search->old_options.value & kIncrementMaskTable[i]) / kIncrementValueTable[i]); |
| 6871 | else |
| 6872 | stringsBuf += sprintf(stringsBuf, "%X", (search->old_options.value & kIncrementMaskTable[i]) / kIncrementValueTable[i]); |
| 6873 | } |
| 6874 | stringsBuf += sprintf(stringsBuf, " (%d)", search->old_options.value); |
| 5371 | 6875 | } |
| 6876 | else |
| 6877 | sprintf(valueBuf, "%2.2X (%2.2d)", search->old_options.value, search->old_options.value); |
| 5372 | 6878 | |
| 5373 | | firstEntry = 0; |
| 6879 | menuSubItem[total++] = valueBuf; |
| 6880 | } |
| 6881 | else |
| 6882 | menuSubItem[total++] = " "; |
| 5374 | 6883 | |
| 5375 | | /* ----- meaningless ? because no longer return with sel = -1 (pressed UI_CONFIG in submenu) ----- */ |
| 5376 | | // if(submenuChoice == -1) |
| 5377 | | // submenuChoice = 0; |
| 6884 | /* ##### VALUE - NEAR TO ##### */ |
| 6885 | menuItem[total] = "Near To"; |
| 6886 | if(menu->sel == kMenu_NearTo) |
| 6887 | { |
| 6888 | if(editActive) |
| 6889 | { |
| 6890 | INT8 i; |
| 6891 | char * stringsBuf = valueBuf; |
| 5378 | 6892 | |
| 5379 | | return sel + 1; |
| 6893 | for(i = 1; i >=0; i--) |
| 6894 | { |
| 6895 | if(i == editCursor) |
| 6896 | stringsBuf += sprintf(stringsBuf, "[%X]", (search->old_options.value & kIncrementMaskTable[i]) / kIncrementValueTable[i]); |
| 6897 | else |
| 6898 | stringsBuf += sprintf(stringsBuf, "%X", (search->old_options.value & kIncrementMaskTable[i]) / kIncrementValueTable[i]); |
| 6899 | } |
| 6900 | stringsBuf += sprintf(stringsBuf, " or %2.2X (%2.2d or %2.2d)", |
| 6901 | (search->old_options.value - 1) & kSearchByteMaskTable[search->bytes], |
| 6902 | search->old_options.value, |
| 6903 | search->old_options.value - 1); |
| 6904 | } |
| 6905 | else |
| 6906 | sprintf(valueBuf, "%2.2X or %2.2X (%2.2d or %2.2d)", |
| 6907 | search->old_options.value, (search->old_options.value - 1) & kSearchByteMaskTable[search->bytes], |
| 6908 | search->old_options.value, search->old_options.value - 1); |
| 6909 | menuSubItem[total++] = valueBuf; |
| 5380 | 6910 | } |
| 5381 | | |
| 5382 | | /********** MENU CONSTRUCTION **********/ |
| 5383 | | if(!doneSaveMemory) |
| 5384 | | menuItem[total] = "Save Memory"; |
| 5385 | 6911 | else |
| 5386 | | menuItem[total] = "Initialize Memory"; |
| 6912 | menuSubItem[total++] = " "; |
| 5387 | 6913 | |
| 5388 | | menuSubItem[total++] = NULL; |
| 5389 | | |
| 5390 | | menuItem[total] = "--------------------"; |
| 5391 | | menuSubItem[total++] = NULL; |
| 5392 | | |
| 5393 | | sprintf(cpuBuffer, "%d", search->targetIdx); |
| 5394 | | menuItem[total] = "CPU"; |
| 5395 | | menuSubItem[total++] = cpuBuffer; |
| 5396 | | |
| 5397 | | if(search->sign && (search->oldOptions.value & kSearchByteSignBitTable[search->bytes])) |
| 6914 | /* ##### INCREMENT/DECREMENT ##### */ |
| 6915 | menuItem[total] = kIncrementNameTable[search->old_options.sign]; |
| 6916 | if(menu->sel == kMenu_Increment) |
| 5398 | 6917 | { |
| 5399 | | UINT32 tempValue; |
| 6918 | if(editActive) |
| 6919 | { |
| 6920 | INT8 i; |
| 6921 | char * stringsBuf = incrementBuf; |
| 5400 | 6922 | |
| 5401 | | tempValue = ~search->oldOptions.value + 1; |
| 5402 | | tempValue &= kSearchByteUnsignedMaskTable[search->bytes]; |
| 5403 | | |
| 5404 | | sprintf(valueBuffer, "-%.*X (-%d)", kSearchByteDigitsTable[search->bytes], tempValue, tempValue); |
| 6923 | for(i = 2; i >=0; i--) |
| 6924 | { |
| 6925 | if(i == editCursor) |
| 6926 | { |
| 6927 | if(i == 2) |
| 6928 | stringsBuf += sprintf(stringsBuf, "[%s]", search->old_options.sign ? "-" : "+"); |
| 6929 | else |
| 6930 | stringsBuf += sprintf(stringsBuf, "[%X]", (search->old_options.delta & kIncrementMaskTable[i]) / kIncrementValueTable[i]); |
| 6931 | } |
| 6932 | else |
| 6933 | { |
| 6934 | if(i == 2) |
| 6935 | stringsBuf += sprintf(stringsBuf, "%s", search->old_options.sign ? "-" : "+"); |
| 6936 | else |
| 6937 | stringsBuf += sprintf(stringsBuf, "%X", (search->old_options.delta & kIncrementMaskTable[i]) / kIncrementValueTable[i]); |
| 6938 | } |
| 6939 | } |
| 6940 | stringsBuf += sprintf(stringsBuf, " (%s%2.2d)", search->old_options.sign ? "-" : "+", search->old_options.delta); |
| 6941 | } |
| 6942 | else |
| 6943 | { |
| 6944 | sprintf(incrementBuf, "%s%2.2X (%s%2.2d)", |
| 6945 | search->old_options.sign ? "-" : "+", |
| 6946 | search->old_options.delta, |
| 6947 | search->old_options.sign ? "-" : "+", |
| 6948 | search->old_options.delta); |
| 6949 | } |
| 6950 | menuSubItem[total++] = incrementBuf; |
| 5405 | 6951 | } |
| 5406 | 6952 | else |
| 5407 | | sprintf(valueBuffer, "%.*X (%d)", kSearchByteDigitsTable[search->bytes], search->oldOptions.value & kSearchByteMaskTable[search->bytes], search->oldOptions.value & kSearchByteMaskTable[search->bytes]); |
| 5408 | | |
| 5409 | | menuItem[total] = "Value (Equal)"; |
| 5410 | | |
| 5411 | | if(sel >= kMenu_ValueNearTo) |
| 5412 | 6953 | menuSubItem[total++] = " "; |
| 5413 | | else |
| 5414 | | menuSubItem[total++] = valueBuffer; |
| 5415 | 6954 | |
| 5416 | | menuItem[total] = "Value (NearTo)"; |
| 5417 | | |
| 5418 | | if(sel >= kMenu_ValueNearTo) |
| 5419 | | menuSubItem[total++] = valueBuffer; |
| 6955 | /* ##### BIT ##### */ |
| 6956 | menuItem[total] = "Bit"; |
| 6957 | if(menu->sel == kMenu_Bit) |
| 6958 | menuSubItem[total++] = kComparisonNameTable[search->old_options.comparison]; |
| 5420 | 6959 | else |
| 5421 | 6960 | menuSubItem[total++] = " "; |
| 5422 | 6961 | |
| 5423 | | menuItem[total] = "Timer (+ or -)"; |
| 5424 | | menuSubItem[total++] = " "; |
| 6962 | /* ##### SEPARATOR ##### */ |
| 6963 | menuItem[total] = MENU_SEPARATOR_ITEM; |
| 6964 | menuSubItem[total++] = NULL; |
| 5425 | 6965 | |
| 5426 | | menuItem[total] = "Energy (Less or Greater)"; |
| 5427 | | menuSubItem[total++] = " "; |
| 6966 | /* ##### CPU ##### */ |
| 6967 | menuItem[total] = "CPU"; |
| 6968 | menuSubItem[total++] = kNumbersTable[search->target_idx]; |
| 5428 | 6969 | |
| 5429 | | menuItem[total] = "Status (Same or Different)"; |
| 5430 | | menuSubItem[total++] = " "; |
| 5431 | | |
| 5432 | | menuItem[total] = "Comparison Option"; |
| 5433 | | menuSubItem[total++] = " "; |
| 5434 | | |
| 5435 | | menuItem[total] = "--------------------"; |
| 6970 | /* ##### MEMORY ##### */ |
| 6971 | if(doneSaveMemory) |
| 6972 | menuItem[total] = "Initialize Memory"; |
| 6973 | else |
| 6974 | menuItem[total] = "Save Memory"; |
| 5436 | 6975 | menuSubItem[total++] = NULL; |
| 5437 | 6976 | |
| 5438 | | menuItem[total] = "View Last Results"; // view result |
| 6977 | /* ##### RESULT VIEWER ##### */ |
| 6978 | menuItem[total] = "View Last Results"; |
| 5439 | 6979 | menuSubItem[total++] = NULL; |
| 5440 | 6980 | |
| 5441 | | menuItem[total] = "Restore Previous Results"; // restore result |
| 6981 | /* ##### RESULT RESTORE ##### */ |
| 6982 | menuItem[total] = "Restore Previous Results"; |
| 5442 | 6983 | menuSubItem[total++] = NULL; |
| 5443 | 6984 | |
| 5444 | | menuItem[total] = "Return to Prior Menu"; // return |
| 6985 | /* ##### RETURN ##### */ |
| 6986 | menuItem[total] = "Return to Prior Menu"; |
| 5445 | 6987 | menuSubItem[total++] = NULL; |
| 5446 | 6988 | |
| 5447 | | menuItem[total] = NULL; // terminate array |
| 6989 | /* ##### TERMINATE ARRAY ##### */ |
| 6990 | menuItem[total] = NULL; |
| 5448 | 6991 | menuSubItem[total] = NULL; |
| 5449 | 6992 | |
| 5450 | | /* ----- if memory has been saved, set sub-menu items ----- */ |
| 5451 | | if(doneSaveMemory) |
| 6993 | /* adjust current cursor position */ |
| 6994 | ADJUST_CURSOR(menu->sel, total) |
| 6995 | |
| 6996 | /* draw it */ |
| 6997 | old_style_menu(menuItem, menuSubItem, 0, menu->sel, 0); |
| 6998 | |
| 6999 | /********** KEY HANDLING **********/ |
| 7000 | if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate)) |
| 5452 | 7001 | { |
| 5453 | | if(search->oldOptions.delta & kSearchByteSignBitTable[search->bytes]) |
| 7002 | if(editActive) |
| 5454 | 7003 | { |
| 5455 | | UINT32 tempValue; |
| 7004 | switch(menu->sel) |
| 7005 | { |
| 7006 | case kMenu_Value: |
| 7007 | case kMenu_NearTo: |
| 7008 | search->old_options.value = DoIncrementHexField(search->old_options.value, editCursor); |
| 7009 | break; |
| 5456 | 7010 | |
| 5457 | | tempValue = ~search->oldOptions.delta + 1; |
| 5458 | | tempValue &= kSearchByteUnsignedMaskTable[search->bytes]; |
| 5459 | | |
| 5460 | | sprintf(valueSignedBuffer, "-%.*X (-%d)", kSearchByteDigitsTable[search->bytes], tempValue, tempValue); |
| 7011 | case kMenu_Increment: |
| 7012 | if(editCursor == 2) |
| 7013 | search->old_options.sign ^= 1; |
| 7014 | else |
| 7015 | search->old_options.delta = DoIncrementHexField(search->old_options.delta, editCursor); |
| 7016 | break; |
| 7017 | } |
| 5461 | 7018 | } |
| 5462 | 7019 | else |
| 5463 | | sprintf(valueSignedBuffer, "%.*X (%d)", kSearchByteDigitsTable[search->bytes], search->oldOptions.delta & kSearchByteMaskTable[search->bytes], search->oldOptions.delta & kSearchByteMaskTable[search->bytes]); |
| 7020 | { |
| 7021 | CURSOR_TO_PREVIOUS(menu->sel, total) |
| 5464 | 7022 | |
| 5465 | | menuSubItem[kMenu_Time] = valueSignedBuffer; |
| 5466 | | menuSubItem[kMenu_Energy] = energyStrings[search->oldOptions.energy]; |
| 5467 | | menuSubItem[kMenu_Status] = equalOrNotStrings[search->oldOptions.status]; |
| 5468 | | menuSubItem[kMenu_Operand] = operandStrings[search->oldOptions.operand]; |
| 7023 | if(menu->sel == kMenu_Separator) menu->sel--; |
| 7024 | } |
| 5469 | 7025 | } |
| 5470 | | |
| 5471 | | /* ----- adjust current cursor position ----- */ |
| 5472 | | if(sel < 0) |
| 5473 | | sel = 0; |
| 5474 | | if(sel >= total) |
| 5475 | | sel = total - 1; |
| 5476 | | |
| 5477 | | /* ----- draw it ----- */ |
| 5478 | | old_style_menu(menuItem, menuSubItem, 0, sel, 0); |
| 5479 | | |
| 5480 | | /********** KEY HANDLING **********/ |
| 5481 | | if(AltKeyPressed()) |
| 5482 | | increment <<= 4; |
| 5483 | | |
| 5484 | | if(UIPressedRepeatThrottle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate)) |
| 7026 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate)) |
| 5485 | 7027 | { |
| 5486 | | sel++; |
| 7028 | if(editActive) |
| 7029 | { |
| 7030 | switch(menu->sel) |
| 7031 | { |
| 7032 | case kMenu_Value: |
| 7033 | case kMenu_NearTo: |
| 7034 | search->old_options.value = DoDecrementHexField(search->old_options.value, editCursor); |
| 7035 | break; |
| 5487 | 7036 | |
| 5488 | | /* ----- if divider, skip it ----- */ |
| 5489 | | if((sel == kMenu_Divider) || (sel == kMenu_Divider2)) |
| 5490 | | sel++; |
| 7037 | case kMenu_Increment: |
| 7038 | if(editCursor == 2) |
| 7039 | search->old_options.sign ^= 1; |
| 7040 | else |
| 7041 | search->old_options.delta = DoDecrementHexField(search->old_options.delta, editCursor); |
| 7042 | break; |
| 7043 | } |
| 7044 | } |
| 7045 | else |
| 7046 | { |
| 7047 | CURSOR_TO_NEXT(menu->sel, total) |
| 5491 | 7048 | |
| 5492 | | if(sel >= total) |
| 5493 | | sel = 0; |
| 7049 | if(menu->sel == kMenu_Separator) menu->sel++; |
| 7050 | } |
| 5494 | 7051 | } |
| 5495 | | |
| 5496 | | if(UIPressedRepeatThrottle(machine, IPT_UI_UP, kVerticalKeyRepeatRate)) |
| 7052 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate)) |
| 5497 | 7053 | { |
| 5498 | | sel--; |
| 5499 | | |
| 5500 | | /* ----- if divider, skip it ----- */ |
| 5501 | | if((sel == kMenu_Divider) || (sel == kMenu_Divider2)) |
| 5502 | | sel--; |
| 5503 | | |
| 5504 | | if(sel < 0) |
| 5505 | | sel = total - 1; |
| 7054 | if(!editActive) |
| 7055 | CURSOR_PAGE_UP(menu->sel) |
| 5506 | 7056 | } |
| 5507 | | |
| 5508 | | if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate)) |
| 7057 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate)) |
| 5509 | 7058 | { |
| 5510 | | sel -= fullMenuPageHeight; |
| 5511 | | |
| 5512 | | if(sel < 0) |
| 5513 | | sel = 0; |
| 7059 | if(!editActive) |
| 7060 | CURSOR_PAGE_DOWN(menu->sel, total) |
| 5514 | 7061 | } |
| 5515 | | |
| 5516 | | if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate)) |
| 7062 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_LEFT, kHorizontalFastKeyRepeatRate)) |
| 5517 | 7063 | { |
| 5518 | | sel += fullMenuPageHeight; |
| 7064 | if(editActive) |
| 7065 | { |
| 7066 | switch(menu->sel) |
| 7067 | { |
| 7068 | case kMenu_Value: |
| 7069 | case kMenu_NearTo: |
| 7070 | if(++editCursor > 1) editCursor = 0; |
| 7071 | break; |
| 5519 | 7072 | |
| 5520 | | if(sel >= total) |
| 5521 | | sel = total - 1; |
| 5522 | | } |
| 5523 | | |
| 5524 | | if(UIPressedRepeatThrottle(machine, IPT_UI_LEFT, kHorizontalFastKeyRepeatRate)) |
| 5525 | | { |
| 5526 | | switch(sel) |
| 7073 | case kMenu_Increment: |
| 7074 | if(++editCursor > 2) editCursor = 0; |
| 7075 | break; |
| 7076 | } |
| 7077 | } |
| 7078 | else |
| 5527 | 7079 | { |
| 5528 | | case kMenu_CPU: |
| 5529 | | if(search->targetIdx > 0) |
| 5530 | | { |
| 5531 | | search->targetIdx--; |
| 7080 | switch(menu->sel) |
| 7081 | { |
| 7082 | case kMenu_Comparison: |
| 7083 | case kMenu_Bit: |
| 7084 | if(--search->old_options.comparison < kComparison_Equal) |
| 7085 | search->old_options.comparison = kComparison_Max; |
| 7086 | break; |
| 5532 | 7087 | |
| 5533 | | BuildSearchRegions(machine, search); |
| 5534 | | AllocateSearchRegions(search); |
| 7088 | case kMenu_Value: |
| 7089 | case kMenu_NearTo: |
| 7090 | search->old_options.value = (search->old_options.value - 1) & kCheatSizeMaskTable[search->bytes]; |
| 7091 | break; |
| 5535 | 7092 | |
| 5536 | | doneSaveMemory = 0; |
| 5537 | | } |
| 5538 | | break; |
| 5539 | | |
| 5540 | | case kMenu_ValueEqual: |
| 5541 | | case kMenu_ValueNearTo: |
| 5542 | | search->oldOptions.value -= increment; |
| 5543 | | |
| 5544 | | search->oldOptions.value &= kSearchByteMaskTable[search->bytes]; |
| 5545 | | break; |
| 5546 | | |
| 5547 | | case kMenu_Time: |
| 5548 | | if(doneSaveMemory) |
| 5549 | | { |
| 5550 | | search->oldOptions.delta -= increment; |
| 5551 | | |
| 5552 | | search->oldOptions.delta &= kSearchByteMaskTable[search->bytes]; |
| 5553 | | } |
| 5554 | | break; |
| 5555 | | |
| 5556 | | case kMenu_Energy: |
| 5557 | | if(doneSaveMemory) |
| 5558 | | { |
| 5559 | | if(search->oldOptions.energy < kEnergy_GreaterOrEqual) |
| 5560 | | search->oldOptions.energy++; |
| 5561 | | else |
| 5562 | | search->oldOptions.energy = kEnergy_Less; |
| 5563 | | } |
| 5564 | | break; |
| 5565 | | |
| 5566 | | case kMenu_Status: |
| 5567 | | if(doneSaveMemory) |
| 5568 | | search->oldOptions.status ^= 1; |
| 5569 | | break; |
| 5570 | | |
| 5571 | | case kMenu_Operand: |
| 5572 | | if(doneSaveMemory) |
| 5573 | | search->oldOptions.operand ^= 1; |
| 5574 | | break; |
| 7093 | case kMenu_Increment: |
| 7094 | if(search->old_options.sign) |
| 7095 | { |
| 7096 | if(++search->old_options.delta > kSearchByteUnsignedMaskTable[search->bytes]) |
| 7097 | search->old_options.delta = kSearchByteUnsignedMaskTable[search->bytes]; |
| 7098 | } |
| 7099 | else if(--search->old_options.delta <= 0) |
| 7100 | { |
| 7101 | search->old_options.delta = 1; |
| 7102 | search->old_options.sign ^= 0x01; |
| 7103 | } |
| 7104 | break; |
| 7105 | } |
| 5575 | 7106 | } |
| 5576 | 7107 | } |
| 5577 | | |
| 5578 | | if(UIPressedRepeatThrottle(machine, IPT_UI_RIGHT, kHorizontalFastKeyRepeatRate)) |
| 7108 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_RIGHT, kHorizontalFastKeyRepeatRate)) |
| 5579 | 7109 | { |
| 5580 | | switch(sel) |
| 7110 | if(editActive) |
| 5581 | 7111 | { |
| 5582 | | case kMenu_CPU: |
| 5583 | | if(search->targetIdx < cpu_gettotalcpu() - 1) |
| 5584 | | { |
| 5585 | | search->targetIdx++; |
| 7112 | switch(menu->sel) |
| 7113 | { |
| 7114 | case kMenu_Value: |
| 7115 | case kMenu_NearTo: |
| 7116 | if(--editCursor < 0) editCursor = 1; |
| 7117 | break; |
| 5586 | 7118 | |
| 5587 | | BuildSearchRegions(machine, search); |
| 5588 | | AllocateSearchRegions(search); |
| 7119 | case kMenu_Increment: |
| 7120 | if(--editCursor < 0) editCursor = 2; |
| 7121 | break; |
| 7122 | } |
| 7123 | } |
| 7124 | else |
| 7125 | { |
| 7126 | switch(menu->sel) |
| 7127 | { |
| 7128 | case kMenu_Comparison: |
| 7129 | case kMenu_Bit: |
| 7130 | if(++search->old_options.comparison > kComparison_GreaterOrEqual) |
| 7131 | search->old_options.comparison = 0; |
| 7132 | break; |
| 5589 | 7133 | |
| 5590 | | doneSaveMemory = 0; |
| 5591 | | } |
| 5592 | | break; |
| 7134 | case kMenu_Value: |
| 7135 | case kMenu_NearTo: |
| 7136 | search->old_options.value = (search->old_options.value + 1) & kCheatSizeMaskTable[search->bytes]; |
| 7137 | break; |
| 5593 | 7138 | |
| 5594 | | case kMenu_ValueEqual: |
| 5595 | | case kMenu_ValueNearTo: |
| 5596 | | search->oldOptions.value += increment; |
| 5597 | | |
| 5598 | | search->oldOptions.value &= kSearchByteMaskTable[search->bytes]; |
| 5599 | | break; |
| 5600 | | |
| 5601 | | case kMenu_Time: |
| 5602 | | if(doneSaveMemory) |
| 5603 | | { |
| 5604 | | search->oldOptions.delta += increment; |
| 5605 | | |
| 5606 | | search->oldOptions.delta &= kSearchByteMaskTable[search->bytes]; |
| 5607 | | } |
| 5608 | | break; |
| 5609 | | |
| 5610 | | case kMenu_Energy: |
| 5611 | | if(doneSaveMemory) |
| 5612 | | { |
| 5613 | | if(search->oldOptions.energy > kEnergy_Less) |
| 5614 | | search->oldOptions.energy--; |
| 5615 | | else |
| 5616 | | search->oldOptions.energy = kEnergy_GreaterOrEqual; |
| 5617 | | } |
| 5618 | | break; |
| 5619 | | |
| 5620 | | case kMenu_Status: |
| 5621 | | if(doneSaveMemory) |
| 5622 | | search->oldOptions.status ^= 1; |
| 5623 | | break; |
| 5624 | | |
| 5625 | | case kMenu_Operand: |
| 5626 | | if(doneSaveMemory) |
| 5627 | | search->oldOptions.operand ^= 1; |
| 5628 | | break; |
| 7139 | case kMenu_Increment: |
| 7140 | if(search->old_options.sign) |
| 7141 | { |
| 7142 | if(--search->old_options.delta <= 0) |
| 7143 | { |
| 7144 | search->old_options.delta = 1; |
| 7145 | search->old_options.sign ^= 0x01; |
| 7146 | } |
| 7147 | } |
| 7148 | else if(++search->old_options.delta > kSearchByteUnsignedMaskTable[search->bytes]) |
| 7149 | { |
| 7150 | search->old_options.delta = kSearchByteUnsignedMaskTable[search->bytes]; |
| 7151 | } |
| 7152 | break; |
| 7153 | } |
| 5629 | 7154 | } |
| 5630 | 7155 | } |
| 5631 | | |
| 5632 | | if(input_ui_pressed(machine, IPT_UI_SELECT)) |
| 7156 | else if(input_ui_pressed(machine, IPT_UI_SELECT)) |
| 5633 | 7157 | { |
| 5634 | | switch(sel) |
| 7158 | if(editActive) |
| 7159 | editActive = 0; |
| 7160 | else |
| 5635 | 7161 | { |
| 5636 | | case kMenu_DoMemorySave: // save memory to search newly |
| 5637 | | doneSaveMemory = 0; |
| 7162 | switch(menu->sel) |
| 7163 | { |
| 7164 | case kMenu_Comparison: |
| 7165 | search->bytes = kSearchSize_8Bit; |
| 7166 | search->rhs = kSearchOperand_First; |
| 7167 | search->comparison = kComparisonConversionTable[search->old_options.comparison]; |
| 7168 | doSearch = 1; |
| 7169 | break; |
| 5638 | 7170 | |
| 5639 | | doSearch = 1; |
| 5640 | | break; |
| 7171 | case kMenu_Value: |
| 7172 | search->bytes = kSearchSize_8Bit; |
| 7173 | search->rhs = kSearchOperand_Value; |
| 7174 | search->comparison = kComparisonConversionTable[search->old_options.comparison]; |
| 7175 | search->value = search->old_options.value; |
| 7176 | doSearch = 1; |
| 7177 | break; |
| 5641 | 7178 | |
| 5642 | | case kMenu_CPU: |
| 5643 | | submenuChoice = 1; // go to region selection menu |
| 5644 | | break; |
| 7179 | case kMenu_NearTo: |
| 7180 | search->bytes = kSearchSize_8Bit; |
| 7181 | search->rhs = kSearchOperand_Value; |
| 7182 | search->comparison = kSearchComparison_NearTo; |
| 7183 | search->value = search->old_options.value; |
| 7184 | doSearch = 1; |
| 7185 | break; |
| 5645 | 7186 | |
| 5646 | | case kMenu_ValueEqual: |
| 5647 | | case kMenu_ValueNearTo: |
| 5648 | | search->bytes = kSearchSize_8Bit; |
| 5649 | | search->lhs = kSearchOperand_Current; |
| 5650 | | search->rhs = kSearchOperand_Value; |
| 7187 | case kMenu_Increment: |
| 7188 | if(search->old_options.delta) |
| 7189 | { |
| 7190 | search->bytes = kSearchSize_8Bit; |
| 7191 | search->rhs = kSearchOperand_First; |
| 7192 | search->comparison = kSearchComparison_IncreasedBy; |
| 5651 | 7193 | |
| 5652 | | if(sel == kMenu_ValueEqual) |
| 5653 | | search->comparison = kSearchComparison_EqualTo; // search requested value |
| 5654 | | else |
| 5655 | | search->comparison = kSearchComparison_NearTo; // search requested and requested -1 value |
| 7194 | if(search->old_options.sign) |
| 7195 | search->value = ~search->old_options.delta + 1; |
| 7196 | else |
| 7197 | search->value = search->old_options.delta; |
| 5656 | 7198 | |
| 5657 | | search->value = search->oldOptions.value; |
| 7199 | doSearch = 1; |
| 7200 | } |
| 7201 | break; |
| 5658 | 7202 | |
| 5659 | | doSearch = 1; |
| 5660 | | break; |
| 7203 | case kMenu_Bit: |
| 7204 | search->bytes = kSearchSize_1Bit; |
| 7205 | search->rhs = kSearchOperand_First; |
| 7206 | search->comparison = kComparisonConversionTable[search->old_options.comparison]; |
| 7207 | doSearch = 1; |
| 7208 | break; |
| 5661 | 7209 | |
| 5662 | | case kMenu_Time: |
| 5663 | | search->bytes = kSearchSize_8Bit; |
| 5664 | | search->lhs = kSearchOperand_Current; |
| 5665 | | search->rhs = kOperandConversionTable[search->oldOptions.operand]; |
| 5666 | | search->comparison = kSearchComparison_IncreasedBy; |
| 5667 | | search->value = search->oldOptions.delta; |
| 7210 | case kMenu_Memory: |
| 7211 | doneSaveMemory = 0; |
| 7212 | doSearch = 1; |
| 7213 | break; |
| 5668 | 7214 | |
| 5669 | | doSearch = 1; |
| 5670 | | break; |
| 7215 | case kMenu_CPU: |
| 7216 | cheat_menu_stack_pop(); |
| 7217 | break; |
| 5671 | 7218 | |
| 5672 | | case kMenu_Energy: |
| 5673 | | search->bytes = kSearchSize_8Bit; |
| 5674 | | search->lhs = kSearchOperand_Current; |
| 5675 | | search->rhs = kOperandConversionTable[search->oldOptions.operand]; |
| 5676 | | search->comparison = kEnergyComparisonConversionTable[search->oldOptions.energy]; |
| 7219 | case kMenu_ViewResult: |
| 7220 | if(search->region_list_length) |
| 7221 | cheat_menu_stack_push(view_search_result_menu, menu->handler, menu->sel); |
| 7222 | break; |
| 5677 | 7223 | |
| 5678 | | doSearch = 1; |
| 5679 | | break; |
| 7224 | case kMenu_RestoreResult: |
| 7225 | restore_search_backup(search); |
| 7226 | break; |
| 5680 | 7227 | |
| 5681 | | case kMenu_Status: |
| 5682 | | search->bytes = kSearchSize_8Bit; |
| 5683 | | search->lhs = kSearchOperand_Current; |
| 5684 | | search->rhs = kOperandConversionTable[search->oldOptions.operand]; |
| 5685 | | search->comparison = kEqualOrNotConversionTable[search->oldOptions.status]; |
| 5686 | | |
| 5687 | | doSearch = 1; |
| 5688 | | break; |
| 5689 | | |
| 5690 | | case kMenu_ViewResult: |
| 5691 | | if(search->regionListLength) |
| 5692 | | { |
| 5693 | | /* ----- go to result viewer ----- */ |
| 5694 | | firstEntry = 1; |
| 5695 | | submenuChoice = 1; |
| 5696 | | } |
| 5697 | | else |
| 5698 | | /* ----- if no search region (eg, sms.c in HazeMD), don't open result viewer to avoid the crash ----- */ |
| 5699 | | ui_popup_time(1, "no search regions"); |
| 5700 | | break; |
| 5701 | | |
| 5702 | | case kMenu_RestoreSearch: |
| 5703 | | /* ----- restore previous results ----- */ |
| 5704 | | RestoreSearchBackup(search); |
| 5705 | | break; |
| 5706 | | |
| 5707 | | case kMenu_Return: |
| 5708 | | sel = -1; |
| 5709 | | lastPos = 0; |
| 5710 | | break; |
| 5711 | | |
| 5712 | | default: |
| 5713 | | break; |
| 7228 | case kMenu_Return: |
| 7229 | menu->sel = -1; |
| 7230 | break; |
| 7231 | } |
| 5714 | 7232 | } |
| 5715 | 7233 | } |
| 5716 | | |
| 5717 | | if(UIPressedRepeatThrottle(machine, IPT_UI_ZOOM_IN, kVerticalKeyRepeatRate)) |
| 5718 | | /* ----- quick menu switch : search -> watchpoint list ----- */ |
| 5719 | | sel = -5; |
| 5720 | | |
| 5721 | | if(UIPressedRepeatThrottle(machine, IPT_UI_ZOOM_OUT, kVerticalKeyRepeatRate)) |
| 5722 | | /* ----- quick menu switch : search -> add/edit ----- */ |
| 5723 | | sel = -3; |
| 5724 | | |
| 5725 | | |
| 5726 | | if(input_ui_pressed(machine, IPT_UI_CANCEL)) |
| 7234 | else if(input_ui_pressed(machine, IPT_UI_EDIT_CHEAT)) |
| 5727 | 7235 | { |
| 5728 | | /* ----- if cursor is now on the return item, adjust cursor keeper ----- */ |
| 5729 | | if(sel == kMenu_Return) |
| 5730 | | lastPos = 0; |
| 5731 | | |
| 5732 | | sel = -1; |
| 7236 | if(menu->sel == kMenu_Value || menu->sel == kMenu_NearTo || menu->sel == kMenu_Increment) |
| 7237 | { |
| 7238 | editActive ^= 1; |
| 7239 | editCursor = 0; |
| 7240 | } |
| 5733 | 7241 | } |
| 7242 | else if(input_ui_pressed(machine, IPT_UI_CANCEL)) |
| 7243 | { |
| 7244 | if(editActive) editActive = 0; |
| 7245 | else menu->sel = -1; |
| 7246 | } |
| 5734 | 7247 | |
| 7248 | /***** SEARCH *****/ |
| 5735 | 7249 | if(doSearch) |
| 5736 | 7250 | { |
| 5737 | 7251 | if(!doneSaveMemory) |
| 5738 | | /* ----- initialize search ----- */ |
| 5739 | | InitializeNewSearch(search); |
| 7252 | init_new_search(search); |
| 5740 | 7253 | |
| 5741 | | if( (sel == kMenu_ValueEqual) || (sel == kMenu_ValueNearTo) || doneSaveMemory) |
| 7254 | if(search->rhs == kSearchOperand_Value || doneSaveMemory) |
| 5742 | 7255 | { |
| 5743 | | /* ----- do search ----- */ |
| 5744 | | BackupSearch(search); |
| 5745 | | |
| 5746 | | DoSearch(search); |
| 7256 | backup_search(search); |
| 7257 | do_search(search); |
| 5747 | 7258 | } |
| 5748 | 7259 | |
| 5749 | | UpdateSearch(search); |
| 5750 | | |
| 5751 | | if( (sel == kMenu_ValueEqual) || (sel == kMenu_ValueNearTo) || doneSaveMemory) |
| 5752 | | popmessage("%d results found", search->numResults); |
| 5753 | | else |
| 5754 | | popmessage("saved all memory regions"); |
| 5755 | | |
| 7260 | update_search(search); |
| 5756 | 7261 | doneSaveMemory = 1; |
| 5757 | 7262 | |
| 5758 | | if(search->numResults == 1) |
| 5759 | | { |
| 7263 | if(search->num_results == 1) |
| 5760 | 7264 | AddCheatFromFirstResult(search); |
| 5761 | | |
| 5762 | | popmessage("1 result found, added to list"); |
| 5763 | | } |
| 5764 | 7265 | } |
| 5765 | 7266 | |
| 5766 | | /* ----- edit a value if direct key input ----- */ |
| 5767 | | if((sel == kMenu_ValueEqual) || (sel == kMenu_ValueNearTo)) |
| 7267 | /********** EDIT **********/ |
| 7268 | switch(menu->sel) |
| 5768 | 7269 | { |
| 5769 | | search->oldOptions.value = DoEditHexField(machine, search->oldOptions.value); |
| 7270 | case kMenu_Value: |
| 7271 | search->old_options.value = do_edit_hex_field(machine, search->old_options.value); |
| 7272 | search->old_options.value &= 0xFF; |
| 7273 | break; |
| 5770 | 7274 | |
| 5771 | | search->oldOptions.value &= kSearchByteMaskTable[search->bytes]; |
| 7275 | case kMenu_Increment: |
| 7276 | search->old_options.delta = do_edit_hex_field(machine, search->old_options.delta); |
| 7277 | search->old_options.delta &= 0x7F; |
| 7278 | break; |
| 5772 | 7279 | } |
| 5773 | | else |
| 5774 | | { |
| 5775 | | if(sel == kMenu_Time) |
| 5776 | | { |
| 5777 | | search->oldOptions.delta = DoEditHexField(machine, search->oldOptions.delta); |
| 5778 | 7280 | |
| 5779 | | search->oldOptions.delta &= kSearchByteMaskTable[search->bytes]; |
| 5780 | | } |
| 5781 | | } |
| 5782 | | |
| 5783 | | /* ----- keep current cursor position ----- */ |
| 5784 | | if(sel >= 0) |
| 5785 | | lastPos = sel; |
| 5786 | | |
| 5787 | | return sel + 1; |
| 7281 | return menu->sel + 1; |
| 5788 | 7282 | } |
| 5789 | 7283 | |
| 5790 | | /*----------------------------------------------------- |
| 5791 | | DoSearchMenu - management for advanced search menu |
| 5792 | | -----------------------------------------------------*/ |
| 7284 | /*------------------------------------------------------------- |
| 7285 | search_advanced_menu - management for advanced search menu |
| 7286 | -------------------------------------------------------------*/ |
| 5793 | 7287 | |
| 5794 | | static int DoSearchMenu(running_machine *machine, int selection) |
| 7288 | static int search_advanced_menu(running_machine *machine, cheat_menu_stack *menu) |
| 5795 | 7289 | { |
| 7290 | #if 0 |
| 5796 | 7291 | /* menu stirngs */ |
| 5797 | 7292 | static const char *const kOperandNameTable[] = |
| 5798 | 7293 | { |
| r2762 | r2763 | |
| 5860 | 7355 | char cpuBuffer[20]; |
| 5861 | 7356 | char flagBuf[kMenu_Max + 2] = { 0 }; |
| 5862 | 7357 | |
| 5863 | | SearchInfo * search = GetCurrentSearch(); |
| 7358 | search_info *search = get_current_search(); |
| 5864 | 7359 | |
| 5865 | 7360 | INT32 sel = selection - 1; |
| 5866 | 7361 | INT32 total = 0; |
| 5867 | 7362 | UINT32 increment = 1; |
| 5868 | 7363 | |
| 5869 | | static INT8 submenuChoice = 0; |
| 7364 | static int submenuChoice = 0; |
| 5870 | 7365 | static UINT8 doneMemorySave = 0; |
| 5871 | 7366 | static UINT8 editActive = 0; |
| 5872 | 7367 | static UINT8 firstEntry = 0; |
| r2762 | r2763 | |
| 5880 | 7375 | switch(sel) |
| 5881 | 7376 | { |
| 5882 | 7377 | case kMenu_CPU: |
| 5883 | | submenuChoice = SelectSearchRegions(machine, submenuChoice, GetCurrentSearch()); |
| 7378 | submenuChoice = SelectSearchRegions(machine, submenuChoice, get_current_search()); |
| 5884 | 7379 | break; |
| 5885 | 7380 | |
| 5886 | 7381 | case kMenu_ViewResult: |
| 5887 | | submenuChoice = ViewSearchResults(machine, submenuChoice, firstEntry); |
| 7382 | submenuChoice = ViewSearchResults(submenuChoice, firstEntry); |
| 5888 | 7383 | break; |
| 5889 | 7384 | } |
| 5890 | 7385 | |
| 5891 | 7386 | firstEntry = 0; |
| 5892 | 7387 | |
| 5893 | | /* ----- meaningless ? because no longer return with sel = -1 (pressed UI_CONFIG in submenu) ----- */ |
| 7388 | /* meaningless ? because no longer return with sel = -1 (pressed UI_CONFIG in submenu) */ |
| 5894 | 7389 | // if(submenuChoice == -1) |
| 5895 | 7390 | // submenuChoice = 0; |
| 5896 | 7391 | |
| r2762 | r2763 | |
| 5985 | 7480 | menu_item[total] = NULL; // terminate array |
| 5986 | 7481 | menu_subitem[total] = NULL; |
| 5987 | 7482 | |
| 5988 | | /* ----- adjust current cursor position ----- */ |
| 7483 | /* adjust current cursor position */ |
| 5989 | 7484 | if(sel < 0) |
| 5990 | 7485 | sel = 0; |
| 5991 | 7486 | if(sel >= total) |
| 5992 | 7487 | sel = total - 1; |
| 5993 | 7488 | |
| 5994 | | /* ----- higlighted sub-item if edit mode ----- */ |
| 7489 | /* higlighted sub-item if edit mode */ |
| 5995 | 7490 | if(editActive) |
| 5996 | 7491 | flagBuf[sel] = 1; |
| 5997 | 7492 | |
| 5998 | | /* ----- draw it ----- */ |
| 7493 | /* draw it */ |
| 5999 | 7494 | old_style_menu(menu_item, menu_subitem, flagBuf, sel, 0); |
| 6000 | 7495 | |
| 6001 | 7496 | /********** KEY HANDLING **********/ |
| r2762 | r2763 | |
| 6006 | 7501 | if(ShiftKeyPressed()) |
| 6007 | 7502 | increment <<= 16; |
| 6008 | 7503 | |
| 6009 | | if(UIPressedRepeatThrottle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate)) |
| 7504 | if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate)) |
| 6010 | 7505 | { |
| 6011 | 7506 | sel++; |
| 6012 | 7507 | |
| 6013 | | /* ----- if divider, skip it ----- */ |
| 7508 | /* if divider, skip it */ |
| 6014 | 7509 | if((sel == kMenu_Divider) || (sel == kMenu_Divider2) || (sel == kMenu_Divider3)) |
| 6015 | 7510 | sel++; |
| 6016 | 7511 | |
| r2762 | r2763 | |
| 6018 | 7513 | sel = 0; |
| 6019 | 7514 | } |
| 6020 | 7515 | |
| 6021 | | if(UIPressedRepeatThrottle(machine, IPT_UI_UP, kVerticalKeyRepeatRate)) |
| 7516 | if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate)) |
| 6022 | 7517 | { |
| 6023 | 7518 | sel--; |
| 6024 | 7519 | |
| 6025 | | /* ----- if divider, skip it ----- */ |
| 7520 | /* if divider, skip it */ |
| 6026 | 7521 | if((sel == kMenu_Divider) || (sel == kMenu_Divider2) || (sel == kMenu_Divider3)) |
| 6027 | 7522 | sel--; |
| 6028 | 7523 | |
| r2762 | r2763 | |
| 6030 | 7525 | sel = total - 1; |
| 6031 | 7526 | } |
| 6032 | 7527 | |
| 6033 | | if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate)) |
| 7528 | if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate)) |
| 6034 | 7529 | { |
| 6035 | 7530 | sel -= fullMenuPageHeight; |
| 6036 | 7531 | |
| r2762 | r2763 | |
| 6038 | 7533 | sel = 0; |
| 6039 | 7534 | } |
| 6040 | 7535 | |
| 6041 | | if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate)) |
| 7536 | if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate)) |
| 6042 | 7537 | { |
| 6043 | 7538 | sel += fullMenuPageHeight; |
| 6044 | 7539 | |
| r2762 | r2763 | |
| 6046 | 7541 | sel = total - 1; |
| 6047 | 7542 | } |
| 6048 | 7543 | |
| 6049 | | if(UIPressedRepeatThrottle(machine, IPT_UI_LEFT, kHorizontalFastKeyRepeatRate)) |
| 7544 | if(ui_pressed_repeat_throttle(machine, IPT_UI_LEFT, kHorizontalFastKeyRepeatRate)) |
| 6050 | 7545 | { |
| 6051 | 7546 | switch(sel) |
| 6052 | 7547 | { |
| r2762 | r2763 | |
| 6106 | 7601 | } |
| 6107 | 7602 | } |
| 6108 | 7603 | |
| 6109 | | if(UIPressedRepeatThrottle(machine, IPT_UI_RIGHT, kHorizontalFastKeyRepeatRate)) |
| 7604 | if(ui_pressed_repeat_throttle(machine, IPT_UI_RIGHT, kHorizontalFastKeyRepeatRate)) |
| 6110 | 7605 | { |
| 6111 | 7606 | switch(sel) |
| 6112 | 7607 | { |
| r2762 | r2763 | |
| 6185 | 7680 | |
| 6186 | 7681 | case kMenu_DoSearch: |
| 6187 | 7682 | if(!doneMemorySave) |
| 6188 | | /* ----- initialize search ----- */ |
| 6189 | | InitializeNewSearch(search); |
| 7683 | /* initialize search */ |
| 7684 | init_new_search(search); |
| 6190 | 7685 | |
| 6191 | 7686 | if((!kSearchOperandNeedsInit[search->lhs] && !kSearchOperandNeedsInit[search->rhs]) || doneMemorySave) |
| 6192 | 7687 | { |
| 6193 | | BackupSearch(search); |
| 7688 | backup_search(search); |
| 6194 | 7689 | |
| 6195 | 7690 | DoSearch(search); |
| 6196 | 7691 | } |
| 6197 | 7692 | |
| 6198 | | UpdateSearch(search); |
| 7693 | update_search(search); |
| 6199 | 7694 | |
| 6200 | 7695 | if((!kSearchOperandNeedsInit[search->lhs] && !kSearchOperandNeedsInit[search->rhs]) || doneMemorySave) |
| 6201 | | popmessage("%d results found", search->numResults); |
| 7696 | popmessage("%d results found", search->num_results); |
| 6202 | 7697 | else |
| 6203 | 7698 | popmessage("saved all memory regions"); |
| 6204 | 7699 | |
| 6205 | 7700 | doneMemorySave = 1; |
| 6206 | 7701 | |
| 6207 | | if(search->numResults == 1) |
| 7702 | if(search->num_results == 1) |
| 6208 | 7703 | { |
| 6209 | 7704 | AddCheatFromFirstResult(search); |
| 6210 | 7705 | |
| r2762 | r2763 | |
| 6213 | 7708 | break; |
| 6214 | 7709 | |
| 6215 | 7710 | case kMenu_SaveMemory: |
| 6216 | | InitializeNewSearch(search); |
| 7711 | init_new_search(search); |
| 6217 | 7712 | |
| 6218 | | UpdateSearch(search); |
| 7713 | update_search(search); |
| 6219 | 7714 | |
| 6220 | 7715 | popmessage("saved all memory regions"); |
| 6221 | 7716 | |
| r2762 | r2763 | |
| 6225 | 7720 | case kMenu_ViewResult: |
| 6226 | 7721 | if(search->regionListLength) |
| 6227 | 7722 | { |
| 6228 | | /* ----- go to result viewer ----- */ |
| 7723 | /* go to result viewer */ |
| 6229 | 7724 | firstEntry = 1; |
| 6230 | 7725 | submenuChoice = 1; |
| 6231 | 7726 | } |
| 6232 | 7727 | else |
| 6233 | | /* ----- if no search region (eg, sms.c in HazeMD), don't open result viewer to avoid the crash ----- */ |
| 7728 | /* if no search region (eg, sms.c in HazeMD), don't open result viewer to avoid the crash */ |
| 6234 | 7729 | ui_popup_time(1, "no search regions"); |
| 6235 | 7730 | break; |
| 6236 | 7731 | |
| 6237 | 7732 | case kMenu_RestoreSearch: |
| 6238 | | /* ----- restore previous results ----- */ |
| 6239 | | RestoreSearchBackup(search); |
| 7733 | /* restore previous results */ |
| 7734 | restore_search_backup(search); |
| 6240 | 7735 | break; |
| 6241 | 7736 | |
| 6242 | 7737 | case kMenu_Return: |
| r2762 | r2763 | |
| 6250 | 7745 | } |
| 6251 | 7746 | } |
| 6252 | 7747 | |
| 6253 | | /* ----- edit selected field ----- */ |
| 7748 | /* edit selected field */ |
| 6254 | 7749 | if(editActive) |
| 6255 | 7750 | { |
| 6256 | 7751 | switch(sel) |
| 6257 | 7752 | { |
| 6258 | 7753 | case kMenu_Value: |
| 6259 | | search->value = DoEditHexField(machine, search->value); |
| 7754 | search->value = do_edit_hex_field(machine, search->value); |
| 6260 | 7755 | |
| 6261 | 7756 | search->value &= kSearchByteMaskTable[search->bytes]; |
| 6262 | 7757 | break; |
| r2762 | r2763 | |
| 6270 | 7765 | if(input_ui_pressed(machine, IPT_UI_CANCEL)) |
| 6271 | 7766 | sel = -1; |
| 6272 | 7767 | |
| 6273 | | /* ----- keep current cursor position ----- */ |
| 7768 | /* keep current cursor position */ |
| 6274 | 7769 | if(!(sel == -1)) |
| 6275 | 7770 | lastSel = sel; |
| 6276 | | |
| 6277 | | return sel + 1; |
| 7771 | #endif |
| 7772 | return menu->sel; |
| 6278 | 7773 | } |
| 6279 | 7774 | |
| 6280 | | /*--------------------------------------------------------------------- |
| 6281 | | SelectSearchRegions - management for search regions selection menu |
| 6282 | | ---------------------------------------------------------------------*/ |
| 7775 | /*--------------------------------------------------------------------------- |
| 7776 | select_search_region_menu - management for search regions selection menu |
| 7777 | ---------------------------------------------------------------------------*/ |
| 6283 | 7778 | |
| 6284 | | static int SelectSearchRegions(running_machine *machine, int selection, SearchInfo * search) |
| 7779 | static int select_search_region_menu(running_machine *machine, cheat_menu_stack *menu) |
| 6285 | 7780 | { |
| 6286 | | static const char *const kSearchSpeedList[] = |
| 7781 | static const char *const ksearch_speedList[] = |
| 6287 | 7782 | { |
| 6288 | 7783 | "Fast", |
| 6289 | 7784 | "Medium", |
| 6290 | 7785 | "Slow", |
| 6291 | 7786 | "Very Slow", |
| 6292 | | "All Memory" |
| 7787 | "All Memory", |
| 7788 | "User Defined" |
| 6293 | 7789 | }; |
| 6294 | 7790 | |
| 6295 | | INT32 sel; |
| 7791 | int total = 0; |
| 7792 | UINT8 doRebuild = 0; |
| 6296 | 7793 | const char ** menuItem; |
| 6297 | 7794 | const char ** menuSubItem; |
| 6298 | | INT32 i; |
| 6299 | | INT32 total = 0; |
| 6300 | | SearchRegion * region; |
| 7795 | search_info *search = get_current_search(); |
| 7796 | search_region *region; |
| 6301 | 7797 | |
| 6302 | | if(!search) |
| 6303 | | return 0; |
| 7798 | /* first setting : NONE */ |
| 7799 | if(menu->first_time) |
| 7800 | menu->first_time = 0; |
| 6304 | 7801 | |
| 6305 | | sel = selection - 1; |
| 7802 | /* required items = speed + total regions + return + terminator */ |
| 7803 | request_strings(search->region_list_length + 3, 0, 0, 0); |
| 7804 | menuItem = menu_strings.main_list; |
| 7805 | menuSubItem = menu_strings.sub_list; |
| 6306 | 7806 | |
| 6307 | | RequestStrings(search->regionListLength + 3, 0, 0, 0); |
| 6308 | | |
| 6309 | 7807 | /********** MENU CONSTRUCTION **********/ |
| 6310 | | menuItem = menuStrings.mainList; |
| 6311 | | menuSubItem = menuStrings.subList; |
| 7808 | /* ##### SEARCH SPEED ##### */ |
| 7809 | menuItem[total] = "Search Speed"; |
| 7810 | menuSubItem[total++] = ksearch_speedList[search->search_speed]; |
| 6312 | 7811 | |
| 6313 | | for(i = 0; i < search->regionListLength; i++) |
| 7812 | /* ##### REGIONS ##### */ |
| 7813 | if(search->region_list_length) |
| 6314 | 7814 | { |
| 6315 | | SearchRegion * traverse = &search->regionList[i]; |
| 7815 | int i; |
| 6316 | 7816 | |
| 6317 | | menuItem[total] = traverse->name; |
| 6318 | | menuSubItem[total++] = (traverse->flags & kRegionFlag_Enabled) ? "On" : "Off"; |
| 7817 | for(i = 0; i < search->region_list_length; i++) |
| 7818 | { |
| 7819 | search_region *region = &search->region_list[i]; |
| 7820 | |
| 7821 | menuItem[total] = region->name; |
| 7822 | menuSubItem[total++] = region->flags & kRegionFlag_Enabled ? "On" : "Off"; |
| 7823 | } |
| 6319 | 7824 | } |
| 7825 | else |
| 7826 | { |
| 7827 | /* in case of no SearchRegion */ |
| 7828 | menuItem[total] = "No Search Region"; |
| 7829 | menuSubItem[total++] = NULL; |
| 7830 | } |
| 6320 | 7831 | |
| 6321 | | menuItem[total] = "Search Speed"; |
| 6322 | | menuSubItem[total++] = kSearchSpeedList[search->searchSpeed]; |
| 6323 | | |
| 6324 | | menuItem[total] = "Return to Prior Menu"; // return item |
| 7832 | /* ##### RETURN ##### */ |
| 7833 | menuItem[total] = "Return to Prior Menu"; |
| 6325 | 7834 | menuSubItem[total++] = NULL; |
| 6326 | 7835 | |
| 6327 | | menuItem[total] = NULL; // terminate array |
| 7836 | /* ##### TERMINATE ARRAY ##### */ |
| 7837 | menuItem[total] = NULL; |
| 6328 | 7838 | menuSubItem[total] = NULL; |
| 6329 | 7839 | |
| 6330 | | /* ----- adjust current cursor positon ----- */ |
| 6331 | | if(sel < 0) |
| 6332 | | sel = 0; |
| 6333 | | if(sel > (total - 1)) |
| 6334 | | sel = total - 1; |
| 7840 | /* adjust current cursor position */ |
| 7841 | ADJUST_CURSOR(menu->sel, total) |
| 6335 | 7842 | |
| 6336 | | if(sel < search->regionListLength) |
| 6337 | | region = &search->regionList[sel]; |
| 7843 | /* draw it */ |
| 7844 | old_style_menu(menuItem, menuSubItem, NULL, menu->sel, 0); |
| 7845 | |
| 7846 | if(search->region_list_length && menu->sel && menu->sel < total -1) |
| 7847 | region = &search->region_list[menu->sel - 1]; |
| 6338 | 7848 | else |
| 6339 | 7849 | region = NULL; |
| 6340 | 7850 | |
| 6341 | | /* ----- draw it ----- */ |
| 6342 | | old_style_menu(menuItem, menuSubItem, NULL, sel, 0); |
| 6343 | | |
| 6344 | 7851 | /********** KEY HANDLING **********/ |
| 6345 | | if(UIPressedRepeatThrottle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate)) |
| 7852 | if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate)) |
| 6346 | 7853 | { |
| 6347 | | sel++; |
| 6348 | | |
| 6349 | | if(sel >= total) |
| 6350 | | sel = 0; |
| 7854 | CURSOR_TO_PREVIOUS(menu->sel, total) |
| 6351 | 7855 | } |
| 6352 | | |
| 6353 | | if(UIPressedRepeatThrottle(machine, IPT_UI_UP, kVerticalKeyRepeatRate)) |
| 7856 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate)) |
| 6354 | 7857 | { |
| 6355 | | sel--; |
| 6356 | | |
| 6357 | | if(sel < 0) |
| 6358 | | sel = total - 1; |
| 7858 | CURSOR_TO_NEXT(menu->sel, total) |
| 6359 | 7859 | } |
| 6360 | | |
| 6361 | | if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate)) |
| 7860 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate)) |
| 6362 | 7861 | { |
| 6363 | | sel -= fullMenuPageHeight; |
| 6364 | | |
| 6365 | | if(sel < 0) |
| 6366 | | sel = 0; |
| 7862 | CURSOR_PAGE_UP(menu->sel) |
| 6367 | 7863 | } |
| 6368 | | |
| 6369 | | if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate)) |
| 7864 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate)) |
| 6370 | 7865 | { |
| 6371 | | sel += fullMenuPageHeight; |
| 6372 | | |
| 6373 | | if(sel >= total) |
| 6374 | | sel = total - 1; |
| 7866 | CURSOR_PAGE_DOWN(menu->sel, total) |
| 6375 | 7867 | } |
| 6376 | | |
| 6377 | | if(UIPressedRepeatThrottle(machine, IPT_UI_LEFT, kHorizontalSlowKeyRepeatRate)) |
| 7868 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_LEFT, kHorizontalSlowKeyRepeatRate)) |
| 6378 | 7869 | { |
| 6379 | | if(sel < search->regionListLength) |
| 7870 | if(region) |
| 6380 | 7871 | { |
| 6381 | | search->regionList[sel].flags ^= kRegionFlag_Enabled; |
| 6382 | | |
| 6383 | | AllocateSearchRegions(search); |
| 7872 | /* toggle ON/OFF */ |
| 7873 | region->flags ^= kRegionFlag_Enabled; |
| 6384 | 7874 | } |
| 6385 | | |
| 6386 | | if(sel == search->regionListLength) // set search speed |
| 7875 | else if(!menu->sel) |
| 6387 | 7876 | { |
| 6388 | | if(search->searchSpeed > kSearchSpeed_Fast) |
| 6389 | | search->searchSpeed--; |
| 6390 | | else |
| 6391 | | search->searchSpeed = kSearchSpeed_Max; |
| 7877 | if(--search->search_speed < 0) |
| 7878 | /* "Fast" -> "User Defined" */ |
| 7879 | search->search_speed = ksearch_speed_Max - 1; |
| 6392 | 7880 | |
| 6393 | | BuildSearchRegions(machine, search); |
| 6394 | | AllocateSearchRegions(search); |
| 7881 | doRebuild = 1; |
| 6395 | 7882 | } |
| 6396 | 7883 | } |
| 6397 | | |
| 6398 | | if(UIPressedRepeatThrottle(machine, IPT_UI_RIGHT, kHorizontalSlowKeyRepeatRate)) |
| 7884 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_RIGHT, kHorizontalSlowKeyRepeatRate)) |
| 6399 | 7885 | { |
| 6400 | | if(sel < search->regionListLength) |
| 7886 | if(region) |
| 6401 | 7887 | { |
| 6402 | | search->regionList[sel].flags ^= kRegionFlag_Enabled; |
| 6403 | | |
| 6404 | | AllocateSearchRegions(search); |
| 7888 | /* toggle ON/OFF */ |
| 7889 | region->flags ^= kRegionFlag_Enabled; |
| 6405 | 7890 | } |
| 6406 | | |
| 6407 | | if(sel == search->regionListLength) // set search speed |
| 7891 | else if(!menu->sel) |
| 6408 | 7892 | { |
| 6409 | | if(search->searchSpeed < kSearchSpeed_Max) |
| 6410 | | search->searchSpeed++; |
| 6411 | | else |
| 6412 | | search->searchSpeed = kSearchSpeed_Fast; |
| 7893 | if(++search->search_speed >= ksearch_speed_Max) |
| 7894 | /* "User Defined" -> "Fast" */ |
| 7895 | search->search_speed = ksearch_speed_Fast; |
| 6413 | 7896 | |
| 6414 | | BuildSearchRegions(machine, search); |
| 6415 | | AllocateSearchRegions(search); |
| 7897 | doRebuild = 1; |
| 6416 | 7898 | } |
| 6417 | 7899 | } |
| 6418 | | |
| 6419 | | if(input_ui_pressed(machine, IPT_UI_DELETE_CHEAT)) |
| 7900 | else if(input_ui_pressed(machine, IPT_UI_DELETE_CHEAT)) |
| 6420 | 7901 | { |
| 6421 | | if(ShiftKeyPressed()) // shift + delete = invalid region |
| 7902 | if(ShiftKeyPressed() && region && search) |
| 6422 | 7903 | { |
| 6423 | | if(region && search) |
| 6424 | | { |
| 6425 | | InvalidateEntireRegion(search, region); |
| 6426 | | |
| 6427 | | ui_popup_time(1, "region invalidated - %d results remain", search->numResults); |
| 6428 | | } |
| 7904 | /* SHIFT + CHEAT DELETE = invalidate selected region */ |
| 7905 | invalidate_entire_region(search, region); |
| 7906 | // ui_popup_time(1, "region invalidated - %d results remain", search->num_results); |
| 6429 | 7907 | } |
| 6430 | 7908 | } |
| 7909 | else if(input_ui_pressed(machine, IPT_UI_RELOAD_CHEAT)) |
| 7910 | { |
| 7911 | if(search->search_speed == ksearch_speed_UserDefined) |
| 7912 | /* reload user region */ |
| 7913 | doRebuild = 1; |
| 7914 | } |
| 7915 | else if(input_ui_pressed(machine, IPT_UI_SELECT)) |
| 7916 | { |
| 7917 | if(region) |
| 7918 | region->flags ^= kRegionFlag_Enabled; |
| 7919 | else if(!menu->sel) |
| 7920 | doRebuild = 1; |
| 7921 | else |
| 7922 | menu->sel = -1; |
| 7923 | } |
| 7924 | else if(input_ui_pressed(machine, IPT_UI_CANCEL)) |
| 7925 | menu->sel = -1; |
| 6431 | 7926 | |
| 6432 | | if(input_ui_pressed(machine, IPT_UI_SELECT)) |
| 7927 | /********** REBUILD SEARCH REGION **********/ |
| 7928 | if(doRebuild) |
| 6433 | 7929 | { |
| 6434 | | if(sel >= total - 1) |
| 6435 | | sel = -1; |
| 7930 | if(search->search_speed != ksearch_speed_UserDefined) |
| 7931 | /* rebuild SearchRegion from memory map */ |
| 7932 | build_search_regions(machine, search); |
| 7933 | else |
| 7934 | /* rebuild SearchRegion from user-defined map */ |
| 7935 | LoadCheatDatabase(machine, kLoadFlag_UserRegion); |
| 7936 | |
| 7937 | /* reallocate SearchRegions */ |
| 7938 | allocate_search_regions(search); |
| 6436 | 7939 | } |
| 6437 | 7940 | |
| 6438 | | if(input_ui_pressed(machine, IPT_UI_CANCEL)) |
| 6439 | | sel = -1; |
| 6440 | | |
| 6441 | | return sel + 1; |
| 7941 | return menu->sel + 1; |
| 6442 | 7942 | } |
| 6443 | 7943 | |
| 6444 | | /*-------------------------------------------------------- |
| 6445 | | ViewSearchResults - management for search result menu |
| 6446 | | --------------------------------------------------------*/ |
| 7944 | /*-------------------------------------------------------------- |
| 7945 | view_search_result_menu - management for search result menu |
| 7946 | --------------------------------------------------------------*/ |
| 6447 | 7947 | |
| 6448 | | static int ViewSearchResults(running_machine *machine, int selection, int firstTime) |
| 7948 | static int view_search_result_menu(running_machine *machine, cheat_menu_stack *menu) |
| 6449 | 7949 | { |
| 6450 | | enum |
| 6451 | | { |
| 7950 | enum{ |
| 6452 | 7951 | kMenu_Header = 0, |
| 6453 | 7952 | kMenu_FirstResult, |
| 6454 | 7953 | |
| 6455 | | kMaxResultsPerPage = 100 |
| 6456 | | }; |
| 7954 | kMaxResultsPerPage = 100 }; |
| 6457 | 7955 | |
| 7956 | int i; |
| 7957 | int total = 0; |
| 7958 | int numPages; |
| 7959 | int resultsPerPage; |
| 7960 | int numToSkip; |
| 7961 | UINT8 hadResults = 0; |
| 7962 | UINT8 pageSwitch = 0; |
| 7963 | UINT8 resultsFound = 0; |
| 7964 | UINT8 selectedAddressGood = 0; |
| 7965 | UINT32 selectedAddress = 0; |
| 7966 | UINT32 selectedOffset = 0; |
| 7967 | UINT32 traverse; |
| 6458 | 7968 | const char ** menu_item; |
| 6459 | 7969 | char ** buf; |
| 6460 | 7970 | char * header; |
| 7971 | search_info *search = get_current_search(); |
| 7972 | search_region *region; |
| 6461 | 7973 | |
| 6462 | | SearchInfo * search = GetCurrentSearch(); |
| 6463 | | SearchRegion * region; |
| 6464 | | |
| 6465 | | INT32 sel; |
| 6466 | | INT32 total = 0; |
| 6467 | | INT32 numPages; |
| 6468 | | INT32 resultsPerPage; |
| 6469 | | INT32 i; |
| 6470 | | UINT32 traverse; |
| 6471 | | UINT8 hadResults = 0; |
| 6472 | | INT32 numToSkip; |
| 6473 | | UINT32 resultsFound = 0; |
| 6474 | | UINT32 selectedAddress = 0; |
| 6475 | | UINT32 selectedOffset = 0; |
| 6476 | | UINT8 selectedAddressGood = 0; |
| 6477 | | int goToNextPage = 0; |
| 6478 | | int goToPrevPage = 0; |
| 6479 | | |
| 6480 | | RequestStrings(kMaxResultsPerPage + 3, kMaxResultsPerPage + 3, 80, 0); |
| 6481 | | |
| 6482 | | menu_item = menuStrings.mainList; |
| 6483 | | buf = &menuStrings.mainStrings[1]; |
| 6484 | | header = menuStrings.mainStrings[0]; |
| 6485 | | |
| 6486 | | sel = selection - 1; |
| 6487 | | |
| 6488 | | /********** FIRST SETTING **********/ |
| 6489 | | if(firstTime) |
| 7974 | /* first setting : initialize region index and page number */ |
| 7975 | if(menu->first_time) |
| 6490 | 7976 | { |
| 6491 | | search->currentRegionIdx = 0; |
| 6492 | | search->currentResultsPage = 0; |
| 7977 | search->current_region_idx = 0; |
| 7978 | search->current_results_page = 0; |
| 6493 | 7979 | |
| 6494 | | /* ----- set current REGION for first display ----- */ |
| 6495 | | for(traverse = 0; traverse < search->regionListLength; traverse++) |
| 7980 | /* set current REGION for first display */ |
| 7981 | for(traverse = 0; traverse < search->region_list_length; traverse++) |
| 6496 | 7982 | { |
| 6497 | | region = &search->regionList[traverse]; |
| 7983 | region = &search->region_list[traverse]; |
| 6498 | 7984 | |
| 6499 | | if(region->numResults) |
| 7985 | if(region->num_results) |
| 6500 | 7986 | { |
| 6501 | | search->currentRegionIdx = traverse; |
| 7987 | search->current_region_idx = traverse; |
| 6502 | 7988 | break; |
| 6503 | 7989 | } |
| 6504 | 7990 | } |
| 7991 | |
| 7992 | menu->first_time = 0; |
| 6505 | 7993 | } |
| 6506 | 7994 | |
| 6507 | | /* ----- adjust current REGION ----- */ |
| 6508 | | if(search->currentRegionIdx >= search->regionListLength) |
| 6509 | | search->currentRegionIdx = search->regionListLength - 1; |
| 6510 | | if(search->currentRegionIdx < 0) |
| 6511 | | search->currentRegionIdx = 0; |
| 7995 | /* required items = (header + defined max items + return + terminator) & (strings buf * (header + defined max items) [max chars = 32]) */ |
| 7996 | request_strings(kMaxResultsPerPage + 3, kMaxResultsPerPage, 32, 0); |
| 7997 | menu_item = menu_strings.main_list; |
| 7998 | header = menu_strings.main_strings[0]; |
| 7999 | buf = &menu_strings.main_strings[1]; |
| 6512 | 8000 | |
| 6513 | | region = &search->regionList[search->currentRegionIdx]; |
| 8001 | /* adjust current REGION */ |
| 8002 | if(search->current_region_idx >= search->region_list_length) |
| 8003 | search->current_region_idx = search->region_list_length - 1; |
| 8004 | if(search->current_region_idx < 0) |
| 8005 | search->current_region_idx = 0; |
| 6514 | 8006 | |
| 6515 | | /* ----- set and adjust maximum displayable result in the PAGE ----- */ |
| 8007 | region = &search->region_list[search->current_region_idx]; |
| 8008 | |
| 8009 | /* set the number of items per PAGE */ |
| 6516 | 8010 | resultsPerPage = fullMenuPageHeight - 3; |
| 6517 | 8011 | |
| 8012 | /* adjust total items per PAGE */ |
| 6518 | 8013 | if(resultsPerPage <= 0) |
| 6519 | 8014 | resultsPerPage = 1; |
| 6520 | 8015 | else if(resultsPerPage > kMaxResultsPerPage) |
| 6521 | 8016 | resultsPerPage = kMaxResultsPerPage; |
| 6522 | 8017 | |
| 6523 | | /* ----- get the number of total page ----- */ |
| 8018 | /* get the number of total PAGEs */ |
| 6524 | 8019 | if(region->flags & kRegionFlag_Enabled) |
| 6525 | | numPages = (region->numResults / kSearchByteStep[search->bytes] + resultsPerPage - 1) / resultsPerPage; |
| 8020 | numPages = (region->num_results / kSearchByteStep[search->bytes] + resultsPerPage - 1) / resultsPerPage; |
| 6526 | 8021 | else |
| 6527 | 8022 | numPages = 0; |
| 6528 | 8023 | |
| 6529 | | /* ----- adjust current PAGE ----- */ |
| 6530 | | if(search->currentResultsPage >= numPages) |
| 6531 | | search->currentResultsPage = numPages - 1; |
| 6532 | | if(search->currentResultsPage < 0) |
| 6533 | | search->currentResultsPage = 0; |
| 8024 | if(numPages > fullMenuPageHeight) |
| 8025 | numPages = fullMenuPageHeight; |
| 6534 | 8026 | |
| 6535 | | /* ----- set the number of undisplay result ----- */ |
| 6536 | | numToSkip = resultsPerPage * search->currentResultsPage; |
| 8027 | /* adjust current PAGE */ |
| 8028 | if(search->current_results_page >= numPages) |
| 8029 | search->current_results_page = numPages - 1; |
| 8030 | if(search->current_results_page < 0) |
| 8031 | search->current_results_page = 0; |
| 6537 | 8032 | |
| 8033 | /* set the number of skipping results to undisplay */ |
| 8034 | numToSkip = resultsPerPage * search->current_results_page; |
| 8035 | |
| 6538 | 8036 | /********** MENU CONSTRUCTION **********/ |
| 6539 | | /* ----- construct header item ----- */ |
| 6540 | | sprintf(header, "%s %d/%d", region->name, search->currentResultsPage + 1, numPages); |
| 8037 | /* ##### HEADER ##### */ |
| 8038 | sprintf(header, "%s %d/%d", region->name, search->current_results_page + 1, numPages); |
| 6541 | 8039 | |
| 6542 | 8040 | menu_item[total++] = header; |
| 6543 | 8041 | |
| 6544 | 8042 | traverse = 0; |
| 6545 | 8043 | |
| 6546 | 8044 | if((region->length < kSearchByteIncrementTable[search->bytes]) || !(region->flags & kRegionFlag_Enabled)) |
| 8045 | { |
| 6547 | 8046 | ; // no results... |
| 8047 | } |
| 6548 | 8048 | else |
| 6549 | 8049 | { |
| 6550 | | /* ----- construct result item ----- */ |
| 6551 | | for(i = 0; (i < resultsPerPage) && (traverse < region->length) && (resultsFound < region->numResults);) |
| 8050 | /* ##### RESULT ##### */ |
| 8051 | for(i = 0; i < resultsPerPage && traverse < region->length && resultsFound < region->num_results;) |
| 6552 | 8052 | { |
| 6553 | | while(!IsRegionOffsetValid(search, region, traverse) && (traverse < region->length)) |
| 8053 | while(is_region_offset_valid(search, region, traverse) == 0 && traverse < region->length) |
| 6554 | 8054 | traverse += kSearchByteStep[search->bytes]; |
| 6555 | 8055 | |
| 6556 | 8056 | if(traverse < region->length) |
| r2762 | r2763 | |
| 6559 | 8059 | numToSkip--; |
| 6560 | 8060 | else |
| 6561 | 8061 | { |
| 6562 | | if(total == sel) |
| 8062 | if(total == menu->sel) |
| 6563 | 8063 | { |
| 6564 | | selectedAddress = region->address + traverse; |
| 6565 | | selectedOffset = traverse; |
| 6566 | | selectedAddressGood = 1; |
| 8064 | selectedAddress = region->address + traverse; |
| 8065 | selectedOffset = traverse; |
| 8066 | selectedAddressGood = 1; |
| 6567 | 8067 | } |
| 6568 | 8068 | |
| 6569 | 8069 | sprintf( buf[total], |
| 6570 | 8070 | "%.8X (%.*X %.*X %.*X)", |
| 6571 | 8071 | region->address + traverse, |
| 6572 | 8072 | kSearchByteDigitsTable[search->bytes], |
| 6573 | | ReadSearchOperand(kSearchOperand_First, search, region, region->address + traverse), |
| 8073 | read_search_operand(kSearchOperand_First, search, region, region->address + traverse), |
| 6574 | 8074 | kSearchByteDigitsTable[search->bytes], |
| 6575 | | ReadSearchOperand(kSearchOperand_Previous, search, region, region->address + traverse), |
| 8075 | read_search_operand(kSearchOperand_Previous, search, region, region->address + traverse), |
| 6576 | 8076 | kSearchByteDigitsTable[search->bytes], |
| 6577 | | ReadSearchOperand(kSearchOperand_Current, search, region, region->address + traverse)); |
| 8077 | read_search_operand(kSearchOperand_Current, search, region, region->address + traverse)); |
| 6578 | 8078 | |
| 6579 | 8079 | menu_item[total] = buf[total]; |
| 6580 | 8080 | total++; |
| r2762 | r2763 | |
| 6589 | 8089 | } |
| 6590 | 8090 | } |
| 6591 | 8091 | |
| 6592 | | /* ----- set special message if empty REGION ----- */ |
| 8092 | /* set special message if empty REGION */ |
| 6593 | 8093 | if(!hadResults) |
| 6594 | 8094 | { |
| 6595 | | if(search->numResults) |
| 8095 | if(search->num_results) |
| 6596 | 8096 | menu_item[total++] = "no results for this region"; |
| 6597 | 8097 | else |
| 6598 | 8098 | menu_item[total++] = "no results found"; |
| 6599 | 8099 | } |
| 6600 | 8100 | |
| 6601 | | menu_item[total++] = "Return to Prior Menu"; // return |
| 8101 | /* ##### RETURN ##### */ |
| 8102 | menu_item[total++] = "Return to Prior Menu"; |
| 6602 | 8103 | |
| 6603 | | menu_item[total] = NULL; // terminate array |
| 8104 | /* ##### TERMINATE ARRAY ##### */ |
| 8105 | menu_item[total] = NULL; |
| 6604 | 8106 | |
| 6605 | | /* ----- adjust current cursor position ----- */ |
| 6606 | | if(sel <= kMenu_Header) |
| 6607 | | sel = kMenu_FirstResult; |
| 6608 | | if(sel > (total - 1) || !hadResults) |
| 6609 | | sel = total - 1; |
| 8107 | /* adjust current cursor position */ |
| 8108 | if(menu->sel <= kMenu_Header) |
| 8109 | menu->sel = kMenu_FirstResult; |
| 8110 | if(menu->sel > total - 1 || !hadResults) |
| 8111 | menu->sel = total - 1; |
| 6610 | 8112 | |
| 6611 | | /* ----- draw it ----- */ |
| 6612 | | old_style_menu(menu_item, NULL, NULL, sel, 0); |
| 8113 | /* draw it */ |
| 8114 | old_style_menu(menu_item, NULL, NULL, menu->sel, 0); |
| 6613 | 8115 | |
| 6614 | 8116 | /********** KEY HANDLING **********/ |
| 6615 | | if(UIPressedRepeatThrottle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate)) |
| 8117 | if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate)) |
| 6616 | 8118 | { |
| 6617 | | sel++; |
| 6618 | | |
| 6619 | | if(sel >= total) |
| 6620 | | sel = kMenu_FirstResult; |
| 8119 | if(--menu->sel < 1) |
| 8120 | menu->sel = total - 1; |
| 6621 | 8121 | } |
| 6622 | | |
| 6623 | | if(UIPressedRepeatThrottle(machine, IPT_UI_UP, kVerticalKeyRepeatRate)) |
| 8122 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate)) |
| 6624 | 8123 | { |
| 6625 | | sel--; |
| 6626 | | |
| 6627 | | if(sel < 1) |
| 6628 | | sel = total - 1; |
| 8124 | if(++menu->sel >= total) |
| 8125 | menu->sel = kMenu_FirstResult; |
| 6629 | 8126 | } |
| 6630 | | |
| 6631 | | if(UIPressedRepeatThrottle(machine, IPT_UI_RIGHT, kHorizontalFastKeyRepeatRate)) |
| 8127 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_RIGHT, kHorizontalFastKeyRepeatRate)) |
| 6632 | 8128 | { |
| 6633 | 8129 | if(ShiftKeyPressed()) |
| 6634 | | search->currentResultsPage = numPages - 1; // shift + right = go to last PAGE |
| 6635 | | else |
| 6636 | 8130 | { |
| 6637 | | if(ControlKeyPressed()) |
| 6638 | | { |
| 6639 | | search->currentRegionIdx++; // ctrl + right = go to next REGION |
| 8131 | /* shift + right = go to last PAGE */ |
| 8132 | search->current_results_page = numPages - 1; |
| 8133 | } |
| 8134 | else if(ControlKeyPressed()) |
| 8135 | { |
| 8136 | /* ctrl + right = go to next REGION */ |
| 8137 | search->current_region_idx++; |
| 6640 | 8138 | |
| 6641 | | if(search->currentRegionIdx >= search->regionListLength) |
| 6642 | | search->currentRegionIdx = 0; |
| 6643 | | } |
| 6644 | | else |
| 6645 | | goToNextPage = 1; // right = go to next PAGE |
| 8139 | if(search->current_region_idx >= search->region_list_length) |
| 8140 | search->current_region_idx = 0; |
| 6646 | 8141 | } |
| 8142 | else |
| 8143 | { |
| 8144 | /* otherwise, go to next PAGE */ |
| 8145 | pageSwitch = 1; |
| 8146 | } |
| 6647 | 8147 | |
| 6648 | | sel = kMenu_FirstResult; |
| 8148 | menu->sel = kMenu_FirstResult; |
| 6649 | 8149 | } |
| 6650 | | |
| 6651 | | if(UIPressedRepeatThrottle(machine, IPT_UI_LEFT, kHorizontalFastKeyRepeatRate)) |
| 8150 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_LEFT, kHorizontalFastKeyRepeatRate)) |
| 6652 | 8151 | { |
| 6653 | 8152 | if(ShiftKeyPressed()) |
| 6654 | | search->currentResultsPage = 0; // shift + left = go to first PAGE |
| 6655 | | else |
| 6656 | 8153 | { |
| 6657 | | if(ControlKeyPressed()) |
| 6658 | | { |
| 6659 | | search->currentRegionIdx--; // ctrl + left = go to previous REGION |
| 8154 | /* shift + left = go to first PAGE */ |
| 8155 | search->current_results_page = 0; |
| 8156 | } |
| 8157 | else if(ControlKeyPressed()) |
| 8158 | { |
| 8159 | /* ctrl + left = go to previous REGION */ |
| 8160 | search->current_region_idx--; |
| 6660 | 8161 | |
| 6661 | | if(search->currentRegionIdx < 0) |
| 6662 | | search->currentRegionIdx = search->regionListLength - 1; |
| 6663 | | } |
| 6664 | | else |
| 6665 | | goToPrevPage = 1; // left = go to previous PAGE |
| 8162 | if(search->current_region_idx < 0) |
| 8163 | search->current_region_idx = search->region_list_length - 1; |
| 6666 | 8164 | } |
| 8165 | else |
| 8166 | { |
| 8167 | /* otherwise, go to previous PAGE */ |
| 8168 | pageSwitch = 2; |
| 8169 | } |
| 6667 | 8170 | |
| 6668 | | sel = kMenu_FirstResult; |
| 8171 | menu->sel = kMenu_FirstResult; |
| 6669 | 8172 | } |
| 6670 | | |
| 6671 | | if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_UP, kHorizontalFastKeyRepeatRate)) |
| 8173 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kHorizontalFastKeyRepeatRate)) |
| 6672 | 8174 | { |
| 6673 | | sel -=fullMenuPageHeight; |
| 8175 | menu->sel -=fullMenuPageHeight; |
| 6674 | 8176 | |
| 6675 | | if(sel <= kMenu_Header) |
| 6676 | | sel = kMenu_FirstResult; |
| 8177 | if(menu->sel <= kMenu_Header) |
| 8178 | menu->sel = kMenu_FirstResult; |
| 6677 | 8179 | } |
| 6678 | | |
| 6679 | | if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_DOWN, kHorizontalFastKeyRepeatRate)) |
| 8180 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kHorizontalFastKeyRepeatRate)) |
| 6680 | 8181 | { |
| 6681 | | sel +=fullMenuPageHeight; |
| 8182 | menu->sel +=fullMenuPageHeight; |
| 6682 | 8183 | |
| 6683 | | if(sel >= total) |
| 6684 | | sel = total - 1; |
| 8184 | if(menu->sel >= total) |
| 8185 | menu->sel = total - 1; |
| 6685 | 8186 | } |
| 6686 | | |
| 6687 | | if(input_code_pressed_once(KEYCODE_END)) |
| 6688 | | search->currentResultsPage = numPages - 1; // go to last PAGE |
| 6689 | | |
| 6690 | | if(input_code_pressed_once(KEYCODE_HOME)) |
| 6691 | | search->currentResultsPage = 0; // go to first PAGE |
| 6692 | | |
| 6693 | | if(UIPressedRepeatThrottle(machine, IPT_UI_PREV_GROUP, kVerticalKeyRepeatRate)) |
| 8187 | else if(input_code_pressed_once(KEYCODE_HOME)) |
| 6694 | 8188 | { |
| 6695 | | search->currentRegionIdx--; // go to previous REGION |
| 8189 | /* go to first PAGE */ |
| 8190 | search->current_results_page = 0; |
| 8191 | } |
| 8192 | else if(input_code_pressed_once(KEYCODE_END)) |
| 8193 | { |
| 8194 | /* go to last PAGE */ |
| 8195 | search->current_results_page = numPages - 1; |
| 8196 | } |
| 8197 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_PREV_GROUP, kVerticalKeyRepeatRate)) |
| 8198 | { |
| 8199 | /* go to previous REGION */ |
| 8200 | search->current_region_idx--; |
| 6696 | 8201 | |
| 6697 | | if(search->currentRegionIdx < 0) |
| 6698 | | search->currentRegionIdx = search->regionListLength - 1; |
| 8202 | if(search->current_region_idx < 0) |
| 8203 | search->current_region_idx = search->region_list_length - 1; |
| 6699 | 8204 | |
| 6700 | | sel = kMenu_FirstResult; |
| 8205 | menu->sel = kMenu_FirstResult; |
| 6701 | 8206 | } |
| 6702 | | |
| 6703 | | if(UIPressedRepeatThrottle(machine, IPT_UI_NEXT_GROUP, kVerticalKeyRepeatRate)) |
| 8207 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_NEXT_GROUP, kVerticalKeyRepeatRate)) |
| 6704 | 8208 | { |
| 6705 | | search->currentRegionIdx++; // go to next REGION |
| 8209 | /* go to next REGION */ |
| 8210 | search->current_region_idx++; |
| 6706 | 8211 | |
| 6707 | | if(search->currentRegionIdx >= search->regionListLength) |
| 6708 | | search->currentRegionIdx = 0; |
| 8212 | if(search->current_region_idx >= search->region_list_length) |
| 8213 | search->current_region_idx = 0; |
| 6709 | 8214 | |
| 6710 | | sel = kMenu_FirstResult; |
| 8215 | menu->sel = kMenu_FirstResult; |
| 6711 | 8216 | } |
| 6712 | | |
| 6713 | | if(goToNextPage) |
| 8217 | else if(input_ui_pressed(machine, IPT_UI_ADD_CHEAT)) |
| 6714 | 8218 | { |
| 6715 | | search->currentResultsPage++; |
| 6716 | | |
| 6717 | | /* ----- if current PAGE is the last, go to first PAGE in next REGION ----- */ |
| 6718 | | if(search->currentResultsPage >= numPages) |
| 8219 | if(selectedAddressGood) |
| 8220 | AddCheatFromResult(search, region, selectedAddress); |
| 8221 | } |
| 8222 | else if(input_ui_pressed(machine, IPT_UI_DELETE_CHEAT)) |
| 8223 | { |
| 8224 | if(ShiftKeyPressed()) |
| 6719 | 8225 | { |
| 6720 | | search->currentResultsPage = 0; |
| 6721 | | search->currentRegionIdx++; |
| 8226 | if(region && search) |
| 8227 | /* shift + delete = invalidate all results in current REGION */ |
| 8228 | invalidate_entire_region(search, region); |
| 8229 | } |
| 8230 | else if(selectedAddressGood) |
| 8231 | { |
| 8232 | /* otherwise, delete selected result */ |
| 8233 | invalidate_region_offset(search, region, selectedOffset); |
| 8234 | search->num_results--; |
| 8235 | region->num_results--; |
| 6722 | 8236 | |
| 6723 | | /* ----- if current REGION is the last, go to first REGION ----- */ |
| 6724 | | if(search->currentRegionIdx >= search->regionListLength) |
| 6725 | | search->currentRegionIdx = 0; |
| 6726 | | |
| 6727 | | /* ----- if next REGION is empty, search next "non-empty" REGION. |
| 6728 | | but incomplete because last REGION is displayed even if empty ----- */ |
| 6729 | | for(traverse = search->currentRegionIdx; traverse < search->regionListLength; traverse++) |
| 6730 | | { |
| 6731 | | search->currentRegionIdx = traverse; |
| 6732 | | |
| 6733 | | if(search->regionList[traverse].numResults) |
| 6734 | | break; |
| 6735 | | } |
| 8237 | messageType = kCheatMessage_SucceededToDelete; |
| 8238 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 6736 | 8239 | } |
| 6737 | | |
| 6738 | | sel = kMenu_FirstResult; |
| 6739 | 8240 | } |
| 8241 | else if(input_ui_pressed(machine, IPT_UI_WATCH_VALUE)) |
| 8242 | { |
| 8243 | if(selectedAddressGood) |
| 8244 | AddWatchFromResult(search, region, selectedAddress); |
| 8245 | } |
| 8246 | else if(input_ui_pressed(machine, IPT_UI_SELECT) || input_ui_pressed(machine, IPT_UI_CANCEL)) |
| 8247 | menu->sel = -1; |
| 6740 | 8248 | |
| 6741 | | if(goToPrevPage) |
| 8249 | switch(pageSwitch) |
| 6742 | 8250 | { |
| 6743 | | search->currentResultsPage--; |
| 8251 | case 1: // go to next PAGE |
| 8252 | search->current_results_page++; |
| 6744 | 8253 | |
| 6745 | | /* ----- if current PAGE is first, go to previous REGION ----- */ |
| 6746 | | if(search->currentResultsPage < 0) |
| 6747 | | { |
| 6748 | | search->currentResultsPage = 0; |
| 6749 | | search->currentRegionIdx--; |
| 8254 | /* if current PAGE is the last, go to first PAGE in next REGION */ |
| 8255 | if(search->current_results_page >= numPages) |
| 8256 | { |
| 8257 | search->current_results_page = 0; |
| 8258 | search->current_region_idx++; |
| 6750 | 8259 | |
| 6751 | | /* ----- if current REGION is first, go to last REGION ----- */ |
| 6752 | | if(search->currentRegionIdx < 0) |
| 6753 | | search->currentRegionIdx = search->regionListLength - 1; |
| 8260 | /* if current REGION is the last, go to first REGION */ |
| 8261 | if(search->current_region_idx >= search->region_list_length) |
| 8262 | search->current_region_idx = 0; |
| 6754 | 8263 | |
| 6755 | | /* ----- if previous REGION is empty, search previous "non-empty" REGION. |
| 6756 | | but incomplete because first REGION is displayed even if empty ----- */ |
| 6757 | | for(i = search->currentRegionIdx; i >= 0; i--) |
| 6758 | | { |
| 6759 | | search->currentRegionIdx = i; |
| 8264 | /* if next REGION is empty, search next "non-empty" REGION. |
| 8265 | but incomplete because last REGION is displayed even if empty */ |
| 8266 | for(traverse = search->current_region_idx; traverse < search->region_list_length; traverse++) |
| 8267 | { |
| 8268 | search->current_region_idx = traverse; |
| 6760 | 8269 | |
| 6761 | | if(search->regionList[i].numResults) |
| 6762 | | break; |
| 8270 | if(search->region_list[traverse].num_results) |
| 8271 | break; |
| 8272 | } |
| 6763 | 8273 | } |
| 6764 | 8274 | |
| 6765 | | /* ----- go to last PAGE in previous REGION ----- */ |
| 6766 | | { |
| 6767 | | /* ----- get the number of total page for previous REGION ----- */ |
| 6768 | | SearchRegion * newRegion = &search->regionList[search->currentRegionIdx]; |
| 6769 | | UINT32 nextNumPages = (newRegion->numResults / kSearchByteStep[search->bytes] + resultsPerPage - 1) / resultsPerPage; |
| 8275 | menu->sel = kMenu_FirstResult; |
| 8276 | break; |
| 6770 | 8277 | |
| 6771 | | if(nextNumPages <= 0) |
| 6772 | | nextNumPages = 1; |
| 8278 | case 2: // go to previous PAGE |
| 8279 | search->current_results_page--; |
| 6773 | 8280 | |
| 6774 | | search->currentResultsPage = nextNumPages - 1; |
| 6775 | | } |
| 6776 | | } |
| 8281 | /* if current PAGE is first, go to previous REGION */ |
| 8282 | if(search->current_results_page < 0) |
| 8283 | { |
| 8284 | search->current_results_page = 0; |
| 8285 | search->current_region_idx--; |
| 6777 | 8286 | |
| 6778 | | sel = kMenu_FirstResult; |
| 6779 | | } |
| 8287 | /* if current REGION is first, go to last REGION */ |
| 8288 | if(search->current_region_idx < 0) |
| 8289 | search->current_region_idx = search->region_list_length - 1; |
| 6780 | 8290 | |
| 6781 | | if(selectedAddressGood) |
| 6782 | | { |
| 6783 | | if(input_ui_pressed(machine, IPT_UI_WATCH_VALUE)) |
| 6784 | | AddWatchFromResult(search, region, selectedAddress); // watch selected result |
| 8291 | /* if previous REGION is empty, search previous "non-empty" REGION. |
| 8292 | but incomplete because first REGION is displayed even if empty */ |
| 8293 | for(i = search->current_region_idx; i >= 0; i--) |
| 8294 | { |
| 8295 | search->current_region_idx = i; |
| 6785 | 8296 | |
| 6786 | | if(input_ui_pressed(machine, IPT_UI_ADD_CHEAT)) |
| 6787 | | AddCheatFromResult(search, region, selectedAddress); // add selected result as new code to cheat list |
| 8297 | if(search->region_list[i].num_results) |
| 8298 | break; |
| 8299 | } |
| 6788 | 8300 | |
| 6789 | | if(input_ui_pressed(machine, IPT_UI_DELETE_CHEAT)) |
| 6790 | | { |
| 6791 | | InvalidateRegionOffset(search, region, selectedOffset); // delete selected result |
| 6792 | | search->numResults--; |
| 6793 | | region->numResults--; |
| 6794 | | } |
| 6795 | | } |
| 8301 | /* go to last PAGE in previous REGION */ |
| 8302 | { |
| 8303 | /* get the number of total PAGEs for previous REGION */ |
| 8304 | search_region *new_region = &search->region_list[search->current_region_idx]; |
| 8305 | UINT32 nextNumPages = (new_region->num_results / kSearchByteStep[search->bytes] + resultsPerPage - 1) / resultsPerPage; |
| 6796 | 8306 | |
| 6797 | | if(input_ui_pressed(machine, IPT_UI_DELETE_CHEAT)) |
| 6798 | | { |
| 6799 | | if(ShiftKeyPressed()) |
| 6800 | | { |
| 6801 | | if(region && search) |
| 6802 | | { |
| 6803 | | InvalidateEntireRegion(search, region); // invalidate all results in current REGION |
| 8307 | if(nextNumPages <= 0) |
| 8308 | nextNumPages = 1; |
| 6804 | 8309 | |
| 6805 | | ui_popup_time(1, "region invalidated - %d results remain", search->numResults); |
| 8310 | search->current_results_page = nextNumPages - 1; |
| 8311 | } |
| 6806 | 8312 | } |
| 6807 | | } |
| 8313 | |
| 8314 | menu->sel = kMenu_FirstResult; |
| 8315 | break; |
| 6808 | 8316 | } |
| 6809 | 8317 | |
| 6810 | | if((input_ui_pressed(machine, IPT_UI_SELECT) && (sel == total - 1)) || input_ui_pressed(machine, IPT_UI_CANCEL)) |
| 6811 | | sel = -1; |
| 6812 | | |
| 6813 | | return sel + 1; |
| 8318 | return menu->sel + 1; |
| 6814 | 8319 | } |
| 6815 | 8320 | |
| 6816 | | /*---------------------------------------------------- |
| 6817 | | ChooseWatch - management for watchpoint list menu |
| 6818 | | ----------------------------------------------------*/ |
| 8321 | /*---------------------------------------------------------- |
| 8322 | choose_watch_menu - management for watchpoint list menu |
| 8323 | ----------------------------------------------------------*/ |
| 6819 | 8324 | |
| 6820 | | static int ChooseWatch(running_machine *machine, int selection) |
| 8325 | static int choose_watch_menu(running_machine *machine, cheat_menu_stack *menu) |
| 6821 | 8326 | { |
| 8327 | int i; |
| 8328 | UINT8 total = 0; |
| 6822 | 8329 | const char ** menuItem; |
| 6823 | 8330 | char ** buf; |
| 6824 | | |
| 8331 | char * stringsBuf; // "USER20 FFFFFFFF (99:32 Bit)" 27 chars |
| 6825 | 8332 | WatchInfo * watch; |
| 6826 | 8333 | |
| 6827 | | static INT32 submenuChoice = 0; |
| 6828 | | static INT32 submenuWatch = 0; |
| 6829 | | INT32 sel; |
| 6830 | | INT32 total = 0; |
| 6831 | | int i; |
| 8334 | /* first setting : NONE */ |
| 8335 | if(menu->first_time) |
| 8336 | menu->first_time = 0; |
| 6832 | 8337 | |
| 6833 | | RequestStrings(watchListLength + 2, watchListLength, 30, 0); |
| 8338 | /* required items = (total watchpoints + return + terminator) & (strings buf * total watchpoints [max chars = 32]) */ |
| 8339 | request_strings(watchListLength + 2, watchListLength, 32, 0); |
| 8340 | menuItem = menu_strings.main_list; |
| 8341 | buf = menu_strings.main_strings; |
| 6834 | 8342 | |
| 6835 | | menuItem = menuStrings.mainList; |
| 6836 | | buf = menuStrings.mainStrings; |
| 8343 | /********** MENU CONSTRUCTION **********/ |
| 8344 | for(i = 0; i < watchListLength; i++) |
| 8345 | { |
| 8346 | WatchInfo * traverse = &watchList[i]; |
| 8347 | cpu_region_info *info = get_cpu_or_region_info(traverse->cpu); |
| 6837 | 8348 | |
| 6838 | | sel = selection - 1; |
| 8349 | /* FORMAT : "CPU/Region : Address (Length : Bytes)" */ |
| 8350 | if(!editActive || menu->sel != i) |
| 8351 | { |
| 8352 | sprintf(buf[i], "%s:%.*X (%d:%s)", |
| 8353 | get_region_name(traverse->cpu), |
| 8354 | info->address_chars_needed, |
| 8355 | traverse->address, |
| 8356 | traverse->numElements, |
| 8357 | kByteSizeStringList[traverse->elementBytes]); |
| 8358 | } |
| 8359 | else |
| 8360 | { |
| 8361 | /* insert edit cursor in quick edit mode */ |
| 8362 | switch(editCursor) |
| 8363 | { |
| 8364 | default: |
| 8365 | { |
| 8366 | INT8 j; |
| 6839 | 8367 | |
| 6840 | | /********** SUB MENU **********/ |
| 6841 | | if(submenuChoice) |
| 6842 | | { |
| 6843 | | submenuChoice = EditWatch(machine, &watchList[submenuWatch], submenuChoice); |
| 8368 | stringsBuf = buf[i]; |
| 6844 | 8369 | |
| 6845 | | /* ----- meaningless ? because no longer return with sel = -1 (pressed UI_CONFIG in submenu) ----- */ |
| 6846 | | // if(submenuChoice == -1) |
| 6847 | | // { |
| 6848 | | // submenuChoice = 0; |
| 6849 | | // sel = -2; |
| 6850 | | // } |
| 8370 | stringsBuf += sprintf(stringsBuf, "%s ", get_region_name(traverse->cpu)); |
| 6851 | 8371 | |
| 6852 | | return sel + 1; |
| 6853 | | } |
| 8372 | for(j = info->address_chars_needed + 1; j > 1; j--) |
| 8373 | { |
| 8374 | INT8 digits = j - 2; |
| 6854 | 8375 | |
| 6855 | | /********** MENU CONSTRUCTION **********/ |
| 6856 | | for(i = 0; i < watchListLength; i++) |
| 6857 | | { |
| 6858 | | WatchInfo * traverse = &watchList[i]; |
| 8376 | if(j == editCursor) |
| 8377 | stringsBuf += sprintf(stringsBuf, "[%X]", (traverse->address & kIncrementMaskTable[digits]) / kIncrementValueTable[digits]); |
| 8378 | else |
| 8379 | stringsBuf += sprintf(stringsBuf, "%X", (traverse->address & kIncrementMaskTable[digits]) / kIncrementValueTable[digits]); |
| 8380 | } |
| 6859 | 8381 | |
| 6860 | | sprintf(buf[i], "%d:%.*X (%d)", traverse->cpu, cpuInfoList[traverse->cpu].addressCharsNeeded, traverse->address, traverse->numElements); |
| 8382 | stringsBuf += sprintf(stringsBuf, " (%d:%s)", traverse->numElements, kByteSizeStringList[traverse->elementBytes]); |
| 8383 | } |
| 8384 | break; |
| 6861 | 8385 | |
| 8386 | case 1: |
| 8387 | sprintf(buf[i], "%s:%.*X ([%d]:%s)", |
| 8388 | get_region_name(traverse->cpu), |
| 8389 | info->address_chars_needed, |
| 8390 | traverse->address, |
| 8391 | traverse->numElements, |
| 8392 | kByteSizeStringList[traverse->elementBytes]); |
| 8393 | break; |
| 8394 | |
| 8395 | case 0: |
| 8396 | sprintf(buf[i], "%s:%.*X (%d:[%s])", |
| 8397 | get_region_name(traverse->cpu), |
| 8398 | info->address_chars_needed, |
| 8399 | traverse->address, |
| 8400 | traverse->numElements, |
| 8401 | kByteSizeStringList[traverse->elementBytes]); |
| 8402 | break; |
| 8403 | } |
| 8404 | } |
| 8405 | |
| 6862 | 8406 | menuItem[total] = buf[i]; |
| 6863 | 8407 | total++; |
| 6864 | 8408 | } |
| 6865 | 8409 | |
| 6866 | | menuItem[total++] = "Return to Prior Menu"; // return |
| 8410 | /* ##### RETURN ##### */ |
| 8411 | menuItem[total++] = "Return to Prior Menu"; |
| 6867 | 8412 | |
| 6868 | | menuItem[total] = NULL; // terminate array |
| 8413 | /* ##### TERMINATE ARRAY ##### */ |
| 8414 | menuItem[total] = NULL; |
| 6869 | 8415 | |
| 6870 | | /* ----- adjust current cursor position ----- */ |
| 6871 | | if(sel < 0) |
| 6872 | | sel = 0; |
| 6873 | | if(sel >= total) |
| 6874 | | sel = total - 1; |
| 8416 | /* adjust current cursor position */ |
| 8417 | ADJUST_CURSOR(menu->sel, total) |
| 6875 | 8418 | |
| 6876 | | /* ----- draw it ----- */ |
| 6877 | | old_style_menu(menuItem, NULL, NULL, sel, 0); |
| 8419 | /* draw it */ |
| 8420 | old_style_menu(menuItem, NULL, NULL, menu->sel, 0); |
| 6878 | 8421 | |
| 6879 | | if(sel < watchListLength) |
| 6880 | | watch = &watchList[sel]; |
| 8422 | if(menu->sel < watchListLength) |
| 8423 | watch = &watchList[menu->sel]; |
| 6881 | 8424 | else |
| 6882 | 8425 | watch = NULL; |
| 6883 | 8426 | |
| 6884 | 8427 | /********** KEY HANDLING **********/ |
| 6885 | | if(UIPressedRepeatThrottle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate)) |
| 8428 | if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate)) |
| 6886 | 8429 | { |
| 6887 | | sel++; |
| 8430 | if(!editActive) |
| 8431 | { |
| 8432 | CURSOR_TO_PREVIOUS(menu->sel, total) |
| 8433 | } |
| 8434 | else |
| 8435 | { |
| 8436 | switch(editCursor) |
| 8437 | { |
| 8438 | default: |
| 8439 | watch->address = DoIncrementHexField(watch->address, editCursor - 2); |
| 8440 | break; |
| 6888 | 8441 | |
| 6889 | | if(sel >= total) |
| 6890 | | sel = 0; |
| 8442 | case 1: |
| 8443 | if(watch->numElements < 99) |
| 8444 | watch->numElements++; |
| 8445 | break; |
| 8446 | |
| 8447 | case 0: |
| 8448 | watch->elementBytes = (watch->elementBytes + 1) & 0x03; |
| 8449 | break; |
| 8450 | } |
| 8451 | } |
| 6891 | 8452 | } |
| 6892 | | |
| 6893 | | if(UIPressedRepeatThrottle(machine, IPT_UI_UP, kVerticalKeyRepeatRate)) |
| 8453 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate)) |
| 6894 | 8454 | { |
| 6895 | | sel--; |
| 8455 | if(!editActive) |
| 8456 | { |
| 8457 | CURSOR_TO_NEXT(menu->sel, total) |
| 8458 | } |
| 8459 | else |
| 8460 | { |
| 8461 | switch(editCursor) |
| 8462 | { |
| 8463 | default: |
| 8464 | watch->address = DoDecrementHexField(watch->address, editCursor - 2); |
| 8465 | break; |
| 6896 | 8466 | |
| 6897 | | if(sel < 0) |
| 6898 | | sel = total - 1; |
| 8467 | case 1: |
| 8468 | if(watch->numElements > 0) |
| 8469 | watch->numElements--; |
| 8470 | break; |
| 8471 | |
| 8472 | case 0: |
| 8473 | watch->elementBytes = (watch->elementBytes - 1) & 0x03; |
| 8474 | break; |
| 8475 | } |
| 8476 | } |
| 6899 | 8477 | } |
| 6900 | | |
| 6901 | | if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate)) |
| 8478 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate)) |
| 6902 | 8479 | { |
| 6903 | | sel -= fullMenuPageHeight; |
| 6904 | | |
| 6905 | | if(sel < 0) |
| 6906 | | sel = 0; |
| 8480 | if(!editActive) |
| 8481 | CURSOR_PAGE_UP(menu->sel) |
| 6907 | 8482 | } |
| 6908 | | |
| 6909 | | if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate)) |
| 8483 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate)) |
| 6910 | 8484 | { |
| 6911 | | sel += fullMenuPageHeight; |
| 8485 | if(!editActive) |
| 8486 | CURSOR_PAGE_DOWN(menu->sel, total) |
| 8487 | } |
| 8488 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_LEFT, kVerticalKeyRepeatRate)) |
| 8489 | { |
| 8490 | if(editActive) |
| 8491 | { |
| 8492 | cpu_region_info *info = get_cpu_or_region_info(watch->cpu); |
| 6912 | 8493 | |
| 6913 | | if(sel >= total) |
| 6914 | | sel = total - 1; |
| 8494 | if(++editCursor > info->address_chars_needed + 1) |
| 8495 | editCursor = 0; |
| 8496 | } |
| 6915 | 8497 | } |
| 6916 | | |
| 6917 | | if(ShiftKeyPressed()) |
| 8498 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_RIGHT, kVerticalKeyRepeatRate)) |
| 6918 | 8499 | { |
| 6919 | | if(input_ui_pressed(machine, IPT_UI_ADD_CHEAT)) // shift + add = add new watchpoint |
| 6920 | | AddWatchBefore(sel); |
| 8500 | if(editActive) |
| 8501 | { |
| 8502 | cpu_region_info *info = get_cpu_or_region_info(watch->cpu); |
| 6921 | 8503 | |
| 6922 | | if(input_ui_pressed(machine, IPT_UI_DELETE_CHEAT)) // shift + delete = delete selected watchpoint |
| 6923 | | DeleteWatchAt(sel); |
| 8504 | if(--editCursor < 0) |
| 8505 | editCursor = info->address_chars_needed + 1; |
| 8506 | } |
| 6924 | 8507 | } |
| 6925 | | else |
| 8508 | else if(input_ui_pressed(machine, IPT_UI_SELECT)) |
| 6926 | 8509 | { |
| 6927 | | if(input_ui_pressed(machine, IPT_UI_SAVE_CHEAT)) // save = save selected watchpoint as watchpoint code |
| 8510 | if(editActive) |
| 8511 | editActive = 0; |
| 8512 | else |
| 6928 | 8513 | { |
| 6929 | 8514 | if(watch) |
| 8515 | cheat_menu_stack_push(command_watch_menu, menu->handler, menu->sel); |
| 8516 | else |
| 8517 | menu->sel = -1; |
| 8518 | } |
| 8519 | } |
| 8520 | else if(input_ui_pressed(machine, IPT_UI_ADD_CHEAT)) |
| 8521 | { |
| 8522 | if(!editActive && watch) |
| 8523 | { |
| 8524 | if(ShiftKeyPressed()) |
| 8525 | AddCheatFromWatch(watch); |
| 8526 | else if(ControlKeyPressed()) |
| 6930 | 8527 | { |
| 6931 | | CheatEntry entry; |
| 8528 | CheatEntry * entry = GetNewCheat(); |
| 6932 | 8529 | |
| 6933 | | memset(&entry, 0, sizeof(CheatEntry)); |
| 8530 | DisposeCheat(entry); |
| 8531 | SetupCheatFromWatchAsWatch(entry, watch); |
| 6934 | 8532 | |
| 6935 | | SetupCheatFromWatchAsWatch(&entry, watch); |
| 6936 | | SaveCheat(machine, &entry, 0, 0); |
| 6937 | | DisposeCheat(&entry); |
| 6938 | | } |
| 6939 | | } |
| 6940 | | |
| 6941 | | if(input_ui_pressed(machine, IPT_UI_ADD_CHEAT)) |
| 6942 | | { |
| 6943 | | if(watch) |
| 6944 | | { |
| 6945 | | if(ControlKeyPressed()) // ctrl + add = add selected watchpoing as watchpoint code to cheat list |
| 8533 | /* when fails to add, delete this entry because it causes the crash */ |
| 8534 | if(messageType == kCheatMessage_FailedToAdd) |
| 6946 | 8535 | { |
| 6947 | | CheatEntry * entry = GetNewCheat(); |
| 6948 | | |
| 6949 | | DisposeCheat(entry); |
| 6950 | | SetupCheatFromWatchAsWatch(entry, watch); |
| 8536 | DeleteCheatAt(cheatListLength - 1); |
| 8537 | messageType = kCheatMessage_FailedToAdd; |
| 8538 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 6951 | 8539 | } |
| 6952 | | else |
| 6953 | | AddCheatFromWatch(watch); // add = add selected watchpoint as cheat code to cheat list |
| 6954 | 8540 | } |
| 8541 | else |
| 8542 | AddWatchBefore(menu->sel); |
| 6955 | 8543 | } |
| 6956 | | |
| 6957 | | if(input_ui_pressed(machine, IPT_UI_DELETE_CHEAT)) |
| 8544 | } |
| 8545 | else if(input_ui_pressed(machine, IPT_UI_DELETE_CHEAT)) |
| 8546 | { |
| 8547 | if(!editActive && watch) |
| 6958 | 8548 | { |
| 6959 | | if(ControlKeyPressed()) |
| 8549 | if(ShiftKeyPressed()) |
| 6960 | 8550 | { |
| 6961 | | for(i = 0; i < watchListLength; i++) // ctrl + delete = disable all watchpoints |
| 8551 | DeleteWatchAt(menu->sel); |
| 8552 | } |
| 8553 | else if(ControlKeyPressed()) |
| 8554 | { |
| 8555 | for(i = 0; i < watchListLength; i++) |
| 6962 | 8556 | watchList[i].numElements = 0; |
| 6963 | 8557 | } |
| 6964 | 8558 | else |
| 6965 | 8559 | { |
| 6966 | | if(watch) // delete = disable selected watchpoint |
| 8560 | if(watch) |
| 6967 | 8561 | watch->numElements = 0; |
| 6968 | 8562 | } |
| 6969 | 8563 | } |
| 8564 | else if(editActive) |
| 8565 | { |
| 8566 | switch(editCursor) |
| 8567 | { |
| 8568 | default: |
| 8569 | watch->address = 0; |
| 8570 | break; |
| 8571 | |
| 8572 | case 1: |
| 8573 | watch->numElements = 0; |
| 8574 | break; |
| 8575 | |
| 8576 | case 0: |
| 8577 | watch->elementBytes = 0; |
| 8578 | } |
| 8579 | } |
| 6970 | 8580 | } |
| 6971 | | |
| 6972 | | if(input_ui_pressed(machine, IPT_UI_EDIT_CHEAT)) // edit = edit selected watchpoint |
| 8581 | else if(input_ui_pressed(machine, IPT_UI_SAVE_CHEAT)) |
| 6973 | 8582 | { |
| 6974 | | if(sel < (total - 1)) |
| 8583 | if(!editActive && watch) |
| 6975 | 8584 | { |
| 6976 | | submenuWatch = sel; |
| 6977 | | submenuChoice = 1; |
| 8585 | CheatEntry entry; |
| 8586 | |
| 8587 | memset(&entry, 0, sizeof(CheatEntry)); |
| 8588 | |
| 8589 | SetupCheatFromWatchAsWatch(&entry, watch); |
| 8590 | SaveCheatCode(machine, &entry); |
| 8591 | DisposeCheat(&entry); |
| 6978 | 8592 | } |
| 6979 | 8593 | } |
| 6980 | | |
| 6981 | | if(input_ui_pressed(machine, IPT_UI_SELECT)) |
| 8594 | else if(input_ui_pressed(machine, IPT_UI_EDIT_CHEAT)) |
| 6982 | 8595 | { |
| 6983 | | if(sel == (total - 1)) // return previous menu |
| 8596 | if(watch) |
| 6984 | 8597 | { |
| 6985 | | submenuChoice = 0; |
| 6986 | | sel = -1; |
| 8598 | editCursor = 2; |
| 8599 | editActive ^= 1; |
| 6987 | 8600 | } |
| 6988 | | else |
| 8601 | } |
| 8602 | else if(input_ui_pressed(machine, IPT_UI_CLEAR)) |
| 8603 | { |
| 8604 | if(!editActive) |
| 6989 | 8605 | { |
| 6990 | | if(sel < (total - 1)) // edit selected watchpoint (same as edit key) |
| 8606 | if(ShiftKeyPressed()) |
| 6991 | 8607 | { |
| 6992 | | submenuWatch = sel; |
| 6993 | | submenuChoice = 1; |
| 8608 | if(watch) |
| 8609 | ResetWatch(watch); |
| 6994 | 8610 | } |
| 8611 | else |
| 8612 | { |
| 8613 | for(i = 0; i < watchListLength; i++) |
| 8614 | ResetWatch(&watchList[i]); |
| 8615 | } |
| 6995 | 8616 | } |
| 8617 | else |
| 8618 | { |
| 8619 | watch->address = 0; |
| 8620 | watch->numElements = 0; |
| 8621 | watch->elementBytes = 0; |
| 8622 | } |
| 6996 | 8623 | } |
| 8624 | else if(input_ui_pressed(machine, IPT_UI_CANCEL)) |
| 8625 | { |
| 8626 | if(editActive) |
| 8627 | editActive = 0; |
| 8628 | else |
| 8629 | menu->sel = -1; |
| 8630 | } |
| 6997 | 8631 | |
| 6998 | | if(input_ui_pressed(machine, IPT_UI_CLEAR)) |
| 8632 | return menu->sel + 1; |
| 8633 | } |
| 8634 | |
| 8635 | /*-------------------------------------------------------------- |
| 8636 | command_watch_menu - management for wathcpoint command menu |
| 8637 | --------------------------------------------------------------*/ |
| 8638 | |
| 8639 | static int command_watch_menu(running_machine *machine, cheat_menu_stack *menu) |
| 8640 | { |
| 8641 | enum{ |
| 8642 | kMenu_EditWatch = 0, |
| 8643 | kMenu_DisableWatch, |
| 8644 | kMenu_DisableAllWatch, |
| 8645 | kMenu_ResetWatch, |
| 8646 | kMenu_ResetAllWatch, |
| 8647 | kMenu_AddAsCheatCode, |
| 8648 | kMenu_AddAsWatchCode, |
| 8649 | kMenu_SaveAsCheatCode, |
| 8650 | kMenu_SaveAsWatchCode, |
| 8651 | kMenu_AddWatch, |
| 8652 | kMenu_DeleteWatch, |
| 8653 | kMenu_Return, |
| 8654 | kMenu_Max }; |
| 8655 | |
| 8656 | int i; |
| 8657 | UINT8 total = 0; |
| 8658 | ui_menu_item menuItem[kMenu_Max + 1]; |
| 8659 | WatchInfo * entry = &watchList[menu->pre_sel]; |
| 8660 | |
| 8661 | /* first setting : NONE */ |
| 8662 | if(menu->first_time) |
| 8663 | menu->first_time = 0; |
| 8664 | |
| 8665 | memset(menuItem, 0, sizeof(menuItem)); |
| 8666 | |
| 8667 | /********** MENU CONSTRUCION **********/ |
| 8668 | menuItem[total++].text = "Edit Watchpoint"; |
| 8669 | menuItem[total++].text = "Disable Watchpoint"; |
| 8670 | menuItem[total++].text = "Disable All Watchpoints"; |
| 8671 | menuItem[total++].text = "Reset Watchpoint"; |
| 8672 | menuItem[total++].text = "Reset All Watchpoints"; |
| 8673 | menuItem[total++].text = "Add as Cheat Code"; |
| 8674 | menuItem[total++].text = "Add as Watch Code"; |
| 8675 | menuItem[total++].text = "Save as Cheat Code"; |
| 8676 | menuItem[total++].text = "Save as Watch Code"; |
| 8677 | menuItem[total++].text = "Add New Watchpoint"; |
| 8678 | menuItem[total++].text = "Delete Watchpoint"; |
| 8679 | menuItem[total++].text = "Return to Prior Menu"; |
| 8680 | menuItem[total].text = NULL; |
| 8681 | |
| 8682 | /* adjust current cursor position */ |
| 8683 | ADJUST_CURSOR(menu->sel, total) |
| 8684 | |
| 8685 | /* print it */ |
| 8686 | ui_menu_draw(menuItem, total, menu->sel, NULL); |
| 8687 | |
| 8688 | /********** KEY HANDLING **********/ |
| 8689 | if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate)) |
| 6999 | 8690 | { |
| 7000 | | /* ----- reset all watchpoints ----- */ |
| 7001 | | for(i = 0; i < watchListLength; i++) |
| 8691 | CURSOR_TO_PREVIOUS(menu->sel, total) |
| 8692 | } |
| 8693 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate)) |
| 8694 | { |
| 8695 | CURSOR_TO_NEXT(menu->sel, total) |
| 8696 | } |
| 8697 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate)) |
| 8698 | { |
| 8699 | CURSOR_PAGE_UP(menu->sel) |
| 8700 | } |
| 8701 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate)) |
| 8702 | { |
| 8703 | CURSOR_PAGE_DOWN(menu->sel, total) |
| 8704 | } |
| 8705 | else if(input_ui_pressed(machine, IPT_UI_SELECT)) |
| 8706 | { |
| 8707 | switch(menu->sel) |
| 7002 | 8708 | { |
| 7003 | | if(watch) |
| 8709 | case kMenu_EditWatch: |
| 8710 | cheat_menu_stack_push(edit_watch_menu, menu->return_handler, menu->pre_sel); |
| 8711 | break; |
| 8712 | |
| 8713 | case kMenu_DisableWatch: |
| 8714 | entry->numElements = 0; |
| 8715 | break; |
| 8716 | |
| 8717 | case kMenu_DisableAllWatch: |
| 8718 | for(i = 0; i < watchListLength; i++) |
| 8719 | watchList[i].numElements = 0; |
| 8720 | break; |
| 8721 | |
| 8722 | case kMenu_ResetWatch: |
| 8723 | ResetWatch(entry); |
| 8724 | break; |
| 8725 | |
| 8726 | case kMenu_ResetAllWatch: |
| 8727 | for(i = 0; i < watchListLength; i++) |
| 8728 | ResetWatch(&watchList[i]); |
| 8729 | break; |
| 8730 | |
| 8731 | case kMenu_AddAsCheatCode: |
| 8732 | AddCheatFromWatch(entry); |
| 8733 | break; |
| 8734 | |
| 8735 | case kMenu_AddAsWatchCode: |
| 7004 | 8736 | { |
| 7005 | | watchList[i].address = 0; |
| 7006 | | watchList[i].cpu = 0; |
| 7007 | | watchList[i].numElements = 0; |
| 7008 | | watchList[i].elementBytes = kWatchSizeConversionTable[0]; |
| 7009 | | watchList[i].labelType = kWatchLabel_None; |
| 7010 | | watchList[i].displayType = kWatchDisplayType_Hex; |
| 7011 | | watchList[i].skip = 0; |
| 7012 | | watchList[i].elementsPerLine = 0; |
| 7013 | | watchList[i].addValue = 0; |
| 8737 | CheatEntry * newEntry = GetNewCheat(); |
| 7014 | 8738 | |
| 7015 | | watchList[i].linkedCheat = NULL; |
| 8739 | DisposeCheat(newEntry); |
| 8740 | SetupCheatFromWatchAsWatch(newEntry, entry); |
| 7016 | 8741 | |
| 7017 | | watchList[i].label[0] = 0; |
| 8742 | /* when fails to add, delete this entry because it causes the crash */ |
| 8743 | if(messageType == kCheatMessage_FailedToAdd) |
| 8744 | { |
| 8745 | DeleteCheatAt(cheatListLength - 1); |
| 8746 | messageType = kCheatMessage_FailedToAdd; |
| 8747 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 8748 | } |
| 7018 | 8749 | } |
| 7019 | | } |
| 7020 | | } |
| 8750 | break; |
| 7021 | 8751 | |
| 7022 | | if(UIPressedRepeatThrottle(machine, IPT_UI_ZOOM_IN, kVerticalKeyRepeatRate)) |
| 7023 | | /* ----- quick menu switch : watchpoint list -> enable/disable ----- */ |
| 7024 | | sel = -2; |
| 8752 | case kMenu_SaveAsCheatCode: |
| 8753 | // underconstruction... |
| 8754 | break; |
| 7025 | 8755 | |
| 7026 | | if(UIPressedRepeatThrottle(machine, IPT_UI_ZOOM_OUT, kVerticalKeyRepeatRate)) |
| 7027 | | /* ----- quick menu switch : watchpoint list -> search ----- */ |
| 7028 | | sel = -4; |
| 8756 | case kMenu_SaveAsWatchCode: |
| 8757 | { |
| 8758 | CheatEntry tempEntry; |
| 7029 | 8759 | |
| 7030 | | if(input_ui_pressed(machine, IPT_UI_CANCEL)) |
| 7031 | | sel = -1; |
| 8760 | memset(&tempEntry, 0, sizeof(CheatEntry)); |
| 7032 | 8761 | |
| 7033 | | return sel + 1; |
| 8762 | SetupCheatFromWatchAsWatch(&tempEntry, entry); |
| 8763 | SaveCheatCode(machine, &tempEntry); |
| 8764 | DisposeCheat(&tempEntry); |
| 8765 | } |
| 8766 | break; |
| 8767 | |
| 8768 | case kMenu_Return: |
| 8769 | menu->sel = -1; |
| 8770 | } |
| 8771 | } |
| 8772 | else if(input_ui_pressed(machine, IPT_UI_RELOAD_CHEAT)) |
| 8773 | { |
| 8774 | ReloadCheatDatabase(machine); |
| 8775 | } |
| 8776 | else if(input_ui_pressed(machine, IPT_UI_CANCEL) || input_ui_pressed(machine, IPT_UI_LEFT) || input_ui_pressed(machine, IPT_UI_RIGHT)) |
| 8777 | { |
| 8778 | menu->sel = -1; |
| 8779 | } |
| 8780 | |
| 8781 | return menu->sel + 1; |
| 7034 | 8782 | } |
| 7035 | 8783 | |
| 7036 | | /*-------------------------------------------------- |
| 7037 | | EditWatch - management for watchpoint edit menu |
| 7038 | | --------------------------------------------------*/ |
| 8784 | /*-------------------------------------------------------- |
| 8785 | edit_watch_menu - management for watchpoint edit menu |
| 8786 | --------------------------------------------------------*/ |
| 7039 | 8787 | |
| 7040 | | static int EditWatch(running_machine *machine, WatchInfo * entry, int selection) |
| 8788 | static int edit_watch_menu(running_machine *machine, cheat_menu_stack *menu) |
| 7041 | 8789 | { |
| 7042 | | enum |
| 7043 | | { |
| 8790 | enum{ |
| 7044 | 8791 | kMenu_Address = 0, |
| 7045 | 8792 | kMenu_CPU, |
| 7046 | 8793 | kMenu_NumElements, |
| r2762 | r2763 | |
| 7057 | 8804 | kMenu_DataShift, |
| 7058 | 8805 | kMenu_XOR, |
| 7059 | 8806 | |
| 7060 | | kMenu_Return |
| 7061 | | }; |
| 8807 | kMenu_Return, |
| 8808 | kMenu_Max }; |
| 7062 | 8809 | |
| 7063 | | static const char *const kWatchSizeStringList[] = |
| 7064 | | { |
| 7065 | | "8 Bit", |
| 7066 | | "16 Bit", |
| 7067 | | "24 Bit", |
| 7068 | | "32 Bit" |
| 7069 | | }; |
| 7070 | | |
| 8810 | UINT8 total = 0; |
| 8811 | UINT32 increment = 1; |
| 7071 | 8812 | const char ** menuItem; |
| 7072 | 8813 | const char ** menuSubItem; |
| 7073 | 8814 | char ** buf; |
| 7074 | 8815 | char * flagBuf; |
| 8816 | WatchInfo * entry = &watchList[menu->pre_sel]; |
| 8817 | cpu_region_info *info = get_cpu_or_region_info(entry->cpu); |
| 7075 | 8818 | |
| 7076 | | INT32 sel; |
| 7077 | | INT32 total = 0; |
| 7078 | | UINT32 increment = 1; |
| 7079 | | static UINT8 editActive = 0; |
| 8819 | /* first setting : NONE */ |
| 8820 | if(menu->first_time) |
| 8821 | menu->first_time = 0; |
| 7080 | 8822 | |
| 7081 | | /* ----- if no watch entry, direct return ----- */ |
| 7082 | | if(!entry) |
| 7083 | | return 0; |
| 8823 | request_strings(kMenu_Max + 1, kMenu_Return, 0, 20); |
| 8824 | menuItem = menu_strings.main_list; |
| 8825 | menuSubItem = menu_strings.sub_list; |
| 8826 | buf = menu_strings.sub_strings; |
| 8827 | flagBuf = menu_strings.flag_list; |
| 7084 | 8828 | |
| 7085 | | RequestStrings(kMenu_Return + 2, kMenu_Return, 0, 20); |
| 8829 | memset(flagBuf, 0, kMenu_Max + 1); |
| 7086 | 8830 | |
| 7087 | | menuItem = menuStrings.mainList; |
| 7088 | | menuSubItem = menuStrings.subList; |
| 7089 | | buf = menuStrings.subStrings; |
| 7090 | | flagBuf = menuStrings.flagList; |
| 7091 | | |
| 7092 | | memset(flagBuf, 0, kMenu_Return + 2); |
| 7093 | | |
| 7094 | | sel = selection - 1; |
| 7095 | | |
| 7096 | 8831 | /********** MENU CONSTRUCTION **********/ |
| 7097 | | sprintf(buf[total], "%.*X", cpuInfoList[entry->cpu].addressCharsNeeded, entry->address >> entry->addressShift); |
| 8832 | /* ##### ADDRESS ##### */ |
| 8833 | sprintf(buf[total], "%.*X", info->address_chars_needed, entry->address >> entry->addressShift); |
| 7098 | 8834 | menuItem[total] = "Address"; |
| 7099 | 8835 | menuSubItem[total] = buf[total]; |
| 7100 | 8836 | total++; |
| 7101 | 8837 | |
| 7102 | | sprintf(buf[total], "%d", entry->cpu); |
| 7103 | | menuItem[total] = "CPU"; |
| 8838 | /* ##### CPU/REGION ##### */ |
| 8839 | sprintf(buf[total], "%s", get_region_name(entry->cpu)); |
| 8840 | menuItem[total] = TEST_FIELD(entry->cpu, RegionFlag) ? "Region" : "CPU"; |
| 7104 | 8841 | menuSubItem[total] = buf[total]; |
| 7105 | 8842 | total++; |
| 7106 | 8843 | |
| 8844 | /* ##### LENGTH ##### */ |
| 7107 | 8845 | sprintf(buf[total], "%d", entry->numElements); |
| 7108 | 8846 | menuItem[total] = "Length"; |
| 7109 | 8847 | menuSubItem[total] = buf[total]; |
| 7110 | 8848 | total++; |
| 7111 | 8849 | |
| 8850 | /* ##### ELEMENT SIZE ##### */ |
| 7112 | 8851 | menuItem[total] = "Element Size"; |
| 7113 | | menuSubItem[total++] = kWatchSizeStringList[entry->elementBytes]; |
| 8852 | menuSubItem[total++] = kByteSizeStringList[entry->elementBytes]; |
| 7114 | 8853 | |
| 8854 | /* ##### LABEL TYPE ##### */ |
| 7115 | 8855 | menuItem[total] = "Label Type"; |
| 7116 | 8856 | menuSubItem[total++] = kWatchLabelStringList[entry->labelType]; |
| 7117 | 8857 | |
| 8858 | /* ##### TEXT LABEL ##### */ |
| 7118 | 8859 | menuItem[total] = "Text Label"; |
| 7119 | 8860 | if(entry->label[0]) |
| 7120 | 8861 | menuSubItem[total++] = entry->label; |
| 7121 | 8862 | else |
| 7122 | 8863 | menuSubItem[total++] = "(none)"; |
| 7123 | 8864 | |
| 8865 | /* ##### DISPLAY TYPE ##### */ |
| 7124 | 8866 | menuItem[total] = "Display Type"; |
| 7125 | 8867 | menuSubItem[total++] = kWatchDisplayTypeStringList[entry->displayType]; |
| 7126 | 8868 | |
| 8869 | /* ##### X POSITION ##### */ |
| 7127 | 8870 | sprintf(buf[total], "%f", entry->x); |
| 7128 | 8871 | menuItem[total] = "X"; |
| 7129 | 8872 | menuSubItem[total] = buf[total]; |
| 7130 | 8873 | total++; |
| 7131 | 8874 | |
| 8875 | /* ##### Y POSITION ##### */ |
| 7132 | 8876 | sprintf(buf[total], "%f", entry->y); |
| 7133 | 8877 | menuItem[total] = "Y"; |
| 7134 | 8878 | menuSubItem[total] = buf[total]; |
| 7135 | 8879 | total++; |
| 7136 | 8880 | |
| 8881 | /* ##### SKIP BYTES ##### */ |
| 7137 | 8882 | sprintf(buf[total], "%d", entry->skip); |
| 7138 | 8883 | menuItem[total] = "Skip Bytes"; |
| 7139 | 8884 | menuSubItem[total] = buf[total]; |
| 7140 | 8885 | total++; |
| 7141 | 8886 | |
| 8887 | /* ##### ELEMENTS PER LINE ##### */ |
| 7142 | 8888 | sprintf(buf[total], "%d", entry->elementsPerLine); |
| 7143 | 8889 | menuItem[total] = "Elements Per Line"; |
| 7144 | 8890 | menuSubItem[total] = buf[total]; |
| 7145 | 8891 | total++; |
| 7146 | 8892 | |
| 8893 | /* ##### ADD VALUE ##### */ |
| 8894 | menuItem[total] = "Add Value"; |
| 7147 | 8895 | if(entry->addValue < 0) |
| 7148 | 8896 | sprintf(buf[total], "-%.2X", -entry->addValue); |
| 7149 | 8897 | else |
| 7150 | 8898 | sprintf(buf[total], "%.2X", entry->addValue); |
| 7151 | | |
| 7152 | | menuItem[total] = "Add Value"; |
| 7153 | 8899 | menuSubItem[total] = buf[total]; |
| 7154 | 8900 | total++; |
| 7155 | 8901 | |
| 8902 | /* ##### ADDRESS SHIFT ##### */ |
| 7156 | 8903 | sprintf(buf[total], "%d", entry->addressShift); |
| 7157 | 8904 | menuItem[total] = "Address Shift"; |
| 7158 | 8905 | menuSubItem[total] = buf[total]; |
| 7159 | 8906 | total++; |
| 7160 | 8907 | |
| 8908 | /* ##### DATA SHIFT ##### */ |
| 7161 | 8909 | sprintf(buf[total], "%d", entry->dataShift); |
| 7162 | 8910 | menuItem[total] = "Data Shift"; |
| 7163 | 8911 | menuSubItem[total] = buf[total]; |
| 7164 | 8912 | total++; |
| 7165 | 8913 | |
| 8914 | /* ##### XOR ##### */ |
| 7166 | 8915 | sprintf(buf[total], "%.*X", kSearchByteDigitsTable[kWatchSizeConversionTable[entry->elementBytes]], entry->xor); |
| 7167 | 8916 | menuItem[total] = "XOR"; |
| 7168 | 8917 | menuSubItem[total] = buf[total]; |
| 7169 | 8918 | total++; |
| 7170 | 8919 | |
| 7171 | | menuItem[total] = "Return to Prior Menu"; // return |
| 8920 | /* ##### RETURN ##### */ |
| 8921 | menuItem[total] = "Return to Prior Menu"; |
| 7172 | 8922 | menuSubItem[total++] = NULL; |
| 7173 | 8923 | |
| 7174 | | menuItem[total] = NULL; // terminate array |
| 8924 | /* ##### TERMINATE ARRAY ##### */ |
| 8925 | menuItem[total] = NULL; |
| 7175 | 8926 | menuSubItem[total] = NULL; |
| 7176 | 8927 | |
| 7177 | | /* ----- adjust current cursor position ----- */ |
| 7178 | | if(sel < 0) |
| 7179 | | sel = 0; |
| 7180 | | if(sel >= total) |
| 7181 | | sel = total - 1; |
| 8928 | /* adjust current cursor position */ |
| 8929 | ADJUST_CURSOR(menu->sel, total) |
| 7182 | 8930 | |
| 7183 | | /* ----- higlighted sub-item if edit mode ----- */ |
| 8931 | /* higlighted sub-item if edit mode */ |
| 7184 | 8932 | if(editActive) |
| 7185 | | flagBuf[sel] = 1; |
| 8933 | flagBuf[menu->sel] = 1; |
| 7186 | 8934 | |
| 7187 | | /* ----- draw it ----- */ |
| 7188 | | old_style_menu(menuItem, menuSubItem, flagBuf, sel, 0); |
| 8935 | /* draw it */ |
| 8936 | old_style_menu(menuItem, menuSubItem, flagBuf, menu->sel, 0); |
| 7189 | 8937 | |
| 7190 | 8938 | /********** KEY HANDLING **********/ |
| 7191 | | if(AltKeyPressed()) |
| 7192 | | increment <<= 4; |
| 7193 | | if(ControlKeyPressed()) |
| 7194 | | increment <<= 8; |
| 7195 | | if(ShiftKeyPressed()) |
| 7196 | | increment <<= 16; |
| 7197 | | |
| 7198 | | if(UIPressedRepeatThrottle(machine, IPT_UI_LEFT, kHorizontalSlowKeyRepeatRate)) |
| 8939 | if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate)) |
| 7199 | 8940 | { |
| 7200 | | editActive = 0; |
| 7201 | | |
| 7202 | | switch(sel) |
| 8941 | CURSOR_TO_PREVIOUS(menu->sel, total) |
| 8942 | } |
| 8943 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate)) |
| 8944 | { |
| 8945 | CURSOR_TO_NEXT(menu->sel, total) |
| 8946 | } |
| 8947 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate)) |
| 8948 | { |
| 8949 | CURSOR_PAGE_UP(menu->sel) |
| 8950 | } |
| 8951 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate)) |
| 8952 | { |
| 8953 | CURSOR_PAGE_DOWN(menu->sel, total) |
| 8954 | } |
| 8955 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_LEFT, kHorizontalSlowKeyRepeatRate)) |
| 8956 | { |
| 8957 | if(editActive) |
| 7203 | 8958 | { |
| 7204 | | case kMenu_Address: |
| 7205 | | entry->address = DoShift(entry->address, entry->addressShift); |
| 7206 | | entry->address -= increment; |
| 7207 | | entry->address = DoShift(entry->address, -entry->addressShift); |
| 8959 | // underconstruction... |
| 8960 | } |
| 8961 | else |
| 8962 | { |
| 8963 | switch(menu->sel) |
| 8964 | { |
| 8965 | case kMenu_Address: |
| 8966 | entry->address = DoShift(entry->address, entry->addressShift); |
| 8967 | entry->address -= increment; |
| 8968 | entry->address = DoShift(entry->address, -entry->addressShift); |
| 7208 | 8969 | |
| 7209 | | if(entry->locationType != kLocation_MemoryRegion) |
| 7210 | | entry->address &= cpuInfoList[entry->cpu].addressMask; |
| 8970 | if(!TEST_FIELD(entry->cpu, RegionFlag)) |
| 8971 | entry->address &= info->address_mask; |
| 8972 | break; |
| 7211 | 8973 | |
| 7212 | | break; |
| 8974 | case kMenu_CPU: |
| 8975 | entry->cpu--; |
| 7213 | 8976 | |
| 7214 | | case kMenu_CPU: |
| 7215 | | entry->cpu--; |
| 8977 | if(entry->cpu >= cpu_gettotalcpu()) |
| 8978 | entry->cpu = cpu_gettotalcpu() - 1; |
| 7216 | 8979 | |
| 7217 | | if(entry->cpu >= cpu_gettotalcpu()) |
| 7218 | | entry->cpu = cpu_gettotalcpu() - 1; |
| 8980 | entry->address &= info->address_mask; |
| 8981 | break; |
| 7219 | 8982 | |
| 7220 | | entry->address &= cpuInfoList[entry->cpu].addressMask; |
| 7221 | | break; |
| 8983 | case kMenu_NumElements: |
| 8984 | if(entry->numElements > 0) |
| 8985 | entry->numElements--; |
| 8986 | else |
| 8987 | entry->numElements = 0; |
| 8988 | break; |
| 7222 | 8989 | |
| 7223 | | case kMenu_NumElements: |
| 7224 | | if(entry->numElements > 0) |
| 7225 | | entry->numElements--; |
| 7226 | | else |
| 7227 | | entry->numElements = 0; |
| 7228 | | break; |
| 8990 | case kMenu_ElementSize: |
| 8991 | if(entry->elementBytes > 0) |
| 8992 | entry->elementBytes--; |
| 8993 | else |
| 8994 | entry->elementBytes = 0; |
| 7229 | 8995 | |
| 7230 | | case kMenu_ElementSize: |
| 7231 | | if(entry->elementBytes > 0) |
| 7232 | | entry->elementBytes--; |
| 7233 | | else |
| 7234 | | entry->elementBytes = 0; |
| 8996 | entry->xor &= kSearchByteMaskTable[kWatchSizeConversionTable[entry->elementBytes]]; |
| 8997 | break; |
| 7235 | 8998 | |
| 7236 | | entry->xor &= kSearchByteMaskTable[kWatchSizeConversionTable[entry->elementBytes]]; |
| 7237 | | break; |
| 8999 | case kMenu_LabelType: |
| 9000 | if(entry->labelType > 0) |
| 9001 | entry->labelType--; |
| 9002 | else |
| 9003 | entry->labelType = 0; |
| 9004 | break; |
| 7238 | 9005 | |
| 7239 | | case kMenu_LabelType: |
| 7240 | | if(entry->labelType > 0) |
| 7241 | | entry->labelType--; |
| 7242 | | else |
| 7243 | | entry->labelType = 0; |
| 7244 | | break; |
| 9006 | case kMenu_TextLabel: |
| 9007 | break; |
| 7245 | 9008 | |
| 7246 | | case kMenu_TextLabel: |
| 7247 | | break; |
| 9009 | case kMenu_DisplayType: |
| 9010 | if(entry->displayType > 0) |
| 9011 | entry->displayType--; |
| 9012 | else |
| 9013 | entry->displayType = 0; |
| 9014 | break; |
| 7248 | 9015 | |
| 7249 | | case kMenu_DisplayType: |
| 7250 | | if(entry->displayType > 0) |
| 7251 | | entry->displayType--; |
| 7252 | | else |
| 7253 | | entry->displayType = 0; |
| 7254 | | break; |
| 9016 | case kMenu_XPosition: |
| 9017 | entry->x -= 0.01f; |
| 9018 | break; |
| 7255 | 9019 | |
| 7256 | | case kMenu_XPosition: |
| 7257 | | entry->x -= 0.01f; |
| 7258 | | break; |
| 9020 | case kMenu_YPosition: |
| 9021 | entry->y -= 0.01f; |
| 9022 | break; |
| 7259 | 9023 | |
| 7260 | | case kMenu_YPosition: |
| 7261 | | entry->y -= 0.01f; |
| 7262 | | break; |
| 9024 | case kMenu_Skip: |
| 9025 | if(entry->skip > 0) |
| 9026 | entry->skip--; |
| 9027 | break; |
| 7263 | 9028 | |
| 7264 | | case kMenu_Skip: |
| 7265 | | if(entry->skip > 0) |
| 7266 | | entry->skip--; |
| 7267 | | break; |
| 9029 | case kMenu_ElementsPerLine: |
| 9030 | if(entry->elementsPerLine > 0) |
| 9031 | entry->elementsPerLine--; |
| 9032 | break; |
| 7268 | 9033 | |
| 7269 | | case kMenu_ElementsPerLine: |
| 7270 | | if(entry->elementsPerLine > 0) |
| 7271 | | entry->elementsPerLine--; |
| 7272 | | break; |
| 9034 | case kMenu_AddValue: |
| 9035 | entry->addValue = (entry->addValue - 1) & 0xFF; |
| 9036 | break; |
| 7273 | 9037 | |
| 7274 | | case kMenu_AddValue: |
| 7275 | | entry->addValue = (entry->addValue - 1) & 0xFF; |
| 7276 | | break; |
| 9038 | case kMenu_AddressShift: |
| 9039 | if(entry->addressShift > -31) |
| 9040 | entry->addressShift--; |
| 9041 | else |
| 9042 | entry->addressShift = 31; |
| 9043 | break; |
| 7277 | 9044 | |
| 7278 | | case kMenu_AddressShift: |
| 7279 | | if(entry->addressShift > -31) |
| 7280 | | entry->addressShift--; |
| 7281 | | else |
| 7282 | | entry->addressShift = 31; |
| 7283 | | break; |
| 9045 | case kMenu_DataShift: |
| 9046 | if(entry->dataShift > -31) |
| 9047 | entry->dataShift--; |
| 9048 | else |
| 9049 | entry->dataShift = 31; |
| 9050 | break; |
| 7284 | 9051 | |
| 7285 | | case kMenu_DataShift: |
| 7286 | | if(entry->dataShift > -31) |
| 7287 | | entry->dataShift--; |
| 7288 | | else |
| 7289 | | entry->dataShift = 31; |
| 7290 | | break; |
| 7291 | | |
| 7292 | | case kMenu_XOR: |
| 7293 | | entry->xor -= increment; |
| 7294 | | entry->xor &= kSearchByteMaskTable[kWatchSizeConversionTable[entry->elementBytes]]; |
| 7295 | | break; |
| 9052 | case kMenu_XOR: |
| 9053 | entry->xor -= increment; |
| 9054 | entry->xor &= kSearchByteMaskTable[kWatchSizeConversionTable[entry->elementBytes]]; |
| 9055 | } |
| 7296 | 9056 | } |
| 7297 | 9057 | } |
| 7298 | | |
| 7299 | | if(UIPressedRepeatThrottle(machine, IPT_UI_RIGHT, kHorizontalSlowKeyRepeatRate)) |
| 9058 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_RIGHT, kHorizontalSlowKeyRepeatRate)) |
| 7300 | 9059 | { |
| 7301 | | editActive = 0; |
| 7302 | | |
| 7303 | | switch(sel) |
| 9060 | if(editActive) |
| 7304 | 9061 | { |
| 7305 | | case kMenu_Address: |
| 7306 | | entry->address = DoShift(entry->address, entry->addressShift); |
| 7307 | | entry->address += increment; |
| 7308 | | entry->address = DoShift(entry->address, -entry->addressShift); |
| 7309 | | entry->address &= cpuInfoList[entry->cpu].addressMask; |
| 7310 | | break; |
| 9062 | // underconstruction... |
| 9063 | } |
| 9064 | else |
| 9065 | { |
| 9066 | switch(menu->sel) |
| 9067 | { |
| 9068 | case kMenu_Address: |
| 9069 | entry->address = DoShift(entry->address, entry->addressShift); |
| 9070 | entry->address += increment; |
| 9071 | entry->address = DoShift(entry->address, -entry->addressShift); |
| 7311 | 9072 | |
| 7312 | | case kMenu_CPU: |
| 7313 | | entry->cpu++; |
| 9073 | if(!TEST_FIELD(entry->cpu, RegionFlag)) |
| 9074 | entry->address &= info->address_mask; |
| 9075 | break; |
| 7314 | 9076 | |
| 7315 | | if(entry->cpu >= cpu_gettotalcpu()) |
| 7316 | | entry->cpu = 0; |
| 9077 | case kMenu_CPU: |
| 9078 | entry->cpu++; |
| 7317 | 9079 | |
| 7318 | | entry->address &= cpuInfoList[entry->cpu].addressMask; |
| 7319 | | break; |
| 9080 | if(entry->cpu >= cpu_gettotalcpu()) |
| 9081 | entry->cpu = 0; |
| 7320 | 9082 | |
| 7321 | | case kMenu_NumElements: |
| 7322 | | entry->numElements++; |
| 7323 | | break; |
| 9083 | entry->address &= info->address_mask; |
| 9084 | break; |
| 7324 | 9085 | |
| 7325 | | case kMenu_ElementSize: |
| 7326 | | if(entry->elementBytes < kSearchSize_32Bit) |
| 7327 | | entry->elementBytes++; |
| 7328 | | else |
| 7329 | | entry->elementBytes = kSearchSize_32Bit; |
| 9086 | case kMenu_NumElements: |
| 9087 | entry->numElements++; |
| 9088 | break; |
| 7330 | 9089 | |
| 7331 | | entry->xor &= kSearchByteMaskTable[kWatchSizeConversionTable[entry->elementBytes]]; |
| 7332 | | break; |
| 9090 | case kMenu_ElementSize: |
| 9091 | if(entry->elementBytes < kSearchSize_32Bit) |
| 9092 | entry->elementBytes++; |
| 9093 | else |
| 9094 | entry->elementBytes = kSearchSize_32Bit; |
| 7333 | 9095 | |
| 7334 | | case kMenu_LabelType: |
| 7335 | | if(entry->labelType < kWatchLabel_MaxPlusOne - 1) |
| 7336 | | entry->labelType++; |
| 7337 | | else |
| 7338 | | entry->labelType = kWatchLabel_MaxPlusOne - 1; |
| 7339 | | break; |
| 9096 | entry->xor &= kSearchByteMaskTable[kWatchSizeConversionTable[entry->elementBytes]]; |
| 9097 | break; |
| 7340 | 9098 | |
| 7341 | | case kMenu_TextLabel: |
| 7342 | | break; |
| 9099 | case kMenu_LabelType: |
| 9100 | if(entry->labelType < kWatchLabel_MaxPlusOne - 1) |
| 9101 | entry->labelType++; |
| 9102 | else |
| 9103 | entry->labelType = kWatchLabel_MaxPlusOne - 1; |
| 9104 | break; |
| 7343 | 9105 | |
| 7344 | | case kMenu_DisplayType: |
| 7345 | | if(entry->displayType < kWatchDisplayType_MaxPlusOne - 1) |
| 7346 | | entry->displayType++; |
| 7347 | | else |
| 7348 | | entry->displayType = kWatchDisplayType_MaxPlusOne - 1; |
| 7349 | | break; |
| 9106 | case kMenu_TextLabel: |
| 9107 | break; |
| 7350 | 9108 | |
| 7351 | | case kMenu_XPosition: |
| 7352 | | entry->x += 0.01f; |
| 7353 | | break; |
| 9109 | case kMenu_DisplayType: |
| 9110 | if(entry->displayType < kWatchDisplayType_MaxPlusOne - 1) |
| 9111 | entry->displayType++; |
| 9112 | else |
| 9113 | entry->displayType = kWatchDisplayType_MaxPlusOne - 1; |
| 9114 | break; |
| 7354 | 9115 | |
| 7355 | | case kMenu_YPosition: |
| 7356 | | entry->y += 0.01f; |
| 7357 | | break; |
| 9116 | case kMenu_XPosition: |
| 9117 | entry->x += 0.01f; |
| 9118 | break; |
| 7358 | 9119 | |
| 7359 | | case kMenu_Skip: |
| 7360 | | entry->skip++; |
| 7361 | | break; |
| 9120 | case kMenu_YPosition: |
| 9121 | entry->y += 0.01f; |
| 9122 | break; |
| 7362 | 9123 | |
| 7363 | | case kMenu_ElementsPerLine: |
| 7364 | | entry->elementsPerLine++; |
| 7365 | | break; |
| 9124 | case kMenu_Skip: |
| 9125 | entry->skip++; |
| 9126 | break; |
| 7366 | 9127 | |
| 7367 | | case kMenu_AddValue: |
| 7368 | | entry->addValue = (entry->addValue + 1) & 0xFF; |
| 7369 | | break; |
| 9128 | case kMenu_ElementsPerLine: |
| 9129 | entry->elementsPerLine++; |
| 9130 | break; |
| 7370 | 9131 | |
| 7371 | | case kMenu_AddressShift: |
| 7372 | | if(entry->addressShift < 31) |
| 7373 | | entry->addressShift++; |
| 7374 | | else |
| 7375 | | entry->addressShift = -31; |
| 7376 | | break; |
| 9132 | case kMenu_AddValue: |
| 9133 | entry->addValue = (entry->addValue + 1) & 0xFF; |
| 9134 | break; |
| 7377 | 9135 | |
| 7378 | | case kMenu_DataShift: |
| 7379 | | if(entry->dataShift < 31) |
| 7380 | | entry->dataShift++; |
| 7381 | | else |
| 7382 | | entry->dataShift = -31; |
| 7383 | | break; |
| 9136 | case kMenu_AddressShift: |
| 9137 | if(entry->addressShift < 31) |
| 9138 | entry->addressShift++; |
| 9139 | else |
| 9140 | entry->addressShift = -31; |
| 9141 | break; |
| 7384 | 9142 | |
| 7385 | | case kMenu_XOR: |
| 7386 | | entry->xor += increment; |
| 7387 | | entry->xor &= kSearchByteMaskTable[kWatchSizeConversionTable[entry->elementBytes]]; |
| 7388 | | break; |
| 9143 | case kMenu_DataShift: |
| 9144 | if(entry->dataShift < 31) |
| 9145 | entry->dataShift++; |
| 9146 | else |
| 9147 | entry->dataShift = -31; |
| 9148 | break; |
| 9149 | |
| 9150 | case kMenu_XOR: |
| 9151 | entry->xor += increment; |
| 9152 | entry->xor &= kSearchByteMaskTable[kWatchSizeConversionTable[entry->elementBytes]]; |
| 9153 | } |
| 7389 | 9154 | } |
| 7390 | 9155 | } |
| 7391 | | |
| 7392 | | if(UIPressedRepeatThrottle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate)) |
| 9156 | else if(input_ui_pressed(machine, IPT_UI_SELECT)) |
| 7393 | 9157 | { |
| 7394 | | sel++; |
| 7395 | | |
| 7396 | | if(sel >= total) |
| 7397 | | sel = 0; |
| 7398 | | |
| 7399 | | editActive = 0; |
| 7400 | | } |
| 7401 | | |
| 7402 | | if(UIPressedRepeatThrottle(machine, IPT_UI_UP, kVerticalKeyRepeatRate)) |
| 7403 | | { |
| 7404 | | sel--; |
| 7405 | | |
| 7406 | | if(sel < 0) |
| 7407 | | sel = total - 1; |
| 7408 | | |
| 7409 | | editActive = 0; |
| 7410 | | } |
| 7411 | | |
| 7412 | | if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate)) |
| 7413 | | { |
| 7414 | | sel -= fullMenuPageHeight; |
| 7415 | | |
| 7416 | | if(sel < 0) |
| 7417 | | sel = 0; |
| 7418 | | |
| 7419 | | editActive = 0; |
| 7420 | | } |
| 7421 | | |
| 7422 | | if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate)) |
| 7423 | | { |
| 7424 | | sel += fullMenuPageHeight; |
| 7425 | | |
| 7426 | | if(sel >= total) |
| 7427 | | sel = total - 1; |
| 7428 | | |
| 7429 | | editActive = 0; |
| 7430 | | } |
| 7431 | | |
| 7432 | | if(input_ui_pressed(machine, IPT_UI_SELECT)) |
| 7433 | | { |
| 7434 | 9158 | if(editActive) |
| 7435 | 9159 | editActive = 0; |
| 7436 | 9160 | else |
| 7437 | 9161 | { |
| 7438 | | switch(sel) |
| 9162 | switch(menu->sel) |
| 7439 | 9163 | { |
| 7440 | | case kMenu_Return: |
| 7441 | | sel = -1; |
| 7442 | | break; |
| 7443 | | |
| 7444 | 9164 | case kMenu_Address: |
| 7445 | 9165 | case kMenu_CPU: |
| 7446 | 9166 | case kMenu_NumElements: |
| r2762 | r2763 | |
| 7453 | 9173 | case kMenu_XOR: |
| 7454 | 9174 | osd_readkey_unicode(1); |
| 7455 | 9175 | editActive = 1; |
| 9176 | break; |
| 9177 | |
| 9178 | case kMenu_Return: |
| 9179 | menu->sel = -1; |
| 7456 | 9180 | } |
| 7457 | 9181 | } |
| 7458 | 9182 | } |
| 9183 | else if(input_ui_pressed(machine, IPT_UI_CLEAR)) |
| 9184 | { |
| 9185 | ResetWatch(entry); |
| 9186 | } |
| 9187 | else if(input_ui_pressed(machine, IPT_UI_CANCEL)) |
| 9188 | { |
| 9189 | if(editActive) |
| 9190 | editActive = 0; |
| 9191 | else |
| 9192 | menu->sel = -1; |
| 9193 | } |
| 7459 | 9194 | |
| 7460 | 9195 | if(editActive) |
| 7461 | 9196 | { |
| 7462 | | switch(sel) |
| 9197 | switch(menu->sel) |
| 7463 | 9198 | { |
| 7464 | 9199 | case kMenu_Address: |
| 7465 | 9200 | entry->address = DoShift(entry->address, entry->addressShift); |
| 7466 | | entry->address = DoEditHexField(machine, entry->address); |
| 9201 | entry->address = do_edit_hex_field(machine, entry->address); |
| 7467 | 9202 | entry->address = DoShift(entry->address, -entry->addressShift); |
| 7468 | | entry->address &= cpuInfoList[entry->cpu].addressMask; |
| 9203 | entry->address &= info->address_mask; |
| 7469 | 9204 | break; |
| 7470 | 9205 | |
| 7471 | 9206 | case kMenu_CPU: |
| 7472 | 9207 | entry->cpu = DoEditDecField(entry->cpu, 0, cpu_gettotalcpu() - 1); |
| 7473 | | entry->address &= cpuInfoList[entry->cpu].addressMask; |
| 9208 | entry->address &= info->address_mask; |
| 7474 | 9209 | break; |
| 7475 | 9210 | |
| 7476 | 9211 | case kMenu_NumElements: |
| r2762 | r2763 | |
| 7502 | 9237 | break; |
| 7503 | 9238 | |
| 7504 | 9239 | case kMenu_XOR: |
| 7505 | | entry->xor = DoEditHexField(machine, entry->xor); |
| 9240 | entry->xor = do_edit_hex_field(machine, entry->xor); |
| 7506 | 9241 | entry->xor &= kSearchByteMaskTable[kWatchSizeConversionTable[entry->elementBytes]]; |
| 7507 | 9242 | break; |
| 7508 | 9243 | } |
| 7509 | | |
| 7510 | | if(input_ui_pressed(machine, IPT_UI_CANCEL)) |
| 7511 | | editActive = 0; |
| 7512 | 9244 | } |
| 7513 | 9245 | else |
| 7514 | 9246 | { |
| r2762 | r2763 | |
| 7520 | 9252 | |
| 7521 | 9253 | if(input_ui_pressed(machine, IPT_UI_SAVE_CHEAT)) |
| 7522 | 9254 | { |
| 7523 | | CheatEntry tempEntry; |
| 9255 | CheatEntry tempEntry; |
| 7524 | 9256 | |
| 7525 | 9257 | memset(&tempEntry, 0, sizeof(CheatEntry)); |
| 7526 | 9258 | |
| 7527 | 9259 | SetupCheatFromWatchAsWatch(&tempEntry, entry); |
| 7528 | | SaveCheat(machine, &tempEntry, 0, 0); |
| 9260 | SaveCheatCode(machine, &tempEntry); |
| 7529 | 9261 | DisposeCheat(&tempEntry); |
| 7530 | 9262 | } |
| 7531 | 9263 | } |
| 7532 | 9264 | |
| 7533 | | if(input_ui_pressed(machine, IPT_UI_CANCEL)) |
| 7534 | | sel = -1; |
| 7535 | | |
| 7536 | | return sel + 1; |
| 9265 | return menu->sel + 1; |
| 7537 | 9266 | } |
| 7538 | 9267 | |
| 7539 | | /*---------------------------------------------- |
| 7540 | | SelectOptions - management for options menu |
| 7541 | | ----------------------------------------------*/ |
| 9268 | /*--------------------------------------------------- |
| 9269 | select_option_menu - management for options menu |
| 9270 | ---------------------------------------------------*/ |
| 7542 | 9271 | |
| 7543 | | static int SelectOptions(running_machine *machine, int selection) |
| 9272 | static int select_option_menu(running_machine *machine, cheat_menu_stack *menu) |
| 7544 | 9273 | { |
| 7545 | | enum |
| 7546 | | { |
| 9274 | enum{ |
| 7547 | 9275 | kMenu_SelectSearch = 0, |
| 9276 | kMenu_LoadCheatOptions, |
| 9277 | kMenu_SaveCheatOptions, |
| 9278 | kMenu_ResetCheatOptions, |
| 9279 | kMenu_Separator, |
| 7548 | 9280 | kMenu_SearchDialogStyle, |
| 7549 | 9281 | kMenu_ShowSearchLabels, |
| 7550 | 9282 | kMenu_AutoSaveCheats, |
| 7551 | 9283 | kMenu_ShowActivationKeyMessage, |
| 7552 | 9284 | kMenu_LoadOldFormat, |
| 7553 | | kMenu_Debug, |
| 9285 | #ifdef MESS |
| 9286 | kMenu_SharedCode, |
| 9287 | #endif |
| 7554 | 9288 | kMenu_Return, |
| 7555 | 9289 | |
| 7556 | | kMenu_Max |
| 7557 | | }; |
| 9290 | kMenu_Max }; |
| 7558 | 9291 | |
| 7559 | | INT32 sel; |
| 7560 | | static INT32 submenuChoice = 0; |
| 7561 | | const char * menuItem[kMenu_Max + 1]; |
| 7562 | | const char * menuSubItem[kMenu_Max + 1]; |
| 7563 | | int total = 0; |
| 9292 | UINT8 total = 0; |
| 9293 | const char * menu_item[kMenu_Max + 1]; |
| 9294 | const char * menu_sub_item[kMenu_Max + 1]; |
| 7564 | 9295 | |
| 7565 | | sel = selection - 1; |
| 9296 | /* first setting : NONE */ |
| 9297 | if(menu->first_time) |
| 9298 | menu->first_time = 0; |
| 7566 | 9299 | |
| 7567 | | /********** SUB MENU **********/ |
| 7568 | | if(submenuChoice) |
| 7569 | | { |
| 7570 | | switch(sel) |
| 7571 | | { |
| 7572 | | case kMenu_SelectSearch: |
| 7573 | | submenuChoice = SelectSearch(machine, submenuChoice); |
| 7574 | | break; |
| 9300 | /********** MENU CONSTRUCTION **********/ |
| 9301 | /* ##### SEARCH REGION ##### */ |
| 9302 | ADD_MENU_2_ITEMS("Select Search", NULL); |
| 7575 | 9303 | |
| 7576 | | default: |
| 7577 | | submenuChoice = 0; |
| 7578 | | sel = -1; |
| 7579 | | break; |
| 7580 | | } |
| 9304 | /* ##### LOAD CHEAT OPTIONS ##### */ |
| 9305 | ADD_MENU_2_ITEMS("Load Cheat Options", NULL); |
| 7581 | 9306 | |
| 7582 | | if(submenuChoice == -1) |
| 7583 | | submenuChoice = 0; |
| 9307 | /* ##### SAVE CHEAT OPTIONS ##### */ |
| 9308 | ADD_MENU_2_ITEMS("Save Cheat Options", NULL); |
| 7584 | 9309 | |
| 7585 | | return sel + 1; |
| 7586 | | } |
| 9310 | /* ##### RESET CHEAT OPTIONS ##### */ |
| 9311 | ADD_MENU_2_ITEMS("Reset Cheat Options", NULL); |
| 7587 | 9312 | |
| 7588 | | /********** MENU CONSTRUCTION **********/ |
| 7589 | | menuItem[total] = "Select Search"; |
| 7590 | | menuSubItem[total++] = NULL; |
| 9313 | /* ##### SEPARATOR ##### */ |
| 9314 | ADD_MENU_2_ITEMS(MENU_SEPARATOR_ITEM, NULL); |
| 7591 | 9315 | |
| 7592 | | menuItem[total] = "Search Dialog Style"; |
| 9316 | /* ##### SEARCH MENU ##### */ |
| 9317 | menu_item[total] = "Search Dialog Style"; |
| 7593 | 9318 | switch(EXTRACT_FIELD(cheatOptions, SearchBox)) |
| 7594 | 9319 | { |
| 7595 | 9320 | case kSearchBox_Minimum: |
| 7596 | | menuSubItem[total++] = "Minimum"; |
| 9321 | menu_sub_item[total++] = "Minimum"; |
| 7597 | 9322 | break; |
| 7598 | 9323 | |
| 7599 | | case kSearchBox_Classic: |
| 7600 | | menuSubItem[total++] = "Classic"; |
| 9324 | case kSearchBox_Standard: |
| 9325 | menu_sub_item[total++] = "Standard"; |
| 7601 | 9326 | break; |
| 7602 | 9327 | |
| 7603 | 9328 | case kSearchBox_Advanced: |
| 7604 | | menuSubItem[total++] = "Advanced"; |
| 9329 | menu_sub_item[total++] = "Advanced"; |
| 7605 | 9330 | break; |
| 9331 | |
| 9332 | default: |
| 9333 | menu_sub_item[total++] = "<< No Search Box >>"; |
| 9334 | break; |
| 7606 | 9335 | } |
| 7607 | 9336 | |
| 7608 | | menuItem[total] = "Show Search Labels"; |
| 7609 | | menuSubItem[total++] = TEST_FIELD(cheatOptions, DontPrintNewLabels) ? "Off" : "On"; |
| 9337 | /* ##### SEARCH LABEL ##### */ |
| 9338 | ADD_MENU_2_ITEMS("Show Search Labels", TEST_FIELD(cheatOptions, DontPrintNewLabels) ? "Off" : "On"); |
| 7610 | 9339 | |
| 7611 | | menuItem[total] = "Auto Save Cheats"; |
| 7612 | | menuSubItem[total++] = TEST_FIELD(cheatOptions, AutoSaveEnabled) ? "On" : "Off"; |
| 9340 | /* ##### AUTO SAVE ##### */ |
| 9341 | ADD_MENU_2_ITEMS("Auto Save Cheats", TEST_FIELD(cheatOptions, AutoSaveEnabled) ? "On" : "Off"); |
| 7613 | 9342 | |
| 7614 | | menuItem[total] = "Show Activation Key Message"; |
| 7615 | | menuSubItem[total++] = TEST_FIELD(cheatOptions, ActivationKeyMessage) ? "On" : "Off"; |
| 9343 | /* ##### ACTIVATION KEY MESSAGE ##### */ |
| 9344 | ADD_MENU_2_ITEMS("Show Activation Key Message", TEST_FIELD(cheatOptions, ActivationKeyMessage) ? "On" : "Off"); |
| 7616 | 9345 | |
| 7617 | | menuItem[total] = "Load Old Format Code"; |
| 7618 | | menuSubItem[total++] = TEST_FIELD(cheatOptions, LoadOldFormat) ? "On" : "Off"; |
| 9346 | /* ##### OLD FORMAT LOADING ##### */ |
| 9347 | ADD_MENU_2_ITEMS("Load Old Format Code", TEST_FIELD(cheatOptions, LoadOldFormat) ? "On" : "Off"); |
| 7619 | 9348 | |
| 7620 | | menuItem[total] = "Debug"; |
| 7621 | | menuSubItem[total++] = TEST_FIELD(cheatOptions, Debug) ? "On" : "Off"; |
| 9349 | #ifdef MESS |
| 9350 | /* ##### SHARED CODE ##### */ |
| 9351 | ADD_MENU_2_ITEMS("Shared Code", TEST_FIELD(cheatOptions, SharedCode) ? "On" : "Off"); |
| 9352 | #endif |
| 7622 | 9353 | |
| 7623 | | menuItem[total] = "Return to Prior Menu"; // return |
| 7624 | | menuSubItem[total++] = NULL; |
| 9354 | /* ##### RETURN ##### */ |
| 9355 | ADD_MENU_2_ITEMS("Return to Prior Menu", NULL); |
| 7625 | 9356 | |
| 7626 | | menuItem[total] = NULL; // terminate array |
| 7627 | | menuSubItem[total] = NULL; |
| 9357 | /* ##### TERMINATE ALLAY ##### */ |
| 9358 | TERMINATE_MENU_2_ITEMS; |
| 7628 | 9359 | |
| 7629 | | /* ----- draw it ----- */ |
| 7630 | | old_style_menu(menuItem, menuSubItem, NULL, sel, 0); |
| 9360 | /* draw it */ |
| 9361 | old_style_menu(menu_item, menu_sub_item, NULL, menu->sel, 0); |
| 7631 | 9362 | |
| 7632 | 9363 | /********** KEY HANDLING **********/ |
| 7633 | | if(UIPressedRepeatThrottle(machine, IPT_UI_RIGHT, kHorizontalSlowKeyRepeatRate)) |
| 9364 | if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate)) |
| 7634 | 9365 | { |
| 7635 | | switch(sel) |
| 9366 | CURSOR_TO_PREVIOUS(menu->sel, total) |
| 9367 | |
| 9368 | if(menu->sel == kMenu_Separator) |
| 9369 | menu->sel--; |
| 9370 | } |
| 9371 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate)) |
| 9372 | { |
| 9373 | CURSOR_TO_NEXT(menu->sel, total) |
| 9374 | |
| 9375 | if(menu->sel == kMenu_Separator) |
| 9376 | menu->sel++; |
| 9377 | } |
| 9378 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate)) |
| 9379 | { |
| 9380 | CURSOR_PAGE_UP(menu->sel) |
| 9381 | } |
| 9382 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate)) |
| 9383 | { |
| 9384 | CURSOR_PAGE_DOWN(menu->sel, total) |
| 9385 | } |
| 9386 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_LEFT, kHorizontalSlowKeyRepeatRate)) |
| 9387 | { |
| 9388 | switch(menu->sel) |
| 7636 | 9389 | { |
| 7637 | 9390 | case kMenu_SearchDialogStyle: |
| 7638 | | { |
| 7639 | | UINT8 length = (EXTRACT_FIELD(cheatOptions, SearchBox) + 1) & 3; |
| 9391 | { |
| 9392 | UINT8 length = (EXTRACT_FIELD(cheatOptions, SearchBox) - 1) & 3; |
| 7640 | 9393 | |
| 7641 | | if(length > kSearchBox_Advanced) |
| 7642 | | length = kSearchBox_Minimum; |
| 9394 | if(length > kSearchBox_Advanced) |
| 9395 | length = kSearchBox_Advanced; |
| 7643 | 9396 | |
| 7644 | | SET_FIELD(cheatOptions, SearchBox, length); |
| 7645 | | } |
| 7646 | | break; |
| 9397 | SET_FIELD(cheatOptions, SearchBox, length); |
| 9398 | } |
| 9399 | break; |
| 7647 | 9400 | |
| 7648 | 9401 | case kMenu_ShowSearchLabels: |
| 7649 | 9402 | TOGGLE_MASK_FIELD(cheatOptions, DontPrintNewLabels); |
| r2762 | r2763 | |
| 7660 | 9413 | case kMenu_LoadOldFormat: |
| 7661 | 9414 | TOGGLE_MASK_FIELD(cheatOptions, LoadOldFormat); |
| 7662 | 9415 | break; |
| 7663 | | |
| 7664 | | case kMenu_Debug: |
| 7665 | | TOGGLE_MASK_FIELD(cheatOptions, Debug); |
| 7666 | | break; |
| 9416 | #ifdef MESS |
| 9417 | case kMenu_SharedCode: |
| 9418 | TOGGLE_MASK_FIELD(cheatOptions, SharedCode); |
| 9419 | #endif |
| 7667 | 9420 | } |
| 7668 | 9421 | } |
| 7669 | | |
| 7670 | | if(UIPressedRepeatThrottle(machine, IPT_UI_LEFT, kHorizontalSlowKeyRepeatRate)) |
| 9422 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_RIGHT, kHorizontalSlowKeyRepeatRate)) |
| 7671 | 9423 | { |
| 7672 | | switch(sel) |
| 9424 | switch(menu->sel) |
| 7673 | 9425 | { |
| 7674 | 9426 | case kMenu_SearchDialogStyle: |
| 7675 | | { |
| 7676 | | UINT8 length = (EXTRACT_FIELD(cheatOptions, SearchBox) - 1) & 3; |
| 9427 | { |
| 9428 | UINT8 length = (EXTRACT_FIELD(cheatOptions, SearchBox) + 1) & 3; |
| 7677 | 9429 | |
| 7678 | | if(length > kSearchBox_Advanced) |
| 7679 | | length = kSearchBox_Advanced; |
| 9430 | if(length > kSearchBox_Advanced) |
| 9431 | length = kSearchBox_Minimum; |
| 7680 | 9432 | |
| 7681 | | SET_FIELD(cheatOptions, SearchBox, length); |
| 7682 | | } |
| 7683 | | break; |
| 9433 | SET_FIELD(cheatOptions, SearchBox, length); |
| 9434 | } |
| 9435 | break; |
| 7684 | 9436 | |
| 7685 | 9437 | case kMenu_ShowSearchLabels: |
| 7686 | 9438 | TOGGLE_MASK_FIELD(cheatOptions, DontPrintNewLabels); |
| r2762 | r2763 | |
| 7696 | 9448 | |
| 7697 | 9449 | case kMenu_LoadOldFormat: |
| 7698 | 9450 | TOGGLE_MASK_FIELD(cheatOptions, LoadOldFormat); |
| 7699 | | break; |
| 7700 | 9451 | |
| 7701 | | case kMenu_Debug: |
| 7702 | | TOGGLE_MASK_FIELD(cheatOptions, Debug); |
| 7703 | | break; |
| 9452 | #ifdef MESS |
| 9453 | case kMenu_SharedCode: |
| 9454 | TOGGLE_MASK_FIELD(cheatOptions, SharedCode); |
| 9455 | #endif |
| 7704 | 9456 | } |
| 7705 | 9457 | } |
| 7706 | | |
| 7707 | | if(UIPressedRepeatThrottle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate)) |
| 9458 | else if(input_ui_pressed(machine, IPT_UI_SELECT)) |
| 7708 | 9459 | { |
| 7709 | | if(sel < (kMenu_Max - 1)) |
| 7710 | | sel++; |
| 7711 | | else |
| 7712 | | sel = 0; |
| 7713 | | } |
| 9460 | switch(menu->sel) |
| 9461 | { |
| 9462 | case kMenu_SelectSearch: |
| 9463 | cheat_menu_stack_push(select_search_menu, menu->handler, menu->sel); |
| 9464 | break; |
| 7714 | 9465 | |
| 7715 | | if(UIPressedRepeatThrottle(machine, IPT_UI_UP, kVerticalKeyRepeatRate)) |
| 7716 | | { |
| 7717 | | if(sel > 0) |
| 7718 | | sel--; |
| 7719 | | else |
| 7720 | | sel = kMenu_Max - 1; |
| 7721 | | } |
| 9466 | case kMenu_LoadCheatOptions: |
| 9467 | LoadCheatDatabase(machine, kLoadFlag_CheatOption); |
| 9468 | break; |
| 7722 | 9469 | |
| 7723 | | if(input_ui_pressed(machine, IPT_UI_SELECT)) |
| 7724 | | { |
| 7725 | | switch(sel) |
| 7726 | | { |
| 7727 | | case kMenu_Return: |
| 7728 | | submenuChoice = 0; |
| 7729 | | sel = -1; |
| 9470 | case kMenu_SaveCheatOptions: |
| 9471 | SaveCheatOptions(); |
| 7730 | 9472 | break; |
| 7731 | 9473 | |
| 7732 | | case kMenu_SelectSearch: |
| 7733 | | submenuChoice = 1; |
| 9474 | case kMenu_ResetCheatOptions: |
| 9475 | cheatOptions = DEFAULT_CHEAT_OPTIONS; |
| 7734 | 9476 | break; |
| 9477 | |
| 9478 | case kMenu_Return: |
| 9479 | menu->sel = -1; |
| 7735 | 9480 | } |
| 7736 | 9481 | } |
| 7737 | | |
| 7738 | | if(input_ui_pressed(machine, IPT_UI_SAVE_CHEAT)) |
| 9482 | else if(input_ui_pressed(machine, IPT_UI_SAVE_CHEAT)) |
| 7739 | 9483 | { |
| 7740 | | SaveCheat(machine, NULL, 0, 2); |
| 7741 | | |
| 7742 | | ui_popup_time(1, "command code saved"); |
| 9484 | SaveCheatOptions(); |
| 7743 | 9485 | } |
| 9486 | else if(input_ui_pressed(machine, IPT_UI_RELOAD_CHEAT)) |
| 9487 | { |
| 9488 | LoadCheatDatabase(machine, kLoadFlag_CheatOption); |
| 9489 | } |
| 9490 | else if(input_ui_pressed(machine, IPT_UI_CANCEL)) |
| 9491 | { |
| 9492 | menu->sel = -1; |
| 9493 | } |
| 7744 | 9494 | |
| 7745 | | if(input_ui_pressed(machine, IPT_UI_RELOAD_CHEAT)) |
| 7746 | | ReloadCheatDatabase(machine); |
| 7747 | | |
| 7748 | | if(input_ui_pressed(machine, IPT_UI_CANCEL)) |
| 7749 | | sel = -1; |
| 7750 | | |
| 7751 | | return sel + 1; |
| 9495 | return menu->sel + 1; |
| 7752 | 9496 | } |
| 7753 | 9497 | |
| 7754 | | /*------------------------------------------------------ |
| 7755 | | SelectSearch - management for search selection menu |
| 7756 | | ------------------------------------------------------*/ |
| 9498 | /*------------------------------------------------------------ |
| 9499 | select_search_menu - management for search selection menu |
| 9500 | ------------------------------------------------------------*/ |
| 7757 | 9501 | |
| 7758 | | static int SelectSearch(running_machine *machine, int selection) |
| 9502 | static int select_search_menu(running_machine *machine, cheat_menu_stack *menu) |
| 7759 | 9503 | { |
| 9504 | #if 0 |
| 7760 | 9505 | INT32 sel; |
| 7761 | 9506 | const char ** menuItem; |
| 7762 | 9507 | char ** buf; |
| r2762 | r2763 | |
| 7765 | 9510 | |
| 7766 | 9511 | sel = selection - 1; |
| 7767 | 9512 | |
| 7768 | | RequestStrings(searchListLength + 2, searchListLength, 300, 0); |
| 9513 | request_strings(search_list_length + 2, search_list_length, 300, 0); |
| 7769 | 9514 | |
| 7770 | | menuItem = menuStrings.mainList; |
| 7771 | | buf = menuStrings.mainStrings; |
| 9515 | menuItem = menu_strings.main_list; |
| 9516 | buf = menu_strings.main_strings; |
| 7772 | 9517 | |
| 7773 | 9518 | /********** MENU CONSTRUCTION **********/ |
| 7774 | | for(i = 0; i < searchListLength; i++) |
| 9519 | for(i = 0; i < search_list_length; i++) |
| 7775 | 9520 | { |
| 7776 | | SearchInfo * info = &searchList[i]; |
| 9521 | search_info *info = &search_list[i]; |
| 7777 | 9522 | |
| 7778 | | if(i == currentSearchIdx) |
| 9523 | if(i == current_search_idx) |
| 7779 | 9524 | { |
| 7780 | 9525 | if(info->name) |
| 7781 | 9526 | sprintf(buf[total], "[#%d: %s]", i, info->name); |
| r2762 | r2763 | |
| 7798 | 9543 | |
| 7799 | 9544 | menuItem[total] = NULL; // terminate array |
| 7800 | 9545 | |
| 7801 | | /* ----- adjust current cursor position ----- */ |
| 9546 | /* adjust current cursor position */ |
| 7802 | 9547 | if(sel < 0) |
| 7803 | 9548 | sel = 0; |
| 7804 | 9549 | if(sel > (total - 1)) |
| 7805 | 9550 | sel = total - 1; |
| 7806 | 9551 | |
| 7807 | | /* ----- draw it ----- */ |
| 9552 | /* draw it */ |
| 7808 | 9553 | old_style_menu(menuItem, NULL, NULL, sel, 0); |
| 7809 | 9554 | |
| 7810 | 9555 | /********** KEY HANDLING **********/ |
| 7811 | | if(UIPressedRepeatThrottle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate)) |
| 9556 | if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate)) |
| 7812 | 9557 | { |
| 7813 | 9558 | sel++; |
| 7814 | 9559 | |
| r2762 | r2763 | |
| 7816 | 9561 | sel = 0; |
| 7817 | 9562 | } |
| 7818 | 9563 | |
| 7819 | | if(UIPressedRepeatThrottle(machine, IPT_UI_UP, kVerticalKeyRepeatRate)) |
| 9564 | if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate)) |
| 7820 | 9565 | { |
| 7821 | 9566 | sel--; |
| 7822 | 9567 | |
| r2762 | r2763 | |
| 7824 | 9569 | sel = total - 1; |
| 7825 | 9570 | } |
| 7826 | 9571 | |
| 7827 | | if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate)) |
| 9572 | if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate)) |
| 7828 | 9573 | { |
| 7829 | 9574 | sel -= fullMenuPageHeight; |
| 7830 | 9575 | |
| r2762 | r2763 | |
| 7832 | 9577 | sel = 0; |
| 7833 | 9578 | } |
| 7834 | 9579 | |
| 7835 | | if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate)) |
| 9580 | if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate)) |
| 7836 | 9581 | { |
| 7837 | 9582 | sel += fullMenuPageHeight; |
| 7838 | 9583 | |
| r2762 | r2763 | |
| 7850 | 9595 | |
| 7851 | 9596 | if(input_ui_pressed(machine, IPT_UI_DELETE_CHEAT)) |
| 7852 | 9597 | { |
| 7853 | | if(searchListLength > 1) |
| 9598 | if(search_list_length > 1) |
| 7854 | 9599 | DeleteSearchAt(sel); |
| 7855 | 9600 | } |
| 7856 | 9601 | |
| 7857 | 9602 | if(input_ui_pressed(machine, IPT_UI_EDIT_CHEAT)) |
| 7858 | 9603 | { |
| 7859 | 9604 | if(sel < total - 1) |
| 7860 | | currentSearchIdx = sel; |
| 9605 | current_search_idx = sel; |
| 7861 | 9606 | } |
| 7862 | 9607 | |
| 7863 | 9608 | if(input_ui_pressed(machine, IPT_UI_SELECT)) |
| r2762 | r2763 | |
| 7865 | 9610 | if(sel >= total - 1) |
| 7866 | 9611 | sel = -1; |
| 7867 | 9612 | else |
| 7868 | | currentSearchIdx = sel; |
| 9613 | current_search_idx = sel; |
| 7869 | 9614 | } |
| 7870 | 9615 | |
| 7871 | 9616 | if(input_ui_pressed(machine, IPT_UI_CANCEL)) |
| 7872 | 9617 | sel = -1; |
| 9618 | #endif |
| 9619 | return menu->sel; |
| 9620 | } |
| 7873 | 9621 | |
| 7874 | | return sel + 1; |
| 9622 | #ifdef MAME_DEBUG |
| 9623 | /*----------------------------------------------------------------------- |
| 9624 | check_activation_key_code_menu - key code checker for activation key |
| 9625 | -----------------------------------------------------------------------*/ |
| 9626 | |
| 9627 | static int check_activation_key_code_menu(running_machine *machine, cheat_menu_stack *menu) |
| 9628 | { |
| 9629 | int code = input_code_poll_switches(FALSE); |
| 9630 | static int index = INPUT_CODE_INVALID; |
| 9631 | char stringsBuf[64]; |
| 9632 | char * buf = stringsBuf; |
| 9633 | astring * keyIndex = astring_alloc(); |
| 9634 | |
| 9635 | if(code != INPUT_CODE_INVALID) |
| 9636 | { |
| 9637 | /* NOTE : if first, no action to prevent from wrong display */ |
| 9638 | if(menu->first_time) |
| 9639 | menu->first_time = 0; |
| 9640 | else |
| 9641 | index = code; |
| 9642 | } |
| 9643 | |
| 9644 | /********** MENU CONSTRUCTION **********/ |
| 9645 | /* ##### HEADER ##### */ |
| 9646 | buf += sprintf(buf, "\tPress a key\n"); |
| 9647 | |
| 9648 | /* ##### KEY NAME / INDEX ##### */ |
| 9649 | if(index != INPUT_CODE_INVALID && input_code_pressed(index)) |
| 9650 | buf += sprintf(buf, "\t%s\n\t%X\n", astring_c(input_code_name(keyIndex, index)), index); |
| 9651 | else |
| 9652 | buf += sprintf(buf, "\n\n"); |
| 9653 | |
| 9654 | /* ##### RETURN ##### */ |
| 9655 | buf += sprintf(buf, "\t Return = Shift + Cancel "); |
| 9656 | |
| 9657 | /* print it */ |
| 9658 | ui_draw_message_window(stringsBuf); |
| 9659 | |
| 9660 | /* NOTE : shift + cancel is only key to return because normal cancel prevents from diplaying this key */ |
| 9661 | if(ShiftKeyPressed() && input_ui_pressed(machine, IPT_UI_CANCEL)) |
| 9662 | { |
| 9663 | index = INPUT_CODE_INVALID; |
| 9664 | menu->sel = -1; |
| 9665 | } |
| 9666 | |
| 9667 | astring_free(keyIndex); |
| 9668 | |
| 9669 | return menu->sel + 1; |
| 7875 | 9670 | } |
| 7876 | 9671 | |
| 9672 | /*------------------------------------------------------------------------------------------------ |
| 9673 | view_cpu_region_info_list_menu - view internal CPU or Region info list called from debug menu |
| 9674 | ------------------------------------------------------------------------------------------------*/ |
| 9675 | |
| 9676 | static int view_cpu_region_info_list_menu(running_machine *machine, cheat_menu_stack *menu) |
| 9677 | { |
| 9678 | enum{ |
| 9679 | kMenu_Header = 0, |
| 9680 | kMenu_Type, |
| 9681 | kMenu_DataBits, |
| 9682 | kMenu_AddressBites, |
| 9683 | kMenu_AddressMask, |
| 9684 | kMenu_Endianness, |
| 9685 | kMenu_AddressShift, |
| 9686 | kMenu_Return, |
| 9687 | kMenu_Max }; |
| 9688 | |
| 9689 | UINT8 total = 0; |
| 9690 | static INT8 index; |
| 9691 | const char ** menuItem; |
| 9692 | const char ** menuSubItem; |
| 9693 | char * headerBuf; |
| 9694 | char * regionNameBuf; |
| 9695 | char * dataBitsBuf; |
| 9696 | char * addressBitsBuf; |
| 9697 | char * addressMaskBuf; |
| 9698 | char * addressShiftBuf; |
| 9699 | cpu_region_info *info; |
| 9700 | |
| 9701 | /* required items = total items + (strings buf * 6 [max chars : 32]) */ |
| 9702 | request_strings(kMenu_Max, kMenu_Max - 2, 32, 0); |
| 9703 | menuItem = menu_strings.main_list; |
| 9704 | menuSubItem = menu_strings.sub_list; |
| 9705 | headerBuf = menu_strings.main_strings[0]; |
| 9706 | regionNameBuf = menu_strings.main_strings[1]; |
| 9707 | dataBitsBuf = menu_strings.main_strings[2]; |
| 9708 | addressBitsBuf = menu_strings.main_strings[3]; |
| 9709 | addressMaskBuf = menu_strings.main_strings[4]; |
| 9710 | addressShiftBuf = menu_strings.main_strings[5]; |
| 9711 | |
| 9712 | /* first setting : set index as 1st */ |
| 9713 | if(menu->first_time) |
| 9714 | { |
| 9715 | index = REGION_CPU1 - REGION_INVALID; |
| 9716 | menu->first_time = 0; |
| 9717 | } |
| 9718 | |
| 9719 | info = get_region_info(index + REGION_INVALID); |
| 9720 | |
| 9721 | /********** MENU CONSTRUCTION **********/ |
| 9722 | /* ##### HEADER ##### */ |
| 9723 | menuItem[total] = "Index"; |
| 9724 | sprintf(headerBuf, "%2.2d", index); |
| 9725 | menuSubItem[total++] = headerBuf; |
| 9726 | |
| 9727 | /* ##### CPU/REGION TYPE ##### */ |
| 9728 | menuItem[total] = "Region"; |
| 9729 | |
| 9730 | if(index < REGION_CPU8 - REGION_INVALID) |
| 9731 | sprintf(regionNameBuf, "%s (%s)", kRegionNames[index], cputype_name(info->type)); |
| 9732 | else |
| 9733 | sprintf(regionNameBuf, "%s (non-cpu)", kRegionNames[info->type - REGION_CPU1 + 1]); |
| 9734 | menuSubItem[total++] = regionNameBuf; |
| 9735 | |
| 9736 | /* ##### DATA BITS ##### */ |
| 9737 | menuItem[total] = "Data Bits"; |
| 9738 | sprintf(dataBitsBuf, "%d", info->data_bits); |
| 9739 | menuSubItem[total++] = dataBitsBuf; |
| 9740 | |
| 9741 | /* ##### ADDRESS BITS ##### */ |
| 9742 | menuItem[total] = "Address Bits"; |
| 9743 | sprintf(addressBitsBuf, "%d", info->address_bits); |
| 9744 | menuSubItem[total++] = addressBitsBuf; |
| 9745 | |
| 9746 | /* ##### ADDRESS MASK/LENGTH ##### */ |
| 9747 | menuItem[total] = "Address Mask"; |
| 9748 | sprintf(addressMaskBuf, "%X (%d)", info->address_mask, info->address_chars_needed); |
| 9749 | menuSubItem[total++] = addressMaskBuf; |
| 9750 | |
| 9751 | /* ##### ENDIANNESS ##### */ |
| 9752 | menuItem[total] = "Endianness"; |
| 9753 | menuSubItem[total++] = info->endianness ? "Big" : "Little"; |
| 9754 | |
| 9755 | /* ##### ADDRESS SHIFT ##### */ |
| 9756 | menuItem[total] = "AddressShift"; |
| 9757 | sprintf(addressShiftBuf, "%d", info->address_shift); |
| 9758 | menuSubItem[total++] = addressShiftBuf; |
| 9759 | |
| 9760 | /* ##### RETURN ##### */ |
| 9761 | menuItem[total] = "Return to Prior Menu"; |
| 9762 | menuSubItem[total++] = NULL; |
| 9763 | |
| 9764 | /* ##### TERMINATE ARRAY ##### */ |
| 9765 | menuItem[total] = NULL; |
| 9766 | menuSubItem[total] = NULL; |
| 9767 | |
| 9768 | /* draw it */ |
| 9769 | old_style_menu(menuItem, menuSubItem, NULL, menu->sel, 0); |
| 9770 | |
| 9771 | /* adjust current cursor position */ |
| 9772 | ADJUST_CURSOR(menu->sel, total) |
| 9773 | |
| 9774 | /********** KEY HANDLING **********/ |
| 9775 | if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate)) |
| 9776 | { |
| 9777 | CURSOR_TO_PREVIOUS(menu->sel, total) |
| 9778 | } |
| 9779 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate)) |
| 9780 | { |
| 9781 | CURSOR_TO_NEXT(menu->sel, total) |
| 9782 | } |
| 9783 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate)) |
| 9784 | { |
| 9785 | CURSOR_PAGE_UP(menu->sel) |
| 9786 | } |
| 9787 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate)) |
| 9788 | { |
| 9789 | CURSOR_PAGE_DOWN(menu->sel, total) |
| 9790 | } |
| 9791 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_RIGHT, kHorizontalSlowKeyRepeatRate)) |
| 9792 | { |
| 9793 | int i = index + 1; |
| 9794 | |
| 9795 | /* search next valid info list */ |
| 9796 | while(1) |
| 9797 | { |
| 9798 | if(i >= REGION_LIST_LENGTH - 1) |
| 9799 | { |
| 9800 | i = 0; |
| 9801 | continue; |
| 9802 | } |
| 9803 | |
| 9804 | if(region_info_list[i].type) |
| 9805 | { |
| 9806 | index = i; |
| 9807 | break; |
| 9808 | } |
| 9809 | else |
| 9810 | i++; |
| 9811 | } |
| 9812 | } |
| 9813 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_LEFT, kHorizontalSlowKeyRepeatRate)) |
| 9814 | { |
| 9815 | int i = index - 1; |
| 9816 | |
| 9817 | /* search previous valid info list */ |
| 9818 | while(1) |
| 9819 | { |
| 9820 | if(i < 0) |
| 9821 | { |
| 9822 | i = REGION_LIST_LENGTH - 1; |
| 9823 | continue; |
| 9824 | } |
| 9825 | |
| 9826 | if(region_info_list[i].type) |
| 9827 | { |
| 9828 | index = i; |
| 9829 | break; |
| 9830 | } |
| 9831 | else |
| 9832 | i--; |
| 9833 | } |
| 9834 | } |
| 9835 | else if(input_ui_pressed(machine, IPT_UI_SELECT)) |
| 9836 | { |
| 9837 | if(menu->sel == kMenu_Return) |
| 9838 | menu->sel = -1; |
| 9839 | } |
| 9840 | else if(input_ui_pressed(machine, IPT_UI_CANCEL)) |
| 9841 | { |
| 9842 | menu->sel = -1; |
| 9843 | } |
| 9844 | |
| 9845 | return menu->sel + 1; |
| 9846 | } |
| 9847 | |
| 9848 | /*----------------------------------------------------- |
| 9849 | debug_cheat_menu - view internal cheat engine data |
| 9850 | -----------------------------------------------------*/ |
| 9851 | |
| 9852 | static int debug_cheat_menu(running_machine *machine, cheat_menu_stack *menu) |
| 9853 | { |
| 9854 | enum{ |
| 9855 | kMenu_DriverName = 0, |
| 9856 | kMenu_GameName, |
| 9857 | #ifdef MESS |
| 9858 | kMenu_CRC, |
| 9859 | #endif |
| 9860 | kMenu_FullMenuPageHeight, |
| 9861 | kMenu_CheatListLength, |
| 9862 | kMenu_Separator, |
| 9863 | kMenu_CPURegionInfo, |
| 9864 | kMenu_KeyCodeChecker, |
| 9865 | kMenu_Return, |
| 9866 | kMenu_Max }; |
| 9867 | |
| 9868 | UINT8 total = 0; |
| 9869 | const char ** menuItem; |
| 9870 | const char ** menuSubItem; |
| 9871 | char * driverNameBuf; |
| 9872 | #ifdef MESS |
| 9873 | char * crcBuf; |
| 9874 | #endif |
| 9875 | char * heightBuf; |
| 9876 | char * numCodeBuf; |
| 9877 | |
| 9878 | /* first setting : NONE */ |
| 9879 | if(menu->first_time) |
| 9880 | menu->first_time = 0; |
| 9881 | |
| 9882 | /* required items = (total items + return + terminator) & (strings buf * 3 [MAME]/4 [MESS]) */ |
| 9883 | request_strings(kMenu_Max + 2, kMenu_Max, 64, 0); |
| 9884 | menuItem = menu_strings.main_list; |
| 9885 | menuSubItem = menu_strings.sub_list; |
| 9886 | driverNameBuf = menu_strings.main_strings[0]; |
| 9887 | heightBuf = menu_strings.main_strings[1]; |
| 9888 | numCodeBuf = menu_strings.main_strings[2]; |
| 9889 | #ifdef MESS |
| 9890 | crcBuf = menu_strings.main_strings[3]; |
| 9891 | #endif |
| 9892 | |
| 9893 | /********** MENU CONSTRUCTION **********/ |
| 9894 | /* ##### DRIVER NAME ##### */ |
| 9895 | menuItem[total] = "Driver"; |
| 9896 | { |
| 9897 | astring * driverName = astring_alloc(); |
| 9898 | |
| 9899 | sprintf(driverNameBuf, "%s", astring_c(core_filename_extract_base(driverName, machine->gamedrv->source_file, TRUE))); |
| 9900 | menuSubItem[total++] = driverNameBuf; |
| 9901 | astring_free(driverName); |
| 9902 | } |
| 9903 | |
| 9904 | /* ##### GAME / MACHINE NAME ##### */ |
| 9905 | #ifdef MESS |
| 9906 | menuItem[total] = "Machine"; |
| 9907 | #else |
| 9908 | menuItem[total] = "Game"; |
| 9909 | #endif |
| 9910 | menuSubItem[total++] = machine->gamedrv->name; |
| 9911 | |
| 9912 | #ifdef MESS |
| 9913 | /* ##### CRC (MESS ONLY) ##### */ |
| 9914 | menuItem[total] = "CRC"; |
| 9915 | sprintf(crcBuf, "%X", thisGameCRC); |
| 9916 | menuSubItem[total++] = crcBuf; |
| 9917 | #endif |
| 9918 | |
| 9919 | /* ##### FULL PAGE MENU HEIGHT ##### */ |
| 9920 | menuItem[total] = "Default Menu Height"; |
| 9921 | sprintf(heightBuf, "%d", fullMenuPageHeight); |
| 9922 | menuSubItem[total++] = heightBuf; |
| 9923 | |
| 9924 | /* ##### CHEAT LIST LENGTH ##### */ |
| 9925 | menuItem[total] = "Total Code Entries"; |
| 9926 | sprintf(numCodeBuf, "%d", cheatListLength); |
| 9927 | menuSubItem[total++] = numCodeBuf; |
| 9928 | |
| 9929 | /* ##### SEPARATOR ##### */ |
| 9930 | menuItem[total] = MENU_SEPARATOR_ITEM; |
| 9931 | menuSubItem[total++] = NULL; |
| 9932 | |
| 9933 | /* ##### CPU/REGION INFO ##### */ |
| 9934 | menuItem[total] = "View CPU/Region Info"; |
| 9935 | menuSubItem[total++] = NULL; |
| 9936 | |
| 9937 | /* ##### ACTIVATION KEY CODE CHEAKCER ##### */ |
| 9938 | menuItem[total] = "Check Activation Key Code"; |
| 9939 | menuSubItem[total++] = NULL; |
| 9940 | |
| 9941 | /* ##### RETURN ##### */ |
| 9942 | menuItem[total] = "Return to Prior Menu"; |
| 9943 | menuSubItem[total++] = NULL; |
| 9944 | |
| 9945 | /* ##### TERMINATE ARRAY ##### */ |
| 9946 | menuItem[total] = NULL; |
| 9947 | menuSubItem[total] = NULL; |
| 9948 | |
| 9949 | /* adjust cursor position */ |
| 9950 | ADJUST_CURSOR(menu->sel, total) |
| 9951 | |
| 9952 | /* draw it */ |
| 9953 | old_style_menu(menuItem, menuSubItem, NULL, menu->sel, 0); |
| 9954 | |
| 9955 | /********** KEY HANDLING **********/ |
| 9956 | if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate)) |
| 9957 | { |
| 9958 | CURSOR_TO_PREVIOUS(menu->sel, total) |
| 9959 | |
| 9960 | if(menu->sel == kMenu_Separator) |
| 9961 | menu->sel--; |
| 9962 | } |
| 9963 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate)) |
| 9964 | { |
| 9965 | CURSOR_TO_NEXT(menu->sel, total) |
| 9966 | |
| 9967 | if(menu->sel == kMenu_Separator) |
| 9968 | menu->sel++; |
| 9969 | } |
| 9970 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate)) |
| 9971 | { |
| 9972 | CURSOR_PAGE_UP(menu->sel) |
| 9973 | } |
| 9974 | else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate)) |
| 9975 | { |
| 9976 | CURSOR_PAGE_DOWN(menu->sel, total) |
| 9977 | } |
| 9978 | else if(input_ui_pressed(machine, IPT_UI_SELECT)) |
| 9979 | { |
| 9980 | switch(menu->sel) |
| 9981 | { |
| 9982 | case kMenu_CPURegionInfo: |
| 9983 | cheat_menu_stack_push(view_cpu_region_info_list_menu, menu->handler, menu->sel); |
| 9984 | break; |
| 9985 | |
| 9986 | case kMenu_KeyCodeChecker: |
| 9987 | cheat_menu_stack_push(check_activation_key_code_menu, menu->handler, menu->sel); |
| 9988 | break; |
| 9989 | |
| 9990 | case kMenu_Return: |
| 9991 | menu->sel = -1; |
| 9992 | break; |
| 9993 | } |
| 9994 | } |
| 9995 | else if(input_ui_pressed(machine, IPT_UI_CANCEL)) |
| 9996 | menu->sel = -1; |
| 9997 | |
| 9998 | return menu->sel + 1; |
| 9999 | } |
| 10000 | #endif |
| 7877 | 10001 | /*------------------ |
| 7878 | 10002 | cheate_periodic |
| 7879 | 10003 | ------------------*/ |
| 7880 | 10004 | |
| 7881 | 10005 | static TIMER_CALLBACK( cheat_periodic ) |
| 7882 | 10006 | { |
| 7883 | | int i; |
| 10007 | int i; |
| 7884 | 10008 | |
| 7885 | 10009 | if(input_ui_pressed(machine, IPT_UI_TOGGLE_CHEAT)) |
| 7886 | 10010 | { |
| 7887 | 10011 | if(ShiftKeyPressed()) |
| 7888 | 10012 | { |
| 7889 | | /* ------ toggle watchpoint display if shift + toggle cheat ----- */ |
| 10013 | /* ##### WATCHPOINT ##### */ |
| 7890 | 10014 | watchesDisabled ^= 1; |
| 7891 | 10015 | |
| 7892 | 10016 | ui_popup_time(1, "Watchpoints %s", watchesDisabled ? "Off" : "On"); |
| 7893 | 10017 | } |
| 7894 | 10018 | else |
| 7895 | 10019 | { |
| 7896 | | /* ------ toggle cheat ----- */ |
| 10020 | /* ##### CHEAT ##### */ |
| 7897 | 10021 | cheatsDisabled ^= 1; |
| 7898 | 10022 | |
| 7899 | 10023 | ui_popup_time(1, "Cheats %s", cheatsDisabled ? "Off" : "On"); |
| r2762 | r2763 | |
| 7911 | 10035 | |
| 7912 | 10036 | for(i = 0; i < cheatListLength; i++) |
| 7913 | 10037 | cheat_periodicEntry(machine, &cheatList[i]); |
| 10038 | |
| 10039 | if(EXTRACT_FIELD(cheatOptions, SearchBox) == kSearchBox_Minimum) |
| 10040 | SET_FIELD(cheatOptions, SearchBox, kSearchBox_Standard); |
| 7914 | 10041 | } |
| 7915 | 10042 | |
| 7916 | 10043 | /*-------------- |
| r2762 | r2763 | |
| 7946 | 10073 | { |
| 7947 | 10074 | switch(size) |
| 7948 | 10075 | { |
| 10076 | case kSearchSize_8Bit: |
| 10077 | case kSearchSize_1Bit: |
| 10078 | default: |
| 10079 | buf[0] = (data >> 0) & 0xFF; |
| 10080 | buf[1] = 0; |
| 10081 | |
| 10082 | return 1; |
| 10083 | |
| 7949 | 10084 | case kSearchSize_16Bit: |
| 7950 | 10085 | buf[0] = (data >> 8) & 0xFF; |
| 7951 | 10086 | buf[1] = (data >> 0) & 0xFF; |
| r2762 | r2763 | |
| 7969 | 10104 | buf[4] = 0; |
| 7970 | 10105 | |
| 7971 | 10106 | return 4; |
| 7972 | | |
| 7973 | | case kSearchSize_8Bit: |
| 7974 | | case kSearchSize_1Bit: |
| 7975 | | default: |
| 7976 | | buf[0] = (data >> 0) & 0xFF; |
| 7977 | | buf[1] = 0; |
| 7978 | | |
| 7979 | | return 1; |
| 7980 | | |
| 7981 | 10107 | } |
| 7982 | | |
| 7983 | 10108 | } |
| 7984 | 10109 | |
| 7985 | 10110 | /*--------------------------------------------- |
| r2762 | r2763 | |
| 7988 | 10113 | |
| 7989 | 10114 | void cheat_display_watches(void) |
| 7990 | 10115 | { |
| 7991 | | int i; |
| 10116 | int i; |
| 7992 | 10117 | |
| 7993 | 10118 | if(watchesDisabled) |
| 7994 | 10119 | return; |
| 7995 | 10120 | |
| 7996 | 10121 | for(i = 0; i < watchListLength; i++) |
| 7997 | 10122 | { |
| 10123 | WatchInfo * info = &watchList[i]; |
| 10124 | |
| 7998 | 10125 | int j; |
| 7999 | | WatchInfo * info = &watchList[i]; |
| 8000 | | char buf[1024]; |
| 8001 | | UINT32 address = info->address; |
| 8002 | | int xOffset = 0, yOffset = 0; |
| 8003 | 10126 | int numChars; |
| 8004 | | int lineElements = 0; |
| 10127 | int xOffset = 0; |
| 10128 | int yOffset = 0; |
| 10129 | int lineElements = 0; |
| 10130 | UINT32 address = info->address; |
| 8005 | 10131 | |
| 8006 | | /* ----- if the length of the watchpoint is not 0, display it ----- */ |
| 10132 | char buf[1024]; |
| 10133 | |
| 8007 | 10134 | if(info->numElements) |
| 8008 | 10135 | { |
| 8009 | | /* ----- label display ----- */ |
| 10136 | /* ##### LABEL ##### */ |
| 8010 | 10137 | switch(info->labelType) |
| 8011 | 10138 | { |
| 8012 | 10139 | case kWatchLabel_Address: |
| r2762 | r2763 | |
| 8024 | 10151 | break; |
| 8025 | 10152 | } |
| 8026 | 10153 | |
| 8027 | | /* ----- value display ----- */ |
| 10154 | /* ##### VALUE ##### */ |
| 8028 | 10155 | for(j = 0; j < info->numElements; j++) |
| 8029 | 10156 | { |
| 8030 | | UINT32 data = 0; |
| 10157 | UINT32 data = 0; |
| 8031 | 10158 | |
| 8032 | | switch(info->locationType) |
| 10159 | if(!TEST_FIELD(info->cpu, RegionFlag)) |
| 8033 | 10160 | { |
| 8034 | | case kLocation_Standard: |
| 8035 | | data = (DoCPURead(info->cpu, address, kSearchByteIncrementTable[info->elementBytes], CPUNeedsSwap(info->cpu)) + info->addValue) & |
| 8036 | | kSearchByteMaskTable[info->elementBytes]; |
| 8037 | | break; |
| 10161 | UINT8 cpu = EXTRACT_FIELD(info->cpu, CPUIndex); |
| 8038 | 10162 | |
| 8039 | | case kLocation_MemoryRegion: |
| 10163 | switch(EXTRACT_FIELD(info->cpu, AddressSpace)) |
| 8040 | 10164 | { |
| 8041 | | int region = REGION_CPU1 + info->cpu; |
| 8042 | | UINT8 * buf = memory_region(region); |
| 10165 | case kAddressSpace_Program: |
| 10166 | data = (DoCPURead(cpu, address, kSearchByteIncrementTable[info->elementBytes], cpu_needs_swap(cpu)) + info->addValue) & kSearchByteMaskTable[info->elementBytes]; |
| 10167 | break; |
| 8043 | 10168 | |
| 8044 | | data = DoMemoryRead(buf, address, kSearchByteIncrementTable[info->elementBytes], RegionNeedsSwap(region) + info->addValue, GetRegionCPUInfo(region)) & |
| 8045 | | kSearchByteMaskTable[info->elementBytes]; |
| 8046 | | } |
| 8047 | | break; |
| 10169 | case kAddressSpace_DataSpace: |
| 10170 | case kAddressSpace_IOSpace: |
| 10171 | case kAddressSpace_OpcodeRAM: |
| 10172 | { |
| 10173 | UINT8 * buf = (UINT8 *) GetMemoryRegionBasePointer(cpu, EXTRACT_FIELD(info->cpu, AddressSpace), address); |
| 8048 | 10174 | |
| 8049 | | case kLocation_IndirectIndexed: |
| 8050 | | return; // under construction... |
| 10175 | if(buf) |
| 10176 | data = DoMemoryRead(buf, address, kSearchByteIncrementTable[info->elementBytes], cpu_needs_swap(cpu) + info->addValue, get_cpu_info(cpu)) & |
| 10177 | kSearchByteMaskTable[info->elementBytes]; |
| 10178 | } |
| 10179 | break; |
| 8051 | 10180 | |
| 8052 | | case kLocation_ProgramSpace: |
| 8053 | | { |
| 8054 | | UINT8 * buf; |
| 8055 | | |
| 8056 | | memory_set_opbase(address); |
| 8057 | | |
| 8058 | | buf = memory_get_op_ptr(info->cpu, address, 0); |
| 8059 | | |
| 8060 | | buf -= address; |
| 8061 | | |
| 8062 | | if(buf) |
| 8063 | | data = DoMemoryRead(buf, address, kSearchByteIncrementTable[info->elementBytes], CPUNeedsSwap(info->cpu) + info->addValue, GetCPUInfo(info->cpu)) & |
| 8064 | | kSearchByteMaskTable[info->elementBytes]; |
| 10181 | default: |
| 10182 | return; |
| 8065 | 10183 | } |
| 8066 | | break; |
| 10184 | } |
| 10185 | else |
| 10186 | { |
| 10187 | UINT8 * buf = memory_region(info->cpu); |
| 8067 | 10188 | |
| 8068 | | default: |
| 8069 | | logerror("invalid location type : %x\n", info->locationType); |
| 8070 | | return; |
| 8071 | | |
| 10189 | if(buf) |
| 10190 | data = DoMemoryRead(buf, address, kSearchByteIncrementTable[info->elementBytes], |
| 10191 | region_needs_swap(info->cpu) + info->addValue, |
| 10192 | get_region_info(info->cpu)) & kSearchByteMaskTable[info->elementBytes]; |
| 8072 | 10193 | } |
| 8073 | 10194 | |
| 8074 | 10195 | data = DoShift(data, info->dataShift); |
| r2762 | r2763 | |
| 8077 | 10198 | if( (lineElements >= info->elementsPerLine) && info->elementsPerLine) |
| 8078 | 10199 | { |
| 8079 | 10200 | lineElements = 0; |
| 8080 | | |
| 8081 | 10201 | xOffset = 0; |
| 8082 | 10202 | yOffset++; |
| 8083 | 10203 | } |
| r2762 | r2763 | |
| 8205 | 10325 | |
| 8206 | 10326 | static void AddCheatBefore(UINT32 idx) |
| 8207 | 10327 | { |
| 8208 | | /* ----- memory reallocation ----- */ |
| 8209 | 10328 | ResizeCheatList(cheatListLength + 1); |
| 8210 | 10329 | |
| 8211 | 10330 | if(idx < (cheatListLength - 1)) |
| r2762 | r2763 | |
| 8214 | 10333 | if(idx >= cheatListLength) |
| 8215 | 10334 | idx = cheatListLength - 1; |
| 8216 | 10335 | |
| 8217 | | /* ----- insert new entry ----- */ |
| 8218 | 10336 | memset(&cheatList[idx], 0, sizeof(CheatEntry)); |
| 8219 | 10337 | |
| 8220 | 10338 | cheatList[idx].flags |= kCheatFlag_Dirty; |
| 8221 | 10339 | |
| 8222 | 10340 | ResizeCheatActionList(&cheatList[idx], 1); |
| 10341 | |
| 10342 | cheatList[idx].actionList[0].extendData = ~0; |
| 10343 | cheatList[idx].actionList[0].lastValue = NULL; |
| 10344 | |
| 10345 | messageType = kCheatMessage_SucceededToAdd; |
| 10346 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 8223 | 10347 | } |
| 8224 | 10348 | |
| 8225 | 10349 | /*---------------- |
| r2762 | r2763 | |
| 8229 | 10353 | static void DeleteCheatAt(UINT32 idx) |
| 8230 | 10354 | { |
| 8231 | 10355 | if(idx >= cheatListLength) |
| 10356 | { |
| 10357 | messageType = kCheatMessage_FailedToDelete; |
| 10358 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 8232 | 10359 | return; |
| 10360 | } |
| 8233 | 10361 | |
| 8234 | 10362 | DisposeCheat(&cheatList[idx]); |
| 8235 | 10363 | |
| r2762 | r2763 | |
| 8239 | 10367 | } |
| 8240 | 10368 | |
| 8241 | 10369 | ResizeCheatListNoDispose(cheatListLength - 1); |
| 10370 | |
| 10371 | messageType = kCheatMessage_SucceededToDelete; |
| 10372 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 8242 | 10373 | } |
| 8243 | 10374 | |
| 8244 | 10375 | /*------------------------------------------------ |
| r2762 | r2763 | |
| 8253 | 10384 | |
| 8254 | 10385 | free(entry->name); |
| 8255 | 10386 | free(entry->comment); |
| 10387 | free(entry->labelIndex); |
| 8256 | 10388 | |
| 8257 | 10389 | for(i = 0; i < entry->actionListLength; i++) |
| 8258 | 10390 | { |
| r2762 | r2763 | |
| 8267 | 10399 | } |
| 8268 | 10400 | } |
| 8269 | 10401 | |
| 8270 | | /*------------------------------------ |
| 8271 | | GetNewCheat - get new cheat entry |
| 8272 | | ------------------------------------*/ |
| 10402 | /*----------------------------------------------------- |
| 10403 | GetNewCheat - insert new cheat entry and return it |
| 10404 | -----------------------------------------------------*/ |
| 8273 | 10405 | |
| 8274 | 10406 | static CheatEntry * GetNewCheat(void) |
| 8275 | 10407 | { |
| 8276 | | /* ----- insert new cheat entry ----- */ |
| 8277 | 10408 | AddCheatBefore(cheatListLength); |
| 8278 | 10409 | |
| 8279 | | /* ----- return inserted entry ----- */ |
| 8280 | 10410 | return &cheatList[cheatListLength - 1]; |
| 8281 | 10411 | } |
| 8282 | 10412 | |
| r2762 | r2763 | |
| 8319 | 10449 | /*--------------------------------- |
| 8320 | 10450 | ResizeCheatActionListNoDispose |
| 8321 | 10451 | ---------------------------------*/ |
| 8322 | | |
| 10452 | #if 0 |
| 8323 | 10453 | static void ResizeCheatActionListNoDispose(CheatEntry * entry, UINT32 newLength) |
| 8324 | 10454 | { |
| 8325 | 10455 | if(newLength != entry->actionListLength) |
| r2762 | r2763 | |
| 8344 | 10474 | } |
| 8345 | 10475 | } |
| 8346 | 10476 | |
| 8347 | | /*------------------ |
| 8348 | | AddActionBefore |
| 8349 | | ------------------*/ |
| 10477 | /*---------------------------------------------------------------- |
| 10478 | AddActionBefore - Insert empty Action |
| 10479 | This function is only called in EditCheat() |
| 10480 | ----------------------------------------------------------------*/ |
| 8350 | 10481 | |
| 8351 | 10482 | static void AddActionBefore(CheatEntry * entry, UINT32 idx) |
| 8352 | 10483 | { |
| r2762 | r2763 | |
| 8359 | 10490 | idx = entry->actionListLength - 1; |
| 8360 | 10491 | |
| 8361 | 10492 | memset(&entry->actionList[idx], 0, sizeof(CheatAction)); |
| 10493 | |
| 10494 | cheatList[idx].actionList[0].extendData = ~0; |
| 10495 | cheatList[idx].actionList[0].lastValue = NULL; |
| 8362 | 10496 | } |
| 8363 | 10497 | |
| 8364 | 10498 | /*----------------- |
| r2762 | r2763 | |
| 8368 | 10502 | static void DeleteActionAt(CheatEntry * entry, UINT32 idx) |
| 8369 | 10503 | { |
| 8370 | 10504 | if(idx >= entry->actionListLength) |
| 10505 | { |
| 10506 | messageType = kCheatMessage_FailedToDelete; |
| 10507 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 8371 | 10508 | return; |
| 10509 | } |
| 8372 | 10510 | |
| 8373 | 10511 | DisposeAction(&entry->actionList[idx]); |
| 8374 | 10512 | |
| r2762 | r2763 | |
| 8376 | 10514 | memmove(&entry->actionList[idx], &entry->actionList[idx + 1], sizeof(CheatAction) * (entry->actionListLength - 1 - idx)); |
| 8377 | 10515 | |
| 8378 | 10516 | ResizeCheatActionListNoDispose(entry, entry->actionListLength - 1); |
| 10517 | |
| 10518 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 10519 | messageType = kCheatMessage_SucceededToDelete; |
| 8379 | 10520 | } |
| 8380 | | |
| 10521 | #endif |
| 8381 | 10522 | /*---------------- |
| 8382 | 10523 | DisposeAction |
| 8383 | 10524 | ----------------*/ |
| r2762 | r2763 | |
| 8388 | 10529 | { |
| 8389 | 10530 | free(action->optionalName); |
| 8390 | 10531 | |
| 10532 | if(action->lastValue) |
| 10533 | free(action->lastValue); |
| 10534 | |
| 8391 | 10535 | memset(action, 0, sizeof(CheatAction)); |
| 8392 | 10536 | } |
| 8393 | 10537 | } |
| 8394 | 10538 | |
| 8395 | | /*---------------------------------------------------- |
| 8396 | | InitWatch - initialize y-position for watchpoints |
| 8397 | | ----------------------------------------------------*/ |
| 10539 | /*------------------------------------------------ |
| 10540 | InitWatch - initialize a value for watchpoint |
| 10541 | ------------------------------------------------*/ |
| 8398 | 10542 | |
| 8399 | 10543 | static void InitWatch(WatchInfo * info, UINT32 idx) |
| 8400 | 10544 | { |
| 10545 | /* NOTE : 1st watchpoint should be always Y = 0 */ |
| 8401 | 10546 | if(idx > 0) |
| 8402 | | /* ----- set 2nd or later y-position ----- */ |
| 8403 | 10547 | info->y = watchList[idx - 1].y + ui_get_line_height(); |
| 8404 | 10548 | else |
| 8405 | | /* ----- set 1st y-position (always Y=0) ----- */ |
| 8406 | 10549 | info->y = 0; |
| 8407 | 10550 | } |
| 8408 | 10551 | |
| r2762 | r2763 | |
| 8536 | 10679 | WatchInfo * info; |
| 8537 | 10680 | WatchInfo * theWatch = NULL; |
| 8538 | 10681 | |
| 8539 | | /* ----- search unused watchpoint ----- */ |
| 10682 | /* search unused watchpoint */ |
| 8540 | 10683 | for(i = 0; i < watchListLength; i++) |
| 8541 | 10684 | { |
| 8542 | 10685 | info = &watchList[i]; |
| r2762 | r2763 | |
| 8548 | 10691 | } |
| 8549 | 10692 | } |
| 8550 | 10693 | |
| 8551 | | /* ----- if unused watchpoint is not found, insert new watchpoint as unused ----- */ |
| 10694 | /* if unused watchpoint is not found, insert new watchpoint */ |
| 8552 | 10695 | if(!theWatch) |
| 8553 | 10696 | { |
| 8554 | 10697 | AddWatchBefore(watchListLength); |
| r2762 | r2763 | |
| 8556 | 10699 | theWatch = &watchList[watchListLength - 1]; |
| 8557 | 10700 | } |
| 8558 | 10701 | |
| 8559 | | /* ----- return unused watchpoint ----- */ |
| 8560 | 10702 | return theWatch; |
| 8561 | 10703 | } |
| 8562 | 10704 | |
| r2762 | r2763 | |
| 8568 | 10710 | { |
| 8569 | 10711 | if(watch) |
| 8570 | 10712 | { |
| 8571 | | CheatEntry * entry = GetNewCheat(); |
| 8572 | | CheatAction * action = &entry->actionList[0]; |
| 10713 | int tempStringLength; |
| 8573 | 10714 | char tempString[1024]; |
| 8574 | | int tempStringLength; |
| 8575 | | UINT32 data = DoCPURead(watch->cpu, watch->address, kSearchByteIncrementTable[watch->elementBytes], 0); |
| 10715 | CheatEntry * entry = GetNewCheat(); |
| 10716 | CheatAction * action = &entry->actionList[0]; |
| 8576 | 10717 | |
| 8577 | | tempStringLength = sprintf(tempString, "%.8X (%d) = %.*X", watch->address, watch->cpu, kSearchByteDigitsTable[watch->elementBytes], data); |
| 10718 | /* set parameters */ |
| 10719 | action->region = watch->cpu; |
| 10720 | SET_FIELD(action->type, CPURegion, action->region); |
| 10721 | SET_FIELD(action->type, AddressSize, watch->elementBytes); |
| 10722 | action->address = action->originalAddress = watch->address; |
| 10723 | action->extendData = ~0; |
| 10724 | action->lastValue = NULL; |
| 8578 | 10725 | |
| 8579 | | entry->name = realloc(entry->name, tempStringLength + 1); |
| 8580 | | memcpy(entry->name, tempString, tempStringLength + 1); |
| 10726 | action->data = ReadData(action); |
| 8581 | 10727 | |
| 8582 | | SET_FIELD(action->type, LocationParameter, watch->cpu); |
| 8583 | | SET_FIELD(action->type, BytesUsed, kSearchByteIncrementTable[watch->elementBytes] - 1); |
| 8584 | | action->address = watch->address; |
| 8585 | | action->data = data; |
| 8586 | | action->extendData = 0xFFFFFFFF; |
| 8587 | | action->originalDataField = data; |
| 10728 | /* set name */ |
| 10729 | tempStringLength = sprintf(tempString, "%.8X (%d) = %.*X", watch->address, watch->cpu, kSearchByteDigitsTable[watch->elementBytes], action->data); |
| 10730 | entry->name = create_string_copy(tempString); |
| 8588 | 10731 | |
| 8589 | 10732 | UpdateCheatInfo(entry, 0); |
| 10733 | |
| 10734 | messageType = kCheatMessage_SucceededToAdd; |
| 10735 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 8590 | 10736 | } |
| 10737 | else |
| 10738 | { |
| 10739 | messageType = kCheatMessage_FailedToAdd; |
| 10740 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 10741 | } |
| 8591 | 10742 | } |
| 8592 | 10743 | |
| 8593 | | /*------------------------------------------------------------------------------------- |
| 10744 | /*-------------------------------------------------------------------------------------- |
| 8594 | 10745 | SetupCheatFromWatchAsWatch - add new watch code from watchpoint list to cheat list |
| 8595 | | -------------------------------------------------------------------------------------*/ |
| 10746 | If watchpoint is not displayed (length = 0), don't add |
| 10747 | --------------------------------------------------------------------------------------*/ |
| 8596 | 10748 | |
| 8597 | 10749 | static void SetupCheatFromWatchAsWatch(CheatEntry * entry, WatchInfo * watch) |
| 8598 | 10750 | { |
| 8599 | 10751 | if(watch && entry && watch->numElements) |
| 8600 | 10752 | { |
| 8601 | | CheatAction * action; |
| 8602 | | char tempString[1024]; |
| 8603 | | size_t tempStringLength; |
| 10753 | char tempString[256]; |
| 10754 | CheatAction * action; |
| 8604 | 10755 | |
| 8605 | 10756 | DisposeCheat(entry); |
| 8606 | 10757 | ResizeCheatActionList(entry, 1); |
| 8607 | 10758 | |
| 8608 | 10759 | action = &entry->actionList[0]; |
| 8609 | 10760 | |
| 8610 | | tempStringLength = sprintf(tempString, "Watch %.8X (%d)", watch->address, watch->cpu); |
| 10761 | sprintf(tempString, "Watch %.8X (%d)", watch->address, watch->cpu); |
| 8611 | 10762 | |
| 8612 | | entry->name = realloc(entry->name, tempStringLength + 1); |
| 8613 | | memcpy(entry->name, tempString, tempStringLength + 1); |
| 10763 | /* set name */ |
| 10764 | entry->name = create_string_copy(tempString); |
| 10765 | entry->comment = create_string_copy(watch->label); |
| 8614 | 10766 | |
| 8615 | | action->type = 0; |
| 8616 | | SET_FIELD(action->type, LocationParameter, watch->cpu); |
| 8617 | | SET_FIELD(action->type, Type, kType_Watch); |
| 8618 | | SET_FIELD(action->type, BytesUsed, kSearchByteIncrementTable[watch->elementBytes] - 1); |
| 8619 | | SET_FIELD(action->type, TypeParameter, watch->displayType | ((watch->labelType == kWatchLabel_String) ? 0x04 : 0)); |
| 10767 | /* set parameters */ |
| 10768 | SET_FIELD(action->type, CodeType, kCodeType_Watch); |
| 10769 | SET_FIELD(action->type, AddressSize, kSearchByteIncrementTable[watch->elementBytes] - 1); |
| 8620 | 10770 | |
| 8621 | | action->address = watch->address; |
| 8622 | | action->data = ((watch->numElements - 1) & 0xFF) | |
| 8623 | | ((watch->skip & 0xFF) << 8) | |
| 8624 | | ((watch->elementsPerLine & 0xFF) << 16) | |
| 8625 | | ((watch->addValue & 0xFF) << 24); |
| 8626 | | action->originalDataField = action->data; |
| 8627 | | action->extendData = 0xFFFFFFFF; |
| 10771 | action->region = watch->cpu; |
| 10772 | action->address = watch->address; |
| 10773 | action->originalAddress = action->address; |
| 10774 | action->originalDataField = action->data; |
| 10775 | action->extendData = 0xFFFFFFFF; |
| 8628 | 10776 | |
| 8629 | | tempStringLength = strlen(watch->label); |
| 8630 | | entry->comment = realloc(entry->comment, tempStringLength + 1); |
| 8631 | | memcpy(entry->comment, watch->label, tempStringLength + 1); |
| 10777 | SET_FIELD(action->data, WatchNumElements, watch->numElements - 1); |
| 10778 | SET_FIELD(action->data, WatchSkip, watch->skip); |
| 10779 | SET_FIELD(action->data, WatchElementsPerLine, watch->elementsPerLine); |
| 10780 | SET_FIELD(action->data, WatchAddValue, watch->addValue); |
| 8632 | 10781 | |
| 10782 | /* set comment */ |
| 10783 | |
| 8633 | 10784 | UpdateCheatInfo(entry, 0); |
| 10785 | |
| 10786 | messageType = kCheatMessage_SucceededToAdd; |
| 10787 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 8634 | 10788 | } |
| 10789 | else |
| 10790 | { |
| 10791 | messageType = kCheatMessage_FailedToAdd; |
| 10792 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 10793 | } |
| 8635 | 10794 | } |
| 8636 | 10795 | |
| 8637 | | /*------------------- |
| 8638 | | ResizeSearchList |
| 8639 | | -------------------*/ |
| 10796 | /*----------------------------------------------------------- |
| 10797 | ResetWatch - clear data in WatchInfo except x/y position |
| 10798 | -----------------------------------------------------------*/ |
| 8640 | 10799 | |
| 8641 | | static void ResizeSearchList(UINT32 newLength) |
| 10800 | static void ResetWatch(WatchInfo * watch) |
| 8642 | 10801 | { |
| 8643 | | if(newLength != searchListLength) |
| 10802 | if(watch) |
| 8644 | 10803 | { |
| 8645 | | if(newLength < searchListLength) |
| 10804 | watch->address = 0; |
| 10805 | watch->cpu = 0; |
| 10806 | watch->numElements = 0; |
| 10807 | watch->elementBytes = kWatchSizeConversionTable[0]; |
| 10808 | watch->labelType = kWatchLabel_None; |
| 10809 | watch->displayType = kWatchDisplayType_Hex; |
| 10810 | watch->skip = 0; |
| 10811 | watch->elementsPerLine = 0; |
| 10812 | watch->addValue = 0; |
| 10813 | watch->addressShift = 0; |
| 10814 | watch->dataShift = 0; |
| 10815 | watch->xor = 0; |
| 10816 | watch->linkedCheat = NULL; |
| 10817 | watch->label[0] = 0; |
| 10818 | } |
| 10819 | } |
| 10820 | |
| 10821 | /*------------------------------------------------------------------ |
| 10822 | resize_search_list - reallocate search list if different length |
| 10823 | ------------------------------------------------------------------*/ |
| 10824 | |
| 10825 | static void resize_search_list(UINT32 new_length) |
| 10826 | { |
| 10827 | if(new_length != search_list_length) |
| 10828 | { |
| 10829 | /* if delete, dispose deleted or later search lists */ |
| 10830 | if(new_length < search_list_length) |
| 8646 | 10831 | { |
| 8647 | | int i; |
| 10832 | int i; |
| 8648 | 10833 | |
| 8649 | | for(i = newLength; i < searchListLength; i++) |
| 8650 | | DisposeSearch(i); |
| 10834 | for(i = new_length; i < search_list_length; i++) |
| 10835 | dispose_search(&search_list[i]); |
| 8651 | 10836 | } |
| 8652 | 10837 | |
| 8653 | | searchList = realloc(searchList, newLength * sizeof(SearchInfo)); |
| 8654 | | if(!searchList && (newLength != 0)) |
| 10838 | /* reallocate search list */ |
| 10839 | search_list = realloc(search_list, new_length * sizeof(search_info)); |
| 10840 | |
| 10841 | if(search_list == NULL && new_length != 0) |
| 8655 | 10842 | { |
| 10843 | /* memory allocation error */ |
| 8656 | 10844 | logerror("ResizeSearchList: out of memory resizing search list\n"); |
| 8657 | 10845 | ui_popup_time(2, "out of memory while adding search"); |
| 8658 | 10846 | |
| 8659 | | searchListLength = 0; |
| 10847 | search_list_length = 0; |
| 8660 | 10848 | |
| 8661 | 10849 | return; |
| 8662 | 10850 | } |
| 8663 | 10851 | |
| 8664 | | if(newLength > searchListLength) |
| 10852 | /* if insert, initialize new search list */ |
| 10853 | if(new_length > search_list_length) |
| 8665 | 10854 | { |
| 8666 | | int i; |
| 10855 | int i; |
| 8667 | 10856 | |
| 8668 | | memset(&searchList[searchListLength], 0, (newLength - searchListLength) * sizeof(SearchInfo)); |
| 10857 | memset(&search_list[search_list_length], 0, (new_length - search_list_length) * sizeof(search_info)); |
| 8669 | 10858 | |
| 8670 | | for(i = searchListLength; i < newLength; i++) |
| 8671 | | { |
| 8672 | | InitSearch(&searchList[i]); |
| 8673 | | } |
| 10859 | for(i = search_list_length; i < new_length; i++) |
| 10860 | init_search(&search_list[i]); |
| 8674 | 10861 | } |
| 8675 | 10862 | |
| 8676 | | searchListLength = newLength; |
| 10863 | search_list_length = new_length; |
| 8677 | 10864 | } |
| 8678 | 10865 | } |
| 8679 | 10866 | |
| 8680 | | /*---------------------------- |
| 8681 | | ResizeSearchListNoDispose |
| 8682 | | ----------------------------*/ |
| 8683 | | |
| 10867 | /*-------------------------------- |
| 10868 | resize_search_list_no_dispose |
| 10869 | --------------------------------*/ |
| 10870 | #if 0 |
| 8684 | 10871 | static void ResizeSearchListNoDispose(UINT32 newLength) |
| 8685 | 10872 | { |
| 8686 | | if(newLength != searchListLength) |
| 10873 | if(newLength != search_list_length) |
| 8687 | 10874 | { |
| 8688 | | searchList = realloc(searchList, newLength * sizeof(SearchInfo)); |
| 10875 | searchList = realloc(searchList, newLength * sizeof(search_info)); |
| 10876 | |
| 8689 | 10877 | if(!searchList && (newLength != 0)) |
| 8690 | 10878 | { |
| 8691 | 10879 | logerror("ResizeSearchList: out of memory resizing search list\n"); |
| 8692 | 10880 | ui_popup_time(2, "out of memory while adding search"); |
| 8693 | 10881 | |
| 8694 | | searchListLength = 0; |
| 10882 | search_list_length = 0; |
| 8695 | 10883 | |
| 8696 | 10884 | return; |
| 8697 | 10885 | } |
| 8698 | 10886 | |
| 8699 | | if(newLength > searchListLength) |
| 8700 | | { |
| 8701 | | memset(&searchList[searchListLength], 0, (newLength - searchListLength) * sizeof(SearchInfo)); |
| 8702 | | } |
| 10887 | if(newLength > search_list_length) |
| 10888 | memset(&searchList[search_list_length], 0, (newLength - search_list_length) * sizeof(search_info)); |
| 8703 | 10889 | |
| 8704 | | searchListLength = newLength; |
| 10890 | search_list_length = newLength; |
| 8705 | 10891 | } |
| 8706 | 10892 | } |
| 8707 | 10893 | |
| 8708 | | /*------------------ |
| 8709 | | AddSearchBefore |
| 8710 | | ------------------*/ |
| 10894 | /*-------------------- |
| 10895 | add_search_before |
| 10896 | --------------------*/ |
| 8711 | 10897 | |
| 8712 | 10898 | static void AddSearchBefore(UINT32 idx) |
| 8713 | 10899 | { |
| 8714 | | ResizeSearchListNoDispose(searchListLength + 1); |
| 10900 | ResizeSearchListNoDispose(search_list_length + 1); |
| 8715 | 10901 | |
| 8716 | | if(idx < (searchListLength - 1)) |
| 8717 | | memmove(&searchList[idx + 1], &searchList[idx], sizeof(SearchInfo) * (searchListLength - 1 - idx)); |
| 10902 | if(idx < (search_list_length - 1)) |
| 10903 | memmove(&search_list[idx + 1], &search_list[idx], sizeof(search_info) * (search_list_length - 1 - idx)); |
| 8718 | 10904 | |
| 8719 | | if(idx >= searchListLength) |
| 8720 | | idx = searchListLength - 1; |
| 10905 | if(idx >= search_list_length) |
| 10906 | idx = search_list_length - 1; |
| 8721 | 10907 | |
| 8722 | | memset(&searchList[idx], 0, sizeof(SearchInfo)); |
| 8723 | | InitSearch(&searchList[idx]); |
| 10908 | memset(&search_list[idx], 0, sizeof(search_info)); |
| 10909 | |
| 10910 | init_search(&search_list[idx]); |
| 8724 | 10911 | } |
| 8725 | 10912 | |
| 8726 | | /*----------------- |
| 8727 | | DeleteSearchAt |
| 8728 | | -----------------*/ |
| 10913 | /*------------------- |
| 10914 | delete_search_at |
| 10915 | -------------------*/ |
| 8729 | 10916 | |
| 8730 | 10917 | static void DeleteSearchAt(UINT32 idx) |
| 8731 | 10918 | { |
| 8732 | | if(idx >= searchListLength) |
| 10919 | if(idx >= search_list_length) |
| 8733 | 10920 | return; |
| 8734 | 10921 | |
| 8735 | 10922 | DisposeSearch(idx); |
| 8736 | 10923 | |
| 8737 | | if(idx < (searchListLength - 1)) |
| 8738 | | { |
| 8739 | | memmove(&searchList[idx], &searchList[idx + 1], sizeof(SearchInfo) * (searchListLength - 1 - idx)); |
| 8740 | | } |
| 10924 | if(idx < (search_list_length - 1)) |
| 10925 | memmove(&search_list[idx], &search_list[idx + 1], sizeof(search_info) * (search_list_length - 1 - idx)); |
| 8741 | 10926 | |
| 8742 | | ResizeSearchListNoDispose(searchListLength - 1); |
| 10927 | ResizeSearchListNoDispose(search_list_length - 1); |
| 8743 | 10928 | } |
| 10929 | #endif |
| 10930 | /*--------------------------------------- |
| 10931 | init_search - initialize search info |
| 10932 | ---------------------------------------*/ |
| 8744 | 10933 | |
| 8745 | | /*-------------------------------------- |
| 8746 | | InitSearch - initialize search info |
| 8747 | | --------------------------------------*/ |
| 8748 | | |
| 8749 | | static void InitSearch(SearchInfo * info) |
| 10934 | static void init_search(search_info *info) |
| 8750 | 10935 | { |
| 8751 | 10936 | if(info) |
| 8752 | | { |
| 8753 | | info->searchSpeed = kSearchSpeed_Medium; |
| 8754 | | } |
| 10937 | info->search_speed = ksearch_speed_Medium; |
| 8755 | 10938 | } |
| 8756 | 10939 | |
| 8757 | | /*----------------------- |
| 8758 | | DisposeSearchRegions |
| 8759 | | -----------------------*/ |
| 10940 | /*--------------------------------------------------------------------------- |
| 10941 | dispose_search_reigons - free all search regions in selected search info |
| 10942 | ---------------------------------------------------------------------------*/ |
| 8760 | 10943 | |
| 8761 | | static void DisposeSearchRegions(SearchInfo * info) |
| 10944 | static void dispose_search_reigons(search_info *info) |
| 8762 | 10945 | { |
| 8763 | | if(info->regionList) |
| 10946 | if(info->region_list) |
| 8764 | 10947 | { |
| 8765 | | int i; |
| 10948 | int i; |
| 8766 | 10949 | |
| 8767 | | for(i = 0; i < info->regionListLength; i++) |
| 10950 | for(i = 0; i < info->region_list_length; i++) |
| 8768 | 10951 | { |
| 8769 | | SearchRegion * region = &info->regionList[i]; |
| 10952 | search_region *region = &info->region_list[i]; |
| 8770 | 10953 | |
| 8771 | 10954 | free(region->first); |
| 8772 | 10955 | free(region->last); |
| 8773 | 10956 | free(region->status); |
| 8774 | | free(region->backupLast); |
| 8775 | | free(region->backupStatus); |
| 10957 | free(region->backup_last); |
| 10958 | free(region->backup_status); |
| 8776 | 10959 | } |
| 8777 | 10960 | |
| 8778 | | free(info->regionList); |
| 10961 | free(info->region_list); |
| 8779 | 10962 | |
| 8780 | | info->regionList = NULL; |
| 10963 | info->region_list = NULL; |
| 8781 | 10964 | } |
| 8782 | 10965 | |
| 8783 | | info->regionListLength = 0; |
| 10966 | info->region_list_length = 0; |
| 8784 | 10967 | } |
| 8785 | 10968 | |
| 8786 | | /*------------------ |
| 8787 | | DisposeSearch |
| 8788 | | ----------------*/ |
| 10969 | /*------------------------------------------------------------------------- |
| 10970 | dispose_search - free selected search info and all search region in it |
| 10971 | -------------------------------------------------------------------------*/ |
| 8789 | 10972 | |
| 8790 | | static void DisposeSearch(UINT32 idx) |
| 10973 | static void dispose_search(search_info *info) |
| 8791 | 10974 | { |
| 8792 | | SearchInfo * info; |
| 10975 | dispose_search_reigons(info); |
| 8793 | 10976 | |
| 8794 | | if(idx >= searchListLength) |
| 8795 | | return; |
| 10977 | free(info->name); |
| 8796 | 10978 | |
| 8797 | | info = &searchList[idx]; |
| 8798 | | |
| 8799 | | DisposeSearchRegions(info); |
| 8800 | | |
| 8801 | | free(info->name); |
| 8802 | 10979 | info->name = NULL; |
| 8803 | 10980 | } |
| 8804 | 10981 | |
| 8805 | | /*---------------------------------------- |
| 8806 | | GetCurrentSearch - return search info |
| 8807 | | ----------------------------------------*/ |
| 10982 | /*-------------------------------------------------- |
| 10983 | get_current_search - return working search info |
| 10984 | --------------------------------------------------*/ |
| 8808 | 10985 | |
| 8809 | | static SearchInfo * GetCurrentSearch(void) |
| 10986 | static search_info *get_current_search(void) |
| 8810 | 10987 | { |
| 8811 | | if(currentSearchIdx >= searchListLength) |
| 8812 | | currentSearchIdx = searchListLength - 1; |
| 8813 | | if(currentSearchIdx < 0) |
| 8814 | | currentSearchIdx = 0; |
| 10988 | if(current_search_idx >= search_list_length) |
| 10989 | current_search_idx = search_list_length - 1; |
| 8815 | 10990 | |
| 8816 | | return &searchList[currentSearchIdx]; |
| 10991 | if(current_search_idx < 0) |
| 10992 | current_search_idx = 0; |
| 10993 | |
| 10994 | return &search_list[current_search_idx]; |
| 8817 | 10995 | } |
| 8818 | 10996 | |
| 8819 | | /*------------------------------------------------------- |
| 8820 | | FillBufferFromRegion - set a data into search region |
| 8821 | | -------------------------------------------------------*/ |
| 10997 | /*---------------------------------------------------------------------------------------------- |
| 10998 | fill_buffer_from_region - fill selected search region with a value read from search address |
| 10999 | ----------------------------------------------------------------------------------------------*/ |
| 8822 | 11000 | |
| 8823 | | static void FillBufferFromRegion(SearchRegion * region, UINT8 * buf) |
| 11001 | static void fill_buffer_from_region(search_region *region, UINT8 * buf) |
| 8824 | 11002 | { |
| 8825 | | UINT32 offset; |
| 11003 | UINT32 offset; |
| 8826 | 11004 | |
| 8827 | | /* ### optimize if needed ### */ |
| 11005 | /* ##### optimize if needed ##### */ |
| 8828 | 11006 | for(offset = 0; offset < region->length; offset++) |
| 8829 | | buf[offset] = ReadRegionData(region, offset, 1, 0); |
| 11007 | buf[offset] = read_region_data(region, offset, 1, 0); |
| 8830 | 11008 | } |
| 8831 | 11009 | |
| 8832 | | /*------------------------------------------------------- |
| 8833 | | ReadRegionData - read a data from region when search |
| 8834 | | -------------------------------------------------------*/ |
| 11010 | /*--------------------------------------------------------------------------- |
| 11011 | read_region_data - read a data from memory or search region in searching |
| 11012 | ---------------------------------------------------------------------------*/ |
| 8835 | 11013 | |
| 8836 | | static UINT32 ReadRegionData(SearchRegion * region, UINT32 offset, UINT8 size, UINT8 swap) |
| 11014 | static UINT32 read_region_data(search_region *region, UINT32 offset, UINT8 size, UINT8 swap) |
| 8837 | 11015 | { |
| 8838 | | UINT32 address = region->address + offset; |
| 11016 | UINT32 address = region->address + offset; |
| 8839 | 11017 | |
| 8840 | | switch(region->targetType) |
| 11018 | switch(region->target_type) |
| 8841 | 11019 | { |
| 8842 | 11020 | case kRegionType_CPU: |
| 8843 | | return DoCPURead(region->targetIdx, address, size, CPUNeedsSwap(region->targetIdx) ^ swap); |
| 11021 | return DoCPURead(region->target_idx, address, size, cpu_needs_swap(region->target_idx) ^ swap); |
| 8844 | 11022 | |
| 8845 | 11023 | case kRegionType_Memory: |
| 8846 | | if(region->cachedPointer) |
| 8847 | | return DoMemoryRead(region->cachedPointer, address, size, swap, &rawCPUInfo); |
| 8848 | | else |
| 8849 | | return 0; |
| 11024 | { |
| 11025 | UINT8 * buf = (UINT8 *)region->cached_pointer; |
| 11026 | |
| 11027 | if(buf) |
| 11028 | /* return DoMemoryRead(region->cached_pointer, address, size, swap, &raw_cpu_info); */ |
| 11029 | return DoMemoryRead(buf, address, size, cpu_needs_swap(region->target_idx) ^ swap, get_cpu_info(region->target_idx)); |
| 11030 | else |
| 11031 | return 0; |
| 11032 | } |
| 8850 | 11033 | } |
| 8851 | 11034 | |
| 8852 | 11035 | return 0; |
| 8853 | 11036 | } |
| 8854 | | /*----------------------------------------------- |
| 8855 | | BackupSearch - back up current search region |
| 8856 | | -----------------------------------------------*/ |
| 11037 | /*------------------------------------------------ |
| 11038 | backup_search - back up current search region |
| 11039 | ------------------------------------------------*/ |
| 8857 | 11040 | |
| 8858 | | static void BackupSearch(SearchInfo * info) |
| 11041 | static void backup_search(search_info *info) |
| 8859 | 11042 | { |
| 8860 | | int i; |
| 11043 | int i; |
| 8861 | 11044 | |
| 8862 | | for(i = 0; i < info->regionListLength; i++) |
| 8863 | | BackupRegion(&info->regionList[i]); |
| 11045 | for(i = 0; i < info->region_list_length; i++) |
| 11046 | backup_region(&info->region_list[i]); |
| 8864 | 11047 | |
| 8865 | | info->oldNumResults = info->numResults; |
| 8866 | | info->backupValid = 1; |
| 11048 | info->old_num_results = info->num_results; |
| 11049 | info->backup_valid = 1; |
| 8867 | 11050 | } |
| 8868 | 11051 | |
| 8869 | | /*------------------------------------------------------- |
| 8870 | | RestoreSearchBackup - restore previous search region |
| 8871 | | -------------------------------------------------------*/ |
| 11052 | /*--------------------------------------------------------- |
| 11053 | restore_search_backup - restore previous search region |
| 11054 | ---------------------------------------------------------*/ |
| 8872 | 11055 | |
| 8873 | | static void RestoreSearchBackup(SearchInfo * info) |
| 11056 | static void restore_search_backup(search_info *info) |
| 8874 | 11057 | { |
| 8875 | 11058 | int i; |
| 8876 | 11059 | |
| 8877 | | if(info && info->backupValid) |
| 11060 | if(info && info->backup_valid) |
| 8878 | 11061 | { |
| 8879 | | for(i = 0; i < info->regionListLength; i++) |
| 8880 | | RestoreRegionBackup(&info->regionList[i]); |
| 11062 | for(i = 0; i < info->region_list_length; i++) |
| 11063 | restore_region_backup(&info->region_list[i]); |
| 8881 | 11064 | |
| 8882 | | info->numResults = info->oldNumResults; |
| 8883 | | info->backupValid = 0; |
| 11065 | info->num_results = info->old_num_results; |
| 11066 | info->backup_valid = 0; |
| 8884 | 11067 | |
| 8885 | | ui_popup_time(1, "values restored"); |
| 11068 | #if 1 |
| 11069 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 11070 | messageType = kCheatMessage_RestoreValue; |
| 11071 | #else |
| 11072 | ui_popup_time(1, "values restored"); /* not displayed when ui is opend */ |
| 11073 | #endif |
| 8886 | 11074 | } |
| 8887 | 11075 | else |
| 8888 | | ui_popup_time(1, "there are no old values"); |
| 11076 | { |
| 11077 | #if 1 |
| 11078 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 11079 | messageType = kCheatMessage_NoOldValue; |
| 11080 | #else |
| 11081 | ui_popup_time(1, "there are no old values"); /* not displayed when ui is opend */ |
| 11082 | #endif |
| 11083 | } |
| 8889 | 11084 | } |
| 8890 | 11085 | |
| 8891 | | /*------------------------------------------------ |
| 8892 | | BackupRegion - back up current search results |
| 8893 | | ------------------------------------------------*/ |
| 11086 | /*------------------------------------------------- |
| 11087 | backup_region - back up current search results |
| 11088 | -------------------------------------------------*/ |
| 8894 | 11089 | |
| 8895 | | static void BackupRegion(SearchRegion * region) |
| 11090 | static void backup_region(search_region *region) |
| 8896 | 11091 | { |
| 8897 | 11092 | if(region->flags & kRegionFlag_Enabled) |
| 8898 | 11093 | { |
| 8899 | | memcpy(region->backupLast, region->last, region->length); |
| 8900 | | memcpy(region->backupStatus, region->status, region->length); |
| 8901 | | region->oldNumResults = region->numResults; |
| 11094 | memcpy(region->backup_last, region->last, region->length); |
| 11095 | memcpy(region->backup_status, region->status, region->length); |
| 11096 | |
| 11097 | region->old_num_results = region->num_results; |
| 8902 | 11098 | } |
| 8903 | 11099 | } |
| 8904 | 11100 | |
| 8905 | | /*-------------------------------------------------------- |
| 8906 | | RestoreSearchBackup - restore previous search results |
| 8907 | | --------------------------------------------------------*/ |
| 11101 | /*---------------------------------------------------------- |
| 11102 | restore_region_backup - restore previous search results |
| 11103 | ----------------------------------------------------------*/ |
| 8908 | 11104 | |
| 8909 | | static void RestoreRegionBackup(SearchRegion * region) |
| 11105 | static void restore_region_backup(search_region *region) |
| 8910 | 11106 | { |
| 8911 | 11107 | if(region->flags & kRegionFlag_Enabled) |
| 8912 | 11108 | { |
| 8913 | | memcpy(region->last, region->backupLast, region->length); |
| 8914 | | memcpy(region->status, region->backupStatus, region->length); |
| 8915 | | region->numResults = region->oldNumResults; |
| 11109 | memcpy(region->last, region->backup_last, region->length); |
| 11110 | memcpy(region->status, region->backup_status, region->length); |
| 11111 | |
| 11112 | region->num_results = region->old_num_results; |
| 8916 | 11113 | } |
| 8917 | 11114 | } |
| 8918 | 11115 | |
| 8919 | | /*----------------------------------------------------------- |
| 8920 | | DefaultEnableRegion - get default regions you can search |
| 8921 | | -----------------------------------------------------------*/ |
| 11116 | /*-------------------------------------------------------- |
| 11117 | default_enable_region - get default regions to search |
| 11118 | --------------------------------------------------------*/ |
| 8922 | 11119 | |
| 8923 | | static UINT8 DefaultEnableRegion(running_machine *machine, SearchRegion * region, SearchInfo * info) |
| 11120 | static UINT8 default_enable_region(running_machine *machine, search_region *region, search_info *info) |
| 8924 | 11121 | { |
| 8925 | | write8_machine_func handler = region->writeHandler->write.mhandler8; |
| 8926 | | FPTR handlerAddress = (FPTR)handler; |
| 11122 | write8_machine_func handler = region->write_handler->write.mhandler8; |
| 11123 | FPTR handlerAddress = (FPTR)handler; |
| 8927 | 11124 | |
| 8928 | | switch(info->searchSpeed) |
| 11125 | switch(info->search_speed) |
| 8929 | 11126 | { |
| 8930 | | case kSearchSpeed_Fast: |
| 8931 | | |
| 11127 | case ksearch_speed_Fast: |
| 8932 | 11128 | #if HAS_SH2 |
| 8933 | | if(machine->config->cpu[0].type == CPU_SH2) |
| 8934 | | { |
| 8935 | | if( (info->targetType == kRegionType_CPU) && (info->targetIdx == 0) && (region->address == 0x06000000)) |
| 11129 | if( machine->config->cpu[0].type == CPU_SH2 && |
| 11130 | (info->target_type == kRegionType_CPU && info->target_idx == 0 && region->address == 0x06000000)) |
| 8936 | 11131 | return 1; |
| 8937 | | |
| 11132 | else |
| 8938 | 11133 | return 0; |
| 8939 | | } |
| 8940 | 11134 | #endif |
| 8941 | | |
| 8942 | | if( (handler == SMH_RAM) && (!region->writeHandler->baseptr)) |
| 11135 | if(handler == SMH_RAM && region->write_handler->baseptr != NULL) |
| 8943 | 11136 | return 1; |
| 8944 | 11137 | |
| 8945 | | #ifndef MESS |
| 8946 | | |
| 8947 | | { |
| 8948 | | /* ----- for neogeo, search bank one ----- */ |
| 8949 | | if( (!strcmp(machine->gamedrv->parent, "neogeo")) && (info->targetType == kRegionType_CPU) && |
| 8950 | | (info->targetIdx == 0) && (handler == SMH_BANK1)) |
| 8951 | | return 1; |
| 8952 | | } |
| 8953 | | |
| 8954 | | #endif |
| 8955 | | |
| 8956 | | #if HAS_TMS34010 |
| 8957 | | |
| 8958 | | /* ----- for exterminator, search bank one ----- */ |
| 8959 | | if( (machine->config->cpu[1].type == CPU_TMS34010) && (info->targetType == kRegionType_CPU) && |
| 8960 | | (info->targetIdx == 1) && (handler == SMH_BANK1)) |
| 11138 | case ksearch_speed_Medium: |
| 11139 | if(handlerAddress >= (FPTR)SMH_BANK1 && handlerAddress <= (FPTR)SMH_BANK24) |
| 8961 | 11140 | return 1; |
| 8962 | 11141 | |
| 8963 | | /* ----- for smashtv, search bank two ----- */ |
| 8964 | | if( (machine->config->cpu[0].type == CPU_TMS34010) && (info->targetType == kRegionType_CPU) && |
| 8965 | | (info->targetIdx == 0) && (handler == SMH_BANK2)) |
| 8966 | | return 1; |
| 8967 | | |
| 8968 | | #endif |
| 8969 | | return 0; |
| 8970 | | |
| 8971 | | case kSearchSpeed_Medium: |
| 8972 | | if( (handlerAddress >= ((FPTR)SMH_BANK1)) && (handlerAddress <= ((FPTR)SMH_BANK24))) |
| 8973 | | return 1; |
| 8974 | | |
| 8975 | 11142 | if(handler == SMH_RAM) |
| 8976 | 11143 | return 1; |
| 8977 | 11144 | |
| 8978 | 11145 | return 0; |
| 8979 | 11146 | |
| 8980 | | case kSearchSpeed_Slow: |
| 8981 | | if( (handler == SMH_NOP) || (handler == SMH_ROM)) |
| 11147 | case ksearch_speed_Slow: |
| 11148 | if(handler == SMH_NOP || handler == SMH_ROM) |
| 8982 | 11149 | return 0; |
| 8983 | 11150 | |
| 8984 | | if( (handlerAddress > STATIC_COUNT) && (!region->writeHandler->baseptr)) |
| 11151 | if(handlerAddress > STATIC_COUNT && region->write_handler->baseptr == NULL) |
| 8985 | 11152 | return 0; |
| 8986 | 11153 | |
| 8987 | 11154 | return 1; |
| 8988 | 11155 | |
| 8989 | | case kSearchSpeed_VerySlow: |
| 8990 | | if( (handler == SMH_NOP) || (handler == SMH_ROM)) |
| 11156 | case ksearch_speed_VerySlow: |
| 11157 | if(handler == SMH_NOP || handler == SMH_ROM) |
| 8991 | 11158 | return 0; |
| 8992 | 11159 | |
| 8993 | 11160 | return 1; |
| r2762 | r2763 | |
| 8996 | 11163 | return 0; |
| 8997 | 11164 | } |
| 8998 | 11165 | |
| 8999 | | /*----------------------------- |
| 9000 | | SetSearchRegionDefaultName |
| 9001 | | -----------------------------*/ |
| 11166 | /*--------------------------------------------------------------------- |
| 11167 | set_search_region_default_name - set name of region to region list |
| 11168 | ---------------------------------------------------------------------*/ |
| 9002 | 11169 | |
| 9003 | | static void SetSearchRegionDefaultName(SearchRegion * region) |
| 11170 | static void set_search_region_default_name(search_region *region) |
| 9004 | 11171 | { |
| 9005 | | switch(region->targetType) |
| 11172 | switch(region->target_type) |
| 9006 | 11173 | { |
| 9007 | 11174 | case kRegionType_CPU: |
| 9008 | 11175 | { |
| 9009 | | char desc[16]; |
| 11176 | char desc[16]; |
| 9010 | 11177 | |
| 9011 | | if(region->writeHandler) |
| 11178 | if(region->write_handler) |
| 9012 | 11179 | { |
| 9013 | | genf * handler = region->writeHandler->write.generic; |
| 9014 | | FPTR handlerAddress = (FPTR)handler; |
| 11180 | genf *handler = region->write_handler->write.generic; |
| 11181 | FPTR handler_address = (FPTR)handler; |
| 9015 | 11182 | |
| 9016 | | if( (handlerAddress >= ((FPTR)SMH_BANK1)) && (handlerAddress <= ((FPTR)SMH_BANK24))) |
| 9017 | | sprintf(desc, "BANK%.2d", (int)(handlerAddress - (FPTR)SMH_BANK1) + 1); |
| 11183 | if(handler_address >= (FPTR)SMH_BANK1 && handler_address <= (FPTR)SMH_BANK24) |
| 11184 | { |
| 11185 | sprintf(desc, "BANK%.2d", (int)(handler_address - (FPTR)SMH_BANK1) + 1); |
| 11186 | } |
| 9018 | 11187 | else |
| 9019 | 11188 | { |
| 9020 | | switch(handlerAddress) |
| 11189 | switch(handler_address) |
| 9021 | 11190 | { |
| 9022 | 11191 | case (FPTR)SMH_NOP: strcpy(desc, "NOP "); break; |
| 9023 | 11192 | case (FPTR)SMH_RAM: strcpy(desc, "RAM "); break; |
| 9024 | 11193 | case (FPTR)SMH_ROM: strcpy(desc, "ROM "); break; |
| 9025 | | default: strcpy(desc, "CUSTOM"); break; |
| 11194 | default: strcpy(desc, "CUSTOM"); break; |
| 9026 | 11195 | } |
| 9027 | 11196 | } |
| 9028 | 11197 | } |
| 9029 | 11198 | else |
| 9030 | | sprintf(desc, "CPU%.2d ", region->targetIdx); |
| 11199 | sprintf(desc, "CPU%.2d ", region->target_idx); |
| 9031 | 11200 | |
| 9032 | 11201 | sprintf(region->name, "%.*X-%.*X %s", |
| 9033 | | cpuInfoList[region->targetIdx].addressCharsNeeded, |
| 9034 | | region->address, |
| 9035 | | cpuInfoList[region->targetIdx].addressCharsNeeded, |
| 9036 | | region->address + region->length - 1, |
| 11202 | cpu_info_list[region->target_idx].address_chars_needed, region->address, |
| 11203 | cpu_info_list[region->target_idx].address_chars_needed, region->address + region->length - 1, |
| 9037 | 11204 | desc); |
| 9038 | 11205 | } |
| 9039 | 11206 | break; |
| 9040 | 11207 | |
| 9041 | | case kRegionType_Memory: |
| 11208 | case kRegionType_Memory: /* unused? */ |
| 9042 | 11209 | sprintf(region->name, "%.8X-%.8X MEMORY", region->address, region->address + region->length - 1); |
| 9043 | 11210 | break; |
| 9044 | 11211 | |
| 9045 | 11212 | default: |
| 9046 | 11213 | sprintf(region->name, "UNKNOWN"); |
| 9047 | | break; |
| 9048 | 11214 | } |
| 9049 | 11215 | } |
| 9050 | 11216 | |
| 9051 | | /*----------------------------------------------------------------------------------- |
| 9052 | | AllocateSearchRegions - free memory for search region then realloc if searchable |
| 9053 | | -----------------------------------------------------------------------------------*/ |
| 11217 | /*------------------------------------------------------------------------------------- |
| 11218 | allocate_search_regions - free memory for search region then realloc if searchable |
| 11219 | -------------------------------------------------------------------------------------*/ |
| 9054 | 11220 | |
| 9055 | | static void AllocateSearchRegions(SearchInfo * info) |
| 11221 | static void allocate_search_regions(search_info *info) |
| 9056 | 11222 | { |
| 9057 | | int i; |
| 11223 | int i; |
| 9058 | 11224 | |
| 9059 | | info->backupValid = 0; |
| 9060 | | info->numResults = 0; |
| 11225 | info->backup_valid = 0; |
| 11226 | info->num_results = 0; |
| 9061 | 11227 | |
| 9062 | | for(i = 0; i < info->regionListLength; i++) |
| 11228 | for(i = 0; i < info->region_list_length; i++) |
| 9063 | 11229 | { |
| 9064 | | SearchRegion * region; |
| 11230 | search_region *region; |
| 9065 | 11231 | |
| 9066 | | region = &info->regionList[i]; |
| 11232 | region = &info->region_list[i]; |
| 11233 | region->num_results = 0; |
| 9067 | 11234 | |
| 9068 | | region->numResults = 0; |
| 9069 | | |
| 9070 | 11235 | free(region->first); |
| 9071 | 11236 | free(region->last); |
| 9072 | 11237 | free(region->status); |
| 9073 | | free(region->backupLast); |
| 9074 | | free(region->backupStatus); |
| 11238 | free(region->backup_last); |
| 11239 | free(region->backup_status); |
| 9075 | 11240 | |
| 9076 | 11241 | if(region->flags & kRegionFlag_Enabled) |
| 9077 | 11242 | { |
| 9078 | | region->first = malloc(region->length); |
| 9079 | | region->last = malloc(region->length); |
| 9080 | | region->status = malloc(region->length); |
| 9081 | | region->backupLast = malloc(region->length); |
| 9082 | | region->backupStatus = malloc(region->length); |
| 11243 | region->first = malloc(region->length); |
| 11244 | region->last = malloc(region->length); |
| 11245 | region->status = malloc(region->length); |
| 11246 | region->backup_last = malloc(region->length); |
| 11247 | region->backup_status = malloc(region->length); |
| 9083 | 11248 | |
| 9084 | | if(!region->first || !region->last || !region->status || !region->backupLast || !region->backupStatus) |
| 9085 | | { |
| 9086 | | free(region->first); |
| 9087 | | free(region->last); |
| 9088 | | free(region->status); |
| 9089 | | free(region->backupLast); |
| 9090 | | free(region->backupStatus); |
| 9091 | | |
| 9092 | | region->first = NULL; |
| 9093 | | region->last = NULL; |
| 9094 | | region->status = NULL; |
| 9095 | | region->backupLast = NULL; |
| 9096 | | region->backupStatus = NULL; |
| 9097 | | |
| 9098 | | region->flags &= ~kRegionFlag_Enabled; |
| 9099 | | } |
| 11249 | if(region->first == NULL || region->last == NULL || region->status == NULL || region->backup_last == NULL || region->backup_status == NULL) |
| 11250 | fatalerror( "cheat: [search region] memory allocation error\n" |
| 11251 | " ----- %s -----\n" |
| 11252 | " first = %p\n" |
| 11253 | " last = %p\n" |
| 11254 | " status = %p\n" |
| 11255 | " backup_last = %p\n" |
| 11256 | " backup_status = %p\n", |
| 11257 | region->name, |
| 11258 | region->first, region->last, region->status, region->backup_last, region->backup_status); |
| 9100 | 11259 | } |
| 9101 | 11260 | else |
| 9102 | 11261 | { |
| 9103 | | region->first = NULL; |
| 9104 | | region->last = NULL; |
| 9105 | | region->status = NULL; |
| 9106 | | region->backupLast = NULL; |
| 9107 | | region->backupStatus = NULL; |
| 11262 | region->first = NULL; |
| 11263 | region->last = NULL; |
| 11264 | region->status = NULL; |
| 11265 | region->backup_last = NULL; |
| 11266 | region->backup_status = NULL; |
| 9108 | 11267 | } |
| 9109 | 11268 | } |
| 9110 | 11269 | } |
| 9111 | 11270 | |
| 9112 | | /*--------------------- |
| 9113 | | BuildSearchRegions |
| 9114 | | ---------------------*/ |
| 11271 | /*-------------------------------------------------------------- |
| 11272 | build_search_regions - build serach regions from memory map |
| 11273 | --------------------------------------------------------------*/ |
| 9115 | 11274 | |
| 9116 | | static void BuildSearchRegions(running_machine *machine, SearchInfo * info) |
| 11275 | static void build_search_regions(running_machine *machine, search_info *info) |
| 9117 | 11276 | { |
| 9118 | 11277 | info->comparison = kSearchComparison_EqualTo; |
| 9119 | 11278 | |
| 9120 | | DisposeSearchRegions(info); |
| 11279 | /* 1st, free all search regions in current search_info */ |
| 11280 | dispose_search_reigons(info); |
| 9121 | 11281 | |
| 9122 | | switch(info->targetType) |
| 11282 | /* 2nd, set parameters from memory map */ |
| 11283 | switch(info->target_type) |
| 9123 | 11284 | { |
| 9124 | 11285 | case kRegionType_CPU: |
| 9125 | 11286 | { |
| 9126 | | if(info->searchSpeed == kSearchSpeed_AllMemory) |
| 11287 | if(info->search_speed == ksearch_speed_AllMemory) |
| 9127 | 11288 | { |
| 9128 | | UINT32 length = cpuInfoList[info->targetIdx].addressMask + 1; |
| 9129 | | SearchRegion * region; |
| 11289 | UINT32 length = cpu_info_list[info->target_idx].address_mask + 1; |
| 11290 | search_region *region; |
| 9130 | 11291 | |
| 9131 | | info->regionList = calloc(sizeof(SearchRegion), 1); |
| 9132 | | info->regionListLength = 1; |
| 9133 | | region = info->regionList; |
| 11292 | info->region_list = calloc(sizeof(search_region), 1); |
| 11293 | info->region_list_length = 1; |
| 9134 | 11294 | |
| 9135 | | region->address = 0; |
| 9136 | | region->length = length; |
| 11295 | region = info->region_list; |
| 11296 | region->address = 0; |
| 11297 | region->length = length; |
| 11298 | region->target_idx = info->target_idx; |
| 11299 | region->target_type = info->target_type; |
| 11300 | region->write_handler = NULL; |
| 11301 | region->first = NULL; |
| 11302 | region->last = NULL; |
| 11303 | region->status = NULL; |
| 11304 | region->backup_last = NULL; |
| 11305 | region->backup_status = NULL; |
| 11306 | region->flags = kRegionFlag_Enabled; |
| 9137 | 11307 | |
| 9138 | | region->targetIdx = info->targetIdx; |
| 9139 | | region->targetType = info->targetType; |
| 9140 | | region->writeHandler = NULL; |
| 9141 | | |
| 9142 | | region->first = NULL; |
| 9143 | | region->last = NULL; |
| 9144 | | region->status = NULL; |
| 9145 | | |
| 9146 | | region->backupLast = NULL; |
| 9147 | | region->backupStatus = NULL; |
| 9148 | | |
| 9149 | | region->flags = kRegionFlag_Enabled; |
| 9150 | | |
| 9151 | | SetSearchRegionDefaultName(region); |
| 11308 | set_search_region_default_name(region); |
| 9152 | 11309 | } |
| 9153 | 11310 | else |
| 9154 | 11311 | { |
| 9155 | | if(info->targetIdx < cpu_gettotalcpu()) |
| 11312 | if(VALID_CPU(info->target_idx)) |
| 9156 | 11313 | { |
| 9157 | | const address_map * map = NULL; |
| 9158 | | const address_map_entry * entry; |
| 9159 | | SearchRegion * traverse; |
| 9160 | | int count = 0; |
| 11314 | int count = 0; |
| 11315 | const address_map *map = NULL; |
| 11316 | const address_map_entry *entry; |
| 11317 | search_region *traverse; |
| 9161 | 11318 | |
| 9162 | | map = memory_get_address_map(info->targetIdx, ADDRESS_SPACE_PROGRAM); |
| 9163 | | for (entry = map->entrylist; entry != NULL; entry = entry->next) |
| 9164 | | if (entry->write.generic) |
| 11319 | map = memory_get_address_map(info->target_idx, ADDRESS_SPACE_PROGRAM); |
| 11320 | |
| 11321 | for(entry = map->entrylist; entry != NULL; entry = entry->next) |
| 11322 | if(entry->write.generic) |
| 9165 | 11323 | count++; |
| 9166 | 11324 | |
| 9167 | | info->regionList = calloc(sizeof(SearchRegion), count); |
| 9168 | | info->regionListLength = count; |
| 9169 | | traverse = info->regionList; |
| 11325 | info->region_list = calloc(sizeof(search_region), count); |
| 11326 | info->region_list_length = count; |
| 11327 | traverse = info->region_list; |
| 9170 | 11328 | |
| 9171 | | for (entry = map->entrylist; entry != NULL; entry = entry->next) |
| 11329 | for(entry = map->entrylist; entry != NULL; entry = entry->next) |
| 9172 | 11330 | { |
| 9173 | 11331 | if (entry->write.generic) |
| 9174 | 11332 | { |
| 9175 | | UINT32 length = (entry->addrend - entry->addrstart) + 1; |
| 11333 | UINT32 length = (entry->addrend - entry->addrstart) + 1; |
| 9176 | 11334 | |
| 9177 | | traverse->address = entry->addrstart; |
| 9178 | | traverse->length = length; |
| 11335 | traverse->address = entry->addrstart; |
| 11336 | traverse->length = length; |
| 11337 | traverse->target_idx = info->target_idx; |
| 11338 | traverse->target_type = info->target_type; |
| 11339 | traverse->write_handler = entry; |
| 11340 | traverse->first = NULL; |
| 11341 | traverse->last = NULL; |
| 11342 | traverse->status = NULL; |
| 11343 | traverse->backup_last = NULL; |
| 11344 | traverse->backup_status = NULL; |
| 11345 | traverse->flags = default_enable_region(machine, traverse, info) ? kRegionFlag_Enabled : 0; |
| 9179 | 11346 | |
| 9180 | | traverse->targetIdx = info->targetIdx; |
| 9181 | | traverse->targetType = info->targetType; |
| 9182 | | traverse->writeHandler = entry; |
| 11347 | set_search_region_default_name(traverse); |
| 9183 | 11348 | |
| 9184 | | traverse->first = NULL; |
| 9185 | | traverse->last = NULL; |
| 9186 | | traverse->status = NULL; |
| 9187 | | |
| 9188 | | traverse->backupLast = NULL; |
| 9189 | | traverse->backupStatus = NULL; |
| 9190 | | |
| 9191 | | traverse->flags = DefaultEnableRegion(machine, traverse, info) ? kRegionFlag_Enabled : 0; |
| 9192 | | |
| 9193 | | SetSearchRegionDefaultName(traverse); |
| 9194 | | |
| 9195 | 11349 | traverse++; |
| 9196 | 11350 | } |
| 9197 | 11351 | } |
| r2762 | r2763 | |
| 9200 | 11354 | } |
| 9201 | 11355 | break; |
| 9202 | 11356 | |
| 9203 | | case kRegionType_Memory: |
| 11357 | case kRegionType_Memory: /* unused? */ |
| 9204 | 11358 | break; |
| 9205 | 11359 | } |
| 9206 | 11360 | } |
| r2762 | r2763 | |
| 9283 | 11437 | { 94, 0x00000B00, kCustomField_None }, |
| 9284 | 11438 | { 95, 0x00000D00, kCustomField_SubtractOne }, |
| 9285 | 11439 | { 100, 0x20800000, kCustomField_None }, |
| 9286 | | { 101, 0x20000001, kCustomField_None }, |
| 11440 | { 101, 0x20800001, kCustomField_None }, |
| 9287 | 11441 | { 102, 0x20800000, kCustomField_None }, |
| 9288 | | { 103, 0x20000001, kCustomField_None }, |
| 11442 | { 103, 0x20800001, kCustomField_None }, |
| 9289 | 11443 | { 110, 0x40800000, kCustomField_None }, |
| 9290 | | { 111, 0x40000001, kCustomField_None }, |
| 11444 | { 111, 0x40800001, kCustomField_None }, |
| 9291 | 11445 | { 112, 0x40800000, kCustomField_None }, |
| 9292 | | { 113, 0x40000001, kCustomField_None }, |
| 11446 | { 113, 0x40800001, kCustomField_None }, |
| 9293 | 11447 | { 120, 0x63000001, kCustomField_None }, |
| 9294 | 11448 | { 121, 0x63000001, kCustomField_DontApplyCPUField | kCustomField_SetBit }, |
| 9295 | 11449 | { 122, 0x63000001, kCustomField_DontApplyCPUField | kCustomField_ClearBit }, |
| r2762 | r2763 | |
| 9298 | 11452 | { -1, 0x00000000, kCustomField_End } |
| 9299 | 11453 | }; |
| 9300 | 11454 | |
| 9301 | | const struct ConversionTable * traverse = kConversionTable; |
| 9302 | | UINT32 newCode; |
| 9303 | | UINT8 linkCheat = 0; |
| 11455 | const struct ConversionTable * traverse = kConversionTable; |
| 9304 | 11456 | |
| 9305 | | /* ----- convert link cheats ----- */ |
| 11457 | UINT8 linkCheat = 0; |
| 11458 | UINT32 newCode; |
| 11459 | |
| 11460 | /* convert link cheats */ |
| 9306 | 11461 | if((code >= 500) && (code <= 699)) |
| 9307 | 11462 | { |
| 9308 | 11463 | linkCheat = 1; |
| 9309 | 11464 | code -= 500; |
| 9310 | 11465 | } |
| 9311 | 11466 | |
| 9312 | | /* ----- look up code ----- */ |
| 11467 | /* look up code */ |
| 9313 | 11468 | while(traverse->oldCode >= 0) |
| 9314 | 11469 | { |
| 9315 | 11470 | if(code == traverse->oldCode) |
| r2762 | r2763 | |
| 9319 | 11474 | |
| 9320 | 11475 | logerror("ConvertOldCode: %d not found\n", code); |
| 9321 | 11476 | |
| 9322 | | /* ----- not found ----- */ |
| 11477 | /* not found */ |
| 9323 | 11478 | *extendData = 0; |
| 9324 | 11479 | return 0; |
| 9325 | 11480 | |
| 9326 | | /* ----- found ----- */ |
| 11481 | /* found */ |
| 9327 | 11482 | foundCode: |
| 9328 | 11483 | |
| 9329 | 11484 | newCode = traverse->newCode; |
| 9330 | 11485 | |
| 9331 | | /* ----- add in the CPU field ----- */ |
| 11486 | /* add in the CPU field */ |
| 9332 | 11487 | if(!(traverse->customField & kCustomField_DontApplyCPUField)) |
| 9333 | 11488 | newCode = (newCode & ~0x1F000000) | ((cpu << 24) & 0x1F000000); |
| 9334 | 11489 | |
| 9335 | | /* ----- hack-ish, subtract one from data field for x5 user select ----- */ |
| 11490 | /* hack-ish, subtract one from data field for x5 user select */ |
| 9336 | 11491 | if(traverse->customField & kCustomField_SubtractOne) |
| 9337 | 11492 | (*data)--; // yaay for C operator precedence |
| 9338 | 11493 | |
| 9339 | | /* ----- set up the extend data ----- */ |
| 11494 | /* set up the extend data */ |
| 9340 | 11495 | if(traverse->customField & kCustomField_BitMask) |
| 9341 | 11496 | *extendData = *data; |
| 9342 | 11497 | else |
| r2762 | r2763 | |
| 9351 | 11506 | return newCode; |
| 9352 | 11507 | } |
| 9353 | 11508 | |
| 9354 | | /*-------------------------------------------------------------------------------- |
| 9355 | | HandleLocalCommandCheat - get special code which is not added into cheat list |
| 9356 | | --------------------------------------------------------------------------------*/ |
| 11509 | /*------------------- |
| 11510 | ConvertToNewCode |
| 11511 | -------------------*/ |
| 9357 | 11512 | |
| 9358 | | static void HandleLocalCommandCheat(running_machine *machine, UINT32 type, UINT32 address, UINT32 data, UINT32 extendData, char * name, char * description) |
| 11513 | static int ConvertToNewCode(CheatAction * action) |
| 9359 | 11514 | { |
| 9360 | | switch(EXTRACT_FIELD(type, LocationType)) |
| 11515 | int newType = 0; |
| 11516 | |
| 11517 | if(EXTRACT_FIELD(action->type, LocationType) == kLocation_IndirectIndexed) |
| 11518 | SET_FIELD(newType, CPURegion, EXTRACT_FIELD(action->type, LocationParameterCPU)); |
| 11519 | else if(EXTRACT_FIELD(action->type, LocationType) != kLocation_Custom) |
| 11520 | SET_FIELD(newType, CPURegion, EXTRACT_FIELD(action->type, LocationParameter)); |
| 11521 | |
| 11522 | if(TEST_FIELD(action->type, UserSelectEnable)) |
| 11523 | SET_FIELD(newType, CodeType, kCodeType_VWrite); |
| 11524 | else if(EXTRACT_FIELD(action->type, LocationType) == kLocation_IndirectIndexed) |
| 11525 | { SET_FIELD(newType, CodeType, kCodeType_IWrite); |
| 11526 | SET_FIELD(newType, IndexSize, EXTRACT_FIELD(action->type, LocationParameterOption)); } |
| 11527 | else |
| 11528 | { SET_FIELD(newType, CodeType, kCodeType_PDWWrite); |
| 11529 | SET_FIELD(newType, IndexSize, kSearchSize_32Bit); } |
| 11530 | |
| 11531 | SET_FIELD(newType, AddressSize, EXTRACT_FIELD(action->type, BytesUsed)); |
| 11532 | |
| 11533 | if(TEST_FIELD(action->type, LinkEnable)) |
| 11534 | SET_FIELD(newType, Link, kLink_Link); |
| 11535 | |
| 11536 | if(TEST_FIELD(action->type, RestorePreviousValue)) |
| 11537 | SET_MASK_FIELD(newType, RestoreValue); |
| 11538 | |
| 11539 | if(EXTRACT_FIELD(action->type, Prefill)) |
| 11540 | SET_MASK_FIELD(newType, PrefillEnable); |
| 11541 | |
| 11542 | if(!EXTRACT_FIELD(action->type, Type) && EXTRACT_FIELD(action->type, TypeParameter)) |
| 11543 | SET_MASK_FIELD(newType, DelayEnable); |
| 11544 | |
| 11545 | if(TEST_FIELD(action->type, OneShot)) |
| 11546 | SET_MASK_FIELD(newType, OneShot); |
| 11547 | |
| 11548 | return newType; |
| 11549 | } |
| 11550 | |
| 11551 | /*-------------------------- |
| 11552 | HandleLocalCommandCheat |
| 11553 | --------------------------*/ |
| 11554 | |
| 11555 | static void HandleLocalCommandCheat(running_machine *machine, int cpu, int type, int address, int data, UINT8 format) |
| 11556 | { |
| 11557 | int command = 0; |
| 11558 | |
| 11559 | if(format != 1) |
| 9361 | 11560 | { |
| 9362 | | case kLocation_Custom: |
| 9363 | | switch(EXTRACT_FIELD(type, LocationParameter)) |
| 9364 | | { |
| 9365 | | /* ----- activation key ----- */ |
| 9366 | | case kCustomLocation_AssignActivationKey: |
| 9367 | | { |
| 9368 | | if(address < cheatListLength) |
| 9369 | | { |
| 9370 | | CheatEntry * entry = &cheatList[address]; |
| 11561 | switch(EXTRACT_FIELD(type, LocationParameter)) |
| 11562 | { |
| 11563 | case kCustomLocation_AssignActivationKey: |
| 11564 | command = kCustomCode_ActivationKey1; |
| 9371 | 11565 | |
| 9372 | | if(!TEST_FIELD(type, OneShot)) |
| 9373 | | { |
| 9374 | | /* ----- 1st activation key ----- */ |
| 9375 | | entry->activationKey1 = data; |
| 9376 | | entry->flags |= kCheatFlag_HasActivationKey1; |
| 9377 | | } |
| 9378 | | else |
| 9379 | | { |
| 9380 | | /* ----- 2nd activation key ----- */ |
| 9381 | | entry->activationKey2 = data; |
| 9382 | | entry->flags |= kCheatFlag_HasActivationKey2; |
| 9383 | | } |
| 9384 | | } |
| 9385 | | } |
| 11566 | if(TEST_FIELD(type, OneShot)) |
| 11567 | command = kCustomCode_ActivationKey2; |
| 9386 | 11568 | break; |
| 9387 | 11569 | |
| 9388 | | /* ----- pre-enable ----- */ |
| 9389 | | case kCustomLocation_Enable: |
| 9390 | | { |
| 9391 | | if(address < cheatListLength) |
| 9392 | | { |
| 9393 | | CheatEntry * entry = &cheatList[address]; |
| 11570 | case kCustomLocation_Enable: |
| 11571 | command = kCustomCode_PreEnable; |
| 11572 | break; |
| 9394 | 11573 | |
| 9395 | | ActivateCheat(entry); |
| 9396 | | } |
| 9397 | | } |
| 11574 | case kCustomLocation_Overclock: |
| 11575 | command = kCustomCode_OverClock; |
| 9398 | 11576 | break; |
| 9399 | 11577 | |
| 9400 | | /* ----- over-clock ----- */ |
| 9401 | | case kCustomLocation_Overclock: |
| 9402 | | { |
| 9403 | | if(address < cpu_gettotalcpu()) |
| 9404 | | { |
| 9405 | | double overclock = data; |
| 11578 | case kCustomLocation_RefreshRate: |
| 11579 | command = kCustomCode_RefreshRate; |
| 11580 | break; |
| 9406 | 11581 | |
| 9407 | | overclock /= 65536.0; |
| 11582 | default: |
| 11583 | return; |
| 11584 | } |
| 11585 | } |
| 11586 | else |
| 11587 | command = EXTRACT_FIELD(type, CodeType); |
| 9408 | 11588 | |
| 9409 | | cpunum_set_clockscale(machine, address, overclock); |
| 9410 | | } |
| 9411 | | } |
| 9412 | | break; |
| 11589 | switch(command) |
| 11590 | { |
| 11591 | case kCustomCode_ActivationKey1: |
| 11592 | case kCustomCode_ActivationKey2: |
| 11593 | if(address < cheatListLength) |
| 11594 | { |
| 11595 | CheatEntry * entry = &cheatList[address]; |
| 9413 | 11596 | |
| 9414 | | /* ----- refresh rate ----- */ |
| 9415 | | case kCustomLocation_RefreshRate: |
| 11597 | if(command == kCustomCode_ActivationKey1) |
| 9416 | 11598 | { |
| 9417 | | int width = video_screen_get_width(machine->primary_screen); |
| 9418 | | int height = video_screen_get_height(machine->primary_screen); |
| 9419 | | const rectangle *visarea = video_screen_get_visible_area(machine->primary_screen); |
| 9420 | | double refresh = data / 65536.0; |
| 9421 | | |
| 9422 | | video_screen_configure(machine->primary_screen, width, height, visarea, HZ_TO_ATTOSECONDS(refresh)); |
| 11599 | entry->activationKey2 = data; |
| 11600 | entry->flags |= kCheatFlag_HasActivationKey2; |
| 9423 | 11601 | } |
| 9424 | | break; |
| 11602 | else |
| 11603 | { |
| 11604 | entry->activationKey1 = data; |
| 11605 | entry->flags |= kCheatFlag_HasActivationKey1; |
| 11606 | } |
| 9425 | 11607 | } |
| 9426 | 11608 | break; |
| 11609 | |
| 11610 | case kCustomCode_PreEnable: |
| 11611 | if(address < cheatListLength) |
| 11612 | { |
| 11613 | CheatEntry * entry = &cheatList[address]; |
| 11614 | |
| 11615 | ActivateCheat(entry); |
| 11616 | |
| 11617 | if(data && (data < entry->actionListLength)) |
| 11618 | entry->selection = data; |
| 11619 | } |
| 11620 | break; |
| 11621 | |
| 11622 | case kCustomCode_OverClock: |
| 11623 | if(VALID_CPU(cpu)) |
| 11624 | { |
| 11625 | double overclock = data / 65536.0; |
| 11626 | |
| 11627 | cpunum_set_clockscale(machine, address, overclock); |
| 11628 | } |
| 11629 | break; |
| 11630 | |
| 11631 | case kCustomCode_RefreshRate: |
| 11632 | { |
| 11633 | int width = video_screen_get_width(machine->primary_screen); |
| 11634 | int height = video_screen_get_height(machine->primary_screen); |
| 11635 | |
| 11636 | const rectangle *visarea = video_screen_get_visible_area(machine->primary_screen); |
| 11637 | double refresh = data / 65536.0; |
| 11638 | |
| 11639 | video_screen_configure(machine->primary_screen, width, height, visarea, HZ_TO_ATTOSECONDS(refresh)); |
| 11640 | } |
| 11641 | break; |
| 9427 | 11642 | } |
| 9428 | 11643 | } |
| 9429 | 11644 | |
| 11645 | /*---------------------------------------------------- |
| 11646 | LoadCheatOption - load cheat option from database |
| 11647 | ----------------------------------------------------*/ |
| 11648 | |
| 11649 | static void LoadCheatOption(char * fileName) |
| 11650 | { |
| 11651 | static char buf[2048]; |
| 11652 | mame_file * theFile; |
| 11653 | file_error filerr; |
| 11654 | cheat_format * format = &cheat_format_table[0]; |
| 11655 | |
| 11656 | /* open the database */ |
| 11657 | filerr = mame_fopen(SEARCHPATH_CHEAT, fileName, OPEN_FLAG_READ, &theFile); |
| 11658 | |
| 11659 | if(filerr != FILERR_NONE) |
| 11660 | { |
| 11661 | messageType = kCheatMessage_FailedToLoadDatabase; |
| 11662 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 11663 | return; |
| 11664 | } |
| 11665 | |
| 11666 | while(mame_fgets(buf, 2048, theFile)) |
| 11667 | { |
| 11668 | char preCommand[9]; |
| 11669 | |
| 11670 | if(sscanf(buf, format->format_string, preCommand) == format->arguments_matched) |
| 11671 | { |
| 11672 | if(strlen(preCommand) == format->length_matched) |
| 11673 | { |
| 11674 | sscanf(preCommand, "%X", &cheatOptions); |
| 11675 | messageType = kCheatMessage_ReloadCheatOption; |
| 11676 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 11677 | } |
| 11678 | } |
| 11679 | } |
| 11680 | |
| 11681 | mame_fclose(theFile); |
| 11682 | } |
| 11683 | |
| 9430 | 11684 | /*------------------------------------------------ |
| 9431 | | LoadCheatFile - load cheat code from database |
| 11685 | LoadCheatCode - load cheat code from database |
| 9432 | 11686 | ------------------------------------------------*/ |
| 9433 | 11687 | |
| 9434 | | static void LoadCheatFile(running_machine *machine, char * fileName) |
| 11688 | static void LoadCheatCode(running_machine *machine, char * fileName) |
| 9435 | 11689 | { |
| 11690 | enum{ |
| 11691 | kFormatLevel_New = 1, |
| 11692 | kFormatLevel_Standard, |
| 11693 | kFormatLevel_Old }; |
| 11694 | |
| 11695 | char buf[2048]; |
| 9436 | 11696 | mame_file * theFile; |
| 9437 | | file_error filerr; |
| 9438 | | char formatString[256]; |
| 9439 | | char oldFormatString[256]; |
| 9440 | | char buf[2048]; |
| 9441 | | int recordNames = 0; |
| 11697 | file_error filerr; |
| 9442 | 11698 | |
| 9443 | | /* ----- open the database ----- */ |
| 11699 | /* open the database */ |
| 9444 | 11700 | filerr = mame_fopen(SEARCHPATH_CHEAT, fileName, OPEN_FLAG_READ, &theFile); |
| 9445 | 11701 | |
| 9446 | 11702 | if(filerr != FILERR_NONE) |
| r2762 | r2763 | |
| 9448 | 11704 | |
| 9449 | 11705 | foundCheatDatabase = 1; |
| 9450 | 11706 | |
| 9451 | | /* ----- make the format strings ----- */ |
| 9452 | | #ifdef MESS |
| 9453 | | sprintf(formatString, ":%s:%s", machine->gamedrv->name, "%x:%x:%x:%x:%x:%[^:\n\r]:%[^:\n\r]"); |
| 9454 | | sprintf(oldFormatString, "%s:%s", machine->gamedrv->name, "%x:%d:%x:%x:%d:%[^:\n\r]:%[^:\n\r]"); |
| 9455 | | #else |
| 9456 | | sprintf(formatString, ":%s:%s", machine->gamedrv->name, "%x:%x:%x:%x:%[^:\n\r]:%[^:\n\r]"); |
| 9457 | | sprintf(oldFormatString, "%s:%s", machine->gamedrv->name, "%d:%x:%x:%d:%[^:\n\r]:%[^:\n\r]"); |
| 9458 | | #endif |
| 9459 | | |
| 9460 | | /* ----- get a line from database ----- */ |
| 11707 | /* get a line from database */ |
| 9461 | 11708 | while(mame_fgets(buf, 2048, theFile)) |
| 9462 | 11709 | { |
| 9463 | | int type; |
| 9464 | | int address; |
| 9465 | | int data; |
| 9466 | | int extendData; |
| 9467 | | char name[256]; |
| 9468 | | char description[256]; |
| 11710 | int i; |
| 9469 | 11711 | #ifdef MESS |
| 9470 | 11712 | int crc; |
| 9471 | 11713 | #endif |
| 9472 | | |
| 9473 | | int argumentsMatched; |
| 9474 | | UINT32 command; |
| 9475 | | |
| 11714 | int type = 0; |
| 11715 | int address = 0; |
| 11716 | int data = 0; |
| 11717 | int extendData = 0; |
| 11718 | int argumentsMatched = 0; |
| 11719 | int formatLevel = 0; |
| 11720 | int oldCPU = 0; |
| 11721 | int oldCode = 0; |
| 11722 | char name[16] = { 0 }; |
| 11723 | char preData[16] = { 0 }; |
| 11724 | char preExtendData[16] = { 0 }; |
| 11725 | char description[256] = { 0 }; |
| 11726 | char comment[256] = { 0 }; |
| 9476 | 11727 | CheatEntry * entry; |
| 9477 | 11728 | CheatAction * action; |
| 9478 | 11729 | |
| 9479 | | /* ----- get command line ----- */ |
| 9480 | | argumentsMatched = sscanf(buf, ":_command:%8X", &command); |
| 9481 | | |
| 9482 | | if(argumentsMatched == 1) |
| 11730 | /* scan and check format */ |
| 11731 | for(i = 1; i < 4; i++) |
| 9483 | 11732 | { |
| 9484 | | /* ----- set cheatOptions from command line ----- */ |
| 9485 | | cheatOptions = command; |
| 11733 | cheat_format * format = &cheat_format_table[i]; |
| 9486 | 11734 | |
| 9487 | | continue; |
| 9488 | | } |
| 9489 | | |
| 9490 | | /* ----- get cheat code ----- */ |
| 9491 | | name[0] = 0; |
| 9492 | | description[0] = 0; |
| 9493 | | |
| 11735 | /* scan a parameter */ |
| 11736 | switch(i) |
| 11737 | { |
| 11738 | case kFormatLevel_New: |
| 11739 | case kFormatLevel_Standard: |
| 9494 | 11740 | #ifdef MESS |
| 9495 | | argumentsMatched = sscanf(buf, formatString, &crc, &type, &address, &data, &extendData, name, description); |
| 11741 | argumentsMatched = sscanf(buf, format->format_string, name, &crc, &type, &address, preData, preExtendData, description, comment); |
| 9496 | 11742 | #else |
| 9497 | | argumentsMatched = sscanf(buf, formatString, &type, &address, &data, &extendData, name, description); |
| 11743 | argumentsMatched = sscanf(buf, format->format_string, name, &type, &address, preData, preExtendData, description, comment); |
| 9498 | 11744 | #endif |
| 11745 | break; |
| 9499 | 11746 | |
| 11747 | case kFormatLevel_Old: |
| 9500 | 11748 | #ifdef MESS |
| 9501 | | if(argumentsMatched < 5) |
| 11749 | argumentsMatched = sscanf(buf, format->format_string, &crc, name, &oldCPU, &address, &data, &oldCode, description, comment); |
| 9502 | 11750 | #else |
| 9503 | | if(argumentsMatched < 4) |
| 11751 | argumentsMatched = sscanf(buf, format->format_string, name, &oldCPU, &address, &data, &oldCode, description, comment); |
| 9504 | 11752 | #endif |
| 9505 | | { |
| 9506 | | int oldCPU; |
| 9507 | | int oldCode; |
| 11753 | } |
| 9508 | 11754 | |
| 11755 | /* NOTE : description and comment are not always needed */ |
| 11756 | if(argumentsMatched < format->arguments_matched) |
| 11757 | continue; |
| 11758 | |
| 9509 | 11759 | #ifdef MESS |
| 9510 | | argumentsMatched = sscanf(buf, oldFormatString, &crc, &oldCPU, &address, &data, &oldCode, name, description); |
| 11760 | /* check name */ |
| 11761 | if(TEST_FIELD(cheatOptions, SharedCode) && strcmp(machine->gamedrv->parent, "0")) |
| 11762 | { |
| 11763 | if(strcmp(name, machine->gamedrv->parent)) |
| 11764 | break; |
| 11765 | } |
| 11766 | else |
| 11767 | #endif |
| 11768 | if(strcmp(name, machine->gamedrv->name)) |
| 11769 | break; |
| 11770 | #ifdef MESS |
| 11771 | /* check crc */ |
| 11772 | if(MatchesCRCTable(crc) == 0) |
| 11773 | break; |
| 11774 | #endif |
| 11775 | if(i != kFormatLevel_Old) |
| 11776 | { |
| 11777 | UINT8 hasError = 0; |
| 9511 | 11778 | |
| 9512 | | if(argumentsMatched < 5) |
| 9513 | | #else |
| 9514 | | argumentsMatched = sscanf(buf, oldFormatString, &oldCPU, &address, &data, &oldCode, name, description); |
| 11779 | /* check the length of data and extendData */ |
| 11780 | if(strlen(preData) != format->length_matched) |
| 11781 | { |
| 11782 | logerror("cheat - LoadCheatFile : %s has invalid extend data field length\n", description); |
| 11783 | messageType = kCheatMessage_WrongCode; |
| 11784 | hasError++; |
| 11785 | } |
| 9515 | 11786 | |
| 9516 | | if(argumentsMatched < 4) |
| 9517 | | #endif |
| 9518 | | /* ----- if it is not a cheat code, continue ----- */ |
| 9519 | | continue; |
| 11787 | if(strlen(preExtendData) != format->length_matched) |
| 11788 | { |
| 11789 | logerror("cheat - LoadCheatFile : %s has invalid data field length\n", description); |
| 11790 | messageType = kCheatMessage_WrongCode; |
| 11791 | hasError++; |
| 11792 | } |
| 11793 | |
| 11794 | if(hasError) |
| 11795 | continue; |
| 11796 | else |
| 11797 | { |
| 11798 | sscanf(preData, "%X", &data); |
| 11799 | sscanf(preExtendData, "%X", &extendData); |
| 11800 | } |
| 11801 | } |
| 9520 | 11802 | else |
| 11803 | type = ConvertOldCode(oldCode, oldCPU, &data, &extendData); |
| 11804 | |
| 11805 | /* matched! */ |
| 11806 | formatLevel = i; |
| 11807 | break; |
| 11808 | } |
| 11809 | |
| 11810 | /* attemp to get next line if unmatched */ |
| 11811 | if(formatLevel == 0) |
| 11812 | continue; |
| 11813 | |
| 11814 | //logerror("cheat: processing %s\n", buf); |
| 11815 | |
| 11816 | /* handle command code */ |
| 11817 | if(formatLevel == kFormatLevel_New) |
| 11818 | { |
| 11819 | if(EXTRACT_FIELD(type, CPURegion) == CUSTOM_CODE && EXTRACT_FIELD(type, CodeType) >= kCustomCode_ActivationKey1) |
| 9521 | 11820 | { |
| 9522 | | #ifdef MESS |
| 9523 | | if(!MatchesCRCTable(crc)) |
| 9524 | | continue; |
| 9525 | | #endif |
| 9526 | | /* ----- convert the old code to the new format ----- */ |
| 9527 | | if(TEST_FIELD(cheatOptions, LoadOldFormat)) |
| 9528 | | type = ConvertOldCode(oldCode, oldCPU, &data, &extendData); |
| 9529 | | // continue; |
| 11821 | // logerror("cheat: cheat line removed\n", buf); |
| 11822 | HandleLocalCommandCheat(machine, EXTRACT_FIELD(type, CPUIndex), type, address, data, formatLevel); |
| 11823 | continue; |
| 9530 | 11824 | } |
| 9531 | 11825 | } |
| 9532 | 11826 | else |
| 9533 | 11827 | { |
| 9534 | | #ifdef MESS |
| 9535 | | if(!MatchesCRCTable(crc)) |
| 9536 | | continue; |
| 9537 | | #endif |
| 11828 | if( EXTRACT_FIELD(type, LocationType) == kLocation_Custom && |
| 11829 | EXTRACT_FIELD(type, LocationParameter) <= kCustomLocation_AssignActivationKey) |
| 11830 | { |
| 11831 | HandleLocalCommandCheat(machine, EXTRACT_FIELD(type, LocationParameter), type, address, data, formatLevel); |
| 11832 | continue; |
| 11833 | } |
| 9538 | 11834 | } |
| 9539 | 11835 | |
| 9540 | | //logerror("cheat: processing %s\n", buf); |
| 9541 | | |
| 9542 | | if(TEST_FIELD(type, RemoveFromList)) |
| 11836 | /***** ENTRY *****/ |
| 11837 | if(EXTRACT_FIELD(type, Link) == kLink_Master) |
| 9543 | 11838 | { |
| 9544 | | //logerror("cheat: cheat line removed\n", buf); |
| 11839 | /* 1st (master) code in an entry */ |
| 11840 | ResizeCheatList(cheatListLength + 1); |
| 9545 | 11841 | |
| 9546 | | HandleLocalCommandCheat(machine, type, address, data, extendData, name, description); |
| 11842 | if(cheatListLength == 0) |
| 11843 | { |
| 11844 | logerror("cheat - LoadCheatFile: cheat list resize failed; bailing\n"); |
| 11845 | goto bail; |
| 11846 | } |
| 11847 | |
| 11848 | entry = &cheatList[cheatListLength - 1]; |
| 11849 | |
| 11850 | entry->name = create_string_copy(description); |
| 11851 | |
| 11852 | if(argumentsMatched == cheat_format_table[formatLevel].comment_matched) |
| 11853 | entry->comment = create_string_copy(comment); |
| 9547 | 11854 | } |
| 9548 | 11855 | else |
| 9549 | 11856 | { |
| 9550 | | if(TEST_FIELD(type, LinkEnable)) |
| 11857 | /* 2nd or later (link) code in an entry */ |
| 11858 | if(cheatListLength == 0) |
| 9551 | 11859 | { |
| 9552 | | /* ----- if 1st code is the link code, it is invalid ----- */ |
| 9553 | | if(cheatListLength == 0) |
| 9554 | | { |
| 9555 | | logerror("LoadCheatFile: first cheat found was link cheat; bailing\n"); |
| 11860 | logerror("cheat - LoadCheatFile: first cheat found was link cheat; bailing\n"); |
| 11861 | goto bail; |
| 11862 | } |
| 9556 | 11863 | |
| 9557 | | goto bail; |
| 9558 | | } |
| 11864 | entry = &cheatList[cheatListLength - 1]; |
| 11865 | } |
| 9559 | 11866 | |
| 9560 | | //logerror("cheat: doing link cheat\n"); |
| 11867 | /***** ACTION *****/ |
| 11868 | ResizeCheatActionList(&cheatList[cheatListLength - 1], entry->actionListLength + 1); |
| 9561 | 11869 | |
| 9562 | | entry = &cheatList[cheatListLength - 1]; |
| 9563 | | } |
| 9564 | | else |
| 9565 | | { |
| 9566 | | /* ----- go to the next cheat entry ----- */ |
| 9567 | | ResizeCheatList(cheatListLength + 1); |
| 11870 | if(entry->actionListLength == 0) |
| 11871 | { |
| 11872 | logerror("cheat - LoadCheatFile: action list resize failed; bailing\n"); |
| 11873 | goto bail; |
| 11874 | } |
| 9568 | 11875 | |
| 9569 | | //logerror("cheat: doing normal cheat\n"); |
| 11876 | action = &entry->actionList[entry->actionListLength - 1]; |
| 9570 | 11877 | |
| 9571 | | if(cheatListLength == 0) |
| 9572 | | { |
| 9573 | | logerror("LoadCheatFile: cheat list resize failed; bailing\n"); |
| 11878 | action->flags = 0; |
| 11879 | action->type = type; |
| 11880 | action->address = action->originalAddress = address; |
| 11881 | action->data = action->originalDataField = data; |
| 11882 | action->extendData = extendData; |
| 11883 | action->optionalName = create_string_copy(description); |
| 11884 | action->lastValue = NULL; |
| 9574 | 11885 | |
| 9575 | | goto bail; |
| 9576 | | } |
| 11886 | if(formatLevel != kFormatLevel_New) |
| 11887 | action->flags |= kActionFlag_OldFormat; |
| 11888 | } |
| 9577 | 11889 | |
| 9578 | | entry = &cheatList[cheatListLength - 1]; |
| 11890 | bail: |
| 9579 | 11891 | |
| 9580 | | /* ----- copy the code name ----- */ |
| 9581 | | entry->name = CreateStringCopy(name); |
| 11892 | /* close the database */ |
| 11893 | mame_fclose(theFile); |
| 11894 | } |
| 9582 | 11895 | |
| 9583 | | /* ----- copy the description if we got it ----- */ |
| 9584 | | if(argumentsMatched == 6) |
| 9585 | | entry->comment = CreateStringCopy(description); |
| 11896 | /*-------------------------------------------------------------------------------- |
| 11897 | LoadUserDefinedSearchRegion - load user region code and rebuild search region |
| 11898 | --------------------------------------------------------------------------------*/ |
| 9586 | 11899 | |
| 9587 | | recordNames = 0; |
| 11900 | static void LoadUserDefinedSearchRegion(running_machine *machine, char * fileName) |
| 11901 | { |
| 11902 | int count = 0; |
| 11903 | char buf[2048]; |
| 9588 | 11904 | |
| 9589 | | /* ----- try to copy the label if label-selection ------ */ |
| 9590 | | if( (EXTRACT_FIELD(type, LocationType) == kLocation_Custom) && |
| 9591 | | (EXTRACT_FIELD(type, LocationParameter) == kCustomLocation_Select)) |
| 9592 | | recordNames = 1; |
| 9593 | | } |
| 11905 | search_info *info = get_current_search(); |
| 11906 | mame_file * theFile; |
| 11907 | file_error filerr; |
| 11908 | cheat_format * format = &cheat_format_table[4]; |
| 9594 | 11909 | |
| 9595 | | ResizeCheatActionList(&cheatList[cheatListLength - 1], entry->actionListLength + 1); |
| 11910 | /* 1st, free all search regions in current search_info */ |
| 11911 | dispose_search_reigons(info); |
| 9596 | 11912 | |
| 9597 | | if(entry->actionListLength == 0) |
| 11913 | /* 2nd, attempt to open the memorymap file */ |
| 11914 | filerr = mame_fopen(SEARCHPATH_CHEAT, fileName, OPEN_FLAG_READ, &theFile); |
| 11915 | |
| 11916 | if(filerr != FILERR_NONE) |
| 11917 | { |
| 11918 | info->region_list_length = 0; |
| 11919 | messageType = kCheatMessage_FailedToLoadDatabase; |
| 11920 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 11921 | return; |
| 11922 | } |
| 11923 | |
| 11924 | /* 3rd, scan parameters from the file */ |
| 11925 | while(mame_fgets(buf, 2048, theFile)) |
| 11926 | { |
| 11927 | #ifdef MESS |
| 11928 | int crc; |
| 11929 | #endif |
| 11930 | int cpu; |
| 11931 | int space; |
| 11932 | int start; |
| 11933 | int end; |
| 11934 | int status; |
| 11935 | char name[9]; |
| 11936 | char description[64]; |
| 11937 | |
| 11938 | cpu_region_info *cpu_info; |
| 11939 | search_region *region; |
| 11940 | |
| 11941 | description[0] = 0; |
| 11942 | |
| 11943 | #ifdef MESS |
| 11944 | if(sscanf(buf, format->format_string, name, &crc, &cpu, &space, &start, &end, &status, description) < format->arguments_matched) |
| 11945 | #else |
| 11946 | if(sscanf(buf, format->format_string, name, &cpu, &space, &start, &end, &status, description) < format->arguments_matched) |
| 11947 | #endif |
| 11948 | continue; |
| 11949 | else |
| 11950 | { |
| 11951 | #ifdef MESS |
| 11952 | if(!MatchesCRCTable(crc)) |
| 11953 | continue; |
| 11954 | #endif |
| 11955 | if(cpu != info->target_idx) |
| 11956 | continue; |
| 11957 | } |
| 11958 | |
| 11959 | cpu_info = get_cpu_info(cpu); |
| 11960 | |
| 11961 | /* check parameters */ |
| 11962 | { |
| 11963 | switch(space) |
| 9598 | 11964 | { |
| 9599 | | logerror("LoadCheatFile: action list resize failed; bailing\n"); |
| 11965 | case kAddressSpace_Program: // standard program space |
| 11966 | case kAddressSpace_DirectMemory: // direct memory access for standard program space |
| 11967 | /* check length */ |
| 11968 | if(start >= end) |
| 11969 | { |
| 11970 | logerror("cheat - LoadUserDefinedSearchRegion : invalid length (start : %X >= end : %X) \n", start, end); |
| 11971 | continue; |
| 11972 | } |
| 9600 | 11973 | |
| 9601 | | goto bail; |
| 11974 | /* check bound */ |
| 11975 | if(end > cpu_info->address_mask) |
| 11976 | { |
| 11977 | logerror("cheat - LoadUserDefinedSearchRegion : end address (%X) is out of range\n", end); |
| 11978 | continue; |
| 11979 | } |
| 11980 | break; |
| 11981 | |
| 11982 | case kAddressSpace_DataSpace: // data space |
| 11983 | case kAddressSpace_IOSpace: // I/O space |
| 11984 | // underconstruction... |
| 11985 | break; |
| 11986 | |
| 11987 | default: |
| 11988 | logerror("cheat - LoadUserDefinedSearchRegion : %X is invalid space\n", space); |
| 11989 | continue; |
| 9602 | 11990 | } |
| 9603 | 11991 | |
| 9604 | | action = &entry->actionList[entry->actionListLength - 1]; |
| 11992 | /* check status */ |
| 11993 | if(status > 1) |
| 11994 | { |
| 11995 | logerror("cheat - LoadUserDefinedSearchRegion : %X is invalid status\n", status); |
| 11996 | continue; |
| 11997 | } |
| 11998 | } |
| 9605 | 11999 | |
| 9606 | | action->type = type; |
| 9607 | | action->address = address; |
| 9608 | | action->data = data; |
| 9609 | | action->originalDataField = data; |
| 9610 | | action->extendData = extendData; |
| 12000 | /* allocate memory for new search region */ |
| 12001 | info->region_list = realloc(info->region_list, (count + 1) * sizeof(search_region)); |
| 9611 | 12002 | |
| 9612 | | /* ----- copy the label if label-selection ------ */ |
| 9613 | | if(recordNames) |
| 9614 | | action->optionalName = CreateStringCopy(name); |
| 12003 | if(!info->region_list) |
| 12004 | { |
| 12005 | /* memory allocation error */ |
| 12006 | logerror("cheat - LoadUserDefinedSearchRegion: out of memory resizing search region\n"); |
| 12007 | ui_popup_time(2, "out of memory while buiding user search region"); |
| 12008 | info->region_list_length = 0; |
| 12009 | mame_fclose(theFile); |
| 12010 | return; |
| 9615 | 12011 | } |
| 12012 | |
| 12013 | region = &info->region_list[count]; |
| 12014 | |
| 12015 | /* 4th, set region parameters from scaned data */ |
| 12016 | region->address = start; |
| 12017 | region->length = end - start + 1; |
| 12018 | region->target_idx = cpu; |
| 12019 | |
| 12020 | if(!space) |
| 12021 | { |
| 12022 | region->target_type = kRegionType_CPU; |
| 12023 | region->cached_pointer = NULL; |
| 12024 | } |
| 12025 | else |
| 12026 | { |
| 12027 | region->target_type = kRegionType_Memory; |
| 12028 | region->cached_pointer = GetMemoryRegionBasePointer(cpu, kAddressSpace_DirectMemory, start); |
| 12029 | |
| 12030 | //logerror("pointer for %s : %p\n", description, region->cachedPointer); |
| 12031 | } |
| 12032 | |
| 12033 | region->write_handler = NULL; |
| 12034 | region->first = NULL; |
| 12035 | region->last = NULL; |
| 12036 | region->status = NULL; |
| 12037 | region->backup_last = NULL; |
| 12038 | region->backup_status = NULL; |
| 12039 | region->flags = status; |
| 12040 | |
| 12041 | sprintf(region->name, "%.*X-%.*X %s", |
| 12042 | cpu_info->address_chars_needed, region->address, |
| 12043 | cpu_info->address_chars_needed, region->address + region->length - 1, |
| 12044 | description); |
| 12045 | |
| 12046 | count++; |
| 9616 | 12047 | } |
| 9617 | 12048 | |
| 9618 | | bail: |
| 12049 | info->region_list_length = count; |
| 9619 | 12050 | |
| 9620 | | /* ----- close the database ----- */ |
| 12051 | if(info->region_list_length) |
| 12052 | { |
| 12053 | messageType = kCheatMessage_ReloadUserRegion; |
| 12054 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 12055 | } |
| 12056 | |
| 9621 | 12057 | mame_fclose(theFile); |
| 9622 | 12058 | } |
| 9623 | 12059 | |
| r2762 | r2763 | |
| 9625 | 12061 | LoadCheatDatabase - get the database name then load it |
| 9626 | 12062 | ---------------------------------------------------------*/ |
| 9627 | 12063 | |
| 9628 | | static void LoadCheatDatabase(running_machine *machine) |
| 12064 | static void LoadCheatDatabase(running_machine *machine, UINT8 flags) |
| 9629 | 12065 | { |
| 9630 | | char buf[4096]; |
| 12066 | UINT8 first = 1; |
| 12067 | |
| 12068 | char buf[256]; |
| 12069 | char data; |
| 9631 | 12070 | const char * inTraverse; |
| 9632 | 12071 | char * outTraverse; |
| 9633 | 12072 | char * mainTraverse; |
| 9634 | | int first = 1; |
| 9635 | | char data; |
| 9636 | 12073 | |
| 9637 | 12074 | cheatfile = options_get_string(mame_options(), OPTION_CHEAT_FILE); |
| 9638 | 12075 | |
| 9639 | | /* ----- set default database name as "cheat.dat" ----- */ |
| 9640 | | if (cheatfile[0] == 0) |
| 12076 | if (!cheatfile[0]) |
| 9641 | 12077 | cheatfile = "cheat.dat"; |
| 9642 | 12078 | |
| 9643 | | inTraverse = cheatfile; |
| 9644 | | outTraverse = buf; |
| 9645 | | mainTraverse = mainDatabaseName; |
| 12079 | inTraverse = cheatfile; |
| 12080 | outTraverse = buf; |
| 12081 | mainTraverse = mainDatabaseName; |
| 9646 | 12082 | |
| 9647 | 12083 | buf[0] = 0; |
| 9648 | 12084 | |
| 9649 | | /* ----- get database name ----- */ |
| 9650 | 12085 | do |
| 9651 | 12086 | { |
| 9652 | 12087 | data = *inTraverse; |
| 9653 | 12088 | |
| 9654 | | /* ----- check separator or line end ----- */ |
| 9655 | | if((data == ';') || (data == 0)) |
| 12089 | /* check separator or end */ |
| 12090 | if(data == ';' || !data) |
| 9656 | 12091 | { |
| 9657 | 12092 | *outTraverse++ = 0; |
| 9658 | 12093 | |
| r2762 | r2763 | |
| 9661 | 12096 | |
| 9662 | 12097 | if(buf[0]) |
| 9663 | 12098 | { |
| 9664 | | /* ----- load database based on the name we gotten ----- */ |
| 9665 | | LoadCheatFile(machine, buf); |
| 12099 | /* load database based on the name we gotten */ |
| 12100 | if(flags & kLoadFlag_CheatOption) |
| 12101 | LoadCheatOption(buf); |
| 12102 | if(flags & kLoadFlag_CheatCode) |
| 12103 | LoadCheatCode(machine, buf); |
| 12104 | if(flags & kLoadFlag_UserRegion) |
| 12105 | LoadUserDefinedSearchRegion(machine, buf); |
| 9666 | 12106 | |
| 9667 | | outTraverse =buf; |
| 9668 | | buf[0] = 0; |
| 9669 | | first = 0; |
| 12107 | outTraverse = buf; |
| 12108 | buf[0] = 0; |
| 12109 | first = 0; |
| 12110 | break; |
| 9670 | 12111 | } |
| 9671 | 12112 | } |
| 9672 | 12113 | else |
| r2762 | r2763 | |
| 9684 | 12125 | UpdateAllCheatInfo(); |
| 9685 | 12126 | } |
| 9686 | 12127 | |
| 9687 | | /*----------------------------------------------------------------------------------------- |
| 9688 | | DisposeCheatDatabase - deactivate all cheats when reload database or exit cheat system |
| 9689 | | -----------------------------------------------------------------------------------------*/ |
| 12128 | /*--------------------------------------------------------------------------------------- |
| 12129 | DisposeCheatDatabase - deactivate all cheats when reload a code or exit cheat system |
| 12130 | ---------------------------------------------------------------------------------------*/ |
| 9690 | 12131 | |
| 9691 | 12132 | static void DisposeCheatDatabase(void) |
| 9692 | 12133 | { |
| 9693 | | int i; |
| 12134 | int i; |
| 9694 | 12135 | |
| 9695 | | /* ----- first, turn all cheats "OFF" ----- */ |
| 12136 | /* first, turn all cheats "OFF" */ |
| 9696 | 12137 | for(i = 0; i < cheatListLength; i++) |
| 9697 | 12138 | TempDeactivateCheat(&cheatList[i]); |
| 9698 | 12139 | |
| 9699 | | /* ----- next, free memory for all cheat entries ----- */ |
| 12140 | /* next, free memory for all cheat entries */ |
| 9700 | 12141 | if(cheatList) |
| 9701 | 12142 | { |
| 9702 | 12143 | for(i = 0; i < cheatListLength; i++) |
| r2762 | r2763 | |
| 9716 | 12157 | static void ReloadCheatDatabase(running_machine *machine) |
| 9717 | 12158 | { |
| 9718 | 12159 | DisposeCheatDatabase(); |
| 9719 | | LoadCheatDatabase(machine); |
| 12160 | LoadCheatDatabase(machine, kLoadFlag_CheatCode); |
| 9720 | 12161 | |
| 9721 | | ui_popup_time(1, "Cheat Database reloaded"); |
| 12162 | if(foundCheatDatabase) |
| 12163 | messageType = kCheatMessage_ReloadCheatCode; |
| 12164 | else |
| 12165 | messageType = kCheatMessage_FailedToLoadDatabase; |
| 12166 | |
| 12167 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 9722 | 12168 | } |
| 9723 | 12169 | |
| 9724 | | /*--------------------------------------------------------------- |
| 9725 | | SaveCheat - save a code (normal code, activation key, option) |
| 9726 | | ---------------------------------------------------------------*/ |
| 12170 | /*------------------------------------------------------ |
| 12171 | SaveCheatCode - save a cheat code into the database |
| 12172 | ------------------------------------------------------*/ |
| 9727 | 12173 | |
| 9728 | | static void SaveCheat(running_machine *machine, CheatEntry * entry, int selection, int saveCode) |
| 12174 | static void SaveCheatCode(running_machine *machine, CheatEntry * entry) |
| 9729 | 12175 | { |
| 9730 | | enum{ |
| 9731 | | normalCode = 0, |
| 9732 | | activationKey, |
| 9733 | | command, |
| 9734 | | }; |
| 9735 | | |
| 9736 | | mame_file * theFile; |
| 9737 | | file_error filerr; |
| 9738 | | UINT32 i; |
| 12176 | #ifdef MESS |
| 12177 | INT8 i; |
| 12178 | INT8 error = 0; |
| 9739 | 12179 | char buf[4096]; |
| 9740 | 12180 | |
| 9741 | | /* ----- check selected entry ----- */ |
| 9742 | | if((saveCode == normalCode) || (saveCode == activationKey)) |
| 12181 | mame_file * theFile; |
| 12182 | file_error filerr; |
| 12183 | |
| 12184 | if(!entry || !entry->actionList || ((entry->flags & kCheatFlag_Select) && entry->actionListLength == 1)) |
| 12185 | error = 1; |
| 12186 | |
| 12187 | /* open the database */ |
| 12188 | if(!error) |
| 9743 | 12189 | { |
| 9744 | | if(!entry || !entry->actionList) |
| 9745 | | return; |
| 12190 | filerr = mame_fopen(SEARCHPATH_CHEAT, mainDatabaseName, OPEN_FLAG_WRITE, &theFile); |
| 9746 | 12191 | |
| 9747 | | if((saveCode == activationKey) && (entry->flags & kCheatFlag_Select) && !entry->actionListLength) |
| 9748 | | return; |
| 12192 | if(!theFile) |
| 12193 | error = 1; |
| 12194 | else if(filerr != FILERR_NONE) |
| 12195 | { |
| 12196 | filerr = mame_fopen(SEARCHPATH_CHEAT, mainDatabaseName, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &theFile); |
| 12197 | |
| 12198 | if(filerr != FILERR_NONE) |
| 12199 | error = 1; |
| 12200 | } |
| 9749 | 12201 | } |
| 9750 | 12202 | |
| 9751 | | /* ----- open the database ----- */ |
| 9752 | | filerr = mame_fopen(SEARCHPATH_CHEAT, mainDatabaseName, OPEN_FLAG_WRITE, &theFile); |
| 12203 | if(error) |
| 12204 | { |
| 12205 | messageType = kCheatMessage_FailedToSave; |
| 12206 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 12207 | return; |
| 12208 | } |
| 9753 | 12209 | |
| 9754 | | /* ----- if fails to create, no save ----- */ |
| 9755 | | if(!theFile) |
| 9756 | | return; |
| 9757 | | if (filerr != FILERR_NONE) |
| 12210 | mame_fseek(theFile, 0, SEEK_END); |
| 12211 | |
| 12212 | /* write the code to the database */ |
| 12213 | for(i = 0; i < entry->actionListLength; i++) |
| 9758 | 12214 | { |
| 9759 | | filerr = mame_fopen(SEARCHPATH_CHEAT, mainDatabaseName, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &theFile); |
| 12215 | UINT8 addressLength = 8; |
| 12216 | char * name; |
| 12217 | char * bufTraverse = buf; |
| 9760 | 12218 | |
| 9761 | | /* ----- if fails to create, no save ----- */ |
| 9762 | | if(filerr != FILERR_NONE) |
| 12219 | CheatAction * action = &entry->actionList[i]; |
| 12220 | |
| 12221 | /* get name */ |
| 12222 | if(!i) |
| 12223 | name = entry->name; |
| 12224 | else |
| 12225 | name = action->optionalName; |
| 12226 | |
| 12227 | /* get address length of CPU/Region */ |
| 12228 | addressLength = get_address_length(EXTRACT_FIELD(action->type, CPURegion)); |
| 12229 | |
| 12230 | /* print format */ |
| 12231 | #ifdef MESS |
| 12232 | bufTraverse += sprintf(bufTraverse, ">%s:%.8X:%.8X:%.*X:%.8X:%.8X", |
| 12233 | machine->gamedrv->name, |
| 12234 | thisGameCRC, |
| 12235 | action->type, |
| 12236 | addressLength, |
| 12237 | action->originalAddress, |
| 12238 | action->originalDataField, |
| 12239 | action->extendData); |
| 12240 | #else |
| 12241 | bufTraverse += sprintf(bufTraverse, ">%s:%.8X:%.*X:%.8X:%.8X", |
| 12242 | machine->gamedrv->name, |
| 12243 | action->type, |
| 12244 | addressLength, |
| 12245 | action->originalAddress, |
| 12246 | action->originalDataField, |
| 12247 | action->extendData); |
| 12248 | #endif |
| 12249 | /* set name */ |
| 12250 | if(name) |
| 12251 | { |
| 12252 | bufTraverse += sprintf(bufTraverse, ":%s", name); |
| 12253 | |
| 12254 | if(!i && entry->comment) |
| 12255 | bufTraverse += sprintf(bufTraverse, ":%s", entry->comment); |
| 12256 | } |
| 12257 | else |
| 12258 | { |
| 12259 | bufTraverse += sprintf(bufTraverse, ":(none)"); |
| 12260 | |
| 12261 | if(!i && entry->comment) |
| 12262 | bufTraverse += sprintf(bufTraverse, ":%s", entry->comment); |
| 12263 | } |
| 12264 | |
| 12265 | /* set comment */ |
| 12266 | if(!i && entry->comment) |
| 12267 | bufTraverse += sprintf(bufTraverse, ":%s", entry->comment); |
| 12268 | |
| 12269 | bufTraverse += sprintf(bufTraverse, "\n"); |
| 12270 | |
| 12271 | mame_fwrite(theFile, buf, (UINT32)strlen(buf)); |
| 12272 | } |
| 12273 | |
| 12274 | /* close the database */ |
| 12275 | mame_fclose(theFile); |
| 12276 | |
| 12277 | /* clear dirty flag as "this entry is already saved" */ |
| 12278 | entry->flags &= ~kCheatFlag_Dirty; |
| 12279 | |
| 12280 | messageType = kCheatMessage_SucceededToSave; |
| 12281 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 12282 | #endif |
| 12283 | SaveDescription(machine); |
| 12284 | } |
| 12285 | |
| 12286 | /*----------------------------------------------------------------- |
| 12287 | SaveActivationKey - save activation key code into the database |
| 12288 | -----------------------------------------------------------------*/ |
| 12289 | |
| 12290 | static void SaveActivationKey(running_machine *machine, CheatEntry * entry, int entryIndex) |
| 12291 | { |
| 12292 | INT8 i; |
| 12293 | INT8 error = 0; |
| 12294 | char buf[4096]; |
| 12295 | |
| 12296 | mame_file * theFile = NULL; |
| 12297 | file_error filerr; |
| 12298 | |
| 12299 | if(!(entry->flags & kCheatFlag_HasActivationKey1) && !(entry->flags & kCheatFlag_HasActivationKey2)) |
| 12300 | error = 1; |
| 12301 | |
| 12302 | if(!error && (!entry || !entry->actionList || ((entry->flags & kCheatFlag_Select) && entry->actionListLength == 1))) |
| 12303 | error = 2; |
| 12304 | |
| 12305 | /* open the database */ |
| 12306 | if(!error) |
| 12307 | { |
| 12308 | filerr = mame_fopen(SEARCHPATH_CHEAT, mainDatabaseName, OPEN_FLAG_WRITE, &theFile); |
| 12309 | |
| 12310 | if(!theFile) |
| 12311 | error = 2; |
| 12312 | else if(filerr != FILERR_NONE) |
| 12313 | { |
| 12314 | filerr = mame_fopen(SEARCHPATH_CHEAT, mainDatabaseName, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &theFile); |
| 12315 | |
| 12316 | if(filerr != FILERR_NONE) |
| 12317 | error = 2; |
| 12318 | } |
| 12319 | } |
| 12320 | |
| 12321 | switch(error) |
| 12322 | { |
| 12323 | case 1: |
| 12324 | messageType = kCheatMessage_NoActivationKey; |
| 12325 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 9763 | 12326 | return; |
| 12327 | |
| 12328 | case 2: |
| 12329 | messageType = kCheatMessage_FailedToSave; |
| 12330 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 12331 | return; |
| 9764 | 12332 | } |
| 9765 | 12333 | |
| 9766 | 12334 | mame_fseek(theFile, 0, SEEK_END); |
| 9767 | 12335 | |
| 9768 | | switch(saveCode) |
| 12336 | /* write the code to the database */ |
| 12337 | for(i = 0; i < 2; i++) |
| 9769 | 12338 | { |
| 9770 | | case normalCode: |
| 9771 | | for(i = 0; i < entry->actionListLength; i++) |
| 9772 | | { |
| 9773 | | CheatAction * action = &entry->actionList[i]; |
| 9774 | | char * name = entry->name; |
| 9775 | | UINT32 type = action->type; |
| 9776 | | char * bufTraverse = buf; |
| 9777 | | int addressLength = 8; |
| 12339 | int addressLength = 8; |
| 12340 | int activationKey = !i ? entry->activationKey1 : entry->activationKey2; |
| 12341 | int type = 0; |
| 12342 | char * bufTraverse = buf; |
| 9778 | 12343 | |
| 9779 | | /* ----- set link enable and label if label-selection ----- */ |
| 9780 | | if(i) |
| 9781 | | { |
| 9782 | | SET_MASK_FIELD(type, LinkEnable); |
| 12344 | CheatAction * action = &entry->actionList[0]; |
| 12345 | astring * name = input_code_name(astring_alloc(), activationKey); |
| 9783 | 12346 | |
| 9784 | | if(entry->flags & kCheatFlag_Select) |
| 9785 | | name = action->optionalName; |
| 9786 | | } |
| 12347 | /* set the flag in type field */ |
| 12348 | SET_FIELD(type, CPURegion, CUSTOM_CODE); |
| 9787 | 12349 | |
| 9788 | | /* ----- get address length for current CPU ----- */ |
| 9789 | | switch(EXTRACT_FIELD(type, LocationType)) |
| 9790 | | { |
| 9791 | | case kLocation_Standard: |
| 9792 | | case kLocation_HandlerMemory: |
| 9793 | | case kLocation_ProgramSpace: |
| 9794 | | addressLength = cpuInfoList[EXTRACT_FIELD(type, LocationParameter)].addressCharsNeeded; |
| 9795 | | break; |
| 12350 | if(activationKey) |
| 12351 | SET_FIELD(type, CodeType, kCustomCode_ActivationKey1); |
| 12352 | else |
| 12353 | SET_FIELD(type, CodeType, kCustomCode_ActivationKey2); |
| 9796 | 12354 | |
| 9797 | | case kLocation_IndirectIndexed: |
| 9798 | | addressLength = cpuInfoList[(EXTRACT_FIELD(type, LocationParameter) >> 2) & 0x7].addressCharsNeeded; |
| 9799 | | break; |
| 12355 | /* get address length of CPU/Region */ |
| 12356 | addressLength = get_address_length(EXTRACT_FIELD(action->type, CPURegion)); |
| 9800 | 12357 | |
| 9801 | | case kLocation_MemoryRegion: |
| 9802 | | { |
| 9803 | | int idx = EXTRACT_FIELD(type, LocationParameter) + REGION_CPU1 - REGION_INVALID; |
| 12358 | /* if not find 1st activation key at saving 1st key, try to save 2nd key */ |
| 12359 | if(!i && !(entry->flags & kCheatFlag_HasActivationKey1)) |
| 12360 | { |
| 12361 | astring_free(name); |
| 12362 | continue; |
| 12363 | } |
| 9804 | 12364 | |
| 9805 | | if(idx < kRegionListLength) |
| 9806 | | addressLength = regionInfoList[idx].addressCharsNeeded; |
| 9807 | | } |
| 9808 | | break; |
| 9809 | | } |
| 12365 | /* if not find 2nd key after 1st key saved, finish */ |
| 12366 | if(i && !(entry->flags & kCheatFlag_HasActivationKey2)) |
| 12367 | { |
| 12368 | astring_free(name); |
| 12369 | break; |
| 12370 | } |
| 12371 | |
| 9810 | 12372 | #ifdef MESS |
| 9811 | | bufTraverse += sprintf(bufTraverse, ":%s:%.8X:%.8X:%.*X:%.8X:%.8X", machine->gamedrv->name, thisGameCRC, type, addressLength, action->address, action->originalDataField, action->extendData); |
| 12373 | bufTraverse += sprintf(bufTraverse, |
| 12374 | ">%s:%.8X:%.8X:%.*X:%.8X:00000000", |
| 12375 | machine->gamedrv->name, |
| 12376 | thisGameCRC, |
| 12377 | type, |
| 12378 | addressLength, |
| 12379 | entryIndex, |
| 12380 | activationKey); |
| 9812 | 12381 | #else |
| 9813 | | bufTraverse += sprintf(bufTraverse, ":%s:%.8X:%.*X:%.8X:%.8X", machine->gamedrv->name, type, addressLength, action->address, action->originalDataField, action->extendData); |
| 12382 | bufTraverse += sprintf(bufTraverse, ">%s:%.8X:%.*X:%.8X:00000000", |
| 12383 | machine->gamedrv->name, |
| 12384 | type, |
| 12385 | addressLength, |
| 12386 | entryIndex, |
| 12387 | activationKey); |
| 9814 | 12388 | #endif |
| 9815 | | /* ----- set description and comment ----- */ |
| 9816 | | if(name) |
| 9817 | | { |
| 9818 | | bufTraverse += sprintf(bufTraverse, ":%s", name); |
| 12389 | /* set description */ |
| 12390 | if(!i) |
| 12391 | { |
| 12392 | if(!(entry->flags & kCheatFlag_Select)) |
| 12393 | bufTraverse += sprintf(bufTraverse, ":Pre-selection Key "); |
| 12394 | else |
| 12395 | bufTraverse += sprintf(bufTraverse, ":1st Activation Key "); |
| 12396 | } |
| 12397 | else |
| 12398 | { |
| 12399 | if(!(entry->flags & kCheatFlag_Select)) |
| 12400 | bufTraverse += sprintf(bufTraverse, ":Next-selection Key "); |
| 12401 | else |
| 12402 | bufTraverse += sprintf(bufTraverse, ":2nd Activation Key "); |
| 12403 | } |
| 9819 | 12404 | |
| 9820 | | if(!i && (entry->comment)) |
| 9821 | | bufTraverse += sprintf(bufTraverse, ":%s", entry->comment); |
| 9822 | | } |
| 9823 | | else |
| 9824 | | { |
| 9825 | | if(!i && (entry->comment)) |
| 9826 | | bufTraverse += sprintf(bufTraverse, ":(none):%s", entry->comment); |
| 9827 | | } |
| 12405 | /* set code name and button index */ |
| 12406 | if(entry->name) |
| 12407 | bufTraverse += sprintf(bufTraverse, "for %s (%s)\n", entry->name, astring_c(name)); |
| 12408 | else |
| 12409 | bufTraverse += sprintf(bufTraverse, "(%s)\n", astring_c(name)); |
| 9828 | 12410 | |
| 9829 | | bufTraverse += sprintf(bufTraverse, "\n"); |
| 12411 | /* write the activation key code */ |
| 12412 | mame_fwrite(theFile, buf, (UINT32)strlen(buf)); |
| 9830 | 12413 | |
| 9831 | | /* ----- write the normal cheat code ----- */ |
| 9832 | | mame_fwrite(theFile, buf, (UINT32)strlen(buf)); |
| 9833 | | } |
| 9834 | | break; |
| 12414 | astring_free(name); |
| 12415 | } |
| 9835 | 12416 | |
| 9836 | | case activationKey: |
| 9837 | | for(i = 0; i < 2; i++) |
| 9838 | | { |
| 9839 | | char * bufTraverse = buf; |
| 9840 | | int addressLength; |
| 12417 | /* close the database */ |
| 12418 | mame_fclose(theFile); |
| 9841 | 12419 | |
| 9842 | | /* ----- if not find 1st activation key at saving 1st key, try to save 2nd key ----- */ |
| 9843 | | if(!i && !(entry->flags & kCheatFlag_HasActivationKey1)) |
| 9844 | | continue; |
| 12420 | messageType = kCheatMessage_ActivationKeySaved; |
| 12421 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 12422 | } |
| 9845 | 12423 | |
| 9846 | | /* ----- if not find 2nd key after 1st key saved, finish ------ */ |
| 9847 | | if(i && !(entry->flags & kCheatFlag_HasActivationKey2)) |
| 9848 | | break; |
| 12424 | /*----------------------------------------------------------- |
| 12425 | SavePreEnable - save a pre-enable code into the database |
| 12426 | -----------------------------------------------------------*/ |
| 9849 | 12427 | |
| 9850 | | /* ----- get address length for current CPU ----- */ |
| 9851 | | if(!(entry->flags & kCheatFlag_Select)) |
| 9852 | | addressLength = cpuInfoList[EXTRACT_FIELD(entry->actionList[0].type, LocationParameter)].addressCharsNeeded; |
| 9853 | | else |
| 9854 | | addressLength = cpuInfoList[EXTRACT_FIELD(entry->actionList[1].type, LocationParameter)].addressCharsNeeded; |
| 12428 | static void SavePreEnable(running_machine *machine, CheatEntry * entry, int entryIndex) |
| 12429 | { |
| 12430 | int type = 0; |
| 12431 | INT8 error = 0; |
| 12432 | INT8 addressLength = 8; |
| 12433 | char buf[4096]; |
| 12434 | char * bufTraverse = buf; |
| 12435 | |
| 12436 | CheatAction * action = &entry->actionList[0]; |
| 12437 | mame_file * theFile = NULL; |
| 12438 | file_error filerr; |
| 12439 | |
| 12440 | if(!entry || !entry->actionList || ((entry->flags & kCheatFlag_Select) && entry->actionListLength == 1)) |
| 12441 | error = 1; |
| 12442 | |
| 12443 | /* open the database */ |
| 12444 | if(!error) |
| 12445 | { |
| 12446 | filerr = mame_fopen(SEARCHPATH_CHEAT, mainDatabaseName, OPEN_FLAG_WRITE, &theFile); |
| 12447 | |
| 12448 | if(!theFile) |
| 12449 | error = 1; |
| 12450 | else if(filerr != FILERR_NONE) |
| 12451 | { |
| 12452 | filerr = mame_fopen(SEARCHPATH_CHEAT, mainDatabaseName, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &theFile); |
| 12453 | |
| 12454 | if(filerr != FILERR_NONE) |
| 12455 | error = 1; |
| 12456 | } |
| 12457 | } |
| 12458 | |
| 12459 | if(error) |
| 12460 | { |
| 12461 | messageType = kCheatMessage_FailedToSave; |
| 12462 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 12463 | return; |
| 12464 | } |
| 12465 | else |
| 12466 | { |
| 12467 | SET_FIELD(type, CPURegion, CUSTOM_CODE); |
| 12468 | SET_FIELD(type, CodeType, kCustomCode_PreEnable); |
| 12469 | } |
| 12470 | |
| 12471 | mame_fseek(theFile, 0, SEEK_END); |
| 12472 | |
| 12473 | /* get address length of CPU/Region */ |
| 12474 | addressLength = get_address_length(EXTRACT_FIELD(action->type, CPURegion)); |
| 12475 | |
| 9855 | 12476 | #ifdef MESS |
| 9856 | | if(!i) |
| 9857 | | bufTraverse += sprintf(bufTraverse, ":%s:%.8X:63004000:%.*X:%.8X:00000000", machine->gamedrv->name, thisGameCRC, addressLength, selection, entry->activationKey1); |
| 9858 | | else |
| 9859 | | bufTraverse += sprintf(bufTraverse, ":%s:%.8X:63004001:%.*X:%.8X:00000000", machine->gamedrv->name, thisGameCRC, addressLength, selection, entry->activationKey2); |
| 12477 | bufTraverse += sprintf(bufTraverse, ">%s:%.8X:%8.8X:%.*X:%.8X:00000000", |
| 12478 | machine->gamedrv->name, |
| 12479 | thisGameCRC, |
| 12480 | type, |
| 12481 | addressLength, |
| 12482 | entryIndex, |
| 12483 | entry->selection); |
| 9860 | 12484 | #else |
| 9861 | | if(!i) |
| 9862 | | bufTraverse += sprintf(bufTraverse, ":%s:63004000:%.*X:%.8X:00000000", machine->gamedrv->name, addressLength, selection, entry->activationKey1); |
| 9863 | | else |
| 9864 | | bufTraverse += sprintf(bufTraverse, ":%s:63004001:%.*X:%.8X:00000000", machine->gamedrv->name, addressLength, selection, entry->activationKey2); |
| 12485 | bufTraverse += sprintf(bufTraverse, ">%s:%8.8X:%.*X:%.8X:00000000", |
| 12486 | machine->gamedrv->name, |
| 12487 | type, |
| 12488 | addressLength, |
| 12489 | entryIndex, |
| 12490 | entry->selection); |
| 9865 | 12491 | #endif |
| 9866 | | /* ----- set description and button index ----- */ |
| 9867 | | if(!i) |
| 9868 | | { |
| 9869 | | /* ----- 1st key ----- */ |
| 9870 | | astring *name = input_code_name(astring_alloc(), entry->activationKey1); |
| 9871 | | if (entry->name) |
| 9872 | | bufTraverse += sprintf(bufTraverse, ":1st Activation Key for %s (%s)\n", entry->name, astring_c(name)); |
| 9873 | | else |
| 9874 | | bufTraverse += sprintf(bufTraverse, ":1st Activation Key (%s)\n", astring_c(name)); |
| 9875 | | astring_free(name); |
| 9876 | | } |
| 9877 | | else |
| 9878 | | { |
| 9879 | | /* ----- 2nd key ----- */ |
| 9880 | | astring *name = input_code_name(astring_alloc(), entry->activationKey2); |
| 9881 | | if (entry->name) |
| 9882 | | bufTraverse += sprintf(bufTraverse, ":2nd Activation Key for %s (%s)\n", entry->name, astring_c(name)); |
| 9883 | | else |
| 9884 | | bufTraverse += sprintf(bufTraverse, ":2nd Activation Key (%s)\n", astring_c(name)); |
| 9885 | | astring_free(name); |
| 9886 | | } |
| 9887 | 12492 | |
| 9888 | | /* ----- write the activation key code ----- */ |
| 9889 | | mame_fwrite(theFile, buf, (UINT32)strlen(buf)); |
| 9890 | | } |
| 9891 | | break; |
| 12493 | /* set name */ |
| 12494 | bufTraverse += sprintf(bufTraverse, ":Pre-enable"); |
| 9892 | 12495 | |
| 9893 | | case command: |
| 9894 | | sprintf(buf, ":_command:%.8X\n", cheatOptions); |
| 12496 | if(entry->name) |
| 12497 | bufTraverse += sprintf(bufTraverse, " for %s", entry->name); |
| 9895 | 12498 | |
| 9896 | | /* ----- write the command code ----- */ |
| 9897 | | mame_fwrite(theFile, buf, (UINT32)strlen(buf)); |
| 9898 | | break; |
| 12499 | /* set label name */ |
| 12500 | if(entry->selection) |
| 12501 | bufTraverse += sprintf(bufTraverse, " Label - %s", entry->actionList[entry->labelIndex[entry->selection]].optionalName); |
| 9899 | 12502 | |
| 9900 | | default: |
| 9901 | | break; |
| 12503 | bufTraverse += sprintf(bufTraverse, "\n"); |
| 12504 | |
| 12505 | /* write the pre-enable code */ |
| 12506 | mame_fwrite(theFile, buf, (UINT32)strlen(buf)); |
| 12507 | |
| 12508 | /* close the database */ |
| 12509 | mame_fclose(theFile); |
| 12510 | |
| 12511 | messageType = kCheatMessage_PreEnableSaved; |
| 12512 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 12513 | } |
| 12514 | |
| 12515 | /*-------------------------------------------------------------- |
| 12516 | SaveCheatOptions - save cheat option code into the database |
| 12517 | --------------------------------------------------------------*/ |
| 12518 | |
| 12519 | static void SaveCheatOptions(void) |
| 12520 | { |
| 12521 | UINT8 error = 0; |
| 12522 | char buf[32]; |
| 12523 | |
| 12524 | mame_file * theFile; |
| 12525 | file_error filerr; |
| 12526 | |
| 12527 | /* open the database */ |
| 12528 | filerr = mame_fopen(SEARCHPATH_CHEAT, mainDatabaseName, OPEN_FLAG_WRITE, &theFile); |
| 12529 | |
| 12530 | if(!theFile) |
| 12531 | error = 1; |
| 12532 | else if(filerr != FILERR_NONE) |
| 12533 | { |
| 12534 | filerr = mame_fopen(SEARCHPATH_CHEAT, mainDatabaseName, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &theFile); |
| 12535 | |
| 12536 | if(filerr != FILERR_NONE) |
| 12537 | error = 1; |
| 9902 | 12538 | } |
| 9903 | 12539 | |
| 9904 | | /* ----- close the database ----- */ |
| 12540 | if(error) |
| 12541 | { |
| 12542 | messageType = kCheatMessage_FailedToSave; |
| 12543 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 12544 | return; |
| 12545 | } |
| 12546 | |
| 12547 | mame_fseek(theFile, 0, SEEK_END); |
| 12548 | |
| 12549 | sprintf(buf, ":_command:%.8X\n", cheatOptions); |
| 12550 | |
| 12551 | /* write the command code */ |
| 12552 | mame_fwrite(theFile, buf, (UINT32)strlen(buf)); |
| 12553 | |
| 12554 | /* close the database */ |
| 9905 | 12555 | mame_fclose(theFile); |
| 9906 | 12556 | |
| 9907 | | /* ----- clear dirty flag ----- */ |
| 9908 | | if((saveCode == normalCode) || (saveCode == activationKey)) |
| 9909 | | entry->flags &= ~kCheatFlag_Dirty; |
| 12557 | messageType = kCheatMessage_SucceededToSave; |
| 12558 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 9910 | 12559 | } |
| 9911 | 12560 | |
| 12561 | /*------------------ |
| 12562 | SaveDescription |
| 12563 | ------------------*/ |
| 12564 | |
| 12565 | static void SaveDescription(running_machine *machine) |
| 12566 | { |
| 12567 | UINT8 error = 0; |
| 12568 | char buf[256]; |
| 12569 | |
| 12570 | mame_file * theFile; |
| 12571 | file_error filerr; |
| 12572 | |
| 12573 | filerr = mame_fopen(SEARCHPATH_CHEAT, mainDatabaseName, OPEN_FLAG_WRITE, &theFile); |
| 12574 | |
| 12575 | if(!theFile) |
| 12576 | error = 1; |
| 12577 | else if(filerr != FILERR_NONE) |
| 12578 | { |
| 12579 | filerr = mame_fopen(SEARCHPATH_CHEAT, mainDatabaseName, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &theFile); |
| 12580 | |
| 12581 | if(filerr != FILERR_NONE) |
| 12582 | error = 1; |
| 12583 | } |
| 12584 | |
| 12585 | if(error) |
| 12586 | { |
| 12587 | messageType = kCheatMessage_FailedToSave; |
| 12588 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 12589 | return; |
| 12590 | } |
| 12591 | |
| 12592 | mame_fseek(theFile, 0, SEEK_END); |
| 12593 | sprintf(buf, "> [ %s ]\n", machine->gamedrv->description); |
| 12594 | |
| 12595 | /* write the command code */ |
| 12596 | mame_fwrite(theFile, buf, (UINT32)strlen(buf)); |
| 12597 | |
| 12598 | /* close the database */ |
| 12599 | mame_fclose(theFile); |
| 12600 | |
| 12601 | messageType = kCheatMessage_SucceededToSave; |
| 12602 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 12603 | } |
| 12604 | |
| 9912 | 12605 | /*-------------------------------------------------------------------------- |
| 9913 | 12606 | DoAutoSaveCheat - save normal code automatically when exit cheat system |
| 9914 | 12607 | --------------------------------------------------------------------------*/ |
| 9915 | 12608 | |
| 9916 | 12609 | static void DoAutoSaveCheats(running_machine *machine) |
| 9917 | 12610 | { |
| 9918 | | int i; |
| 12611 | int i; |
| 9919 | 12612 | |
| 9920 | 12613 | for(i = 0; i < cheatListLength; i++) |
| 9921 | 12614 | { |
| 9922 | | CheatEntry * entry = &cheatList[i]; |
| 12615 | CheatEntry * entry = &cheatList[i]; |
| 9923 | 12616 | |
| 12617 | /* if the entry is not edited/added newly or has not been already saved, save it */ |
| 9924 | 12618 | if(entry->flags & kCheatFlag_Dirty) |
| 9925 | | SaveCheat(machine, entry, 0, 0); |
| 12619 | SaveCheatCode(machine, entry); |
| 9926 | 12620 | } |
| 9927 | 12621 | } |
| 9928 | 12622 | |
| r2762 | r2763 | |
| 9930 | 12624 | AddCheatFromResult - add a code from result viewer to cheat list |
| 9931 | 12625 | -------------------------------------------------------------------*/ |
| 9932 | 12626 | |
| 9933 | | static void AddCheatFromResult(SearchInfo * search, SearchRegion * region, UINT32 address) |
| 12627 | static void AddCheatFromResult(search_info *search, search_region *region, UINT32 address) |
| 9934 | 12628 | { |
| 9935 | | if(region->targetType == kRegionType_CPU) |
| 12629 | if((region->target_type == kRegionType_CPU) || (region->target_type == kRegionType_Memory)) |
| 9936 | 12630 | { |
| 9937 | 12631 | CheatEntry * entry = GetNewCheat(); |
| 9938 | 12632 | CheatAction * action = &entry->actionList[0]; |
| 9939 | 12633 | char tempString[1024]; |
| 9940 | 12634 | int tempStringLength; |
| 9941 | | UINT32 data = ReadSearchOperand(kSearchOperand_First, search, region, address); |
| 12635 | UINT32 data = read_search_operand(kSearchOperand_First, search, region, address); |
| 9942 | 12636 | |
| 9943 | | tempStringLength = sprintf(tempString, "%.8X (%d) = %.*X", address, region->targetIdx, kSearchByteDigitsTable[search->bytes], data); |
| 12637 | tempStringLength = sprintf(tempString, "%.8X (%d) = %.*X", address, region->target_idx, kSearchByteDigitsTable[search->bytes], data); |
| 9944 | 12638 | |
| 9945 | 12639 | entry->name = realloc(entry->name, tempStringLength + 1); |
| 9946 | 12640 | memcpy(entry->name, tempString, tempStringLength + 1); |
| 9947 | 12641 | |
| 9948 | | SET_FIELD(action->type, LocationParameter, region->targetIdx); |
| 9949 | | SET_FIELD(action->type, BytesUsed, kSearchByteIncrementTable[search->bytes] - 1); |
| 12642 | SET_FIELD(action->type, CPURegion, region->target_idx); |
| 12643 | SET_FIELD(action->type, AddressSize, kSearchByteIncrementTable[search->bytes] - 1); |
| 9950 | 12644 | action->address = address; |
| 9951 | | action->data = data; |
| 12645 | action->data = action->originalDataField = data; |
| 9952 | 12646 | action->extendData = 0xFFFFFFFF; |
| 9953 | | action->originalDataField = data; |
| 12647 | action->lastValue = NULL; |
| 9954 | 12648 | |
| 9955 | 12649 | UpdateCheatInfo(entry, 0); |
| 9956 | 12650 | } |
| r2762 | r2763 | |
| 9960 | 12654 | AddCheatFromFirstResult - add a code from search box to cheat list if found result is one |
| 9961 | 12655 | --------------------------------------------------------------------------------------------*/ |
| 9962 | 12656 | |
| 9963 | | static void AddCheatFromFirstResult(SearchInfo * search) |
| 12657 | static void AddCheatFromFirstResult(search_info *search) |
| 9964 | 12658 | { |
| 9965 | 12659 | int i; |
| 9966 | 12660 | |
| 9967 | | for(i = 0; i < search->regionListLength; i++) |
| 12661 | for(i = 0; i < search->region_list_length; i++) |
| 9968 | 12662 | { |
| 9969 | | SearchRegion * region = &search->regionList[i]; |
| 12663 | search_region *region = &search->region_list[i]; |
| 9970 | 12664 | |
| 9971 | | if(region->numResults) |
| 12665 | if(region->num_results) |
| 9972 | 12666 | { |
| 9973 | 12667 | UINT32 traverse; |
| 9974 | 12668 | |
| r2762 | r2763 | |
| 9976 | 12670 | { |
| 9977 | 12671 | UINT32 address = region->address + traverse; |
| 9978 | 12672 | |
| 9979 | | if(IsRegionOffsetValid(search, region, traverse)) |
| 12673 | if(is_region_offset_valid(search, region, traverse)) |
| 9980 | 12674 | { |
| 9981 | 12675 | AddCheatFromResult(search, region, address); |
| 9982 | | |
| 9983 | 12676 | return; |
| 9984 | 12677 | } |
| 9985 | 12678 | } |
| r2762 | r2763 | |
| 9991 | 12684 | AddWatchFromResult - add a watch code from result viewer to cheat list |
| 9992 | 12685 | -------------------------------------------------------------------------*/ |
| 9993 | 12686 | |
| 9994 | | static void AddWatchFromResult(SearchInfo * search, SearchRegion * region, UINT32 address) |
| 12687 | static void AddWatchFromResult(search_info *search, search_region *region, UINT32 address) |
| 9995 | 12688 | { |
| 9996 | | if(region->targetType == kRegionType_CPU) |
| 12689 | if(region->target_type == kRegionType_CPU || region->target_type == kRegionType_Memory) |
| 9997 | 12690 | { |
| 9998 | | WatchInfo * info = GetUnusedWatch(); |
| 12691 | WatchInfo * info = GetUnusedWatch(); |
| 9999 | 12692 | |
| 10000 | | info->address = address; |
| 10001 | | info->cpu = region->targetIdx; |
| 10002 | | info->numElements = 1; |
| 10003 | | info->elementBytes = kWatchSizeConversionTable[search->bytes]; |
| 10004 | | info->labelType = kWatchLabel_None; |
| 10005 | | info->displayType = kWatchDisplayType_Hex; |
| 10006 | | info->skip = 0; |
| 10007 | | info->elementsPerLine = 0; |
| 10008 | | info->addValue = 0; |
| 12693 | info->address = address; |
| 12694 | info->cpu = region->target_idx; |
| 12695 | info->numElements = 1; |
| 12696 | info->elementBytes = kWatchSizeConversionTable[search->bytes]; |
| 12697 | info->labelType = kWatchLabel_None; |
| 12698 | info->displayType = kWatchDisplayType_Hex; |
| 12699 | info->skip = 0; |
| 12700 | info->elementsPerLine = 0; |
| 12701 | info->addValue = 0; |
| 12702 | info->linkedCheat = NULL; |
| 12703 | info->label[0] = 0; |
| 10009 | 12704 | |
| 10010 | | info->linkedCheat = NULL; |
| 10011 | | |
| 10012 | | info->label[0] = 0; |
| 12705 | messageType = kCheatMessage_SucceededToAdd; |
| 12706 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 10013 | 12707 | } |
| 12708 | else |
| 12709 | { |
| 12710 | messageType = kCheatMessage_FailedToAdd; |
| 12711 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 12712 | } |
| 10014 | 12713 | } |
| 10015 | 12714 | |
| 10016 | | /*-------------------- |
| 10017 | | SearchSignExtend |
| 10018 | | --------------------*/ |
| 12715 | /*--------------------- |
| 12716 | search_sign_extend |
| 12717 | ---------------------*/ |
| 10019 | 12718 | |
| 10020 | | static UINT32 SearchSignExtend(SearchInfo * search, UINT32 value) |
| 12719 | static UINT32 search_sign_extend(search_info *search, UINT32 value) |
| 10021 | 12720 | { |
| 10022 | 12721 | if(search->sign) |
| 10023 | | { |
| 10024 | 12722 | if(value & kSearchByteSignBitTable[search->bytes]) |
| 10025 | 12723 | value |= ~kSearchByteUnsignedMaskTable[search->bytes]; |
| 10026 | | } |
| 10027 | 12724 | |
| 10028 | 12725 | return value; |
| 10029 | 12726 | } |
| 10030 | 12727 | |
| 10031 | | /*------------------------------------------------------------------- |
| 10032 | | ReadSearchOperand - read a data from search region and return it |
| 10033 | | -------------------------------------------------------------------*/ |
| 12728 | /*--------------------------------------------------------------------- |
| 12729 | read_search_operand - read a data from search region and return it |
| 12730 | ---------------------------------------------------------------------*/ |
| 10034 | 12731 | |
| 10035 | | static UINT32 ReadSearchOperand(UINT8 type, SearchInfo * search, SearchRegion * region, UINT32 address) |
| 12732 | static UINT32 read_search_operand(UINT8 type, search_info *search, search_region *region, UINT32 address) |
| 10036 | 12733 | { |
| 10037 | | UINT32 value = 0; |
| 12734 | UINT32 value = 0; |
| 10038 | 12735 | |
| 10039 | 12736 | switch(type) |
| 10040 | 12737 | { |
| 10041 | 12738 | case kSearchOperand_Current: |
| 10042 | | value = ReadRegionData(region, address - region->address, kSearchByteIncrementTable[search->bytes], search->swap); |
| 12739 | value = read_region_data(region, address - region->address, kSearchByteIncrementTable[search->bytes], search->swap); |
| 10043 | 12740 | break; |
| 10044 | 12741 | |
| 10045 | 12742 | case kSearchOperand_Previous: |
| r2762 | r2763 | |
| 10052 | 12749 | |
| 10053 | 12750 | case kSearchOperand_Value: |
| 10054 | 12751 | value = search->value; |
| 10055 | | break; |
| 10056 | 12752 | } |
| 10057 | 12753 | |
| 10058 | | value = SearchSignExtend(search, value); |
| 12754 | value = search_sign_extend(search, value); |
| 10059 | 12755 | |
| 10060 | 12756 | return value; |
| 10061 | 12757 | } |
| 10062 | 12758 | |
| 10063 | | /*------------------------------------------------------------------------------------------ |
| 10064 | | ReadSearchOperandBit - read a bit data from search region and return it when bit search |
| 10065 | | ------------------------------------------------------------------------------------------*/ |
| 12759 | /*--------------------------------------------------------------------------------------------- |
| 12760 | read_search_operand_bit - read a bit data from search region and return it when bit search |
| 12761 | ---------------------------------------------------------------------------------------------*/ |
| 10066 | 12762 | |
| 10067 | | static UINT32 ReadSearchOperandBit(UINT8 type, SearchInfo * search, SearchRegion * region, UINT32 address) |
| 12763 | static UINT32 read_search_operand_bit(UINT8 type, search_info *search, search_region *region, UINT32 address) |
| 10068 | 12764 | { |
| 10069 | | UINT32 value = 0; |
| 12765 | UINT32 value = 0; |
| 10070 | 12766 | |
| 10071 | 12767 | switch(type) |
| 10072 | 12768 | { |
| 10073 | 12769 | case kSearchOperand_Current: |
| 10074 | | value = ReadRegionData(region, address - region->address, kSearchByteIncrementTable[search->bytes], search->swap); |
| 12770 | value = read_region_data(region, address - region->address, kSearchByteIncrementTable[search->bytes], search->swap); |
| 10075 | 12771 | break; |
| 10076 | 12772 | |
| 10077 | 12773 | case kSearchOperand_Previous: |
| r2762 | r2763 | |
| 10087 | 12783 | value = 0xFFFFFFFF; |
| 10088 | 12784 | else |
| 10089 | 12785 | value = 0x00000000; |
| 10090 | | break; |
| 10091 | 12786 | } |
| 10092 | 12787 | |
| 10093 | | value = SearchSignExtend(search, value); |
| 12788 | value = search_sign_extend(search, value); |
| 10094 | 12789 | |
| 10095 | 12790 | return value; |
| 10096 | 12791 | } |
| 10097 | 12792 | |
| 10098 | | /*---------------------------------------------------------- |
| 10099 | | DoSearchComparison - compare data and return it matched |
| 10100 | | ----------------------------------------------------------*/ |
| 12793 | /*------------------------------------------------------------ |
| 12794 | do_search_comparison - compare data and return it matched |
| 12795 | ------------------------------------------------------------*/ |
| 10101 | 12796 | |
| 10102 | | static UINT8 DoSearchComparison(SearchInfo * search, UINT32 lhs, UINT32 rhs) |
| 12797 | static UINT8 do_search_comparison(search_info *search, UINT32 lhs, UINT32 rhs) |
| 10103 | 12798 | { |
| 10104 | | INT32 svalue; |
| 12799 | INT32 svalue; |
| 10105 | 12800 | |
| 10106 | 12801 | if(search->sign) |
| 10107 | 12802 | { |
| 10108 | | /* ----- signed ----- */ |
| 12803 | /* signed */ |
| 10109 | 12804 | INT32 slhs = lhs; |
| 10110 | 12805 | INT32 srhs = rhs; |
| 10111 | 12806 | |
| r2762 | r2763 | |
| 10131 | 12826 | |
| 10132 | 12827 | case kSearchComparison_IncreasedBy: |
| 10133 | 12828 | svalue = search->value; |
| 12829 | |
| 10134 | 12830 | if(search->value & kSearchByteSignBitTable[search->bytes]) |
| 10135 | 12831 | svalue |= ~kSearchByteUnsignedMaskTable[search->bytes]; |
| 10136 | 12832 | |
| r2762 | r2763 | |
| 10142 | 12838 | } |
| 10143 | 12839 | else |
| 10144 | 12840 | { |
| 10145 | | /* ----- unsigned ----- */ |
| 12841 | /* unsigned */ |
| 10146 | 12842 | switch(search->comparison) |
| 10147 | 12843 | { |
| 10148 | 12844 | case kSearchComparison_LessThan: |
| r2762 | r2763 | |
| 10165 | 12861 | |
| 10166 | 12862 | case kSearchComparison_IncreasedBy: |
| 10167 | 12863 | svalue = search->value; |
| 12864 | |
| 10168 | 12865 | if(search->value & kSearchByteSignBitTable[search->bytes]) |
| 10169 | 12866 | svalue |= ~kSearchByteUnsignedMaskTable[search->bytes]; |
| 10170 | 12867 | |
| r2762 | r2763 | |
| 10178 | 12875 | return 0; |
| 10179 | 12876 | } |
| 10180 | 12877 | |
| 10181 | | /*----------------------------------------------------------------- |
| 10182 | | DoSearchComparisonBit - compare bit data and return it matched |
| 10183 | | -----------------------------------------------------------------*/ |
| 12878 | /*-------------------------------------------------------------------- |
| 12879 | do_search_comparison_bit - compare bit data and return it matched |
| 12880 | --------------------------------------------------------------------*/ |
| 10184 | 12881 | |
| 10185 | | static UINT32 DoSearchComparisonBit(SearchInfo * search, UINT32 lhs, UINT32 rhs) |
| 12882 | static UINT32 do_search_comparison_bit(search_info *search, UINT32 lhs, UINT32 rhs) |
| 10186 | 12883 | { |
| 10187 | 12884 | switch(search->comparison) |
| 10188 | 12885 | { |
| r2762 | r2763 | |
| 10202 | 12899 | return 0; |
| 10203 | 12900 | } |
| 10204 | 12901 | |
| 10205 | | /*---------------------- |
| 10206 | | IsRegionOffsetValid |
| 10207 | | ----------------------*/ |
| 12902 | /*---------------------------------------------- |
| 12903 | is_region_offset_valid - ????? unused ????? |
| 12904 | ----------------------------------------------*/ |
| 10208 | 12905 | |
| 10209 | | /* |
| 10210 | | static UINT8 IsRegionOffsetValid(SearchInfo * search, SearchRegion * region, UINT32 offset) |
| 12906 | #if 0 |
| 12907 | static UINT8 is_region_offset_valid(search_info *search, search_region *region, UINT32 offset) |
| 10211 | 12908 | { |
| 10212 | 12909 | switch(kSearchByteIncrementTable[search->bytes]) |
| 10213 | 12910 | { |
| r2762 | r2763 | |
| 10226 | 12923 | |
| 10227 | 12924 | return 0; |
| 10228 | 12925 | } |
| 10229 | | */ |
| 12926 | #endif |
| 10230 | 12927 | |
| 10231 | | /*---------------------------------------------------------- |
| 10232 | | IsRegionOffsetValidBit - check selected offset is valid |
| 10233 | | ----------------------------------------------------------*/ |
| 12928 | /*----------------------------------------------------- |
| 12929 | is_region_offset_valid_bit - check selected offset |
| 12930 | -----------------------------------------------------*/ |
| 10234 | 12931 | |
| 10235 | | static UINT8 IsRegionOffsetValidBit(SearchInfo * search, SearchRegion * region, UINT32 offset) |
| 12932 | static UINT8 is_region_offset_valid_bit(search_info *search, search_region *region, UINT32 offset) |
| 10236 | 12933 | { |
| 10237 | 12934 | switch(kSearchByteStep[search->bytes]) |
| 10238 | 12935 | { |
| r2762 | r2763 | |
| 10256 | 12953 | return 0; |
| 10257 | 12954 | } |
| 10258 | 12955 | |
| 10259 | | /*---------------------------------------------------------------- |
| 10260 | | InvalidateRegionOffset - remove unmatched offset after search |
| 10261 | | ----------------------------------------------------------------*/ |
| 12956 | /*------------------------------------------------------------------ |
| 12957 | invalidate_region_offset - remove unmatched offset after search |
| 12958 | ------------------------------------------------------------------*/ |
| 10262 | 12959 | |
| 10263 | | static void InvalidateRegionOffset(SearchInfo * search, SearchRegion * region, UINT32 offset) |
| 12960 | static void invalidate_region_offset(search_info *search, search_region *region, UINT32 offset) |
| 10264 | 12961 | { |
| 10265 | 12962 | switch(kSearchByteStep[search->bytes]) |
| 10266 | 12963 | { |
| r2762 | r2763 | |
| 10283 | 12980 | } |
| 10284 | 12981 | } |
| 10285 | 12982 | |
| 10286 | | /*----------------------------------------------------------------------- |
| 10287 | | InvalidateRegionOffsetBit - remove unmatched offset after bit search |
| 10288 | | -----------------------------------------------------------------------*/ |
| 12983 | /*-------------------------------------------------------------------------- |
| 12984 | invalidate_region_offset_bit - remove unmatched offset after bit search |
| 12985 | --------------------------------------------------------------------------*/ |
| 10289 | 12986 | |
| 10290 | | static void InvalidateRegionOffsetBit(SearchInfo * search, SearchRegion * region, UINT32 offset, UINT32 invalidate) |
| 12987 | static void invalidate_region_offset_bit(search_info *search, search_region *region, UINT32 offset, UINT32 invalidate) |
| 10291 | 12988 | { |
| 10292 | 12989 | switch(kSearchByteStep[search->bytes]) |
| 10293 | 12990 | { |
| r2762 | r2763 | |
| 10310 | 13007 | } |
| 10311 | 13008 | } |
| 10312 | 13009 | |
| 10313 | | /*-------------------------------------------------------------- |
| 10314 | | InvalidateEntireRegions - invalidate selected search region |
| 10315 | | --------------------------------------------------------------*/ |
| 13010 | /*---------------------------------------------------------------- |
| 13011 | invalidate_entire_regions - invalidate selected search region |
| 13012 | ----------------------------------------------------------------*/ |
| 10316 | 13013 | |
| 10317 | | static void InvalidateEntireRegion(SearchInfo * search, SearchRegion * region) |
| 13014 | static void invalidate_entire_region(search_info *search, search_region *region) |
| 10318 | 13015 | { |
| 10319 | 13016 | memset(region->status, 0, region->length); |
| 10320 | 13017 | |
| 10321 | | search->numResults -= region->numResults; |
| 10322 | | region->numResults = 0; |
| 13018 | search->num_results -= region->num_results; |
| 13019 | region->num_results = 0; |
| 10323 | 13020 | } |
| 10324 | 13021 | |
| 10325 | | /*------------------------------------------------------------------- |
| 10326 | | InitializeNewSearch - initialize search region to start a search |
| 10327 | | -------------------------------------------------------------------*/ |
| 13022 | /*--------------------------------------------------------------- |
| 13023 | init_new_search - initialize search region to start a search |
| 13024 | ---------------------------------------------------------------*/ |
| 10328 | 13025 | |
| 10329 | | static void InitializeNewSearch(SearchInfo * search) |
| 13026 | static void init_new_search(search_info *search) |
| 10330 | 13027 | { |
| 10331 | | int i; |
| 13028 | int i; |
| 10332 | 13029 | |
| 10333 | | search->numResults = 0; |
| 13030 | search->num_results = 0; |
| 10334 | 13031 | |
| 10335 | | for(i = 0; i < search->regionListLength; i++) |
| 13032 | for(i = 0; i < search->region_list_length; i++) |
| 10336 | 13033 | { |
| 10337 | | SearchRegion * region = &search->regionList[i]; |
| 13034 | search_region *region = &search->region_list[i]; |
| 10338 | 13035 | |
| 10339 | 13036 | if(region->flags & kRegionFlag_Enabled) |
| 10340 | 13037 | { |
| 10341 | | region->numResults = 0; |
| 13038 | region->num_results = 0; |
| 10342 | 13039 | |
| 10343 | 13040 | memset(region->status, 0xFF, region->length); |
| 10344 | 13041 | |
| 10345 | | FillBufferFromRegion(region, region->first); |
| 13042 | fill_buffer_from_region(region, region->first); |
| 10346 | 13043 | |
| 10347 | 13044 | memcpy(region->last, region->first, region->length); |
| 10348 | 13045 | } |
| 10349 | 13046 | } |
| 10350 | 13047 | } |
| 10351 | 13048 | |
| 10352 | | /*--------------------------------------------------------------------------- |
| 10353 | | UpdateSearch - updata a data in search region after initialize or search |
| 10354 | | ---------------------------------------------------------------------------*/ |
| 13049 | /*---------------------------------------------------------------------------- |
| 13050 | update_search - update a data in search region after initialize or search |
| 13051 | ----------------------------------------------------------------------------*/ |
| 10355 | 13052 | |
| 10356 | | static void UpdateSearch(SearchInfo * search) |
| 13053 | static void update_search(search_info *search) |
| 10357 | 13054 | { |
| 10358 | | int i; |
| 13055 | int i; |
| 10359 | 13056 | |
| 10360 | | for(i = 0; i < search->regionListLength; i++) |
| 13057 | for(i = 0; i < search->region_list_length; i++) |
| 10361 | 13058 | { |
| 10362 | | SearchRegion * region = &search->regionList[i]; |
| 13059 | search_region *region = &search->region_list[i]; |
| 10363 | 13060 | |
| 10364 | 13061 | if(region->flags & kRegionFlag_Enabled) |
| 10365 | | FillBufferFromRegion(region, region->last); |
| 13062 | fill_buffer_from_region(region, region->last); |
| 10366 | 13063 | } |
| 10367 | 13064 | } |
| 10368 | 13065 | |
| 10369 | | /*------------------------------------- |
| 10370 | | DoSearch - management for a search |
| 10371 | | -------------------------------------*/ |
| 13066 | /*--------------------------------------- |
| 13067 | do_search - cheat engine search core |
| 13068 | ---------------------------------------*/ |
| 10372 | 13069 | |
| 10373 | | static void DoSearch(SearchInfo * search) |
| 13070 | static void do_search(search_info *search) |
| 10374 | 13071 | { |
| 10375 | | int i, j; |
| 13072 | int i, j; |
| 10376 | 13073 | |
| 10377 | | search->numResults = 0; |
| 13074 | search->num_results = 0; |
| 10378 | 13075 | |
| 10379 | 13076 | if(search->bytes == kSearchSize_1Bit) |
| 10380 | 13077 | { |
| 10381 | | /* ----- bit search ----- */ |
| 10382 | | for(i = 0; i < search->regionListLength; i++) |
| 13078 | /* bit search */ |
| 13079 | for(i = 0; i < search->region_list_length; i++) |
| 10383 | 13080 | { |
| 10384 | | SearchRegion * region = &search->regionList[i]; |
| 10385 | | UINT32 lastAddress = region->length - kSearchByteIncrementTable[search->bytes] + 1; |
| 10386 | | UINT32 increment = kSearchByteStep[search->bytes]; |
| 13081 | search_region *region = &search->region_list[i]; |
| 13082 | UINT32 lastAddress = region->length - kSearchByteIncrementTable[search->bytes] + 1; |
| 13083 | UINT32 increment = kSearchByteStep[search->bytes]; |
| 10387 | 13084 | |
| 10388 | | region->numResults = 0; |
| 13085 | region->num_results = 0; |
| 10389 | 13086 | |
| 10390 | | if((region->length < kSearchByteIncrementTable[search->bytes]) || !region->flags & kRegionFlag_Enabled) |
| 13087 | if(region->length < kSearchByteIncrementTable[search->bytes] || (region->flags & kRegionFlag_Enabled) == 0) |
| 10391 | 13088 | continue; |
| 10392 | 13089 | |
| 10393 | 13090 | for(j = 0; j < lastAddress; j += increment) |
| r2762 | r2763 | |
| 10397 | 13094 | |
| 10398 | 13095 | address = region->address + j; |
| 10399 | 13096 | |
| 10400 | | if(IsRegionOffsetValidBit(search, region, j)) |
| 13097 | if(is_region_offset_valid_bit(search, region, j)) |
| 10401 | 13098 | { |
| 10402 | 13099 | UINT32 validBits; |
| 10403 | 13100 | |
| 10404 | | lhs = ReadSearchOperandBit(search->lhs, search, region, address); |
| 10405 | | rhs = ReadSearchOperandBit(search->rhs, search, region, address); |
| 13101 | lhs = read_search_operand_bit(search->lhs, search, region, address); |
| 13102 | rhs = read_search_operand_bit(search->rhs, search, region, address); |
| 10406 | 13103 | |
| 10407 | | /* ----- do search ----- */ |
| 10408 | | validBits = DoSearchComparisonBit(search, lhs, rhs); |
| 13104 | /* do bit search */ |
| 13105 | validBits = do_search_comparison_bit(search, lhs, rhs); |
| 10409 | 13106 | |
| 10410 | | InvalidateRegionOffsetBit(search, region, j, ~validBits); |
| 13107 | invalidate_region_offset_bit(search, region, j, ~validBits); |
| 10411 | 13108 | |
| 10412 | | if(IsRegionOffsetValidBit(search, region, j)) |
| 13109 | if(is_region_offset_valid_bit(search, region, j)) |
| 10413 | 13110 | { |
| 10414 | | search->numResults++; |
| 10415 | | region->numResults++; |
| 13111 | search->num_results++; |
| 13112 | region->num_results++; |
| 10416 | 13113 | } |
| 10417 | 13114 | } |
| 10418 | 13115 | } |
| r2762 | r2763 | |
| 10420 | 13117 | } |
| 10421 | 13118 | else |
| 10422 | 13119 | { |
| 10423 | | /* ----- normal search ----- */ |
| 10424 | | for(i = 0; i < search->regionListLength; i++) |
| 13120 | /* normal search */ |
| 13121 | for(i = 0; i < search->region_list_length; i++) |
| 10425 | 13122 | { |
| 10426 | | SearchRegion * region = &search->regionList[i]; |
| 10427 | | UINT32 lastAddress = region->length - kSearchByteIncrementTable[search->bytes] + 1; |
| 10428 | | UINT32 increment = kSearchByteStep[search->bytes]; |
| 13123 | search_region *region = &search->region_list[i]; |
| 13124 | UINT32 lastAddress = region->length - kSearchByteIncrementTable[search->bytes] + 1; |
| 13125 | UINT32 increment = kSearchByteStep[search->bytes]; |
| 10429 | 13126 | |
| 10430 | | region->numResults = 0; |
| 13127 | region->num_results = 0; |
| 10431 | 13128 | |
| 10432 | | if((region->length < kSearchByteIncrementTable[search->bytes]) || !region->flags & kRegionFlag_Enabled) |
| 13129 | if(region->length < kSearchByteIncrementTable[search->bytes] || (region->flags & kRegionFlag_Enabled) == 0) |
| 10433 | 13130 | continue; |
| 10434 | 13131 | |
| 10435 | 13132 | for(j = 0; j < lastAddress; j += increment) |
| r2762 | r2763 | |
| 10439 | 13136 | |
| 10440 | 13137 | address = region->address + j; |
| 10441 | 13138 | |
| 10442 | | if(IsRegionOffsetValid(search, region, j)) |
| 13139 | if(is_region_offset_valid(search, region, j)) |
| 10443 | 13140 | { |
| 10444 | | lhs = ReadSearchOperand(search->lhs, search, region, address); |
| 10445 | | rhs = ReadSearchOperand(search->rhs, search, region, address); |
| 13141 | lhs = read_search_operand(search->lhs, search, region, address); |
| 13142 | rhs = read_search_operand(search->rhs, search, region, address); |
| 10446 | 13143 | |
| 10447 | | /* ----- do search ----- */ |
| 10448 | | if(!DoSearchComparison(search, lhs, rhs)) |
| 10449 | | /* ----- unmatched ----- */ |
| 10450 | | InvalidateRegionOffset(search, region, j); |
| 13144 | /* do value search */ |
| 13145 | if(do_search_comparison(search, lhs, rhs) == 0) |
| 13146 | { |
| 13147 | /* unmatched */ |
| 13148 | invalidate_region_offset(search, region, j); |
| 13149 | } |
| 10451 | 13150 | else |
| 10452 | 13151 | { |
| 10453 | | /* ----- matched ----- */ |
| 10454 | | search->numResults++; |
| 10455 | | region->numResults++; |
| 13152 | /* matched */ |
| 13153 | search->num_results++; |
| 13154 | region->num_results++; |
| 10456 | 13155 | } |
| 10457 | 13156 | } |
| 10458 | 13157 | } |
| r2762 | r2763 | |
| 10460 | 13159 | } |
| 10461 | 13160 | } |
| 10462 | 13161 | |
| 10463 | | /*---------------------- |
| 10464 | | LookupHandlerMemory |
| 10465 | | ----------------------*/ |
| 13162 | /*----------------------------------------------------------- |
| 13163 | LookupHandlerMemory - search specified write handler |
| 13164 | -----------------------------------------------------------*/ |
| 10466 | 13165 | |
| 10467 | 13166 | static UINT8 ** LookupHandlerMemory(UINT8 cpu, UINT32 address, UINT32 * outRelativeAddress) |
| 10468 | 13167 | { |
| 10469 | | const address_map * map = memory_get_address_map(cpu, ADDRESS_SPACE_PROGRAM); |
| 10470 | | const address_map_entry *entry; |
| 13168 | const address_map * map = memory_get_address_map(cpu, ADDRESS_SPACE_PROGRAM); |
| 13169 | const address_map_entry *entry; |
| 10471 | 13170 | |
| 10472 | | for (entry = map->entrylist; entry != NULL; entry = entry->next) |
| 10473 | | if (entry->write.generic != NULL && (address >= entry->addrstart) && (address <= entry->addrend)) |
| 13171 | for(entry = map->entrylist; entry != NULL; entry = entry->next) |
| 13172 | { |
| 13173 | if(entry->write.generic != NULL && address >= entry->addrstart && address <= entry->addrend) |
| 10474 | 13174 | { |
| 10475 | 13175 | if(outRelativeAddress) |
| 13176 | { |
| 10476 | 13177 | *outRelativeAddress = address - entry->addrstart; |
| 10477 | | |
| 10478 | | return (UINT8 **)entry->baseptr; |
| 13178 | return (UINT8 **)entry->baseptr; |
| 13179 | } |
| 10479 | 13180 | } |
| 13181 | } |
| 10480 | 13182 | |
| 10481 | 13183 | return NULL; |
| 10482 | 13184 | } |
| 10483 | 13185 | |
| 10484 | | /*------------------------------------------ |
| 10485 | | DoCPURead - read a data from RAM region |
| 10486 | | ------------------------------------------*/ |
| 13186 | /*------------------------------------------------------------------------------------------------------------- |
| 13187 | GetMemoryRegionBasePointer - return base pointer to the base of RAM associated with given CPU and address |
| 13188 | -------------------------------------------------------------------------------------------------------------*/ |
| 10487 | 13189 | |
| 13190 | static UINT8 ** GetMemoryRegionBasePointer(UINT8 cpu, UINT8 space, UINT32 address) |
| 13191 | { |
| 13192 | UINT8 * buf = NULL; |
| 13193 | |
| 13194 | switch(space) |
| 13195 | { |
| 13196 | case kAddressSpace_DataSpace: |
| 13197 | buf = memory_get_read_ptr(cpu, ADDRESS_SPACE_DATA, address); |
| 13198 | break; |
| 13199 | |
| 13200 | case kAddressSpace_IOSpace: |
| 13201 | buf = memory_get_read_ptr(cpu, ADDRESS_SPACE_IO, address); |
| 13202 | break; |
| 13203 | |
| 13204 | case kAddressSpace_OpcodeRAM: |
| 13205 | buf = memory_get_op_ptr(cpu, address, 0); |
| 13206 | break; |
| 13207 | |
| 13208 | case kAddressSpace_DirectMemory: |
| 13209 | buf = memory_get_read_ptr(cpu, ADDRESS_SPACE_PROGRAM, address); |
| 13210 | break; |
| 13211 | |
| 13212 | default: |
| 13213 | logerror("invalid address space (%x)\n", space); |
| 13214 | } |
| 13215 | |
| 13216 | if(buf) buf -= address; |
| 13217 | |
| 13218 | //logerror("pointer (return) : %p\n", buf); |
| 13219 | |
| 13220 | return (UINT8 **)buf; |
| 13221 | } |
| 13222 | |
| 13223 | /*-------------------------------------------------------------------------------------------------------------- |
| 13224 | DoCPURead - read a data from standard CPU region |
| 13225 | NOTE : if a driver has cpu_spinutil(), reading a data via cpunum_read_byte may conflict with it |
| 13226 | --------------------------------------------------------------------------------------------------------------*/ |
| 13227 | |
| 10488 | 13228 | static UINT32 DoCPURead(UINT8 cpu, UINT32 address, UINT8 bytes, UINT8 swap) |
| 10489 | 13229 | { |
| 13230 | cpu_region_info *info = get_cpu_info(cpu); |
| 13231 | |
| 13232 | address = DoShift(address, info->address_shift); |
| 13233 | |
| 10490 | 13234 | switch(bytes) |
| 10491 | 13235 | { |
| 10492 | 13236 | case 1: |
| r2762 | r2763 | |
| 10521 | 13265 | return 0; |
| 10522 | 13266 | } |
| 10523 | 13267 | |
| 10524 | | /*----------------------------------------------------- |
| 10525 | | DoMemoryRead - read a data from ROM or User region |
| 10526 | | -----------------------------------------------------*/ |
| 13268 | /*-------------------------------------------------- |
| 13269 | DoMemoryRead - read a data from memory directly |
| 13270 | --------------------------------------------------*/ |
| 10527 | 13271 | |
| 10528 | | static UINT32 DoMemoryRead(UINT8 * buf, UINT32 address, UINT8 bytes, UINT8 swap, CPUInfo * info) |
| 13272 | static UINT32 DoMemoryRead(UINT8 * buf, UINT32 address, UINT8 bytes, UINT8 swap, cpu_region_info *info) |
| 10529 | 13273 | { |
| 10530 | | UINT32 data = 0; |
| 13274 | int i; |
| 13275 | int data = 0; |
| 10531 | 13276 | |
| 13277 | if(info) |
| 13278 | address = DoShift(address, info->address_shift); |
| 13279 | |
| 10532 | 13280 | if(!info) |
| 10533 | 13281 | { |
| 10534 | 13282 | switch(bytes) |
| r2762 | r2763 | |
| 10553 | 13301 | break; |
| 10554 | 13302 | |
| 10555 | 13303 | default: |
| 10556 | | info = &rawCPUInfo; |
| 13304 | info = &raw_cpu_info; |
| 10557 | 13305 | goto generic; |
| 10558 | 13306 | } |
| 10559 | 13307 | |
| r2762 | r2763 | |
| 10561 | 13309 | } |
| 10562 | 13310 | |
| 10563 | 13311 | generic: |
| 13312 | for(i = 0; i < bytes; i++) |
| 13313 | data |= swap ? buf[SwapAddress(address + i, bytes, info)] << (i * 8) : |
| 13314 | buf[SwapAddress(address + i, bytes, info)] << ((bytes - i - 1) * 8); |
| 10564 | 13315 | |
| 10565 | | if(swap) |
| 10566 | | { |
| 10567 | | UINT32 i; |
| 10568 | | |
| 10569 | | for(i = 0; i < bytes; i++) |
| 10570 | | data |= buf[SwapAddress(address + i, bytes, info)] << (i * 8); |
| 10571 | | } |
| 10572 | | else |
| 10573 | | { |
| 10574 | | UINT32 i; |
| 10575 | | |
| 10576 | | for(i = 0; i < bytes; i++) |
| 10577 | | data |= buf[SwapAddress(address + i, bytes, info)] << ((bytes - i - 1) * 8); |
| 10578 | | } |
| 10579 | | |
| 10580 | 13316 | return data; |
| 10581 | 13317 | } |
| 10582 | 13318 | |
| 10583 | | /*-------------------------------------------- |
| 10584 | | DoCPUWrite - write a data into RAM region |
| 10585 | | --------------------------------------------*/ |
| 13319 | /*----------------------------------------------------- |
| 13320 | DoCPUWrite - write a data into standard CPU region |
| 13321 | -----------------------------------------------------*/ |
| 10586 | 13322 | |
| 10587 | 13323 | static void DoCPUWrite(UINT32 data, UINT8 cpu, UINT32 address, UINT8 bytes, UINT8 swap) |
| 10588 | 13324 | { |
| 13325 | cpu_region_info *info = get_cpu_info(cpu); |
| 13326 | |
| 13327 | address = DoShift(address, info->address_shift); |
| 13328 | |
| 10589 | 13329 | switch(bytes) |
| 10590 | 13330 | { |
| 10591 | 13331 | case 1: |
| r2762 | r2763 | |
| 10643 | 13383 | } |
| 10644 | 13384 | } |
| 10645 | 13385 | |
| 10646 | | /*------------------------------------------------------- |
| 10647 | | DoMemoryWrite - write a data into ROM or User region |
| 10648 | | -------------------------------------------------------*/ |
| 13386 | /*---------------------------------------------------- |
| 13387 | DoMemoryWrite - write a data into memory directly |
| 13388 | ----------------------------------------------------*/ |
| 10649 | 13389 | |
| 10650 | | static void DoMemoryWrite(UINT32 data, UINT8 * buf, UINT32 address, UINT8 bytes, UINT8 swap, CPUInfo * info) |
| 13390 | static void DoMemoryWrite(UINT32 data, UINT8 * buf, UINT32 address, UINT8 bytes, UINT8 swap, cpu_region_info *info) |
| 10651 | 13391 | { |
| 13392 | UINT32 i; |
| 13393 | |
| 13394 | if(info) |
| 13395 | address = DoShift(address, info->address_shift); |
| 13396 | |
| 10652 | 13397 | if(!info) |
| 10653 | 13398 | { |
| 10654 | 13399 | switch(bytes) |
| r2762 | r2763 | |
| 10673 | 13418 | break; |
| 10674 | 13419 | |
| 10675 | 13420 | default: |
| 10676 | | info = &rawCPUInfo; |
| 13421 | info = &raw_cpu_info; |
| 10677 | 13422 | goto generic; |
| 10678 | 13423 | } |
| 10679 | 13424 | |
| r2762 | r2763 | |
| 10681 | 13426 | } |
| 10682 | 13427 | |
| 10683 | 13428 | generic: |
| 10684 | | |
| 10685 | | if(swap) |
| 13429 | for(i = 0; i < bytes; i++) |
| 10686 | 13430 | { |
| 10687 | | UINT32 i; |
| 10688 | | |
| 10689 | | for(i = 0; i < bytes; i++) |
| 10690 | | buf[SwapAddress(address + i, bytes, info)] = data >> (i * 8); |
| 13431 | if(swap) buf[SwapAddress(address + i, bytes, info)] = data >> (i * 8); |
| 13432 | else buf[SwapAddress(address + i, bytes, info)] = data >> ((bytes - i - 1) * 8); |
| 10691 | 13433 | } |
| 10692 | | else |
| 10693 | | { |
| 10694 | | UINT32 i; |
| 10695 | | |
| 10696 | | for(i = 0; i < bytes; i++) |
| 10697 | | buf[SwapAddress(address + i, bytes, info)] = data >> ((bytes - i - 1) * 8); |
| 10698 | | } |
| 10699 | 13434 | } |
| 10700 | 13435 | |
| 10701 | | /*-------------------------------- |
| 10702 | | CPUNeedsSwap - endian checker |
| 10703 | | --------------------------------*/ |
| 13436 | /*----------- |
| 13437 | ReadData |
| 13438 | -----------*/ |
| 10704 | 13439 | |
| 10705 | | static UINT8 CPUNeedsSwap(UINT8 cpu) |
| 13440 | static UINT32 ReadData(CheatAction * action) |
| 10706 | 13441 | { |
| 10707 | | return cpuInfoList[cpu].endianness ^ 1; |
| 10708 | | } |
| 13442 | UINT8 addressRead = EXTRACT_FIELD(action->type, AddressRead); |
| 13443 | UINT8 bytes = EXTRACT_FIELD(action->type, AddressSize) + 1; |
| 10709 | 13444 | |
| 10710 | | /*----------------------------------- |
| 10711 | | RegionNeedsSwap - endian checker |
| 10712 | | -----------------------------------*/ |
| 10713 | | |
| 10714 | | static UINT8 RegionNeedsSwap(UINT8 region) |
| 10715 | | { |
| 10716 | | CPUInfo * temp = GetRegionCPUInfo(region); |
| 10717 | | |
| 10718 | | if(temp) |
| 10719 | | return temp->endianness ^ 1; |
| 10720 | | |
| 10721 | | return 0; |
| 10722 | | } |
| 10723 | | |
| 10724 | | /*---------------------------------------------------- |
| 10725 | | GetCPUInfo - return CPU info for standard region |
| 10726 | | ----------------------------------------------------*/ |
| 10727 | | |
| 10728 | | static CPUInfo * GetCPUInfo(UINT8 cpu) |
| 10729 | | { |
| 10730 | | return &cpuInfoList[cpu]; |
| 10731 | | } |
| 10732 | | |
| 10733 | | /*------------------------------------------------- |
| 10734 | | GetRegionCPUInfo - return CPU info for regions |
| 10735 | | -------------------------------------------------*/ |
| 10736 | | |
| 10737 | | static CPUInfo * GetRegionCPUInfo(UINT8 region) |
| 10738 | | { |
| 10739 | | if((region >= REGION_INVALID) && (region < REGION_MAX)) |
| 10740 | | return ®ionInfoList[region - REGION_INVALID]; |
| 10741 | | |
| 10742 | | return NULL; |
| 10743 | | } |
| 10744 | | |
| 10745 | | /*-------------- |
| 10746 | | SwapAddress |
| 10747 | | --------------*/ |
| 10748 | | |
| 10749 | | static UINT32 SwapAddress(UINT32 address, UINT8 dataSize, CPUInfo * info) |
| 10750 | | { |
| 10751 | | switch(info->dataBits) |
| 13445 | if(addressRead != kReadFrom_Variable) |
| 10752 | 13446 | { |
| 10753 | | case 16: |
| 10754 | | if(info->endianness == CPU_IS_BE) |
| 10755 | | return BYTE_XOR_BE(address); |
| 10756 | | else |
| 10757 | | return BYTE_XOR_LE(address); |
| 13447 | /* read a data from memory */ |
| 13448 | int address = ~0; |
| 10758 | 13449 | |
| 10759 | | case 32: |
| 10760 | | if(info->endianness == CPU_IS_BE) |
| 10761 | | return BYTE4_XOR_BE(address); |
| 10762 | | else |
| 10763 | | return BYTE4_XOR_LE(address); |
| 10764 | | } |
| 13450 | if(addressRead == kReadFrom_Address) address = action->address; |
| 13451 | else if(addressRead == kReadFrom_Index) address = cheatVariable[action->address]; |
| 10765 | 13452 | |
| 10766 | | return address; |
| 10767 | | } |
| 10768 | | |
| 10769 | | /*------------------------------------ |
| 10770 | | ReadData - read a data per region |
| 10771 | | ------------------------------------*/ |
| 10772 | | |
| 10773 | | static UINT32 ReadData(CheatAction * action) |
| 10774 | | { |
| 10775 | | UINT8 parameter = EXTRACT_FIELD(action->type, LocationParameter); |
| 10776 | | UINT8 bytes = EXTRACT_FIELD(action->type, BytesUsed) + 1; |
| 10777 | | UINT8 swapBytes = EXTRACT_FIELD(action->type, Endianness); |
| 10778 | | |
| 10779 | | switch(EXTRACT_FIELD(action->type, LocationType)) |
| 10780 | | { |
| 10781 | | case kLocation_Standard: |
| 10782 | | return DoCPURead(parameter, action->address, bytes, CPUNeedsSwap(parameter) ^ swapBytes); |
| 10783 | | break; |
| 10784 | | |
| 10785 | | case kLocation_MemoryRegion: |
| 13453 | if(!TEST_FIELD(action->region, RegionFlag)) |
| 10786 | 13454 | { |
| 10787 | | int region = REGION_CPU1 + parameter; |
| 10788 | | UINT8 * buf = memory_region(region); |
| 13455 | /* read a data from CPU */ |
| 13456 | UINT8 cpu = EXTRACT_FIELD(action->region, CPUIndex); |
| 10789 | 13457 | |
| 10790 | | if(buf) |
| 13458 | switch(EXTRACT_FIELD(action->region, AddressSpace)) |
| 10791 | 13459 | { |
| 10792 | | if(TEST_FIELD(cheatOptions, Debug)) |
| 10793 | | { |
| 10794 | | if(ControlKeyPressed()) |
| 10795 | | ui_popup_time(1, "MR : %x : %p", region, buf); |
| 10796 | | } |
| 13460 | case kAddressSpace_Program: |
| 13461 | if(action->flags & kActionFlag_IndexAddress) |
| 13462 | { |
| 13463 | int indexAddress; |
| 10797 | 13464 | |
| 10798 | | if(IsAddressInRange(action, memory_region_length(region))) |
| 10799 | | return DoMemoryRead(buf, action->address, bytes, RegionNeedsSwap(region) ^ swapBytes, GetRegionCPUInfo(region)); |
| 10800 | | } |
| 10801 | | } |
| 10802 | | break; |
| 13465 | cpu_region_info *info = get_cpu_info(cpu); |
| 10803 | 13466 | |
| 10804 | | case kLocation_HandlerMemory: |
| 10805 | | { |
| 10806 | | UINT32 relativeAddress; |
| 10807 | | UINT8 ** buf; |
| 13467 | indexAddress = DoCPURead(cpu, address, EXTRACT_FIELD(action->type, IndexSize) + 1, cpu_needs_swap(cpu)); |
| 10808 | 13468 | |
| 10809 | | if(!action->cachedPointer) |
| 10810 | | action->cachedPointer = LookupHandlerMemory(parameter, action->address, &action->cachedOffset); |
| 13469 | if(info && info->address_shift) |
| 13470 | indexAddress = DoShift(indexAddress, info->address_shift); |
| 10811 | 13471 | |
| 10812 | | buf = action->cachedPointer; |
| 10813 | | relativeAddress = action->cachedOffset; |
| 13472 | if(indexAddress) |
| 13473 | { |
| 13474 | indexAddress += action->extendData; |
| 13475 | return DoCPURead(cpu, indexAddress, bytes, cpu_needs_swap(cpu)); |
| 13476 | } |
| 13477 | } |
| 13478 | else if(action->flags & kActionFlag_PDWWrite) |
| 13479 | { |
| 13480 | if(action->flags & kActionFlag_IsFirst) |
| 13481 | { |
| 13482 | address += bytes; |
| 13483 | bytes = EXTRACT_FIELD(action->type, IndexSize) + 1; |
| 13484 | action->flags &= ~kActionFlag_IsFirst; |
| 13485 | } |
| 13486 | else |
| 13487 | action->flags |= kActionFlag_IsFirst; |
| 10814 | 13488 | |
| 10815 | | if(buf && *buf) |
| 10816 | | return DoMemoryRead(*buf, relativeAddress, bytes, CPUNeedsSwap(parameter) ^ swapBytes, GetCPUInfo(parameter)); |
| 10817 | | } |
| 10818 | | break; |
| 13489 | return DoCPURead(cpu, address, bytes, cpu_needs_swap(cpu)); |
| 13490 | } |
| 13491 | else |
| 13492 | { |
| 13493 | return DoCPURead(cpu, address, bytes, cpu_needs_swap(cpu)); |
| 13494 | } |
| 13495 | break; |
| 10819 | 13496 | |
| 10820 | | case kLocation_IndirectIndexed: |
| 10821 | | { |
| 10822 | | UINT32 address; |
| 10823 | | INT32 offset = action->extendData; |
| 10824 | | UINT8 cpu = (parameter >> 2) & 0x7; |
| 10825 | | UINT8 addressBytes = (parameter & 0x3) + 1; |
| 10826 | | CPUInfo * info = GetCPUInfo(cpu); |
| 13497 | case kAddressSpace_DataSpace: |
| 13498 | case kAddressSpace_IOSpace: |
| 13499 | case kAddressSpace_OpcodeRAM: |
| 13500 | case kAddressSpace_DirectMemory: |
| 13501 | { |
| 13502 | UINT8 * buf; |
| 10827 | 13503 | |
| 10828 | | address = DoCPURead(cpu, action->address, addressBytes, CPUNeedsSwap(cpu) ^ swapBytes); |
| 13504 | action->cachedPointer = GetMemoryRegionBasePointer(cpu, EXTRACT_FIELD(action->type, AddressSpace), address); |
| 13505 | buf = (UINT8 *) action->cachedPointer; |
| 10829 | 13506 | |
| 10830 | | if(info) |
| 10831 | | address = DoShift(address, info->addressShift); |
| 13507 | if(buf) |
| 13508 | { |
| 13509 | if(action->flags && kActionFlag_PDWWrite) |
| 13510 | { |
| 13511 | if(action->flags & kActionFlag_IsFirst) |
| 13512 | { |
| 13513 | address += bytes; |
| 13514 | bytes = EXTRACT_FIELD(action->type, IndexSize) + 1; |
| 13515 | action->flags &= ~kActionFlag_IsFirst; |
| 13516 | } |
| 13517 | else |
| 13518 | action->flags |= kActionFlag_IsFirst; |
| 13519 | } |
| 10832 | 13520 | |
| 10833 | | if(address) |
| 10834 | | { |
| 10835 | | address += offset; |
| 13521 | return DoMemoryRead(buf, address, bytes, cpu_needs_swap(cpu), get_cpu_info(cpu)); |
| 13522 | } |
| 13523 | } |
| 13524 | break; |
| 10836 | 13525 | |
| 10837 | | return DoCPURead(cpu, address, bytes, CPUNeedsSwap(cpu) ^ swapBytes); |
| 10838 | | } |
| 10839 | | } |
| 10840 | | break; |
| 13526 | case kAddressSpace_MappedMemory: |
| 13527 | { |
| 13528 | int relativeAddress; |
| 13529 | UINT8 ** buf; |
| 10841 | 13530 | |
| 10842 | | case kLocation_ProgramSpace: |
| 10843 | | { |
| 10844 | | UINT8 * buf; |
| 13531 | action->cachedPointer = LookupHandlerMemory(cpu, address, &action->cachedOffset); |
| 13532 | buf = action->cachedPointer; |
| 13533 | relativeAddress = action->cachedOffset; |
| 10845 | 13534 | |
| 10846 | | memory_set_opbase(action->address); |
| 13535 | if(buf && *buf) |
| 13536 | { |
| 13537 | if(action->flags & kActionFlag_PDWWrite) |
| 13538 | { |
| 13539 | if(action->flags & kActionFlag_IsFirst) |
| 13540 | { |
| 13541 | relativeAddress += bytes; |
| 13542 | bytes = EXTRACT_FIELD(action->type, IndexSize) + 1; |
| 13543 | action->flags &= ~kActionFlag_IsFirst; |
| 13544 | } |
| 13545 | else |
| 13546 | action->flags |= kActionFlag_IsFirst; |
| 13547 | } |
| 10847 | 13548 | |
| 10848 | | buf = memory_get_op_ptr(parameter, action->address, 0); |
| 13549 | return DoMemoryRead(*buf, relativeAddress, bytes, cpu_needs_swap(cpu), get_cpu_info(cpu)); |
| 13550 | } |
| 13551 | } |
| 13552 | break; |
| 10849 | 13553 | |
| 10850 | | buf -= action->address; |
| 13554 | case kAddressSpace_EEPROM: |
| 13555 | { |
| 13556 | int length; |
| 13557 | UINT8 * buf; |
| 10851 | 13558 | |
| 10852 | | if(buf) |
| 10853 | | { |
| 10854 | | if(TEST_FIELD(cheatOptions, Debug)) |
| 10855 | | { |
| 10856 | | if(ControlKeyPressed()) |
| 10857 | | ui_popup_time(1,"PG : %x : %p", parameter, buf); |
| 10858 | | } |
| 13559 | buf = eeprom_get_data_pointer(&length); |
| 10859 | 13560 | |
| 10860 | | return DoMemoryRead(buf, action->address, bytes, CPUNeedsSwap(parameter) ^ swapBytes, GetCPUInfo(parameter)); |
| 13561 | if(IsAddressInRange(action, length)) |
| 13562 | { |
| 13563 | if(action->flags & kActionFlag_PDWWrite) |
| 13564 | { |
| 13565 | if(action->flags & kActionFlag_IsFirst) |
| 13566 | { |
| 13567 | address += bytes; |
| 13568 | bytes = EXTRACT_FIELD(action->type, IndexSize) + 1; |
| 13569 | action->flags &= ~kActionFlag_IsFirst; |
| 13570 | } |
| 13571 | else |
| 13572 | action->flags |= kActionFlag_IsFirst; |
| 13573 | } |
| 13574 | |
| 13575 | return DoMemoryRead(buf, address, bytes, 0, &raw_cpu_info); |
| 13576 | } |
| 13577 | } |
| 13578 | break; |
| 10861 | 13579 | } |
| 10862 | 13580 | } |
| 10863 | | break; |
| 13581 | else |
| 13582 | { |
| 13583 | /* read a data from region */ |
| 13584 | UINT8 * buf = memory_region(action->region); |
| 10864 | 13585 | |
| 10865 | | case kLocation_Custom: |
| 10866 | | { |
| 10867 | | switch(parameter) |
| 13586 | if(buf && IsAddressInRange(action, memory_region_length(action->region))) |
| 10868 | 13587 | { |
| 10869 | | case kCustomLocation_Comment: |
| 10870 | | break; |
| 10871 | | |
| 10872 | | case kCustomLocation_EEPROM: |
| 13588 | if(action->flags & kActionFlag_PDWWrite) |
| 10873 | 13589 | { |
| 10874 | | int length; |
| 10875 | | UINT8 * buf; |
| 13590 | if(action->flags & kActionFlag_IsFirst) |
| 13591 | { |
| 13592 | address += bytes; |
| 13593 | bytes = EXTRACT_FIELD(action->type, IndexSize) + 1; |
| 13594 | action->flags &= ~kActionFlag_IsFirst; |
| 13595 | } |
| 13596 | else |
| 13597 | action->flags |= kActionFlag_IsFirst; |
| 10876 | 13598 | |
| 10877 | | buf = EEPROM_get_data_pointer(&length); |
| 10878 | | |
| 10879 | | if(IsAddressInRange(action, length)) |
| 10880 | | return DoMemoryRead(buf, action->address, bytes, swapBytes, &rawCPUInfo); |
| 13599 | return DoMemoryRead(buf, address, bytes, region_needs_swap(action->region), get_region_info(action->region)); |
| 10881 | 13600 | } |
| 10882 | | break; |
| 13601 | else |
| 13602 | return DoMemoryRead(buf, address, bytes, region_needs_swap(action->region), get_region_info(action->region)); |
| 10883 | 13603 | } |
| 10884 | 13604 | } |
| 10885 | | break; |
| 10886 | | |
| 10887 | | default: |
| 10888 | | break; |
| 10889 | 13605 | } |
| 13606 | else |
| 13607 | /* read a data from variable */ |
| 13608 | return (cheatVariable[action->address] & kCheatSizeMaskTable[EXTRACT_FIELD(action->type, AddressSize)]); |
| 10890 | 13609 | |
| 10891 | 13610 | return 0; |
| 10892 | 13611 | } |
| 10893 | 13612 | |
| 10894 | | /*-------------------------------------- |
| 10895 | | WriteData - write a data per region |
| 10896 | | --------------------------------------*/ |
| 13613 | /*------------------------------------- |
| 13614 | WriteData - write a data to memory |
| 13615 | -------------------------------------*/ |
| 10897 | 13616 | |
| 10898 | 13617 | static void WriteData(CheatAction * action, UINT32 data) |
| 10899 | 13618 | { |
| 10900 | | UINT8 parameter = EXTRACT_FIELD(action->type, LocationParameter); |
| 10901 | | UINT8 bytes = EXTRACT_FIELD(action->type, BytesUsed) + 1; |
| 10902 | | UINT8 swapBytes = EXTRACT_FIELD(action->type, Endianness); |
| 13619 | UINT8 addressRead = EXTRACT_FIELD(action->type, AddressRead); |
| 13620 | UINT8 bytes = EXTRACT_FIELD(action->type, AddressSize) + 1; |
| 10903 | 13621 | |
| 10904 | | switch(EXTRACT_FIELD(action->type, LocationType)) |
| 13622 | if(EXTRACT_FIELD(action->type, AddressRead) != kReadFrom_Variable) |
| 10905 | 13623 | { |
| 10906 | | case kLocation_Standard: |
| 10907 | | DoCPUWrite(data, parameter, action->address, bytes, CPUNeedsSwap(parameter) ^ swapBytes); |
| 13624 | /* write a data to memory */ |
| 13625 | int address = ~0; |
| 10908 | 13626 | |
| 10909 | | break; |
| 13627 | if(addressRead == kReadFrom_Address) address = action->address; |
| 13628 | else if(addressRead == kReadFrom_Index) address = cheatVariable[action->address]; |
| 10910 | 13629 | |
| 10911 | | case kLocation_MemoryRegion: |
| 13630 | if(!TEST_FIELD(action->region, RegionFlag)) |
| 10912 | 13631 | { |
| 10913 | | int region = REGION_CPU1 + parameter; |
| 10914 | | UINT8 * buf = memory_region(region); |
| 13632 | UINT8 cpu = EXTRACT_FIELD(action->region, CPUIndex); |
| 10915 | 13633 | |
| 10916 | | if(buf) |
| 13634 | switch(EXTRACT_FIELD(action->region, AddressSpace)) |
| 10917 | 13635 | { |
| 10918 | | if(IsAddressInRange(action, memory_region_length(region))) |
| 10919 | | DoMemoryWrite(data, buf, action->address, bytes, RegionNeedsSwap(region) ^ swapBytes, GetRegionCPUInfo(region)); |
| 10920 | | } |
| 10921 | | } |
| 10922 | | break; |
| 13636 | case kAddressSpace_Program: |
| 13637 | if(action->flags & kActionFlag_IndexAddress) |
| 13638 | { |
| 13639 | int indexAddress; |
| 10923 | 13640 | |
| 10924 | | case kLocation_HandlerMemory: |
| 10925 | | { |
| 10926 | | UINT32 relativeAddress; |
| 10927 | | UINT8 ** buf; |
| 13641 | cpu_region_info *info = get_cpu_info(cpu); |
| 10928 | 13642 | |
| 10929 | | if(!action->cachedPointer) |
| 10930 | | { |
| 10931 | | action->cachedPointer = LookupHandlerMemory(parameter, action->address, &action->cachedOffset); |
| 10932 | | } |
| 13643 | indexAddress = DoCPURead(cpu, address, EXTRACT_FIELD(action->type, IndexSize) + 1, cpu_needs_swap(cpu)); |
| 10933 | 13644 | |
| 10934 | | buf = action->cachedPointer; |
| 10935 | | relativeAddress = action->cachedOffset; |
| 13645 | if(info && info->address_shift) |
| 13646 | indexAddress = DoShift(indexAddress, info->address_shift); |
| 10936 | 13647 | |
| 10937 | | if(buf && *buf) |
| 10938 | | DoMemoryWrite(data, *buf, relativeAddress, bytes, CPUNeedsSwap(parameter) ^ swapBytes, GetCPUInfo(parameter)); |
| 10939 | | } |
| 10940 | | break; |
| 13648 | if(indexAddress) |
| 13649 | { |
| 13650 | indexAddress += action->extendData; |
| 13651 | DoCPUWrite(data, cpu, indexAddress, bytes, cpu_needs_swap(cpu)); |
| 13652 | } |
| 13653 | } |
| 13654 | else if(action->flags & kActionFlag_PDWWrite) |
| 13655 | { |
| 13656 | if(action->flags & kActionFlag_IsFirst) |
| 13657 | { |
| 13658 | address += bytes; |
| 13659 | bytes = EXTRACT_FIELD(action->type, IndexSize) + 1; |
| 13660 | action->flags &= ~kActionFlag_IsFirst; |
| 13661 | } |
| 13662 | else |
| 13663 | action->flags |= kActionFlag_IsFirst; |
| 10941 | 13664 | |
| 10942 | | case kLocation_IndirectIndexed: |
| 10943 | | { |
| 10944 | | UINT32 address; |
| 10945 | | INT32 offset = action->extendData; |
| 10946 | | UINT8 cpu = (parameter >> 2) & 0x7; |
| 10947 | | UINT8 addressBytes = (parameter & 0x3) + 1; |
| 10948 | | CPUInfo * info = GetCPUInfo(cpu); |
| 13665 | DoCPUWrite(data, cpu, address, bytes, cpu_needs_swap(cpu)); |
| 13666 | } |
| 13667 | else |
| 13668 | { |
| 13669 | DoCPUWrite(data, cpu, address, bytes, cpu_needs_swap(cpu)); |
| 13670 | } |
| 13671 | break; |
| 10949 | 13672 | |
| 10950 | | address = DoCPURead(cpu, action->address, addressBytes, CPUNeedsSwap(cpu) ^ swapBytes); |
| 13673 | case kAddressSpace_DataSpace: |
| 13674 | case kAddressSpace_IOSpace: |
| 13675 | case kAddressSpace_OpcodeRAM: |
| 13676 | case kAddressSpace_DirectMemory: |
| 13677 | { |
| 13678 | UINT8 * buf; |
| 10951 | 13679 | |
| 10952 | | if(info) |
| 10953 | | address = DoShift(address, info->addressShift); |
| 13680 | action->cachedPointer = GetMemoryRegionBasePointer(cpu, EXTRACT_FIELD(action->type, AddressSpace), address); |
| 13681 | buf = (UINT8 *) action->cachedPointer; |
| 10954 | 13682 | |
| 10955 | | if(address) |
| 10956 | | { |
| 10957 | | address += offset; |
| 13683 | if(buf) |
| 13684 | { |
| 13685 | if(action->flags & kActionFlag_PDWWrite) |
| 13686 | { |
| 13687 | if(action->flags & kActionFlag_IsFirst) |
| 13688 | { |
| 13689 | address += bytes; |
| 13690 | bytes = EXTRACT_FIELD(action->type, IndexSize) + 1; |
| 13691 | action->flags &= ~kActionFlag_IsFirst; |
| 13692 | } |
| 13693 | else |
| 13694 | action->flags |= kActionFlag_IsFirst; |
| 13695 | } |
| 10958 | 13696 | |
| 10959 | | DoCPUWrite(data, cpu, address, bytes, CPUNeedsSwap(cpu) ^ swapBytes); |
| 10960 | | } |
| 10961 | | } |
| 10962 | | break; |
| 13697 | DoMemoryWrite(data, buf, address, bytes, cpu_needs_swap(cpu), get_cpu_info(cpu)); |
| 13698 | } |
| 13699 | } |
| 13700 | break; |
| 10963 | 13701 | |
| 10964 | | case kLocation_ProgramSpace: |
| 10965 | | { |
| 10966 | | UINT8 * buf; |
| 13702 | case kAddressSpace_MappedMemory: |
| 13703 | { |
| 13704 | int relativeAddress; |
| 13705 | UINT8 ** buf; |
| 10967 | 13706 | |
| 10968 | | memory_set_opbase(action->address); |
| 13707 | action->cachedPointer = LookupHandlerMemory(cpu, address, &action->cachedOffset); |
| 13708 | buf = action->cachedPointer; |
| 13709 | relativeAddress = action->cachedOffset; |
| 10969 | 13710 | |
| 10970 | | buf = memory_get_op_ptr(parameter, action->address, 0); |
| 13711 | if(buf && *buf) |
| 13712 | { |
| 13713 | if(action->flags & kActionFlag_PDWWrite) |
| 13714 | { |
| 13715 | if(action->flags & kActionFlag_IsFirst) |
| 13716 | { |
| 13717 | relativeAddress += bytes; |
| 13718 | bytes = EXTRACT_FIELD(action->type, IndexSize) + 1; |
| 13719 | action->flags &= ~kActionFlag_IsFirst; |
| 13720 | } |
| 13721 | else |
| 13722 | action->flags |= kActionFlag_IsFirst; |
| 13723 | } |
| 10971 | 13724 | |
| 10972 | | buf -= action->address; |
| 13725 | DoMemoryWrite(data, *buf, relativeAddress, bytes, cpu_needs_swap(cpu), get_cpu_info(cpu)); |
| 13726 | return; |
| 13727 | } |
| 13728 | } |
| 13729 | break; |
| 10973 | 13730 | |
| 10974 | | if(buf) |
| 10975 | | DoMemoryWrite(data, buf, action->address, bytes, CPUNeedsSwap(parameter) ^ swapBytes, GetCPUInfo(parameter)); |
| 13731 | case kAddressSpace_EEPROM: |
| 13732 | { |
| 13733 | int length; |
| 13734 | UINT8 * buf; |
| 13735 | |
| 13736 | buf = eeprom_get_data_pointer(&length); |
| 13737 | |
| 13738 | if(IsAddressInRange(action, length)) |
| 13739 | { |
| 13740 | if(action->flags & kActionFlag_PDWWrite) |
| 13741 | { |
| 13742 | if(action->flags & kActionFlag_IsFirst) |
| 13743 | { |
| 13744 | address += bytes; |
| 13745 | bytes = EXTRACT_FIELD(action->type, IndexSize) + 1; |
| 13746 | action->flags &= ~kActionFlag_IsFirst; |
| 13747 | } |
| 13748 | else |
| 13749 | action->flags |= kActionFlag_IsFirst; |
| 13750 | } |
| 13751 | |
| 13752 | DoMemoryWrite(data, buf, address, bytes, 0, &raw_cpu_info); |
| 13753 | return; |
| 13754 | } |
| 13755 | } |
| 13756 | break; |
| 13757 | } |
| 10976 | 13758 | } |
| 10977 | | break; |
| 13759 | else |
| 13760 | { |
| 13761 | /* write a data into region */ |
| 13762 | UINT8 * buf = memory_region(action->region); |
| 10978 | 13763 | |
| 10979 | | case kLocation_Custom: |
| 10980 | | { |
| 10981 | | switch(parameter) |
| 13764 | if(buf && IsAddressInRange(action, memory_region_length(action->region))) |
| 10982 | 13765 | { |
| 10983 | | case kCustomLocation_Comment: |
| 10984 | | break; |
| 10985 | | |
| 10986 | | case kCustomLocation_EEPROM: |
| 13766 | if(action->flags & kActionFlag_PDWWrite) |
| 10987 | 13767 | { |
| 10988 | | int length; |
| 10989 | | UINT8 * buf; |
| 13768 | if(action->flags & kActionFlag_IsFirst) |
| 13769 | { |
| 13770 | address += bytes; |
| 13771 | bytes = EXTRACT_FIELD(action->type, IndexSize) + 1; |
| 13772 | action->flags &= ~kActionFlag_IsFirst; |
| 13773 | } |
| 13774 | else |
| 13775 | action->flags |= kActionFlag_IsFirst; |
| 13776 | } |
| 10990 | 13777 | |
| 10991 | | buf = EEPROM_get_data_pointer(&length); |
| 10992 | | |
| 10993 | | if(IsAddressInRange(action, length)) |
| 10994 | | DoMemoryWrite(data, buf, action->address, bytes, swapBytes, &rawCPUInfo); |
| 10995 | | } |
| 10996 | | break; |
| 13778 | DoMemoryWrite(data, buf, address, bytes, region_needs_swap(action->region), get_region_info(action->region)); |
| 13779 | return; |
| 10997 | 13780 | } |
| 10998 | 13781 | } |
| 10999 | | break; |
| 11000 | | |
| 11001 | | default: |
| 11002 | | break; |
| 11003 | 13782 | } |
| 13783 | else |
| 13784 | cheatVariable[action->address] = data & kCheatSizeMaskTable[EXTRACT_FIELD(action->type, AddressSize)]; |
| 11004 | 13785 | } |
| 11005 | 13786 | |
| 11006 | | /*----------------------------------------------------- |
| 11007 | | WatchCheatEntry - set watchpoint from action entry |
| 11008 | | -----------------------------------------------------*/ |
| 13787 | /*------------------------------------------------------------------------------------ |
| 13788 | WatchCheatEntry - set watchpoint when watch value key is pressed in several menus |
| 13789 | ------------------------------------------------------------------------------------*/ |
| 11009 | 13790 | |
| 11010 | 13791 | static void WatchCheatEntry(CheatEntry * entry, UINT8 associate) |
| 11011 | 13792 | { |
| 11012 | | UINT32 i, j; |
| 13793 | int i, j; |
| 11013 | 13794 | CheatEntry * associateEntry = NULL; |
| 11014 | 13795 | |
| 13796 | /* NOTE : calling with associate = 1 doesn't exist right now */ |
| 11015 | 13797 | if(associate) |
| 11016 | 13798 | associateEntry = entry; |
| 11017 | 13799 | |
| 11018 | 13800 | if(!entry) |
| 13801 | { |
| 13802 | messageType = kCheatMessage_FailedToAdd; |
| 13803 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 11019 | 13804 | return; |
| 13805 | } |
| 11020 | 13806 | |
| 11021 | 13807 | for(i = 0; i < entry->actionListLength; i++) |
| 11022 | 13808 | { |
| 11023 | | if(!i) |
| 11024 | | /* ----- first action entry ----- */ |
| 11025 | | AddActionWatch(&entry->actionList[i], associateEntry); |
| 11026 | | else |
| 13809 | CheatAction * action = &entry->actionList[i]; |
| 13810 | |
| 13811 | if(!(action->flags & kActionFlag_NoAction) && !EXTRACT_FIELD(action->type, AddressRead)) |
| 11027 | 13812 | { |
| 11028 | | /* ----- 2nd or later action entry ----- */ |
| 11029 | | UINT8 sameAddress = 0; |
| 13813 | /* NOTE : unsupported the watchpoint for indirect index right now */ |
| 13814 | if((action->flags & kActionFlag_IndexAddress) && action->extendData != ~0) |
| 13815 | continue; |
| 11030 | 13816 | |
| 11031 | | for(j = 0; j < i; j++) |
| 13817 | if(!i) |
| 11032 | 13818 | { |
| 11033 | | /* ----- if we find the same address action entry, skip it ----- */ |
| 11034 | | if(entry->actionList[j].address == entry->actionList[i].address) |
| 11035 | | sameAddress = 1; |
| 13819 | /* first CheatAction */ |
| 13820 | AddActionWatch(&entry->actionList[i], associateEntry); |
| 11036 | 13821 | } |
| 13822 | else |
| 13823 | { |
| 13824 | /* 2nd or later CheatAction */ |
| 13825 | UINT8 differentAddress = 1; |
| 11037 | 13826 | |
| 11038 | | if(!sameAddress) |
| 11039 | | AddActionWatch(&entry->actionList[i], associateEntry); |
| 13827 | for(j = 0; j < i; j++) |
| 13828 | { |
| 13829 | /* if we find the same address CheatAction, skip it */ |
| 13830 | if(entry->actionList[j].address == entry->actionList[i].address) |
| 13831 | differentAddress = 0; |
| 13832 | } |
| 13833 | |
| 13834 | if(differentAddress) |
| 13835 | AddActionWatch(&entry->actionList[i], associateEntry); |
| 13836 | } |
| 11040 | 13837 | } |
| 11041 | 13838 | } |
| 13839 | |
| 13840 | messageType = kCheatMessage_SucceededToAdd; |
| 13841 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 11042 | 13842 | } |
| 11043 | 13843 | |
| 11044 | | /*-------------------------------------------------- |
| 11045 | | AddActionWatch - add watchpoint into watch list |
| 11046 | | --------------------------------------------------*/ |
| 13844 | /*----------------------------------------------------------------------- |
| 13845 | AddActionWatch - set watchpoint parameters into WatchInfo. |
| 13846 | called from WatchCheatEntry() when watch value key |
| 13847 | or ActivateCheat() via watchpoint code. |
| 13848 | -----------------------------------------------------------------------*/ |
| 11047 | 13849 | |
| 11048 | 13850 | static void AddActionWatch(CheatAction * action, CheatEntry * entry) |
| 11049 | 13851 | { |
| 11050 | | if( (EXTRACT_FIELD(action->type, LocationType) == kLocation_Standard) || |
| 11051 | | (EXTRACT_FIELD(action->type, LocationType) == kLocation_MemoryRegion) || |
| 11052 | | (EXTRACT_FIELD(action->type, LocationType) == kLocation_IndirectIndexed) || |
| 11053 | | (EXTRACT_FIELD(action->type, LocationType) == kLocation_ProgramSpace)) |
| 11054 | | |
| 13852 | switch(EXTRACT_FIELD(action->type, CodeType)) |
| 11055 | 13853 | { |
| 11056 | | WatchInfo * info = GetUnusedWatch(); |
| 13854 | case kCodeType_Write: |
| 13855 | case kCodeType_PDWWrite: |
| 13856 | case kCodeType_RWrite: |
| 13857 | case kCodeType_IWrite: |
| 13858 | case kCodeType_CWrite: |
| 13859 | case kCodeType_VWrite: |
| 13860 | case kCodeType_VRWrite: |
| 13861 | case kCodeType_Branch: |
| 13862 | case kCodeType_Move: |
| 13863 | case kCodeType_Loop: |
| 13864 | case kCodeType_Popup: |
| 13865 | { |
| 13866 | WatchInfo * info = GetUnusedWatch(); |
| 11057 | 13867 | |
| 11058 | | info->address = action->address; |
| 11059 | | info->cpu = EXTRACT_FIELD(action->type, LocationParameter); |
| 11060 | | info->displayType = kWatchDisplayType_Hex; |
| 11061 | | info->elementBytes = kByteConversionTable[EXTRACT_FIELD(action->type, BytesUsed)]; |
| 11062 | | info->label[0] = 0; |
| 11063 | | info->labelType = kWatchLabel_None; |
| 11064 | | info->linkedCheat = entry; |
| 11065 | | info->numElements = 1; |
| 11066 | | info->skip = 0; |
| 13868 | info->address = action->address; |
| 13869 | info->cpu = action->region; |
| 13870 | info->displayType = kWatchDisplayType_Hex; |
| 13871 | info->elementBytes = kSearchSize_8Bit; |
| 13872 | info->label[0] = 0; |
| 13873 | info->labelType = kWatchLabel_None; |
| 13874 | info->numElements = EXTRACT_FIELD(action->type, AddressSize) + 1; |
| 13875 | info->linkedCheat = entry; |
| 13876 | info->skip = 0; |
| 11067 | 13877 | |
| 11068 | | info->locationType = EXTRACT_FIELD(action->type, LocationType); |
| 13878 | if(action->flags & kActionFlag_PDWWrite) |
| 13879 | { |
| 13880 | info->numElements += (EXTRACT_FIELD(action->type, IndexSize) + 1); |
| 13881 | } |
| 13882 | else if(action->flags & kActionFlag_Repeat) |
| 13883 | { |
| 13884 | info->numElements = EXTRACT_FIELD(action->extendData, LSB16); |
| 13885 | info->skip = EXTRACT_FIELD(action->extendData, MSB16) - 1; |
| 13886 | } |
| 13887 | } |
| 13888 | break; |
| 11069 | 13889 | |
| 11070 | | if(EXTRACT_FIELD(action->type, Type) == kType_Watch) |
| 11071 | | { |
| 11072 | | /* ----- set watchpoint from watch code ----- */ |
| 11073 | | UINT32 typeParameter = EXTRACT_FIELD(action->type, TypeParameter); |
| 13890 | case kCodeType_Watch: |
| 13891 | { |
| 13892 | WatchInfo * info = GetUnusedWatch(); |
| 11074 | 13893 | |
| 11075 | | info->numElements = (action->data & 0xFF) + 1; |
| 13894 | info->address = action->address; |
| 13895 | info->cpu = EXTRACT_FIELD(action->type, CPURegion); |
| 13896 | info->displayType = EXTRACT_FIELD(action->type, WatchDisplayFormat); |
| 13897 | info->elementBytes = kByteConversionTable[EXTRACT_FIELD(action->type, AddressSize)]; |
| 13898 | info->label[0] = 0; |
| 13899 | info->linkedCheat = entry; |
| 13900 | info->numElements = EXTRACT_FIELD(action->data, WatchNumElements) + 1; |
| 13901 | info->skip = EXTRACT_FIELD(action->data, WatchSkip); |
| 13902 | info->elementsPerLine = EXTRACT_FIELD(action->data, WatchElementsPerLine); |
| 13903 | info->addValue = EXTRACT_FIELD(action->data, WatchAddValue); |
| 11076 | 13904 | |
| 11077 | | info->skip = (action->data >> 8) & 0xFF; |
| 11078 | | info->elementsPerLine = (action->data >> 16) & 0xFF; |
| 11079 | | info->addValue = (action->data >> 24) & 0xFF; |
| 13905 | if(info->addValue & 0x80) |
| 13906 | info->addValue |= ~0xFF; |
| 11080 | 13907 | |
| 11081 | | if(info->addValue & 0x80) |
| 11082 | | info->addValue |= ~0xFF; |
| 13908 | if(action->extendData != ~0) |
| 13909 | { |
| 13910 | /* ### fix me... ### */ |
| 13911 | info->x = (float)(EXTRACT_FIELD(action->extendData, LSB16)) / 100; |
| 13912 | info->y = (float)(EXTRACT_FIELD(action->extendData, MSB16)) / 100; |
| 13913 | } |
| 11083 | 13914 | |
| 11084 | | if(action->extendData != 0xFFFFFFFF) |
| 11085 | | { |
| 11086 | | /* ### fix me... ### */ |
| 11087 | | info->x = (float)((action->extendData >> 16) & 0xFFFF)/100; |
| 11088 | | info->y = (float)((action->extendData >> 0) & 0xFFFF)/100; |
| 13915 | if(TEST_FIELD(action->type, WatchShowLabel) && entry->comment && strlen(entry->comment) < 256) |
| 13916 | { |
| 13917 | info->labelType = kWatchLabel_String; |
| 13918 | strcpy(info->label, entry->comment); |
| 13919 | } |
| 13920 | else |
| 13921 | info->labelType = kWatchLabel_None; |
| 11089 | 13922 | } |
| 11090 | | |
| 11091 | | /* ----- if label is needed, copy the description from comment field ----- */ |
| 11092 | | if((typeParameter & 0x04) && (entry->comment) && (strlen(entry->comment) < 256)) |
| 11093 | | { |
| 11094 | | info->labelType = kWatchLabel_String; |
| 11095 | | strcpy(info->label, entry->comment); |
| 11096 | | } |
| 11097 | | |
| 11098 | | info->displayType = typeParameter & 0x03; |
| 11099 | | } |
| 13923 | break; |
| 11100 | 13924 | } |
| 11101 | 13925 | } |
| 11102 | 13926 | |
| 11103 | | /*----------------------------------------------------------------- |
| 11104 | | RemoveAssociatedWatches - remove watchpoint when CODE is "OFF" |
| 11105 | | -----------------------------------------------------------------*/ |
| 13927 | /*------------------------------------------------------------------------------ |
| 13928 | RemoveAssociatedWatches - delete watchpoints when watchpoint code is "OFF". |
| 13929 | called from DeactivateCheat(). |
| 13930 | ------------------------------------------------------------------------------*/ |
| 11106 | 13931 | |
| 11107 | 13932 | static void RemoveAssociatedWatches(CheatEntry * entry) |
| 11108 | 13933 | { |
| 11109 | | int i; |
| 13934 | int i; |
| 11110 | 13935 | |
| 11111 | 13936 | for(i = watchListLength - 1; i >= 0; i--) |
| 11112 | 13937 | { |
| 11113 | | WatchInfo * info = &watchList[i]; |
| 13938 | WatchInfo * info = &watchList[i]; |
| 11114 | 13939 | |
| 11115 | 13940 | if(info->linkedCheat == entry) |
| 11116 | 13941 | DeleteWatchAt(i); |
| 11117 | 13942 | } |
| 11118 | 13943 | } |
| 11119 | 13944 | |
| 11120 | | /*---------------------------------------------------------------------- |
| 11121 | | ResetAction - back up data and set action flags when turn CODE "ON" |
| 11122 | | ----------------------------------------------------------------------*/ |
| 13945 | /*-------------------------------------------------- |
| 13946 | ResetAction - back up data and set action flags |
| 13947 | --------------------------------------------------*/ |
| 11123 | 13948 | |
| 11124 | 13949 | static void ResetAction(CheatAction * action) |
| 11125 | 13950 | { |
| 11126 | | action->frameTimer = 0; |
| 13951 | if(action->flags & kActionFlag_NoAction) |
| 13952 | return; |
| 11127 | 13953 | |
| 11128 | | /* ----- backup value ----- */ |
| 13954 | /* back up a value */ |
| 11129 | 13955 | if(!(action->flags & kActionFlag_LastValueGood)) |
| 11130 | | action->lastValue = ReadData(action); |
| 13956 | { |
| 13957 | switch(EXTRACT_FIELD(action->type, CodeType)) |
| 13958 | { |
| 13959 | default: |
| 13960 | action->lastValue = malloc_or_die(sizeof(action->lastValue)); |
| 13961 | action->lastValue[0] = ReadData(action); |
| 13962 | break; |
| 11131 | 13963 | |
| 13964 | case kCodeType_PDWWrite: |
| 13965 | action->lastValue = malloc_or_die(sizeof(action->lastValue) * 2); |
| 13966 | action->lastValue[0] = ReadData(action); |
| 13967 | action->lastValue[1] = ReadData(action); |
| 13968 | break; |
| 13969 | |
| 13970 | case kCodeType_RWrite: |
| 13971 | case kCodeType_VRWrite: |
| 13972 | { |
| 13973 | int i; |
| 13974 | |
| 13975 | for(i = 0; i < EXTRACT_FIELD(action->extendData, LSB16); i++) |
| 13976 | { |
| 13977 | action->lastValue = realloc(action->lastValue, sizeof(action->lastValue) * EXTRACT_FIELD(action->extendData, LSB16)); |
| 13978 | action->lastValue[i] = ReadData(action); |
| 13979 | action->address += EXTRACT_FIELD(action->extendData, MSB16) ? |
| 13980 | EXTRACT_FIELD(action->extendData, MSB16) : |
| 13981 | kSearchByteIncrementTable[EXTRACT_FIELD(action->type, AddressSize)]; |
| 13982 | } |
| 13983 | action->address = action->originalAddress; |
| 13984 | } |
| 13985 | break; |
| 13986 | } |
| 13987 | } |
| 13988 | |
| 13989 | action->frameTimer = 0; |
| 11132 | 13990 | action->flags &= ~kActionFlag_StateMask; |
| 11133 | 13991 | action->flags |= kActionFlag_LastValueGood; |
| 13992 | |
| 13993 | if(action->flags & kActionFlag_CheckCondition) |
| 13994 | { |
| 13995 | if(EXTRACT_FIELD(action->type, CodeParameter) == kCondition_PreviousValue) |
| 13996 | { |
| 13997 | if(EXTRACT_FIELD(action->type, CodeType) == kCodeType_CWrite) |
| 13998 | action->extendData = ReadData(action); |
| 13999 | else |
| 14000 | action->data = ReadData(action); |
| 14001 | } |
| 14002 | } |
| 11134 | 14003 | } |
| 11135 | 14004 | |
| 11136 | 14005 | /*------------------------------------------------------------------------------------- |
| r2762 | r2763 | |
| 11143 | 14012 | |
| 11144 | 14013 | for(i = 0; i < entry->actionListLength; i++) |
| 11145 | 14014 | { |
| 11146 | | CheatAction * action = &entry->actionList[i]; |
| 14015 | CheatAction * action = &entry->actionList[i]; |
| 11147 | 14016 | |
| 11148 | 14017 | ResetAction(action); |
| 11149 | 14018 | |
| 11150 | | /* ----- if watchpoint code, add watchpoint ----- */ |
| 11151 | | if(EXTRACT_FIELD(action->type, Type) == kType_Watch) |
| 14019 | /* if watchpoint code, add watchpoint */ |
| 14020 | if(EXTRACT_FIELD(action->type, CodeType) == kCodeType_Watch) |
| 11152 | 14021 | AddActionWatch(action, entry); |
| 11153 | 14022 | } |
| 11154 | 14023 | |
| 14024 | /* set activate flag */ |
| 11155 | 14025 | entry->flags |= kCheatFlag_Active; |
| 11156 | 14026 | } |
| 11157 | 14027 | |
| r2762 | r2763 | |
| 11161 | 14031 | |
| 11162 | 14032 | static void DeactivateCheat(CheatEntry * entry) |
| 11163 | 14033 | { |
| 11164 | | int i; |
| 14034 | int i; |
| 11165 | 14035 | |
| 11166 | 14036 | for(i = 0; i < entry->actionListLength; i++) |
| 11167 | 14037 | { |
| 11168 | | CheatAction * action = &entry->actionList[i]; |
| 14038 | CheatAction * action = &entry->actionList[i]; |
| 11169 | 14039 | |
| 11170 | | /* ----- restore previous value and clear backup flag if needed ----- */ |
| 11171 | | if(EXTRACT_FIELD(action->type, RestorePreviousValue) && (action->flags & kActionFlag_LastValueGood)) |
| 14040 | /* restore previous value and clear backup flag if needed */ |
| 14041 | if(TEST_FIELD(action->type, RestoreValue) && (action->flags & kActionFlag_LastValueGood)) |
| 11172 | 14042 | { |
| 11173 | | WriteData(action, action->lastValue); |
| 14043 | switch(EXTRACT_FIELD(action->type, CodeType)) |
| 14044 | { |
| 14045 | default: |
| 14046 | WriteData(action, (UINT32)action->lastValue[0]); |
| 14047 | break; |
| 11174 | 14048 | |
| 14049 | case kCodeType_PDWWrite: |
| 14050 | WriteData(action, (UINT32)action->lastValue[0]); |
| 14051 | WriteData(action, (UINT32)action->lastValue[1]); |
| 14052 | break; |
| 14053 | |
| 14054 | case kCodeType_RWrite: |
| 14055 | case kCodeType_VRWrite: |
| 14056 | { |
| 14057 | int j; |
| 14058 | |
| 14059 | for(j = 0; j < EXTRACT_FIELD(action->extendData, LSB16); j++) |
| 14060 | { |
| 14061 | WriteData(action, (UINT32)action->lastValue[j]); |
| 14062 | action->address += EXTRACT_FIELD(action->extendData, MSB16) ? |
| 14063 | EXTRACT_FIELD(action->extendData, MSB16) : |
| 14064 | kSearchByteIncrementTable[EXTRACT_FIELD(action->type, AddressSize)]; |
| 14065 | } |
| 14066 | action->address = action->originalAddress; |
| 14067 | } |
| 14068 | break; |
| 14069 | } |
| 11175 | 14070 | action->flags &= ~kActionFlag_LastValueGood; |
| 11176 | 14071 | } |
| 14072 | free(action->lastValue); |
| 14073 | action->lastValue = NULL; |
| 11177 | 14074 | } |
| 11178 | 14075 | |
| 11179 | | /* ----- remove watchpoint ----- */ |
| 14076 | /* remove watchpoint */ |
| 11180 | 14077 | RemoveAssociatedWatches(entry); |
| 11181 | 14078 | |
| 14079 | /* clear active flag */ |
| 11182 | 14080 | entry->flags &= ~kCheatFlag_StateMask; |
| 11183 | 14081 | } |
| 11184 | 14082 | |
| r2762 | r2763 | |
| 11190 | 14088 | { |
| 11191 | 14089 | if(entry->flags & kCheatFlag_Active) |
| 11192 | 14090 | { |
| 11193 | | int i; |
| 14091 | int i; |
| 11194 | 14092 | |
| 11195 | 14093 | for(i = 0; i < entry->actionListLength; i++) |
| 11196 | 14094 | { |
| 11197 | | CheatAction * action = &entry->actionList[i]; |
| 14095 | CheatAction * action = &entry->actionList[i]; |
| 11198 | 14096 | |
| 11199 | | /* ----- restore previous value if needed ----- */ |
| 11200 | | if(EXTRACT_FIELD(action->type, RestorePreviousValue) && (action->flags & kActionFlag_LastValueGood)) |
| 11201 | | WriteData(action, action->lastValue); |
| 14097 | action->frameTimer = 0; |
| 14098 | action->flags &= ~kActionFlag_OperationDone; |
| 14099 | |
| 14100 | /* restore previous value if needed */ |
| 14101 | switch(EXTRACT_FIELD(action->type, CodeType)) |
| 14102 | { |
| 14103 | default: |
| 14104 | WriteData(action, (UINT32)action->lastValue[0]); |
| 14105 | break; |
| 14106 | |
| 14107 | case kCodeType_PDWWrite: |
| 14108 | WriteData(action, (UINT32)action->lastValue[0]); |
| 14109 | WriteData(action, (UINT32)action->lastValue[1]); |
| 14110 | break; |
| 14111 | |
| 14112 | case kCodeType_RWrite: |
| 14113 | case kCodeType_VRWrite: |
| 14114 | { |
| 14115 | int j; |
| 14116 | |
| 14117 | for(j = 0; j < EXTRACT_FIELD(action->extendData, LSB16); j++) |
| 14118 | { |
| 14119 | WriteData(action, (UINT32)action->lastValue[j]); |
| 14120 | action->address += EXTRACT_FIELD(action->extendData, MSB16) ? |
| 14121 | EXTRACT_FIELD(action->extendData, MSB16) : |
| 14122 | kSearchByteIncrementTable[EXTRACT_FIELD(action->type, AddressSize)]; |
| 14123 | } |
| 14124 | action->address = action->originalAddress; |
| 14125 | } |
| 14126 | break; |
| 14127 | } |
| 11202 | 14128 | } |
| 11203 | 14129 | } |
| 11204 | 14130 | } |
| 11205 | 14131 | |
| 14132 | |
| 11206 | 14133 | /*------------------------------------------------------------ |
| 11207 | 14134 | cheat_periodicOperation - management for cheat operations |
| 11208 | 14135 | ------------------------------------------------------------*/ |
| 11209 | 14136 | |
| 11210 | 14137 | static void cheat_periodicOperation(CheatAction * action) |
| 11211 | 14138 | { |
| 11212 | | UINT8 operation = EXTRACT_FIELD(action->type, Operation) | (EXTRACT_FIELD(action->type, OperationExtend) << 2); |
| 14139 | int data = TEST_FIELD(action->type, DataRead) ? cheatVariable[action->data] : action->data; |
| 11213 | 14140 | |
| 11214 | | switch(operation) |
| 14141 | if(action->flags & kActionFlag_PDWWrite) |
| 11215 | 14142 | { |
| 11216 | | case kOperation_WriteMask: |
| 14143 | action->flags &= ~kActionFlag_IsFirst; |
| 14144 | WriteData(action, data); |
| 14145 | WriteData(action, action->extendData); |
| 14146 | } |
| 14147 | else if(action->flags & kActionFlag_Repeat) |
| 14148 | { |
| 14149 | int i; |
| 14150 | |
| 14151 | for(i = 0; i < EXTRACT_FIELD(action->extendData, LSB16); i++) |
| 11217 | 14152 | { |
| 11218 | | UINT32 temp; |
| 14153 | WriteData(action, data); |
| 14154 | action->address += EXTRACT_FIELD(action->extendData, MSB16) ? |
| 14155 | EXTRACT_FIELD(action->extendData, MSB16) : |
| 14156 | kSearchByteIncrementTable[EXTRACT_FIELD(action->type, AddressSize)]; |
| 14157 | } |
| 14158 | action->address = action->originalAddress; |
| 14159 | } |
| 14160 | else |
| 14161 | { |
| 14162 | switch(EXTRACT_FIELD(action->type, CodeType)) |
| 14163 | { |
| 14164 | case kCodeType_Write: |
| 14165 | WriteData(action, (data & action->extendData) | (ReadData(action) & ~action->extendData)); |
| 14166 | break; |
| 11219 | 14167 | |
| 11220 | | if(action->flags & kActionFlag_IgnoreMask) |
| 11221 | | WriteData(action, action->data); |
| 11222 | | else |
| 11223 | | { |
| 11224 | | temp = ReadData(action); |
| 14168 | case kCodeType_IWrite: |
| 14169 | switch(EXTRACT_FIELD(action->type, CodeParameter)) |
| 14170 | { |
| 14171 | case kIWrite_Write: |
| 14172 | WriteData(action, data); |
| 14173 | break; |
| 11225 | 14174 | |
| 11226 | | temp = (action->data & action->extendData) | (temp & ~action->extendData); |
| 14175 | case kIWrite_BitSet: |
| 14176 | WriteData(action, ReadData(action) | data); |
| 14177 | break; |
| 11227 | 14178 | |
| 11228 | | WriteData(action, temp); |
| 11229 | | } |
| 11230 | | } |
| 11231 | | break; |
| 14179 | case kIWrite_BitClear: |
| 14180 | WriteData(action, ReadData(action) & ~data); |
| 14181 | break; |
| 11232 | 14182 | |
| 11233 | | case kOperation_AddSubtract: |
| 11234 | | { |
| 11235 | | //INT32 temp, bound; |
| 14183 | case kIWrite_LimitedMask: |
| 14184 | WriteData(action, (EXTRACT_FIELD(data, MSB16) & EXTRACT_FIELD(data, LSB16)) | (ReadData(action) & ~EXTRACT_FIELD(data, LSB16))); |
| 14185 | break; |
| 14186 | } |
| 14187 | break; |
| 11236 | 14188 | |
| 11237 | | /* ----- if extend data field is invalid, direct return ----- */ |
| 11238 | | //if(action->flags & kActionFlag_IgnoreMask) |
| 11239 | | return; |
| 14189 | case kCodeType_CWrite: |
| 14190 | case kCodeType_VWrite: |
| 14191 | WriteData(action, data); |
| 14192 | break; |
| 11240 | 14193 | |
| 11241 | | /* FIXME: AddSubstract looks seriously broken |
| 11242 | | * and being worked on. */ |
| 11243 | | #if 0 |
| 11244 | | temp = ReadData(action); |
| 14194 | case kCodeType_Move: |
| 14195 | cheatVariable[EXTRACT_FIELD(action->type, CodeParameter)] = ReadData(action) + data; |
| 14196 | break; |
| 11245 | 14197 | |
| 11246 | | /* ----- OperationParameter field stores add/subtract ----- */ |
| 11247 | | if(TEST_FIELD(action->type, OperationParameter)) |
| 11248 | | { |
| 11249 | | /* ----- subtract ----- */ |
| 11250 | | bound = action->extendData + action->data; |
| 14198 | case kCodeType_Popup: |
| 14199 | switch(EXTRACT_FIELD(action->type, PopupParameter)) |
| 14200 | { |
| 14201 | case kPopup_Label: |
| 14202 | ui_popup_time(1, "%s", action->optionalName); |
| 14203 | break; |
| 11251 | 14204 | |
| 11252 | | if(temp > bound) |
| 11253 | | temp -= action->data; |
| 11254 | | } |
| 11255 | | else |
| 11256 | | { |
| 11257 | | /* ----- add ----- */ |
| 11258 | | bound = action->extendData - action->data; |
| 14205 | case kPopup_Value: |
| 14206 | ui_popup_time(1, "%*.*X", |
| 14207 | kCheatSizeDigitsTable[EXTRACT_FIELD(action->type, AddressRead)], |
| 14208 | kCheatSizeDigitsTable[EXTRACT_FIELD(action->type, AddressRead)], |
| 14209 | ReadData(action)); |
| 14210 | break; |
| 11259 | 14211 | |
| 11260 | | if(temp < bound) |
| 11261 | | temp += action->data; |
| 11262 | | } |
| 14212 | case kPopup_LabelValue: |
| 14213 | ui_popup_time(1, "%s %*.*X", |
| 14214 | action->optionalName, |
| 14215 | kCheatSizeDigitsTable[EXTRACT_FIELD(action->type, AddressRead)], |
| 14216 | kCheatSizeDigitsTable[EXTRACT_FIELD(action->type, AddressRead)], |
| 14217 | ReadData(action)); |
| 14218 | break; |
| 11263 | 14219 | |
| 11264 | | WriteData(action, temp); |
| 14220 | case kPopup_ValueLabel: |
| 14221 | ui_popup_time(1, "%*.*X %s", |
| 14222 | kCheatSizeDigitsTable[EXTRACT_FIELD(action->type, AddressRead)], |
| 14223 | kCheatSizeDigitsTable[EXTRACT_FIELD(action->type, AddressRead)], |
| 14224 | ReadData(action), |
| 14225 | action->optionalName); |
| 14226 | break; |
| 14227 | } |
| 14228 | break; |
| 14229 | #ifdef MAME_DEBUG |
| 14230 | default: |
| 14231 | ui_popup_time(1, "Invalid CodeType : %X", EXTRACT_FIELD(action->type, CodeType)); |
| 11265 | 14232 | #endif |
| 11266 | 14233 | } |
| 11267 | | break; |
| 14234 | } |
| 14235 | } |
| 11268 | 14236 | |
| 11269 | | case kOperation_ForceRange: |
| 11270 | | { |
| 11271 | | UINT32 temp; |
| 14237 | /*------------------------------------------------------------ |
| 14238 | cheat_periodicCondition - management for cheat conditions |
| 14239 | used by CWrite, Branch, Popup |
| 14240 | ------------------------------------------------------------*/ |
| 11272 | 14241 | |
| 11273 | | /* ----- if extend data field is invalid, direct return ----- */ |
| 11274 | | if(action->flags & kActionFlag_IgnoreMask) |
| 11275 | | return; |
| 14242 | static UINT8 cheat_periodicCondition(CheatAction * action) |
| 14243 | { |
| 14244 | int data = ReadData(action); |
| 14245 | int value = EXTRACT_FIELD(action->type, CodeType) == kCodeType_CWrite ? action->extendData : action->data; |
| 11276 | 14246 | |
| 11277 | | temp = ReadData(action); |
| 14247 | switch(EXTRACT_FIELD(action->type, CodeParameter)) |
| 14248 | { |
| 14249 | case kCondition_Equal: |
| 14250 | return (data == value); |
| 11278 | 14251 | |
| 11279 | | if(!TEST_FIELD(action->type, BytesUsed)) |
| 11280 | | { |
| 11281 | | /* ----- 8 bit ----- */ |
| 11282 | | if( (temp < ((action->extendData >> 8) & 0xFF)) || (temp > ((action->extendData >> 0) & 0xFF))) |
| 11283 | | { |
| 11284 | | temp = action->data; |
| 14252 | case kCondition_NotEqual: |
| 14253 | return (data != value); |
| 11285 | 14254 | |
| 11286 | | WriteData(action, temp); |
| 11287 | | } |
| 11288 | | } |
| 11289 | | else |
| 11290 | | { |
| 11291 | | /* ----- 16 bit (or 24, 32 bit) ----- */ |
| 11292 | | if( (temp < ((action->extendData >> 16) & 0xFFFF)) || (temp > ((action->extendData >> 0) & 0xFFFF))) |
| 11293 | | { |
| 11294 | | temp = action->data; |
| 14255 | case kCondition_Less: |
| 14256 | return (data < value); |
| 11295 | 14257 | |
| 11296 | | WriteData(action, temp); |
| 11297 | | } |
| 11298 | | } |
| 11299 | | } |
| 11300 | | break; |
| 14258 | case kCondition_LessOrEqual: |
| 14259 | return (data <= value); |
| 11301 | 14260 | |
| 11302 | | case kOperation_SetOrClearBits: |
| 11303 | | { |
| 11304 | | UINT32 temp; |
| 14261 | case kCondition_Greater: |
| 14262 | return (data > value); |
| 11305 | 14263 | |
| 11306 | | temp = ReadData(action); |
| 14264 | case kCondition_GreaterOrEqual: |
| 14265 | return (data >= value); |
| 11307 | 14266 | |
| 11308 | | if(TEST_FIELD(action->type, OperationParameter)) |
| 11309 | | /* ----- clear bit ----- */ |
| 11310 | | temp &= ~action->data; |
| 11311 | | else |
| 11312 | | /* ----- set bit ----- */ |
| 11313 | | temp |= action->data; |
| 14267 | case kCondition_BitSet: |
| 14268 | return (data & value); |
| 11314 | 14269 | |
| 11315 | | WriteData(action, temp); |
| 11316 | | } |
| 11317 | | break; |
| 14270 | case kCondition_BitClear: |
| 14271 | return (!(data & value)); |
| 11318 | 14272 | |
| 11319 | | case kOperation_WriteMatch: |
| 11320 | | { |
| 11321 | | UINT32 temp; |
| 11322 | | |
| 11323 | | /* ----- if extend data field is invalid, direct return ----- */ |
| 11324 | | if(action->flags & kActionFlag_IgnoreMask) |
| 11325 | | return; |
| 11326 | | |
| 11327 | | temp = ReadData(action); |
| 11328 | | |
| 11329 | | /* ----- if current value matches appointed value, write ----- */ |
| 11330 | | if(temp == action->extendData) |
| 14273 | case kCondition_PreviousValue: |
| 14274 | if(data != value) |
| 11331 | 14275 | { |
| 11332 | | temp = action->data; |
| 14276 | if(EXTRACT_FIELD(action->type, CodeType) == kCodeType_CWrite) |
| 14277 | action->extendData = data; |
| 14278 | else |
| 14279 | action->data = data; |
| 11333 | 14280 | |
| 11334 | | WriteData(action, temp); |
| 14281 | return 1; |
| 11335 | 14282 | } |
| 11336 | | } |
| 11337 | | break; |
| 11338 | | |
| 11339 | | case kOperation_None: |
| 11340 | 14283 | break; |
| 11341 | 14284 | |
| 11342 | | default: |
| 11343 | | break; |
| 14285 | case kCondition_KeyPressedOnce: |
| 14286 | return (input_code_pressed_once(value)); |
| 14287 | |
| 14288 | case kCondition_KeyPressedRepeat: |
| 14289 | return (input_code_pressed(value)); |
| 14290 | |
| 14291 | case kCondition_True: |
| 14292 | return 1; |
| 11344 | 14293 | } |
| 14294 | |
| 14295 | return 0; |
| 11345 | 14296 | } |
| 11346 | 14297 | |
| 11347 | 14298 | /*------------------------------------------------------ |
| 11348 | 14299 | cheat_periodicAction - management for cheat actions |
| 11349 | 14300 | ------------------------------------------------------*/ |
| 11350 | 14301 | |
| 11351 | | static void cheat_periodicAction(running_machine *machine, CheatAction * action) |
| 14302 | static int cheat_periodicAction(running_machine *machine, CheatAction * action, int selection) |
| 11352 | 14303 | { |
| 11353 | | UINT8 parameter = EXTRACT_FIELD(action->type, TypeParameter); |
| 14304 | UINT8 executeOperation = 0; |
| 11354 | 14305 | |
| 11355 | | /* ----- if operation is done in case of one shot, no action ----- */ |
| 11356 | | if(action->flags & kActionFlag_OperationDone) |
| 11357 | | return; |
| 14306 | if(driverSpecifiedFlag) |
| 14307 | return (TEST_FIELD(action->type, Return) ? CHEAT_RETURN_VALUE : selection + 1); |
| 11358 | 14308 | |
| 11359 | | if(TEST_FIELD(action->type, Prefill) && (!(action->flags & kActionFlag_PrefillDone))) |
| 14309 | if(TEST_FIELD(action->type, PrefillEnable) && !(action->flags & kActionFlag_PrefillDone)) |
| 11360 | 14310 | { |
| 11361 | | /* ----- pre-fill ----- */ |
| 11362 | | UINT32 prefillValue = kPrefillValueTable[EXTRACT_FIELD(action->type, Prefill)]; |
| 14311 | UINT8 prefillValue = kPrefillValueTable[EXTRACT_FIELD(action->type, PrefillEnable)]; |
| 11363 | 14312 | |
| 11364 | 14313 | if(!(action->flags & kActionFlag_PrefillWritten)) |
| 11365 | 14314 | { |
| 11366 | | /* ----- set pre-fill value ---- */ |
| 14315 | /* set prefill */ |
| 11367 | 14316 | WriteData(action, prefillValue); |
| 11368 | | |
| 11369 | 14317 | action->flags |= kActionFlag_PrefillWritten; |
| 14318 | return (TEST_FIELD(action->type, Return) ? CHEAT_RETURN_VALUE : selection + 1); |
| 11370 | 14319 | |
| 11371 | | return; |
| 11372 | 14320 | } |
| 11373 | 14321 | else |
| 11374 | 14322 | { |
| 11375 | | /* ----- if value is changed, try to write new value ----- */ |
| 14323 | /* do re-write */ |
| 11376 | 14324 | if(ReadData(action) == prefillValue) |
| 11377 | | return; |
| 14325 | return (TEST_FIELD(action->type, Return) ? CHEAT_RETURN_VALUE : selection + 1); |
| 11378 | 14326 | |
| 11379 | 14327 | action->flags |= kActionFlag_PrefillDone; |
| 11380 | 14328 | } |
| 11381 | 14329 | } |
| 11382 | 14330 | |
| 11383 | | switch(EXTRACT_FIELD(action->type, Type)) |
| 14331 | if(EXTRACT_FIELD(action->type, DelayEnable)) |
| 11384 | 14332 | { |
| 11385 | | case kType_NormalOrDelay: |
| 14333 | if(TEST_FIELD(action->type, OneShot) && TEST_FIELD(action->type, RestoreValue)) |
| 11386 | 14334 | { |
| 11387 | | if(TEST_FIELD(action->type, OneShot) && TEST_FIELD(action->type, RestorePreviousValue) && parameter) |
| 14335 | /* Keep */ |
| 14336 | executeOperation = 1; |
| 14337 | |
| 14338 | if(action->frameTimer++ >= EXTRACT_FIELD(action->type, DelayEnable) * ATTOSECONDS_TO_HZ(video_screen_get_frame_period(machine->primary_screen).attoseconds)) |
| 14339 | action->flags |= kActionFlag_OperationDone; |
| 14340 | } |
| 14341 | else |
| 14342 | { |
| 14343 | if(action->frameTimer++ >= EXTRACT_FIELD(action->type, DelayEnable) * ATTOSECONDS_TO_HZ(video_screen_get_frame_period(machine->primary_screen).attoseconds)) |
| 11388 | 14344 | { |
| 11389 | | /* ----- keep if one shot + restore prevous value + delay !=0 ----- */ |
| 14345 | /* Delay */ |
| 14346 | executeOperation = 1; |
| 14347 | action->frameTimer = 0; |
| 14348 | |
| 14349 | if(TEST_FIELD(action->type, OneShot)) |
| 14350 | action->flags |= kActionFlag_OperationDone; |
| 14351 | } |
| 14352 | } |
| 14353 | } |
| 14354 | else |
| 14355 | { |
| 14356 | if(action->frameTimer++) |
| 14357 | { |
| 14358 | if(action->frameTimer >= EXTRACT_FIELD(action->type, DelayEnable) * ATTOSECONDS_TO_HZ(video_screen_get_frame_period(machine->primary_screen).attoseconds)) |
| 14359 | action->frameTimer = 0; |
| 14360 | |
| 14361 | return (TEST_FIELD(action->type, Return) ? CHEAT_RETURN_VALUE : selection + 1); |
| 14362 | } |
| 14363 | else |
| 14364 | { |
| 14365 | executeOperation = 1; |
| 14366 | |
| 14367 | action->flags |= kActionFlag_OperationDone; |
| 14368 | } |
| 14369 | } |
| 14370 | |
| 14371 | if(executeOperation) |
| 14372 | { |
| 14373 | /* do cheat operation */ |
| 14374 | switch(EXTRACT_FIELD(action->type, CodeType)) |
| 14375 | { |
| 14376 | case kCodeType_Write: |
| 14377 | case kCodeType_PDWWrite: |
| 14378 | case kCodeType_RWrite: |
| 14379 | case kCodeType_IWrite: |
| 14380 | case kCodeType_VWrite: |
| 14381 | case kCodeType_VRWrite: |
| 14382 | case kCodeType_Move: |
| 11390 | 14383 | cheat_periodicOperation(action); |
| 14384 | break; |
| 11391 | 14385 | |
| 11392 | | if(action->frameTimer >= (parameter * ATTOSECONDS_TO_HZ(video_screen_get_frame_period(machine->primary_screen).attoseconds))) |
| 14386 | case kCodeType_CWrite: |
| 14387 | case kCodeType_Popup: |
| 14388 | if(cheat_periodicCondition(action)) |
| 14389 | cheat_periodicOperation(action); |
| 14390 | break; |
| 14391 | |
| 14392 | case kCodeType_Branch: |
| 14393 | if(cheat_periodicCondition(action)) |
| 14394 | return action->extendData; |
| 14395 | break; |
| 14396 | |
| 14397 | case kCodeType_Loop: |
| 11393 | 14398 | { |
| 11394 | | action->frameTimer = 0; |
| 14399 | int counter = ReadData(action); |
| 11395 | 14400 | |
| 11396 | | action->flags |= kActionFlag_OperationDone; |
| 14401 | if(counter) |
| 14402 | { |
| 14403 | WriteData(action, counter - 1); |
| 14404 | |
| 14405 | return (TEST_FIELD(action->type, DataRead) ? cheatVariable[action->data] : action->data); |
| 14406 | } |
| 11397 | 14407 | } |
| 11398 | | else |
| 11399 | | action->frameTimer++; |
| 14408 | break; |
| 14409 | } |
| 14410 | } |
| 14411 | |
| 14412 | return (TEST_FIELD(action->type, Return) ? CHEAT_RETURN_VALUE : selection + 1); |
| 14413 | } |
| 14414 | |
| 14415 | /*----------------------------------------------------- |
| 14416 | cheat_periodicEntry - management for cheat entries |
| 14417 | -----------------------------------------------------*/ |
| 14418 | |
| 14419 | static void cheat_periodicEntry(running_machine *machine, CheatEntry * entry) |
| 14420 | { |
| 14421 | int i = 0; |
| 14422 | UINT8 pressedKey = 0; |
| 14423 | UINT8 isSelect = 0; |
| 14424 | |
| 14425 | /* ***** 1st, handle activation key ***** */ |
| 14426 | |
| 14427 | if(!ui_is_menu_active()) |
| 14428 | { |
| 14429 | /* NOTE : activation key should be not checked in activating UI menu because it conflicts activation key checker */ |
| 14430 | if((entry->flags & kCheatFlag_HasActivationKey1) && input_code_pressed_once(entry->activationKey1)) |
| 14431 | pressedKey = 1; |
| 14432 | else if((entry->flags & kCheatFlag_HasActivationKey2) && input_code_pressed_once(entry->activationKey2)) |
| 14433 | pressedKey = 2; |
| 14434 | } |
| 14435 | |
| 14436 | if(entry->flags & kCheatFlag_Select) |
| 14437 | { |
| 14438 | if(pressedKey) |
| 14439 | { |
| 14440 | if(pressedKey == 1) |
| 14441 | { |
| 14442 | if(--entry->selection < 0) |
| 14443 | entry->selection = entry->labelIndexLength - 1; |
| 11400 | 14444 | } |
| 11401 | 14445 | else |
| 11402 | 14446 | { |
| 11403 | | /* ----- otherwise, delay ----- */ |
| 11404 | | if(action->frameTimer >= (parameter * ATTOSECONDS_TO_HZ(video_screen_get_frame_period(machine->primary_screen).attoseconds))) |
| 11405 | | { |
| 11406 | | action->frameTimer = 0; |
| 14447 | if(++entry->selection >= entry->labelIndexLength) |
| 14448 | entry->selection = 0; |
| 14449 | } |
| 11407 | 14450 | |
| 11408 | | cheat_periodicOperation(action); |
| 14451 | /* NOTE : in handling activatio key, forced to activate a cheat even if one shot */ |
| 14452 | if(!(entry->flags & kCheatFlag_OneShot) && !(entry->labelIndex[entry->selection])) |
| 14453 | DeactivateCheat(entry); |
| 14454 | else |
| 14455 | ActivateCheat(entry); |
| 11409 | 14456 | |
| 11410 | | if(TEST_FIELD(action->type, OneShot)) |
| 11411 | | action->flags |= kActionFlag_OperationDone; |
| 11412 | | } |
| 14457 | if(TEST_FIELD(cheatOptions, ActivationKeyMessage)) |
| 14458 | { |
| 14459 | if(!entry->selection) |
| 14460 | ui_popup_time(1,"%s disabled", entry->name); |
| 11413 | 14461 | else |
| 11414 | | action->frameTimer++; |
| 14462 | ui_popup_time(1,"%s : %s selected", entry->name, entry->actionList[entry->labelIndex[entry->selection]].optionalName); |
| 11415 | 14463 | } |
| 11416 | 14464 | } |
| 11417 | | break; |
| 11418 | | |
| 11419 | | case kType_WaitForModification: |
| 14465 | } |
| 14466 | else |
| 14467 | { |
| 14468 | /* NOTE : if value-selection has activatinon key, no handling -----*/ |
| 14469 | if(!(entry->flags & kCheatFlag_UserSelect) && pressedKey) |
| 11420 | 14470 | { |
| 11421 | | if(action->flags & kActionFlag_WasModified) |
| 14471 | if(entry->flags & kCheatFlag_OneShot) |
| 11422 | 14472 | { |
| 11423 | | if(action->frameTimer <= 0) |
| 11424 | | { |
| 11425 | | cheat_periodicOperation(action); |
| 14473 | ActivateCheat(entry); |
| 11426 | 14474 | |
| 11427 | | action->flags &= ~kActionFlag_WasModified; |
| 14475 | if(TEST_FIELD(cheatOptions, ActivationKeyMessage)) |
| 14476 | ui_popup_time(1,"set %s", entry->name); |
| 14477 | } |
| 14478 | else if(entry->flags & kCheatFlag_Active) |
| 14479 | { |
| 14480 | DeactivateCheat(entry); |
| 11428 | 14481 | |
| 11429 | | if(TEST_FIELD(action->type, OneShot)) |
| 11430 | | action->flags |= kActionFlag_OperationDone; |
| 11431 | | } |
| 11432 | | else |
| 11433 | | action->frameTimer--; |
| 11434 | | |
| 11435 | | action->lastValue = ReadData(action); |
| 14482 | if(TEST_FIELD(cheatOptions, ActivationKeyMessage)) |
| 14483 | ui_popup_time(1,"%s disabled", entry->name); |
| 11436 | 14484 | } |
| 11437 | 14485 | else |
| 11438 | 14486 | { |
| 11439 | | UINT32 currentValue = ReadData(action); |
| 14487 | ActivateCheat(entry); |
| 11440 | 14488 | |
| 11441 | | if(currentValue != action->lastValue) |
| 11442 | | { |
| 11443 | | action->frameTimer = parameter * ATTOSECONDS_TO_HZ(video_screen_get_frame_period(machine->primary_screen).attoseconds); |
| 14489 | if(TEST_FIELD(cheatOptions, ActivationKeyMessage)) |
| 14490 | ui_popup_time(1,"%s enabled", entry->name); |
| 14491 | } |
| 14492 | } |
| 14493 | } |
| 11444 | 14494 | |
| 11445 | | action->flags |= kActionFlag_WasModified; |
| 11446 | | } |
| 14495 | /* ***** 2nd, do cheat actions ***** */ |
| 11447 | 14496 | |
| 11448 | | action->lastValue = currentValue; |
| 14497 | /* if "OFF", no action */ |
| 14498 | if(!(entry->flags & kCheatFlag_Active)) |
| 14499 | return; |
| 14500 | |
| 14501 | while(1) |
| 14502 | { |
| 14503 | if(entry->actionList[i].flags & kActionFlag_Custom) |
| 14504 | { |
| 14505 | if(EXTRACT_FIELD(entry->actionList[i].type, CodeType) == kCustomCode_LabelSelect) |
| 14506 | { |
| 14507 | i = entry->labelIndex[entry->selection]; |
| 14508 | isSelect = 1; |
| 14509 | continue; |
| 11449 | 14510 | } |
| 14511 | else |
| 14512 | i++; |
| 11450 | 14513 | } |
| 11451 | | break; |
| 14514 | else if((entry->actionList[i].flags & kActionFlag_OperationDone) || (entry->actionList[i].flags & kActionFlag_NoAction)) |
| 14515 | { |
| 14516 | i++; |
| 14517 | } |
| 14518 | else if(entry->actionList[i].flags & kActionFlag_OldFormat) |
| 14519 | { |
| 14520 | int tempType = entry->actionList[i].type; |
| 14521 | int j = i; |
| 11452 | 14522 | |
| 11453 | | case kType_IgnoreIfDecrementing: |
| 14523 | entry->actionList[i].type = ConvertToNewCode(&entry->actionList[i]); |
| 14524 | i = cheat_periodicAction(machine, &entry->actionList[i], i); |
| 14525 | entry->actionList[j].type = tempType; |
| 14526 | } |
| 14527 | else |
| 14528 | i = cheat_periodicAction(machine, &entry->actionList[i], i); |
| 14529 | |
| 14530 | if(i >= entry->actionListLength) |
| 14531 | break; |
| 14532 | |
| 14533 | if(isSelect && EXTRACT_FIELD(entry->actionList[i].type, Link) != kLink_SubLink) |
| 14534 | break; |
| 14535 | } |
| 14536 | |
| 14537 | /* ***** 3rd, deactive a cheat if one shot ***** */ |
| 14538 | |
| 14539 | if(entry->flags & kCheatFlag_OneShot) |
| 14540 | { |
| 14541 | UINT8 done = 1; |
| 14542 | |
| 14543 | i = 0; |
| 14544 | isSelect = 0; |
| 14545 | |
| 14546 | while(1) |
| 11454 | 14547 | { |
| 11455 | | UINT32 currentValue = ReadData(action); |
| 11456 | | |
| 11457 | | /* ### is "NotEqual" correct ? "LessOrEqual" seems to be good... ### */ |
| 11458 | | if(currentValue != (action->lastValue - parameter)) |
| 14548 | if(entry->actionList[i].flags & kActionFlag_Custom) |
| 11459 | 14549 | { |
| 11460 | | cheat_periodicOperation(action); |
| 11461 | | |
| 11462 | | if(TEST_FIELD(action->type, OneShot)) |
| 11463 | | action->flags |= kActionFlag_OperationDone; |
| 14550 | if(EXTRACT_FIELD(entry->actionList[i].type, CodeType) == kCustomCode_LabelSelect) |
| 14551 | { |
| 14552 | i = entry->labelIndex[entry->selection]; |
| 14553 | isSelect = 1; |
| 14554 | continue; |
| 14555 | } |
| 11464 | 14556 | } |
| 14557 | else if(entry->actionList[i].flags & kActionFlag_NoAction) |
| 14558 | { |
| 14559 | i++; |
| 14560 | } |
| 14561 | else if(!(entry->actionList[i].flags & kActionFlag_OperationDone)) |
| 14562 | { |
| 14563 | done = 0; |
| 14564 | i++; |
| 14565 | } |
| 14566 | else |
| 14567 | i++; |
| 11465 | 14568 | |
| 11466 | | action->lastValue = currentValue; |
| 14569 | if(i >= entry->actionListLength) |
| 14570 | break; |
| 14571 | |
| 14572 | if(isSelect && EXTRACT_FIELD(entry->actionList[i].type, Link) != kLink_SubLink) |
| 14573 | break; |
| 11467 | 14574 | } |
| 11468 | | break; |
| 11469 | 14575 | |
| 11470 | | default: |
| 11471 | | break; |
| 14576 | if(done) |
| 14577 | DeactivateCheat(entry); |
| 11472 | 14578 | } |
| 11473 | 14579 | } |
| 11474 | 14580 | |
| 11475 | | /*----------------------------------------------------- |
| 11476 | | cheat_periodicEntry - management for cheat entries |
| 11477 | | -----------------------------------------------------*/ |
| 14581 | /*------------------------------------------------------------------ |
| 14582 | UpdateAllCheatInfo - update all cheat info when database loaded |
| 14583 | ------------------------------------------------------------------*/ |
| 11478 | 14584 | |
| 11479 | | static void cheat_periodicEntry(running_machine *machine, CheatEntry * entry) |
| 14585 | static void UpdateAllCheatInfo(void) |
| 11480 | 14586 | { |
| 11481 | | int i; |
| 14587 | int i; |
| 11482 | 14588 | |
| 11483 | | /* ----- special handling for label-selection ----- */ |
| 11484 | | if(entry->flags & kCheatFlag_Select) |
| 14589 | /* update flags for all CheatEntry */ |
| 14590 | for(i = 0; i < cheatListLength; i++) |
| 11485 | 14591 | { |
| 11486 | | /* ----- special handling for activation key ----- */ |
| 11487 | | if((entry->flags & kCheatFlag_HasActivationKey1) || (entry->flags & kCheatFlag_HasActivationKey2)) |
| 14592 | UpdateCheatInfo(&cheatList[i], 1); |
| 14593 | |
| 14594 | if(cheatList[i].flags & kCheatFlag_Select) |
| 14595 | BuildLabelIndexTable(&cheatList[i]); |
| 14596 | } |
| 14597 | |
| 14598 | SetLayerIndex(); |
| 14599 | } |
| 14600 | |
| 14601 | /*--------------------------------------------------------------------------------------------- |
| 14602 | UpdateCheatInfo - check several fields on CheatEntry and CheatAction then set flags |
| 14603 | "isLoadTime" parameter is set when called UpdateAllCheatInfo() right now |
| 14604 | ---------------------------------------------------------------------------------------------*/ |
| 14605 | |
| 14606 | static void UpdateCheatInfo(CheatEntry * entry, UINT8 isLoadTime) |
| 14607 | { |
| 14608 | int i; |
| 14609 | int flags = 0; |
| 14610 | UINT8 isOneShot = 1; |
| 14611 | UINT8 isNull = 1; |
| 14612 | UINT8 isSeparator = 1; |
| 14613 | UINT8 isNewFormat = 1; |
| 14614 | |
| 14615 | flags = entry->flags & kCheatFlag_PersistentMask; |
| 14616 | |
| 14617 | for(i = 0; i < entry->actionListLength; i++) |
| 14618 | { |
| 14619 | CheatAction * action = &entry->actionList[i]; |
| 14620 | |
| 14621 | int actionFlags = action->flags & kActionFlag_PersistentMask; |
| 14622 | |
| 14623 | action->region = EXTRACT_FIELD(action->type, CPURegion); |
| 14624 | |
| 14625 | if(actionFlags & kActionFlag_OldFormat) |
| 11488 | 14626 | { |
| 11489 | | if(input_code_pressed(entry->activationKey1) || input_code_pressed(entry->activationKey2)) |
| 14627 | if( (EXTRACT_FIELD(action->type, LocationType) == kLocation_Custom) && |
| 14628 | (EXTRACT_FIELD(action->type, LocationParameter) == kCustomLocation_Select)) |
| 14629 | flags |= kCheatFlag_Select; |
| 14630 | |
| 14631 | if(EXTRACT_FIELD(action->type, LocationType) != kLocation_Custom) |
| 14632 | isNull = 0; |
| 14633 | |
| 14634 | if(!TEST_FIELD(action->type, OneShot)) |
| 14635 | isOneShot = 0; |
| 14636 | |
| 14637 | if(TEST_FIELD(action->type, UserSelectEnable)) |
| 14638 | flags |= kCheatFlag_UserSelect; |
| 14639 | |
| 14640 | if( (EXTRACT_FIELD(action->type, LocationType) == kLocation_Custom) && |
| 14641 | (EXTRACT_FIELD(action->type, LocationParameter) == kCustomLocation_Select)) |
| 14642 | actionFlags |= kActionFlag_NoAction; |
| 14643 | |
| 14644 | if( (EXTRACT_FIELD(action->type, LocationType) == kLocation_IndirectIndexed) || |
| 14645 | ((EXTRACT_FIELD(action->type, LocationType) != kLocation_Custom) && |
| 14646 | ((EXTRACT_FIELD(action->type, Operation) | EXTRACT_FIELD(action->type, OperationExtend) << 2) == 1))) |
| 14647 | actionFlags |= kActionFlag_IndexAddress; |
| 14648 | |
| 14649 | if(i && entry->actionList[i-1].type == entry->actionList[i].type) |
| 11490 | 14650 | { |
| 11491 | | if(!(entry->flags & kCheatFlag_ActivationKeyPressed)) |
| 14651 | if( entry->actionList[i].address >= entry->actionList[i-1].address && |
| 14652 | entry->actionList[i].address <= entry->actionList[i-1].address + 3) |
| 14653 | actionFlags |= kActionFlag_NoAction; |
| 14654 | } |
| 14655 | |
| 14656 | isNewFormat = 0; |
| 14657 | } |
| 14658 | else |
| 14659 | { |
| 14660 | if(action->region != CUSTOM_CODE) |
| 14661 | { |
| 14662 | switch(EXTRACT_FIELD(action->type, CodeType)) |
| 11492 | 14663 | { |
| 11493 | | /* ----- move current position until find OFF or no link extension code ----- */ |
| 11494 | | do{ |
| 11495 | | /* ----- 1st activation key pressed ----- */ |
| 11496 | | if(input_code_pressed(entry->activationKey1)) |
| 11497 | | { |
| 11498 | | entry->selection++; |
| 14664 | case kCodeType_PDWWrite: |
| 14665 | actionFlags |= kActionFlag_PDWWrite; |
| 14666 | break; |
| 11499 | 14667 | |
| 11500 | | if(entry->flags & kCheatFlag_OneShot) |
| 11501 | | { |
| 11502 | | if(entry->selection >= entry->actionListLength) |
| 11503 | | { |
| 11504 | | entry->selection = 1; |
| 14668 | case kCodeType_RWrite: |
| 14669 | actionFlags |= kActionFlag_Repeat; |
| 14670 | break; |
| 11505 | 14671 | |
| 11506 | | if(entry->selection >= entry->actionListLength) |
| 11507 | | entry->selection = 0; |
| 11508 | | } |
| 14672 | case kCodeType_IWrite: |
| 14673 | case kCodeType_Move: |
| 14674 | case kCodeType_Loop: |
| 14675 | if(action->extendData != ~0) |
| 14676 | actionFlags |= kActionFlag_IndexAddress; |
| 14677 | break; |
| 11509 | 14678 | |
| 11510 | | if(!TEST_FIELD(entry->actionList[entry->selection].type, LinkExtension)) |
| 11511 | | { |
| 11512 | | ActivateCheat(entry); |
| 14679 | case kCodeType_CWrite: |
| 14680 | case kCodeType_Branch: |
| 14681 | actionFlags |= kActionFlag_CheckCondition; |
| 14682 | break; |
| 11513 | 14683 | |
| 11514 | | entry->flags |= kCheatFlag_DoOneShot; |
| 11515 | | } |
| 11516 | | } |
| 11517 | | else |
| 11518 | | { |
| 11519 | | if(entry->selection >= entry->actionListLength) |
| 11520 | | { |
| 11521 | | entry->selection = 0; |
| 14684 | case kCodeType_VWrite: |
| 14685 | flags |= kCheatFlag_UserSelect; |
| 11522 | 14686 | |
| 11523 | | DeactivateCheat(entry); |
| 11524 | | } |
| 11525 | | else |
| 11526 | | { |
| 11527 | | if(!TEST_FIELD(entry->actionList[entry->selection].type, LinkExtension)) |
| 11528 | | ActivateCheat(entry); |
| 11529 | | } |
| 11530 | | } |
| 11531 | | } |
| 11532 | | /* ----- 2nd activation key pressed ----- */ |
| 11533 | | else |
| 11534 | | { |
| 11535 | | entry->selection--; |
| 14687 | if(action->extendData != ~0) |
| 14688 | actionFlags |= kActionFlag_IndexAddress; |
| 14689 | break; |
| 11536 | 14690 | |
| 11537 | | if(entry->flags & kCheatFlag_OneShot) |
| 11538 | | { |
| 11539 | | if(entry->selection <= 0) |
| 11540 | | entry->selection = entry->actionListLength - 1; |
| 14691 | case kCodeType_VRWrite: |
| 14692 | flags |= kCheatFlag_UserSelect; |
| 14693 | actionFlags |= kActionFlag_Repeat; |
| 14694 | break; |
| 11541 | 14695 | |
| 11542 | | if(!TEST_FIELD(entry->actionList[entry->selection].type, LinkExtension)) |
| 11543 | | { |
| 11544 | | ActivateCheat(entry); |
| 14696 | case kCodeType_Popup: |
| 14697 | actionFlags |= kActionFlag_CheckCondition; |
| 11545 | 14698 | |
| 11546 | | entry->flags |= kCheatFlag_DoOneShot; |
| 11547 | | } |
| 11548 | | } |
| 11549 | | else |
| 11550 | | { |
| 11551 | | if(!entry->selection) |
| 11552 | | DeactivateCheat(entry); |
| 11553 | | else |
| 11554 | | { |
| 11555 | | if(entry->selection < 0) |
| 11556 | | entry->selection = entry->actionListLength - 1; |
| 14699 | if(action->extendData != ~0) |
| 14700 | actionFlags |= kActionFlag_IndexAddress; |
| 14701 | break; |
| 11557 | 14702 | |
| 11558 | | if(!TEST_FIELD(entry->actionList[entry->selection].type, LinkExtension)) |
| 11559 | | ActivateCheat(entry); |
| 11560 | | } |
| 11561 | | } |
| 11562 | | } |
| 11563 | | }while(entry->selection && TEST_FIELD(entry->actionList[entry->selection].type, LinkExtension)); |
| 14703 | case kCodeType_Watch: |
| 14704 | actionFlags |= kActionFlag_NoAction; |
| 14705 | break; |
| 14706 | } |
| 11564 | 14707 | |
| 11565 | | /* ----- display selected label name if needed ----- */ |
| 11566 | | if(TEST_FIELD(cheatOptions, ActivationKeyMessage)) |
| 11567 | | { |
| 11568 | | if(!entry->selection) |
| 11569 | | ui_popup_time(1,"%s disabled", entry->name); |
| 11570 | | else |
| 11571 | | ui_popup_time(1,"%s : %s selected", entry->name, entry->actionList[entry->selection].optionalName); |
| 11572 | | } |
| 14708 | isNull = 0; |
| 14709 | isSeparator = 0; |
| 14710 | } |
| 14711 | else |
| 14712 | { |
| 14713 | /* is label-select? */ |
| 14714 | if(EXTRACT_FIELD(action->type, CodeType) == kCustomCode_LabelSelect) |
| 14715 | flags |= kCheatFlag_Select; |
| 11573 | 14716 | |
| 11574 | | entry->flags |= kCheatFlag_ActivationKeyPressed; // set flag |
| 11575 | | } |
| 14717 | /* is comment? */ |
| 14718 | if(EXTRACT_FIELD(action->type, CodeType) != kCustomCode_Comment) |
| 14719 | isNull = 0; |
| 14720 | |
| 14721 | /* is separator? */ |
| 14722 | if(EXTRACT_FIELD(action->type, CodeType) != kCustomCode_Separator) |
| 14723 | isSeparator = 0; |
| 14724 | |
| 14725 | /* is layer index? */ |
| 14726 | if(EXTRACT_FIELD(action->type, CodeType) == kCustomCode_Layer) |
| 14727 | flags |= kCheatFlag_LayerIndex; |
| 14728 | |
| 14729 | actionFlags |= kActionFlag_NoAction; |
| 14730 | actionFlags |= kActionFlag_Custom; |
| 11576 | 14731 | } |
| 11577 | | else |
| 11578 | | entry->flags &= ~kCheatFlag_ActivationKeyPressed; // clear flag |
| 14732 | |
| 14733 | /* is one shot? */ |
| 14734 | if(!TEST_FIELD(action->type, OneShot)) |
| 14735 | isOneShot = 0; |
| 11579 | 14736 | } |
| 11580 | 14737 | |
| 11581 | | /* ----- if a subcheat is selected, handle it ----- */ |
| 11582 | | if(entry->selection) |
| 14738 | action->flags = actionFlags; |
| 14739 | } |
| 14740 | |
| 14741 | /* one shot is set if "ALL" actions are not an one shot */ |
| 14742 | if(isOneShot) |
| 14743 | flags |= kCheatFlag_OneShot; |
| 14744 | |
| 14745 | if(isNull) |
| 14746 | { |
| 14747 | if(entry->actionListLength > 1) |
| 14748 | flags |= kCheatFlag_ExtendComment; |
| 14749 | else |
| 14750 | flags |= kCheatFlag_Null; |
| 14751 | } |
| 14752 | |
| 14753 | if(isSeparator) |
| 14754 | { |
| 14755 | flags |= kCheatFlag_Null; |
| 14756 | flags |= kCheatFlag_Separator; |
| 14757 | } |
| 14758 | |
| 14759 | if(isNewFormat == 0) |
| 14760 | flags |= kCheatFlag_OldFormat; |
| 14761 | |
| 14762 | entry->flags = (flags & kCheatFlag_InfoMask) | (entry->flags & ~kCheatFlag_InfoMask); |
| 14763 | |
| 14764 | /* clear dirty flag as "this entry has already exist in the database" when loaded from a database */ |
| 14765 | if(isLoadTime) |
| 14766 | entry->flags &= ~kCheatFlag_Dirty; |
| 14767 | |
| 14768 | CheckCodeFormat(entry); |
| 14769 | } |
| 14770 | |
| 14771 | /*-------------------- |
| 14772 | AnalyseCodeFormat |
| 14773 | --------------------*/ |
| 14774 | |
| 14775 | static UINT32 AnalyseCodeFormat(CheatEntry * entry, CheatAction * action) |
| 14776 | { |
| 14777 | UINT32 errorFlag = 0; |
| 14778 | |
| 14779 | /* check type field */ |
| 14780 | if(action->flags & kActionFlag_OldFormat) |
| 14781 | { |
| 14782 | UINT8 type = EXTRACT_FIELD(action->type, LocationType); |
| 14783 | UINT8 parameter = EXTRACT_FIELD(action->type, LocationParameter); |
| 14784 | UINT8 operation = EXTRACT_FIELD(action->type, Operation); |
| 14785 | |
| 14786 | if(type >= kLocation_Unused5) |
| 14787 | errorFlag |= kErrorFlag_InvalidLocationType; |
| 14788 | |
| 14789 | if(TEST_FIELD(action->type, OperationExtend)) |
| 14790 | errorFlag |= kErrorFlag_InvalidOperation; |
| 14791 | |
| 14792 | if(type == kLocation_IndirectIndexed) |
| 11583 | 14793 | { |
| 11584 | | i = entry->selection; |
| 14794 | if(operation != kOperation_WriteMask && operation != kOperation_SetOrClearBits) |
| 14795 | errorFlag |= kErrorFlag_ConflictedExtendField; |
| 14796 | } |
| 11585 | 14797 | |
| 11586 | | do{ |
| 11587 | | if(!(entry->flags & kCheatFlag_OneShot) || (entry->flags & kCheatFlag_DoOneShot)) |
| 11588 | | cheat_periodicAction(machine, &entry->actionList[i]); |
| 14798 | if(operation == kOperation_ForceRange) |
| 14799 | { |
| 14800 | if(EXTRACT_FIELD(action->type, MSB16) <= EXTRACT_FIELD(action->type, LSB16)) |
| 14801 | errorFlag |= kErrorFlag_InvalidRange; |
| 14802 | } |
| 11589 | 14803 | |
| 11590 | | i++; |
| 14804 | if(type == kLocation_MemoryRegion) |
| 14805 | { |
| 14806 | if(!TEST_FIELD(action->type, RestorePreviousValue)) |
| 14807 | errorFlag |= kErrorFlag_NoRestorePreviousValue; |
| 14808 | } |
| 11591 | 14809 | |
| 11592 | | /* ----- if illegal index, finish ----- */ |
| 11593 | | if(i >= entry->actionListLength) |
| 11594 | | break; |
| 14810 | if((entry->flags & kCheatFlag_UserSelect) && (entry->flags & kCheatFlag_Select)) |
| 14811 | errorFlag |= kErrorFlag_ConflictedSelects; |
| 11595 | 14812 | |
| 11596 | | /* ----- if next code has link extension, handle it too ----- */ |
| 11597 | | }while(TEST_FIELD(entry->actionList[i].type, LinkExtension)); |
| 14813 | if(TEST_FIELD(action->type, UserSelectEnable)) |
| 14814 | { |
| 14815 | if(!action->originalDataField) |
| 14816 | errorFlag |= kErrorFlag_NoSelectableValue; |
| 11598 | 14817 | } |
| 14818 | |
| 14819 | if(type == kLocation_Custom && parameter == kCustomLocation_Select) |
| 14820 | { |
| 14821 | if(entry->actionListLength == 1) |
| 14822 | errorFlag |= kErrorFlag_NoLabel; |
| 14823 | |
| 14824 | if(action->originalDataField) |
| 14825 | errorFlag |= kErrorFlag_InvalidDataField; |
| 14826 | |
| 14827 | if(action->extendData) |
| 14828 | errorFlag |= kErrorFlag_InvalidExtendDataField; |
| 14829 | } |
| 14830 | |
| 14831 | if(operation == kOperation_WriteMask) |
| 14832 | { |
| 14833 | if(type == kLocation_Standard) |
| 14834 | { |
| 14835 | if(!action->extendData || action->extendData == 0xFF || action->extendData == 0xFFFF || action->extendData == 0xFFFFFF) |
| 14836 | errorFlag |= kErrorFlag_InvalidExtendDataField; |
| 14837 | } |
| 14838 | else if(type == kLocation_MemoryRegion) |
| 14839 | { |
| 14840 | if(action->extendData != ~0) |
| 14841 | errorFlag |= kErrorFlag_InvalidExtendDataField; |
| 14842 | } |
| 14843 | } |
| 11599 | 14844 | } |
| 11600 | 14845 | else |
| 11601 | 14846 | { |
| 11602 | | /* ----- NOTE : activatinon key for value-selection is disabled -----*/ |
| 11603 | | if(((entry->flags & kCheatFlag_HasActivationKey1) || (entry->flags & kCheatFlag_HasActivationKey2)) && |
| 11604 | | !(entry->flags & kCheatFlag_UserSelect)) |
| 14847 | if((action->flags & kActionFlag_Custom) == 0) |
| 11605 | 14848 | { |
| 11606 | | /* ----- special handling for activation key ----- */ |
| 11607 | | if(input_code_pressed(entry->activationKey1) || input_code_pressed(entry->activationKey2)) |
| 14849 | UINT8 codeType = EXTRACT_FIELD(action->type, CodeType); |
| 14850 | UINT8 codeParameter = EXTRACT_FIELD(action->type, CodeParameter); |
| 14851 | |
| 14852 | if(codeType >= kCodeType_Unused1 && codeType <= kCodeType_Unused4) |
| 14853 | errorFlag |= kErrorFlag_InvalidCodeType; |
| 14854 | |
| 14855 | if(action->flags & kActionFlag_CheckCondition) |
| 11608 | 14856 | { |
| 11609 | | if(!(entry->flags & kCheatFlag_ActivationKeyPressed)) |
| 11610 | | { |
| 11611 | | if(entry->flags & kCheatFlag_OneShot) |
| 11612 | | { |
| 11613 | | ActivateCheat(entry); |
| 14857 | if(codeParameter >= kCondition_Unused1 && codeParameter <= kCondition_Unused4) |
| 14858 | errorFlag |= kErrorFlag_InvalidCondition; |
| 14859 | } |
| 11614 | 14860 | |
| 11615 | | /* ----- display description for one shot if needed ----- */ |
| 11616 | | if(TEST_FIELD(cheatOptions, ActivationKeyMessage)) |
| 11617 | | ui_popup_time(1,"set %s", entry->name); |
| 11618 | | } |
| 11619 | | else |
| 11620 | | { |
| 11621 | | if(entry->flags & kCheatFlag_Active) |
| 11622 | | { |
| 11623 | | DeactivateCheat(entry); |
| 14861 | if(codeType == kCodeType_PDWWrite) |
| 14862 | { |
| 14863 | if(EXTRACT_FIELD(action->type, AddressRead) == kReadFrom_Variable) |
| 14864 | errorFlag |= kErrorFlag_ForbittenVariable; |
| 14865 | } |
| 11624 | 14866 | |
| 11625 | | /* ----- display description for OFF if needed ----- */ |
| 11626 | | if(TEST_FIELD(cheatOptions, ActivationKeyMessage)) |
| 11627 | | ui_popup_time(1,"%s disabled", entry->name); |
| 11628 | | } |
| 11629 | | else |
| 11630 | | { |
| 11631 | | ActivateCheat(entry); |
| 14867 | if(EXTRACT_FIELD(action->type, Link) == kLink_CopyLink) |
| 14868 | { |
| 14869 | if(!entry->flags & kCheatFlag_UserSelect) |
| 14870 | errorFlag |= kErrorFlag_CopyLinkWithoutSelect; |
| 14871 | } |
| 11632 | 14872 | |
| 11633 | | /* ----- display description for ON if needed ----- */ |
| 11634 | | if(TEST_FIELD(cheatOptions, ActivationKeyMessage)) |
| 11635 | | ui_popup_time(1,"%s enabled", entry->name); |
| 11636 | | } |
| 11637 | | } |
| 14873 | if( TEST_FIELD(action->region, RegionFlag) || |
| 14874 | EXTRACT_FIELD(action->type, AddressSpace) == kAddressSpace_OpcodeRAM) |
| 14875 | { |
| 14876 | if(!TEST_FIELD(action->type, RestoreValue)) |
| 14877 | errorFlag |= kErrorFlag_NoRestorePreviousValue; |
| 14878 | } |
| 11638 | 14879 | |
| 11639 | | entry->flags |= kCheatFlag_ActivationKeyPressed; |
| 11640 | | } |
| 14880 | if( EXTRACT_FIELD(action->type, CodeType) == kCodeType_VWrite || |
| 14881 | EXTRACT_FIELD(action->type, CodeType) == kCodeType_VRWrite) |
| 14882 | { |
| 14883 | if(!action->originalDataField) |
| 14884 | errorFlag |= kErrorFlag_NoSelectableValue; |
| 11641 | 14885 | } |
| 11642 | | else |
| 11643 | | entry->flags &= ~kCheatFlag_ActivationKeyPressed; |
| 11644 | | } |
| 11645 | 14886 | |
| 11646 | | if(!(entry->flags & kCheatFlag_Active)) |
| 11647 | | return; |
| 14887 | if(action->flags & kActionFlag_Repeat) |
| 14888 | { |
| 14889 | if(!EXTRACT_FIELD(action->extendData, LSB16)) |
| 14890 | errorFlag |= kErrorFlag_NoRepeatCount; |
| 14891 | } |
| 11648 | 14892 | |
| 11649 | | /* ----- update all actions ----- */ |
| 11650 | | for(i = 0; i < entry->actionListLength; i++) |
| 11651 | | cheat_periodicAction(machine, &entry->actionList[i]); |
| 14893 | if(EXTRACT_FIELD(action->type, AddressRead)) |
| 14894 | { |
| 14895 | if(EXTRACT_FIELD(action->type, AddressRead) > kReadFrom_Variable) |
| 14896 | errorFlag |= kErrorFlag_UndefinedAddressRead; |
| 11652 | 14897 | |
| 11653 | | /* ----- if all actions are done, deactivate the cheat if oneshot entry ----- */ |
| 11654 | | { |
| 11655 | | UINT8 done = 1; |
| 14898 | if(action->address >= VARIABLE_MAX_ARRAY) |
| 14899 | errorFlag |= kErrorFlag_AddressVariableOutRange; |
| 14900 | } |
| 11656 | 14901 | |
| 11657 | | for(i = 0 ; (i < entry->actionListLength && done) ; i++) |
| 11658 | | if(!(entry->actionList[i].flags & kActionFlag_OperationDone)) |
| 11659 | | done = 0; |
| 14902 | if(TEST_FIELD(action->type, DataRead)) |
| 14903 | { |
| 14904 | if(action->data >= VARIABLE_MAX_ARRAY) |
| 14905 | errorFlag |= kErrorFlag_DataVariableOutRange; |
| 14906 | } |
| 11660 | 14907 | |
| 11661 | | if(done) |
| 11662 | | DeactivateCheat(entry); |
| 14908 | if(codeType == kCodeType_Write) |
| 14909 | { |
| 14910 | if(!action->extendData || action->extendData == 0xFF || action->extendData == 0xFFFF || action->extendData == 0xFFFFFF) |
| 14911 | errorFlag |= kErrorFlag_InvalidExtendDataField; |
| 14912 | } |
| 14913 | |
| 14914 | if(!(action->flags & kActionFlag_Custom)) |
| 14915 | { |
| 14916 | if(TEST_FIELD(action->region, RegionFlag)) |
| 14917 | { |
| 14918 | UINT8 region = EXTRACT_FIELD(action->region, RegionIndex); |
| 14919 | |
| 14920 | if(region >= REGION_MAX) errorFlag |= kErrorFlag_OutOfCPURegion; |
| 14921 | else if(!region_info_list[region].type) errorFlag |= kErrorFlag_InvalidCPURegion; |
| 14922 | else if(!IsAddressInRange(action, memory_region_length(action->region))) |
| 14923 | errorFlag |= kErrorFlag_RegionOutOfRange; |
| 14924 | } |
| 14925 | else |
| 14926 | { |
| 14927 | UINT8 cpu = EXTRACT_FIELD(action->region, CPUIndex); |
| 14928 | |
| 14929 | if(!VALID_CPU(cpu)) |
| 14930 | errorFlag |= kErrorFlag_OutOfCPURegion; |
| 14931 | else if(cpu_info_list[cpu].type == 0) |
| 14932 | errorFlag |= kErrorFlag_InvalidCPURegion; |
| 14933 | |
| 14934 | if(EXTRACT_FIELD(action->type, AddressSpace) > kAddressSpace_EEPROM) |
| 14935 | errorFlag |= kErrorFlag_InvalidAddressSpace; |
| 14936 | } |
| 14937 | } |
| 11663 | 14938 | } |
| 14939 | else |
| 14940 | { |
| 14941 | if(EXTRACT_FIELD(action->type, CodeParameter) >= kCustomCode_Unused1) |
| 14942 | errorFlag |= kErrorFlag_InvalidCustomCode; |
| 14943 | } |
| 11664 | 14944 | } |
| 14945 | |
| 14946 | return errorFlag; |
| 11665 | 14947 | } |
| 11666 | 14948 | |
| 11667 | | /*------------------------------------------------------------------ |
| 11668 | | UpdateAllCheatInfo - update all cheat info when database loaded |
| 11669 | | ------------------------------------------------------------------*/ |
| 14949 | /*---------------------------------------- |
| 14950 | CheckCodeFormat - code format checker |
| 14951 | ----------------------------------------*/ |
| 11670 | 14952 | |
| 11671 | | static void UpdateAllCheatInfo(void) |
| 14953 | static void CheckCodeFormat(CheatEntry * entry) |
| 11672 | 14954 | { |
| 11673 | | int i; |
| 14955 | int i; |
| 14956 | UINT8 isError = 0; |
| 11674 | 14957 | |
| 11675 | | for(i = 0; i < cheatListLength; i++) |
| 11676 | | UpdateCheatInfo(&cheatList[i], 1); |
| 14958 | for(i = 0; i < entry->actionListLength; i++) |
| 14959 | { |
| 14960 | CheatAction * action = &entry->actionList[i]; |
| 14961 | |
| 14962 | if(AnalyseCodeFormat(entry, action)) |
| 14963 | isError = 1; |
| 14964 | } |
| 14965 | |
| 14966 | if(isError) |
| 14967 | { |
| 14968 | entry->flags |= kCheatFlag_HasWrongCode; |
| 14969 | messageType = kCheatMessage_WrongCode; |
| 14970 | messageTimer = DEFAULT_MESSAGE_TIME; |
| 14971 | } |
| 11677 | 14972 | } |
| 11678 | 14973 | |
| 11679 | | /*-------------------------------------------------- |
| 11680 | | UpdateCheatInfo - update entry, action and flag |
| 11681 | | --------------------------------------------------*/ |
| 14974 | /*------------------------------------------------------------------------------------------------- |
| 14975 | BuildLabelIndexTable - create index table for label-selection and calculate index table length |
| 14976 | -------------------------------------------------------------------------------------------------*/ |
| 11682 | 14977 | |
| 11683 | | static void UpdateCheatInfo(CheatEntry * entry, UINT8 isLoadTime) |
| 14978 | static void BuildLabelIndexTable(CheatEntry *entry) |
| 11684 | 14979 | { |
| 11685 | | int isOneShot = 1; |
| 11686 | | int isNull = 1; |
| 11687 | | int flags = 0; |
| 11688 | | int i; |
| 14980 | int i, j, length = 0; |
| 11689 | 14981 | |
| 11690 | | flags = entry->flags & kCheatFlag_PersistentMask; |
| 14982 | entry->labelIndexLength = 0; |
| 11691 | 14983 | |
| 11692 | | /* ---- is it label-selection ? ----- */ |
| 11693 | | if( (EXTRACT_FIELD(entry->actionList[0].type, LocationType) == kLocation_Custom) && |
| 11694 | | (EXTRACT_FIELD(entry->actionList[0].type, LocationParameter) == kCustomLocation_Select)) |
| 11695 | | flags |= kCheatFlag_Select; |
| 14984 | for(i = 0, j = 0; i < entry->actionListLength; i++) |
| 14985 | { |
| 14986 | CheatAction * action = &entry->actionList[i]; |
| 11696 | 14987 | |
| 11697 | | for(i = 0; i < entry->actionListLength; i++) |
| 14988 | if((action->flags && kActionFlag_Custom) && EXTRACT_FIELD(action->type, CodeType) == kCustomCode_LabelSelect) |
| 14989 | { |
| 14990 | entry->labelIndex = malloc_or_die(sizeof(entry->labelIndex) * (++entry->labelIndexLength + 1)); |
| 14991 | entry->labelIndex[j++] = i; |
| 14992 | |
| 14993 | length = action->data ? action->data + i : entry->actionListLength; |
| 14994 | } |
| 14995 | else if(EXTRACT_FIELD(action->type, Link) == kLink_Link) |
| 14996 | { |
| 14997 | if(length) |
| 14998 | { |
| 14999 | entry->labelIndex = realloc(entry->labelIndex, sizeof(entry->labelIndex) * (++entry->labelIndexLength + 1)); |
| 15000 | entry->labelIndex[j++] = i; |
| 15001 | } |
| 15002 | } |
| 15003 | } |
| 15004 | |
| 15005 | if(entry->labelIndexLength <= 1) |
| 11698 | 15006 | { |
| 11699 | | CheatAction * action = &entry->actionList[i]; |
| 15007 | logerror("cheat - BuildLabelIndexTable : %s fails to build due to invalid or no link\n", entry->name); |
| 15008 | return; |
| 15009 | } |
| 11700 | 15010 | |
| 11701 | | int isActionNull = 0; |
| 11702 | | UINT32 size; |
| 11703 | | UINT32 operation; |
| 11704 | | UINT32 actionFlags = action->flags & kActionFlag_PersistentMask; |
| 15011 | if(entry->flags & kCheatFlag_OneShot) |
| 15012 | entry->selection = 1; |
| 11705 | 15013 | |
| 11706 | | size = EXTRACT_FIELD(action->type, BytesUsed); |
| 15014 | //logerror("Cheat - Finish building index table for %s (length = %x)\n", entry->name, entry->labelIndexLength); |
| 15015 | //for(i = 0; i < entry->labelIndexLength; i++) |
| 15016 | // logerror("IndexTable[%x] = %x\n",i,entry->labelIndex[i]); |
| 11707 | 15017 | |
| 11708 | | operation = EXTRACT_FIELD(action->type, Operation) | EXTRACT_FIELD(action->type, OperationExtend) << 2; |
| 15018 | } |
| 11709 | 15019 | |
| 11710 | | /* ---- is it comment ? ----- */ |
| 11711 | | if( (EXTRACT_FIELD(action->type, LocationType) == kLocation_Custom) && |
| 11712 | | (EXTRACT_FIELD(action->type, LocationParameter) == kCustomLocation_Comment)) |
| 11713 | | isActionNull = 1; |
| 11714 | | else |
| 11715 | | isNull = 0; |
| 15020 | /*---------------- |
| 15021 | SetLayerIndex |
| 15022 | ----------------*/ |
| 11716 | 15023 | |
| 11717 | | /* ---- is it one shot ? ----- */ |
| 11718 | | if(!TEST_FIELD(action->type, OneShot)) |
| 11719 | | isOneShot = 0; |
| 15024 | static void SetLayerIndex(void) |
| 15025 | { |
| 15026 | int i, j; |
| 11720 | 15027 | |
| 11721 | | /* ---- is it value-selection ? ----- */ |
| 11722 | | if(TEST_FIELD(action->type, UserSelectEnable)) |
| 11723 | | flags |= kCheatFlag_UserSelect; |
| 15028 | for(i = 0; i < cheatListLength; i++) |
| 15029 | { |
| 15030 | CheatEntry * entry = &cheatList[i]; |
| 11724 | 15031 | |
| 11725 | | /* ---- is it relative address ? ----- */ |
| 11726 | | if(EXTRACT_FIELD(action->type, LocationType) == kLocation_IndirectIndexed) |
| 11727 | | actionFlags |= kActionFlag_IgnoreMask; |
| 11728 | | else |
| 15032 | if(entry->flags & kCheatFlag_LayerIndex) |
| 11729 | 15033 | { |
| 11730 | | if(isLoadTime) |
| 15034 | int length = entry->actionList[0].extendData; |
| 15035 | |
| 15036 | if(length < cheatListLength && (i + length) <= cheatListLength) |
| 11731 | 15037 | { |
| 11732 | | /* ----- check for mask == 0 and fix when database loaded ----- */ |
| 11733 | | if((operation == kOperation_WriteMask) && (action->extendData == 0)) |
| 11734 | | action->extendData = ~0; |
| 15038 | entry->layerIndex = entry->actionList[0].address; |
| 15039 | |
| 15040 | for(j = i + 1; j <= i + length; j++) |
| 15041 | { |
| 15042 | CheatEntry * traverse = &cheatList[j]; |
| 15043 | |
| 15044 | if(!(traverse->flags & kCheatFlag_LayerIndex)) |
| 15045 | traverse->layerIndex = entry->actionList[0].data; |
| 15046 | } |
| 11735 | 15047 | } |
| 11736 | 15048 | } |
| 15049 | } |
| 15050 | } |
| 11737 | 15051 | |
| 11738 | | action->flags = actionFlags; |
| 15052 | /*----------------------------------------------------------------------------------------- |
| 15053 | DisplayCheatMessage - display cheat message via ui_draw_text_box instead of popup menu |
| 15054 | warning message is displayed with red back color |
| 15055 | -----------------------------------------------------------------------------------------*/ |
| 15056 | |
| 15057 | static void DisplayCheatMessage(void) |
| 15058 | { |
| 15059 | static const char *const kCheatMessageTable[] = { |
| 15060 | "INVALID MESSAGE!", // this message is unused |
| 15061 | "cheat option reloaded", |
| 15062 | "cheat code reloaded", |
| 15063 | "user defined search region reloaded", |
| 15064 | "failed to load database!", |
| 15065 | "cheats found", |
| 15066 | "1 result found, added to list", |
| 15067 | "succeeded to save", |
| 15068 | "failed to save!", |
| 15069 | "cheats saved", |
| 15070 | "activation key saved", |
| 15071 | "no activation key!", |
| 15072 | "pre-enable saved", |
| 15073 | "succeeded to add", |
| 15074 | "failed to add!", |
| 15075 | "succeeded to delete", |
| 15076 | "failed to delete!", |
| 15077 | "no search region!", |
| 15078 | "values restored", |
| 15079 | "there are no old values!", |
| 15080 | "saved all memory regions", |
| 15081 | "region invalidated remains results are", |
| 15082 | "debug mode only!", |
| 15083 | "found wrong code!" }; |
| 15084 | |
| 15085 | char buf[64]; |
| 15086 | |
| 15087 | if(!messageType) |
| 15088 | return; |
| 15089 | |
| 15090 | switch(messageType) |
| 15091 | { |
| 15092 | /* simple message */ |
| 15093 | default: |
| 15094 | sprintf(buf, "%s", kCheatMessageTable[messageType]); |
| 15095 | break; |
| 15096 | |
| 15097 | /* message with data */ |
| 15098 | case kCheatMessage_CheatFound: |
| 15099 | case kCheatMessage_InvalidatedRegion: |
| 15100 | { |
| 15101 | search_info *search = get_current_search(); |
| 15102 | |
| 15103 | sprintf(buf, "%d %s", search->num_results, kCheatMessageTable[messageType]); |
| 15104 | } |
| 15105 | break; |
| 15106 | |
| 15107 | case kCheatMessage_AllCheatSaved: |
| 15108 | sprintf(buf, "%d %s", cheatListLength, kCheatMessageTable[messageType]); |
| 15109 | break; |
| 11739 | 15110 | } |
| 11740 | 15111 | |
| 11741 | | /* ---- set one shot flag ----- */ |
| 11742 | | if(isOneShot) |
| 11743 | | flags |= kCheatFlag_OneShot; |
| 15112 | /* draw it */ |
| 15113 | switch(messageType) |
| 15114 | { |
| 15115 | default: |
| 15116 | ui_draw_text_box(buf, JUSTIFY_CENTER, 0.5f, 0.9f, UI_FILLCOLOR); |
| 15117 | break; |
| 11744 | 15118 | |
| 11745 | | /* ---- set null flag ----- */ |
| 11746 | | if(isNull) |
| 11747 | | flags |= kCheatFlag_Null; |
| 15119 | case kCheatMessage_None: |
| 15120 | case kCheatMessage_FailedToLoadDatabase: |
| 15121 | case kCheatMessage_FailedToSave: |
| 15122 | case kCheatMessage_NoActivationKey: |
| 15123 | case kCheatMessage_FailedToAdd: |
| 15124 | case kCheatMessage_FailedToDelete: |
| 15125 | case kCheatMessage_NoSearchRegion: |
| 15126 | case kCheatMessage_NoOldValue: |
| 15127 | case kCheatMessage_Max: |
| 15128 | case kCheatMessage_DebugOnly: |
| 15129 | case kCheatMessage_WrongCode: |
| 15130 | /* warning message has red background color */ |
| 15131 | ui_draw_text_box(buf, JUSTIFY_CENTER, 0.5f, 0.9f, UI_REDCOLOR); |
| 15132 | break; |
| 15133 | } |
| 11748 | 15134 | |
| 11749 | | entry->flags = (flags & kCheatFlag_InfoMask) | (entry->flags & ~kCheatFlag_InfoMask); |
| 15135 | /* decrement message timer */ |
| 15136 | if(--messageTimer == 0) |
| 15137 | messageType = 0; |
| 15138 | } |
| 11750 | 15139 | |
| 11751 | | if(isLoadTime) |
| 11752 | | entry->flags &= ~kCheatFlag_Dirty; |
| 15140 | /*--------------------- |
| 15141 | get_address_length |
| 15142 | ---------------------*/ |
| 15143 | |
| 15144 | static UINT8 get_address_length(UINT8 region) |
| 15145 | { |
| 15146 | if(region != CUSTOM_CODE) |
| 15147 | { |
| 15148 | cpu_region_info *info = get_cpu_or_region_info(region); |
| 15149 | |
| 15150 | if(info && info->type) |
| 15151 | return info->address_chars_needed; |
| 15152 | } |
| 15153 | |
| 15154 | return 8; |
| 11753 | 15155 | } |
| 11754 | 15156 | |
| 11755 | | /*-------------------------------------------------------------------------------- |
| 11756 | | IsAddressInRange - check an address is in range (1 = in range, 0 = out range) |
| 11757 | | --------------------------------------------------------------------------------*/ |
| 15157 | /*------------------ |
| 15158 | get_region_name |
| 15159 | ------------------*/ |
| 11758 | 15160 | |
| 11759 | | static int IsAddressInRange(CheatAction * action, UINT32 length) |
| 15161 | static char *get_region_name(UINT8 region) |
| 11760 | 15162 | { |
| 11761 | | UINT8 bytes = EXTRACT_FIELD(action->type, BytesUsed) + 1; |
| 15163 | if(TEST_FIELD(region, RegionIndex)) |
| 15164 | { |
| 15165 | if(region >= REGION_INVALID && region < REGION_MAX) |
| 15166 | return (char *)kRegionNames[EXTRACT_FIELD(region, RegionIndex)]; |
| 15167 | } |
| 15168 | else |
| 15169 | { |
| 15170 | if(VALID_CPU(region)) |
| 15171 | return (char *)kRegionNames[EXTRACT_FIELD(region, CPUIndex) + 1]; |
| 15172 | } |
| 11762 | 15173 | |
| 11763 | | return ((action->address + bytes) <= length); |
| 15174 | return (char *)kRegionNames[0]; |
| 11764 | 15175 | } |
| 11765 | 15176 | |
| 11766 | | /*--------------------------------------------------------------- |
| 11767 | | BuildCPUInfoList - get CPU info when initialize cheat system |
| 11768 | | ---------------------------------------------------------------*/ |
| 15177 | /*------------------------------------------------------------------------------------ |
| 15178 | build_cpu_region_info_list - get CPU and region info when initialize cheat system |
| 15179 | ------------------------------------------------------------------------------------*/ |
| 11769 | 15180 | |
| 11770 | | static void BuildCPUInfoList(running_machine *machine) |
| 15181 | static void build_cpu_region_info_list(running_machine *machine) |
| 11771 | 15182 | { |
| 11772 | | int i; |
| 15183 | int i; |
| 11773 | 15184 | |
| 11774 | | /* ----- do regions ----- */ |
| 15185 | /* do regions */ |
| 11775 | 15186 | { |
| 11776 | | const rom_entry * traverse = rom_first_region(machine->gamedrv); |
| 15187 | const rom_entry *traverse = rom_first_region(machine->gamedrv); |
| 11777 | 15188 | |
| 11778 | | memset(regionInfoList, 0, sizeof(CPUInfo) * kRegionListLength); |
| 15189 | memset(region_info_list, 0, sizeof(cpu_region_info) * REGION_LIST_LENGTH); |
| 11779 | 15190 | |
| 11780 | 15191 | while(traverse) |
| 11781 | 15192 | { |
| 11782 | 15193 | if(ROMENTRY_ISREGION(traverse)) |
| 11783 | 15194 | { |
| 11784 | | UINT8 regionType = ROMREGION_GETTYPE(traverse); |
| 15195 | UINT8 region_type = ROMREGION_GETTYPE(traverse); |
| 11785 | 15196 | |
| 11786 | | /* ----- non-cpu region ? ----- */ |
| 11787 | | if((regionType >= REGION_GFX1) && (regionType <= REGION_USER8)) |
| 15197 | /* non-cpu region */ |
| 15198 | if(region_type >= REGION_GFX1 && region_type <= REGION_PLDS) |
| 11788 | 15199 | { |
| 11789 | | CPUInfo * info = ®ionInfoList[regionType - REGION_INVALID]; |
| 11790 | | UINT32 length = memory_region_length(regionType); |
| 11791 | | int bitState = 0; |
| 15200 | UINT8 bit_state = 0; |
| 15201 | UINT32 length = memory_region_length(region_type); |
| 15202 | cpu_region_info *info = ®ion_info_list[region_type - REGION_INVALID]; |
| 11792 | 15203 | |
| 11793 | | info->type = regionType; |
| 11794 | | info->dataBits = ROMREGION_GETWIDTH(traverse); |
| 15204 | info->type = region_type; |
| 15205 | info->data_bits = ROMREGION_GETWIDTH(traverse); |
| 15206 | info->address_bits = 0; |
| 15207 | info->address_mask = length; |
| 15208 | info->address_chars_needed = info->address_bits >> 2; |
| 15209 | info->endianness = ROMREGION_ISBIGENDIAN(traverse); |
| 11795 | 15210 | |
| 11796 | | info->addressBits = 0; |
| 11797 | | info->addressMask = length; |
| 15211 | if(info->address_bits & 3) |
| 15212 | info->address_chars_needed++; |
| 11798 | 15213 | |
| 11799 | | /* ----- build address mask ----- */ |
| 15214 | /* build address mask */ |
| 11800 | 15215 | for(i = 0; i < 32; i++) |
| 11801 | 15216 | { |
| 11802 | | UINT32 mask = 1 << (31 - i); |
| 15217 | UINT32 mask = 1 << (31 - i); |
| 11803 | 15218 | |
| 11804 | | if(bitState) |
| 11805 | | info->addressMask |= mask; |
| 15219 | if(bit_state) |
| 15220 | info->address_mask |= mask; |
| 11806 | 15221 | else |
| 11807 | 15222 | { |
| 11808 | | if(info->addressMask & mask) |
| 15223 | if(info->address_mask & mask) |
| 11809 | 15224 | { |
| 11810 | | info->addressBits = 32 - i; |
| 11811 | | bitState = 1; |
| 15225 | info->address_bits = 32 - i; |
| 15226 | bit_state = 1; |
| 11812 | 15227 | } |
| 11813 | 15228 | } |
| 11814 | 15229 | } |
| 11815 | | |
| 11816 | | info->addressCharsNeeded = info->addressBits >> 2; |
| 11817 | | |
| 11818 | | if(info->addressBits & 3) |
| 11819 | | info->addressCharsNeeded++; |
| 11820 | | |
| 11821 | | info->endianness = ROMREGION_ISBIGENDIAN(traverse); |
| 11822 | 15230 | } |
| 11823 | 15231 | } |
| 11824 | 15232 | |
| r2762 | r2763 | |
| 11826 | 15234 | } |
| 11827 | 15235 | } |
| 11828 | 15236 | |
| 11829 | | /* ----- do CPUs ----- */ |
| 15237 | /* do CPUs */ |
| 11830 | 15238 | { |
| 11831 | | memset(cpuInfoList, 0, sizeof(CPUInfo) * MAX_CPU); |
| 15239 | memset(cpu_info_list, 0, sizeof(cpu_region_info) * MAX_CPU); |
| 11832 | 15240 | |
| 11833 | 15241 | for(i = 0; i < cpu_gettotalcpu(); i++) |
| 11834 | 15242 | { |
| 11835 | | CPUInfo * info = &cpuInfoList[i]; |
| 11836 | | CPUInfo * regionInfo = ®ionInfoList[REGION_CPU1 + i - REGION_INVALID]; |
| 15243 | cpu_region_info *cpu_info = &cpu_info_list[i]; |
| 15244 | cpu_region_info *region_info = ®ion_info_list[REGION_CPU1 + i - REGION_INVALID]; |
| 15245 | cpu_type type = machine->config->cpu[i].type; |
| 11837 | 15246 | |
| 11838 | | cpu_type type = machine->config->cpu[i].type; |
| 15247 | cpu_info->type = type; |
| 15248 | cpu_info->data_bits = cputype_databus_width(type, ADDRESS_SPACE_PROGRAM); |
| 15249 | cpu_info->address_bits = cputype_addrbus_width(type, ADDRESS_SPACE_PROGRAM); |
| 15250 | cpu_info->address_mask = 0xFFFFFFFF >> (32 - cpu_info->address_bits); |
| 15251 | cpu_info->address_chars_needed = cpu_info->address_bits >> 2; |
| 15252 | cpu_info->endianness = (cputype_endianness(type) == CPU_IS_BE); |
| 15253 | cpu_info->address_shift = cputype_addrbus_shift(type, ADDRESS_SPACE_PROGRAM); |
| 11839 | 15254 | |
| 11840 | | info->type = type; |
| 11841 | | info->dataBits = cputype_databus_width(type, ADDRESS_SPACE_PROGRAM); |
| 11842 | | info->addressBits = cputype_addrbus_width(type, ADDRESS_SPACE_PROGRAM); |
| 11843 | | info->addressMask = 0xFFFFFFFF >> (32 - cputype_addrbus_width(type, ADDRESS_SPACE_PROGRAM)); |
| 15255 | if(cpu_info->address_bits & 0x3) |
| 15256 | cpu_info->address_chars_needed++; |
| 11844 | 15257 | |
| 11845 | | info->addressCharsNeeded = info->addressBits >> 2; |
| 11846 | | if(info->addressBits & 0x3) |
| 11847 | | info->addressCharsNeeded++; |
| 11848 | | |
| 11849 | | info->endianness = (cputype_endianness(type) == CPU_IS_BE); |
| 11850 | | |
| 11851 | | switch(type) |
| 11852 | | { |
| 11853 | | #if HAS_TMS34010 |
| 11854 | | case CPU_TMS34010: |
| 11855 | | info->addressShift = 3; |
| 11856 | | break; |
| 11857 | | #endif |
| 11858 | | #if HAS_TMS34020 |
| 11859 | | case CPU_TMS34020: |
| 11860 | | info->addressShift = 3; |
| 11861 | | break; |
| 11862 | | #endif |
| 11863 | | default: |
| 11864 | | info->addressShift = 0; |
| 11865 | | break; |
| 11866 | | } |
| 11867 | | |
| 11868 | | /* ----- copy to region list ----- */ |
| 11869 | | memcpy(regionInfo, info, sizeof(CPUInfo)); |
| 15258 | /* copy CPU info to region info */ |
| 15259 | memcpy(region_info, cpu_info, sizeof(cpu_region_info)); |
| 11870 | 15260 | } |
| 11871 | 15261 | } |
| 11872 | 15262 | } |
| 11873 | | |