/* loader.h
 * loader defines and structures;
 */

#ifndef	__NCLD_H__
#define	__NCLD_H__

#include <nitro.h>
#include <nitro/types.h>

// define DEBUG for more verbosity;

#define	DEBUG		// debug messages;

// NC IPC defines;

#define	IPC_BASE 		(HW_CTRDG_ROM)
#define	IPC_BUF 		(HW_CTRDG_ROM + 16384 - 256)
#define	IPC_REGS		(IPC_BASE + 0x01fffff0)

#define	IPC_OUT_L_REG	(IPC_REGS + 0x0)
#define	IPC_OUT_H_REG	(IPC_REGS + 0x2)
#define	IPC_IN_L_REG	(IPC_REGS + 0x4)
#define	IPC_IN_H_REG	(IPC_REGS + 0x6)
#define	IPC_CTRL_REG	(IPC_REGS + 0x8)

#define	IPC_CTRL_IN_ACK_MASK	0x0008
#define	IPC_CTRL_OUT_MSG_MASK	0x0001

// IOS request structure;
// copy here instead of referring to sk source;

typedef union {
	u8 key[16];			// aes key;
	u32 rom_base;		// ptr to ds rom;
} IOSResourceDs;		// max 20 bytes;

typedef struct {
	u32 cmd;
	u32 status;
	u32 handle;
	IOSResourceDs ds;
} IOSResourceRequest;

#define	IOS_ERROR_OK	0
#define	IOS_REPLY	8
#define	IOS_DSMODE	9

// launch code;

void Launch(u32 base);

// font structures;

extern const u32 d_CharData[8*256];
extern const u32 d_PaletteData[8*16];

// gui api;

extern void guiInit(void);
extern void guiClearScreen(void);
extern void guiPrintf(u16 x, u16 y, u8 palette, char *fmt, ...);
extern void guiPanic(u32 code);

#ifdef	DEBUG
#define	guiDebug	guiPrintf
#else	// DEBUG
#define	guiDebug
#endif	// DEBUG

// gui error codes;

#define	NCLD_UNSPEC			0	// unknown error;
#define	NCLD_NO_NC			1	// no NC card detected;
#define	NCLD_NC_PULLED		2	// NC card has been removed;
#define	NCLD_DS_PULLED		3	// DS card has been removed;
#define	NCLD_IPC_NOT_READY		4	// nc ipc not ready;
#define	NCLD_IPC_NO_REPLY		5	// no/bad nc ipc reply;
#define	NCLD_BAD_LAUNCH		6	// launch check failed;

// gui colors;

#define	GUI_BLACK		0
#define	GUI_RED			1
#define	GUI_GREEN		2
#define	GUI_BLUE		3
#define	GUI_YELLOW		4
#define	GUI_PURPLE		5
#define	GUI_LIGHT_BLUE	6
#define	GUI_DARK_RED	7
#define	GUI_DARK_GREEN	8
#define	GUI_DARK_BLUE	9
#define	GUI_DARK_YELLOW	10
#define	GUI_DARK_PURPLE	11
#define	GUI_BLUE2		12
#define	GUI_GRAY		13
#define	GUI_DARK_GREY	14
#define	GUI_WHITE		15

#endif	/* __NCLD_H__ */
