MCPcopy Create free account
hub / github.com/BlitterStudio/amiberry / debug_trainer_enable

Function debug_trainer_enable

src/debug.cpp:9019–9116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9017}
9018
9019static void debug_trainer_enable(struct trainerpatch *tp, bool enable)
9020{
9021 if (tp->enabled == enable)
9022 return;
9023
9024 if (tp->replacedata) {
9025 if (enable) {
9026 bool first = false;
9027 if (!tp->replacedata_original) {
9028 tp->replacedata_original = xcalloc(uae_u16, tp->replacelength);
9029 first = true;
9030 }
9031 for (int j = 0; j < tp->replacelength; j++) {
9032 uae_u16 v = tp->replacedata[j];
9033 uae_u16 m = tp->replacemaskdata[j];
9034 uaecptr addr = (tp->addr - tp->offset * 2) + j * 2 + tp->replaceoffset * 2;
9035 if (m == 0xffff) {
9036 x_put_word(addr, v);
9037 } else {
9038 uae_u16 vo = x_get_word(addr);
9039 x_put_word(addr, (vo & ~m) | (v & m));
9040 if (first)
9041 tp->replacedata_original[j] = vo;
9042 }
9043 }
9044 } else if (tp->replacedata_original) {
9045 for (int j = 0; j < tp->replacelength; j++) {
9046 uae_u16 m = tp->replacemaskdata[j];
9047 uaecptr addr = (tp->addr - tp->offset * 2) + j * 2 + tp->replaceoffset * 2;
9048 if (m != 0xffff) {
9049 x_put_word(addr, tp->replacedata_original[j]);
9050 }
9051 }
9052 }
9053 }
9054
9055 if (tp->patchtype == TRAINER_SETONCE && tp->varaddr != 0xffffffff) {
9056 uae_u32 v = enable ? tp->setvalue : tp->oldval;
9057 switch (tp->varsize)
9058 {
9059 case 1:
9060 x_put_byte(tp->varaddr, tp->setvalue);
9061 break;
9062 case 2:
9063 x_put_word(tp->varaddr, tp->setvalue);
9064 break;
9065 case 4:
9066 x_put_long(tp->varaddr, tp->setvalue);
9067 break;
9068 }
9069 }
9070
9071 if ((tp->patchtype == TRAINER_NOP || tp->patchtype == TRAINER_FREEZE || tp->patchtype == TRAINER_SET) && tp->varaddr != 0xffffffff) {
9072 struct memwatch_node *mwn;
9073 if (!memwatch_enabled)
9074 initialize_memwatch(0);
9075 if (enable) {
9076 int i;

Callers 2

debug_trainer_matchFunction · 0.85
debug_trainer_eventFunction · 0.85

Calls 4

initialize_memwatchFunction · 0.85
memwatch_setupFunction · 0.85
memwatch_dump2Function · 0.85
write_logFunction · 0.70

Tested by

no test coverage detected