From: Spiro Trikaliotis (spiro_at_ivs.cs.uni-magdeburg.de)
Date: 2003-03-05 16:57:23
Hello, adding to what Uz said: Greg Long wrote: > The Merge and Quick sort algorithms > are faster, but waste memory...up to twice the ammount of the original > array. Well, where do they waste memory? In the needed stack size, or elsewhere? > (Now how do I overload the < and > operators in C?) You can't. Overloading in general and overloading built-in operations in particular are C++-specific extensions not available to C. > Known bugs: > ----------- > 1) cprintf does not appear to work properly : replace \r with \n and > watch the results. MV already told you what you have to do: Use \r\n instead. > //Code below > void stopwatch_reset(); [...] > unsigned long stopwatch(); [...] > int main() Although not really necessary, I suggest using a void parameter instead of an empty parameter list. In C++, this is the same, but it is not in C. In C, it means the function can take any parameter, which seems not to be the thing you meant, did you? > //bank out BASIC interpreter > a = PEEK(1); > POKE(1,a&254); I rather would code it something like: unsigned char *pP6510IO = 1; and then *pP6510IO &= 0xFE; This looks much more "C-like" (or "C++-like") to me. > //stores # of seconds in locations 1020-1021 > POKEW(1020,secs); Here, something similar like above applies. > //re-enable BASIC interpreter > a = PEEK(1); > POKE(1,a|1); *pP6510IO |= 0x01; > unsigned long stopwatch() > { > unsigned long sw_time = 0; > > sw_time += ((unsigned long)PEEK(160)) * 0x10000; > sw_time += ((unsigned long)PEEK(161)) * 0x100; > sw_time += (unsigned long)PEEK(162); > > return sw_time; > } Is the counter really in this order (160 = high byte, 162 = low byte)? If yes, what about: unsigned char *pTimer = 160; sw_time = (((unsigned long)pTimer[0]) << 16) | (((unsigned long)pTimer[1]) << 8) | pTimer[2]; On many architectures, this results in much faster code. I'm not sure about CC65 (haven't tested it). If the counter were in the order 160 = low byte, 162 = high byte, I even suggest: unsigned long *pTimer = 160; sw_time = (*pTimer) & 0xFFFFFFl; > char quit=0; > > while(!quit) [...] Since the condition is true on first invocation, I would suggest rewriting the loop to char quit = 0; do { ... } while (!quit); This way, it is more understandable what your intention was. Spiro. ---------------------------------------------------------------------- To unsubscribe from the list send mail to majordomo_at_musoftware.de with the string "unsubscribe cc65" in the body(!) of the mail.
This archive was generated by hypermail 2.1.3 : 2003-03-05 17:30:22 CET