正如您所希望的那样,我为您准备了一个示例。如果连续按两次相同的键,边框颜色将变为红色,否则保持黑色。
警告!本示例使用kernal
例程。没有什么不妥。但还有一种较低级别的方法可以在不使用的情况下执行此操作$ffd2
(输出向量,chrout)和$ffe4
(从键盘获取)内核调用。但由于理解起来要复杂得多,我更喜欢这个例子。
如果你想知道幕后发生了什么(内核调用),你可以轻松地跟踪内核 ROM 代码AAY64
文档。这是链接:
AAY 主页:http://www.the-dreams.de/aay.html http://www.the-dreams.de/aay.html
AAY64 在线 HTML 版本:http://unusedino.de/ec64/technical/aay/c64/ http://unusedino.de/ec64/technical/aay/c64/
内核 ROM 列表:http://unusedino.de/ec64/technical/aay/c64/krnromma.htm http://unusedino.de/ec64/technical/aay/c64/krnromma.htm
$ffd2
(输出向量,chrout):http://unusedino.de/ec64/technical/aay/c64/romffd2.htm http://unusedino.de/ec64/technical/aay/c64/romffd2.htm
$ffe4
(从键盘获取):http://unusedino.de/ec64/technical/aay/c64/romffe4.htm http://unusedino.de/ec64/technical/aay/c64/romffe4.htm
您可以通过按操作码和地址上的链接进行更深入的浏览。
这是示例代码。您可以使用以下命令编译此代码ACME Crossassembler
你可以在这里找到 ->http://www.esw-heim.tu-clausthal.de/~marco/smorbrod/acme/ http://www.esw-heim.tu-clausthal.de/~marco/smorbrod/acme/
!to "keycomp.prg",cbm
zpBuffer = $fa ; $fa-$fb are reserved for 2 bytes of key buffer
* = $0801
!byte $0c, $08, $00, $00, $9e, $32, $30, $36, $31, $00, $00, $00
* = $080d
; key buffer initialization
ldx #$f0 ; initialize key buffer
stx zpBuffer ; with two different
inx ; values to avoid instant
stx zpBuffer+1 ; match at the beginning
; border color initialization
lda #$00 ; set startup border color to black
sta $d020 ; which means "no match"
; main loop
mainloop
lda zpBuffer ; shift key buffer
sta zpBuffer+1 ; by one
readKey
jsr $ffe4 ; read key
beq readKey ; if no key pressed loop forever
jsr $ffd2 ; show key on the screen
sta zpBuffer ; store the key to key buffer
lda zpBuffer ; compare the last stored key
cmp zpBuffer+1 ; with the old key value
beq cmpMatch ; if there is a match jmp to cmpMatch
lda #$00 ; if two pressed keys are different
sta $d020 ; change border color to black
jmp cmpOut ; skip the other condition code block
cmpMatch
lda #$02 ; if there is a repeated key
sta $d020 ; change border color to red
cmpOut
jmp mainloop ; wait for the next key