main.c
4.5 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
148
149
150
151
/*---------------------------------------------------------------------
Copyright (C) 1998 Nintendo.
File main.c
Coded by Koji Mitsunari. Apr 30, 1998.
Modified by Koji Mitsunari. Oct 27, 1998.
Comments 64GB-PAK test program main
$Id:
---------------------------------------------------------------------*/
#include <ultra64.h>
#include "nu64sys.h"
#include "main.h"
#include "siproc.h" /* siproc用 */
#include "graph.h" /* 画面表示用 */
u8 gb_id[OS_GBPAK_ROM_ID_SIZE]; /* GB の ROMの登録エリア */
u8 buffer[DATA_SIZE]; /* データ読み込み用バッファ */
static OSMesg siMsgBuf[SI_MSG_NUM];
static OSThread siThread;
static u64 siStack[STACKSIZE/sizeof(u64)];
static SiMsg siMsg;
OSMesgQueue siMsgQ;
/*---------------------------------------------------------------------
エラーメッセージの画面表示
---------------------------------------------------------------------*/
void
PrintErrorMessage(s32 errmes) {
u16 *p = (u16 *)osViGetNextFramebuffer();
switch(errmes) {
case GBPAK_ERR_MES_NOPACK:
printmes(p, ERR_X, ERR_Y1, WHITE, mes0);
printmes(p, ERR_X, ERR_Y2, WHITE, mes1);
printmes(p, ERR_X, ERR_Y3, WHITE, mes2);
break;
case GBPAK_ERR_MES_ERR_DEVICE:
printmes(p, ERR_X, ERR_Y1, WHITE, mes4);
printmes(p, ERR_X, ERR_Y2, WHITE, mes5);
printmes(p, ERR_X, ERR_Y3, WHITE, mes6);
break;
case GBPAK_ERR_MES_FAIL:
printmes(p, ERR_X, ERR_Y1, WHITE, mes7);
printmes(p, ERR_X, ERR_Y2, WHITE, mes8);
printmes(p, ERR_X, ERR_Y3, WHITE, mes9);
break;
case GBPAK_ERR_MES_NOCART:
printmes(p, ERR_X, ERR_Y1, WHITE, mes10);
printmes(p, ERR_X, ERR_Y2, WHITE, mes11);
break;
case GBPAK_ERR_MES_ANOTHER_GAME:
printmes(p, ERR_X, ERR_Y1, WHITE, mes12);
printmes(p, ERR_X, ERR_Y2, WHITE, mes13);
printmes(p, ERR_X, ERR_Y3, WHITE, mes14);
break;
case GBPAK_ERR_MES_NOW_LOADING:
printmes(p, ERR_X, ERR_Y1, WHITE, mes16);
printmes(p, ERR_X, ERR_Y2, WHITE, mes17);
printmes(p, ERR_X, ERR_Y3, WHITE, mes18);
break;
case GBPAK_ERR_MES_FAIL_IN_READ_ID:
printmes(p, ERR_X, ERR_Y1, WHITE, mes20);
printmes(p, ERR_X, ERR_Y2, WHITE, mes21);
printmes(p, ERR_X, ERR_Y3, WHITE, mes22);
printmes(p, ERR_X, ERR_Y4, WHITE, mes23);
printmes(p, ERR_X, ERR_Y5, WHITE, mes24);
break;
default:
break;
}
}
/*---------------------------------------------------------------------
Main
---------------------------------------------------------------------*/
void
mainproc(void) {
static s32 step = 0;
u16 *p;
RetMsg *msg = NULL;
osCreateMesgQueue(&siMsgQ, siMsgBuf, SI_MSG_NUM);
osCreateThread(&siThread, 8, (void *)siproc, 0,
siStack+STACKSIZE/sizeof(u64), 12);
osStartThread(&siThread);
while(1){
siMsg.cmd = SI_CONT_READ;
osSendMesg(&siMsgQ, (OSMesg *)&siMsg, OS_MESG_NOBLOCK);
/* SI_CONT_READの終了メッセージを待つ */
while(!osRecvMesg(&retMsgQ, NULL, OS_MESG_NOBLOCK));
osWritebackDCache(cfb_16_a, SCREEN_WD*SCREEN_HT*2);
while(!osRecvMesg(&n_retraceMessageQ, NULL, OS_MESG_NOBLOCK));
osRecvMesg(&n_retraceMessageQ, NULL, OS_MESG_BLOCK);
p = (u16 *)osViGetNextFramebuffer();
switch (step) {
case 0: /* Gbpak処理を始める */
siMsg.cmd = SI_GBPAK_READ;
siMsg.address = 0; /* Gameboy address */
siMsg.size = DATA_SIZE; /* Data size (byte) */
siMsg.buffer = buffer; /* RDRAM buffer pointer */
osSendMesg(&siMsgQ, (OSMesg *)&siMsg, OS_MESG_BLOCK);
step ++;
break;
case 1: /* Gbpak処理の終了チェック */
if (!MQ_IS_EMPTY(&retMsgQ)){
gcls(p);
osRecvMesg(&retMsgQ, (OSMesg *)&msg, OS_MESG_BLOCK);
if (msg->proc_status == 0) { /* 64GBパックの処理が終わった */
if (msg->ret != 0){
if ( (msg->ret == PFS_ERR_NEW_GBCART)
&& (msg->errmes == NULL)) {
step = 0;
} else {
PrintErrorMessage(msg->errmes);/* エラーメッセージ表示 */
#if 1
if (msg->errmes==GBPAK_ERR_MES_FAIL_IN_READ_ID) {
step = 3;
} else {
step = 2;
}
#else /*--- デバッグ用 ---*/
step = 2;
#endif
}
} else { /* 64GBパックの読み書きに成功! */
printmes(p, ERR_X, ERR_Y1, WHITE, mes19);
step = 3; /* 終わり */
}
} else { /* 64GBパックの処理が終わっていない */
PrintErrorMessage(msg->errmes);
}
}
break;
case 2: /* キー入力待ち */
printmes(p, ERR_X, ERR_YY, WHITE, mes15);
if (conts[CONTNO].nowtrg & A_BUTTON) {
gcls(p);
step = 0;
}
break;
}
}
}