Qbasicnews.com
October 19, 2021, 09:46:52 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Screen 13 buffer  (Read 5242 times)
Aaron
Member
*
Posts: 35


« on: May 04, 2003, 02:37:47 AM »

I'm in the process of writing subs to enable me to have a buffer in screen buffer in Screen 13. The only problem is, they have ended up being very, very slow. It takes quite a long time for each of them to run and thus my graphics are fairly slow (although there are no flicker problmes Smiley ).  Anyway, I was just wondering what suggestions, if any, you guys had as to what to do to increase the speed of my routines. One thought I had, don't know if its worth doing, or even possible (due to the offset limit size) was to only define my segment once and then just use offsets to reference my memory locations. As you can probably see, the routine I use below (te equivelant of put) is quite calculation intensive and redifnes the segment 2 times per cycle. BTW, page() is the screen buffer.

 
Code:

SUB fastput (x%, y%, img%())                         'has automasking feature
   wimg& = img%(0) / 8                                'determines width of the image to be put
   himg& = img%(1)                                 'determines height of the image
   wpage& = page(0) / 8                                'determines width of the page to be written to
   simg& = VARPTR(img%(2))                            'finds the start of the img to be displayed
   spage& = VARPTR(page(2))                            'finds the start of the actual graphics data
   FOR ycnt& = 0 TO himg& - 1                             'loops through the images rows
      FOR xcnt& = 0 TO wimg& - 1                          'loops through the columns of a row in the image
         oimg& = wimg& * ycnt& + xcnt& + simg&          'finds the pixel in the images offset
         'DEF SEG = VARSEG(img%(0)) + INT(oimg& / 16)    'sets the segment of the pixel being pulled from the image
         DEF SEG = VARSEG(img%(0))
         'pixeltocopy% = PEEK(oimg& MOD 16)              'gets the value at the pixel
         pixeltocopy% = PEEK(oimg&)
         'PSET (xcnt& + 20, ycnt& + 20), pixeltocopy%
         IF pixeltocopy% THEN
            opage& = wpage& * (ycnt& + y%) + xcnt& + x% + spage&   'finds offset in screen buffer
            DEF SEG = VARSEG(page%(0)) + INT(opage& / 16) 'sets the segment of the pixel being placed on the page
            POKE opage& MOD 16, pixeltocopy%               'places the pixel in the page buffer
         END IF
      NEXT xcnt&
   NEXT ycnt&
   DEF SEG                                              'returns segment to basic's default

END SUB
Logged
toonski84
__/--\__
*****
Posts: 2567



« Reply #1 on: May 04, 2003, 11:06:52 AM »

quick suggestion.  if you're only using integers, use integer division. ("\" instead of "/").  and instead of mod, which uses division to do its thing, use "and" on powers of 2.  so instead of:

something mod 16

use

something and 15

also, just the usual, unroll loops and dont use different data types together, etc.  actually, if you want "pure qb" for some reason, i'd go ahead and not use subroutines for sprites unless it's necessary, as qb's stack handler blows.   instead, i'd use one giant drawscreen sub and not let that call anything except maybe setvideoseg.
Logged

i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
relsoft
*/-\*
*****
Posts: 3927



WWW
« Reply #2 on: May 05, 2003, 02:53:11 AM »

RelGFX or SETVDEOSEG.
Logged

y smiley is 24 bit.


Genso's Junkyard:
http://rel.betterwebber.com/
Aaron
Member
*
Posts: 35


« Reply #3 on: May 05, 2003, 11:40:56 AM »

I assume RelGFX is a library, is it in pure qbasic, or does it have asm? I want to try to keep this in pure qbasic.

Also, what is setvdeoseg? Is there a special command you can use just to set the video segment?

btw, thanks toonski84, i will try the integer division and the and statement
Logged
Aaron
Member
*
Posts: 35


« Reply #4 on: May 06, 2003, 01:00:18 AM »

So, here's it is, fixed:
Code:

SUB bbput (x%, y%, filename$)
   DIM img%(201)
   DEF SEG = VARSEG(img%(0))
   BLOAD "shipa.put", VARPTR(img%(0))
   wimg% = img%(0) \ 8                                                
   himg% = img%(1)                                                  
   wpage% = page(0) \ 8                                              
   simg% = VARPTR(img%(2))
   spage% = VARPTR(page(2))
   FOR ycnt% = 0 TO himg% - 1
      FOR xcnt% = 0 TO wimg% - 1
         oimg% = wimg% * ycnt% + xcnt% + simg%
         DEF SEG = VARSEG(img%(0))
         pixeltocopy% = PEEK(oimg%)
         IF pixeltocopy% THEN
            opage% = wpage% * (ycnt% + y%) + xcnt% + x% + spage%
            DEF SEG = VARSEG(page(0))
            POKE opage%, pixeltocopy%
         END IF
      NEXT xcnt%
   NEXT ycnt%
   DEF SEG
END SUB


previously, I was using two subs to do this same thing (one loaded the file into the array, and then passed it on to the other)

I now realize that this is what was slowing down my code so much, with this, and the total conversion to short integers, my sub puts grafix to the buffer in about 1/3 to 1/4 the time qbasics put can write them to the screen. Granted I still have to transfer them from the buffer to the screen, but that is rather quick in the overall scheme of things.

thanks for all your help with getting this little thing worked out, I appreciate the responses

Aaron
Logged
relsoft
*/-\*
*****
Posts: 3927



WWW
« Reply #5 on: May 09, 2003, 04:29:12 AM »

RelGFX is pureQB no asm no hack. SetvideoSeg enables you to use QB's drawing primitives(all the GFX statements in screen 13) in a buffer.

So you only have to:

SetVideoSeg Varseg(Page(6))

Pset(X,Y),Col

SetvideoSeg &ha000

Put(0,0), Page(6),Pset
Logged

y smiley is 24 bit.


Genso's Junkyard:
http://rel.betterwebber.com/
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!