Organizing files

This commit is contained in:
Remnants of Forgotten Disney 2024-03-19 13:52:23 -05:00
parent 22fc6ee9d2
commit 53e7748d48
41 changed files with 32 additions and 490 deletions

View File

@ -5,7 +5,7 @@
#include <tonc.h>
#include <string>
#include "LinkSPI.hpp"
#include "libraries/gba-link-connection/LinkSPI.hpp"
/*
#define LINK_SPI_NO_DATA 0xffffffff

View File

@ -1,4 +1,5 @@
//Created by Lorenzooone https://github.com/Lorenzooone/Pokemon-Gen3-to-Gen-X
// Originally created by Lorenzooone and modified with their permission
// Source: https://github.com/Lorenzooone/Pokemon-Gen3-to-Gen-X
#ifndef BASE_INCLUDE__
#define BASE_INCLUDE__

View File

@ -1,4 +1,5 @@
//Created by Lorenzooone https://github.com/Lorenzooone/Pokemon-Gen3-to-Gen-X
// Originally created by Lorenzooone and modified with their permission
// Source: https://github.com/Lorenzooone/Pokemon-Gen3-to-Gen-X
#ifndef DELAYS__
#define DELAYS__

View File

@ -1,4 +1,5 @@
//Created by Lorenzooone https://github.com/Lorenzooone/Pokemon-Gen3-to-Gen-X
// Originally created by Lorenzooone and modified with their permission
// Source: https://github.com/Lorenzooone/Pokemon-Gen3-to-Gen-X
#ifndef SAVE__
#define SAVE__

View File

@ -1,4 +1,5 @@
//Created by Lorenzooone https://github.com/Lorenzooone/Pokemon-Gen3-to-Gen-X
// Originally created by Lorenzooone and modified with their permission
// Source: https://github.com/Lorenzooone/Pokemon-Gen3-to-Gen-X
#ifndef TIMING_BASIC__
#define TIMING_BASIC__

View File

@ -1,4 +1,5 @@
//Created by Lorenzooone https://github.com/Lorenzooone/Pokemon-Gen3-to-Gen-X
// Originally created by Lorenzooone and modified with their permission
// Source: https://github.com/Lorenzooone/Pokemon-Gen3-to-Gen-X
#ifndef USEFUL_QUALIFIERS__
#define USEFUL_QUALIFIERS__

View File

@ -1,10 +1,11 @@
//Created by Lorenzooone https://github.com/Lorenzooone/Pokemon-Gen3-to-Gen-X
// Originally created by Lorenzooone and modified with their permission
// Source: https://github.com/Lorenzooone/Pokemon-Gen3-to-Gen-X
#include "base_include.h"
#include "libraries/Pokemon-Gen3-to-Gen-X/include/base_include.h"
#include <stddef.h>
#include "useful_qualifiers.h"
#include "timing_basic.h"
#include "delays.h"
#include "libraries/Pokemon-Gen3-to-Gen-X/include/useful_qualifiers.h"
#include "libraries/Pokemon-Gen3-to-Gen-X/include/timing_basic.h"
#include "libraries/Pokemon-Gen3-to-Gen-X/include/delays.h"
#define NUM_CYCLES_PER_ITER 4
#define NUM_CYCLES_PER_ITER_CHECK 8

View File

@ -1,19 +0,0 @@
//Created by Laqieer https://github.com/laqieer/libsavgba
const char * const SavErrCodes[] = {
"E_SUCCESS",
"E_INVALID_PARAM",
"E_OUT_OF_RANGE",
"E_VERIFY_FAIL",
"E_UNSUPPORTED_DEVICE",
"E_TIMEOUT",
};
const char * const SavErrMsgs[] = {
"No error",
"Invalid input parameter",
"Address is out of range",
"Failed to verify written data",
"Device type is not supported",
"Operation timeout",
};

View File

@ -3,7 +3,7 @@
#include "flash_mem.h"
#include "pokemon.h"
#include "rom_data.h"
#include "save.h"
#include "libraries/Pokemon-Gen3-to-Gen-X/include/save.h"
#define pkmn_length 80
#define READ_SAVE_SECTIONS 5

View File

@ -1,4 +1,5 @@
// Original code created by StevenChaulk https://github.com/stevenchaulk/arduino-poke-gen2
// Loosely based on code created by StevenChaulk
// Source: https://github.com/stevenchaulk/arduino-poke-gen2
#include <tonc.h>
#include <string>

View File

@ -1,18 +0,0 @@
#include "interrupt.h"
#include "libugba/include/ugba.h"
void interrupt_init(void) {
IRQ_Init();
}
void interrupt_set_handler(interrupt_index index, interrupt_vector function) {
IRQ_SetHandler((irq_index)index, function);
}
void interrupt_enable(interrupt_index index) {
IRQ_Enable((irq_index)index);
}
void interrupt_disable(interrupt_index index) {
IRQ_Disable((irq_index)index);
}

View File

@ -1,79 +0,0 @@
// SPDX-License-Identifier: MIT
//
// Copyright (c) 2020 Antonio Niño Díaz
#include "libugba/include/ugba.h"
#define BIOS_GLOBAL_IRQ_HANDLER *(irq_vector *)(0x03007FFC)
extern void IRQ_GlobalInterruptHandler(void); // Assembly
irq_vector IRQ_VectorTable[IRQ_NUMBER];
void IRQ_Init(void)
{
REG_IME = 0;
for (int i = 0; i < IRQ_NUMBER; i ++)
IRQ_VectorTable[i] = NULL;
BIOS_GLOBAL_IRQ_HANDLER = IRQ_GlobalInterruptHandler;
REG_IE = 0;
REG_IF = 0x3FFF; // Clear IF
// Enable interrupts after clearing the flags
REG_IME = 1;
}
void IRQ_SetHandler(irq_index index, irq_vector function)
{
if (index < IRQ_NUMBER)
IRQ_VectorTable[index] = function;
}
void IRQ_Enable(irq_index index)
{
if (index >= IRQ_NUMBER)
return;
// Entering critical section. Disable interrupts.
uint16_t old_ime = REG_IME;
REG_IME = 0;
if (index == IRQ_VBLANK)
REG_DISPSTAT |= DISPSTAT_VBLANK_IRQ_ENABLE;
else if (index == IRQ_HBLANK)
REG_DISPSTAT |= DISPSTAT_HBLANK_IRQ_ENABLE;
else if (index == IRQ_VCOUNT)
REG_DISPSTAT |= DISPSTAT_VCOUNT_IRQ_ENABLE;
REG_IE |= (1 << index);
REG_IME = old_ime;
}
void IRQ_Disable(irq_index index)
{
if (index >= IRQ_NUMBER)
return;
uint16_t old_ime = REG_IME;
// Entering critical section. Disable interrupts.
REG_IME = 0;
if (index == IRQ_VBLANK)
REG_DISPSTAT &= ~DISPSTAT_VBLANK_IRQ_ENABLE;
else if (index == IRQ_HBLANK)
REG_DISPSTAT &= ~DISPSTAT_HBLANK_IRQ_ENABLE;
else if (index == IRQ_VCOUNT)
REG_DISPSTAT &= ~DISPSTAT_VCOUNT_IRQ_ENABLE;
REG_IE &= ~(1 << index);
REG_IME = old_ime;
}

View File

@ -1,210 +0,0 @@
// SPDX-License-Identifier: MIT
//
// Copyright (c) 2020-2022 Antonio Niño Díaz
.section .iwram, "ax", %progbits
.code 32
.set MEM_IO_ADDR, 0x04000000
.set OFFSET_IE, 0x200
.set OFFSET_IF, 0x202
.set OFFSET_IME, 0x208
.global IRQ_GlobalInterruptHandler
IRQ_GlobalInterruptHandler:
// Get the pending interrupts that the user actually cares about. If
// something isn't set in IE, ignore it.
mov r0, #MEM_IO_ADDR // r0 = MEM_IO_ADDR
ldr r1, [r0, #OFFSET_IE] // r1 = REG_IE | (REG_IF << 16)
and r1, r1, r1, lsr #16 // r1 = REG_IE & REG_IF
// Iterate from BIT(0) to BIT(13)
.extern IRQ_VectorTable
// Notes on the default priority of interrupts:
//
// - HBLANK is first because it's very short, so saving a few cycles is
// important, specially because it is called every scanline.
// - VCOUNT is second because it's similar to HBLANK, but it is triggered
// less often. However, it needs higher priority than VBL because they
// are both triggered at the same time when VBL starts, and VBL is much
// longer.
ldr r3, =IRQ_VectorTable + 4
mov r2, #(1 << 1) // HBLANK
tst r1, r2
bne interrupt_found
add r3, r3, #4
mov r2, #(1 << 2) // VCOUNT
tst r1, r2
bne interrupt_found
sub r3, r3, #8
mov r2, #(1 << 0) // VBLANK
tst r1, r2
bne interrupt_found
add r3, r3, #12
mov r2, #(1 << 3) // TIMER0
tst r1, r2
bne interrupt_found
add r3, r3, #4
mov r2, #(1 << 4) // TIMER1
tst r1, r2
bne interrupt_found
add r3, r3, #4
mov r2, #(1 << 5) // TIMER2
tst r1, r2
bne interrupt_found
add r3, r3, #4
mov r2, #(1 << 6) // TIMER3
tst r1, r2
bne interrupt_found
add r3, r3, #4
mov r2, #(1 << 7) // SERIAL
tst r1, r2
bne interrupt_found
add r3, r3, #4
mov r2, #(1 << 8) // DMA0
tst r1, r2
bne interrupt_found
add r3, r3, #4
mov r2, #(1 << 9) // DMA1
tst r1, r2
bne interrupt_found
add r3, r3, #4
mov r2, #(1 << 10) // DMA2
tst r1, r2
bne interrupt_found
add r3, r3, #4
mov r2, #(1 << 11) // DMA3
tst r1, r2
bne interrupt_found
add r3, r3, #4
mov r2, #(1 << 12) // KEYPAD
tst r1, r2
bne interrupt_found
add r3, r3, #4
mov r2, #(1 << 13) // GAMEPAK
tst r1, r2
bne interrupt_found
// If no interrupt flag is set, fall to the next section of code.
// If no interrupt handlers have to be called, clear all bits in the IF and
// BIOS flags register.
add r3, r0, #(OFFSET_IF & 0xFF00)
orr r3, r3, #(OFFSET_IF & 0xFF)
ldrh r1, [r3]
strh r1, [r3]
ldrh r2, [r0, #-8] // The BIOS register is mirrored at 0x03FFFFF8
orr r2, r2, r1
strh r2, [r0, #-8]
bx lr
// This point is reached if there is at least one bit set in IF & IE
interrupt_found:
// r0 = REG_BASE
// r2 = IRQ bit of the current vector
// r3 = Pointer to vector to jump to
// Write bit to IF and the BIOS register to acknowledge this interrupt, but
// leave the others alone.
add r1, r0, #(OFFSET_IF & 0xFF00)
orr r1, r1, #(OFFSET_IF & 0xFF)
strh r2, [r1]
// The BIOS register (BIOS_INTR_FLAGS) is mirrored at 0x03FFFFF8
ldrh r1, [r0, #-8]
orr r1, r1, r2
strh r1, [r0, #-8]
// If the interrupt handler is null, exit handler
ldr r3, [r3]
cmp r3, #0
bxeq lr
// If this point is reached, there is a valid interrupt handler
// r0 = REG_BASE
// r3 = Vector to jump to
// Clear IME so that we don't get any nested interrupt during the handler of
// the current one. At the same time, the old value is preserved so that it
// can be restored after the end of the interrupt handler. Note that it is
// safe to access IME in 32-bit accesses.
add r2, r0, #(OFFSET_IME & 0xFF00)
orr r2, r2, #(OFFSET_IME & 0xFF)
mov r1, #0
swp r1, r1, [r2]
// Get current spsr
mrs r2, spsr
// Push old IME, spsr and lr
stmfd sp!, {r1-r2, lr}
.equ MODE_IRQ, 0x12
.equ MODE_SYSTEM, 0x1F
.equ MODE_MASK, 0x1F
.equ FLAG_IRQ_DISABLE, 1 << 7
// Set CPU mode to system (like user, but privileged, so we can go back to
// mode IRQ later). Re-enable the master IRQ bit in CPSR so that the
// interrupt handler can re-enable interrupts by setting IME to 1.
mrs r2, cpsr
//bic r2, r2, #MODE_MASK // Not needed for MODE_SYSTEM
bic r2, r2, #FLAG_IRQ_DISABLE
orr r2, r2, #MODE_SYSTEM
msr cpsr, r2
// Call interrupt handler
push {lr}
mov lr, pc
bx r3
pop {lr}
// Disable interrupts while switching modes
mov r0, #MEM_IO_ADDR
str r0, [r0, #OFFSET_IME]
// Set CPU mode to IRQ. Disable interrupts so that setting IME to 1
// afterwards doesn't let the CPU jump to the interrupt handler.
mrs r2, cpsr
bic r2, r2, #MODE_MASK
orr r2, r2, #(MODE_IRQ | FLAG_IRQ_DISABLE)
msr cpsr, r2
// Pop old IME, spsr and lr
ldmfd sp!, {r1-r2, lr}
// Restore spsr
msr spsr, r2
// Restore old IME
str r1, [r0, #OFFSET_IME]
bx lr
.end

View File

@ -1,127 +0,0 @@
// Original code created by afska https://github.com/afska/gba-link-connection/tree/master
#include <tonc.h>
#include <string>
// (0) Include the header
#include "LinkSPI.hpp"
// (1) Create a LinkSPI instance
LinkSPI* linkSPI = new LinkSPI();
void cable_init() {
// (2) Add the interrupt service routines
/* LIBUGBA setup:
interrupt_init();
interrupt_set_handler(INTR_VBLANK, VBLANK);
interrupt_enable(INTR_VBLANK);
interrupt_set_handler(INTR_SERIAL, LINK_SPI_ISR_SERIAL);
interrupt_enable(INTR_SERIAL);
*/
irq_init(NULL);
irq_enable(II_VBLANK);
irq_add(II_SERIAL, LINK_SPI_ISR_SERIAL);
}
int example_main() {
cable_init();
bool firstTransfer = false;
bool async = false;
u32 counter = 0;
while (true) {
std::string output = "";
u16 keys = ~REG_KEYS & KEY_ANY;
if (!linkSPI->isActive()) {
firstTransfer = true;
output += "START: Set as Master\n";
output += "SELECT: Set as Slave\n";
output += "\n(stop: press L+R)\n";
output += "(hold A on start for async)\n";
output += "(hold B on start for waitMode)\n";
output +=
"\n\n\n\n\n\n\n\n\n\n\n\n[!] to test this demo...\n "
"...use a GBC Link Cable!";
if ((keys & KEY_START) | (keys & KEY_SELECT)) {
// (3) Initialize the library
linkSPI->activate((keys & KEY_START) ? LinkSPI::Mode::MASTER_256KBPS
: LinkSPI::Mode::SLAVE);
linkSPI->setWaitModeActive(keys &
KEY_B); // see `waitMode` in README.md
if (keys & KEY_A)
async = true;
}
} else {
// Title
auto modeName =
linkSPI->getMode() == LinkSPI::Mode::SLAVE ? "[slave]" : "[master]";
output += std::string(modeName) + "\n";
if (firstTransfer) {
log(output + "Waiting...");
firstTransfer = false;
}
if (!async) {
// (4)/(5) Exchange 32-bit data with the other end
u32 remoteKeys = linkSPI->transfer(keys, []() {
u16 keys = ~REG_KEYS & KEY_ANY;
return (keys & KEY_L) && (keys & KEY_R);
});
output += "> " + std::to_string(keys) + "\n";
output += "< " + std::to_string(remoteKeys) + "\n";
} else {
// (6) Exchange data asynchronously
if (keys != 0 &&
linkSPI->getAsyncState() == LinkSPI::AsyncState::IDLE) {
counter++;
linkSPI->transferAsync(counter, []() {
u16 keys = ~REG_KEYS & KEY_ANY;
return (keys & KEY_L) && (keys & KEY_R);
});
log(output + ">> " + std::to_string(counter));
wait(228 * 60);
}
if (linkSPI->getAsyncState() == LinkSPI::AsyncState::READY) {
log(output + "<< " + std::to_string(linkSPI->getAsyncData()));
wait(228 * 60);
}
}
// Cancel
if ((keys & KEY_L) && (keys & KEY_R)) {
linkSPI->deactivate();
async = false;
counter = 0;
}
}
// Print
VBlankIntrWait();
log(output);
}
return 0;
}
void log(std::string text) {
tte_erase_screen();
tte_write("#{P:0,0}");
tte_write(text.c_str());
}
void wait(u32 verticalLines) {
u32 count = 0;
u32 vCount = REG_VCOUNT;
while (count < verticalLines) {
if (REG_VCOUNT != vCount) {
count++;
vCount = REG_VCOUNT;
}
};
}

