使用 8086 汇编器 TASM 项目协助闪烁/毛刺像素

问题描述

我创建了一个虚拟钢琴,能够弹奏一个完整的八度音程(可以选择使用 + 和 - 将八度音程提高两次),但我的问题不在于音频,而在于图形。我的程序正在运行一个图形程序,它基本上绘制白色方块,绘制黑色线条以分隔音符,然后打印小字母以帮助用户知道哪个字母激活哪个键,以及黑色音符本身。完成纯图形部分后,我开始研究 RecieveKey proc,我完成了 proc 的编写,一切正常,你可以用字母 SL 激活所有 8 个白色音符,用 E、R、Y、U 激活所有黑色音符,一世。但我遇到了一个非常烦人的“错误”。按下键盘上的键后,音符变为灰色,0.746 秒后变回白色。但是有一个我似乎无法解决的闪烁/毛刺奇怪的问题。我将在这里粘贴完整的代码,有人可以帮助我理解为什么会这样吗?

; Play white keys with S,D,F,G,H,J,K,Left
; Play black keys with E,R,Y,U,I
; Go up octave with +
; Go down octave with -
; Press ESC to end
IDEAL
MODEL small
STACK 100h
DATASEG
; --------------------------
; Your variables here
    x dw 0; position of X
    y dw 0; position of Y
    color1 dw 00007h ; Gray
    color3 dw 0000h; Black Color
    CorrentOctave db 31h; Starts at Octave n1:
    Linex dw 0; position of X of line
    Column db 0; Position of Column
    Row db 0; Position of Row
    Letter db 0; Letter
; --------------------------
CODESEG
; ------------------------------------------------------------------------------------------------------------------------------------------
proc Graphic
    xor ax,ax
    xor dx,dx
    xor cx,cx
    mov ax,13h
    int 10h     ;Moving to graphic mode
    call PrintWhite
    call PrintBlackLines
    call PrintLetterNotes
    call PrintBlackKeys
    call PrintFix
    call PrintCorrentOctave

    ret
endp Graphic
; --------------------------
proc PrintPixel ;This procedure Receives parameters of x and y and a colour and prints a pixel on the screen
    push bp
    mov bp,sp
    push cx
    mov ax,[bp+4]  ;Colour of the pixel
    mov dx,[bp+6]  ;Y parameter of the pixel
    mov cx,[bp+8]  ;X parameter of the pixel
    mov bh,0h      ;Page,should be 0
    mov ah,0ch
    int 10h         ;Pixel draw interrupt
    pop cx
    pop bp
    ret 6
endp PrintPixel
; --------------------------
proc PrintWhite ;This procedure prints a 120x320 white rectangle
    mov [x],0
    mov [y],50
PrintLine1:
    push [x]
    push [y]
    push 0000Fh; White Color
    call PrintPixel
    cmp [x],320
    jne PrintLine2
    cmp [y],170
    jne PrintLine3
    ret
PrintLine2:
    inc [x]
    jmp PrintLine1
PrintLine3:
    mov [x],0
    inc [y]
    jmp PrintLine1
    
endp PrintWhite
; --------------------------
proc PrintBlackLines ;This procedure will print the black lines seperating the white keys every 20 pixels.
    mov [Linex],40
    call PrintBlackLine1
    mov [Linex],80
    call PrintBlackLine1
    mov [Linex],120
    call PrintBlackLine1
    mov [Linex],160
    call PrintBlackLine1
    mov [Linex],200
    call PrintBlackLine1
    mov [Linex],240
    call PrintBlackLine1
    mov [Linex],280
    call PrintBlackLine1
endp PrintBlackLines

proc PrintBlackLine1 ; this procedure will print the first black line seperating keys.
    mov ax,[Linex]
    mov [x],ax
    mov [y],50
FirstBlack1:
    push [x]
    push [y]
    push 0000h; Black Color
    call PrintPixel
    cmp [y],170
    jne FirstBlack2
    ret
FirstBlack2:
    inc [y]
    jmp FirstBlack1
endp PrintBlackLine1
; --------------------------
; --------------------------
proc PrintBlackKeys; this procedure will print all the 6 black keys on the piano
    call PrintBlackKey1
    call PrintBlackKey2
    call PrintBlackKey3
    call PrintBlackKey4
    call PrintBlackKey5
