completely finished the documentation of the EBUF module (!)
[neuro.git] / src / video / debug.c
blob176316061503b9222ab4fee308b0caf30787d9cc
1 /*
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
22 /* debug.c
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 --------------------------*/
37 #include "video.h"
38 #include <graphics.h>
41 /*-------------------- Other ----------------------------*/
43 /*-------------------- Global Variables ----------------------------*/
45 /*-------------------- Static Variables ----------------------------*/
47 /*-------------------- Static Prototypes ---------------------------*/
51 /*-------------------- Static Functions ----------------------------*/
53 /*-------------------- Global Functions ----------------------------*/
55 /* debug function */
56 void
57 Graphics_DebugPrintQueue()
59 INSTRUCTION_ENGINE *cur;
61 if (Neuro_EBufIsEmpty(Graphics_GetQueueBuffer()))
62 return;
63 /* cur = Neuro_GiveEBuf(_Queue, 0); */
64 cur = Graphics_GetFirstElem();
65 /* printf("Queue address %d\n", (int)cur); */
67 while (cur != NULL)
69 /*if (cur->current->type == TDRAW_SDRAWN)
71 cur = cur->next;
72 continue;
73 }*/
75 Debug_Val(0, "layer #%d address &%x type %d\n", cur->current->layer, cur,
76 cur->current->type);
78 if (cur->next == Graphics_GetFirstElem())
80 Debug_Val(0, "Error- this element points to the beginning element\n");
81 break;
83 else
84 cur = cur->next;
88 void
89 Graphics_DebugBufferQueue(EBUF *src)
91 INSTRUCTION_ENGINE *cur;
93 if (Neuro_EBufIsEmpty(Graphics_GetQueueBuffer()))
94 return;
96 cur = Graphics_GetFirstElem();
98 if (verbose_missing_output == 1)
100 Debug_Val(0, "Outputting initial queue for missing data\n");
103 while (cur != NULL)
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");
122 break;
124 else
125 cur = cur->next;
129 void
130 Graphics_DebugPrintMissing(EBUF *src)
132 INSTRUCTION_ENGINE *cur;
133 debug_status *tmp;
134 EBUF *missing_list;
135 u32 total;
136 u8 found = 0;
138 if (Neuro_EBufIsEmpty(Graphics_GetQueueBuffer()))
139 return;
141 if (Neuro_EBufIsEmpty(src))
142 return;
144 Neuro_CreateEBuf(&missing_list);
146 cur = Graphics_GetFirstElem();
148 while (cur != NULL)
150 total = Neuro_GiveEBufCount(src) - 1;
151 found = 0;
153 while (total-- > 0)
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"); */
161 found++;
163 /*else
164 Debug_Val(0, "no\n");*/
167 if (found == 0)
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;
178 else if (found > 1)
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");
193 break;
195 else
196 cur = cur->next;
199 /* now that we filled the missing_list buffer, we can output
200 * its data.
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()));
211 else
213 Debug_Val(0, "NO missing/destroyed/duplicate addresses!\n");
214 total = 0;
215 Neuro_CleanEBuf(&missing_list);
216 return;
219 total--;
221 while (total-- > 0)
223 struct debug_status *dstmp = NULL;
225 dstmp = Neuro_GiveEBuf(missing_list, total);
227 if (!dstmp)
228 continue;
230 if (dstmp->duplicates == 0)
231 Debug_Val(0, "the address 0x%x is missing\n", dstmp->missing);
232 else
233 Debug_Val(0, "the address 0x%x is present %d times\n",
234 dstmp->duplicates);
237 Neuro_CleanEBuf(&missing_list);
240 void
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
256 from its buffer */
257 u8 correct_raw_and_queue = 0; /* the raw data are all contained in the
258 queue */
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
263 * from the ebuf.
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
273 * for those.
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");
297 return;
300 /* we start to check the queue integrity
301 * -- correct_queue_integ
303 cur = Graphics_GetFirstElem();
304 correct_queue_integ = 1;
306 while (cur != NULL)
309 if (cur->current == NULL)
310 correct_queue_integ = 0;
312 cur = cur->next;
315 /* now we check if the last element is the
316 * correct one.
317 * -- correct_last_elem
319 cur = Graphics_GetFirstElem();
321 while (cur != NULL)
324 if (cur->next == NULL)
326 if (cur == Graphics_GetLastElem())
327 correct_last_elem = 1;
329 break;
332 cur = cur->next;
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;
343 while (qtotal-- > 0)
345 raw = Neuro_GiveEBuf(Graphics_GetQueueBuffer(), qtotal);
347 cur = Graphics_GetFirstElem();
348 temp = 0;
350 while (cur != NULL)
352 if (cur == raw)
353 temp = 1;
355 cur = cur->next;
358 if (temp == 0)
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;
369 while (rtotal-- > 0)
371 data = Neuro_GiveEBuf(Graphics_GetRawBuffer(), rtotal);
373 qtotal = Neuro_GiveEBufCount(Graphics_GetQueueBuffer()) - 1;
375 temp = 0;
377 while (qtotal-- > 0)
379 raw = Neuro_GiveEBuf(Graphics_GetQueueBuffer(), qtotal);
381 if (raw->current == data)
382 temp = 1;
385 if (temp == 0)
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();
395 temp = 0;
397 while (cur != NULL)
400 if (cur->current)
402 if (cur->current->layer < temp)
403 correct_order_queue = 0;
405 temp = cur->current->layer;
408 cur = cur->next;
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);