* datasheet
https://eater.net/datasheets/w65c22.pdf
* code exam.
https://github.com/fenarinarsa/Latecomer/blob/master/tools.a#L174
-sets timer
config_timer
; interruption - TIMER 1 6522
LDA #%01000000 ; continuous interrupt / PB7 disabled
ldy #$0B
STA (MB_OUT),y ; $Cx0B Auxiliary Control Register
LDA #%11000000 ;
ldy #$0D
STA (MB_OUT),y ; $Cx0D interrupt flag register (Time Out of Timer 1/Int)
ldy #$0E
STA (MB_OUT),y ; $Cx0E interrupt Enable register (Timer 1 + Set)
; The 6522 timer to play at 50Hz is different on a PAL or NTSC Apple II
; Main Apple II clock is (composite frequency):
; PAL = 1.016 MHz
; NTSC = 1.0205 MHz
;
; For future reference the 6522 counter for a complete frame size should be set to
; PAL = $4F36 (50.08Hz) = 20280-2 cycles
; NTSC = $4284 (~59.94Hz) = 17030-2 cycles
;
; Of course on PAL Apple IIc the VSYNC interrupt may be used, it already has a frequency of 50.08Hz
;
; Because of the clock differences,
; to get a frequency 50.08Hz on an NTSC Apple II the 6522 counter should actually be set at $4F88
; but the difference is not big enough to be heard and I'm lazy
;
; We're using T1 (first timer) on MB's first 6522 (there is two timers/6522 and two 6522 on a MB)
; T1 is set in free run mode so the counter needs to be set up only once
; the timer will start and loop once the counter high byte is written
LDA #$36
ldy #$04
STA (MB_OUT),y ; $Cx04 T1C-Lower
LDA #$4F
ldy #$05
STA (MB_OUT),y ; $Cx05 T1C-High
lda MB_OUT+1 ; modifies the BIT instruction in VBLI
sta vbli_mod1+2
+set_ptr VBLI_compatible,$FFFE ; setting up the 50Hz interrupt handler
rts
- interrupt routine
VBLI_compatible
; Interrupt handler for IIe/IIc, using a 50Hz mockingboard interrupt
; on PAL should activate roughly at the start of VBLANK
; on NTSC will activate quite anywhere => tearing :)
php ; save flags
sta save_a
stx save_x
sty save_y
lda #$7f
vbli_mod1 sta $C40D ; clear IFR
;bit $C404 ; Clears interrupt (T1CL) / modified instruction
; change VBL flag
ldx #0
stx vblflag ; clear hibit
;----- HGR double buffering
lda vbl_swaphgr
beq .noswap
stx vbl_swaphgr
jsr swap_page
.noswap +inc16 vbl_count
; play music
lda music_on
beq .no_music
jsr player_mb
.no_music
ldy save_y
ldx save_x
lda save_a
plp
rti