endp PrintBlackKeys

proc PrintBlackKey1; this procedure will print the first black key.
    mov [x],30
    mov [y],50
FirstBlackKey1:
    push [x]
    push [y]
    push [color3]; Black Color
    call PrintPixel
    cmp [x],45
    jne FirstBlackKey2
    cmp [y],110
    jne FirstBlackKey3
    ret
FirstBlackKey2:
    inc [x]
    jmp FirstBlackKey1
FirstBlackKey3:
    mov [x],30
    inc [y]
    jmp FirstBlackKey1
endp PrintBlackKey1

proc PrintBlackKey2; this procedure will print the Second black key.
    mov [x],70
    mov [y],50
SecondBlackKey1:
    push [x]
    push [y]
    push [color3]; Black Color
    call PrintPixel
    cmp [x],85
    jne SecondBlackKey2
    cmp [y],110
    jne SecondBlackKey3
    ret
SecondBlackKey2:
    inc [x]
    jmp SecondBlackKey1
SecondBlackKey3:
    mov [x],70
    inc [y]
    jmp SecondBlackKey1
endp PrintBlackKey2

proc PrintBlackKey3; this procedure will print the third black key.
    mov [x],150
    mov [y],50
ThirdBlackKey1:
    push [x]
    push [y]
    push [color3]; Black Color
    call PrintPixel
    cmp [x],165
    jne ThirdBlackKey2
    cmp [y],110
    jne ThirdBlackKey3
    ret
ThirdBlackKey2:
    inc [x]
    jmp ThirdBlackKey1
ThirdBlackKey3:
    mov [x],150
    inc [y]
    jmp ThirdBlackKey1
endp PrintBlackKey3

proc PrintBlackKey4; this procedure will print the Fourth black key.
    mov [x],190
    mov [y],50
ForthBlackKey1:
    push [x]
    push [y]
    push [color3]; Black Color
    call PrintPixel
    cmp [x],205
    jne ForthBlackKey2
    cmp [y],110
    jne ForthBlackKey3
    ret
ForthBlackKey2:
    inc [x]
    jmp ForthBlackKey1
ForthBlackKey3:
    mov [x],190
    inc [y]
    jmp ForthBlackKey1
endp PrintBlackKey4

proc PrintBlackKey5; this procedure will print the Fifth black key.
    mov [x],230
    mov [y],50
FifthBlackKey1:
    push [x]
    push [y]
    push [color3]; Black Color
    call PrintPixel
    cmp [x],245
    jne FifthBlackKey2
    cmp [y],110
    jne FifthBlackKey3
    ret
FifthBlackKey2:
    inc [x]
    jmp FifthBlackKey1
FifthBlackKey3:
    mov [x],230
    inc [y]
    jmp FifthBlackKey1
endp PrintBlackKey5
; -------------------------
proc PrintFix
    mov [x],171
PrintFix1:
    push [x]
    push [y]
    push 0000h; Black Color
    call PrintPixel
    ret
endp PrintFix
; --------------------------
proc PrintLetterNotes ; this procedure will print a letter on each note so the user can know which key in the keyboard activates each note
    mov [Column],2
    mov [Row],22
    mov [Letter],53h
    call PrintLetter ; Letter S
    mov [Column],7
    mov [Row],44h ; Letter D
    call PrintLetter
    mov [Column],12
    mov [Row],46h ; Letter F
    call PrintLetter
    mov [Column],17
    mov [Row],47h ; Letter G
    call PrintLetter
    mov [Column],22
    mov [Row],48h ; Letter H
    call PrintLetter
    mov [Column],27
    mov [Row],4Ah ; Letter J
    call PrintLetter
    mov [Column],32
    mov [Row],4Bh ; Letter K
    call PrintLetter
    mov [Column],37
    mov [Row],4Ch ; Letter L
    call PrintLetter
    mov [Column],4
    mov [Row],5
    mov [Letter],45h ; Letter E
    call PrintLetter
    mov [Column],9
    mov [Row],52h ; Letter R
    call PrintLetter
    mov [Column],19
    mov [Row],59h ; Letter Y
    call PrintLetter
    mov [Column],24
    mov [Row],55h ; Letter U
    call PrintLetter
    mov [Column],29
    mov [Row],49h ; Letter I
    call PrintLetter
        mov [Column],2
    mov [Letter],4Fh ; Letter O
    call PrintLetter
    mov [Column],3
    mov [Row],63h ; Letter c
    call PrintLetter
    mov [Column],74h ; Letter t
    call PrintLetter
    mov [Column],5
    mov [Row],61h ; Letter a
    call PrintLetter
    mov [Column],6
    mov [Row],76h ; Letter v
    call PrintLetter
    mov [Column],65h ; Letter e
    call PrintLetter
    mov [Column],8
    mov [Row],3Ah ; Char :
    call PrintLetter
    ret
