Jump to content
Sign in to follow this  
Cybernoid

Detecting CTRL-SHIFT key presses?

Recommended Posts

Is there a way to detect a CTRL-SHIFT key press on the 8bit?

 

For example, can I detect a CTRL-SHIFT-A, or more importantly, can I detect a CTRL-SHIFT-'+'(LEFT ARROW) or CTRL-SHIFT-'*'(RIGHT ARROW)?

 

Have any assembly, C or BASIC code examples?

 

Thanks...

--C

Share this post


Link to post
Share on other sites

Off course, you can...

 

Simply detect it by scanning at address 764.

 

First of all you have to erase the data stored there, by writing 255 ($ff)into 764. Then you can listen which key was pressed by reading 764 (in Basic with peek).

 

Ok, here the assumed results for pressing the arrows:

 

shift+control+up -> 206

shift+control+down -> 207

 

left and right can´t be detectet, as I just noticed with this little routine:

10 POKE 764,255

20 ?PEEK(764)

30 G.20

 

There are more keys not detected with shift and control pressed...

 

Greets from Germany

Share this post


Link to post
Share on other sites

IIRC, one of the keys sets the high bit and one sets bit 6. So you can check for immediate values using a table, or use a generic routine to detect those bits (the value should be $C0 or higher for both of those keys being pressed).

Share this post


Link to post
Share on other sites

shift+control+up       -> 206

shift+control+down   -> 207

 

left and right can´t be detectet, as I just noticed with this little routine:

 

There are more keys not detected with shift and control pressed...

 

Greets from Germany

 

Ah, I was afraid that there were some key combos that you cannot detect.

 

I know that CTRL and shift are bits 7 and 6, but I couldn't seem to use this with the left and right arrows. Darn!

 

Happy Easter from Texas!

Share this post


Link to post
Share on other sites

Yup, sucks. This is why Flickerterm 80 had to use Ctrl-Shift-< and Ctrl-Shift-> for its left/right arrow keys (unless you were in arrow key mode).

Share this post


Link to post
Share on other sites

Hi,

 

does anyone have an assembly listing for how to "listen" for a keypress and branch when certain key is pressed?

Share this post


Link to post
Share on other sites

;-------------

LDA $02FC

CMP #$FF

BEQ no_keys

;insert comparisons/branches here

 

no_keys:

;-------------

 

 

 

If you have a lot of keys to check, you could just assign branch values to a table...which would take 64 bytes of memory (more or less, depending on what the upper/lower limits of the value will be). You just simply adjust the value of A if needed, and then transfer it to the X or Y register to be used as an offset to get the jump value. Once the routine finishes what it has to do, you'll have to clear the global keyboard location by storing #$FF back at $02FC.

;-------------

LDA $02FC

CMP #$FF

BEQ no_keys ;branch if no keys pressed

CMP #lowest_value-1 ;check for the lowest value allowed

BCS Key_pressed ;branch if over (ok to use)

CMP #highest_value+1 ;check for the highest value allowed

BCC Key_pressed ;branch if under (ok to use)

LDA #$FF ;otherwise, clear the keyboard

STA $02FC

BNE no_keys ;...and branch ahead

 

Key_pressed:

SEC

SBC #lowest_value ;lower the amount (this will trim down the size of the table)

TAX ;...and use as an offset for the tables

LDA Lo_table,X ;get the lo byte of the destination address

STA Jump_Address ;and save to our vector

LDA Hi_table,X ;if the jump destinations are all on the same page, ...

STA Jump_Address+1 ;...you can just set this value during init.

JMP (Jump_Address) ;jump to the address saved at the vector

 

no_keys:

;program continues...

;-------------

 

Care must be taken that the address of vector Jump_Address does not cross a page boundry.

Share this post


Link to post
Share on other sites

i suspect i should be able to find this out but i've had a fairly detailed look through the docs i have... how do i trap for the reset button?

Share this post


Link to post
Share on other sites

I can't recall offhand, but it's just a vector that you change in zero page. Just update the 2 bytes there to hold the address of where you want the program to go on system reset. Looks like $0244 holds the cold start flag on whether to reboot. If non-zero, the system will reboot if the reset key is pressed. If zero, it won't.

Share this post


Link to post
Share on other sites
i suspect i should be able to find this out but i've had a fairly detailed look through the docs i have... how do i trap for the reset button?

 

