flat assembler
Message board for the users of flat assembler.

Index > DOS > Changing antique software (delay loops)

Author
Thread Post new topic Reply to topic
prino



Joined: 24 Jun 2004
Posts: 17
prino
Hi all,

I've "inherited" some software dating back to the 1990'ies that no longer works on today's PCs, not because it's written to be run on pure DOS and requires a parallel port (I still have a PC that runs DOS and has a parallel port), but because it has nine hardcoded delay loops of the type

Code:
; following delay used to make sure STB signal is low for
; at least 12us before reading data.  This is 3x delay
; required on a 20MHz processor.
;
        mov     cx,225          ; load with delay count
$DLY1:
        loop    $DLY1 ($DLY2,$DLY3,$DLY4 are the same)

; the following delay loop guarantees that the D4 signal
; will be low at least 9us on a 20MHz processor before
; it is set high again.

        mov     cx,165
$DLY5:
        loop    $DLY5

; no comment...

        mov     cx,100
$DLY6:
        loop    $DLY6

; no comment, same as $DLY5

        mov     cx,165
$DLY7:
        loop    $DLY7

;-----------------------------------------------------------
; Hold HSK low for certain length of time (HSK delay)
;-----------------------------------------------------------
        mov     cx,165           ; delay for timing
$DLY8:
        loop    $DLY8

; no comment...

        mov     cx,150
$DLY9:
        loop    $DLY9
    

and with multi-GHz PCs that obviously no longer cuts the ice. I can go for a kludge, and just loop on ecx, adapted for the speed of the PC this will be running on, but it would be a lot nicer if someone would have any code to share that actually dynamically adjusts the loops. It must be DOS based, but using 32-bit instructions is not a problem.

Thanks,

Robert

_________________
Robert AH Prins
robert dot ah dot prins at the big account from Google Wink
Post 19 Apr 2014, 09:25
View user's profile Send private message Visit poster's website Reply with quote
alexfru



Joined: 23 Mar 2014
Posts: 72
alexfru
Look at the RDTSC instruction. TSC increments on every CPU clock.
Post 19 Apr 2014, 10:25
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17010
Location: In your JS exploiting you and your system
revolution
If you have a standard mobo with the hardware high-precision timer present then use that. It runs at a fixed frequency independent of the CPU clock speed so things like lower power modes won't affect the timing.
Post 19 Apr 2014, 10:34
View user's profile Send private message Visit poster's website Reply with quote
prino



Joined: 24 Jun 2004
Posts: 17
prino
alexfru wrote:
Look at the RDTSC instruction. TSC increments on every CPU clock.
I know about the RDTSC instruction, int 15 AH=86, the RTC, but I normally program in PL/I and REXX, so stringing the lot together is just a trifle more complicated for me. Sad

_________________
Robert AH Prins
robert dot ah dot prins at the big account from Google Wink
Post 19 Apr 2014, 11:21
View user's profile Send private message Visit poster's website Reply with quote
alexfru



Joined: 23 Mar 2014
Posts: 72
alexfru
I lost you there, sorry, can you elaborate? What do PL/I and REXX have to do with changing the presented assembly code? Did you not tell us all the requirements/restrictions the solution must meet?
Post 19 Apr 2014, 11:55
View user's profile Send private message Reply with quote
prino



Joined: 24 Jun 2004
Posts: 17
prino
alexfru wrote:
I lost you there, sorry, can you elaborate? What do PL/I and REXX have to do with changing the presented assembly code? Did you not tell us all the requirements/restrictions the solution must meet?

PL/I and REXX are the two languages I use as a programmer on z/OS systems. I know a bit about x86 assembler from looking at the code generated by various PC based compilers (mostly Pascal), but actually writing x86 assembler from scratch is another kettle of fish. I'm sure I will get there in the end using Google, but
revolution wrote:
If you have a standard mobo with the hardware high-precision timer present then use that. It runs at a fixed frequency independent of the CPU clock speed so things like lower power modes won't affect the timing.
is something completely new to me.

In essence I'm looking for a simple routine where I put the required delay (in usec) in (E)CX and it loops for usec. Using

Code:
RDTSC
INT 15/86 (delay 1mS)
RDTSC    

I can determine the CU frequency, now all I need is a reliable way of multiplying ECX with a fraction of that frequency to get the (approximate) delays that used to occur with the values in the initial post on a 20MHz machine.

_________________
Robert AH Prins
robert dot ah dot prins at the big account from Google Wink
Post 19 Apr 2014, 12:31
View user's profile Send private message Visit poster's website Reply with quote
freecrac



Joined: 19 Oct 2011
Posts: 117
Location: Germany Hamburg
freecrac
Hello.
I never try to use the parrallel port with my own program and so i do not known the timing that we have to wait between to send some commands to the port.

But what do you think about to redirect the vector(address 0x20,0x22) of the timer-interrupt(8) to an own ISR for to get a constant delay with it, will it solve those problems?

Dirk
Post 19 Apr 2014, 12:45
View user's profile Send private message Send e-mail Reply with quote
prino



Joined: 24 Jun 2004
Posts: 17
prino
freecrac wrote:
Hello.
I never try to use the parrallel port with my own program and so i do not known the timing that we have to wait between to send some commands to the port.

But what do you think about to redirect the vector(address 0x20,0x22) of the timer-interrupt(Cool to an own ISR for to get a constant delay with it, will it solve those problems?

If I was that smart or accomplished with x86 assembler, I probably wouldn't have posted here Wink

_________________
Robert AH Prins
robert dot ah dot prins at the big account from Google Wink
Post 19 Apr 2014, 17:22
View user's profile Send private message Visit poster's website Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
Quote:
If I was that smart or accomplished with x86 assembler, I probably wouldn't have posted here

Usually, the common visitors of FlatAssembler message board are people with some assembly knowledge.

BTW, do you have the sources of your software, or you have to patch the binaries?
Post 19 Apr 2014, 18:50
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
prino



Joined: 24 Jun 2004
Posts: 17
prino
JohnFound wrote:
Quote:
If I was that smart or accomplished with x86 assembler, I probably wouldn't have posted here

Usually, the common visitors of FlatAssembler message board are people with some assembly knowledge.

BTW, do you have the sources of your software, or you have to patch the binaries?

I have quite a bit of knowledge about x86 assembler having converted most of my original Pascal programs to use vast sections of inline assembler.

And yes, I do have the sources, but there is no way I can share them with anyone.

_________________
Robert AH Prins
robert dot ah dot prins at the big account from Google Wink
Post 19 Apr 2014, 19:31
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.