test_64dd.c
11.6 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
/*---------------------------------------------------------------------*
Copyright (C) 1998 Nintendo.
$RCSfile: test_64dd.c,v $
$Revision: 1.1.1.1 $
$Date: 2002/05/02 03:27:09 $
*---------------------------------------------------------------------*/
#include "hscr.h"
static s32 _screen = SCREEN_INIT;
static s32 _cursor = 1;
static u8 temp[32];
LEODiskTime RTCdata;
static u8 *func_str[] = {
"LeoCreateLeoManager()",
"LeoReadWrite()(WRITE)",
"LeoReadWrite()(READ)",
"LeoSeek()",
"LeoRezero()",
"LeoReadDiskID()",
"LeoReadRTC()",
"LeoSetRTC()",
"LeoModeSelectAsync()",
"LeoSpdlMotor()(SLEEP)",
"LeoSpdlMotor()(BRAKE)",
"LeoSpdlMotor()(ACTIVE)",
"LeoTestUnitReady()",
};
OSMesgQueue myQ;
OSMesg myQBuf[1];
TMessage4dd _ddmsg = {0};
static s32 rtc_check(u16 year ,u8 month ,u8 day);
s32
sb_clip(s32 val ,s32 from ,s32 to)
{
s32 ret;
ret = val;
if( val < from ) ret = to;
else if( val > to ) ret = from;
return ret;
}
u8
fromBCD(u8 data)
{
return ((data >> 4) & 15) * 10 + (data & 15);
}
u8
toBCD(u8 data)
{
return ((u8)(data / 10)) * 16 + (data % 10);
}
static s32
rtc_check(u16 year ,u8 month ,u8 day)
{
s32 daymax[]={31,28,31,30,31,30,31,31,30,31,30,31};
if((year % 4) == 0) daymax[2-1]=29;
return ( day <= daymax[month-1]);
}
void
printDate(Gfx **gpp)
{
Gfx *gp = *gpp;
sprintf(temp, "%02d%02d/%02d/%02d %02d:%02d:%02d",
fromBCD(RTCdata.yearhi),
fromBCD(RTCdata.yearlo),
fromBCD(RTCdata.month),
fromBCD(RTCdata.day),
fromBCD(RTCdata.hour),
fromBCD(RTCdata.minute),
fromBCD(RTCdata.second) );
_setString(&gp, temp, MES_DATE_X + 0, MES_DATE_Y,RGBA_WHITE);
*gpp = gp;
}
void
_setString(Gfx **gpp,u8 * str,s32 x,s32 y,u32 color)
{
Gfx *gp = *gpp;
font_set_color( (u8)((color >> 24 ) & 0xFF)
, (u8)((color >> 16 ) & 0xFF)
, (u8)((color >> 8 ) & 0xFF)
, (u8)((color >> 0 ) & 0xFF) );
font_set_pos(x, y);
font_show_string( &gp, str );
*gpp = gp;
}
void
_setJStr(Gfx **gpp,s32 str_no,s32 x,s32 y,u32 color)
{
Gfx *gp = *gpp;
font_set_color( (u8)((color >> 24 ) & 0xFF)
, (u8)((color >> 16 ) & 0xFF)
, (u8)((color >> 8 ) & 0xFF)
, (u8)((color >> 0 ) & 0xFF) );
font_set_pos(x, y);
jfont_show_string( &gp, str_no );
*gpp = gp;
}
void
_setScreen(s32 i)
{
_screen = i;
}
s32
_getCurrentScreen(void)
{
return _screen;
}
void
test_64dd( Gfx **pglistp )
{
Gfx *gp;
gp = *pglistp;
font_init( &gp );
switch( _screen )
{
case SCREEN_INIT:
scr_init(&gp);
_printErrorNo(&gp);
break;
case SCREEN_MENU:
scr_menu(&gp);
break;
case SCREEN_RESULT:
scr_result(&gp);
_printErrorNo(&gp);
break;
case SCREEN_SETRTC:
scr_setrtc(&gp);
break;
case SCREEN_SETMOTOR:
scr_setmotor(&gp);
break;
default:
break;
}
/* Display Error No */
scr_error(&gp);
font_finish( &gp );
*pglistp = gp;
}
void
_printErrorNo(Gfx **gpp)
{
Gfx *gp=*gpp;
s32 i;
sprintf(temp, "%02d", dd_errbuf[0] );
_setString(&gp, temp, 32 + 0*28, 200, RGBA_WHITE );
for (i = 1 ; i < 5 ; i ++)
{
if( !dd_errbuf[i] ) break;
sprintf(temp, "%02d", dd_errbuf[i] );
_setString(&gp, temp, 32 + i*28, 200, RGBA_WHITE );
/*
if ( dd_errbuf[i] == LEO_ERROR_POWERONRESET_DEVICERESET_OCCURED )
{
sprintf(temp, "%02d", dd_getStatus()->counter );
_setString(&gp, temp, 32 + i*28, 180, RGBA_WHITE );
}
*/
}
*gpp = gp;
}
void
scr_result(Gfx **gpp)
{
Gfx *gp = *gpp;
s32 cur;
cur = _getCursor();
_setString( &gp, func_str[cur], MES_CMD_X, MES_CMD_Y, RGBA_WHITE );
if( dd_checkGate(&_ddmsg) )
{
if( A_BUTTON_PUSH )
{
dd_errbuf[1] = 0;
_setScreen(SCREEN_MENU);
}
if( _ddmsg.command == LEOCMD_GETRTC )
{
bcopy( &_ddmsg.param ,&RTCdata , sizeof(LEODiskTime));
printDate(&gp);
}
_setJStr(&gp, ES_SEIJO_SHURYO, 120,120 ,RGBA_WHITE);
}
*gpp = gp;
}
void
scr_init(Gfx **gpp)
{
Gfx *gp = *gpp;
static s32 _first = 1;
static s32 _step=0;
if(_first)
{
osCreateMesgQueue(&myQ, myQBuf, 1);
_ddmsg.retQ = &myQ;
/* dd_errHook(9,5,1);*/
dd_create();
_first--;
}
_setString(&gp,func_str[0],MES_CMD_X,MES_CMD_Y,RGBA_WHITE);
if( dd_checkGate(&_ddmsg) )
{
switch(_step)
{
case 0:
if( (dd_getStatus()->errmes & 0xFF) == ERRMES__SET_CLOCK )
{
if( A_BUTTON_PUSH )
{
_setScreen( SCREEN_SETRTC );
return;
}
break;
}
if( dd_getStatus()->mode == DDSTAT_GOOD ) ++_step;
break;
case 1: /* read rtc */
_ddmsg.command = LEOCMD_GETRTC;
dd_exec( &_ddmsg );
++_step;
break;
case 2: /* first write */
if( _ddmsg.retVal )
{
bcopy( &_ddmsg.param ,&RTCdata , sizeof(LEODiskTime));
_ddmsg.command = LEOCMD_LBAWRITE;
_ddmsg.param.hi = TEST_START_LBA;
_ddmsg.param.lo = 1;
_ddmsg.param.rw = NULL;
dd_exec( &_ddmsg );
++_step;
}
break;
case 3:
if ( A_BUTTON_PUSH )
{
_setScreen( SCREEN_MENU );
return;
}
printDate(&gp);
_setJStr(&gp, ES_SEIJO_SHURYO, 120,120 ,RGBA_WHITE);
break;
default:
break;
}
}
*gpp = gp;
}
void
scr_menu(Gfx **gpp)
{
Gfx *gp = *gpp;
s32 i;
font_set_transparent( 1 );
font_set_win( 32, 1 );
for ( i = 1 ; i < FUNC_NUM ; i++)
_setString(&gp, func_str[i],MES_CMD_X, MES_CMD_Y + MES_CMD_DY*(i-1),
((i == _cursor) ? RGBA_SELECTED : RGBA_UNSELECTED));
if( dd_checkGate(&_ddmsg) )
{
if( A_BUTTON_PUSH )
{
switch ( _cursor )
{
case 1:
_ddmsg.command = LEOCMD_LBAWRITE;
_ddmsg.param.hi = TEST_START_LBA;
_ddmsg.param.lo = 1;
_ddmsg.param.rw = NULL;
dd_exec(&_ddmsg);
_setScreen( SCREEN_RESULT );
break;
case 2:
_ddmsg.command = LEOCMD_LBAREAD;
_ddmsg.param.hi = TEST_START_LBA;
_ddmsg.param.lo = 1;
_ddmsg.param.rw = NULL;
dd_exec(&_ddmsg);
_setScreen( SCREEN_RESULT );
break;
case 3:
_ddmsg.command = LEOCMD_SEEK;
_ddmsg.param.hi = TEST_START_LBA;
dd_exec(&_ddmsg);
_setScreen( SCREEN_RESULT );
break;
case 4:
_ddmsg.command = LEOCMD_REZERO;
dd_exec(&_ddmsg);
_setScreen( SCREEN_RESULT );
break;
case 5:
_ddmsg.command = LEOCMD_GETID;
_ddmsg.param.hi = 0; /* ID is no required */
_ddmsg.param.lo = 0; /* boot ID required */
dd_exec(&_ddmsg);
_setScreen( SCREEN_RESULT );
break;
case 6:
_ddmsg.command = LEOCMD_GETRTC;
dd_exec(&_ddmsg);
_setScreen( SCREEN_RESULT );
break;
case 7:
_setScreen( SCREEN_SETRTC );
break;
case 8:
_setScreen( SCREEN_SETMOTOR );
break;
case 9:
_ddmsg.command = LEOCMD_SLEEP;
dd_exec(&_ddmsg);
_setScreen( SCREEN_RESULT );
break;
case 10:
_ddmsg.command = LEOCMD_BRAKE;
dd_exec(&_ddmsg);
_setScreen( SCREEN_RESULT );
break;
case 11:
_ddmsg.command = LEOCMD_ACTIVE;
dd_exec(&_ddmsg);
_setScreen( SCREEN_RESULT );
break;
case 12:
_ddmsg.command = LEOCMD_TESTUNIT;
dd_exec(&_ddmsg);
_setScreen( SCREEN_RESULT );
break;
default:
break;
}
return;
}
switch ( conts[0].nowtrg )
{
case D_JPAD:
if (++_cursor >= FUNC_NUM) _cursor = 1;
break;
case U_JPAD:
if (--_cursor < 1) _cursor = sizeof(func_str)/sizeof(u8 *) - 1;
break;
}
}
*gpp = gp;
}
s32
_getCursor(void)
{
return _cursor;
}
#define U_JPAD_PUSH ((conts[0].nowtrg | conts[0].repeat) & U_JPAD)
#define D_JPAD_PUSH ((conts[0].nowtrg | conts[0].repeat) & D_JPAD)
void
scr_setrtc(Gfx **gpp)
{
Gfx *gp = *gpp;
static s32 i;
static s16 xpos;
static s32 _first = 1;
s32 dire=0,next_screen;
static u16 year = 1999;
static u8 month = 7;
static u8 day = 7;
static u8 hour = 23;
static u8 minute = 59;
static u8 second = 59;
if(_first)
{
xpos = 0;
i = MES_DATE_X + 2*8;
if(dd_getStatus()->errmes != ERRMES__SET_CLOCK)
{
year = fromBCD(RTCdata.yearhi)*100 + fromBCD(RTCdata.yearlo);
month = fromBCD(RTCdata.month);
day = fromBCD(RTCdata.day);
hour = fromBCD(RTCdata.hour);
minute = fromBCD(RTCdata.minute);
second = fromBCD(RTCdata.second);
}
--_first;
}
_setString(&gp,func_str[7],MES_CMD_X,MES_CMD_Y,RGBA_WHITE);
sprintf(temp, "%04d/%02d/%02d %02d:%02d:%02d",
year, month, day,
hour, minute, second);
_setString(&gp,temp,MES_DATE_X + 0, MES_DATE_Y,RGBA_WHITE);
_setString(&gp,"--",i, MES_DATE_Y+8 ,RGBA_YELLOW);
if( dd_checkGate(&_ddmsg) )
{
switch ( conts[0].nowtrg )
{
case A_BUTTON:
if (rtc_check(year,month,day))
{
RTCdata.yearhi = toBCD( (u8)(year / 100) );
RTCdata.yearlo = toBCD( (u8)(year % 100) );
RTCdata.month = toBCD(month);
RTCdata.day = toBCD(day);
RTCdata.hour = toBCD(hour);
RTCdata.minute = toBCD(minute);
RTCdata.second = toBCD(second);
_ddmsg.command = LEOCMD_SETRTC;
bcopy( &RTCdata ,&_ddmsg.param , sizeof(LEODiskTime));
next_screen = ( (dd_getStatus()->errmes & 0xff) == ERRMES__SET_CLOCK ) ?
SCREEN_INIT : SCREEN_RESULT;
dd_exec( &_ddmsg );
_setScreen(next_screen);
}
break;
case B_BUTTON:
if( (dd_getStatus()->errmes & 0xff) != ERRMES__SET_CLOCK )
{
_setScreen(SCREEN_MENU);
++_first;
}
break;
case R_JPAD:
if ( xpos < 5 ) xpos ++;
break;
case L_JPAD:
if ( xpos > 0 ) xpos --;
break;
}
if(U_JPAD_PUSH) dire = 1;
if(D_JPAD_PUSH) dire = -1;
switch (xpos)
{
case 0:
i = MES_DATE_X + 2*8;
year = sb_clip(year+dire,1996,2095);
break;
case 1:
i = MES_DATE_X + 5*8;
month = sb_clip(month+dire,1,12);
break;
case 2:
i = MES_DATE_X + 8*8;
day = sb_clip(day + dire,1,31);
break;
case 3:
i = MES_DATE_X + 11*8;
hour = sb_clip( hour + dire, 0, 23 );
break;
case 4:
i = MES_DATE_X + 14*8;
minute = sb_clip( minute + dire, 0, 59 );
break;
case 5:
i = MES_DATE_X + 17*8;
second = sb_clip( second + dire, 0, 59 );
break;
}
}
*gpp = gp;
}
#define U_JPAD_PUSH ((conts[0].nowtrg | conts[0].repeat) & U_JPAD)
#define D_JPAD_PUSH ((conts[0].nowtrg | conts[0].repeat) & D_JPAD)
void
scr_setmotor(Gfx **gpp)
{
Gfx *gp = *gpp;
static s16 _first=1,standby, sleep ,xpos;
s32 dire;
u32 color[2]={RGBA_WHITE};
if(_first)
{
standby = 3;
sleep = 1;
xpos = 0;
--_first;
}
_setString(&gp,func_str[8],MES_CMD_X,MES_CMD_Y,RGBA_WHITE);
color[xpos] = RGBA_YELLOW;
color[xpos^1] = RGBA_WHITE;
sprintf(temp, "%2d", standby);
_setString(&gp, "To STANDBY", MES_CMD_X + 16, MES_CMD_Y + 52, color[0]);
_setString(&gp, temp, MES_CMD_X + 36, MES_CMD_Y + 72, color[0]);
sprintf(temp, "%2d", sleep);
_setString(&gp, "To SLEEP", MES_CMD_X + 128, MES_CMD_Y + 52, color[1]);
_setString(&gp, temp, MES_CMD_X + 144, MES_CMD_Y + 72, color[1]);
if( dd_checkGate(&_ddmsg) )
{
switch ( conts[0].nowtrg )
{
case A_BUTTON:
_ddmsg.command = LEOCMD_SETMOTORTIME;
_ddmsg.param.hi = standby;
_ddmsg.param.lo = sleep;
dd_exec(&_ddmsg);
_setScreen( SCREEN_RESULT );
break;
case B_BUTTON:
_setScreen( SCREEN_MENU );
break;
case U_JPAD:
dire = 1;
goto UPDOWN;
case D_JPAD:
dire = -1;
goto UPDOWN;
case R_JPAD:
case L_JPAD:
xpos ^= 1;
break;
default:
break;
UPDOWN:
if (xpos == 0)
standby = sb_clip(standby+dire,0,10);
else
sleep = sb_clip(sleep + dire,0,10);
break;
}
}
*gpp = gp;
}