Jump to content
IGNORED

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


Recommended Posts

Hi there!

From the information i'm finding at http://www.vdsteenoven.com/aquarius/keyboard.html and http://www.vdsteenoven.com/aquarius/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!

Link to comment
Share on other sites

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.

 

post-14916-0-63896400-1372773204_thumb.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

Link to comment
Share on other sites

thanks, @catsfolly! :) in the meanwhile i found that http://archive.kontek.net/aqemu.classicgaming.gamespy.com/Files/aqromdis.txt you're talking about! thanks for confirming! :) - posted my last experiment from Boriel's ZX-Basic Compiler at http://atariage.com/forums/topic/213965-aquarius-stuff-from-boriels-zx-basic-compiler-first-attempt/page__gopid__2785577?do=findComment&comment=2785577 (attachment there, sources and .rom included! )

Link to comment
Share on other sites

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

  • Like 1
Link to comment
Share on other sites

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

aquarius_borielszxbasiccompiler_example01i_201307031201.zip

Edited by nitrofurano
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

  • Like 1
Link to comment
Share on other sites

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

aquarius_borielszxbasiccompiler_example01i_201307041547.zip

Link to comment
Share on other sites

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

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...