From: bpat@cs.mcgill.ca (Patrick BETREMIEUX)
Subject: ST Timer-B routine
Keywords: Floppies floprt
Organization: McGill University, Montreal, Canada
Date: Wed, 7 Oct 1992 13:22:33 GMT

Since it seems that a lot of people want to know about those MFP timers, I've
decided to re-post a program I wrote that uses Timer-B to make the menu bar
rotate with colors:
I hope the fact that it's in assembler won't bother too much. The addresses
of the MFP are visible though (They have $FFFFFxxx)

					Patrick.

PS. I haven't forgotten that I promised to give the font formats. It's just
that I had many other things to do, and I never got around to posting it.
I'll do it later.

==================== CUT HERE ====================

 move.l 4(a7),a5
 move.l $C(a5),d0
 add.l $14(a5),d0
 add.l $1C(a5),d0
 lea stack,a7
 move.l d0,size
 move.l d0,-(sp)
 move.l a5,-(sp)
 clr.w -(sp)
 move.w #$4A,-(sp)
 trap #1                  ; All this just to reserve memory
 add.l #12,sp
 pea vbl_init
 move.w #38,-(sp)
 trap #14                 ; execute this routine in supervisor mode
 addq.l #6,sp
 clr.w -(sp)
 move.l size,-(sp)
 move.w #$31,-(sp)
 trap #1                  ; Terminate and Stay Resident
 rts

vbl_init:
 move.w #5,rotate
 move.l #palettes,pal
 move.l #register,reg
 lea save,a6
 move.b $FFFFFa07,(a6)+   ; just to save the previous values
 move.b $FFFFFA09,(a6)+
 move.b #$FF,$FFFFFA07    ; open all interrupts of the MFP
 move.b #$FF,$FFFFFA09    ;
 move.l $70,vbl2 + 2      ; place original address in jmp instruction
 move.l #new_vbl,$70      ; install new vbl routine
 rts

new_vbl:
 and.w #$F0FF,sr          ; Interrupt level 0
 move.l #palettes,pal     ; reset palettes
 move.l #register,reg     ;   and registers
 move.b #0,$FFFFFA1B      ; stop timer B
 bset #3,$FFFFFA17        ; set timer B as Software-end-of-interrupt
                          ; That is, interrupt is reset only when my program
			  ; says so.
 move.l #new_hbl,$120     ; set interrupt vector for timer B
 move.b #1,$FFFFFA21      ; counter for timer B
 bset #0,$FFFFFA13        ; unmask timer B
 bset #0,$FFFFFA07        ; allow timer B interupt
 move.b #8,$FFFFFA1B      ; event count mode. Timer B is hooked up to the
                          ; monitor's line counter. It goes down by one at
			  ; every line return
 bclr #0,$FFFFFA0F        ; run timer B

            ; All that follows is just to make the color scrolling
 move.l a6,-(sp)
 move.l a5,-(sp)
 lea $FFFF8240,a5         ; $FFFF8240 is the address of the palette
 move.l reg,a6
 add.w (a6),a5
 move.l pal,a6
 move.w (a6),(a5)
 addq.l #2,pal
 addq.l #2,reg
 move.l d6,-(sp)
 move.l d7,-(sp)
 lea rotation,a5
\loop1:
 cmp.l #-1,(a5)
 beq \stop_r
 subq.w #1,6(a5)
 bne next_r
 move.w 4(a5),6(a5)
 lea palettes,a6
 move.w (a5),d6
 move.w 2(a5),d7
 move.w (a6,d6.w),color
\loop2:
 addq.w #2,d6
 move.w (a6,d6.w),-2(a6,d6.w)
 cmp.w d6,d7
 bne \loop2
 move.w color,(a6,d6.w)
\next_r:
 add.l #8,a5
 jmp \loop1
\stop_r:
 move.l (sp)+,d7
 move.l (sp)+,d6
 move.l (sp)+,a5
 move.l (sp)+,a6
vbl2:
 jmp $333333           ; go to old vbl (Takes care of mouse, and drive spin)

new_hbl:
 or.w #$0700,sr        ; cut all interrupts.
 move.l a6,-(sp)
 move.l a5,-(sp)
 lea $FFFF8240,a5      ; change the palette in the shifter
 move.l reg,a6
 add.w (a6),a5
 move.l pal,a6
 move.w (a6),(a5)
 addq.l #2,pal
 addq.l #2,reg
 move.l (sp)+,a5
 move.l (sp)+,a6
 cmp.l #end_pal,pal
 bne \no1
 move.b #0,$FFFFFA1B   ; if at end of list, stop timer B
\no1:
 bclr #0,$FFFFFA0F     ; let timer B continue
 rte

rotate: ds.w 1
color:  ds.w 1
pal:    ds.l 1
reg:    ds.l 1

; In here, you may do any modification you want.
; for each set of 4 words, we have the following:
;  - first line of rotation, x2
;  - last line of rotation, x2
;  - number of vbl to wait before rotating
;  - counter for number left to wait (Gets modified)
;
; the last one has -1 in all four

rotation:
 dc.w 0,16,5,5
 dc.w -1,-1,-1,-1

; Says which color pen gets changed to the corresponding value in palettes
; must be x2 as well (Careful, the number is in shifter order, not GEM.
; Background is color 15)

register
 dc.w 30,30,30,30,30,30,30,30,30,30
 dc.w 4,4,4,4,4,4,4,4,4
 .
 .    21 times in all
 .
 dc.w 4,4,4,4,4,4,4,4,4

palettes:
 dc.w $700,$600,$600,$500,$400,$400,$500,$600,$600,$000
end_pal:
 dc.w
 .
 . any data you want, as long as you use it
 .
 dc.w

save:  ds.l 1
size:  ds.l 1
       ds.l 50
stack: ds.l 1

 end
Newsgroups: comp.sys.atari.st.tech