*******************************************************************
* Short example of disabling of operating system for games, etc.  *
* Disables system, changes the background colours a bit and then  *
* enables system.						  *	
* Disables the operating system by disabling ALL interrupts and   *
* DMA. This method based on Bullfrog game code supplied with      *
* Amiga Format Issues 39-43.				          *		
* Uses VPOS wait loop described by Jolyon Ralph in the Machine    *
* Code column in Amiga Computing 1990.				  *	
* Written by James Margitich, 10th of April 1993.                 *
*******************************************************************

INTENAR equ $dff01c
DMACONR equ $dff002

INTENA equ $dff09a
DMACON equ $dff096
INTREQ equ $dff09c

VPOSR equ $dff004
COLOUR0 equ $dff180


	move.w  INTENAR,old_intena	;save interrupt status
	move.w  DMACONR,old_dmacon	;save dma status
	movem.l	d0-d7/a0-a6,-(sp)	;save registers on the stack
	move.w	#%0011111111111111,INTENA	;disable interrupts
	move.w	#%0000000111111111,DMACON	;disable dma
	move.w	#$7fff,INTREQ		;take care of current interrupts	
;Here be where the body of the program begins. Feel free to delete it and 
;replace with your own code and rename this file accordingly.
	move.l	#0,d0			;Set loop counter to zero
	move.l	#0,d1			;Set colour counter to zero
	move.w	#$3,d2			;Set colour to $003
loop
	move.w	d2,COLOUR0		;Set background colour
	move.l	VPOSR,d3		;get beam position
	and.l	#%11111111100000000,d3	;Only want vertical component
	lsr.l	#8,d3			;Move it to lower byte
	cmp.w	#305,d3			;Are we at the bottom of the screen?
	bne.s	loop			;If not, loop back now
	cmp.l	#250,d0			;Is loop counter at 250 (50vbi)?
	bne	.samecolour
	cmp.l	#6,d1			;Is colour counter 6?
	beq 	.allfinished		;If so, finish up.
	add.w	#$2,d2			;Increase colour no. by $002
	move.l	#0,d0			;reset loop counter
	add.l	#1,d1			;Increment colour counter	
	bra.s	loop			;Just reset counter, remember?
.samecolour
	add.l	#1,d0			;Increment loop counter
.fullframe
	move.l	VPOSR,d3		;get beam position
	and.l	#%11111111100000000,d3	;Only want vertical component
	lsr.l	#8,d3			;Move it to lower byte
	cmp.w	#305,d3			;Are we on next frame?
	bge	.fullframe       	;If not, wait until we are
	bra.s	loop			;Loop back
.allfinished
;Here be where the main program ends. 
	move.w	old_intena,d0
	or.w	#$8000,d0
	move.w	d0,INTENA
	move.w	old_dmacon,d0
	or.w	#$8000,d0
	move.w	d0,DMACON
	movem.l	(sp)+,d0-d7/a0-a6	;restore registers
	rts         

old_intena	dc.w	0
old_dmacon	dc.w	0
