;*********************************************************
;*This intro uses the blitter to scroll text and the	 *
;*Copper to initiate the scroll and the raster		 *
;*********************************************************
speed	       equ	2
mod	       equ	0
;	       include	"df1:exec_lib.i"
;	       include	"df1:special_lib.i"
;	       include	"df1:copmac.i"
;	       include	"df1:dos_lib.i"
LIBRARIES_DOS_LIB_I	SET	$1
reserve EQU	$4
vsize	EQU	$6
count	SET	$FFFFFFE2
LIBENT	MACRO
_LVO\1	EQU	count
count	SET	count-vsize
	ENDM
	LIBENT	Open
	LIBENT	Close
	LIBENT	Read
	LIBENT	Write
	LIBENT	Input
	LIBENT	Output
	LIBENT	Seek
	LIBENT	DeleteFile
	LIBENT	Rename
	LIBENT	Lock
	LIBENT	UnLock
	LIBENT	DupLock
	LIBENT	Examine
	LIBENT	ExNext
	LIBENT	Info
	LIBENT	CreateDir
	LIBENT	CurrentDir
	LIBENT	IoErr
	LIBENT	CreateProc
	LIBENT	Exit
	LIBENT	LoadSeg
	LIBENT	UnLoadSeg
	LIBENT	GetPacket
	LIBENT	QueuePacket
	LIBENT	DeviceProc
	LIBENT	SetComment
	LIBENT	SetProtection
	LIBENT	DateStamp
	LIBENT	Delay
	LIBENT	WaitForChar
	LIBENT	ParentDir
	LIBENT	IsInteractive
	LIBENT	Execute
    ifnd macros
;	include "macros.s"
    endc
*------------------------------------------------------------------------*
* MyExec.i								 *
*------------------------------------------------------------------------*

set	       equ	1<<15
all	       equ	1<<9
bpldma	       equ	1<<8
copdma	       equ	1<<7
bltdma	       equ	1<<6
sprdma	       equ	1<<5
dskdma	       equ	1<<4
ch3dma	       equ	1<<3
ch2dma	       equ	1<<2
ch1dma	       equ	1<<1
ch0dma	       equ	1

ChipBase equ $dff000

CIA_A_PA equ $bfe001
CIA_A_PB equ $bfe101
CIA_A_DDRA equ $bfe201
CIA_A_DDRB equ $bfe301
CIA_A_TALO equ $bfe401
CIA_A_TAHI equ $bfe501
CIA_A_TBLO equ $bfe601
CIA_A_TBHI equ $bfe701
CIA_A_E.LSB equ $bfe801
CIA_A_E.MID equ $bfe901
CIA_A_E.MSB equ $bfea01
CIA_A_SP equ $bfec01
CIA_A_IRC equ $bfed01
CIA_A_CRA equ $bfee01
CIA_A_CRB equ $bfef01

CIA_B_PA equ $bfd001
CIA_B_PB equ $bfd101
CIA_B_DDRA equ $bfd201
CIA_B_DDRB equ $bfd301
CIA_B_TALO equ $bfd401
CIA_B_TAHI equ $bfd501
CIA_B_TBLO equ $bfd601
CIA_B_TBHI equ $bfd701
CIA_B_E.LSB equ $bfd801
CIA_B_E.MID equ $bfd901
CIA_B_E.MSB equ $bfda01
CIA_B_SP equ $bfdc01
CIA_B_IRC equ $bfdd01
CIA_B_CRA equ $bfde01
CIA_B_CRB equ $bfdf01

bltddat equ $000
dmaconr equ $002
vposr equ $004
vhposr equ $006
dskdatr equ $008
joy0dat equ $0A
joy1dat equ $00C
clxdat equ $00E

adkconr equ $010
pot0dat equ $012
pot1dat equ $014
potinp equ $016
serdatr equ $018
dskbytr equ $01A
intenar equ $01C
intreqr equ $01E

