ps2 code help request

ZX evolution software and hardware

Postby justine » 22 Jan 2012, 18:23

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
User avatar
justine
 
Posts: 101
Joined: 06 Jul 2011, 00:50
Location: Scotland
Group: Registered users

Postby Budder » 23 Jan 2012, 10:38

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

for 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...
User avatar
Budder
 
Posts: 57
Joined: 20 Jul 2007, 15:05
Group: Registered users

Postby justine » 23 Jan 2012, 19:21

Thanx Budder :ura:

Having comments in English really helps me understand how these routines work.
User avatar
justine
 
Posts: 101
Joined: 06 Jul 2011, 00:50
Location: Scotland
Group: Registered users

Postby justine » 25 Jan 2012, 16:57

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.
User avatar
justine
 
Posts: 101
Joined: 06 Jul 2011, 00:50
Location: Scotland
Group: Registered users

Postby DimkaM » 25 Jan 2012, 17:30

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
ZX-Evo rev C, ZXNetUsb rev С
DimkaM
 
Posts: 1290
Joined: 24 Mar 2010, 13:42
Location: джунгли Амазонки
Group: Registered users

Postby DimkaM » 25 Jan 2012, 17:34

PENT_CONF EQU $EFF7 ;ld bc,PENT_CONF
PENT_CONF WORD $EFF7 ; ld bc,(PENT_CONF)
ZX-Evo rev C, ZXNetUsb rev С
DimkaM
 
Posts: 1290
Joined: 24 Mar 2010, 13:42
Location: джунгли Амазонки
Group: Registered users

Postby justine » 25 Jan 2012, 18:14

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.
User avatar
justine
 
Posts: 101
Joined: 06 Jul 2011, 00:50
Location: Scotland
Group: Registered users

Postby lvd » 25 Jan 2012, 19:28

justine, you should then take alasm with sts, compile and step your code on real machine.
Многого нет здесь: http://lvd.nedopc.com
Image
User avatar
lvd
 
Posts: 1637
Joined: 07 Apr 2007, 22:28
Group: Registered users

Postby Budder » 26 Jan 2012, 01:08

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
User avatar
Budder
 
Posts: 57
Joined: 20 Jul 2007, 15:05
Group: Registered users

Postby justine » 28 Jan 2012, 20:27

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 ?
User avatar
justine
 
Posts: 101
Joined: 06 Jul 2011, 00:50
Location: Scotland
Group: Registered users

Next

Return to Пентева - софт и железо

Who is online

Users browsing this forum: No registered users and 6 guests

cron