Àäàïòåð óïðàâëåíèÿ èãðàìè
Àäàïòåð óïðàâëåíèÿ èãðàìè
Àäàïòåð óïðàâëåíèÿ èãðàìè ïîäêëþ÷àåò ê ñèñòåìå äæîéñòèêè è äðóãèå
îðãàíû óïðàâëåíèÿ èãðîé. Ýòî âñå àíàëîãîâûå óñòðîéñòâà - ò.å., îíè
íå ìîãóò ðàáîòàòü ñ íóëÿìè è åäèíèöàìè. Èõ âõîäíûå çíà÷åíèÿ - ýòî
ñîïðîòèâëåíèå, êîòîðîå ÝÂÌ íå ìîæåò ïðî÷èòàòü íåïîñðåäñòâåííî.
Àäàïòåð óïðàâëåíèÿ èãðàìè ïðåîáðàçóåò çíà÷åíèå ñîïðîòèâëåíèÿ â
íå÷òî òàêîå, ñ ÷åì ÝÂÌ ìîæåò èìåòü äåëî.
Àäàïòåð óïðàâëåíèÿ èãðàìè íå ïðåîáðàçóåò çíà÷åíèå ñîïðîòèâëåíèÿ
íåïîñðåäñòâåííî â äâîè÷íîå ÷èñëî. Âìåñòî ýòîãî àäàïòåð ïðåîáðàçóåò
çíà÷åíèå ñîïðîòèâëåíèÿ âî âðåìåííóþ çàäåðæêó. ×åì áîëüøå
ñîïðîòèâëåíèå, òåì áîëüøå âðåìåííàÿ çàäåðæêà. Ýòó çàäåðæêó
êîìïüþòåð ìîæåò èçìåðèòü. Ïðåîáðàçîâàòü çàäåðæêó â ÷èñëî,
ñîîòâåòñòâóþùåå ïîëîæåíèþ äæîéñòèêà, ìîæíî ïðîãðàììíûì ñïîñîáîì.
Íàøåé çàäà÷åé ÿâëÿåòñÿ íàïèñàíèå ïðîãðàììû, êîòîðàÿ ïðåîáðàçóåò
âðåìåííóþ çàäåðæêó â ÷èñëî.
Àäàïòåð óïðàâëåíèÿ èãðàìè îáñëóæèâàåò äî ÷åòûðåõ âõîäîâ
ñîïðîòèâëåíèÿ. Ìåõàíèçì âðåìåííîé çàäåðæêè ïî êàæäîìó èç ýòèõ
âõîäîâ ïîäêëþ÷åí ê îòäåëüíîìó áèòó ïîðòà ââîäà-âûâîäà 201H. Êîãäà
âû âûâîäèòå ëþáîå ÷èñëî â ïîðò 201H, ÷åòûðå åãî ìëàäøèõ áèòà
ñáðàñûâàþòñÿ â 0. Áèòû âîçâðàùàþòñÿ â ñîñòîÿíèå 1 ïîñëå íåêîòîðãî
èíòåðâàëà âðåìåíè. Ýòîò èíòåðâàë âðåìåíè îïðåäåëÿåòñÿ çíà÷åíèåì
ñîïðîòèâëåíèÿ, ïîäêëþ÷åííîãî ê àäàïòåðó. Ïðîãðàììà íà Ôèã. 8.18 -
ýòî ïðèìåð îïðåäåëåíèÿ çíà÷åíèÿ ñîïðîòèâëåíèÿ äâóõ èç ÷åòûðåõ
âõîäíûõ ïîðòîâ. Ýòà ïðîãðàììà èñïîëüçóåò ïðîñòîé ìåòîä. Âìåñòî
îïðåäåëåíèÿ âðåìåííîé çàäåðæêè âñåõ ÷åòûðåõ ïîðòîâ îäíîâðåìåííî,
îíà îáñëóæèâàåò èõ ïîñëåäîâàòåëüíî. Êîëè÷åñòâî âðåìåíè, íóæíîãî äëÿ
îïðåäåëåíèÿ îäíîé çàäåðæêè, íåâåëèêî.  ðåçóëüòàòå, ïîî÷åðåäíàÿ
îáðàáîòêà ýòèõ çàäåðæåê âìåñòî îäíîâðåìåííîé âûïîëíÿåòñÿ áåç
ïðîáëåì.
Microsoft (R) Macro Assembler Version 5.00 1/1/80 04:05:57
Ôèã. 8.18 Àäàïòåð óïðàâëåíèÿ èãðàìè Page 1-1
PAGE ,132
TITLE Ôèã. 8.18 Àäàïòåð óïðàâëåíèÿ èãðàìè
= 0201 GAME_PORT EQU 201H
0000 STACK SEGMENT STACK
0000 0040[ DW 64 DUP (?)
????
]
0080 STACK ENDS
0000 CODE SEGMENT
ASSUME CS:CODE
0000 GAME_CONTROL PROC FAR
0000 1E PUSH DS ; Àäðåñ âîçâðàòà
0001 2B C0 SUB AX, AX
0003 50 PUSH AX
0004 BA 0201 MOV DX, GAME_PORT
0007 B8 B000 MOV AX, 0B000H ; Ñåãìåíò äèñïëåéíîé ïàìÿòè
000A 8E D8 MOV DS, AX
000C B5 21 MOV CH, 21H ; Ñèìâîë, êîòîðûé áóäåò çàïèñûâàòüñÿ â áóôåð
000E B1 00 MOV CL, 0
0010 WRITE_LOOP:
0010 B4 01 MOV AH, 1 ; Âûáîð êîîðäèíàòû X
0012 E8 0042 R CALL POSITION
0015 8B D8 MOV BX, AX ; Ñîõðàíåíèå êîîðäèíàòû X â áóôåðå
0017 D1 EB SHR BX, 1
0019 D1 EB SHR BX, 1 ; Äåëåíèå íà 4
Ôèã. 8.18 Àäàïòåð óïðàâëåíèÿ èãðàìè (íà÷àëî)
001B B4 02 MOV AH, 2 ; Âûáîð êîîðäèíàòû Y
001D E8 0042 R CALL POSITION
0020 D0 E8 SHR AL, 1
0022 D0 E8 SHR AL, 1
0024 D0 E8 SHR AL, 1
0026 D0 E8 SHR AL, 1 ; Äåëåíèå íà 16
0028 B4 A0 MOV AH, 160
002A F6 E4 MUL AH ; Ïðåîáðàçîâàíèå â ñìåùåíèå â áóôåðå
002C 03 D8 ADD BX, AX
002E 88 2F MOV [BX], CH ; Ñîõðàíåíèå ñèìâîëà
0030 EC IN AL, DX
0031 24 10 AND AL, 10H
0033 3A C1 CMP AL, CL
0035 74 D9 JE WRITE_LOOP
0037 8A C8 MOV CL, AL
0039 80 F9 10 CMP CL, 10H
003C 75 D2 JNE WRITE_LOOP
003E FE C5 INC CH ; Ñëåäóþùèé ñèìâîë
0040 EB CE JMP WRITE_LOOP
0042 GAME_CONTROL ENDP
;----- Â AH áèò ìàñêè
0042 POSITION PROC NEAR
0042 51 PUSH CX
0043 2B C9 SUB CX, CX ; Íà÷àëüíîå çíà÷åíèå äëÿ öèêëà ââîäà
0045 EE OUT DX, AL ; Çàïóñê òàéìåðà
0046 POS_LOOP:
0046 EC IN AL, DX
0047 84 C4 TEST AL, AH
0049 E0 FB LOOPNE POS_LOOP ; Öèêë ïîêà 1 - òàéìåð íå çàêîí÷èë îòñ÷åò
004B B8 0000 MOV AX, 0
004E 2B C1 SUB AX, CX ; Îïðåäåëåíèå çíà÷åíèÿ ñ÷åò÷èêà
0050 59 POP CX ; â äèàïàçîíå 0-255
0051 C3 RET
0052 POSITION ENDP
0052 CODE ENDS
END
Ôèã. 8.18 Àäàïòåð óïðàâëåíèÿ èãðàìè (ïðîäîëæåíèå)
Ïîñëåäíÿÿ ÷àñòü ïðîãðàììû íà Ôèã. 8.18 áåðåò ïîçèöèþ X-Y,
îïðåäåëåííóþ ïî âõîäó îò äæîéñòèêà, è çàïèñûâàåò ñèìâîë â
ñîîòâåòñòâóþùóþ ïîçèöèþ äèñïëåÿ. Àäàïòåð óïðàâëåíèÿ èãðàìè òàêæå
äîïóñêàåò ÷åòûðå ïåðåêëþ÷àþùèõ ââîäà, çíà÷åíèÿ êîòîðûõ ìîæíî
ïðî÷èòàòü â ñòàðøèõ ÷åòûðåõ áèòàõ ïîðòà 201H. Ïðîãðàììà â ïðèìåðå
îïðàøèâàåò îäèí èç ýòèõ áèòîâ ïåðåêëþ÷åíèÿ, ÷òîáû ïåðåéòè îò îäíîãî
ñèìâîëà ê äðóãîìó è âûâåñòè åãî íà ýêðàí.