dskpt equ $020
dsklen equ $024
dskdat equ $026
refptr equ $028
vposw equ $02A
vhposw equ $02C
copcon equ $02E
serdat equ $030
serper equ $032
potgo  equ $034
joytest equ $036
strequ equ $038
strvbl equ $03A
strhor equ $03C
strlong equ $03E

bltcon0 equ $040
bltcon1 equ $042
bltafwm equ $044
bltalwm equ $046
bltcpt equ $048
bltbpt equ $04C
bltapt equ $050
bltdpt equ $054
bltsize equ $058

bltcmod equ $060
bltbmod equ $062
bltamod equ $064
bltdmod equ $066

bltcdat equ $070
bltbdat equ $072
bltadat equ $074

dsksync equ $07E

cop1lc equ $080
cop2lc equ $084
copjmp1 equ $088
copjmp2 equ $08A
copins equ $08C
diwstrt equ $08E
diwstop equ $090
ddfstrt equ $092
ddfstop equ $094
dmacon equ $096
clxcon equ $098
intena equ $09A
intreq equ $09C
adkcon equ $09E

aud  equ $0A0
aud0 equ $0A0
aud1 equ $0B0
aud2 equ $0C0
aud3 equ $0D0

ac_ptr equ $00	 ; ptr to start of waveform data
ac_len equ $04	 ; length of waveform in words
ac_per equ $06	 ; sample period
ac_vol equ $08	 ; volume
ac_dat equ $0A	 ; sample pair
ac_SIZEOF equ $10

bplpt equ $0E0

bplcon0 equ $100
bplcon1 equ $102
bplcon2 equ $104
bpl1mod equ $108
bpl2mod equ $10A

bpldat equ $110

sprpt  equ $120

spr equ $140

sd_pos equ $00
sd_ctl equ $02
sd_dataa equ $04
sd_datab equ $08

color equ $180

cmove	       macro
	       dc.w	\2,\1
	       endm
cwait	       macro
	       dc.b	\1,$01
	       dc.w	$ff00
	       endm
cend	       macro
	       dc.w	$ffff,$fffe
	       endm

cb	       macro
	       dc.w	$0180,$0000
	       endm



    ifnd macros
;	include "macros.s"
    endc
ExecBase equ 4
Supervisor equ -30
ExitIntr equ -36
Schedule equ -42
Reschedule equ -48
Switch equ -54
Dispatch equ -60
Exception equ -66
InitCode equ -72
InitStruct equ -78
MakeLibrary equ -84
MakeFunctions equ -90
FindResident equ -96
InitResident equ -102
Alert equ -108
Debug equ -114
Disable equ -120
Enable equ -126
Forbid equ -132
Permit equ -138
SetSR equ -144
SuperState equ -150
UserState equ -156
SetIntVector equ -162
AddIntServer equ -168
RemIntServer equ -174
Cause equ -180
Allocate equ -186
Deallocate equ -192
AllocMem equ -198
AllocAbs equ -204
FreeMem equ -210
AvailMem equ -216
AllocEntry equ -222
FreeEntry equ -228
Insert equ -234
AddHead equ -240
AddTail equ -246
Remove equ -252
RemHead equ -258
RemTail equ -264
Enqueue equ -270
FindName equ -276
AddTask equ -282
RemTask equ -288
FindTask equ -294
SetTaskPri equ -300
SetSignal equ -306
SetExcept equ -312
Wait equ -318
Signal equ -324
AllocSignal equ -330
FreeSignal equ -336
AllocTrap equ -342
FreeTrap equ -348
AddPort equ -354
RemPort equ -360
PutMsg equ -366
GetMsg equ -372
ReplyMsg equ -378
WaitPort equ -384
FindPort equ -390
AddLibrary equ -396
RemLibrary equ -402
OldOpenLibrary equ -408
CloseLibrary equ -414
SetFunction equ -420
SumLibrary equ -426
AddDevice equ -432
RemDevice equ -438
OpenDevice equ -444
CloseDevice equ -450
DoIO equ -456
SendIO equ -462
CheckIO equ -468
WaitIO equ -474
AbortIO equ -480
AddResource equ -486
RemResource equ -492
OpenResource equ -498
RawIOInit equ -504
RawMayGetChar equ -510
RawPutChar equ -516
RawDoFmt equ -522
GetCC equ -528
TypeOfMem equ -534
Procure equ -540
Vacate equ -546
OpenLibrary equ -552
; Kickstart 1.3 only
InitSemaphore equ -558
ObtainSemaphore equ -564
ReleaseSemaphore equ -570
AttemptSemaphore equ -576
ObtainSemaphorelist equ -582
ReleaseSemaphorelist equ -588
FindSemaphore equ -594
AddSemaphore equ -600
RemSemaphore equ -606
SumKickData equ -612
AddMemList equ -618
CopyMem equ -624
CopyMemQuick equ -630

	       section	mycode,code_c

