text typing now in a suitable release state

This commit is contained in:
farisawan-2000
2020-12-15 17:46:07 -05:00
parent 29855712a8
commit ac3c4dbf75
6 changed files with 122 additions and 35 deletions

View File

@@ -18,4 +18,7 @@ extern Gfx *gdl_head;
// Other games: change this to the appropriate alloc function
#define alloc alloc_display_list
// The frame timer that is used to time s2d_type_print
#define s2d_timer gGlobalTimer
#endif

View File

@@ -2,29 +2,15 @@
#include <PR/gs2dex.h>
#include <PR/gu.h>
#include "config.h"
#include "s2d_draw.h"
#include "s2d_print.h"
#include "s2d_ustdlib.h"
int saved_degrees = 0;
int s2d_atoi(char *s, char **s2) {
int ret = 0;
int isNegative = (*s == '-');
if (isNegative) {
s++;
(*s2)++;
}
for (; *s != '\0' && *s != ' ' && *s >= '0' && *s <= '9'; s++) {
ret *= 10;
if (*s >= '0' && *s <= '9')
ret += *s - '0';
else break;
if (!(*(s+1) != '\0' && *(s+1) != ' ' && *(s+1) >= '0' && *(s+1) <= '9')) break;
(*s2)++;
}
if (isNegative) ret *= -1;
return ret;
}
extern u32 gGlobalTimer;
@@ -68,8 +54,6 @@ void s2d_print(int x, int y, const char *str, uObjMtx *buf) {
s2d_alpha = s2d_atoi(p, &p);
break;
break;
default:
if (myDegrees == 0)
draw_s2d_glyph(r, (x += (8 * myScale)) + tx, y + ty, (buf++));
@@ -77,6 +61,7 @@ void s2d_print(int x, int y, const char *str, uObjMtx *buf) {
draw_s2d_glyph(r, (x += ((8 * myScale))) + tx, y + ty, (buf++));
}
// myDegrees += saved_degrees;
if (*p == '\0') break;
p++;
} while (*p != '\0');
myScale = 1;
@@ -88,15 +73,22 @@ void s2d_print(int x, int y, const char *str, uObjMtx *buf) {
void s2d_type_print(int x, int y, char *str, uObjMtx *buf, int *pos) {
char *temp_str = str;
char t = temp_str[*pos];
switch(t) {
case CH_TRANSLATE:
CH_SKIP(temp_str);
s2d_atoi(temp_str, &temp_str);
char tmp = temp_str[*pos];
int len = s2d_strlen(str);
switch(tmp) {
case CH_SCALE:
(*pos) += s2d_ilen(str + *pos + 2);
break;
case CH_ROT:
(*pos) += 2;
}
temp_str[*pos] = '\0';
s2d_print(x, y, temp_str, buf);
temp_str[*pos] = t;
(*pos)++;
temp_str[*pos] = tmp;
if (s2d_timer % 2 == 0) {
if (*pos < len)
(*pos)++;
}
}

View File

@@ -15,6 +15,6 @@
#define CH_NEWLINE '\n'
#define CH_GET_NEXT(x) (*(++x))
#define CH_SKIP(x) ((++x))
#define CH_SKIP(x) ((x++))
extern void s2d_print(int x, int y, const char *str, uObjMtx *buf);

39
s2d_ustdlib.c Normal file
View File

@@ -0,0 +1,39 @@
// ustdlib means un-standard library
// i'm going to abuse so much of my power here lol
int s2d_atoi(char *s, char **s2) {
int ret = 0;
int isNegative = (*s == '-');
if (isNegative) {
s++;
(*s2)++;
}
for (; *s != '\0' && *s != ' ' && *s >= '0' && *s <= '9'; s++) {
ret *= 10;
if (*s >= '0' && *s <= '9')
ret += *s - '0';
else break;
if (!(*(s+1) != '\0' && *(s+1) != ' ' && *(s+1) >= '0' && *(s+1) <= '9')) break;
(*s2)++;
}
// (*s2)--;
if (isNegative) ret *= -1;
return ret;
}
int s2d_ilen(char *s) {
int ret = 0;
char *p = s;
while (*p >= '0' && *p <= '9') {
ret++;
p++;
}
return ret;
}
int s2d_strlen(char *s) {
int result;
char *p = s;
do {result++;} while (*(++p) != '\0');
return result;
}

8
s2d_ustdlib.h Normal file
View File

@@ -0,0 +1,8 @@
// ustdlib means un-standard library
// i'm going to abuse so much of my power here lol
extern int s2d_atoi(char *s, char **s2);
extern int s2d_ilen(char *s);
extern int s2d_strlen(char *s);

View File

@@ -110,17 +110,62 @@ void s2d_print(int x, int y, char *str) {
ty = 0;
}
void s2d_type_print(int x, int y, char *str, int pos) {
char t = str[pos];
str[pos] = '\0';
s2d_print(x, y, str);
str[pos] = t;
int s2d_ilen(char *s) {
int ret = 0;
char *p = s;
while (*p >= '0' && *p <= '9') {
ret++;
p++;
}
return ret;
}
void s2d_type_print(int x, int y, char *str, int *pos) {
char *temp_str = str;
char tmp = temp_str[*pos];
int len = strlen(str);
char current_transformation;
int cur_transform_index;
switch(tmp) {
case CH_SCALE:
current_transformation = CH_SCALE;
cur_transform_index = *pos;
// temp_str[*pos] = ' ';
printf("SCALE %c %d\n", str[*pos + 1], s2d_ilen(str + *pos + 1));
(*pos) += s2d_ilen(str + *pos+2) + 1;
break;
case CH_ROT:
(*pos) += 2;
}
// temp_str[*pos] = '\0';
// s2d_print(x, y, temp_str);
// // temp_str[cur_transform_index] = current_transformation;
// temp_str[*pos] = tmp;
// if (gGlobalTimer % 5 == 0) {
if (*pos < len)
(*pos)++;
// }
}
char sss[] = SCALE "2";
// SCALE "4"
// "big chungus";
char myS[] = "small test"
SCALE "2"
"big test"
SCALE "0001"
"small chungus";
int pos;
int main(void) {
// printf("%d\n", s2d_atoi(s, &s));
// printf("%s\n", s);
s2d_print(0,0, t);
// printf("%d\n", s2d_atoi("3582932j"));
// s2d_print(0,0, t);
while (pos != strlen(myS)) {
s2d_type_print(0, 0, myS, &pos);
printf("%d %c\n", pos, myS[pos]);
}
// printf("%d\n", s2d_ilen(sss + 1));
}