/*
    exDOS - Experimental 32 Bit protected mode scripted operating system
    (C) 2005 Jason Hunt
    
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

    Contact: nulluser@gmail.com

    File: stdio.c
*/

#include "types.h"
#include "video.h"
#include "keyboard.h"

dword rand_seed = 0x12345678;



/* Return the next random number */
word rand( void )
{
    rand_seed = rand_seed * 1103515245 + 12345;
       
    return ((rand_seed >> 16) & 0x7FFF); 
}
/* End of rand */



/* Display a char */
inline void putchar( byte c )
{
    vga_put_char(c);
}
/* End of putchar */


/* Wait for a char and return */
inline byte getchar( void )
{
    return(key_get_char());
}
/* End of getchar */


/* Display a string */
inline void puts(char *s)
{
    vga_put_str(s); 
}
/* End of puts */


/* Get a line of input */
inline void getline(char *l, byte max)
{
    key_get_line(l, max);      
}
/* End of getline */
        
        
/* Returns true if a key is down */
byte kbhit( void )
{
    return(key_hit());
}
/* End of key_hit */

   
/* Compare two strings */
int strcmp(char *s1, char *s2)
{
    while (*s1 == *s2)
    {
        if (!*s1 || !*s2) return(0);
            
        s1++;
        s2++;
    }
                
    return(*s1 - *s2);        
}
/* End of strcmp */
        
        
        
/* Convert to lower case */
byte to_lower(byte c)
{
    if (c >= 'A' && c <= 'Z')
        return(c | 0x20);
    else 
        return(c);
}
/* end of to_lower */


void prints(char *s1, char *s2)
{
    puts(s1);
    puts(s2);
    putchar('\n');
}

void printb(char *s1, byte b)
{
    puts(s1);
    vga_put_hex(b);
    putchar('\n');
}

void printw(char *s1, word w)
{
    puts(s1);
    vga_put_hex_16(w);
    putchar('\n');
}


void printd(char *s1, dword d)
{
    puts(s1);
    vga_put_hex_32(d);
    putchar('\n');
}

word strlen(byte *s)
{
    word l = 0;
    while (*s++) l++;
    return(l);
}
        
void  strncpy(byte *s1, byte *s2, word n)
{
    if (!n) return;

    n--;  // make room for null

    while (*s2 && n--)
        *s1++ = *s2++;

    *s1++ = NULL;
}

     














