This commit is contained in:
farisawan-2000
2020-12-11 21:47:11 -05:00
commit 871eed30af
13 changed files with 2090 additions and 0 deletions

18
config.h Normal file
View File

@@ -0,0 +1,18 @@
#ifndef S2D_CONFIG_H
#define S2D_CONFIG_H
// include your font header here
#include "fonts/impact.h"
// get your symbols defined here
#define s2d_font impact_obj
#define s2d_tex impact_tex
// Debug: bypass custom matrix setup
#define s2d_mat impact_mtx
// homebrew users: use this to rename your gdl head
#define gdl_head gDisplayListHead
extern Gfx *gdl_head;
#endif

1
fixed_point_math.c Normal file
View File

@@ -0,0 +1 @@
// jk i dont think this file is needed lol

1685
fonts/impact.c Normal file

File diff suppressed because it is too large Load Diff

134
fonts/impact.h Normal file
View File

@@ -0,0 +1,134 @@
#include <PR/ultratypes.h>
#include <PR/gs2dex.h>
extern uObjTxtr impact_tex[];
extern uObjMtx impact_mtx;
extern uObjSprite impact_obj;
extern void call_impact_sprite_dl(int idx, int x, int y, uObjMtx *buffer, int buf_idx);
extern u8 impact_tex_0[];
extern u8 impact_tex_1[];
extern u8 impact_tex_2[];
extern u8 impact_tex_3[];
extern u8 impact_tex_4[];
extern u8 impact_tex_5[];
extern u8 impact_tex_6[];
extern u8 impact_tex_7[];
extern u8 impact_tex_8[];
extern u8 impact_tex_9[];
extern u8 impact_tex_10[];
extern u8 impact_tex_11[];
extern u8 impact_tex_12[];
extern u8 impact_tex_13[];
extern u8 impact_tex_14[];
extern u8 impact_tex_15[];
extern u8 impact_tex_16[];
extern u8 impact_tex_17[];
extern u8 impact_tex_18[];
extern u8 impact_tex_19[];
extern u8 impact_tex_20[];
extern u8 impact_tex_21[];
extern u8 impact_tex_22[];
extern u8 impact_tex_23[];
extern u8 impact_tex_24[];
extern u8 impact_tex_25[];
extern u8 impact_tex_26[];
extern u8 impact_tex_27[];
extern u8 impact_tex_28[];
extern u8 impact_tex_29[];
extern u8 impact_tex_30[];
extern u8 impact_tex_31[];
extern u8 impact_tex_32[];
extern u8 impact_tex_33[];
extern u8 impact_tex_34[];
extern u8 impact_tex_35[];
extern u8 impact_tex_36[];
extern u8 impact_tex_37[];
extern u8 impact_tex_38[];
extern u8 impact_tex_39[];
extern u8 impact_tex_40[];
extern u8 impact_tex_41[];
extern u8 impact_tex_42[];
extern u8 impact_tex_43[];
extern u8 impact_tex_44[];
extern u8 impact_tex_45[];
extern u8 impact_tex_46[];
extern u8 impact_tex_47[];
extern u8 impact_tex_48[];
extern u8 impact_tex_49[];
extern u8 impact_tex_50[];
extern u8 impact_tex_51[];
extern u8 impact_tex_52[];
extern u8 impact_tex_53[];
extern u8 impact_tex_54[];
extern u8 impact_tex_55[];
extern u8 impact_tex_56[];
extern u8 impact_tex_57[];
extern u8 impact_tex_58[];
extern u8 impact_tex_59[];
extern u8 impact_tex_60[];
extern u8 impact_tex_61[];
extern u8 impact_tex_62[];
extern u8 impact_tex_63[];
extern u8 impact_tex_64[];
extern u8 impact_tex_65[];
extern u8 impact_tex_66[];
extern u8 impact_tex_67[];
extern u8 impact_tex_68[];
extern u8 impact_tex_69[];
extern u8 impact_tex_70[];
extern u8 impact_tex_71[];
extern u8 impact_tex_72[];
extern u8 impact_tex_73[];
extern u8 impact_tex_74[];
extern u8 impact_tex_75[];
extern u8 impact_tex_76[];
extern u8 impact_tex_77[];
extern u8 impact_tex_78[];
extern u8 impact_tex_79[];
extern u8 impact_tex_80[];
extern u8 impact_tex_81[];
extern u8 impact_tex_82[];
extern u8 impact_tex_83[];
extern u8 impact_tex_84[];
extern u8 impact_tex_85[];
extern u8 impact_tex_86[];
extern u8 impact_tex_87[];
extern u8 impact_tex_88[];
extern u8 impact_tex_89[];
extern u8 impact_tex_90[];
extern u8 impact_tex_91[];
extern u8 impact_tex_92[];
extern u8 impact_tex_93[];
extern u8 impact_tex_94[];
extern u8 impact_tex_95[];
extern u8 impact_tex_96[];
extern u8 impact_tex_97[];
extern u8 impact_tex_98[];
extern u8 impact_tex_99[];
extern u8 impact_tex_100[];
extern u8 impact_tex_101[];
extern u8 impact_tex_102[];
extern u8 impact_tex_103[];
extern u8 impact_tex_104[];
extern u8 impact_tex_105[];
extern u8 impact_tex_106[];
extern u8 impact_tex_107[];
extern u8 impact_tex_108[];
extern u8 impact_tex_109[];
extern u8 impact_tex_110[];
extern u8 impact_tex_111[];
extern u8 impact_tex_112[];
extern u8 impact_tex_113[];
extern u8 impact_tex_114[];
extern u8 impact_tex_115[];
extern u8 impact_tex_116[];
extern u8 impact_tex_117[];
extern u8 impact_tex_118[];
extern u8 impact_tex_119[];
extern u8 impact_tex_120[];
extern u8 impact_tex_121[];
extern u8 impact_tex_122[];
extern u8 impact_tex_123[];
extern u8 impact_tex_124[];
extern u8 impact_tex_125[];
extern u8 impact_tex_126[];
extern u8 impact_tex_127[];

