Date:  05-Nov-95 13:06 CET
From:  =?ISO-8859-1?Q?Marko_M=E4kel=E4?= > INTERNET:Marko.Makela@HUT.FI
Subj:  Rasterroutine

Sender: msmakela@snakemail.hut.fi
Received: from vinkku.hut.fi by dub-img-4.compuserve.com (8.6.10/5.950515)
        id GAA11842; Sun, 5 Nov 1995 06:58:31 -0500
Received: from lk-hp-20.hut.fi (lk-hp-20.hut.fi [130.233.247.33]) by
vinkku.hut.fi (8.6.12/8.6.7) with ESMTP id NAA17071; Sun, 5 Nov 1995 13:57:53
+0200
Received: (msmakela@localhost) by lk-hp-20.hut.fi (8.6.12/8.6.7) id NAA05932;
Sun, 5 Nov 1995 13:57:55 +0200
Date: Sun, 5 Nov 1995 13:57:55 +0200
Message-Id: <199511051157.NAA05932@lk-hp-20.hut.fi>
From: Marko.Makela@HUT.FI (=?ISO-8859-1?Q?Marko_M=E4kel=E4?=)
Organization: Helsinki University of Technology, Finland.
To: jopi@stekt.oulu.fi, b150542@proffa.cc.tut.fi, 100112.220@compuserve.com,
        boose@linux.rz.fh-hannover.de,
        cipdd097@student.e-technik.uni-stuttgart.de,
        bauec002@goofy.zdv.uni-mainz.de
Subject: Rasterroutine
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit

Terve!
Hallo!


Well, I'm not going to speak in languages this time.  Here's the
raster routine I wrote this weekend.  It fully synchronizes in 4
rasterlines, even if there is a bad line in the area.  The current
version only works with PAL videochips and in the $30-$f0 area,
because it assumes that bad lines exist everywhere, also in the
borders.  But this is fairly easy to fix, as well as making versions
for NTSC videochips.

Here's the DASM source for the routine, and a C64 program file if you
want to test it.  Just POKE53266 with different values and see how the
color strip moves around.  The color table at end of the source is not
used yet, it's for the raster effect I am going to code next weekend.



        Marko

-8<--leikkaa tdstd--8<--hier schneiden--8<--leikkaa tdstd--8<--hier schneiden-

  processor 6502

; Select the video timing (processor clock cycles per raster line)
;CYCLES = 65        ; 6567R8 and above, NTSC-M
;CYCLES = 64        ; 6567R5 6A, NTSC-M
CYCLES = 63        ; 6569 (all revisions), PAL-B

cinv = $314        ; KERNAL IRQ vector
raster = 52        ; start of raster interrupt
m = $fb                ; zero page variable
cnt = m

  .org $801
basic:
  .word 0$        ; link to next line
  .word 1995        ; line number
  .byte $9E        ; SYS token

; SYS digits

  .if (* + 8) / 10000
  .byte $30 + (* + 8) / 10000
  .endif
  .if (* + 7) / 1000
  .byte $30 + (* + 7) % 10000 / 1000
  .endif
  .if (* + 6) / 100
  .byte $30 + (* + 6) % 1000 / 100
  .endif
  .if (* + 5) / 10
  .byte $30 + (* + 5) % 100 / 10
  .endif
  .byte $30 + (* + 4) % 10

0$:
  .byte 0,0,0        ; end of BASIC program

start:
  jmp install
  jmp deinstall

install:        ; install the raster routine
  lda cinv      ; check the original IRQ vector
  ldx cinv+1        ; (to avoid multiple installation)
  cmp #<irq1
  bne irqinit
  cpx #>irq1
  beq skipinit
irqinit:
  sei
  sta oldirq        ; store the old IRQ vector
  stx oldirq+1
  lda #<irq1
  ldx #>irq1
  sta cinv        ; set the new interrupt vector
  stx cinv+1
skipinit:
  lda #<irq2
  ldx #>irq2
  sta $fffe        ; set the interrupt vector of the 2nd raster routine
  stx $ffff
  lda #$1b
  sta $d011        ; set the raster interrupt location
  lda #raster
  sta $d012


;  ldx #$e
;  clc
;  adc #3
;  tay
;  lda #0
;  sta m
;0$:
;  lda m
;  sta $d000,x        ; set the sprite X
;  adc #24
;  sta m
;  tya
;  sta $d001,x        ; and Y coordinates
;  dex
;  dex
;  bpl 0$


  lda #$7f
  sta $dc0d        ; disable timer interrupts
  sta $dd0d
  ldx #1
  stx $d01a        ; enable raster interrupt
  lda $dc0d        ; acknowledge CIA interrupts
  lda $dd0d
  lsr $d019        ; and video interrupts
  ldy #0
  sty $d015        ; turn off all sprites
  cli
  rts

