Confusing Chr$ explanation
#15
Here the QB4.5 equivalent of the QB64 code. (https://staging.qb64phoenix.com/showthre...6#pid17636)

This code is faster in DOS. Not in QB64.
In the DOS BOX is this code very fast.

Because the segment is not part of the native operating system in Windows 10 / 11.
Under Windows 10 / 11 is the QB64 code faster
Both examples are intended to show how characters and colors can be displayed at a specific position. And the interaction with the table itself should also be demonstrated in this way.

Both examples are intended for practice purposes.
And not to say that it already exists.  Rolleyes

Code: (Select All)
' Segment B800 is for text memory
' 1 Byte Char + 1 Byte Color (4 Bit Back- and 4 Bit Foreground)
DEF SEG = &HB800

' Screen Info for Screen 0
' max line  = 25
' max length = 80
' max colors = 16
' Screen Buffer =  25 * 80 = 2000
' + with colors = 2000 * 2 = 4000
DIM screenchar(1999) AS INTEGER
DIM screencol(1999) AS INTEGER

' dimension variables
DIM winx AS INTEGER
DIM winy AS INTEGER
DIM x AS INTEGER
DIM y AS INTEGER
DIM posi AS INTEGER
DIM keyin AS STRING

' Create window area with colors
winx = 14
winy = 4
FOR y = winy + 0 TO winy + 16
  FOR x = winx + 0 TO winx + 16 * 3
    screenchar(y * 80 + x) = &H20
    screencol(y * 80 + x) = &H70
  NEXT x
NEXT y

' Create table info
FOR i = 0 TO 15
  screenchar(winy * 80 + winx + (i * 3) + 2) = &H30
  screenchar(winy * 80 + winx + (i * 3) + 3) = ASC(HEX$(i))
  screencol(winy * 80 + winx + (i * 3) + 2) = &H74
  screencol(winy * 80 + winx + (i * 3) + 3) = &H74

  screenchar((winy + i + 1) * 80 + winx + 1) = &H30
  screenchar((winy + i + 1) * 80 + winx) = ASC(HEX$(i))
  screencol((winy + i + 1) * 80 + winx + 0) = &H74
  screencol((winy + i + 1) * 80 + winx + 1) = &H74
NEXT i

' Create ASCII characters
winx = winx + 1
winy = winy + 1
x = 0
y = winy
FOR i = 0 TO 255
  screenchar(y * 80 + (winx + (x * 3 + 2))) = i
  screencol(y * 80 + (winx + (x * 3 + 2))) = &H70
  x = x + 1
  IF x = 16 THEN
    x = 0
    y = y + 1
  END IF
NEXT i

' Draw all ASCII Chars in the table
FOR i = 0 TO 3999 STEP 2
  POKE i + 0, screenchar(i \ 2)
  POKE i + 1, screencol(i \ 2)
NEXT i

' Start of selectet character
posi = (winy + sely) * 80 + (winx + selx * 3)
screencol(posi) = &H27
POKE ((posi + 2) * 2) + 1, screencol(posi)

DO
  ' Color change by new position
  IF posi <> ((winy + sely) * 80 + (winx + selx * 3)) THEN
    ' Old position reset
    screencol(posi) = &H70
    POKE ((posi + 2) * 2) + 1, screencol(posi)

    ' New position set
    posi = (winy + sely) * 80 + (winx + selx * 3)
    screencol(posi) = &H27
    POKE ((posi + 2) * 2) + 1, screencol(posi)
  END IF
 
  ' Output of decimal and hex value of current char
  COLOR 0, 7
  LOCATE winy + 17, winx: PRINT SPACE$(25)
  LOCATE winy + 17, winx: PRINT "ASCII: DEC(" + LTRIM$(STR$(sely * 16 + selx)) + ") HEX(" + HEX$(sely * 16 + selx) + ")"

  ' Key Input
  DO
    keyin = INKEY$
  LOOP WHILE keyin = ""

  ' Arrow keys to select the current char
  IF keyin = CHR$(0) + CHR$(77) THEN IF selx >= 15 THEN selx = 0 ELSE selx = selx + 1
  IF keyin = CHR$(0) + CHR$(75) THEN IF selx <= 0 THEN selx = 15 ELSE selx = selx - 1
  IF keyin = CHR$(0) + CHR$(80) THEN IF sely >= 15 THEN sely = 0 ELSE sely = sely + 1
  IF keyin = CHR$(0) + CHR$(72) THEN IF sely <= 0 THEN sely = 15 ELSE sely = sely - 1

  ' ESC to end the program
LOOP WHILE keyin <> CHR$(27)
Reply


Messages In This Thread
Confusing Chr$ explanation - by PhilOfPerth - 07-07-2023, 01:18 AM
RE: Confusing Chr$ explanation - by CharlieJV - 07-07-2023, 01:31 AM
RE: Confusing Chr$ explanation - by PhilOfPerth - 07-07-2023, 01:49 AM
RE: Confusing Chr$ explanation - by Space_Ghost - 07-07-2023, 01:52 AM
RE: Confusing Chr$ explanation - by mnrvovrfc - 07-08-2023, 02:49 AM
RE: Confusing Chr$ explanation - by PhilOfPerth - 07-07-2023, 03:36 AM
RE: Confusing Chr$ explanation - by Space_Ghost - 07-07-2023, 04:52 AM
RE: Confusing Chr$ explanation - by PhilOfPerth - 07-07-2023, 05:39 AM
RE: Confusing Chr$ explanation - by Space_Ghost - 07-07-2023, 06:16 AM
RE: Confusing Chr$ explanation - by PhilOfPerth - 07-08-2023, 12:47 AM
RE: Confusing Chr$ explanation - by Space_Ghost - 07-08-2023, 01:14 AM
RE: Confusing Chr$ explanation - by SagaraS - 07-08-2023, 08:52 AM
RE: Confusing Chr$ explanation - by bplus - 07-08-2023, 02:05 PM
RE: Confusing Chr$ explanation - by Space_Ghost - 07-08-2023, 03:59 PM
RE: Confusing Chr$ explanation - by SagaraS - 07-08-2023, 07:35 PM
RE: Confusing Chr$ explanation - by TempodiBasic - 07-08-2023, 09:30 PM
RE: Confusing Chr$ explanation - by mnrvovrfc - 07-08-2023, 10:44 PM
RE: Confusing Chr$ explanation - by PhilOfPerth - 07-09-2023, 02:49 AM
RE: Confusing Chr$ explanation - by TempodiBasic - 07-09-2023, 03:10 PM
RE: Confusing Chr$ explanation - by PhilOfPerth - 07-09-2023, 04:22 AM
RE: Confusing Chr$ explanation - by Space_Ghost - 07-09-2023, 07:43 AM
RE: Confusing Chr$ explanation - by RhoSigma - 07-09-2023, 08:05 AM
RE: Confusing Chr$ explanation - by TempodiBasic - 07-09-2023, 03:48 PM
RE: Confusing Chr$ explanation - by PhilOfPerth - 07-10-2023, 01:29 AM
RE: Confusing Chr$ explanation - by SagaraS - 07-09-2023, 08:12 AM
RE: Confusing Chr$ explanation - by SagaraS - 07-09-2023, 11:50 AM
RE: Confusing Chr$ explanation - by TempodiBasic - 07-09-2023, 04:40 PM
RE: Confusing Chr$ explanation - by SagaraS - 07-10-2023, 11:23 AM
RE: Confusing Chr$ explanation - by mnrvovrfc - 07-10-2023, 03:34 PM
RE: Confusing Chr$ explanation - by mnrvovrfc - 07-11-2023, 04:17 PM
RE: Confusing Chr$ explanation - by PhilOfPerth - 07-12-2023, 06:03 AM
RE: Confusing Chr$ explanation - by SMcNeill - 07-16-2023, 11:00 PM
RE: Confusing Chr$ explanation - by SagaraS - 07-15-2023, 08:47 AM
RE: Confusing Chr$ explanation - by PhilOfPerth - 07-16-2023, 12:18 AM
RE: Confusing Chr$ explanation - by SagaraS - 07-16-2023, 10:31 AM
RE: Confusing Chr$ explanation - by mnrvovrfc - 07-16-2023, 05:06 PM
RE: Confusing Chr$ explanation - by bplus - 07-16-2023, 05:53 PM
RE: Confusing Chr$ explanation - by mnrvovrfc - 07-16-2023, 07:35 PM
RE: Confusing Chr$ explanation - by SagaraS - 07-16-2023, 08:24 PM
RE: Confusing Chr$ explanation - by PhilOfPerth - 07-16-2023, 11:24 PM
RE: Confusing Chr$ explanation - by SMcNeill - 07-16-2023, 11:42 PM
RE: Confusing Chr$ explanation - by PhilOfPerth - 07-17-2023, 01:10 AM
RE: Confusing Chr$ explanation - by bplus - 07-17-2023, 01:18 AM
RE: Confusing Chr$ explanation - by PhilOfPerth - 07-17-2023, 01:34 AM
RE: Confusing Chr$ explanation - by bplus - 07-17-2023, 01:41 AM
RE: Confusing Chr$ explanation - by PhilOfPerth - 07-17-2023, 01:49 AM
RE: Confusing Chr$ explanation - by bplus - 07-17-2023, 02:08 AM
RE: Confusing Chr$ explanation - by PhilOfPerth - 07-17-2023, 02:33 AM



Users browsing this thread: 20 Guest(s)