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

New thanm spec format (also featuring th18 support) #86

Merged
merged 59 commits into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
d68a662
thanm: new script dump format
Priw8 Feb 14, 2020
5b20433
util: move seqmap from thecl/ to util/
Priw8 Feb 14, 2020
44f714f
thanm: add mnemonic mapping
Priw8 Feb 14, 2020
99ad1a6
thanm: use a more convenient struct for instrs
Priw8 Feb 14, 2020
bb5074b
thanm: add labels (v8 only for now)
Priw8 Feb 15, 2020
8a9008a
thanm: add named script/sprite dumps (v8)
Priw8 Feb 15, 2020
1580d6b
thanm: new entry dump format
Priw8 Feb 15, 2020
edd985c
thanm: add missing newlines
Priw8 Feb 15, 2020
ee732aa
thanm: require -o for anm creation with old spec
Priw8 Feb 15, 2020
a8d4d10
thanm: add nullptr check for old spec parsing
Priw8 Feb 15, 2020
c308d9a
thanm: remove useless parens, scripts take no args
Priw8 Feb 15, 2020
1b4ea93
thanm: fix spacing
Priw8 Feb 15, 2020
dab4c33
thanm: fix spec file indentation
Priw8 Feb 15, 2020
8233a13
thanm: somehow, this built without these headers
Priw8 Feb 15, 2020
6c0063a
thanm: add (still WIP) new format parser
Priw8 Feb 16, 2020
76d93a6
thanm: fix new format v0 recompilation
Priw8 Feb 17, 2020
9b81110
thanm: fix dumping unnecessary IDs
Priw8 Feb 17, 2020
da3d6c5
thanm: support negative script IDs
Priw8 Feb 17, 2020
4513b6d
thanm: add missing v8 formats
Priw8 Feb 17, 2020
e0b426f
thanm: make labels local to scripts
Priw8 Feb 17, 2020
18f2c25
thanm: add #version directive
Priw8 Feb 17, 2020
c7177ee
thanm: dump hasData=0, default hasData to 1
Priw8 Feb 17, 2020
d0acf2c
thanm: allow ommiting most entry properties
Priw8 Feb 17, 2020
19ab98a
thanm: add global definitions
Priw8 Feb 18, 2020
0918613
thanm: error if there is no entry before a script
Priw8 Feb 18, 2020
b4882c2
thanm: add timeof(label) operator-like thing
Priw8 Mar 1, 2020
85ba4b0
thanm: allow sprite/script names without quotes
Priw8 Mar 7, 2020
f1b1587
thanm: add offsetof, scriptof and spriteof operators
Priw8 Mar 7, 2020
d42f8e0
thanm: change PropertyList syntax
Priw8 Mar 13, 2020
e2a041c
thanm: add #anmmap directive
Priw8 Mar 13, 2020
10011ec
thecl/util: move path to util
Priw8 Mar 13, 2020
21c426c
thanm: add #include directive
Priw8 Mar 13, 2020
822e394
thanm: variables and expressions
Priw8 Mar 21, 2020
54694ad
thanm: use current version, not default version
Priw8 Mar 21, 2020
d754fbb
thanm: fix crash when no operators are found
Priw8 Mar 21, 2020
1accd78
thanm: don't read files of entries with no data
Priw8 Apr 28, 2020
edae10b
thanm: allow exporting symbols to a file
Priw8 Jun 2, 2020
bd2339f
thanm: fix possible print_usage string confusion
Priw8 Jun 2, 2020
c56b625
thanm: fix the symbol file not being closed when using -o
Priw8 Jun 2, 2020
4ec42e2
thanm: add compile-time expression evaluation
Priw8 Jul 27, 2020
0e41e68
thanm: add a few missing v8 formats
Priw8 Jul 31, 2020
236101a
thanm: add more v8 formats
Priw8 Aug 2, 2020
1f1ad88
thanm: add 's' format support
Priw8 Aug 3, 2020
ce334f3
thanm: print opcode name in instr_check_types errors
Priw8 Aug 3, 2020
a284731
thanm: fix variable dumping for 's' format
Priw8 Aug 3, 2020
29628ef
fix remaining signatures in v4 and v8 anm
ExpHP Aug 20, 2020
7e80046
Merge pull request #82 from ExpHP/patch-1
Priw8 Aug 20, 2020
2b2710b
thanm: fix negative script id recompiling
Priw8 Aug 20, 2020
0c6d805
fix all anm v3 signatures
ExpHP Aug 24, 2020
87d4d2a
fix anm v2 signatures
ExpHP Aug 24, 2020
b30bbf0
Fix anm v0 signatures
ExpHP Aug 29, 2020
b7321bb
Merge pull request #83 from ExpHP/patch-2
Priw8 Aug 31, 2020
f0c9913
thanm: fix v0 label offset calculation
Priw8 Sep 1, 2020
f34ea08
thanm: add operators and registers for non-v8
Priw8 Mar 20, 2021
8a1e372
thanm: don't crash on unknown instructions
Priw8 Mar 21, 2021
1325504
thanm: add th18 ins_614 format
Priw8 Mar 21, 2021
6d6a92d
thanm: remove old format support
Priw8 Mar 21, 2021
4dc7730
thanm: display a message for old spec files
Priw8 Mar 21, 2021
3adc7a9
thanm: UM full ver support
Priw8 May 4, 2021
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
11 changes: 8 additions & 3 deletions thanm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
include_directories(${PNG_INCLUDE_DIRS})
find_package(BISON REQUIRED)
find_package(FLEX REQUIRED)
bison_target(AnmParse anmparse.y ${CMAKE_CURRENT_BINARY_DIR}/anmparse.c COMPILE_FLAGS ${BISON_FLAGS})
flex_target(AnmScan anmscan.l ${CMAKE_CURRENT_BINARY_DIR}/anmscan.c)
include_directories(${PNG_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
add_executable(thanm
thanm.c image.c
thanm.h image.h
${BISON_AnmParse_OUTPUT_SOURCE} ${FLEX_AnmScan_OUTPUTS}
thanm.c image.c anmmap.c reg.c expr.c
thanm.h image.h anmmap.h reg.h expr.h
)
target_link_libraries(thanm util ${PNG_LIBRARY})
link_setargv(thanm)
Expand Down
181 changes: 181 additions & 0 deletions thanm/anmmap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
/*
* Redistribution and use in source and binary forms, with
* or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain this list
* of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce this
* list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*/

#include <config.h>
#include <stdlib.h>
#include <string.h>
#include "anmmap.h"
#include "program.h"
#include "util.h"

anmmap_t*
anmmap_new() {
anmmap_t* map = (anmmap_t*)malloc(sizeof(anmmap_t));
if (map) {
map->ins_names = seqmap_new();
map->gvar_names = seqmap_new();
map->gvar_types = seqmap_new();
}
return map;
}

void
anmmap_free(
anmmap_t* map
) {
if (map) {
seqmap_free(map->ins_names);
seqmap_free(map->gvar_names);
seqmap_free(map->gvar_types);
free(map);
}
}

typedef struct state_t {
anmmap_t* amap;
seqmap_t* smap;
int ident;
const char* fn;
} state_t;

static int
control(
state_t* state,
int linenum,
const char* cline
) {
if (!strcmp(cline, "!ins_names")) {
state->smap = state->amap->ins_names;
state->ident = 1;
} else if (!strcmp(cline, "!gvar_names")) {
state->smap = state->amap->gvar_names;
state->ident = 1;
} else if (!strcmp(cline, "!gvar_types")) {
state->smap = state->amap->gvar_types;
state->ident = 0;
} else {
fprintf(stderr, "%s:%s:%u: unknown control line '%s'\n", argv0, state->fn, linenum, cline);
return 1;
}
return 0;
}

static int
is_keyword(
const char* value)
{
static const char* keywords[] = {
"script", "entry", "global", "int", "float",
"rand", "sin", "cos", "tan", "acos", "atan",
"timeof", "offsetof", "scriptof", "spriteof",
NULL
};
const char** kwp = keywords;
while (*kwp) {
if (!strcmp(value, *kwp++)) {
return 1;
}
}
return 0;
}

static int
validate_ident(
state_t* state,
int linenum,
const char* value)
{
const char* ptr = value;
if (ptr[0] >= '0' && ptr[0] <= '9') { /* first character must not be digit */
fprintf(stderr, "%s:%s:%u: '%s' isn't valid identifier\n", argv0, state->fn, linenum, value);
return 1;
}
while (*ptr) {
if (!(*ptr >= '0' && *ptr <= '9' || *ptr >= 'a' && *ptr <= 'z' || *ptr >= 'A' && *ptr <= 'Z' || *ptr == '_')) {
break;
}
ptr++;
}
if (*ptr) {
fprintf(stderr, "%s:%s:%u: '%s' isn't valid identifier\n", argv0, state->fn, linenum, value);
return 1;
}
if (!util_strcmp_ref(value, stringref("ins_"))) {
fprintf(stderr, "%s:%s:%u: mnemonic can't start with 'ins_'\n", argv0, state->fn, linenum);
return 1;
}
else if (is_keyword(value)) {
fprintf(stderr, "%s:%s:%u: '%s' is a keyword, ignoring\n", argv0, state->fn, linenum, value);
return 1;
}
return 0;
}

static int
validate_type(
state_t* state,
int linenum,
const char* ptr)
{
if (ptr[0] != '$' && ptr[0] != '%' || ptr[0] && ptr[1]) {
fprintf(stderr, "%s:%s:%u: unknown type '%s'\n", argv0, state->fn, linenum, ptr);
return 1;
}
return 0;
}

static int
set(
state_t* state,
int linenum,
const seqmap_entry_t* ent
) {
if (state->ident) {
if (validate_ident(state, linenum, ent->value))
return 1;
} else if (state->smap == state->amap->gvar_types) {
if (validate_type(state, linenum, ent->value))
return 1;
}
seqmap_set(state->smap, ent);
return 0;
}

void
anmmap_load(
anmmap_t* map,
FILE* file,
const char* fn
) {
state_t state;
state.amap = map;
state.fn = fn;
control(&state, 0, "!ins_names");
seqmap_load("!anmmap", &state, (seqmap_setfunc_t)set, (seqmap_controlfunc_t)control, file, fn);
}
46 changes: 46 additions & 0 deletions thanm/anmmap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Redistribution and use in source and binary forms, with
* or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain this list
* of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce this
* list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*/

#ifndef ANMMAP_H_
#define ANMMAP_H_

#include <config.h>
#include "seqmap.h"

typedef struct anmmap_t {
seqmap_t* ins_names;
seqmap_t* gvar_names;
seqmap_t* gvar_types;
} anmmap_t;

anmmap_t* anmmap_new();
void anmmap_free(anmmap_t* map);
void anmmap_load(anmmap_t* map, FILE* file, const char* fn);

#endif
Loading