Skip to content

Commit

Permalink
#407 32X add SH-2 ASM faceAdd* routines, on-chip blocks for prepare a…
Browse files Browse the repository at this point in the history
…nd render functions (still slower than SDRAM), multi-CPU OT flush, fb clear on the slave CPU
  • Loading branch information
XProger committed May 10, 2022
1 parent d91a919 commit 380d137
Show file tree
Hide file tree
Showing 23 changed files with 1,560 additions and 698 deletions.
8 changes: 7 additions & 1 deletion src/fixed/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@
#define USE_FMT (LVL_FMT_PKD)

#include "32x.h"

enum MarsCmd {
MARS_CMD_NONE = 0,
MARS_CMD_CLEAR,
MARS_CMD_FLUSH
};
#else
#error unsupported platform
#endif
Expand Down Expand Up @@ -2913,7 +2919,7 @@ void drawLevelInit();
void drawLevelFree();
void drawText(int32 x, int32 y, const char* text, TextAlign align);
void drawModel(const ItemObj* item);
void drawItem(const ItemObj* item);
void drawSprite(const ItemObj* item);
void drawRooms(Camera* camera);
void drawCinematicRooms();
void drawHUD(Lara* lara);
Expand Down
15 changes: 4 additions & 11 deletions src/fixed/draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -701,15 +701,6 @@ void drawModel(const ItemObj* item)
}
}

void drawItem(const ItemObj* item)
{
if (level.models[item->type].count > 0) {
drawModel(item);
} else {
drawSprite(item);
}
}

void drawRoom(const Room* room)
{
setViewport(room->clip);
Expand Down Expand Up @@ -811,7 +802,7 @@ void drawRooms(Camera* camera)

Room** visRoom = camera->view.room->getVisibleRooms();

// draw Lara first
#ifdef DRAW_LARA_FIRST
for (int32 i = 0; i < MAX_PLAYERS; i++)
{
Lara* lara = players[i];
Expand All @@ -823,7 +814,7 @@ void drawRooms(Camera* camera)
lara->flags |= ITEM_FLAG_STATUS_INVISIBLE; // skip drawing in the general pass
}
}

#endif
// draw rooms and objects
while (*visRoom)
{
Expand All @@ -832,6 +823,7 @@ void drawRooms(Camera* camera)
room->reset();
}

#ifdef DRAW_LARA_FIRST
// reset visibility flags for Lara
for (int32 i = 0; i < MAX_PLAYERS; i++)
{
Expand All @@ -841,6 +833,7 @@ void drawRooms(Camera* camera)
lara->flags &= ~ITEM_FLAG_STATUS;
}
}
#endif

setPaletteIndex(0);
setViewport(vp);
Expand Down
2 changes: 1 addition & 1 deletion src/fixed/enemy.h
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ struct Wolf : Enemy
case STATE_STOP:
{
if (nextState)
nextState;
return nextState;
return STATE_WALK;
}

Expand Down
6 changes: 5 additions & 1 deletion src/fixed/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,11 @@ void ItemObj::update()

void ItemObj::draw()
{
drawItem(this);
if (level.models[type].count > 0) {
drawModel(this);
} else {
drawSprite(this);
}
}

