Commodore 128 Alive!

Commodore 128 => 128 programmers => Assembly => Topic started by: MIRKOSOFT on October 06, 2009, 04:50 AM

Title: Programming IRQ - like on C64?
Post by: MIRKOSOFT on October 06, 2009, 04:50 AM
Hi!

First time I want to try programming IRQ on Commodore 128. Before I had C64 - and there I know it. Is it different?
Exactly:

IRQ programming:
1. save A, X, Y registers
2. set address to ROUTTAB
3. set equivalent bit in MAINMASK
4. redirect IRQ-pointer
5. set MAINCOUNT to $00

MAINMASK:
bit       7|6|5|4|3|2|1|0
routine 8|7|6|5|4|3|2|1

ROUTTAB: LO - HI
routine 1 > ROUTTAB
routine 2 > R1, ...
IRQ-pointer: $0314
Old IRQ: $EA31
MAINMASK: $7C
MAINCOUNT: $7D
MAINSAVE $7E

Are used other addresses or what is different?

Thanks for help.

Miro
Title: Re: Programming IRQ - like on C64?
Post by: Hydrophilic on October 06, 2009, 12:51 PM
IRQ programming is quite different on the C128.  Instead of the CIA generating the IRQ, the VIC-IIe generates the IRQ.  To clear the main (raster) IRQ, you must write 1 into $D019. 

The main IRQ sets up the 40-column display mode according to the value in $d8.  (This is normally text mode, but will be bitmap mode if use BASIC's GRAPHIC n where n is 1 to 4).  The main IRQ also calls KERNAL to scan keyboard and update jiffy clock (like the C64).  The main IRQ also calls BASIC IRQ routine (unless a special bit is set to ignore BASIC IRQ).

Besides the main IRQ, the VIC-IIe can also generate other IRQs for BASIC.  Specifically for use with sprites (COLLISION) and the light pen (PEN).

When IRQ occurs, you can test if it is the raster interrupt by
LDA $D019
AND #1
BEQ not_raster

Other bits in $D019 are set for sprite or light pen IRQ.

Besides that, the raster IRQ can happen twice if using split screen (GRAPHIC 2 or GRAPHIC 4).  Only one of the two is the main IRQ.

To determine if the raster IRQ is the main IRQ, immediately check raster high bit like this

;we know it is raster interrupt
LDA $D011
BPL not_main_irq


You should only call keyboard scan and jiffy clock update on main IRQ (not the middle raster in split screen) or jiffy clock will be really wrong and keys will type too fast.

When an IRQ occurs, the CPU will save A, X, Y (like C64) but will also save contents of $FF00 (current memory configuration) before JMP ($314).

If you write your own IRQ, you can end by JMP $FF33.  This will restore $FF00, A, X, and Y then do RTI.

The memory will configured to BANK 15 before JMP ($314) so your IRQ routine should be visible in BANK 15.

For C128, Old IRQ (as you say) is $FA65.

To enable your own IRQ routine, it is much like C64:

SEI
LDY #>ROUTTAB
LDX #<ROUTTAB
STX $314
STY $315
CLI
RTS


I'm sorry, but I don't know what MAINMASK, MAINCOUNT, or MAINSAVE are.

EhPortal 1.34 © 2025, WebDev