From 3cfcf85a3a93de151f8b5aa8c6c059591b60624c Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Sun, 23 Apr 2017 23:24:30 -0400 Subject: [PATCH] tokenize_asoft: add support for manually setting offset --- asoft_basic-utils/asoft_detoken.c | 2 +- asoft_basic-utils/tokenize_asoft.c | 51 ++++++++++++++++++++++++++---- 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/asoft_basic-utils/asoft_detoken.c b/asoft_basic-utils/asoft_detoken.c index e5af3858..d5f02fd4 100644 --- a/asoft_basic-utils/asoft_detoken.c +++ b/asoft_basic-utils/asoft_detoken.c @@ -80,7 +80,7 @@ int main(int argc, char **argv) { link=(link2<<8)|link1; offset+=2; - if (print_link) printf("%04X:",link); + if (print_link) printf("*%04X",link); /* link==0 indicates EOF */ if (link==0) goto the_end; diff --git a/asoft_basic-utils/tokenize_asoft.c b/asoft_basic-utils/tokenize_asoft.c index d180280b..2f8d5dfe 100644 --- a/asoft_basic-utils/tokenize_asoft.c +++ b/asoft_basic-utils/tokenize_asoft.c @@ -8,6 +8,8 @@ #include "version.h" +static int debug=0; + /* TODO */ /* match lowercase tokens as well as upper case ones */ @@ -65,13 +67,37 @@ static void show_problem(char *line_ptr) { fprintf(stderr,"^\n"); } -static int getnum(void) { +static int get_line_num(int *linenum, int *custom_offset) { int num=0; + int offset=0; /* skip any whitespace */ while((*line_ptr<=' ') && (*line_ptr!=0)) line_ptr++; + /* Custom Offset */ + if (*line_ptr=='*') { + line_ptr++; + while(*line_ptr>' ') { + if ((*line_ptr>='0')&&(*line_ptr<='9')) { + offset*=16; + offset+=(*line_ptr)-'0'; + } else if ((*line_ptr>='A')&&(*line_ptr<='F')) { + offset*=16; + offset+=(*line_ptr)-'A'+10; + } + else { + fprintf(stderr,"Invalid offset line %d\n",line); + show_problem(line_ptr); + exit(-1); + } + line_ptr++; + } + + /* Skip whitespace */ + while((*line_ptr<=' ') && (*line_ptr!=0)) line_ptr++; + } + while (*line_ptr>' ') { if ((*line_ptr<'0')||(*line_ptr>'9')) { fprintf(stderr,"Invalid line number line %d\n",line); @@ -88,6 +114,13 @@ static int getnum(void) { exit(-1); } + if (linenum) *linenum=num; + if (custom_offset) { + *custom_offset=offset; + if (debug) fprintf(stderr,"CO=%x\n",offset); + + } + return num; } @@ -170,10 +203,9 @@ int main(int argc, char **argv) { int offset=2,i; - int linenum=0,lastline=0,link_offset; + int linenum=0,custom_offset=0,lastline=0,link_offset; int link_value=0x801; /* start of applesoft program */ int token; - int debug=0; int c; FILE *fff; @@ -225,7 +257,7 @@ int main(int argc, char **argv) { /* skip empty lines */ if (line_ptr[0]=='\n') continue; - linenum=getnum(); + get_line_num(&linenum,&custom_offset); if ((linenum>65535) || (linenum<0)) { fprintf(stderr,"Invalid line number %d\n",linenum); exit(-1); @@ -246,6 +278,7 @@ int main(int argc, char **argv) { while(1) { token=find_token(); output[offset]=token; + if (debug) fprintf(stderr,"%2X ",token); offset++; check_oflo(offset); if (!token) break; @@ -259,8 +292,14 @@ int main(int argc, char **argv) { /* point link value to next line */ check_oflo(offset+2); - output[link_offset]=LOW(link_value); - output[link_offset+1]=HIGH(link_value); + if (custom_offset) { + output[link_offset]=LOW(custom_offset); + output[link_offset+1]=HIGH(custom_offset); + } + else { + output[link_offset]=LOW(link_value); + output[link_offset+1]=HIGH(link_value); + } } /* set last link field to $00 $00 which indicates EOF */ check_oflo(offset+2);