Skip to content

Commit

Permalink
#407 32X S/F/FT/FTA/GT/GTA SH-2 rasterization asm, transform optims, …
Browse files Browse the repository at this point in the history
…change input mapping
  • Loading branch information
XProger committed Apr 3, 2022
1 parent efc069e commit 8fe5d86
Show file tree
Hide file tree
Showing 17 changed files with 1,461 additions and 220 deletions.
6 changes: 1 addition & 5 deletions src/fixed/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@ EWRAM_DATA ExtraInfoLara playersExtra[MAX_PLAYERS];
#define LEVEL_INFO(name, title, track, secrets) { #name, NULL, title, track, secrets }
#endif

#ifdef __3DO__ // TODO fix the title scren on 3DO
EWRAM_DATA LevelID gLevelID = LVL_TR1_1;
#else
EWRAM_DATA LevelID gLevelID = LVL_TR1_TITLE;
#endif

const LevelInfo gLevelInfo[LVL_MAX] = {
// TR1
Expand Down Expand Up @@ -97,7 +93,7 @@ int32 rand_draw()

#ifdef USE_DIV_TABLE
EWRAM_DATA ALIGN16 divTableInt divTable[DIV_TABLE_SIZE] = { // must be at EWRAM start
0xFFFF, 0xFFFF, 0x8000, 0x5555, 0x4000, 0x3333, 0x2AAA, 0x2492,
0x0000, 0x7FFF, 0x7FFF, 0x5555, 0x4000, 0x3333, 0x2AAA, 0x2492,
0x2000, 0x1C71, 0x1999, 0x1745, 0x1555, 0x13B1, 0x1249, 0x1111,
0x1000, 0x0F0F, 0x0E38, 0x0D79, 0x0CCC, 0x0C30, 0x0BA2, 0x0B21,
0x0AAA, 0x0A3D, 0x09D8, 0x097B, 0x0924, 0x08D3, 0x0888, 0x0842,
Expand Down
9 changes: 6 additions & 3 deletions src/fixed/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#endif

#if defined(_WIN32)
#define MODE4
#define USE_DIV_TABLE

#define MODE4
Expand Down Expand Up @@ -218,6 +217,12 @@ typedef unsigned int uint32;
typedef uint16 divTableInt;
#endif

#if defined(__32X__)
typedef int8 ColorIndex;
#else
typedef uint8 ColorIndex;
#endif

//#include <new>
inline void* operator new(size_t, void *ptr)
{
Expand Down Expand Up @@ -826,8 +831,6 @@ struct RoomVertex
{
#if defined(__3DO__)
uint16 xyz565;
#elif defined(__32X__)
uint8 g, z, y, x;
#else
uint8 x, y, z, g;
#endif
Expand Down
1 change: 1 addition & 0 deletions src/fixed/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ void gameLoadLevel(const void* data)
//resetLara(0, 9, _vec3i(49669, 7680, 57891), ANGLE_0); // first door
//resetLara(0, 10, _vec3i(43063, 7168, 61198), ANGLE_0); // transp
//resetLara(0, 14, _vec3i(20215, 6656, 52942), ANGLE_90 + ANGLE_45); // bridge
//resetLara(0, 25, _vec3i(8789, 5632, 80173), 0); // portal
//resetLara(0, 17, _vec3i(16475, 6656, 59845), ANGLE_90); // bear
//resetLara(0, 26, _vec3i(24475, 6912, 83505), ANGLE_90); // switch timer 1
//resetLara(0, 35, _vec3i(35149, 2048, 74189), ANGLE_90); // switch timer 2
Expand Down
3 changes: 3 additions & 0 deletions src/fixed/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ int32 alignOffset(int32 a, int32 b)

void* soundPlay(int16 id, const vec3i* pos)
{
#ifdef __32X__ // TODO
return NULL;
#endif
if (!gSettings.audio_sfx)
return NULL;

Expand Down
10 changes: 5 additions & 5 deletions src/fixed/lara.h
Original file line number Diff line number Diff line change
Expand Up @@ -2739,12 +2739,12 @@ struct Lara : ItemObj
}
#elif defined(__32X__)
// 6 buttons
if (keys & IK_A) input |= IN_WEAPON;
if (keys & IK_B) input |= IN_ACTION;
if (keys & IK_C) input |= IN_JUMP;
if (keys & IK_X) input |= IN_LOOK;
if (keys & IK_A) input |= IN_ACTION;
if (keys & IK_B) input |= IN_JUMP;
if (keys & IK_C) input |= IN_WEAPON;
if (keys & IK_X) input |= IN_WALK;
if (keys & IK_Y) input |= IN_UP | IN_DOWN;
if (keys & IK_Z) input |= IN_WALK;
if (keys & IK_Z) input |= IN_LOOK;
#elif defined(__GBA__) || defined(_WIN32)
int32 ikA, ikB;

Expand Down
2 changes: 1 addition & 1 deletion src/platform/32x/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@ $(BUILD)/%.o: ../../fixed/%.cpp
$(SHXX) $(SHCCFLAGS) $(INCPATH) -o $@ $<

clean:
$(RM) $(BUILD)/* *.32x *.elf
$(RM) $(BUILD)/* $(TARGET).32x $(TARGET).elf
92 changes: 73 additions & 19 deletions src/platform/32x/asm/common.i
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,18 @@

#define FACE_TYPE_F 1

#define VERTEX_X 0
#define VERTEX_Y 2
#define VERTEX_Z 4
#define VERTEX_G 6
#define VERTEX_CLIP 7
#define VERTEX_T 8
#define VERTEX_PREV 12
#define VERTEX_NEXT 13
#define VERTEX_X 0
#define VERTEX_Y 2
#define VERTEX_Z 4
#define VERTEX_G 6
#define VERTEX_CLIP 7
#define VERTEX_T 8
#define VERTEX_PREV 12
#define VERTEX_NEXT 13
#define VERTEX_PADDING 14

#define VERTEX_SIZEOF_SHIFT 4
#define VERTEX_SIZEOF (1 << VERTEX_SIZEOF_SHIFT)

#define VIEW_DIST (1024 * 10) // max = DIV_TABLE_END << PROJ_SHIFT
#define FOG_SHIFT 1
Expand All @@ -56,20 +60,70 @@
#define VIEW_MAX (VIEW_DIST)
#define VIEW_OFF 4096

#define CLIP_LEFT (1 << 0)
#define CLIP_RIGHT (1 << 1)
#define CLIP_TOP (1 << 2)
#define CLIP_BOTTOM (1 << 3)
#define CLIP_FAR (1 << 4)
#define CLIP_NEAR (1 << 5)
#define CLIP_FRAME (1 << 0)
#define CLIP_LEFT (1 << 1)
#define CLIP_RIGHT (1 << 2)
#define CLIP_TOP (1 << 3)
#define CLIP_BOTTOM (1 << 4)
#define CLIP_FAR (1 << 5)
#define CLIP_NEAR (1 << 6)

#define VP_MINX 0
#define VP_MINY 4
#define VP_MAXX 8
#define VP_MAXY 12

.macro shlr14 reg
shll2 \reg
shlr16 \reg
//exts.w reg, reg // skip this because of mov.w
.endm
#define FRAME_WIDTH 320
#define FRAME_HEIGHT 224

.macro align_fetch
.p2alignw 2, 0x0009
.endm

.macro shlr14 x
shll2 \x
shlr16 \x
//exts.w x, x // skip this because of mov.w
.endm

// int32 >> 12
// 1. shar x 12 => 12 op
// 2. (int32(int16(x >> 16)) << 4) | (x >> 12) => 8 op (require an extra register)
.macro shar12 x, t
swap.w \x, \t
exts.w \t, \t
shll2 \t
shll2 \t
shlr8 \x
shlr2 \x
shlr2 \x
or \t, \x
.endm

// out = uv * f
// uv and out regs must be different
// destructive for uv reg
.macro scaleUV uv, out, f
muls.w \uv, \f
shlr16 \uv
sts MACL, \out // v = int16(uv) * f (16-bit shift)
muls.w \uv, \f
sts MACL, \uv // u = int16(uv >> 16) * f (16-bit shift)
shlr16 \uv
xtrct \uv, \out // out = uint16(v >> 16) | (u & 0xFFFF0000)
.endm

// UUuuVVvv -> 0000VVUU
.macro getUV uv, index
swap.b \uv, \index // UUuuvvVV
swap.w \index, \index // vvVVUUuu
shll8 \index // VVUUuu00
shlr16 \index // 0000VVUU
.endm

// index (r0) = gLightmap[index]
// in index 0..255
// in lightmap one of 32 gLightmap slices
.macro lit lightmap, index
mov.b @(\index, \lightmap), \index
.endm
36 changes: 19 additions & 17 deletions src/platform/32x/asm/rasterize.s
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "common.i"
SEG_RASTER

#define type r0
#define proc r1
Expand All @@ -9,45 +10,46 @@
#define pixel flags
#define y type

.text
.align 4
.global _rasterize_asm
_rasterize_asm:
mov flags, type
shll2 type
swap.w type, type
and #15, type
shlr16 type
extu.b type, proc

cmp/eq #FACE_TYPE_F, type
bf/s 0f
cmp/eq #FACE_TYPE_F, type // cmp/eq #imm is 8-bit
bf/s .getProc
mov L, R
extu.b flags, R

0: // proc = table[type]
mov type, proc
.getProc: // proc = table[type]
mova var_table, type
shll2 proc
mov.l @(type, proc), proc

// pixel = fb + y * 320
// pixel = fb + y * 320 = fb + y * 256 + y * 64
mov.w @(VERTEX_Y, L), y
mov.l var_fb, pixel
shll8 y
add y, pixel // pixel += y * 256
shlr2 y
shar y
shar y
jmp @proc
add y, pixel // pixel += y * 64
nop

.align 2
var_fb:
.long 0x24000200
// overwrite image frame buffer address has the same
// write per but allow transparent write for byte & word
.long 0x24020200
var_table:
.long _rasterizeS_c
.long _rasterizeF_c
.long _rasterizeFT_c
.long _rasterizeFTA_c
.long _rasterizeGT_c
.long _rasterizeGTA_c
.long _rasterizeS_asm
.long _rasterizeF_asm
.long _rasterizeFT_asm
.long _rasterizeFT_asm
.long _rasterizeGT_asm
.long _rasterizeGT_asm
.long _rasterizeSprite_c
.long _rasterizeFillS_c
.long _rasterizeLineH_c
Expand Down
Loading

0 comments on commit 8fe5d86

Please sign in to comment.