Assembling Z80 source using TASM or similar

jejump
Posts: 31
Joined: Tue Jun 04, 2019 9:32 pm

Re: Assembling Z80 source using TASM or similar

Post by jejump »

Sorry, I just realized the '700 has five function keys, not four. Anyway, none of them do anything using the above program.
 

Jj
User avatar
Pacman
Posts: 172
Joined: Mon Feb 05, 2018 2:59 pm

Re: Assembling Z80 source using TASM or similar

Post by Pacman »

From my head, it seems to me that the monitor 1Z-013A does not take into account the function keys, hence the non detection. To be checked with the function $001B (GETKEY)
User avatar
Pacman
Posts: 172
Joined: Mon Feb 05, 2018 2:59 pm

Re: Assembling Z80 source using TASM or similar

Post by Pacman »

To do this, you must test line 10 and recover the active bit (s) (low state) when a function key is pressed.
kbmatrix2.gif
kbmatrix2.gif (15.42 KiB) Viewed 5217 times
jejump
Posts: 31
Joined: Tue Jun 04, 2019 9:32 pm

Re: Assembling Z80 source using TASM or similar

Post by jejump »

 
I was afraid that would be the answer. There's hardly mention at all of the function keys in this list of calls:
 

https://www.sharpmz.no/articles/the-mz ... z-1z013a/

Oh well... No biggie! I'll just follow your instruction, Pacman. I really want those keys available in my later application. Thanks for the reply!
 
 
Jj
jejump
Posts: 31
Joined: Tue Jun 04, 2019 9:32 pm

Re: Assembling Z80 source using TASM or similar

Post by jejump »

Confirm if you can, that my understanding of the matrix is correct. It appears that if I write a column value ($F0 to $F9) to address $E000, then read back the row value on address $E001 and CP against the key of interest ($7F, $BF, $DF... $FE), I can confirm whether the key of interest was pressed or not. True?
jejump
Posts: 31
Joined: Tue Jun 04, 2019 9:32 pm

Re: Assembling Z80 source using TASM or similar

Post by jejump »

 
 
YES! I was correct. I added this to my program and now I can see the hexadecimal numbers $F1 to $F4 correspond to F1 to F4 keys respectively. Lovely learning experience!
 

Code: Select all

CHECK_F_KEYS:
	LD	DE, $E000
	LD	A, $F9
	LD	(DE), A
	LD	DE, $E001
	LD	A, (DE)
	CP	$7F
	JP	NZ, CHECK_F2
	LD	A, $F1
	CALL	PRINT_CODE
	JP	EXIT_F_KEYS
CHECK_F2:
	CP	$BF
	JP	NZ, CHECK_F3
	LD	A, $F2
	CALL	PRINT_CODE
	JP	EXIT_F_KEYS
CHECK_F3:
	CP	$DF
	JP	NZ, CHECK_F4
	LD	A, $F3
	CALL	PRINT_CODE
	JP	EXIT_F_KEYS
CHECK_F4:
	CP	$EF
	JP	NZ, EXIT_F_KEYS
	LD	A, $F4
	CALL	PRINT_CODE
EXIT_F_KEYS:
	RET
	
	
jejump
Posts: 31
Joined: Tue Jun 04, 2019 9:32 pm

Re: Assembling Z80 source using TASM or similar

Post by jejump »

 
:roll: And AGAIN!... I forgot there are FIVE function keys.
 
 
hlide
Posts: 681
Joined: Thu Jan 25, 2018 9:31 pm

Re: Assembling Z80 source using TASM or similar

Post by hlide »

I tend to keep them in a bitmask so I can press them simultaneaously (going right with [->] and firing with [SP] for instance).

This one I used for Brick Buster:

Code: Select all

; -----------------------------------------------------------------------------
; Reset keyboard
; --------------
; in:
;	none
; out:
;	flag Z = 1 if no change else 0
kbd_reset:
		XOR		A
		JP		@0f
; -----------------------------------------------------------------------------
; Read keyboard
; -------------
; in:
;	none
; out:
;	A = current keymap - one bit set to 1 means keypressed
;		(bit 7: [BREAK], bits 6,5,4: [F1][F2][F3], bit 2: [SPACE], bits 1,0: [->][<-])
;	C = previous keymap - same rationale as current keymap
;	flag Z = 1 if no change else 0
kbd_read:
		LD		HL,PPI8255_KEYPA	; port A to select keyboard matrix column
		LD		DE,PPI8255_KEYPB	; port B to read keyboard matrix row
		LD		B,$F0+6			; matrix column 6
		LD		(HL),B			; select keyboard matrix column containing SPACE key
		LD		A,(DE)			; read keyboard matrix row
		CPL
		AND		$10			; SPACE bit
		LD		C,A
		INC		B			; matrix column 7
		LD		(HL),B			; select keyboard matrix column containing [<-/->] arrows keys
		LD		A,(DE)			; read keyboard matrix row
		CPL
		AND		$0C			; [<-] and [->] arrows bits
		OR		C
		RRCA
		RRCA
		LD		C,A
		INC		B			; matrix column 8
		LD		(HL),B			; select keyboard matrix column containing [BREAK] key
		LD		A,(DE)			; read keyboard matrix row
		CPL
		AND		$80			; BREAK bit
		OR		C
		LD		C,A
		INC		B
		LD		(HL),B			; select keyboard matrix column containing [F1/F2/F3] keys
		LD		A,(DE)			; read keyboard matrix row
		CPL
		AND		$E0			; [F1/F2/F3] bits
		RRCA
		OR		C
@0:		LD		HL,kbd_keymap
		LD		C,(HL)			; retrieve previous keymap in C register
		CP		C			; compare it to current keymap in A register
		RET		Z			; no change of key status
		LD		(HL),A
		RET
 
jejump
Posts: 31
Joined: Tue Jun 04, 2019 9:32 pm

Re: Assembling Z80 source using TASM or similar

Post by jejump »

Ahhh, good maneuver! The way I have my code written, only one F-key can be detected until it's released. I'll keep that in mind.
NoWone
Posts: 1
Joined: Thu Aug 10, 2023 7:05 pm

Re: Assembling Z80 source using TASM or similar

Post by NoWone »

I'm sorry total Z80 asm newbie here.

Is it possible to create a .mzt/.mzf file from an object file assembled with sjasmplus or the assembler in the z88dk toolchain?
Post Reply