Compare keystrokes - CCS64 build

I want to compare keystrokes in an assembly (CCS64). If I type the same key in a row, I want to do something. Example: A A = do it

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

Suggestions?

+4
source share
2 answers

I have prepared for you an example of how you wanted it. If you press the same keys twice in a row, the frame color changes to red, otherwise black.

Attention! This example uses kernal routines. There is nothing wrong with that. But there is a lower way to do this without using the $ffd2 (Output Vector, chrout) and $ffe4 (Get From Keyboad) kernel calls. But since this is a lot harder to understand, I preferred this example.

If you want to know what happens behind the scenes (kernel calls), you can easily track ROM kernel codes from the AAY64 documentation. Here are the links:

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

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

Kernal ROM List: 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 clicking links to opcodes and addresses.

Here is a sample code. You can compile this code with 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 
+7
source

I'm not a C64 person, but I know the 6502 build. To achieve your goal you need to know two things. First, learn 6502 assembly language if you still don't know about it. This page has excellent resources, for example.

Secondly, you will learn about C64 architecture and OS. He called Kernal at Commodore, they say, fast Google should point you in the right direction.

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

+2
source

Source: https://habr.com/ru/post/1379032/


All Articles