begin	       move.l	(ExecBase).w,a6    ;Get ExecBase
	       lea	$dff000,a4	   ;Chipbase
	       jsr	Forbid(a6)         ;Prevent multitasking
	       move.l	(a6),a2            ;
	       move.l	(a2),a3            ;Get gfxbase
;	       move.l	$32(a3),d5         ;save old Clist
	       move.w	intenar(a4),d1     ;save intena
	       or.w	#$c000,d1	   ;Enable all bits that were set
	       move.w	d1,intsav	   ;
	       lea	MyCopper(pc),a1    ;
	       move.l	a1,a2		   ;
;	       move.l	a1,$32(a3)         ;tell the system about our Clist
	       move.l	a1,cop1lc(a4)      ;poke the copper anyway
	       clr.w	copjmp1(a4)        ;start it
	       move.l	#$10002,d1
	       move.l	#(40*200),d0
	       jsr	AllocMem(a6)       ;allocate 1 bitplane lores
	       move.l	d0,d7
	       bne.s	skl
	       rts
skl
	       move.w	d0,6(a2)           ;put the bitplane address
	       swap	d0		   ;in our copper list
	       move.w	d0,2(a2)           ;
	       lea	text(pc),a1        ;initial text to print
	       move.l	a1,textptn	   ;initialize the pointer
ww	       btst	#6,dmaconr(a4)     ;
	       bne ww			   ;Waitblit()
upt	       move.l	$6c.w,interuptsave ;save autovector
	       lea	newinterupt(pc),a1 ;
	       move.l	a1,$6c.w	   ;put ours there
	       move.w	#$3fff,intena(a4)  ;clear all interupts
	       move.w	#$c020,intena(a4)  ;blit and vertical blank only
	       move.w	#$0020,dmacon(a4)  ;turn off sprites
	       move.w	#$8040,dmacon(a4)  ;turn on blitter dma
	       move.l	d7,bitaddress	   ;
;	       bsr	putit		   ;print text
wait_mouse     btst	#6,$bfe001	   ;
	       bne.s	wait_mouse	   ;wait for mouse click
	       jmp	endint

newinterupt    movem.l	a0-a6/d0-d7,-(sp)
	       lea	$dff000,a4	   ;get chipbase
	       move.l	#-1,bltafwm(a4)    ;make first and last masks all 1's
	       lea	MyCopper(pc),a1    ;
	       move.l	a1,cop1lc(a4)      ;poke copper, redundant
	       clr.w	copjmp1(a4)        ;activate it
	       lea	copstart(pc),a0    ;address of copper
	       lea	colortab(pc),a1    ;color table
	       move.l	#$0103fffe,(a0)+   ;wait line 1
	       move.l	#$01820000,(a0)+   ;black background
	       move.l	#$01820fff,(a0)+   ;white foreground
	       moveq.l	#24-2,d0	   ;size of 8 colors
	       lea	position(pc),a2    ;get position of sin table
	       lea	positiontab(pc),a3 ;get address of table
	       move.l	a3,d2
	       clr.l	d3
	       move.w	(a2),d3
	       add.l	d3,d2
	       move.l	d2,a2
	       clr.l	d4
	       move.b	(a2),d4
	       addi.b	#80,d4
	       lea	possave(pc),a4
	       move.w	d4,(a4)
	       lsl.w	#4,d4
	       lsl.w	#4,d4
	       andi.w	#$ff00,d4
	       or.w	#$01,d4
