Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

HELP: C/C++ equivalent of dos,crt Pascal units

112 views
Skip to first unread message

Dhruba Bandopadhyay

unread,
Sep 1, 2006, 11:14:17 AM9/1/06
to
I am trying to port an old Pascal DOS game to DOS C/C++. I am wondering if
anyone is familar with the dos & crt Pascal units and whether there are
C/C++ equivalent libraries. Maybe dos.c & crt.c?

Below lists names of variables, functions, types & weird interrupt
procedures found in Pascal. Am wondering what can be done to get around them
for use in C/C++.

dos.pas
crt.pas

---undefined identifiers---
'black'
'blue'
'clrscr'
'lightblue'
'lightcyan'
'lightgray'
'lightgreen'
'lightmagenta'
'lightred'
'mem'
'port'
'wherex'
'wherey'
'white'
'yellow'


---undefined functions---
'addr'
'blockread'
'delay'
'fillchar'
'fsearch'
'getintvec'
'gettime'
'gotoxy'
'hi'
'inline_'
'int_'
'intr'
'lo'
'ofs'
'seg'
'setintvec'
'settime'
'swap'
'textbackground'
'textcolor'
'window'


---unknown types---
Single
registers


---misc---
Port[$3C8] := reg;
l := port[$60];
port[$20] := $20;
Port[$43] := $B6;
ch := mem[seg(tex) + (let div 16): ofs(tex) + (let mod 16)];
procedure NewInt1C; Interrupt;
procedure NewInt08; Interrupt;

Carl Daniel [VC++ MVP]

unread,
Sep 1, 2006, 11:44:16 AM9/1/06
to
Dhruba Bandopadhyay wrote:
> I am trying to port an old Pascal DOS game to DOS C/C++. I am
> wondering if anyone is familar with the dos & crt Pascal units and
> whether there are C/C++ equivalent libraries. Maybe dos.c & crt.c?
>
> Below lists names of variables, functions, types & weird interrupt
> procedures found in Pascal. Am wondering what can be done to get
> around them for use in C/C++.

This is not primarily a Borland Pascal vs. C++ issue. Rather, it's a DOS,
writes directly to screen memory versus Windows issue. Windows does not
permit a program to directly write to screen memory, access I/O ports, issue
interrupts, etc.

You'll need to figure out what the code is doing, and then ask questions
about specific things that you don't know how to do under Windows because
there is no simple substitute or header file that will magically make this
code work outside of DOS.

-cd


Alex Blekhman

unread,
Sep 1, 2006, 12:08:38 PM9/1/06
to


It seems that this Pascal program directly operates video
memory buffer as well as sound, clock and something else I'm
not familiar with. If you want to port it to 16-bit DOS
program, then it should be straightforward. First of all,
get 16-bit compiler (Visual C++ v1.52 or old Borland Turbo
C++, or whatever). Then writing and reading to/from ports is
basically the same. You just call outp/inp functions. Also,
IIRC, Turbo C++ had quite rich functions set for console IO.
I reckon VC++1.52 is on par with TC++.

Porting it to Windows is completely different story. You
cannot access hardware directly anymore. So, you have
different functions in Platform SDK to reach your goals. See
these sections for beginning:

"Using the Console"
http://msdn.microsoft.com/library/en-us/dllproc/base/using_the_console.asp

"Multimedia Timers"
http://msdn.microsoft.com/library/en-us/multimed/htm/_win32_multimedia_timers.asp

"Multimedia Audio"
http://msdn.microsoft.com/library/en-us/multimed/htm/_win32_multimedia_audio.asp

If you need just a basic beep, then call to Beep() can
suffice.

HTH
Alex


Eric Hill

unread,
Sep 1, 2006, 12:21:28 PM9/1/06
to Dhruba Bandopadhyay
> I am trying to port an old Pascal DOS game to DOS C/C++. I am wondering
> if
> anyone is familar with the dos & crt Pascal units and whether there are
> C/C++ equivalent libraries. Maybe dos.c & crt.c?

A large amount of what Pascal did is just set colors and draw in fixed
locations. You can accomplish the same things with a C++ screen IO
library:

http://conio.sourceforge.net

This library is dependent on the conio.h file, which ships with VC. You
won't be able to use interrupts like Pascal did (DOS-specific feature) but
typical usage of interrupts was to do things like clear the screen and
handle keyboard IO. Since that's all built into the console now, you can
use the standard Windows API calls to perform those tasks.

Eric

Tim Roberts

unread,
Sep 3, 2006, 2:07:58 AM9/3/06
to
"Dhruba Bandopadhyay" <dhruba.ba...@hotmail.com> wrote:
>
>I am trying to port an old Pascal DOS game to DOS C/C++. I am wondering if
>anyone is familar with the dos & crt Pascal units and whether there are
>C/C++ equivalent libraries. Maybe dos.c & crt.c?

You need to be careful with your terminology here. None of this stuff is
in the standards for either Pascal or C. What you have is a Borland Turbo
Pascal program. Assuming you want to do the same thing in Microsoft Visual
C++ 1.52 (which was the last 16-bit compiler), then we can give you an
answer.

>Below lists names of variables, functions, types & weird interrupt
>procedures found in Pascal. Am wondering what can be done to get around them
>for use in C/C++.
>
>dos.pas
>crt.pas
>
>---undefined identifiers---
>'black'
>'blue'
>'clrscr'
>'lightblue'
>'lightcyan'
>'lightgray'
>'lightgreen'
>'lightmagenta'
>'lightred'

>'white'
>'yellow'

You will have to compute these constants yourself. It isn't hard.

>'mem'

The "mem" array is just Turbo Pascal's way of accessing arbitrary memory
accesses. You will want to use far pointers or huge pointers for this.

>'port'

The "port" array is the equivalent of the inp and outp functions in
Microsoft C.

>'wherex'
>'wherey'

These return the current cursor position. You'll probably have to write
that yourself by calling INT 10.

>---unknown types---
>Single
>registers

The Pascal "single" type is the same as C's "float" type. In VC++1.52, the
dos.h include file has a REGS type that can be used to make interrupt
calls.

>---misc---
>Port[$3C8] := reg;
>l := port[$60];
>port[$20] := $20;
>Port[$43] := $B6;

outp( 0x3c8, reg );
l = inp( 0x60 );
outp( 0x20, 0x20 );
outp( 0x43, 0xb6 );

>ch := mem[seg(tex) + (let div 16): ofs(tex) + (let mod 16)];

There are probably better ways to do this in C. Microsoft C suports a
"huge" pointer type that is probably the same as this. Assuming you have
this:
char __huge * tex;
then you can say:
ch = tex[let];

>procedure NewInt1C; Interrupt;
>procedure NewInt08; Interrupt;

Microsoft C has an __interrupt keyword to let you define interrupt
routines, although it isn't as automatic as Turbo Pascal.

void __interrupt NewInt1C()
{
__asm push ax
__asm push bx
etc...
}
--
- Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

0 new messages