/*
    Ninja Sample

    COPYRIGHT (C) SEGA ENTERSRISES,LTD.

    Backup Sample #1 for SET5

    1998.7.28
*/

#include <shinobi.h>
#include "backup.h"

Sint32 gFrameCount;

void DispBackupRAMInfo(Sint32 x, Sint32 y, Sint32 drive);

void njUserInit(void)
{
    gFrameCount = 0;

    njSetBorderColor( 0 ) ;
    sbInitSystem(NJD_RESOLUTION_320x240_NTSCNI, NJD_FRAMEBUFFER_MODE_RGB565, 1);
    njInitVertexBuffer(10000, 0, 100000, 0, 0);
    njInitPrint(NULL,0,0) ;
    njSetBackColor(0x00000000, 0x00000000, 0x0000C060);

    BupInit();
}

Sint32 njUserMain(void)
{
    Sint32 drive;
    Sint32 x, y;

    njPrintC(NJM_LOCATION(2, 2), "BACKUP SAMPLE #1");
    njPrintH(NJM_LOCATION(30, 2), gFrameCount++, 8);

    x = 2;
    y = 2;
    for (drive = 0; drive < 8; drive++) {
        y = drive * 2 + 6;
        DispBackupRAMInfo(x, y, drive);
    }

    return NJD_USER_CONTINUE;
}

void njUserExit(void)
{
    BupExit();
    njExitPrint();
    sbExitSystem();
}


/*===============================================================*/
/* バックアップRAMの状態を表示する                               */
/* 接続されていなければ「---」を、フォーマットされていなければ   */
/* 「UNFORMAT」を、フォーマットされている場合は空き容量と最大    */
/* 容量を表示します。                                            */
/*===============================================================*/

void DispBackupRAMInfo(Sint32 x, Sint32 y, Sint32 drive)
{
    const BACKUPINFO* binfo;
    BUS_DISKINFO* diskinfo;

    binfo = BupGetInfo(drive);
    diskinfo = &binfo->DiskInfo;

    njPrint(NJM_LOCATION(x, y), "MEMORY CARD #%d",drive);

    if (binfo->Ready) {
        if (binfo->IsFormat) {
            njPrint(NJM_LOCATION(x + 15, y), "%04d/%04d BLOCKS",
                diskinfo->free_user_blocks,
                diskinfo->total_user_blocks);
        } else {
            njPrint(NJM_LOCATION(x + 15, y), "UNFORMAT        ");
        }
    } else {
        if (binfo->Operation == BUD_OP_MOUNT) {
            njPrint(NJM_LOCATION(x + 15, y), "CHECKING...     ");
        } else {
            njPrint(NJM_LOCATION(x + 15, y), "----------------");
        }
    }
}