loop	       move.w	d4,(a0)+           ;construct copper wait
	       move.w	#$fffe,(a0)+       ;mask
	       move.w	#$0182,(a0)+       ;color0
	       move.w	(a1)+,(a0)+        ;poke color
	       add.l	#$0100,d4	   ;increase vertical position
	       dbf	d0,loop 	   ;
	       move.w	d4,(a0)+           ;black
	       move.w	#$fffe,(a0)+       ;
	       move.l	#$01800000,(a0)+   ; black
	       move.w	#$0182,(a0)+       ;foreground move
	       lea	colortab(pc),a5    ;
	       move.w	(a5),(a0)+         ;flash text at bottom
	       move.l	#$fffffffe,(a0)    ;end of Clist
	       moveq.l	#1,d0		   ;
	       sub.w	d0,time 	   ;
	       bne.s	df		   ;
	       move.w	#speed,time	   ;speed of rotation
	       lea	colortab(pc),a1    ;rotate colors
	       move.l	a1,a0		   ;
	       move.w	(a1)+,d2           ;save first color
	       move.l  #(colortab2-colortab-4)/2,d0  ;
loop2	       move.w	(a1)+,(a0)+        ;load color+1  sta color
	       dbf	d0,loop2
	       move.w	d2,(a0)            ;move saved color at end of list
df	       lea	position(pc),a0    ;
	       move.w	(a0),d0            ;increment sin table
	       addq.w	#1,d0
	       cmpi.w	#(ptabend-ptabst)-1,d0
	       bne.s	posok
	       moveq	#0,d0
posok	       move.w	d0,(a0)
	       lea	$dff000,a4
	       bsr	scrollit	   ;scroll the scroller
	       move.w	#$20,intreq(a4)    ;clear vertb interupt
endo	       movem.l	(sp)+,a0-a6/d0-d7  ;restore regs
	       rte

scrollit       move.l	bitaddress,a3	   ;clear
	       move.l	#(40*8*4),d0       ; the
	       add.l	d0,a3		   ;   scroller
	       move.l	a3,bltdpt(a4)      ;    area
	       clr.w	bltdmod(a4)        ;     for
	       move.w	#$0100,bltcon0(a4) ;      redraw
	       move.w	#$0000,bltcon1(a4) ;
	       move.w	#8724,bltsize(a4)  ;
bw1	       btst	#6,dmaconr(a4)     ; Waitblit()
	       bne	bw1
	       clr.l	d0
	       clr.l	d1
	       move.w	possave,d0	   ;
	       sub.w	#$24,d0 	   ;
	       move.l	#40,d1		   ;calculate new position of scroller
	       mulu.w	d0,d1		   ;
	       add.l	bitaddress,d1	   ;
	       move.l	d1,a0
	       lea	scrollbuffer(pc),a1;
	       move.w	#$09f0,bltcon0(a4) ;blit it
	       move.w	#$2,bltamod(a4)    ;  onto
	       move.l	a1,bltapt(a4)      ;   the screen
	       move.l	a0,bltdpt(a4)      ; size=40 bytes wide (320 pixels)
	       move.w	#532,bltsize(a4)   ; 8 lines high
bw2	       btst	#6,dmaconr(a4)     ;Waitblit()
	       bne.s	bw2
	       lea	charend(pc),a0     ;
	       move.l	a0,bltapt(a4)      ;scroll the
	       move.l	a0,bltdpt(a4)      ;  scroller
	       clr.w	bltdmod(a4)        ;    to the
	       clr.w	bltamod(a4)        ;      left
	       move.w	#$49f0,bltcon0(a4) ; 1 shift left channel A, USEA USED
	       move.w	#$0002,bltcon1(a4) ; Decrement
	       move.w	#533,bltsize(a4)   ;size, 328 pixels wide, 8 high
