Confusing Chr$ explanation
#22
(07-09-2023, 04:22 AM)PhilOfPerth Wrote: I'm able to see characters for all the Alt values, but I'm unable to produce the Copyright (and some others). The Alt table says it should be Alt 0169,
but Alt + 0169 only produces the ┌ symbol (or something very similar).
When I enter  Alt + 0169  here, on the Forum, I get the © ok. Why not in my program?
The copyright character does not exist in the DOS ASCII character set of code page 437.

All characters from 128 to 255 are different characters than what you have in Windows + those of other countries.

e.g.:
Code page 437 = English https://de.wikipedia.org/wiki/Codepage_437
Character 169 / &HA9
MS DOS characters: ⌐
MS WIN Character: ©

Code page 850 = Western European https://de.wikipedia.org/wiki/Codepage_850
Character 169 / &HA9
MS DOS characters: ®
MS WIN Character: ©

You must use a Unicode set for that.

Create the following file
CP850.CSV
Code: (Select All)
' Microsoft_pc_cp850
199,252,233,226,228,224,229,231,234,235,232,239,238,236,196,197
201,230,198,244,246,242,251,249,255,214,220,248,163,216,215,402
225,237,243,250,241,209,170,186,191,174,172,189,188,161,171,187
9617,9618,9619,9474,9508,193,194,192,169,9571,9553,9559,9565,162,165,9488
9492,9524,9516,9500,9472,9532,227,195,9562,9556,9577,9574,9568,9552,9580,164
240,208,202,203,200,**305**,205,206,207,9496,9484,9608,9604,166,204,9600
211,223,212,210,245,213,181,254,222,218,219,217,253,221,175,180
173,177,8215,190,182,167,247,184,176,168,183,185,179,178,9632,160

The character numbered 305 in the table (which is bracketed with asterisks) is the euro character. Simply remove the stars to have the euro sign in the set.

Then you can use the following in QB64:
Code: (Select All)

SCREEN 0
_FONT _LOADFONT("C:\Windows\Fonts\Cour.ttf", 20, "MONOSPACE") 'select monospace font
FileName$ = "CP850.CSV" '              <<<<<<< Enter Unicode CSV data text file name you created here!**
f = FREEFILE
OPEN FileName$ FOR INPUT AS #f
INPUT #f, CodePage$ '                  read code page ID on first line of file
IF NOT EOF(f) THEN PRINT CodePage$ '    display code page number

FOR ascii = 128 TO 255 '                assign unicode values to ascii 128 to 255 only
  IF EOF(f) THEN EXIT FOR
  INPUT #f, unicode&
  IF unicode& = 0 THEN unicode& = 9744 'make undefined characters look like a box
  _MAPUNICODE unicode& TO ascii '      replace ascii with unicode value
NEXT
CLOSE #f

FOR code = 128 TO 255
  PRINT code; CHR$(code); '            display unicode characters
NEXT

END

And this would be your output:
Character 169 is now ®
[Image: cp850h7dyd.png]

Here a QB64 code for the complete table

Code: (Select All)
' instructs the compiler to require variable declaration
OPTION _EXPLICIT

' Control function off to set all characters
_CONTROLCHR OFF

' dimension variables
DIM winX AS _UNSIGNED INTEGER
DIM winY AS _UNSIGNED INTEGER
DIM i AS _UNSIGNED _BYTE
DIM x AS _UNSIGNED _BYTE
DIM y AS _UNSIGNED _BYTE
DIM selx AS _UNSIGNED _BYTE
DIM sely AS _UNSIGNED _BYTE
DIM keyin AS STRING

' variables for codepages
DIM Filename AS STRING
DIM CodePage AS STRING
DIM ASCII AS _UNSIGNED _BYTE
DIM UNICODE AS _UNSIGNED LONG
DIM F AS _UNSIGNED _BYTE

' Load codepage 850 from UNICODE
_FONT _LOADFONT("C:\Windows\Fonts\Cour.ttf", 20, "MONOSPACE") 'select monospace font
Filename = "CP850.CSV" '              <<<<<<< Enter Unicode CSV data text file name you created here!**
F = FREEFILE
OPEN Filename FOR INPUT AS #F
INPUT #F, CodePage '                  read code page ID on first line of file
IF NOT EOF(F) THEN PRINT CodePage '    display code page number

FOR ASCII = 128 TO 255 '                assign unicode values to ascii 128 to 255 only
  IF EOF(F) THEN EXIT FOR
  INPUT #F, UNICODE
  IF UNICODE = 0 THEN UNICODE = 9744 'make undefined characters look like a box
  _MAPUNICODE UNICODE TO ASCII '      replace ascii with unicode value
NEXT
CLOSE #F

' Create window area with colors
COLOR 4, 7
winX = 14
winY = 4
FOR y = winY + 0 TO winY + 16
  FOR x = winX + 0 TO winX + 16 * 3
    LOCATE y, x: PRINT SPACE$(2);
  NEXT x
NEXT y

' Create table info
FOR i = 0 TO 15
  LOCATE winY, winX + (i * 3) + 3: PRINT "0" + HEX$(i);
  LOCATE winY + i + 1, winX: PRINT HEX$(i) + "0";
NEXT i

' Create ASCII characters
' Init values for the table of ASCII chars
COLOR 0, 7
winX = winX + 1
winY = winY + 1

DO
  ' Output of all ASCII characters in the table
  x = 0
  y = winY
  FOR i = 0 TO 255
    IF selx = x AND sely = y - winY THEN COLOR 7, 2 ELSE COLOR 0, 7
    LOCATE y, winX + (x * 3) + 3: PRINT CHR$(i);
    x = x + 1
    IF x = 16 THEN
      x = 0
      y = y + 1
    END IF
  NEXT i

  ' Output of decimal and hex value of current char
  COLOR 0, 7
  LOCATE winY + 16, winX - 1: PRINT SPACE$(25);
  LOCATE winY + 16, winX - 1: PRINT "ASCII:  DEC(" + LTRIM$(STR$(sely * 16 + selx)) + ")  HEX(" + HEX$(sely * 16 + selx) + ")";

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

  ' Arrowkeys 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)

Output is this:
[Image: cp850_2s4fg9.png]


When you use the DOSBox you must change the keyboard + character set.
KEYB gr 850   <- It's for german keyboard layout + codepage 850

Then have the same result in the DOSBox with the characters:
[Image: qb_0053ofcm.png]

In both cases you then have your copyright char in the set.
Character 169 - ®
Character 184 - ©



If you are looking for a suitable DOS TrueType font on the Internet, you can also make the characters look original. (QB64)
e.g.: https://archive.org/details/ultimate_old..._pack_v1.0

The output then looks like this:
("PxPlus_IBM_VGA9.ttf", 16, "MONOSPACE")
[Image: cp850_31kdmi.png]
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: 7 Guest(s)