Browse Source

+ introduced BAS_EncodeNumber to make it easier to encode numbers in the BASIC program

git-svn-id: branches/z80@44591 -
nickysn 5 years ago
parent
commit
8619a8cb32
2 changed files with 26 additions and 1 deletions
  1. 1 1
      utils/ihx2tzx/ihx2tzx.lpr
  2. 25 0
      utils/ihx2tzx/zxbasic.pas

+ 1 - 1
utils/ihx2tzx/ihx2tzx.lpr

@@ -100,7 +100,7 @@ begin
   FTapeWriter := TTZXWriter.Create(FOutputFile);
 
   BasicLine1 := ' '+BC_LOAD+'"" '+BC_CODE+#13;
-  BasicLine2 := ' '+BC_PRINT+BC_USR+IntToStr(FInputImage.Origin)+#14#0#0+Chr(Byte(FInputImage.Origin))+Chr(Byte(FInputImage.Origin shr 8))+#0#13;
+  BasicLine2 := ' '+BC_PRINT+BC_USR+BAS_EncodeNumber(FInputImage.Origin)+#13;
   BasicProgram := #0#10+Chr(Byte(Length(BasicLine1)))+Chr(Byte(Length(BasicLine1) shr 8))+BasicLine1+
                   #0#20+Chr(Byte(Length(BasicLine2)))+Chr(Byte(Length(BasicLine2) shr 8))+BasicLine2;
 

+ 25 - 0
utils/ihx2tzx/zxbasic.pas

@@ -124,7 +124,32 @@ const
   BC_RETURN    = #254;  { RETURN    }
   BC_COPY      = #255;  { COPY      }
 
+function BAS_EncodeNumber(N: Integer): ansistring;
+function BAS_EncodeNumber(N: Real): ansistring;
+
 implementation
 
+function BAS_EncodeNumber(N: Integer): ansistring;
+begin
+  if (N >= -65535) and (N <= 65535) then
+  begin
+    Str(N, Result);
+    if N >= 0 then
+      Result := Result + #14#0#0 + Chr(Byte(N)) + Chr(Byte(N shr 8)) + #0
+    else
+    begin
+      N := Word(N + 131072);
+      Result := Result + #14#0#255 + Chr(Byte(N)) + Chr(Byte(N shr 8)) + #0;
+    end;
+  end
+  else
+    Result := BAS_EncodeNumber(Real(N));
+end;
+
+function BAS_EncodeNumber(N: Real): ansistring;
+begin
+  raise ENotImplemented.Create('Real number support not yet implemented');
+end;
+
 end.