Code: Select all
A000 LDA #$3B ; Cyan and cyan
A002 LDX #$20 ; Raster position for the cutoff
A004 CPX $9004
A007 BCS $A00B
A009 LDA #F8 ; After the cutoff, use light black and yellow
A00B STA $900F ; Set the screen color
A00E JMP $A000
Moderator: Moderators
Code: Select all
A000 LDA #$3B ; Cyan and cyan
A002 LDX #$20 ; Raster position for the cutoff
A004 CPX $9004
A007 BCS $A00B
A009 LDA #F8 ; After the cutoff, use light black and yellow
A00B STA $900F ; Set the screen color
A00E JMP $A000
So I'd be looking for a different raster value? If #$20 is perfect for NTSC, I might need a different value for PAL?Note these routines definitely need you to take differences between NTSC and PAL into account.
Marko's code is overly complicated, and I found a technically better method for myself.chysn wrote:Okay, thanks. I just looked over Marko Makela's stable raster interrupt code.
It's much easier to check the table of the initial VIC register values beginning at $EDE4. The init value of $9000 (XPOS) at $EDE4 is 12 for PAL and 5 for NTSC.I'm assuming that I can detect whether it's a PAL or NTSC machine by watching $9004 to see how high it gets before going back to 0?
You mean, pages 218 to 226? ...chysn wrote:There's this whole section of the Programmer's Reference Guide that I never even looked at.
Exactly. The pages that, once you try to open to them, the book literally starts to fall apart.
Code: Select all
A000 SEI
A001 LDA #$18
A003 STA $0314
A006 LDA #$A0
A008 STA $0315
A00B STA $9128 ; Start the timer latch
A00E STA $9129 ; Clear the interrupt bit, all the other stuff writing to this does
A011 LDA #$F0
A013 STA $912E ; Enable the timer 2 interrupt
A016 CLI
A017 RTS
A018 LDA $912D ; Check the source of the interrupt
A01B AND #$20
A01D BNE $A022 ; If the timer 2 interrupt is in, do the timer 2 ISR
A01F JMP $EABF ; otherwise, just go to the system ISR
A022 LDA #$08 ; Make the screen black on black
A024 LDX #$28 ; The raster switch-over point
A026 CPX $9004
A029 BCC $A02D
A02B LDA #$3B ; If the raster is lower in number (physically, higher), change to cyan on cyan
A02D STA $900F
A030 LDA #$40
A032 STA $9128 ; Re-initialize the timer
A035 LDA #$00
A037 STA $9129
A03A JMP $EB18 ; Pull the registers, RTI
Code: Select all
LDA $912D
AND #$20
Code: Select all
LDA #$20
AND $912D
I know, right?! That's what's weird about it. This is a real NTSC CR VIC-20, which had a bad 6522 when I got it. Both of my current 6522s are scavenged from an early-model VIC-20. Aside from this weirdness, there's no indication that there's anything wrong. Maybe I should pick up a pair of 6522s to have around.
OK, I'll give that a shot. My reasoning here was that timer 1 was already occupied with the jiffy-counter, cursor-blinking ISR. It sounds like you're saying that the technique involves changing the timing of that so that the raster is in the same place during every interrupt. That provides one time reference, but it seems like I need two time reference points, because the color changes twice per frame.I'd then however recommend you program a period in timer 1 that aligns the timer interrupt to a given raster position. Normally timer 1 runs at roughly 60 Hz (irrespective of PAL/NTSC!) and on NTSC, is slightly different from the frame rate, so drifts, and on PAL it's effectively uncorrelated. For NTSC, you'd put 261x65-2 into timer 1, and for PAL, 312x71-2.
One reference point is sufficient, which is done by timer 1, and which also does the first colour change in the frame.chysn wrote:it seems like I need two time reference points, because the color changes twice per frame.
Code: Select all
; ------------------------------------------------------------------------------------------------
; Set interupt IRQ vector to the BACKROUND routine.
; ------------------------------------------------------------------------------------------------
SETBACKGROUNDIRQ:
LDA CINVL
STA SAVEIRQ1
LDA CINVH
STA SAVEIRQ2
SEI
LDX #<BACKGROUND
LDY #>BACKGROUND
STX CINVL ; enable my IRQ vector jump
STY CINVH
LDY #$A0
STY VIA2T2CL ; start the timer latch
STY VIA2T2CH ; clear the interrupt bit
LDA #$F0
STA VIA2IER
CLI
RTS
Code: Select all
; ------------------------------------------------------------------------------------------------
; interesting raster stuff
; ------------------------------------------------------------------------------------------------
BACKGROUND:
LDA VIA2IFR
AND #$20 ; 0010 0000 Bit 5 of timer two interrupt is 0 when timer 2 in and 1 when
; timer 2 expires.
BNE @CONT1 ; When timer 2 is IN then do something
JMP $EABF ; otherwise jump to hardware IRQ
@CONT1: LDA SCREENCOLOR1
LDX VIC+$04 ; check raster at 36868
CPX #$64 ; raster switch over point 1
BCC @HERE
LDA SCREENCOLOR2
CPX #$68 ; raster switch over point 2
BCC @HERE
LDA SCREENCOLOR3
@HERE: STA VIC+$0F ; 36879
LDA #$40 ; re-initialize the timer
STA VIA2T2CL
LDA #$00
STA VIA2T2CH
JMP $EB18 ; pull registers and RTI
Code: Select all
; pertinent VIC20 symbols
TIMEH = $A0
TIMEM = $A1
TIMEL = $A2 ; jiffy-clock low byte value
COLORPAGE = $F4 ; high order byte of screen color page
SCRNPAGE = $0288 ; screen memory page (unexpanded = 1E)
CINVL = $0314 ; Vector to Interrupt routine
CINVH = $0315
VIC = $9000 ; start of video interface chip registers
CHARDATA = $1C00 ; character definitions
SCREEN = $1E00 ; Top left of Screen (unexpanded)
COLOR = $9600 ; Color for top left of screen (unexpanded)
; VIA2 addresses
VIA2T2CL = $9128 ; Timer 2 low order LSB counter and LSB latch
VIA2T2CH = $9129 ; Timer 2 high order MSB and MSB latch
VIA2IFR = $912D ; Interupt flag register
VIA2IER = $912E ; Interrupt enable register