Скачать PingAnsi v1.33 - Ansi Emulation for Turbo Pascal v5+

Ping Hansen
Скачать файл (19,70 Кб)

PingAnsi v1.30 (c) CopyRight 1990 P.H.Rankin Hansen. Musica v1.00 (c) CopyRight 1990 P.H.Rankin Hansen.

The PingAnsi unit provides partial Ansi emulation for Turbo Pascal versions 5.x and higher. (version 4 does not support procedural types). Some routines may be handled in a non-standard way. The Musica unit implements the Play statement known from Basic. By using this material You assume FULL responsibility for ANY consequences - direct or indirect - thereof. Any dispute regarding this material shall be setteled by Danish law and in a Danish Court.

This source may NOT be used by Lawyers, Politicians or, persons engaged in any other form of terrorism. Otherwise the usage is free. This source may be freely distributed as long as no fee is charged.


The text file device driver mechanism was suggested by Robert Mashlan.

The so called 'Ansi'-music is due to steady prompting and lots of small hints from Dan Wulff, Dragons Lair (2:231/57.0).

In creating the units I have used Turbo Pascal 5.5 Professional (Borland), Turbo Analyst 5.04 and Turbo Professional Toolbox 5.07 (Turbo Power).

The units were written to end the steady stream of questions in the international Pascal echo about how to implement Ansi emulation with turbo Pascal. Sofar it looks like it has increased the number.

Using the units

(This is a preliminary document and NOT complete ! )

First let me make one thing prefectly clear. If You issue grabtimer function in the Musica unit, the 8253 timer 0 will be re-programmed to a 1 ms period. Therefore Interrupt 8 occurs 1000 times a second instead of 18.2 times. The original interrupt is called only once every 55 interrupts and the system is therefore operating like usual. If You have other routines that re-program timer 0 the result will propably be less than impressing. Keep in mind that problems may also occur if a TSR with memory-swap pops up on top of the interrupt handler. You can normalize the timer and release the interrupt using the procedure ReleaseTimer.

First You have to decide how You are going to use the units. There are three conditionals (Small, BBS and, Music) that govern the function of PingAnsi.

The conditional 'Small' defines wether the Text File device driver should be included. The Device driver will be slower for single characters, but presumably faster for strings. If You define 'Small' the driver part will be left out. Wether You include the text file driver will have NO influence on the AnsiWrite function, only on the size of the compiled unit.

The conditional 'BBS' defines wether the hook BBSHook(Char) should be called as well as AnsiWrite during writes. Use this for echoing all Write(Ansi,......) to e.g. the ComPort or a log file.

The conditional 'Music' defines wether the Ansi parser should check for so called Ansi music. Please note that this is NOT part of the Ansi specs., but the name sticks and I have been _asked_ to implement it. I have interfaced the procedure PlayHook(St : String) wich, using the Musica unit, can be used to implement the Play statement known from Basic. Musica supports background buffering of music.


Several hooks besides BBSHook are implemented.

ReplyHook     : Procedure(St : String);

ReplyHook is a hook for implementing Your own Device Status Report procedure. It defaults to a procedure that places the response in the keyboard buffer, but can be redirected to e.g. sending the report to the comport.

KeyHook     : Procedure(St : String);

KeyHook is a hook for implementing Your own KeyBoard Re-assignment. You could use this in a comms. program to report attempts to re-assign Your keyboard.

WriteHook   : Procedure(Ch : Char);

WriteHook is a Hook for handling control chars i.e. Ord(Ch) < $20

PlayHook : Procedure(Tone, Duration : word);

This hook is for implementing 'Ansi' music.


Several variables have been interfaced:

Ansi is the name of the Text file device driver.

Wrap is set to true if cursor should wrap at the screen edge. Defaults to true.

ReportedX are ReportedY the reported cursor location issued by a parsed position report. i.e. if the string #27[#;#R is run through the parser.

Procedures and functions
Procedure AnsiWrite(Ch : Char);

This is the main routine.

Function In_Ansi : Boolean;

Returns true if a ansi sequence is pending.

Procedure AssignAnsi(Var f : Text);

This is used like AssignCrt. It resets the driver. The driver is automatically assigned to the file Ansi at startup, but You're the boss.

You handle the Text file device driver like any other write:


This unit can be used as a standalone unit as it does not depend on the PingAnsi unit.

  WaitForEmpty : boolean = True;

Governs the behavior of the procedure that places the motes in the background buffer. If set to true and the PlayBuffer is full, stuff will wait until space is awailable before returning. If false and the PlayBuffer is full, stuff will discard the note and return (buffer overrun).