Multi-Key Handling
Multi-Key Handling
Hi,
I m looking for a multi-key press handling C script
I saw that Chema did it with Blake's 7 ( with the arrow ) . but don't found this code.
Is it possible to use a such routine since the C ?
I m looking for a multi-key press handling C script
I saw that Chema did it with Blake's 7 ( with the arrow ) . but don't found this code.
Is it possible to use a such routine since the C ?
Re: Multi-Key Handling
Hi goyo!
For keyboard handling I always use an idea from Dbug, which consists in updating a virtual matrix of 1s and 0s representing the state of each key (pressed or released). This matrix is updated from the interrupt service routine. You can find the code in assembler here http://miniserve.defence-force.org/svn/ ... keyboard.s
The routine is called ReadKeyboard. There are also 3 more routines used to read a single key and return its ASCII code, with and without bouncing (repeating) and one to wait for a key press.
It is surely possible to add the Readkeyboard routine in asm to your C project and export the virtual matrix as a global C variable so you can use it from C. The ReadKeyboard routine should be called from the interrupt handler, but that can be done with the chain_irq library function or directly in asm in your project.
I could give some examples, but I am not near my laptop now. Holidays, you know![Wink ;)](./images/smilies/icon_wink.gif)
Hope this helps.
For keyboard handling I always use an idea from Dbug, which consists in updating a virtual matrix of 1s and 0s representing the state of each key (pressed or released). This matrix is updated from the interrupt service routine. You can find the code in assembler here http://miniserve.defence-force.org/svn/ ... keyboard.s
The routine is called ReadKeyboard. There are also 3 more routines used to read a single key and return its ASCII code, with and without bouncing (repeating) and one to wait for a key press.
It is surely possible to add the Readkeyboard routine in asm to your C project and export the virtual matrix as a global C variable so you can use it from C. The ReadKeyboard routine should be called from the interrupt handler, but that can be done with the chain_irq library function or directly in asm in your project.
I could give some examples, but I am not near my laptop now. Holidays, you know
![Wink ;)](./images/smilies/icon_wink.gif)
Hope this helps.
Re: Multi-Key Handling
Thanks a lot Chema i think that is i wanted !
I ll try to understand this script... and call it from C
have good Holidays , maybe a good time to think about a new genial Oric game !![Wink :wink:](./images/smilies/icon_wink.gif)
I ll try to understand this script... and call it from C
have good Holidays , maybe a good time to think about a new genial Oric game !
![Wink :wink:](./images/smilies/icon_wink.gif)
- ibisum
- Wing Commander
- Posts: 1655
- Joined: Fri Apr 03, 2009 8:56 am
- Location: Vienna, Austria
- Contact:
Re: Multi-Key Handling
Awesome thread!
Re: Multi-Key Handling
In my projects I'm using the Dbug/Chema keyboard routines too (with some minor modifications related to cc65 compatibility) - everything works nice!
But for multi-key handling there is already another routine from Geoff Philips's
Oric Atmos and Oric 1 Graphics and Machine code techniques - in DF library (see chap.4).
The idea is to "ask" for status of particular key. Here is the code (ready for copy/paste):
Next you need to create small sub-routines per your needs, for instance to check if keys 'A' AND 'Z' are pressed export these functions:
Now you can use from C:
That's it! ![Smile :)](./images/smilies/icon_smile.gif)
But for multi-key handling there is already another routine from Geoff Philips's
Oric Atmos and Oric 1 Graphics and Machine code techniques - in DF library (see chap.4).
The idea is to "ask" for status of particular key. Here is the code (ready for copy/paste):
Code: Select all
; ------------------------------------------------------------------
; from Oric Atmos and Oric 1 Graphics and Machine code techniques
; by Geoff Philips (See chapter 4.)
; ------------------------------------------------------------------
; Routine to check for particular key
; ------------------------------------------------------------------
; Key required Accumulator X register
; ------------------------------------------------------------------
; 1 2 3 0 2 0 DF BF 7F
; 4 5 6 2 0 2 F7 FB FD
; 7 8 9 0 7 3 FE FE FD
; 0 -= 7 3 7 FB F7 7F
; \ ESC Q 3 1 1 BF DF BF
; W E R 6 6 1 7F F7 FB
; T Y U 1 6 5 FD FE FE
; I 0 P 5 5 5 FD FB F7
; [ ] DEL 5 5 5 7F BF DF
; CTRL A S 2 6 6 EF DF BF
; D F G 1 1 6 7F F7 FB
; H J K 6 1 3 FD FE FE
; L ; “ 7 3 3 FD FB 7F
; RETURN 7 DF
; SHIFT (LEFT) 4 EF
; Z X C 2 0 2 DF BF 7F
; VBN 0 2 0 F7 FB FD
; M comma period 2 4 4 FE FD FB
; / SHIFT (RIGHT) 7 7 F7 EF
; LEFT ARROW 4 DF
; DOWN ARROW 4 BF
; SPACE 4 FE
; UP ARROW 4 F7
; RIGHT ARROW 4 7F
; ------------------------------------------------------------------
check_key
php
sei
pha
lda #$0e
jsr $f590 ; ROM1.0 $f535
pla
ora #$b8
sta $0300
ldx #$04
delay dex
bne delay
lda $0300
and #$08
tax
plp
txa
rts
Code: Select all
; key A => 6 + DF
_check_A
lda #$06
ldx #$df
jmp check_key
; key Z => 2 + DF
_check_Z
lda #$02
ldx #$df
jmp check_key
Code: Select all
if (check_A() && check_Z())
{
// both keys A and Z are pressed
}
![Smile :)](./images/smilies/icon_smile.gif)
- ibisum
- Wing Commander
- Posts: 1655
- Joined: Fri Apr 03, 2009 8:56 am
- Location: Vienna, Austria
- Contact:
Re: Multi-Key Handling
Also nice, but what I like about Dbug/Chema/Twi's approach, is the bonus sound handler ..
Re: Multi-Key Handling
Thank you Iss, It's work fine !!!iss wrote: ↑Thu Aug 22, 2019 4:07 pm In my projects I'm using the Dbug/Chema keyboard routines too (with some minor modifications related to cc65 compatibility) - everything works nice!
But for multi-key handling there is already another routine from Geoff Philips's
Oric Atmos and Oric 1 Graphics and Machine code techniques - in DF library (see chap.4).
The idea is to "ask" for status of particular key. Here is the code (ready for copy/paste):Next you need to create small sub-routines per your needs, for instance to check if keys 'A' AND 'Z' are pressed export these functions:Code: Select all
; ------------------------------------------------------------------ ; from Oric Atmos and Oric 1 Graphics and Machine code techniques ; by Geoff Philips (See chapter 4.) ; ------------------------------------------------------------------ ; Routine to check for particular key ; ------------------------------------------------------------------ ; Key required Accumulator X register ; ------------------------------------------------------------------ ; 1 2 3 0 2 0 DF BF 7F ; 4 5 6 2 0 2 F7 FB FD ; 7 8 9 0 7 3 FE FE FD ; 0 -= 7 3 7 FB F7 7F ; \ ESC Q 3 1 1 BF DF BF ; W E R 6 6 1 7F F7 FB ; T Y U 1 6 5 FD FE FE ; I 0 P 5 5 5 FD FB F7 ; [ ] DEL 5 5 5 7F BF DF ; CTRL A S 2 6 6 EF DF BF ; D F G 1 1 6 7F F7 FB ; H J K 6 1 3 FD FE FE ; L ; “ 7 3 3 FD FB 7F ; RETURN 7 DF ; SHIFT (LEFT) 4 EF ; Z X C 2 0 2 DF BF 7F ; VBN 0 2 0 F7 FB FD ; M comma period 2 4 4 FE FD FB ; / SHIFT (RIGHT) 7 7 F7 EF ; LEFT ARROW 4 DF ; DOWN ARROW 4 BF ; SPACE 4 FE ; UP ARROW 4 F7 ; RIGHT ARROW 4 7F ; ------------------------------------------------------------------ check_key php sei pha lda #$0e jsr $f590 ; ROM1.0 $f535 pla ora #$b8 sta $0300 ldx #$04 delay dex bne delay lda $0300 and #$08 tax plp txa rts
Now you can use from C:Code: Select all
; key A => 6 + DF _check_A lda #$06 ldx #$df jmp check_key ; key Z => 2 + DF _check_Z lda #$02 ldx #$df jmp check_key
That's it!Code: Select all
if (check_A() && check_Z()) { // both keys A and Z are pressed }
![]()
Code: Select all
unsigned char check_A();
unsigned char check_7();
void main()
{
while (1)
{
if (check_A() && check_Z())
{
printf("// both keys A and Z are pressed !\n");
}
}
}
Re: Multi-Key Handling
In my C program, can I use the matrix like this to read it ?Chema wrote: ↑Thu Aug 22, 2019 2:30 pm Hi goyo!
For keyboard handling I always use an idea from Dbug, which consists in updating a virtual matrix of 1s and 0s representing the state of each key (pressed or released). This matrix is updated from the interrupt service routine. You can find the code in assembler here http://miniserve.defence-force.org/svn/ ... keyboard.s
The routine is called ReadKeyboard. There are also 3 more routines used to read a single key and return its ASCII code, with and without bouncing (repeating) and one to wait for a key press.
It is surely possible to add the Readkeyboard routine in asm to your C project and export the virtual matrix as a global C variable so you can use it from C. The ReadKeyboard routine should be called from the interrupt handler, but that can be done with the chain_irq library function or directly in asm in your project.
I could give some examples, but I am not near my laptop now. Holidays, you know
Hope this helps.
Code: Select all
unsigned char extern KeyBank[8];
keyboard.s
; The virtual Key Matrix
_KeyBank .dsb 8
Re: Multi-Key Handling
It's very nice to make a multi-player game !!
![Wink :wink:](./images/smilies/icon_wink.gif)
I think they are no many on Oric.
Code: Select all
void extern InitISR();
unsigned char extern KeyBank[8];
void main()
{
unsigned char i;
InitISR();
while (1)
{
gotoxy(4,10);
for (i=0;i<8;i++)
printf("[%d]",peek(KeyBank+i));;
}
}
Re: Multi-Key Handling
Don't thank me! It was Dbug's idea ![Very Happy :D](./images/smilies/icon_biggrin.gif)
![Very Happy :D](./images/smilies/icon_biggrin.gif)
Re: Multi-Key Handling
Chema wrote: ↑Thu Aug 22, 2019 2:30 pm Hi goyo!
For keyboard handling I always use an idea from Dbug, which consists in updating a virtual matrix of 1s and 0s representing the state of each key (pressed or released). This matrix is updated from the interrupt service routine. You can find the code in assembler here http://miniserve.defence-force.org/svn/ ... keyboard.s
hi all,
I get an error trying to follow the link to Blake's 7 sources. Are they still available somewhere? Didn't find them on DF's page for the game.
Thanks
![Wink ;)](./images/smilies/icon_wink.gif)
S.
Re: Multi-Key Handling
Hi Symoon!
The sources are accesible from the link at the top-right in the game website https://www.defence-force.org/index.php ... me=blakes7
But there have been some problems with the repo recently... not sure if they are accesible right now.
So here is my local copy: Cheers!
The sources are accesible from the link at the top-right in the game website https://www.defence-force.org/index.php ... me=blakes7
But there have been some problems with the repo recently... not sure if they are accesible right now.
So here is my local copy: Cheers!
Re: Multi-Key Handling
Ooooh thanks. I've been looking carefully in the article, but not thereChema wrote: ↑Tue Oct 31, 2023 8:40 pmThe sources are accesible from the link at the top-right in the game website https://www.defence-force.org/index.php ... me=blakes7
![Laughing :lol:](./images/smilies/icon_lol.gif)
Thanks a lot!
I'm trying to learn about the keyboard and collecting various sources before divning into it. It's quite possible that I'll "borrow" some code from you in the future
![Embarassed :oops:](./images/smilies/icon_redface.gif)
![Wink ;)](./images/smilies/icon_wink.gif)
EDIT: indeed, it seems a bit complicated to get the sources using the osdn.net link.
Re: Multi-Key Handling
Yup, I need to find another solution.
OSDN was supposed to be great - even if wonky - because it was were quite a few big open source projects were hosted, but it ended up being quite poor in performance, and support is basically inexistant.
OSDN was supposed to be great - even if wonky - because it was were quite a few big open source projects were hosted, but it ended up being quite poor in performance, and support is basically inexistant.