#include <ios.h>
#include <hw.h>
#include <iostypes.h>
#include <ioslibc.h>

#define STACK_SIZE 1024
const u8 _initStack[STACK_SIZE];
const u32 _initStackSize = sizeof(_initStack);
const u32 _initPriority = 10;

static u32 isDI = 0;

static void 
tstmsg(IOSError rv1, IOSError rv2, char *s)
{
    if (isDI) {
        if (rv1 < 0) {
            printf("DI process: Set %s -> 1 FAILED: %d\n", s, rv1);
            
        } else {
            printf("DI process: Set %s -> 1 PASSED\n", s);
        }
        if (rv2 < 0) {
            printf("DI process: Set %s -> 0 FAILED: %d\n", s, rv2);
        } else {
            printf("DI process: Set %s -> 0 PASSED\n", s);
        }

    } else {
        if (rv1 != IOS_ERROR_ACCESS) {
            printf("non-DI process: Set %s -> 1 FAILED: %d\n", s, rv1);
        } else {
            printf("non-DI process: Set %s -> 1 refused: PASSED\n", s);
        }
        if (rv2 != IOS_ERROR_ACCESS) {
            printf("non-DI process: Set %s -> 0 FAILED: %d\n", s, rv2);
        } else {
            printf("non-DI process: Set %s -> 0 refused: PASSED\n", s);
        }
    }
} 

void 
test_setgetAHBPI2DI(void)
{
    IOSError rv1, rv2;
    u32 val = IOS_GetEnableAHBPI2DI();
    rv1 = IOS_SetEnableAHBPI2DI(1);
    rv2 = IOS_SetEnableAHBPI2DI(0);
    IOS_SetEnableAHBPI2DI(val); /* try to restore */
    tstmsg(rv1, rv2, "EnableAHBPI2DI");
}

void 
test_setgetDvdReadDisable(void)
{
    IOSError rv1, rv2;
    u32 val = IOS_GetDvdReadDisable();
    rv1 = IOS_SetDvdReadDisable(1);
    rv2 = IOS_SetDvdReadDisable(0);
    IOS_SetDvdReadDisable(val); /* try to restore */
    tstmsg(rv1, rv2, "DvdReadDisable");
}

void
main(u32 arg)
{ 
    isDI = (IOS_DI_PROCESS == IOS_GetProcessId())? 1 : 0;
    test_setgetDvdReadDisable();
    test_setgetAHBPI2DI();
}
