[inherit('sys$library:starlet','lib$spawn','smgdefs','smg$repaint_line',
'BB.PEN')]
module setup;

[global] procedure setup;

{This is a housekeeping module for setting up the initial linked lists and
 defining the areas of the terminal display.}

var
  item_test : items;
  length_name : [volatile] integer;
  
begin

  {Set up lists for processing.}
  new(dir_root);
  dir_root^.next:=nil;
  dir_root^.previous:=nil;
  dir_root^.number:=0;

  new(topic_root);
  topic_root^.next:=nil;
  topic_root^.previous:=nil;
  topic_root^.number:=0;

  new(data_root);
  data_root^.next:=nil;
  data_root^.previous:=data_root;
  data_curr:=data_root;

  {Set up logical file pointers from system symbol list}
  with item_test do
    begin
      adr::name_ptr:=address(data_logical);
      retlen::integer_ptr:=address(length_name);
      length:=100;
      code:=lnm$_string;
    end;
  $trnlnm(tabnam:='LNM$DCL_LOGICAL',lognam:='BB$DATA_DIRECTORY',
          itmlst:=item_test);

  item_test.adr::name_ptr:=address(help_logical);
  $trnlnm(tabnam:='LNM$DCL_LOGICAL',lognam:='BB$HELP_DIRECTORY',
          itmlst:=item_test);

  item_test.adr::name_ptr:=address(new_user_logical);
  $trnlnm(tabnam:='LNM$DCL_LOGICAL',lognam:='BB$USER_DIRECTORY',
          itmlst:=item_test);
 
  {set up partitions on screen for screen management routines}
  smg$create_virtual_keyboard(keyboard);
  smg$create_pasteboard(pasteboard);
  smg$control_mode(pasteboard,smg$m_minupd+smg$m_clear_screen+smg$m_notabs);

  smg$create_virtual_display(3,screen_cols,header_display);
  smg$paste_virtual_display(header_display,pasteboard,1,1);

  smg$create_virtual_display(2,screen_cols-17,header_display1,,smg$m_reverse);
  smg$create_virtual_display(2,screen_cols-63,header_display2,,smg$m_reverse);

  smg$create_virtual_display(screen_rows-6,screen_cols,main_display);
  smg$paste_virtual_display(main_display,pasteboard,4,1);

  smg$create_virtual_display(screen_rows-5,screen_cols,message_display);

  smg$create_virtual_display(5,screen_cols-2,broadcast_display,smg$m_border);

  smg$create_virtual_display(1,screen_cols-2,error_display,smg$m_border);
  smg$create_virtual_display(1,screen_cols-2,menu_display,smg$m_border);

  smg$create_virtual_display(2,screen_cols,help_header_display);
  smg$create_virtual_display(screen_rows-5,screen_cols,help_display);
  put_help('CCF Bulletin Board','BB$BANNER.TXT',pause:=false);

  smg$paste_virtual_display(menu_display,pasteboard,screen_rows-1,2);

  smg$set_out_of_band_asts(pasteboard,control_char_mask:=ast_mask,
                           ast_routine:=%immed out_of_band_handler);
  smg$set_broadcast_trapping(pasteboard,%immed broadcast_handler);
end;
end.
