comp.lang.ada
 help / color / mirror / Atom feed
From: cl1 <charles.w.lambert@gmail.com>
Subject: updating a hardware cursor with assembly and ada
Date: Thu, 6 Mar 2008 09:07:02 -0800 (PST)
Date: 2008-03-06T09:07:02-08:00	[thread overview]
Message-ID: <ad7bde49-8e2b-44e5-9fe3-f16a5e7dde4a@m3g2000hsc.googlegroups.com> (raw)

I an trying to learn some operating system development. I have it
booting and printing text to the screen. However, I have an issue with
updating the hardware cursor. It does not update. I can provide the
whole sources if need be, but i believe i am missunderstanding
something in Ada. The tutorial I am learning from is written in C and
for the most part its pretty easy converting it to ada. The code i'm
having an issue with follows. The important parts are outportb in the
c files and Update_Cursor in the vga package body.

// this is the way the tutorial updated the hardware cursor. My
version is
// in the Vga package called Update_Cursor
// void move_csr(void)
// {
//   unsigned temp;
//   temp = csr_y * 80 + csr_x; // csr_y and csr_x are global
variables
//
//   outportb(0x3D4, 14);
//   outportb(0x3D5, temp >> 8);
//   outportb(0x3D4, 15);
//   outportb(0x3D5, temp);
// }

// port.h
#ifndef __PORT_H
#define __PORT_H
extern unsigned char inportb (unsigned short _port);
extern void outportb (unsigned short _port, usigned char _data);

// port.c
#include "port.h"

unsigned char inportb (unsigned short _port)
{
 unsigned char rv;
 __asm__ __volatile__ ("inb %1, %0" : "=a" (rv) : "dN" (_port));
 return rv;
}

unsigned char outportb (unsigned short _port, unsigned char _data)
{
 __asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), "a" (_data));
}

-- vga.ads
package Vga is
 
-----------------------------------------------------------------------------
  type Color is (
     Black,         -- 0000
     Blue,          -- 0001
     Green,         -- 0010
     Cyan,          -- 0011
     Red,           -- 0100
     Magenta,       -- 0101
     Brown,         -- 0110
     Light_Grey,    -- 0111
     Dark_Grey,     -- 1000
     Light_Blue,    -- 1001
     Light_Green,   -- 1010
     Light_Cyan,    -- 1011
     Light_Red,     -- 1100
     Light_Magenta, -- 1101
     Light_Brown,   -- 1110
     White);        -- 1111

  for Color use (
     Black         => 16#0#,
     Blue          => 16#1#,
     Green         => 16#2#,
     Cyan          => 16#3#,
     Red           => 16#4#,
     Magenta       => 16#5#,
     Brown         => 16#6#,
     Light_Grey    => 16#7#,
     Dark_Grey     => 16#8#,
     Light_Blue    => 16#9#,
     Light_Green   => 16#A#,
     Light_Cyan    => 16#B#,
     Light_Red     => 16#C#,
     Light_Magenta => 16#D#,
     Light_Brown   => 16#E#,
     White         => 16#F#);

  for Color'Size use 4;
 
-----------------------------------------------------------------------------
  subtype Background_Color is Color range Color'First..Light_Grey;


  subtype Row is Positive range Positive'First..25;
  subtype Column is Positive range Positive'First..80;
 
-----------------------------------------------------------------------------
  type Video_Console is
     record
        Foreground : Color := White;
        Background : Background_Color := Black;
        Row : Vga.Row := Vga.Row'First;
        Column : Vga.Column := Vga.Column'First;
     end record;

  procedure Clear(Console : in out Video_Console);
  procedure Put(Console : in out Video_Console; S : String);
 
-----------------------------------------------------------------------------
end Vga;

-- vga.adb
with System;
package body Vga is
 
-----------------------------------------------------------------------------
  type Video_Character is
     record
        Foreground : Color;
        Background : Background_Color;
        Glyph      : Character;
     end record;

  for Video_Character use
     record
        Foreground at 0 range 8..11;
        Background at 0 range 12..15;
        Glyph      at 0 range 0..7;
     end record;

  for Video_Character'Size use 16;
 
-----------------------------------------------------------------------------
  Video_Memory : array (Row'Range, Column'Range) of Video_Character;

  for Video_Memory'Address use System'To_Address (16#000B8000#);

  pragma Import (Ada, Video_Memory);
 
-----------------------------------------------------------------------------
  procedure Update_Cursor (Console : Video_Console) is
     procedure OutportB (Port : Natural; Data : Natural);
     pragma Import(C, OutportB, "outportB");

     Data : Natural := Console.Column * 80 + Console.Row;
  begin
     OutportB ( 16#3D4#, 14);
     OutportB ( 16#3D5#, Data / 2 ** 8);
     OutportB ( 16#3D4#, 15);
     OutportB ( 16#3D5#, Data);
  end Update_Cursor;
 
-----------------------------------------------------------------------------
  procedure Clear (Console : in out Video_Console) is
     Clear_Character : Video_Character := (
       Foreground => Console.Foreground,
       Background => Console.Background,
       Glyph      => ' ');
  begin
     for R in Row'Range loop
        for C in Column'Range loop
           Video_Memory (R, C) := Clear_Character;
        end loop;
     end loop;
     Console.Row := Row'First;
     Console.Column := Column'First;
     Update_Cursor(Console);
  end Clear;
 
-----------------------------------------------------------------------------
  procedure Put (Console : in out Video_Console;
                        C           :        Character) is
     V : Video_Character := (
       Foreground => Console.Foreground,
       Background => Console.Background,
       Glyph      => C);
     Tmp : Positive := Console.Column + 1;
  begin
     Video_Memory(Console.Row, Console.Column) := V;
     if Tmp > Column'Last then
        Console.Column := Column'First;
        Console.Row := Row'Succ(Console.Row);
     else
        Console.Column := Column'Succ(Console.Column);
     end if;
     Update_Cursor(Console);
  end Put;
 
-----------------------------------------------------------------------------
  procedure Put (Console : in out Video_Console; S : String) is
  begin
     for I in S'Range loop
        Put (Console, S (I));
     end loop;
  end Put;
 
-----------------------------------------------------------------------------
end Vga;



             reply	other threads:[~2008-03-06 17:07 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-06 17:07 cl1 [this message]
2008-03-06 17:26 ` updating a hardware cursor with assembly and ada Georg Bauhaus
2008-03-06 17:51   ` cl1
2008-03-06 21:31     ` Adam Beneschan
2008-03-06 19:39 ` Jeffrey R. Carter
2008-03-06 20:08 ` Gautier
2008-03-06 20:14 ` Gautier
2008-03-06 22:54   ` Ludovic Brenta
2008-03-07 15:26 ` cl1
2008-03-07 19:01 ` cl1
2008-03-07 20:16   ` Ludovic Brenta
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox