Jump to content

Photo

[Aquarius] reading the keymap i/o port in assembly

z80 i/o assembly keymap aquarius

9 replies to this topic

#1 nitrofurano OFFLINE  

nitrofurano

    Moonsweeper

  • 308 posts
  • meditating
  • Location:porto

Posted Tue Jul 2, 2013 4:41 AM

Hi there!
From the information i'm finding at http://www.vdsteenov...s/keyboard.html and http://www.vdsteenov...rius/iomap.html , it looks like the 14bit information from the keymap is all stored in AF 16bit register? i can't get the bits between 8 and 13, and the B register seems to have no value at all
I'm really struggling a lot on understanding it...
What would look like in a z80 assembly routine snippet, that you can read all keys pressed? from the $FF i only can read the colscan (A is a 8bit register, i think), so when i press "w", the same happens when i press "t", "i", "e", "y", etc. - How can i distinguish between "w", "t", "i", "e" and "y"?
Thanks!

#2 catsfolly OFFLINE  

catsfolly

    Dragonstomper

  • 742 posts
  • Location:Japan

Posted Tue Jul 2, 2013 8:18 AM

Hi there!
From the information i'm finding at http://www.vdsteenov...s/keyboard.html and http://www.vdsteenov...rius/iomap.html , it looks like the 14bit information from the keymap is all stored in AF 16bit register? i can't get the bits between 8 and 13, and the B register seems to have no value at all
I'm really struggling a lot on understanding it...
What would look like in a z80 assembly routine snippet, that you can read all keys pressed? from the $FF i only can read the colscan (A is a 8bit register, i think), so when i press "w", the same happens when i press "t", "i", "e", "y", etc. - How can i distinguish between "w", "t", "i", "e" and "y"?
Thanks!


You have to set the B register to different values, depending on which column you want to scan.

Screen shot 2013-07-02 at 10.51.24 PM.png

The number on the far right of the above table is the number that goes in the B register to scan that column.

For example, to scan column 1, you would do:
	
ld bc,$feff ; 11111110 - scanning column 1
in	 a,(c)


To scan column 8,

ld bc,$7fff ; 01111111 - scanning column 8
	 in	 a,(c)

The value returned has a 0 bit set for each button in that column that is being pressed.

For example, if the "w" key is pressed, the a register will contain 11111101 when column 8 is scanned, but will return 11111111 when any other column is scanned.

If the "t" is pressed, the a register will contain the same 11111101 when column 6 is scanned, but will return 11111111 when any other column is scanned.

So the way you can tell a "w" from a "t" is based on which column you are scanning, which is based on what number you put into the b register before doing the "in" instruction.

Does this help?

If you want to see how basic does it, check out "KEYCHK2" in the disassembly at:
http://archive.konte...es/aqromdis.txt


Catsfolly

#3 nitrofurano OFFLINE  

nitrofurano

    Moonsweeper

  • Topic Starter
  • 308 posts
  • meditating
  • Location:porto

Posted Tue Jul 2, 2013 8:49 AM

thanks, @catsfolly! :) in the meanwhile i found that http://archive.konte...es/aqromdis.txt you're talking about! thanks for confirming! :) - posted my last experiment from Boriel's ZX-Basic Compiler at http://atariage.com/...77#entry2785577 (attachment there, sources and .rom included! )

#4 mvdsteenoven OFFLINE  

mvdsteenoven

    Chopper Commander

  • 181 posts
  • Location:Netherlands

Posted Tue Jul 2, 2013 4:02 PM

thanks, @catsfolly! :) in the meanwhile i found that http://archive.konte...es/aqromdis.txt you're talking about! thanks for confirming! :) - posted my last experiment from Boriel's ZX-Basic Compiler at http://atariage.com/...77#entry2785577 (attachment there, sources and .rom included! )


You can also call KEYCHK2 directly. In this case you won't have to translate the row-scan and col-scan yourself. KEYCHK2 will give the ASCII code of the key pressed.
Better yet is to call the KEYCHK function at $1e80 in ROM.
But these ROM functions use the memory area from $3800 to $38ff, so you need to make sure that these have the correct values before calling KEYCHK.
See http://www.vdsteenov...mempointer.html for the memory area with their default values.

The KEYCHK function uses (KWADDR $380b), (SCANCNT $380f), (LASTKEY $380E)
The first thing the KEYCHK function does is an EXX (exchange) of all registers.
If you call the KEYCHK function in ROM you should write something like

AQUARIUS_KEYCHK:

XOR A	 ; Set A to zero
LD ($380B), A ; KWADDR
LD ($380C), A
LD ($380E), A ; LASTKEY
LD ($380F), A ; SCANCNT
CALL $1e80 ; Call Keychck
	 ; A holds result
RET


Regs,
Martin

#5 nitrofurano OFFLINE  

