How do banks use the momory?

Blitz3D Forums/Blitz3D Programming/How do banks use the momory?

bytecode77(Posted 2008) [#1]
hi!

in order to poke integers to a DLL i compiled with FreeBasic, i need to know how to store bytes in the bank.
the first step is: if you type >Bank=CreateBank()< in bb. does the variable bank contain the memory pointer?
the next step would be to poke integers offsetted to that position. in what direction they go will be easy to find out. but how do i do this anyway? some ideas?

(if anyone knows something about FreeBasic, it would be
brilliant!)

thanks for thinking about it :)
bye!

edit:
bb code:
Graphics 640, 480, 32, 2
SetBuffer BackBuffer()

bank = CreateBank(32)
banktest(bank)
For i = 0 To 31
	Write i + " = "
	Print PeekByte(bank, i)
Next
WaitKey()
End
freeBasic code:
' fbc -dll mydll.bas

declare function banktest lib "BankTestDLL" alias "banktest" (byval bank as integer) as integer

function banktest(byval bank as integer) as integer export
    poke byte, bank + 8, 123
    function = 1
end function



Kev(Posted 2008) [#2]
when a bank is created the returned value is an internal struct used by blitz. the correct way would be to pass the bank to the .dll as an address pointer using '*' defined in the .decls function.

*EDIT

so your .decls might look like this


.lib "mydll.dll"
banktest%(bank*):"_banktest@4"




bytecode77(Posted 2008) [#3]
i tried that beforre and somehow my bank still is full of zeros when i write bytes to it using the freeBasic code above :(


Kev(Posted 2008) [#4]
!!!POST REMOVED!!!


Kev(Posted 2008) [#5]
ok this works for me.

the freebasic function
function banktest(byval bank as integer) as integer export
    poke byte, bank, 123
    poke byte, bank+1, 10
    function = 1
end function


the blitz decls
.lib "mydll.dll"
banktest%(bank*):"BANKTEST@4"


the blitz test example
;
;
;

bank = CreateBank(10)
banktest(bank)

For loop = 0 To BankSize(bank)-1
	Print PeekByte(bank,loop)
Next

MouseWait
End


and finaly the output

123
10
0
0
0
0
0
0
0
0



bytecode77(Posted 2008) [#6]
WOW! THANKS A LOT DUDE :)
this really solved the problem, but i have to check out what i did wrong ;)

i can tell you what i need this for: remember my textured software renderer with thousands of features except the speed? well, this time, it will be the speed :)
using this and the gread inline ASM support, i will rock the bank ;)
bye!


_33(Posted 2008) [#7]
So, I suppose this also works for image buffers?


Dreamora(Posted 2008) [#8]
there are no image buffers, only pixmap buffers.
and no, they are no banks, so you would access those BytePtr through regular memory accessing -> pixmapPtr[byte to read] for example


jfk EO-11110(Posted 2008) [#9]
I've posted some code in the archives on how to redirect a bank struct to an image in order to poke right to an image. It works, but isn't any faster than writepixelfast, simply because of the bottleneck between CPU and VRAM.

There is also a thread about "how to hack certain properties" in the tutorials section.

Both samples describe the blitz bank struct. I think it was:
long: adress of data
long: size in bytes

So a bank handle is the adress of the struct. something like that.


Jasu(Posted 2008) [#10]
Do I understand correctly, that the dll is poking the blitz programs memory area? How can this work?

EDIT: I had to see it myself, and it works. But why?