Author Topic: Really? Does _PRINTSTRING have lag issues? [SOLVED]  (Read 3186 times)

0 Members and 1 Guest are viewing this topic.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Really? Does _PRINTSTRING have lag issues? [SOLVED]
« on: October 19, 2021, 02:16:41 pm »
This is just for testing. I'm using _PRINTSTRING to write to a hardware overlay. Now in SCREEN 0, this type of letter printing works properly, but _PRINTSTRING seems to have lag, which throws off the timer.

If you try the code, you will need to hold down alt, and it will start printing the alphabet. The problem... what comes after J? O_ay, I'm just _idding. The problem is this: It should print each character with a .4 sec delay between characters. On my machine, it seems to lag around "M" "N" or "P" and then some buffer effect causes it to print two letters together. Now if you use this to print one letter over the other, instead of in a line, that makes it appear like it misses a letter. In other words A-M appears one letter at a time, but N and O get buffered together, so the user sees O as the next letter, instead of N. This is why, for this example, I put the display in a line, so you could see the lag/buffering issue more clearly. Do a REPLACE: [nxt + i] to: [nxt] if you want to see the letters print over themselves.

So, is there a way around this lag issue? 

Code: QB64: [Select]
  1. Screen0 = _NEWIMAGE(80, 25, 0)
  2. SCREEN Screen0
  3. swidth = _WIDTH
  4.  
  5. DIM SHARED Overlay
  6.  
  7. DIM SHARED lmargin%, rmargin%, topmargin%, screenwidth%, level, ibk, ileadingrow
  8. DIM SHARED irow, icol, inextrnd, imaxalienmissiles, alienforce%, ileadingmax, imaxalienforce, ihits, score$
  9.  
  10.  
  11.  
  12. _DEST Overlay
  13.  
  14. font = _LOADFONT("lucon.ttf", 20, "monospace")
  15. IF font <= 0 THEN font = 16
  16. _FONT font
  17.  
  18. bxy% = 3.5
  19. bxx% = 13 '27
  20. COLOR DarkOrange, 0
  21. t$ = " " + CHR$(218) + STRING$(27, CHR$(196)) + CHR$(191) + " "
  22. PSL bxy%, bxx% - 1, t$
  23. FOR i = 1 TO 11
  24.     t$ = " " + CHR$(179) + STRING$(27, CHR$(32)) + CHR$(179) + " "
  25.     PSL bxy% + i, bxx% - 1, t$
  26. t$ = " " + CHR$(192) + STRING$(27, CHR$(196)) + CHR$(217) + " "
  27. PSL bxy% + i, bxx% - 1, t$
  28.  
  29. COLOR Black, DarkOrange
  30. t$ = "    NAME   SCORE    DATE   "
  31. PSL bxy% + 1, bxx% + 1, t$
  32.  
  33. COLOR DarkOrange, 0
  34. FOR i = 1 TO 5
  35.     t$ = hsdata$(i)
  36.     PSL bxy% + 1 + i * 2, bxx% + 1, t$
  37.  
  38.  
  39. DEF SEG = 0
  40. initials$ = "": delay = .4
  41. i = 0
  42. bar$ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + CHR$(27) + CHR$(27) + CHR$(27)
  43. lscr = 14
  44.     IF PEEK(1047) MOD 16 = 7 OR PEEK(1047) MOD 16 = 8 THEN
  45.         DO
  46.             i = i + 1
  47.             COLOR , Black: t$ = " "
  48.             PSL 6 + rank * 2, lscr + nxt, t$
  49.             IF MID$(bar$, i, 1) = CHR$(27) AND LEN(initials$) = 0 THEN i = 1 ' No go back symbol shown on first initial.
  50.             IF i > LEN(bar$) THEN i = 1
  51.             COLOR DarkOrange: t$ = MID$(bar$, i, 1)
  52.             PSL 6 + rank * 2, lscr + nxt + i, t$
  53.             z1 = TIMER
  54.             IF LEN(initials$) = 3 THEN
  55.                 bar$ = CHR$(27) + CHR$(26) + CHR$(26) + CHR$(26) + CHR$(27)
  56.             END IF
  57.             DO UNTIL ABS(TIMER - z1) > delay
  58.                 IF PEEK(1047) MOD 16 <> 7 AND PEEK(1047) MOD 16 <> 8 THEN
  59.                     IF MID$(bar$, i, 1) = CHR$(26) THEN
  60.                         ''''''''PRINT " ";
  61.                         COLOR , Black: t$ = " "
  62.                         PSL 6 + rank * 2, lscr + nxt, t$
  63.                         COLOR DarkOrange
  64.                         flag = -999
  65.                         EXIT DO
  66.                     END IF
  67.                     IF MID$(bar$, i, 1) = CHR$(27) THEN
  68.                         IF LEN(initials$) THEN
  69.                             i = ASC(RIGHT$(initials$, 1)) - 66: IF i < 0 THEN i = 0
  70.                             initials$ = MID$(initials$, 1, LEN(initials$) - 1)
  71.                             COLOR , Black: t$ = " "
  72.                             PSL 6 + rank * 2, lscr + nxt, t$
  73.                             COLOR DarkOrange
  74.                             nxt = nxt - 1
  75.  
  76.                             flag = -2
  77.                         END IF
  78.                     ELSE
  79.                         initials$ = initials$ + MID$(bar$, i, 1)
  80.                         bar$ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + CHR$(27) + CHR$(27) + CHR$(27)
  81.                         i = 26
  82.                         flag = -1
  83.                     END IF
  84.                     EXIT DO
  85.                 END IF
  86.             LOOP
  87.             IF flag THEN EXIT DO
  88.         LOOP
  89.         IF flag = -999 THEN flag = 0: EXIT DO
  90.         IF flag <> -2 THEN
  91.             IF MID$(bar$, i, 1) <> CHR$(27) THEN nxt = nxt + 1 ELSE i = 0
  92.         END IF
  93.     ELSE
  94.         _DELAY .5
  95.     END IF
  96.     flag = 0
  97.  
  98. SUB PSL (y, x, t$)
  99.     _PRINTSTRING ((x - 1) * _FONTWIDTH, (y - 1) * _FONTHEIGHT), t$
  100.     Overlay_Hardware = _COPYIMAGE(Overlay, 33)
  101.  
  102.     _PUTIMAGE (0, 0), Overlay_Hardware
  103.     _DISPLAY
  104.  
  105.  

