Середовище програмування MADL

Информация о пользователе

Привет, Гость! Войдите или зарегистрируйтесь.


Вы здесь » Середовище програмування MADL » КР-580 » Емуляція КР-580 розкладення "на пальцях"(1)


Емуляція КР-580 розкладення "на пальцях"(1)

Сообщений 1 страница 28 из 28

1

Емуляція КР-580 розкладення "на пальцях"(1)

2

https://forumupload.ru/uploads/001b/d4/a7/2/922798.png

https://forumupload.ru/uploads/001b/d4/a7/2/922798.png

3

C:\_SEFA\_SEFA13\Program\Emulator\

Код:
Unit uEmulator_I8080;
Interface
const f_S=128;f_Z=64;f_5=32;f_A=16;f_3=8;f_P=4;f_1=2;f_C=1;
const flags: array [0..256]of Byte=(
 70,2,2,6,2,6,6,2,2,6,6,2,6,2,2,6,2,6,6,2,6,2,2,6,6,2,2,6,2,6,6,2,2,6,6,2,6,2,2,
 6,6,2,2,6,2,6,6,2,6,2,2,6,2,6,6,2,2,6,6,2,6,2,2,6,2,6,6,2,6,2,2,6,6,2,2,6,2,6,6,
 2,6,2,2,6,2,6,6,2,2,6,6,2,6,2,2,6,6,2,2,6,2,6,6,2,2,6,6,2,6,2,2,6,2,6,6,2,6,2,2,
 6,6,2,2,6,2,6,6,2,130,134,134,130,134,130,130,134,134,130,130,134,130,134,134,130,
 134,130,130,134,130,134,134,130,130,134,134,130,134,130,130,134,134,130,130,134,130,
 134,134,130,130,134,134,130,134,130,130,134,130,134,134,130,134,130,130,134,134,130,
 130,134,130,134,134,130,134,130,130,134,130,134,134,130,130,134,134,130,134,130,130,
 134,130,134,134,130,134,130,130,134,134,130,130,134,130,134,134,130,130,134,134,130,
 134,130,130,134,134,130,130,134,130,134,134,130,134,130,130,134,130,134,134,130,130,
 134,134,130,134,130,130,134,0);
var  ports : array [0..256] of byte;
    memory: array [0..65535] of byte;MemoryCardinal_:Array[0..16383] of Cardinal absolute memory;
 RgA,RgB,RgC,RgD,RgE,RgH,RgL,RgF,RpPC,RpSP:Longint;
FlagChangeC1:Cardinal;{прапор зміни порту C1}
 video,VideoDirty_ : array [0..16384] of byte;
FlagChangeVIDEO:Cardinal;{Прапор зміни ячейки в VRAM}
ChangeVIDEOadrMIN,ChangeVIDEOadrMAX:Cardinal;{мін и макс адреса які були "задіти" в VRAM}
Var  ZoomY:Byte=2;ZoomX:Byte=2;{Zoom екрану}
OffSetX:Longint=32;OffSetY:Longint=-8;{Зміщення по екрану}
CT:Int64=0;{лічильник тактів}
CountCommand:Int64=0;

procedure ResetComp;
procedure ResetCompNotBIOS;{Без BIOS}
procedure i8080_do_opcodes(nb_cycles : longint);
procedure DrawScreen;
procedure DrawScreen1;
procedure DrawScreen2;

function do_read(addr : Cardinal): Cardinal;
procedure do_write(do_write_addr, do_write_bt:Cardinal);
procedure do_write2(a_lo,a_hi,bt:integer);
function do_read2(a_lo,a_hi:integer):integer;
procedure do_output(port,bt:integer);
function do_input(port:integer):integer;


implementation
uses uGraph,Stub,uEmulator_BIOS;

procedure ResetPorts;var i : word;begin i:=0;while (i<256) do begin ports[i]:=$FF;inc(i);end;end;

procedure load_bios;var i: word;begin i:=0;while (i<4096) do begin MemoryCardinal_[i+12288]:=BIOS1Cardinal[i];inc(i);end;end;

procedure ResetComp;begin ResetPorts;load_bios; ports[$C2]:=$FF;RpPC:=$C000;FlagChangeC1:=1;end;
procedure ResetCompNotBIOS;begin ResetPorts;ports[$C2]:=$FF;RpPC:=$C000;FlagChangeC1:=1;end;


function do_read(addr : Cardinal): Cardinal;// считаем значение из пямяти
begin addr:=(addr and $FFFF);
 if ((ports[$C2] and 2)<>0) then begin do_read := memory[addr];end else
 if (addr>$7FFF) then begin do_read := memory[addr];end else
 if (addr<$4000) then begin do_read := 0;end else begin do_read := video[addr-$4000];end;
end;

procedure do_write(do_write_addr, do_write_bt:Cardinal);
var wremw:word;
begin if do_write_addr> $FFFF then do_write_addr:=$FFFF;
 if (do_write_addr>=$C000) then begin exit;end;
 if ((ports[$C2] and 2)<>0) then begin memory[do_write_addr]:=do_write_bt;
if do_write_addr=48669 then memory48669:=memory[48669]; end
else if (do_write_addr<$4000) then begin exit;end else
 if (do_write_addr<$8000) then begin
 {в VRAM} wremw:=do_write_addr-$4000;video[(wremw)]:=do_write_bt;
 {порівнюємо чи є зміни}
 if do_write_bt <> VideoDirty_[(wremw)] then begin FlagChangeVIDEO:=1;
 If wremw < ChangeVIDEOadrMIN then ChangeVIDEOadrMIN:=wremw;
 If wremw > ChangeVIDEOadrMAX then ChangeVIDEOadrMAX:=wremw;end;end
else begin memory[do_write_addr]:=do_write_bt;
 if do_write_addr=48669 then memory48669:=memory[48669];end;end;


procedure do_write2(a_lo,a_hi,bt:integer);begin do_write(a_lo+(a_hi SHL 8),bt);end;
function do_read2(a_lo,a_hi:integer):integer;begin do_read2 := do_read(a_lo+(a_hi SHL 8));end;


procedure do_output(port,bt:integer);// out
begin port:=$C0+(port and $13);case port of
 $c1: begin // зміна порту кольору {fillchar(VideoDirty,sizeof(VideoDirty),257);}
 FlagChangeC1:=1;{прапор зміни порту $C1} end;end;ports[port]:=bt;end;



function do_input(port:integer):integer;
var i,r:integer;nD2,nD0:byte;
begin nD2:=0;nD0:=0;port:=$C0+(port and $13);
 case port of
 $C2:begin do_input:=ports[$C2];end;
 $D1:begin nD0:=not ports[$D0];r:=0;i:=0;
 while (i<8) do begin
 if ((nD0 and (1 SHL i))<>0) then begin r:=(r or kbd_base[i]);end;
 inc(i);end;
 do_input := ((not r) and $FF);end;
 $D2:begin nD2:= not ports[$D2];r:=0;i:=0;
 while (i<4) do begin
 if ((nD2 and (1 SHL i))<>0) then begin r:=(r or kbd_ext[i]);end;
 inc(i);end;
 do_input := not ((r SHL 4) or (nD2 and $0F)) and $FF;end
 else begin do_input := $FF;end;end;end;



procedure i8080_do_opcodes(nb_cycles : longint);
var tmp3, tmp2, tmp1, opcode : Longint;
var cz:Cardinal;{після виконання команди, кількість тактів даної команди}
cz1:Cardinal;
begin cz:=0;tmp1:=0;tmp2:=0;tmp3:=0;cz1:=0;
 while (cz1 < nb_cycles) do
 begin
 opcode:=do_read(RpPC);
