[Coco] BAS binary format

Johann Klasek johann+coco at klasek.at
Wed Nov 6 11:22:22 EST 2013


On Wed, Nov 06, 2013 at 01:47:52AM -0500, Mathieu Bouchard wrote:
> Le 2013-11-05 à 23:59:00, Mathieu Bouchard a écrit :
> 
> >I mean the binary ColorBASIC format itself, for recording programmes. I 
> >put it together in the same mail because those are some of the most 
> >important formats to me.
> 
> Ok, I just wrote a decoder, so that I can LIST the contents of a 
> ColorBasic binary .BAS file from a commandline in Linux. It should also 
> work as-is in MacOS 10.x, but on Windows, you'll need to download the 
> interpreter. It's written in the Ruby language.

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

Some comments and suggestions to improve this program ...

[..]
> #!/usr/bin/env ruby
> # encoding: utf-8
> #
> # décodeur de fichiers .BAS binaires de ColorBASIC
> # decoder for .BAS binary files from ColorBASIC
> # 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 KLINE HGET HPUT \
> HBUFF HPRINT ERR BRK LOCATE HSTAT HSET HRESET HDRAW CMP RGB ATTR".split

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

> 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
> 
> data = File.open(ARGV[0],"r:ASCII-8BIT") {|f|f.read}
> #i=1
> i=5
> print data[i].ord*256+data[i+1].ord," "
> i+=2
> while data[i]
>   c = data[i].ord

The stringconstant case is missing. While in "..." you must not
expand token codes.

Every  c==34 should flip a "in string" flag.

>   if c==255 then
Only if not "in string" ...

>     print foncts[data[i+1].ord-128]
>     i+=1
>   elsif c>=128
>     print instrucs[c-128]
Only if not "in string" ...

>   elsif c>=32 then
>     print c.chr
>   elsif c==0 then
>     print "\n",data[i+3].ord*256+data[i+4].ord," " rescue break
>     i+=4
Reset "in string" flag in case a string has no explicit closing '"'.


>   else
>     printf "[%02x]", c # caractère inconnu
>   end
>   i+=1
> end
> puts ""
> -----------------8<--------cut-here--------8<-----------------

I hope this helps ... ;)

Johann




More information about the Coco mailing list