Recent

Author Topic: CRT won't show ascii characters properly  (Read 1791 times)

ShadowG04

  • Newbie
  • Posts: 4
CRT won't show ascii characters properly
« on: January 28, 2021, 09:52:36 pm »
So im trying to use box characters for my program, but since im using CRT the characters won't display in the correct codepage.

it appears that my system is using codepage 1252 but i did some research and i think that changing the codepage of the system on the regedit would mess up with my pc.

im testing my output using this code:

Code: Pascal  [Select][+][-]
  1. Program CodePage;
  2.  
  3. USES CRT;
  4.  
  5. BEGIN
  6.         Writeln('Console output codepage: ', GetTextCodePage(Output));
  7.         Writeln('System codepage: ', DefaultSystemCodePage);
  8.         System.SetTextCodePage(Output, 850);
  9.         Writeln('Console output codepage: ', GetTextCodePage(Output));
  10.         Writeln('System codepage: ', DefaultSystemCodePage);
  11.         WriteLN (char(186)); {║}
  12.         WriteLN (char(167)); {º}
  13.         WriteLN (char(245)); {§}
  14.         WriteLN (char(229)); {Õ}
  15.         WriteLN (char(134)); {å}
  16.         ReadLn();
  17. END.
  18.  

any ideas of what i could do to fix the output?

Bart

  • Hero Member
  • *****
  • Posts: 4469
    • Bart en Mariska's Webstek
Re: CRT won't show ascii characters properly
« Reply #1 on: January 28, 2021, 10:15:46 pm »
Characters above #127 are not ASCII.
Try setting the codepage of the console before running the program ("chcp 437", I think it is, without the quotes of course).

Bart

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1623
  • Former Delphi 1-7, 10.2 user
Re: CRT won't show ascii characters properly
« Reply #2 on: January 28, 2021, 11:10:57 pm »
The American Standards Association "X3.4-1963 - American Standard Code for Information Interchange" (ASCII) source document: https://web.archive.org/web/20150901201534/https://worldpowersystems.com/projects/codes/X3.4-1963/

The only source of ASCII truth.
Lazarus 2.3 + FPC 3.3.1 2021-10-19 macOS 10.14.6 Xcode 11.3.1
Lazarus 2.3 + FPC 3.3.1 2021-09-21 macOS 11.6 aarch64 Xcode 13
Lazarus 2.3 2021-08-11 FPC 3.2.2 FreeBSD 13.0 amd64 VMware VM
Lazarus 2.1 r61574 FPC 3.0.4 Ubuntu 20.04 Parallels VM
Lazarus 2.0.10 FPC 3.2.0 Win10 Parallels VM

ShadowG04

  • Newbie
  • Posts: 4
Re: CRT won't show ascii characters properly
« Reply #3 on: January 29, 2021, 07:45:05 am »
Characters above #127 are not ASCII.
Try setting the codepage of the console before running the program ("chcp 437", I think it is, without the quotes of course).

Bart

I changed the codepage from the console to all of the posible values and i still cant get box characters show up.

I found a page with this guy having the same problem as me
Quote
http://www.productionautomation.net/FPC/ASCII/
it appears is all because crt doesnt show properly those characters.

Looks like my options are either stop using crt or stop trying to use box characters on pascal

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: CRT won't show ascii characters properly
« Reply #4 on: January 29, 2021, 08:23:22 am »
I found a page with this guy having the same problem as me
Quote
http://www.productionautomation.net/FPC/ASCII/
it appears is all because crt doesnt show properly those characters.

It's not because crt but because the console itself can't show those characters, most probably due to either the font used or because the code-page can not be properly changed to IBM437 (the only one which has all box characters). Also FP might be making an internal conversion between the system and console codepages before the output which might be mangling it all, though I'm not entirely sure that's true...

In that page you cite the author forgot to make a simple test: compile and run his FP program under the same emulator (DOSBox) he did  the Turbo Pascal one: the result would demostrate the point that it's not really crt who's the culprit, I think.

You can make another simple test: use CP437 for the console and try with a full-screen rather than a windowed one. And, BTW, don't test from inside the IDE: open a console and launch the program.
« Last Edit: January 29, 2021, 08:26:41 am by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

FlierMate

  • Guest
