Page 1 of 2
ps2 code help request
Posted:
22 Jan 2012, 18:23
by justine
Could someone help me by making a routine that when called would read the PS2 keyboard and output in A either the ASCII character or any other keys like F1 , F2 etc and these would have a value of 128 + .
And provide the keyboard map with values.
Many thanx in advance
Re: ps2 code help request
Posted:
23 Jan 2012, 10:38
by Budder
here is my PS/2 handler, that i use in WildCommander:
http://zx-evo-fpga.googlecode.com/svn/branches/tslabs/pentevo/soft/WC/source/003!%20%20%20PS2P.ASMfor use: just add
CALL PSD2 at Interrupts.
and use this code for init (at the start):- Code: Select all
LD BC,#EFF7,A,#80:OUT A;also see specs for this port!
LD BC,#DFF7,A,#F0:OUT A
LD BC,#BFF7,A,#02:OUT A
if you need get char (like 0-9/)-!,a-z/A-Z): use
CLAvA function.
for specific keyz (like F1-F12/TAB/cursors): use dedicated functions (UPPP,DWWW,...,ESC,F1-F10 etc). also see source code.
P.S. PS/2 module is not finished yet...
Re: ps2 code help request
Posted:
23 Jan 2012, 19:21
by justine
Thanx Budder
Having comments in English really helps me understand how these routines work.
Re: ps2 code help request
Posted:
25 Jan 2012, 16:57
by justine
I am trying to make my own PS2 routine that should read a value from the buffer and return with the value in A. At the moment i am using my PUTCHAR routine which display an character on screen who's input is in A . But i dont see any character changing on screen. Later when this works i will start on decoding the values to key presses.
Can someone look at this code and see what i am doing wrong , why i get no values in A each time call READ_BUFFER .
- Code: Select all
PENT_CONF EQU $EFF7
CMOS_ON EQU $80
CMOS_OFF EQU 0
CMOS_SET_ADR EQU $DFF7
CMOS_RD_WR EQU $BFF7
; Out A - Key value
READ_KEY LD H,$0C
CALL READCMOS ; 0X0C CMOS
SET 0,L ; 0=1
CALL WRITECMOS
LD HL,$F002 ; Enable PS2 keyboard
CALL WRITECMOS
READ_BUFFER LD H,$F0 ; Read key buffer
CALL READCMOS
AND A
JR Z,READ_BUFFER
INC A
JR Z,READ_KEY ; FF
; Out Value in A
RET
; In H - Address of cmos register. In L - Data from register
READCMOS DI
PUSH BC
LD BC,PENT_CONF
LD A,CMOS_ON
OUT (C),A
LD BC,(CMOS_SET_ADR)
OUT (C),H
LD BC,(CMOS_RD_WR)
IN L,(C)
JR OFF_CMOS
; In H - Address of cmos register. Out L - Data to register
WRITECMOS DI
PUSH BC
LD BC,PENT_CONF
LD A,CMOS_ON
OUT (C),A
LD BC,(CMOS_SET_ADR)
OUT (C),H
LD BC,(CMOS_RD_WR)
OUT (C),L
OFF_CMOS LD A,CMOS_OFF
LD BC,(PENT_CONF)
OUT (C),A
POP BC
LD A,L
AND A
RET
Thanx Guys.
Re: ps2 code help request
Posted:
25 Jan 2012, 17:30
by DimkaM
- Code: Select all
PENT_CONF EQU $EFF7
CMOS_ON EQU $80
CMOS_OFF EQU 0
CMOS_SET_ADR EQU $DFF7
CMOS_RD_WR EQU $BFF7
; Out A - Key value
READ_KEY LD H,$0C
CALL READCMOS ; 0X0C CMOS
SET 0,L ; 0=1
CALL WRITECMOS
LD HL,$F002 ; Enable PS2 keyboard
CALL WRITECMOS
READ_BUFFER LD H,$F0 ; Read key buffer
CALL READCMOS
AND A
JR Z,READ_BUFFER
INC A
JR Z,READ_KEY ; FF
; Out Value in A
RET
; In H - Address of cmos register. In L - Data from register
READCMOS DI
PUSH BC
LD BC,PENT_CONF
LD A,CMOS_ON
OUT (C),A
LD BC,CMOS_SET_ADR
OUT (C),H
LD BC,CMOS_RD_WR
IN L,(C)
JR OFF_CMOS
; In H - Address of cmos register. Out L - Data to register
WRITECMOS DI
PUSH BC
LD BC,PENT_CONF
LD A,CMOS_ON
OUT (C),A
LD BC,CMOS_SET_ADR
OUT (C),H
LD BC,CMOS_RD_WR
OUT (C),L
OFF_CMOS LD A,CMOS_OFF
LD BC,PENT_CONF
OUT (C),A
POP BC
LD A,L
AND A
RET
Re: ps2 code help request
Posted:
25 Jan 2012, 17:34
by DimkaM
PENT_CONF EQU $EFF7 ;ld bc,PENT_CONF
PENT_CONF WORD $EFF7 ; ld bc,(PENT_CONF)
Re: ps2 code help request
Posted:
25 Jan 2012, 18:14
by justine
I must be doing something wrong ??
I corrected the silly mistakes as pointed out by DimkaM but i still get nothing.
All i want is a routine i can call that will read a byte from the ps2 buffer then store the value in A .
And i call it again i will get the next byte etc and it must clear the buffer when full once all data is read out.
Re: ps2 code help request
Posted:
25 Jan 2012, 19:28
by lvd
justine, you should then take alasm with sts, compile and step your code on real machine.
Re: ps2 code help request
Posted:
26 Jan 2012, 01:08
by Budder
justine, why you use opening/closing ports every CALL? for what reason?
added INIT function:- Code: Select all
PENT_CONF EQU $EFF7
CMOS_ON EQU $80
CMOS_OFF EQU 0
CMOS_SET_ADR EQU $DFF7
CMOS_RD_WR EQU $BFF7
;-------------------------------------
ORG #6000
CALL INIT
;---------------
CALL READ_KEY
CALL PRINT_CHAR;put here your print function
;---------------
CALL TERMINATE
RET
;-------------------------------------
;opening CMOS ports:
;(you should do this ONCE!)
INIT LD BC,PENT_CONF
LD A,CMOS_ON
OUT A;=OUT (C),A
HL,$F002; write #02 to #F0
CALL WRITECMOS
RET
TERMINATE LD BC,PENT_CONF
LD A,CMOS_OFF
OUT A
RET
CLEAR_BUFFER LD HL,$0C01;
CALL WRITECMOS
; Out A - Key value
READ_KEY
;LD H,$F0
;CALL READCMOS ; 0X0C CMOS
;SET 0,L ; 0=1
;CALL WRITECMOS
;LD HL,$F002 ; Enable PS2 keyboard
;CALL WRITECMOS
READ_BUFFER LD H,$F0 ; Read key buffer
CALL READCMOS
OR A
JR Z,READ_BUFFER
CP #FF
JR Z,CLEAR_BUFFER
;INC A
;JR Z,READ_KEY ; FF
;Out Value in A
RET
; In H - Address of cmos register. In L - Data from register
READCMOS PUSH BC
;LD BC,PENT_CONF
;LD A,CMOS_ON
;OUT (C),A
LD BC,CMOS_SET_ADR
OUT (C),H
LD BC,CMOS_RD_WR
IN L,(C)
POP BC
RET; JR OFF_CMOS
; In H - Address of cmos register. Out L - Data to register
WRITECMOS PUSH BC
;LD BC,PENT_CONF
;LD A,CMOS_ON
;OUT (C),A
LD BC,CMOS_SET_ADR
OUT (C),H
LD BC,CMOS_RD_WR
OUT (C),L
;OFF_CMOS LD A,CMOS_OFF
;LD BC,PENT_CONF
;OUT (C),A
POP BC
LD A,L
OR A
RET
Re: ps2 code help request
Posted:
28 Jan 2012, 20:27
by justine
Budder If i get you right , i call INIT once then i call READ_KEY which outputs the value in L and the do LD A,L and call my PUTCHAR routine which takes A as the input. I only call TERMINATE once i have finished reading the keyboard ?