endp PrintLetterNotes
; --------------------------
proc PrintLetter ; prints letter 
    mov  dl,[Column]   ;Column
    mov  dh,[Row]   ;Row
    mov  bh,0    ;Display page
    mov  ah,02h  ;SetCursorPosition
    int  10h

    mov  al,[Letter]
    mov  bl,000Fh  ;Color is White
    mov  bh,0Eh  ;Teletype
    int  10h
    ret
endp PrintLetter
; ------------------------
proc PrintCorrentOctave
    mov  dl,9  ;Column
    mov  dh,2   ;Row
    mov  bh,[CorrentOctave]
    mov  bl,0Eh  ;Teletype
    int  10h
    ret
endp PrintCorrentOctave
; ----------------------------------------------------------------------------------------------
proc ReceiveKey ;This procedure Receives a key from the keyboard and matches it to a note
ReceiveKey: 
    
    mov ah,0
    Int 16h
    cmp al,73h                 ;S on the keyboard (WHITE)
    je FirstWhiteKey
    cmp al,64h                 ;D on the keyboard (WHITE)
    je SecondWhiteKey
    cmp al,66h                 ;F on the keyboard (WHITE)
    je ThirdWhiteKey
    cmp al,67h                 ;G on the keyboard (WHITE)
    je FourthWhiteKey
    cmp al,68h                 ;H on the keyboard (WHITE)
    je FifthWhiteKey
    cmp al,6Ah                 ;J on the keyboard (WHITE)
    je SixthWhiteKey
    cmp al,6Bh                 ;K on the keyboard (WHITE)
    je SeventhWhiteKey
    cmp al,6Ch                 ;L on the keyboard (WHITE)
    je EighthWhiteKey
    cmp al,65h                 ;E on the keyboard (BLACK)
    je FirstBlackKey
    cmp al,72h                 ;R on the keyboard (BLACK)
    je SecondBlackKey
    cmp al,79h                 ;Y on the keyboard (BLACK)
    je ThirdBlackKey
    cmp al,75h                 ;U on the keyboard (BLACK)
    je FourthBlackKey
    cmp al,69h                 ;I on the keyboard (BLACK)
    je FifthBlackKey
    cmp al,2Dh           ;Arrow Left on the keyboard (octave Dec)
    je OctaveDec
    cmp al,3Dh              ;Arrow Right on the keyboard (octave inc)
    je OctaveInc
    cmp al,1Bh                 ;ESC on the keyboard (CLOSE)
    je EndOfProc
    
    
    jmp ReceiveKey

FirstWhiteKey:
    ;call FirstWhiteKeyMusic
    call FirstWhiteKeyPaint 
    jmp ReceiveKey
SecondWhiteKey:
    ;call SecondWhiteKeyMusic
    call SecondWhiteKeyPaint 
    jmp ReceiveKey
    
ThirdWhiteKey:
    ;call SecondWhiteKeyMusic
    call ThirdWhiteKeyPaint 
    jmp ReceiveKey

FourthWhiteKey:
    ;call FourthWhiteKeyMusic
    call FourthWhiteKeyPaint 
    jmp ReceiveKey

FifthWhiteKey:
    ;call FourthWhiteKeyMusic
    call FifthWhiteKeyPaint 
    jmp ReceiveKey
    
SixthWhiteKey:
    ;call FourthWhiteKeyMusic
    call SixthWhiteKeyPaint 
    jmp ReceiveKey

