Solved

Programming interrupts ASM - Convert Pascal -> Deplhi inline ASM

Posted on 2004-04-06
6
1,738 Views
Last Modified: 2008-01-16
I need help to convert following code for Delphi inline ASM :

http://www.bsdg.org/SWAG/INTERRUP/0022.PAS.html

/////////////////////////////////////////////////////////////////

{$define IRQ7}
uses
  Dos,
  Crt;
{---------------------------------------------------------------------------}

var
  Lpt            : Word;
  InterruptCount : Word;
  LptOrgVec      : Procedure;
{---------------------------------------------------------------------------}

procedure SetPortBit(PortAdr:Word; Bit:Byte); assembler;
asm
           mov   dx,PortAdr
           in    al,dx
           mov   cl,Bit
           and   cl,7
           mov   ah,1
           shl   ah,cl
           or    al,ah
           out   dx,al
end;
{---------------------------------------------------------------------------}

procedure ClearPortBit(PortAdr:Word; Bit:Byte); assembler;
asm
           mov   dx,PortAdr
           in    al,dx
           mov   cl,Bit
           and   cl,7
           mov   ah,1
           shl   ah,cl
           not   ah
           and   al,ah
           out   dx,al
end;
{---------------------------------------------------------------------------}

function GetLptPort(LptNr:Byte):Word;
begin
  GetLptPort:=MemW[$0040:8 + (LptNr - 1) * 2];
end;
{---------------------------------------------------------------------------}

{$F+}
procedure NewLptInt; interrupt;
begin
  Sound(880);                                      {Quittungssignal ausgeben}
  Delay(5);
  NoSound;

  Inc(InterruptCount);                              {Interruptzdhler erhvhen}

  SetPortBit(Lpt + 1,6);                 {Bit 6 im Interrupt Register setzen}

  asm                                         {Interrupt Anforderung lvschen}
    mov  al,20h
    out  20h,al
  end;
end;
{$F-}
{---------------------------------------------------------------------------}

begin
  ClrScr;

  Lpt:=GetLptPort(1);                     {Port Adresse der 1. Schnittstelle}
  SetPortBit(Lpt + 1,6);                 {Bit 6 im Interrupt Register setzen}
  SetPortBit(Lpt + 2,4);                  {Bit 4 im Kontroll Register setzen}

{$ifdef IRQ7}
  ClearPortBit($21,7);                {IRQ7 im Intrrupt-Controller freigeben}
  GetIntVec($0F,@LptOrgVec);              {Bisherigen Interrupt Vektor holen}
  SetIntVec($0F,@NewLptInt);              {Vektor f|r neuen Interrupt setzen}
{$else}
  ClearPortBit($21,5);                {IRQ5 im Intrrupt-Controller freigeben}
  GetIntVec($0D,@LptOrgVec);              {Bisherigen Interrupt Vektor holen}
  SetIntVec($0D,@NewLptInt);              {Vektor f|r neuen Interrupt setzen}
{$endif}

  Writeln('Press the interrupt-switch to test response, or any key to quit...');
  Writeln('Interrupts occurrences : ');
  InterruptCount:=0;
  repeat
    GotoXY(25,2);
    Write(InterruptCount:5);
  until KeyPressed;
  ReadKey;

{$ifdef IRQ7}
  SetPortBit($21,7);                    {IRQ7 im Intrrupt-Controller sperren}
  SetIntVec($0F,@LptOrgVec);     {Vektor von urspr|nglichem Interrupt setzen}
{$else}
  SetPortBit($21,5);                    {IRQ5 im Intrrupt-Controller sperren}
  SetIntVec($0D,@LptOrgVec);     {Vektor von urspr|nglichem Interrupt setzen}
{$endif}
end.
0
Comment
Question by:simoha
  • 3
6 Comments
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 10772706
Delphi is 32bit Protected Mode and Your pascal code appears to be 16bit. So I dont think you will be able to :(


-Brian
0
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 10772709
Unless you build a 16bit application :)

-brian
0
 
LVL 19

Accepted Solution

by:
BrianGEFF719 earned 113 total points
ID: 10772716
Yah that code is not going to work for Delphi Inline ASM./.


-Brian
0
 
LVL 22

Assisted Solution

by:grg99
grg99 earned 112 total points
ID: 10773949
You need to either:

put that code in a driver.

or

use some add-on like "giveio" which allows a 32-bit app to do port I/O.

do a google search for "giveio".  It's easy to use.

0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How do I defuse  Phase_2 in bomblab 12 1,005
Creating EXE from Assembly Code 13 765
memory mapped I/O query 6 147
gcc error: -mpreferred-stack-boundary=2 is not between 4 and 12 7 1,854
This article outlines the process to identify and resolve account lockout in an Active Directory environment.
Adding Computers to AD groups through an SCCM Task Sequence
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question