bb2 file format

Community Forums/General Help/bb2 file format

markcw(Posted 2009) [#1]
I found this site so I thought I'd have a look at the source code but now I find it's some wierd Amiga format.
http://www.config.freeuk.com/amiga/blitz/

I can't find any info on Google so I thought I'd ask here and see if there is anyone still around who knows something about the bb2 or bb2.xtra formats or how to convert them into a PC text file?


skidracer(Posted 2009) [#2]
You will need to use an emulator as Ted used to keep source tokenized for smaller files by default.


markcw(Posted 2009) [#3]
Aha. Ok, thanks skid.


skidracer(Posted 2009) [#4]
Most of the .bb source on aminet should hopefully be in ascii. Tokenized source like static userlib numbers was optimal for the time but doesn't make it easy to recover / translate.

I can't remember but it might be possible to build a bb detokenizer.

I just saved a print "hello" and got in binary
81 20 22 68 65 6c 6c 6f 22 00 00

and found this old list



but unfortunately the lib id doesn't look if it matches up for the print command

perhaps someone else a little more familiar can comment

converting the above to a bb program, and tokenizing it in Ted I suppose could be other option, bleh.

hmm, quick look in the original manual reveals:


Tokens

The Blitz 2 editor stores all the BASIC keywords as tokens, these
tokens are 16 bit numbers encoding which library the BASIC keyword
comes from and an offset detailing where in the library the keyword's
ASCII name, help information and compile time code can be found.

Because the user can configure Blitz 2 to use some libraries and not
others problems can arise when a program's source code includes tokens
that are not available in the libraries that Blitz 2 loaded when it
was run. The error Token Not Found $xxxx signals the token code it
was unable to locate.

Each library can include 128 statements and functions. The token
code uses the lower 7 bits for which function/ statement it is
and the upper 9 bits to signify which library the token came from.



so $dd81 gives us command 1 with lib#443 which anded with 255 (high bit obviously dictates it's a token so 9 bit reference above is wrong) gives us the correct decoding for print, woot!


BlitzSupport(Posted 2009) [#5]
Part of the problem is that what the tokenizer converted each token into was dependent on the individual installation's library numbers, so it wasn't uncommon to find source code full of undecodeable ?????? statements or incorrect commands picked up from differently-numbered libraries.

In the latter days of Amiga Blitz (1999-ish?), the Blitz List members tended to share code almost exclusively exported in ASCII format because of this. All you can realistically do (unless you're really willing to get into parsing the files, and even then you can't account for conflicting libnums) is load the code into AmiBlitz on WinUAE and hope for the best (then export as ASCII if it looks OK).


markcw(Posted 2009) [#6]
Thanks guys. It would be cool to code a bb2 detokenizer but I don't have the time atm so I'll take the emulator route for now. :)


skidracer(Posted 2016) [#7]
Score.


First version. Strips tokens but at least we can read the comments / strings.

path$="/Users/simon/blitz2/husker3.bb2"

bank:TBank=LoadBank(path)
Print bank.Size()

src$=""

For i=0 Until bank.size()

b=bank.PeekByte(i)

If b=0 
	src:+"~r~n"
EndIf

If b>31 And b<127 
	src:+Chr(b)
EndIf

Next

Print src



skidracer(Posted 2016) [#8]
The tool now seems to manage a little more. The original blitz2 source code courtesy Sibly is also here.

https://github.com/nitrologic/blitz2


BlitzSupport(Posted 2016) [#9]
Just saw that on Github in passing -- wondered why I hadn't noticed it before!

If you're faffing about with bb2 code, you might find this "library investigator" handy -- it was written by my 'back-in-the-day' Blitz buddy Curt Esser (sadly no longer with us):

http://aminet.net/package/dev/basic/Blitz.I

It lists all the commands from the libraries installed on your specific system, bearing in mind that a given libnum on one person's system was often mapped to a different library on another's.

It was meant to be turned into a bb2 parser that would look up each command based on the tokens in the bb2 source and then convert to .asc. I think the idea was that you could then remap each libnum until the output 'looked' right, but it didn't get that far...

Anyway, could help with matching tokens to libs/commands, particularly for the standard acidlibs, etc...


skidracer(Posted 2016) [#10]
It is turning out to be quite the challenge. I am looking forward to scanning bb2 source files on mass once the bugs are out...


skidracer(Posted 2016) [#11]
Major break through, nearly there.

This original Skidmarks source shows a few remaining ##[$ tokens unfound.

100% Blitz BASiC 2, 50% inline assembler (packed).


BlitzSupport(Posted 2016) [#12]
That's looking very close.


skidracer(Posted 2016) [#13]
Just dropped a mother lode of bb code from 1995 A4000 archive.

A few teething problems at github...

https://github.com/nitrologic/blitz2/tree/master/tools/readbb2/scan


LOLS


BlitzSupport(Posted 2016) [#14]
Don't know if the ## are constants (ie. this might not be much use), but ##[$80B9] looks like it's a MOD, going by online search of this formula, and I see it's in the skidmarks link too, used in a similar scenario:

Seed=((25173*Seed)+13849) ##[$80B9] 65536


https://duckduckgo.com/?q=%28%2825173*Seed%29%2B13849%29+%23%23[%2480B9]+65536&t=ffab&ia=web


BlitzSupport(Posted 2016) [#15]
Some results seem to be missing newlines, by the way, eg:

https://github.com/nitrologic/blitz2/blob/master/tools/readbb2/scan/poly%20%26%20polyf.bb.txt


skidracer(Posted 2016) [#16]
Thanks!

Those files were already ascii.

Should be fixed now.


skidracer(Posted 2016) [#17]
A little more hacking and yup, nearly there...

;
; My first starfield in Blitz2
;

NoCli

NEWTYPE .p
	speed.w
	x.w
	y.w
End NEWTYPE

Dim List star.p(39)

USEPATH star()

BLITZ
BitMap 0,320,256,2
BitMap 1,320,256,2

Slice 0,44,2
Green 1,15,15,15
db=0
Gosub fillspace
While Joyb(0)=0
	VWait
	Show db:db=1-db:Use BitMap db
	BlockScroll
	Gosub drawstars
Wend

End

.fillspace
	USEPATH star()
	ResetList star()
	While AddItem(star())
		\speed=Rnd(10)
		If \speed=0 Then \speed=1
		\x=Rnd(319)
		\y=Rnd(250)
	Wend
Return

.drawstars
	USEPATH star()
	ResetList star()
	While NextItem(star())
		Point \x,\y,1
		\y=QWrap(\y+\speed,0,250)
	Wend
Return


Green???