From 3a7491244ab0add7e17c0fa75a157cd07af309ed Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sun, 19 Jan 2025 07:17:23 +0100 Subject: [PATCH] ulas: Added .section directive This directive allows a user to define the memory region. This is currently only used for mlb symbol files. --- man/ulas.1 | 4 ++-- man/ulas.5 | 13 ++++++++++--- src/ulas.c | 47 ++++++++++++++++++++++++++++++++++++++--------- src/ulas.h | 7 +++++++ tests/t0.s | 3 +++ 5 files changed, 60 insertions(+), 14 deletions(-) diff --git a/man/ulas.1 b/man/ulas.1 index b2ce502..4614691 100644 --- a/man/ulas.1 +++ b/man/ulas.1 @@ -1,7 +1,7 @@ .\" Manpage for ulas. .\" Contact lukas@krickl.dev to correct errors or typos. -.TH man 1 "29 October 2024" "0.0.1" "ulas manual" +.TH man 1 "19 January 2025" "0.0.1" "ulas manual" .SH NAME ulas @@ -77,4 +77,4 @@ Lukas Krickl (lukas@krickl.dev) .SH COPYRIGHT - Copyright 2024 Lukas Krickl (lukas@krickl.dev) + Copyright 2025 Lukas Krickl (lukas@krickl.dev) diff --git a/man/ulas.5 b/man/ulas.5 index 785395d..ec22dfd 100644 --- a/man/ulas.5 +++ b/man/ulas.5 @@ -1,7 +1,7 @@ .\" Manpage for ulas. .\" Contact lukas@krickl.dev to correct errors or typos. -.TH man 1 "29 October 2024" "0.0.1" "ulas language reference" +.TH man 5 "19 January 2025" "0.0.1" "ulas language reference" .SH PREPROCESSOR @@ -128,7 +128,7 @@ The special value $ will evaluate to the current address. Re-defines the ascii value for one character to another value. Can be used for custom encodings. -.SH .chr +.SH chr \.chr 01233213 Outputs a byte as a 2bpp sprite. Must have exactly 8 values ranging from 0-3 @@ -138,6 +138,13 @@ The special value $ will evaluate to the current address. Repeats the instruction n times advancing from 0 by step each iteration. The first parameter is a counter value that allows the instruction to access the current iterator value. + +.SH section + \.section + Defines a section name. + This is currently only used for mlb symbol files, but might be added to other areas in the future. + If no section was defined the .section directive will use pre-defined values for mlb outputs. + .SH SEE ALSO ulas(1) for a rference on how to use ulas. @@ -146,4 +153,4 @@ The special value $ will evaluate to the current address. Lukas Krickl (lukas@krickl.dev) .SH COPYRIGHT - Copyright 2024 Lukas Krickl (lukas@krickl.dev) + Copyright 2025 Lukas Krickl (lukas@krickl.dev) diff --git a/src/ulas.c b/src/ulas.c index 33d3192..2b0acbd 100644 --- a/src/ulas.c +++ b/src/ulas.c @@ -365,6 +365,11 @@ int ulas_symbolset(const char *cname, int scope, struct ulas_tok tok, } int ulas_symbolout_mlbloc(FILE *dst, long addr) { + if (ulas.section[0] != '\0') { + fprintf(dst, "%s:", ulas.section); + return 0; + } + if (addr == -1) { fprintf(dst, "Unknown:"); return 0; @@ -2430,6 +2435,18 @@ int ulas_asmdirrep(FILE *dst, FILE *src, const char **line, unsigned long n) { return rc; } +int ulas_asmdirsection(FILE *dst, FILE *src, const char **line, + unsigned long n) { + ulas_tok(&ulas.tok, line, n); + if (!ulas_isname(ulas.tok.buf, + MIN(strlen(ulas.tok.buf), ulas.tok.maxlen))) { + ULASERR("Unexpected token '%s'\n", ulas.tok.buf); + return -1; + } + strncpy(ulas.section, ulas.tok.buf, ULAS_SECTIONMAX); + return 0; +} + int ulas_asmline(FILE *dst, FILE *src, const char *line, unsigned long n) { // this buffer is written both to dst and to verbose output char outbuf[ULAS_OUTBUFMAX]; @@ -2466,14 +2483,23 @@ int ulas_asmline(FILE *dst, FILE *src, const char *line, unsigned long n) { } if (ulas.tok.buf[0] == ULAS_TOK_ASMDIR_BEGIN) { - const char *dirstrs[] = {ULAS_ASMSTR_ORG, ULAS_ASMSTR_SET, - ULAS_ASMSTR_BYTE, ULAS_ASMSTR_STR, - ULAS_ASMSTR_FILL, ULAS_ASMSTR_PAD, - ULAS_ASMSTR_INCBIN, ULAS_ASMSTR_DEF, - ULAS_ASMSTR_CHKSM, ULAS_ASMSTR_ADV, - ULAS_ASMSTR_SET_ENUM_DEF, ULAS_ASMSTR_DEFINE_ENUM, - ULAS_ASMSTR_SETCHRCODE, ULAS_ASMSTR_CHR, - ULAS_ASMSTR_REP, NULL}; + const char *dirstrs[] = {ULAS_ASMSTR_ORG, + ULAS_ASMSTR_SET, + ULAS_ASMSTR_BYTE, + ULAS_ASMSTR_STR, + ULAS_ASMSTR_FILL, + ULAS_ASMSTR_PAD, + ULAS_ASMSTR_INCBIN, + ULAS_ASMSTR_DEF, + ULAS_ASMSTR_CHKSM, + ULAS_ASMSTR_ADV, + ULAS_ASMSTR_SET_ENUM_DEF, + ULAS_ASMSTR_DEFINE_ENUM, + ULAS_ASMSTR_SETCHRCODE, + ULAS_ASMSTR_CHR, + ULAS_ASMSTR_REP, + ULAS_ASMSTR_SECTION, + NULL}; enum ulas_asmdir dirs[] = { ULAS_ASMDIR_ORG, ULAS_ASMDIR_SET, ULAS_ASMDIR_BYTE, ULAS_ASMDIR_STR, @@ -2482,7 +2508,7 @@ int ulas_asmline(FILE *dst, FILE *src, const char *line, unsigned long n) { ULAS_ASMDIR_CHKSM, ULAS_ASMDIR_ADV, ULAS_ASMDIR_SET_ENUM_DEF, ULAS_ASMDIR_DEFINE_ENUM, ULAS_ASMDIR_SETCHRCODE, ULAS_ASMDIR_CHR, - ULAS_ASMDIR_REP}; + ULAS_ASMDIR_REP, ULAS_ASMDIR_SECTION}; enum ulas_asmdir dir = ULAS_ASMDIR_NONE; @@ -2546,6 +2572,9 @@ int ulas_asmline(FILE *dst, FILE *src, const char *line, unsigned long n) { case ULAS_ASMDIR_REP: rc = ulas_asmdirrep(dst, src, &line, n); break; + case ULAS_ASMDIR_SECTION: + rc = ulas_asmdirsection(dst, src, &line, n); + break; case ULAS_ASMDIR_PAD: // TODO: pad is the same as .fill n, $ - n case ULAS_ASMDIR_NONE: diff --git a/src/ulas.h b/src/ulas.h index d6c6f90..fc67478 100644 --- a/src/ulas.h +++ b/src/ulas.h @@ -38,6 +38,8 @@ extern unsigned long defslen; #define ULAS_OUTBUFMAX 64 #define ULAS_MACROPARAMMAX 15 +#define ULAS_SECTIONMAX 32 + #define MAX(x, y) (((x) > (y)) ? (x) : (y)) #define MIN(x, y) (((x) < (y)) ? (x) : (y)) @@ -75,6 +77,7 @@ extern unsigned long defslen; #define ULAS_ASMSTR_SETCHRCODE ".scc" #define ULAS_ASMSTR_CHR ".chr" #define ULAS_ASMSTR_REP ".rep" +#define ULAS_ASMSTR_SECTION ".section" // configurable tokens #define ULAS_TOK_COMMENT ';' @@ -315,6 +318,7 @@ struct ulas { // defaults to just x=x mapping // but cna be set with a directive char charcodemap[ULAS_CHARCODEMAPLEN]; + char section[ULAS_SECTIONMAX]; struct ulas_arch arch; }; @@ -457,6 +461,9 @@ enum ulas_asmdir { // .rep , , // repeats a line n times ULAS_ASMDIR_REP, + // .section + // set the current section + ULAS_ASMDIR_SECTION, }; #define ULAS_INSTRTOKMAX 16 diff --git a/tests/t0.s b/tests/t0.s index 66b53bd..814596b 100644 --- a/tests/t0.s +++ b/tests/t0.s @@ -1,3 +1,6 @@ +.section test ; with comment +.section tests + ; this is a sample assembly file ; that can be read by tests. ; the expected result will just be a regular run of the program -- 2.30.2