1 /*---------------------------------------------------------------------------* 2 Project: Revolution OS 3 File: os.h 4 Programmers: Shiki Okasaka 5 Hashida Takayuki 6 Tian 7 Carl 8 Dante 9 HIRATSU Daisuke 10 Kazuki Hirose 11 12 Copyright 1998-2005 Nintendo. All rights reserved. 13 14 These coded instructions, statements, and computer programs contain 15 proprietary information of Nintendo of America Inc. and/or Nintendo 16 Company Ltd., and are protected by Federal copyright law. They may 17 not be disclosed to third parties or copied or duplicated in any form, 18 in whole or in part, without the prior written consent of Nintendo. 19 20 $Log: os.h,v $ 21 Revision 1.21 2008/05/19 08:41:32 nakano_yoshinobu 22 Added OSCrc.h. 23 24 Revision 1.20 2007/10/02 08:02:55 nakano_yoshinobu 25 Fixed argument of OSInitStopwatch(). : char* -> const char* 26 27 Revision 1.19 2007/06/22 04:22:34 tsuji 28 add OS_CONSOLE_RVA_PROD1 29 30 Revision 1.18 2007/06/07 11:24:12 ooizumi 31 Added OS_APP_TYPE_WC24. 32 33 Revision 1.17 2007/05/07 01:17:00 wada_jumpei 34 Removed OSPlayTime.h 35 36 Revision 1.16 2007/03/22 08:22:47 wada_jumpei 37 Moved APP_TYPEs definition 38 39 Revision 1.15 2007/02/13 00:32:49 johnc 40 Added include of OSPlayTime.h 41 42 Revision 1.14 2007/01/11 08:55:33 wada_jumpei 43 Moved OSGetApp* APIs into C++ scope 44 45 Revision 1.13 2006/10/26 00:45:45 ooizumi 46 Removed SRAM setting functions. 47 48 Revision 1.12 2006/08/09 07:53:51 wada_jumpei 49 Added OSGetAppGamename and OSGetAppType. 50 51 Revision 1.11 2006/07/05 01:20:07 ooizumi 52 Added OS_CONSOLE_RVL_NDEV2_1. 53 54 Revision 1.10 2006/05/15 01:02:47 kawaset 55 Updated default clock value. 56 57 Revision 1.9 2006/02/28 12:17:04 hirose 58 Updated console type information. 59 60 Revision 1.8 2006/02/15 07:53:27 hirose 61 Updated console type definitions. 62 63 Revision 1.7 2006/02/08 10:22:27 mitu 64 fixed for win32 application. 65 66 Revision 1.6 2006/02/08 02:47:19 hirose 67 Updated Arena function definitions and console type macros. 68 69 Revision 1.5 2006/02/04 11:56:44 hashida 70 (none) 71 72 Revision 1.4 2006/01/28 09:33:12 hirose 73 Moved memory size APIs to OSMemory.h 74 Enabled MEM2 arena functions to all platform. 75 76 Revision 1.3 2006/01/21 02:01:17 hirose 77 Fixed #ifdef for time base definitions. 78 79 Revision 1.2 2006/01/07 06:18:20 hirose 80 Opened MEM1 macros to all targets. Added OSIsMEM?Region() macros. 81 82 Revision 1.1.1.1 2005/12/29 06:53:27 hiratsu 83 Initial import. 84 85 Revision 1.8 2005/12/27 10:07:24 hirose 86 Added MEM1 arena macros. Deleted obsoleted definitions. 87 88 Revision 1.7 2005/12/26 12:34:44 hiratsu 89 Renamed GDDR3 API.: BMEM -> MEM2. 90 91 92 59 1/23/03 9:38 Shiki 93 Defined OS_CONSOLE_TDEV, etc. 94 95 58 8/29/02 12:49 Shiki 96 Revised __VA_ARGS__ availability test code for NDEBUG, SNSYS. 97 98 57 8/29/02 9:49 Shiki 99 Revised __VA_ARGS__ availability test code for SNSYS. 100 101 56 8/26/02 13:32 Shiki 102 Removed old WIN emulator specific OS_TIMER_CLOCK definition. 103 Fixed __VA_ARGS__ availability test code. 104 105 55 8/22/02 11:57 Shiki 106 Clean up. 107 108 54 8/22/02 10:48 Shiki 109 Put #ifndef around ASSERTMSGn() macros. 110 Refined ASSERTMSG() using the C9x extension for MW 1.3.x users 111 Added another const keyword to the OSPanic() function prototype. 112 113 53 8/20/02 21:33 Shiki 114 Added OSFatal(). 115 116 52 8/12/02 15:16 Shiki 117 Added _padding field to OSStopwatch{}. 118 119 51 8/09/02 8:54 Shiki 120 Added const keywords to the OSReport() function prototype. 121 122 50 8/07/02 21:41 Shiki 123 Added OSRegisterVersion(). 124 125 49 8/05/02 18:04 Shiki 126 Added const keywords to relevant function prototypes. 127 128 48 11/27/01 21:12 Shiki 129 Included <revolution/os/OSModule.h>. 130 131 47 11/12/01 12:58 Shiki 132 Added OS[Get/Set]ProgressiveMode(). 133 134 46 10/29/01 11:08 Shiki 135 Included <revolution/os/OSSemaphore.h>. 136 137 45 10/25/01 13:58 Shiki 138 Fixed OS_LANG_*. 139 140 44 10/18/01 13:50 Shiki 141 Included <revolution/os/OSExpansion.h>. 142 143 43 9/03/01 14:43 Shiki 144 Included <revolution/os/OSSerial.h> 145 146 42 7/11/01 10:20p Hashida 147 Added OSReset.h 148 149 41 01/07/05 21:06 Shiki 150 Added OSGetProgressiveMode()/OSSetProgressiveMode(). 151 152 40 6/11/01 7:53p Tian 153 Changed to use AT_ADDRESS macro 154 155 39 5/17/01 1:26p Shiki 156 Updated OS_CORE_CLOCK, OS_BUS_CLOCK. 157 158 38 5/09/01 1:42p Carl 159 Conditionalized #define ASSERT. 160 161 37 01/04/27 17:45 Shiki 162 Added OS_LANG_NEUTRAL. 163 164 36 01/04/27 17:05 Shiki 165 Removed duplicated OS*etSoundMode() declarations. 166 167 35 01/04/27 16:43 Shiki 168 Fixed OS_LANG_DUTCH value. 169 170 34 01/04/27 16:25 Shiki 171 Added OS_LANG_*. 172 173 33 01/04/19 13:30 Shiki 174 Included <revolution/os/OSFont.h>. 175 176 32 01/02/15 10:55 Shiki 177 Added msec and usec to OSCalendarTime. 178 179 31 01/02/13 20:06 Shiki 180 Added sound mode and calendar functions. 181 182 30 11/09/00 7:40p Tian 183 Added calibrated clock values to HW2 184 185 29 9/11/00 2:59p Shiki 186 Added OS_CONSOLE_RETAIL2. 187 188 28 9/07/00 7:54p Shiki 189 Fixed OS_*_CLOCK defines and related macros for handling final clock 190 setup. 191 192 27 9/07/00 2:57p Shiki 193 Removed OSSetTick() and OSSetTime(). 194 195 26 9/05/00 5:18p Shiki 196 Added OS_CONSOLE_DEVHW2. 197 198 25 8/16/00 6:20p Shiki 199 Added OSDiffTick(). 200 201 24 7/14/00 3:48p Shiki 202 Added OSGetRTC()/OSSetRTC(). 203 204 23 7/10/00 6:40p Dante 205 Bug Fix (on the PC OSGetTick returns milliseconds) 206 207 22 6/15/00 4:47a Shiki 208 Rollback MINNOW clock speed defines for backward boot ROM 209 compatibility. 210 211 21 6/15/00 4:41a Shiki 212 Revised real-time clock API for HW1. 213 214 20 6/14/00 4:53p Shiki 215 Fixed HW1_DRIP clock settings. 216 217 19 5/18/00 9:28a Shiki 218 Added OSAllocFromArenaLo() and OSAllocFromArenaHi(). 219 220 18 5/14/00 1:38p Shiki 221 Fixed DRIP clock settings. 222 223 17 5/10/00 4:24p Shiki 224 Added clock configuration for DRIP. 225 226 16 3/29/00 3:05p Hashida 227 Added memory size APIs. 228 229 15 3/27/00 2:02p Tian 230 Added OSFastCast.h 231 232 14 3/16/00 7:04p Shiki 233 Removed timer API. Included <os/OSAlarm.h>. 234 235 13 3/14/00 2:44p Shiki 236 Added ASSERTMSGn() macros. 237 238 12 3/01/00 3:29p Tian 239 Cleaned up clock rate settings. They were wrong for GEKKO. 240 241 11 2/15/00 6:03p Shiki 242 Revised OS_CONSOLE_* define names. 243 244 10 2/01/00 1:50p Shiki 245 Added OS_CONSOLE_DEVELOPMENT1 define name. 246 247 9 1/18/00 6:22p Shiki 248 Included <revolution/os/OSMutex.h>. 249 250 8 1/18/00 5:46p Tian 251 MINNOW_MARLIN -> MINNOW 252 253 7 1/18/00 3:29p Shiki 254 Included <revolution/os/OSMessage.h>. 255 256 6 1/18/00 1:57p Tian 257 Changed the address translation macros for MINNOW_MARLIN to enable FIFO 258 emulation. Because ORs/ANDs are used, we sacrifice some safety. 259 260 5 1/18/00 10:43a Shiki 261 Implemented basic thread API. 262 263 4 1/10/00 2:43p Hashida 264 Changed so that OSTicksToMicroseconds and OSMicrosecondsToTicks macros 265 works with 33MHz busclock systems. 266 267 3 12/16/99 2:52p Tian 268 New core/bus speeds for Gekko + Spruce 269 270 2 12/15/99 3:08p Shiki 271 Added OS_*_CLOCK defines for MINNOW. 272 273 17 10/07/99 4:13p Shiki 274 Added Idle Function API section. 275 276 16 8/23/99 7:18p Shiki 277 Added OS_BASE_CACHED and OS_BASE_UNCACHED. 278 279 15 8/02/99 2:20p Shiki 280 Included OSInterrupt.h 281 282 14 99/07/27 4:51p Shiki 283 Added function versions of address translation APIs. 284 285 13 99/07/27 3:43p Shiki 286 Revised OSTicksToNanoseconds() and OSNanosecondsToTicks(). 287 288 12 99/07/27 3:16p Shiki 289 Fixed time-cycle conversion macros. 290 291 11 99/07/12 9:37p Shiki 292 Included OSError.h 293 294 10 99/07/12 3:24p Shiki 295 Cleanup. Removed EPPC specific OSReport() and OSPanic() declarations. 296 297 9 6/04/99 3:02p Tianli01 298 Cleanup. Added rounding macros, OSTicksToCycles. 299 300 8 5/25/99 5:28p Shiki 301 Added the following line: 302 #include <revolution/os/OSAlloc.h> 303 304 7 5/19/99 5:13p Shiki 305 Renamed Halt() to OSHalt(). 306 307 6 5/19/99 4:20p Shiki 308 Cleaned up address translation macros. 309 310 5 5/18/99 5:06p Shiki 311 Fixed address translation macros. 312 313 4 5/11/99 4:42p Shiki 314 Refreshed include tree. 315 316 2 5/03/99 5:26p Tianli01 317 PPC->EPPC 318 319 1 4/30/99 12:49p Tianli01 320 321 10 4/21/99 4:12p Tianli01 322 Added OSGetConsoleType. Changed OSInterruptLevel to BOOL. Cleaned up 323 Interrupt interface. 324 325 9 4/19/99 5:04p Shiki 326 Revised real-time clock API related definitions. 327 328 8 7/15/99 3:46p Shiki 329 1. Cleaned up ASSERT stuff 330 2. Moved to _DEBUG (avoid DEBUG) 331 332 7 4/15/99 2:45p Tianli01 333 Removed OS_BASE_CLOCK (it should have been OS_BUS_CLOCK). Added 334 ASSERTs for PPC. 335 336 6 4/13/99 5:48p Tianli01 337 Rearranged. Added stopwatch APIs. 338 339 5 4/12/99 7:45p Tianli01 340 Deleted OSEvent stuff. Move to DEBUG for consistency (avoid NDEBUG). 341 Fixed Halt/OSPanic for PPC target 342 343 4 4/01/99 7:53p Tianli01 344 Added OSTimer interfaces. Fixed time base constants for Arthur. 345 346 3 3/31/99 6:10p Tianli01 347 Added arena APIs (not implemented) , address translation constants for 348 assembly code, PPC OSReport APIs (only relevant for Arthur board). 349 350 2 3/26/99 2:06p Tianli01 351 Broke up into more header files (OSContext.h, OSEmu.h, OSException.h), 352 cleaned up, address translation macros added. 353 354 1 3/04/99 2:22p Tianli01 355 Initial checkin to new tree 356 357 5 12/18/98 11:28a Shiki 358 Removed declaration of __OSLoadContext2() 359 360 4 12/18/98 9:25a Shiki 361 Fixed definition of OSContext for Gecko 362 363 3 12/17/98 9:04a Shiki 364 Fixed ASSERT macro 365 366 2 12/16/98 8:54p Shiki 367 1. Used OSContext for windows stack environment instead of jmp_buf 368 to support __OSWinCall() API 369 2. Added the __cdecl modifiers to inline assembler functions 370 371 1 12/15/98 10:08p Shiki 372 373 Change History: 374 12/15/1998 Shiki Okasaka 1. Added __OSRaiseException() and 375 __OSRaiseInterrupt() 376 2. Revised __OSMach structure 377 12/12/1998 Shiki Okasaka Added OSSwitchStack() 378 12/11/1998 Shiki Okasaka 1. Moved bEnabled member from __OSMach to 379 OSContext 380 2. Fixed OSTime from u64 to s64 381 12/10/1998 Shiki Okasaka Revised to refrect the coding guidelines 382 12/07/1998 Shiki Okasaka Included <types.h> 383 12/06/1998 Shiki Okasaka 1. Revised __OSInitMach not to time-out 384 but to take data pointer 385 2. Added OSClearContext() 386 12/05/1998 Shiki Okasaka 1. Fixed __OSMach to keep stack bottom 387 2. Revised __OSInitMach to time-out 388 3. Revised OSSaveContext() 389 12/03/1998 Shiki Okasaka 1. Added interrupt time-out 390 2. Fixed OSSaveContext() 391 12/02/1998 Shiki Okasaka 2nd Edition 392 11/28/1998 Shiki Okasaka Created 393 394 $NoKeywords: $ 395 *---------------------------------------------------------------------------*/ 396 397 #ifndef __OS_H__ 398 #define __OS_H__ 399 400 #ifndef __DOLPHIN_RC__ 401 #include <revolution/types.h> 402 #include <revolution/gx/GXStruct.h> 403 #endif // __DOLPHIN_RC__ 404 405 #include <stdarg.h> 406 407 #ifdef __cplusplus 408 extern "C" { 409 #endif 410 411 /*---------------------------------------------------------------------------* 412 Arena API 413 *---------------------------------------------------------------------------*/ 414 415 void* OSGetMEM1ArenaHi( void ); 416 void* OSGetMEM1ArenaLo( void ); 417 void OSSetMEM1ArenaHi( void* newHi ); 418 void OSSetMEM1ArenaLo( void* newLo ); 419 420 void* OSGetMEM2ArenaHi( void ); 421 void* OSGetMEM2ArenaLo( void ); 422 void OSSetMEM2ArenaHi( void* newHi ); 423 void OSSetMEM2ArenaLo( void* newLo ); 424 425 void* OSAllocFromMEM1ArenaLo( u32 size, u32 align ); 426 void* OSAllocFromMEM1ArenaHi( u32 size, u32 align ); 427 void* OSAllocFromMEM2ArenaLo( u32 size, u32 align ); 428 void* OSAllocFromMEM2ArenaHi( u32 size, u32 align ); 429 430 // For backward compatibility 431 void* OSGetArenaHi( void ); // Same as OSGetMEM1ArenaHi 432 void* OSGetArenaLo( void ); // Same as OSGetMEM1ArenaLo 433 void OSSetArenaHi( void* newHi ); // Same as OSSetMEM1ArenaHi 434 void OSSetArenaLo( void* newLo ); // Same as OSSetMEM1ArenaLo 435 436 #define OSAllocFromArenaLo OSAllocFromMEM1ArenaLo 437 #define OSAllocFromArenaHi OSAllocFromMEM1ArenaHi 438 439 #ifdef HOLLYWOOD_EMU 440 #define OS_MEM2_EMU_SIZE 0x00100000 // 1Mbyte. 441 #endif 442 443 /*---------------------------------------------------------------------------* 444 Round APIs 445 *---------------------------------------------------------------------------*/ 446 447 // Most Dolphin subsystems require 32 byte alignment 448 #define OSRoundUp32B(x) (((u32)(x) + 32 - 1) & ~(32 - 1)) 449 #define OSRoundDown32B(x) (((u32)(x)) & ~(32 - 1)) 450 451 /*---------------------------------------------------------------------------* 452 Basic OS API 453 *---------------------------------------------------------------------------*/ 454 455 void OSInit ( void ); 456 457 #define OS_CONSOLE_MASK 0xf0000000 458 #define OS_CONSOLE_RETAIL 0x00000000 459 #define OS_CONSOLE_DEVELOPMENT 0x10000000 460 #define OS_CONSOLE_TDEV 0x20000000 461 462 #define OS_CONSOLE_RVA_PROD1 0x00000100 463 464 #define OS_CONSOLE_RVL_RETAIL3 0x00000023 465 #define OS_CONSOLE_RVL_RETAIL2 0x00000022 466 #define OS_CONSOLE_RVL_RETAIL1 0x00000021 467 #define OS_CONSOLE_RVL_PP2_2 0x00000020 468 #define OS_CONSOLE_RVL_PP2_1 0x00000012 469 #define OS_CONSOLE_RVL_PP1 0x00000011 470 #define OS_CONSOLE_RVL_PP0 0x00000010 471 #define OS_CONSOLE_RVL_NDEV2_1 0x10000021 472 #define OS_CONSOLE_RVL_NDEV2_0 0x10000020 473 #define OS_CONSOLE_RVL_NDEV1_2 0x10000012 474 #define OS_CONSOLE_RVL_NDEV1_1 0x10000011 475 #define OS_CONSOLE_RVL_NDEV1_0 0x10000010 476 477 #define OS_CONSOLE_RETAIL4 0x00000004 478 #define OS_CONSOLE_RETAIL3 0x00000003 479 #define OS_CONSOLE_RETAIL2 0x00000002 480 #define OS_CONSOLE_RETAIL1 0x00000001 481 #define OS_CONSOLE_TDEVHW4 0x20000007 482 #define OS_CONSOLE_TDEVHW3 0x20000006 483 #define OS_CONSOLE_TDEVHW2 0x20000005 484 #define OS_CONSOLE_TDEVHW1 0x20000004 485 #define OS_CONSOLE_RVL_EMULATOR 0x10000008 // For Revolution emulator kit 486 #define OS_CONSOLE_DEVHW4 0x10000007 487 #define OS_CONSOLE_DEVHW3 0x10000006 488 #define OS_CONSOLE_DEVHW2 0x10000005 489 #define OS_CONSOLE_DEVHW1 0x10000004 490 #define OS_CONSOLE_MINNOW 0x10000003 491 #define OS_CONSOLE_ARTHUR 0x10000002 492 #define OS_CONSOLE_PC_EMULATOR 0x10000001 493 #define OS_CONSOLE_EMULATOR 0x10000000 494 495 496 u32 OSGetConsoleType( void ); 497 498 void OSRegisterVersion( const char* id ); 499 500 /*---------------------------------------------------------------------------* 501 Interrupt API 502 *---------------------------------------------------------------------------*/ 503 504 BOOL OSDisableInterrupts ( void ); 505 BOOL OSEnableInterrupts ( void ); 506 BOOL OSRestoreInterrupts ( BOOL level ); 507 508 /*---------------------------------------------------------------------------* 509 Address Translation API 510 *---------------------------------------------------------------------------*/ 511 512 // Declarations 513 void* OSPhysicalToCached ( u32 paddr ); 514 void* OSPhysicalToUncached ( u32 paddr ); 515 u32 OSCachedToPhysical ( const void* caddr ); 516 u32 OSUncachedToPhysical ( const void* ucaddr ); 517 void* OSCachedToUncached ( const void* caddr ); 518 void* OSUncachedToCached ( const void* ucaddr ); 519 520 // Upper words of the masks, since UIMM is only 16 bits 521 #define OS_CACHED_REGION_PREFIX 0x8000 522 #define OS_UNCACHED_REGION_PREFIX 0xC000 523 #define OS_PHYSICAL_MASK 0x3FFF 524 525 #define OS_BASE_CACHED (OS_CACHED_REGION_PREFIX << 16) 526 #define OS_BASE_UNCACHED (OS_UNCACHED_REGION_PREFIX << 16) 527 528 // Macro overrides 529 #ifndef _DEBUG 530 #define OSPhysicalToCached(paddr) ((void*) ((u32)(paddr) + OS_BASE_CACHED)) 531 #define OSPhysicalToUncached(paddr) ((void*) ((u32)(paddr) + OS_BASE_UNCACHED)) 532 #define OSCachedToPhysical(caddr) ((u32) ((u8*)(caddr) - OS_BASE_CACHED)) 533 #define OSUncachedToPhysical(ucaddr) ((u32) ((u8*)(ucaddr)- OS_BASE_UNCACHED)) 534 #define OSCachedToUncached(caddr) ((void*) ((u8*)(caddr) + (OS_BASE_UNCACHED - OS_BASE_CACHED))) 535 #define OSUncachedToCached(ucaddr) ((void*) ((u8*)(ucaddr)- (OS_BASE_UNCACHED - OS_BASE_CACHED))) 536 #endif // _DEBUG 537 538 // Memory region identifiers 539 #define OS_MEM1_REGION_PREFIX 0x00000000 540 #define OS_MEM2_REGION_PREFIX 0x10000000 541 #define OS_MEM_REGION_ID_MASK 0x30000000 542 543 #define OSIsMEM1Region(addr) (((u32)(addr) & OS_MEM_REGION_ID_MASK) == OS_MEM1_REGION_PREFIX) 544 #define OSIsMEM2Region(addr) (((u32)(addr) & OS_MEM_REGION_ID_MASK) == OS_MEM2_REGION_PREFIX) 545 546 /*---------------------------------------------------------------------------* 547 Real-time Clock API 548 *---------------------------------------------------------------------------*/ 549 typedef s64 OSTime; 550 typedef u32 OSTick; 551 552 #ifndef WIN32 553 u32 __OSBusClock AT_ADDRESS(OS_BASE_CACHED | 0x00F8); // sync with OSLoMem.h 554 u32 __OSCoreClock AT_ADDRESS(OS_BASE_CACHED | 0x00FC); // sync with OSLoMem.h 555 #define OS_BUS_CLOCK __OSBusClock 556 #define OS_CORE_CLOCK __OSCoreClock 557 #define OS_TIMER_CLOCK (OS_BUS_CLOCK/4) 558 #endif 559 560 // Default Configuration 561 #ifndef OS_CORE_CLOCK 562 #define OS_CORE_CLOCK 729000000u 563 #endif 564 #ifndef OS_BUS_CLOCK 565 #define OS_BUS_CLOCK 243000000u 566 #endif 567 #ifndef OS_TIMER_CLOCK 568 #define OS_TIMER_CLOCK (OS_BUS_CLOCK/4) 569 #endif 570 571 #define OSTicksToCycles( ticks ) (((ticks) * ((OS_CORE_CLOCK * 2) / OS_TIMER_CLOCK)) / 2) 572 #define OSTicksToSeconds( ticks ) ((ticks) / OS_TIMER_CLOCK) 573 #define OSTicksToMilliseconds( ticks ) ((ticks) / (OS_TIMER_CLOCK / 1000)) 574 #define OSTicksToMicroseconds( ticks ) (((ticks) * 8) / (OS_TIMER_CLOCK / 125000)) 575 #define OSTicksToNanoseconds( ticks ) (((ticks) * 8000) / (OS_TIMER_CLOCK / 125000)) 576 #define OSSecondsToTicks( sec ) ((sec) * OS_TIMER_CLOCK) 577 #define OSMillisecondsToTicks( msec ) ((msec) * (OS_TIMER_CLOCK / 1000)) 578 #define OSMicrosecondsToTicks( usec ) (((usec) * (OS_TIMER_CLOCK / 125000)) / 8) 579 #define OSNanosecondsToTicks( nsec ) (((nsec) * (OS_TIMER_CLOCK / 125000)) / 8000) 580 581 #define OSDiffTick(tick1, tick0) ((s32) (tick1) - (s32) (tick0)) 582 583 OSTick OSGetTick( void ); 584 OSTime OSGetTime( void ); 585 586 typedef struct OSCalendarTime 587 { 588 int sec; // seconds after the minute [0, 61] 589 int min; // minutes after the hour [0, 59] 590 int hour; // hours since midnight [0, 23] 591 int mday; // day of the month [1, 31] 592 int mon; // month since January [0, 11] 593 int year; // years since 0000 594 int wday; // days since Sunday [0, 6] 595 int yday; // days since January 1 [0, 365] 596 597 int msec; // milliseconds after the second [0,999] 598 int usec; // microseconds after the millisecond [0,999] 599 } OSCalendarTime; 600 601 OSTime OSCalendarTimeToTicks( OSCalendarTime* td ); 602 void OSTicksToCalendarTime( OSTime ticks, OSCalendarTime* td ); 603 604 /*---------------------------------------------------------------------------* 605 Stopwatch API 606 *---------------------------------------------------------------------------*/ 607 608 typedef struct OSStopwatch 609 { 610 const char* name; // name of this stopwatch 611 u32 hits; // number of times turned on and off 612 OSTime total; // total time running 613 OSTime min; // smallest time measured 614 OSTime max; // longest time measured 615 616 OSTime last; // time at which this sw was last started 617 BOOL running; // TRUE if sw is running 618 u32 _padding; 619 } OSStopwatch; 620 621 622 void OSInitStopwatch ( OSStopwatch* sw, const char* name ); 623 void OSStartStopwatch ( OSStopwatch* sw ); 624 void OSStopStopwatch ( OSStopwatch* sw ); 625 OSTime OSCheckStopwatch ( OSStopwatch* sw ); 626 void OSResetStopwatch ( OSStopwatch* sw ); 627 void OSDumpStopwatch ( OSStopwatch* sw ); 628 629 /*----------------------------------------------------------------------* 630 Debug API 631 *----------------------------------------------------------------------*/ 632 633 #define OSHalt(msg) OSPanic(__FILE__, __LINE__, msg) 634 635 #ifdef _DEBUG 636 637 #ifndef ASSERT 638 #define ASSERT(exp) \ 639 (void) ((exp) || \ 640 (OSPanic(__FILE__, __LINE__, "Failed assertion " #exp), 0)) 641 #endif 642 643 #ifndef ASSERTMSG 644 #if defined(__STDC_VERSION__) && (199901L <= __STDC_VERSION__) || defined(__MWERKS__) || defined(__SN__) 645 #define ASSERTMSG(exp, ...) \ 646 (void) ((exp) || \ 647 (OSPanic(__FILE__, __LINE__, __VA_ARGS__), 0)) 648 #else 649 #define ASSERTMSG(exp, msg) \ 650 (void) ((exp) || \ 651 (OSPanic(__FILE__, __LINE__, (msg)), 0)) 652 #endif 653 #endif 654 655 #ifndef ASSERTMSG1 656 #define ASSERTMSG1(exp, msg, param1) \ 657 (void) ((exp) || \ 658 (OSPanic(__FILE__, __LINE__, (msg), \ 659 (param1)), 0)) 660 #endif 661 662 #ifndef ASSERTMSG2 663 #define ASSERTMSG2(exp, msg, param1, param2) \ 664 (void) ((exp) || \ 665 (OSPanic(__FILE__, __LINE__, (msg), \ 666 (param1), (param2)), 0)) 667 #endif 668 669 #ifndef ASSERTMSG3 670 #define ASSERTMSG3(exp, msg, param1, param2, param3) \ 671 (void) ((exp) || \ 672 (OSPanic(__FILE__, __LINE__, (msg), \ 673 (param1), (param2), (param3)), 0)) 674 #endif 675 676 #ifndef ASSERTMSG4 677 #define ASSERTMSG4(exp, msg, param1, param2, param3, param4) \ 678 (void) ((exp) || \ 679 (OSPanic(__FILE__, __LINE__, (msg), \ 680 (param1), (param2), (param3), (param4)), 0)) 681 #endif 682 683 #else // _DEBUG 684 685 #ifndef ASSERT 686 #define ASSERT(exp) ((void) 0) 687 #endif 688 689 #ifndef ASSERTMSG 690 #if defined(__STDC_VERSION__) && (199901L <= __STDC_VERSION__) || defined(__MWERKS__) || defined(__SN__) 691 #define ASSERTMSG(exp, ...) ((void) 0) 692 #else 693 #define ASSERTMSG(exp, msg) ((void) 0) 694 #endif 695 #endif 696 697 #ifndef ASSERTMSG1 698 #define ASSERTMSG1(exp, msg, param1) ((void) 0) 699 #endif 700 #ifndef ASSERTMSG2 701 #define ASSERTMSG2(exp, msg, param1, param2) ((void) 0) 702 #endif 703 #ifndef ASSERTMSG3 704 #define ASSERTMSG3(exp, msg, param1, param2, param3) ((void) 0) 705 #endif 706 #ifndef ASSERTMSG4 707 #define ASSERTMSG4(exp, msg, param1, param2, param3, param4) ((void) 0) 708 #endif 709 710 #endif // _DEBUG 711 712 #ifndef __DOLPHIN_RC__ 713 714 void OSPanic ( const char* file, int line, const char* msg, ... ); 715 void OSReport ( const char* msg, ... ); 716 void OSVReport( const char* msg, va_list list ); 717 void OSFatal ( GXColor fg, GXColor bg, const char* msg ); 718 719 #endif // __DOLPHIN_RC__ 720 721 /*---------------------------------------------------------------------------* 722 Get infomation APIs 723 *---------------------------------------------------------------------------*/ 724 725 const char* OSGetAppGamename(void); 726 const u8 OSGetAppType(void); 727 #define OS_APP_TYPE_WC24 0x20 728 #define OS_APP_TYPE_IPL 0x40 729 #define OS_APP_TYPE_DVD 0x80 730 #define OS_APP_TYPE_NAND 0x81 731 732 #ifdef __cplusplus 733 } 734 #endif 735 736 /*---------------------------------------------------------------------------* 737 Advanced OS APIs 738 *---------------------------------------------------------------------------*/ 739 740 #include <revolution/os/OSAlloc.h> // Memory allocation routines and defines 741 #include <revolution/os/OSAlarm.h> // Alarm routines and defines 742 #include <revolution/os/OSCache.h> // Cache operation APIs 743 #include <revolution/os/OSContext.h> // Context structures and defines 744 #include <revolution/os/OSError.h> // Error handler routines and defines 745 #include <revolution/os/OSException.h> // Exception handling routines and defines 746 #include <revolution/os/OSExpansion.h> // Expansion interface APIs 747 #include <revolution/os/OSFastCast.h> // Fast float/int conversion 748 #include <revolution/os/OSFont.h> // ROM font routines and defines 749 #include <revolution/os/OSInterrupt.h> // Interrupt handling routines and defines 750 #include <revolution/os/OSMemory.h> // Memory size and protection APIs 751 #include <revolution/os/OSMessage.h> // Message routines and defines 752 #include <revolution/os/OSModule.h> // Relocatable module routines and defines 753 #include <revolution/os/OSMutex.h> // Mutex routines and defines 754 #include <revolution/os/OSResetSW.h> // Reset switch APIs 755 #include <revolution/os/OSSerial.h> // Serial interface APIs 756 #include <revolution/os/OSSemaphore.h> // Semaphore routines and defines 757 #include <revolution/os/OSThread.h> // Thread routines and defines 758 #include <revolution/os/OSReset.h> // Reset APIs 759 #include <revolution/os/OSCrc.h> // CRC APIs 760 761 #endif // __OS_H__ 762