10
init.c Normal file
View File

@@ -0,0 +1,10 @@
#include "init.h"
void s2d_init(void) {
gSPLoadUcode(gdl_head++, s2d_text, s2d_data);
}
void s2d_stop(void) {
gSPLoadUcode(gdl_head++, zex_text, zex_data);
}

14
init.h Normal file
View File

@@ -0,0 +1,14 @@
#include <ultra64.h>
#include <PR/gs2dex.h>
#include "config.h"
#define s2d_text gspS2DEX2_fifoTextStart
#define s2d_data gspS2DEX2_fifoDataStart
#define zex_text gspF3DZEX2_PosLight_fifoTextStart
#define zex_data gspF3DZEX2_PosLight_fifoDataStart
extern void s2d_init(void);
extern void s2d_stop(void);

64
mtx.c Normal file
View File

@@ -0,0 +1,64 @@
#include <ultra64.h>
#include <PR/gs2dex.h>
#include "stack.h"
void mat2_dst_mul(uObjMtx *dst, uObjMtx *m1, uObjMtx *m2) {
int m1A = m1->m.A >> 16;
int m1B = m1->m.B >> 16;
int m1C = m1->m.C >> 16;
int m1D = m1->m.D >> 16;
int m2A = m2->m.A >> 16;
int m2B = m2->m.B >> 16;
int m2C = m2->m.C >> 16;
int m2D = m2->m.D >> 16;
dst->m.A = ((m1A * m2A) * (m1B * m2C)) << 16;
dst->m.B = ((m1A * m2B) * (m1B * m2D)) << 16;
dst->m.C = ((m1C * m2A) * (m1D * m2C)) << 16;
dst->m.D = ((m1C * m2B) * (m1D * m2D)) << 16;
}
void mat2_dst_add(uObjMtx *dst, uObjMtx *m1, uObjMtx *m2) {
dst->m.A = (m1->m.A + m2->m.A);
dst->m.B = (m1->m.B + m2->m.B);
dst->m.C = (m1->m.C + m2->m.C);
dst->m.D = (m1->m.D + m2->m.D);
}
void mat2_ident(uObjMtx *dst, int scale) {
dst->m.A = scale << 16;
dst->m.B = 0;
dst->m.C = 0;
dst->m.D = scale << 16;
dst->m.X = 0;
dst->m.Y = 0;
}
void mat2_mul(uObjMtx *m1, uObjMtx *m2) {
mat2_dst_mul(m1, m1, m2);
}
void mat2_add(uObjMtx *m1, uObjMtx *m2) {
mat2_dst_mul(m1, m1, m2);
}
void mat2_scale(uObjMtx *dst, int scale) {
dst->m.A *= scale;
dst->m.B *= scale;
dst->m.C *= scale;
dst->m.D *= scale;
}
void mat2_translate(uObjMtx *m, int x, int y) {
m->m.X = x;
m->m.Y = y;
}
void get_final_mat(uObjMtx *dst) {
u32 s_temp_top = stack_top;
if (s_isempty()) return;
while (s_temp_top != 0) {
mat2_mul(dst, &stack[s_temp_top]);
}
}

19
mtx.h Normal file
View File

@@ -0,0 +1,19 @@
#include <ultra64.h>
#include <PR/gs2dex.h>
#include "stack.h"
extern void mat2_dst_mul(uObjMtx *dst, uObjMtx *m1, uObjMtx *m2);
extern void mat2_dst_add(uObjMtx *dst, uObjMtx *m1, uObjMtx *m2);
extern void mat2_ident(uObjMtx *dst, int scale);
extern void mat2_mul(uObjMtx *m1, uObjMtx *m2);
extern void mat2_add(uObjMtx *m1, uObjMtx *m2);
extern void mat2_scale(uObjMtx *dst, int scale);
extern void get_final_mat(uObjMtx *dst);
extern void mat2_translate(uObjMtx *m, int x, int y);