SeventhWhiteKey:
    ;call FourthWhiteKeyMusic
    call SeventhWhiteKeyPaint 
    jmp ReceiveKey
    
EighthWhiteKey:
    ;call FourthWhiteKeyMusic
    call EighthWhiteKeyPaint 
    jmp ReceiveKey
FirstBlackKey:
    ;call FirstWhiteKeyMusic
    call FirstBlackKeyPaint 
    jmp ReceiveKey
SecondBlackKey:
    ;call FirstWhiteKeyMusic
    call SecondBlackKeyPaint 
    jmp ReceiveKey
ThirdBlackKey:
    ;call FirstWhiteKeyMusic
    call ThirdBlackKeyPaint 
    jmp ReceiveKey
FourthBlackKey:
    ;call FirstWhiteKeyMusic
    call FourthBlackKeyPaint 
    jmp ReceiveKey
FifthBlackKey:
    ;call FirstWhiteKeyMusic
    call FifthBlackKeyPaint 
    jmp ReceiveKey
    
EndOfProc:
    jmp exit
    
endp ReceiveKey
; --------------------------
proc OctaveInc
    cmp [CorrentOctave],33h
    jne OctaveInc1
    jmp ReceiveKey
OctaveInc1:
    inc [CorrentOctave]
    call PrintCorrentOctave
    jmp ReceiveKey
endp OctaveInc

proc OctaveDec
    cmp [CorrentOctave],31h
    jne OctaveDec1
    jmp ReceiveKey
OctaveDec1:
    dec [CorrentOctave]
    call PrintCorrentOctave
    jmp ReceiveKey
endp OctaveDec
; --------------------------
proc FirstWhiteKeyPaint ; paints the first white key in gray 
    mov [x],50
FirstWhiteKeyPaintBig: ;paints the big rectangle on the first white key in gray
    push [x]
    push [y]
    push [color1]
    call PrintPixel
    cmp [x],29
    jne FirstWhiteBig1
    cmp [y],170
    jne FirstWhiteBig2
    mov [x],111
    jmp FirstWhiteKeyPaintSmall
FirstWhiteBig1:
    inc [x]
    jmp FirstWhiteKeyPaintBig
FirstWhiteBig2:
    inc [y]
    mov [x],0
    jmp FirstWhiteKeyPaintBig
FirstWhiteKeyPaintSmall: ;Paints the small rectangle on the first white key gray
    push [x]
    push [y]
    push [color1]
    call PrintPixel
    cmp [x],39
    jne FirstWhiteSmall1
    cmp [y],170
    jne FirstWhiteSmall2
    mov  cx,6h
    mov  dx,4240h
    mov  ah,86h
    int  15h
    cmp [color1],00007h
    je ChangeToWhite1
    mov [color1],00007h
    call ReceiveKey
ChangeToWhite1:
    mov [color1],0000Fh
    call FirstWhiteKeyPaint
    
FirstWhiteSmall1:
    inc [x]
    jmp FirstWhiteKeyPaintSmall
FirstWhiteSmall2:
    inc [y]
    mov [x],30
    jmp FirstWhiteKeyPaintSmall
    
endp FirstWhiteKeyPaint
; --------------------------
proc SecondWhiteKeyPaint ; paints the Second white key in gray 
    mov [x],41
    mov [y],111
SecondWhiteKeyPaintBig: ;paints the big rectangle on the Second white key in gray
    push [x]
    push [y]
    push [color1]
    call PrintPixel
    cmp [x],79
    jne SecondWhiteBig1
    cmp [y],170
    jne SecondWhiteBig2
    mov [x],46
    mov [y],50
    jmp SecondWhiteKeyPaintSmall
SecondWhiteBig1:
    inc [x]
    jmp SecondWhiteKeyPaintBig
SecondWhiteBig2:
    inc [y]
    mov [x],41
    jmp SecondWhiteKeyPaintBig
SecondWhiteKeyPaintSmall: ;Paints the small rectangle on the Second white key gray
    push [x]
    push [y]
    push [color1]
    call PrintPixel
    cmp [x],69
    jne SecondWhiteSmall1
    cmp [y],111
    jne SecondWhiteSmall2
    mov  cx,00007h
    je ChangeToWhite2
    mov [color1],00007h
    call ReceiveKey
