/*
 *               Copyright (C) 2005, BroadOn Communications Corp.
 *
 *  These coded instructions, statements, and computer programs contain
 *  unpublished proprietary information of BroadOn Communications Corp.,
 *  and are protected by federal copyright law. They may not be disclosed
 *  to third parties or copied or duplicated in any form, in whole or in
 *  part, without the prior written consent of BroadOn Communications Corp.
 *
 */


#include <types.h>
#include <sc/sc.h>
#include <sc/dv_boot.h>
#include <ioslibc.h>

#define WHITE    8
#define ORANGE   9
#define RED     10
#define BLUE    11
#define YELLOW  12
#define GREEN   13
#define PURPLE  14

void
#define MAX_WIDTH 30
gbaprint(u8 x, u8 y, u8 color, char *s)
{
    int i;
    printf("Attempting to print: %s\n", s);
    while (*s) {
        u32 val = (x << 24) | (y << 16) | (color << 8) | *s;
        //printf("spin");
        while (!(IO_READ(IPC_CTRL_REG) & IPC_CTRL_IN_ACK));
        /* Delay for a bit */
        for (i = 0; i < 8; ++i) {
            IO_READ(IPC_CTRL_REG);
        }

        /* Send out msg and clear ack */
        IO_WRITE(IPC_OUT_REG, val);
        IO_WRITE(IPC_CTRL_REG, IPC_CTRL_IN_ACK|IPC_CTRL_OUT_MSG);
        s++;
        if (++x >= MAX_WIDTH) {
            x = 0;
            ++y;
        }
    }
}

int
cpu0main(void)
{
    int         rc = 0;

    printf("GBA Print\n");

    IO_WRITE(ROM_CFG1_REG, IO_READ(ROM_CFG1_REG) | ROM_CFG1_IPC_EN);
    gbaprint(0, 2, RED, "Now is the time for all good men to come to the aid of their country.");
    gbaprint(0, 7, BLUE, "The quick brown fox jumped over the lazy dog.");

    return (rc);
}


int cpu1main(void)
{
    int         rc = 0;

    return (rc);
}
