|
@@ -103,6 +103,7 @@ unit cgcpu;
|
|
procedure a_jmp_cond(list : TAsmList;cond : TOpCmp;l: tasmlabel);
|
|
procedure a_jmp_cond(list : TAsmList;cond : TOpCmp;l: tasmlabel);
|
|
procedure fixref(list : TAsmList;var ref : treference);
|
|
procedure fixref(list : TAsmList;var ref : treference);
|
|
function normalize_ref(list : TAsmList;ref : treference; const refopertypes:trefoperandtypes; out allocatedregs:tregisterlist) : treference;
|
|
function normalize_ref(list : TAsmList;ref : treference; const refopertypes:trefoperandtypes; out allocatedregs:tregisterlist) : treference;
|
|
|
|
+ procedure adjust_normalized_ref(list: TAsmList;var ref: treference; value: longint);
|
|
|
|
|
|
procedure emit_mov(list: TAsmList;reg2: tregister; reg1: tregister);
|
|
procedure emit_mov(list: TAsmList;reg2: tregister; reg1: tregister);
|
|
|
|
|
|
@@ -1276,24 +1277,65 @@ unit cgcpu;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
+ procedure tcgz80.adjust_normalized_ref(list: TAsmList; var ref: treference; value: longint);
|
|
|
|
+ var
|
|
|
|
+ i: Integer;
|
|
|
|
+ begin
|
|
|
|
+ if is_ref_addr16(ref) then
|
|
|
|
+ Inc(ref.offset,value)
|
|
|
|
+ else if is_ref_hl(ref) then
|
|
|
|
+ begin
|
|
|
|
+ if value>0 then
|
|
|
|
+ for i:=1 to value do
|
|
|
|
+ list.concat(taicpu.op_reg(A_INC,NR_HL))
|
|
|
|
+ else
|
|
|
|
+ for i:=-1 downto value do
|
|
|
|
+ list.concat(taicpu.op_reg(A_DEC,NR_HL));
|
|
|
|
+ end
|
|
|
|
+ else if is_ref_ix_d(ref) then
|
|
|
|
+ begin
|
|
|
|
+ if ((ref.offset+value)<=127) and ((ref.offset+value)>=-128) then
|
|
|
|
+ inc(ref.offset,value)
|
|
|
|
+ else
|
|
|
|
+ begin
|
|
|
|
+ { todo: IX is the frame pointer, we cannot change it, so we }
|
|
|
|
+ { think of another mechanism to deal with this situation }
|
|
|
|
+ internalerror(2020042101);
|
|
|
|
+ //if value>0 then
|
|
|
|
+ // for i:=1 to value do
|
|
|
|
+ // list.concat(taicpu.op_reg(A_INC,NR_IX))
|
|
|
|
+ //else
|
|
|
|
+ // for i:=-1 downto value do
|
|
|
|
+ // list.concat(taicpu.op_reg(A_DEC,NR_IX));
|
|
|
|
+ end;
|
|
|
|
+ end
|
|
|
|
+ else if is_ref_iy_d(ref) then
|
|
|
|
+ begin
|
|
|
|
+ if ((ref.offset+value)<=127) and ((ref.offset+value)>=-128) then
|
|
|
|
+ inc(ref.offset,value)
|
|
|
|
+ else
|
|
|
|
+ if value>0 then
|
|
|
|
+ for i:=1 to value do
|
|
|
|
+ list.concat(taicpu.op_reg(A_INC,NR_IY))
|
|
|
|
+ else
|
|
|
|
+ for i:=-1 downto value do
|
|
|
|
+ list.concat(taicpu.op_reg(A_DEC,NR_IY));
|
|
|
|
+ end;
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+
|
|
procedure tcgz80.a_load_reg_ref(list : TAsmList; fromsize, tosize: tcgsize; reg : tregister;const ref : treference);
|
|
procedure tcgz80.a_load_reg_ref(list : TAsmList; fromsize, tosize: tcgsize; reg : tregister;const ref : treference);
|
|
var
|
|
var
|
|
href : treference;
|
|
href : treference;
|
|
i : integer;
|
|
i : integer;
|
|
|
|
+ regsused: tregisterlist;
|
|
begin
|
|
begin
|
|
- href:=Ref;
|
|
|
|
- { ensure, href.base contains a valid register if there is any register used }
|
|
|
|
- if href.base=NR_NO then
|
|
|
|
- begin
|
|
|
|
- href.base:=href.index;
|
|
|
|
- href.index:=NR_NO;
|
|
|
|
- end;
|
|
|
|
-
|
|
|
|
if (tcgsize2size[fromsize]>32) or (tcgsize2size[tosize]>32) or (fromsize=OS_NO) or (tosize=OS_NO) then
|
|
if (tcgsize2size[fromsize]>32) or (tcgsize2size[tosize]>32) or (fromsize=OS_NO) or (tosize=OS_NO) then
|
|
internalerror(2011021307);
|
|
internalerror(2011021307);
|
|
if tcgsize2size[fromsize]>tcgsize2size[tosize] then
|
|
if tcgsize2size[fromsize]>tcgsize2size[tosize] then
|
|
internalerror(2020040802);
|
|
internalerror(2020040802);
|
|
|
|
|
|
|
|
+ href:=normalize_ref(list,Ref,[OT_REF_ADDR16,OT_REF_HL,OT_REF_IX_d,OT_REF_IY_d],regsused);
|
|
if (fromsize=tosize) or (fromsize in [OS_8,OS_16,OS_32]) then
|
|
if (fromsize=tosize) or (fromsize in [OS_8,OS_16,OS_32]) then
|
|
begin
|
|
begin
|
|
getcpuregister(list,NR_A);
|
|
getcpuregister(list,NR_A);
|
|
@@ -1304,7 +1346,7 @@ unit cgcpu;
|
|
if i<>tcgsize2size[fromsize] then
|
|
if i<>tcgsize2size[fromsize] then
|
|
reg:=GetNextReg(reg);
|
|
reg:=GetNextReg(reg);
|
|
if i<>tcgsize2size[tosize] then
|
|
if i<>tcgsize2size[tosize] then
|
|
- inc(href.offset);
|
|
|
|
|
|
+ adjust_normalized_ref(list,href,1);
|
|
end;
|
|
end;
|
|
for i:=tcgsize2size[fromsize]+1 to tcgsize2size[tosize] do
|
|
for i:=tcgsize2size[fromsize]+1 to tcgsize2size[tosize] do
|
|
begin
|
|
begin
|
|
@@ -1313,7 +1355,7 @@ unit cgcpu;
|
|
list.concat(taicpu.op_ref_reg(A_LD,href,NR_A));
|
|
list.concat(taicpu.op_ref_reg(A_LD,href,NR_A));
|
|
if i<>tcgsize2size[tosize] then
|
|
if i<>tcgsize2size[tosize] then
|
|
begin
|
|
begin
|
|
- inc(href.offset);
|
|
|
|
|
|
+ adjust_normalized_ref(list,href,1);
|
|
reg:=GetNextReg(reg);
|
|
reg:=GetNextReg(reg);
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
@@ -1329,7 +1371,7 @@ unit cgcpu;
|
|
if i<>tcgsize2size[fromsize] then
|
|
if i<>tcgsize2size[fromsize] then
|
|
reg:=GetNextReg(reg);
|
|
reg:=GetNextReg(reg);
|
|
if i<>tcgsize2size[tosize] then
|
|
if i<>tcgsize2size[tosize] then
|
|
- inc(href.offset);
|
|
|
|
|
|
+ adjust_normalized_ref(list,href,1);
|
|
end;
|
|
end;
|
|
list.concat(taicpu.op_none(A_RLA));
|
|
list.concat(taicpu.op_none(A_RLA));
|
|
list.concat(taicpu.op_reg_reg(A_SBC,NR_A,NR_A));
|
|
list.concat(taicpu.op_reg_reg(A_SBC,NR_A,NR_A));
|
|
@@ -1338,12 +1380,13 @@ unit cgcpu;
|
|
list.concat(taicpu.op_ref_reg(A_LD,href,NR_A));
|
|
list.concat(taicpu.op_ref_reg(A_LD,href,NR_A));
|
|
if i<>tcgsize2size[tosize] then
|
|
if i<>tcgsize2size[tosize] then
|
|
begin
|
|
begin
|
|
- inc(href.offset);
|
|
|
|
|
|
+ adjust_normalized_ref(list,href,1);
|
|
reg:=GetNextReg(reg);
|
|
reg:=GetNextReg(reg);
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
ungetcpuregister(list,NR_A);
|
|
ungetcpuregister(list,NR_A);
|
|
end;
|
|
end;
|
|
|
|
+ ungetcpuregisters(list,regsused);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|