Ok, first thing you have to ensure is, that $0244 (580) is set to zero.

If it isn´t zero the system will hard reset if the reset key is pressed.

 

Now set $0009 to one. This makes the system jumps thru the DOSVEC ($000a & $000b) if reset is done.

 

Set DOSVEC to your assumed address and it should work...

Share this post


Link to post
Share on other sites
Set DOSVEC to your assumed address and it should work...

 

[hack hack]... i had to do a little reading up but actually having an idea where to start helped; it seems to be DOSINI rather than DOSVEC but Reaxion A8 now flips back to the titles page when reset is pressed so ta very much! =-)

Share this post


Link to post
Share on other sites

TMR >>> You can also detect if OPTION key is pressed right after RESET-ting the game and if so - do a system reset ($e477). It's very useful feature, but unfortunately very uncommon...

Share this post


Link to post
Share on other sites
TMR >>> You can also detect if OPTION key is pressed right after RESET-ting the game and if so - do a system reset ($e477). It's very useful feature, but unfortunately very uncommon...

 

i was only really worried about using the reset as a quit feature, one thing that bugs me about a few games (possibly because i used to use a tape-based machine) is that hitting reset just lost the game so Reaxion just jumps back to it's titles page.

Share this post


Link to post
Share on other sites

Hi all, just to slightly change the subject away from trapping the reset key, I wondered if anyone can help with this one. I'm attempting to write what I thought would be a seemingly simple routine to change RMT song positions by pressing keys 1-9.

 

It's actually the G2f/RMT merged routines that I am trying to include this function into. with the help of the previous posts, I have attempted to include a routine.

 

I thought the best way to do this would be to create a variable "SONGNUM" which I can assign a value to depending on the key code pressed and then in the main code create a loop to continually check for the key press. As Raster suggested I have created multiple RMT songs contained in the one module so all I need to do is set the starting song line number and initiate the play routine.

 

Now here's my big problem. My 6502 experience! Here's a slice of the sourcecode from my poor first attempt which does nothing

 

 

;--- RMT music player

MODUL equ $5000 ;address of RMT module

VCOUNT equ $d40b ;vertical screen lines counter address

KEY equ $2fc ;keypressed code

VLINE equ 16 ;screen line for synchronization

SONGNUM equ 0 ;song number variable

 

>

>

>

>

 

org $6000

music ldx #

ldy #>MODUL ;hi byte of RMT module to Y reg

lda songnum ;starting song line 0-255 to A reg

jsr RASTERMUSICTRACKER ;Init

tay

lda tabpp-1,y

sta acpapx2+1 ;sync counter spacing

lda #16+0

sta acpapx1+1 ;sync counter init

;

lda $02FC

cmp #$FF

beq no_keys

lda $02fc

cmp $1F ;key 1 pressed

lda #0

sta songnum

jmp music

rts

lda $02fc

cmp $1E ;key 2 pressed

lda #3

sta songnum

jmp music

;

no_keys nop

;

Share this post


Link to post
Share on other sites

Well, there are a few fundimental problems with some of the lines...

 

lda $02FC

cmp #$FF

beq no_keys

lda $02fc ;no need to reload A...it's already got the value

cmp $1F ;comparison not even used...A is reloaded below!

lda #0

sta songnum

jmp music

;no way to reach this point...since a compare that falls thru never branches

rts

lda $02fc

cmp $1E ;same problem as above...the comparison is not used

lda #3

sta songnum

jmp music

;

no_keys: nop ;what is happening here? You can't end a M/L routine with a NOP

 

 

 

 

 

 

 

 

Here's kinda sorta the same thing your're trying to accomplish (I think)...

 

 

;start

lda $02FC

cmp #$FF

beq no_keys

cmp $1F ;check if 1

bne not_one ;branch if not

lda #0 ;otherwise, load the values and jump to the player

sta songnum

jmp music

 

not_one:

cmp $1E

bne not_two

lda #3

sta songnum

jmp music

 

not_two:

 

;etc....

 

 

 

 

;after the last comparison...

not_nine:

lda #$FF ;clear out any unused keys

sta $02FC

no_keys:

rts ;return if no matches

Share this post


Link to post
Share on other sites
Nukey Shay wrote Well, there are a few fundimental problems with some of the lines...

 

lda $02fc ;no need to reload A...it's already got the value
Oops, ah I didn't realise that i keep loading the acc with the same value for no reason!

 

