/[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 841 - (show annotations)
Tue Sep 18 13:42:10 2012 UTC (6 years, 11 months ago) by mmu_man
File MIME type: text/plain
File size: 2727 byte(s)
Fix warnings.

1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 char *keywords[]= {
6 "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 main(int argc, char **argv)
23 {
24 unsigned int i, car, number, end, lastptr, adr;
25 int j,ptr,keyw,string,rem,data;
26 unsigned char ligne[256];
27 FILE *in,*out;
28 if (argc!=3) {
29 perror("Usage : txt2bas txtfile <Oric-BASIC-file>\n");
30 exit(1);
31 }
32 in=fopen(argv[1],"r");
33 if (in==NULL) { perror("Can't open input file\n"); exit(1); }
34 out=fopen(argv[2],"wb");
35 if (out==NULL) { perror("Can't open file for writing\n"); exit(1); }
36
37 i=0;
38 while(1) {
39 buf[i++]=0; buf[i++]=0;
40 if(fscanf(in,"%u",&number)==0) break;
41 buf[i++]=number&0xFF; buf[i++]=number>>8;
42 j=0; while((ligne[j]=getc(in))!='\n') j++; ligne[j]=0;
43 ptr=0; rem=0; string=0; data=0;
44 if (ligne[ptr]=' ') ptr++;
45 while(ligne[ptr]) {
46 if (rem) {
47 buf[i++]=ligne[ptr++];
48 } else if (string) {
49 if (ligne[ptr]=='"') string=0;
50 buf[i++]=ligne[ptr++];
51 } else if (data) {
52 if (ligne[ptr]==':') data=0;
53 buf[i++]=ligne[ptr++];
54 } else {
55 keyw=search_keyword(ligne+ptr);
56 if (keyw==29 || ligne[ptr]=='\'') rem=1;
57 if (keyw==17) data=1;
58 if (ligne[ptr]=='"') string=1;
59 if (keyw>=0) {
60 buf[i++]=keyw+128; ptr+=strlen(keywords[keyw]);
61 } else {
62 buf[i++]=ligne[ptr++];
63 }
64 }
65 }
66 buf[i++]=0;
67 }
68 buf[i++]=0;
69 end=0x501+i; head[8]=end>>8; head[9]=end&0xFF;
70 for(j=4,lastptr=0;j<i;j++)
71 if (buf[j]==0) {
72 adr=0x500+j+1;
73 buf[lastptr]=adr&0xFF; buf[lastptr+1]=adr>>8;
74 lastptr=j+1;
75 j+=4;
76 }
77 fwrite(head,1,14,out);
78 fwrite(buf,1,i,out); fclose(out);
79 }
80
81 search_keyword(char *str)
82 {
83 int i;
84 for (i=0;i<sizeof(keywords)/sizeof(char *);i++)
85 if (strncmp(keywords[i],str,strlen(keywords[i]))==0)
86 return i;
87 return -1;
88 }

  ViewVC Help
Powered by ViewVC 1.1.26