Code segment
Code segment
Assume DS: Data, CS: CODE
Main Proc Far
Main program
Start:
Call init; calling initializer
NEW_SCAN:
Call scan_key; scanning the key pressed
CMP SONG, 100; Judging whether the song key is pressed
JE HAND_PLAY; if not, continue to judge
Call play_song; if it is playing music
JMP new_scan; the end of performance, rescan the key to press
HAND_PLAY:
CMP Keynum, 100; judgment if manual performance
JZ new_scan; if not, rescan the key to press
If yes, do button processing
Push bx
MOV BX, Keynum
Call key_down; display the state on the screen
POP BX
Call load_audio; judge the high and low, C / D adjustment, and load the corresponding frequency segment address to BX
Push Si
Mov Si, Keynum
MOV Di, [BX Si]
Call gen_hand; vocal
POP Si
Push bx
MOV BX, Keynum; Displayed on the screen
Call Key_up
POP BX
JMP new_scan; rescan all-purpose press until you press the ESC button
Main endp
Gen_Hand Proc Near
; Manual playing programs
; In: di
Push AX
Push bx
PUSH CX
Push dx
Push di
MOV Al, 0B6H; Timer initialization
OUT 43H, Al
MOV DX, 12H
MOV AX, 348CH
DIV DI
OUT 42H, Al; timer delivery value
IN AL, 61H; open speaker
MOV
Al
AH
OUT 42H, Al
IN AL, 61H
Mov Ah,
Al
Oral
Al
3
OUT 61H, Al
Wait1:
Call waitf; call delay
IN Al, 60h
Test Al, 80h; whether the query key is released
JZ WAIT1; Unseeded Continue Query
MOV Al, AH; release of the speaker OUT 61H, Al
POP DI
POP DX
POP CX
POP BX
POP AX
RET
Gen_hand endp
Gen_Auto Proc Near
Automatic playing voice program
Push AX
Push bx
PUSH CX
Push dx
Push di
MOV
Al
0B6H
OUT 43H, Al
MOV DX, 12H
MOV AX, 348CH
DIV DI
OUT 42H, Al
IN AL, 61H
MOV
Al
AH
OUT 42H, Al
IN AL, 61H
Mov Ah,
Al
Oral
Al
3
OUT 61H, Al
Wait2:
Call Waitf
Dec BX
JNZ WAIT2; Judging whether it is played
MOV Al, AH; Turn the speaker
OUT 61H, Al
POP DI
POP DX
POP CX
POP BX
POP AX
RET
Gen_Auto ENDP
Waitf proc near
Delayed procedure
Push AX
MOV CX, DELAY_TIME
Waitf1:
IN AL, 61H
And Al, 10h; Check PB4 port
CMP AL, AH; Judgment Al changed
JE WAITF1; Waiting for Al Change
MOV AH, Al; save the new state of PB4 (in Al)
Loop
Waitf1
POP AX
RET
WAITF ENDP
Piano_Draw proc Near
Draw the key
LEA SI, ST_LX; load white starting point address
Lea di, ed_lx; load white endpoint address
MOV CX, 21; Number of white bonds
Next_draw:
Draw [Si], ST_Y, [DI], ED_Y, 0FH; call macro definition painting white key
Draw [Si], 90, [Di], 93, 07h; Shadow
Add Si, 2; Next button
Add di, 2
Loop
Next_draw
Lea Si, BT_X; load black start point address
Lea Di, BD_X; load black endpoint address
MOV CX, 15; Number of black keys
Next_block:
Draw [Si], BT_Y, [DI], BD_Y, 00H
Add Si, 2
Add di, 2
Loop
Next_block
RET
PIANO_DRAW ENDP
Key_Down Proc Near
; When the key is pressed, display it on the screen.
Push Si
Push di
Call load; Load Press button on the screen DRAW [Si BX], 90, [DI BX], 92, 0FH
Draw [Si BX], 92, [DI BX], 94, 07H
POP DI
POP Si
RET
Key_Down ENDP
Key_up Proc Near
Key to restore normal status
Push Si
Push di
Call load; Load the position of the bounce button on the screen
Draw [Si BX], 90, [DI BX], 93, 07H; Restore Shadow
Draw [Si BX], 93, [DI BX], 94, 05H; Restore Background Color
POP DI
POP Si
RET
Key_up Endp