Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CustomDefinitions.event
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
//item ID for skill scroll
#define SkillScroll 0xFE

//For fourth allegiance
#define NeutralForce 3

#include "EngineHacks/SkillSystem/skill_definitions.event"

// #define __DEBUG__ // Uncomment to get the Debug startup menu :p
2 changes: 1 addition & 1 deletion EngineHacks/Config.event
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
// The location it is repointed to is also defined here. The default location is
// the area used for debug printing.
//#define REPOINT_UNIT_LOAD_BUFFER
#define NewUnitLoadBufferLoc 0x2026F30
//#define NewUnitLoadBufferLoc 0x2026F30


// =================================
Expand Down
32 changes: 32 additions & 0 deletions EngineHacks/FourthAllegiance/AssembleC.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
@echo off

SET startDir=C:\devkitPro\devkitARM\bin\
SET gcc="%startDir%arm-none-eabi-gcc"
SET as="%startDir%arm-none-eabi-as"
SET ref="FE-CLib\reference\FE8U-20190316"
SET lyn="lyn.exe"

@rem compile into an object file
%gcc% -mcpu=arm7tdmi -mabi=aapcs -mthumb -mthumb-interwork -fomit-frame-pointer -ffast-math -fno-toplevel-reorder -mlong-calls -I "FE-CLib\include" -Os -c %1 -o "%~n1.o"

@rem check for a library s file(called %~n1.lib), and assemble it if needed
if exist "%ref%.s" (
%as% -g -mcpu=arm7tdmi -mthumb-interwork "%ref%.s" -o "%ref%.o"

@rem transform object file into event file with the lib file using lyn
%lyn% "%~n1.o" "%ref%.o" > "%~n1.event"

) else (

@rem transform object file into event file without lib
%lyn% "%~n1.o" > "%~n1.event"

)

echo y | del "%~n1.o"

if exist "%~n1_lib.o" (
echo y | del "%~n1_lib.o"
)

pause
10 changes: 10 additions & 0 deletions EngineHacks/FourthAllegiance/FE-CLib/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Objects
*.o
*.elf

# lyn output
*.lyn.event

# lyn itself
utility/lyn
utility/lyn.exe
38 changes: 38 additions & 0 deletions EngineHacks/FourthAllegiance/FE-CLib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

This is a set a C headers along with reference object sources for the purpose of writing FE8 wizardry. Only a FE8U reference is available for now, but adding a FE8J reference is feasible.

