main.c++
3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*---------------------------------------------------------------------*
Copyright (C) 1998 Nintendo. (Originated by SGI)
$RCSfile: main.c++,v $
$Revision: 1.1.1.1 $
$Date: 2002/05/02 03:27:30 $
*---------------------------------------------------------------------*/
#define STACKSIZEBYTES 0x2000
#define DMA_QUEUE_SIZE 200
#define INIT_PRIORITY 10
#define GAME_PRIORITY 10
#include <ultratypes.h>
#include <os.h>
#include "main.h"
extern "C" {
void boot(void *argv);
void osInitializeCPP( u8 *base, s32 len );
};
/**** threads used by this file ****/
static OSThread gameThread;
static OSThread initThread;
/**** Stack for boot code. Space can be reused after 1st thread starts ****/
u64 bootStack[STACKSIZEBYTES/sizeof(u64)];
/**** Stacks for the threads, divide by 8 which is the size of a u64 ****/
static u64 gameThreadStack[STACKSIZEBYTES/sizeof(u64)];
static u64 initThreadStack[STACKSIZEBYTES/sizeof(u64)];
static u64 cppArena[STACKSIZEBYTES/sizeof(u64)];
/**** function prototypes for private functions in this file ****/
static void gameproc(void *);
static void initproc(char *);
/**** message queues and message buffers used by this app ****/
static OSMesg PiMessages[DMA_QUEUE_SIZE];
static OSMesgQueue PiMessageQ;
void boot(void *arg)
{
osInitialize();
osInitializeCPP((u8 *)cppArena, sizeof(cppArena));
osCreateThread(&initThread, 1, (void(*)(void *))initproc, arg,
(void *)(initThreadStack+(STACKSIZEBYTES/sizeof(u64))),
(OSPri)INIT_PRIORITY);
osStartThread(&initThread);
}
static void initproc(char *argv)
{
/**** Start PI Mgr for access to cartridge ****/
osCreatePiManager((OSPri) OS_PRIORITY_PIMGR, &PiMessageQ, PiMessages,
DMA_QUEUE_SIZE);
/**** Create the game thread and start it up ****/
osCreateThread(&gameThread, 6, gameproc, argv, gameThreadStack +
(STACKSIZEBYTES/sizeof(u64)), (OSPri)GAME_PRIORITY);
osStartThread(&gameThread);
/**** Set the thread to be the idle thread ****/
osSetThreadPri(0, 0);
for(;;);
}
void gameproc(void *)
{
osSyncPrintf("adsf\n"); // flush printf buffer???
Foo foo;
foo.Proc1(); // stack object
Bar *theBar = new Bar(); // heap object
theBar->Proc1();
delete theBar;
}
MyClass::MyClass()
{
i = 1;
j = 2;
osSyncPrintf("really\n");
osSyncPrintf("MyClass::MyClass() - 0x%x\n", this);
}
MyClass::~MyClass()
{
osSyncPrintf("MyClass::~MyClass() - 0x%x\n", this);
}
void MyClass::NotImp()
{}
//--------------------------------------------------
// Foo object
//--------------------------------------------------
Foo::Foo()
{
mc.i = 1;
osSyncPrintf("Foo::Foo() - 0x%x\n", this);
}
Foo::~Foo()
{
osSyncPrintf("Foo::~Foo() - 0x%x\n", this);
}
void Foo::Proc1()
{
osSyncPrintf("Foo::Proc1() - 0x%x\n", this);
}
void Foo::Proc2()
{
osSyncPrintf("Foo::Proc2() - 0x%x\n", this);
}
//--------------------------------------------------
// Bar object
//--------------------------------------------------
Bar::Bar()
{
osSyncPrintf("Bar::Bar() - 0x%x\n", this);
}
Bar::~Bar()
{
osSyncPrintf("Bar::~Bar() - 0x%x\n", this);
}
void Bar::Proc1()
{
osSyncPrintf("Bar::Proc1() - 0x%x\n", this);
}