Multi-Key Handling

Since we do not have native C compilers on the Oric, this forum will be mostly be used by people using CC65 or the OSDK. But any general C related post will be welcome !
User avatar
goyo
Officer Cadet
Posts: 52
Joined: Sat Jan 12, 2019 10:16 am

Multi-Key Handling

Post by goyo »

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 ?
User avatar
Chema
Game master
Posts: 3013
Joined: Tue Jan 17, 2006 10:55 am
Location: Gijón, SPAIN
Contact:

Re: Multi-Key Handling

Post by Chema »

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.
User avatar
goyo
Officer Cadet
Posts: 52
Joined: Sat Jan 12, 2019 10:16 am

Re: Multi-Key Handling

Post by goyo »

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:
User avatar
ibisum
Wing Commander
Posts: 1643
Joined: Fri Apr 03, 2009 8:56 am
Location: Vienna, Austria
Contact:

Re: Multi-Key Handling

Post by ibisum »

Awesome thread!
User avatar
iss
Wing Commander
Posts: 1637
Joined: Sat Apr 03, 2010 5:43 pm
Location: Bulgaria
Contact:

Re: Multi-Key Handling

Post by iss »

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):

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
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

;  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
Now you can use from C:

Code: Select all

if (check_A() && check_Z())
{
    // both keys A and Z are pressed
}
That's it! :)
User avatar
ibisum
Wing Commander
Posts: 1643
Joined: Fri Apr 03, 2009 8:56 am
Location: Vienna, Austria
Contact:

Re: Multi-Key Handling

Post by ibisum »

Also nice, but what I like about Dbug/Chema/Twi's approach, is the bonus sound handler ..
User avatar
goyo
Officer Cadet
Posts: 52
Joined: Sat Jan 12, 2019 10:16 am

Re: Multi-Key Handling

Post by goyo »

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):

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
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

;  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
Now you can use from C:

Code: Select all

if (check_A() && check_Z())
{
    // both keys A and Z are pressed
}
That's it! :)
Thank you Iss, It's work fine !!!

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");
	}
    }
}
User avatar
goyo
Officer Cadet
Posts: 52
Joined: Sat Jan 12, 2019 10:16 am

Re: Multi-Key Handling

Post by goyo »

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.
In my C program, can I use the matrix like this to read it ?

Code: Select all

unsigned char extern KeyBank[8];

keyboard.s
; The virtual Key Matrix
_KeyBank .dsb 8

User avatar
Chema
Game master
Posts: 3013
Joined: Tue Jan 17, 2006 10:55 am
Location: Gijón, SPAIN
Contact:

Re: Multi-Key Handling

Post by Chema »

Yep :D
User avatar
goyo
Officer Cadet
Posts: 52
Joined: Sat Jan 12, 2019 10:16 am

Re: Multi-Key Handling

Post by goyo »

multikey.zip
(9.7 KiB) Downloaded 359 times
It's work fine ! Thank you Chema!

It's very nice to make a multi-player game !! :wink:
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));;		
  }  
}
 
User avatar
Chema
Game master
Posts: 3013
Joined: Tue Jan 17, 2006 10:55 am
Location: Gijón, SPAIN
Contact:

Re: Multi-Key Handling

Post by Chema »

Don't thank me! It was Dbug's idea :D
User avatar
Symoon
Archivist
Posts: 2301
Joined: Sat Jan 14, 2006 12:44 am
Location: Paris, France

Re: Multi-Key Handling

Post by Symoon »

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 ;)
S.
User avatar
Chema
Game master
Posts: 3013
Joined: Tue Jan 17, 2006 10:55 am
Location: Gijón, SPAIN
Contact:

Re: Multi-Key Handling

Post by Chema »

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:
keyboard.zip
(2.71 KiB) Downloaded 62 times
Cheers!
User avatar
Symoon
Archivist
Posts: 2301
Joined: Sat Jan 14, 2006 12:44 am
Location: Paris, France

Re: Multi-Key Handling

Post by Symoon »

Chema 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
Ooooh thanks. I've been looking carefully in the article, but not there :lol:
Chema wrote: Tue Oct 31, 2023 8:40 pm So here is my local copy:
keyboard.zip
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 :oops: ;)

EDIT: indeed, it seems a bit complicated to get the sources using the osdn.net link.
User avatar
Dbug
Site Admin
Posts: 4437
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: Multi-Key Handling

Post by Dbug »

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.
Post Reply