ChangeToWhite2:
    mov [color1],0000Fh
    call SecondWhiteKeyPaint
SecondWhiteSmall1:
    inc [x]
    jmp SecondWhiteKeyPaintSmall
SecondWhiteSmall2:
    inc [y]
    mov [x],46
    jmp SecondWhiteKeyPaintSmall
endp SecondWhiteKeyPaint
; --------------------------
proc ThirdWhiteKeyPaint ; paints the Third white key in gray 
    mov [x],81
    mov [y],111
ThirdWhiteKeyPaintBig: ;paints the big rectangle on the Third white key in gray
    push [x]
    push [y]
    push [color1]
    call PrintPixel
    cmp [x],119
    jne ThirdWhiteBig1
    cmp [y],170
    jne ThirdWhiteBig2
    mov [x],86
    mov [y],50
    jmp ThirdWhiteKeyPaintSmall
ThirdWhiteBig1:
    inc [x]
    jmp ThirdWhiteKeyPaintBig
ThirdWhiteBig2:
    inc [y]
    mov [x],81
    jmp ThirdWhiteKeyPaintBig
    
ThirdWhiteKeyPaintSmall: ;Paints the small rectangle on the Third white key gray
    push [x]
    push [y]
    push [color1]
    call PrintPixel
    cmp [x],119
    jne ThirdWhiteSmall1
    cmp [y],110
    jne ThirdWhiteSmall2
    mov  cx,00007h
    je ChangeToWhite3
    mov [color1],00007h
    call ReceiveKey
ChangeToWhite3:
    mov [color1],0000Fh
    call ThirdWhiteKeyPaint
ThirdWhiteSmall1:
    inc [x]
    jmp ThirdWhiteKeyPaintSmall
ThirdWhiteSmall2:
    inc [y]
    mov [x],86
    jmp ThirdWhiteKeyPaintSmall
endp ThirdWhiteKeyPaint;
; -------------------------

proc FourthWhiteKeyPaint ; paints the Fourth white key in gray 
    mov [x],121
    mov [y],50
FourthWhiteKeyPaintBig: ;paints the big rectangle on the Fourth white key in gray
    push [x]
    push [y]
    push [color1]
    call PrintPixel
    cmp [x],149
    jne FourthWhiteBig1
    cmp [y],170
    jne FourthWhiteBig2
    mov [x],149
    mov [y],111
    jmp FourthWhiteKeyPaintSmall
FourthWhiteBig1:
    inc [x]
    jmp FourthWhiteKeyPaintBig
FourthWhiteBig2:
    inc [y]
    mov [x],121
    jmp FourthWhiteKeyPaintBig
FourthWhiteKeyPaintSmall: ;Paints the small rectangle on the Fourth white key gray
    push [x]
    push [y]
    push [color1]
    call PrintPixel
    cmp [x],159
    jne FourthWhiteSmall1
    cmp [y],170
    jne FourthWhiteSmall2
    mov  cx,00007h
    je ChangeToWhite4
    mov [color1],00007h
    call ReceiveKey
ChangeToWhite4:
    mov [color1],0000Fh
    call FourthWhiteKeyPaint
    
FourthWhiteSmall1:
    inc [x]
    jmp FourthWhiteKeyPaintSmall
FourthWhiteSmall2:
    inc [y]
    mov [x],121
    jmp FourthWhiteKeyPaintSmall
    
endp FourthWhiteKeyPaint
; --------------------------
proc FifthWhiteKeyPaint ; paints the Fifth white key in gray 
    mov [x],161
    mov [y],111
FifthWhiteKeyPaintBig: ;paints the big rectangle on the Fifth white key in gray
    push [x]
    push [y]
    push [color1]
    call PrintPixel
    cmp [x],199
    jne FifthWhiteBig1
    cmp [y],170
    jne FifthWhiteBig2
    mov [x],166
    mov [y],50
    jmp FifthWhiteKeyPaintSmall
FifthWhiteBig1:
    inc [x]
    jmp FifthWhiteKeyPaintBig
