How to properly use interrupt handlers in 6502 Assembler?

323 views Asked by At

I'm new to assemblers, so this question might sound dumb, but exactly what type of code should be implemented in a raster interrupt handler?

So I know this handler gets called when the desired raster line is rendered. But this seems to happen only once (if I ack the interrupt). Unless I clear the screen or redraw the relevant part of it, the handler routine won't be called again, right?

So then what's the point of using an interrupt?

If have a main loop like this:

main
  jsr readKeyboard
  jsr readJoystick
  ...
  jmp main

... then I have an endless loop monitoring everything anyway, so I don't understand what do I use interrupts for?

I mean, I thought interrupts can be used to implement an event system. They eliminate the need for polling and wasting CPU cycles by waiting. But if they happen only once, then this is not possible.

interruptHandler
  inc $d019 ; acknowledge
  ...
  ; do the work
  jmp $ea81

If I acknowledge like this, the method is called only once. If I don't, it gets called over and over again.

So please help me understand the concept here.

What's the right way to use interrupts? What functionality they are suitable for? When should I use them?

Thx!

1

There are 1 answers

0
Omar and Lorraine On

If I acknowledge like this, the method is called only once. If I don't, it gets called over and over again.

It looks like you are expecting and handling a VIC-II interrupt. The Commodore 64 connects the VIC-II's interrupt line to the 6502's IRQ. The VIC-II asserts the interrupt line until the interrupt has been acknowledged.

On the 6502, the IRQ is such that for as long as the IRQ is asserted, unless interrupts have been disabled, the IRQ routine will be invoked.

These two facts mean that if you do not acknowledge the VIC-II's interrupt, then as soon as your interrupt handler ends (this usually implicitly re-enables the interrupt), it will start over again, because the VIC-II is still asserting the interrupt request.

This is all explained in the answers to my question here

If you do acknowledge the interrupt, then when the interrupt handler ends, it will pass control back to whatever code was running when the interrupt happened. Of course, some time later, the interrupt could fire again. An undisturbed raster interrupt will fire fifty times a second (in my country at least).

And just one nitpick: this is not a method, but an interrupt handler.