Moduł obsługi portu joysticka [1] - należy skompilować do formatu joystick.tpu unit joystick; interface const port1_x = 1; button1 = 1; port1_y = 2; button2 = 2; port2_x = 4; button3 = 4; port2_y = 8; button4 = 8; function readvalue (resistor: integer) : integer; function readbutton: integer; function testbutton (button: integer) : boolean; implementation function readvalue; begin inline ( $8b/$46/$06/{ mov ax, [bp+6]; } $24/$0f/ { and al,Ofh; } $8a/$d8/ { mov bl,al; } $33/$c9/ { xor cx, cx; } $ba/$01/$02/{ cli; } $ec/ {hop1: in al,dx; } $84/$c3/ { test bl,al;} $74/$04/ { je hop2;} $e2/$f9/ { loop hop1;} $eb/$13/ { jmp end;} $ee/ {hop2: out dx,al; } $ec/ { in al, dx; } $84/$c3/ { test bl,al; } $74/$FA/ { je hop2; } $33/$c9/ { xor cx,cx; } $ec/ {hop3: in al,dx; } $84/$C3/ { test bl, al; } $74/$04/ { je hop4; } $E2/$F9/ { lopp hop3; } $EB/$02/ { jmp end; } $F7/$D9/ {hop4: neg cx; } $FB/ {end: sti; } $89/$4e/$fe){ mov [bd-2],cx; } end; function ReadButton; begin inline ( $ba/$01/$02/ { mov dx,201h; } $ec/ { in al,dx ; } $d0/$e8/ { shr al,1 ; } $d0/$e8/ { shr al,1 ; } $d0/$e8/ { shr al,1 ; } $d0/$e8/ { shr al,1 ; } $34/$0F/ { xor al,0fh; } $32/$e4/ { xor al,ah; } $89/$46/$fe ) { mov [bp-2],ax; } end; function TestButton; begin TestButton:=Boolean(ReadButton and Button); end; end. Program główny [2] PROGRAM wahadlo; USES Crt,Joystick; CONST delta_t = 0.838097E-6; czulosc = 120; VAR dos_t :LONGINT ABSOLUTE $0040:$006C; start_czas :LONGINT; i :INTEGER; czas :REAL; time :array[1..40] of REAL; PROCEDURE start_stoper; BEGIN ASM MOV AL, $34 OUT $43, AL SUB AX, AX OUT $40, AL OUT $40, AL END; start_czas:=dos_t; END{start_stoper}; PROCEDURE odczyt_czasu(VAR ile_zliczen:WORD;VAR czas:LONGINT); VAR c:WORD; BEGIN ASM MOV AL, $00 OUT $43, AL IN AL, $40 MOV DL, AL IN AL, $40 MOV DH, AL MOV c, DX END; ile_zliczen:=c; czas:=dos_t; END{odczyt_czasu}; PROCEDURE stop_stoper (VAR czas:REAL); VAR ile_zliczen:WORD; stop_czas:LONGINT; BEGIN odczyt_czasu(ile_zliczen,stop_czas); czas:=delta_t*((65536 - ile_zliczen)+65536*(stop_czas-start_czas)); END{stop_stoper}; PROCEDURE tabela; BEGIN WriteLN; WriteLN (' n t(s)'); WriteLN; WriteLN ('10'); WriteLN; WriteLN ('20'); WriteLN ; WriteLN ('30'); WriteLN; WriteLN ('40'); WriteLN; END {tabela}; PROCEDURE pomiar; BEGIN Repeat Until ReadValue(2)>czulosc; start_stoper; While Not KeyPressed do Begin i:=i+1; Repeat Until ReadValue(1)>czulosc; Repeat Until ReadValue(2)>czulosc; stop_stoper(czas); GoToXY (2,12); Write ('Liczba drgan : ',i); time[i]:=czas; GoToXY (8,2+Trunc(i*0.2)); If i=10 Then Write(time[10]:1:1) else If i=20 Then Write(time[20]:1:1) else If i=30 Then Write(time[30]:1:1) else If i=40 Then Write(time[40]:1:1) else If i>40 Then exit End; END {pomiar}; BEGIN i:=0; ClrScr; tabela; pomiar; Repeat Until Keypressed; END.