updated readme to have some better sample code

This commit is contained in:
farisawan-2000
2021-01-07 14:07:27 -05:00
parent be343003fc
commit 13e5ecbdbb
6 changed files with 27 additions and 17 deletions

View File

@@ -18,10 +18,15 @@ char myString[] = "This is a " SCALE "2" "test string!\n"
// ...
void some_func(void) {
// initialized S2DEX; only needed once before all prints
s2d_init();
uObjMtx *buffer;
// substitute with a different alloc function as neccesary
buffer = alloc_display_list(0x200 * sizeof(uObjMtx));
s2d_print(50, 50, myString, buffer);
// reloads the original microcode; only needed once after all prints
s2d_stop();
}
```

6
mtx.c
View File

@@ -28,11 +28,11 @@ void mat2_copy(uObjMtx *dst, uObjMtx *src) {
dst->m.Y = src->m.Y;
}
void mat2_ident(uObjMtx *dst, int scale) {
dst->m.A = scale << 16;
void mat2_ident(uObjMtx *dst, float scale) {
dst->m.A = (1 << 16);
dst->m.B = 0;
dst->m.C = 0;
dst->m.D = scale << 16;
dst->m.D = (1 << 16);
dst->m.X = 0;
dst->m.Y = 0;

2
mtx.h
View File

@@ -8,7 +8,7 @@ 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_ident(uObjMtx *dst, float scale);
extern void mat2_mul(uObjMtx *m1, uObjMtx *m2);

View File

@@ -44,20 +44,20 @@ void setup_font_texture(int idx) {
// Original Mtx Pipeline
// Distorts when rotating, but is faster
void mtx_pipeline(uObjMtx *m, int x, int y) {
// init
mat2_ident(m, 1);
mat2_ident(&rot_mtx, 1);
// void mtx_pipeline(uObjMtx *m, int x, int y) {
// // init
// mat2_ident(m, 1);
// mat2_ident(&rot_mtx, 1);
// create rot matrix
mat2_rotate(&rot_mtx, (myDegrees) * (M_PI / 180.0f));
// scale m
mat2_scale(m, myScale);
mat2_dst_mul(m,m, &rot_mtx);
mat2_translate(m, x, y);
// // create rot matrix
// mat2_rotate(&rot_mtx, (myDegrees) * (M_PI / 180.0f));
// // scale m
// mat2_scale(m, myScale);
// mat2_dst_mul(m,m, &rot_mtx);
// mat2_translate(m, x, y);
gSPObjMatrix(gdl_head++, m);
}
// gSPObjMatrix(gdl_head++, m);
// }
// New matrix pipeline
// Works with both rotation and scale,

View File

@@ -18,7 +18,7 @@ char impact_kerning_table[] = {
/* , */ 3,
/* - */ 5,
/* . */ 3,
/* / */ 4,
/* / */ 8,
/* 0 */ 6,
/* 1 */ 5,
/* 2 */ 6,

View File

@@ -88,6 +88,11 @@ void s2d_print(int x, int y, const char *str, uObjMtx *buf) {
s2d_snprint(x, y, str, buf, s2d_strlen(str));
}
void s2d_print_alloc(int x, int y, const char *str) {
uObjMtx *b = alloc(sizeof(uObjMtx) * s2d_strlen(str));
s2d_snprint(x, y, str, b, s2d_strlen(str));
}
void s2d_type_print(int x, int y, const char *str, uObjMtx *buf, int *pos) {
int len = s2d_strlen(str);