1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - GX -
3 File: g3.c
4
5 Copyright 2003-2008 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 $Date:: 2008-09-18#$
14 $Rev: 8573 $
15 $Author: okubata_ryoma $
16 *---------------------------------------------------------------------------*/
17
18 #include <nitro/gx/g3.h>
19
20
21 /*---------------------------------------------------------------------------*
22 Name: G3_BeginMakeDL
23
24 Description: Initialize GXDLInfo before display list generation.
25
26 Arguments: info a pointer to display list info.
27 ptr a pointer to the buffer where a display list is stored
28 length the length of the buffer(in bytes)
29
30 Returns: none
31 *---------------------------------------------------------------------------*/
G3_BeginMakeDL(GXDLInfo * info,void * ptr,u32 length)32 void G3_BeginMakeDL(GXDLInfo *info, void *ptr, u32 length)
33 {
34 SDK_ALIGN4_ASSERT(ptr);
35 SDK_ALIGN4_ASSERT(length);
36
37 info->length = length;
38 info->bottom = (u32 *)ptr;
39 info->curr_cmd = (u8 *)ptr;
40 info->curr_param = (u32 *)ptr + 1;
41 info->param0_cmd_flg = FALSE;
42 }
43
44
45 /*---------------------------------------------------------------------------*
46 Name: G3_EndMakeDL
47
48 Description: Finish generating a display list.
49
50 Arguments: info a pointer to display list info
51
52 Returns: none
53 *---------------------------------------------------------------------------*/
54 #include <nitro/code32.h> // avoid byte access problems
G3_EndMakeDL(GXDLInfo * info)55 u32 G3_EndMakeDL(GXDLInfo *info)
56 {
57 u32 sz;
58 if ((u8 *)info->bottom == info->curr_cmd)
59 {
60 // no display list generated
61 return 0;
62 }
63
64 switch ((u32)info->curr_cmd & 3)
65 {
66 // padding
67 case 0:
68 SDK_ASSERT((u32)info->bottom < (u32)info->curr_cmd);
69 return (u32)((u32)info->curr_cmd - (u32)info->bottom);
70 case 1:
71 *info->curr_cmd++ = 0; // byte access
72 case 2:
73 *info->curr_cmd++ = 0;
74 case 3:
75 *info->curr_cmd++ = 0;
76 };
77
78 // code for hardware bug in geometry fifo.
79 if (info->param0_cmd_flg)
80 {
81 *(u32 *)(info->curr_param++) = 0;
82 info->param0_cmd_flg = FALSE;
83 }
84
85 info->curr_cmd = (u8 *)info->curr_param;
86
87 SDK_ASSERT((u32)info->bottom < (u32)info->curr_cmd);
88 SDK_ASSERTMSG(((u32)info->curr_cmd - (u32)info->bottom <= info->length),
89 "Buffer overflow ! : Current DL buffer doesn't have enough capacity for new commands\n");
90
91 sz = (u32)((u32)info->curr_cmd - (u32)info->bottom);
92
93 return sz;
94 }
95
96 #include <nitro/codereset.h>
97