//out2nd = //output to ho2 (string file) //out = //output to ho1 (ASM file) void out(void); void out2nd(void); //pre-assemble file void prefile(void) { word pb,p1,p2,p3,ttt; byte a,b,c; byte f1; //misc flags byte f2; byte f3; byte f4; byte comment,commentchar; comment=0; while (!EOFF[ch]) { readln(); strcpy(str,buf); pb=0; if (comment) { while (*(buf+pb)) { if (*(buf+pb)==commentchar) { comment=0; break; } pb++; } continue; } //get 1st word (looking for include/#include/strings"") pb=0; while (buf[pb]) { a=buf[pb]; if (a==32) {pb++;continue;} if (a==' ') {pb++;continue;} break; } if (!memcmp(buf+pb,"include",7)) { //include found //this line is lost! pb+=7; buf[pb]=0; while (!buf[pb]) { //NEW in v1.1 pb++; if (buf[pb]==32) {buf[pb]=0;continue;} if (buf[pb]==';') {buf[pb]=0;continue;} } ttt=pb; while (buf[pb]) { pb++; if (buf[pb]==32) {buf[pb]=0;break;} } pb=ttt; file=buf+pb; dofile(); //recursive call continue; } if (!memcmp(buf+pb,"comment ",8)) { comment=1; pb+=7; while (*(buf+pb)==32) { pb++; if (!*(buf+pb)) errorf("Invalid comment directive"); } commentchar=*(buf+pb); continue; } if (!memcmp(buf+pb,"#include",8)) { str[pb]=32; //remove the # and move on foundit=1; } pb=0; f1=0; // '' string in use f2=0; // "" string in use f3=0; // proper '' found! f4=0; // proper "" found! while (buf[pb]) { // 39 = '''' if (f1) { //' if ((buf[pb]=='\'')&&(buf[pb+1]=='\'')) { pb+=2; continue; } if (buf[pb]=='\'') { f1=0; f3=1; } pb++; continue; } if (f2) { //" if ((buf[pb]=='"')&&(buf[pb+1]=='"')) { pb+=2; continue; } if ((buf[pb]=='\\')&&(buf[pb+1]=='\\')) { //NEW in v1.1 pb+=2; continue; } if ((buf[pb]=='\\')&&(buf[pb+1]=='"')) { //NEW in v1.1 pb+=2; continue; } if (buf[pb]=='"') { f2=0; f4=1; } pb++; continue; } if (buf[pb]=='"') f2=1; if (buf[pb]=='\'') f1=1; if (buf[pb]==';') break; //ignore rest of line pb++; } buf[pb]=0; //in case we remove the REMed part if ((f2)||(f1)) { errorf("string left open[1]\r\n"); } // was removed in version 1.02 // if ((f3)&&(f4)) errorf("not allowed to mix strings on a line\r\n"); f1=0; //start of new string f2=0; //just added \r\n (13,10) or \0 (0) // BUG!!? f3=0; //in mid of string if (f4) { //string found pb=0; //buf invoke printf,"SEGA!\r\n" p1=0; //str invoke printf,offset str_0000 p2=0; //str2 'SEGA!',13,10 str[0]=0; // str2[0]=0; //not needed while (buf[pb]) { #ifdef DEBUG2 printf("%i ",pb); #endif if (buf[pb]=='"') { //handle string f1=1; f2=0; f3=0; pb++; p2=0; str2[0]=0; while (1) { if ( (buf[pb]=='"') && (buf[pb+1]=='"')) { if (f1) { f1=0; str2[p2++]='\''; } if (f2) { f2=0; str2[p2++]=','; str2[p2++]='\''; } pb++; f3=1; str2[p2++]=buf[pb++]; continue; } if (buf[pb]=='"') break; if (buf[pb]==0) errorf("string left open[2]\r\n"); if ((buf[pb]=='\\') && (buf[pb+1]=='\"')) { if (f1) f1=0; pb+=2; if (f3) { str2[p2++]='\''; f3=0; str2[p2]=0; strcat(str2,",34"); p2+=3; f2=1; continue; } if (f2) str2[p2++]=','; else f2=1; str2[p2]=0; strcat(str2,"34"); p2+=2; continue; } if ((buf[pb]=='\\') && (buf[pb+1]=='\'')) { if (f1) f1=0; pb+=2; if (f3) { str2[p2++]='\''; f3=0; str2[p2]=0; strcat(str2,",39"); p2+=3; f2=1; continue; } if (f2) str2[p2++]=','; else f2=1; str2[p2]=0; strcat(str2,"39"); p2+=2; continue; } if ((buf[pb]=='\\') && (buf[pb+1]=='t')) { //NEW : v1.11 if (f1) f1=0; pb+=2; if (f3) { str2[p2++]='\''; f3=0; str2[p2]=0; strcat(str2,",09"); p2+=3; f2=1; continue; } if (f2) str2[p2++]=','; else f2=1; str2[p2]=0; strcat(str2,"09"); p2+=2; continue; } if ((buf[pb]=='\\') && (buf[pb+1]=='n')) { if (f1) f1=0; pb+=2; if (f3) { str2[p2++]='\''; f3=0; str2[p2]=0; strcat(str2,",10"); p2+=3; f2=1; continue; } if (f2) str2[p2++]=','; else f2=1; str2[p2]=0; strcat(str2,"10"); p2+=2; continue; } if ((buf[pb]=='\\') && (buf[pb+1]=='r')) { if (f1) f1=0; pb+=2; if (f3) { str2[p2++]='\''; f3=0; str2[p2]=0; strcat(str2,",13"); p2+=3; f2=1; continue; } if (f2) str2[p2++]=','; else f2=1; str2[p2]=0; strcat(str2,"13"); p2+=2; continue; } if ((buf[pb]=='\\') && (buf[pb+1]=='0')) { if (f1) f1=0; pb+=2; if (f3) { str2[p2++]='\''; f3=0; str2[p2]=0; strcat(str2,",0"); p2+=2; f2=1; continue; } if (f2) str2[p2++]=','; else f2=1; str2[p2]=0; strcat(str2,"0"); p2+=1; continue; } if ((buf[pb]=='\\') && (buf[pb+1]=='\\')) { if (f1) { f1=0; str2[p2++]='\''; f3=1; } if (!f3) { if (f2) {str2[p2++]=',';f2=0;} str2[p2++]='\''; f3=1; } pb++; str2[p2++]=buf[pb++]; continue; } if (f1) { f1=0; str2[p2++]='\''; } if (f2) { f2=0; str2[p2++]=','; str2[p2++]='\''; } f3=1; if (buf[pb]=='\'') str2[p2++]='\''; // FIX : v1.2 str2[p2++]=buf[pb++]; } //end while if (f1) { //null string FIX v1.1 str2[p2++]='0'; str2[p2++]=0; anulstr=1; } else { if (f2) str2[p2]=0; else { str2[p2++]='\''; str2[p2]=0; } anulstr=0; } out2nd(); //out the string stuff pb++; //pts now to next , (or end) //finish up 1 string thingy str[p1]=0; #ifdef DEBUG2 printf("%i\n",pb); printf("%s\n",buf); printf("%s\n\n",str); #endif sprintf(str3,"offset str_%05u",cnum-1); str[p1]=0; strcat(str,str3); p1=strlen(str); #ifdef DEBUG2 printf("%i\n",pb); printf("%s\n",buf); printf("%s\n\n",str); #endif } else { str[p1++]=buf[pb++]; str[p1]=0; //not really needed (for debugging) } } //end while str[p1]=0; #ifdef DEBUG2 printf("%i\n",pb); printf("%s\n",buf); printf("%s\n\n",str); #endif } //end if "string mode" out(); //output normal string (may be mod by string stuff!!) } } void out(void) { word a; strcat(str,enter); a=strlen(str); if ((a+bufp1)>bufsiz) { write(ho1,bufo1,bufp1); bufp1=0; } memcpy(bufo1+bufp1,str,a); bufp1+=a; } //places str2 into ho2 void out2nd(void) { word a; word p; p=strlen(str2); if (!anulstr) str2[p++]=','; str2[p++]='0'; str2[p]=0; sprintf(str3,"str_%05u db ",cnum++); if (cnum==64000) error("too many strings\r\n"); //unlikely!!! strcat(str3,str2); strcat(str3,enter); a=strlen(str3); if ((a+bufp2)>bufsiz) { write(ho2,bufo2,bufp2); bufp2=0; } memcpy(bufo2+bufp2,str3,a); bufp2+=a; } byte out2setup[]=".data\r\n"; void setup(void) { //open files and setup out2nd ho1=open("asm.tmp",O_BINARY|O_WRONLY|O_CREAT|O_TRUNC); if (ho1==-1) error("creating asm.tmp\r\n"); ho1on=1; ho2=open("_str_.tmp",O_BINARY|O_WRONLY|O_CREAT|O_TRUNC); if (ho2==-1) error("creating _str_.tmp\r\n"); write(ho2,out2setup,7); inc=(void*)getenv("INCLUDE"); if ((dword)inc==ERROR) { printf("Warning:INCLUDE not set in enviroment\r\n"); } else { incsiz=strlen(inc); } } void flush(void) { write(ho1,bufo1,bufp1); write(ho2,bufo2,bufp2); bufp1=0; close(ho1); ho1on=0; close(ho2); }