Skip to content
Merged
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
11 changes: 11 additions & 0 deletions include/bg_triangles.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define GUARD_SPRITE_4_H

typedef struct {
#if !WIDESCREEN_HACK
u8 unk0;
u8 unk1;
u8 unk2;
Expand All @@ -10,6 +11,16 @@ typedef struct {
u8 unk5;
u8 unk6;
u8 unk7;
#else
u16 unk0;
u16 unk1;
u16 unk2;
u16 unk3;
u16 unk4;
u16 unk5;
u16 unk6;
u16 unk7;
#endif
} TriParam1;

extern void sub_800724C(u8 bg, TriParam1 *param1);
Expand Down
28 changes: 17 additions & 11 deletions include/gba/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,26 @@
#define DISPLAY_WIDTH 426
#define DISPLAY_HEIGHT 240

// NOTE: We shouldn't consider WIDESCREEN_HACK a permanent thing.
// This hack should best be removed once there's a "native" platform layer.
#if ((DISPLAY_WIDTH >= 256) || (DISPLAY_HEIGHT >= 256))
#undef VRAM_SIZE
#define VRAM_SIZE (0x18000 + (0x800 * (12)))
#define WIDESCREEN_HACK TRUE
#define EXTENDED_OAM TRUE
#else
#define WIDESCREEN_HACK FALSE
#define EXTENDED_OAM !TRUE
#endif
extern uint8_t VRAM[VRAM_SIZE];

#if !EXTENDED_OAM
//#include "gba/types.h"
// TODO: Fix #define OAM_SIZE (OAM_ENTRY_COUNT*sizeof(OamData))
#define OAM_SIZE (OAM_ENTRY_COUNT*8)
#else // EXTENDED_OAM
#define OAM_SIZE (OAM_ENTRY_COUNT*0xC)
#endif
extern struct SoundMixerState *SOUND_INFO_PTR;
extern uint16_t INTR_CHECK;
extern void (*INTR_VECTOR)(void);
Expand All @@ -56,17 +73,6 @@ extern uint16_t PLTT[PLTT_SIZE/sizeof(uint16_t)];
#define OBJ_PLTT (u8*)&PLTT[BG_PLTT_SIZE/sizeof(uint16_t)]
extern uint8_t OAM[OAM_SIZE];

// NOTE: We shouldn't consider WIDESCREEN_HACK a permanent thing.
// This hack should best be removed once there's a "native" platform layer.
#if ((DISPLAY_WIDTH >= 256) || (DISPLAY_HEIGHT >= 256))
#undef VRAM_SIZE
#define VRAM_SIZE (0x18000 + (0x800 * (12)))
#define WIDESCREEN_HACK TRUE
#else
#define WIDESCREEN_HACK FALSE
#endif
extern uint8_t VRAM[VRAM_SIZE];

#define BG_VRAM &VRAM[0]
#define BG_CHAR_ADDR(n) (((u8*)BG_VRAM) + (0x4000 * (n)))
#define BG_CHAR_ADDR_FROM_BGCNT(bg) (BG_VRAM + ((gBgCntRegs[bg] & BGCNT_CHARBASE(0x3)) << 12))
Expand Down
123 changes: 87 additions & 36 deletions include/gba/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,17 @@ struct PlttData
// as well using this to determine the size for some DMAs to gOamBuffer.
// TODO: Somehow this does not work by #include-ing main.h and using PACKED();
// TODO: EXTENDED_OAM is not yet functional
#define EXTENDED_OAM FALSE
#if !EXTENDED_OAM
PACKED(OamDataShort, {
/*0x00*/
u32 y : 8;

/*0x01*/
u32 affineMode : 2; // 0x1, 0x2 -> 0x4
u32 objMode : 2; // 0x4, 0x8 -> 0xC
u32 mosaic : 1; // 0x10
u32 bpp : 1; // 0x20
u32 shape : 2; // 0x40, 0x80 -> 0xC0
u32 affineMode : 2; // 0x100, 0x200 -> 0x300
u32 objMode : 2; // 0x400, 0x800 -> 0xC00
u32 mosaic : 1; // 0x1000
u32 bpp : 1; // 0x2000
u32 shape : 2; // 0x4000, 0x8000 -> 0xC000

/*0x02*/
u32 x : 9;
Expand All @@ -118,36 +117,15 @@ PACKED(OamDataShort, {
u16 priority : 2; // 0x400, 0x800 -> 0xC00
u16 paletteNum : 4;
}); /* size: 0x6 (important to not be 0x8, see comment above struct!) */
#else
PACKED(OamDataShort, {
/* 0x00 */ s16 x;
/* 0x02 */ s16 y;

/* 0x04 */ u32 affineMode:2; // 0x1, 0x2 -> 0x4
u32 objMode:2; // 0x4, 0x8 -> 0xC
u32 mosaic:1; // 0x10
u32 bpp:1; // 0x20
u32 shape:2; // 0x40, 0x80 -> 0xC0

/* 0x06 */ u32 padding:9;
u32 matrixNum:5; // bits 3/4 are h-flip/v-flip if not in affine mode
u32 size:2; // 0x4000, 0x8000 -> 0xC000

/* 0x08 */ u16 tileNum:10; // 0x3FF
u16 priority:2; // 0x400, 0x800 -> 0xC00
u16 paletteNum:4;
}); /* size: 0x6 (important to not be 0x8, see comment above struct!) */
#endif

#if !EXTENDED_OAM
typedef union {
struct {
/*0x00*/ u32 y:8;
/*0x01*/ u32 affineMode:2; // 0x1, 0x2 -> 0x4
u32 objMode:2; // 0x4, 0x8 -> 0xC
u32 mosaic:1; // 0x10
u32 bpp:1; // 0x20
u32 shape:2; // 0x40, 0x80 -> 0xC0
/*0x01*/ u32 affineMode:2; // 0x100, 0x200 -> 0x400
u32 objMode:2; // 0x400, 0x800 -> 0xC00
u32 mosaic:1; // 0x1000
u32 bpp:1; // 0x2000
u32 shape:2; // 0x4000, 0x8000 -> 0xC000

/*0x02*/ u32 x:9;
u32 matrixNum:5; // bits 3/4 are h-flip/v-flip if not in affine mode
Expand All @@ -171,7 +149,58 @@ typedef union {

u16 raw[4];
} OamData;

#define OAM_GET_X(oamEntry) ((oamEntry)->all.attr1 & 0x1FF)
#define OAM_INIT_X(oamEntry, value, flip) (oamEntry)->all.attr1 = (((value) & 0x1FF) | ((flip) ? 0x1000 : 0));
#define OAM_SET_X(oamEntry, value) { \
u32 v; \
(oamEntry)->all.attr1 &= ~0x1FF; \
v = (value); \
(oamEntry)->all.attr1 += v & 0x1FF; \
}

#define OAM_GET_Y(oamEntry) (oamEntry)->all.attr0 & 0xFF
#define OAM_INIT_Y(oamEntry, value) (oamEntry)->all.attr0 = (value) & 0xFF
#define OAM_SET_Y(oamEntry, value) { \
u32 v; \
(oamEntry)->all.attr0 &= ~0xFF; \
v = (value); \
(oamEntry)->all.attr0 += v & 0xFF; \
}
#define OAM_SET_AFFINE_MODE(oamEntry, value) { \
u32 v; \
(oamEntry)->all.attr0 &= ~0x3; \
v = (value); \
(oamEntry)->all.attr0 |= v; \
}

#define OAM_DATA_SIZE_AFFINE 8
#define OAM_DATA_SIZE_NO_AFFINE 6

#define OAM_DATA_COUNT_AFFINE (OAM_DATA_SIZE_AFFINE / sizeof(short))
#define OAM_DATA_COUNT_NO_AFFINE (OAM_DATA_SIZE_NO_AFFINE / sizeof(short))

#else
PACKED(OamDataShort, {
/* 0x00 */ s16 x;
/* 0x02 */ s16 y;

/* 0x04 */ u32 affineMode:2; // 0x1, 0x2 -> 0x4
u32 objMode:2; // 0x4, 0x8 -> 0xC
u32 mosaic:1; // 0x10
u32 bpp:1; // 0x20
u32 shape:2; // 0x40, 0x80 -> 0xC0

/* 0x05 */ u32 matrixNum:5; // bits 3/4 are h-flip/v-flip if not in affine mode
u32 size:2; // 0x4000, 0x8000 -> 0xC000u32
u32 padding:17; // NOTE: Padding MUST be here for some platforms not to break

/* 0x08 */ u16 tileNum:10; // 0x3FF
u16 priority:2; // 0x400, 0x800 -> 0xC00
u16 paletteNum:4;

}); /* size: 0x6 (important to not be 0x8, see comment above struct!) */

typedef union {
struct {
/* 0x00 */ s16 x;
Expand All @@ -183,9 +212,9 @@ typedef union {
u32 bpp:1; // 0x20
u32 shape:2; // 0x40, 0x80 -> 0xC0

/* 0x06 */ u32 padding:9;
u32 matrixNum:5; // bits 3/4 are h-flip/v-flip if not in affine mode
u32 size:2; // 0x4000, 0x8000 -> 0xC000
/* 0x05 */ u32 matrixNum:5; // bits 3/4 are h-flip/v-flip if not in affine mode
u32 size:2; // 0x4000, 0x8000 -> 0xC000
u32 padding:17; // NOTE: Padding MUST be here for some platforms not to break

/* 0x08 */ u16 tileNum:10; // 0x3FF
u16 priority:2; // 0x400, 0x800 -> 0xC00
Expand All @@ -205,8 +234,30 @@ typedef union {
u16 affineParam;
} all;

u16 raw[4];
u16 raw[6];
} OamData;

#define OAM_GET_X(oamEntry) (oamEntry)->x
#define OAM_INIT_X(oamEntry, value, flip) \
(oamEntry)->split.x = (value); \
(oamEntry)->split.matrixNum = ((flip) ? 0x08 : 0);
#define OAM_SET_X(oamEntry, value) { \
(oamEntry)->split.x = (value); \
}

#define OAM_GET_Y(oamEntry) (oamEntry)->split.y
#define OAM_INIT_Y(oamEntry, value) (oamEntry)->split.y = (value);
#define OAM_SET_Y(oamEntry, value) (oamEntry)->split.y = (value);
#define OAM_SET_AFFINE_MODE(oamEntry, value) { \
(oamEntry)->split.affineMode = (value); \
}

#define OAM_DATA_SIZE_AFFINE 12
#define OAM_DATA_SIZE_NO_AFFINE 10

#define OAM_DATA_COUNT_AFFINE (OAM_DATA_SIZE_AFFINE / sizeof(short))
#define OAM_DATA_COUNT_NO_AFFINE (OAM_DATA_SIZE_NO_AFFINE / sizeof(short))

#endif

#define ST_OAM_HFLIP 0x08
Expand Down
9 changes: 7 additions & 2 deletions include/platform/shared/input.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#ifndef GUARD_PLATFORM_SHARED_INPUT_H
#define GUARD_PLATFORM_SHARED_INPUT_H

#include "sprite.h" // for Sprite
typedef u32 SharedKeys;

u16 GetXInputKeys();
#define KEY_SPEEDUP (1 << 16)
#define SPEEDUP_SCALE 5.0f

#ifdef _WIN32
SharedKeys GetXInputKeys();
#endif // _WIN32

#endif // GUARD_PLATFORM_SHARED_INPUT_H
21 changes: 12 additions & 9 deletions src/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,10 +490,14 @@ static void UpdateScreenDma(void)

if (sLastCalledVblankFuncId == VBLANK_FUNC_ID_NONE) {
CopyOamBufferToOam();
DmaCopy16(3, gOamBuffer + 0x00, (void *)OAM + 0x000, 0x100);
DmaCopy16(3, gOamBuffer + 0x20, (void *)OAM + 0x100, 0x100);
DmaCopy16(3, gOamBuffer + 0x40, (void *)OAM + 0x200, 0x100);
DmaCopy16(3, gOamBuffer + 0x60, (void *)OAM + 0x300, 0x100);
DmaCopy16(3, gOamBuffer + (OAM_ENTRY_COUNT / 4) * 0, (void *)OAM + (OAM_ENTRY_COUNT * (OAM_DATA_SIZE_AFFINE / 4) * 0),
OAM_SIZE / 4);
DmaCopy16(3, gOamBuffer + (OAM_ENTRY_COUNT / 4) * 1, (void *)OAM + (OAM_ENTRY_COUNT * (OAM_DATA_SIZE_AFFINE / 4) * 1),
OAM_SIZE / 4);
DmaCopy16(3, gOamBuffer + (OAM_ENTRY_COUNT / 4) * 2, (void *)OAM + (OAM_ENTRY_COUNT * (OAM_DATA_SIZE_AFFINE / 4) * 2),
OAM_SIZE / 4);
DmaCopy16(3, gOamBuffer + (OAM_ENTRY_COUNT / 4) * 3, (void *)OAM + (OAM_ENTRY_COUNT * (OAM_DATA_SIZE_AFFINE / 4) * 3),
OAM_SIZE / 4);
}

for (i = 0; i < gNumVBlankIntrs; i++) {
Expand Down Expand Up @@ -569,11 +573,10 @@ static void ClearOamBufferDma(void)
#endif
}
gFlags &= ~FLAGS_EXECUTE_HBLANK_COPY;
DmaFill16(3, 0x200, gOamBuffer + 0x00, 0x100);
DmaFill16(3, 0x200, gOamBuffer + 0x20, 0x100);
DmaFill16(3, 0x200, gOamBuffer + 0x40, 0x100);
DmaFill16(3, 0x200, gOamBuffer + 0x60, 0x100);

DmaFill16(3, 0x200, gOamBuffer + (OAM_ENTRY_COUNT / 4) * 0, OAM_SIZE / 4);
DmaFill16(3, 0x200, gOamBuffer + (OAM_ENTRY_COUNT / 4) * 1, OAM_SIZE / 4);
DmaFill16(3, 0x200, gOamBuffer + (OAM_ENTRY_COUNT / 4) * 2, OAM_SIZE / 4);
DmaFill16(3, 0x200, gOamBuffer + (OAM_ENTRY_COUNT / 4) * 3, OAM_SIZE / 4);
gNumVBlankCallbacks = 0;
gFlags &= ~FLAGS_10;
}
Expand Down
Loading
Loading