[Coco] BAS binary format

Mathieu Bouchard matju at artengine.ca
Wed Nov 6 16:50:27 EST 2013


Le 2013-11-06 à 17:22:00, Johann Klasek a écrit :
> I did something similar for Dragon ColorBasic (less tokens and some
> differences in ordering) with a Perl script recently.
> See http://klasek.at/hc/dragon/iec-floppy/#tools

Crazy how everything used to be designed without even attempting 
cross-platformness. When Jean Sammet made her study on categorising 
programming languages around 1970, there were already over 2000 
programming languages, even though very few computers were selling. This 
difference in binary formats for very similar programming languages is 
just one more testimony to that mentality.

(I just read yesterday evening about ADOS vs ECB2 vs ADOS3 keyword 
confusion, and about the bug that makes DECB tokens crash a plain ECB 
ROM.)


> This is not just ColorBASIC, there are also disk extensions ...

Yup, that's what I meant to do. I had the CB, ECB and DECB keywords from 
one document at first, and then I decided to look for ECB2 keywords and I 
spent extra time finding & adding the ECB2 keywords too, because that 
covers what I used and what almost everybody used. All I have apart from 
that is a few ADOS3 programmes.


> The stringconstant case is missing. While in "..." you must not
> expand token codes.
>
> Every  c==34 should flip a "in string" flag.
> Only if not "in string" ...
> Only if not "in string" ...
> Reset "in string" flag in case a string has no explicit closing '"'.

Ok, I implemented it, even though CB doesn't. (though I didn't do it with 
a flag).

I also fixed a typo (had written KLINE instead of HLINE).

I also implemented some simple syntax colouring.

-----------------8<--------découpez-ici--------8<-----------------
#!/usr/bin/env ruby
# encoding: utf-8
#
# décodeur de fichiers .BAS binaires de ColorBASIC (avec CoCo3+disquettes)
# decoder for .BAS binary files from ColorBASIC (with CoCo3+diskettes)
# Copyright (c) 2013 Mathieu L Bouchard

instrucs = "FOR GO REM ' ELSE IF DATA PRINT ON INPUT END NEXT DIM READ \
RUN RESTORE RETURN STOP POKE CONT LIST CLEAR NEW CLOAD CSAVE OPEN CLOSE \
LLIST SET RESET CLS MOTOR SOUND AUDIO EXEC SKIPF TAB( TO SUB THEN NOT \
STEP OFF + - * / ^ AND OR > = < DEL EDIT TRON TROFF DEF LET LINE PCLS \
PSET PRESET SCREEN PCLEAR COLOR CIRCLE PAINT GET PUT DRAW PCOPY PMODE \
PLAY DLOAD RENUM FN USING DIR DRIVE FIELD FILES KILL LOAD LSET MERGE \
RENAME RSET SAVE WRITE VERIFY UNLOAD DSKINI BACKUP COPY DSKI$ DSKO$ :-) \
WIDTH PALETTE HSCREEN LPOKE HCLS HCOLOR HPAINT HCIRCLE HLINE HGET HPUT \
HBUFF HPRINT ERR BRK LOCATE HSTAT HSET HRESET HDRAW CMP RGB ATTR".split

foncts = "SGN INT ABS USR RND SIN PEEK LEN STR$ VAL ASC CHR$ EOF JOYSTK \
LEFT$ RIGHT$ MID$ POINT INKEY$ MEM ATN COS TAN EXP FIX LOG POS SQR HEX$ \
VARPTR INSTR TIMER PPOINT STRING$ CVN FREE LOC LOF MKN$ :-) \
LPEEK BUTTON HPOINT ERNO ERLIN".split

a = File.open(ARGV[0],"r:ASCII-8BIT") {|f|f.read}
#i=1
i=5
print a[i].ord*256+a[i+1].ord," "
i+=2
while a[i]
   c = a[i].ord
   if c==255 then
     print "\e[1;33m#{foncts[a[i+1].ord-128]}\e[0m"
     i+=2
   elsif c>=128
     print "\e[1;32m#{instrucs[c-128]}\e[0m"
     i+=1
   elsif c==34 then
     j=a.index(/["\0]/,i+1)+1
     j+=1 if a[j]==34
     print "\e[1;36m#{a[i...j]}\e[0m"
     i=j
   elsif c>=32 then
     print c.chr; i+=1
   elsif c==0 then
     print "\n",a[i+3].ord*256+a[i+4].ord," " rescue break
     i+=5
   else
     printf "[%02x]", c # caractère inconnu
     i+=1
   end
end
puts ""
-----------------8<--------découpez-ici--------8<-----------------

  ______________________________________________________________________
| Mathieu BOUCHARD ----- téléphone : +1.514.383.3801 ----- Montréal, QC


More information about the Coco mailing list