Jump to content
IGNORED

CIO read keyboard, stuck after first press, and always 00. WTF?


Recommended Posts

Hi guys, chugging along on the first bits of a programmer text editor that uses CIO functions for output (so that it is compatible with lots of display outputs).

 

But I'm scratching my head a bit...

 

I of course, can read whether a character is gated via CH, and I do so, to tell CIO to grab the ATASCII key from the K:eyboard...but after the CIOV happens, I get back a 0, regardless, and it hangs from that point...

_YET_ when I run from Amoeba, I can get the correct behavior that I'm looking for (because it's obviously clearing something).

 

My example code uses the value to set background color, (just so i can debug the thing for now and get it right)...and I'm really scratching my head, because it's something so simple, but I'm missing it...

 

 

??                  ATARI Macro Assembler Ver  1.0C  Page   1
  KEYPUNCH EDITOR FOR ATARI                            D2:MAIN.ASM        
  MAIN FILE                                         
?
                            LIST D, I
  0000              
                    ;**
                    ;* MAIN.ASM - MAIN FILE
                    ;* --------------------
                    ;* THE MAIN FILE TO ASSEMBLE FOR THE
                    ;* EDITOR.
                    ;**
                    
                     
                    
  0000  = 2000              ORG $2000
                    
                            INCLUDE D2:CIOEQU.ASM
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
                  ATARI Macro Assembler Ver  1.0C  Page   2
  KEYPUNCH EDITOR FOR ATARI                            D2:CIOEQU.ASM      
  CIO EQUATES                                       
?
  2000              ;***********************************
                    ;* CIO EQUATES
                    ;***********************************
                    
        = 0003      OPEN    EQU     $03
        = 0004      OREAD   EQU     $04
        = 0008      OWRITE  EQU     $08
        = 0005      GETREC  EQU     $05
        = 0007      GETCHR  EQU     $07
        = 0009      PUTREC  EQU     $09
        = 000B      PUTCHR  EQU     $0B
        = 000C      CLOSE   EQU     $0C
                    
  2000  453A9B      EDEVICE DB 'E:',$9B
  2003  4B3A9B      KDEVICE DB 'K:',$9B
                    
        = 0000      IOCB0   EQU     $00
        = 0010      IOCB1   EQU     $10
        = 0020      IOCB2   EQU     $20
        = 0030      IOCB3   EQU     $30
        = 0040      IOCB4   EQU     $40
        = 0050      IOCB5   EQU     $50
        = 0060      IOCB6   EQU     $60
        = 0070      IOCB7   EQU     $70
                    
        = 0054      ROWCRS  EQU     $0054
        = 0055      COLCRS  EQU     $0055
                    
                    ; ATASCII CHARS
        = 007D      CH_CLR  EQU     $7D
        = 001C      CH_UP   EQU     $1C
        = 001D      CH_DN   EQU     $1D
        = 001E      CH_LF   EQU     $1E
        = 001F      CH_RT   EQU     $1F
        = 00A0      CH_LIN  EQU     $A0
                    
                            INCLUDE D2:EDIT.ASM
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
                  ATARI Macro Assembler Ver  1.0C  Page   3
  KEYPUNCH EDITOR FOR ATARI                            D2:EDIT.ASM        
  MAINLINE EDITOR CODE                              