Re: CRT won't show ascii characters properly
« Reply #5 on: January 29, 2021, 09:24:54 am »
Code: Pascal  [Select][+][-]
  1. Program CodePage;
  2.  
  3. {USES CRT;}
  4.  
  5. BEGIN
  6.         Writeln('Console output codepage: ', GetTextCodePage(Output));
  7.         Writeln('System codepage: ', DefaultSystemCodePage);
  8.         System.SetTextCodePage(Output, 65001);
  9.         Writeln('Console output codepage: ', GetTextCodePage(Output));
  10.         Writeln('System codepage: ', DefaultSystemCodePage);
  11.         WriteLN (widechar(#$250C)); {║}
  12.         WriteLN (widechar(#$2510)); {º}
  13.         WriteLN (widechar(#$2514)); {§}
  14.         WriteLN (widechar(#$2518)); {Õ}
  15.         WriteLN (widechar(#$252C)); {å}
  16.         ReadLn();
  17. END.
  18.  

I try to use Unicode character and set the code page to 65001. Then it works fine on my PC.

Not sure if this is the right way to do it.
« Last Edit: January 29, 2021, 09:37:11 am by FlierMate »

ASerge

  • Hero Member
  • *****
  • Posts: 1869
Re: CRT won't show ascii characters properly
« Reply #6 on: January 29, 2021, 03:26:31 pm »
I try to use Unicode character and set the code page to 65001. Then it works fine on my PC.
This work fine on my PC without chcp and SetTextCodePage:
Code: Pascal  [Select][+][-]
  1. {$APPTYPE CONSOLE}
  2. begin
  3.   Writeln(#$250C#$252C#$2510);
  4.   Writeln(#$2514#$2534#$2518);
  5.   Readln;
  6. end.

FlierMate

  • Guest
Re: CRT won't show ascii characters properly
« Reply #7 on: January 29, 2021, 03:32:22 pm »
I try to use Unicode character and set the code page to 65001. Then it works fine on my PC.
This work fine on my PC without chcp and SetTextCodePage:
Code: Pascal  [Select][+][-]
  1. {$APPTYPE CONSOLE}
  2. begin
  3.   Writeln(#$250C#$252C#$2510);
  4.   Writeln(#$2514#$2534#$2518);
  5.   Readln;
  6. end.

👍 Fantastic!

ShadowG04

  • Newbie
  • Posts: 4
Re: CRT won't show ascii characters properly
« Reply #8 on: January 29, 2021, 07:22:23 pm »
Code: Pascal  [Select][+][-]
  1. Program CodePage;
  2.  
  3. {USES CRT;}
  4.  
  5. BEGIN
  6.         Writeln('Console output codepage: ', GetTextCodePage(Output));
  7.         Writeln('System codepage: ', DefaultSystemCodePage);
  8.         System.SetTextCodePage(Output, 65001);
  9.         Writeln('Console output codepage: ', GetTextCodePage(Output));
  10.         Writeln('System codepage: ', DefaultSystemCodePage);
  11.         WriteLN (widechar(#$250C)); {║}
  12.         WriteLN (widechar(#$2510)); {º}
  13.         WriteLN (widechar(#$2514)); {§}
  14.         WriteLN (widechar(#$2518)); {Õ}
  15.         WriteLN (widechar(#$252C)); {å}
  16.         ReadLn();
  17. END.
  18.  

I try to use Unicode character and set the code page to 65001. Then it works fine on my PC.

Not sure if this is the right way to do it.

You're not using crt, thats why it works fine.

ShadowG04

  • Newbie
  • Posts: 4
Re: CRT won't show ascii characters properly
« Reply #9 on: January 29, 2021, 07:25:10 pm »
I found a page with this guy having the same problem as me
Quote
http://www.productionautomation.net/FPC/ASCII/
it appears is all because crt doesnt show properly those characters.

It's not because crt but because the console itself can't show those characters, most probably due to either the font used or because the code-page can not be properly changed to IBM437 (the only one which has all box characters). Also FP might be making an internal conversion between the system and console codepages before the output which might be mangling it all, though I'm not entirely sure that's true...

In that page you cite the author forgot to make a simple test: compile and run his FP program under the same emulator (DOSBox) he did  the Turbo Pascal one: the result would demostrate the point that it's not really crt who's the culprit, I think.

You can make another simple test: use CP437 for the console and try with a full-screen rather than a windowed one. And, BTW, don't test from inside the IDE: open a console and launch the program.

Did the test and nothing changed, i'll run some test with DOSBox emulator to see if thats the problem.

FlierMate

  • Guest
Re: CRT won't show ascii characters properly
« Reply #10 on: January 29, 2021, 08:47:38 pm »
Windows Console is using UCS, and hence while Unicode 0~127 can represent ASCII(0x0 ~0x7F), 128~255 (and beyond) cannot.

Finally I understand why, the widely adopted UTF-8 is a variable-width encoding.
Extended ASCII 128 and above are used by UTF-8, either as continuation byte (128-191), or as indicator of the width of encoded bytes (0xCx, 0xEx, 0xFx).

It means that if extended ASCII is still in use, Unicode (or UCS) has no way to differentiate which is Unicode character and which is not.
After all, each byte has only 8-bit.

 

TinyPortal © 2005-2018