Timer interrupts with 65C22
Posted: Sun Jun 22, 2025 4:42 pm
Hello everyone
I've built a simple SBC with a 65C02, 65C22, SST39SF020 for ROM, AS6C22256, and some NAND gates for address decoding.
I've been trying to output a sine lookup table on port A of the 65C22.
The weirdest thing is that when I reset the computer, some stuff happens on port A, but then at seemingly random intervals after reset, it just stops. I have the PB7 toggle enabled on the 65C22 to make sure the timer is running, which doesn't stop when port A does, so at least the timer is running I think.
What could be wrong here?
Here is the source code:
SIENINDEX = $00
DDRA = $4003
PORTA = $4001
TCNT1L = $4004
TCNT1H = $4005
OCR1L = $4006
OCR1H = $4007
ACR = $400B
IER = $400E
.org $c000
RESET:
LDX #$FF ;stack init
TXS ;yoooo
LDX #$00
STX SIENINDEX
LDA #$FF ;poort A on
STA DDRA ;yoooo
LDA #$C0 ;Timer1 continues interrupt with PB7 toggle
STA ACR ;yooooo
LDA #$C0 ;Timer1 and interrupts in general
STA IER ;yoooooo
LDA #$FF ;decimal 255 to count down from
STA OCR1L ;yooooo
LDA #$00 ;decimal 0 high order byte
STA OCR1H ;yooooo
LDA #$FF ;decimal 255 to count from
STA TCNT1L ;yoooo
LDA #$00 ;decimal 0 low order byte
STA TCNT1H ;yoooo
CLI ;enable them interrupts
MAIN:
NOP
JMP MAIN
INT_VECT:
LDA TCNT1L ; to clear interrupt flag in 65C22
LDX SIENINDEX
LDA SIENTABEL, X
STA PORTA
INX
STX SIENINDEX
RTI
SIENTABEL:
.byte 128, 131, 134, 137, 140, 143, 146, 149
.byte 152, 155, 158, 162, 165, 167, 170, 173
.byte 176, 179, 182, 185, 188, 190, 193, 196
.byte 198, 201, 203, 206, 208, 211, 213, 215
.byte 218, 220, 222, 224, 226, 228, 230, 232
.byte 234, 235, 237, 238, 240, 241, 243, 244
.byte 245, 246, 248, 249, 250, 250, 251, 252
.byte 253, 253, 254, 254, 254, 255, 255, 255
.byte 255, 255, 255, 255, 254, 254, 254, 253
.byte 253, 252, 251, 250, 250, 249, 248, 246
.byte 245, 244, 243, 241, 240, 238, 237, 235
.byte 234, 232, 230, 228, 226, 224, 222, 220
.byte 218, 215, 213, 211, 208, 206, 203, 201
.byte 198, 196, 193, 190, 188, 185, 182, 179
.byte 176, 173, 170, 167, 165, 162, 158, 155
.byte 152, 149, 146, 143, 140, 137, 134, 131
.byte 128, 124, 121, 118, 115, 112, 109, 106
.byte 103, 100, 97, 93, 90, 88, 85, 82
.byte 79, 76, 73, 70, 67, 65, 62, 59
.byte 57, 54, 52, 49, 47, 44, 42, 40
.byte 37, 35, 33, 31, 29, 27, 25, 23
.byte 21, 20, 18, 17, 15, 14, 12, 11
.byte 10, 9, 7, 6, 5, 5, 4, 3
.byte 2, 2, 1, 1, 1, 0, 0, 0
.byte 0, 0, 0, 0, 1, 1, 1, 2
.byte 2, 3, 4, 5, 5, 6, 7, 9
.byte 10, 11, 12, 14, 15, 17, 18, 20
.byte 21, 23, 25, 27, 29, 31, 33, 35
.byte 37, 40, 42, 44, 47, 49, 52, 54
.byte 57, 59, 62, 65, 67, 70, 73, 76
.byte 79, 82, 85, 88, 90, 93, 97, 100
.byte 103, 106, 109, 112, 115, 118, 121, 124
.org $FFFC
.word RESET
.org $FFFE
.word INT_VECT
I've built a simple SBC with a 65C02, 65C22, SST39SF020 for ROM, AS6C22256, and some NAND gates for address decoding.
I've been trying to output a sine lookup table on port A of the 65C22.
The weirdest thing is that when I reset the computer, some stuff happens on port A, but then at seemingly random intervals after reset, it just stops. I have the PB7 toggle enabled on the 65C22 to make sure the timer is running, which doesn't stop when port A does, so at least the timer is running I think.
What could be wrong here?
Here is the source code:
SIENINDEX = $00
DDRA = $4003
PORTA = $4001
TCNT1L = $4004
TCNT1H = $4005
OCR1L = $4006
OCR1H = $4007
ACR = $400B
IER = $400E
.org $c000
RESET:
LDX #$FF ;stack init
TXS ;yoooo
LDX #$00
STX SIENINDEX
LDA #$FF ;poort A on
STA DDRA ;yoooo
LDA #$C0 ;Timer1 continues interrupt with PB7 toggle
STA ACR ;yooooo
LDA #$C0 ;Timer1 and interrupts in general
STA IER ;yoooooo
LDA #$FF ;decimal 255 to count down from
STA OCR1L ;yooooo
LDA #$00 ;decimal 0 high order byte
STA OCR1H ;yooooo
LDA #$FF ;decimal 255 to count from
STA TCNT1L ;yoooo
LDA #$00 ;decimal 0 low order byte
STA TCNT1H ;yoooo
CLI ;enable them interrupts
MAIN:
NOP
JMP MAIN
INT_VECT:
LDA TCNT1L ; to clear interrupt flag in 65C22
LDX SIENINDEX
LDA SIENTABEL, X
STA PORTA
INX
STX SIENINDEX
RTI
SIENTABEL:
.byte 128, 131, 134, 137, 140, 143, 146, 149
.byte 152, 155, 158, 162, 165, 167, 170, 173
.byte 176, 179, 182, 185, 188, 190, 193, 196
.byte 198, 201, 203, 206, 208, 211, 213, 215
.byte 218, 220, 222, 224, 226, 228, 230, 232
.byte 234, 235, 237, 238, 240, 241, 243, 244
.byte 245, 246, 248, 249, 250, 250, 251, 252
.byte 253, 253, 254, 254, 254, 255, 255, 255
.byte 255, 255, 255, 255, 254, 254, 254, 253
.byte 253, 252, 251, 250, 250, 249, 248, 246
.byte 245, 244, 243, 241, 240, 238, 237, 235
.byte 234, 232, 230, 228, 226, 224, 222, 220
.byte 218, 215, 213, 211, 208, 206, 203, 201
.byte 198, 196, 193, 190, 188, 185, 182, 179
.byte 176, 173, 170, 167, 165, 162, 158, 155
.byte 152, 149, 146, 143, 140, 137, 134, 131
.byte 128, 124, 121, 118, 115, 112, 109, 106
.byte 103, 100, 97, 93, 90, 88, 85, 82
.byte 79, 76, 73, 70, 67, 65, 62, 59
.byte 57, 54, 52, 49, 47, 44, 42, 40
.byte 37, 35, 33, 31, 29, 27, 25, 23
.byte 21, 20, 18, 17, 15, 14, 12, 11
.byte 10, 9, 7, 6, 5, 5, 4, 3
.byte 2, 2, 1, 1, 1, 0, 0, 0
.byte 0, 0, 0, 0, 1, 1, 1, 2
.byte 2, 3, 4, 5, 5, 6, 7, 9
.byte 10, 11, 12, 14, 15, 17, 18, 20
.byte 21, 23, 25, 27, 29, 31, 33, 35
.byte 37, 40, 42, 44, 47, 49, 52, 54
.byte 57, 59, 62, 65, 67, 70, 73, 76
.byte 79, 82, 85, 88, 90, 93, 97, 100
.byte 103, 106, 109, 112, 115, 118, 121, 124
.org $FFFC
.word RESET
.org $FFFE
.word INT_VECT