case opcode of
 $00: begin cz:=4;inc(RpPC);end;
 $F3: begin cz:=4;inc(RpPC);end;
 $FB: begin cz:=4;inc(RpPC);end;
 $01: begin RgB:=do_read(RpPC+2);RgC:=do_read(RpPC+1);cz:=10;inc(RpPC,3);end;
 $02: begin do_write2(RgC,RgB,RgA);cz:=7;inc(RpPC);end;
 $03: begin RgC:=RgC+1;if (RgC>$FF) then begin RgC:=0;RgB:=RgB+1;
 if (RgB>$FF) then begin RgB:=0;end;end;cz:=5;inc(RpPC);end;
 $04: begin tmp2:=((RgB+1) and $FF);RgF:=(flags[tmp2] or (RgF and f_C));
 if (((tmp2 xor RgB) and $10)<>0) then
 begin RgF:=RgF or f_A;end;RgB:=tmp2;cz:=5;inc(RpPC);end;
 $05: begin tmp2:=((RgB-1) and $FF);RgF:=(flags[tmp2] or (RgF and f_C));
 if (((tmp2 xor RgB) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgB:=tmp2;cz:=5;inc(RpPC);end;
 $06: begin RgB:=do_read(RpPC+1);cz:=7;inc(RpPC,2);end;
 $07: begin RgA:=RgA SHL 1;if (RgA>$FF) then begin RgA:=RgA or 1;
 RgF:=RgF or f_C;RgA:= RgA and $FF;end else
 begin RgF:=(RgF and (not f_C));end;cz:=4;inc(RpPC);end;
 $08: begin begin cz:=4;inc(RpPC);end;end;
 $10: begin begin cz:=4;inc(RpPC);end;end;
 $18: begin begin cz:=4;inc(RpPC);end;end;
 $20: begin begin cz:=4;inc(RpPC);end;end;
 $28: begin begin cz:=4;inc(RpPC);end;end;
 $30: begin begin cz:=4;inc(RpPC);end;end;
 $38: begin begin cz:=4;inc(RpPC);end;end;
 $09: begin RgL:=RgL+RgC;RgH:=RgH+RgB;if (RgL>$FF) then
 begin inc(RgH);RgL:=(RgL and $FF);end;if (RgH>$FF) then
 begin RgH:=(RgH and $FF);RgF:=(RgF or f_C);end else
 begin RgF:=(RgF and (not f_C));end;cz:=10;inc(RpPC);end;
 $0A: begin RgA:=do_read2(RgC,RgB);cz:=7;inc(RpPC);end;
 $0B: begin RgC:=RgC-1;if (RgC<0) then begin RgC:=$FF;RgB:=RgB-1;
 if (RgB<0) then begin RgB:=$FF;end;end;
 cz:=5;inc(RpPC);end;
 $0C: begin tmp2:=((RgC+1) and $FF);RgF:=(flags[tmp2] or (RgF and f_C));
 if (((tmp2 xor RgC) and $10)<>0) then begin RgF:=RgF or f_A;end;
 RgC:=tmp2;cz:=5;inc(RpPC);end;
 $0D: begin tmp2:=((RgC-1) and $FF);RgF:=flags[tmp2] or (RgF and f_C);
 if (((tmp2 xor RgC) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgC:=tmp2;cz:=5;inc(RpPC);end;
 $0E: begin RgC:=do_read(RpPC+1);cz:=7;inc(RpPC,2);end;
 $0F: begin tmp1:=(RgA and 1);RgA:=(RgA shr 1);if (tmp1<>0) then
 begin RgA:=(RgA or $80);RgF:=(RgF or f_C);end else
 begin RgF:=(RgF and ( not f_C));end;cz:=4;inc(RpPC);end;
 $11: begin RgD:=do_read(RpPC+2);RgE:=do_read(RpPC+1);cz:=10;inc(RpPC,3);end;
 $12: begin do_write2(RgE,RgD,RgA);cz:=7;inc(RpPC);end;
 $13: begin RgE:=RgE+1;if (RgE>$FF) then begin RgE:=0;RgD:=RgD+1;
 if (RgD>$FF) then begin RgD:=0;end;end;cz:=5;inc(RpPC);end;
 $14: begin tmp2:=((RgD+1)and $FF);RgF:=(flags[tmp2] or (RgF and f_C));
 if (((tmp2 xor RgD) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgD:=tmp2;cz:=5;inc(RpPC);end;
 $15: begin tmp2:=((RgD-1)and $FF);RgF:=(flags[tmp2] or (RgF and f_C));
 if (((tmp2 xor RgD) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgD:=tmp2;cz:=5;inc(RpPC);end;
 $16: begin RgD:=do_read(RpPC+1);cz:=7;inc(RpPC,2);end;
 $17: begin RgA:=(RgA shl 1);if ((RgF and f_C)<>0) then begin RgA:=(RgA or 1);end;
 if (RgA>$FF) then begin RgF:=(RgF or f_C);RgA:=(RgA and $FF);end else begin
 RgF:=(RgF and (not f_C));end;cz:=4;inc(RpPC);end;
 $19: begin RgL:=(RgL + RgE);RgH:=(RgH + RgD);if (RgL>$FF) then
 begin inc(RgH);RgL:=(RgL and $FF);end;
 if (RgH>$FF) then begin RgH:=(RgH and $FF);RgF:=(RgF or f_C);end else
 begin RgF:=(RgF and not (f_C));end;cz:=10;inc(RpPC);end;
 $1A: begin RgA:=do_read2(RgE,RgD);cz:=7;inc(RpPC);end;
 $1B: begin RgE:=RgE-1;if (RgE<0) then begin RgE:=$FF;RgD:=RgD-1;
 if (RgD<0) then begin RgD:=$FF;end;end;cz:=5;
 inc(RpPC);end;
 $1C: begin tmp2:=((RgE+1)and $FF);RgF:=(flags[tmp2] or (RgF and f_C));
 if (((tmp2 xor RgE) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgE:=tmp2;cz:=5;inc(RpPC);end;
 $1D: begin tmp2:=((RgE-1) and $FF);RgF:=(flags[tmp2] or (RgF and f_C));
 if (((tmp2 xor RgE) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgE:=tmp2;cz:=5;inc(RpPC);end;
 $1E: begin RgE:=do_read(RpPC+1);cz:=7;inc(RpPC,2);end;
 $1F: begin tmp1:=(RgA and 1);RgA:=(RgA SHR 1);if ((RgF and f_C)<>0) then
 begin RgA:=(RgA or $80);end;
 if (tmp1<>0) then begin RgF:=(RgF or f_C);end else
 begin RgF:=(RgF and not(f_C));end;cz:=4;inc(RpPC);end;
 $21: begin RgH:=do_read(RpPC+2);RgL:=do_read(RpPC+1);cz:=10;inc(RpPC,3);end;
 $22: begin tmp1:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);do_write(tmp1,RgL);
 do_write(tmp1+1,RgH);cz:=16;inc(RpPC,3);end;
 $23: begin RgL:=RgL+1;if (RgL>$FF) then begin RgL:=0;RgH:=RgH+1;
 if (RgH>$FF) then begin RgH:=0;end;end;
 cz:=5;inc(RpPC);end;
 $24: begin tmp2:=((RgH+1) and $FF);RgF:=(flags[tmp2] or (RgF and f_C));
 if (((tmp2 xor RgH) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgH:=tmp2;cz:=5;inc(RpPC);end;
 $25: begin tmp2:=((RgH-1) and $FF);RgF:=(flags[tmp2] or (RgF and f_C));
 if (((tmp2 xor RgH) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgH:=tmp2;cz:=5;inc(RpPC);end;
 $26: begin RgH:=do_read(RpPC+1);cz:=7;inc(RpPC,2);end;
 $27: begin tmp1:=0;if (((RgF and f_C)<>0) or (RgA>$99)) then begin
 tmp1:=(tmp1 or $60);end;
 if (((RgF and f_A)<>0) or ((RgA and $0F)>$09)) then begin
 tmp1:=(tmp1 or $06);end;tmp2:=RgA+tmp1;RgF:=flags[tmp2 and $FF];
 if (((tmp2 xor RgA xor tmp1) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 if (tmp2>$FF) then begin RgF:=(RgF or f_C);end;RgA:=tmp2 and $FF;
 cz:=4;inc(RpPC);end;
 $29: begin RgL:=RgL + RgL;RgH:=RgH + RgH;
 if (RgL>$FF) then begin inc(RgH);RgL:=(RgL and $FF);end;
 if (RgH>$FF) then begin RgH:=(RgH and $FF);RgF:=(RgF or f_C);end else begin
 RgF:=(RgF and (not f_C));end;cz:=10;inc(RpPC);end;
 $2A: begin tmp1:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);RgL:=do_read(tmp1);
 RgH:=do_read(tmp1+1);cz:=16;inc(RpPC,3);end;
 $2B: begin RgL:=RgL-1;if (RgL <0) then begin RgL:=$FF;
 RgH:=RgH-1;if (RgH<0) then begin RgH:=$FF;end;end;
 cz:=5;inc(RpPC);end;
 $2C: begin tmp2:=((RgL+1) and $FF);RgF:=(flags[tmp2] or (RgF and f_C));
 if (((tmp2 xor RgL) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgL:=tmp2;cz:=5;inc(RpPC);end;
 $2D: begin tmp2:=((RgL-1) and $FF);RgF:=(flags[tmp2] or (RgF and f_C));
 if (((tmp2 xor RgL) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgL:=tmp2;cz:=5;inc(RpPC);end;
 $2E: begin RgL:=do_read(RpPC+1);cz:=7;inc(RpPC,2);end;
 $2F: begin RgA:=(RgA xor $FF);cz:=4;inc(RpPC);end;
 $31: begin RpSP:=(do_read(RpPC+2) shl 8)+do_read(RpPC+1);cz:=10;
 inc(RpPC,3);end;
 $32: begin do_write2(do_read(RpPC+1),do_read(RpPC+2),RgA);cz:=13;
 inc(RpPC,3);end;
 $33: begin if (RpSP=$FFFF) then begin RpSP:=0;end else
 begin inc(RpSP);end;cz:=5;inc(RpPC);end;
 $34: begin tmp1:=do_read2(RgL,RgH);tmp2:=((tmp1+1) and $FF);
 RgF:=(flags[tmp2] or (RgF and f_C));if (((tmp2 xor tmp1) and $10)<>0) then
 begin RgF:=(RgF or f_A);end;do_write2(RgL,RgH,tmp2);cz:=10;
 inc(RpPC);end;
 $35: begin tmp1:=do_read2(RgL,RgH);tmp2:=((tmp1-1) and $FF);RgF:=flags[tmp2] or (RgF and f_C);
 if (((tmp2 xor tmp1) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 do_write2(RgL,RgH,tmp2);cz:=10;inc(RpPC);end;
 $36: begin do_write2(RgL,RgH,do_read(RpPC+1));cz:=10;inc(RpPC,2);end;
 $37: begin RgF:=(RgF or f_C);cz:=4;inc(RpPC);end;
 $39: begin RgL:=(RgL + (RpSP and $FF));RgH:=(RgH + ((RpSP shr 8) and $FF));
 if (RgL>$FF) then begin inc(RgH);RgL:=(RgL and $FF);end;
 if (RgH>$FF) then begin RgH:=(RgH and $FF);RgF:=(RgF or f_C);
 end else begin RgF:=(RgF and (not f_C));end;cz:=10;inc(RpPC);end;
 $3A: begin RgA:=do_read2(do_read(RpPC+1),do_read(RpPC+2));cz:=13;
 inc(RpPC,3);end;
 $3B: begin if (RpSP<>0) then begin RpSP:=RpSP-1;end else
 begin RpSP:=$FFFF;end;cz:=5;inc(RpPC);end;
 $3C: begin tmp2:=((RgA+1) and $FF);RgF:=(flags[tmp2] or (RgF and f_C));
 if (((tmp2 xor RgA) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgA:=tmp2;cz:=5;inc(RpPC);end;
 $3D: begin tmp2:=((RgA-1) and $FF);RgF:=(flags[tmp2] or (RgF and f_C));
 if (((tmp2 xor RgA) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgA:=tmp2;cz:=5;inc(RpPC);end;
 $3E: begin RgA:=do_read(RpPC+1);cz:=7;inc(RpPC,2);end;
 $3F: begin RgF:=RgF xor f_C;cz:=4;inc(RpPC);end;
 $40: begin cz:=5;inc(RpPC);end;
 $49: begin cz:=5;inc(RpPC);end;
 $52: begin cz:=5;inc(RpPC);end;
 $5B: begin cz:=5;inc(RpPC);end;
 $64: begin cz:=5;inc(RpPC);end;
 $6D: begin cz:=5;inc(RpPC);end;
 $7F: begin cz:=5;inc(RpPC);end;
 $41: begin RgB:=RgC;cz:=5;inc(RpPC);end;
 $42: begin RgB:=RgD;cz:=5;inc(RpPC);end;
 $43: begin RgB:=RgE;cz:=5;inc(RpPC);end;
 $44: begin RgB:=RgH;cz:=5;inc(RpPC);end;
 $45: begin RgB:=RgL;cz:=5;inc(RpPC);end;
 $46: begin RgB:=do_read2(RgL,RgH);cz:=7;inc(RpPC);end;
 $47: begin RgB:=RgA;cz:=5;inc(RpPC);end;
 $48: begin RgC:=RgB;cz:=5;inc(RpPC);end;
 $4A: begin RgC:=RgD;cz:=5;inc(RpPC);end;
 $4B: begin RgC:=RgE;cz:=5;inc(RpPC);end;
 $4C: begin RgC:=RgH;cz:=5;inc(RpPC);end;
 $4D: begin RgC:=RgL;cz:=5;inc(RpPC);end;
 $4E: begin RgC:=do_read2(RgL,RgH);cz:=7;inc(RpPC);end;
 $4F: begin RgC:=RgA;cz:=5;inc(RpPC);end;
 $50: begin RgD:=RgB;cz:=5;inc(RpPC);end;
 $51: begin RgD:=RgC;cz:=5;inc(RpPC);end;
 $53: begin RgD:=RgE;cz:=5;inc(RpPC);end;
 $54: begin RgD:=RgH;cz:=5;inc(RpPC);end;
 $55: begin RgD:=RgL;cz:=5;inc(RpPC);end;
 $56: begin RgD:=do_read2(RgL,RgH);cz:=7;inc(RpPC);end;
 $57: begin RgD:=RgA;cz:=5;inc(RpPC);end;
 $58: begin RgE:=RgB;cz:=5;inc(RpPC);end;
 $59: begin RgE:=RgC;cz:=5;inc(RpPC);end;
 $5A: begin RgE:=RgD;cz:=5;inc(RpPC);end;
 $5C: begin RgE:=RgH;cz:=5;inc(RpPC);end;
 $5D: begin RgE:=RgL;cz:=5;inc(RpPC);end;
 $5E: begin RgE:=do_read2(RgL,RgH);cz:=7;inc(RpPC);end;
 $5F: begin RgE:=RgA;cz:=5;inc(RpPC);end;
 $60: begin RgH:=RgB;cz:=5;inc(RpPC);end;
 $61: begin RgH:=RgC;cz:=5;inc(RpPC);end;
 $62: begin RgH:=RgD;cz:=5;inc(RpPC);end;
 $63: begin RgH:=RgE;cz:=5;inc(RpPC);end;
 $65: begin RgH:=RgL;cz:=5;inc(RpPC);end;
 $66: begin RgH:=do_read2(RgL,RgH);cz:=7;inc(RpPC);end;
 $67: begin RgH:=RgA;cz:=5;inc(RpPC);end;
 $68: begin RgL:=RgB;cz:=5;inc(RpPC);end;
 $69: begin RgL:=RgC;cz:=5;inc(RpPC);end;
 $6A: begin RgL:=RgD;cz:=5;inc(RpPC);end;
 $6B: begin RgL:=RgE;cz:=5;inc(RpPC);end;
 $6C: begin RgL:=RgH;cz:=5;inc(RpPC);end;
 $6E: begin RgL:=do_read2(RgL,RgH);cz:=7;inc(RpPC);end;
 $6F: begin RgL:=RgA;cz:=5;inc(RpPC);end;
 $70: begin do_write2(RgL,RgH,RgB);cz:=7;inc(RpPC);end;
 $71: begin do_write2(RgL,RgH,RgC);cz:=7;inc(RpPC);end;
 $72: begin do_write2(RgL,RgH,RgD);cz:=7;inc(RpPC);end;
 $73: begin do_write2(RgL,RgH,RgE);cz:=7;inc(RpPC);end;
 $74: begin do_write2(RgL,RgH,RgH);cz:=7;inc(RpPC);end;
 $75: begin do_write2(RgL,RgH,RgL);cz:=7;inc(RpPC);end;
 $76: begin cz:=4;inc(RpPC);end;
 $77: begin do_write2(RgL,RgH,RgA);cz:=7;inc(RpPC);end;
 $78: begin RgA:=RgB;cz:=5;inc(RpPC);end;
 $79: begin RgA:=RgC;cz:=5;inc(RpPC);end;
 $7A: begin RgA:=RgD;cz:=5;inc(RpPC);end;
 $7B: begin RgA:=RgE;cz:=5;inc(RpPC);end;
 $7C: begin RgA:=RgH;cz:=5;inc(RpPC);end;
 $7D: begin RgA:=RgL;cz:=5;inc(RpPC);end;
 $7E: begin RgA:=do_read2(RgL,RgH);cz:=7;inc(RpPC);end;
 $80: begin tmp2:=RgA+RgB;RgF:=flags[tmp2 and $FF];
 if (((tmp2 xor RgA xor RgB) and $10)<>0) then begin
 RgF:=(RgF or f_A);end;if (tmp2>$FF) then
 begin RgF:=(RgF or f_C);end;RgA:=(tmp2 and $FF);
 cz:=4;inc(RpPC);end;
 $81: begin tmp2:=RgA+RgC;RgF:=flags[tmp2 and $FF];
 if (((tmp2 xor RgA xor RgC) and $10)<>0) then
 begin RgF:=(RgF or f_A);end;
 if (tmp2>$FF) then begin RgF:=(RgF or f_C);end;
 RgA:=tmp2 and $FF;cz:=4;inc(RpPC);end;
 $82: begin tmp2:=RgA+RgD;RgF:=flags[tmp2 and $FF];
 if (((tmp2 xor RgA xor RgD) and $10)<>0) then begin
 RgF:=(RgF or f_A);end;
 if (tmp2>$FF) then begin RgF:=(RgF or f_C);end;
 RgA:=tmp2 and $FF;cz:=4;inc(RpPC);end;
 $83: begin tmp2:=RgA+RgE;RgF:=flags[tmp2 and $FF];
 if (((tmp2 xor RgA xor RgE) and $10)<>0) then begin
 RgF:=(RgF or f_A);end;if (tmp2>$FF) then
 begin RgF:=(RgF or f_C);end;
 RgA:=tmp2 and $FF;cz:=4;inc(RpPC);end;
 $84: begin tmp2:=RgA+RgH;RgF:=flags[tmp2 and $FF];
 if (((tmp2 xor RgA xor RgH) and $10)<>0) then
 begin RgF:=(RgF or f_A);end;
 if (tmp2>$FF) then begin RgF:=(RgF or f_C);end;
 RgA:=tmp2 and $FF;cz:=4;inc(RpPC);end;
 $85: begin tmp2:=RgA+RgL;RgF:=flags[tmp2 and $FF];
 if (((tmp2 xor RgA xor RgL) and $10)<>0) then begin
 RgF:=(RgF or f_A);end;
 if (tmp2>$FF) then begin RgF:=(RgF or f_C);end;
 RgA:=tmp2 and $FF;cz:=4;inc(RpPC);end;
 $86: begin tmp1:=do_read2(RgL,RgH);tmp2:=RgA+tmp1;RgF:=flags[tmp2 and $FF];
 if (((tmp2 xor RgA xor tmp1) and $10)<>0) then begin
 RgF:=(RgF or f_A);end;
 if (tmp2>$FF) then begin RgF:=(RgF or f_C);end;
 RgA:=tmp2 and $FF;cz:=7;inc(RpPC);end;
 $87: begin tmp2:=RgA+RgA;RgF:=flags[tmp2 and $FF];
 if (((tmp2 xor RgA xor RgA) and $10)<>0) then begin
 RgF:=(RgF or f_A);end;
 if (tmp2>$FF) then begin RgF:=(RgF or f_C);end;
 RgA:=tmp2 and $FF;cz:=4;inc(RpPC);end;
 $88: begin tmp2:=RgA+RgB;if ((RgF and f_C)<>0) then tmp2:=tmp2+1 else tmp2:=tmp2+0;
 RgF:=flags[tmp2 and $FF];if (((tmp2 xor RgA xor RgB) and $10)<>0) then
 begin RgF:=(RgF or f_A);end;
 if (tmp2>$FF) then begin RgF:=(RgF or f_C);end;
 RgA:=tmp2 and $FF;cz:=4;inc(RpPC);end;
 $89: begin tmp2:=RgA+RgC;
 if ((RgF and f_C)<>0) then tmp2:=tmp2+1 else tmp2:=tmp2+0;
 RgF:=flags[tmp2 and $FF];
 if (((tmp2 xor RgA xor RgC) and $10)<>0) then
 begin RgF:=(RgF or f_A);end;
 if (tmp2>$FF) then begin RgF:=(RgF or f_C);end;
 RgA:=tmp2 and $FF;cz:=4;inc(RpPC);end;
 $8A: begin tmp2:=RgA+RgD;
 if ((RgF and f_C)<>0) then tmp2:=tmp2+1 else tmp2:=tmp2+0;
 RgF:=flags[tmp2 and $FF];
 if (((tmp2 xor RgA xor RgD) and $10)<>0) then
 begin RgF:=(RgF or f_A);end;
 if (tmp2>$FF) then begin RgF:=(RgF or f_C);end;
 RgA:=tmp2 and $FF;cz:=4;inc(RpPC);
 end;
 $8B: begin tmp2:=RgA+RgE;
 if ((RgF and f_C)<>0) then tmp2:=tmp2+1 else tmp2:=tmp2+0;
 RgF:=flags[tmp2 and $FF];
 if (((tmp2 xor RgA xor RgE) and $10)<>0) then
 begin RgF:=(RgF or f_A);end;
 if (tmp2>$FF) then begin RgF:=(RgF or f_C);end;
 RgA:=tmp2 and $FF;cz:=4;inc(RpPC);end;
 $8C: begin tmp2:=RgA+RgH;
 if ((RgF and f_C)<>0) then tmp2:=tmp2+1 else tmp2:=tmp2+0;
 RgF:=flags[tmp2 and $FF];if (((tmp2 xor RgA xor RgH) and $10)<>0) then
 begin RgF:=(RgF or f_A);end;
 if (tmp2>$FF) then begin RgF:=RgF or f_C;end;
 RgA:=tmp2 and $FF;cz:=4;inc(RpPC);end;
 $8D: begin tmp2:=RgA+RgL;
 if ((RgF and f_C)<>0) then tmp2:=tmp2+1 else tmp2:=tmp2+0;
 RgF:=flags[tmp2 and $FF];
 if (((tmp2 xor RgA xor RgL) and $10)<>0) then
 begin RgF:=(RgF or f_A);end;
 if (tmp2>$FF) then begin RgF:=(RgF or f_C);end;
 RgA:=tmp2 and $FF;cz:=4;inc(RpPC);end;
 $8E: begin tmp1:=do_read2(RgL,RgH);
 tmp2:=RgA+tmp1;if ((RgF and f_C)<>0) then tmp2:=tmp2+1 else tmp2:=tmp2+0;
 RgF:=flags[tmp2 and $FF];
 if (((tmp2 xor RgA xor tmp1) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 if (tmp2>$FF) then begin RgF:=(RgF or f_C);end;
 RgA:=tmp2 and $FF;cz:=7;inc(RpPC);end;
 $8F: begin tmp2:=RgA+RgA;
 if ((RgF and f_C)<>0) then tmp2:=tmp2+1 else tmp2:=tmp2+0;
 RgF:=flags[tmp2 and $FF];
 if (((tmp2 xor RgA xor RgA) and $10)<>0) then
 begin RgF:=(RgF or f_A);end;
 if (tmp2>$FF) then begin RgF:=(RgF or f_C);end;
 RgA:=tmp2 and $FF;cz:=4;inc(RpPC);end;
 $90: begin tmp2:=(RgA-RgB) and $FF;RgF:=flags[tmp2];
 if (RgA<RgB) then begin RgF:=(RgF or f_C);end;
 if (((tmp2 xor RgA xor RgB) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgA:=tmp2;cz:=4;inc(RpPC);end;
 $91: begin tmp2:=(RgA-RgC) and $FF;RgF:=flags[tmp2];
 if (RgA<RgC) then begin RgF:=(RgF or f_C);end;
 if (((tmp2 xor RgA xor RgC) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgA:=tmp2;cz:=4;inc(RpPC);end;
 $92: begin tmp2:=(RgA-RgD) and $FF;RgF:=flags[tmp2];
 if (RgA<RgD) then begin RgF:=(RgF or f_C);end;
 if (((tmp2 xor RgA xor RgD) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgA:=tmp2;cz:=4;inc(RpPC);end;
 $93: begin tmp2:=(RgA-RgE) and $FF;RgF:=flags[tmp2];
 if (RgA<RgE) then begin RgF:=(RgF or f_C);end;
 if (((tmp2 xor RgA xor RgE) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgA:=tmp2;cz:=4;inc(RpPC);end;
 $94: begin tmp2:=(RgA-RgH) and $FF;RgF:=flags[tmp2];
 if (RgA<RgH) then begin RgF:=(RgF or f_C);end;
 if (((tmp2 xor RgA xor RgH) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgA:=tmp2;cz:=4;inc(RpPC);end;
 $95: begin tmp2:=(RgA-RgL) and $FF;RgF:=flags[tmp2];
 if (RgA<RgL) then begin RgF:=RgF or f_C;end;
 if (((tmp2 xor RgA xor RgL) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgA:=tmp2;cz:=4;inc(RpPC);end;
 $96: begin tmp1:=do_read2(RgL,RgH);tmp2:=(RgA-tmp1) and $FF;RgF:=flags[tmp2];
 if (RgA<tmp1) then begin RgF:=(RgF or f_C);end;
 if (((tmp2 xor RgA xor tmp1) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgA:=tmp2;cz:=7;inc(RpPC);end;
 $97: begin RgF:=flags[0];RgA:=0;cz:=4;inc(RpPC);end;
 $98: begin if ((RgF and f_C)<>0) then tmp3:=1 else tmp3:=0;tmp2:=(RgA-RgB-tmp3) and $FF;
 RgF:=flags[tmp2];if (RgA<RgB+tmp3) then begin RgF:=(RgF or f_C);end;
 if (((tmp2 xor RgA xor RgB) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgA:=tmp2;cz:=4;inc(RpPC);end;
 $99: begin if ((RgF and f_C)<>0) then tmp3:=1 else tmp3:=0;tmp2:=(RgA-RgC-tmp3) and $FF;
 RgF:=flags[tmp2];if (RgA<(RgC+tmp3)) then begin RgF:=(RgF or f_C);end;
 if (((tmp2 xor RgA xor RgC) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgA:=tmp2;cz:=4;inc(RpPC);end;
 $9A: begin if ((RgF and f_C)<>0) then tmp3:=1 else tmp3:=0;tmp2:=(RgA-RgD-tmp3) and $FF;
 RgF:=flags[tmp2];if (RgA<RgD+tmp3) then begin RgF:=(RgF or f_C);end;
 if (((tmp2 xor RgA xor RgD) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgA:=tmp2;cz:=4;inc(RpPC);end;
 $9B: begin if ((RgF and f_C)<>0) then tmp3:=1 else tmp3:=0;tmp2:=(RgA-RgE-tmp3) and $FF;
 RgF:=flags[tmp2];if (RgA<RgE+tmp3) then begin RgF:=(RgF or f_C);end;
 if (((tmp2 xor RgA xor RgE) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgA:=tmp2;cz:=4;inc(RpPC);end;
 $9C: begin if ((RgF and f_C)<>0) then tmp3:=1 else tmp3:=0;
 tmp2:=(RgA-RgH-tmp3) and $FF;RgF:=flags[tmp2];if (RgA<RgH+tmp3) then
 begin RgF:=(RgF or f_C);end;
 if (((tmp2 xor RgA xor RgH) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgA:=tmp2;cz:=4;inc(RpPC);end;
 $9D: begin if ((RgF and f_C)<>0) then tmp3:=1 else tmp3:=0;
 tmp2:=(RgA-RgL-tmp3) and $FF;RgF:=flags[tmp2];
 if (RgA<RgL+tmp3) then begin RgF:=(RgF or f_C);end;
 if (((tmp2 xor RgA xor RgL) and $10)<>0) then begin
 RgF:=(RgF or f_A);end;
 RgA:=tmp2;cz:=4;inc(RpPC);end;
 $9E: begin tmp1:=do_read2(RgL,RgH);
 if ((RgF and f_C)<>0) then tmp3:=1 else tmp3:=0;
 tmp2:=(RgA-tmp1-tmp3) and $FF;RgF:=flags[tmp2];
 if (RgA<tmp1+tmp3) then begin RgF:=(RgF or f_C);end;
 if (((tmp2 xor RgA xor tmp1) and $10)<>0) then begin
 RgF:=(RgF or f_A);end;
 RgA:=tmp2;cz:=7;inc(RpPC);end;
 $9F: begin if ((RgF and f_C)<>0) then tmp2:=$FF else tmp2:=0;
 RgF:=flags[tmp2];if (tmp2<>0) then begin RgF:=RgF or (f_A or f_C);end;
 RgA:=tmp2;cz:=4;inc(RpPC);end;
 $A0: begin RgA:=RgA and RgB;RgF:=flags[RgA] or (RgF and f_A);
 cz:=4;inc(RpPC);end;
 $A1: begin RgA:=RgA and RgC;RgF:=flags[RgA] or (RgF and f_A);
 cz:=4;inc(RpPC);end;
 $A2: begin RgA:=RgA and RgD;RgF:=flags[RgA] or (RgF and f_A);
 cz:=4;inc(RpPC);end;
 $A3: begin RgA:=RgA and RgE;RgF:=flags[RgA] or (RgF and f_A);
 cz:=4;inc(RpPC);end;
 $A4: begin RgA:=RgA and RgH;RgF:=flags[RgA] or (RgF and f_A);
 cz:=4;inc(RpPC);end;
 $A5: begin RgA:=RgA and RgL;RgF:=flags[RgA] or (RgF and f_A);
 cz:=4;inc(RpPC);end;
 $A6: begin tmp1:=do_read2(RgL,RgH);
 RgA:=RgA and tmp1;RgF:=flags[RgA] or (RgF and f_A);
 cz:=7;inc(RpPC);end;
 $A7: begin RgA:=RgA and RgA;RgF:=flags[RgA] or (RgF and f_A);
 cz:=4;inc(RpPC);end;
 $A8: begin RgA:=RgA xor RgB;RgF:=flags[RgA] or (RgF and f_A);
 cz:=4;inc(RpPC);end;
 $A9: begin RgA:=RgA xor RgC;RgF:=flags[RgA] or (RgF and f_A);
 cz:=4;inc(RpPC);end;
 $AA: begin RgA:=RgA xor RgD;RgF:=flags[RgA] or (RgF and f_A);
 cz:=4;inc(RpPC);end;
 $AB: begin RgA:=RgA xor RgE;RgF:=flags[RgA] or (RgF and f_A);
 cz:=4;inc(RpPC);end;
 $AC: begin RgA:=RgA xor RgH;RgF:=flags[RgA] or (RgF and f_A);
 cz:=4;inc(RpPC);end;
 $AD: begin RgA:=RgA xor RgL;RgF:=flags[RgA] or (RgF and f_A);
 cz:=4;inc(RpPC);end;
 $AE: begin tmp1:=do_read2(RgL,RgH);RgA:=RgA xor tmp1;
 RgF:=flags[RgA] or (RgF and f_A);cz:=7;inc(RpPC);end;
 $AF: begin RgA:=0;RgF:=flags[RgA] or (RgF and f_A);
 cz:=4;inc(RpPC);end;
 $B0: begin RgA:=RgA or RgB;RgF:=flags[RgA] or (RgF and f_A);
 cz:=4;inc(RpPC);end;
 $B1: begin RgA:=RgA or RgC;RgF:=flags[RgA] or (RgF and f_A);
 cz:=4;inc(RpPC);end;
 $B2: begin RgA:=RgA or RgD;
 RgF:=flags[RgA] or (RgF and f_A);cz:=4;
 inc(RpPC);end;
 $B3: begin RgA:=RgA or RgE;RgF:=flags[RgA] or (RgF and f_A);
 cz:=4;inc(RpPC);end;
 $B4: begin RgA:=RgA or RgH;RgF:=flags[RgA] or (RgF and f_A);
 cz:=4;inc(RpPC);end;
 $B5: begin RgA:=RgA or RgL;RgF:=flags[RgA] or (RgF and f_A);
 cz:=4;inc(RpPC);end;
 $B6: begin tmp1:=do_read2(RgL,RgH);RgA:=RgA or tmp1;
 RgF:=flags[RgA] or (RgF and f_A);cz:=7;
 inc(RpPC);end;
 $B7: begin RgA:=RgA or RgA;RgF:=flags[RgA] or (RgF and f_A);
 cz:=4;inc(RpPC);end;
 $B8: begin tmp2:=(RgA-RgB) and $FF;RgF:=flags[tmp2];
 if (RgA<RgB) then begin RgF:=(RgF or f_C);end;
 if (((tmp2 xor RgA xor RgB) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 cz:=4;inc(RpPC);end;
 $B9: begin tmp2:=(RgA-RgC) and $FF;RgF:=flags[tmp2];if (RgA<RgC) then
 begin RgF:=(RgF or f_C);end;
 if (((tmp2 xor RgA xor RgC) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 cz:=4;inc(RpPC);end;
 $BA: begin tmp2:=(RgA-RgD) and $FF;RgF:=flags[tmp2];
 if (RgA<RgD) then begin RgF:=(RgF or f_C);end;
 if (((tmp2 xor RgA xor RgD) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 cz:=4;inc(RpPC);end;
 $BB: begin tmp2:=(RgA-RgE) and $FF;RgF:=flags[tmp2];
 if (RgA<RgE) then begin RgF:=(RgF or f_C);end;
 if (((tmp2 xor RgA xor RgE) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 cz:=4;inc(RpPC);end;
 $BC: begin tmp2:=(RgA-RgH) and $FF;RgF:=flags[tmp2];
 if (RgA<RgH) then begin RgF:=(RgF or f_C);end;
 if (((tmp2 xor RgA xor RgH) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 cz:=4;inc(RpPC);end;
 $BD: begin tmp2:=(RgA-RgL) and $FF;RgF:=flags[tmp2];
 if (RgA<RgL) then begin RgF:=(RgF or f_C);end;
 if (((tmp2 xor RgA xor RgL) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 cz:=4;inc(RpPC);end;
 $BE: begin tmp1:=do_read2(RgL,RgH);tmp2:=(RgA-tmp1) and $FF;RgF:=flags[tmp2];
 if (RgA<tmp1) then begin RgF:=(RgF or f_C);end;
 if (((tmp2 xor RgA xor tmp1) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 cz:=7;inc(RpPC);end;
 $BF: begin RgF:=flags[0];cz:=4;inc(RpPC);end;
 $C0: begin if ((RgF and f_Z)<>0) then begin cz:=5;inc(RpPC);end else
 begin RpPC:=do_read(RpSP);RpPC:=RpPC+(do_read(RpSP+1) shl 8);RpSP:=(RpSP+2) and $FFFF;
 cz:=11;end;end;
 $C1: begin RgC:=do_read(RpSP);RgB:=do_read(RpSP+1);RpSP:=(RpSP+2) and $FFFF;
 cz:=10;inc(RpPC);end;
 $C2: begin if ((RgF and f_Z)<>0) then begin cz:=10;inc(RpPC,3);end else
 begin RpPC:=do_read(RpPC+1)+((do_read(RpPC+2) shl 8));cz:=10;end;end;
 $C3: begin RpPC:=do_read(RpPC+1)+((do_read(RpPC+2) shl 8));cz:=10;end;
 $C4: begin if ((RgF and f_Z)<>0) then begin cz:=11;
 inc(RpPC,3);end else begin tmp1:=do_read(RpPC+1)+((do_read(RpPC+2) shl 8));
 RpSP:=(RpSP-2) and $FFFF;inc(RpPC,3);do_write(RpSP,RpPC and $FF);
 do_write(RpSP+1,(RpPC shr 8) and $FF);RpPC:=tmp1;cz:=17;end;end;
 $C5: begin RpSP:=(RpSP-2) and $FFFF;do_write(RpSP,RgC);do_write(RpSP+1,RgB);
 cz:=11;inc(RpPC);end;
 $C6: begin tmp1:=do_read(RpPC+1);tmp2:=RgA+tmp1;RgF:=flags[tmp2 and $FF];
 if (((tmp2 xor RgA xor tmp1) and $10)<>0) then begin RgF:=RgF or f_A;end;
 if (tmp2>$FF) then begin RgF:=RgF or f_C;end;
 RgA:=tmp2 and $FF;cz:=7;inc(RpPC,2);end;
 $C7: begin RpSP:=(RpSP-2) and $FFFF;inc(RpPC);do_write(RpSP,RpPC and $FF);
 do_write(RpSP+1,(RpPC shr 8) and $FF);RpPC:=0*8;cz:=11;end;
 $C8: begin if ((RgF and f_Z)=0) then begin cz:=5;inc(RpPC);
 end else begin RpPC:=do_read(RpSP);RpPC:=RpPC+(do_read(RpSP+1) shl 8);
 RpSP:=(RpSP+2) and $FFFF;cz:=11;end;end;
 $C9: begin RpPC:=do_read(RpSP);RpPC:=RpPC+(do_read(RpSP+1) shl 8);RpSP:=(RpSP+2) and $FFFF;
 cz:=11;end;
 $CA: begin if ((RgF and f_Z)=0) then begin cz:=10;
 inc(RpPC,3);end else begin RpPC:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);
 cz:=10;end;end;
 $CB: begin begin RpPC:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);
 cz:=10;end;end;
 $CC: begin if ((RgF and f_Z)=0) then begin cz:=11;inc(RpPC,3);end else
 begin tmp1:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);RpSP:=(RpSP-2) and $FFFF;
 inc(RpPC,3);do_write(RpSP,RpPC and $FF);do_write(RpSP+1,(RpPC shr 8) and $FF);
 RpPC:=tmp1;cz:=17;end end;
 $CD: begin tmp1:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);RpSP:=(RpSP-2) and $FFFF;
 inc(RpPC,3);do_write(RpSP,RpPC and $FF);do_write(RpSP+1,(RpPC shr 8) and $FF);
 RpPC:=tmp1;cz:=17;end;
 $CE: begin tmp1:=do_read(RpPC+1);tmp2:=RgA+tmp1;
 if ((RgF and f_C)<>0) then tmp2:=tmp2+1 else tmp2:=tmp2+0;
 RgF:=flags[tmp2 and $FF];
 if (((tmp2 xor RgA xor tmp1) and $10)<>0) then begin RgF:=RgF or f_A;end;
 if (tmp2>$FF) then begin RgF:=RgF or f_C;end;
 RgA:=tmp2 and $FF;cz:=7;inc(RpPC,2);end;
 $CF: begin RpSP:=(RpSP-2) and $FFFF;inc(RpPC);
 do_write(RpSP,RpPC and $FF);do_write(RpSP+1,(RpPC shr 8) and $FF);
 RpPC:=1*8;cz:=11;end;
 $D0: begin if ((RgF and f_C)<>0) then begin cz:=5;inc(RpPC);end else
 begin RpPC:=do_read(RpSP);RpPC:=RpPC+(do_read(RpSP+1) shl 8);
 RpSP:=(RpSP+2) and $FFFF;cz:=11;end end;
 $D1: begin RgE:=do_read(RpSP);RgD:=do_read(RpSP+1);RpSP:=(RpSP+2) and $FFFF;
 cz:=10;inc(RpPC);end;
 $D2: begin if ((RgF and f_C)<>0) then begin cz:=10;
 inc(RpPC,3);end else begin
 RpPC:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);cz:=10;end;end;
 $D3: begin do_output(do_read(RpPC+1),RgA);cz:=10;inc(RpPC,2);end;
 $D4: begin if ((RgF and f_C)<>0) then begin cz:=11;inc(RpPC,3);end
 else begin tmp1:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);
 RpSP:=(RpSP-2) and $FFFF;inc(RpPC,3);do_write(RpSP,RpPC and $FF);
 do_write(RpSP+1,(RpPC shr 8) and $FF);RpPC:=tmp1;cz:=17;end;end;
 $D5: begin RpSP:=(RpSP-2) and $FFFF;do_write(RpSP,RgE);do_write(RpSP+1,RgD);
 cz:=11;inc(RpPC);end;
 $D6: begin tmp1:=do_read(RpPC+1);tmp2:=(RgA-tmp1) and $FF;RgF:=flags[tmp2];
 if (RgA<tmp1) then begin RgF:=RgF or f_C;end;
 if (((tmp2 xor RgA xor tmp1) and $10)<>0) then begin RgF:=RgF or f_A;end;
 RgA:=tmp2;cz:=7;inc(RpPC,2);end;
 $D7: begin RpSP:=(RpSP-2) and $FFFF;inc(RpPC);do_write(RpSP,RpPC and $FF);
 do_write(RpSP+1,(RpPC shr 8) and $FF);RpPC:=2*8;cz:=11;end;
 $D8: begin if ((RgF and f_C)=0) then begin cz:=5;inc(RpPC);end
 else begin RpPC:=do_read(RpSP);RpPC:=RpPC+do_read(RpSP+1) shl 8;
 RpSP:=(RpSP+2) and $FFFF;cz:=11;end;end;
 $D9: begin begin RpPC:=do_read(RpSP);RpPC:=RpPC+do_read(RpSP+1) shl 8;
 RpSP:=(RpSP+2) and $FFFF;cz:=11;end;end;
 $DA: begin if ((RgF and f_C)=0) then begin cz:=10;inc(RpPC,3);end
 else begin RpPC:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);cz:=10;end;end;
 $DB: begin RgA:=do_input(do_read(RpPC+1));cz:=10;inc(RpPC,2);end;
 $DC: begin if ((RgF and f_C)=0) then begin cz:=11;inc(RpPC,3);end
 else begin tmp1:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);RpSP:=(RpSP-2) and $FFFF;
 inc(RpPC,3);do_write(RpSP,RpPC and $FF);do_write(RpSP+1,(RpPC shr 8) and $FF);
 RpPC:=tmp1;cz:=17;end;end;
 $DD: begin begin tmp1:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);
 RpSP:=(RpSP-2) and $FFFF;inc(RpPC,3);do_write(RpSP,RpPC and $FF);
 do_write(RpSP+1,(RpPC shr 8) and $FF);RpPC:=tmp1;
 cz:=17;end;end;
 $ED: begin begin tmp1:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);
 RpSP:=(RpSP-2) and $FFFF;inc(RpPC,3);
 do_write(RpSP,RpPC and $FF);do_write(RpSP+1,(RpPC shr 8) and $FF);
 RpPC:=tmp1;cz:=17;end;end;
 $FD: begin begin tmp1:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);RpSP:=(RpSP-2) and $FFFF;
 inc(RpPC,3);do_write(RpSP,RpPC and $FF);do_write(RpSP+1,(RpPC shr 8) and $FF);
 RpPC:=tmp1;cz:=17;end;end;
 $DE: begin tmp1:=do_read(RpPC+1);if ((RgF and f_C)<>0) then tmp3:=1 else tmp3:=0;
 tmp2:=(RgA-tmp1-tmp3) and $FF;RgF:=flags[tmp2];if (RgA<tmp1+tmp3) then
 begin RgF:=RgF or f_C;end;
 if (((tmp2 xor RgA xor tmp1) and $10)<>0) then begin RgF:=RgF or f_A;end;
 RgA:=tmp2;cz:=7;inc(RpPC,2);end;
 $DF: begin RpSP:=(RpSP-2) and $FFFF;inc(RpPC); do_write(RpSP,RpPC and $FF);
 do_write(RpSP+1,(RpPC shr 8) and $FF); RpPC:=3*8; cz:=11; end;
 $E0: begin if ((RgF and f_P)<>0) then begin cz:=5;inc(RpPC);end
 else begin RpPC:=do_read(RpSP);RpPC:=RpPC+do_read(RpSP+1) shl 8;
 RpSP:=(RpSP+2) and $FFFF;cz:=11;end ;end;
 $E1: begin RgL:=do_read(RpSP);RgH:=do_read(RpSP+1);RpSP:=(RpSP+2) and $FFFF;
 cz:=10;inc(RpPC);end;
 $E2: begin if ((RgF and f_P)<>0) then begin cz:=10; inc(RpPC,3);end else begin
 RpPC:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8); cz:=10;end;end;
 $E3: begin tmp1:=do_read(RpSP);do_write(RpSP,RgL);RgL:=tmp1;
 tmp1:=do_read(RpSP+1);do_write(RpSP+1,RgH);RgH:=tmp1;
 cz:=18;inc(RpPC);end;
 $E4: begin if ((RgF and f_P)<>0) then
 begin cz:=11;inc(RpPC,3);end else
 begin tmp1:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);
 RpSP:=(RpSP-2) and $FFFF;inc(RpPC,3);do_write(RpSP,RpPC and $FF);
 do_write(RpSP+1,(RpPC shr 8) and $FF);RpPC:=tmp1;cz:=17;end;end;
 $E5: begin RpSP:=(RpSP-2) and $FFFF;do_write(RpSP,RgL);
 do_write(RpSP+1,RgH);cz:=11;inc(RpPC);end;
 $E6: begin RgA:=RgA and do_read(RpPC+1);RgF:=flags[RgA] or (RgF and f_A);
 cz:=7;inc(RpPC,2);end;
 $E7: begin RpSP:=(RpSP-2) and $FFFF;inc(RpPC);
 do_write(RpSP,RpPC and $FF);do_write(RpSP+1,(RpPC shr 8) and $FF);
 RpPC:=4*8;cz:=11;end;
 $E8: begin if ((RgF and f_P)=0) then begin
 cz:=5;inc(RpPC);end else begin
 RpPC:=do_read(RpSP);RpPC:=RpPC+do_read(RpSP+1) shl 8;
 RpSP:=(RpSP+2) and $FFFF;cz:=11;end;end;
 $E9: begin RpPC:=(RgH shl 8)+RgL;cz:=5;end;
 $EA: begin if ((RgF and f_P)=0) then begin cz:=10;
 inc(RpPC,3);end else begin
 RpPC:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);
 cz:=10;end;end;
 $EB: begin tmp1:=RgD;RgD:=RgH;RgH:=tmp1;
 tmp1:=RgE;RgE:=RgL;RgL:=tmp1;cz:=4;
 inc(RpPC);end;
 $EC: begin if ((RgF and f_P)=0) then begin cz:=11;
 inc(RpPC,3);end else begin
 tmp1:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);
 RpSP:=(RpSP-2) and $FFFF;inc(RpPC,3);
 do_write(RpSP,RpPC and $FF);do_write(RpSP+1,(RpPC shr 8) and $FF);
 RpPC:=tmp1;cz:=17;end;end;
 $EE: begin RgA:= RgA xor do_read(RpPC+1);RgF:=flags[RgA] or (RgF and f_A);
 cz:=7;inc(RpPC,2);end;
 $EF: begin RpSP:=(RpSP-2) and $FFFF;inc(RpPC);
 do_write(RpSP,RpPC and $FF);do_write(RpSP+1,(RpPC shr 8) and $FF);
 RpPC:=5*8;cz:=11;end;
 $F0: begin if ((RgF and f_S)<>0) then begin
 cz:=5;inc(RpPC);end
 else begin RpPC:=do_read(RpSP);RpPC:=RpPC+(do_read(RpSP+1) shl 8);
 RpSP:=(RpSP+2) and $FFFF;cz:=11;end;end;
 $F1: begin RgF:=do_read(RpSP);RgA:=do_read(RpSP+1);
 RpSP:=(RpSP+2) and $FFFF;cz:=10;inc(RpPC);end;
 $F2: begin if ((RgF and f_S)<>0) then begin
 cz:=10;inc(RpPC,3);end else
 begin RpPC:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);cz:=10;end;end;
 $F4: begin if ((RgF and f_S)<>0) then begin cz:=11;
 inc(RpPC,3);end else begin
 tmp1:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);
 RpSP:=(RpSP-2) and $FFFF;inc(RpPC,3);
 do_write(RpSP,RpPC and $FF);do_write(RpSP+1,(RpPC shr 8) and $FF);
 RpPC:=tmp1;cz:=17;end;end;
 $F5: begin RpSP:=(RpSP-2) and $FFFF;do_write(RpSP,RgF);
 do_write(RpSP+1,RgA);cz:=11;inc(RpPC);end;
 $F6: begin RgA:=RgA or do_read(RpPC+1);RgF:=flags[RgA] or (RgF and f_A);
 cz:=7;inc(RpPC,2);end;
 $F7: begin RpSP:=(RpSP-2) and $FFFF;inc(RpPC);
 do_write(RpSP,RpPC and $FF);do_write(RpSP+1,(RpPC shr 8) and $FF);
 RpPC:=6*8;cz:=11;end;
 $F8: begin if ((RgF and f_S)=0) then begin cz:=5;
 inc(RpPC);end else begin
 RpPC:=do_read(RpSP);RpPC:=RpPC+(do_read(RpSP+1) shl 8);
 RpSP:=(RpSP+2) and $FFFF;cz:=11;end;end;
 $F9: begin RpSP:=(RgH shl 8)+RgL;cz:=5;inc(RpPC);end;
 $FA: begin if ((RgF and f_S)=0) then begin cz:=10;
 inc(RpPC,3);end else begin RpPC:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);
 cz:=10;end;end;
 $FC: begin if ((RgF and f_S)=0) then begin cz:=11;
 inc(RpPC,3);end else begin tmp1:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);
 RpSP:=(RpSP-2) and $FFFF;inc(RpPC,3);do_write(RpSP,RpPC and $FF);
 do_write(RpSP+1,(RpPC shr 8) and $FF);RpPC:=tmp1;cz:=17;
 end;end;
 $FE: begin tmp1:=do_read(RpPC+1);tmp2:=(RgA-tmp1) and $FF;
 RgF:=flags[tmp2];if (RgA<tmp1) then begin
 RgF:=RgF or f_C;end;
 if (((tmp2 xor RgA xor tmp1) and $10)<>0) then begin
 RgF:=RgF or f_A;end;cz:=7;inc(RpPC,2);end;
 $FF: begin RpSP:=(RpSP-2) and $FFFF;
 inc(RpPC);do_write(RpSP,RpPC and $FF);do_write(RpSP+1,(RpPC shr 8) and $FF);
 RpPC:=7*8;cz:=11;end
end;{<=case opcode of}
cz1:=cz1+cz; CT:=CT+cz;
end;{<=while (cz1 < nb_cycles) do}
end;


{ВИВЕДЕННЯ НА ЕКРАН}

function compute_color_index(port: byte;LVcolor: Byte): LongInt;
const clBlack=$000000;clLime=$00FF00;clBlue=$FF0000;clRed=$0000FF;
 clAqua=$FFFF00;clYellow=$00FFFF;clFuchsia=$FF00FF;clWhite=$FFFFFF;
const pas_clBlack=0;pas_clLime=10;pas_clBlue=9;pas_clRed=12;pas_clAqua=11;
pas_clYellow=14;pas_clFuchsia=13;pas_clWhite=15;

var Res:LongInt;
begin
 Res:=clBlack;
 if ((port and $40)<>0) then Res:= (Res xor clBlue);
 if ((port and $20)<>0) then Res:= (Res xor clLime);
 if ((port and $10)<>0) then Res:= (Res xor clRed);
 case LVcolor of
   0: begin
      if ((port and $08)=0) then begin Res:= (Res xor clRed);end;
       if ((port and $04)=0) then begin Res:= (Res xor clBlue);end;end;
   1: begin Res:= (Res xor clLime);end;
   2: begin Res:= (Res xor clBlue);if ((port and $01)=0) then
       begin Res:= (Res xor clRed);end;end;
    3: begin Res:= (Res xor clRed);
    if ((port and $02)=0) then begin Res:= (Res xor clLime);end;end;end;
iF Res<$FF0000 then begin
 iF Res<$00FF00 then begin
    iF Res=clBlack then res:=pas_clBlack else
     If Res=clRed then res:=pas_clRed else      end else begin
      iF Res=clLime then res:=pas_clLime else
       If Res=(clLime + clRed) then res:=pas_clYellow else
                   end end else
begin  iF Res<$FFFF00 then begin
If Res=clBlue then res:=pas_clBlue else
If Res=(clBlue + clRed) then res:=pas_clFuchsia else  end else begin
    If Res=(clLime + clBlue ) then res:=pas_clAqua else
    If Res=(clLime + clBlue+ clRed)     then res:=pas_clWhite;end;
end;compute_color_index:=res;end;



Procedure PutPixelZoom(X,Y,clr:Longint);
begin

X:=X+OffSetX;Y:=Y+OffSetY;

If (ZoomX=1) and (ZoomY=1) then uGraph.uPutPixel(X,Y,clr) else

uBar((X*ZoomX),(Y*ZoomY),(X*ZoomX)+(ZoomX-1),(Y*ZoomY)+(ZoomY-1),Clr);

end;

procedure GamecanvasCanvasPixels(vertX,gorY,portsC1,video_i:Cardinal);
Var pix:byte;
begin
begin pix:=0;if (video_i and 128)=128 then pix:=pix+1;if (video_i and 8)=8 then pix:=pix+2;
PutPixelZoom(vertX,gorY,compute_color_index(portsC1,pix));end;

begin pix:=0;if (video_i and 64)=64 then pix:=pix+1;if (video_i and 4)=4 then pix:=pix+2;
PutPixelZoom(vertX+1,gorY,compute_color_index(portsC1,pix));end;

begin pix:=0;if (video_i and 32)=32 then pix:=pix+1;if (video_i and 2)=2 then pix:=pix+2;
PutPixelZoom(vertX+2,gorY,compute_color_index(portsC1,pix));end;

begin pix:=0;if (video_i and 16)=16 then pix:=pix+1;if (video_i and 1)=1 then pix:=pix+2;
PutPixelZoom(vertX+3,gorY,compute_color_index(portsC1,pix));end;

end;


procedure drawScreen1;// "жорстка перемальовка"
var i,vertX,gorY:Cardinal;
begin i:=0;vertX:=0;gorY:=0;
{$R-} while (i<$4000) do begin

GamecanvasCanvasPixels(vertX,gorY,ports[$C1],video[i]);

 vertX:=vertX+4;if vertX>=256 then begin vertX:=0;gorY:=gorY+1;end;inc(i);end;{$R+}
{$R-}for I := 0 to $4000 do VideoDirty_[i]:= video[i];{$R+}

FlagChangeC1:=0;FlagChangeVIDEO:=0;ChangeVIDEOadrMIN:=16383;ChangeVIDEOadrMAX:=0;end;


procedure drawScreen2;// "м'яка перемальовка"
var i,vertX,gorY : Cardinal;
begin i:=ChangeVIDEOadrMIN;{vertX:=0;gorY:=0;}
{$R-}while (i <=ChangeVIDEOadrMAX) do Begin
 if video[i]<>VideoDirty_[i] then
 begin vertX:= (i mod 64)*4;gorY:=(i div 64);

 GamecanvasCanvasPixels(vertX,gorY,ports[$C1],video[i]);

 VideoDirty_[i]:=video[i];
 end;inc(i);end;{$R+}
FlagChangeC1:=0;FlagChangeVIDEO:=0;ChangeVIDEOadrMIN:=16383;ChangeVIDEOadrMAX:=0;end;


procedure DrawScreen;
begin
 If FlagChangeC1=1 then drawScreen1 // "жорстка перемальовка"
 else if FlagChangeVIDEO=1 then drawScreen2;// "м'яка перемальовка"
end;


end.

4

Видалено все окрім case opcode of а також
inc(RpPC); inc(RpPC,2);  inc(RpPC,3);
cz:=4;cz:=10;cz:=7;cz:=5;cz:=16;cz:=17;cz:=18;

Код:
case opcode of
 $00: begin end;
 $F3: begin end;
 $FB: begin end;
 $01: begin RgB:=do_read(RpPC+2);RgC:=do_read(RpPC+1);end;
 $02: begin do_write2(RgC,RgB,RgA);end;
 $03: begin RgC:=RgC+1;if (RgC>$FF) then begin RgC:=0;RgB:=RgB+1;
 if (RgB>$FF) then begin RgB:=0;end;end;end;
 $04: begin tmp2:=((RgB+1) and $FF);RgF:=(flags[tmp2] or (RgF and f_C));
 if (((tmp2 xor RgB) and $10)<>0) then
 begin RgF:=RgF or f_A;end;RgB:=tmp2;end;
 $05: begin tmp2:=((RgB-1) and $FF);RgF:=(flags[tmp2] or (RgF and f_C));
 if (((tmp2 xor RgB) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgB:=tmp2;end;
 $06: begin RgB:=do_read(RpPC+1);end;
 $07: begin RgA:=RgA SHL 1;if (RgA>$FF) then begin RgA:=RgA or 1;
 RgF:=RgF or f_C;RgA:= RgA and $FF;end else
 begin RgF:=(RgF and (not f_C));end;end;
 $08: begin begin end;end;
 $10: begin begin end;end;
 $18: begin begin end;end;
 $20: begin begin end;end;
 $28: begin begin end;end;
 $30: begin begin end;end;
 $38: begin begin end;end;
 $09: begin RgL:=RgL+RgC;RgH:=RgH+RgB;if (RgL>$FF) then
 begin inc(RgH);RgL:=(RgL and $FF);end;if (RgH>$FF) then
 begin RgH:=(RgH and $FF);RgF:=(RgF or f_C);end else
 begin RgF:=(RgF and (not f_C));end;end;
 $0A: begin RgA:=do_read2(RgC,RgB);end;
 $0B: begin RgC:=RgC-1;if (RgC<0) then begin RgC:=$FF;RgB:=RgB-1;
 if (RgB<0) then begin RgB:=$FF;end;end;
 end;
 $0C: begin tmp2:=((RgC+1) and $FF);RgF:=(flags[tmp2] or (RgF and f_C));
 if (((tmp2 xor RgC) and $10)<>0) then begin RgF:=RgF or f_A;end;
 RgC:=tmp2;end;
 $0D: begin tmp2:=((RgC-1) and $FF);RgF:=flags[tmp2] or (RgF and f_C);
 if (((tmp2 xor RgC) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgC:=tmp2;end;
 $0E: begin RgC:=do_read(RpPC+1);end;
 $0F: begin tmp1:=(RgA and 1);RgA:=(RgA shr 1);if (tmp1<>0) then
 begin RgA:=(RgA or $80);RgF:=(RgF or f_C);end else
 begin RgF:=(RgF and ( not f_C));end;end;
 $11: begin RgD:=do_read(RpPC+2);RgE:=do_read(RpPC+1);end;
 $12: begin do_write2(RgE,RgD,RgA);end;
 $13: begin RgE:=RgE+1;if (RgE>$FF) then begin RgE:=0;RgD:=RgD+1;
 if (RgD>$FF) then begin RgD:=0;end;end;end;
 $14: begin tmp2:=((RgD+1)and $FF);RgF:=(flags[tmp2] or (RgF and f_C));
 if (((tmp2 xor RgD) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgD:=tmp2;end;
 $15: begin tmp2:=((RgD-1)and $FF);RgF:=(flags[tmp2] or (RgF and f_C));
 if (((tmp2 xor RgD) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgD:=tmp2;end;
 $16: begin RgD:=do_read(RpPC+1);end;
 $17: begin RgA:=(RgA shl 1);if ((RgF and f_C)<>0) then begin RgA:=(RgA or 1);end;
 if (RgA>$FF) then begin RgF:=(RgF or f_C);RgA:=(RgA and $FF);end else begin
 RgF:=(RgF and (not f_C));end;end;
 $19: begin RgL:=(RgL + RgE);RgH:=(RgH + RgD);if (RgL>$FF) then
 begin inc(RgH);RgL:=(RgL and $FF);end;
 if (RgH>$FF) then begin RgH:=(RgH and $FF);RgF:=(RgF or f_C);end else
 begin RgF:=(RgF and not (f_C));end;end;
 $1A: begin RgA:=do_read2(RgE,RgD);end;
 $1B: begin RgE:=RgE-1;if (RgE<0) then begin RgE:=$FF;RgD:=RgD-1;
 if (RgD<0) then begin RgD:=$FF;end;end;
 end;
 $1C: begin tmp2:=((RgE+1)and $FF);RgF:=(flags[tmp2] or (RgF and f_C));
 if (((tmp2 xor RgE) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgE:=tmp2;end;
 $1D: begin tmp2:=((RgE-1) and $FF);RgF:=(flags[tmp2] or (RgF and f_C));
 if (((tmp2 xor RgE) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgE:=tmp2;end;
 $1E: begin RgE:=do_read(RpPC+1);end;
 $1F: begin tmp1:=(RgA and 1);RgA:=(RgA SHR 1);if ((RgF and f_C)<>0) then
 begin RgA:=(RgA or $80);end;
 if (tmp1<>0) then begin RgF:=(RgF or f_C);end else
 begin RgF:=(RgF and not(f_C));end;end;
 $21: begin RgH:=do_read(RpPC+2);RgL:=do_read(RpPC+1);end;
 $22: begin tmp1:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);do_write(tmp1,RgL);
 do_write(tmp1+1,RgH);end;
 $23: begin RgL:=RgL+1;if (RgL>$FF) then begin RgL:=0;RgH:=RgH+1;
 if (RgH>$FF) then begin RgH:=0;end;end;
 end;
 $24: begin tmp2:=((RgH+1) and $FF);RgF:=(flags[tmp2] or (RgF and f_C));
 if (((tmp2 xor RgH) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgH:=tmp2;end;
 $25: begin tmp2:=((RgH-1) and $FF);RgF:=(flags[tmp2] or (RgF and f_C));
 if (((tmp2 xor RgH) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgH:=tmp2;end;
 $26: begin RgH:=do_read(RpPC+1);end;
 $27: begin tmp1:=0;if (((RgF and f_C)<>0) or (RgA>$99)) then begin
 tmp1:=(tmp1 or $60);end;
 if (((RgF and f_A)<>0) or ((RgA and $0F)>$09)) then begin
 tmp1:=(tmp1 or $06);end;tmp2:=RgA+tmp1;RgF:=flags[tmp2 and $FF];
 if (((tmp2 xor RgA xor tmp1) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 if (tmp2>$FF) then begin RgF:=(RgF or f_C);end;RgA:=tmp2 and $FF;
 end;
 $29: begin RgL:=RgL + RgL;RgH:=RgH + RgH;
 if (RgL>$FF) then begin inc(RgH);RgL:=(RgL and $FF);end;
 if (RgH>$FF) then begin RgH:=(RgH and $FF);RgF:=(RgF or f_C);end else begin
 RgF:=(RgF and (not f_C));end;end;
 $2A: begin tmp1:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);RgL:=do_read(tmp1);
 RgH:=do_read(tmp1+1);end;
 $2B: begin RgL:=RgL-1;if (RgL <0) then begin RgL:=$FF;
 RgH:=RgH-1;if (RgH<0) then begin RgH:=$FF;end;end;
 end;
 $2C: begin tmp2:=((RgL+1) and $FF);RgF:=(flags[tmp2] or (RgF and f_C));
 if (((tmp2 xor RgL) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgL:=tmp2;end;
 $2D: begin tmp2:=((RgL-1) and $FF);RgF:=(flags[tmp2] or (RgF and f_C));
 if (((tmp2 xor RgL) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgL:=tmp2;end;
 $2E: begin RgL:=do_read(RpPC+1);end;
 $2F: begin RgA:=(RgA xor $FF);end;
 $31: begin RpSP:=(do_read(RpPC+2) shl 8)+do_read(RpPC+1);
 end;
 $32: begin do_write2(do_read(RpPC+1),do_read(RpPC+2),RgA);
 end;
 $33: begin if (RpSP=$FFFF) then begin RpSP:=0;end else
 begin inc(RpSP);end;end;
 $34: begin tmp1:=do_read2(RgL,RgH);tmp2:=((tmp1+1) and $FF);
 RgF:=(flags[tmp2] or (RgF and f_C));if (((tmp2 xor tmp1) and $10)<>0) then
 begin RgF:=(RgF or f_A);end;do_write2(RgL,RgH,tmp2);
 end;
 $35: begin tmp1:=do_read2(RgL,RgH);tmp2:=((tmp1-1) and $FF);RgF:=flags[tmp2] or (RgF and f_C);
 if (((tmp2 xor tmp1) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 do_write2(RgL,RgH,tmp2);end;
 $36: begin do_write2(RgL,RgH,do_read(RpPC+1));end;
 $37: begin RgF:=(RgF or f_C);end;
 $39: begin RgL:=(RgL + (RpSP and $FF));RgH:=(RgH + ((RpSP shr 8) and $FF));
 if (RgL>$FF) then begin inc(RgH);RgL:=(RgL and $FF);end;
 if (RgH>$FF) then begin RgH:=(RgH and $FF);RgF:=(RgF or f_C);
 end else begin RgF:=(RgF and (not f_C));end;end;
 $3A: begin RgA:=do_read2(do_read(RpPC+1),do_read(RpPC+2));
 end;
 $3B: begin if (RpSP<>0) then begin RpSP:=RpSP-1;end else
 begin RpSP:=$FFFF;end;end;
 $3C: begin tmp2:=((RgA+1) and $FF);RgF:=(flags[tmp2] or (RgF and f_C));
 if (((tmp2 xor RgA) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgA:=tmp2;end;
 $3D: begin tmp2:=((RgA-1) and $FF);RgF:=(flags[tmp2] or (RgF and f_C));
 if (((tmp2 xor RgA) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgA:=tmp2;end;
 $3E: begin RgA:=do_read(RpPC+1);end;
 $3F: begin RgF:=RgF xor f_C;end;
 $40: begin end;
 $49: begin end;
 $52: begin end;
 $5B: begin end;
 $64: begin end;
 $6D: begin end;
 $7F: begin end;
 $41: begin RgB:=RgC;end;
 $42: begin RgB:=RgD;end;
 $43: begin RgB:=RgE;end;
 $44: begin RgB:=RgH;end;
 $45: begin RgB:=RgL;end;
 $46: begin RgB:=do_read2(RgL,RgH);end;
 $47: begin RgB:=RgA;end;
 $48: begin RgC:=RgB;end;
 $4A: begin RgC:=RgD;end;
 $4B: begin RgC:=RgE;end;
 $4C: begin RgC:=RgH;end;
 $4D: begin RgC:=RgL;end;
 $4E: begin RgC:=do_read2(RgL,RgH);end;
 $4F: begin RgC:=RgA;end;
 $50: begin RgD:=RgB;end;
 $51: begin RgD:=RgC;end;
 $53: begin RgD:=RgE;end;
 $54: begin RgD:=RgH;end;
 $55: begin RgD:=RgL;end;
 $56: begin RgD:=do_read2(RgL,RgH);end;
 $57: begin RgD:=RgA;end;
 $58: begin RgE:=RgB;end;
 $59: begin RgE:=RgC;end;
 $5A: begin RgE:=RgD;end;
 $5C: begin RgE:=RgH;end;
 $5D: begin RgE:=RgL;end;
 $5E: begin RgE:=do_read2(RgL,RgH);end;
 $5F: begin RgE:=RgA;end;
 $60: begin RgH:=RgB;end;
 $61: begin RgH:=RgC;end;
 $62: begin RgH:=RgD;end;
 $63: begin RgH:=RgE;end;
 $65: begin RgH:=RgL;end;
 $66: begin RgH:=do_read2(RgL,RgH);end;
 $67: begin RgH:=RgA;end;
 $68: begin RgL:=RgB;end;
 $69: begin RgL:=RgC;end;
 $6A: begin RgL:=RgD;end;
 $6B: begin RgL:=RgE;end;
 $6C: begin RgL:=RgH;end;
 $6E: begin RgL:=do_read2(RgL,RgH);end;
 $6F: begin RgL:=RgA;end;
 $70: begin do_write2(RgL,RgH,RgB);end;
 $71: begin do_write2(RgL,RgH,RgC);end;
 $72: begin do_write2(RgL,RgH,RgD);end;
 $73: begin do_write2(RgL,RgH,RgE);end;
 $74: begin do_write2(RgL,RgH,RgH);end;
 $75: begin do_write2(RgL,RgH,RgL);end;
 $76: begin end;
 $77: begin do_write2(RgL,RgH,RgA);end;
 $78: begin RgA:=RgB;end;
 $79: begin RgA:=RgC;end;
 $7A: begin RgA:=RgD;end;
 $7B: begin RgA:=RgE;end;
 $7C: begin RgA:=RgH;end;
 $7D: begin RgA:=RgL;end;
 $7E: begin RgA:=do_read2(RgL,RgH);end;
 $80: begin tmp2:=RgA+RgB;RgF:=flags[tmp2 and $FF];
 if (((tmp2 xor RgA xor RgB) and $10)<>0) then begin
 RgF:=(RgF or f_A);end;if (tmp2>$FF) then
 begin RgF:=(RgF or f_C);end;RgA:=(tmp2 and $FF);
 end;
 $81: begin tmp2:=RgA+RgC;RgF:=flags[tmp2 and $FF];
 if (((tmp2 xor RgA xor RgC) and $10)<>0) then
 begin RgF:=(RgF or f_A);end;
 if (tmp2>$FF) then begin RgF:=(RgF or f_C);end;
 RgA:=tmp2 and $FF;end;
 $82: begin tmp2:=RgA+RgD;RgF:=flags[tmp2 and $FF];
 if (((tmp2 xor RgA xor RgD) and $10)<>0) then begin
 RgF:=(RgF or f_A);end;
 if (tmp2>$FF) then begin RgF:=(RgF or f_C);end;
 RgA:=tmp2 and $FF;end;
 $83: begin tmp2:=RgA+RgE;RgF:=flags[tmp2 and $FF];
 if (((tmp2 xor RgA xor RgE) and $10)<>0) then begin
 RgF:=(RgF or f_A);end;if (tmp2>$FF) then
 begin RgF:=(RgF or f_C);end;
 RgA:=tmp2 and $FF;end;
 $84: begin tmp2:=RgA+RgH;RgF:=flags[tmp2 and $FF];
 if (((tmp2 xor RgA xor RgH) and $10)<>0) then
 begin RgF:=(RgF or f_A);end;
 if (tmp2>$FF) then begin RgF:=(RgF or f_C);end;
 RgA:=tmp2 and $FF;end;
 $85: begin tmp2:=RgA+RgL;RgF:=flags[tmp2 and $FF];
 if (((tmp2 xor RgA xor RgL) and $10)<>0) then begin
 RgF:=(RgF or f_A);end;
 if (tmp2>$FF) then begin RgF:=(RgF or f_C);end;
 RgA:=tmp2 and $FF;end;
 $86: begin tmp1:=do_read2(RgL,RgH);tmp2:=RgA+tmp1;RgF:=flags[tmp2 and $FF];
 if (((tmp2 xor RgA xor tmp1) and $10)<>0) then begin
 RgF:=(RgF or f_A);end;
 if (tmp2>$FF) then begin RgF:=(RgF or f_C);end;
 RgA:=tmp2 and $FF;end;
 $87: begin tmp2:=RgA+RgA;RgF:=flags[tmp2 and $FF];
 if (((tmp2 xor RgA xor RgA) and $10)<>0) then begin
 RgF:=(RgF or f_A);end;
 if (tmp2>$FF) then begin RgF:=(RgF or f_C);end;
 RgA:=tmp2 and $FF;end;
 $88: begin tmp2:=RgA+RgB;if ((RgF and f_C)<>0) then tmp2:=tmp2+1 else tmp2:=tmp2+0;
 RgF:=flags[tmp2 and $FF];if (((tmp2 xor RgA xor RgB) and $10)<>0) then
 begin RgF:=(RgF or f_A);end;
 if (tmp2>$FF) then begin RgF:=(RgF or f_C);end;
 RgA:=tmp2 and $FF;end;
 $89: begin tmp2:=RgA+RgC;
 if ((RgF and f_C)<>0) then tmp2:=tmp2+1 else tmp2:=tmp2+0;
 RgF:=flags[tmp2 and $FF];
 if (((tmp2 xor RgA xor RgC) and $10)<>0) then
 begin RgF:=(RgF or f_A);end;
 if (tmp2>$FF) then begin RgF:=(RgF or f_C);end;
 RgA:=tmp2 and $FF;end;
 $8A: begin tmp2:=RgA+RgD;
 if ((RgF and f_C)<>0) then tmp2:=tmp2+1 else tmp2:=tmp2+0;
 RgF:=flags[tmp2 and $FF];
 if (((tmp2 xor RgA xor RgD) and $10)<>0) then
 begin RgF:=(RgF or f_A);end;
 if (tmp2>$FF) then begin RgF:=(RgF or f_C);end;
 RgA:=tmp2 and $FF;
 end;
 $8B: begin tmp2:=RgA+RgE;
 if ((RgF and f_C)<>0) then tmp2:=tmp2+1 else tmp2:=tmp2+0;
 RgF:=flags[tmp2 and $FF];
 if (((tmp2 xor RgA xor RgE) and $10)<>0) then
 begin RgF:=(RgF or f_A);end;
 if (tmp2>$FF) then begin RgF:=(RgF or f_C);end;
 RgA:=tmp2 and $FF;end;
 $8C: begin tmp2:=RgA+RgH;
 if ((RgF and f_C)<>0) then tmp2:=tmp2+1 else tmp2:=tmp2+0;
 RgF:=flags[tmp2 and $FF];if (((tmp2 xor RgA xor RgH) and $10)<>0) then
 begin RgF:=(RgF or f_A);end;
 if (tmp2>$FF) then begin RgF:=RgF or f_C;end;
 RgA:=tmp2 and $FF;end;
 $8D: begin tmp2:=RgA+RgL;
 if ((RgF and f_C)<>0) then tmp2:=tmp2+1 else tmp2:=tmp2+0;
 RgF:=flags[tmp2 and $FF];
 if (((tmp2 xor RgA xor RgL) and $10)<>0) then
 begin RgF:=(RgF or f_A);end;
 if (tmp2>$FF) then begin RgF:=(RgF or f_C);end;
 RgA:=tmp2 and $FF;end;
 $8E: begin tmp1:=do_read2(RgL,RgH);
 tmp2:=RgA+tmp1;if ((RgF and f_C)<>0) then tmp2:=tmp2+1 else tmp2:=tmp2+0;
 RgF:=flags[tmp2 and $FF];
 if (((tmp2 xor RgA xor tmp1) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 if (tmp2>$FF) then begin RgF:=(RgF or f_C);end;
 RgA:=tmp2 and $FF;end;
 $8F: begin tmp2:=RgA+RgA;
 if ((RgF and f_C)<>0) then tmp2:=tmp2+1 else tmp2:=tmp2+0;
 RgF:=flags[tmp2 and $FF];
 if (((tmp2 xor RgA xor RgA) and $10)<>0) then
 begin RgF:=(RgF or f_A);end;
 if (tmp2>$FF) then begin RgF:=(RgF or f_C);end;
 RgA:=tmp2 and $FF;end;
 $90: begin tmp2:=(RgA-RgB) and $FF;RgF:=flags[tmp2];
 if (RgA<RgB) then begin RgF:=(RgF or f_C);end;
 if (((tmp2 xor RgA xor RgB) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgA:=tmp2;end;
 $91: begin tmp2:=(RgA-RgC) and $FF;RgF:=flags[tmp2];
 if (RgA<RgC) then begin RgF:=(RgF or f_C);end;
 if (((tmp2 xor RgA xor RgC) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgA:=tmp2;end;
 $92: begin tmp2:=(RgA-RgD) and $FF;RgF:=flags[tmp2];
 if (RgA<RgD) then begin RgF:=(RgF or f_C);end;
 if (((tmp2 xor RgA xor RgD) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgA:=tmp2;end;
 $93: begin tmp2:=(RgA-RgE) and $FF;RgF:=flags[tmp2];
 if (RgA<RgE) then begin RgF:=(RgF or f_C);end;
 if (((tmp2 xor RgA xor RgE) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgA:=tmp2;end;
 $94: begin tmp2:=(RgA-RgH) and $FF;RgF:=flags[tmp2];
 if (RgA<RgH) then begin RgF:=(RgF or f_C);end;
 if (((tmp2 xor RgA xor RgH) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgA:=tmp2;end;
 $95: begin tmp2:=(RgA-RgL) and $FF;RgF:=flags[tmp2];
 if (RgA<RgL) then begin RgF:=RgF or f_C;end;
 if (((tmp2 xor RgA xor RgL) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgA:=tmp2;end;
 $96: begin tmp1:=do_read2(RgL,RgH);tmp2:=(RgA-tmp1) and $FF;RgF:=flags[tmp2];
 if (RgA<tmp1) then begin RgF:=(RgF or f_C);end;
 if (((tmp2 xor RgA xor tmp1) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgA:=tmp2;end;
 $97: begin RgF:=flags[0];RgA:=0;end;
 $98: begin if ((RgF and f_C)<>0) then tmp3:=1 else tmp3:=0;tmp2:=(RgA-RgB-tmp3) and $FF;
 RgF:=flags[tmp2];if (RgA<RgB+tmp3) then begin RgF:=(RgF or f_C);end;
 if (((tmp2 xor RgA xor RgB) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgA:=tmp2;end;
 $99: begin if ((RgF and f_C)<>0) then tmp3:=1 else tmp3:=0;tmp2:=(RgA-RgC-tmp3) and $FF;
 RgF:=flags[tmp2];if (RgA<(RgC+tmp3)) then begin RgF:=(RgF or f_C);end;
 if (((tmp2 xor RgA xor RgC) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgA:=tmp2;end;
 $9A: begin if ((RgF and f_C)<>0) then tmp3:=1 else tmp3:=0;tmp2:=(RgA-RgD-tmp3) and $FF;
 RgF:=flags[tmp2];if (RgA<RgD+tmp3) then begin RgF:=(RgF or f_C);end;
 if (((tmp2 xor RgA xor RgD) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgA:=tmp2;end;
 $9B: begin if ((RgF and f_C)<>0) then tmp3:=1 else tmp3:=0;tmp2:=(RgA-RgE-tmp3) and $FF;
 RgF:=flags[tmp2];if (RgA<RgE+tmp3) then begin RgF:=(RgF or f_C);end;
 if (((tmp2 xor RgA xor RgE) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgA:=tmp2;end;
 $9C: begin if ((RgF and f_C)<>0) then tmp3:=1 else tmp3:=0;
 tmp2:=(RgA-RgH-tmp3) and $FF;RgF:=flags[tmp2];if (RgA<RgH+tmp3) then
 begin RgF:=(RgF or f_C);end;
 if (((tmp2 xor RgA xor RgH) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 RgA:=tmp2;end;
 $9D: begin if ((RgF and f_C)<>0) then tmp3:=1 else tmp3:=0;
 tmp2:=(RgA-RgL-tmp3) and $FF;RgF:=flags[tmp2];
 if (RgA<RgL+tmp3) then begin RgF:=(RgF or f_C);end;
 if (((tmp2 xor RgA xor RgL) and $10)<>0) then begin
 RgF:=(RgF or f_A);end;
 RgA:=tmp2;end;
 $9E: begin tmp1:=do_read2(RgL,RgH);
 if ((RgF and f_C)<>0) then tmp3:=1 else tmp3:=0;
 tmp2:=(RgA-tmp1-tmp3) and $FF;RgF:=flags[tmp2];
 if (RgA<tmp1+tmp3) then begin RgF:=(RgF or f_C);end;
 if (((tmp2 xor RgA xor tmp1) and $10)<>0) then begin
 RgF:=(RgF or f_A);end;
 RgA:=tmp2;end;
 $9F: begin if ((RgF and f_C)<>0) then tmp2:=$FF else tmp2:=0;
 RgF:=flags[tmp2];if (tmp2<>0) then begin RgF:=RgF or (f_A or f_C);end;
 RgA:=tmp2;end;
 $A0: begin RgA:=RgA and RgB;RgF:=flags[RgA] or (RgF and f_A);
 end;
 $A1: begin RgA:=RgA and RgC;RgF:=flags[RgA] or (RgF and f_A);
 end;
 $A2: begin RgA:=RgA and RgD;RgF:=flags[RgA] or (RgF and f_A);
 end;
 $A3: begin RgA:=RgA and RgE;RgF:=flags[RgA] or (RgF and f_A);
 end;
 $A4: begin RgA:=RgA and RgH;RgF:=flags[RgA] or (RgF and f_A);
 end;
 $A5: begin RgA:=RgA and RgL;RgF:=flags[RgA] or (RgF and f_A);
 end;
 $A6: begin tmp1:=do_read2(RgL,RgH);
 RgA:=RgA and tmp1;RgF:=flags[RgA] or (RgF and f_A);
 end;
 $A7: begin RgA:=RgA and RgA;RgF:=flags[RgA] or (RgF and f_A);
 end;
 $A8: begin RgA:=RgA xor RgB;RgF:=flags[RgA] or (RgF and f_A);
 end;
 $A9: begin RgA:=RgA xor RgC;RgF:=flags[RgA] or (RgF and f_A);
 end;
 $AA: begin RgA:=RgA xor RgD;RgF:=flags[RgA] or (RgF and f_A);
 end;
 $AB: begin RgA:=RgA xor RgE;RgF:=flags[RgA] or (RgF and f_A);
 end;
 $AC: begin RgA:=RgA xor RgH;RgF:=flags[RgA] or (RgF and f_A);
 end;
 $AD: begin RgA:=RgA xor RgL;RgF:=flags[RgA] or (RgF and f_A);
 end;
 $AE: begin tmp1:=do_read2(RgL,RgH);RgA:=RgA xor tmp1;
 RgF:=flags[RgA] or (RgF and f_A);end;
 $AF: begin RgA:=0;RgF:=flags[RgA] or (RgF and f_A);
 end;
 $B0: begin RgA:=RgA or RgB;RgF:=flags[RgA] or (RgF and f_A);
 end;
 $B1: begin RgA:=RgA or RgC;RgF:=flags[RgA] or (RgF and f_A);
 end;
 $B2: begin RgA:=RgA or RgD;
 RgF:=flags[RgA] or (RgF and f_A);
 end;
 $B3: begin RgA:=RgA or RgE;RgF:=flags[RgA] or (RgF and f_A);
 end;
 $B4: begin RgA:=RgA or RgH;RgF:=flags[RgA] or (RgF and f_A);
 end;
 $B5: begin RgA:=RgA or RgL;RgF:=flags[RgA] or (RgF and f_A);
 end;
 $B6: begin tmp1:=do_read2(RgL,RgH);RgA:=RgA or tmp1;
 RgF:=flags[RgA] or (RgF and f_A);
 end;
 $B7: begin RgA:=RgA or RgA;RgF:=flags[RgA] or (RgF and f_A);
 end;
 $B8: begin tmp2:=(RgA-RgB) and $FF;RgF:=flags[tmp2];
 if (RgA<RgB) then begin RgF:=(RgF or f_C);end;
 if (((tmp2 xor RgA xor RgB) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 end;
 $B9: begin tmp2:=(RgA-RgC) and $FF;RgF:=flags[tmp2];if (RgA<RgC) then
 begin RgF:=(RgF or f_C);end;
 if (((tmp2 xor RgA xor RgC) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 end;
 $BA: begin tmp2:=(RgA-RgD) and $FF;RgF:=flags[tmp2];
 if (RgA<RgD) then begin RgF:=(RgF or f_C);end;
 if (((tmp2 xor RgA xor RgD) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 end;
 $BB: begin tmp2:=(RgA-RgE) and $FF;RgF:=flags[tmp2];
 if (RgA<RgE) then begin RgF:=(RgF or f_C);end;
 if (((tmp2 xor RgA xor RgE) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 end;
 $BC: begin tmp2:=(RgA-RgH) and $FF;RgF:=flags[tmp2];
 if (RgA<RgH) then begin RgF:=(RgF or f_C);end;
 if (((tmp2 xor RgA xor RgH) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 end;
 $BD: begin tmp2:=(RgA-RgL) and $FF;RgF:=flags[tmp2];
 if (RgA<RgL) then begin RgF:=(RgF or f_C);end;
 if (((tmp2 xor RgA xor RgL) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 end;
 $BE: begin tmp1:=do_read2(RgL,RgH);tmp2:=(RgA-tmp1) and $FF;RgF:=flags[tmp2];
 if (RgA<tmp1) then begin RgF:=(RgF or f_C);end;
 if (((tmp2 xor RgA xor tmp1) and $10)<>0) then begin RgF:=(RgF or f_A);end;
 end;
 $BF: begin RgF:=flags[0];end;
 $C0: begin if ((RgF and f_Z)<>0) then begin end else
 begin RpPC:=do_read(RpSP);RpPC:=RpPC+(do_read(RpSP+1) shl 8);RpSP:=(RpSP+2) and $FFFF;
 end;end;
 $C1: begin RgC:=do_read(RpSP);RgB:=do_read(RpSP+1);RpSP:=(RpSP+2) and $FFFF;
 end;
 $C2: begin if ((RgF and f_Z)<>0) then begin end else
 begin RpPC:=do_read(RpPC+1)+((do_read(RpPC+2) shl 8));end;end;
 $C3: begin RpPC:=do_read(RpPC+1)+((do_read(RpPC+2) shl 8));end;
 $C4: begin if ((RgF and f_Z)<>0) then begin 
 end else begin tmp1:=do_read(RpPC+1)+((do_read(RpPC+2) shl 8));
 RpSP:=(RpSP-2) and $FFFF;do_write(RpSP,RpPC and $FF);
 do_write(RpSP+1,(RpPC shr 8) and $FF);RpPC:=tmp1;end;end;
 $C5: begin RpSP:=(RpSP-2) and $FFFF;do_write(RpSP,RgC);do_write(RpSP+1,RgB);
 end;
 $C6: begin tmp1:=do_read(RpPC+1);tmp2:=RgA+tmp1;RgF:=flags[tmp2 and $FF];
 if (((tmp2 xor RgA xor tmp1) and $10)<>0) then begin RgF:=RgF or f_A;end;
 if (tmp2>$FF) then begin RgF:=RgF or f_C;end;
 RgA:=tmp2 and $FF;end;
 $C7: begin RpSP:=(RpSP-2) and $FFFF;do_write(RpSP,RpPC and $FF);
 do_write(RpSP+1,(RpPC shr 8) and $FF);RpPC:=0*8;end;
 $C8: begin if ((RgF and f_Z)=0) then begin 
 end else begin RpPC:=do_read(RpSP);RpPC:=RpPC+(do_read(RpSP+1) shl 8);
 RpSP:=(RpSP+2) and $FFFF;end;end;
 $C9: begin RpPC:=do_read(RpSP);RpPC:=RpPC+(do_read(RpSP+1) shl 8);RpSP:=(RpSP+2) and $FFFF;
 end;
 $CA: begin if ((RgF and f_Z)=0) then begin 
 end else begin RpPC:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);
 end;end;
 $CB: begin begin RpPC:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);
 end;end;
 $CC: begin if ((RgF and f_Z)=0) then begin end else
 begin tmp1:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);RpSP:=(RpSP-2) and $FFFF;
 do_write(RpSP,RpPC and $FF);do_write(RpSP+1,(RpPC shr 8) and $FF);
 RpPC:=tmp1;end end;
 $CD: begin tmp1:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);RpSP:=(RpSP-2) and $FFFF;
 do_write(RpSP,RpPC and $FF);do_write(RpSP+1,(RpPC shr 8) and $FF);
 RpPC:=tmp1;end;
 $CE: begin tmp1:=do_read(RpPC+1);tmp2:=RgA+tmp1;
 if ((RgF and f_C)<>0) then tmp2:=tmp2+1 else tmp2:=tmp2+0;
 RgF:=flags[tmp2 and $FF];
 if (((tmp2 xor RgA xor tmp1) and $10)<>0) then begin RgF:=RgF or f_A;end;
 if (tmp2>$FF) then begin RgF:=RgF or f_C;end;
 RgA:=tmp2 and $FF;end;
 $CF: begin RpSP:=(RpSP-2) and $FFFF;
 do_write(RpSP,RpPC and $FF);do_write(RpSP+1,(RpPC shr 8) and $FF);
 RpPC:=1*8;end;
 $D0: begin if ((RgF and f_C)<>0) then begin end else
 begin RpPC:=do_read(RpSP);RpPC:=RpPC+(do_read(RpSP+1) shl 8);
 RpSP:=(RpSP+2) and $FFFF;end end;
 $D1: begin RgE:=do_read(RpSP);RgD:=do_read(RpSP+1);RpSP:=(RpSP+2) and $FFFF;
 end;
 $D2: begin if ((RgF and f_C)<>0) then begin 
 end else begin
 RpPC:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);end;end;
 $D3: begin do_output(do_read(RpPC+1),RgA);end;
 $D4: begin if ((RgF and f_C)<>0) then begin end
 else begin tmp1:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);
 RpSP:=(RpSP-2) and $FFFF;do_write(RpSP,RpPC and $FF);
 do_write(RpSP+1,(RpPC shr 8) and $FF);RpPC:=tmp1;end;end;
 $D5: begin RpSP:=(RpSP-2) and $FFFF;do_write(RpSP,RgE);do_write(RpSP+1,RgD);
 end;
 $D6: begin tmp1:=do_read(RpPC+1);tmp2:=(RgA-tmp1) and $FF;RgF:=flags[tmp2];
 if (RgA<tmp1) then begin RgF:=RgF or f_C;end;
 if (((tmp2 xor RgA xor tmp1) and $10)<>0) then begin RgF:=RgF or f_A;end;
 RgA:=tmp2;end;
 $D7: begin RpSP:=(RpSP-2) and $FFFF;do_write(RpSP,RpPC and $FF);
 do_write(RpSP+1,(RpPC shr 8) and $FF);RpPC:=2*8;end;
 $D8: begin if ((RgF and f_C)=0) then begin end
 else begin RpPC:=do_read(RpSP);RpPC:=RpPC+do_read(RpSP+1) shl 8;
 RpSP:=(RpSP+2) and $FFFF;end;end;
 $D9: begin begin RpPC:=do_read(RpSP);RpPC:=RpPC+do_read(RpSP+1) shl 8;
 RpSP:=(RpSP+2) and $FFFF;end;end;
 $DA: begin if ((RgF and f_C)=0) then begin end
 else begin RpPC:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);end;end;
 $DB: begin RgA:=do_input(do_read(RpPC+1));end;
 $DC: begin if ((RgF and f_C)=0) then begin end
 else begin tmp1:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);RpSP:=(RpSP-2) and $FFFF;
 do_write(RpSP,RpPC and $FF);do_write(RpSP+1,(RpPC shr 8) and $FF);
 RpPC:=tmp1;end;end;
 $DD: begin begin tmp1:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);
 RpSP:=(RpSP-2) and $FFFF;do_write(RpSP,RpPC and $FF);
 do_write(RpSP+1,(RpPC shr 8) and $FF);RpPC:=tmp1;
 end;end;
 $ED: begin begin tmp1:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);
 RpSP:=(RpSP-2) and $FFFF;
 do_write(RpSP,RpPC and $FF);do_write(RpSP+1,(RpPC shr 8) and $FF);
 RpPC:=tmp1;end;end;
 $FD: begin begin tmp1:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);RpSP:=(RpSP-2) and $FFFF;
 do_write(RpSP,RpPC and $FF);do_write(RpSP+1,(RpPC shr 8) and $FF);
 RpPC:=tmp1;end;end;
 $DE: begin tmp1:=do_read(RpPC+1);if ((RgF and f_C)<>0) then tmp3:=1 else tmp3:=0;
 tmp2:=(RgA-tmp1-tmp3) and $FF;RgF:=flags[tmp2];if (RgA<tmp1+tmp3) then
 begin RgF:=RgF or f_C;end;
 if (((tmp2 xor RgA xor tmp1) and $10)<>0) then begin RgF:=RgF or f_A;end;
 RgA:=tmp2;end;
 $DF: begin RpSP:=(RpSP-2) and $FFFF; do_write(RpSP,RpPC and $FF);
 do_write(RpSP+1,(RpPC shr 8) and $FF); RpPC:=3*8;  end;
 $E0: begin if ((RgF and f_P)<>0) then begin end
 else begin RpPC:=do_read(RpSP);RpPC:=RpPC+do_read(RpSP+1) shl 8;
 RpSP:=(RpSP+2) and $FFFF;end ;end;
 $E1: begin RgL:=do_read(RpSP);RgH:=do_read(RpSP+1);RpSP:=(RpSP+2) and $FFFF;
 end;
 $E2: begin if ((RgF and f_P)<>0) then begin  end else begin
 RpPC:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8); end;end;
 $E3: begin tmp1:=do_read(RpSP);do_write(RpSP,RgL);RgL:=tmp1;
 tmp1:=do_read(RpSP+1);do_write(RpSP+1,RgH);RgH:=tmp1;
 end;
 $E4: begin if ((RgF and f_P)<>0) then
 begin end else
 begin tmp1:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);
 RpSP:=(RpSP-2) and $FFFF;do_write(RpSP,RpPC and $FF);
 do_write(RpSP+1,(RpPC shr 8) and $FF);RpPC:=tmp1;end;end;
 $E5: begin RpSP:=(RpSP-2) and $FFFF;do_write(RpSP,RgL);
 do_write(RpSP+1,RgH);end;
 $E6: begin RgA:=RgA and do_read(RpPC+1);RgF:=flags[RgA] or (RgF and f_A);
 end;
 $E7: begin RpSP:=(RpSP-2) and $FFFF;
 do_write(RpSP,RpPC and $FF);do_write(RpSP+1,(RpPC shr 8) and $FF);
 RpPC:=4*8;end;
 $E8: begin if ((RgF and f_P)=0) then begin
 end else begin
 RpPC:=do_read(RpSP);RpPC:=RpPC+do_read(RpSP+1) shl 8;
 RpSP:=(RpSP+2) and $FFFF;end;end;
 $E9: begin RpPC:=(RgH shl 8)+RgL;end;
 $EA: begin if ((RgF and f_P)=0) then begin 
 end else begin
 RpPC:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);
 end;end;
 $EB: begin tmp1:=RgD;RgD:=RgH;RgH:=tmp1;
 tmp1:=RgE;RgE:=RgL;RgL:=tmp1;
 end;
 $EC: begin if ((RgF and f_P)=0) then begin 
 end else begin
 tmp1:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);
 RpSP:=(RpSP-2) and $FFFF;
 do_write(RpSP,RpPC and $FF);do_write(RpSP+1,(RpPC shr 8) and $FF);
 RpPC:=tmp1;end;end;
 $EE: begin RgA:= RgA xor do_read(RpPC+1);RgF:=flags[RgA] or (RgF and f_A);
 end;
 $EF: begin RpSP:=(RpSP-2) and $FFFF;
 do_write(RpSP,RpPC and $FF);do_write(RpSP+1,(RpPC shr 8) and $FF);
 RpPC:=5*8;end;
 $F0: begin if ((RgF and f_S)<>0) then begin
 end
 else begin RpPC:=do_read(RpSP);RpPC:=RpPC+(do_read(RpSP+1) shl 8);
 RpSP:=(RpSP+2) and $FFFF;end;end;
 $F1: begin RgF:=do_read(RpSP);RgA:=do_read(RpSP+1);
 RpSP:=(RpSP+2) and $FFFF;end;
 $F2: begin if ((RgF and f_S)<>0) then begin
 end else
 begin RpPC:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);end;end;
 $F4: begin if ((RgF and f_S)<>0) then begin 
 end else begin
 tmp1:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);
 RpSP:=(RpSP-2) and $FFFF;
 do_write(RpSP,RpPC and $FF);do_write(RpSP+1,(RpPC shr 8) and $FF);
 RpPC:=tmp1;end;end;
 $F5: begin RpSP:=(RpSP-2) and $FFFF;do_write(RpSP,RgF);
 do_write(RpSP+1,RgA);end;
 $F6: begin RgA:=RgA or do_read(RpPC+1);RgF:=flags[RgA] or (RgF and f_A);
 end;
 $F7: begin RpSP:=(RpSP-2) and $FFFF;
 do_write(RpSP,RpPC and $FF);do_write(RpSP+1,(RpPC shr 8) and $FF);
 RpPC:=6*8;end;
 $F8: begin if ((RgF and f_S)=0) then begin 
 end else begin
 RpPC:=do_read(RpSP);RpPC:=RpPC+(do_read(RpSP+1) shl 8);
 RpSP:=(RpSP+2) and $FFFF;end;end;
 $F9: begin RpSP:=(RgH shl 8)+RgL;end;
 $FA: begin if ((RgF and f_S)=0) then begin 
 end else begin RpPC:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);
 end;end;
 $FC: begin if ((RgF and f_S)=0) then begin 
 end else begin tmp1:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);
 RpSP:=(RpSP-2) and $FFFF;do_write(RpSP,RpPC and $FF);
 do_write(RpSP+1,(RpPC shr 8) and $FF);RpPC:=tmp1;
 end;end;
 $FE: begin tmp1:=do_read(RpPC+1);tmp2:=(RgA-tmp1) and $FF;
 RgF:=flags[tmp2];if (RgA<tmp1) then begin
 RgF:=RgF or f_C;end;
 if (((tmp2 xor RgA xor tmp1) and $10)<>0) then begin
 RgF:=RgF or f_A;end;end;
 $FF: begin RpSP:=(RpSP-2) and $FFFF;
 do_write(RpSP,RpPC and $FF);do_write(RpSP+1,(RpPC shr 8) and $FF);
 RpPC:=7*8;end
end;{<=case opcode of}
cz1:=cz1+cz; CT:=CT+cz;
end;{<=while (cz1 < nb_cycles) do}
end;


5

Видалено все окрім case opcode of а також
inc(RpPC); inc(RpPC,2);  inc(RpPC,3);
cz:=4;cz:=10;cz:=7;cz:=5;cz:=16;cz:=17;cz:=18;

сортування по камандах
'do_read2(RgL,RgH);' замінено на 'RgM;'
'do_write2(RgL,RgH,' замінено на 'RgM:=('

const f_S=128;f_Z=64;f_5=32;f_A=16;f_3=8;f_P=4;f_1=2;f_C=1;
const flags: array [0..256]of Byte=(
70,2,2,6,2,6,6,2,2,6,6,2,6,2,2,6,2,6,6,2,6,2,2,6,6,2,2,6,2,6,6,2,2,6,6,2,6,2,2,
6,6,2,2,6,2,6,6,2,6,2,2,6,2,6,6,2,2,6,6,2,6,2,2,6,2,6,6,2,6,2,2,6,6,2,2,6,2,6,6,
2,6,2,2,6,2,6,6,2,2,6,6,2,6,2,2,6,6,2,2,6,2,6,6,2,2,6,6,2,6,2,2,6,2,6,6,2,6,2,2,
6,6,2,2,6,2,6,6,2,130,134,134,130,134,130,130,134,134,130,130,134,130,134,134,130,
134,130,130,134,130,134,134,130,130,134,134,130,134,130,130,134,134,130,130,134,130,
134,134,130,130,134,134,130,134,130,130,134,130,134,134,130,134,130,130,134,134,130,
130,134,130,134,134,130,134,130,130,134,130,134,134,130,130,134,134,130,134,130,130,
134,130,134,134,130,134,130,130,134,134,130,130,134,130,134,134,130,130,134,134,130,
134,130,130,134,134,130,130,134,130,134,134,130,134,130,130,134,130,134,134,130,130,
134,134,130,134,130,130,134,0);

заміна  'RgF:=(RgF or f_A);' на '{уст fА}' - установка флагу A,
A - also called AC,Auxiliary Carry flag = додатковий перенос, 4 біт

заміна  'RgF:=(RgF or f_C);' на '{уст fC}' - установка флагу C,
C - Carry flag = призник переносу/займу, 0 біт

{NOP} $00, $08,  $10,  $18,  $20,  $28,  $30,  $38

{MOV}
$40, $49, $52, $5B, $64, $6D, $7F- пусто

$41:RgB:=RgC;  $42:RgB:=RgD;  $43:RgB:=RgE; $44:RgB:=RgH;  $45:RgB:=RgL;
$46:RgB:=RgM;  $47:RgB:=RgA;

$48:RgC:=RgB;  $4A:RgC:=RgD;  $4B:RgC:=RgE; $4C:RgC:=RgH;  $4D:RgC:=RgL;
$4E:RgC:=RgM;  $4F:RgC:=RgA;

$50:RgD:=RgB;  $51:RgD:=RgC;  $53:RgD:=RgE; $54:RgD:=RgH;  $55:RgD:=RgL;
$56:RgD:=RgM;  $57:RgD:=RgA;

$58:RgE:=RgB;  $59:RgE:=RgC;  $5A:RgE:=RgD; $5C:RgE:=RgH;  $5D:RgE:=RgL;
$5E:RgE:=RgM;  $5F:RgE:=RgA;

$60:RgH:=RgB;  $61:RgH:=RgC;  $62:RgH:=RgD; $63:RgH:=RgE;  $65:RgH:=RgL;
$66:RgH:=RgM;  $67:RgH:=RgA;

$68:RgL:=RgB;  $69:RgL:=RgC;  $6A:RgL:=RgD; $6B:RgL:=RgE;  $6C:RgL:=RgH;
$6E:RgL:=RgM;  $6F:RgL:=RgA;

$70:RgM:=RgB;  $71:RgM:=RgC;  $72:RgM:=RgD; $73:RgM:=RgE;  $74:RgM:=RgH;
$75:RgM:=RgL; $76:{Стоп процесор}  $77:RgM:=RgA;

$78:RgA:=RgB;  $79:RgA:=RgC; $7A:RgA:=RgD;  $7B:RgA:=RgE;  $7C:RgA:=RgH;
$7D:RgA:=RgL;  $7E:RgA:=RgM;

{MVI}

$06: RgB:=do_read(RpPC+1);
$0E: RgC:=do_read(RpPC+1);
$16: RgD:=do_read(RpPC+1);
$1E: RgE:=do_read(RpPC+1);
$26: RgH:=do_read(RpPC+1);
$2E: RgL:=do_read(RpPC+1);
$36: RgM:=(do_read(RpPC+1));
$3E: RgA:=do_read(RpPC+1);

{STA}$32: begin do_write2(do_read(RpPC+1),do_read(RpPC+2),RgA); end;
{LDA}$3A: begin RgA:=do_read2(do_read(RpPC+1),do_read(RpPC+2)); end;


{STAX B}$02: begin do_write2(RgC,RgB,RgA);end;
{STAX D}$12: begin do_write2(RgE,RgD,RgA);end;

{LDAX B} $0A: begin RgA:=do_read2(RgC,RgB);end;
{LDAX D}$1A: begin RgA:=do_read2(RgE,RgD);end;

6

{INR}

$04:tmp2:=((RgB+1) and $FF);RgF:=(flags[tmp2] or (RgF and f_C));
if (((tmp2 xor RgB) and $10)<>0) then {уст fА}  RgB:=tmp2;

$0C:tmp2:=((RgC+1) and $FF);RgF:=(flags[tmp2] or (RgF and f_C));
if (((tmp2 xor RgC) and $10)<>0) then {уст fА}   RgC:=tmp2;

$14:tmp2:=((RgD+1)and $FF);RgF:=(flags[tmp2] or (RgF and f_C));
if (((tmp2 xor RgD) and $10)<>0) then  {уст fА}   RgD:=tmp2;

$1C:tmp2:=((RgE+1)and $FF);RgF:=(flags[tmp2] or (RgF and f_C));
if (((tmp2 xor RgE) and $10)<>0) then {уст fА}    RgE:=tmp2;

$24:tmp2:=((RgH+1) and $FF);RgF:=(flags[tmp2] or (RgF and f_C));
if (((tmp2 xor RgH) and $10)<>0) then {уст fА}    RgH:=tmp2;

$2C:tmp2:=((RgL+1) and $FF);RgF:=(flags[tmp2] or (RgF and f_C));
if (((tmp2 xor RgL) and $10)<>0) then begin {уст fА} RgL:=tmp2;

$34:tmp1:=RgM;
     tmp2:=((tmp1+1) and $FF); RgF:=(flags[tmp2] or (RgF and f_C));
if (((tmp2 xor tmp1) and $10)<>0) then {уст fА}   RgM:=tmp2;

$3C: tmp2:=((RgA+1) and $FF);RgF:=(flags[tmp2] or (RgF and f_C));
if (((tmp2 xor RgA) and $10)<>0) then {уст fА}    RgA:=tmp2;



{ADD}
$80:tmp2:=RgA+RgB;RgF:=flags[tmp2 and $FF];
if (((tmp2 xor RgA xor RgB) and $10)<>0) then {уст fА}
if (tmp2>$FF) then {уст fC}
RgA:=(tmp2 and $FF);

$81:tmp2:=RgA+RgC;RgF:=flags[tmp2 and $FF];
if (((tmp2 xor RgA xor RgC) and $10)<>0) then {уст fА}
if (tmp2>$FF) then {уст fC}
RgA:=tmp2 and $FF;

$82:tmp2:=RgA+RgD;RgF:=flags[tmp2 and $FF];
if (((tmp2 xor RgA xor RgD) and $10)<>0) then {уст fА}
if (tmp2>$FF) then {уст fC}
RgA:=tmp2 and $FF;

$83:tmp2:=RgA+RgE;RgF:=flags[tmp2 and $FF];
if (((tmp2 xor RgA xor RgE) and $10)<>0) then  {уст fА}
if (tmp2>$FF) then {уст fC}
RgA:=tmp2 and $FF;

$84:tmp2:=RgA+RgH;RgF:=flags[tmp2 and $FF];
if (((tmp2 xor RgA xor RgH) and $10)<>0) then {уст fА}
if (tmp2>$FF) then {уст fC}
RgA:=tmp2 and $FF;

$85:tmp2:=RgA+RgL;RgF:=flags[tmp2 and $FF];
if (((tmp2 xor RgA xor RgL) and $10)<>0) then {уст fА}
if (tmp2>$FF) then {уст fC}
RgA:=tmp2 and $FF;

$86:tmp2:=RgA+RgM;RgF:=flags[tmp2 and $FF];
if (((tmp2 xor RgA xor RgM) and $10)<>0) then {уст fА}
if (tmp2>$FF) then {уст fC}
RgA:=tmp2 and $FF;

$87:tmp2:=RgA+RgA;RgF:=flags[tmp2 and $FF];
if (((tmp2 xor RgA xor RgA) and $10)<>0) then {уст fА}
if (tmp2>$FF) then {уст fC}
RgA:=tmp2 and $FF;

{ADI} $C6: begin tmp1:=do_read(RpPC+1);tmp2:=RgA+tmp1;RgF:=flags[tmp2 and $FF];
if (((tmp2 xor RgA xor tmp1) and $10)<>0) then begin RgF:=RgF or f_A;end;
if (tmp2>$FF) then begin RgF:=RgF or f_C;end;
RgA:=tmp2 and $FF;end;

7

{ADC}

$88: tmp2:=RgA+RgB;
if ((RgF and f_C)<>0) then tmp2:=tmp2+1
RgF:=flags[tmp2 and $FF];
if (((tmp2 xor RgA xor RgB) and $10)<>0) then {уст fА}
if (tmp2>$FF) then {уст fC}
RgA:=tmp2 and $FF;

$89: tmp2:=RgA+RgC;
if ((RgF and f_C)<>0) then tmp2:=tmp2+1
RgF:=flags[tmp2 and $FF];
if (((tmp2 xor RgA xor RgC) and $10)<>0) then {уст fА}
if (tmp2>$FF) then {уст fC}
RgA:=tmp2 and $FF;

$8A: tmp2:=RgA+RgD;
if ((RgF and f_C)<>0) then tmp2:=tmp2+1
RgF:=flags[tmp2 and $FF];
if (((tmp2 xor RgA xor RgD) and $10)<>0) then {уст fА}
if (tmp2>$FF) then {уст fC}
RgA:=tmp2 and $FF;

$8B: tmp2:=RgA+RgE;
if ((RgF and f_C)<>0) then tmp2:=tmp2+1
RgF:=flags[tmp2 and $FF];
if (((tmp2 xor RgA xor RgE) and $10)<>0) then {уст fА}
if (tmp2>$FF) then {уст fC}
RgA:=tmp2 and $FF;

$8C: tmp2:=RgA+RgH;
if ((RgF and f_C)<>0) then tmp2:=tmp2+1
RgF:=flags[tmp2 and $FF];
if (((tmp2 xor RgA xor RgH) and $10)<>0) then {уст fА}
if (tmp2>$FF) then {уст fC}
RgA:=tmp2 and $FF;

$8D: begin tmp2:=RgA+RgL;
if ((RgF and f_C)<>0) then tmp2:=tmp2+1
RgF:=flags[tmp2 and $FF];
if (((tmp2 xor RgA xor RgL) and $10)<>0) then {уст fА}
if (tmp2>$FF) then {уст fC}
RgA:=tmp2 and $FF;

$8E:
tmp2:=RgA+RgM;if ((RgF and f_C)<>0) then tmp2:=tmp2+1
RgF:=flags[tmp2 and $FF];
if (((tmp2 xor RgA xor RgM) and $10)<>0) then {уст fА}
if (tmp2>$FF) then {уст fC}
RgA:=tmp2 and $FF;

$8F: begin tmp2:=RgA+RgA;
if ((RgF and f_C)<>0) then tmp2:=tmp2+1
RgF:=flags[tmp2 and $FF];
if (((tmp2 xor RgA xor RgA) and $10)<>0) then {уст fА}
if (tmp2>$FF) then {уст fC}
RgA:=tmp2 and $FF;

{ACI} $CE: begin tmp1:=do_read(RpPC+1);tmp2:=RgA+tmp1;
if ((RgF and f_C)<>0) then tmp2:=tmp2+1 else tmp2:=tmp2+0;
RgF:=flags[tmp2 and $FF];
if (((tmp2 xor RgA xor tmp1) and $10)<>0) then begin RgF:=RgF or f_A;end;
if (tmp2>$FF) then begin RgF:=RgF or f_C;end;
RgA:=tmp2 and $FF;end;

8

{SUB}

$90:
tmp2:=(RgA-RgB) and $FF;RgF:=flags[tmp2];
if (RgA<RgB) then {уст fC}
if (((tmp2 xor RgA xor RgB) and $10)<>0) then {уст fА}
RgA:=tmp2;

$91:
tmp2:=(RgA-RgC) and $FF;RgF:=flags[tmp2];
if (RgA<RgC) then {уст fC}
if (((tmp2 xor RgA xor RgC) and $10)<>0) then {уст fА}
RgA:=tmp2;

$92:
tmp2:=(RgA-RgD) and $FF;RgF:=flags[tmp2];
if (RgA<RgD) then {уст fC}
if (((tmp2 xor RgA xor RgD) and $10)<>0) then {уст fА}
RgA:=tmp2;

$93:
tmp2:=(RgA-RgE) and $FF;RgF:=flags[tmp2];
if (RgA<RgE) then {уст fC}
if (((tmp2 xor RgA xor RgE) and $10)<>0) then {уст fА}
RgA:=tmp2;

$94:
tmp2:=(RgA-RgH) and $FF;RgF:=flags[tmp2];
if (RgA<RgH) then {уст fC}
if (((tmp2 xor RgA xor RgH) and $10)<>0) then {уст fА}
RgA:=tmp2;

$95:
tmp2:=(RgA-RgL) and $FF;RgF:=flags[tmp2];
if (RgA<RgL) then {уст fC}
if (((tmp2 xor RgA xor RgL) and $10)<>0) then {уст fА}
RgA:=tmp2;

$96:
tmp1:=RgM;tmp2:=(RgA-tmp1) and $FF;RgF:=flags[tmp2];
if (RgA<tmp1) then {уст fC}
if (((tmp2 xor RgA xor tmp1) and $10)<>0) then {уст fА}
RgA:=tmp2;

$97:
RgF:=flags[0];RgA:=0;

{SUI}$D6: begin tmp1:=do_read(RpPC+1);tmp2:=(RgA-tmp1) and $FF;RgF:=flags[tmp2];
if (RgA<tmp1) then begin RgF:=RgF or f_C;end;
if (((tmp2 xor RgA xor tmp1) and $10)<>0) then begin RgF:=RgF or f_A;end;
RgA:=tmp2;end;

9

{SBB}

$98:
if ((RgF and f_C)<>0) then tmp3:=1 else tmp3:=0;
tmp2:=(RgA-RgB-tmp3) and $FF;
RgF:=flags[tmp2];
if (RgA<RgB+tmp3) then {уст fC}
if (((tmp2 xor RgA xor RgB) and $10)<>0) then {уст fА}
RgA:=tmp2;

$99:
if ((RgF and f_C)<>0) then tmp3:=1 else tmp3:=0;
tmp2:=(RgA-RgC-tmp3) and $FF;
RgF:=flags[tmp2];
if (RgA<(RgC+tmp3)) then {уст fC}
if (((tmp2 xor RgA xor RgC) and $10)<>0) then {уст fА}
RgA:=tmp2;

$9A:
if ((RgF and f_C)<>0) then tmp3:=1 else tmp3:=0;
tmp2:=(RgA-RgD-tmp3) and $FF;
RgF:=flags[tmp2];
if (RgA<RgD+tmp3) then {уст fC}
if (((tmp2 xor RgA xor RgD) and $10)<>0) then {уст fА}
RgA:=tmp2;

$9B:
if ((RgF and f_C)<>0) then tmp3:=1 else tmp3:=0;
tmp2:=(RgA-RgE-tmp3) and $FF;
RgF:=flags[tmp2];
if (RgA<RgE+tmp3) then {уст fC}
if (((tmp2 xor RgA xor RgE) and $10)<>0) then {уст fА}
RgA:=tmp2;

$9C:
if ((RgF and f_C)<>0) then tmp3:=1 else tmp3:=0;
tmp2:=(RgA-RgH-tmp3) and $FF;
RgF:=flags[tmp2];
if (RgA<RgH+tmp3) then {уст fC}
if (((tmp2 xor RgA xor RgH) and $10)<>0) then {уст fА}
RgA:=tmp2;

$9D:
if ((RgF and f_C)<>0) then tmp3:=1 else tmp3:=0;
tmp2:=(RgA-RgL-tmp3) and $FF;
RgF:=flags[tmp2];
if (RgA<RgL+tmp3) then {уст fC}
if (((tmp2 xor RgA xor RgL) and $10)<>0) then {уст fА}
RgA:=tmp2;

$9E:
if ((RgF and f_C)<>0) then tmp3:=1 else tmp3:=0;
tmp2:=(RgA-RgM-tmp3) and $FF;RgF:=flags[tmp2];
if (RgA<RgM+tmp3) then {уст fC}
if (((tmp2 xor RgA xor RgM) and $10)<>0) then  {уст fА}
RgA:=tmp2;

$9F:
if ((RgF and f_C)<>0) then tmp2:=$FF else tmp2:=0;
RgF:=flags[tmp2];
if (tmp2<>0) then begin RgF:=RgF or (f_A or f_C);
RgA:=tmp2;

{SBI}$DE: begin tmp1:=do_read(RpPC+1);if ((RgF and f_C)<>0) then tmp3:=1 else tmp3:=0;
tmp2:=(RgA-tmp1-tmp3) and $FF;RgF:=flags[tmp2];if (RgA<tmp1+tmp3) then
begin RgF:=RgF or f_C;end;
if (((tmp2 xor RgA xor tmp1) and $10)<>0) then begin RgF:=RgF or f_A;end;
RgA:=tmp2;end;

10

{ANA}
$A0: RgA:=RgA and RgB;RgF:=flags[RgA] or (RgF and f_A);
$A1: RgA:=RgA and RgC;RgF:=flags[RgA] or (RgF and f_A);
$A2: RgA:=RgA and RgD;RgF:=flags[RgA] or (RgF and f_A);
$A3: RgA:=RgA and RgE;RgF:=flags[RgA] or (RgF and f_A);
$A4: RgA:=RgA and RgH;RgF:=flags[RgA] or (RgF and f_A);
$A5: RgA:=RgA and RgL;RgF:=flags[RgA] or (RgF and f_A);
$A6: RgA:=RgA and RgM;RgF:=flags[RgA] or (RgF and f_A);
$A7: RgA:=RgA and RgA;RgF:=flags[RgA] or (RgF and f_A);

{ANI}$E6: begin RgA:=RgA and do_read(RpPC+1);RgF:=flags[RgA] or (RgF and f_A); end;

11

{XRA}
$A8:RgA:=RgA xor RgB;RgF:=flags[RgA] or (RgF and f_A);
$A9:RgA:=RgA xor RgC;RgF:=flags[RgA] or (RgF and f_A);
$AA:RgA:=RgA xor RgD;RgF:=flags[RgA] or (RgF and f_A);
$AB:RgA:=RgA xor RgE;RgF:=flags[RgA] or (RgF and f_A);
$AC:RgA:=RgA xor RgH;RgF:=flags[RgA] or (RgF and f_A);
$AD:RgA:=RgA xor RgL;RgF:=flags[RgA] or (RgF and f_A);
$AE:RgA:=RgA xor RgM;RgF:=flags[RgA] or (RgF and f_A);
$AF:RgA:=0;RgF:=flags[RgA] or (RgF and f_A);

{XRI}$EE: begin RgA:= RgA xor do_read(RpPC+1);RgF:=flags[RgA] or (RgF and f_A); end;

12

{ORA}
$B0:RgA:=RgA or RgB;RgF:=flags[RgA] or (RgF and f_A);
$B1:RgA:=RgA or RgC;RgF:=flags[RgA] or (RgF and f_A);
$B2:RgA:=RgA or RgD;RgF:=flags[RgA] or (RgF and f_A);
$B3:RgA:=RgA or RgE;RgF:=flags[RgA] or (RgF and f_A);
$B4:RgA:=RgA or RgH;RgF:=flags[RgA] or (RgF and f_A);
$B5:RgA:=RgA or RgL;RgF:=flags[RgA] or (RgF and f_A);
$B6:RgA:=RgA or RgM;RgF:=flags[RgA] or (RgF and f_A);
$B7:RgA:=RgA or RgA;RgF:=flags[RgA] or (RgF and f_A);

{ORI} $F6: begin RgA:=RgA or do_read(RpPC+1);RgF:=flags[RgA] or (RgF and f_A); end;

13

{CMP}
$B8:
tmp2:=(RgA-RgB) and $FF;
RgF:=flags[tmp2];
if (RgA<RgB) then {уст fC}
if (((tmp2 xor RgA xor RgB) and $10)<>0) then {уст fА}

$B9:
tmp2:=(RgA-RgC) and $FF;
RgF:=flags[tmp2];
if (RgA<RgC) then {уст fC}
if (((tmp2 xor RgA xor RgC) and $10)<>0) then {уст fА}

$BA:
tmp2:=(RgA-RgD) and $FF;
RgF:=flags[tmp2];
if (RgA<RgD) then {уст fC}
if (((tmp2 xor RgA xor RgD) and $10)<>0) then {уст fА}

$BB:
tmp2:=(RgA-RgE) and $FF;
RgF:=flags[tmp2];
if (RgA<RgE) then {уст fC}
if (((tmp2 xor RgA xor RgE) and $10)<>0) then {уст fА}

$BC:
tmp2:=(RgA-RgH) and $FF;
RgF:=flags[tmp2];
if (RgA<RgH) then  {уст fC}
if (((tmp2 xor RgA xor RgH) and $10)<>0) then {уст fА}

$BD:
tmp2:=(RgA-RgL) and $FF;
RgF:=flags[tmp2];
if (RgA<RgL) then {уст fC}
if (((tmp2 xor RgA xor RgL) and $10)<>0) then {уст fА}

$BE:
tmp1:=RgM;tmp2:=(RgA-tmp1) and $FF;
RgF:=flags[tmp2];
if (RgA<tmp1) then {уст fC}
if (((tmp2 xor RgA xor tmp1) and $10)<>0) then {уст fА}

$BF: RgF:=flags[0];


{CPI} $FE: begin tmp1:=do_read(RpPC+1);tmp2:=(RgA-tmp1) and $FF;
RgF:=flags[tmp2];if (RgA<tmp1) then begin
RgF:=RgF or f_C;end;
if (((tmp2 xor RgA xor tmp1) and $10)<>0) then begin
RgF:=RgF or f_A;end;end;



{RLC}$07: begin RgA:=RgA SHL 1;if (RgA>$FF) then begin RgA:=RgA or 1;
RgF:=RgF or f_C;RgA:= RgA and $FF;end else
begin RgF:=(RgF and (not f_C));end;end;

{RRC}$0F: begin tmp1:=(RgA and 1);RgA:=(RgA shr 1);if (tmp1<>0) then
begin RgA:=(RgA or $80);{уст fC}end else
begin RgF:=(RgF and ( not f_C));end;end;

{RLC}$17: begin RgA:=(RgA shl 1);if ((RgF and f_C)<>0) then begin RgA:=(RgA or 1);end;
if (RgA>$FF) then begin {уст fC}RgA:=(RgA and $FF);end else begin
RgF:=(RgF and (not f_C));end;end;

{RAR}$1F: begin tmp1:=(RgA and 1);RgA:=(RgA SHR 1);if ((RgF and f_C)<>0) then
begin RgA:=(RgA or $80);end;
if (tmp1<>0) then begin {уст fC}end else
begin RgF:=(RgF and not(f_C));end;end;

{DAA}$27: begin tmp1:=0;if (((RgF and f_C)<>0) or (RgA>$99)) then begin
tmp1:=(tmp1 or $60);end;
if (((RgF and f_A)<>0) or ((RgA and $0F)>$09)) then begin
tmp1:=(tmp1 or $06);end;tmp2:=RgA+tmp1;RgF:=flags[tmp2 and $FF];
if (((tmp2 xor RgA xor tmp1) and $10)<>0) then begin {уст fА}end;
if (tmp2>$FF) then begin {уст fC}end;RgA:=tmp2 and $FF; end;

{CMA}$2F: begin RgA:=(RgA xor $FF);end;

{STC}$37: begin {уст fC}end;

{CMC}$3F: begin RgF:=RgF xor f_C;end;

14

{LXI}
$01: RgB:=do_read(RpPC+2);RgC:=do_read(RpPC+1);
$11: RgD:=do_read(RpPC+2);RgE:=do_read(RpPC+1);
$21: RgH:=do_read(RpPC+2);RgL:=do_read(RpPC+1);
$31: RpSP:=(do_read(RpPC+2) shl 8)+do_read(RpPC+1);

{SHLD}$22: begin tmp1:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);do_write(tmp1,RgL);
do_write(tmp1+1,RgH);end;

{LHLD}$2A: begin tmp1:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);RgL:=do_read(tmp1);
RgH:=do_read(tmp1+1);end;

15

{INX}
$03: RgC:=RgC+1;if (RgC>$FF) then begin RgC:=0;RgB:=RgB+1;if (RgB>$FF) then RgB:=0;end;
$13: RgE:=RgE+1;if (RgE>$FF) then begin RgE:=0;RgD:=RgD+1;if (RgD>$FF) then RgD:=0;end;
$23: RgL:=RgL+1;if (RgL>$FF) then begin RgL:=0;RgH:=RgH+1;if (RgH>$FF) then RgH:=0;end;
$33: if (RpSP=$FFFF) then RpSP:=0 else inc(RpSP);

16

{}

17

{DCX}

$05: tmp2:=((RgB-1) and $FF);RgF:=(flags[tmp2] or (RgF and f_C));
if (((tmp2 xor RgB) and $10)<>0) then {уст fА}    RgB:=tmp2;

$0D: tmp2:=((RgC-1) and $FF);RgF:=flags[tmp2] or (RgF and f_C);
if (((tmp2 xor RgC) and $10)<>0) then {уст fА}    RgC:=tmp2;

$15: tmp2:=((RgD-1)and $FF);RgF:=(flags[tmp2] or (RgF and f_C));
if (((tmp2 xor RgD) and $10)<>0) then {уст fА}    RgD:=tmp2;

$1D: tmp2:=((RgE-1) and $FF);RgF:=(flags[tmp2] or (RgF and f_C));
if (((tmp2 xor RgE) and $10)<>0) then {уст fА}    RgE:=tmp2;

$25: tmp2:=((RgH-1) and $FF);RgF:=(flags[tmp2] or (RgF and f_C));
if (((tmp2 xor RgH) and $10)<>0) then {уст fА}    RgH:=tmp2;

$2D: tmp2:=((RgL-1) and $FF);RgF:=(flags[tmp2] or (RgF and f_C));
if (((tmp2 xor RgL) and $10)<>0) then {уст fА}    RgL:=tmp2;

$35: tmp1:=RgM;tmp2:=((tmp1-1) and $FF);RgF:=flags[tmp2] or (RgF and f_C);
if (((tmp2 xor tmp1) and $10)<>0) then {уст fА}    RgM:=(tmp2);

$3D: tmp2:=((RgA-1) and $FF);RgF:=(flags[tmp2] or (RgF and f_C));
if (((tmp2 xor RgA) and $10)<>0) then {уст fА}    RgA:=tmp2;

18

{}

19

{DAD}

$09:RgL:=RgL+RgC;RgH:=RgH+RgB;if (RgL>$FF) then begin inc(RgH);RgL:=(RgL and $FF);end;
if (RgH>$FF) then begin RgH:=(RgH and $FF);{уст fC}end else RgF:=(RgF and (not f_C));

$19:RgL:=RgL+RgE;RgH:=RgH+RgD;if (RgL>$FF) then begin inc(RgH);RgL:=(RgL and $FF);end;
if (RgH>$FF) then begin RgH:=(RgH and $FF);{уст fC}end else RgF:=(RgF and not (f_C));

$29:RgL:=RgL+RgL;RgH:=RgH+RgH;if (RgL>$FF) then begin inc(RgH);RgL:=(RgL and $FF);end;
if (RgH>$FF) then begin RgH:=(RgH and $FF);{уст fC}end else RgF:=(RgF and (not f_C));

$39:RgL:=(RgL+(RpSP and $FF));RgH:=(RgH +((RpSP shr 8) and $FF)); if (RgL>$FF) then begin inc(RgH);RgL:=(RgL and $FF);end;
if (RgH>$FF) then begin RgH:=(RgH and $FF);{уст fC} end else RgF:=(RgF and (not f_C));

20

{DCX}

$0B: RgC:=RgC-1;if (RgC<0) then begin RgC:=$FF;RgB:=RgB-1; if (RgB<0) then RgB:=$FF;end;

$1B: RgE:=RgE-1;if (RgE<0) then begin RgE:=$FF;RgD:=RgD-1; if (RgD<0) then RgD:=$FF;end;

$2B: RgL:=RgL-1;if (RgL <0) then begin RgL:=$FF; RgH:=RgH-1;if (RgH<0) then RgH:=$FF;end;

$3B: if (RpSP<>0) then begin RpSP:=RpSP-1;end else  RpSP:=$FFFF;

21

{XTHL}$E3: begin tmp1:=do_read(RpSP);do_write(RpSP,RgL);RgL:=tmp1;
tmp1:=do_read(RpSP+1);do_write(RpSP+1,RgH);RgH:=tmp1; end;

{PCHL}$E9: begin RpPC:=(RgH shl 8)+RgL;end;

{XCHG} $EB: begin tmp1:=RgD;RgD:=RgH;RgH:=tmp1; tmp1:=RgE;RgE:=RgL;RgL:=tmp1; end;

{SPHL} $F9: begin RpSP:=(RgH shl 8)+RgL;end;

22

{PUSH}

$C5: RpSP:=(RpSP-2) and $FFFF;do_write(RpSP,RgC);do_write(RpSP+1,RgB);

$D5: RpSP:=(RpSP-2) and $FFFF;do_write(RpSP,RgE);do_write(RpSP+1,RgD);

$E5: RpSP:=(RpSP-2) and $FFFF;do_write(RpSP,RgL);do_write(RpSP+1,RgH);

$F5: RpSP:=(RpSP-2) and $FFFF;do_write(RpSP,RgF);do_write(RpSP+1,RgA);

{POP}

$C1:RgC:=do_read(RpSP);RgB:=do_read(RpSP+1);RpSP:=(RpSP+2) and $FFFF;

$D1:RgE:=do_read(RpSP);RgD:=do_read(RpSP+1);RpSP:=(RpSP+2) and $FFFF;

$E1:RgL:=do_read(RpSP);RgH:=do_read(RpSP+1);RpSP:=(RpSP+2) and $FFFF;

$F1:RgF:=do_read(RpSP);RgA:=do_read(RpSP+1);RpSP:=(RpSP+2) and $FFFF;

23

{JMP} $C3,$CB: begin RpPC:=do_read(RpPC+1)+((do_read(RpPC+2) shl 8));end;

{JNZ,GotoUnNot0}$C2: begin if ((RgF and f_Z)<>0) then else {JMP}

{JZ,GotoUn0}$CA:if ((RgF and f_Z)=0) then else {JMP}

{JNC,GotoUnNotZaem}$D2: if ((RgF and f_C)<>0) then else {JMP}

{JC,GotoUnZaem}$DA:if ((RgF and f_C)=0) then else {JMP}

{JPO,GotoUnNotChet}$E2:if ((RgF and f_P)<>0) then else {JMP}

{JPE,GotoUnChet}$EA:if ((RgF and f_P)=0) then else {JMP}

{JP,GotoUnPlus}$F2:if ((RgF and f_S)<>0) then else {JMP}

{JM,GotoUnMinus}$FA:if ((RgF and f_S)=0) then else {JMP}



{RET}{POP PC}$C9,$ D9:RpPC:=do_read(RpSP);RpPC:=RpPC+(do_read(RpSP+1) shl 8);RpSP:=(RpSP+2) and $FFFF;

{RNZ,RetUnNot0}$C0:if ((RgF and f_Z)<>0) then else {RET}

{RZ,RetUn0}$C8:if ((RgF and f_Z)=0) then else {RET}

{RNC,RetUnNotZaem}$D0: if ((RgF and f_C)<>0) then else {RET}

{RC,RetUnZaem}$D8:if ((RgF and f_C)=0) then else {RET}

{RPO,RetUnNotChet}$E0:if ((RgF and f_P)<>0) then else {RET}

{RPE,RetUnChet}$E8:if ((RgF and f_P)=0) then else {RET}

{RP,RetUnPlus}$F0:if ((RgF and f_S)<>0) then else {RET}

{RM,RetUnMinus}$F8:if ((RgF and f_S)=0) then else {RET}

24

{}

25

{Push PC}  RpSP:=(RpSP-2) and $FFFF; do_write(RpSP,RpPC and $FF);do_write(RpSP+1,(RpPC shr 8) and $FF);

{Call}$CD, $DD, $ED, $FD: begin tmp1:=do_read(RpPC+1)+(do_read(RpPC+2) shl 8);
{Push PC} RpPC:=tmp1;end;

{CNZ,CallUnNot0}$C4: begin if ((RgF and f_Z)<>0) then begin end else {Call}

{CZ,CallUn0}$CC:if ((RgF and f_Z)=0) then else {Call}

{CNC,CallUnNotZaem}$D4: if ((RgF and f_C)<>0) then else {Call}

{CC,CallUnZaem}$DC:if ((RgF and f_C)=0) then else {Call}

{CPO,CallUnNotChet}$E4:if ((RgF and f_P)<>0) then else {Call}

{CPE,CallUnChet}$EC:if ((RgF and f_P)=0) then else {Call}

{CP,CallUnPlus}$F4:if ((RgF and f_S)<>0) then else {Call}

{CM,CallUnMinus}$FC:if ((RgF and f_S)=0) then else {Call}

26

{}

27

{PUSHPCp1} RpSP:=(RpSP-2) and $FFFF;inc(RpPC);do_write(RpSP,RpPC and $FF);do_write(RpSP+1,(RpPC shr 8) and $FF)

{RST ...}

$C7:{PUSHPCp1} RpPC:=0*8;

$CF:{PUSHPCp1} RpPC:=1*8;

$D7:{PUSHPCp1} RpPC:=2*8;

$DF:{PUSHPCp1} RpPC:=3*8;

$E7:{PUSHPCp1} RpPC:=4*8;

$EF:{PUSHPCp1} RpPC:=5*8;

$F7:{PUSHPCp1} RpPC:=6*8;

$FF:{PUSHPCp1} RpPC:=7*8;

28

{OUT}$D3: begin do_output(do_read(RpPC+1),RgA);end;

{IN} $DB: begin RgA:=do_input(do_read(RpPC+1));end;

{DI}$F3: begin end;{не реалізовані}

{EI}$FB: begin end;{не реалізовані}


Вы здесь » Середовище програмування MADL » КР-580 » Емуляція КР-580 розкладення "на пальцях"(1)