#include <shinobi.h>
#include <kamui2.h>
#include <km2util.h>
#include <string.h>
#include "dispstrex.h"
#include "command.h"

void MemCommand(int argc, char *argv[])
{
	Uint32 wholeFreeSize, biggestFreeBlockSize;
	KMSTATUS status;
	KMUINT32 FreeTexSize, MaxBlockSize;

	syMallocStat(&wholeFreeSize, &biggestFreeBlockSize);
	kmGetFreeTextureMem(&FreeTexSize, &MaxBlockSize);

	if(strcmp(argv[1], "-H") == 0 || strcmp(argv[1], "-h") == 0)
	{
		PRINTOUT(("Memory Free Area Information Display\n"));
		PRINTOUT(("mem [-hex]\n"));
		PRINTOUT(("-hex : Hexadecimal Information\n"));
		return;
	}

	PRINTOUT(("[System Memory]\n"));
	if(strcmp(argv[1], "-Hex") == 0 || strcmp(argv[1], "-hex") == 0)
	{
		PRINTOUT(("Free SH4 Mem = %8X[bytes]\n", wholeFreeSize));
		PRINTOUT(("MaxBlockSize = %8X[bytes]\n", biggestFreeBlockSize));
	}
	else
	{
		PRINTOUT(("Free SH4 Mem = %d[bytes]\n", wholeFreeSize));
		PRINTOUT(("MaxBlockSize = %d[bytes]\n", biggestFreeBlockSize));
	}

	PRINTOUT(("[Texture Memory]\n"));
	if(strcmp(argv[1], "-Hex") == 0 || strcmp(argv[1], "-hex") == 0)
	{
		PRINTOUT(("Free TextMem = %8X[bytes]\n", FreeTexSize));
		PRINTOUT(("MaxBlockSize = %8X[bytes]\n", MaxBlockSize));
	}
	else
	{
		PRINTOUT(("Free TextMem = %d[bytes]\n", FreeTexSize));
		PRINTOUT(("MaxBlockSize = %d[bytes]\n", MaxBlockSize));
	}
}

void TimeCommand(int argc, char *argv[])
{
	SYS_RTC_DATE date;
#if 0
    Uint16 year;                   /* year:        1950...2085            */
    Uint8  month;                  /* month:       1...12                 */
    Uint8  day;                    /* day:         1...31                 */
    Uint8  hour;                   /* hour:        0...23                 */
    Uint8  minute;                 /* minute:      0...59                 */
    Uint8  second;                 /* second:      0...59                 */
    Uint8  dayofweek;              /* day of week: 0(Sunday)...6(Saturday)*/
    Uint8  ageofmoon;              /* age of the moon: 0(new moon)...15(full moon)...29 */
#endif
	syRtcGetDate( &date );
	PRINTOUT(("Date %d / %d / %d\n", date.year, date.month, date.day));
	PRINTOUT(("Time %d : %d : %d  ", date.hour, date.minute, date.second));
	switch(date.dayofweek)
	{
		case 0:
			PRINTOUT(("Sunday\n")); break;
		case 1:
			PRINTOUT(("Monday\n")); break;
		case 2:
			PRINTOUT(("Tuesday\n")); break;
		case 3:
			PRINTOUT(("Wednesday\n")); break;
		case 4:
			PRINTOUT(("Thursday\n")); break;
		case 5:
			PRINTOUT(("Friday\n")); break;
		case 6:
			PRINTOUT(("Saturday\n")); break;
	}
}

void ExitCommand(int argc, char *argv[])
{
	sbExitSystem();
	syBtExit();
}
void InitMemCommand(void)
{
	RegisterCommand(MemCommand, NULL, NULL, "mem", PROCESSTYPE_WO_DRAW);	/* Draw Command は無し */
	RegisterCommand(TimeCommand, NULL, NULL, "date", PROCESSTYPE_WO_DRAW);	/* Draw Command は無し */
	RegisterCommand(ExitCommand, NULL, NULL, "exit", PROCESSTYPE_WO_DRAW);	/* Draw Command は無し */
}