45
s2d_draw.c Normal file
View File

@@ -0,0 +1,45 @@
#include <ultra64.h>
#include "config.h"
#include "mtx.h"
int myScale = 1;
int degrees = 0;
uObjMtx final_mtx, rot_mtx;
static Gfx s2d_init_dl[] = {
gsDPPipeSync(),
gsDPSetTexturePersp(G_TP_NONE),
gsDPSetTextureLOD(G_TL_TILE),
gsDPSetTextureLUT(G_TT_NONE),
gsDPSetTextureConvert(G_TC_FILT),
gsDPSetAlphaCompare(G_AC_THRESHOLD),
gsDPSetBlendColor(0, 0, 0, 0x01),
gsDPSetCombineMode(G_CC_DECALRGBA, G_CC_DECALRGBA),
gsSPEndDisplayList(),
};
void setup_font(int idx) {
gDPPipeSync(gDisplayListHead++);
gSPDisplayList(gDisplayListHead++, s2d_init_dl);
gDPSetCycleType(gDisplayListHead++, G_CYC_1CYCLE);
gDPSetRenderMode(gDisplayListHead++, G_RM_XLU_SPRITE, G_RM_XLU_SPRITE2);
gSPObjRenderMode(gDisplayListHead++, G_OBJRM_XLU | G_OBJRM_BILERP);
gSPObjLoadTxtr(gDisplayListHead++, &s2d_tex[idx]);
}// 32 32
void mtx_pipeline(uObjMtx *m, int x, int y) {
mat2_ident(m, 1);
mat2_ident(&rot_mtx, 1);
// mat2_translate(&rot_mtx, 50, 50);
mat2_scale(m, myScale);
// mat2_mul(m, &rot_mtx);
mat2_translate(m, x, y);
gSPObjMatrix(gDisplayListHead++, m);
}
void print_s2d(char c) {
setup_font(c);
mtx_pipeline(&final_mtx, 50, 50);
// gSPObjMatrix(gDisplayListHead++, &s2d_mat);
gSPObjSprite(gDisplayListHead++, &s2d_font);
}

15
s2d_draw.h Normal file
View File

@@ -0,0 +1,15 @@
#ifndef S2D_DRAW_H
#define S2D_DRAW_H
#include <ultra64.h>
extern int myScale;
extern int degrees;
extern uObjMtx final_mtx, rot_mtx;
extern void setup_font(int idx);
extern void mtx_pipeline(uObjMtx *m, int x, int y);
extern void print_s2d(char c);
#endif

40
s2d_parse.c Normal file
View File

@@ -0,0 +1,40 @@
#include <ultra64.h>
#include <PR/gs2dex.h>
#include "s2d_draw.h"
#define SCALE '\x80'
#define ROT '\x81'
#define TRANSLATE '\x82'
#define CH_GET_NEXT(x) (*(++x))
void s2d_parse(const char *str) {
char *p = str;
while (*(p++) != '\0') {
char r = *p;
char s, t, x, y;
switch (r) {
case SCALE:
s = CH_GET_NEXT(p);
myScale = s;
break;
case ROT:
t = CH_GET_NEXT(p);
degrees = t;
break;
case TRANSLATE:
x = CH_GET_NEXT(p);
y = CH_GET_NEXT(p);
default:
x = 0;
// print(r);
}
}
}

33
stack.c Normal file
View File

@@ -0,0 +1,33 @@
#include <ultra64.h>
#include <PR/gs2dex.h>
// My matrix stack for S2DEX transformations.
// Probably doesnt need to be 0x80 long
#define ARRAY_COUNT(x) (sizeof(x) / sizeof(x[0]))
uObjMtx stack[0x80];
u32 stack_top = 0;
u32 s_isfull(void) {
return (stack_top >= ARRAY_COUNT(stack));
}
u32 s_isempty(void) {
return (stack_top == 0);
}
void s_push(uObjMtx *f) {
if (!s_isfull())
stack[++stack_top] = *f;
}
uObjMtx *s_pop(void) {
if (!s_isempty())
return &stack[stack_top--];
}
void s_clear(void) {
stack_top = 0;
}

12
stack.h Normal file
View File

@@ -0,0 +1,12 @@
#include <ultra64.h>
#include <PR/gs2dex.h>
extern uObjMtx stack[0x80];
extern u32 stack_top;
extern u32 s_isfull(void);
extern u32 s_isempty(void);
extern void s_push(uObjMtx *f);
extern uObjMtx *s_pop(void);
extern void s_clear(void);