-
Notifications
You must be signed in to change notification settings - Fork 15
[WIP] Improve knightos/display.h #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,8 +97,20 @@ void draw_short(SCREEN *screen, unsigned char x, unsigned char y, unsigned short | |
| **/ | ||
| void draw_byte(SCREEN *screen, unsigned char x, unsigned char y, unsigned char value); | ||
|
|
||
| /*.* | ||
| /** | ||
| * Draws a signed short at x, y | ||
| **/ | ||
| void draw_signed(SCREEN *screen, unsigned char x, unsigned char y, signed short value); | ||
|
|
||
| /** | ||
| * Draws a float at x,y | ||
| **/ | ||
|
|
||
| void draw_float(SCREEN* screen, unsigned char x, unsigned char y, float value); | ||
|
|
||
| /** | ||
| * Draws a long at x, y | ||
| * NYI | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO is better, it's more commonly used |
||
| **/ | ||
| void draw_long(SCREEN *screen, unsigned char x, unsigned char y, unsigned long value); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -330,6 +330,46 @@ void draw_short(SCREEN *screen, unsigned char x, unsigned char y, unsigned short | |
| screen; x; y; value; | ||
| } | ||
|
|
||
| void draw_signed(SCREEN* screen, unsigned char x, unsigned char y, signed short value) { | ||
| if(value < 0){ | ||
| draw_char(screen, x, y, '-'); | ||
| x += 4; | ||
| value = -value; | ||
| } | ||
| draw_short(screen, x, y, value); | ||
| return; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the explicit return? |
||
| } | ||
|
|
||
| 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @aviallon what was wrong with snprintf? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. %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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Worst case, I'd like to see %f support using this function as a base. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, this function has a major issue : There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let me know when this PR is done. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. First idea: don't worry about fast. It can be sped up later if we need to. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let me know when this is ready for another review :) |
||
| unsigned int integer_part; | ||
| unsigned int frac_part; | ||
| unsigned int integer_part_len; | ||
| bool sgn = (value < 0); | ||
|
|
||
|
|
||
| value = sgn ? -value : value; | ||
|
|
||
| integer_part = (unsigned int)value; | ||
| frac_part = ((value - (float)integer_part)*10000); | ||
|
|
||
| integer_part_len = (log10u(integer_part)) + 1; | ||
|
|
||
| if(sgn){ | ||
| draw_char(screen, x, y, '-'); | ||
| x += 4; | ||
| } | ||
|
|
||
| draw_short(screen, x, y, integer_part); | ||
| x += integer_part_len*4; | ||
| draw_char(screen, x, y, '.'); | ||
|
|
||
| x += 4; | ||
| draw_short(screen, x, y, frac_part); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| void invert_pixel(SCREEN *screen, char x, char y) { | ||
| __asm | ||
| POP BC ; return | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.