Lazarus

Announcements => Third party => Topic started by: Edson on August 31, 2018, 09:24:46 pm

Title: P65Pas a new 6502 Pascal compiler
Post by: Edson on August 31, 2018, 09:24:46 pm
I would like to present my new Pascal compiler for the 6502 CPU  :D: https://github.com/t-edson/P65Pas

If it's very similar to my PicPas PIC compiler, is because they are brothers and share many libraries and code.

This compiler is just in the beginning (incomplete) and have implemented only very basic functionalities  :-[

Any collaboration is welcome.
Title: Re: P65Pas a new 6502 Pascal compiler
Post by: Mike.Cornflake on September 01, 2018, 01:46:20 am
:-)   Many thanks for this.  When I return home in a few weeks I look forward to playing with this.  Fond memories of the 6502 from the Vic 20 days :-)
Title: Re: P65Pas a new 6502 Pascal compiler
Post by: hansotten on September 01, 2018, 04:42:01 pm
Great project!

What I like about it, that you did not try to implement yet another Pascal compiler for the 6502, like UCSD Pascal.

The 6502 is not very compiler friendly.: lack of 16 bit registers, hardware stack with 8 bit stackpointer.
High level, block structured based, recursion able, languages require lots of memory, stacks, heaps, stack frames, variables on the stack. That means on the 6502 a software stack with zero page based stack pointer, and quite some code. Storing data stored on the stack also requires quite some code.
A solution often used on small machines with the 6502 is to generate compact code for virtual machine and the virtual machine implements an interpreteer for a  stack machine. It works but is slow.
Trying to generate 6502 code leads to lots of code alas and memory is filled up quickly.

Instead you choose to design a language in the Pascal spirit but without no recursion, no blocks, dasta stored static   

That i why I like your approach: no recursion, static variables.
 
I did a quick test (I am aware not all is implemented!)

Code: [Select]
program testprog;

  var i : byte ;
      l : byte absolute $F000 ;
 
  procedure test (j: byte);
 
  var k : byte ;
     
 
  begin
    k := j ;
    j := k ;
  end;
 
begin
   asm
    cld ;
  end

  i := 2 ;
  test (i) ;
  i := i + 1 ;
  l := i ;
 end.

Code: [Select]
    ;Code generated by P6502 compiler
    processor 6502
;===RAM usage===
i EQU 0x005
l EQU 0xF000
j EQU 0x003
k EQU 0x004
;------ Work and Aux. Registers ------
;===Blocks of Code===
            ORG $0000
      $0000 4C 0F 00 JMP $000F
j     $0003 DB ??
k     $0004 DB ??
i     $0005 DB ??
__test:
      $0006 A5 03    LDA $03
      $0008 85 04    STA $04
      $000A A5 04    LDA $04
      $000C 85 03    STA $03
      $000E 60       RTS 
__main_program__:
      $000F D8       CLD 
      $0010 A9 02    LDA #$02
      $0012 85 05    STA $05
      $0014 A5 05    LDA $05
      $0016 85 03    STA $03
      $0018 20 06 00 JSR $0006
      $001B E6 05    INC $05
      $001D 85 05    STA $05
      $001F A5 05    LDA $05
      $0021 8D 00 F0 STA $F000
;--------------------
      END

Great start! I like to see your progress!
Title: Re: P65Pas a new 6502 Pascal compiler
Post by: marcov on September 01, 2018, 08:44:13 pm
Maybe if you define some zeropage pairs as parameter and some as volatile registers.
Title: Re: P65Pas a new 6502 Pascal compiler
Post by: Edson on March 06, 2019, 03:41:17 am
New functions added to P65Pas. Still far for be complete, but can compile simple codes. Tetsing in Commodore64:
Title: Re: P65Pas a new 6502 Pascal compiler
Post by: Edson on June 13, 2019, 10:06:41 pm
Advancing the implementation of P65Pas compiler: https://github.com/t-edson/P65Pas

Supporting to define arrays of char, added.

New assembler operators for access bytes of word constants.
Title: Re: P65Pas a new 6502 Pascal compiler
Post by: Edson on June 27, 2019, 08:12:07 pm
P65Pas 0.6 more complete, more powerfull. Now support for arrays and register parameters:

Title: Re: P65Pas a new 6502 Pascal compiler
Post by: Edson on July 24, 2019, 04:23:01 am
P65Pas has been updated. Now in the version 0.7.1, includes better support for arrays and types: https://github.com/t-edson/P65Pas
Title: Re: P65Pas a new 6502 Pascal compiler
Post by: tr_escape on July 24, 2019, 12:55:49 pm
P65Pas has been updated. Now in the version 0.7.1, includes better support for arrays and types: https://github.com/t-edson/P65Pas
Is there any plan for a c64 game ?
Title: Re: P65Pas a new 6502 Pascal compiler
Post by: Edson on July 24, 2019, 04:01:05 pm
Is there any plan for a c64 game ?

