home *** CD-ROM | disk | FTP | other *** search
- (* ----------------------------------------------------------------------- *)
- (* DCOUT.PAS *)
- (* Ausgabe-Modul des didaktischen Computers *)
- (* ----------------------------------------------------------------------- *)
- PROCEDURE Error (error_type: errors); (* Fehleranzeige *)
- CONST
- s1 = 'falsch'; s2 = 'es Argument'; s3 = 'e Adresse';
- s4 = 'er Befehl'; s5 = 'e Konstante'; s6 = 'e Marke';
- s7 = 'er Code'; s8 = 'Ueberlauf'; s9 = 'Endlos-Schleife';
- s10= 'er Dateiname'; s11= 'Hilfe nicht gefunden'; s12= 'Programm gestoppt';
- BEGIN
- GotoXY(2,25); RevOn; Write('Fehler: ');
- CASE error_type OF
- illcmd: Write(s1, s4); (* Illegal command *)
- illadd: Write(s1, s3); (* Illegal address *)
- illarg: Write(s1, s2); (* Illegal argument *)
- illlab: Write(s1, s6); (* Illegal label *)
- illcod: Write(s1, s7); (* Illegal code *)
- illcon: Write(s1, s5); (* Illegal constant *)
- illfil: Write(s1, s10); (* Illegal filename *)
- illhlp: Write(s11); (* Help not found *)
- break : Write(s12); (* User break *)
- loops : Write(s9); (* Looping *)
- ovf : Write(s8); (* Overflow *)
- END;
- RevOff;
- END;
-
- PROCEDURE Erase_Error;
- BEGIN GotoXY(2,25); RevOn; Write(' ':31); RevOff; END;
- (* ----------------------------------------------------------------------- *)
- PROCEDURE Disassemble (VAR reg : dc_word; (* Code und Argument eines *)
- VAR mnem: mnem_str; (* Maschinenbefehls wieder *)
- VAR arg : INTEGER); (* zurueck uebersetzen *)
- BEGIN
- Bin_to_Int(reg,op_start,op_end,arg); mnem := mnems[arg];
- Bin_to_Int(reg,addr_start,addr_end,arg);
- END;
- (* ----------------------------------------------------------------------- *)
- PROCEDURE Print_Register (x, y: INTEGER; VAR reg: dc_word);
- BEGIN GotoXY(x,y); Write(reg); END;
-
- PROCEDURE Out_Cell (adr: INTEGER);
- VAR arg, y: INTEGER; mnem: mnem_str;
- BEGIN
- Disassemble(memory[adr],mnem,arg); y := (adr MOD 25) + 1;
- GotoXY(59,y); Write(adr:2,mnem:4,arg:3);
- GotoXY(69,y); Write(memory[adr],' ');
- END;
-
- PROCEDURE Print_MemPage (adr: INTEGER);
- VAR i, from_cell, to_cell, arg, y: INTEGER;
- BEGIN
- i := adr DIV screen_lines; RevOn;
- IF i <> mempage THEN BEGIN
- mempage := i; y := 0;
- from_cell := i*screen_lines; to_cell := from_cell+Pred(screen_lines);
- IF to_cell > mem_size THEN to_cell := mem_size;
- FOR i := from_cell TO to_cell DO BEGIN Out_Cell(i); y := Succ(y); END;
- WHILE y < screen_lines DO BEGIN
- y := Succ(y);
- GotoXY(59,y); Write(' ':9); GotoXY(69,y); Write(' ':Succ(word_size));
- END;
- END;
- RevOff;
- END;
-
- PROCEDURE Print_Cell (i: INTEGER); (* Inhalt einer Speicherzelle anzeigen *)
- BEGIN
- IF (i DIV screen_lines)=mempage THEN BEGIN RevOn; Out_Cell(i); RevOff; END;
- END;
-
- PROCEDURE Invert_Cell (i: INTEGER);
- BEGIN Print_MemPage(i); RevOff; Out_Cell(i); END;
-
- PROCEDURE Print_Cycle (Str: lines); (* Maschinen-Zyklus anzeigen *)
- BEGIN
- IF out_cycle THEN BEGIN RevOn; GotoXY(6,25); Write(Str); RevOff; END;
- END;
- (* ----------------------------------------------------------------------- *)
- PROCEDURE WriteCh (ch: string2; n: INTEGER); (* "n" Zeichen ausgeben *)
- VAR i: INTEGER;
- BEGIN FOR i := 1 TO n DO Write(ch); END;
-
- PROCEDURE Scroll_Up; (* Dialog-Fenster scrollen *)
- VAR i: INTEGER;
- BEGIN
- FOR i := winymin TO winymax-1 DO BEGIN
- window[i] := window[i+1]; GotoXY(3,i); Write(window[i]);
- END;
- GotoXY(3,winymax); WriteCh(' ',max_length); GotoXY(3,winymax);
- END;
-
- PROCEDURE W_Write (VAR Str: lines); (* In's Dialog-Fenster schreiben *)
- BEGIN
- window[row] := Str; row := row + 1; GotoXY(1,row);
- IF row = winymax+1 THEN BEGIN row := winymax; Scroll_Up; END;
- END;
- (* ----------------------------------------------------------------------- *)
- PROCEDURE LED (ch: CHAR); (* Die LEDs zur Anzeige von Registerinhalten *)
- BEGIN CASE ch OF '0': Write(led_off); '1': Write(led_on); END; END;
- (* ein Registerinhalt mit obigen LEDs anzeigen: *)
- PROCEDURE Display (VAR register: dc_word; x, y, left, right: INTEGER);
- VAR i: INTEGER;
- BEGIN
- IF out_cycle THEN
- BEGIN GotoXY(x,y); FOR i := left TO right DO LED(register[i]); END;
- END;
-
- PROCEDURE Display_AC; (* der Akkumulator *)
- BEGIN Display(ac,23,4,sign_bit,1); Display(ac,25,4,sign_bit+1,word_size);END;
-
- PROCEDURE Display_PC; (* der Programmzaehler *)
- BEGIN Display(pc,8,4,addr_start,addr_end); END;
-
- PROCEDURE Display_AR; (* das Adressregister *)
- BEGIN Display(ar,48,4,addr_start,addr_end); END;
-
- PROCEDURE Display_DR; (* das Datenregister *)
- BEGIN Display(dr,44,12,sign_bit,word_size); END;
-
- PROCEDURE Display_IR; (* das Befehlsregister *)
- BEGIN
- Display(ir,4,13,op_start,op_end); Display(ir,9,13,addr_start,addr_end);
- END;
-
- PROCEDURE Display_SP; (* der Stack-Pointer *)
- BEGIN Display(sp,4,7,addr_start,addr_end); END;
-
- PROCEDURE Print_Registers; (* und jetzt alle zusammen neben Dialog-Fenster *)
- BEGIN
- Print_Register(37,18,ac); Print_Register(37,19,dr);
- Print_Register(37,20,ar); Print_Register(37,21,ir);
- Print_Register(37,22,pc); Print_Register(37,23,sp);
- END;
-
- PROCEDURE Display_Status; (* logo ? *)
- BEGIN
- out_cycle := TRUE; Print_Registers; Display_AR; Display_PC; Display_AC;
- Display_DR; Display_IR; Display_SP;
- END;
- (* ----------------------------------------------------------------------- *)
- PROCEDURE Interrupt; (* Anzeige einer Unterbrechung *)
- VAR ia: dc_word; err: INTEGER;
- BEGIN
- IF items = 1 THEN BEGIN
- int_addr := none; GotoXY(41,25); RevOn; Write('none'); RevOff;
- GotoXY(38,4); WriteCh('-',Succ(addr_end-addr_start));
- END
- ELSE BEGIN
- Val(item[2],int_addr,err);
- IF (err = null) AND Legal(int_addr) THEN BEGIN
- GotoXY(41,25); RevOn; Write(int_addr:4); RevOff;
- Int_to_Bin(int_addr,addr_start,addr_end,ia);
- Display(ia,38,4,addr_start,addr_end);
- END
- ELSE Error(illadd); (* Illegall address *)
- END;
- END;
- (* ----------------------------------------------------------------------- *)
- PROCEDURE Breakpoint; (* Anzeige eines Haltepunktes *)
- VAR err: INTEGER;
- BEGIN
- IF items = 1 THEN BEGIN
- break_addr := none; GotoXY(41,24); RevOn; Write('none'); RevOff;
- END
- ELSE BEGIN
- Val(item[2],break_addr,err);
- IF (err = null) AND Legal(break_addr) THEN BEGIN
- GotoXY(41,24); RevOn; Write(break_addr:4); RevOff;
- END
- ELSE Error(illadd); (* Illegall address *)
- END;
- END;
- (* ----------------------------------------------------------------------- *)
- PROCEDURE Wait; (* bei der Ausfuehrung eines Progs. entspr. warten *)
- VAR ch: CHAR;
- BEGIN
- CASE mode OF
- waiting : IF command = step THEN BEGIN
- GotoXY(2,25); RevOn; Write('Druecke eine Taste'); RevOff;
- Bell; REPEAT UNTIL KeyEntered; ch := ReadKeyboard;
- END;
- nowait : ;
- delaying: Delay(time);
- END;
- IF out_cycle THEN Erase_Error;
- END;
- (* ----------------------------------------------------------------------- *)
- (* Anzeigen der verschiedenen Steuersignale bei der Ausfuehrung: *)
- PROCEDURE Gate (VAR s: string2; x,y : INTEGER; blink: BOOLEAN);
- VAR i: INTEGER;
- BEGIN
- IF blink THEN
- FOR i := 1 TO blink_num DO BEGIN
- GotoXY(x,y); Write(s); Delay(blink_time); RevOn;
- GotoXY(x,y); Write(s); Delay(blink_time); RevOff;
- END
- ELSE BEGIN RevOff; GotoXY(x,y); Write(s); END;
- END;
- (* ----------------------------------------------------------------------- *)
- PROCEDURE Print_Computer; (* Bild des Computers zeichnen *)
- VAR i: INTEGER; s: CHAR;
- BEGIN
- s := ' '; GotoXY(1,1);
- Write('AB',he,dhe); WriteCh(he,6); Write(dhe); WriteCh(he,5); Write(dhe);
- WriteCh(he,23); Write(dhe); WriteCh(he,9); Write(dhe); WriteCh(he,4);
- WriteLn(ule);
- WriteCh(s,3); Write(sl); WriteCh(s,6); Write(sl); WriteCh(s,5);
- Write(sl,s,ure); WriteCh(he,8); Write(ule); WriteCh(s,12); Write(sl);
- WriteCh(s,9); Write(sl); WriteCh(s,4); WriteLn(sl);
- WriteCh(s,3); Write(ve); WriteCh(s,2); Write(ure,he,he,he,uhe,he,he,ule);
- WriteCh(s,2); Write(ve,s,ve); WriteCh(s,2); Write(ure); WriteCh(he,5);
- Write(uhe); WriteCh(he,5); Write(ule); WriteCh(s,2);
- Write(ure,he,he,he,uhe,he,he,ule); WriteCh(s,2);
- WriteLn(ure,he,he,he,uhe,he,he,ule,s,ve);
- WriteCh(s,3); Write(ve,'PC',ve); WriteCh(s,6); Write(rve); WriteCh(s,2);
- Write(ve,s,ve,'AC',ve); WriteCh(s,11); Write(ve,'IA',ve); WriteCh(s,6);
- Write(ve,'AR',ve); WriteCh(s,6); WriteLn(ve,s,ve);
- WriteCh(s,3); Write(ve); WriteCh(s,2); Write(dre); WriteCh(he,6);
- Write(dle); WriteCh(s,2); Write(ve,s,ve); WriteCh(s,2); Write(dre);
- WriteCh(he,5); Write(dhe); WriteCh(he,5); Write(dle); WriteCh(s,2);
- Write(rve); WriteCh(he,6); Write(lve); WriteCh(s,2);
- WriteLn(dre,he,he,he,dhe,he,he,dle,s,ve);
- Write(sp2,ure,uhe); WriteCh(he,5); Write(ule); WriteCh(s,6);
- Write(ve,s,ve); WriteCh(s,8); Write(sl); WriteCh(s,8);
- Write(ve,' INT ',ve,ure); WriteCh(he,5); WriteLn(uhe,he,he,ule,s,ve);
- Write('SP',ve); WriteCh(s,6); Write(rve); WriteCh(s,6); Write(ve,s,ve);
- WriteCh(s,5); Write(ure,he,he,uhe,he,he,ule); WriteCh(s,5); Write(dre);
- WriteCh(he,6); Write(dle,ve); WriteCh(s,8); WriteLn(ve,s,ve);
- Write(sp2,dre); WriteCh(he,6); Write(dle); WriteCh(s,6); Write(ve,s,ve);
- WriteCh(s,5); Write(ve); WriteCh(s,5); Write(ve); WriteCh(s,13);
- WriteLn(ve,' MEMORY ',ve,s,ve);
- Write(ure); WriteCh(he,9); Write(ule); WriteCh(s,5); Write(ve,s,ve,s,s);
- Write(ure,he,he,dle); WriteCh(s,5); Write(dre,he,he,ule); WriteCh(s,10);
- Write(lve); WriteCh(s,8); WriteLn(ve,s,ve);
- Write(ve,' CONTROL ',ve); WriteCh(s,5); Write(ve,s,ve,s,s,ve);
- WriteCh(s,4); Write('ALU'); WriteCh(s,4); Write(ve); WriteCh(s,10);
- Write(dre); WriteCh(he,5); WriteLn(dhe,he,he,dle,s,ve);
- Write(dre,he,ule); WriteCh(s,4); Write(ure,he,he,dle,ure);
- WriteCh(he,4); Write(dle,s,ve,s,s,ve); WriteCh(s,4); Write(ure,he,ule);
- WriteCh(s,4); Write(ve); WriteCh(s,8); Write(ure); WriteCh(he,7);
- WriteLn(uhe,he,he,ule,s,ve);
- WriteCh(s,2); Write(rve); WriteCh(s,4); Write(ce); WriteCh(he,3);
- Write(uhe,he,he,ule,s,s,s,ve,s,s,ve); WriteCh(s,4); Write(ve,s,ve);
- WriteCh(s,4); Write(ve); WriteCh(s,6); Write('DR',ve); WriteCh(s,10);
- WriteLn(ve,s,ve);
- Write('IR',ve); WriteCh(s,11); Write(ve,s,s,s,ve,s,s);
- Write(dre,he,dhe,he,he,dle,s,dre,he,he,dhe,he,dle);
- WriteCh(s,8); Write(dre); WriteCh(he,5); Write(dhe); WriteCh(he,4);
- WriteLn(dle,s,ve);
- WriteCh(s,2); Write(dre); WriteCh(he,4); Write(ce); WriteCh(he,6);
- Write(dle,s,s,s,rve); WriteCh(he,4); Write(dle); WriteCh(s,7); Write(ve);
- WriteCh(s,16); Write(ve); WriteCh(s,6); WriteLn(ve);
- WriteCh(s,7); Write(sl); WriteCh(s,10); Write(sl);
- WriteCh(s,12); Write(sl); WriteCh(s,16); Write(sl);
- WriteCh(s,6); WriteLn(ve);
- Write('DB'); WriteCh(he,5); Write(uhe); WriteCh(he,10); Write(uhe);
- WriteCh(he,12);Write(uhe); WriteCh(he,16);Write(uhe);
- WriteCh(he,6); WriteLn(dle);
- END;
- (* ----------------------------------------------------------------------- *)
- PROCEDURE Print_Display; (* das Drumherum zeichnen *)
- VAR i: INTEGER;
- BEGIN
- FOR i := 1 TO 25 DO
- BEGIN GotoXY(58,i); Write(vd); GotoXY(68,i); Write(vd); END;
- GotoXY(1,winymin-1);
- RevOn; Write(' DC v1.3 (c) 1987 PASCAL INT. ');
- Write(' Register: Mnem: '); RevOff;
- FOR i := winymin-1 TO winymax+1 DO
- BEGIN GotoXY(33,i); Write(vd); GotoXY(47,i); Write(vd); END;
- GotoXY(34,24); RevOn; Write(' Bpt: none ');
- GotoXY(34,25); Write(' Int: none ');
- GotoXY(1,25); Write(' ':32);
- GotoXY(48,18); Write(' LDA ??? '); GotoXY(48,19); Write(' STA ??? ');
- GotoXY(48,20); Write(' ADD ??? '); GotoXY(48,21); Write(' SUB ??? ');
- GotoXY(48,22); Write(' JMP ??? '); GotoXY(48,23); Write(' JMS ??? ');
- GotoXY(48,24); Write(' JSR ??? '); GotoXY(48,25); Write(' RTN DEF ');
- RevOff; GotoXY(34,18); Write('AC'); GotoXY(34,19); Write('DR');
- GotoXY(34,20); Write('AR'); GotoXY(34,21); Write('IR');
- GotoXY(34,22); Write('PC'); GotoXY(34,23); Write('SP');
- END;
- (* ----------------------------------------------------------------------- *)
- (* DCOUT.PAS *)
-