Jump to content
IGNORED

5200 Keypad IRQ [crash!]


Recommended Posts

Hi,

 

I am trying to free myself from the 5200 logo screen. Everything works, except one "minor" detail. Now when I set IRQEN to $40, for keypad enable, it crashes the emu out.

 

I don't think my keypad code is right anyways tho... should I really have to do LDA #$40 STA IRQEN to keep the keypad active? Surely there is a zeropage address that will handle the situation permanently.

 

Any ideas on this would be great!

 

Thanks,

calamari

Link to comment
Share on other sites

Thanks!

 

It still is crashing when I push a keypad button, but I think I might have that code in the wrong place, or my existing code might be in the wrong order.

 

Maybe a sequence of events would be helpful here:

 

1) clear antic, gtia, etc..

2) clear ram $0200-$3fff

3) etc ??? (This is where I am probably having a problem)

 

I'm guessing that any vectors should probably set up first.. I think I might be missing a few though. DLI, DL, IRQ, keyboard, timer, ?

 

After the vectors, I put more generic stuff like setting up character sets, colors, gractl, chactl, prior.. that kind of stuff.

 

I probably have 99% of what I need, but I might be missing 1 or 2 things or have something in the wrong order.

 

Thanks

calamari

Link to comment
Share on other sites

Oh yeah, Koffi crashed on the real machine at one time, too, when you tried to press keypad buttons.

 

Do you have a Vertical Blank Interrupt set up? Debro sent me a sample program that I used to set mine up. The VBI Deferred routine places the pressed-keypad value into a variable which Debro called CH and thus, so do I.

 

code:


;************* Setup hardware registers / Interrupts *************

 

ldx #$0B ;12 values in OS ROM table

SetOSVectors

lda InterruptVectorData,x

sta $0200,x

dex

bpl SetOSVectors

 

...

 

InterruptVectorData

.byte $03,$FC ; VIMIRQ (Immediate IRQ vector)

.byte $B8,$FC ; VVBLK1 (Immediate VBI vector)

.word VBITitle ; VVBLKD (Deferred VBI vector)

.word DLIRoutine ; VDSLST (DLI vector)

.byte $02,$FD ; VKYBDI (Keyboard IRQ vector)

.word KBCodeVector ; VKYBDF (Keypad routine continuation

; vector)

 


 

Do you have code similar to this, to set up your VBI vectors and other vectors that lie in the $200,$201,$202, etc area of memory?

Link to comment
Share on other sites

Another piece of related code, the KBCodeVector routine.

 

code:


;-----------------------------------------------------------------KBCodeVector

; KBCodeVector

;

; This is our Keypad continuation vector routine. The default Keyboard IRQ

; vector reads the KBCODE and converts the value for us but only

; stores this value in the accumulator.

;

; The default Keypad continuation vector just pops the stack and returns from

; the interrupt so the key press value is lost unless we store it somewhere.

 

KBCodeVector

sta CH ; Store the last key pressed value

jmp XITVBL ; XITVBL=$fcb2


 

[ 01-24-2002: Message edited by: Cafeman ]

  • Like 1
Link to comment
Share on other sites

If you are using the original code i sent, there is a bug

 

In my original keypad routine I think I was popping the stack and placing it in the x register twice

 

Check your keypad routine to be sure you are popping the stack in the correct order. The code that Cafeman supplied should work for you.

Link to comment
Share on other sites

Cafeman, you got it!

 

Here's what I was missing (as always, it makes perfect sense in retrospect.. hehe):

 

code:


LDA #$02 ; point Keyboard immediate

STA $0208 ; to BIOS routine

LDA #$FD ; /

STA $0209 ;/


 

I also like the way that loop is used to store the $02xx values (saves a few bytes.. I think I'm going to do it that way

 

Thanks a lot!

calamari

 

[ 01-24-2002: Message edited by: calamari ]

Link to comment
Share on other sites

Here is my deferred keyboard routine. It gives a 16 character buffer, so if the program can't get around to reading the keyboard right away, the keystrokes won't be lost. I have no idea if this is actually necessary in practice, but it works for me

 

code:


;---------------------------------------------------------------------

; KEYPAD -- Keypad buffer handler

; On entry: A=key just pressed

;---------------------------------------------------------------------

.ORG $BC00

LDX KEYSTAT

CPX #$0F ; already at buffer limit?

BEQ KEYDONE ; if so, ignore this keypress

STA KEYBUFF,X ; otherwise, store key

INC KEYSTAT ; update number of keys in buffer

KEYDONE PLA

TAY ;POP Y

PLA

TAX ;POP X

PLA ;POP A

RTI


 

Here is the routine I use to read a character from the buffer:

code:


;---------------------------------------------------------------------

; INKEY

; Requires: KEYBUFF (16-character buffer)

; KEYSTAT (points to last character+1)

; Destroys: X,Y

; Returns: keypress in A, or A=$FF if no key waiting

;---------------------------------------------------------------------

INKEY LDA KEYSTAT ; get current key buffer length

BEQ NOKEY ; key pressed? (buffer>0) if not, return $FF

LDY KEYBUFF ; Y=first key from buffer

LDX #$01 ; move all buffered keys to the left one

NEXTKEY LDA KEYBUFF,X ; A=KEYBUFF(X)

STA KEYBUFF-1,X ; KEYBUFF(X-1)=A

INX ; X=X+1

CPX #$0F ; is X=KEYSTAT?

BNE NEXTKEY ; if not, move the next keystroke left one

DEC KEYSTAT ; point KEYSTAT to the new end char

TYA ; restore the first key from Y to A

RTS

NOKEY LDA #$FF

RTS


 

calamari

Link to comment
Share on other sites

cal,

It appears you found the problem. When you are clearing memory and starting at $200 you are wiping out the interrupt jump table. If you start at (I think) $208 for your memory clear, you will keep all the BIOS routine addresses in the table. I did the same thing and couldn't figure out why my code kept crashing. Finally Dan pointed out my stupid error

AlanD

Link to comment
Share on other sites

Well, the keypad problem is solved.. but there is another problem that I did not expect.

 

Text on Antic 2 mode lines in the display list the screen text doesn't show up, but text on Antic 4 lines shows up fine. (of course it looks weird because it's an Antic 2 character set)

 

Does anyone have a disassembly of the 5200 ROM? I'd like to know exactly what it does and does not do, maybe that would help me here.

 

Thanks,

calamari

Link to comment
Share on other sites

This time it was a bit more complicated.. I was missing these lines (I had them before but didn't think they were needed anymore.. whoops I also needed COLOR1 to be set, not just COLOR0.

 

code:


LDA #$22

STA SDMCTL


 

According to what I read, setting SDMCTL ($0007, shadow for $D400) to zero turns off the ANTIC, and also speeds up program execution (at the expense of a blank screen). I'm still not sure why Antic 4 mode lines were working (this was still zero with them), maybe just a bug in the emu.

 

calamari

Link to comment
Share on other sites

  • 18 years later...

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