bw3	       btst.b	#6,dmaconr(a4)     ;Waitblit()
	       bne.s	bw3
	       move.w	scroll,d0
	       subq.w	#4,d0
	       move.w	d0,scroll
	       beq.s	newchar
	       rts
	       
newchar        move.l	textptn,a0	   ;
reloop	       addq.l	#1,a0		   ;fetch
	       move.l	a0,textptn	   ;  new
	       clr.l	d0		   ;	letter
	       subq.l	#1,a0		   ;	  and
	       move.b	(a0)+,d0           ;        print it
	       bne.s	aok		   ;	     into the
	       lea	text(pc),a0        ;          end of the
	       bra.s	reloop		   ;		scroll
aok	       cmpi.b	#'a',d0            ;             buffer
	       blo.s	nolet2		   ;
	       cmpi.b	#'z',d0
	       bge.s	nolet2
	       subi.l	#$60,d0
nolet2	       add.l	d0,d0
	       add.l	d0,d0
	       add.l	d0,d0
	       lea	charbase+2048(pc),a0
	       add.l	d0,a0
	       lea	charsave(pc),a1
	       subq.l	#1,a1
	       moveq.l	#8,d0
nlp	       move.b	(a0),(a1)
	       addq.l	#1,a0
	       add.l	#42,a1
	       subq.l	#1,d0
	       bne.s	nlp
	       move.w	#8,scroll
	       rts

endint	       move.l	interuptsave(pc),$6c.w  ; restore old autovector
	       move.w	#$7fff,intena(a4)       ;clear all interupts
	       move.w	intsav,intena(a4)       ; put old bits back
;	       move.l	d5,$32(a3)              ;put Clist pack
;	       move.l	d5,cop1lc(a4)           ;force it back
	       move.l	38(a3),cop1lc(a4)
	       clr.w	copjmp1(a4)             ;load it
	       move.w	#$8020,dmacon(a4)       ;enable sprites
	       move.w	#$8020,intreq(a4)       ;trigger a soft int
enddeb	       move.l	d7,a1			;
	       move.l	#(40*200),d0            ;
	       jsr	FreeMem(a6)             ;free bitplane
	       jsr	Permit(a6)              ;renable multitasking
	       moveq	#0,d0
	       rts

interuptsave   dc.l	0
scroll	       dc.w	8
textptn        dc.l	0
bitaddress     dc.l	0

colortab       dc.w	$000,$010,$020,$030,$040,$050,$060,$070,$080
	       dc.w	$090,$0a0,$0b0,$0c0,$0d0,$0e0,$0f0,$0f0
	       dc.w	$0e0,$0d0,$0c0,$0b0,$0a0,$090,$080,$070
	       dc.w	$060,$050,$040,$030,$020,$010,$000
	       dc.w	$000,$001,$002,$003,$004,$005,$006,$007,$008
	       dc.w	$009,$00a,$00b,$00c,$00d,$00e,$00f,$00f
	       dc.w	$00e,$00d,$00c,$00b,$00a,$009,$008,$007
	       dc.w	$006,$005,$004,$003,$002,$001,$000
	       dc.w	$000,$100,$200,$300,$400,$500,$600,$700,$800
	       dc.w	$900,$a00,$b00,$c00,$d00,$e00,$f00,$f00
	       dc.w	$e00,$d00,$c00,$b00,$a00,$900,$800,$700
	       dc.w	$600,$500,$400,$300,$200,$100,$000
	       dc.w	$000,$111,$222,$333,$444,$555,$666,$777
	       dc.w	$888,$999,$aaa,$bbb,$ccc,$ddd,$eee,$fff
	       dc.w	$fff,$eee,$ddd,$ccc,$bbb,$aaa,$999,$888
	       dc.w	$777,$666,$555,$444,$333,$222,$111,$000
	       dc.w	$008,$018,$028,$038,$048,$058,$068,$078
	       dc.w	$088,$098,$0a8,$0b8,$0c8,$0d8,$0e8,$0f8
	       dc.w	$0f8,$0e8,$0d8,$0c8,$0b8,$0a8,$098,$088
	       dc.w	$078,$068,$058,$048,$038,$028,$018,$008
	       dc.w	$008,$108,$208,$308,$408,$508,$608,$708
	       dc.w	$808,$908,$a08,$b08,$c08,$d08,$e08,$f08
	       dc.w	$f08,$e08,$d08,$c08,$b08,$a08,$908,$808
	       dc.w	$708,$608,$508,$408,$308,$208,$108,$008