View File

@ -27,7 +27,7 @@
#include "mystery_gift_injector.h"
#include "mystery_gift_builder.h"
#include "rom_data.h"
#include "save.h"
#include "libraries/Pokemon-Gen3-to-Gen-X/include/save.h"
/*

View File

@ -1,14 +0,0 @@
// SPDX-License-Identifier: LGPL-3.0-only
//
// Copyright (c) 2020 Antonio Niño Díaz
#include <stdint.h>
#define MEM_IO_SIZE (0x00000400)
uint64_t internal_io[MEM_IO_SIZE / sizeof(uint64_t)];
uintptr_t UGBA_MemIO(void)
{
return (uintptr_t)(&internal_io[0]);
}

View File

@ -3,7 +3,7 @@
#include "flash_mem.h"
#include "mystery_gift_builder.h"
#include "rom_data.h"
#include "save.h"
#include "libraries/Pokemon-Gen3-to-Gen-X/include/save.h"
#include "pokemon_data.h"
// This will need to be modified for the JP releases

View File

@ -1,11 +1,14 @@
//Created by Lorenzooone https://github.com/Lorenzooone/Pokemon-Gen3-to-Gen-X
// Originally created by Lorenzooone and modified with their permission
// Source: https://github.com/Lorenzooone/Pokemon-Gen3-to-Gen-X
#include "libraries/Pokemon-Gen3-to-Gen-X/include/base_include.h"
#include "libraries/Pokemon-Gen3-to-Gen-X/include/delays.h"
#include "libraries/Pokemon-Gen3-to-Gen-X/include/save.h"
#include "libraries/Pokemon-Gen3-to-Gen-X/include/useful_qualifiers.h"
#include "libraries/Pokemon-Gen3-to-Gen-X/include/timing_basic.h"
#include "base_include.h"
#include "save.h"
#include <stddef.h>
#include "useful_qualifiers.h"
#include "timing_basic.h"
#include "delays.h"
#define IS_FLASH 1
#define SAVE_POS SRAM

View File

@ -4,7 +4,7 @@
#include "debug_mode.h"
#include "main_menu.h"
#include "pokemon_data.h"
#include "save.h"
#include "libraries/Pokemon-Gen3-to-Gen-X/include/save.h"
byte save_data_array[SAVE_DATA_SIZE];

View File

@ -1,4 +1,3 @@
#include <tonc.h>
#include <string>
#include "script_var.h"