Mateusz Faderewski 01968b55db
Cheats support (backend only) (#94)
<!--- Provide a general summary of your changes in the Title above -->

## Description
This PR implements cheat support (patcher + engine) with a simple API to
provide Action Replay/Game Shark compatible cheats (with exception of
cheats that utilize GS button).

API consist of a single pointer to an array of the cheats ended with a
double zero entry,
For example, if you want to pass these cheats to the patcher:
```
D01F9B91 0020 // Majora's Mask (USA) Inventory Editor
803FDA3F 0002
```
Put cheats in a `uint32_t` array as such (notice last two entries are
zeros):
```
uint32_t cheats[] = {
    0xD01F9B91,
    0x0020,
    0x803FDA3F,
    0x0002,
    0,
    0,
};
```
And pass this array as a boot parameter: `menu->boot_params->cheat_list
= cheats;`

<!--- Describe your changes in detail -->

## Motivation and Context
To provide users with ability to run game modifications in a easy way.
<!--- What does this sample do? What problem does it solve? -->
<!--- If it fixes/closes/resolves an open issue, please link to the
issue here -->

## How Has This Been Tested?
On a SummerCart64 flashcart + assembly instructions generation verified
in ares emulator via GDB.
<!-- (if applicable) -->
<!--- Please describe in detail how you tested your sample/changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->

## Screenshots
No screenshots
<!-- (if appropriate): -->

## Types of changes
<!--- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->
- [x] Improvement (non-breaking change that adds a new feature)
- [ ] Bug fix (fixes an issue)
- [ ] Breaking change (breaking change)
- [ ] Config and build (change in the configuration and build system,
has no impact on code or features)

## Checklist:
<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
- [x] My code follows the code style of this project.
- [x] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [ ] I have added tests to cover my changes.
- [ ] All new and existing tests passed.

<!--- It would be nice if you could sign off your contribution by
replacing the name with your GitHub user name and GitHub email contact.
-->
Signed-off-by: Polprzewodnikowy <sc@mateuszfaderewski.pl>
2024-05-05 00:19:20 +02:00

98 lines
1.8 KiB
ArmAsm

#include "reboot.h"
#define IPL3_ENTRY 0xA4000040
#define REBOOT_ADDRESS 0xA4001000
#define STACK_ADDRESS 0xA4001FF0
#define RI_ADDRESS 0xA4700000
#define RI_SELECT 0x0C
#define RI_REFRESH 0x10
.set noat
.section .text.reboot, "ax", %progbits
reboot_start:
.global reboot_start
# NOTE: CIC x105 requirement
ipl2:
.set noreorder
lui $t5, 0xBFC0
1:
lw $t0, 0x7FC($t5)
addiu $t5, $t5, 0x7C0
andi $t0, $t0, 0x80
bnel $t0, $zero, 1b
lui $t5, 0xBFC0
lw $t0, 0x24($t5)
lui $t3, 0xB000
.set reorder
reboot_entry:
.set reboot, REBOOT_ADDRESS + (. - reboot_start)
.global reboot
li $sp, STACK_ADDRESS
bnez $a0, reset_rdram_skip # Skip when cheats are enabled
bnez $s5, reset_rdram_skip # Skip when reset type is set to NMI
reset_rdram:
li $t0, RI_ADDRESS
sw $zero, RI_REFRESH($t0)
sw $zero, RI_SELECT($t0)
reset_rdram_skip:
detect_console_region:
li $t0, 1
beq $s4, $zero, pal_console
beq $s4, $t0, ntsc_console
b mpal_console
pal_console:
li $ra, 0xA4001554
b prepare_registers
ntsc_console:
li $ra, 0xA4001550
b prepare_registers
mpal_console:
li $ra, 0xA4001554
prepare_registers:
move $at, $zero
move $v0, $zero
move $v1, $zero
move $a0, $zero
move $a1, $zero
move $a2, $zero
move $a3, $zero
move $t0, $zero
move $t1, $zero
li $t2, 0x40
move $t4, $zero
move $t5, $zero
move $t6, $zero
move $t7, $zero
move $s0, $zero
move $s1, $zero
move $s2, $zero
move $t8, $zero
move $t9, $zero
move $k0, $zero
move $k1, $zero
move $gp, $zero
move $fp, $zero
run_ipl3:
li $t3, IPL3_ENTRY
jr $t3
.set reboot_size, (. - reboot_start)
.global reboot_size