Lazarus

Free Pascal => FPC development => Topic started by: kveroneau on January 03, 2018, 07:56:18 pm

Title: Possible to create a 6502/65c02 target for FreePascal
Post by: kveroneau on January 03, 2018, 07:56:18 pm
I am working on various 65c02 projects, and would like to know how easy it would be to create a new target for FreePascal to compile programs to generate 6502 binary code with custom load addresses?  I have been recently using the rather useful cc65.org project, which is basically a set of binutils and a C compiler to target the 6502 family of processors.  I am looking through the FreePascal source tree to better understand how the RTL works, and I do see assemble language code in various units.  Is creating a new target as simple as updating these assembly instructions to 65c02 assembly, and having it use the ca65 assembler and ld65 linker to build the RTL units?

I found and read the following wiki pages, but they aren't as helpful as I would otherwise prefer them to be:
http://wiki.freepascal.org/Porting_Free_Pascal
http://wiki.freepascal.org/System_unit_structure
http://wiki.freepascal.org/Porting_Free_Pascal_Example

To be clear, I'm not interested in porting the compiler, but just allowing FPC to build 6502 compatible binary files.  I was able to easily update cc65 to build binaries for custom targets using custom memory maps and load addresses.  I was hoping it might be just as easy to update FPC to perform a similar feat.

cc65 (6502 binutils): http://www.cc65.org/

Is there a document perhaps that explains the actual compile/build process of a Pascal program to machine code and what exactly is involved?  Could FPC say output 6502 assembly code, which can then be used with ca65 to generate my desired binary image?

Any assistance on this matter would be most grateful.
Title: Re: Possible to create a 6502/65c02 target for FreePascal
Post by: marcov on January 03, 2018, 08:00:46 pm
No, it is not as simple as simply upgrading the RTL to use 6502/10 assembler.

The main thing is actually writing a 6502 codegenerator, which is quite involved.
Title: Re: Possible to create a 6502/65c02 target for FreePascal
Post by: tr_escape on January 03, 2018, 08:41:18 pm
Maybe you and "t-edson" can work together :

http://forum.lazarus.freepascal.org/index.php/topic,36595.0.html

But how many cpu 6502 are there in the market? I just wondered.
Title: Re: Possible to create a 6502/65c02 target for FreePascal
Post by: kveroneau on January 03, 2018, 09:15:05 pm
Maybe you and "t-edson" can work together :

http://forum.lazarus.freepascal.org/index.php/topic,36595.0.html
Thank you, I will look into this as a potential option.

But how many cpu 6502 are there in the market? I just wondered.
The 6502 is sometimes used as an alternative chip in embedded systems, an alternative to an AVR, ATmega, ARM, and embeeded Intel chips.

Considering there is a working C compiler, and a dedicated active forum for the 6502: http://6502.org/  I believe it has a fairly sized userbase.  WDC still produces the chips and sells them:  http://www.westerndesigncenter.com/wdc/

Pascal was one of the languages also supported on the original Apple 2, which also ran the 6502.  It would be really nice if FPC could for example, compile these old Pascal programs and either target modern machines, or even the original Apple 2 hardware.  FPC does preserve the dialect from the TurboPascal days, and old DOS TP7 programs can be ported to modern systems as a result.
Title: Re: Possible to create a 6502/65c02 target for FreePascal
Post by: Blaazen on January 03, 2018, 09:28:59 pm
Are you planning to develop for revival of never released Commodore 65, http://mega65.org/ (http://mega65.org/)?  :)
Title: Re: Possible to create a 6502/65c02 target for FreePascal
Post by: korba812 on January 03, 2018, 09:50:45 pm
There is pascal compiler for atari 8bit thats even support objects. It is written in Delphi and can be compiled in FreePascal but is not based on it (based on XD-Pascal)
http://mads.atari8.info/madpascal.html (http://mads.atari8.info/madpascal.html) (unfortunately in polish)
Title: Re: Possible to create a 6502/65c02 target for FreePascal
Post by: kveroneau on January 03, 2018, 09:51:40 pm
Are you planning to develop for revival of never released Commodore 65, http://mega65.org/ (http://mega65.org/)?  :)

No, but something a bit similar I guess...  I am the creator and main developer of Hacker's Edge (http://www.hackers-edge.com/), a multiplayer online hacking simulation game.  The game uses a 65c02 Virtual Machine/Emulator to run all the virtual in-game computer systems, and most of the game is going to need to be programmed in 65c02.  So far I wrote a pretty primitive operating system in 65c02 Assembly using the ca65 assembler, and cc65 is also able to target my in-game virtual machines.  However, I very much prefer the Pascal language over the C language, which is why I was asking about how easy it can be to port FPC to target the 6502 with a custom memory map and program load addresses.  Getting cc65 to work was very easy, as it has a fully working clib made in 6502 assembly, I only needed to update the crt0.s(C startup code), and a couple machine specific function calls like standard input/output, and it was able to compile code.  However, I do understand that the FPC compiler isn't aware of 6502 whatsoever.  I do see that AVR is supported, so it doesn't sound impossible to do, if an AVR target is possible, then I don't see why a 6502 target shouldn't be.

Another interesting advantage of supporting 6502 is being able to target even more Nintendo consoles. :)  I see Wii, NDS, and GBA are all supported targets.  However, Nintendo's most iconic system, the Nintendo Entertainment System is absent as a FPC target.  Adding 6502 code generation support will invite the NES along for the FreePascal ride as well.  Although GBA/NDS are subsets of ARM, and Wii is a subset of the PPC targets...  FreePascal could be the go-to language for targetting every single Nintendo platform.
Title: Re: Possible to create a 6502/65c02 target for FreePascal
Post by: tr_escape on January 07, 2018, 12:30:51 pm
Actually it would be good for nostalgia but VICE project is my advice.
Because it is still developing I downloaded whole project and recompiled in Linux Mint 32bit (It can be take some time becuase of packages needs).

And my memories lived again I missed my broken commodore.

However, VICE is a good project but written in c, c++ maybe you can start this project.

I wish you my best luck.
Title: Re: Possible to create a 6502/65c02 target for FreePascal
Post by: Blaazen on January 07, 2018, 12:38:51 pm
Screenshot is really pretty. It emulates the fuzzy look of old CRT televisions perfectly.
Title: Re: Possible to create a 6502/65c02 target for FreePascal
Post by: engkin on January 07, 2018, 04:39:57 pm
There is pascal compiler for atari 8bit thats even support objects. It is written in Delphi and can be compiled in FreePascal but is not based on it (based on XD-Pascal)
http://mads.atari8.info/madpascal.html (http://mads.atari8.info/madpascal.html) (unfortunately in polish)

Thanks for pointing this one out.

Here is the English page (http://mads.atari8.info/mads_eng.html) which states:
Quote
With the free compiler Free Pascal Compiler, it is possible to compile MADS for other platforms

It also includes instructions for using FPC. The source code link is at the top of this page (http://mads.atari8.info/).
Title: Re: Possible to create a 6502/65c02 target for FreePascal
Post by: Edson on August 12, 2018, 07:15:27 am
I'm writing a version of my compiler PicPas to support CPU 6502.

Just some basic functions supported: https://github.com/t-edson/P65Pas
TinyPortal © 2005-2018