Help... screen 13 virtual memory and a few library questions

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
LightBulb
Newbie
Posts: 6
Joined: Wed Apr 02, 2008 8:04 pm

Help... screen 13 virtual memory and a few library questions

Post by LightBulb » Wed Apr 02, 2008 8:15 pm

I have just a few questions involving these two topics. Thanks in advance for answering my questions.

I understand the basics of making a screen 13 virtual memory page, such as PSETing to it and POINTing to it. put when the "virtual flip" happens, I don't understand how it works. Also, is there a way to PUT and GET from the virutal page?

Involving Libraries...
Is the .BI file nesessary? I've seen turtorials that say to do it, and others that don't even mention it.

in the "Set Paths" option in quick basic, rather than typing in /L (your lib here) in MS-DOS, can you just type in the file path to your library there?

How do you type in multiple flie names in zones in the "Set Paths" option?

Thanks!

User avatar
Michael Calkins
Veteran
Posts: 76
Joined: Tue Apr 05, 2005 8:40 pm
Location: Floresville, Texas
Contact:

Post by Michael Calkins » Wed Apr 02, 2008 10:58 pm

I understand the basics of making a screen 13 virtual memory page, such as PSETing to it and POINTing to it. put when the "virtual flip" happens, I don't understand how it works. Also, is there a way to PUT and GET from the virutal page?
I assume you are talking about the video memory pages that you can manipulate with the SCREEN and PCOPY statements?? This wouldn't be virtual memory... Maybe you are referring to something else... Screen 13 only has 1 video memory page...
For screen modes that allow multiple pages, I think the VGA hardware is instructed somehow to switch what part of memory it uses for the screen?? I'm not sure. The BIOS Int 0x10 functions allow video memory pages, but how exactly it works, I don't know.

Here is some code that demonstrates video memory pages:

Code: Select all

DEFINT A-Z
z = &H1000

SCREEN 0, , 1, 1
CLS
COLOR 15, 1
PRINT "A"
SCREEN 0, , 0, 0
CLS
COLOR 7, 0
PRINT "a"
DEF SEG = &HB800
PRINT HEX$(PEEK(0)), HEX$(PEEK(1))
PRINT HEX$(PEEK(z)), HEX$(PEEK(z + 1))
As you can see, the "A" in page 1 is at b800:1000, while the "a" in page 0 is at b800:0000.

To get or put to a specific page, just make it the active page.
But screen 13 only has one page... Are you using some library to emulate multiple pages for it? If so, could you please state what library, and someone with experience with it can help you....
Is the .BI file nesessary?
I don't use QB 4.5, but if it's like anything else, the include file (like a .h file in C) is just a file that gets copied into your source at compile time.
#include <whatever.h>
is the same as copying the contents of the file into your code at that spot. include files contain declarations of functions, etc, that your code will use. I'm not sure, but I imagine they are necessary (either in an included header file, or in your code itself). I imagine there would be link time problems without them?
Regards,
Michael
Bring on the Maulotaurs! oops...
I like to slay Disciples of D'Sparil...

User avatar
Codemss
Veteran
Posts: 124
Joined: Sun Jun 24, 2007 6:49 am
Location: Utrecht, The Netherlands
Contact:

Post by Codemss » Thu Apr 03, 2008 2:07 pm

Well. There is, somewhere in memory, a large portion of bytes which holds the screen data. You can manipulate them with POKE and PEEK. If you set DEF SEG = &HA000, and then poke at 320 * y + x, and with the colour as argument, you have a faster alternative for pset. Example:
(pset) POKE y * 320 + x, colour
(point) colour = PEEK(x* 320 + x)

You can optimize this by making a LUT with 200 integers which mulitplies with 320. Then you don't have to multiply, but you can simply use y as the index for the array.

It is the fastest if you use a pointer that starts at zero, but ends at 64000(=320*200, so at the right bottom of the screen). So every time you increase this pointer by one, the pixel that will be affected by that poke, is one to the right. And every 320 times the pointer moves to the beginning of the next row of pixels.
(Something I found out by looking at a heavily optimized rotozoomer is that can be a normal integer, but it will work only when compiled then. It is very weird: compiled the integers dont give an overflow error, so you can always try to replace long integers by normal integers before compiling, this speeds everything up A LOT. I used this much by making optimized demo effects and it is really great)

