Page 2 of 4 FirstFirst 1234 LastLast
Results 11 to 20 of 36

Thread: Pas2C64

  1. #11
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45
    Hmm is that PDN in the background? 1 word man: Sweet. Not M$ paint or something paid for but open source goodness I miss very much as a native app in linux, yes Pinta and others have their benefits, but its never the same is it?

    Anyway, nice work. I especially like that editor. Keep it up dude
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

  2. #12
    Quote Originally Posted by code_glitch View Post
    Hmm is that PDN in the background? 1 word man: Sweet. Not M$ paint or something paid for but open source goodness I miss very much as a native app in linux, yes Pinta and others have their benefits, but its never the same is it?

    Anyway, nice work. I especially like that editor. Keep it up dude
    LOL Yeah, it is Paint.NET in the background - I used it for saving the image

    I have made the editor using D2010, and the TSynEdit component so I could get syntax highlighting, etc. very sweet

    cheers,
    Paul

  3. #13
    Quote Originally Posted by Darthman View Post
    hmmmmm.... nostalgia.. (remember of my C64 in faк far past ^_^)

    Great, keep it going !
    <Homer Simpson accent>MMMMMMMMMMMMM...............NOSTALGIA...... ..</Homer Simpson accent>

    haha!

    Thanks for the support

    cheers,
    Paul

  4. #14
    Cool to see someone else targeting retro hardware... I just finished a DOS game targeting a 128k 4.77mhz 8088 as the minimum spec... though I've been also working in DEFT Pascal on the TRS-80 Color Computer.

    Was there no original pascal compiler for the C64 in the first place? Admittedly, a modern optimizing compiler meant for the target system would be a huge step up (just compare TP7 to TP3) but surely there must have been SOMETHING.

    I mean, on the Coco we had three -- OS/9 Pascal (which sucked but is what most people used), DEFT Pascal (the only one that made standalone .bin files you could cloadm or loadm and exec while having access to all 64k of memory if present) and StarPAS (which was just a p-code interpreter)... surely there must have been something for the C=64.

    Don't suppose you are planning on adding VIC=20 support to that? Just thinking I've still got one here. (along with my 64K coco 1 and my Tandy 1000EX)

    Writing programs for old systems is having an interesting side effect -- at least for me... portability. Emulators are ported to pretty much every modern system, so by writing a game for an old machine, you suddenly make it available to everyone.
    The accessibility of a website from time to time must be refreshed with the blood of designers and owners. It is its natural manure

  5. #15
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45
    There is one interesting aspect of all this: if the super-optimized code designed for a few Mhz and KB could be 'adapted' (even if at a slight performance loss) to work with todays' PCs - imagine the speed you could pull out of it! XD It's like when I had to load DOS 7.1 on a quad core machine: basically DOS on steroids.

    Now, that has even more potential
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

  6. #16
    Quote Originally Posted by deathshadow View Post
    Cool to see someone else targeting retro hardware... I just finished a DOS game targeting a 128k 4.77mhz 8088 as the minimum spec... though I've been also working in DEFT Pascal on the TRS-80 Color Computer.]
    Neat I never had a TRS-80 computer though, only the C64 (and then 128D).

    Quote Originally Posted by deathshadow View Post
    Was there no original pascal compiler for the C64 in the first place? Admittedly, a modern optimizing compiler meant for the target system would be a huge step up (just compare TP7 to TP3) but surely there must have been SOMETHING.

    I mean, on the Coco we had three -- OS/9 Pascal (which sucked but is what most people used), DEFT Pascal (the only one that made standalone .bin files you could cloadm or loadm and exec while having access to all 64k of memory if present) and StarPAS (which was just a p-code interpreter)... surely there must have been something for the C=64.]
    There were a bunch of Pascal compilers for the C64, but I wanted something native to windows, etc. that was easier to use

    It is also a fun project + diversion for me too LOL

    Quote Originally Posted by deathshadow View Post
    Don't suppose you are planning on adding VIC=20 support to that? Just thinking I've still got one here. (along with my 64K coco 1 and my Tandy 1000EX)
    I hadn't thought of VIC-20 support, but maybe I will...first I will get C64 support going

    Quote Originally Posted by deathshadow View Post
    Writing programs for old systems is having an interesting side effect -- at least for me... portability. Emulators are ported to pretty much every modern system, so by writing a game for an old machine, you suddenly make it available to everyone.
    Yeah! Emulators rock! On a nostalgia note, I do wish I had a real C64 though still though - it is what I learnt programming on part way between my 11th and 12 birthday

    Oh well...

    cheers,
    Paul

  7. #17
    Hey all,
    I hadn't worked on pas2c64 since February, so I thought I would have a bit more of a play with it. Since I have been using Lazarus 0.9.30 I thought I would have a go at converting over the program from Delphi to Lazarus using the automatic conversion.

    It actually worked perfectly!! Everything still works, even considering I am using SynEdit as the programming GUI part...I was pleasantly surprised!!

    So now I am continuing this using Lazarus now

    I am also now working on converting Delphi floating point numbers to c64 floating point numbers using this site as a basis for an algorithm I am writing:

    ftp://n2dvm.com/Commodore/Commie-CDs...e-base/197.htm

    I have a good feeling about this, so hopefully soon I will also be able to convert floating point numbers using the parser to c64 floating point format (4-byte mantissa + 1 byte exponent, ie. compressed memory version)...

    Once this works I will be able to use the C64 ROM routines to do any maths using floating point numbers!

    cheers,
    Paul
    Last edited by paul_nicholls; 08-06-2011 at 09:40 AM.

  8. #18
    Great news! Still waiting release
    Theory is - when you know everything but nothing works.
    Practice is - when all works, but you don't know why.
    We combine theory and practice - nothing works and nobody knows why

  9. #19
    Wow! It looks like I might have cracked this 'nut' wide open

    It seems I can now convert Delphi Doubles to c64 5-byte (packed memory representation, used for variables, etc) and 6-byte (c64 FP register) floating point representations!!

    I used the description found below to make the algorithms:
    ftp://n2dvm.com/Commodore/Commie-CDs...e-base/197.htm

    Here is the code if anyone is interested

    Code:
      PC64MemFloat = ^TC64MemFloat;
      TC64MemFloat = packed record
        Exponent: Byte;
        Mantissa: array[0..3] of Byte;
      end;
    
      PC64RegFloat = ^TC64RegFloat;
      TC64RegFloat = packed record
        Exponent: Byte;
        Mantissa: array[0..3] of Byte;
        Sign: Byte;
      end;
    
    procedure FloatToC64Float(num: Double; out aC64Float: TC64MemFloat); overload;
    procedure FloatToC64Float(num: Double; out aC64Float: TC64RegFloat); overload;
    function  C64FloatToStr(var aC64Float: TC64MemFloat): String; overload;
    function  C64FloatToStr(var aC64Float: TC64RegFloat): String; overload;
    
    implementation
    
    procedure FloatToC64Float(num: Double; out aC64Float: TC64MemFloat);
    // converts a floating point number to 5-byte memory FP representation: exponent (1), mantissa (4)
    //ftp://n2dvm.com/Commodore/Commie-CDs/Kazez%20FREE-CD/c64-knowledge-base/197.htm
    var
      ExpCount: Integer;
      SignBit: Integer;
      Index: Integer;
    begin
      Write(Format('%.10f = ',[num]));
    
      // save sign bit
      SignBit := 0;
      if num < 0 then
      begin
        SignBit := 128;
        num := -num;
      end;
    
      if Abs(num) < 0.000001 then
      begin
        aC64Float.Exponent    := 0;
        aC64Float.Mantissa[0] := 0;
        aC64Float.Mantissa[1] := 0;
        aC64Float.Mantissa[2] := 0;
        aC64Float.Mantissa[3] := 0;
    
        C64FloatToStr(aC64Float);
        Exit;
      end;
    
      // calculate exponent byte
      ExpCount := 0;
      if num < 1 then
        while num < 1 do
        begin
          Dec(ExpCount);
          num := num * 2;
        end
      else
      if num >= 2 then
        while num >= 2 do
        begin
          Inc(ExpCount);
          num := num / 2;
        end;
      aC64Float.Exponent := 129 + ExpCount;
    
      num := Frac(num / 2); // 'un-normalize' it for forther processing (immediate mantissa)
    
      // calculate mantissa digits
      for Index := 0 to 3 do
      begin
        num := num * 256;
        aC64Float.Mantissa[Index] := Trunc(num);
        num := Frac(num);
      end;
    
      // round last mantissa digit when required
      if num > 0.5 then Inc(aC64Float.Mantissa[3]);
    
      // include sign bit in first mantissa digit
      aC64Float.Mantissa[0] := (aC64Float.Mantissa[0] and $7F) or SignBit;
    
      C64FloatToStr(aC64Float);
    end;
    
    procedure FloatToC64Float(num: Double; out aC64Float: TC64RegFloat);
    // converts a floating point number to 6-byte register FP representation: exponent (1), mantissa (4), separate sign (1)
    //ftp://n2dvm.com/Commodore/Commie-CDs/Kazez%20FREE-CD/c64-knowledge-base/197.htm
    var
      ExpCount: Integer;
      SignBit: Integer;
      Index: Integer;
    begin
      Write(Format('%.10f = ',[num]));
    
      // save sign bit
      SignBit := 0;
      if num < 0 then
      begin
        SignBit := 128;
        num := -num;
      end;
    
      if Abs(num) < 0.000001 then
      begin
        aC64Float.Exponent    := 0;
        aC64Float.Mantissa[0] := 0;
        aC64Float.Mantissa[1] := 0;
        aC64Float.Mantissa[2] := 0;
        aC64Float.Mantissa[3] := 0;
        aC64Float.Sign        := 0;
    
        C64FloatToStr(aC64Float);
        Exit;
      end;
    
      // calculate exponent byte
      ExpCount := 0;
      if num < 1 then
        while num < 1 do
        begin
          Dec(ExpCount);
          num := num * 2;
        end
      else
      if num >= 2 then
        while num >= 2 do
        begin
          Inc(ExpCount);
          num := num / 2;
        end;
      aC64Float.Exponent := 129 + ExpCount;
    
      num := Frac(num / 2); // 'un-normalize' it for forther processing (immediate mantissa)
    
      // calculate mantissa digits
      for Index := 0 to 3 do
      begin
        num := num * 256;
        aC64Float.Mantissa[Index] := Trunc(num);
        num := Frac(num);
      end;
    
      // round last mantissa digit when required
      if num > 0.5 then Inc(aC64Float.Mantissa[3]);
    
      // include sign bit in sign part
      aC64Float.Mantissa[4] := SignBit;
    
      C64FloatToStr(aC64Float);
    end;
    
    function  C64FloatToStr(var aC64Float: TC64MemFloat): String;
    begin
      //output C64 mem floating point as hex (Exponent, Mantissa)
      WriteLn(Format('$%.2x $%.2x $%.2x $%.2x $%.2x (mem FP)',
                     [aC64Float.Exponent,
                      aC64Float.Mantissa[0],
                      aC64Float.Mantissa[1],
                      aC64Float.Mantissa[2],
                      aC64Float.Mantissa[3]]));
    end;
    
    function  C64FloatToStr(var aC64Float: TC64RegFloat): String;
    begin
      //output C64 reg floating point as hex (Exponent, Mantissa, Sign)
      WriteLn(Format('$%.2x $%.2x $%.2x $%.2x $%.2x $%.2x (reg FP)',
                     [aC64Float.Exponent,
                      aC64Float.Mantissa[0],
                      aC64Float.Mantissa[1],
                      aC64Float.Mantissa[2],
                      aC64Float.Mantissa[3],
                      aC64Float.Sign]));
    end;
    I can do this:

    Code:
    var
      C64MemFLoat: TC64MemFloat;
      C64RegFLoat: TC64RegFloat;
    begin
      FloatToC64Float(0,C64RegFLoat);
      FloatToC64Float(1,C64RegFLoat);
      FloatToC64Float(2,C64RegFLoat);
      FloatToC64Float(3,C64RegFLoat);
      FloatToC64Float(1/2,C64RegFLoat);
      FloatToC64Float(1/4,C64RegFLoat);
      FloatToC64Float(-67,C64RegFLoat);
    
      FloatToC64Float(13,C64RegFLoat);
    
      FloatToC64Float(0,C64MemFLoat);
      FloatToC64Float(3.141592654,C64MemFLoat);
      FloatToC64Float(+27,C64MemFLoat);
    
      ReadLn;
    end.
    and get this output (seems to exactly match what examples I have seen online!)
    Code:
    0.0000000000 = $00 $00 $00 $00 $00 $00 (reg FP)
    1.0000000000 = $81 $80 $00 $00 $00 $00 (reg FP)
    2.0000000000 = $82 $80 $00 $00 $00 $00 (reg FP)
    3.0000000000 = $82 $C0 $00 $00 $00 $00 (reg FP)
    0.5000000000 = $80 $80 $00 $00 $00 $00 (reg FP)
    0.2500000000 = $7F $80 $00 $00 $00 $00 (reg FP)
    -67.0000000000 = $87 $86 $00 $00 $00 $80 (reg FP)
    13.0000000000 = $84 $D0 $00 $00 $00 $00 (reg FP)
    0.0000000000 = $00 $00 $00 $00 $00 (mem FP)
    3.1415926540 = $82 $49 $0F $DA $A3 (mem FP)
    27.0000000000 = $85 $58 $00 $00 $00 (mem FP)
    Quote Originally Posted by Darthman View Post
    Great news! Still waiting release
    LOL thanks! if I get much further, I might make an open source project (read-only for now) somewhere so people can follow using SVN, etc.

    Oh, I am also going to see if I can make the reverse, following the instructions on that site so I can go from c64 FP to Delphi Double for debugging, etc.

    cheers,
    Paul

  10. #20
    After testing, and some assembly help from forum.6502.org, I can now create C64 floating point numbers and at least print them out in a C64 emulator!!

    This input:

    Code:
    program Test;
    begin
      WriteLn(102);
    end;
    Generated this assembler:

    Code:
        .org $0800 ; start at BASIC
        .byte $00 $0c $08 $0a $00 $9e $20 $32 ; encode SYS 2064
        .byte $30 $36 $34 $00 $00 $00 $00 $00 ; as BASIC line
    
    Lab2064
        JMP main
    main
    ;load floating point number at L1 into FAC1
        LDA #<L1
        LDY #>L1
        JSR $BBA2
        
    ;convert number in FAC1 to ASCII (pointer in A & Y)
        JSR $BDDD
        
    ;store pointer of ASCII string into zero-page
        STA $FB
        STY $FB + 1
    
    ;loop through each character in the ASCII and print it out (stop on NULL ($00) value)
        LDY #$00
    L0
        LDA ($FB),Y
        BEQ L2
        JSR $FFD2
        INY
        JMP L0
    L1
        .byte $87 $4C $00 $00 $00
    L2
        RTS
    And this in turn ran on the C64 emulator and printed out the number I entered in the program

    This means that after some refactoring, I should now be able to add expressions to my compiler and do some math on the C64

    cheers,
    Paul

Page 2 of 4 FirstFirst 1234 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •