Author Topic: Poke to screen 0 for speed  (Read 16804 times)

0 Members and 1 Guest are viewing this topic.

Offline PMACKAY

  • Forum Regular
  • Posts: 188
  • LIFE is Temporary
    • View Profile
Poke to screen 0 for speed
« on: July 30, 2018, 11:09:09 pm »
how can i make a sub that will poke to screen 0 fast. i want to have more speed at printing text. with color.

only want it to poke one ascii at a time : replace locate x,y:print "j"; with just a sub eg. loc x,y,char$

needs to be faster then locate and print

this is sort of what want

for i%=1 to 40
     for j%=1 to 25
          b$=mid$(screenmem$(j%),i%,1)
          loc x,y,b$
     next j%
next i%
_display

need speed as needs to go through this routine as in frames per second


will defseg=0 and other commands be slower than just locate x,y:print mid$(screenmem$(j%),i%,1)

thinking of making a boulderdash in ibm ascii
MackyWhite

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Poke to screen 0 for speed
« Reply #1 on: July 30, 2018, 11:38:20 pm »
Use _MEMPUT and _MEMGET for direct memory access.  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

FellippeHeitor

  • Guest
Re: Poke to screen 0 for speed
« Reply #2 on: July 30, 2018, 11:38:52 pm »
Or, for simplicity:

_PRINTSTRING (x, y), text$

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Poke to screen 0 for speed
« Reply #3 on: July 31, 2018, 01:29:50 pm »
or if you want to go real old skool,
Code: QB64: [Select]
  1. SUB reaprint (Layer%, x%, y%, text$, col%)
  2.  DEF SEG = &HB800
  3.  l% = Layer% * 4096
  4.  xloc% = x% * 2
  5.  yloc% = y%
  6.  IF LEN(LTRIM$(RTRIM$(text$))) > 1 THEN
  7.   FOR I% = 1 TO LEN(text$)
  8.    t$ = MID$(text$, I%, 1)
  9.    t% = ASC(t$)
  10.    POKE l% + 0 + xloc% + (yloc% * 160), t%
  11.    POKE l% + 1 + xloc% + (yloc% * 160), col%
  12.    xloc% = xloc% + 2
  13.    IF xloc% = 160 THEN xloc% = 0: yloc% = yloc% + 1
  14.   NEXT I%
  15.  ELSEIF LEN(text$) = 1 THEN
  16.   t% = ASC(text$)
  17.   POKE l% + 0 + xloc% + (yloc% * 160), t%
  18.   POKE l% + 1 + xloc% + (yloc% * 160), col%
  19.  

in nutshell
 DEF SEG = &HB800           'text memory seg
  POKE  offset% + 0 , t%   'character
  POKE  offset% + 1, col% 'color
 DEF SEG                           'restore memory seg

in todays terms there really isn't any speed gain from this method anymore its just a matter of whether or not you like using it.
Which I still do anyway.

by that I mean vs SMcNiell's MEMGET\PUT suggestion and FellippeHeitors _PRINTSTRING suggestion
« Last Edit: July 31, 2018, 01:33:03 pm by Cobalt »
Granted after becoming radioactive I only have a half-life!

FellippeHeitor

  • Guest
Re: Poke to screen 0 for speed
« Reply #4 on: July 31, 2018, 01:35:36 pm »
in todays terms there really isn't any speed gain from this method anymore its just a matter of whether or not you like using it.
Which I still do anyway.

by that I mean vs SMcNiell's MEMGET\PUT suggestion and FellippeHeitors _PRINTSTRING suggestion

There's no speed gain anymore because VGA memory is emulated and is, in the background, essentially doing what _PRINTSTRING is.

Offline SkyCharger001

  • Newbie
  • Posts: 14
    • View Profile
Re: Poke to screen 0 for speed
« Reply #5 on: August 03, 2018, 01:50:46 pm »
MEMGET/PUT allow you to bypass some checks performed by the normal graphical functions.

Offline PMACKAY

  • Forum Regular
  • Posts: 188
  • LIFE is Temporary
    • View Profile
Re: Poke to screen 0 for speed
« Reply #6 on: August 14, 2018, 07:37:02 am »
Would you be able to show me a small example on how to use _memget/memput


I need to speed up this a lot more with a faster way to print. its not slow and runs perfect but i want to start adding more stuff to this.


works perfect and boulders drop as should. like boulder dash.


ANIMATE:

_LIMIT 1000: FOR I% = 2 TO 19: FOR J% = 11 TO 2 STEP -1
        COLOR 14, 0
        B$ = MID$(MAP$(J%), I%, 1)
        C$ = MID$(MAP$(J% - 1), I%, 1)
        IF B$ = " " AND C$ = "O" THEN MID$(MAP$(J%), I%, 1) = "O": MID$(MAP$(J% - 1), I%, 1) = " ": SOUND INT(RND(1) * 400) + 1030, .03
        IF B$ = " " AND C$ = "D" AND INT(RND(1) * 2) = 1 THEN MID$(MAP$(J%), I%, 1) = "D": MID$(MAP$(J% - 1), I%, 1) = " ": SOUND INT(RND(1) * 400) + 5030, .04
        IF B$ = "v" AND C$ = "D" AND INT(RND(1) * 6) = 5 THEN MID$(MAP$(J%), I%, 1) = "D": MID$(MAP$(J% - 1), I%, 1) = " ": SOUND INT(RND(1) * 400) + 6030, .04
NEXT J%: NEXT I%
PRINTMAP:

FOR I% = 1 TO 20: FOR J% = 1 TO 12
        B$ = MID$(MAP$(J%), I%, 1)
        SELECT CASE B$
            CASE "B"
                COLOR BRICK%, BACK%: B$ = CHR$(178)
            CASE "D"
                COLOR DIAMOND%, FORG%: B$ = CHR$(4)
            CASE "3"
                COLOR BRICK%, BACK%
            CASE " "
                COLOR BACK%, FORG%: B$ = " "
            CASE "."
                COLOR DIRT%, FORG%: B$ = CHR$(176)
            CASE "M"
                COLOR MONSTER%, FORG%: B$ = CHR$(234)
            CASE "m"
                COLOR MONSTER%, FORG%: B$ = CHR$(232)
            CASE "X"
                COLOR BACK%, EXITDOOR%: B$ = CHR$(127)
            CASE "O"
                COLOR ROCK%, FORG%: B$ = "o"
            CASE "v"
                COLOR MAN%, FORG%: B$ = CHR$(2)
        END SELECT
        LOCATE J% + 2, I%: PRINT B$;
NEXT J%: NEXT I%
_DISPLAY
RETURN
MackyWhite

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Poke to screen 0 for speed
« Reply #7 on: August 14, 2018, 07:56:35 am »
One easy change which I immediately see which would vastly improve this would be to use ASC instead of MID$.

    B = ASC(MAP$(J%), I%)
    C= ASC(MAP$(J% - 1), I%)

Then use ASC values in your IF statements, such as substituting 32 for the space. (I'm on my iPad ATM and don't have a handy chart for value substitutions.)

I imagine the performance will increase dramatically.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Poke to screen 0 for speed
« Reply #8 on: August 14, 2018, 08:21:54 am »
Does _Limit work outside a loop? But that won't speed up things...

Does SOUND delay the action in loop? ie does execution wait for sound to finish before proceeding with next step?

Offline PMACKAY

  • Forum Regular
  • Posts: 188
  • LIFE is Temporary
    • View Profile
Re: Poke to screen 0 for speed
« Reply #9 on: August 14, 2018, 08:24:38 am »
i was thinking of rewriting the whole section including map$ form

dim screenmem$(?) to dim screenx%(?),screeny%(?)

then data from "????????????" to ?,?,?,?,?,?,? and doing away with mid$ altogether to get more speed


and where select case is no more char$, would change to ascII char and only have a color change as the ascii char already set


do you think it would be much faster
« Last Edit: August 14, 2018, 08:25:58 am by PMACKAY »
MackyWhite

Offline PMACKAY

  • Forum Regular
  • Posts: 188
  • LIFE is Temporary
    • View Profile
Re: Poke to screen 0 for speed
« Reply #10 on: August 14, 2018, 08:31:27 am »
the sound works perfect on my pc for speed limit. the animation is the right speed. but i just want stuff to execute faster as i am going to get my monsters to animat in the loop also


good pickup on limit.. going to remove it.
MackyWhite

FellippeHeitor

  • Guest
Re: Poke to screen 0 for speed
« Reply #11 on: August 14, 2018, 08:35:14 am »
Quote
Does _Limit work outside a loop?

Yes, provided it is in a section that'll be repeated with GOTO or GOSUB for example.

Offline PMACKAY

  • Forum Regular
  • Posts: 188
  • LIFE is Temporary
    • View Profile
Re: Poke to screen 0 for speed
« Reply #12 on: August 14, 2018, 08:41:26 am »
i added below my bas file... it is not complete. this is just the very first to see how things work. it will run. but thinking of recoding from the start. new keyboard routine needed. new arrays.. instead of strings just two single arrays


arrow keys to move, q to quit.
« Last Edit: August 14, 2018, 08:43:05 am by PMACKAY »
MackyWhite

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Poke to screen 0 for speed
« Reply #13 on: August 14, 2018, 11:11:20 am »
Hi PMACKAY,

To me, it seems most natural to use an x by y, 2 dimensional array eg things are located by an x, y coordinate.

Say a diamond is located at x=10, y=12 or map$(10, 12) = "D" or "Diamond"

or a map can be of numbers where say a diamond = 100  so map%(10, 12) = 100.

This is not to say dash isn't dashing!  ;) though I haven't quit have figured out the object of the game yet. I ended up stuck in a corner buried by rocks, yikes! ;)

PS Data could be loaded in from a file, a file created in a map making app.
« Last Edit: August 14, 2018, 11:20:36 am by bplus »

Offline PMACKAY

  • Forum Regular
  • Posts: 188
  • LIFE is Temporary
    • View Profile
Re: Poke to screen 0 for speed
« Reply #14 on: August 14, 2018, 11:19:09 am »
I have redone the work. the download is here. much faster if you take out the loop with wait &h3da,8 out. not complete but working. will work on more now. but much better
MackyWhite