Reading keyboard status, with keypress sound and cursor flashing disabled

Here you can ask questions or provide insights about how to use efficiently 6502 assembly code on the Oric.
User avatar
marmakoide
Private
Posts: 3
Joined: Tue Apr 21, 2020 2:52 pm
Location: Aquitaine, France
Contact:

Reading keyboard status, with keypress sound and cursor flashing disabled

Post by marmakoide »

I'm working on Oric 1, with latest Oricutron fresh for its github repository.

I'm trying to put together some assembler code that read the keyboard status and display something, using the full TEXT screen and without the cursor flashing. I mostly got it, I just want to get rid of the keypress sounds. I'm a bit puzzled over that later issue.

In Basic, I can stop the cursor flashing and the keyboard sounds with this command

Code: Select all

POKE #026A, (PEEK(#026A) AND 254) OR 8
I translated this command in assembler (I use XA syntax as it seems the de-facto standard here)

Code: Select all

#define ORIC1_STATUS_ADDR $026A
#define ORIC1_STATUS_CURSOR_BLINK   %10000000 ; 1 to enable
#define ORIC1_STATUS_KEYBOARD_SOUND 8 ; 0 to enable

; --- disable cursor blinking and keyboard sound
lda ORIC1_STATUS_ADDR
ora #ORIC1_STATUS_KEYBOARD_SOUND
sta ORIC1_STATUS_ADDR

lda ORIC1_STATUS_ADDR
and #!ORIC1_STATUS_CURSOR_BLINK
sta ORIC1_STATUS_ADDR
While the cursor is disabled, the keypress still triggers a sound.

Even more puzzling : if only disable the keyboard sound, and keep the cursor flashing on, the sound is disabled properly !

Code: Select all

#define ORIC1_STATUS_ADDR $026A
#define ORIC1_STATUS_CURSOR_BLINK   %10000000 ; 1 to enable
#define ORIC1_STATUS_KEYBOARD_SOUND 8 ; 0 to enable

; --- disable keyboard sound
lda ORIC1_STATUS_ADDR
ora #ORIC1_STATUS_KEYBOARD_SOUND
sta ORIC1_STATUS_ADDR

Here's the routine I use to read they keyboard status, copied verbatim from the (excellent) "Oric Atmos and Oric 1 Graphics and Machine Code Techniques" book by Geoff Phililps.

Code: Select all

; -----------------------------------------------------------------------------
; Read keyboard keys state
;    - key's row on keyboard A
;    - key's column on keyboard in X
;    - Result is given by zero status flag
; -----------------------------------------------------------------------------
#define ORIC1_ROM_WRITE_TO_8192_CHIP $F535

_is_key_pressed
.(
	php
	sei
	pha
	lda #$0E
	jsr ORIC1_ROM_WRITE_TO_8192_CHIP
	pla
	ora #$B8
	sta $0300
	ldx #$04
_loop
	dex
	bne _loop
	lda $0300
	and #$08	
	tax
	plp
	txa
	rts
.)
I call this routine as following

Code: Select all

		; --- check for key D status
		lda #ORIC_ROW_KEY_D
		ldx #ORIC_COL_KEY_D
		jsr _is_key_pressed

		; --- if D is pressed, update cursor column
		beq _d_key_not_pressed
		.(
		   ; do stuffs
		.)
		_d_key_not_pressed
What the heck is going on ?! Is it a good idea to rely on the ROM routines to handle the keyboard ?
User avatar
ibisum
Wing Commander
Posts: 1645
Joined: Fri Apr 03, 2009 8:56 am
Location: Vienna, Austria
Contact:

Re: Reading keyboard status, with keypress sound and cursor flashing disabled

Post by ibisum »

Disable interrupts first?

BTW does anyone have the "Oric Atmos and Oric 1 Graphics and Machine Code Techniques" book by Geoff Phililps? Archive.org's copy of the .zip seems to be corrupt ..
User avatar
marmakoide
Private
Posts: 3
Joined: Tue Apr 21, 2020 2:52 pm
Location: Aquitaine, France
Contact:

