English Amiga Board

English Amiga Board (http://eab.abime.net/index.php)
-   Coders. Blitz Basic (http://eab.abime.net/forumdisplay.php?f=126)
-   -   INCBIN weirdness (http://eab.abime.net/showthread.php?t=94121)

neumanix 07 September 2018 16:59

INCBIN weirdness
I'd like to include an image, a shape, or module into the executable, just as a challange to see what I can make, for example in just 64k.

I have both BB2.1 and Amiblitz2 and haven't been able to get this to work
properly in either.

This little example sort of works, but if I run it with the debugger on, it always gives a GURU warning at exit. It might run a few times, but then it always crashes.


Bitmap 0,320,256,2
DecodeILBM 0,?img
Slice 0,44,2
Show 0

IncBin "image.iff"

In AmiBlitz2 I tried adding the Chip command before the img: label to make sure it goes into chipmem, but same result.

There must be a solution to this right?

Daedalus 07 September 2018 18:11

I think you need to have an End statement before the img: label, otherwise when you click the mouse at the end of the program, the code runs on and tries to execute your image data... Which will not end well.

neumanix 07 September 2018 18:38

Of course. I didn't think of that. I omitted the End command, just so I could see the
debugger message at exit. I was hoping to see a "End of program" message, but with the End command the debugger just closes if there is no error it seems.

idrougge 08 September 2018 14:33

Use "Stop" if you want to break into the debugger.

Daedalus 08 September 2018 15:14

AmiBlitz3 gives you a "Program finished" message in the console, but Blitz just quits back to the IDE. A simple fix:


NPrint "Program finished. Press Enter."
x$ = Edit$(1)

The reason the debugger gives you an End Program message is that you shouldn't just let the program run out like that. The End statement does some things like freeing resources, closing files etc. For a simple program it won't make much difference, but if you run the program many times you might find your free RAM slowly disappearing.

idrougge 08 September 2018 17:03

By the way, is there no way to force Incbin to include files into chip RAM? If your picture or sound data ends up in fast RAM, you're wasting memory en masse.

Daedalus 09 September 2018 14:23

No, there's no way - IncBin files are packed as part of the executable object and so are loaded into fast RAM along with the program itself (if Fast RAM exists). The Decode#? commands then extract this data to chip RAM. So yeah, I guess it is a waste of RAM...

carrion 09 September 2018 19:35

Yeah That's actually a big bummer. I stepped at this problem when coding my "Alien Apparat" demo. Too bad Blitz doesn't have SECTIONS :(

There's also one more problem I encountered while coding the demo. Sometimes DecodePalette command didn't work and hanged the code causing Guru. Till this time I don't know what was the problem. Other Decode commands worked fine but DecodePalette didn't. One of my clues was that maybe the gfx tool I used (Grafx2) didn't save IFF files the right way, but it wasn't the case, as I reproduced the problem with files saved by PPaint... If you guys had the same problems with DecodePalette or other Decode commands pls lat us know here.

Daedalus 09 September 2018 22:47

I think Blitz's loading and saving of IFF palettes in general is a little buggy - I ran into some bugs when I was writing a palette manipulation program and ended up just implementing my own load/save routines.

neumanix 10 September 2018 21:30

Thanks for your tips on the debugger. I got INCBIN to work with protracker modules (PT Player) by checking if fastmem is installed and copying the module data to a bank in chipmem. I skip the copying if no fastmem is found.

bjadams 13 September 2018 17:10

The command DecodeModule doesn't seem to exist.
How can you play a MOD that has been INCBINed?

Daedalus 13 September 2018 17:26

Perhaps it's the DecodeMedModule? Interestingly, it seems it doesn't actually do any decoding:


DecodeMedModule replaces the cludgemedmodule, as med modules are not packed but used
raw, DecodeMedModule simply checks to see the memory location passed is in ChipMem
(if not it copies the data to chip) and points the Blitz MedModule object to that

bjadams 13 September 2018 22:49

What about non-MED modules?
As Blitz supports 2 types of modules: standard tracker mods and MED mods

Daedalus 13 September 2018 23:11

There doesn't seem to be an equivalent for MODs unfortunately.

bjadams 14 September 2018 00:55

I found out the XBONES CIA Lib on the Blitz Extras CD
DecodeModule is actually a CIA lib command!
However once I started to use this, my prog now crashes completely at END
If I don't use the StartTracker command all works fine

If i switch DEBUGGER ON, all works fine!!!

Any ideas?

neumanix 14 September 2018 21:28

I used the ptplayer which is a protracker player routine that idrougge converted, get it here:
You incbin the mod, but you need to check if fastmem is available, if it is then
the module will most likely end up there.
So you make a bank in chipmem, the size of the module, and copy the data from
fastmem to chipmem.


fastmem.b=AvailMem_(4) ; 4=fast, 2=chip
if fastmem ; is fastmem available? if so, better copy the module to chipmem
  InitBank 0,music_length,2
  For n.l=0 To music_length-1 Step 4
    Poke.l Bank(0)+n, Peek.l(?music+n)
  MTInit 0,0
Else ; if no fastmem is detected, the module must be in chipmem
  MTInit ?music,0,0

MTPlay On



If fastmem
  Freebank 0 ; free up the bank we allocated

IncBin "yourmodule.mod"

bjadams 15 September 2018 21:40


Thanks a lot, looks very straightforward.
Worked great for me!

All times are GMT +2. The time now is 17:30.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2018, vBulletin Solutions Inc.

Page generated in 0.04310 seconds with 11 queries