cmp $1F ;comparison not even used...A is reloaded below!  

lda #0

oh right I'm trying to use the acc for more than one task when it can only hold one value at a time. should I use x or y reg to store the value into variable SONGNUM?

 

I guess the branches that never get reached will then execute as it were.

 

no_keys: nop ;what is happening here? You can't end a M/L routine with a NOP
sorry I left that in from an earlier attempt. The no_keys label should just continue to main routine. I'm not sure what to do at this point of the code.

 

Thanks for your help Nukey, appreciate it ;)[/b]

Share this post


Link to post
Share on other sites
cmp $1F ;comparison not even used...A is reloaded below!  

lda #0

oh right I'm trying to use the acc for more than one task when it can only hold one value at a time. should I use x or y reg to store the value into variable SONGNUM?

No need to (though you could make the code shorter by just using X or Y and increment it each time the compare fails). What I meant was there should be a branching instruction used just below the CMP lines. i.e. where should the program go if it doesn't match? Since -if a compare matches- the routine just JMP's to the player, it's safe to use the accumulator over (since we'll be leaving anyway).

 

One thing to keep in mind is where the program is executed. I'm not familiar with the programs you are using...and if those are trying to use the memory locations you used. For small programs like this, you could probably use page 6 (which most programs ignore). This area of memory runs from $0600 to $06FF.

Share this post


Link to post
Share on other sites

Hi Nukey, thanks for that. I've included your method into my code as follows...

 

org $6000

music ldx #

ldy #>MODUL ;hi byte of RMT module to Y reg

lda songnum ;starting song line 0-255 to A reg

jsr RASTERMUSICTRACKER ;Init

tay

lda tabpp-1,y

sta acpapx2+1 ;sync counter spacing

lda #16+0

sta acpapx1+1 ;sync counter init

jsr keychk

 

keychk lda $02FC

cmp #$FF

beq no_keys

cmp $1F ;check if 1

bne not_one ;branch if not

lda #0 ;otherwise, load the values and jump to the player

sta songnum

jmp music

 

not_one

cmp $1E

bne not_two

lda #3

sta songnum

jmp music

 

not_two

lda #$FF ;clear out any unused keys

sta $02FC

no_keys:

rts ;return if no matches

 

I'm not sure if I have this routine in the right part of the code because it has no effect. The sourcecode I am using is the merged G2F and RMT playback routines such as the fish intro that Heaven posted a while back. I think the keypress routine should go someplace else. The sourcecode also includes playback routines from the supplied RMT sources (rmtpayr.asx). I think maybe the main code is running around someplace else and never reaching the "check for key press routine" I suppose I should post my full sourcecode for the routine rather than a section but that would ruin the surprise when I post the finished project.

Share this post


Link to post
Share on other sites

Yup...you'll still need to find out a place that you can jump to your routine (patch). Look around the program and try to find an area where it's doing nothing but waiting for input. Then JSR to your routine instead of doing what it was supposed to do. If you just add programming instructions to memory, it won't accomplish anything if the running program never goes there. Once all of the comparisons fall through (where the RTS is), you can add in the instruction that it was originally doing where the new JSR (to this routine) now exists.

Share this post


Link to post
Share on other sites

Try consol for detecting keys pressed. its 53279, or $DO1F HEX

 

Just saw a program that used this, but I have not tried it.

Share this post


Link to post
Share on other sites

AFAIK, the low nybble of that location is used to hold the 3 function keys (Option, Select, Start).

Share this post


Link to post
Share on other sites

Hi Tezz,

 

try to do this as its own routine. Insert a jsr yourroutine just before the jsr music at main.

 

Every jmp music has to be rts within your routine.

 

At the shown state the program calls itselves again and again...

Share this post


Link to post
Share on other sites

pps, Nukey Shay Thanks for that guys, I thought that I had included the routine in the wrong place. I'll try that out later on tonight when I get home from work! :)

Share this post


Link to post
Share on other sites

Arrrrr :? Still can't get this to work??? I've tried placing a jsr to my routine just before the jsr music at main. Also tried some other locations.

 

I seem to get either the loading message freezing which I guess means that my routine is caught in its own loop or that my added routine doesn't rts back to the right location.

 

or I get the picture and RMT track playing with no keypress routine??

 

I'm really confused by this. Anyone got any further ideas for where I'm going wrong?

Share this post


Link to post
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.

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...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...