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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1188 - (hide annotations)
Wed Sep 17 21:04:56 2014 UTC (5 years, 5 months ago) by Jylam
File MIME type: text/plain
File size: 2785 byte(s)
Fix ugly bus in parsing

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

  ViewVC Help
Powered by ViewVC 1.1.26