Merge branch 'master' of git://github.com/deater/dos33fsprogs

This commit is contained in:
Vince Weaver 2017-04-24 09:50:45 -04:00
commit e31cdb2620
6 changed files with 222 additions and 72 deletions

View File

@ -1,10 +1,14 @@
/* asoft_detoken: detokenize an applesoft BASIC program */
/* by Vince Weaver (vince@deater.net) */
#include <stdio.h>
#include <string.h> /* strlen() */
#include <unistd.h> /* getopt() */
#include "version.h"
/* Starting at 0x80 */
char applesoft_tokens[][8]={
/* 80 */ "END","FOR","NEXT","DATA","INPUT","DEL","DIM","READ",
/* 88 */ "GR","TEXT","PR #","IN #","CALL","PLOT","HLIN","VLIN",
/* 90 */ "HGR2","HGR","HCOLOR=","HPLOT","DRAW","XDRAW","HTAB","HOME",
@ -24,61 +28,94 @@ char applesoft_tokens[][8]={
};
int main(int argc, char **argv) {
int ch1,i;
int size1,size2;
int line1,line2;
int link1,link2,link;
int debug=0;
int offset=0x801;
/* read size, first two bytes */
size1=fgetc(stdin);
size2=fgetc(stdin);
if (debug) fprintf(stderr,"File size: %x %x\n",size1,size2);
while(!feof(stdin)) {
/* link points to the next line */
/* assumes asoft program starts at address $801 */
link1=fgetc(stdin);
link2=fgetc(stdin);
link=(link2<<8)|link1;
offset+=2;
int ch1,i;
int size1,size2;
int line1,line2;
int link1,link2,link;
int debug=0,print_link=0;
int offset=0x801;
int c;
FILE *fff;
/* link==0 indicates EOF */
if (link==0) goto the_end;
/* line number is little endian 16-bit value */
line1=fgetc(stdin);
line2=fgetc(stdin);
if (feof(stdin)) goto the_end;
printf("%4d ",((line2)<<8)+line1);
offset+=2;
/* repeat until EOL character (0) */
while( (ch1=fgetc(stdin))!=0 ) {
offset++;
/* if > 0x80 it's a token */
if (ch1>=0x80) {
fputc(' ',stdout);
for(i=0;i<strlen(applesoft_tokens[ch1-0x80]);i++) {
fputc(applesoft_tokens[ch1-0x80][i],stdout);
}
fputc(' ',stdout);
}
/* otherwise it is an ascii char */
else {
fputc(ch1,stdout);
}
}
offset++;
printf("\n");
if (link!=offset) fprintf(stderr,"WARNING! link!=offset %x %x\n",
link,offset);
}
the_end:;
return 0;
/* Check command line arguments */
while ((c = getopt (argc, argv,"dl"))!=-1) {
switch (c) {
case 'd':
debug=1;
break;
case 'l':
print_link=1;
break;
}
}
/* No file specified, used stdin */
if (optind==argc) {
fff=stdin;
}
else {
fff=fopen(argv[optind],"r");
if (fff==NULL) {
fprintf(stderr,"Error, could not open %s\n",argv[optind]);
return -1;
}
}
/* read size, first two bytes */
size1=fgetc(fff);
size2=fgetc(fff);
if (debug) fprintf(stderr,"File size: %x %x\n",size1,size2);
while(!feof(fff)) {
/* link points to the next line */
/* assumes asoft program starts at address $801 */
link1=fgetc(fff);
link2=fgetc(fff);
link=(link2<<8)|link1;
offset+=2;
if (print_link) printf("*%04X",link);
/* link==0 indicates EOF */
if (link==0) goto the_end;
/* line number is little endian 16-bit value */
line1=fgetc(fff);
line2=fgetc(fff);
if (feof(fff)) goto the_end;
printf("%4d ",((line2)<<8)+line1);
offset+=2;
/* repeat until EOL character (0) */
while( (ch1=fgetc(fff))!=0 ) {
offset++;
/* if > 0x80 it's a token */
if (ch1>=0x80) {
/* Leading space */
fputc(' ',stdout);
for(i=0;i<strlen(applesoft_tokens[ch1-0x80]);i++) {
fputc(applesoft_tokens[ch1-0x80][i],stdout);
}
/* Trailing space, but not if REM */
if ((ch1-0x80)!=0x32) fputc(' ',stdout);
}
/* otherwise it is an ascii char */
else {
fputc(ch1,stdout);
}
}
offset++;
printf("\n");
if (link!=offset) {
fprintf(stderr,"WARNING! link!=offset %x %x\n",link,offset);
}
}
the_end:;
return 0;
}

View File

@ -1,21 +1,27 @@
/* tokenize_asoft: Tokenize an Applesoft BASIC program */
/* by Vince Weaver <vince@deater.net> */
#include <stdio.h>
#include <string.h> /* strlen() */
#include <stdlib.h> /* exit() */
#include <unistd.h> /* getopt() */
#include "version.h"
static int debug=0;
/* TODO */
/* match lowercase tokens as well as upper case ones */
/* Info from http://docs.info.apple.com/article.html?coll=ap&artnum=57 */
/* In memory, applesoft file starts at address $801 */
/* format is <LINE><LINE><LINE>$00$00 */
/* Where <LINE> is: */
/* 2 bytes (little endian) of LINK indicating addy of next line */
/* 2 bytes (little endian) giving the line number */
/* a series of bytes either ASCII or tokens (see below) */
/* a $0 char indicating end of line */
/* In memory, applesoft file starts at address $801 */
/* format is <LINE><LINE><LINE>$00$00 */
/* Where <LINE> is: */
/* 2 bytes (little endian) of LINK indicating addy of next line */
/* 2 bytes (little endian) giving the line number */
/* a series of bytes either ASCII or tokens (see below) */
/* a $0 char indicating end of line */
#define NUM_TOKENS 107
@ -61,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);
@ -84,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;
}
@ -166,13 +203,38 @@ 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 c;
FILE *fff;
/* Check command line arguments */
while ((c = getopt (argc, argv,"d"))!=-1) {
switch (c) {
case 'd':
debug=1;
break;
}
}
/* No file specified, used stdin */
if (optind==argc) {
fff=stdin;
}
else {
fff=fopen(argv[optind],"r");
if (fff==NULL) {
fprintf(stderr,"Error, could not open %s\n",argv[optind]);
return -1;
}
if (debug) fprintf(stderr,"Opened file %s\n",argv[optind]);
}
while(1) {
/* get line from input file */
line_ptr=fgets(input_line,BUFSIZ,stdin);
line_ptr=fgets(input_line,BUFSIZ,fff);
line++;
if (line_ptr==NULL) break;
@ -180,7 +242,7 @@ int main(int argc, char **argv) {
if (line_ptr[0]=='\'') {
if (!strncmp(line_ptr,"\'.if 0",6)) {
while(1) {
line_ptr=fgets(input_line,BUFSIZ,stdin);
line_ptr=fgets(input_line,BUFSIZ,fff);
line++;
if (line_ptr==NULL) break;
if (!strncmp(line_ptr,"\'.endif",7)) break;
@ -192,12 +254,10 @@ int main(int argc, char **argv) {
/* VMW extension: use leading ' as a comment char */
if (line_ptr[0]=='\'') continue;
/* 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);
@ -218,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;
@ -231,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);

14
deceptive_list/Makefile Normal file
View File

@ -0,0 +1,14 @@
DOS33 = ../dos33fs-utils/dos33
TXT2BAS = ../asoft_basic-utils/tokenize_asoft
all: deceptive.dsk
BACKWARD.BAS: backward.basd
$(TXT2BAS) < backward.basd > BACKWARD.BAS
deceptive.dsk: BACKWARD.BAS
$(DOS33) -y deceptive.dsk SAVE A BACKWARD.BAS
clean:
rm -f *~ *.BAS *.SHAPE sound_test.bas shape_test.bas *.lst

Binary file not shown.

11
deceptive_list/hidden.bas Normal file
View File

@ -0,0 +1,11 @@
5 REM FUN TIMES
7 PRINT
10 PRINT "** DECEPTIVE LIST **"
20 PRINT " BY "
30 PRINT " VINCE WEAVER "
40 PRINT "********************"
50 PRINT
55 PRINT "WHATEVER YOU DO, DON'T TYPE LIST"
60 PRINT
70 END

View File

@ -0,0 +1,21 @@
'0811
*08BB 5 REM FUN TIMES
'0817
*0817 7 PRINT
'0833
*0833 10 PRINT "** DECEPTIVE LIST **"
'084F
*084F 20 PRINT " BY "
'086B
*086B 30 PRINT " VINCE WEAVER "
'0887
*0887 40 PRINT "********************"
'088D
*088D 50 PRINT
'08B5
*08B5 55 PRINT "WHATEVER YOU DO, DON'T TYPE LIST"
'08BB
*08BB 60 PRINT
'08C1
*08C1 70 END