Uses Crt, Dos; Const BaseAddress : Word = $350; IRQ = 5; Var IDIntVec : Procedure; IntOccurred : Boolean; Key : Char; LoopVar : Byte; ValueRead, ValueMask : Word; Function Deci(DS : String) : Word; Var BS : String; Er : Integer; DI : Word; Begin BS := '$' + DS; Val(BS, DI, Er); Deci := DI; End; Function Hex(BB : Word) : String; Var AA, CC : Byte; DD : String; HexTable : String; Begin HexTable := '0123456789ABCDEF'; DD := '000'; DD[3] := HexTable[(BB AND $00F) + 1]; DD[2] := HexTable[((BB AND $0F0) SHR 4) + 1]; DD[1] := HexTable[((BB AND $F00) SHR 8) + 1]; Hex := DD; End; Procedure ExitProgram(errorCode : Integer); Begin ClrScr; WriteLn('A fatal error occured, program halted!'); WriteLn('Error code returned was ', errorCode); End; function AskForBaseAddress(OldOne : String) : Word; const Msg : string[4] = '0'; var NewOne, Success, Dummy, Error : Word; AddrInputPosX, AddrInputPosY : Word; begin if (OldOne = 'OLD') then OldOne := Msg; WriteLn('Please enter the Base Address (0000-FFFF) for your card (in hex)'); WriteLn('or press ENTER for ', OldOne, '. '); Write('>'); AddrInputPosX := WhereX; AddrInputPosY := WhereY; repeat GotoXY(AddrInputPosX, AddrInputPosY); ClrEol; Readln(Msg); Val('$' + Msg, NewOne, Error); if (error=0) then begin Success := 1; Dummy := NewOne; end else if (Msg = '') then begin GotoXY(AddrInputPosX, AddrInputPosY); WriteLn(OldOne); Msg := OldOne; Success := 1; Val('$' + Msg, Dummy, Error); end; until (Success = 1); AskForBaseAddress := Dummy; end; { end of AskForBaseAddress } Procedure EnableMicroprocessor; Begin Port[BaseAddress + 5] := 0; End; Procedure DisableMicroprocessor; Var Hold : Byte; Begin Hold := Port[BaseAddress + 1]; End; {$F+} Procedure IDIInterrupt; interrupt; Begin IntOccurred := True; Port[$20] := $20; End; {$F-} Begin ClrScr; BaseAddress := AskForBaseAddress('350'); { Prompt for base addr } WriteLn('Pascal Language Sample for IDI-48 Option C. Version 1.00'); WriteLn; WriteLn; WriteLn('This sample will show option C''s functionality.'); WriteLn; WriteLn('IDI-48 Card setup:'); WriteLn(' Card is at base address ', Hex(BaseAddress), ' Hex.'); WriteLn(' Card is set at IRQ5.'); WriteLn(' MODE switch has switch 1 OFF and 2-5 ON.'); WriteLn; WriteLn('Press any key to continue... '); WriteLn; Key := ReadKey; Port[$21] := Port[$21] AND NOT(1 SHL IRQ); { Enable IRQ5 on motherboard } Port[$20] := $20; { Clear interrupts } GetIntVec(IRQ + 8, @IDIntVec); { Save old interrupt routine } SetIntVec(IRQ + 8, Addr(IDIInterrupt)); { Set to new interrupt routine } EnableMicroprocessor; ClrScr; Repeat GotoXY(1, 1); WriteLn('Toggle a bit on digital port 0. The microprocessor will'); WriteLn('detect a change of state and generate an interrupt on'); WriteLn('IRQ5. Press ESC to exit the program.'); Repeat Until (IntOccurred OR KeyPressed); If NOT IntOccurred Then { If no interrupt } Begin { check for exit } Key := ReadKey; If Key = #27 Then { If exit then. . . } Begin ClrScr; WriteLn('Exiting Sample 0 Program...'); { notify and. . . } Port[$21] := Port[$21] OR (1 SHL IRQ); { Disable IRQ5 } SetIntVec(IRQ+8,Addr(IDIntVec)); { Restore ISR } DisableMicroprocessor; { Disable processor } Exit; { Exit } End; End Else Begin { If one did occur } Sound(500); Delay(100); Nosound; GotoXY(1, 5); WriteLn('A bit of data port zero was toggled!'); WriteLn('It is now: '); ValueRead := PortW[BaseAddress]; For LoopVar := 0 To 15 Do Begin ValueMask := 1 SHL LoopVar; WriteLn(' Bit ', LoopVar, ' = ', Ord((ValueRead AND ValueMask) = ValueMask)); End; WriteLn; IntOccurred := False; EnableMicroprocessor; End; Until KeyPressed; End.