º8¶a§1¬3
                      Coding 1200/4000 compatible
¬2
               Written By Crew 01/Vicious and Intercept
¬1
As many happy 1200-users know, many demos do not work on their machine.
Beeing  a amiga 1200-user and a coder I know how easy it actually is to
code  1200/4000-compatible.   In  this  article  I  hope to help coders
without an amiga 1200 to code aga-compatible.  If you do not agree with
my  statements  in  this  article,  please contact me, then we can talk
about it.

First of all:
¬3- Proper Copper Setup¬1

With  the  introduction of the AGA, or AA as some call it, a lot of new
hardware  registers  are introduced in amiga-world.  The 'old' demos do
not  clear such registers, nor call the library-call that should do the
job.   Demos  like  that  are  recognized  by  the 'not-so-very-normal'
screens.   (It  looks like the modulo is set to $07fe or something like
that.)   To  avoid  problems  like  that,  call  the  dos-library  call
'Loadview(A1)' and just clear A1 for an complete 'display-flush'.

¬3-An example,tested om my 1200, 500's and a 600 :¬1

¬2*  Please note that the copperadress is obtained in another way than in
the hardware manual is described.¬1

Init:	move.l	$4.w,a6				;exec pointer to a6
	lea.l	gfxname,a1			;set library pointer
	moveq	#0,d0
	jsr	oldopenlibrary(a6)		;open graphics.library
	Move.l	d0,gfxbase
	move.l	d0,a6				;use base-pointer
	Move.l	34(a6),wbview			;!!!! Store view-adress

	Move.l	#0,a1
	jsr	-$00de(a6)			; Loadview 0
	jsr	-$010e(a6)			; WaitTOF (Top Of Frame)
	jsr	-$010e(a6)

	lea	$dff000,a6
	move.w	$1c(a6),intena_save		;store old intena
	move.w	$2(a6),dmacon_save		;store old dmacon
	move.w	$10(a6),adkcon_save		;store old adkcon

	move.w	#$7fff,$9a(a6)			;clear interrupt enable

	bsr	vwait				;you could also use waitTOF

	move.w	#$7fff,$96(a6)			;clear dma channels
	lea	copperlist,a0
	move.l	a0,$80(a6)			;copper1 start address
	move.w	#dmaset!$8200,$96(a6)		;dma kontrol data
	move.l	$6c.w,oldinter_save		;store old inter pointer
	lea	newirq,a0
	move.l	a0,$6c.w			;set interrupt pointer

	move.w	#$7fff,$9c(a6)			;clear request
	move.w	#$c020,$9a(a6)			;interrupt enable
	rts

Restore:
	lea	$dff000,a6

	move.w	#$7fff,$9a(a6)		;disable interrupts

	bsr	vwait			;could also use a library call

	move.w	#$7fff,$96(a6)
	move.l	oldinter_save,$6c.w	;restore inter pointer
	move.w	dmacon_save,d0		;restore old dmacon
	or.w	#$8000,d0
	move.w	d0,$96(a6)		
	move.w	adkcon_save,d0		;restore old adkcon
	or.w	#$8000,d0
	move.w	d0,$9e(a6)
	move.w	intena_save,d0		;restore inter data
	or.w	#$c000,d0
	move.w	#$7fff,$9c(a6)
	move.w	d0,$9a(a6)

	Move.l	gfxbase,a6
	Move.l	wbview,a1			;restore view
	jsr	-$00de(a6)			;loadview
	jsr	-$010e(a6)
	jsr	-$010e(a6)

	Move.l	38(a6),$dff080			; and restore copper

	Move.l	a6,a1
	move.l	$4.w,a6				;exec pointer to a6
	jsr	closelibrary(a6)		;close graphics library

	rts


¬2*****-> Insert the proper variables here... (Like WBVIEW, INTENA_SAVE, Etc.)¬1
Second:
¬3- Self Modifying code.¬1

I heard some coders use this sequence for VBL-interrupt setting:

Set_Myinterrupt:
	Move.l	$6c.w,Nextplease+2
	Lea	Myinterrupt,a0
	Move.l	a0,$6c.w
	Rts

Myinterrupt:
	Bsr	MyMusic
	Bsr	DoIt
Nextplease:
	Jmp	$00000000


¬2DONT DO THIS !!!¬1
The  Code-Cache on 68020,(and higher) sometimes still contains the 'JMP
$0000000'-instruction   when  executing  your  interrupt,  causing  the
computer to crash.

It  is  best  to use ADDINTSERVER, or something like that.  Still, I am
lazy  and use instead of the 'JMP $xxxxxxxx' at the end of my interrupt
a 'complete new' interrupt like this one:

NewIrq:
	Movem.l	d0-d7/a0-a6,-(sp)		;put registers on stack
	Lea	$dff000,a6
	Bsr	DoIt				;Do your stuff here..
	Move.w	#$4020,$9c(a6)			;clear interrupt request
	Movem.l	(sp)+,d0-d7/a0-a6		;get registers from stack
	Rte



Third:
¬3- Loop Timing¬1

As  of  now,  forget  about  timing  with  the processor.  Use vertical
blanking  or  cia-timing  instead,  because  small  loops  are speed up
incredably on amigas with code-cache.

	Move.l  #10000,d0
.Loop:	Dbf	D0,.Loop		; Runs a million times faster on
					; code-cached computers !!

For  those  of you who don't know how to time with the CIA's, here's an
example:  ¬2** NOT ** Written by me.¬1

;Timer A-delay
timer_DS:					;waits ca. 1/100 sec.
	move.b	#$00,$bfde00			;clear CRA
	move.b	#$7f,$bfdd00			;clear ICR
	move.b	#$20,$bfd500			;timer_DS a -high
	move.b	#$00,$bfd400			;timer_DS a -low
						;(wait-value=$2000)
	move.b	#$09,$bfde00			;set oneshot/start
wait_timer_DS:
	btst	#0,$bfdd00			;test ta-bit/that clears ICR
	beq.s	wait_timer_DS
	rts


Well,  I  think that is all for this time.  I don't think I have to say
that  you shouldn't use 'illegal'-routines, undocumented library-calls,
weird gfxbase-offsets, absolute code, code only for fast ram (A1200 has
only  2  MB  CHIP  standard!!),  Code_F,  Data_F, BSS_F hunks, Absolute
(de)crunchers  like Bytekiller or TRSI-Cruncher, or any of that ancient
stuff.

Greetings  from  Crew 01, at the moment CED'ing and listening to a cool
700Kb module, and still 1003054 bytes memory free !!  (A1200 rulez !!)

Contact me:	Crew One / Vicious
		Golfpark 140
		8241 AG Lelystad
		Holland

Or leave a message one of these BBS'S to Crew One:

Nasa Hq:            01803-20437
(Eclipse   BBS,  PD,  Really  Elite,  Running  2  Mhz  Amiga  500,  1Mb
Harddisk,and Paragon, Sysop is TEAK !!) (Hi Teak :-)

Mystical  Places:   010-4779507
(Former Desire and Alpha Flight BBS,now JUStICE EHQ, 16k4+ only, locked
on 38k8, Elite Only, Cool Coders Conference, Mad Sysop is THC !)
