/[projet1]/public/pc/tools/oric/txt2bas/txt2bas.c
Defence Force logotype

Contents of /public/pc/tools/oric/txt2bas/txt2bas.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 20 - (show annotations)
Mon Feb 23 21:49:24 2009 UTC (10 years, 9 months ago) by dbug
File MIME type: text/plain
File size: 2685 byte(s)
Added txt2bas from Fabrice Frances
1 #include <stdio.h>
2
3 char *keywords[]= {
4 "END","EDIT","STORE","RECALL","TRON","TROFF","POP","PLOT",
5 "PULL","LORES","DOKE","REPEAT","UNTIL","FOR","LLIST","LPRINT","NEXT","DATA",
6 "INPUT","DIM","CLS","READ","LET","GOTO","RUN","IF","RESTORE","GOSUB","RETURN",
7 "REM","HIMEM","GRAB","RELEASE","TEXT","HIRES","SHOOT","EXPLODE","ZAP","PING",
8 "SOUND","MUSIC","PLAY","CURSET","CURMOV","DRAW","CIRCLE","PATTERN","FILL",
9 "CHAR","PAPER","INK","STOP","ON","WAIT","CLOAD","CSAVE","DEF","POKE","PRINT",
10 "CONT","LIST","CLEAR","GET","CALL","!","NEW","TAB(","TO","FN","SPC(","@",
11 "AUTO","ELSE","THEN","NOT","STEP","+","-","*","/","^","AND","OR",">","=","<",
12 "SGN","INT","ABS","USR","FRE","POS","HEX$","&","SQR","RND","LN????","EXP","COS",
13 "SIN","TAN","ATN","PEEK","DEEK","LOG","LEN","STR$","VAL","ASC","CHR$","PI",
14 "TRUE","FALSE","KEY$","SCRN","POINT","LEFT$","RIGHT$","MID$"
15 };
16
17 unsigned char buf[48*1024];
18 unsigned char head[14]={ 0x16,0x16,0x16,0x24,0,0,0,0,0,0,5,1,0,0 };
19
20 main(int argc, char **argv)
21 {
22 unsigned int i, car, number, end, lastptr, adr;
23 int j,ptr,keyw,string,rem,data;
24 unsigned char ligne[256];
25 FILE *in,*out;
26 if (argc!=3) {
27 perror("Usage : txt2bas txtfile <Oric-BASIC-file>\n");
28 exit(1);
29 }
30 in=fopen(argv[1],"r");
31 if (in==NULL) { perror("Can't open input file\n"); exit(1); }
32 out=fopen(argv[2],"wb");
33 if (out==NULL) { perror("Can't open file for writing\n"); exit(1); }
34
35 i=0;
36 while(1) {
37 buf[i++]=0; buf[i++]=0;
38 if(fscanf(in,"%u",&number)==0) break;
39 buf[i++]=number&0xFF; buf[i++]=number>>8;
40 j=0; while((ligne[j]=getc(in))!='\n') j++; ligne[j]=0;
41 ptr=0; rem=0; string=0; data=0;
42 if (ligne[ptr]=' ') ptr++;
43 while(ligne[ptr]) {
44 if (rem) {
45 buf[i++]=ligne[ptr++];
46 } else if (string) {
47 if (ligne[ptr]=='"') string=0;
48 buf[i++]=ligne[ptr++];
49 } else if (data) {
50 if (ligne[ptr]==':') data=0;
51 buf[i++]=ligne[ptr++];
52 } else {
53 keyw=search_keyword(ligne+ptr);
54 if (keyw==29 || ligne[ptr]=='\'') rem=1;
55 if (keyw==17) data=1;
56 if (ligne[ptr]=='"') string=1;
57 if (keyw>=0) {
58 buf[i++]=keyw+128; ptr+=strlen(keywords[keyw]);
59 } else {
60 buf[i++]=ligne[ptr++];
61 }
62 }
63 }
64 buf[i++]=0;
65 }
66 buf[i++]=0;
67 end=0x501+i; head[8]=end>>8; head[9]=end&0xFF;
68 for(j=4,lastptr=0;j<i;j++)
69 if (buf[j]==0) {
70 adr=0x500+j+1;
71 buf[lastptr]=adr&0xFF; buf[lastptr+1]=adr>>8;
72 lastptr=j+1;
73 j+=4;
74 }
75 fwrite(head,1,14,out);
76 fwrite(buf,1,i,out); fclose(out);
77 }
78
79 search_keyword(char *str)
80 {
81 int i;
82 for (i=0;i<sizeof(keywords)/sizeof(char *);i++)
83 if (strncmp(keywords[i],str,strlen(keywords[i]))==0)
84 return i;
85 return -1;
86 }

  ViewVC Help
Powered by ViewVC 1.1.26