;*======================================================================*
;*                TITLE:                  SKELETON.S                    *
;*                Function:               Video Setup Stub              *
;*                                                                      *
;*                Project #:              JAGUAR                        *
;*                Programmer:             Rob Zdybel                    *
;*                                                                      *
;*              COPYRIGHT 1993 Atari Computer Corporation               *
;*          UNATHORIZED REPRODUCTION, ADAPTATION, DISTRIBUTION,         *
;*          PERFORMANCE OR DISPLAY OF THIS COMPUTER PROGRAM OR          *
;*        THE ASSOCIATED AUDIOVISUAL WORK IS STRICTLY PROHIBITED.       *
;*                            ALL RIGHTS RESERVED.                      *
;*                                                                      *
;*======================================================================*

BASE		EQU	$00D00000	;* 68000 GPU register base address

	include "jaguar.inc"
	include "blit.inc"

;
;	EXTERNAL SYMBOLS
;
	.extern	make_olist
	.extern	vblank
	.extern	vidinit
	.extern	waitsync

	.extern	framecnt

;
;	PUBLIC SYMBOLS
;
	.globl	disp_ptr
	.globl	draw_ptr
	.globl	DISPBUF1


;
;	USEFUL DEFINES
;
BUFFERSIZE	EQU	(320*200*2)	; screen 320 X 200 in 16.16 color mode
DISPBUF1	EQU	ENDRAM-BUFFERSIZE
DISPBUF0	EQU	DISPBUF1-BUFFERSIZE

OFF68K		EQU	$900000
RAMSIZE		EQU	$1000		; 4K bytes
GPUPROG		EQU	G_RAM-OFF68K	; from the GPU's eye
INPUT6		EQU	G_ENDRAM-$4	; pointer to parameter 6 for GPU
INPUT5		EQU	INPUT6-$4	; pointer to parameter 5 for GPU
INPUT4		EQU	INPUT5-$4	; pointer to parameter 4 for GPU
INPUT3		EQU	INPUT4-$4	; pointer to parameter 3 for GPU
INPUT2		EQU	INPUT3-$4	; pointer to parameter 2 for GPU
INPUT1		EQU	INPUT2-$4	; pointer to parameter 1 for GPU

;
;	LOCAL MACROS
;
.macro	LONGALIGN	addr
	addq.l	#3,\addr		; make sure the address will remain
	andi.l	#$FFFFFFFC,\addr	; within the buffer area
.endm

;
;	PROGRAM SEGMENT
;
	.text

main:
	move.l	#$b000,sp	; **KLUDGE** Init the stack

	jsr	initialize	; initialize the system

loop:
	move.l	disp_ptr,d0
	move.l	draw_ptr,disp_ptr
	move.l	d0,draw_ptr	; Swap buffers

	jsr	waitsync	; Wait for video sync

	bra	loop		; UNTIL (Eternity)

stop:
	illegal			; **KLUDGE** FORCE EXIT TO ADB
	nop


;
;	SUBROUTINE AREA
;

;
;	INITIALIZE   Initialize the system
;
;	Given:
;		Control
;
;	Returns:
;		320x200 Double-Buffered Video Enabled
;
;	Register Usage:
;		All Registers Restored
;
;	Externals:
;		VIDINIT, MAKE_OLIST
;
initialize:
	move.l	d0,-(sp)

	jsr	vidinit		; Initialize 320x200 NTSC Video

	move.w	MEMCON1,d0
	or	#$60,d0
	move.w	d0,MEMCON1	; Enable fast DRAM

	move.l	#$00020002,G_BIGEND	; Run GPU in Intel I/O mode, Motorola Pixel Mode

	jsr	make_olist	; Initialize Object List to single 320x200 Object

	move.l	#DISPBUF1,disp_ptr
	move.l	#DISPBUF0,draw_ptr	; Initialize Double-Buffer Ptrs

	move.l	#vblank,LEVEL2	; Capture VBLANK Interrupt
	move.w	#451,VI		; (must be ODD)
	move.w	#1,INT1
	move.w	sr,d0
	and.w	#$f8ff,d0
	move.w	d0,sr		; Enable Interrupt

	move.w	#$C1,VMODE	; Turn on the display

	move.l	(sp)+,d0
	rts

;
;	VARIABLE RAM
;
	.bss
	.even

disp_ptr:		; Display buffer ptr
	.ds.l	1
draw_ptr:		; Draw buffer ptr
	.ds.l	1

;
;	CONSTANT DATA
;
	.data
	.even

liteModel:
	.dc.w	$40		;* Ambient:	Intensity
	.dc.w	$80FF		;* InScene:	Intensity
	.dc.w	$e000		;*		Vector	X component
	.dc.w	$0000		;*			Y
	.dc.w	$0000		;*			Z
	.dc.w	$FF		;* Sunlight:	Intensity
	.dc.w	$0000		;*		Vector	X component
	.dc.w	$4000		;*			Y
	.dc.w	$0000		;*			Z
	.dc.w	$0000		;* InScene:	(0000 = End of list)

;*======================================================================*
;*                                 EOF                                  *
;*======================================================================*
