比较击键 - 装配 CCS64

发布于 2024-12-13 03:49:11 字数 153 浏览 0 评论 0原文

我想比较汇编(CCS64)中的击键。 如果我连续输入相同的键,我想做某事 例如: A A = 执行此操作

,但如果我输入以下内容: A B = 执行其他操作

有建议吗?

I want to compare keystrokes in assembly (CCS64).
If I type in the same key in a row I want to do something
example: A A = do this

but if I type this: A B = do something else

Suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

城歌 2024-12-20 03:49:11

正如您所希望的那样,我为您准备了一个示例。如果连续按两次相同的键,边框颜色将变为红色,否则保持黑色。

警告!此示例使用kernal 例程。这并没有什么问题。但还有一种较低级别的方法可以在不使用 $ffd2(输出向量,chrout)和 $ffe4(从键盘获取)内核调用的情况下执行此操作。但由于理解起来要复杂得多,我更喜欢这个例子。

如果您想了解幕后发生的情况(内核调用),您可以轻松地从 AAY64 文档中跟踪内核 ROM 代码。链接如下:

AAY 主页:http://www.the-dreams.de/aay.html

AAY64 在线 HTML 版本:http://unusedino.de/ec64/technical/aay/c64/

ROM列表:http://unusedino.de/ec64/technical/aay/c64/krnromma.htm

$ffd2 (输出向量,chrout):http://unusedino.de/ec64/technical/aay/c64/romffd2.htm

$ffe4(从键盘获取):http://unusedino.de/ec64/technical/aay/c64/romffe4.htm

您可以浏览通过按操作码和地址上的链接可以更深入地了解。

这是示例代码。您可以使用 ACME Crossassembler 编译此代码,您可以在此处找到 -> 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

I prepared an example to you just like you've wanted. If you press same keys in a row twice, border color changes to red, otherwise stays black.

Warning! This example uses kernal routines. There is nothing wrong with that. But there is also a lower level way to do this without using $ffd2 (Output Vector, chrout) and $ffe4 (Get From Keyboad) kernal calls. But since it is much more complicated to understand, I prefered this example.

If you want to know what is happening behind the scenes (kernal calls), you can easily trace the kernal ROM codes from AAY64 documentation. Here is the links:

Main AAY Page: http://www.the-dreams.de/aay.html

AAY64 Online HTML Version: http://unusedino.de/ec64/technical/aay/c64/

Kernal ROM Listing: http://unusedino.de/ec64/technical/aay/c64/krnromma.htm

$ffd2 (Output Vector, chrout): http://unusedino.de/ec64/technical/aay/c64/romffd2.htm

$ffe4 (Get From Keyboad): http://unusedino.de/ec64/technical/aay/c64/romffe4.htm

You can browse deeper by pressing links on the opcodes and addresses.

Here goes the example code. You can compile this code using ACME Crossassembler which you can find here -> 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
不喜欢何必死缠烂打 2024-12-20 03:49:11

我不是 C64 人,但我知道 6502 汇编。为了实现你的目标,你需要知道两件事。首先是学习 6502 汇编语言(如果您还不了解它)。例如,此页面拥有优秀的资源。

二是了解C64架构和OS。用 Commodore 的话说,它被称为Kernal,快速谷歌应该会为您指明正确的方向。

但还有一个替代方案。您始终可以使用 cc65,这是一个出色的免费软件包,由几乎符合 ISO 的 C 编译器、6502 汇编器组成、一个链接器和几个其他 6502 相关工具。它支持所有流行的 6502 平台,包括 Atari 8 位、Apple II,当然还有 Commodore 64。它有大量文档,并且邮件列表中的人员都非常友善且乐于助人。作为提示,键盘输入和屏幕输出函数在 conio.h 中定义。

I'm not a C64 person but I know 6502 assembly. You need to know two things to achieve your goal. The first is to learn 6502 assembly language if you don't already know about it. This page has excellent resources for example.

The second is to learn about C64 architecture and OS. It's called Kernal in Commodore speak, a quick google should point you in the right direction.

But there is an alternative. You can always use cc65, an excellent freeware package consisting of an almost-ISO-complient C compiler, a 6502 assembler, a linker and couple of other 6502 related tools. It has support for every popular 6502 platform including Atari 8-bit, Apple II and, of course, Commodore 64. It has a good amount of documentation and the people in the mailing list are nice and helpful. As a hint, keyboard entry and screen output functions are defined in conio.h.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文