My First C64 Interrupt Program

In late 1983, I began learning 6502 assembly-language by hand-assembling 6502 code on an Apple II computer at school. I had also been toying with a Commodore 64.

I had been reading some C64 articles that pertained to inserting interrupt-driven machine-code routines by modifying the vector stored in $0314 / $0315.

My first interrupt-driven C64 code simply incremented the border color with each invocation of the timer interrupt. Although I had originally written the code using Jim Butterfield’s SuperMon 64, I recently rewrote the same code using a label-based assembler:


; Interrupt-driver border changer for the C64
 ;
 ; License: MIT / X11
 ; Copyright (c) 2013 by James K. Lawless
 ; jimbo@radiks.net
 ; http://lawlessguy.com
 ;
 ; Permission is hereby granted, free of charge, to any person
 ; obtaining a copy of this software and associated documentation
 ; files (the "Software"), to deal in the Software without
 ; restriction, including without limitation the rights to use,
 ; copy, modify, merge, publish, distribute, sublicense, and/or sell
 ; copies of the Software, and to permit persons to whom the
 ; Software is furnished to do so, subject to the following
 ; conditions:
 ;
 ; The above copyright notice and this permission notice shall be
 ; included in all copies or substantial portions of the Software.
 ;
 ; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 ; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 ; OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 ; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 ; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 ; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 ; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 ; OTHER DEALINGS IN THE SOFTWARE.
 ;
 ; To use in C64 BASIC:
 ; sys 49152

 * = $c000
 sei
 lda $0314
 sta jumper+1

lda $0315
 sta jumper+2

lda #<iroutine
 sta $0314
 lda #>iroutine
 sta $0315
 cli
 rts

iroutine = *
 inc $d020
 lda $d020
 and #$0f
 sta $d020

; the target address will be dynamically modified by the
 ; init portion of this code
 jumper = *
 jmp $0000
 end

You can download the source and .P00 file here:

http://www.mailsend-online.com/wp2/c64border.zip

When I had run the original program, the timing seemed to work nicely with NTSC video. I recall the colors changing in a manner that left scrolling colored stripes in the border where each stripe was about the size of a C64 character in height.

I no longer have a stock C64, so I had tried to tune VICE into generating the same effect, to no avail. Here’s what the code looked like in VICE with my settings:

Advertisements

About Jim Lawless

I've been programming computers for about 36 years ... 30 of that professionally. I've been a teacher, I've worked as a consultant, and have written articles here and there for publications like Dr. Dobbs Journal, The C/C++ Users Journal, Nuts and Volts, and others.
This entry was posted in Programming and tagged , , . Bookmark the permalink.

2 Responses to My First C64 Interrupt Program

  1. Paul Holt says:

    sei
    lda $0314
    sta jumper+1

    lda $0315
    sta jumper+2

    ;this is how to tell the VICII to generate a raster interrupt **
    lda #$01 ; **
    sta $d01a ; **

    ;this is how to tell at which rasterline we want the irq to be triggered **
    lda #$?? ; **
    sta $d012 ; **

    lda #iroutine
    sta $0315
    cli
    rts

    iroutine = *
    lsr $d019 ; Acknowledge the interrupt
    inc $d020
    lda $d020
    and #$0f
    sta $d020

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s