nitrofurano

    Moonsweeper

  • Topic Starter
  • 308 posts
  • meditating
  • Location:porto

Posted Wed Jul 3, 2013 5:04 AM

added aquariuskeychk.bas as library on Boriel's ZX-Basic Compiler - weird that is not working... :S (result would appear in the center of the upper edge of the display) - sad, because i was also curious about how random numbers from bios works as well... :S

Attached Files


Edited by nitrofurano, Wed Jul 3, 2013 5:06 AM.


#6 catsfolly OFFLINE  

catsfolly

    Dragonstomper

  • 742 posts
  • Location:Japan

Posted Wed Jul 3, 2013 10:27 AM

added aquariuskeychk.bas as library on Boriel's ZX-Basic Compiler - weird that is not working... :S (result would appear in the center of the upper edge of the display) - sad, because i was also curious about how random numbers from bios works as well... :S

I tried it in virtual Aquarius and I could move the ascii-space guy up, down, left and right using the keyboard. What part is not working?

#7 nitrofurano OFFLINE  

nitrofurano

    Moonsweeper

  • Topic Starter
  • 308 posts
  • meditating
  • Location:porto

Posted Wed Jul 3, 2013 1:20 PM

I tried it in virtual Aquarius and I could move the ascii-space guy up, down, left and right using the keyboard.

3 ascii-space guys! you move one with "wsad", other with "tgfh", and other with "ikjl"

What part is not working?

far above - there you see an attribute byte (cell) for all key rows (or columns) from the keyboard, a sequence of 8 attribute bytes for each row (or column); and the next one is that part is not working, it should be an ascii character of the key pressed (using that bios call as suggested from @mvdsteenoven ) -
http://img853.images...3/5724/i7fw.png (that one i marked with a red arrow)

Edited by nitrofurano, Wed Jul 3, 2013 1:21 PM.


#8 catsfolly OFFLINE  

catsfolly

    Dragonstomper

  • 742 posts
  • Location:Japan

Posted Wed Jul 3, 2013 2:47 PM

3 ascii-space guys! you move one with "wsad", other with "tgfh", and other with "ikjl"


far above - there you see an attribute byte (cell) for all key rows (or columns) from the keyboard, a sequence of 8 attribute bytes for each row (or column); and the next one is that part is not working, it should be an ascii character of the key pressed (using that bios call as suggested from @mvdsteenoven ) -
http://img853.images...3/5724/i7fw.png (that one i marked with a red arrow)


Is that part drawn by this code?


poke $3412,aquariuskeychk()
poke $3412,$08


I'm guessing that it should be:


poke $3012,aquariuskeychk()
poke $3412,$08

Otherwise, the second poke writes over the first poke.

Catsfolly

#9 nitrofurano OFFLINE  

nitrofurano

    Moonsweeper

  • Topic Starter
  • 308 posts
  • meditating
  • Location:porto

Posted Thu Jul 4, 2013 8:49 AM

Is that part drawn by this code?

poke $3412,aquariuskeychk()
poke $3412,$08

I'm guessing that it should be:

poke $3012,aquariuskeychk()
poke $3412,$08

Otherwise, the second poke writes over the first poke.

Catsfolly


thanks, and sorry about my dyslexia! :D - btw, i would imagine that would fix, but now it is showing "£" there instead... :S

Attached Files



#10 catsfolly OFFLINE  

catsfolly

    Dragonstomper

  • 742 posts
  • Location:Japan

Posted Thu Jul 4, 2013 11:49 AM

thanks, and sorry about my dyslexia! :D - btw, i would imagine that would fix, but now it is showing "£" there instead... :S


The Keychk routine is trying to debounce the keyboard. Basically Keychk is called every frame, and only returns a value if it detects the same key down 4 times in a row. To do this, Keychk saves the value of the pressed key in "LASTKEY", and it keeps a count of the number of times in a row the key was down by incrementing the variable "SCANCOUNT".

So, if we clear these variables every time we call Keychk then it will always return 0.

AQUARIUS_KEYCHK:

XOR A ; Set A to zero
LD ($380B), A ; KWADDR
LD ($380C), A
LD ($380E), A ; LASTKEY
LD ($380F), A ; SCANCNT
CALL $1e80 ; Call Keychck
; A holds result
RET
I guess we have to clear the variables one time as part of some "initialization sequence", and then just call Keychck when we want to check for a key.

AQUARIUS_INIT:

XOR A ; Set A to zero
LD ($380B), A ; KWADDR
LD ($380C), A
LD ($380E), A ; LASTKEY
LD ($380F), A ; SCANCNT

RET


AQUARIUS_KEYCHK:
CALL $1e80 ; Call Keychck
; A holds result
RET

Maybe that will work.

Catsfolly





Also tagged with one or more of these keywords: z80, i/o, assembly, keymap, aquarius

0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users