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 :)
Title: Re: P65Pas a new 6502 Pascal compiler
Post by: Edson on January 14, 2020, 05:32:04 am
P65Pas is updated. Now in version 0.7.5.  Some bugs are fixed, and the code generator is modified to map internal register in the system unit.
Documentation is updated too.
Title: Re: P65Pas a new 6502 Pascal compiler
Post by: lazdeveloper on January 14, 2020, 07:25:02 pm
GREAT!
I would to thank you for such great projects. Pascal is so good for hardware programming please and again keep the support to keep it alive
Thanks
Title: Re: P65Pas a new 6502 Pascal compiler
Post by: Edson on March 14, 2022, 03:33:33 am
Version 0.9.0 are available now in https://github.com/t-edson/P65Pas.

First version with a new lexer and an improved Code generator.  :)
Title: Re: P65Pas a new 6502 Pascal compiler
Post by: dseligo on March 14, 2022, 04:17:33 am
Great work 8)
Title: Re: P65Pas a new 6502 Pascal compiler
Post by: Chronos on March 14, 2022, 10:32:39 am
Analyzer.pas file is missing from github project so it can't be built.
Title: Re: P65Pas a new 6502 Pascal compiler
Post by: Edson on March 14, 2022, 03:56:39 pm
Analyzer.pas file is missing from github project so it can't be built.

 :o
Sorry. It's fixed now and updated to work with Lazarus 2.2.0.

To compile the compiler you'll only need the Epik Timer component. All other dependencies are included in the /Source folder.

There are some detailed documentation about the compiler for interested people.
Title: Re: P65Pas a new 6502 Pascal compiler
Post by: Chronos on March 14, 2022, 06:56:42 pm
Thanks for the missing file.

It seems that P65Pas really looks very like PicPas. So one would think that you can have single project for both P65Pas and PicPas. It may not be easy to develop such dual/multi target IDE but I guess it would reduce code duplicity a lot. At least I would merge those two project into one. And perhaps release it as multi-target compiler/IDE or also as two single target compilers/IDEs.

And my previous suggestions for PicPas are also valid for P65Pas:
* The application doesn't remember windows size and position.
* Scaling and High DPI support is not enabled. So windows and text looks wrong under high DPI.
* File open and save dialog won't use path to current opened file or last used path.
* Application config file P65Pas-linux.xml should be better placed into user config directory. Use function GetAppConfigDir(False) to get that directory. Also don't put your local recent files into that file and into git. It should be initialized as clean.
* Temp directory should be located under linux in /tmp directory or something like /tmp/P65Pas or /tmp/P65Pas-username. Or it can be also located in user config dir as temp.
* Use .gitignore file to ignore dynamically created directories and files like project.lrs, project.res and project/lib.
* It would be better to support translation via standard .po files generation rather than manually generate translation as pascal source.
* Put EpikTimer package source into your project so anybody compiling your project won't need to download it manually and the package version will match with your project nicely

Feel free to implement them if you want to improve usability of your app.
Title: Re: P65Pas a new 6502 Pascal compiler
Post by: Chronos on March 14, 2022, 11:28:02 pm
Snap package is now available https://snapcraft.io/p65pas
Snap fork: https://github.com/chronoscz/P65Pas
Title: Re: P65Pas a new 6502 Pascal compiler
Post by: Edson on March 15, 2022, 01:26:02 am
It seems that P65Pas really looks very like PicPas. So one would think that you can have single project for both P65Pas and PicPas. It may not be easy to develop such dual/multi target IDE but I guess it would reduce code duplicity a lot. At least I would merge those two project into one. And perhaps release it as multi-target compiler/IDE or also as two single target compilers/IDEs.

Yes. P65Pas and PicPas share the almost all the same code for the IDE (Although, at the compiler level, P65Pas has a more advanced internal architecture). The merge of both projects it's one of my future objectives. But that requires several tasks to be done beforehand. For example I have been doing considerable work on separation of the IDE and compiler code. Now it's almost done. I hope to have soon a command line compiler.
Finally, there would be a single IDE (With debugger and emulator) and several compilers for the 6502/65C02, PIC10F/16F/18F and I'm thinking on create new compilers for the Z80 and AMD devices. All accessible from the same IDE.

And my previous suggestions for PicPas are also valid for P65Pas:
* The application doesn't remember windows size and position.
* Scaling and High DPI support is not enabled. So windows and text looks wrong under high DPI.
* File open and save dialog won't use path to current opened file or last used path.
* Application config file P65Pas-linux.xml should be better placed into user config directory. Use function GetAppConfigDir(False) to get that directory. Also don't put your local recent files into that file and into git. It should be initialized as clean.
* Temp directory should be located under linux in /tmp directory or something like /tmp/P65Pas or /tmp/P65Pas-username. Or it can be also located in user config dir as temp.
* Use .gitignore file to ignore dynamically created directories and files like project.lrs, project.res and project/lib.
* It would be better to support translation via standard .po files generation rather than manually generate translation as pascal source.
* Put EpikTimer package source into your project so anybody compiling your project won't need to download it manually and the package version will match with your project nicely

I can implement most of this features now in this branch. Currently I'm fixing a problem with units references and some other features. When the compiler is more advanced, I will start migrating PicPas to the new P65Pas architecture and separating the IDEs to eventually merge them into a single IDE.
Title: Re: P65Pas a new 6502 Pascal compiler
Post by: Edson on August 15, 2022, 06:51:54 pm
P65Pas https://github.com/t-edson/P65Pas is now updated with a new redesign of the core compiler and the IDE/Debugger. Some changes are:

- New lexer with ability to change the syntax definition on runtime.
- Abstract syntax Tree improved with new syntax elements.
- Improved Assembler blocks with support for DB or DW.
- Compiler separated from the IDE. Now there are two separated projects.
- IDE redesigned to support several compilers including tools.
- More control about the binary code to adapt to several 6502 system like Commodore PET or Commodore 128.
Title: Re: P65Pas a new 6502 Pascal compiler
Post by: Chronos on August 15, 2022, 09:25:32 pm
Nice. Can you create new tag or also new release in github for that 1.0.0 version?
Title: Re: P65Pas a new 6502 Pascal compiler
Post by: Edson on August 16, 2022, 12:46:45 am
Nice. Can you create new tag or also new release in github for that 1.0.0 version?

New tag created in the Github.

Some additional changes I forgot to mention:

- Support for themes in the IDE is improved.
- File explorer improved and implemented for Linux too.
- Translation via "*.po" files.
Title: Re: P65Pas a new 6502 Pascal compiler
Post by: Edson on September 01, 2022, 05:22:44 pm
Some work have been done in the 6502 assembler debugger included in the IDE of the compiler. Some instructions execution are fixed and the interfaz is updated.

Moreover, new directives are implemented to define Bootloader code: {$BOOTLOADER ...} and to set the format for encoding literal strings {$STRING }.
Title: Re: P65Pas a new 6502 Pascal compiler
Post by: Edson on November 07, 2022, 04:05:09 am
P65pas is updated. Version 1.0.1 is ready: https://github.com/t-edson/P65Pas

RAM initialization is improved and now there is a better support to compile for Commodore64, Commodore128, Commodore Vic20 and for Commander X16.
TinyPortal © 2005-2018