Discussion:
HELP: C/C++ equivalent of dos,crt Pascal units
(too old to reply)
Dhruba Bandopadhyay
2006-09-01 15:13:03 UTC
Permalink
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;
Rudy Velthuis [TeamB]
2006-09-01 16:43:52 UTC
Permalink
Post by 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?
Have a look at conio.h as a replacement for crt. The names are different,
but the functionality is similar. IIRC, there was a dos.h in the old
Turbo C++'s. Note that dos.h will really only work in DOS. In Win32,
you'd have to use the Windows API instead of INT calls.
--
Rudy Velthuis [TeamB] http://rvelthuis.de/

"I'm all in favor of keeping dangerous weapons out of the hands
of fools. Let's start with typewriters."
-- Frank Lloyd Wright (1868-1959)
Liz Albin
2006-09-01 16:41:00 UTC
Permalink
Post by 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?
There is a dos.h header file, but it's worth noting that in 32 bit
windows you may well have to use something else
--
liz
Ed Mulroy
2006-09-01 16:47:35 UTC
Permalink
You have posted your message in all of these newsgroups:
borland.public.cpp.borlandcpp
borland.public.cpp.turbocpp
borland.public.cppbuilder.language.cpp
borland.public.turbopascal

Newsgroup guidelines dictate that you pick one group for your message and
post it there:
http://info.borland.com/newsgroups/guide.html

You do not identify which compiler you are using and the assortment of
newsgroups you elected to multi-post to covers all of them. Read the help
for the compiler you are using. If it is a compiler which can create DOS
programs then the help will tell you about most of the things about which
you are asking. The rest can be inferred either from the compiler's
accompanying examples or from the C language. For example addr translates
to &, blockread to fread and textcolor remains textcolor.

. Ed
Post by 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?
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;
Loren Pechtel
2006-09-02 02:24:49 UTC
Permalink
On Fri, 1 Sep 2006 16:13:03 +0100, "Dhruba Bandopadhyay"
Post by 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?
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
Basically everything you need for the filesystem. Stdio.h if I
remember my C right. (It's been a *LONG* time since I needed to use
it.)
Post by Dhruba Bandopadhyay
crt.pas
Stuff for dealing with the screen directly. I don't know the C
equivalent.
Post by Dhruba Bandopadhyay
---undefined identifiers---
Most of these are constants for colors.
Post by Dhruba Bandopadhyay
'black'
'blue'
'clrscr'
Clear screen
Post by Dhruba Bandopadhyay
'lightblue'
'lightcyan'
'lightgray'
'lightgreen'
'lightmagenta'
'lightred'
'mem'
This provides direct access to any memory address. It takes two
parameters, the segment and the offset. You could build a C pointer
to do the same thing.
Post by Dhruba Bandopadhyay
'port'
Port access.
Post by Dhruba Bandopadhyay
'wherex'
'wherey'
These two read the cursor position.
Post by Dhruba Bandopadhyay
'white'
'yellow'
---undefined functions---
'addr'
'blockread'
Untyped file read.
Post by Dhruba Bandopadhyay
'delay'
Spin your wheels for the specified number of milliseconds.
Post by Dhruba Bandopadhyay
'fillchar'
Writes a specified byte value to a region of memory.
Post by Dhruba Bandopadhyay
'fsearch'
'getintvec'
Reads the value of an interrupt vector. Wrapper for the BIOS function
that does this.
Post by Dhruba Bandopadhyay
'gettime'
'gotoxy'
Sets the cursor position.
Post by Dhruba Bandopadhyay
'hi'
The high order byte of a word.
Post by Dhruba Bandopadhyay
'inline_'
'int_'
'intr'
'lo'
The low order byte of a word.
Post by Dhruba Bandopadhyay
'ofs'
The offset portion of a pointer.
Post by Dhruba Bandopadhyay
'seg'
The segment portion of a pointer.
Post by Dhruba Bandopadhyay
'setintvec'
Writes the value of an interrupt vector. Wrapper for the BIOS
function.
Post by Dhruba Bandopadhyay
'settime'
'swap'
'textbackground'
The background color of the screen.
Post by Dhruba Bandopadhyay
'textcolor'
The foreground color of the screen.
Post by Dhruba Bandopadhyay
'window'
Restricts output to the specified area of the screen.
Post by Dhruba Bandopadhyay
---unknown types---
Single
A basic floating point type
Post by Dhruba Bandopadhyay
registers
A record structure that holds all the register values. It's needed
when setting up BIOS calls.
Post by Dhruba Bandopadhyay
---misc---
Port[$3C8] := reg;
A write to the port
Post by Dhruba Bandopadhyay
l := port[$60];
A read from it
Post by Dhruba Bandopadhyay
port[$20] := $20;
Port[$43] := $B6;
Two port writes
Post by Dhruba Bandopadhyay
ch := mem[seg(tex) + (let div 16): ofs(tex) + (let mod 16)];
This appears to be a workaround for the fact that you can't have a
32-bit pointer. This seems to take a pointer in Tex and a 32-bit
offset in Let and read the byte thus pointed to
Post by Dhruba Bandopadhyay
procedure NewInt1C; Interrupt;
procedure NewInt08; Interrupt;
Declaring a procedure interrupt means the registers will be
saved/restored and it will exit with an iret rather than just a ret.
Iain Macmillan
2006-09-09 00:09:17 UTC
Permalink
Post by Loren Pechtel
Post by Dhruba Bandopadhyay
crt.pas
Stuff for dealing with the screen directly. I don't know the C
equivalent.
Well, mostly we built our own. I had to, that was part of the requirements
of the C course I did.

