tokenize_asoft: add support for manually setting offset

This commit is contained in:
Vince Weaver 2017-04-23 23:24:30 -04:00
parent d0e03fd31e
commit 3cfcf85a3a
2 changed files with 46 additions and 7 deletions

View File

@ -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;

View File

@ -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);