/*
    Keyboard Sample

    COPYRIGHT (C) SEGA ENTERSRISES,LTD.

    Low Level Keyboard Sample fot Set5

    1998.7.5
*/

#include <shinobi.h>
#include <sg_pdkbd.h>

Sint32 gFrameCount;

void njUserInit(void)
{
    gFrameCount = 0;

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

Sint32 njUserMain(void)
{
    const PDS_KEYBOARD* kbd;

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

    kbd = pdKbdGetData(PDD_PORT_A0);

    if (kbd) {
        njPrint(NJM_LOCATION(2, 6),
                "%02X %02X %02X %02X %02X %02X %02X %02X",
                kbd->ctrl, kbd->led,
                kbd->key[0], kbd->key[1], kbd->key[2],
                kbd->key[3], kbd->key[4], kbd->key[5]);

        if (kbd->ctrl & PDD_KEY_CTRL_LGUI) {
            njPrintC(NJM_LOCATION(2, 8), "LEFT GUI");
        }
        if (kbd->ctrl & PDD_KEY_CTRL_LALT) {
            njPrintC(NJM_LOCATION(2, 9), "LEFT ALT");
        }
        if (kbd->ctrl & PDD_KEY_CTRL_LSHIFT) {
            njPrintC(NJM_LOCATION(2, 10), "LEFT SHIFT");
        }
        if (kbd->ctrl & PDD_KEY_CTRL_LCTRL) {
            njPrintC(NJM_LOCATION(2, 11), "LEFT CTRL");
        }
        if (kbd->ctrl & PDD_KEY_CTRL_RGUI) {
            njPrintC(NJM_LOCATION(14, 8), "RIGHT GUI");
        }
        if (kbd->ctrl & PDD_KEY_CTRL_RALT) {
            njPrintC(NJM_LOCATION(14, 9), "RIGHT ALT");
        }
        if (kbd->ctrl & PDD_KEY_CTRL_RSHIFT) {
            njPrintC(NJM_LOCATION(14, 10), "RIGHT SHIFT");
        }
        if (kbd->ctrl & PDD_KEY_CTRL_RCTRL) {
            njPrintC(NJM_LOCATION(14, 11), "RIGHT CTRL");
        }
    } else {
        njPrintC(NJM_LOCATION(2, 6), "CONNECT KEYBOARD TO PORT A");
    }

    return NJD_USER_CONTINUE;
}

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


