Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2012-12

converting a TP/BP library to FPC

8 messages · 5 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

waldo kitty

w2k with FPC 2.6.0 release using lazarus 1.1 only as an editor... no GUI stuffings at all... i'm using -Mtp in the project options...

i have finally gotten around to trying to convert the old FTN/BBS MKSMG library to FPC... it was written for DOS TP/BP and has defines for windows which i assume is the early delphi... this is a first run at this and i'm only working with a project file that contains all the units in the uses clause...

currently i'm taking the "easiest way out" with "IFDEF FPC" to define within the "IFDEF WINDOWS" blocks using the DOS format for most things and using the FPC DOS unit... but i've run into something i don't know how to handle...

Var
   TimeCounter: LongInt Absolute $40:$6C;

FPC tells me the following...

MKDOS.PAS(14,36) Fatal: Syntax error, ";" expected but ":" found

i know this is using direct access to the timer ticker from the BIOS but at this time, i don't know how to best handle it in FPC...

this is not used in the current BBS message base library code that i'm working with but it is a routine that is used in other portions of the BBS library code... in the current unit, MKDOS, it is only used in a routine to determine if there's been a timeout indicating user inactivity for users that were logged into the bbs... as i say above, this is not a routine used in the message base code which is currently my main concern in getting ported to FPC...

so how should i handle this?

PS: i saw a notation in some FPC code that Mark May had ported whatever unit i was looking at to linux and then it was further enhanced by another individual... i don't know if Mark is still reading these FPC lists or not, though... i haven't seen anything indicating that the MKSMG sources have been ported to FPC, either... so i may be "reinventing the wheel" if this work has already been done... at least i'm getting plenty of practice typing "{$IFDEF FPC}", "{$ELSE}" and "{$ENDIF FPC}" ;)

PPS: sorry if this is rambling... today is my birthday and i'm also celebrating that, such as it is -=B-)

Chad Berchek
to waldo kitty

Perhaps it would be sufficient to supply the time value from another source converted to the units the other code is expecting to see. Assuming the frequency for the BIOS timer is about 18.2 Hz:

function TimeCounter: LongInt;
begin
   Result := LongInt(Round(GetTickCount * 18.2065 / 1000));
end;

wherein GetTickCount is a function returning a value in milliseconds. However you'd have to be careful of the overflow wrap around and see if the old code can handle it.

waldo kitty wrote 10 lines
Var TimeCounter: LongInt Absolute $40:$6C; FPC tells me the following... MKDOS.PAS(14,36) Fatal: Syntax error, ";" expected but ":" found i know this is using direct access to the timer ticker from the BIOS but at this time, i don't know how to best handle it in FPC...
Mark Morgan Lloyd
to waldo kitty: w2k with FPC 2.6.0 release using lazarus 1.1 only as an editor... no GUI stuffings at…
waldo kitty wrote 11 lines
w2k with FPC 2.6.0 release using lazarus 1.1 only as an editor... no GUI stuffings at all... i'm using -Mtp in the project options... i have finally gotten around to trying to convert the old FTN/BBS MKSMG library to FPC... it was written for DOS TP/BP and has defines for windows which i assume is the early delphi... this is a first run at this and i'm only working with a project file that contains all the units in the uses clause... PPS: sorry if this is rambling... today is my birthday and i'm also celebrating that, such as it is -=B-)

Happy birthday, hopefully the novelty hasn't work off yet :-)

Thinking back to when people started doing this sort of conversion, as a general point keep an eye open for any code that loops to poll a key or e.g. display an on-screen clock. That sort of technique might be fine in DOS, but as soon as you have a multitasking OS you need to look for alternatives.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]
Tomas Hajny
to waldo kitty: w2k with FPC 2.6.0 release using lazarus 1.1 only as an editor... no GUI stuffings at…
waldo kitty wrote 8 lines
w2k with FPC 2.6.0 release using lazarus 1.1 only as an editor... no GUI stuffings at all... i'm using -Mtp in the project options... i have finally gotten around to trying to convert the old FTN/BBS MKSMG library to FPC... it was written for DOS TP/BP and has defines for windows which i assume is the early delphi... this is a first run at this and i'm only

The Windows part may be also TPW (Turbo Pascal for Windows) or the Windows (MS Win 3.1) target in BP.

Show quoted text 19 lines
working with a project file that contains all the units in the uses clause... currently i'm taking the "easiest way out" with "IFDEF FPC" to define within the "IFDEF WINDOWS" blocks using the DOS format for most things and using the FPC DOS unit... but i've run into something i don't know how to handle... Var TimeCounter: LongInt Absolute $40:$6C; FPC tells me the following... MKDOS.PAS(14,36) Fatal: Syntax error, ";" expected but ":" found i know this is using direct access to the timer ticker from the BIOS but at this time, i don't know how to best handle it in FPC...

