Transferring Sprites to EMS in the DQB Library

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:

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...

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...

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:


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:

address& = spriteNumber% * 260&

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

For further aid check DQB extensive documentation:



DECLARE SUB DQBpoke (BYVAL dataSeg, BYVAL dataOff, BYVAL Offset AS LONG, BYVAL Length)


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



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


' All integers for speed


' 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
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

PS: nooo, I'm not Angelo :D


TransferingSpritesToEMSinDQB - page last edited 2004-02-10 12:29:35 by (home) (edit)
Blast WIKI - by RoboticBoy - edited and tweaked for our evil purposes by Hexadecimal Disaster