struct ItemSave {
Expand Down
2 changes: 2 additions & 0 deletions src/platform/32x/32x.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,6 @@ extern "C"
CacheControl(0);\
CacheControl(SH2_CCTL_CP | SH2_CCTL_CE);

#define MARS_WAIT() {while (MARS_SYS_COMM4);}

#endif
61 changes: 61 additions & 0 deletions src/platform/32x/asm/block_prepare.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include "common.i"
.data

.global _block_prepare_start
.global _block_prepare_end

.align 4
_block_prepare_start:

#include "transformMesh.i"
#include "transformRoom.i"

.align 2
var_gVerticesBase:
.long _gVerticesBase
var_gMatrixPtr:
.long _gMatrixPtr
var_gLightAmbient:
.long _gLightAmbient
var_divTable:
.long _divTable
var_viewportRel:
.long _viewportRel

#include "faceAddMeshQuads.i"
#include "faceAddMeshTriangles.i"

.align 2
var_gVertices_fam:
.long _gVertices
var_gFacesBase_fam:
.long _gFacesBase
var_gVerticesBase_fam:
.long _gVerticesBase
const_FACE_CLIPPED_fam:
.long FACE_CLIPPED
const_FACE_TRIANGLE_fam:
.long FACE_TRIANGLE
var_gOT_fam:
.long _gOT

#include "faceAddRoomQuads.i"
#include "faceAddRoomTriangles.i"

.align 2
var_gVertices_far:
.long _gVertices
var_gFacesBase_far:
.long _gFacesBase
var_gVerticesBase_far:
.long _gVerticesBase
const_FACE_CLIPPED_far:
.long FACE_CLIPPED
const_FACE_GOURAUD_far:
.long FACE_GOURAUD
const_FACE_TRIANGLE_far:
.long FACE_TRIANGLE
var_gOT_far:
.long _gOT

_block_prepare_end:
36 changes: 36 additions & 0 deletions src/platform/32x/asm/block_render.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "common.i"
.data

.global _block_render_start
.global _block_render_end

.align 4
_block_render_start:

#include "rasterize.i"
//#include "rasterize_dummy.i"
#include "rasterizeS.i"
#include "rasterizeF.i"

.align 2
var_LMAP_ADDR_fs:
.long _gLightmap_base
var_divTable_fs:
.long _divTable
var_frameWidth_fs:
.word FRAME_WIDTH

#include "rasterizeFT.i"
#include "rasterizeGT.i"

.align 2
var_LMAP_ADDR:
.long _gLightmap_base
var_divTable:
.long _divTable
var_mask:
.word 0xFF00
var_frameWidth:
.word FRAME_WIDTH

_block_render_end:
40 changes: 36 additions & 4 deletions src/platform/32x/asm/common.i
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#define SEG_MATH .text
#define SEG_TRANS .data
#define SEG_FACE .data
#define SEG_RASTER .data
#ifndef H_COMMON_ASM
#define H_COMMON_ASM

#define SEG_MATH .data
#define SEG_PHYSICS .data

//#define ON_CHIP_RENDER

// Matrix:
// int16 e00, e01, e02 // rotation
// int16 e10, e11, e12 // rotation
Expand Down Expand Up @@ -32,6 +34,10 @@
#define FIXED_SHIFT 14

#define FACE_TYPE_F 1
#define FACE_TYPE_SHIFT 14
#define FACE_CLIPPED (1 << 30)
#define FACE_TRIANGLE (1 << 31)
#define FACE_GOURAUD (2 << FACE_TYPE_SHIFT)

#define VERTEX_X 0
#define VERTEX_Y 2
Expand All @@ -46,6 +52,8 @@
#define VERTEX_SIZEOF_SHIFT 4
#define VERTEX_SIZEOF (1 << VERTEX_SIZEOF_SHIFT)

#define FACE_SIZEOF 16

#define VIEW_DIST (1024 * 10) // max = DIV_TABLE_END << PROJ_SHIFT
#define FOG_SHIFT 1
#define FOG_MAX VIEW_DIST
Expand All @@ -61,6 +69,7 @@
#define CLIP_BOTTOM (1 << 4)
#define CLIP_FAR (1 << 5)
#define CLIP_NEAR (1 << 6)
#define CLIP_DISCARD (CLIP_LEFT + CLIP_RIGHT + CLIP_TOP + CLIP_BOTTOM + CLIP_FAR + CLIP_NEAR)

#define VP_MINX 0
#define VP_MINY 4
Expand Down Expand Up @@ -121,3 +130,26 @@
.macro lit lightmap, index
mov.b @(\index, \lightmap), \index
.endm

// (vy1 - vy0) * (vx0 - vx2) <= (vx1 - vx0) * (vy0 - vy2)
.macro ccw vp0, vp1, vp2, vx0, vy0, vx1, vy1, vx2, vy2
mov.w @\vp0+, \vx0
mov.w @\vp0+, \vy0
mov.w @\vp1+, \vx1
mov.w @\vp1+, \vy1
sub \vx0, \vx1 // vx1 -= vx0
sub \vy0, \vy1 // vy1 -= vy0
mov.w @\vp2+, \vx2
sub \vx2, \vx0 // vx0 -= vx2
mov.w @\vp2+, \vy2
sub \vy2, \vy0 // vy0 -= vy2

muls.w \vy1, \vx0
sts MACL, \vx0 // vx0 *= vy1
muls.w \vx1, \vy0
sts MACL, \vy0 // vy0 *= vx1

cmp/ge \vx0, \vy0 // T = (vy0 >= vx0)
.endm

#endif // H_COMMON_ASM
Loading

0 comments on commit 380d137

Please sign in to comment.