(******************************* Variant 2-8 *******************************) (* 2- базовый адрес задается в десятеричном виде двумя компонентами: сегментом и смещением. 8- содержимое выводится в восьмеричном виде сериями по 8 однобайтовых слов.*) (***************************************************************************) program Lab1; uses crt; var H: array[0..3199] of byte; type TMemoryPtr=^TMemory; TMemory=object private Segment, Offset: word; public constructor Init; function GetByte: byte; procedure SetByte(B: byte); procedure Go(S,O: word); procedure Move(S,O: integer); function GetSegment: word; function GetOffset: word; end; constructor TMemory.Init; begin Segment:=0; Offset:=0; end; function TMemory.GetByte: byte; begin GetByte:=Mem[Segment:Offset]; end; procedure TMemory.SetByte(B: byte); begin Mem[Segment:Offset]:=B; end; procedure TMemory.Go(S,O: word); begin Segment:=S; Offset:=O; end; procedure TMemory.Move(S,O: integer); begin Segment:=Segment+S; if(Segment>65535) then Segment:=(Segment-65534) else if(Segment<0) then Segment:=(65536+Segment); Offset:=Offset+O; if(Offset>65535) then Offset:=(Offset-65534) else if(Offset<0) then Offset:=(65536+Offset); end; function TMemory.GetSegment: word; begin GetSegment:=Segment; end; function TMemory.GetOffset: word; begin GetOffset:=Offset; end; procedure ShowString(S: string; VM: TMemoryPtr); var i: byte; begin for i:=1 to length(S) do begin VM^.SetByte(ord(S[i])); VM^.Move(0,2); end; end; procedure ShowAll(M: TMemoryPtr; VM: TMemoryPtr); var A,L,i,j,P: word; AA,LL,JJ: word; begin P:=M^.GetOffset; for j:=1 to 4 do begin VM^.Go($B800,(3+j)*160+2*2); VM^.Move(0,2*4); L:=M^.GetSegment; for i:=1 to 5 do begin A:=L mod 10; L:=L div 10; A:=A+48; VM^.SetByte(A); VM^.Move(0,-2); end; VM^.Go($B800,(3+j)*160+7*2); ShowString(':',VM); VM^.Move(0,2*4); L:=M^.GetOffset; for i:=1 to 5 do begin A:=L mod 10; L:=L div 10; A:=A+48; VM^.SetByte(A); VM^.Move(0,-2); end; VM^.Go($B800,(3+j)*160+19*2); if(M^.GetOffset<$FFF0) then begin for i:=1 to 8 do begin { VM^.SetByte(M^.GetByte); VM^.Move(0,2); } LL := M^.GetByte; for JJ:=1 to 3 do begin AA := LL mod 8; LL := LL div 8; AA:=AA+48; VM^.SetByte(AA); VM^.Move(0,2); end; ShowString(' ',VM); M^.Move(0,1); (* if (i mod {8}4=0) then begin ShowString(' ',VM); end; *) end; end else begin ShowString(' ',VM); M^.Move(0,16); end; end; M^.Go(M^.GetSegment,P); end; procedure ClearScreen(VM: TMemoryPtr); var i: word; begin VM^.Go($B800,0); for i:=0 to 3199 do begin H[i]:=VM^.GetByte; VM^.SetByte(32); VM^.Move(0,2); end; end; procedure ReturnScreen(VM: TMemoryPtr); var i: word; begin VM^.Go($B800,0); for i:=0 to 3199 do begin VM^.SetByte(H[i]); VM^.Move(0,2); end; end; var Memory: TMemory; VMemory: TMemory; C: char; A,B: word; S: string; begin clrscr; Memory.Init; VMemory.Init; ClearScreen(@VMemory); VMemory.Go($B800,0); ShowString(' Лабораторная работа 2-8',@VMemory); VMemory.Go($B800,1*160+0); ShowString('--------------------------------------------------------------------------------',@VMemory); ShowString(' Сегмент:Смещение Содержимое памяти',@VMemory); VMemory.Go($B800,3*160+0); ShowString('--------------------------------------------------------------------------------',@VMemory); VMemory.Go($B800,8*160+0); ShowString('--------------------------------------------------------------------------------',@VMemory); VMemory.Go($B800,10*160+0); ShowString('--------------------------------------------------------------------------------',@VMemory); VMemory.Go($B800,12*160+0); ShowString(' [',@VMemory); ShowString(chr(24),@VMemory); ShowString('],[',@VMemory); ShowString(chr(25),@VMemory); ShowString('] прокр. смещения',@VMemory); VMemory.Go($B800,13*160+0); ShowString(' [PgUp],[PgDn] прокр. сегмента',@VMemory); VMemory.Go($B800,14*160+0); ShowString(' [Insert] Ввод сегмента',@VMemory); VMemory.Go($B800,15*160+0); ShowString(' [Delete] Ввод смещения',@VMemory); VMemory.Go($B800,16*160+0); ShowString(' [Esc] Выход',@VMemory); ShowAll(@Memory,@VMemory); while true do begin while not(KeyPressed) do; C:=ReadKey; if (ord(C)=72) then Memory.Move(0,-1) else if(ord(C)=80) then Memory.Move(0,1) else if(ord(C)=73) then Memory.Move(-1,0) else if(ord(C)=81) then Memory.Move(1,0) else if(ord(C)=82) then begin VMemory.Go($B800,9*160+1*2); ShowString('Введите сегмент: ', @VMemory); gotoxy(22,10); readln(S); val(S,A,B); Memory.Go(A, Memory.GetOffset); VMemory.Go($B800,9*160+1*2); ShowString(' ', @VMemory); end else if(ord(C)=83) then begin VMemory.Go($B800,9*160+1*2); ShowString('Введите смещение ', @VMemory); gotoxy(22,10); readln(S); val(S,A,B); Memory.Go(Memory.GetSegment,A); VMemory.Go($B800,9*160+1*2); ShowString(' ', @VMemory); end else if(ord(C)=27) then begin ReturnScreen(@VMemory); halt(0); end; ShowAll(@Memory,@VMemory); end; end.