📄 plane.asm
字号:
MOUSE_BUT PROC FAR
;Test for right button pressed
PUSH AX
PUSH DS
PUSH AX
MOV AX,DATA
MOV DS,AX
POP AX
TEST AL,00001000B ;Test bit for right button
JNZ NEW_GAME ;The right button was pressed
LEFT_BUT:
CMP DS:PLANE_OFF,0
JNE END_BUT
MOV DS:PLANE_OFF,1 ;Set PLANE-off switch
MOV DS:GUN_FIRED,1 ;Set gun-fired switch
PUSH BX
PUSH CX
PUSH DX
;Test x coordinate for on-target
;On-target condition depends on the values assigned to the
;equate ON_Y and ON_X listed at the start of the code
MOV AX,DS:CROSS_X ;Cross hair x coordinate
MOV BX,DS:PLANE_X ;PLANE's x coordinate when gun was fired
SUB AX,ON_X ;To make range positive
;On target requires BX - AX < 2 * ON_X
SUB BX,AX ;Subtract to get BX-AX
JNC TEST_X_TARGET ;Continue testing if no carry
JMP NO_TARGET ;No target if AX > BX
TEST_X_TARGET:
MOV AX,ON_X2 ;Clear high-order element
CMP AX,BX ;AX must be larger
JC NO_TARGET
;Test y coordinate for on-target
MOV AX,DS:CROSS_Y ;Cross hair y coordinate
MOV BX,DS:PLANE_Y
SUB AX,ON_Y ;To make range positive
;On target requires BX - AX < 2 * ON_Y
SUB BX,AX ;Subtract to get BX-AX
JNC TEST_Y_TARGET ;Continue testing of no carry
JMP NO_TARGET ;No target if AX>BX
TEST_Y_TARGET:
MOV AX,ON_Y2
CMP AX,BX ;AX must be larget
JC NO_TARGET
;Procedure high frequency sound to indicate hit
MOV BX,HIT_FREQ ;3000-Hz frequency
MOV CX,HIT_DELAY
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
CALL SOUND ;Procedure from section 8.2.3
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
CALL XOR_PLANE
MOV DS:HIT_SW,1 ;Set switch for hit
MOV DS:PLANE_X,0
JMP EXIT_FIRED
;Procedure a low-frequency, shorter sound to indicate miss
NO_TARGET:
MOV BX,MISS_FREQ ;Set frequency
MOV CX,MISS_DELAY ;Set delay
CALL SOUND ;Procedure from section 8.2.3
MOV DS:HIT_SW,0 ;Set for missed
EXIT_FIRED:
POP DX
POP CX
POP BX
NEW_GAME:
MOV DS:PLANE_OFF,0
END_BUT:
POP DS
POP AX
QUIT:
RET
MOUSE_BUT ENDP
;------------------------------------------------------------------------------------------
;SOUND--Make a sound according to the frequency and delay
;On entry:
; BX: Sound frequency (for example,6000)
; CX: Sound delay (for example,1000)
;------------------------------------------------------------------------------------------
SOUND PROC NEAR
PUSH AX
PUSH DX
MOV DX,CX ;Sound duration
IN AL,61H ;Get port 61H
AND AL,11111100B ;AND off bits 0,1
TRIG:
XOR AL,2 ;Toggle bit 1
OUT 61H,AL ;Output to port 61h
MOV CX,BX ;Value of wait
DELAY:
LOOP DELAY ;Delay a while
DEC DX ;Turn on/off 1000 times
JNE TRIG
POP DX
POP AX
RET
SOUND ENDP
;------------------------------------------------------------------------------------------
KBR_STATUS PROC NEAR
MOV AH,1 ;BIOS service request numbers
INT 16H
JNZ PRESSED
;No key waiting
CLC
RET
PRESSED:
STC
RET
KBR_STATUS ENDP
;------------------------------------------------------------------------------------------
KBR_FLUSH PROC NEAR
;Flush old characters from keyboard buffer
FLUSH_1:
MOV AH,1 ;BIOS service request number
INT 16H
JZ NOCHAR ;OK to exit, buffer clear
;Flush old character
MOV AH,0 ;BIOS service request number
INT 16H
JMP FLUSH_1
NOCHAR:
CLC ;No error detection
RET
KBR_FLUSH ENDP
;------------------------------------------------------------------------------------------
KBR_WAIT PROC NEAR
;Wait for one keyboard character
;On exit:
; AL = keyboard character
; AH = keyboard scan code
MOV AH,0 ;Service request number
INT 16H
RET
KBR_WAIT ENDP
CODE ENDS
;******************************************************************************************
SSEG SEGMENT STACK
DB 0400H DUP('?') ;Default stack is 1K
STACK_TOP EQU THIS BYTE
SSEG ENDS
;******************************************************************************************
DATA SEGMENT
NUM_BUFFER DB 5 DUP(20H) ;5-digit buffer used by
DW 0 ;Conversion routines
;Graphics block message for the words Shooting PLANE
GALL_MS DB 2 ;开始行
DB 2 ;开始列
DB 10001110B ;颜色属性,闪烁的青色
DB ' W E L C O M T O ' ,0FFH,0FFH
DB 20H
;1
DB 20H
DB 20H
DB 20H
;2
DB 20H
DB ' T A N K E G A M E ' ,0FFH,0FFH
DB 20H
;3
DB 20H
DB 20H
DB 20H
;4
DB 20H
DB 20H
;5
DB 20H
DB ' T H A N K S F O R ' ,0FFH,0FFH
DB 20H
;6
DB 20H
DB 20H
DB ' Y O U R P L A Y I N G ',0FFH,0FFH
DB 00H
;Graphics block for the mouse drawing
MOU_MS DB 4 ;Start row
DB 58 ;Start column
DB 10000110B ;Color <<<********Edited********>>>
;Graphics encoding of a mouse using the IBM character set
DB 20H,0BFH,5 DUP(20H),0DAH,0FFH
DB 20H,0B3H,5 DUP(20H),0B3H,0FFH
DB 0C9H,0D8H,0CDH,0D1H,0CDH,0D1H,0CDH,0D8H,0BBH,0FFH
DB 0BAH,0B3H,20H,0B3H,20H,0B3H,20H,0B3H,0BAH,0FFH
DB 0C7H,0C4H,0C4H,0D9H,29H,0C0H,0C4H,0C4H,0B6H,0FFH
DB 0BAH,7 DUP(20H),0BAH,0FFH
DB 0BAH,20H,'Mouse',20H,0BAH,0FFH
DB 0BAH,7 DUP(20H),0BAH,0FFH
DB 0C8H,7 DUP(0CDH),0BCH,0FFH
DB 00H
;Instruction message displayed at top right of screen
TOP_MS DB 1 ;Start row
DB 50 ;Start column
DB 10001110B ;Color <<<*******edited*******>>>
DB 'I n s t r u c t i o n s',0FFH
DB ' <Esc> to END',0FFH
DB 'press to press to',0FFH
DB ' fire start game',0FFH
DB 00H
;Text message and graphics displayed at the scoreboard area
BOT_MS DB 15 ;Start row
DB 22 ;Start column
DB 10001110B ;Color
;
DB ' *** S C O R E B O A R D ***',0FFH,0FFH
DB ' game fired left score',0FFH
DB 20H,0C9H,7 DUP(0CDH),0CBH,7 DUP(0CDH),0CBH
DB 7 DUP(0CDH),0CBH,9 DUP(0CDH),0BBH,0FFH,0FFH
;
DB 20H,0C8H,7 DUP(0CDH),0CAH,7 DUP(0CDH),0CAH
DB 7 DUP(0CDH),0CAH,9 DUP(0CDH),0BCH,0FFH
DB 00H
;
DATA_LN DB 19 ;Start row
DB 22 ;Start column
DB 10001110B ;Color
;
DB 20H,0BAH,20H,20H
GAME DB '1',4 DUP(020H),0BAH,20H,20H
FIRED DB '0',4 DUP(020H),0BAH,20H,20H
LEFT DB '10',3 DUP(020H),0BAH,3 DUP(020H)
SCORE DB '0',5 DUP(20H),0BAH,00H
;Program controls
START_COL DB 0 ;Initial display column used
;by the GRAPHIC_TEXT procedure
GAME_CNT DB 0 ;Counter for game number
FIRE_CNT DB 10 ;Counter for rounds fired
SCORE_CNT DB 0 ;Game score counter
;Error message
BAD_MOUSE_MS DB 'Mouse is not operational $' ;Error message
;******************************************************************************************
;Parameter storage
;******************************************************************************************
OLD_VECTOR_1C DD 0 ;Pointer to original INT 1CH interrupt
;Operational variables
GUN_FIRED DB 0 ;Set by gun-fired handler
HIT_SW DB 0 ;Hit-or-miss switch, 1 = Hit
;Used by the VARI_PATTERN procedure
X_COORD DW 0000H ;Storage for x coordinate
BYTES DB 0H ;Number of bytes per block row
COUNT_8 DB 8 ;Operational bit counter
;------------------------------------------------------------------------------------------
;Graphics block area for cross-hair
;00000www|www00000 ---- 07E0H
;000w000w|000w0000 ---- 1110H
;00w0000w|0000w000 ---- 210BH
;0w00000w|00000w00 ---- 4104H
;w000000r|000000w0 ---- 8102H
;w000000r|000000w0 ---- 8102H
;w000000r|000000w0 ---- 8102H
;wwwwrrrr|rrrwwww0 ---- FFFEH
;w000000r|000000w0 ---- 8102H
;w000000r|000000w0 ---- 8102H
;w000000r|000000w0 ---- 8102H
;0w00000w|00000w00 ---- 4104H
;00w0000w|0000w000 ---- 2108H
;000w000w|000w0000 ---- 1110H
;0000wwww|www00000 ---- 07E0H
;
;Color code:
;For XORing with 00001000B (GRAY background)
;0:0000B = 0H (pixel is unchanged)
;w:1111B = FH (pixel is white)
;r:1100B = CH (pixel is red)
;
CROSS_X DW 320 ;Present x coordinate, range = 0 to 630
CROSS_Y DW 360 ;Present y coordinate, range = 360 to 460
DB 15 ;Horizontal rows in block
DB 2 ;Number of bytes per row
;Symbol encoding of cross-hair symbol
DB 07H,0E0H,11H,10H,21H,08H,41H,04H,81H,02H
DB 81H,02H,81H,02H,0FFH,0FFH,81H,02H,81H,02H
DB 81H,02H,41H,04H,21H,08H,11H,10H,07H,0E0H
DW 0000H ;Safety padding
;Color encoding of cross-hair symbol
CR_COL DB 0,0,0,0,0,0FH,0FH,0FH,0FH,0FH,0FH,0,0,0,0,0
DB 0,0,0,0FH,0,0,0,0FH,0,0,0,0FH,0,0,0,0
DB 0,0,0FH,0,0,0,0,0FH,0,0,0,0,0FH,0,0,0
DB 0,0FH,0,0,0,0,0,0FH,0,0,0,0,0,0FH,0,0
DB 0FH,0,0,0,0,0,0,0CH,0,0,0,0,0,0,0FH,0
DB 0FH,0,0,0,0,0,0,0CH,0,0,0,0,0,0,0FH,0
DB 0FH,0,0,0,0,0,0,0CH,0,0,0,0,0,0,0FH,0
DB 0FH,0FH,0FH,0CH,0CH,0CH,0CH,0CH,0CH,0CH,0CH,0CH,0FH,0FH,0FH,0
DB 0FH,0,0,0,0,0,0,0CH,0,0,0,0,0,0,0FH,0
DB 0FH,0,0,0,0,0,0,0CH,0,0,0,0,0,0,0FH,0
DB 0FH,0,0,0,0,0,0,0CH,0,0,0,0,0,0,0FH,0
DB 0,0FH,0,0,0,0,0,0FH,0,0,0,0,0,0FH,0,0
DB 0,0,0FH,0,0,0,0,0FH,0,0,0,0,0FH,0,0,0
DB 0,0,0,0FH,0,0,0,0FH,0,0,0,0FH,0,0,0,0
DB 0,0,0,0,0,0FH,0FH,0FH,0FH,0FH,0FH,0,0,0,0,0
;------------------------------------------------------------------------------------------
;Bit pattern for PLANE
PLANE_X DW 0
PLANE_Y DW 410
DB 12
DB 2
DB 00H, 0CH, 00H, 1EH, 00H, 1CH, 00H, 1CH
DB 00H, 1EH, 00H, 1EH, 06H, 0DFH, 07H, 0FFH
DB 37H, 0ECH, 7FH, 0CCH,0C7H, 8CH, 03H, 08H
DW 0000H
; Symbol encoding for PLANE
PLANE_COLOR DB 0FH
DB 0FH
DB 0FH
DB 0FH
DB 0FH
DB 16 DUP(0FH)
DB 16 DUP(0FH)
DB 16 DUP(0FH)
DB 16 DUP(0FH)
DB 16 DUP(0FH)
DB 16 DUP(0FH)
DB 0FH
DB 0FH
DB 0FH
DB 0FH
DB 0FH
FIRST_PLANE DB 1
PLANE_OFF DB 1
;******************************************************************************************
DATA ENDS
END START
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -