[Coco] BAS binary format
Mathieu Bouchard
matju at artengine.ca
Wed Nov 6 01:47:52 EST 2013
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.
Here's the whole source code :
-----------------8<--------cut-here--------8<-----------------
#!/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
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
if c==255 then
print foncts[data[i+1].ord-128]
i+=1
elsif c>=128
print instrucs[c-128]
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
else
printf "[%02x]", c # caractère inconnu
end
i+=1
end
puts ""
-----------------8<--------cut-here--------8<-----------------
______________________________________________________________________
| Mathieu BOUCHARD ----- téléphone : +1.514.383.3801 ----- Montréal, QC
More information about the Coco
mailing list