Back to the point
When you want to get rid of flicker, you have to make a screen buffer. That is just a large array with 32002 integers, that you set def seg to:
DEF SEG = VARSEG(array(0))
Then you poke to it, and then you can PUT at the screen.
Almost forgot: you got to dimension the array. There are two ways:
1. Use GET (0, 0) - (319, 199), array(0)
2. Dimension them by hand:
array(0) = 320(this can be another value too, but only smaller, but this is only if you want a smaller screen buffer. If you do this, I have to mention that the pointer moves to the next row every (x + 1) steps) * 8
array(1) = 199(again this can be smaller if you want a smaller screen buffer)

I hope you understood. This is pretty much all I know about screen buffers, pointers, peek and poke, memory in QB and optimizations.
Check out my site: <a href="http://members.lycos.nl/rubynl">Click here</a>
Hope you like it. Send some feedback if you want: <a href="mailto:basicallybest@live.nl">Mail me</a>
Codemss, before known as RubyNL

LightBulb
Newbie
Posts: 6
Joined: Wed Apr 02, 2008 8:04 pm

Thanks!

Post by LightBulb » Sun Apr 06, 2008 8:41 pm

Thanks Codemss. I think I understand it. I'll play with it some and find out exactly how it works. I figured out my library question to. you just have to define the functions and subs again...

LightBulb
Newbie
Posts: 6
Joined: Wed Apr 02, 2008 8:04 pm

Post by LightBulb » Thu Apr 10, 2008 6:37 pm

I played with this virtual screen some, but I have a few questions. I've been able to "PSET" to the virtual page by using poke, while playing with it, but now, do you happen to know a way to "PUT", and "GET" from the virtual screen? or is POKEing and PEEKing to it fast enough to forget about the other statements and not make a statment to mimic there functions?

User avatar
burger2227
Veteran
Posts: 2434
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 » Thu Apr 10, 2008 8:01 pm

Once you have the image, you can GET a boxed area. You can later PUT it anywhere within the screen area. You need an appropriate sized array for the job.

The screen buffer can hold the entire screen using BSAVE, but GET and PUT fall a little short of fullscreen in 13.

Ted
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0

Yazar
Coder
Posts: 11
Joined: Sat May 24, 2008 10:51 pm

Post by Yazar » Sun Jun 01, 2008 12:16 pm

also these are the virtual memory pages;

----------------------------------1:

Code: Select all

DIM MyScreen(199) as String * 320
MyPset;

Code: Select all

Sub Dot(X%,Y%,Z%)
ax& = x%
ay& = y%
Def Seg = Varseg(MyScreen(0))
Offset& = VarPtr(MyScreen(0)) + ax& + ay& * 320&   'Be carefull With Overflow Error!
Poke Offset&, Z%
def seg
End Sub


Function Pixel%(X%,Y%)
ax& = x%
ay& = y%
'Returns The Pxiel Value
Def Seg = Varseg(MyScreen(0))
Offset& = VarPtr(MyScreen(0)) + ax& + ay& * 320&   'Be carefull With Overflow Error!
k%=Peek(Offset&)
def seg
Pixel = k%
End Function

THESE 2 ROUTINNES ARE FASTER THEN USING MID$(MyScreen(Y%),X%+1,1)




For Drawing;

Code: Select all

add& = 0
For y% = 0 to 199
For x% = 0 to 319
def seg = &HA000
p% = Pixel(x%,y%)
add& = add& + 1
poke add&, p%
next
next
def seg
You must use assembly for faster paste.


Now;

Code: Select all

Dim SHared Virmem(9) as String * 10  'we have 100 bytes ! 10-10-10...
VirMem(0) = "TOLGAARCOK"

'Now Lets Use The Function Above
k% = Pixel(0,5)   'Note That it means 1,6!!!
Print K%

Dot 0,5,66
Print VirMem(0)
The Result is 65 which is ASC(A) and after Dot Command;
TOLGABRCOK

I hope you get it... The Fixed String Storage Are Is your own home :D



-----------------------------------------------2:
use a file! Just use a file for storing some temp data, it can be used as a memeory too, but be carefull, you must access lots of time to there so not nice for hdd.

Post Reply