very low-level fraction convertions
Posted: Mon May 23, 2011 12:46 pm
I'm using a double in my kernel code, and I need to convert it to an int. The standard type-casting does not seem to work (or am I wrong?). How do I convert a double into an int (I want to remove the fraction part). Or perhaps someone knows how else I could improve the following code:
Any help?
EDIT: Oh yeah, I forgot... i'll post a screenshot to show what this 'masterpiece' does:
Code: Select all
/*
splash.h
Atom user-friendly loading screen.
When kernel debugging is disabled, a more
user-friendly loading screen (known as a splash
screen) is displayed to let the user know that
something is happening (a black screen may cause
users to lose patience).
*/
#ifndef _SPLASH_H
#define _SPLASH_H
#include <atom/kernel.h>
#include <atom/konsole.h>
#include <config/splash.conf>
#define SLD_XOFF (80/2)-(SLD_WIDTH/2)
#define SLD_XEND (80/2)+(SLD_WIDTH/2)
typedef struct splash_action_struct
{
void (*callback)(int);
int arg;
} splash_action_t;
double splash_single_len;
double splash_count_actions(splash_action_t actions[])
{
double count=0;
int i=0;
while (1)
{
if (actions[i++].callback == NULL) return count;
else count += 1.0;
};
};
void splash_draw_bar(int x, int y, int width, u8int attr)
{
unsigned char * vidmem = (unsigned char *) 0xb8000;
int loc = (((y * width) + x) * 2) + 1;
printdec(loc);
while (width--)
{
vidmem[loc] = attr;
loc += 2;
};
putk(' ');
};
void splash_init(splash_action_t actions[])
{
konsole_clear(SLD_ATTR);
splash_single_len = (1.0/splash_count_actions(actions))*((float)SLD_WIDTH);
int textoff = (80/2)-(strlen(SLD_MSG)/2);
konsole_status.x = textoff;
konsole_status.y = 18;
printk(SLD_MSG);
splash_draw_bar(SLD_XOFF, 80, SLD_WIDTH, SLD_BACK);
int i;
double barwidth=0;
for (i=0; i<splash_count_actions(actions); i++)
{
splash_draw_bar(SLD_XOFF, 80, barwidth, SLD_COLOR);
actions[i].callback(actions[i].arg);
barwidth += splash_single_len;
};
};
#endif
EDIT: Oh yeah, I forgot... i'll post a screenshot to show what this 'masterpiece' does: