18.10.2014 Views

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

308 System programm<strong>in</strong>g<br />

A program to pr<strong>in</strong>t the current time of day <strong>in</strong> hours, m<strong>in</strong>utes and seconds <strong>in</strong> a programm<strong>in</strong>g runn<strong>in</strong>g under the<br />

DOS operat<strong>in</strong>g system is as follows:<br />

with System, System.Storage_Elements,<br />

<strong>Ada</strong>.Text_Io, <strong>Ada</strong>.Integer_Text_Io;<br />

use System, System.Storage_Elements,<br />

<strong>Ada</strong>.Text_Io, <strong>Ada</strong>.Integer_Text_Io;<br />

procedure Ma<strong>in</strong> is<br />

Time_High_Address : constant Address := To_Address( 16#046C# );<br />

Time_Low_Address : constant Address := To_Address( 16#046E# );<br />

type Seconds_T is range 0 .. 1_000_000_000; --up to 65k * 5<br />

type Time is range 0 .. 65365; --Unsigned<br />

for Time'Size use 16;<br />

-- <strong>in</strong> 2 bytes<br />

Time_Low : Time;<br />

for Time_Low'Address use Time_High_Address;<br />

Time_High: Time;<br />

for Time_High'Address use Time_Low_Address;<br />

Seconds : Seconds_T;<br />

beg<strong>in</strong><br />

Put("Time is ");<br />

Put( Time'Image(Time_High) ); Put(" :"); --Hour<br />

Seconds := (Seconds_T(Time_Low) * 5) / 91;<br />

Put(Seconds_T'Image(Seconds/60)); Put(" :"); --M<strong>in</strong>s<br />

Put(Seconds_T'Image(Seconds rem 60)); --Seconds<br />

New_L<strong>in</strong>e;<br />

end Ma<strong>in</strong>;<br />

which when run on a DOS system would produce output of the form:<br />

Time is 17 : 54 : 57<br />

Note:<br />

For this to work, the generated code must be able to access these low locations <strong>in</strong> DOS.<br />

21.2.1 Access to <strong>in</strong>dividual bits<br />

On an MS DOS system memory address 16#0417# conta<strong>in</strong>s the status of various keyboard sett<strong>in</strong>gs. Individual<br />

bits <strong>in</strong> this byte <strong>in</strong>dicate the sett<strong>in</strong>gs (set or not set) for the scroll lock, number lock, caps and <strong>in</strong>sert keys. The<br />

layout of this byte is illustrated <strong>in</strong> Figure 21.1.<br />

Most significant<br />

Bit position<br />

Least significant<br />

7 6 5 4 3 2 1 0<br />

Insert<br />

Caps<br />

lock<br />

Number<br />

lock<br />

Scroll<br />

lock<br />

Figure 21.1 Keyboard status on an MSDOS system.<br />

© M A Smith - May not be reproduced without permission

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!