deinstall:
  sei                ; disable interrupts
  lda #$1b
  sta $d011        ; restore text screen mode
  lda #$81
  sta $dc0d        ; enable Timer A interrupts on CIA 1
  lda #0
  sta $d01a        ; disable video interrupts
  lda oldirq
  sta cinv        ; restore old IRQ vector
  lda oldirq+1
  sta cinv+1
  cli
  rts

; Auxiliary raster interrupt (for syncronization)
irq1:
; irq (event)   ; > 7 + at least 2 cycles of last instruction (9 to 16 total)
; pha           ; 3
; txa           ; 2
; pha           ; 3
; tya           ; 2
; pha           ; 3
; tsx           ; 2
; lda $0104,x   ; 4
; and #$10      ; 2
; beq           ; 3
; jmp ($314)    ; 5
                ; ---
                ; 38 to 45 cycles delay at this stage

  ldx $d012
  ldy #7
  sty $d019        ; acknowledge the raster interrupt
  cli                ; enable interrupts
  inx
  txa
  eor $d011
  and #7        ; is the following line bad?
  beq bad2$        ; yes, branch
  cpx $d012        ; is the current line bad?
  bne bad$        ; yes, branch

; no bad lines before interrupt -> 43 extra cycles to waste
  txa
  inx
  sbc $d011        ; the C flag is set at this stage
  and #7
  eor #7
  sec
  adc #0
  ldy #3
delay$:
  dey
  bne delay$
  nop
  nop
  tay
  bpl ret$        ; branch always

bad2$:
  iny
  inx
ret$:
  nop
bad$:
  stx $d012
  lda #$35
  sta 1                ; select 60k RAM + 4k I/O
  nop                ; the interrupt will occur at this place
  nop
  nop
  nop
  lda #$37        ; restore original memory configuration
  sta 1

oldirq = * + 1        ; Placeholder for self-modifying code
  jmp *                ; Return to the original interrupt

; Main raster interrupt (called directly from $fffe)
irq2:
  dey
  tya
  beq bad$        ; skip extra delay if this is a bad line
  ldy #8
delay$:
  dey
  bne delay$
  ldy $a4        ; this is for delay
bad$:
  cpx $d012        ; check the synchronization
  beq *+2
  sta cnt
  dex
  dex
  stx $d012        ; restore original raster interrupt position
  asl $d019        ; acknowledge the interrupt (and set the C flag)
  dec cnt
  beq bad2$
  lda cnt
  and #7
  sta cnt
  ldy #7
delay2$:
  dey
  bne delay2$
bad2$:
  stx $d020        ; nice raster effect
  dex
  stx $d020
  rti

colors:
  .byte 0        ; final color
  .byte $46,$4b,$44,$0e,$83,$0d,$01,$01,$07,$4f,$4a,$08,$89,$40,$40,$00
        ; nice color cycle


begin 644 superraster.c64
M`0@*",L'GC(P-C$```!,$PA,8PBM%`.N%0/)@=`$X`CP$7B-P0B.P@BI@:((
MC10#CA4#J<.B"(W^_X[__ZD;C1'0J32-$M"I?XT-W(T-W:(!CAK0K0W<K0W=
M3AG0H`",%=!88'BI&XT1T*F!C0W<J0"-&M"MP0B-%`.MP@B-%0-88*X2T*`'
MC!G06.B*31'0*0?P&^P2T-`9BNCM$=`I!TD'.&D`H`.(T/WJZJ@0`LCHZHX2
MT*DUA0'JZNKJJ3>%`4S`"(B8\`>@"(C0_:2D[!+0\`"%^\K*CA+0#AG0QOOP
E"Z7[*0>%^Z`'B-#]CB#0RHX@T$``1DM$#H,-`0$'3TH(B4!``!+0
`
end


Distribution:

To: [100112,220]
    INTERNET:B150542@PROFFA.CC.TUT.FI   INTERNET:JOPI@STEKT.OULU.FI
    INTERNET:BAUEC002@GOOFY.ZDV.UNI-MAINZ.DE
    INTERNET:BOOSE@LINUX.RZ.FH-HANNOVER.DE
    INTERNET:CIPDD097@STUDENT.E-TECHNIK.UNI-STUTTGART.DE

