From ac3c4dbf759f4de1b5086245f19ab525b03949a3 Mon Sep 17 00:00:00 2001 From: farisawan-2000 Date: Tue, 15 Dec 2020 17:46:07 -0500 Subject: [PATCH] text typing now in a suitable release state --- config.h | 3 ++ s2d_parse.c | 46 +++++++++++++----------------- s2d_print.h | 2 +- s2d_ustdlib.c | 39 ++++++++++++++++++++++++++ s2d_ustdlib.h | 8 ++++++ x86_testing_ground/atoi.c | 59 ++++++++++++++++++++++++++++++++++----- 6 files changed, 122 insertions(+), 35 deletions(-) create mode 100644 s2d_ustdlib.c create mode 100644 s2d_ustdlib.h diff --git a/config.h b/config.h index f148460a..1970a816 100644 --- a/config.h +++ b/config.h @@ -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 \ No newline at end of file diff --git a/s2d_parse.c b/s2d_parse.c index 86d52492..802b3276 100644 --- a/s2d_parse.c +++ b/s2d_parse.c @@ -2,29 +2,15 @@ #include #include +#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)++; + } } diff --git a/s2d_print.h b/s2d_print.h index 6596d865..6c527416 100644 --- a/s2d_print.h +++ b/s2d_print.h @@ -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); diff --git a/s2d_ustdlib.c b/s2d_ustdlib.c new file mode 100644 index 00000000..183c0e7b --- /dev/null +++ b/s2d_ustdlib.c @@ -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; +} diff --git a/s2d_ustdlib.h b/s2d_ustdlib.h new file mode 100644 index 00000000..d68df011 --- /dev/null +++ b/s2d_ustdlib.h @@ -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); diff --git a/x86_testing_ground/atoi.c b/x86_testing_ground/atoi.c index e1b23abf..48fee781 100644 --- a/x86_testing_ground/atoi.c +++ b/x86_testing_ground/atoi.c @@ -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)); } \ No newline at end of file