2 * libneuro, a light weight abstraction of high or lower libraries
3 * and toolkit for applications.
4 * Copyright (C) 2005-2006 Nicholas Niro, Robert Lemay
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 * debugging functions (mostly dumps and checks) for
25 * the painter's algorithm mainly and will probably
26 * be home to all the debugging function for the
27 * whole graphics module.
30 /*-------------------- Extern Headers Including --------------------*/
31 #include <ebuf.h> /* we use the normal allocation functions from this */
32 #include <debug.h> /* we use the function Debug_Val */
34 /*-------------------- Local Headers Including ---------------------*/
36 /*-------------------- Main Module Header --------------------------*/
41 /*-------------------- Other ----------------------------*/
43 /*-------------------- Global Variables ----------------------------*/
45 /*-------------------- Static Variables ----------------------------*/
47 /*-------------------- Static Prototypes ---------------------------*/
51 /*-------------------- Static Functions ----------------------------*/
53 /*-------------------- Global Functions ----------------------------*/
57 Graphics_DebugPrintQueue()
59 INSTRUCTION_ENGINE
*cur
;
61 if (Neuro_EBufIsEmpty(Graphics_GetQueueBuffer()))
63 /* cur = Neuro_GiveEBuf(_Queue, 0); */
64 cur
= Graphics_GetFirstElem();
65 /* printf("Queue address %d\n", (int)cur); */
69 /*if (cur->current->type == TDRAW_SDRAWN)
75 Debug_Val(0, "layer #%d address &%x type %d\n", cur
->current
->layer
, cur
,
78 if (cur
->next
== Graphics_GetFirstElem())
80 Debug_Val(0, "Error- this element points to the beginning element\n");
89 Graphics_DebugBufferQueue(EBUF
*src
)
91 INSTRUCTION_ENGINE
*cur
;
93 if (Neuro_EBufIsEmpty(Graphics_GetQueueBuffer()))
96 cur
= Graphics_GetFirstElem();
98 if (verbose_missing_output
== 1)
100 Debug_Val(0, "Outputting initial queue for missing data\n");
105 debug_status
*tmp
= NULL
;
106 Neuro_AllocEBuf(src
, sizeof(debug_status
*), sizeof(debug_status
));
108 tmp
= Neuro_GiveCurEBuf(src
);
110 /* memcpy(tmp, cur, sizeof(INSTRUCTION_ENGINE*)); */
111 tmp
->missing
= (u32
)cur
;
113 if (verbose_missing_output
== 1)
115 Debug_Val(0, "layer #%d address &%x (%x) type %d\n", cur
->current
->layer
, cur
,
116 tmp
->missing
, cur
->current
->type
);
119 if (cur
->next
== Graphics_GetFirstElem())
121 Debug_Val(0, "Error- this element points to the beginning element\n");
130 Graphics_DebugPrintMissing(EBUF
*src
)
132 INSTRUCTION_ENGINE
*cur
;
138 if (Neuro_EBufIsEmpty(Graphics_GetQueueBuffer()))
141 if (Neuro_EBufIsEmpty(src
))
144 Neuro_CreateEBuf(&missing_list
);
146 cur
= Graphics_GetFirstElem();
150 total
= Neuro_GiveEBufCount(src
) - 1;
155 tmp
= Neuro_GiveEBuf(src
, total
);
157 /* Debug_Val(0, "is 0x%x the same as 0x%x? ", tmp->missing, cur); */
158 if (tmp
->missing
== (u32
)cur
)
160 /* Debug_Val(0, "yes\n"); */
164 Debug_Val(0, "no\n");*/
169 struct debug_status
*dstmp
;
170 Neuro_AllocEBuf(missing_list
, sizeof(struct debug_status
*), sizeof(struct debug_status
));
172 dstmp
= Neuro_GiveCurEBuf(missing_list
);
174 dstmp
->missing
= (u32
)cur
;
176 dstmp
->duplicates
= 0;
180 struct debug_status
*dstmp
;
181 Neuro_AllocEBuf(missing_list
, sizeof(struct debug_status
*), sizeof(struct debug_status
));
183 dstmp
= Neuro_GiveCurEBuf(missing_list
);
185 dstmp
->missing
= (u32
)cur
;
187 dstmp
->duplicates
= found
;
190 if (cur
->next
== Graphics_GetFirstElem())
192 Error_Print("This element points to the beginning element\n");
199 /* now that we filled the missing_list buffer, we can output
203 Debug_Print("Debug queue status report");
205 if (!Neuro_EBufIsEmpty(missing_list
))
207 total
= Neuro_GiveEBufCount(missing_list
);
208 Debug_Val(0, "We found %d missing/destroyed/duplicate addresses on %d\n", total
,
209 Neuro_GiveEBufCount(Graphics_GetQueueBuffer()));
213 Debug_Val(0, "NO missing/destroyed/duplicate addresses!\n");
215 Neuro_CleanEBuf(&missing_list
);
223 struct debug_status
*dstmp
= NULL
;
225 dstmp
= Neuro_GiveEBuf(missing_list
, total
);
230 if (dstmp
->duplicates
== 0)
231 Debug_Val(0, "the address 0x%x is missing\n", dstmp
->missing
);
233 Debug_Val(0, "the address 0x%x is present %d times\n",
237 Neuro_CleanEBuf(&missing_list
);
241 Graphics_DebugQueueIntegrityCheck()
243 INSTRUCTION_ENGINE
*cur
; /* ordered element from the queue */
244 u32 qtotal
; /* the queue engine buffer total decrementor */
245 INSTRUCTION_ENGINE
*raw
; /* unordered element from the buffer */
246 RAW_ENGINE
*data
; /* the raw data pointer */
247 u32 rtotal
; /* the raw engine buffer total decrementor */
248 u8 temp
; /* used in the tests */
250 /* those are booleans for the report this function will give */
251 u8 correct_queue_integ
= 0; /* integrity of the queue data;
252 ie the content of each exist and
253 it exists in the raw_engine buffer */
254 u8 correct_last_elem
= 0; /* specific */
255 u8 correct_queue_and_buffer
= 0; /* the queue contains all the elements
257 u8 correct_raw_and_queue
= 0; /* the raw data are all contained in the
259 u8 correct_order_queue
= 0; /* the queue has the correct ordering */
261 /* this function will check the queue's
262 * elements with all the unordered elements
265 * -- correct_queue_integ
266 * It will first check if all the elements in
267 * the queue exist in the ebuf and if the raw
268 * content they contain also exist.
270 * -- correct_last_elem
271 * It will also check if the first and last
272 * elements are the same as the variables pointers
275 * -- correct_queue_and_buffer
276 * It will then see if all the unordered ebuf queue
277 * elements are contained (linked) in the ordered queue.
279 * -- correct_raw_and_queue
280 * It will check if ALL the elements from the RAW_ENGINE
281 * buffer are contained in the unordered queue buffer.
283 * -- correct_order_queue
284 * It will check if the order of the ordered queue is good.
286 * Take good note that this integrity check should in fact
287 * have its own module because we can't currently easily
288 * see if the first_element is correct or no...
290 * We currently ASSUME the first_element is correct and non
291 * NULL or else we don't do any tests.
294 if (Graphics_GetFirstElem
== NULL
)
296 Error_Print("failed, first_element is NULL");
300 /* we start to check the queue integrity
301 * -- correct_queue_integ
303 cur
= Graphics_GetFirstElem();
304 correct_queue_integ
= 1;
309 if (cur
->current
== NULL
)
310 correct_queue_integ
= 0;
315 /* now we check if the last element is the
317 * -- correct_last_elem
319 cur
= Graphics_GetFirstElem();
324 if (cur
->next
== NULL
)
326 if (cur
== Graphics_GetLastElem())
327 correct_last_elem
= 1;
335 /* It will then see if all the unordered ebuf queue
336 * elements are contained (linked) in the ordered queue.
337 * -- correct_queue_and_buffer
339 correct_queue_and_buffer
= 1;
341 qtotal
= Neuro_GiveEBufCount(Graphics_GetQueueBuffer()) - 1;
345 raw
= Neuro_GiveEBuf(Graphics_GetQueueBuffer(), qtotal
);
347 cur
= Graphics_GetFirstElem();
359 correct_queue_and_buffer
= 0;
362 /* It will check if ALL the elements from the RAW_ENGINE
363 * buffer are contained in the unordered queue buffer.
364 * -- correct_raw_and_queue
366 rtotal
= Neuro_GiveEBufCount(Graphics_GetRawBuffer()) - 1;
367 correct_raw_and_queue
= 1;
371 data
= Neuro_GiveEBuf(Graphics_GetRawBuffer(), rtotal
);
373 qtotal
= Neuro_GiveEBufCount(Graphics_GetQueueBuffer()) - 1;
379 raw
= Neuro_GiveEBuf(Graphics_GetQueueBuffer(), qtotal
);
381 if (raw
->current
== data
)
386 correct_raw_and_queue
= 0;
389 * It will check if the order of the ordered queue is good.
390 * -- correct_order_queue
392 correct_order_queue
= 1;
394 cur
= Graphics_GetFirstElem();
402 if (cur
->current
->layer
< temp
)
403 correct_order_queue
= 0;
405 temp
= cur
->current
->layer
;
411 /* now we output our report */
412 Debug_Print("Data Integrity Check Report");
414 Debug_Val(0, "Queue integrity : %d\n", correct_queue_integ
);
415 Debug_Val(0, "Correct last element : %d\n", correct_last_elem
);
416 Debug_Val(0, "Queue and its buffer : %d\n", correct_queue_and_buffer
);
417 Debug_Val(0, "Raw and Queue buffer presence : %d\n", correct_raw_and_queue
);
418 Debug_Val(0, "Order of the queue : %d\n", correct_order_queue
);