Qbasicnews.com

Full Version: Using DQBPoke w/ graphics?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How would I poke an image to a certain EMS location using DQB?

I do it like this:

DQBPoke VARSEG(gfx(0)), VARPTR(gfx(0)), Address, Length

but that doesn't work... Is it just WinXP?
Your consciousness is telling you to use UGL..
No, it's saing CONVERT TO C++
That's the evil part of you speaking....
Just sent the link, Agamemnus Smile
Well, most problems using DQBPoke come from not callculating well the length.

Imagine you have a sprite measuring 16x16. Its size is given by this formula:

Code:
sizeInBytes% = With% * Height% + 4

(Explanation: Each pixel take a byte, so you have width*height for the entire image. The four extra bytes are for the two first integer array indexes that specify your sprite's width and height themselves, 'cause 1 integer = 2 bytes)

So you have that your sprite size will be 16 * 16 + 4 = 260 bytes. If your sprite is in spriteArray%(), you just need to...

Code:
DQBPoke VARSEG(spriteArray%(0)), VARPTR(spriteArray%(0)), offset&, 260

Where offset& is an absolute address into EMS (imagine that the EMS you have allocated is flat-measured). The size of your EMS working area is the third parameter to your DQBInit function, so if you just...

Code:
i% = DQBInit (1, 0, 100)

You are telling DQB that you need 1 extra offset buffer, 0 sound "docks" and 100 Kb of EMS memory.

(be sure to check this:

Code:
IF DQBInit(1, 0, 100) THEN DQBClose: PRINT "EMS NOT FOUND!": SLEEP: k$=INKEY$: SYSTEM

so you can tell whether it is not working 'cause EMS has not been properly configured or not).

That means that your offset& can be from 0 to 102400 (100 Kb), but you must beware not to poke outside the EMS reserved, or DQB and your DOS box will crash together (so ugly, isn't it?). Letting you select the address directly can be a little confusing, but you'll realize that it will give you complete control.

Imagine that you have only 16x16 sprites; that way you can imaginarily divide your EMS into 260 bytes "bits" and index them, so you can use this formula:

Code:
address& = spriteNumber% * 260&

to keep track where are you writing (or reading using DQBPeek).

For further aid check DQB extensive documentation:

Quote:DQBpoke SUB

Prototype:

Code:
DECLARE SUB DQBpoke (BYVAL DataSeg, BYVAL DataOff, BYVAL Offset AS LONG, BYVAL Length)

Calling:

■ DataSeg Segment of QB array or variable where is data to copy to EMS
■ DataOff Offset of QB array or variable where is data to copy to EMS
■ Offset Absolute offset into allocated EMS memory where to copy data
■ Length Length in bytes to copy

Returns:

none


Description: DQBpoke is used to write data from a QB array or variable, into the user EMS memory poll; you must specify the address and the length in bytes of the source data, plus an offset into EMS where to copy it. As for DQBpeek, this address is absolute, so you refer to your user EMS area as a flat memory area.

Notes: Never try to copy data when it (or a part of it) will lie outside the user EMS memory area set by the DQBinit function; you may end with a machine crash.

See also DQBpeek


Example:

Code:
' All integers for speed
DEFINT A-Z

'$INCLUDE: 'directqb.bi'

' Let's initialize the library with no layers nor sounds, but 100KB of EMS
IF DQBinit(0, 0, 100) THEN DQBclose: PRINT DQBerror$: END

' Here we declare a string we'll copy to EMS
DIM Text AS STRING * 30
Text = "This is a test!!"

' Let's display our string
PRINT "Now the string is: " + Text

' Copies the string to EMS, at address 0 of our user memory area
DQBpoke VARSEG(Text), VARPTR(Text), 0, 30

' Clears our string and display it
Text = ""
PRINT "Now the string is: " + Text

' Gets back the string from the EMS user memory area
DQBpeek VARSEG(Text), VARPTR(Text), 0, 30

' Displays it again
PRINT "Now the string is: " + Text

' Ends program
DQBclose
END

PS: nooo, I'm not Angelo Big Grin
Quote:PS: nooo, I'm not Angelo Big Grin

Riiiight. Wink Agamemnus said he's gonna try and see if it can be converted to UGL, I'll try this too.