?
  2006              ;**
                    ;* EDIT.ASM - THE MAIN EDITOR
                    ;**
                    
  2006  = 0001      NUMROWS DS 1
  2007  = 0001      NUMCOLS DS 1
  2008  = 0001      TEMP1   DS 1
  2009  = 0001      KEYBUF  DS 1
                    
  200A              START    
                    
                    ; OPEN KEYBOARD IOCB:
  200A  A210                LDX #IOCB1
  200C  A903                LDA #OPEN
  200E  9D4203              STA ICCOM,X
  2011  A904                LDA #OREAD
  2013  9D4A03              STA ICAX1,X
  2016  A900                LDA #$00
  2018  9D4B03              STA ICAX2,X 
  201B  A903                LDA #LOW KDEVICE
  201D  9D4403              STA ICBAL,X
  2020  A920                LDA #HIGH KDEVICE
  2022  9D4503              STA ICBAH,X
  2025  2056E4              JSR CIOV
                    
                    ; CLOSE THE EDITOR IOCB:
  2028  A200                LDX #IOCB0
  202A  A90C                LDA #CLOSE
  202C  9D4203              STA ICCOM,X
  202F  A900                LDA #$00
  2031  9D4A03              STA ICAX1,X
  2034  9D4B03              STA ICAX2,X
  2037  2056E4              JSR CIOV
                    
                    ; OPEN EDITOR BACK UP.
  203A  A903        OPENED  LDA #OPEN
  203C  9D4203              STA ICCOM,X
  203F  A908                LDA #OWRITE
  2041  9D4A03              STA ICAX1,X
  2044  A900                LDA #$00
  2046  9D4B03              STA ICAX2,X
  2049  A900                LDA #LOW EDEVICE
  204B  9D4403              STA ICBAL,X
  204E  A920                LDA #HIGH EDEVICE
  2050  9D4503              STA ICBAH,X
  2053  2056E4              JSR CIOV
                    
                    ; AND SEND EXPLICIT CLEAR
  2056  A90B        EDCLR   LDA #PUTCHR
  2058  9D4203              STA ICCOM,X
  205B  A908                LDA #OWRITE
  205D  9D4A03              STA ICAX1,X
  2060  A900                LDA #$00
  2062  9D4B03              STA ICAX2,X
  2065  9D4403              STA ICBAL,X
  2068  9D4503              STA ICBAH,X
  206B  9D4803              STA ICBLL,X
?
?
?
?
?
                  ATARI Macro Assembler Ver  1.0C  Page   4
  KEYPUNCH EDITOR FOR ATARI                            D2:EDIT.ASM        
  MAINLINE EDITOR CODE                              
?
  206E  9D4903              STA ICBLH,X
  2071  A97D                LDA #CH_CLR
  2073  2056E4              JSR CIOV
                    
                    ; DETERMINE SCREEN SIZE BY SENDING
                    ; AN UP ARROW, AND A LEFT ARROW 
                    ; CHARACTER, WHICH WILL MAX OUT
                    ; ROWCRS AND COLCRS, AND THEREBY GIVE
                    ; US THE MAXIMUM TERMINAL SIZE.
                    
  2076  A91C        TRMSIZ  LDA #CH_UP
  2078  2056E4              JSR CIOV
  207B  A91E                LDA #CH_LF
  207D  2056E4              JSR CIOV
  2080  A554                LDA ROWCRS
  2082  8D0620              STA NUMROWS
  2085  A555                LDA COLCRS
  2087  8D0720              STA NUMCOLS
                    
                    ; NOW DO AN INITIAL DRAW OF SCREEN.
                    
  208A  A900        INIDRW  LDA #$00
  208C  8555                STA COLCRS
  208E  AC0620              LDY NUMROWS
  2091  88                  DEY
  2092  8454                STY ROWCRS
  2094  AC0720              LDY NUMCOLS
  2097  C8                  INY
  2098  8C0820              STY TEMP1 
  209B  A9A0        DRWLIN  LDA #CH_LIN
  209D  2056E4              JSR CIOV
  20A0  CE0820              DEC TEMP1
  20A3  D0F6 ^209B          BNE DRWLIN
                    
                    ; AND SET SCREEN TO 0,0
                    
  20A5  A900        INIHOM  LDA #$00
  20A7  8554                STA ROWCRS
  20A9  8555                STA COLCRS
  20AB  A920                LDA #$20
  20AD  2056E4              JSR CIOV
                    
                    ; INITIAL KEY INPUT ROUTINE
                    
  20B0  ADFC02      KEYRT   LDA CH
  20B3  C9FF                CMP #$FF
  20B5  F0F9 ^20B0          BEQ KEYRT
  20B7  A210        KEYINI  LDX #IOCB1
  20B9  A907                LDA #GETCHR
  20BB  9D4203              STA ICCOM,X
  20BE  A904                LDA #OREAD
  20C0  9D4A03              STA ICAX1,X
  20C3  A900                LDA #$00
  20C5  9D4B03              STA ICAX2,X
  20C8  9D4803              STA ICBLL,X
  20CB  9D4903              STA ICBLH,X
  20CE  2056E4      KEYGET  JSR CIOV
