Using key scan/read code

Post programming questions related to the CPC Here!
Post Reply
Kitsune Mifune
Posts: 28
Joined: Tue Oct 22, 2019 6:46 am
Location: Glasgow
Contact:

Using key scan/read code

Post by Kitsune Mifune » Sun Dec 01, 2019 1:39 pm

Apologies for what must seem like a really thick question Keith, but I'm getting rid of the last bit of firmware use by incorporating your Key Scanning/Reading code into my program, but I'm a little stuck on how to actually check for a key press.

Like, how do you actually tell the computer if you push, for example "s", then do stuff?

With the firmware I just load the accumulator with the keycode of the key I want to push and then do a skip 'jr' over the "do stuff" code if it's not pushed, so what would be the equivalent of that using the Hardware Keyboard map in the key reading code?

(PS, the transparency code from my last post worked a treat, so cheers for that!)
Programming: 90% failures, 10% victories, and 100% hair loss!

User avatar
akuyou
Posts: 328
Joined: Mon Apr 22, 2019 3:19 am

Re: Using key scan/read code

Post by akuyou » Mon Dec 02, 2019 8:27 pm

Here you go... a sample file to read the keys and respond to S or T keys

Basically, the keyscanner routine reads in the lines of the keyboard into a 10 byte array, and you'll need to test those bits somehow to work out which keys are pressed - 1 means the key isn't pressed... 0 means it's pressed down.

The attached file has the layout of the keys in the layout they appear on the hardware (and resulting array) at the bottom... you can also see it here:
https://www.chibiakumas.com/z80/platform.php#LessonP6
Attachments
CPC_KeyTest.7z
(1.09 KiB) Downloaded 2 times
Chibi Akuma(s) Comedy-Horror 8-bit Bullet Hell shooter! // 「チビ悪魔」可笑しいゴシックSTG ! // Work in Progress: ChibiAliens

Interested in CPU's :Z80,6502,68000,6809,ARM,8086,RISC-V
Learning: 65816,ARM,8086,6809

Kitsune Mifune
Posts: 28
Joined: Tue Oct 22, 2019 6:46 am
Location: Glasgow
Contact:

Re: Using key scan/read code

Post by Kitsune Mifune » Tue Dec 03, 2019 9:32 am

Awesome, that's just what I was looking for!

Cheers!
Programming: 90% failures, 10% victories, and 100% hair loss!

Post Reply

Return to “Amstrad CPC Assembly Programming”