colortab2
time	       dc.w	speed
MyCopper       dc.w	$00e0
bitplanehi     dc.w	$007c
	       dc.w	$00e2
bitplanelo     dc.w	$0000
	       cmove	$2c81,$008e
	       cmove	$f4c1,$0090
	       cmove	$0038,$0092
	       cmove	$00d0,$0094
	       cmove	$0000,$0180
	       cmove	$0000,$0120
	       cmove	$0000,$0122
	       cmove	mod,$108
	       cmove	mod,$10a
	       cmove	%0001001000000000,$0100
	       dc.w	$383b,$fffe
copstart       ds.l	100
	       even
	       dc.l	0
	       ds.l	10
	       even
scrollbuffer   ds.b	320
	       ds.w	6
charend        dc.w	0
charsave       equ	scrollbuffer+40
intsav	       dc.w	0
position       dc.w	0
possave        dc.w	0
	       dc.w	50,50,50,50
ptabst
positiontab:    incbin	"ram:sine_data"
ptabend
	       even
*------------------ Print rotine
* a0=bitplane
* d0=character
* d1=x
* d2=y
horez	       equ	320
charbase       incbin	"df1:charset"
a	       set	0
table
	       rept   25
	       dc.w	a
a	       set	a+horez
	       endr

cprint	       movem.l	d0-d3/a0-a1,-(sp)
	       lea	table(pc),a1
	       add.l	d2,d2
	       move.w	0(a1,d2.w),d2
	       lea	charbase+2048(pc),a1
	       add.l	d0,d0
	       add.l	d0,d0
	       add.l	d0,d0	    ; C=character x 8
	       add.l	d0,a1	    ; c=c+charbase    Add it to original Base
*------------------ Offset it
	       add.l	d2,d1	    ; Add X + (Y*8) --> d
	       add.l	d1,a0	    ; Add d to BITMAP
*------------------ Transfer
	       moveq	#8-1,d0
	       moveq	#(horez/8),d1
.loop	       move.b	(a1)+,d3
	       move.b	d3,(a0)
	       add.w	d1,a0
	       dbra	d0,.loop
	       movem.l	(sp)+,d0-d3/a0-a1
	       rts
*------------------ Character set plot
putit
	       move.l	d7,a0
	       moveq	#0,d1
	       moveq	#22,d2
	       lea	text2(pc),a1
	       moveq	#0,d0
hyu	       move.b	(a1)+,d0
	       beq.s	tend
	       cmpi.b	#'a',d0
	       blo.s	nolet
	       cmpi.b	#'z',d0
	       bge.s	nolet
	       subi.l	#$60,d0
nolet	       bsr	cprint
	       addq.l	#1,d1
	       bra.s	hyu
tend	       rts
text2	       dc.b	'-    Insert your screen text here!   -',0
	       even
text	       dc.b	'OK, This is a TEST of my scroll text for my INTRO. HERE IS THE CAPS CHARACTER SET, HERE is the lower case set. '
	       dc.b	'The code is old, sloppy, and redundant, but it works. When I get the time, I will allocate '
	       dc.b	'a screen using the OS, remove the forbid, shut down amiga n/m, and see if it is still as '
	       dc.b	'smooth. My mail address is rjc@gnu.ai.mit.edu. Have fun disecting my code. Remember, '
	       dc.b	'this code is old and I did it when I was still a novice. Note, this program could be '
	       dc.b	'done in C except for the beginning of the interupt which would probably need an asm '
	       dc.b	'tag routine. ',0
	       even



