[WIP] Improve knightos/display.h#23
Conversation
Implemented in C since I don't know if the kernel supports it natively.
There was a problem hiding this comment.
Honestly, it'd probably be better to write this in asm and expose a small C interface. SDCC 4 is a lot better with codegen, but it still reeks compared to hand-written (and we're not on it, just yet).
If you'd rather not redo this, I get it, and I'm happy to merge as is after testing a bit.
| } | ||
|
|
||
| void draw_float(SCREEN* screen, unsigned char x, unsigned char y, float value){ | ||
| /* Implementation is weird and slow because of non-working snprintf. Indeed, %f format strings are not yet implemented */ |
There was a problem hiding this comment.
%f doesn't work at all (it's ignored). I don't know if it is standard, but every libc I know supports it. And it really is useful.
There was a problem hiding this comment.
I can't remember why we didn't implement %f, and there's probably a good reason, but you may want to experiment with https://github.com/KnightOS/libc/blob/master/src/format.c
There was a problem hiding this comment.
Worst case, I'd like to see %f support using this function as a base.
There was a problem hiding this comment.
Actually, this function has a major issue :
it does not support floats whose integer part is greater than INT_MAX...
In order to have full float support, I would have to go char by char... which may be even slower 😞
There was a problem hiding this comment.
Let me know when this PR is done.
There was a problem hiding this comment.
Yup, I will do. If you have any idea on a fast implementation for that, I'm all ears 😝
There was a problem hiding this comment.
First idea: don't worry about fast. It can be sped up later if we need to.
There was a problem hiding this comment.
Let me know when this is ready for another review :)
There was a problem hiding this comment.
Perhaps in a few other years 😆
|
I may try to do the signed integer one in ASM. But for floats it may be a little hard. |
|
@aviallon fyi @pixelherodev and I are active on IRC. #knightos on freenode.net |
Are you interested in a Matrix group? (IRC bridges are easy to set up and officially supported) I'm coming soon. |
|
Needs to be updated now that e.g. log10 is in libc. |
|
WTF happened (somehow I had random commits in my PR) |
6355594 to
a35754c
Compare
|
Updated to use log10u. I am in the process to try to make a draw_float able to display any floats, but it certainly is not trivial ! I got some ideas though... |
|
|
||
| /** | ||
| * Draws a long at x, y | ||
| * NYI |
There was a problem hiding this comment.
TODO is better, it's more commonly used
| value = -value; | ||
| } | ||
| draw_short(screen, x, y, value); | ||
| return; |
There was a problem hiding this comment.
Reaching the end of a function returning void is equivalent to return;. Reaching the end of any other value-returning function is undefined behavior if the result of the function is used in an expression (it is allowed to discard such return value). For main, see main function.
https://cppreference.com/w/c/language/return.html
I got bitten by non-standard conforming compilers that behaved incorrectly with void functions in the past.
| } | ||
|
|
||
| void draw_float(SCREEN* screen, unsigned char x, unsigned char y, float value){ | ||
| /* Implementation is weird and slow because of non-working snprintf. Indeed, %f format strings are not yet implemented */ |
There was a problem hiding this comment.
Let me know when this is ready for another review :)
Implemented several functions in C since I don't know if the kernel supports it natively.