~registry/dolphin-emu/triforce

« back to all changes in this revision

Viewing changes to Source/TestSuite/SI/source/dolphintest_si.cpp

  • Committer: Sérgio Benjamim
  • Date: 2015-02-13 05:54:40 UTC
  • Revision ID: sergio_br2@yahoo.com.br-20150213055440-ey2rt3sjpy27km78
Dolphin Triforce branch from code.google, commit b957980 (4.0-315).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <stdlib.h>
 
3
#include <string.h>
 
4
#include <malloc.h>
 
5
#include <ogcsys.h>
 
6
#include <gccore.h>
 
7
#include <iostream>
 
8
#include <iomanip>
 
9
#include <unistd.h>
 
10
#include <fat.h>
 
11
 
 
12
#ifdef HW_RVL
 
13
#include <wiiuse/wpad.h>
 
14
#include <sdcard/wiisd_io.h>
 
15
#endif
 
16
 
 
17
static void *xfb;
 
18
static GXRModeObj *rmode;
 
19
 
 
20
void Initialise();
 
21
void (*reboot)() = (void(*)())0x80001800;
 
22
static u32* const SI_REG = (u32*)0xCD006400;
 
23
static bool haveInit = false;
 
24
static int counter = 0;
 
25
static bool logWritten = false;
 
26
 
 
27
void AppendSDLog()
 
28
{
 
29
#ifdef HW_RVL
 
30
        FILE *f = fopen("sd:/si_log.txt", "a");
 
31
        if (f)
 
32
        {
 
33
                fprintf(f, "\n-------------------------------------\n");
 
34
                for (int i = 0; i < 4; i++)
 
35
                        fprintf(f, "%i\tstatus: %x\t type:%x\n", i, SI_GetStatus(i), SI_GetType(i));
 
36
                u32 x = 0;
 
37
                fprintf(f, "-------------------------------------\n");
 
38
                fprintf(f, "SI_CHANNEL_0_OUT\t%08x\n", SI_REG[x++]);
 
39
                fprintf(f, "SI_CHANNEL_0_IN_HI\t%08x\n", SI_REG[x++]);
 
40
                fprintf(f, "SI_CHANNEL_0_IN_LO\t%08x\n", SI_REG[x++]);
 
41
                fprintf(f, "SI_CHANNEL_1_OUT\t%08x\n", SI_REG[x++]);
 
42
                fprintf(f, "SI_CHANNEL_1_IN_HI\t%08x\n", SI_REG[x++]);
 
43
                fprintf(f, "SI_CHANNEL_1_IN_LO\t%08x\n", SI_REG[x++]);
 
44
                fprintf(f, "SI_CHANNEL_2_OUT\t%08x\n", SI_REG[x++]);
 
45
                fprintf(f, "SI_CHANNEL_2_IN_HI\t%08x\n", SI_REG[x++]);
 
46
                fprintf(f, "SI_CHANNEL_2_IN_LO\t%08x\n", SI_REG[x++]);
 
47
                fprintf(f, "SI_CHANNEL_3_OUT\t%08x\n", SI_REG[x++]);
 
48
                fprintf(f, "SI_CHANNEL_3_IN_HI\t%08x\n", SI_REG[x++]);
 
49
                fprintf(f, "SI_CHANNEL_3_IN_LO\t%08x\n", SI_REG[x++]);
 
50
                fprintf(f, "SI_POLL\t\t\t%08x\n", SI_REG[x++]);
 
51
                fprintf(f, "SI_COM_CSR\t\t\t%08x\n", SI_REG[x++]);
 
52
                fprintf(f, "SI_STATUS_REG\t\t%08x\n", SI_REG[x++]);
 
53
                fprintf(f, "SI_EXI_CLOCK_COUNT\t%08x\n", SI_REG[x++]);
 
54
                fprintf(f, "-------------------------------------\n");
 
55
                fclose(f);
 
56
        }
 
57
#endif
 
58
}
 
59
 
 
60
int main(int argc, char **argv)
 
61
{
 
62
        Initialise();
 
63
 
 
64
        while(1) {
 
65
                if (haveInit) PAD_ScanPads();
 
66
 
 
67
                VIDEO_ClearFrameBuffer(rmode, xfb, COLOR_BLACK);
 
68
 
 
69
                printf("\x1b[4;0H");
 
70
 
 
71
                for(int Chan = 0; Chan < 4; Chan++)
 
72
                        printf("%i\tstatus: %x\t type:%x\n", Chan, SI_GetStatus(Chan), SI_GetType(Chan));
 
73
 
 
74
                printf("SI Regs: (cc006000)\n");
 
75
                for (u32 i = 0; i < 16/*num SI regs*/; ++i)
 
76
                {
 
77
                        printf("%08x ", SI_REG[i]);
 
78
                        if ((i+1)%8==0) printf("\n");
 
79
                }
 
80
 
 
81
                if (haveInit)
 
82
                        printf("\nPAD_Init\n");
 
83
 
 
84
                VIDEO_WaitVSync();
 
85
 
 
86
                if (haveInit)
 
87
                {
 
88
                        if (PAD_ButtonsDown(0) & PAD_BUTTON_START)
 
89
                        {
 
90
                                AppendSDLog();
 
91
                        #ifdef HW_RVL
 
92
                                fatUnmount("sd");
 
93
                                __io_wiisd.shutdown();
 
94
                        #endif
 
95
                                reboot();
 
96
                        }
 
97
                }
 
98
 
 
99
                counter++;
 
100
                AppendSDLog();
 
101
                if (counter > 5 && !haveInit)
 
102
                {
 
103
                        PAD_Init();
 
104
                        haveInit = true;
 
105
                }
 
106
                else if (haveInit && !logWritten)
 
107
                {
 
108
                        logWritten = true;
 
109
                }
 
110
        }
 
111
 
 
112
        return 0;
 
113
}
 
114
 
 
115
void Initialise()
 
116
{
 
117
        // Initialise the video system
 
118
        VIDEO_Init();
 
119
 
 
120
        // Obtain the preferred video mode from the system
 
121
        // This will correspond to the settings in the Wii menu
 
122
        rmode = VIDEO_GetPreferredMode(NULL);
 
123
 
 
124
        // Allocate memory for the display in the uncached region
 
125
        xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
 
126
 
 
127
        // Initialise the console, required for printf
 
128
        console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
 
129
 
 
130
        // Set up the video registers with the chosen mode
 
131
        VIDEO_Configure(rmode);
 
132
 
 
133
        // Tell the video hardware where our display memory is
 
134
        VIDEO_SetNextFramebuffer(xfb);
 
135
 
 
136
        // Make the display visible
 
137
        VIDEO_SetBlack(FALSE);
 
138
 
 
139
        // Flush the video register changes to the hardware
 
140
        VIDEO_Flush();
 
141
 
 
142
        // Wait for Video setup to complete
 
143
        VIDEO_WaitVSync();
 
144
        if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
 
145
 
 
146
#ifdef HW_RVL
 
147
        // Initialize FAT so we can write to SD.
 
148
        __io_wiisd.startup();
 
149
        fatMountSimple("sd", &__io_wiisd);
 
150
#endif
 
151
}