123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- {
- This file is part of the Free Pascal run time library.
- and implements some stuff for protected mode programming
- Copyright (c) 1999-2000 by the Free Pascal development team.
- These files adds support for TP styled port accesses
- See the file COPYING.FPC, included in this distribution,
- for details about the copyright.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- **********************************************************************}
- unit ports;
- interface
- type
- tport = object
- procedure writeport(p : word;data : byte);
- function readport(p : word) : byte;
- property pp[w : word] : byte read readport write writeport;default;
- end;
- tportw = object
- procedure writeport(p : word;data : word);
- function readport(p : word) : word;
- property pp[w : word] : word read readport write writeport;default;
- end;
- tportl = object
- procedure writeport(p : word;data : longint);
- function readport(p : word) : longint;
- property pp[w : word] : longint read readport write writeport;default;
- end;
- var
- { we don't need to initialize port, because neither member
- variables nor virtual methods are accessed }
- port,
- portb : tport;
- portw : tportw;
- portl : tportl;
- const
- fpc_in_x86_inportb = fpc_in_cpu_first;
- fpc_in_x86_inportw = fpc_in_cpu_first+1;
- // fpc_in_x86_inportl = fpc_in_cpu_first+2;
- fpc_in_x86_outportb = fpc_in_cpu_first+3;
- fpc_in_x86_outportw = fpc_in_cpu_first+4;
- // fpc_in_x86_outportl = fpc_in_cpu_first+5;
- function inportb(port : word) : byte;[internproc:fpc_in_x86_inportb];
- function inportw(port : word) : word;[internproc:fpc_in_x86_inportw];
- //function inportl(port : word) : longint;[internproc:fpc_in_x86_inportl];
- procedure outportb(port : word;data : byte);[internproc:fpc_in_x86_outportb];
- procedure outportw(port : word;data : word);[internproc:fpc_in_x86_outportw];
- //procedure outportl(port : word;data : longint);[internproc:fpc_in_x86_outportl];
- implementation
- { to give easy port access like tp with port[] }
- procedure tport.writeport(p : word;data : byte);inline;
- begin
- outportb(p,data);
- end;
- function tport.readport(p : word) : byte;inline;
- begin
- readport:=inportb(p);
- end;
- procedure tportw.writeport(p : word;data : word);inline;
- begin
- outportw(p,data);
- end;
- function tportw.readport(p : word) : word;inline;
- begin
- readport:=inportw(p);
- end;
- {$asmcpu 80386}
- procedure tportl.writeport(p : word;data : longint);assembler;
- asm
- mov dx, p
- mov eax, data
- out dx, eax
- end;
- function tportl.readport(p : word) : longint;assembler;
- asm
- mov dx, p
- in eax, dx
- mov edx, eax
- shr edx, 16
- end;
- end.
|