ipl4.h 7.61 KB
/********************************************************************************
	ipl4.h: NINTENDO64 Disk Drive IPL4 header.

	February 4, 1987
 ********************************************************************************/

#ifndef IPL4_H
#define	IPL4_H

#include "buffer.h"


#ifdef _LANGUAGE_C

#define	Align128(n)				(((uint)(n)+15)&0xfffffff0)
#define	Align64(n)				(((uint)(n)+ 7)&0xfffffff8)
#define	Align32(n)				(((uint)(n)+ 3)&0xfffffffc)
#define	Align16(n)				(((uint)(n)+ 1)&0xfffffffe)

typedef	unsigned char		uchar;
typedef	unsigned short		ushort;
typedef unsigned int		uint;
typedef	unsigned long		ulong;
typedef	unsigned long long	uwlong;
typedef signed   long long	wlong;

typedef union {
	long	word;
	short	half[2];
	char	byte[4];
} SPacked;


/********************************************************************************/
/*																				*/
/*																				*/
/*	Drive ROM data																*/
/*																				*/
/*																				*/
/********************************************************************************/

#define	FONTDATA_ROMADDR	0x0A0000
#define	WAVEDATA_ROMADDR	0x140000


/********************************************************************************/
/*																				*/
/*																				*/
/*	Thread ID and thread priority												*/
/*																				*/
/*																				*/
/********************************************************************************/

#define	IDLE_THREAD_ID		1
#define	MAIN_THREAD_ID		2
#define	GRPH_THREAD_ID		3
#define	DISK_THREAD_ID		4

#define	BOOT_PRIORITY		20
#define MAIN_PRIORITY		10
#define DISK_PRIORITY		11
#define GRPH_PRIORITY		12


/********************************************************************************/
/*																				*/
/*																				*/
/*	OS messages																	*/
/*																				*/
/*																				*/
/********************************************************************************/

#define MESG_GRPH_STOPGFX		((OSMesg)100)
#define	MESG_GRPH_RESTART		((OSMesg)101)
#define	MESG_GRPH_PRENMI		((OSMesg)102)

#define MESG_GRPH_RETRACE		((OSMesg)110)
#define MESG_GRPH_RSPDONE		((OSMesg)111)
#define MESG_GRPH_RDPDONE		((OSMesg)112)
#define MESG_GRPH_SIMDONE		((OSMesg)113)


#define MESG_MAIN_LOADDONE		((OSMesg)200)
#define MESG_MAIN_GRPHDONE		((OSMesg)201)


#define	MESG_DISK_START			((OSMesg)300)
#define	MESG_DISK_HANGUP		((OSMesg)301)


#define NUM_PIMG_MESGS		16
#define NUM_MAIN_MESGS		 1
#define NUM_GRPH_MESGS		 4
#define NUM_DISK_MESGS		 1

extern OSMesgQueue	mainMesgque;			/* main thread message queue		*/
extern OSMesgQueue	grphMesgque;			/* graphics thread message queue	*/
extern OSMesgQueue	diskMesgque;			/* disk drive thread message queue	*/
extern OSMesgQueue	PimgMesgque;			/* PI manager message queue			*/


/********************************************************************************/
/*																				*/
/*	IPL Header record															*/
/*																				*/
/*	This is the structure that should be placed on the system area				*/
/*	of the disk. This structure will probably change. For example,				*/
/*	should we use nbytes or nblocks?											*/
/*																				*/
/********************************************************************************/

typedef struct IPLHeader {
	void *		location;			/* copy from disk to this location			*/
	void *		entry;				/* entry point of program					*/
	long		skip;				/* number of bytes on disk to skip			*/
	long		nbytes;				/* number of bytes to copy from disk		*/
	long		nblocks;			/* number of logical blocks to copy			*/
	long		firstlba;			/* where program resides on disk			*/
} IPLHeader;

extern IPLHeader bootHeader;