FifthWhiteBig2:
    inc [y]
    mov [x],161
    jmp FifthWhiteKeyPaintBig
FifthWhiteKeyPaintSmall: ;Paints the small rectangle on the Fifth white key gray
    push [x]
    push [y]
    push [color1]
    call PrintPixel
    cmp [x],189
    jne FifthWhiteSmall1
    cmp [y],111
    jne FifthWhiteSmall2
    mov  cx,00007h
    je ChangeToWhite5
    mov [color1],00007h
    call ReceiveKey
ChangeToWhite5:
    mov [color1],0000Fh
    call FifthWhiteKeyPaint
FifthWhiteSmall1:
    inc [x]
    jmp FifthWhiteKeyPaintSmall
FifthWhiteSmall2:
    inc [y]
    mov [x],166
    jmp FifthWhiteKeyPaintSmall
endp FifthWhiteKeyPaint

; --------------------------
proc SixthWhiteKeyPaint ; paints the Sixth white key in gray 
    mov [x],201
    mov [y],111
SixthWhiteKeyPaintBig: ;paints the big rectangle on the Sixth white key in gray
    push [x]
    push [y]
    push [color1]
    call PrintPixel
    cmp [x],239
    jne SixthWhiteBig1
    cmp [y],170
    jne SixthWhiteBig2
    mov [x],206
    mov [y],50
    jmp SixthWhiteKeyPaintSmall
SixthWhiteBig1:
    inc [x]
    jmp SixthWhiteKeyPaintBig
SixthWhiteBig2:
    inc [y]
    mov [x],201
    jmp SixthWhiteKeyPaintBig
SixthWhiteKeyPaintSmall: ;Paints the small rectangle on the Sixth white key gray
    push [x]
    push [y]
    push [color1]
    call PrintPixel
    cmp [x],229
    jne SixthWhiteSmall1
    cmp [y],111
    jne SixthWhiteSmall2
    mov  cx,00007h
    je ChangeToWhite6
    mov [color1],00007h
    call ReceiveKey
ChangeToWhite6:
    mov [color1],0000Fh
    call SixthWhiteKeyPaint
SixthWhiteSmall1:
    inc [x]
    jmp SixthWhiteKeyPaintSmall
SixthWhiteSmall2:
    inc [y]
    mov [x],206
    jmp SixthWhiteKeyPaintSmall
endp SixthWhiteKeyPaint
; --------------------------
proc SeventhWhiteKeyPaint ; paints the Seventh white key in gray 
    mov [x],246
    mov [y],50
SeventhWhiteKeyPaintBig: ;paints the big rectangle on the Seventh white key in gray
    push [x]
    push [y]
    push [color1]
    call PrintPixel
    cmp [x],279
    jne SeventhWhiteBig1
    cmp [y],170
    jne SeventhWhiteBig2
    mov [x],241
    mov [y],111
    jmp SeventhWhiteKeyPaintSmall
SeventhWhiteBig1:
    inc [x]
    jmp SeventhWhiteKeyPaintBig
SeventhWhiteBig2:
    inc [y]
    mov [x],246
    jmp SeventhWhiteKeyPaintBig
    
SeventhWhiteKeyPaintSmall: ;Paints the small rectangle on the Seventh white key gray
    push [x]
    push [y]
    push [color1]
    call PrintPixel
    cmp [x],246
    jne SeventhWhiteSmall1
    cmp [y],170
    jne SeventhWhiteSmall2
    mov  cx,00007h
    je ChangeToWhite7
    mov [color1],00007h
    call ReceiveKey
ChangeToWhite7:
    mov [color1],0000Fh
    call SeventhWhiteKeyPaint
SeventhWhiteSmall1:
    inc [x] 
    jmp SeventhWhiteKeyPaintSmall
SeventhWhiteSmall2:
    inc [y]
    mov [x],241
    jmp SeventhWhiteKeyPaintSmall
endp SeventhWhiteKeyPaint;
; --------------------------

proc EighthWhiteKeyPaint ; paints the Eighth white key in gray 
    mov [x],281
    mov [y],50
