Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/nesasm.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2023-08-07 17:10:05 +0300
committerGitHub <noreply@github.com>2023-08-07 17:10:05 +0300
commit92ee26530f2a50c110d5b49d8a21e33dae3129b9 (patch)
tree51dba47c5feaa747503195e0472ea7b75f13bbf6
parent82f59a310d2cd60a5234d48fb05d84ddd2721a89 (diff)
parent6f7e71326c55504210da18f6f5c66fa7356033a2 (diff)
Merge pull request #5 from flamecyclone/master
Added new commands: .str and some code optimizations
-rw-r--r--README.md11
-rw-r--r--source/command.c176
-rw-r--r--source/defs.h8
-rw-r--r--source/externs.h4
-rw-r--r--source/inst.h4
-rw-r--r--source/main.c4
-rw-r--r--source/protos.h1
-rw-r--r--source/vars.h4
8 files changed, 200 insertions, 12 deletions
diff --git a/README.md b/README.md
index 1b003ea..45445f8 100644
--- a/README.md
+++ b/README.md
@@ -275,7 +275,16 @@ Other 'special' parameters can be used, here's a list of all the possible parame
represent the page index.
DB - Store one or more data bytes at the current location.
-
+
+ STR - Stores a string, the first byte is the length of the string,
+ followed by the string content,
+ The effect is equivalent to . DB is preceded with a length,
+ here's a small example:
+ ;use DB specified a length + string:
+ DB 12,"Hello World!"
+ ;can be replaced with STR:
+ STR "Hello World!"
+
DW - Store data words.
BYTE - Same as DB.
diff --git a/source/command.c b/source/command.c
index 9b3784f..d740f1a 100644
--- a/source/command.c
+++ b/source/command.c
@@ -15,7 +15,7 @@ char pseudo_flag[] = {
0x0F, 0x0F, 0x0F, 0x0C, 0x0C, 0x0C, 0x0C, 0x0F, 0x0F, 0x0F, // 30 - 39
0x0F, 0x0F, 0x0C, 0x0C, 0x0C, 0x04, 0x04, 0x04, 0x04, 0x04, // 40 - 49
0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, // P_INESPRGRAM - 50, P_INESPRGNVRAM - 51, P_INESCHRRAM - 52, P_INESCHRNVRAM - 53, P_INESSUBMAP - 54, P_INESBAT - 55, P_INESTIM - 56
- 0x0F // P_SEQU 57
+ 0x0C, 0x0F // P_SEQU 58
};
@@ -337,6 +337,180 @@ do_dw(int *ip)
println();
}
+/* ----
+ * do_str()
+ * ----
+ * .str pseudo
+ */
+
+void
+do_str(int *ip)
+{
+ unsigned char c;
+ unsigned char str_len = 0;
+ int ip_tmp = 0;
+
+ /* define label */
+ labldef(loccnt, 1);
+
+ /* output infos */
+ data_loccnt = loccnt;
+ data_level = 2;
+
+ /* skip spaces */
+ while (isspace((int)prlnbuf[++(*ip)]));
+
+ ip_tmp = *ip;
+ /* get string length */
+ for (;;) {
+ /* ASCII string */
+ if (prlnbuf[*ip] == '\"') {
+ for (;;) {
+ c = prlnbuf[++(ip_tmp)];
+ if (c == '\"')
+ break;
+ if (c == '\0') {
+ error("Unterminated ASCII string!");
+ return;
+ }
+ if (c == '\\') {
+ c = prlnbuf[++(ip_tmp)];
+ switch(c) {
+ case 'r':
+ c = '\r';
+ break;
+ case 'n':
+ c = '\n';
+ break;
+ case 't':
+ c = '\t';
+ break;
+ }
+ }
+
+ /* update length counter */
+ str_len++;
+ }
+ ip_tmp++;
+ }
+ /* bytes */
+ else {
+ /* get a byte */
+ if (!evaluate(&ip_tmp, 0))
+ return;
+
+ /* update length counter */
+ str_len++;
+
+ /* check byte on last pass */
+ if (pass == LAST_PASS) {
+ /* check for overflow */
+ if ((value > 0xFF) && (value < 0xFFFFFF80)) {
+ error("Overflow error!");
+ return;
+ }
+ }
+ }
+
+ /* check if there's another byte */
+ c = prlnbuf[ip_tmp++];
+
+ if (c != ',')
+ break;
+ }
+
+ /* store string length on first btye */
+ if (str_len > 0) {
+ putbyte(loccnt, str_len);
+ loccnt++;
+ }
+
+ /* get bytes */
+ for (;;) {
+ /* ASCII string */
+ if (prlnbuf[*ip] == '\"') {
+ for (;;) {
+ c = prlnbuf[++(*ip)];
+ if (c == '\"')
+ break;
+ if (c == '\0') {
+ error("Unterminated ASCII string!");
+ return;
+ }
+ if (c == '\\') {
+ c = prlnbuf[++(*ip)];
+ switch(c) {
+ case 'r':
+ c = '\r';
+ break;
+ case 'n':
+ c = '\n';
+ break;
+ case 't':
+ c = '\t';
+ break;
+ }
+ }
+ /* store char on last pass */
+ if (pass == LAST_PASS)
+ putbyte(loccnt, c);
+
+ /* update location counter */
+ loccnt++;
+ }
+ (*ip)++;
+ }
+ /* bytes */
+ else {
+ /* get a byte */
+ if (!evaluate(ip, 0))
+ return;
+
+ /* update location counter */
+ loccnt++;
+
+ /* store byte on last pass */
+ if (pass == LAST_PASS) {
+ /* check for overflow */
+ if ((value > 0xFF) && (value < 0xFFFFFF80)) {
+ error("Overflow error!");
+ return;
+ }
+
+ /* store byte */
+ putbyte(loccnt - 1, value);
+ }
+ }
+
+ /* check if there's another byte */
+ c = prlnbuf[(*ip)++];
+
+ if (c != ',')
+ break;
+ }
+
+ /* check error */
+ if (c != ';' && c != '\0') {
+ error("Syntax error!");
+ return;
+ }
+
+ /* size */
+ if (lablptr) {
+ lablptr->data_type = P_DB;
+ lablptr->data_size = loccnt - data_loccnt;
+ }
+ else {
+ if (lastlabl) {
+ if (lastlabl->data_type == P_DB)
+ lastlabl->data_size += loccnt - data_loccnt;
+ }
+ }
+
+ /* output line */
+ if (pass == LAST_PASS)
+ println();
+}
/* ----
* do_equ()
diff --git a/source/defs.h b/source/defs.h
index e3c3894..aa61aa3 100644
--- a/source/defs.h
+++ b/source/defs.h
@@ -1,4 +1,5 @@
#define MAX_BANKS 4096
+#define BANK_SIZE 8192
/* path separator */
#if defined(DJGPP) || defined(MSDOS) || defined(WIN32)
@@ -14,9 +15,9 @@
#define MACHINE_NES 1
/* reserved bank index */
-#define RESERVED_BANK (MAX_BANKS - 0x0F)
-#define PROC_BANK (MAX_BANKS - 0x0F + 1)
-#define GROUP_BANK (MAX_BANKS - 0x0F + 2)
+#define RESERVED_BANK (MAX_BANKS - 0x10)
+#define PROC_BANK (MAX_BANKS - 0x10 + 1)
+#define GROUP_BANK (MAX_BANKS - 0x10 + 2)
/* tile format for encoder */
#define CHUNKY_TILE 1
@@ -106,6 +107,7 @@
#define P_INESBAT 55 // .inesbat
#define P_INESTIM 56 // .inestim
#define P_SEQU 57 // .sequ
+#define P_STR 58 // .str
/* symbol flags */
#define MDEF 3 /* multiply defined */
diff --git a/source/externs.h b/source/externs.h
index ac7a9b0..fbf0342 100644
--- a/source/externs.h
+++ b/source/externs.h
@@ -1,5 +1,5 @@
-extern unsigned char rom[MAX_BANKS][8192];
-extern unsigned char map[MAX_BANKS][8192];
+extern unsigned char rom[MAX_BANKS][BANK_SIZE];
+extern unsigned char map[MAX_BANKS][BANK_SIZE];
extern char bank_name[MAX_BANKS][64];
extern int bank_loccnt[4][256];
extern int bank_page[4][256];
diff --git a/source/inst.h b/source/inst.h
index 42076e6..40bd517 100644
--- a/source/inst.h
+++ b/source/inst.h
@@ -61,7 +61,7 @@ struct t_opcode base_inst[57] = {
};
/* pseudo instruction table */
-struct t_opcode base_pseudo[77] = {
+struct t_opcode base_pseudo[79] = {
{NULL, "=", do_equ, PSEUDO, P_EQU, 0},
{NULL, "BANK", do_bank, PSEUDO, P_BANK, 0},
@@ -102,6 +102,7 @@ struct t_opcode base_pseudo[77] = {
{NULL, "RS", do_rs, PSEUDO, P_RS, 0},
{NULL, "WORD", do_dw, PSEUDO, P_DW, 0},
{NULL, "ZP", do_section, PSEUDO, P_ZP, S_ZP},
+ {NULL, "STR", do_str, PSEUDO, P_STR, 0},
{NULL, ".BANK", do_bank, PSEUDO, P_BANK, 0},
{NULL, ".BSS", do_section, PSEUDO, P_BSS, S_BSS},
@@ -140,6 +141,7 @@ struct t_opcode base_pseudo[77] = {
{NULL, ".RS", do_rs, PSEUDO, P_RS, 0},
{NULL, ".WORD", do_dw, PSEUDO, P_DW, 0},
{NULL, ".ZP", do_section, PSEUDO, P_ZP, S_ZP},
+ {NULL, ".STR", do_str, PSEUDO, P_STR, 0},
{NULL, NULL, NULL, 0, 0, 0}
};
diff --git a/source/main.c b/source/main.c
index 0185e65..811ed8b 100644
--- a/source/main.c
+++ b/source/main.c
@@ -314,8 +314,8 @@ main(int argc, char **argv)
}
/* clear the ROM array */
- memset(rom, zero_fill ? 0 : 0xff, 8192 * 128);
- memset(map, zero_fill ? 0 : 0xff, 8192 * 128);
+ memset(rom, zero_fill ? 0 : 0xff, sizeof(rom));
+ memset(map, zero_fill ? 0 : 0xff, sizeof(map));
/* fill the instruction hash table */
addinst(base_inst);
diff --git a/source/protos.h b/source/protos.h
index c6f8277..f5179ba 100644
--- a/source/protos.h
+++ b/source/protos.h
@@ -30,6 +30,7 @@ void do_mlist(int *ip);
void do_nolist(int *ip);
void do_nomlist(int *ip);
void do_db(int *ip);
+void do_str(int *ip);
void do_dw(int *ip);
void do_equ(int *ip);
void do_sequ(int *ip);
diff --git a/source/vars.h b/source/vars.h
index c1a68bf..07be861 100644
--- a/source/vars.h
+++ b/source/vars.h
@@ -1,5 +1,5 @@
-unsigned char rom[MAX_BANKS][8192];
-unsigned char map[MAX_BANKS][8192];
+unsigned char rom[MAX_BANKS][BANK_SIZE];
+unsigned char map[MAX_BANKS][BANK_SIZE];
char bank_name[MAX_BANKS][64];
int bank_loccnt[4][256];
int bank_page[4][256];