Ver Mensaje Individual
  #6  
Antiguo 25-09-2003
Avatar de delphi.com.ar
delphi.com.ar delphi.com.ar is offline
Federico Firenze
 
Registrado: may 2003
Ubicación: Buenos Aires, Argentina *
Posts: 5.932
Reputación: 27
delphi.com.ar Va por buen camino
¿Que te parece este código?

Código:
unit RX2_Util;

interface

uses Windows;

// set address of game port (default '$201')
procedure SetPortAddr(const addr: string);

// get current channel number and signal presence
procedure GetStatus(var chan: Integer; var signal: Boolean);

// push button for t milliseconds
procedure PushButton(t: Integer);

implementation

uses SysUtils;

var
  port_addr: Word;

function ReadPort: Byte;
begin
  asm
    mov dx,port_addr;
    in al,dx
    shr al,4
    mov result,al
  end;
end;

procedure SetPortAddr(const addr: string);
begin
  port_addr := StrToInt(addr);
end;

procedure GetStatus(var chan: Integer; var signal: Boolean);
var
  data: Byte;
const
  chan_no: array[0..7] of Integer = (0,1,2,3,0,4,0,5);
begin
  data := ReadPort;
  signal := data > 8;
  chan := chan_no[data mod 8];
end;

procedure PushButton(t: Integer);
var
  start: Integer;
begin
  start := GetTickCount;
  repeat
    asm
      mov dx,port_addr
      mov al,1
      out dx,al
    end;
  until (GetTickCount - start) >= t;
end;

initialization
  SetPortAddress('$201');

finalization 
end.
Saludos!
__________________
delphi.com.ar

Dedique el tiempo suficiente para formular su pregunta si pretende que alguien dedique su tiempo en contestarla.
Responder Con Cita