Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Commodore 64 IRQ Moving Raster Bars
- ; Target address: $C000 (SYS 49152 to start)
- org $c000
- init_irq:
- sei ; Disable interrupts while making changes
- ; Turn off standard CIA timer interrupts (stops cursor flash/keyboard scan from breaking timing)
- lda #$7f
- sta $dc0d
- sta $dd0d
- lda $dc0d ; Acknowledge any pending CIA interrupts
- ; Enable VIC-II Raster Interrupts
- lda #$01
- sta $d01a
- ; Set the first raster line where our IRQ should trigger
- lda bar_y
- sta $d012
- lda $d011 ; Clear high bit of raster line (since lines go above 255)
- and #$7f
- sta $d011
- ; Point the C64's RAM interrupt vector ($0314/$0315) to our custom routine
- lda #<irq_handler
- sta $0314
- lda #>irq_handler
- sta $0315
- cli ; Re-enable interrupts
- rts ; Return to BASIC. The effect now runs purely in the background!
- ; ==========================================
- ; CUSTOM INTERRUPT HANDLER
- ; ==========================================
- irq_handler:
- ; 1. Acknowledge the VIC-II interrupt flag so it can trigger again next frame
- lsr $d019
- ; 2. Draw the colored bar gradient line-by-line
- ldx #0 ; Index for our color table
- color_loop:
- lda color_table,x
- sta $d020 ; Write to border color
- sta $d021 ; Write to background color
- ; Inline delay to let a color stretch across a few lines
- ldy #$0a
- line_delay:
- dey
- bne line_delay
- inx
- cpx #32 ; Have we painted all 32 lines?
- bne color_loop
- ; 3. Reset colors back to black
- lda #0
- sta $d020
- sta $d021
- ; 4. Update the bar position for the next frame (Animation)
- inc frame_count
- lda frame_count
- cmp #2 ; Speed control (Higher = Slower)
- bne finish_irq
- lda #0
- sta frame_count
- inc bar_y ; Move DOWN. (Change to 'dec bar_y' to move UP)
- lda bar_y
- cmp #$b0 ; Wrap around bottom boundary
- bne finish_irq
- lda #$30 ; Reset to top boundary
- sta bar_y
- finish_irq:
- ; 5. Update the next IRQ trigger line to match the new bar position
- lda bar_y
- sta $d012
- ; 6. Exit the interrupt routine cleanly via standard KERNAL exit
- jmp $ea31
- ; ==========================================
- ; VARIABLES & DATA TABLES
- ; ==========================================
- bar_y: byte $30 ; Dynamic starting line for the raster interrupt
- frame_count: byte 0
- ; 32-Byte symmetric color gradient (Dark Blue -> Light Blue -> White -> Dark Blue)
- color_table:
- byte $06, $06, $06, $06, $0e, $0e, $0e, $0e
- byte $03, $03, $03, $03, $01, $01, $01, $01
- byte $01, $01, $01, $01, $03, $03, $03, $03
- byte $0e, $0e, $0e, $0e, $06, $06, $06, $06
Advertisement