/********************************************************************************/
/*																				*/
/*																				*/
/*	Disk Drive clock															*/
/*																				*/
/*																				*/
/********************************************************************************/

#define	CLOCK_STAT_INACTIVE		0
#define	CLOCK_STAT_ACTIVE		1

typedef struct DDClock {
	uchar		year;
	uchar		month;
	uchar		day;
	uchar		hour;
	uchar		minute;
	uchar		second;
	ushort		status;
} DDClock;

extern DDClock diskClock;


/********************************************************************************/
/*																				*/
/*																				*/
/*	Disk status																	*/
/*																				*/
/*																				*/
/********************************************************************************/

typedef enum DiskStatus {
	DISK_STAT_WAITING,
	DISK_STAT_WORKING,
	DISK_STAT_LOADING,
	DISK_STAT_LOADEND,
	DISK_STAT_NODISK,
	DISK_STAT_NOCONNECT,
	DISK_STAT_BADINSERT,
	DISK_STAT_DISKEJECT,
	DISK_STAT_DISKERROR
} DiskStatus;

extern DiskStatus diskStatus;


/********************************************************************************/
/*																				*/
/*																				*/
/*	Error message																*/
/*																				*/
/*																				*/
/********************************************************************************/

#define	ERRMSG_KINDMASK			0xFF00
#define	ERRMSG_NUMMASK			0x00FF

#define	ERRMSG_NOERROR			0x0000
#define	ERRMSG_NORAMPACK		0x0100
#define	ERRMSG_NOCONNECT		0x0200
#define	ERRMSG_BADINSERT		0x0300
#define	ERRMSG_DISKEJECT		0x0400
#define	ERRMSG_DISKERROR		0x0500
#define	ERRMSG_CLOCKSTOP		0x0600


/********************************************************************************/
/*																				*/
/*																				*/
/*	Main thread status															*/
/*																				*/
/*																				*/
/********************************************************************************/

#define	MAIN_STAT_LOADDONE		0x0001
#define	MAIN_STAT_GRPHDONE		0x0002


/********************************************************************************/
/*																				*/
/*																				*/
/*	Global variables															*/
/*																				*/
/*																				*/
/********************************************************************************/

extern int		diskErrorNo;
extern int		memoryPack;

extern int 		clockSetting;
extern int		systemReset;
extern ulong	frameCounter;


/********************************************************************************/
/*																				*/
/*																				*/
/*	Disk routines																*/
/*																				*/
/*																				*/
/********************************************************************************/

extern void DiskProcess(void *arg);
extern void ResetDiskDriver(void);
extern void WriteDDClock(DDClock *time);

extern void BootDiskImage(IPLHeader *header);
extern void FinalBoot(void *);


/********************************************************************************/
/*																				*/
/*	Graphics routines															*/
/*																				*/
/********************************************************************************/

extern char *AllocDynamic(long size);
extern void SetClearColor(uchar red, uchar green, uchar blue);
extern void GrphProcess(void *arg);

extern int  DisplayGraphics(OSMesg event);
extern void	InitErrorMessage(void);
extern void DrawErrorMessage(int status);


extern char _CodeSegmentEnd[];
extern char _FontSegmentRomStart[];
extern char _ShapeSegmentRomStart[];
extern char _ShapeSegmentRomEnd[];

extern uwlong	frameBuffer[2][FRAMEBUFF_SIZE64];
extern uwlong	depthBuffer[FRAMEBUFF_SIZE64];

extern uwlong	rspDramStack[SP_DRAM_STACK_SIZE64];			/* RSP DRAM stack			*/
extern uwlong	rspFifoBuffer[SP_FIFO_SIZE64];

extern uwlong	dynamicMemory[2][DYNAMIC_SIZE64];

/* EPI routine  */
extern long osPiStartDma_DriveRomOnly(OSIoMesg *IOMesg, long prio, long dir, ulong romStart, void *ramAddr, ulong size, OSMesgQueue *mesgque);

#endif
#endif