Not by the moment. There are some features I want to include to the compiler first, like float numbers or objects support. Also it's needed to create some libraries, examples and documentation.
Title: Re: P65Pas a new 6502 Pascal compiler
Post by: lucamar on July 24, 2019, 04:41:16 pm
For such a limited target I wouldn't add objects unless you make them very basic, kind of like what extended records are today. Even old-style objects (the Turbo Pascal ones) can become quite  slow and memory-heavy if you must allow for virtual methods, etc. and will tend to use up the stack very quickly.
Title: Re: P65Pas a new 6502 Pascal compiler
Post by: Edson on July 24, 2019, 05:29:25 pm
Exactly. The object support will be very Basic in this compiler, as the style of extended records. All static by now. Not constructors/destructors/virtual methods. I use a dfferent syntax of object. Still in testing:

Code: Pascal  [Select]
  1. var
  2.   rec: object
  3.          x,y: byte;
  4.          procedure Clear;
  5.          begin
  6.            x:=0;
  7.            y:=0
  8.          end;
  9.        end;
  10. begin
  11.   rec.clear;
  12. end.
Title: Re: P65Pas a new 6502 Pascal compiler
Post by: Squall_FF8 on October 30, 2019, 03:17:03 pm
@Edson excellent work on this project!
I tried it and it works great! I actually plan to use it to develop games/applications for the new computer: Commander X16. If you are interested what I changed in order to produce code for X16, I will gladly share!

I have MANY questions and suggestions for your project, but I guess we will need a faster way to communicate like Discord or Facebook.

P.S. Are you still working on the project?
P.S.2 My Discord is Squall#0443
Title: Re: P65Pas a new 6502 Pascal compiler
Post by: Edson on October 30, 2019, 07:15:36 pm
Hi. I'm taken a rest from compilers by now. Just solving simple issues. Daily work doesn't give much time for personal projects.

I have never heard about Commander X16, but it looks cool. It's like the dreamed 8 bit CPU for gamers of the 80's.

I don't use Discord but You can find me in Facebook like "Tito Hinostroza" I use WhatsApp too.
Title: Re: P65Pas a new 6502 Pascal compiler
Post by: sstvmaster on October 30, 2019, 08:08:23 pm
@Edson

Do you know "The 8-Bit Guy" ?

see:
- https://www.youtube.com/user/adric22/search?query=x16
- https://murray2.com/forums/commander-x16.9/

Title: Re: P65Pas a new 6502 Pascal compiler
Post by: Edson on October 31, 2019, 12:59:44 am
@Edson

Do you know "The 8-Bit Guy" ?

see:
- https://www.youtube.com/user/adric22/search?query=x16
- https://murray2.com/forums/commander-x16.9/

Not really.
Title: Re: P65Pas a new 6502 Pascal compiler
Post by: Squall_FF8 on October 31, 2019, 02:06:57 pm
Found you on Facebook. A friend request was sent. :)

And yes, the links that sstvmaster shared are the one. It still in process of designing but has already huge fan base and many people developing for it. It will be close to Comodore 64, this where similarities come from.
In the spirit of 8bit era it comes with BASIC. I can do assembly but it is a much slower process and very easy to make mistakes. So the Pascal and your IDE make it a RAD tool  8-)

P.S. Here is a screenshot of the application showing the system palette written with p65pas:

Title: Re: P65Pas a new 6502 Pascal compiler
Post by: Edson on October 31, 2019, 09:27:24 pm
It's good to see people are using the P65Pas. There are still many features to implement and fix in the compiler. The support for assembler is very complete and can interact well with the Pascal code.

Fortunately  P65Pas was designed to be a general 6502 compiler, and not for a specific target. You can write a unit for the Commander X16 defining the hardware specific details.
Title: Re: P65Pas a new 6502 Pascal compiler
Post by: Squall_FF8 on November 04, 2019, 09:13:11 am
Quote
The support for assembler is very complete and can interact well with the Pascal code.
That is what I love about Pascal - it eliminate the need to write in pure assembly by providing a good asm code for output. In places where the compiler doesn't you can always rewrite segments for speed ups.
Quote
Fortunately  P65Pas was designed to be a general 6502 compiler, and not for a specific target. You can write a unit for the Commander X16 defining the hardware specific details.
That is exactly what I did - I used the included C64 as a base and modified it for X16 :)