
; 2 mhz 40 column 128 mode interrupt routine
; This will enable the 40 column mode of the c128 to run at almost 2MHz!
; The trick is to turn on the 2MHz mode in the borders, and turn on the
; 1MHz mode while in the 40 column screen.
; This also illustrates the technique of interrupt handling and VIC-II
; massaging by handling the raster interrupts.
; By Todd S. Elliott

; Equates
iirq = $0314; IRQ Vector for interrupt handling
mmucr = $FF00; MMU Configuration Register
vicirq = $D019; VIC-II Interrupt Register
raster = $D012; Raster compare register
clkrat = $D030; Adjusts the speed of the 8502 chip
crti = $ff33; Common interrupt return vector

; set up the irq routine
two'mhz sei
  lda <twomhz
  sta iirq
  lda >twomhz
  sta iirq+1
  cli
  rts

; the irq routine to handle the 2 mhz speed output

twomhz lda #$00:sta mmucr; switch to bank 15 first
  cld; required by irq routine
  lda #$01
  sta vicirq; prevent normal raster clear-interrupt
  lda raster
  cmp #248; check to see which scanline we're at
  bcc +
  ldy #$05
- nop; a little timing tweak to finesse the raster interrupt
  dey; (NTSC timing)
  bne -
  lda #49
  sta raster
  lda #$01
  sta clkrat; turn on 2 mhz mode
  bne ++
+ lda #$00
  sta clkrat; switch back to 1 mhz mode
  lda #249
  sta raster; store in bottom scanline
  jsr $f5f8; update timer
  lda $dc0d; clear CIA interrupts
  jsr $ff9f; check keypress
+ jmp crti; return to normal irq exit routine

; end of 2 mhz routine