Pete

EDIT SOLVED!

Code: QB64: [Select]
  1. Screen0 = _NEWIMAGE(80, 25, 0)
  2. SCREEN Screen0
  3. swidth = _WIDTH
  4.  
  5. DIM SHARED Overlay
  6.  
  7. DIM SHARED lmargin%, rmargin%, topmargin%, screenwidth%, level, ibk, ileadingrow
  8. DIM SHARED irow, icol, inextrnd, imaxalienmissiles, alienforce%, ileadingmax, imaxalienforce, ihits, score$
  9.  
  10.  
  11.  
  12. _DEST Overlay
  13.  
  14. font = _LOADFONT("lucon.ttf", 20, "monospace")
  15. IF font <= 0 THEN font = 16
  16. _FONT font
  17.  
  18. bxy% = 3.5
  19. bxx% = 13 '27
  20. COLOR DarkOrange, 0
  21. t$ = " " + CHR$(218) + STRING$(27, CHR$(196)) + CHR$(191) + " "
  22. PSL bxy%, bxx% - 1, t$
  23. FOR i = 1 TO 11
  24.     t$ = " " + CHR$(179) + STRING$(27, CHR$(32)) + CHR$(179) + " "
  25.     PSL bxy% + i, bxx% - 1, t$
  26. t$ = " " + CHR$(192) + STRING$(27, CHR$(196)) + CHR$(217) + " "
  27. PSL bxy% + i, bxx% - 1, t$
  28.  
  29. COLOR Black, DarkOrange
  30. t$ = "    NAME   SCORE    DATE   "
  31. PSL bxy% + 1, bxx% + 1, t$
  32.  
  33. COLOR DarkOrange, 0
  34. FOR i = 1 TO 5
  35.     t$ = hsdata$(i)
  36.     PSL bxy% + 1 + i * 2, bxx% + 1, t$
  37.  
  38.  
  39. DEF SEG = 0
  40. initials$ = "": delay = .4
  41. i = 0
  42. bar$ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + CHR$(27) + CHR$(27) + CHR$(27)
  43. lscr = 14
  44.     IF PEEK(1047) MOD 16 = 7 OR PEEK(1047) MOD 16 = 8 THEN
  45.         DO
  46.             i = i + 1
  47.             COLOR , Black: t$ = " "
  48.             PSL 6 + rank * 2, lscr + nxt, t$
  49.             IF MID$(bar$, i, 1) = CHR$(27) AND LEN(initials$) = 0 THEN i = 1 ' No go back symbol shown on first initial.
  50.             IF i > LEN(bar$) THEN i = 1
  51.             COLOR DarkOrange: t$ = MID$(bar$, i, 1)
  52.             PSL 6 + rank * 2, lscr + nxt + i, t$
  53.             z1 = TIMER
  54.             IF LEN(initials$) = 3 THEN
  55.                 bar$ = CHR$(27) + CHR$(26) + CHR$(26) + CHR$(26) + CHR$(27)
  56.             END IF
  57.             _DISPLAY ' <-------------------------Moved it here from the sub.
  58.             DO UNTIL ABS(TIMER - z1) > delay
  59.                 IF PEEK(1047) MOD 16 <> 7 AND PEEK(1047) MOD 16 <> 8 THEN
  60.                     IF MID$(bar$, i, 1) = CHR$(26) THEN
  61.                         ''''''''PRINT " ";
  62.                         COLOR , Black: t$ = " "
  63.                         PSL 6 + rank * 2, lscr + nxt, t$
  64.                         COLOR DarkOrange
  65.                         flag = -999
  66.                         EXIT DO
  67.                     END IF
  68.                     IF MID$(bar$, i, 1) = CHR$(27) THEN
  69.                         IF LEN(initials$) THEN
  70.                             i = ASC(RIGHT$(initials$, 1)) - 66: IF i < 0 THEN i = 0
  71.                             initials$ = MID$(initials$, 1, LEN(initials$) - 1)
  72.                             COLOR , Black: t$ = " "
  73.                             PSL 6 + rank * 2, lscr + nxt, t$
  74.                             COLOR DarkOrange
  75.                             nxt = nxt - 1
  76.  
  77.                             flag = -2
  78.                         END IF
  79.                     ELSE
  80.                         initials$ = initials$ + MID$(bar$, i, 1)
  81.                         bar$ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + CHR$(27) + CHR$(27) + CHR$(27)
  82.                         i = 26
  83.                         flag = -1
  84.                     END IF
  85.                     EXIT DO
  86.                 END IF
  87.             LOOP
  88.             IF flag THEN EXIT DO
  89.         LOOP
  90.  
  91.         IF flag = -999 THEN flag = 0: EXIT DO
  92.         IF flag <> -2 THEN
  93.             IF MID$(bar$, i, 1) <> CHR$(27) THEN nxt = nxt + 1 ELSE i = 0
  94.         END IF
  95.     ELSE
  96.         _DELAY .5
  97.     END IF
  98.     flag = 0
  99.  
  100. SUB PSL (y, x, t$)
  101.     _PRINTSTRING ((x - 1) * _FONTWIDTH, (y - 1) * _FONTHEIGHT), t$
  102.     Overlay_Hardware = _COPYIMAGE(Overlay, 33)
  103.  
  104.     _PUTIMAGE (0, 0), Overlay_Hardware
  105.  
  106.     ' --------------> Moved this out of sub and into main: _DISPLAY
  107.  