Much like [the python tools](https://github.com/StanHash/FE-PyTools), this was previously located within [FE-CHAX](https://github.com/StanHash/FE-CHAX). This is now being moved in its own repository since I will start using it in other projects too (namely in my [port of VBA to make/EA](https://github.com/StanHash/VBA-MAKE)).

## Usage

- Add the `include` directory to your include path, and include `gbafe.h` in the sources in which you may want to use FE8 stuff.
- Build the *latest* corresponding reference object (sources in the `reference` directory) and link against it.

_**Note**: as of 2019-01-02, I removed all `#pragma long_calls` from the headers. This means that you will have to rely on either compiler or linker flags if you need long calls to work._

## Reference objects

I call "reference object" a relocatable object that only defines a series of global absolute symbols mapping names to addresses in a given game. For example, a reference object for FE8U will define a symbol named `gActiveUnit` with absolute value `03004E50`.

This "reference object" may be used to "link" the game to your code.

The symbol names in the latest reference object should correspond to the symbol names in the current gbafe headers. *However*, names in previous reference objects may not correspond to current libgbafe. Those are provided to better prepare users for breaks in compatibility.

### Updating the reference

Basically since I'm bad I change function and object names a lot. But I try to be nice anyway so I'm trying to provide an easy-ish way to "update" from an older nameset to the latest one.

You may note that reference object sources have dates attached to their names. That's because the plan is to keep all the previous references in so that is becomes easier to "port" your code to a newer version of FE-CLib.

I have written [an updating helper script](./utility/update-reference-object.sh) that may help you update from an old reference to the latest one. It requires `lyn` to compare references, but it isn't necessarily meant to be excusively used for updating a `lyn`-based environment.

The way it works is fairly simple: it uses `lyn` to generate a "diff" of the symbol map defined by two objects, generates a series of `sed` invocations that should replace old names with new names; and then it calls those for each .h, .c and .s files it can find under the working directory.

Basically how you'd use it is like this:

```sh
cd path/to/directory/to/update
sh path/to/utility/update-reference-object.sh path/to/old/reference.o path/to/new/reference.o
```

You could also use this to port your already written code from your old stuff to this! Or vice-versa, if you want code written for this to work in your environment with a custom reference.
26 changes: 26 additions & 0 deletions EngineHacks/FourthAllegiance/FE-CLib/include/gba/defines.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef GUARD_GBA_DEFINES
#define GUARD_GBA_DEFINES

#include "types.h"

#define TRUE 1
#define FALSE 0

#define PLTT ((unsigned char*)(0x5000000))
#define VRAM ((unsigned char*)(0x6000000))
#define OAM ((unsigned char*)(0x7000000))

#define VRAM_BG_CHAR_ADDR(n) (VRAM + (0x4000 * (n)))
#define VRAM_BG_SCREEN_ADDR(n) (VRAM + (0x800 * (n)))
#define VRAM_BG_TILE_ADDR(n) (VRAM + (0x80 * (n)))

#define VRAM_OBJ (VRAM + 0x10000)

#define COLOR_RGB(r, g, b) (((r) & 0x1F) + (((g) & 0x1F) << 5) + (((b) & 0x1F) << 10))

#define COLOR_WHITE COLOR_RGB(31, 31, 31)
#define COLOR_BLACK COLOR_RGB(0, 0, 0)

#define PUREFUNC __attribute__((pure))

#endif // GUARD_GBA_DEFINES
10 changes: 10 additions & 0 deletions EngineHacks/FourthAllegiance/FE-CLib/include/gba/gba.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef GUARD_GBA_GBA_H
#define GUARD_GBA_GBA_H

#include "types.h"
#include "defines.h"
#include "ioreg.h"
#include "syscall.h"
#include "macro.h"

#endif // GUARD_GBA_GBA_H
119 changes: 119 additions & 0 deletions EngineHacks/FourthAllegiance/FE-CLib/include/gba/ioreg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#ifndef GUARD_GBA_IO_REG_H
#define GUARD_GBA_IO_REG_H

#include "types.h"

enum
{
IO_ADDR_DISPCNT = 0x4000000,
IO_ADDR_DISPSTAT = 0x4000004,
IO_ADDR_VCOUNT = 0x4000006,
IO_ADDR_BG0CNT = 0x4000008,
IO_ADDR_BG1CNT = 0x400000A,
IO_ADDR_BG2CNT = 0x400000C,
IO_ADDR_BG3CNT = 0x400000E,
IO_ADDR_BG0HOFS = 0x4000010,
IO_ADDR_BG0VOFS = 0x4000012,
IO_ADDR_BG1HOFS = 0x4000014,
IO_ADDR_BG1VOFS = 0x4000016,
IO_ADDR_BG2HOFS = 0x4000018,
IO_ADDR_BG2VOFS = 0x400001A,
IO_ADDR_BG3HOFS = 0x400001C,
IO_ADDR_BG3VOFS = 0x400001E,
IO_ADDR_BG2PA = 0x4000020,
IO_ADDR_BG2PB = 0x4000022,
IO_ADDR_BG2PC = 0x4000024,
IO_ADDR_BG2PD = 0x4000026,
IO_ADDR_BG2X = 0x4000028,
IO_ADDR_BG2Y = 0x400002C,
IO_ADDR_BG3PA = 0x4000030,
IO_ADDR_BG3PB = 0x4000032,
IO_ADDR_BG3PC = 0x4000034,
IO_ADDR_BG3PD = 0x4000036,
IO_ADDR_BG3X = 0x4000038,
IO_ADDR_BG3Y = 0x400003C,

// TODO: win io

IO_ADDR_MOSAIC = 0x400004C,
IO_ADDR_BLDCNT = 0x4000050,
IO_ADDR_BLDALPHA = 0x4000052,
IO_ADDR_BLDY = 0x4000054,

// TODO: sound io
// TODO: dma io
// TODO: timer io
// TODO: sio io

IO_ADDR_KEYINPUT = 0x4000130,
IO_ADDR_KEYCNT = 0x4000132,

// TODO: more sio io

IO_ADDR_IE = 0x4000200,
IO_ADDR_IF = 0x4000202,
IO_ADDR_WAITCNT = 0x4000204,
IO_ADDR_IME = 0x4000208,
};

#define DISPCNT (*(struct DispControl*) (IO_ADDR_DISPCNT))
#define DISPSTAT (*(struct DispStat*) (IO_ADDR_DISPSTAT))
#define VCOUNT (*(u16*) (IO_ADDR_VCOUNT))
#define BG0CNT (*(struct BgControl*) (IO_ADDR_BG0CNT))
#define BG1CNT (*(struct BgControl*) (IO_ADDR_BG1CNT))
#define BG2CNT (*(struct BgControl*) (IO_ADDR_BG2CNT))
#define BG3CNT (*(struct BgControl*) (IO_ADDR_BG3CNT))
#define BG0HOFS (*(u16*) (IO_ADDR_BG0HOFS))
#define BG0VOFS (*(u16*) (IO_ADDR_BG0VOFS))
#define BG1HOFS (*(u16*) (IO_ADDR_BG1HOFS))
#define BG1VOFS (*(u16*) (IO_ADDR_BG1VOFS))
#define BG2HOFS (*(u16*) (IO_ADDR_BG2HOFS))
#define BG2VOFS (*(u16*) (IO_ADDR_BG2VOFS))
#define BG3HOFS (*(u16*) (IO_ADDR_BG3HOFS))
#define BG3VOFS (*(u16*) (IO_ADDR_BG3VOFS))
#define BG2PA (*(u16*) (IO_ADDR_BG2PA)) // TODO: better type
#define BG2PB (*(u16*) (IO_ADDR_BG2PB)) // TODO: better type
#define BG2PC (*(u16*) (IO_ADDR_BG2PC)) // TODO: better type
#define BG2PD (*(u16*) (IO_ADDR_BG2PD)) // TODO: better type
#define BG2X (*(u32*) (IO_ADDR_BG2X)) // TODO: better type
#define BG2Y (*(u32*) (IO_ADDR_BG2Y)) // TODO: better type
#define BG3PA (*(u16*) (IO_ADDR_BG3PA)) // TODO: better type
#define BG3PB (*(u16*) (IO_ADDR_BG3PB)) // TODO: better type
#define BG3PC (*(u16*) (IO_ADDR_BG3PC)) // TODO: better type
#define BG3PD (*(u16*) (IO_ADDR_BG3PD)) // TODO: better type
#define BG3X (*(u32*) (IO_ADDR_BG3X)) // TODO: better type
#define BG3Y (*(u32*) (IO_ADDR_BG3Y)) // TODO: better type

// TODO: win io

#define MOSAIC (*(struct MosaicConfig*)(IO_ADDR_MOSAIC))
#define BLDCNT (*(struct BlendControl*)(IO_ADDR_BLDCNT))
#define BLDALPHA (*(struct BlendAlpha*) (IO_ADDR_BLDALPHA))
#define BLDY (*(u16*) (IO_ADDR_BLDY))

// TODO: sound io
// TODO: dma io
// TODO: timer io
// TODO: sio io

#define KEYINPUT (*(u16*) (IO_ADDR_KEYINPUT))
#define KEYCNT (*(struct KeyControl*) (IO_ADDR_KEYCNT))

// TODO: more sio io

#define IE (*(u16*) (IO_ADDR_IE))
#define IF (*(u16*) (IO_ADDR_IF))
#define WAITCNT (*(struct WaitControl*) (IO_ADDR_WAITCNT))
#define IME (*(u16*) (IO_ADDR_IME))

// HELPERS

#define BG0OFFSET (*(struct Vec2u*) (IO_ADDR_BG0HOFS))
#define BG1OFFSET (*(struct Vec2u*) (IO_ADDR_BG1HOFS))
#define BG2OFFSET (*(struct Vec2u*) (IO_ADDR_BG2HOFS))
#define BG3OFFSET (*(struct Vec2u*) (IO_ADDR_BG3HOFS))

#define BG2AFFINE (*(struct BgAffine*)(IO_ADDR_BG2PA))
#define BG3AFFINE (*(struct BgAffine*)(IO_ADDR_BG3PA))

#endif // GUARD_GBA_IO_REG_H
Loading