Hey Guys, you have all been so helpful in the past I was wondering if you could help me with an issue im experiencing with the 6522. I am trying to use Handshake mode on PA - Specifically testing with Write Handshake at the moment.
Whenever I present Data on PA, the 6522 Pulls CA2 Low as expected. My microcontroller receives this interrupt and grabs the data and responds with pulling CA1 Low. The Interrupt is registered on the 6502 and is processed - but it is not clearing CA2 (Data Ready) state on the 6522 which if I am reading the datasheet correctly it should automatically. The IRQ flag is being reset when i read PA but CA2 remains low and the only way to reset it is to do a full system reset.
Here is my code, perhaps it's my configuration with the 6522?
Code:
VIA: .SET $9000
;----------System Setup 6522----------------------
;-- Parameters - VOID
;-------------------------------------------------
SYS_INIT6522:
LDA #@00000000 ; Set all Pins to input
STA VIA+$02 ; And Set DDR to that on Port B
LDA #$FF
STA VIA+$03 ; Set Drive to Output Mode (PA Output)
LDA #@00001000 ; Negative Active PB & Handshake on CA2
STA VIA+$0C
; Now Set up Timer
LDA #$FF
STA VIA+$04 ; Lo Byte Counter FF
LDA #$FF
STA VIA+$05 ; Hi Byte Counter FF
LDA #@01000011 ; Enable Continual Interrupts on T1 & LATCH on PA & PB
STA VIA+$0B ; Put it in ACR
; Enable Interrupts
LDA #@11010010 ; Enable Interrupt on Timer1, CB1 AND CA1
STA VIA+$0E
RTS
And my Interrupt handler as follows (Keep in mind it also handles the timer and Keyboard)
Code:
;----------Interrupt Request----------------------
;-- Parameters - VOID
;-------------------------------------------------
SYS_IRQ:
PHA
LDA #@00000010
BIT VIA+$0D
BEQ .checkKeyboard
M_PRINT_STR STR_DRTC_CALLED ; Print a confirmation that this was called on screen
LDA VIA+$01 ; Read Data from PORTA of Via - this resets the interrupt
.checkKeyboard
; Did a Timer go off or Is Data on PortB
LDA #@00010000 ; Test for CB1
BIT VIA+$0D ; Flag Register of VIA
BEQ .checkTimer1 ; CB1 didn't interrupt Check Timer
LDA VIA+$00 ; Read from PortB of the VIA
STA INPUT_CBUF ; Store it in input Buffer
.checkTimer1
LDA #@01000000 ; Check Timer1 Bit
BIT VIA+$0D ; Flag Register of VIA
BEQ .done ; Not the Timer1 Bit calling Interrupt goto Done
LDA VIA+$04 ; Read from T1L to clear bit
INC TIMER_COUNT ; Increase the Timer
; Done checking on the VIA
.done
PLA
RTI