Improve shape table program

Now fully functional.  Will also warn you if your
shape table has zero fields that will be ignored.
This commit is contained in:
Vince Weaver 2012-05-09 13:06:08 -04:00
parent 2282929065
commit 6b6d6d0216
2 changed files with 278 additions and 12 deletions

158
presenter_demo/num.table Normal file
View File

@ -0,0 +1,158 @@
# Number of shapes
13
# Number "0"
START
NUP
RT
DN
DN
LT
LT
UP
UP
RT
STOP
# Number "1"
START
NUP
DN
DN
STOP
# Number "2"
START
NUP
NLT
RT
RT
DN
LT
LT
DN
RT
RT
STOP
# Number "3"
START
NUP
NLT
RT
RT
DN
LT
LT
NRT
NRT
DN
LT
LT
STOP
# Number "4"
START
NUP
NLT
DN
RT
RT
UP
NDN
DN
STOP
# Number "5"
START
NUP
NRT
LT
LT
DN
RT
RT
DN
LT
LT
STOP
# Number "6"
START
NUP
NRT
LT
LT
DN
RT
RT
DN
LT
LT
UP
STOP
# Number "7"
START
NUP
NLT
RT
RT
DN
DN
STOP
# Number "8"
START
LT
UP
#
RT
RT
#
DN
LT
NRT
#
DN
LT
#
LT
UP
STOP
# Number "9"
START
LT
UP
#
RT
RT
#
DN
LT
NRT
#
DN
STOP
# "."
START
NDN
UP
STOP
# "-"
START
LT
NRT
#
RT
STOP
# "W"
START
NUP
NLT
#
DN
DN
#
RT
UP
#
RT
DN
#
RT
UP
#
UP
STOP

View File

@ -1,4 +1,7 @@
/* http://www.atariarchives.org/cgp/Ch03_Sec05.php */
/* Creates an AppleSoft BASIC shape table */
/* See the AppleSoft manual for info on how this works */
/* Other online info (I'm looking at you, atariarchives.org) */
/* is inaccurate */
#include <stdio.h>
#include <string.h>
@ -13,6 +16,25 @@ void set_offset(current_shape,current_offset) {
table[2+(current_shape*2)+1]=(current_offset>>8)&0xff;
}
#define LOC_A 0
#define LOC_B 1
#define LOC_C 2
static void warn_if_zero(unsigned char byte, int line) {
/* Check to see if we're accidentally ignoring bytes */
if (byte==0) {
fprintf(stderr,"Warning, all-0 byte will be ignored on line %d!\n",
line);
}
if ((byte&0xf8)==0) {
fprintf(stderr,"Warning, ignoring C and B due to 0 on line %d!\n",
line);
}
}
int main(int argc, char **argv) {
char string[BUFSIZ];
@ -20,21 +42,24 @@ int main(int argc, char **argv) {
int table_size=0;
int num_shapes=0;
int current_offset=0,current_shape=0;
int i;
int i,line=1;
int command=0,sub_pointer;
while(1) {
result=fgets(string,BUFSIZ,stdin);
if (result==NULL) break;
line++;
/* skip comments and blank lines */
if ((string[0]=='#') || (string[0]=='\n')) continue;
sscanf(string,"%d",&num_shapes);
break;
}
printf("Num shapes: %d\n",num_shapes);
//fprintf(stderr,"Num shapes: %d\n",num_shapes);
table[0]=num_shapes;
table[1]=0;
@ -42,23 +67,106 @@ int main(int argc, char **argv) {
current_shape=0;
current_offset=2+2*(num_shapes);
set_offset(current_shape,current_offset);
for(current_shape=0;current_shape<num_shapes;current_shape++) {
/* Find START */
set_offset(current_shape,current_offset);
while(1) {
result=fgets(string,BUFSIZ,stdin);
if (result==NULL) break;
/* Find START */
/* skip comments and blank lines */
if ((string[0]=='#') || (string[0]=='\n')) continue;
while(1) {
result=fgets(string,BUFSIZ,stdin);
if (result==NULL) break;
line++;
if (!strstr(string,"START")) continue;
/* skip comments and blank lines */
if ((string[0]=='#') || (string[0]=='\n')) continue;
}
if (strstr(string,"START")) break;
}
/* READ DATA */
sub_pointer=LOC_A;
while(1) {
result=fgets(string,BUFSIZ,stdin);
if (result==NULL) break;
line++;
/* skip comments and blank lines */
if ((string[0]=='#') || (string[0]=='\n')) continue;
if (strstr(string,"STOP")) break;
/* yes, this is inefficient... */
if (strstr(string,"NUP")) command=0;
else if (strstr(string,"NRT")) command=1;
else if (strstr(string,"NDN")) command=2;
else if (strstr(string,"NLT")) command=3;
else if (strstr(string,"UP")) command=4;
else if (strstr(string,"RT")) command=5;
else if (strstr(string,"DN")) command=6;
else if (strstr(string,"LT")) command=7;
else fprintf(stderr,"Unknown command %s",string);
if (sub_pointer==LOC_A) {
table[current_offset]=(command&0x7);
sub_pointer=LOC_B;
}
else if (sub_pointer==LOC_B) {
table[current_offset]|=((command&0x7)<<3);
sub_pointer=LOC_C;
}
else {
/* Try to fit in LOC_C. This can only hold no-draw moves */
/* Also a LOC_C of 0 is ignored */
if ((command&0x4) || (command==0)) {
/* Write to LOC_A instead */
warn_if_zero(table[current_offset],line);
current_offset++;
table[current_offset]=(command&0x7);
sub_pointer=LOC_B;
}
else {
/* write to LOC_C */
table[current_offset]|=((command&0x3)<<6);
warn_if_zero(table[current_offset],line);
current_offset++;
sub_pointer=LOC_A;
}
}
}
if (sub_pointer!=LOC_A) current_offset++;
table[current_offset]=0; current_offset++;
}
table_size=current_offset;
/* put near highmem */
int address=0x1ff0-table_size;
printf("10 HIMEM:%d\n",address);
printf("20 POKE 232,%d:POKE 233,%d\n",(address&0xff),(address>>8)&0xff);
printf("30 FOR L=%d TO %d: READ B:POKE L,B:NEXT L\n",
address,(address+table_size)-1);
printf("35 HGR:ROT=0:SCALE=2\n");
printf("40 FOR I=1 TO %d: XDRAW I AT I*10,100:NEXT I\n",
num_shapes);
printf("90 END\n");
for(i=0;i<current_offset;i++) {
if(i%10==0) printf("%d DATA ",100+i/10);
printf("%d",table[i]);