EighthWhiteKeyPaintBig: ;paints the big rectangle on the Seventh white key in gray
    push [x]
    push [y]
    push [color1]
    call PrintPixel
    cmp [x],319
    jne EighthWhite1
    cmp [y],170
    jne EighthWhite2
    mov  cx,00007h
    je ChangeToWhite8
    mov [color1],00007h
    call ReceiveKey
ChangeToWhite8:
    mov [color1],0000Fh
    call EighthWhiteKeyPaint
EighthWhite1:
    inc [x]
    jmp EighthWhiteKeyPaintBig
EighthWhite2:
    inc [y]
    mov [x],281
    jmp EighthWhiteKeyPaintBig
endp EighthWhiteKeyPaint

; --------------------------------------------------------------------------------------------
proc FirstBlackKeyPaint
    mov [color3],00008h; Dark Gray Color
FirstBlackKeyPaint1:
    call PrintBlackKey1
    mov  cx,86h
    int  15h
    cmp [color3],00008h
    je ChangeToBlack1
    mov [color3],00008h
    call ReceiveKey
ChangeToBlack1:
    mov [color3],0000h
    call FirstBlackKeyPaint1
endp FirstBlackKeyPaint

; --------------------------
proc SecondBlackKeyPaint
    mov [color3],00008h; Dark Gray Color
SecondBlackKeyPaint1:
    call PrintBlackKey2
    mov  cx,00008h
    je ChangeToBlack2
    mov [color3],00008h
    call ReceiveKey
ChangeToBlack2:
    mov [color3],0000h
    call SecondBlackKeyPaint1
endp SecondBlackKeyPaint

; --------------------------

proc ThirdBlackKeyPaint
    mov [color3],00008h; Dark Gray Color
ThirdBlackKeyPaint1:
    call PrintBlackKey3
    mov  cx,00008h
    je ChangeToBlack3
    mov [color3],00008h
    call ReceiveKey
ChangeToBlack3:
    mov [color3],0000h
    call ThirdBlackKeyPaint1
endp ThirdBlackKeyPaint     
; --------------------------
proc FourthBlackKeyPaint
    mov [color3],00008h; Dark Gray Color
FourthBlackKeyPaint1:
    call PrintBlackKey4
    mov  cx,00008h
    je ChangeToBlack4
    mov [color3],00008h
    call ReceiveKey
ChangeToBlack4:
    mov [color3],0000h
    call FourthBlackKeyPaint1
endp FourthBlackKeyPaint
; --------------------------

proc FifthBlackKeyPaint
    mov [color3],00008h; Dark Gray Color
FifthBlackKeyPaint1:
    call PrintBlackKey5
    mov  cx,00008h
    je ChangeToBlack5
    mov [color3],00008h
    call ReceiveKey
ChangeToBlack5:
    mov [color3],0000h
    call FifthBlackKeyPaint1
endp FifthBlackKeyPaint     
; --------------------------------------------------------------------------------------------

start:
    mov ax,@data
    mov ds,ax
; --------------------------
; Your code here
    call graphic 
    call ReceiveKey
    
; --------------------------
exit:
    mov ax,4c00h
    int 21h
END start

解决方法

按下键盘上的键后,音符变为灰色,并在 0.746 秒后变回白色。

它完全按照您在 proc FirstBlackKeyPaint 中使用 Int 15/AH=86h

指示您的程序进行等待

长时间按下某个键时会出现闪烁/毛刺。然后,键码以键入速率重复存储到键盘缓冲区,并在 proc ReceiveKey 中通过 Int 16/AH=00h 多次检索,尽管键盘键已经释放。 您可以在每个 ReceiveKey 之前使用 DOS 服务 Int 21/AH=0Ch 刷新缓冲区:

ReceiveKey: 
 ;   mov ah,0
 ;   Int 16h
    MOV AH,0Ch  ; FLUSH BUFFER AND READ STANDARD INPUT
    MOV AL,01h  ; CHECK FOR KEYSTROKE
    INT 21h

但是,您可能希望生成长度可变的音调,在这种情况下,您将需要一种不同的输入方法:从键盘端口 60h 直接输入而不是 BIOS service Int 16h。我的 DOS 实用程序 OPIN Keys 可用于了解按下和释放键时从键盘端口读取的代码。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...