home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / 1987 / 12 / dc / dcout.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1987-09-21  |  13.0 KB  |  286 lines

  1. (* ----------------------------------------------------------------------- *)
  2. (*                                DCOUT.PAS                                *)
  3. (*                Ausgabe-Modul des didaktischen Computers                 *)
  4. (* ----------------------------------------------------------------------- *)
  5. PROCEDURE Error (error_type: errors);                     (* Fehleranzeige *)
  6. CONST
  7.   s1 = 'falsch';       s2 = 'es Argument';          s3 = 'e Adresse';
  8.   s4 = 'er Befehl';    s5 = 'e Konstante';          s6 = 'e Marke';
  9.   s7 = 'er Code';      s8 = 'Ueberlauf';            s9 = 'Endlos-Schleife';
  10.   s10= 'er Dateiname'; s11= 'Hilfe nicht gefunden'; s12= 'Programm gestoppt';
  11. BEGIN
  12.   GotoXY(2,25);  RevOn;  Write('Fehler: ');
  13.   CASE error_type OF
  14.     illcmd: Write(s1, s4);                      (* Illegal command         *)
  15.     illadd: Write(s1, s3);                      (* Illegal address         *)
  16.     illarg: Write(s1, s2);                      (* Illegal argument        *)
  17.     illlab: Write(s1, s6);                      (* Illegal label           *)
  18.     illcod: Write(s1, s7);                      (* Illegal code            *)
  19.     illcon: Write(s1, s5);                      (* Illegal constant        *)
  20.     illfil: Write(s1, s10);                     (* Illegal filename        *)
  21.     illhlp: Write(s11);                         (* Help not found          *)
  22.     break : Write(s12);                         (* User break              *)
  23.     loops : Write(s9);                          (* Looping                 *)
  24.     ovf   : Write(s8);                          (* Overflow                *)
  25.   END;
  26.   RevOff;
  27. END;
  28.  
  29. PROCEDURE Erase_Error;
  30. BEGIN  GotoXY(2,25);  RevOn;  Write(' ':31);  RevOff;  END;
  31. (* ----------------------------------------------------------------------- *)
  32. PROCEDURE Disassemble (VAR reg : dc_word;       (* Code und Argument eines *)
  33.                        VAR mnem: mnem_str;      (* Maschinenbefehls wieder *)
  34.                        VAR arg : INTEGER);      (* zurueck uebersetzen     *)
  35. BEGIN
  36.   Bin_to_Int(reg,op_start,op_end,arg);  mnem := mnems[arg];
  37.   Bin_to_Int(reg,addr_start,addr_end,arg);
  38. END;
  39. (* ----------------------------------------------------------------------- *)
  40. PROCEDURE Print_Register (x, y: INTEGER; VAR reg: dc_word);
  41. BEGIN  GotoXY(x,y);  Write(reg);  END;
  42.  
  43. PROCEDURE Out_Cell (adr: INTEGER);
  44. VAR arg, y: INTEGER;  mnem: mnem_str;
  45. BEGIN
  46.   Disassemble(memory[adr],mnem,arg);  y := (adr MOD 25) + 1;
  47.   GotoXY(59,y);  Write(adr:2,mnem:4,arg:3);
  48.   GotoXY(69,y);  Write(memory[adr],' ');
  49. END;
  50.  
  51. PROCEDURE Print_MemPage (adr: INTEGER);
  52. VAR i, from_cell, to_cell, arg, y: INTEGER;
  53. BEGIN
  54.   i := adr DIV screen_lines;  RevOn;
  55.   IF i <> mempage THEN BEGIN
  56.     mempage := i;  y := 0;
  57.     from_cell := i*screen_lines;  to_cell := from_cell+Pred(screen_lines);
  58.     IF to_cell > mem_size THEN to_cell := mem_size;
  59.     FOR i := from_cell TO to_cell DO BEGIN Out_Cell(i); y := Succ(y); END;
  60.     WHILE y < screen_lines DO BEGIN
  61.       y := Succ(y);
  62.       GotoXY(59,y); Write(' ':9); GotoXY(69,y); Write(' ':Succ(word_size));
  63.     END;
  64.   END;
  65.   RevOff;
  66. END;
  67.  
  68. PROCEDURE Print_Cell (i: INTEGER);  (* Inhalt einer Speicherzelle anzeigen *)
  69. BEGIN
  70.  IF (i DIV screen_lines)=mempage THEN BEGIN RevOn; Out_Cell(i); RevOff; END;
  71. END;
  72.  
  73. PROCEDURE Invert_Cell (i: INTEGER);
  74. BEGIN  Print_MemPage(i);  RevOff;  Out_Cell(i);  END;
  75.  
  76. PROCEDURE Print_Cycle (Str: lines);           (* Maschinen-Zyklus anzeigen *)
  77. BEGIN
  78.   IF out_cycle THEN BEGIN  RevOn;  GotoXY(6,25);  Write(Str);  RevOff;  END;
  79. END;
  80. (* ----------------------------------------------------------------------- *)
  81. PROCEDURE WriteCh (ch: string2; n: INTEGER);  (* "n" Zeichen  ausgeben *)
  82. VAR  i: INTEGER;
  83. BEGIN  FOR i := 1 TO n DO Write(ch);  END;
  84.  
  85. PROCEDURE Scroll_Up;                            (* Dialog-Fenster scrollen *)
  86. VAR  i: INTEGER;
  87. BEGIN
  88.   FOR i := winymin TO winymax-1 DO BEGIN
  89.     window[i] := window[i+1];  GotoXY(3,i);  Write(window[i]);
  90.   END;
  91.   GotoXY(3,winymax);  WriteCh(' ',max_length);  GotoXY(3,winymax);
  92. END;
  93.  
  94. PROCEDURE W_Write (VAR Str: lines);       (* In's Dialog-Fenster schreiben *)
  95. BEGIN
  96.   window[row] := Str;  row := row + 1;  GotoXY(1,row);
  97.   IF row = winymax+1 THEN BEGIN  row := winymax;  Scroll_Up;  END;
  98. END;
  99. (* ----------------------------------------------------------------------- *)
  100. PROCEDURE LED (ch: CHAR);     (* Die LEDs zur Anzeige von Registerinhalten *)
  101. BEGIN  CASE ch OF '0': Write(led_off); '1': Write(led_on);  END;  END;
  102.                            (* ein Registerinhalt mit obigen LEDs anzeigen: *)
  103. PROCEDURE Display (VAR register: dc_word; x, y, left, right: INTEGER);
  104. VAR  i: INTEGER;
  105. BEGIN
  106.   IF out_cycle THEN
  107.     BEGIN  GotoXY(x,y);  FOR i := left TO right DO LED(register[i]);  END;
  108. END;
  109.  
  110. PROCEDURE Display_AC;                                   (* der Akkumulator *)
  111. BEGIN Display(ac,23,4,sign_bit,1); Display(ac,25,4,sign_bit+1,word_size);END;
  112.  
  113. PROCEDURE Display_PC;                               (* der Programmzaehler *)
  114. BEGIN  Display(pc,8,4,addr_start,addr_end);  END;
  115.  
  116. PROCEDURE Display_AR;                                (* das Adressregister *)
  117. BEGIN  Display(ar,48,4,addr_start,addr_end);  END;
  118.  
  119. PROCEDURE Display_DR;                                 (* das Datenregister *)
  120. BEGIN  Display(dr,44,12,sign_bit,word_size);  END;
  121.  
  122. PROCEDURE Display_IR;                               (* das Befehlsregister *)
  123. BEGIN
  124.   Display(ir,4,13,op_start,op_end);  Display(ir,9,13,addr_start,addr_end);
  125. END;
  126.  
  127. PROCEDURE Display_SP;                                 (* der Stack-Pointer *)
  128. BEGIN  Display(sp,4,7,addr_start,addr_end);  END;
  129.  
  130. PROCEDURE Print_Registers; (* und jetzt alle zusammen neben Dialog-Fenster *)
  131. BEGIN
  132.   Print_Register(37,18,ac);  Print_Register(37,19,dr);
  133.   Print_Register(37,20,ar);  Print_Register(37,21,ir);
  134.   Print_Register(37,22,pc);  Print_Register(37,23,sp);
  135. END;
  136.  
  137. PROCEDURE Display_Status;                                        (* logo ? *)
  138. BEGIN
  139.  out_cycle := TRUE; Print_Registers; Display_AR; Display_PC; Display_AC;
  140.  Display_DR; Display_IR; Display_SP;
  141. END;
  142. (* ----------------------------------------------------------------------- *)
  143. PROCEDURE Interrupt;                        (* Anzeige einer Unterbrechung *)
  144. VAR  ia: dc_word;  err: INTEGER;
  145. BEGIN
  146.   IF items = 1 THEN BEGIN
  147.       int_addr := none; GotoXY(41,25); RevOn; Write('none'); RevOff;
  148.       GotoXY(38,4); WriteCh('-',Succ(addr_end-addr_start));
  149.     END
  150.   ELSE BEGIN
  151.       Val(item[2],int_addr,err);
  152.       IF (err = null) AND Legal(int_addr) THEN BEGIN
  153.           GotoXY(41,25);  RevOn;  Write(int_addr:4);  RevOff;
  154.           Int_to_Bin(int_addr,addr_start,addr_end,ia);
  155.           Display(ia,38,4,addr_start,addr_end);
  156.         END
  157.       ELSE  Error(illadd);                             (* Illegall address *)
  158.     END;
  159. END;
  160. (* ----------------------------------------------------------------------- *)
  161. PROCEDURE Breakpoint;                        (* Anzeige eines Haltepunktes *)
  162. VAR  err: INTEGER;
  163. BEGIN
  164.   IF items = 1 THEN BEGIN
  165.       break_addr := none;  GotoXY(41,24);  RevOn;  Write('none');  RevOff;
  166.     END
  167.   ELSE BEGIN
  168.       Val(item[2],break_addr,err);
  169.       IF (err = null) AND Legal(break_addr) THEN BEGIN
  170.           GotoXY(41,24);  RevOn;  Write(break_addr:4);  RevOff;
  171.         END
  172.       ELSE  Error(illadd);                             (* Illegall address *)
  173.     END;
  174. END;
  175. (* ----------------------------------------------------------------------- *)
  176. PROCEDURE Wait;         (* bei der Ausfuehrung eines Progs. entspr. warten *)
  177. VAR ch: CHAR;
  178. BEGIN
  179.   CASE mode OF
  180.     waiting : IF command = step THEN BEGIN
  181.                 GotoXY(2,25);  RevOn;  Write('Druecke eine Taste');  RevOff;
  182.                 Bell;  REPEAT UNTIL KeyEntered;  ch := ReadKeyboard;
  183.               END;
  184.     nowait  : ;
  185.     delaying: Delay(time);
  186.   END;
  187.   IF out_cycle THEN Erase_Error;
  188. END;
  189. (* ----------------------------------------------------------------------- *)
  190. (*      Anzeigen der verschiedenen Steuersignale bei der Ausfuehrung:      *)
  191. PROCEDURE Gate (VAR s: string2; x,y : INTEGER; blink: BOOLEAN);
  192. VAR i: INTEGER;
  193. BEGIN
  194.   IF blink THEN
  195.     FOR i := 1 TO blink_num DO BEGIN
  196.       GotoXY(x,y);  Write(s);  Delay(blink_time);  RevOn;
  197.       GotoXY(x,y);  Write(s);  Delay(blink_time);  RevOff;
  198.     END
  199.   ELSE BEGIN  RevOff; GotoXY(x,y); Write(s);  END;
  200. END;
  201. (* ----------------------------------------------------------------------- *)
  202. PROCEDURE Print_Computer;                   (* Bild des Computers zeichnen *)
  203. VAR  i: INTEGER;  s: CHAR;
  204. BEGIN
  205.   s := ' ';  GotoXY(1,1);
  206.   Write('AB',he,dhe); WriteCh(he,6); Write(dhe); WriteCh(he,5); Write(dhe);
  207.   WriteCh(he,23); Write(dhe); WriteCh(he,9); Write(dhe); WriteCh(he,4);
  208.   WriteLn(ule);
  209.   WriteCh(s,3); Write(sl); WriteCh(s,6); Write(sl); WriteCh(s,5);
  210.   Write(sl,s,ure); WriteCh(he,8);  Write(ule);  WriteCh(s,12); Write(sl);
  211.   WriteCh(s,9); Write(sl); WriteCh(s,4); WriteLn(sl);
  212.   WriteCh(s,3); Write(ve); WriteCh(s,2); Write(ure,he,he,he,uhe,he,he,ule);
  213.   WriteCh(s,2); Write(ve,s,ve); WriteCh(s,2); Write(ure); WriteCh(he,5);
  214.   Write(uhe); WriteCh(he,5); Write(ule); WriteCh(s,2);
  215.   Write(ure,he,he,he,uhe,he,he,ule); WriteCh(s,2);
  216.   WriteLn(ure,he,he,he,uhe,he,he,ule,s,ve);
  217.   WriteCh(s,3); Write(ve,'PC',ve); WriteCh(s,6); Write(rve); WriteCh(s,2);
  218.   Write(ve,s,ve,'AC',ve); WriteCh(s,11); Write(ve,'IA',ve); WriteCh(s,6);
  219.   Write(ve,'AR',ve); WriteCh(s,6); WriteLn(ve,s,ve);
  220.   WriteCh(s,3); Write(ve); WriteCh(s,2); Write(dre); WriteCh(he,6);
  221.   Write(dle); WriteCh(s,2); Write(ve,s,ve); WriteCh(s,2); Write(dre);
  222.   WriteCh(he,5); Write(dhe); WriteCh(he,5); Write(dle); WriteCh(s,2);
  223.   Write(rve); WriteCh(he,6); Write(lve); WriteCh(s,2);
  224.   WriteLn(dre,he,he,he,dhe,he,he,dle,s,ve);
  225.   Write(sp2,ure,uhe); WriteCh(he,5); Write(ule); WriteCh(s,6);
  226.   Write(ve,s,ve); WriteCh(s,8); Write(sl); WriteCh(s,8);
  227.   Write(ve,' INT  ',ve,ure); WriteCh(he,5); WriteLn(uhe,he,he,ule,s,ve);
  228.   Write('SP',ve); WriteCh(s,6); Write(rve); WriteCh(s,6); Write(ve,s,ve);
  229.   WriteCh(s,5); Write(ure,he,he,uhe,he,he,ule); WriteCh(s,5); Write(dre);
  230.   WriteCh(he,6); Write(dle,ve); WriteCh(s,8); WriteLn(ve,s,ve);
  231.   Write(sp2,dre); WriteCh(he,6); Write(dle); WriteCh(s,6); Write(ve,s,ve);
  232.   WriteCh(s,5); Write(ve); WriteCh(s,5); Write(ve); WriteCh(s,13);
  233.   WriteLn(ve,' MEMORY ',ve,s,ve);
  234.   Write(ure); WriteCh(he,9); Write(ule); WriteCh(s,5); Write(ve,s,ve,s,s);
  235.   Write(ure,he,he,dle); WriteCh(s,5); Write(dre,he,he,ule); WriteCh(s,10);
  236.   Write(lve); WriteCh(s,8); WriteLn(ve,s,ve);
  237.   Write(ve,' CONTROL ',ve); WriteCh(s,5); Write(ve,s,ve,s,s,ve);
  238.   WriteCh(s,4); Write('ALU'); WriteCh(s,4); Write(ve); WriteCh(s,10);
  239.   Write(dre); WriteCh(he,5); WriteLn(dhe,he,he,dle,s,ve);
  240.   Write(dre,he,ule); WriteCh(s,4); Write(ure,he,he,dle,ure);
  241.   WriteCh(he,4); Write(dle,s,ve,s,s,ve); WriteCh(s,4); Write(ure,he,ule);
  242.   WriteCh(s,4); Write(ve); WriteCh(s,8); Write(ure); WriteCh(he,7);
  243.   WriteLn(uhe,he,he,ule,s,ve);
  244.   WriteCh(s,2); Write(rve); WriteCh(s,4); Write(ce); WriteCh(he,3);
  245.   Write(uhe,he,he,ule,s,s,s,ve,s,s,ve); WriteCh(s,4); Write(ve,s,ve);
  246.   WriteCh(s,4); Write(ve); WriteCh(s,6); Write('DR',ve); WriteCh(s,10);
  247.   WriteLn(ve,s,ve);
  248.   Write('IR',ve); WriteCh(s,11); Write(ve,s,s,s,ve,s,s);
  249.   Write(dre,he,dhe,he,he,dle,s,dre,he,he,dhe,he,dle);
  250.   WriteCh(s,8); Write(dre); WriteCh(he,5); Write(dhe); WriteCh(he,4);
  251.   WriteLn(dle,s,ve);
  252.   WriteCh(s,2); Write(dre); WriteCh(he,4); Write(ce); WriteCh(he,6);
  253.   Write(dle,s,s,s,rve); WriteCh(he,4); Write(dle); WriteCh(s,7); Write(ve);
  254.   WriteCh(s,16); Write(ve); WriteCh(s,6); WriteLn(ve);
  255.   WriteCh(s,7);  Write(sl);  WriteCh(s,10);  Write(sl);
  256.   WriteCh(s,12); Write(sl);  WriteCh(s,16); Write(sl);
  257.   WriteCh(s,6);  WriteLn(ve);
  258.   Write('DB'); WriteCh(he,5); Write(uhe); WriteCh(he,10); Write(uhe);
  259.   WriteCh(he,12);Write(uhe); WriteCh(he,16);Write(uhe);
  260.   WriteCh(he,6); WriteLn(dle);
  261. END;
  262. (* ----------------------------------------------------------------------- *)
  263. PROCEDURE Print_Display;                         (* das Drumherum zeichnen *)
  264. VAR  i: INTEGER;
  265. BEGIN
  266.   FOR i := 1 TO 25 DO
  267.     BEGIN GotoXY(58,i); Write(vd); GotoXY(68,i); Write(vd);  END;
  268.   GotoXY(1,winymin-1);
  269.   RevOn;  Write('  DC v1.3 (c) 1987  PASCAL INT.  ');
  270.   Write('  Register:      Mnem:  ');  RevOff;
  271.   FOR i := winymin-1 TO winymax+1 DO
  272.     BEGIN  GotoXY(33,i); Write(vd);  GotoXY(47,i);  Write(vd);  END;
  273.   GotoXY(34,24); RevOn; Write('  Bpt: none  ');
  274.   GotoXY(34,25);        Write('  Int: none  ');
  275.   GotoXY(1,25);  Write(' ':32);
  276.   GotoXY(48,18); Write(' LDA  ??? ');  GotoXY(48,19); Write(' STA  ??? ');
  277.   GotoXY(48,20); Write(' ADD  ??? ');  GotoXY(48,21); Write(' SUB  ??? ');
  278.   GotoXY(48,22); Write(' JMP  ??? ');  GotoXY(48,23); Write(' JMS  ??? ');
  279.   GotoXY(48,24); Write(' JSR  ??? ');  GotoXY(48,25); Write(' RTN  DEF ');
  280.   RevOff;  GotoXY(34,18); Write('AC');  GotoXY(34,19);  Write('DR');
  281.   GotoXY(34,20); Write('AR');  GotoXY(34,21); Write('IR');
  282.   GotoXY(34,22); Write('PC');  GotoXY(34,23); Write('SP');
  283. END;
  284. (* ----------------------------------------------------------------------- *)
  285. (*                                DCOUT.PAS                                *)
  286.