?
?
?
?
?
                  ATARI Macro Assembler Ver  1.0C  Page   5
  KEYPUNCH EDITOR FOR ATARI                            D2:EDIT.ASM        
  MAINLINE EDITOR CODE                              
?
  20D1  8DC602              STA $02C6
  20D4  4CB020              JMP KEYRT
                    
                    
                    ; SIT AND SPIN
                    
  20D7  4CD720      LOOP    JMP LOOP
                    
  20DA  = 02E2              ORG $02E2
  02E2  0A20                DW START
                    
 
 
  no ERRORs,  140 Labels, $444A free.
?
?

 

any ideas? Feel free to thwap me upside the head.

 

-Thom

keypunch_backup.atr

Link to comment
Share on other sites

You're running your program off of an INIT segment instead of a RUN segment, so IOCB #1 is still open by DOS to the executable and not the keyboard.

Altirra> .iocb
CIO IOCBs:
 #  Dev      Cd St Bufr PutR BfLn X1 X2 X3 X4 X5 X6
ZP  D2:      07 88 2003 0D04 0000 04 00 62 0D 10 00
 0  E:       0B 01 0000 F2AF 0000 08 00 00 00 00 00
 1  D2:      07 88 2003 0D04 0000 04 00 00 00 00 01
 2           0C 01 0000 E4DB 0000 00 00 00 00 00 00
 3           0C 01 0000 E4DB 0000 00 00 00 00 00 00
 4           0C 01 0000 E4DB 0000 00 00 00 00 00 00
 5           0C 01 0000 E4DB 0000 00 00 00 00 00 00
 6           0C 01 0000 E4DB 0000 00 00 00 00 00 00
 7           0C 01 0000 E4DB 0000 04 00 00 00 00 00

By the way, testing CH isn't a reliable way of determining if K: will return since some keys like Caps Lock are eaten internally by that device. If you want to block, just read from K:. If you don't want to block, then you'll probably have to do like TBXL and have a lookup table of scancodes that don't cause K: to return.

  • Like 2
Link to comment
Share on other sites

You could do that, but then you'd be responsible for all of the auxiliary functions that the keyboard interrupt does -- like auto-repeat, debouncing, and clearing attract mode. It's a bit easier to just replace K:, and continue to use the OS keyboard IRQ handler. You'll still need to handle scancode-to-ATASCII conversion, Caps Lock, and Inverse functionality.

  • Like 1
Link to comment
Share on other sites

You can also get undesired behaviour allowing all keycodes <$C0.

 

CTRL-1 will pause screen output if you're echoing to S: or E: or plotting pixels using S: It doesn't generate an Ascii code, in fact the pause flag toggling is dealt with in the key IRQ.

CTRL-3 indicates EOF condition for the device. For that reason you should have a branch if negative after the CIO call to read keys to deal with that. This key combo is detected at the K: read level so you could test for it and mask it beforehand. You'd probably want to wrap SEI/CLI around the test and CIO call if masking keys in case they occur in between test and K: handler calls.

 

You could probably get away with a 64 byte key lookup table. Then hardcode what's needed to deal with the likes of Caps Lock, Help, F1-F4 etc. Actually you could probably use the high bit in a keyboard table to signify special keys then have a second table with those keycodes and jump addresses to deal with them.

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...