Page 1 of 4 123 ... LastLast
Results 1 to 10 of 36

Thread: Pas2C64

  1. #1

    Pas2C64

    Hey all,
    Just for fun, I am attempting to make a 'compiler' (called Pas2C64) that will compile a simple Pascal-like language into C64 (6510 processor) assembly instructions.

    The assembly instructions will assembled by Win2C64, a windows cross-assembler that creates T64 (tape format) programs that can be run by a C64 emulator. There are Linux/Mac versions too apparently on request...

    I knew that there were a bunch of cross compilers (like cc65, a 6502 C compiler) that generate C64 programs using a C/C++ language, but I wanted good old Pascal damn-it! LOL

    I have started creating a TCodeGenerator_C64 class which I have been directly testing (no Pascal -> ML yet..):

    Input:
    Code:
              cg.WriteMainProgramStart(49152);
    
              cg.WriteComment('Copy the background color to the border');
    
              cg.LoadReg_Mem(regA,$D021);
              cg.StoreReg(regA,$D020);
    
              cg.OpCode(opRTS);
    Output:
    Code:
        .org $C000
    main
    ;Copy the background color to the border
        LDA $D021
        STA $D020
        RTS
    I can then assemble the code using Win2C64, and run it on the WinVICE C64 emulator doing this:

    Code:
    SYS 49152
    To save time for myself (or others), I can also add in a Basic loader at the beginning of the code by doing this:

    Code:
              cg.WriteBasicLoader;
              cg.WriteMainProgramStart;
    
              cg.WriteComment('Copy the background color to the border');
    
              cg.LoadReg_Mem(regA,$D021);
              cg.StoreReg(regA,$D020);
    
              cg.OpCode(opRTS);
    which produces this:

    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
    ;Copy the background color to the border
        LDA $D021
        STA $D020
        RTS
    This means that when the program loads in WinVICE, it automatically runs due to the line of basic code that does the system call to the machine code program

    This should be an interesting little diversion for me LOL

    cheers,
    Paul
    Last edited by paul_nicholls; 21-01-2011 at 03:52 AM.

  2. #2
    Good idea Paul
    I enjoy these kind of retro-projects and I will follow your progress.
    ZGameEditor - Develop 64kb games for Windows.
    Thrust for Vectrex - ROM-file and 6809 source code.

  3. #3
    Sounds interesting. Making a compiler is also on my todo-list.
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  4. #4
    Well, I have gotten a bit further, am actually doing some parsing now...

    Now I can do this:

    Code:
    WriteMemB(53248,5);
    
    WriteMemB($A000,201);
    
    WriteMemB(32768,%1010);
    
    CopyMemB(53248,$D022)
    and get this:


    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
        LDA #$05
        STA $D000
    
        LDA #$C9
        STA $A000
    
        LDA #$0A
        STA $8000
    
        LDA $D000
        STA $D022
        RTS
    I added in some blank lines in the assembler output to break up the commands output so you can see it more clearly

    It even checks that the address is not larger than $FFFF, and that the value is not larger than $FF for the commands...

    It's a start!

    cheers,
    Paul

  5. #5
    as usual paul you make incredible work !
    Current (and lifetime) project: FAR Colony
    https://www.farcolony.com/

  6. #6
    Quote Originally Posted by farcodev View Post
    as usual paul you make incredible work !
    thanks mate

    You are very good yourself, looking at your game screenshots!

    cheers,
    Paul

  7. #7

    Talking

    May be you remember I started a compiler for Z-80 (here). Currently it's in stand by (as most of my current projects) but it has a complete parser and is able to compile "ASM".

    I'll take a look to your project to steal some code.
    No signature provided yet.

  8. #8
    LOL! I will have to release some code first

    cheers,
    Paul

  9. #9
    Since I have added a WriteLn() command (for strings only ATM) to pas2c64, I decided to make a "hello world" example! LOL



    I skipped the basic loader to save some vertical space...

    It might not be the most exciting code ever, but it works <G>
    cheers,
    Paul
    Last edited by paul_nicholls; 08-02-2011 at 11:34 AM.

  10. #10
    hmmmmm.... nostalgia.. (remember of my C64 in faк far past ^_^)

    Great, keep it going !
    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

Page 1 of 4 123 ... 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
  •