home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / CRT.SWG / 0002_Re: Using PORTS.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1996-02-21  |  2.2 KB  |  76 lines

  1. {
  2.    Direct port access
  3.    ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  4.   For access to the 80x86 CPU data ports, Borland Pascal implements two
  5.   predefined arrays, Port and PortW.
  6.  
  7.   Both are one-dimensional arrays, and each element represents a data port,
  8.   whose port address corresponds to its index.
  9.  
  10.   The index type is the integer type Word. Components of the port array are of
  11.   type Byte and components of the PortW array are of type Word.
  12.  
  13.   When a value is assigned to a component of Port or PortW, the value is
  14.   output to the selected port. When a component of Port or PortW is referenced
  15.   in an expression, its value is input from the selected port.
  16.  
  17.   Use of the Port and PortW arrays is restricted to assignment and reference
  18.   in expressions only; that is, components of Port and PortW cannot be used as
  19.   variable parameters. Also, references to the entire Port or PortW array
  20.   (reference without index) are not allowed.
  21.  
  22. Simply type "port", put the cursor on it, then press Ctrl+F1.
  23.  
  24. Reading a port (port nr. $378 in this case): x := Port[$378];
  25. Writing to that same port                  : Port[$378] := x
  26. in which X is a byte variable.
  27.  
  28. A colourful example:
  29. }
  30.  
  31. PROGRAM Playing_with_Ports;
  32.  
  33. {$X+}
  34.  
  35. USES Crt;
  36.  
  37. PROCEDURE SetVideomode(CONST mode: byte); ASSEMBLER;
  38. ASM mov AL, mode
  39.     xor AH, AH
  40.     int $10
  41. END;
  42.  
  43. PROCEDURE SetColor(CONST Color, Blue, Green, Red: byte);
  44. BEGIN port[$3C8] := Color;
  45.       port[$3C9] := Red;
  46.       port[$3C9] := Green;
  47.       port[$3C9] := Blue
  48. END;
  49.  
  50. { - Main: }
  51.  
  52. CONST Color_U_Want = Crt.Blue;  { -- Or whatever. }
  53.       pause        = 500;
  54.  
  55. VAR Red, Green, Blue: byte;
  56.  
  57. BEGIN SetVideomode(3);  { -- To be sure. }
  58.       TextBackground(Color_U_Want); clrscr;
  59.       gotoxy(20, 5); write('D a z z l i n g');
  60.       gotoxy(20, 7); write('      o r');
  61.       gotoxy(20, 9); write('    w h a t');
  62.       readkey;
  63.       randomize;
  64.       REPEAT SetColor(Color_U_Want, random(63), random(63), random(63));
  65.              delay(pause)
  66.       UNTIL keypressed;
  67.       delay(pause);
  68.       SetVideomode(3)
  69. END.
  70.  
  71. A list of what each port does can be found in Ralf Brown's Interrupt List
  72. (filenames INTERnnx.ZIP; "nn" = version number, currently 48, and "x" is a
  73. letter).
  74.  
  75.  
  76.