On Sat, Feb 10, 2007 at 05:58:38PM -0500, Jac Ato wrote: > In an attempt to implement the printf function on my embedded system, > I wanted to reroute any queries that are sent through printf to my > serial function: uart_send_char(char c). But I have failed to do > exactly that. I've noticed that on the platform that I am working on, > a modified NES with a serial port, I cannot get cc65 to generate a > working binary file with the code below. It just wont get to the part > of the write function. This was checked through my NES simulator. So > what is the best way of doing the above idea? The call hierarchy is: printf -> vfprintf -> _printf -> fwrite -> write This means: printf uses fwrite for output, which in turn calls write. So I would first try to call fwrite and check if your write function is called. > int __fastcall__ write (int fd, const void* buf, unsigned count){ > char* temp=buf; > char i=0; > do{uart_send_char(temp[i++]);} > while(count--); > } > > I know that fastcall will get the right most parameter (is it count?) > from a register instead of the stack, so that my implementation is > probably wrong. The implementation is wrong because write() must return the number of bytes written, or EOF (-1) as an error code. Anyway, the function should be called at least once. You may want to try something like this instead: int __fastcall__ write (int fd, const void* buf, unsigned count) { unsigned i = 0; while (i < count) { uart_send_char (((const char*) buf)[i]); ++i; } return count; } > Also, what does fd represents? The file descriptor. For a quick solution, you can ignore it. Older runtime library implementations for the Commodore machines did so in the times before actual file I/O was implemented. Regards Uz -- Ullrich von Bassewitz uz@musoftware.de ---------------------------------------------------------------------- To unsubscribe from the list send mail to majordomo@musoftware.de with the string "unsubscribe cc65" in the body(!) of the mail.Received on Sun Feb 11 15:37:33 2007
This archive was generated by hypermail 2.1.8 : 2007-02-11 15:37:37 CET