I had to move the _DISPLAY out of the sub, for some reason I still haven't figured out. I just took a shot at it. Bullet casings everywhere!

Edit: Well moving did cut the number of _DISPLAY calls in half, if that was the issue. Now it prints the blank space and then the next letter before it cycles to _DISPLAY again. Before, it printed the blank character, displayed it, and then the next character, and displayed it. Weird. Graphics stuff is just weird. SCREEN 0 up Mr. Sulu, and phasers on _FULLSCREEN.

Pete out
« Last Edit: October 19, 2021, 02:53:52 pm by Pete »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Really? Does _PRINTSTRING have lag issues? [SOLVED]
« Reply #1 on: October 19, 2021, 03:48:29 pm »
_DISPLAY turns off the autodisplay which updates your screen automagically.  Once you call it, you'll either need to call _DISPLAY again to update the screen, or else you'll need to turn _AUTODISPLAY back on.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Really? Does _PRINTSTRING have lag issues? [SOLVED]
« Reply #2 on: October 19, 2021, 08:19:19 pm »
@SMcNeill  Well I think I've got it worked into the previous routine. I like the effect. It's a keeper.

Strange it's  bit of trial and error with matching colors using OUT vs _RGB() It seems like...

            OUT &H3C9, 6
            OUT &H3C9, 6
            OUT &H3C9, 6

