PUTing images made in PP 256 to a Virtual screen

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
DaveUnit
Veteran
Posts: 72
Joined: Sat Oct 29, 2005 10:07 am

PUTing images made in PP 256 to a Virtual screen

Post by DaveUnit »

Well, I made a page-flipping SUB and a PUT that puts to the virtual page for the hell of it. Well, I'd like to ask anyone that's familiar with PixelPlus 256 this question.
How would I put those images into my Virtual screen? I'm sure I could figure it out if there were no Indexes (used for multiple images in a single file), that's what confuses me, those Indexes. I'm gonna take another good look at the MakeImageIndex SUB to see if I can find out how the indexes work but right now I'm confuzzled.
I can put arrays made by me to the Vitrual screen because I know how everything is setup, but PP 256 is a little different with those Indexes.
Any and all help is very much appreciated. I try to do things without having to ask people questions but being a newbie sometimes I just can't figure it out.
Thanks yet again, I love this forum. :)
~Dave~
Guest

Post by Guest »

Well, let's say you have a file with 10 images, and they're all 16x16. The formula for how many QB Integers you need for a file is this: (Width * Height + 2) * NumberOfTiles / 2. So (16x16 + 2) * 10 / 2 = 650.

Since your array starts at 0, and an image starts every 130 integers, then the formula for which image to use is ImageNumber * SizeOfOneImage. In this case, it would be ImageNumber * 130.

Calling a routine to do this might look like:

Code: Select all


'QB Code

PutToBuffer x, y, VARSEG(ImageArray (ImgNumber * 130)), VARPTR(ImageArray (ImgNumber * 130))

VARSEG and VARPTR just return the memory address of that particular part of memory, which I assume you know, since you wrote your own buffer routine. :D
User avatar
The Awakened
Veteran
Posts: 144
Joined: Sun Aug 07, 2005 1:51 am

Post by The Awakened »

Arg... that's me in the above post.
"Sorry for beating you up with a baseball bat Julian, but I DID think that you were a samsquanch."
DaveUnit
Veteran
Posts: 72
Joined: Sat Oct 29, 2005 10:07 am

Post by DaveUnit »

Hey, thanks alot! That really helped a lot. I'm gonna get right on that and try to get some of my sprites walking 'round the screen. :D

I like my buffer routine, but I'm afraid without any ASM pixel scrolling will never be fast enough unless there's some way to really speed up the code.
But regardless of whether or not I can do pixel by pixel scrolling, I'm happy that I made a Virtual screen PUT(with clipping), VGet, VCLS, and a VPset. I've finally amounted to something. :P

Well, Thanks again, man. You helped me alot. :)

~Dave~
DaveUnit
Veteran
Posts: 72
Joined: Sat Oct 29, 2005 10:07 am

Post by DaveUnit »

Okay, I can get an image on screen, the problem is this...
Becuase an integer is 2 bytes, I can only show every other pixel in the image.
This wouldn't be a problem normally but I've already DEF SEG'd my Virtual Screen.
Here's a my Put routine so far... It only handles 20 x 20 sprites right now just so i can make sure Put works right...

Code: Select all

DEFINT A-Z
SUB VPut (x, y, array(), IndexNumber)

DEF SEG = VARSEG(VPage(0))
offset% = VARPTR(VPage(0))
FOR yy = 1 TO 20
        FOR xx = 1 TO 20
                newx = x + xx
                newy = y + yy
                'CLIPPING: checks to see if x or y is offscreen and skips it.
                IF newx > 320 OR newx < 0 OR newy < 0 OR newy > 200 THEN
                        skip = 1
                        ELSE skip = 0
                END IF
                IF skip <> 1 THEN
                        colour = xx+yy*20
                        '^here's where part of the problem is
                        POKE offset% + newx + 320& * newy + 3, array(colour)                        
                END IF

        NEXT
NEXT

END SUB
I need to be able to access every byte of the array.
Much thanks to anyone that can help me out.
~Dave~
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post by Nodtveidt »

You can do one of two things:

1. PEEK the array you pass for the value rather than accessing the array the way you're doing it. Of course, without some kind of buffering optimization, this means switching segments back and forth, which can be a slow process, but on a modern computer, this isn't going to be a very expensive operation so you should be able to get away with it.
2. Use your current method, but you'd need to read and then plot 2 pixels at a time by splitting each integer into high and low values:

Code: Select all

pixel2 = array(index) AND 255
pixel1 = (array(index) - pixel2) / 256
This should work, but it's going to be rather slow. It's also not the best way of doing this. I typed it out of my head so it may not even work :) but it should.

Both of these methods can be further improved upon. I'll leave it up to you to figure out how. :D
DaveUnit
Veteran
Posts: 72
Joined: Sat Oct 29, 2005 10:07 am

Post by DaveUnit »

Thanks alot Nekrophidius! (the 2 lords prototype was great by the way) :D
I made the page flipping routine to try to see if I could get graphics with no flicker in programs that I make without using a library. I'm not against using libraries, but if I just use someone else's code to make my programs better I won't learn a single thing, so I'm trying to do as much as I can by myself. It looks like I'll hafta use libraries if I want fast buffering... :(

Well, I suppose I'll go fix my Put routine now and then... uhh... eat turkey. :D

Adios, thanks for the help.

~Dave~
Post Reply