Browse Source

+ 6502: use normalize_ref in a_load_const_ref to handle all ref cases

Nikolay Nikolov 1 month ago
parent
commit
a79f0cf350
1 changed files with 20 additions and 2 deletions
  1. 20 2
      compiler/mos6502/cgcpu.pas

+ 20 - 2
compiler/mos6502/cgcpu.pas

@@ -1451,11 +1451,12 @@ unit cgcpu;
          shift : byte;
          shift : byte;
          href: treference;
          href: treference;
          i: Integer;
          i: Integer;
+         allocatedregs: tregisterlist;
        begin
        begin
-         list.Concat(tai_comment.Create(strpnew('TODO: a_load_const_ref '+tcgsize2str(size) + ' '+tostr(a)+' '+ref2string(ref))));
+         //list.Concat(tai_comment.Create(strpnew('TODO: a_load_const_ref '+tcgsize2str(size) + ' '+tostr(a)+' '+ref2string(ref))));
          mask:=$ff;
          mask:=$ff;
          shift:=0;
          shift:=0;
-         href:=ref;
+         href:=normalize_ref(list,ref,allocatedregs);
          if (href.base=NR_NO) and (href.index=NR_NO) then
          if (href.base=NR_NO) and (href.index=NR_NO) then
            begin
            begin
              { TODO: get/unget register A }
              { TODO: get/unget register A }
@@ -1470,7 +1471,24 @@ unit cgcpu;
                      inc(href.offset);
                      inc(href.offset);
                    end;
                    end;
                end;
                end;
+           end
+         else
+           begin
+             { TODO: get/unget register A }
+             for i:=tcgsize2size[size] downto 1 do
+               begin
+                 list.Concat(taicpu.op_const(A_LDA,(qword(a) and mask) shr shift));
+                 list.Concat(taicpu.op_ref(A_STA,href));
+                 if i<>1 then
+                   begin
+                     mask:=mask shl 8;
+                     inc(shift,8);
+                     list.Concat(taicpu.op_none(A_INY));
+                     //inc(href.offset);
+                   end;
+               end;
            end;
            end;
+         ungetcpuregisters(list,allocatedregs);
          //if (href.base=NR_NO) and (href.index<>NR_NO) then
          //if (href.base=NR_NO) and (href.index<>NR_NO) then
          //  begin
          //  begin
          //    href.base:=href.index;
          //    href.base:=href.index;