Perfect choice for Halloween, right? matched RGB(24, 24, 24)

Code has file creation disabled. No file will be created if used as is.

Oh, if anyone trying this has not tried the ASCII Invaders game in the "Competition" thread, you enter your initials using just the Alt key. Hold it down to file through letters. Release it when your letter comes up. Wait for the arrow back symbol to appear, after "Z" to go back and redo. After the 3rd initial is input, hold the Alt key down again. You will have the choice of arrow back to correct, and arrow forward. Release Alt on the arrow forward symbol to finish.

Code: QB64: [Select]
  1. Screen0 = _NEWIMAGE(80, 25, 0)
  2. SCREEN Screen0
  3. swidth = _WIDTH
  4.  
  5. DIM SHARED Overlay
  6. REDIM SHARED hsdata$(6), highscore$(6)
  7. hsdata$(1) = "01  BBB  065000  10-19-21"
  8. hsdata$(2) = "02  CCC  053460  10-17-21"
  9. hsdata$(3) = "03  DDD  045700  10-17-21"
  10. hsdata$(4) = "04  EEE  034780  10-16-21"
  11. hsdata$(5) = "05  FFF  025890  10-12-21"
  12. FOR i = 1 TO 5
  13.     highscore$(i) = MID$(hsdata$(i), 10, 6)
  14.  
  15. DIM SHARED intro%: intro% = -1
  16.  
  17. skip_intro:
  18. DIM SHARED lmargin%, rmargin%, topmargin%, screenwidth%, level, ibk, ileadingrow
  19. DIM SHARED irow, icol, inextrnd, imaxalienmissiles, alienforce%, ileadingmax, imaxalienforce, ihits, score$
  20.  
  21.  
  22. score$ = "069000"
  23. imaxalienforce = 6
  24. imaxalienmissiles = 3
  25. lmargin% = 2
  26. rmargin% = 79
  27. topmargin% = 3
  28. ialiencolstat = 6
  29. iwin = 3 ' 3 Levels.
  30. screenwidth% = rmargin% - lmargin% + 1
  31. ibk = 0 ' Background color
  32.  
  33. REM Make aliens
  34. a1$ = "^^" + CHR$(79) + "^^  "
  35. a$ = a1$ + a1$ + a1$ + a1$ + a1$ + a1$ + a1$ + a1$ + a1$ + a1$
  36. alt1$ = "--" + CHR$(79) + "--  "
  37. a$ = a1$ + alt1$ + a1$ + alt1$ + a1$ + alt1$ + a1$ + alt1$ + a1$ + alt1$
  38. alt$ = alt1$ + a1$ + alt1$ + a1$ + alt1$ + a1$ + alt1$ + a1$ + alt1$ + a1$
  39.  
  40. DIM SHARED a(imaxalienforce) AS STRING * 68
  41.  
  42. CALL qbide
  43.  
  44. COLOR 8, 0
  45. ialiencol = ialiencolstat
  46. LOCATE 5, ialiencol
  47. FOR i = 1 TO imaxalienforce
  48.     IF i MOD 1 = 0 THEN PRINT
  49.     LOCATE , ialiencol
  50.     IF i = imaxalienforce THEN
  51.         ileadingrow = CSRLIN: ileadingmax = ileadingrow
  52.     END IF
  53.     IF i \ 2 = i / 2 THEN a(i) = a$ ELSE a(i) = alt$
  54.     PRINT a(i)
  55.  
  56. CALL displayhighscores
  57.  
  58. WHILE LEN(INKEY$): WEND ' Clear keyboard buffer in case user pressed a key during program run.
  59. a$ = INPUT$(1)
  60.  
  61. SUB PSLC (y, x, t$)
  62.     _PRINTSTRING ((x - 1), (y - 1) * _FONTHEIGHT), t$
  63.  
  64. SUB PSL (y, x, t$)
  65.     _PRINTSTRING ((x - 1) * _FONTWIDTH, (y - 1) * _FONTHEIGHT), t$
  66.     Overlay_Hardware = _COPYIMAGE(Overlay, 33)
  67.     _PUTIMAGE (0, 0), Overlay_Hardware
  68.  
  69. SUB underline (y, x)
  70.     STATIC ucnt
  71.     ucnt = -ucnt - 1
  72.     IF ucnt THEN COLOR DarkOrange, _RGB(24, 24, 24): t$ = "_" ELSE COLOR , _RGB(24, 24, 24): t$ = " "
  73.     _PRINTSTRING ((x - 1) * _FONTWIDTH, (y - 1) * _FONTHEIGHT + 4), t$
  74.     Overlay_Hardware = _COPYIMAGE(Overlay, 33)
  75.     _PUTIMAGE (0, 0), Overlay_Hardware
  76.     IF unct = 0 THEN COLOR DarkOrange
  77.  
  78. SUB qbide
  79.     PALETTE 2, 59
  80.     COLOR 15, 0
  81.     CLS
  82.  
  83.     COLOR 0, 7
  84.     LOCATE 1, 1
  85.     PRINT SPACE$(80)
  86.     LOCATE 1, 1: PRINT "   File  Edit  View  Search  Run  Debug  Calls  Options                   Help"
  87.  
  88.     COLOR 7, 0 ' Black background.
  89.  
  90.     LOCATE 2, 1: PRINT CHR$(218)
  91.     LOCATE 2, 2: PRINT STRING$(78, CHR$(196))
  92.     LOCATE 2, 80: PRINT CHR$(191)
  93.  
  94.     LOCATE 2, 76: PRINT CHR$(180)
  95.     LOCATE 2, 78: PRINT CHR$(195)
  96.  
  97.     COLOR 0, 7
  98.     LOCATE 2, 77: PRINT CHR$(24)
  99.     LOCATE 2, 36: PRINT " Untitled "
  100.  
  101.     COLOR 7, 0
  102.     FOR Rows = 3 TO 24
  103.         LOCATE Rows, 1: PRINT CHR$(179);
  104.         LOCATE Rows, 80: PRINT CHR$(179);
  105.     NEXT Rows
  106.  
  107.     COLOR 0, 3: LOCATE 25, 1: PRINT " <Shift+F1=Help> <F6=Window> <F2=Subs> <F5=Run> <F8=Step> ";
  108.     LOCATE 25, 59: PRINT SPACE$(4);
  109.     COLOR 0, 3
  110.     LOCATE 25, 63: PRINT CHR$(179);
  111.     LOCATE 25, 64: PRINT SPACE$(6);
  112.     LOCATE 25, 68: PRINT "C  00001:001 ";
  113.  
  114.  
  115. SUB displayhighscores
  116.  
  117.     COLOR 0, 3
  118.     LOCATE 25, 68: PRINT "Score "; score$;
  119.  
  120.     DIM hs AS STRING * 25
  121.     ''''''''''''''REDIM highscore$(6), hsdata$(6)
  122.     DO
  123.         IF _FILEEXISTS("ascii-invaders-high-score.dat") THEN
  124.             '''OPEN "ascii-invaders-high-score.dat" FOR RANDOM AS #1 LEN = 25
  125.             '''FOR i = 1 TO 5
  126.             '''  GET #1, i, hs
  127.             '''highscore$(i) = MID$(hs, 10, 6): hsdata$(i) = hs
  128.             '''NEXT
  129.             '''CLOSE #1
  130.         ELSE
  131.             '''FOR i = 1 TO 5
  132.             ''' hsdata$(i) = SPACE$(25)
  133.             '''NEXT
  134.         END IF
  135.  
  136.         IF VAL(score$) > VAL(highscore$(5)) THEN
  137.  
  138.             IF VAL(score$) > VAL(highscore$(1)) THEN
  139.                 msg$ = " <<< HIGH SCORE / Enter Your Initials >>> "
  140.             ELSE
  141.                 msg$ = " <<< Top 5 Score. Enter Your Initials >>> "
  142.             END IF
  143.  
  144.             GOSUB hiscore
  145.  
  146.             a = 14
  147.             OUT &H3C8, 0
  148.             OUT &H3C9, 20 - a
  149.             OUT &H3C9, 20 - a
  150.             OUT &H3C9, 20 - a
  151.  
  152.             OUT &H3C8, 8
  153.             OUT &H3C9, 30 - a
  154.             OUT &H3C9, 30 - a
  155.             OUT &H3C9, 30 - a
  156.  
  157.             OUT &H3C8, 7
  158.             OUT &H3C9, 30 - a
  159.             OUT &H3C9, 30 - a
  160.             OUT &H3C9, 30 - a
  161.  
  162.             OUT &H3C8, 3
  163.             OUT &H3C9, 30 - a
  164.             OUT &H3C9, 30 - a
  165.             OUT &H3C9, 30 - a
  166.  
  167.             _DELAY .5
  168.  
  169.             '''''''''PRINT VAL(score$), VAL(highscore$(1)), highscore$(1): END '''''''''''''
  170.             COLOR 6, 0
  171.             LOCATE 4, 41 - LEN(msg$) \ 2
  172.             PRINT msg$;
  173.  
  174.             LOCATE 4, 41 - LEN(msg$) \ 2
  175.             COLOR 6 + 16, 0
  176.             PRINT msg$;
  177.             _DELAY 2
  178.             COLOR 6, 0
  179.             LOCATE 4, 41 - LEN(msg$) \ 2
  180.             PRINT msg$;
  181.  
  182.             GOSUB hardware_overlay
  183.  
  184.             DEF SEG = 0
  185.             initials$ = "": delay = .33
  186.             i = 0
  187.             bar$ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + CHR$(27) + CHR$(27)
  188.             lscr = 19
  189.             DO
  190.                 _LIMIT 60
  191.                 IF PEEK(1047) MOD 16 = 7 OR PEEK(1047) MOD 16 = 8 THEN
  192.                     DO
  193.                         _LIMIT 60
  194.                         i = i + 1
  195.                         underline 5 + rank * 2, lscr + nxt
  196.                         COLOR , _RGB(24, 24, 24): t$ = " "
  197.                         PSL 5 + rank * 2, lscr + nxt, t$
  198.                         IF MID$(bar$, i, 1) = CHR$(27) AND LEN(initials$) = 0 THEN i = 1 ' No go back symbol shown on first initial.
  199.                         IF i > LEN(bar$) THEN i = 1 ' loop.
  200.                         COLOR DarkOrange: t$ = MID$(bar$, i, 1)
  201.                         PSL 5 + rank * 2, lscr + nxt, t$
  202.                         z1 = TIMER
  203.                         IF LEN(initials$) = 3 THEN
  204.                             bar$ = CHR$(27) + CHR$(26) + CHR$(26) + CHR$(26) + CHR$(27)
  205.                         ELSE
  206.                             bar$ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + CHR$(27) + CHR$(27)
  207.                         END IF
  208.                         _DISPLAY ' <-------------------------Moved it here from the sub.
  209.                         DO UNTIL ABS(TIMER - z1) > delay
  210.                             IF PEEK(1047) MOD 16 <> 7 AND PEEK(1047) MOD 16 <> 8 THEN
  211.                                 IF MID$(bar$, i, 1) = CHR$(26) THEN
  212.                                     COLOR , _RGB(24, 24, 24): t$ = " "
  213.                                     PSL 5 + rank * 2, lscr + nxt, t$
  214.                                     COLOR DarkOrange
  215.                                     flag = -999
  216.                                     EXIT DO
  217.                                 END IF
  218.                                 IF MID$(bar$, i, 1) = CHR$(27) THEN
  219.                                     IF LEN(initials$) THEN
  220.                                         i = ASC(RIGHT$(initials$, 1)) - 66: IF i < 0 THEN i = 0
  221.                                         initials$ = MID$(initials$, 1, LEN(initials$) - 1)
  222.                                         nxt = nxt - 1
  223.                                         COLOR , _RGB(24, 24, 24): t$ = "  "
  224.                                         PSL 5 + rank * 2, lscr + nxt, t$
  225.                                         COLOR DarkOrange
  226.                                         flag = -2
  227.                                     END IF
  228.                                 ELSE
  229.                                     initials$ = initials$ + MID$(bar$, i, 1)
  230.                                     nxt = nxt + 1
  231.                                     i = 26
  232.                                     flag = -1
  233.                                 END IF
  234.                                 EXIT DO
  235.                             END IF
  236.                         LOOP
  237.                         IF flag THEN EXIT DO
  238.                     LOOP
  239.  
  240.                     IF flag = -999 THEN flag = 0: EXIT DO
  241.                     IF flag <> -2 THEN
  242.                         IF MID$(bar$, i, 1) = CHR$(27) THEN i = 0
  243.                     END IF
  244.                 ELSE
  245.                     underline 5 + rank * 2, lscr + nxt
  246.                     _DISPLAY
  247.                     _DELAY .2
  248.                 END IF
  249.                 flag = 0
  250.                 COLOR _RGB(24, 24, 24), 0: t$ = "____"
  251.                 _PRINTSTRING ((lscr - 1) * _FONTWIDTH, (5 + rank * 2 - 1) * _FONTHEIGHT + 4), t$
  252.                 Overlay_Hardware = _COPYIMAGE(Overlay, 33)
  253.                 _PUTIMAGE (0, 0), Overlay_Hardware
  254.                 _DISPLAY
  255.                 COLOR DarkOrange
  256.             LOOP
  257.             DEF SEG
  258.  
  259.             hsname$ = initials$
  260.  
  261.             MID$(hsdata$(rank), 5, 3) = hsname$ + SPACE$(3 - LEN(hsname$))
  262.             OPEN "ascii-invaders-high-score.dat" FOR RANDOM AS #1 LEN = 25
  263.             FOR i = 1 TO 5
  264.                 hs = hsdata$(i)
  265.                 IF LEFT$(hs, 1) = "" THEN MID$(hs, 1, 2) = "0" + LTRIM$(STR$(i))
  266.                 PUT #1, i, hs
  267.             NEXT
  268.             CLOSE #1
  269.  
  270.             SOUND 700, .3: _DELAY .2: SOUND 1100, .3: _DELAY .2: SOUND 1400, .3
  271.             _DELAY 1
  272.             _DISPLAY ' Remove scoreboard.
  273.             _DELAY 1
  274.             _FREEIMAGE Overlay
  275.             _FONT 16 'select inbuilt 8x16 default font
  276.             _FREEFONT font
  277.  
  278.             _DEST 0 'Reset dest back to the normal screen 0.
  279.  
  280.             _AUTODISPLAY
  281.             COLOR 6, 0
  282.             msg$ = SPACE$(40)
  283.             LOCATE 4, 41 - LEN(msg$) \ 2
  284.             PRINT msg$;
  285.             _DELAY 1
  286.  
  287.             EXIT DO
  288.         ELSE
  289.             EXIT DO ' Not in the top 5 highest scores so exit sub.
  290.         END IF
  291.     LOOP
  292.     EXIT SUB
  293.  
  294.     hardware_overlay:
  295.     Overlay = _NEWIMAGE(_WIDTH * _FONTWIDTH, _HEIGHT * _FONTHEIGHT, 32)
  296.  
  297.     _DEST Overlay
  298.     _DISPLAY ' Turn autodisplay off.
  299.  
  300.     font = _LOADFONT("lucon.ttf", 20, "monospace")
  301.     IF font <= 0 THEN font = 16
  302.     _FONT font
  303.  
  304.     bxy% = 4
  305.     bxx% = 13
  306.     COLOR DarkOrange, 0
  307.     t$ = " " + CHR$(218) + STRING$(27, CHR$(196)) + CHR$(191) + " "
  308.     PSL bxy%, bxx% - 1, t$
  309.     FOR i = 1 TO 11
  310.         t$ = " " + CHR$(179) + STRING$(27, CHR$(32)) + CHR$(179) + " "
  311.         PSL bxy% + i, bxx% - 1, t$
  312.     NEXT
  313.     t$ = " " + CHR$(192) + STRING$(27, CHR$(196)) + CHR$(217) + " "
  314.     PSL bxy% + i, bxx% - 1, t$
  315.  
  316.     COLOR 0, DarkOrange
  317.     t$ = "    NAME   SCORE    DATE   "
  318.     PSL bxy% + 1, bxx% + 1, t$
  319.  
  320.     COLOR DarkOrange, 0
  321.     FOR i = 1 TO 5
  322.         t$ = hsdata$(i)
  323.         PSL bxy% + 1 + i * 2, bxx% + 2, t$
  324.     NEXT
  325.  
  326.     _DISPLAY
  327.  
  328.     RETURN
  329.  
  330.     hiscore:
  331.     FOR i = 1 TO 5
  332.         IF VAL(score$) > VAL(highscore$(i)) THEN rank = i: EXIT FOR
  333.     NEXT
  334.  
  335.     hsdata$(6) = SPACE$(25)
  336.     MID$(hsdata$(6), 10, 6) = score$
  337.     MID$(hsdata$(6), 18, 8) = MID$(DATE$, 1, 6) + MID$(DATE$, 9, 2)
  338.     highscore$(6) = score$
  339.     FOR i = 1 TO 6
  340.         FOR j = 1 TO 6
  341.             IF i <> j THEN
  342.                 IF VAL(highscore$(i)) > VAL(highscore$(j)) THEN
  343.                     SWAP highscore$(i), highscore$(j)
  344.                     SWAP hsdata$(i), hsdata$(j)
  345.                 END IF
  346.             END IF
  347.         NEXT
  348.     NEXT
  349.     FOR i = 1 TO 5
  350.         MID$(hsdata$(i), 1, 2) = "0" + LTRIM$(STR$(i))
  351.     NEXT
  352.  
  353.     RETURN
  354.  
  355.  

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Really? Does _PRINTSTRING have lag issues? [SOLVED]
« Reply #3 on: October 19, 2021, 09:35:19 pm »
Use _PALETTECOLOR.  Much easier than the old caveman way and it works with _RGB automatically.