All this stuff is quite easy with

int86();
and
union regs
(both in dos.h
and a reference book documenting the dos interrupts.
Post by Loren Pechtel
Post by Dhruba Bandopadhyay
'clrscr'
Clear screen
Really fast cls in C:
_setvideomode(_getvideomode());
(I told you these routines were easy to write..<g>)
Post by Loren Pechtel
Post by Dhruba Bandopadhyay
'delay'
Spin your wheels for the specified number of milliseconds.
LOL.
Or less than that number.
Or throw RTE 200.

Definitely write this one yourself.
You couldn't do worse than Borland's offering!
Post by Loren Pechtel
This appears to be a workaround for the fact that you can't have a
32-bit pointer. This seems to take a pointer in Tex and a 32-bit
offset in Let and read the byte thus pointed to
Oh, yes we had to do this in 16-bit.
Most compiler's libraries include SEG and OFS macros for dissecting a far
pointer and something like MK_FP for making one.
Post by Loren Pechtel
Declaring a procedure interrupt means the registers will be
saved/restored and it will exit with an iret rather than just a ret.
in C this should work.
void _interrupt mynewhandler()
{ /*some code*/ }
Loren Pechtel
2006-09-09 02:11:40 UTC
Permalink
On Sat, 09 Sep 2006 01:09:17 +0100, "Iain Macmillan"
Post by Iain Macmillan
Post by Loren Pechtel
Post by Dhruba Bandopadhyay
crt.pas
Stuff for dealing with the screen directly. I don't know the C
equivalent.
Well, mostly we built our own. I had to, that was part of the requirements
of the C course I did.
All this stuff is quite easy with
int86();
and
union regs
(both in dos.h
and a reference book documenting the dos interrupts.
Post by Loren Pechtel
Post by Dhruba Bandopadhyay
'clrscr'
Clear screen
_setvideomode(_getvideomode());
(I told you these routines were easy to write..<g>)
That's going to flicker the screen.
Post by Iain Macmillan
Post by Loren Pechtel
Post by Dhruba Bandopadhyay
'delay'
Spin your wheels for the specified number of milliseconds.
LOL.
Or less than that number.
Or throw RTE 200.
True, it's not all that accurate. The RTE200 is cured by various bits
of code out there on the web.
Post by Iain Macmillan
Post by Loren Pechtel
This appears to be a workaround for the fact that you can't have a
32-bit pointer. This seems to take a pointer in Tex and a 32-bit
offset in Let and read the byte thus pointed to
Oh, yes we had to do this in 16-bit.
Most compiler's libraries include SEG and OFS macros for dissecting a far
pointer and something like MK_FP for making one.
I was just giving you an interpretation of all the stuff you were
saying was missing.
Post by Iain Macmillan
Post by Loren Pechtel
Declaring a procedure interrupt means the registers will be
saved/restored and it will exit with an iret rather than just a ret.
in C this should work.
void _interrupt mynewhandler()
{ /*some code*/ }
Sounds right. My C is too rusty to be sure.
Marco van de Voort
2006-09-09 17:15:25 UTC
Permalink
Post by Iain Macmillan
Post by Loren Pechtel
Post by Dhruba Bandopadhyay
'delay'
Spin your wheels for the specified number of milliseconds.
LOL.
Or less than that number.
Or throw RTE 200.
Definitely write this one yourself.
You couldn't do worse than Borland's offering!
See how many other compilers of that era are still in production use, and
you realise that this issue is
1) actually fixable!
2) one of the few.

