1 /*---------------------------------------------------------------------------*
2 Project: Dolphin/Revolution GD library
3 File: GD.c
4
5 Copyright 2001- 2006 Nintendo. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Log: GDBase.c,v $
14 Revision 1.3 2006/02/20 04:24:39 mitu
15 Changed include path from dolphin/ to revolution/.
16
17 Revision 1.2 2006/02/03 08:54:52 hirose
18 Avoided use of EPPC and use WIN32.
19
20 Revision 1.1.1.1 2005/05/12 02:15:49 yasuh-to
21 Ported from dolphin source tree.
22
23
24 2 2001/09/12 3:56p Carl
25 Renamed some functions to make it clear which act on "current".
26
27 1 2001/09/12 1:52p Carl
28 Initial revision of GD: Graphics Display List Library.
29
30 $NoKeywords: $
31 *---------------------------------------------------------------------------*/
32
33 #include <revolution/gd.h>
34 #include <revolution/os.h>
35
36 /*---------------------------------------------------------------------------*/
37
38 // This object is global, but the user should not access it directly:
39 GDLObj *__GDCurrentDL = NULL;
40
41 // Overflow callback pointer
42 static GDOverflowCallback overflowcb = NULL;
43
44 /*---------------------------------------------------------------------------*/
45
46 // Initialize parameters
GDInitGDLObj(GDLObj * dl,void * start,u32 length)47 void GDInitGDLObj(GDLObj *dl, void *start, u32 length)
48 {
49 ASSERTMSG( ((u32) start & 31) == 0, "start must be aligned to 32 bytes");
50 ASSERTMSG( (length & 31) == 0, "length must be aligned to 32 bytes");
51
52 dl->start = start;
53 dl->ptr = (u8*) start;
54 dl->top = (u8*) start + length;
55 dl->length = length;
56 }
57
58 // Makes sure current DL is flushed out of cache (on HW)
GDFlushCurrToMem()59 void GDFlushCurrToMem()
60 {
61 #ifndef WIN32
62 DCFlushRange(__GDCurrentDL->start, __GDCurrentDL->length);
63 #endif
64 }
65
66 // Pads current DL out to 32B
GDPadCurr32()67 void GDPadCurr32()
68 {
69 u32 n = ((u32) __GDCurrentDL->ptr & 31);
70 if (n)
71 {
72 for(; n<32; n++)
73 {
74 __GDWrite(0);
75 }
76 }
77 }
78
79 // Overflow-related functions
GDOverflowed()80 void GDOverflowed()
81 {
82 if (overflowcb)
83 {
84 (*overflowcb)();
85 } else {
86 ASSERTMSG(0, "GDWrite: display list overflowed");
87 }
88 }
89
GDSetOverflowCallback(GDOverflowCallback callback)90 void GDSetOverflowCallback(GDOverflowCallback callback)
91 {
92 overflowcb = callback;
93 }
94
GDGetOverflowCallback(void)95 GDOverflowCallback GDGetOverflowCallback( void )
96 {
97 return overflowcb;
98 }
99