Re: Reading keyboard status, with keypress sound and cursor flashing disabled

Post by marmakoide »

@ibisum Where do you think I should be disabling/enabling interrupts ?
User avatar
iss
Wing Commander
Posts: 1641
Joined: Sat Apr 03, 2010 5:43 pm
Location: Bulgaria
Contact:

Re: Reading keyboard status, with keypress sound and cursor flashing disabled

Post by iss »

Here you are:

Code: Select all

.text
* = $1000
_entry
        lda $026A
        ora #%00001000
        and #%01111111      ; and #!%10000000 <-- doesn't work
        sta $026A
        rts
Your code works fine, but the problem is in the '!' - it's not a 'NOT' operation. From the XA manual:

Code: Select all

          !    in situations where the expression could be understood
               as either an absolute or zero page value, do not
               attempt to optimize to a zero page argument for those
               opcodes that support it (i.e., keep as 16 bit word)
EDIT: The Geoff's book is attached below because wayback machine returns only partial file.
Attachments
Geoff_Phillips-book.pdf.zip
(2.93 MiB) Downloaded 1178 times
User avatar
marmakoide
Private
Posts: 3
Joined: Tue Apr 21, 2020 2:52 pm
Location: Aquitaine, France
Contact:

Re: Reading keyboard status, with keypress sound and cursor flashing disabled

Post by marmakoide »

Nice catch ! It all makes sense now, thanks you ! The bit order is the other way tho

Code: Select all

	lda ORIC1_STATUS_ADDR
	ora #%00001000 ; disable sound
	and #%11111110 ; disable cursor blinking
	sta ORIC1_STATUS_ADDR
User avatar
iss
Wing Commander
Posts: 1641
Joined: Sat Apr 03, 2010 5:43 pm
Location: Bulgaria
Contact:

Re: Reading keyboard status, with keypress sound and cursor flashing disabled

Post by iss »

Cool!
For more info about Geoff's keyboard routine check this OLD POST ... and the book is available in the DF Library too. :)
User avatar
Dbug
Site Admin
Posts: 4444
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: Reading keyboard status, with keypress sound and cursor flashing disabled

Post by Dbug »

I checked the code of the assembler, it does not have any support for the bitwise negation of values.

Guess that would make sense to add, not sure if that should use "!" or "~", personally, considering that many of the expressions in the XA preprocessor are C compatible, I would go with the "~" symbol, this way it's compatible :)

so

LDA #0 -> 0
LDA #~0 -> FF

would that make sense?
User avatar
iss
Wing Commander
Posts: 1641
Joined: Sat Apr 03, 2010 5:43 pm
Location: Bulgaria
Contact:

Re: Reading keyboard status, with keypress sound and cursor flashing disabled

Post by iss »

@Dbug: I'm not sure that the case requires any action at all.

You know XA supports bitwise XOR with '^', so it's easy to use #defines:

Code: Select all

#define val       1
#define xorval    ($ff ^ val)
...
        and #xorval
...

or macro with parameter:

Code: Select all

#define val       1
#define xor(x)    ($ff ^ x)
...
        and #xor(val)
...
User avatar
Dbug
Site Admin
Posts: 4444
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: Reading keyboard status, with keypress sound and cursor flashing disabled

Post by Dbug »

should probably be "notval" instead of "xorval", but yes, makes sense :)
User avatar
Chema
Game master
Posts: 3014
Joined: Tue Jan 17, 2006 10:55 am
Location: Gijón, SPAIN
Contact:

Re: Reading keyboard status, with keypress sound and cursor flashing disabled

Post by Chema »

I was about to post in the same direction... using the ^$ff for bitwise NOT operation, but it would not make harm to have a ~ operator. In any case, I am not sure if modifying XA to include it just for the OSDK is worthwhile.
Post Reply