_PALETTECOLOR 14, _RGB32(255, 128, 64)

or use _RGBA32 if you want to include alpha channels.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

FellippeHeitor

  • Guest
Re: Really? Does _PRINTSTRING have lag issues? [SOLVED]
« Reply #4 on: October 19, 2021, 09:50:29 pm »
_RGB32 can take an extra fourth alpha parameter too. _RGBA32 remains for retrocompatibility, but it became unnecessary with v1.3 I think.

Also:

1 parameter: _RGB32(255) is the same as _RGB32(255, 255, 255)

2 parameters: _RGB32(255, 30) is the same as _RGB32(255, 255, 255, 30)

3 parameters is the default RGB setting.

4 parameters is RGBA.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Really? Does _PRINTSTRING have lag issues? [SOLVED]
« Reply #5 on: October 19, 2021, 10:15:38 pm »
Are you guys trying to make my head explode? If so, you'll have to come over and clean up the mess. And Steve says... No worries, I'll bring the half-a-napkin and Fell can bring the dust pan.

Kidding aside, it's pretty amazing how much the coding slows to a crawl when one is not familiar with just a half a dozen statements. It just isn't at that intuitive point yet; but I've always credited BASIC with being the most intuitive language available; so, this old goat will chew through it and have it digested before he kicks the can. Farm references provided so Steve will find my reply more intuitive.

Thanks guys! 🤯

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/