Recent

Author Topic: Unit CRT changes the ASCII character set  (Read 9355 times)

Vampirro

  • Newbie
  • Posts: 3
Unit CRT changes the ASCII character set
« on: December 06, 2016, 08:49:06 am »
Hi,

This is my first post and I'm sorry about my poor English.

Well, I have to make an old fashioned DOS application for Windows, with the ▒╣ and similar characters to create windows. But when I use the CRT unit for using colours, gotoxy and so on the character set changes to CP-1252. I've tried to print all the ASCII character set but these characters (▒╣╩╦) have gone. I've tried to use UTF-8 with

Code: Pascal  [Select][+][-]
  1. write (utf8ToAnsi('░'));

But the result is the character '¦' (the same with ▒,▓...)

How can I resolve this problem? Thanks for all

Vampirro

  • Newbie
  • Posts: 3
Re: Unit CRT changes the ASCII character set
« Reply #1 on: December 06, 2016, 12:05:53 pm »
I don't know if it's important, but... I have Windows 10. This code:

Code: Pascal  [Select][+][-]
  1. program ascii;
  2.  
  3. begin
  4.     writeln(chr(176));
  5. end.
  6.  

prints "░" in screen, but this one:

Code: Pascal  [Select][+][-]
  1. program ascii;
  2.  
  3. uses crt;
  4.  
  5. begin
  6.     writeln(chr(176));
  7. end.
  8.  

prints this character "°". Why? How can I continue using the "non-CRT" characters with the crt functions and procedures?

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Unit CRT changes the ASCII character set
« Reply #2 on: December 06, 2016, 01:06:38 pm »
Windows has three character encodings:

- Unicode, which is UTF16 for unicode characters
- ansi, which is a collective name for various 8-bit encodings (including utf-8 in the few places where Windows uses it)
- oem, the dos-like codepage from the console.

Constants are ansi, but you want to print OEM. The conversion function is ansitooem (which is nowadays implemented using chartooem). CRT takes over the console and probably does this automatically (?)

Another thing to try is changing the OEM codepage from the default 850 to ancient default dos with

chcp 437

before running your program.
« Last Edit: December 06, 2016, 01:08:10 pm by marcov »

Vampirro

  • Newbie
  • Posts: 3
Re: Unit CRT changes the ASCII character set
« Reply #3 on: December 06, 2016, 07:04:18 pm »
Thanks!

But... I'm not used to code in Pascal. I'm looking for an example of CharToOemBuff function in a Free Pascal program but I cannot find it. Could you give me an example, please?

Thanks for all

jackokring

  • Newbie
  • Posts: 2
Re: Unit CRT changes the ASCII character set
« Reply #4 on: November 15, 2018, 08:15:47 pm »
https://bitbucket.org/jackokring/clifly-fpc/src/master/ Not all of it, as it is far from complete U437 does translations from ANSI code page and cp437 into UTF-8 encoded AnsiStrings. If your terminal is UTF-8 compatible, then this should print correct. It seems the console appears to switch into ISO latin-1, which indicates potential Unicode compatibility? I've tried the source, but the code page mentioned in crt, video ... confusion.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Unit CRT changes the ASCII character set
« Reply #5 on: November 15, 2018, 09:28:59 pm »
The most probable culprit is crt.CrtWrite(). It starts with:

Code: Pascal  [Select][+][-]
  1.   OldConsoleOutputCP:=GetConsoleOutputCP;
  2.   SetConsoleOutputCP(GetACP);
  3.  

That switchs (if at all possible) the console to the current Windows code-page and IIRC, no "normal" Windows (aka ANSI) codepage contains those funny DOS characters.
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.

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Unit CRT changes the ASCII character set
« Reply #6 on: November 16, 2018, 05:03:42 am »
See if UnicodeCRT works for you.

Edit:
Sorry, I fell in the trap of responding to an old thread.
« Last Edit: November 16, 2018, 05:09:17 am by engkin »

Weosule

  • Newbie
  • Posts: 5
Re: Unit CRT changes the ASCII character set
« Reply #7 on: February 16, 2019, 02:15:53 am »
Hi...

I have had similar problems when recompiling programs I wrote in Turbo Pascal 7 for DOS. However, I discovered that FP has a number of units to cover the problem. Unit cp437 (Standard ASCII) is probably the unit you need to resolve your problem, however, there are units for other DOS and Windows code pages. Additional information can be found in the PDF file on runtime units in the document section of this site. You may have to use the actual character codes, e.g. chr(246) for lower case o-umlaut, for any characters in hi-ASCII.

Hope this helps,

Weosule

 

TinyPortal © 2005-2018