/* video.c 
 *
 * Written by Vicente Esteve LLoret <viesllo@inf.upv.es>
 * Copyright (C) Feb, 2003 OCERA Consortium.
 *
 * 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 version 2.
 *
 * Some Visualization Functions.
 */

/*****************************************************************
  
  		  This is the module to write Video Memory
		  and functions to manage strings.

		  It must be implemented the API video interface
		  defined in Documentation directory
		  
******************************************************************/

#include <arch/mprot.h>
#include <rtl_sync.h>
#include <rtl_conf.h>

#ifdef CONFIG_ARM_SA1100
#include <asm/arch/SA-1100.h>
#endif

#ifdef CONFIG_ARM_PXA
#include <asm/arch/pxa-regs.h>
#endif

#include "serial.h"



void output_byte_serial(char byte)
{
   //wait for room in the fifo.
   unsigned long s;   
   rtl_no_interrupts(s);
   while((SERIAL_UTSR0 & UTSR0_TX_HALF_EMPTY) == 0);

   SERIAL_UTDR = byte;
   rtl_restore_interrupts(s);
};

void output_string_serial(char *ptr) 
{
 while (*ptr) {
   output_byte_serial(*ptr);
   ptr++;
 };
};


void printhexa(unsigned long valor)
    {    
    char buf[10];
    char *ptr = &buf[0];
    unsigned long hex;
    int despl=28;
    int mascara=0xF0000000;
    ptr[8]=0;
    
    while (despl>=0) 
      {
       hex=(valor & mascara)>>despl;
       if (hex<0xa) 
           {
             *ptr='0'+(char) hex;
             ptr++;
           }
       else
           {
            *ptr='A'+((char) hex-0xa);
            ptr++;
           };          
    
      despl=despl-4;
      mascara=(mascara>>4) & 0x0fffffff;
      };
    ptr=&buf[0];
    output_string_serial(" ");
    output_string_serial(ptr);
    output_string_serial(" ");
    output_byte_serial(10);
    output_byte_serial(13);
    };


void PutChar(unsigned long x,unsigned long y,char car,char attrib)
 {
 }

                 /* Visualiza un String por pantalla en las cordenadas
                    (x,y) y con los atributos de color attrib */

void PutString(unsigned long x,unsigned long y,char *ptr,char attrib)
 {
#if CONFIG_KERNEL_MEMORYPROT   
 mprot_t mprot;
#endif 

 STARTKERNELCODE(mprot);
 
 output_string_serial(ptr);
 output_byte_serial(10);
 output_byte_serial(13);
 
 ENDKERNELCODE(mprot);

}
void DebugString(char *str)
{
#if CONFIG_KERNEL_MEMORYPROT   
  mprot_t mprot;
#endif

  STARTKERNELCODE(mprot);
	
  output_string_serial(str);
  output_byte_serial(10);
  output_byte_serial(13);
  ENDKERNELCODE(mprot);
};

void ClearVHAL(void)
{
}

