Keyboard emulation

You need an actual VIC.

Moderator: Moderators

User avatar
lgb
Vic 20 Drifter
Posts: 25
Joined: Tue Apr 26, 2016 8:10 am
Website: http://lgb.hu/
Location: Hungary
Occupation: System engineer

Keyboard emulation

Postby lgb » Tue Apr 26, 2016 9:27 am

Hi, this is my first post on this forum, and I'm also new about the VIC-20 (I'm more familiar with other Commodore machines), so sorry for my possible stupid questions :)

Recently I've found Pixel's (hopefully I succeeded to find his nick out on this forum ...) shadowVIC emulator, and since I'm great fan (even if I am not an expert in this topic ...) of trying :) to write emulators, I started to think about getting familiar with VIC-20 too (inspiration by shadowVIC ...), and trying to write my own emulator as well, utilizing the cross-platform SDL2 library. I've already managed to get the READY. prompt with the original ROM images with my own 65C02 (I know, VIC-20 didn't use the 65C02, the reason of this choice, that I already have an emulation coded for this CPU ... even if it's incorrect choice, and no illegal opcodes will work this way of the original NMOS line) and VIA emulations, originally written for my Commodore LCD emulator (both in Javascript for a web browser based emulator and C version for a native application emulator for Windows - cross compiled with gcc/mingw on Linux - and UNIX-like machines including Linux and Raspberry Pi).

Now, my headache is about emulating the keyboard. As far as I thought, it's a really simple 8x8 matrix, controlled by two ports of VIA2. Interestingly, if I try to do this, odd things happen: even with a fixed keyboard matrix value (ie emulating that a single key is pressed constantly) it seems kernal detects sometimes a different key, sometimes as shift would be pressed as well, etc. I also had the suspect, that maybe my CPU emulation is incorrect for some opcodes, and that causes the problems. But I am really unsure. With logging what kind of VIA port writes are initiated (by the CPU) it seems only a single line is tried to be scanned at all.

Is there any special with the VIC-20 keyboard, I don't know? Can someone suggest something, including some schematic which shows the connection of VIA-2 and the keyboard matrix? To be honest, even with Commodore LCD I had no problem with keyboard, it uses VIA's shift register and shifts 16 bits (with additional byte of other information, like battery status, special keys etc), so in nutshell: it's quite strange stuff for me. However now VIC-20 seems to be even more cryptic for me, which it shouldn't be so complex, or at least I can't see where I am wrong in this topic :)

Any help is welcome, and thanks for the possible answers :)

groepaz
Vic 20 Nerd
Posts: 597
Joined: Wed Aug 25, 2010 5:30 pm

Re: Keyboard emulation

Postby groepaz » Tue Apr 26, 2016 10:27 am

there is nothing special about the keyboard, its a simple 8x8 matrix with switches and no more (no less) :)

User avatar
lgb
Vic 20 Drifter
Posts: 25
Joined: Tue Apr 26, 2016 8:10 am
Website: http://lgb.hu/
Location: Hungary
Occupation: System engineer

Re: Keyboard emulation

Postby lgb » Tue Apr 26, 2016 12:50 pm

groepaz wrote:there is nothing special about the keyboard, its a simple 8x8 matrix with switches and no more (no less) :)


I see. Thanks for your answer. Since now for the very same matrix state different characters displayed after getting to BASIC, it must be my CPU emulator which is buggy somewhere. It can't be a "big" bug, as emulation managed to reach the BASIC "welcome" screen, correct memory amount, etc. I will study the VIC20 kernal ROM disassembly to try to figure out which instruction is emulated faulty by me ...

User avatar
mrr19121970
Vic 20 Nerd
Posts: 802
Joined: Tue Jan 19, 2016 9:22 am
Location: Germany
Occupation: IT service manager

Re: Keyboard emulation

Postby mrr19121970 » Tue Apr 26, 2016 1:03 pm

groepaz wrote:there is nothing special about the keyboard, its a simple 8x8 matrix with switches and no more (no less) :)


Where can I read more about this. How does it work ? There are 66 keys. Is it shift lock and restore that are not in this matrix ??

User avatar
lgb
Vic 20 Drifter
Posts: 25
Joined: Tue Apr 26, 2016 8:10 am
Website: http://lgb.hu/
Location: Hungary
Occupation: System engineer

Re: Keyboard emulation

Postby lgb » Tue Apr 26, 2016 1:30 pm

lgb wrote:
groepaz wrote:there is nothing special about the keyboard, its a simple 8x8 matrix with switches and no more (no less) :)


I see. Thanks for your answer. Since now for the very same matrix state different characters displayed after getting to BASIC, it must be my CPU emulator which is buggy somewhere. It can't be a "big" bug, as emulation managed to reach the BASIC "welcome" screen, correct memory amount, etc. I will study the VIC20 kernal ROM disassembly to try to figure out which instruction is emulated faulty by me ...


Or it's my VIA emulation ... There is a ROL on port B data port register in keyboard scan routine. Though in theory I am aware of the behaviour of VIA port A and port B (and the difference) on reading when direction is output, etc, but it still can be buggy somewhere ...

User avatar
lgb
Vic 20 Drifter
Posts: 25
Joined: Tue Apr 26, 2016 8:10 am
Website: http://lgb.hu/
Location: Hungary
Occupation: System engineer

Re: Keyboard emulation

Postby lgb » Tue Apr 26, 2016 1:37 pm

mrr19121970 wrote:
groepaz wrote:there is nothing special about the keyboard, its a simple 8x8 matrix with switches and no more (no less) :)


Where can I read more about this. How does it work ? There are 66 keys. Is it shift lock and restore that are not in this matrix ??


I'm really not an expert (but a newbie ..) with VIC-20, but I *think* RESTORE key is handled separately, connected to a VIA pin alone (CA1?), while shift lock is just a mechanical toggle (?) switch connected in parallel of shift key for "permanent shift effect". Or something like this :)

User avatar
mrr19121970
Vic 20 Nerd
Posts: 802
Joined: Tue Jan 19, 2016 9:22 am
Location: Germany
Occupation: IT service manager

Re: Keyboard emulation

Postby mrr19121970 » Tue Apr 26, 2016 1:43 pm

This was my line of thinking too. Left shift and right shift are different for sure. Shift lock and left shift seem to be the same. Restore as you say has its own line to the VIA uab1

User avatar
lgb
Vic 20 Drifter
Posts: 25
Joined: Tue Apr 26, 2016 8:10 am
Website: http://lgb.hu/
Location: Hungary
Occupation: System engineer

Re: Keyboard emulation

Postby lgb » Tue Apr 26, 2016 1:47 pm

Oh well :) I forgot to store output register data in VIA emulation on port write, so port read always read zero :-) Sorry for the noise, stupid mistake of mine :)


Return to “Emulation and Cross Development”

Who is online

Users browsing this forum: No registered users and 1 guest