E.g. I have a version (and slightly newer) of Topspeeds offerings, and I
already had to work around the IDE not starting several times.
Iain Macmillan
2006-09-13 00:59:02 UTC
Permalink
Post by Marco van de Voort
Post by Iain Macmillan
You couldn't do worse than Borland's offering!
See how many other compilers of that era are still in production use,
Well no, I wasn't suggesting that everything is bad because of this mistake;
just that as mistakes go it was a real howler.
Post by Marco van de Voort
and
you realise that this issue is
1) actually fixable!
Sure; TP6 is OK except that it does not delay the requisite number of
milliseconds.
Easily fixed. Write your own routine. Hint, if you want to know what time it
is, look at the *clock*. Much better than counting on your fingers..

.. Compare with TP7, when that approach led to counting so many fingers that
brain overload occurred. <g>
Post by Marco van de Voort
2) one of the few.
Indeed.
Post by Marco van de Voort
E.g. I have a version (and slightly newer) of Topspeeds offerings, and I
already had to work around the IDE not starting several times.
Hmm, well mostly my old compilers were just compilers, not IDE's, and afaics
they still work.
In any case, once your project gets only a bit big, the Turbo IDE runs out
of memory, so you have to just use the command-line compiler tpc.exe anyway.
Dhruba Bandopadhyay
2006-10-02 13:06:20 UTC
Permalink
I just been browsing Grant Smith, aka Denthor of Asphyxia, Graphics
Programming Tutorials on http://www.cprogramming.com/tutorial/tut1.html

Does anyone know his email address or how I can contact him?

I like his comparison of Pascal & C code. This is helping me to convert an
old Pascal game to C++.

However there's still some Pascal functions I need C++ equivalent off. Eg.

addr - I think this is like C's &
blockread
fsearch

getintvec - I think C equivalent is getvec?
setintvec - I think C equivalent is setvec?

ofs -
seg -

Borland dos.h has these macros but are they equivalent of ofs & seg???
#define MK_FP(seg,ofs) ((void __seg *)(seg) + (void __near *)(ofs))
#define FP_SEG(fp) ((unsigned)(void __seg *)(void __far *)(fp))
#define FP_OFF(fp) ((unsigned)(fp))

mem[ : ] - I know memset to set it, but what about get ? Maybe peek & poke?





Let me know if these are correct translations from Pascal to C/C++.
Post by 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?
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;
Thomas Maeder [TeamB]
2006-10-02 16:27:59 UTC
Permalink
Please direct your browser at http://info.borland.com/newsgroups/ and
read the newsgroup guidelines. One of them asks us not to post the
same question to different newsgroups, but to pick the most
appropriate one and just post there. Thanks!

Loading...