Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some new features and bug fixes in thecl #59

Merged
merged 30 commits into from
Aug 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
7ccbecd
thecl: Add ZUN-style difficulty switches for writing custom ECL
Priw8 Aug 24, 2019
348d4f3
thecl: Don't force typecasts for instruction calls
Priw8 Aug 24, 2019
b6fbf4a
thecl: syntax for writing degree-floats (auto converts value to radians)
Priw8 Aug 24, 2019
27c53b6
thecl: add syntax for writing binary integer literals
Priw8 Aug 24, 2019
77825e1
thecl: this way of writing degree floats should be less weird
Priw8 Aug 25, 2019
323765f
thecl: fix passing expressions to sub calls by name
Priw8 Aug 25, 2019
d70bd9b
thecl: add forced sub calls by name
Priw8 Aug 25, 2019
5fe9ac5
thecl: allow var declarations anywhere in the sub
Priw8 Aug 25, 2019
c59777c
thecl: declare and assign values to vars at once
Priw8 Aug 25, 2019
9841d89
thecl: fix sub calls by name that don't contain any parameters
Priw8 Aug 25, 2019
ca9634c
thecl: fix difficulty switches (how did that ever work for me!?)
Priw8 Aug 25, 2019
e9b899f
util: add list_tail
Priw8 Aug 25, 2019
8f23627
thecl: automatically add ins_10 if there is no ins_10/ins_1 at the en…
Priw8 Aug 25, 2019
3876845
thecl: check version for automatic ins adding and difficulty switches
Priw8 Aug 25, 2019
eb7340a
thecl: set time of ins_40 to 0
Priw8 Aug 25, 2019
33d82ab
thecl: error when a variable is redeclared
Priw8 Aug 26, 2019
60b6a3b
thecl: better difficulty switch expression
Priw8 Aug 26, 2019
9ffc742
thecl: improve short difficulty switches
Priw8 Aug 26, 2019
0ed9688
thecl: no overdrive in pre-th13 diff switches
Priw8 Aug 26, 2019
c07e372
thecl: add "times" loop known from ZUN's ECL
Priw8 Aug 26, 2019
e3acf54
thecl: get ins numbers from expr symbols/defines
Priw8 Aug 26, 2019
f4fe2b8
thecl: add simple creation mode
Priw8 Aug 26, 2019
284e1a0
thecl: better diff switch code
Priw8 Aug 27, 2019
65ca666
thecl: break statement for times loop
Priw8 Aug 27, 2019
e3c8187
thecl: don't require instruction after rank setting statement
Priw8 Aug 27, 2019
6fb8f92
thecl: change forced sub calls by name syntax
Priw8 Aug 27, 2019
315ac25
thecl: define call ins numbers
Priw8 Aug 27, 2019
1321864
thecl: fix break statement
Priw8 Aug 27, 2019
8a520b0
thecl: fix pre-th10 difficulty flag dumping
Priw8 Aug 27, 2019
06758a0
thecl: error on stack variable creation in pre-th10
Priw8 Aug 27, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
422 changes: 382 additions & 40 deletions thecl/ecsparse.y

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions thecl/ecsscan.l
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"else" return ELSE;
"do" return DO;
"while" return WHILE;
"times" return TIMES;
"switch" return SWITCH;
"case" return CASE;
"break" return BREAK;
Expand Down Expand Up @@ -126,6 +127,10 @@ _fS return CAST_FI;
yylval.floating = strtof(yytext, NULL);
return FLOATING;
}
rad\(-?[0-9]+(\.[0-9]*)?f\) {
yylval.floating = strtof(yytext+4, NULL) / 180.0f * 3.14159265359f;
return FLOATING;
}
ins_[0-9]+ {
yylval.integer = strtol(yytext + 4, NULL, 10);
return INSTRUCTION;
Expand All @@ -138,6 +143,12 @@ ins_[0-9]+ {
yylval.integer = strtol(yytext, NULL, 16);
return INTEGER;
}
-?0b[0-1]+ {
bool isNegative = yytext[0] == '-';
yylval.integer = strtol(yytext + (isNegative ? 3 : 2), NULL, 2);
if (isNegative) yylval.integer = -yylval.integer;
return INTEGER;
}
![-*ENHLWXYZO4567]+ {
yylval.string = strdup(yytext + 1);
return RANK;
Expand Down
14 changes: 1 addition & 13 deletions thecl/expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,7 @@ th10_expressions[] = {
static const expr_t*
expr_get_table(unsigned int version)
{
if ( version == 10
|| version == 103
|| version == 11
|| version == 12
|| version == 125
|| version == 128
|| version == 13
|| version == 14
|| version == 143
|| version == 15
|| version == 16
|| version == 165
|| version == 17)
if (not_pre_th10(version))
return th10_expressions;
return th10_no_expressions;
}
Expand Down
32 changes: 31 additions & 1 deletion thecl/thecl.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ extern const thecl_module_t th10_ecl;
eclmap_t* g_eclmap_opcode = NULL;
eclmap_t* g_eclmap_global = NULL;
bool g_ecl_rawoutput = false;
bool g_ecl_simplecreate = false;
bool g_was_error = false;

thecl_t*
Expand Down Expand Up @@ -173,6 +174,25 @@ free_eclmaps(void)
eclmap_free(g_eclmap_global);
}

int
not_pre_th10(
unsigned int version)
{
return version == 10
|| version == 103
|| version == 11
|| version == 12
|| version == 125
|| version == 128
|| version == 13
|| version == 14
|| version == 143
|| version == 15
|| version == 16
|| version == 165
|| version == 17;
}

static void
print_usage(void)
{
Expand All @@ -183,6 +203,7 @@ print_usage(void)
" -V display version information and exit\n"
" -m use map file for translating mnemonics\n"
" -r output raw ECL opcodes, applying minimal transformations\n"
" -s use simple creation, which doesn't add any instructions automatically\n"
"VERSION can be:\n"
" 6, 7, 8, 9, 95, 10, 103 (for Uwabami Breakers), 11, 12, 125, 128, 13, 14, 143, 15, 16, 165 or 17\n"
"Report bugs to <" PACKAGE_BUGREPORT ">.\n", argv0);
Expand All @@ -208,7 +229,7 @@ main(int argc, char* argv[])
int opt;
int ind=0;
while(argv[util_optind]) {
switch(opt = util_getopt(argc, argv, ":c:d:Vm:r")) {
switch(opt = util_getopt(argc, argv, ":c:d:Vm:r:s")) {
case 'c':
case 'd':
if(mode != -1) {
Expand All @@ -234,6 +255,9 @@ main(int argc, char* argv[])
case 'r':
g_ecl_rawoutput = true;
break;
case 's':
g_ecl_simplecreate = true;
break;
default:
util_getopt_default(&ind,argv,opt,print_usage);
}
Expand Down Expand Up @@ -284,6 +308,12 @@ main(int argc, char* argv[])
exit(1);
}
}
if (g_ecl_simplecreate) {
if (mode != 'c') {
fprintf(stderr, "%s: 's' option cannot be used while dumping\n", argv0);
exit(1);
}
}

if (0 < argc) {
current_input = argv[0];
Expand Down
11 changes: 11 additions & 0 deletions thecl/thecl.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ typedef enum {
#define RANK_ID_6 (1 << 6)
#define RANK_ID_7 (1 << 7)

// Numbers of important ECL instructions
#define TH10_INS_RET_BIG 1
#define TH10_INS_RET_NORMAL 10
#define TH10_INS_CALL 11
#define TH10_INS_CALL_ASYNC 15
#define TH10_INS_STACK_ALLOC 40

typedef struct thecl_param_t {
int type;
value_t value;
Expand All @@ -69,6 +76,9 @@ thecl_param_t* param_new(
void param_free(
thecl_param_t* param);

int not_pre_th10(
unsigned int version);

typedef struct thecl_instr_t {
thecl_instr_type type;
char* string;
Expand Down Expand Up @@ -188,6 +198,7 @@ extern int yyparse(parser_state_t*);
extern eclmap_t* g_eclmap_opcode;
extern eclmap_t* g_eclmap_global;
extern bool g_ecl_rawoutput;
extern bool g_ecl_simplecreate;
extern bool g_was_error;

#endif
8 changes: 4 additions & 4 deletions thecl/thecl06.c
Original file line number Diff line number Diff line change
Expand Up @@ -865,10 +865,10 @@ th06_dump(
(instr->rank) & RANK_NORMAL ? "N" : "",
(instr->rank) & RANK_HARD ? "H" : "",
(instr->rank) & RANK_LUNATIC ? "L" : "",
!((instr->rank) & RANK_ID_4) ? "W" : "",
!((instr->rank) & RANK_ID_5) ? "X" : "",
!((instr->rank) & RANK_ID_6) ? "Y" : "",
!((instr->rank) & RANK_ID_7) ? "Z" : "");
!((instr->rank) & RANK_ID_4) ? "4" : "",
!((instr->rank) & RANK_ID_5) ? "5" : "",
!((instr->rank) & RANK_ID_6) ? "6" : "",
!((instr->rank) & RANK_ID_7) ? "7" : "");
}
break;
case THECL_INSTR_INSTR: {
Expand Down
10 changes: 10 additions & 0 deletions util/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ list_head(
return NULL;
}

void*
list_tail(
list_t* list)
{
if (list->tail)
return list->tail->data;
else
return NULL;
}

int
list_empty(
list_t* list)
Expand Down
2 changes: 2 additions & 0 deletions util/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ list_t* list_new(void);
list_node_t* list_node_new(void);
/* Returns the data of head in the list. */
void* list_head(list_t* list);
/* Returns the data of tail in the list. */
void* list_tail(list_t* list);
/* Returns 1 if the list is empty. */
int list_empty(list_t* list);
/* Sets a node as the tail of the list. */
Expand Down