Recent

Author Topic: P65Pas a new 6502 Pascal compiler  (Read 12854 times)

Edson

  • Hero Member
  • *****
  • Posts: 1301
P65Pas a new 6502 Pascal compiler
« 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.
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1260
Re: P65Pas a new 6502 Pascal compiler
« Reply #1 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 :-)
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

hansotten

  • Jr. Member
  • **
  • Posts: 88
Re: P65Pas a new 6502 Pascal compiler
« Reply #2 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!

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: P65Pas a new 6502 Pascal compiler
« Reply #3 on: September 01, 2018, 08:44:13 pm »
Maybe if you define some zeropage pairs as parameter and some as volatile registers.

Edson

  • Hero Member
  • *****
  • Posts: 1301
Re: P65Pas a new 6502 Pascal compiler
« Reply #4 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:
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

Edson

  • Hero Member
  • *****
  • Posts: 1301
Re: P65Pas a new 6502 Pascal compiler
« Reply #5 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.
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

Edson

  • Hero Member
  • *****
  • Posts: 1301
Re: P65Pas a new 6502 Pascal compiler
« Reply #6 on: June 27, 2019, 08:12:07 pm »
P65Pas 0.6 more complete, more powerfull. Now support for arrays and register parameters:

Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

Edson

  • Hero Member
  • *****
  • Posts: 1301
Re: P65Pas a new 6502 Pascal compiler
« Reply #7 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
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

tr_escape

  • Sr. Member
  • ****
  • Posts: 432
  • sector name toys | respect to spectre
    • Github:
Re: P65Pas a new 6502 Pascal compiler
« Reply #8 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 ?

Edson

  • Hero Member
  • *****
  • Posts: 1301
Re: P65Pas a new 6502 Pascal compiler
« Reply #9 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.
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: P65Pas a new 6502 Pascal compiler
« Reply #10 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.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Edson

  • Hero Member
  • *****
  • Posts: 1301
Re: P65Pas a new 6502 Pascal compiler
« Reply #11 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.
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

Squall_FF8

  • Newbie
  • Posts: 3
Re: P65Pas a new 6502 Pascal compiler
« Reply #12 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
« Last Edit: October 30, 2019, 03:20:38 pm by Squall_FF8 »

Edson

  • Hero Member
  • *****
  • Posts: 1301
Re: P65Pas a new 6502 Pascal compiler
« Reply #13 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.
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

sstvmaster

  • Sr. Member
  • ****
  • Posts: 299
Re: P65Pas a new 6502 Pascal compiler
« Reply #14 on: October 30, 2019, 08:08:23 pm »
greetings Maik

Windows 10,
- Lazarus 2.2.6 (stable) + fpc 3.2.2 (stable)
- Lazarus 2.2.7 (fixes) + fpc 3.3.1 (main/trunk)

 

TinyPortal © 2005-2018