I would recommend switching to Dos.GetMSCount for a cross-platform solution. Note the following comment provided within the source:

{Offset between two return values corresponds to amount of milliseconds between the two calls, however the exact value is not guaranteed to have particular meaning - it can be e.g. amount of milliseconds since computer startup on DOS-like x86 platforms, derived from Unix time on Unix etc.}

GetTickCount proposed in another response is WinXX specific (Win32/Win64 API call).

.
.

PPS: sorry if this is rambling... today is my birthday and i'm also celebrating that, such as it is -=B-)

Happy birthday then! :-)

Tomas

Tomas Hajny
to Mark Morgan Lloyd: Happy birthday, hopefully the novelty hasn't work off yet :-) Thinking back to when…
Mark Morgan Lloyd wrote 20 lines
waldo kitty wrote: > w2k with FPC 2.6.0 release using lazarus 1.1 only as an editor... no GUI > stuffings at all... i'm using -Mtp in the project options... > > i have finally gotten around to trying to convert the old FTN/BBS MKSMG > library to FPC... it was written for DOS TP/BP and has defines for > windows which i assume is the early delphi... this is a first run at > this and i'm only working with a project file that contains all the > units in the uses clause... > PPS: sorry if this is rambling... today is my birthday and i'm also > celebrating that, such as it is -=B-) Happy birthday, hopefully the novelty hasn't work off yet :-) Thinking back to when people started doing this sort of conversion, as a general point keep an eye open for any code that loops to poll a key or e.g. display an on-screen clock. That sort of technique might be fine in DOS, but as soon as you have a multitasking OS you need to look for alternatives.

Indeed, good point - SysUtils.Sleep is a better option in this case. Dos.GetMsCount (suggested in my other response to this thread) still has its place if you need to check whether at least certain period passed between two events, etc.

Tomas

Mark Morgan Lloyd
to Tomas Hajny
Tomas Hajny wrote 10 lines
> Thinking back to when people started doing this sort of conversion, as a > general point keep an eye open for any code that loops to poll a key or > e.g. display an on-screen clock. That sort of technique might be fine in > DOS, but as soon as you have a multitasking OS you need to look for > alternatives. Indeed, good point - SysUtils.Sleep is a better option in this case. Dos.GetMsCount (suggested in my other response to this thread) still has its place if you need to check whether at least certain period passed between two events, etc.

Way back, I was selling and supporting languages and operating systems. Programmers used only to QuickBasic etc. had a major eye-opener when they tried to run multiple copies of their program on CDOS, Desqview, Windows-386 or OS/2 (once it got to the point of supporting multiple dosboxes), and found that almost all the CPU was going into the idle loop which included keyboard and clock polling.

Of course, OSes pretty quickly learnt to detect the common "time wasters" and to put in at least a forcible Yield or Sleep(0). But it's far better not to make a mess in the first place than to rely on somebody else clearing up for you.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]
waldo kitty
to Chad Berchek: Perhaps it would be sufficient to supply the time value from another source converted to…
Chad Berchek wrote 10 lines
Perhaps it would be sufficient to supply the time value from another source converted to the units the other code is expecting to see. Assuming the frequency for the BIOS timer is about 18.2 Hz: function TimeCounter: LongInt; begin Result := LongInt(Round(GetTickCount * 18.2065 / 1000)); end; wherein GetTickCount is a function returning a value in milliseconds.

this is pretty much what i have thought about doing...

However you'd have to be careful of the overflow wrap around and see if the old code can handle it.

that routine follows... it doesn't seem to be all that fancy, though...

Function TimeOut(Time:LongInt):Boolean;
   Var
     TimeDiff: LongInt;
   Begin
   TimeDiff := Time - TimeCounter;
   If TimeDiff < 0 Then
     TimeOut := True
   Else
     Begin
     If (TimeDiff > 780000) Then
     Dec(TimeDiff, 1572480);
     If TimeDiff < 0 Then
       TimeOut := True
     Else
       TimeOut := False;
     End;
   End;
Show quoted text 17 lines
On 12/5/2012 6:25 PM, waldo kitty wrote: > > Var > TimeCounter: LongInt Absolute $40:$6C; > > FPC tells me the following... > > MKDOS.PAS(14,36) Fatal: Syntax error, ";" expected but ":" found > > i know this is using direct access to the timer ticker from the BIOS but > at this time, i don't know how to best handle it in FPC... _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal