Add preliminary support for plotting graphs

This commit is contained in:
Vince Weaver 2012-05-09 16:09:47 -04:00
parent 6b6d6d0216
commit a6aa19c8b9
5 changed files with 233 additions and 29 deletions

View File

@ -77,6 +77,8 @@ static void print_line(unsigned char c, int num) {
}
static void center_comment(unsigned char c, int max_len, char *string) {
int half_len;
@ -131,19 +133,20 @@ struct footer_info {
char *center;
};
#define SLIDE_40COL 0
#define SLIDE_80COL 1
#define SLIDE_HGR 2
#define SLIDE_HGR2 3
#define SLIDE_40COL 0
#define SLIDE_80COL 1
#define SLIDE_HGR 2
#define SLIDE_HGR2 3
#define SLIDE_HGR_PLOT 4
#define MAX_SLIDES 100
#define MAX_SLIDES 89
struct slide_info {
int type;
char *filename;
};
#define LINES_PER_SLIDE 30
#define LINES_PER_SLIDE 100
static void generate_slide(int num, int max, char*filename) {
@ -173,23 +176,118 @@ static void generate_slide(int num, int max, char*filename) {
fprintf(stderr,"Couldn't open %s!\n",filename);
}
else {
int address=0x6000;
int num_plots=0,plot,color;
double maxx,maxy,x,y;
int applex,appley,hplot_num,first=1;
#define HPLOTS_ON_LINE 5
result=fgets(type,BUFSIZ,fff);
if (strstr(type,"HGR2")) {
if (strstr(type,"HGR_PLOT")) {
printf("%d IF ST%%=1 GOTO %d\n",line_num,line_num+3); line_num++;
printf("%d PRINT CHR$(4);\"BLOAD NUM.SHAPE\"\n",line_num); line_num++;
printf("%d POKE 232,%d: POKE 233,%d : ROT=0: SCALE=3: ST%%=1\n",
line_num,address&0xff,(address>>8)&0xff); line_num++;
printf("%d HGR\n",line_num); line_num++;
/* get the size */
while(1) {
result=fgets(string,BUFSIZ,fff);
if (result==NULL) break;
if ((string[0]=='#') || (string[0]=='\n')) continue;
sscanf(string,"%lf %lf",&maxx,&maxy);
break;
}
/* get number of plots */
while(1) {
result=fgets(string,BUFSIZ,fff);
if (result==NULL) break;
if ((string[0]=='#') || (string[0]=='\n')) continue;
sscanf(string,"%d",&num_plots);
break;
}
for(plot=0;plot<num_plots;plot++) {
first=1;
/* Look for START */
while(1) {
result=fgets(string,BUFSIZ,fff);
if (result==NULL) break;
if ((string[0]=='#') || (string[0]=='\n')) continue;
if (strstr(string,"START")) break;
}
/* get the color of the plot */
while(1) {
result=fgets(string,BUFSIZ,fff);
if (result==NULL) break;
if ((string[0]=='#') || (string[0]=='\n')) continue;
sscanf(string,"%d",&color);
break;
}
printf("%d HCOLOR=%d\n",line_num,color); line_num++;
/* Plot the points */
while(1) {
result=fgets(string,BUFSIZ,fff);
if (result==NULL) break;
if ((string[0]=='#') || (string[0]=='\n')) continue;
if (strstr(string,"STOP")) break;
sscanf(string,"%lf %lf",&x,&y);
applex=(int)((x/maxx)*280.0);
appley=159-(int)((y/maxy)*160.0);
if (first) {
printf("%d HPLOT %d,%d ",line_num,applex,appley); line_num++;
hplot_num=1;
first=0;
}
else if (hplot_num%HPLOTS_ON_LINE!=0) {
printf("TO %d,%d ",applex,appley);
hplot_num++;
} else {
printf("\n%d HPLOT TO %d,%d ",
line_num,applex,appley); line_num++;
hplot_num++;
}
}
printf("\n");
}
}
else if (strstr(type,"HGR2")) {
printf("%d HGR2\n",line_num); line_num++;
printf("%d PRINT CHR$(4);\"BLOAD TITLE.IMG,A$4000\"\n",
line_num); line_num++;
while(1) {
result=fgets(string,BUFSIZ,fff);
if (result==NULL) break;
if ((string[0]=='#') || (string[0]=='\n')) continue;
}
string[strlen(string)-1]='\0';
printf("%d PRINT CHR$(4);\"BLOAD %s,A$4000\"\n",
line_num,string); line_num++;
}
else if (strstr(type,"HGR")) {
printf("%d HGR\n",line_num); line_num++;
while(1) {
result=fgets(string,BUFSIZ,fff);
if (result==NULL) break;
if ((string[0]=='#') || (string[0]=='\n')) continue;
}
string[strlen(string)-1]='\0';
printf("%d PRINT CHR$(4);\"BLOAD %s,A$2000\"\n",
line_num,string); line_num++;
}
else if (strstr(type,"80COL")) {
}
else if (strstr(type,"40COL")) {
printf("%d VTAB 1\n",line_num); line_num++;
printf("%d TEXT:VTAB 1\n",line_num); line_num++;
while(1) {
result=fgets(string,BUFSIZ,fff);
if (result==NULL) break;
@ -346,7 +444,7 @@ int main(int argc, char **argv) {
generate_initial_comment(info.title,info.author,info.email);
printf("20 HOME\n");
printf("30 P%%=0 : TP%%=%d\n",info.slides-1);
printf("30 P%%=0 : TP%%=%d: ST%%=0\n",info.slides-1);
for(i=0;i<info.slides;i++) {
generate_slide(i,info.slides,slides[i].filename);
@ -357,5 +455,6 @@ int main(int argc, char **argv) {
generate_keyhandler();
generate_footer(footer.left,footer.center,40);
return 0;
}

View File

@ -4,11 +4,15 @@ LFLAGS =
all: presenter_demo.dsk
presenter_demo.dsk: PRESENTER_DEMO TITLE.IMG
presenter_demo.dsk: PRESENTER_DEMO TITLE.IMG NUM.SHAPE
../dos33 presenter_demo.dsk SAVE A PRESENTER_DEMO
../dos33 presenter_demo.dsk SAVE B TITLE.IMG
../dos33 presenter_demo.dsk SAVE B NUM.SHAPE
NUM.SHAPE: num.table
../shape_table -b < num.table > NUM.SHAPE
TITLE.IMG: title.pcx ../pcx2hgr
../pcx2hgr title.pcx > TITLE.IMG

View File

@ -8,9 +8,10 @@ EMAIL
vweaver1@eecs.utk.edu
SLIDES
slide_wattsup_plot
slide_rapl_intro
slide_rapl_continued
slide_rapl_more
slide_rapl_finish
slide_title
END_SLIDES
END_SLIDES

View File

@ -0,0 +1,49 @@
HGR_PLOT
40 70
1
START
1
0 32.4
1 32.3
2 52.8
3 42.3
4 65.3
5 66.2
6 66.3
7 63.7
8 66.3
9 66.7
10 66.5
11 67.6
12 67.4
13 67.6
14 67.9
15 63.8
16 67.3
17 65.2
18 68.6
19 68.5
20 65.0
21 68.7
22 67.3
23 67.2
24 69.2
25 63.6
26 68.1
27 63.7
28 63.3
29 65.8
30 64.0
31 69.4
32 68.1
33 64.5
34 64.1
35 66.9
36 68.4
37 57.7
38 35.4
39 35.1
STOP
WATTS TIME(seconds)
Blah Blah Blah Measured

View File

@ -5,6 +5,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX_SIZE 8192 /* not really, but anything larger would be crazy */
@ -35,6 +36,15 @@ static void warn_if_zero(unsigned char byte, int line) {
}
void print_usage(char *exe) {
printf("Usage:\t%s [-h] [-a] [-b]\n\n",exe);
printf("\t-h\tprint this help message\n");
printf("\t-a\toutput shape table in applesoft BASIC format\n");
printf("\t-b\toutput shape table in binary format for BLOADing\n");
printf("\n");
exit(1);
}
int main(int argc, char **argv) {
char string[BUFSIZ];
@ -46,6 +56,28 @@ int main(int argc, char **argv) {
int command=0,sub_pointer;
int output_binary=0;
if (argc<2) {
output_binary=0;
}
else {
if (argv[1][0]=='-') {
switch(argv[1][1]) {
case 'h': print_usage(argv[0]);
case 'b': output_binary=1;
break;
case 'a': output_binary=0;
break;
default: printf("Unknown options %s\n",argv[1]);
print_usage(argv[0]);
}
}
}
while(1) {
result=fgets(string,BUFSIZ,stdin);
if (result==NULL) break;
@ -155,24 +187,43 @@ int main(int argc, char **argv) {
table_size=current_offset;
/* put near highmem */
int address=0x1ff0-table_size;
if (output_binary) {
unsigned char header[4];
int offset=0x6000;
header[0]=offset&0xff;
header[1]=(offset>>8)&0xff;
header[2]=table_size&0xff;
header[3]=(table_size>>8)&0xff;
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");
fprintf(stderr,"Be sure to POKE 232,%d : POKE 233,%d\n"
"\tto let applesoft know the location of the table\n",
offset&0xff,(offset>>8)&0xff);
for(i=0;i<current_offset;i++) {
if(i%10==0) printf("%d DATA ",100+i/10);
printf("%d",table[i]);
fwrite(header,sizeof(unsigned char),4,stdout);
if ((i%10==9)||(i==current_offset-1)) printf("\n");
else printf(",");
fwrite(table,sizeof(unsigned char),table_size,stdout);
}
else {
/* 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]);
if ((i%10==9)||(i==current_offset-1)) printf("\n");
else printf(",");
}
}
return 0;