RetroAchievements / rcheevos

Library to parse and evaluate achievements and leaderboards for RetroAchievements
MIT License
86 stars 33 forks source link

Add Accumulator Function for Remembering and Recalling a value. #343

Closed redwizard42 closed 3 months ago

redwizard42 commented 3 months ago

Adds a Remember condition to store a value into a designated accumulator for the current group (core, alt1, etc). Defaults to accepting a single operand or can specify an operator and a second operand. At the beginning of an evaluation, the accumulator holds an unsigned integer with value 0.

Adds a Recall operand which evaluates to the value of the group's accumulator.

The Remember condition is a combining condition (similar to Add Source and Add Address) and does not break a chain.

redwizard42 commented 3 months ago

Example use case:

Access data at a calculated location at the end of a pointer. Recalled value at the Add Address Line below evaluations to Pointer Value + (16-Bit Value at 0x1234) * 8 + 4. The 8-bit value at this location is then compared to 0x1c.

Remember    Mem    16-Bit 0x1234 * Value        0x08
Remember    Recall               + Value        0x04
Remember    Recall               + Mem   32-Bit Pointer 
Add Address Recall
            Mem    8-Bit  0x00   = Value        0x1c
Or, just remember a value to use later: ID Flag Type Size Memory Cmp Type Size Mem/Val Hits
1 Remember Mem 16-bit 0x1234 - Delta 16-Bit 0x1224
2 And Next Recall = Value 0x05
3 Add Hits Mem 8-Bit 0x1000 = Value 0x03 1 (0)
4 And Next Recall = Value 0x14
5 Add Hits Mem 8-Bit 0x1000 = Value 0x03 1 (0)
6 And Next Recall = Value 0x14
7 Add Hits Mem 8-Bit 0x1000 = Value 0x03 1 (0)
8 Measured Value 0x00 = Value 0x00 3 (0)
redwizard42 commented 3 months ago

Comments, indentation, etc should all be cleaned up now.

PopovMark commented 3 months ago

Is there only one slot for the accumulator or will you do multiple, kinda like variables? From what I can tell you can only store one value at any given time, why not make it 4 or 8 values?