Category : Miscellaneous Language Source Code
Archive   : DPADA.ZIP
Filename : DISPBD.ADA

 
Output of file : DISPBD.ADA contained in archive : DPADA.ZIP
with text_io;
use text_io;

package body display is

package io is new integer_io (integer);
use io;

xr1 : constant integer := 18;
xr2 : constant integer := 79;

procedure clear_screen is
begin
put_line (ascii.esc & "[2J");
end clear_screen;

procedure set_position (x,y : integer) is
begin
put (ascii.esc);
put ('[');
if y > 9 then
put (character'val ((y / 10) + character'pos ('0')));
end if;
put (character'val ((y mod 10) + character'pos ('0')));
put (';');
if x > 9 then
put (character'val ((x / 10) + character'pos ('0')));
end if;
put (character'val ((x mod 10) + character'pos ('0')));
put ('f');
end set_position;

procedure set_char (x : x_coord; y : y_coord; ch : character) is
begin
set_position (x, y);
put (ch);
new_line;
end set_char;

procedure initialise_screen is
x : x_coord;
begin
clear_screen;
put (ascii.esc & "[7m");
for lx in xr1 .. xr2
loop
set_char (lx, 1, ' ');
set_char (lx, 23, ' ');
end loop;
for y in 2 .. 22
loop
x := xr1;
set_char (x, y, ' ');
x := xr2;
set_char (x, y, ' ');
end loop;
put (ascii.esc & "[0m");
x := xr1 + 5;
set_position (x, 1);
put (" The Dining Philosophers ");
-- draw the door
for y in y_door-1 .. y_door + 1
loop
set_char (x_door, y, ' ');
end loop;
-- draw the table
x := x_table - table_width / 2;
for y in y_table - table_height / 2 .. y_table + table_height / 2
loop
set_position (x+1, y);
put (ascii.esc & "[7m");
put_line (" " & ascii.esc & "[m");
end loop;

end initialise_screen;

task body display_task is
phil_terminated : integer := 0;
x : x_coord;
y : y_coord;
p1 : position;
p2 : position;
p : phil_id;
st : phil_state;
fk : fork;
i : integer;
b : boolean;
begin
initialise_screen;
loop
begin
select
accept show_state (i : phil_id; s : phil_state) do
p := i;
st := s;
end show_state;
x := xr1 + 39;
set_position (x, 4*p+1);
put ('p');
put (P, width => 1);
put (": ");
case st is
when thinking =>
put ("Thinking ");
when going_to_eat =>
put ("Going to eat ");
when waiting_at_door =>
put ("Waiting at door ");
when getting_lh_fork =>
put ("Getting lh fork ");
when getting_rh_fork =>
put ("Getting rh fork ");
when eating =>
put ("Eating ");
when leaving_the_room =>
put ("Leaving the room");
when terminated =>
put ("Full up ");
end case;
new_line;
or
accept show_occupancy (full : boolean; c : integer) do
b := full;
i := c;
end show_occupancy;
x := xr1 + 5;
set_position (x, 22);
if not b then
put ("Number of phils in room = ");
put (i, width => 1);
put (" ");
else
put ("Room full and ");
put (i, width => 1);
put (" philosopher waiting");
end if;
new_line;
or
accept draw_fork (f : fork) do
fk := f;
end draw_fork;
case fk.user is
when 1 =>
x := fk.x;
y := fk.y - 2;
when 2 =>
x := fk.x + 5;
y := fk.y;
when 3 =>
x := fk.x;
y := fk.y + 2;
when 4 =>
x := fk.x - 5;
y := fk.y;
when others =>
null;
end case;
if fk.used then
set_char (fk.x, fk.y, ' ');
set_char (x, y, 'F');
else
set_char (x, y, ' ');
set_char (fk.x, fk.y, 'F');
end if;
or
accept draw_phil (i : phil_id; pos1 : position; pos2 : position) do
p1 := pos1;
p2 := pos2;
p := i;
end draw_phil;
set_char (p2.x, p2.y, character'val(character'pos('0')+p));
set_char (p1.x, p1.y, ' ');
or
accept stopped do
phil_terminated := phil_terminated + 1;
end stopped;
if phil_terminated = 4 then
clear_screen;
set_position (30, 12);
put (" Ada Dining Philosophers");
set_position (30, 14);
put (" Terminated ");
new_line;
end if;
exit when phil_terminated = 4;
end select;
exception
when others =>
raise;
end;
end loop;
end display_task;

begin
null;
end display;


  3 Responses to “Category : Miscellaneous Language Source Code
Archive   : DPADA.ZIP
Filename : DISPBD.ADA

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/