C64 Pascal source code available

In this forum you can write about anything that does not fit in other forums.
This includes generic Oric talkings and things that are totaly unrelated but want to share with people here :)
User avatar
kamelito
Flying Officer
Posts: 182
Joined: Sun Jan 08, 2006 6:34 pm
Location: Nantes, France

C64 Pascal source code available

Post by kamelito »

Hi

There's no Pascal forum so I post it here, in case there's Pascal lover who wanna port it to the Oric.
Kamel

http://kildall.apana.org.au/~cjb/G-Pascal/gpascal.a

usenet original post.
In the 1980s an Australian programmer, Nick Gammon, published a Pascal
development system for the Commodore 64 and Apple][ called G-Pascal.

In spite of it being a p-code based interpreter (based, like a lot of
others, on the BYTE Tiny Pascal from 1978), it was amazingly fast, and
it was a life-line to teenage me who was wanting to go beyond BASIC and
assembler. I even used it for writing my first-year University
programming assignments. The G-Pascal software cost $80, and was totally
worth it-- I couldn't wait to actually buy a legal copy! :)

(About two years ago I had a go at reverse-compiling the 16kB G-Pascal
program so that I could port it to other 6502 systems.. and then I got a
Life. :)

Anyway, last year, Nick Gammon was interviewed online at
<http://www.supercoders.com.au/blog/nick ... scal.shtml> (Read it!),
and he's now placed all his source code and documentation online at
http://www.gammon.com.au/GPascal/source/

His original code was developed with the Apple][ Merlin assembler (I
can't say I blame him.. writing, editing and building 180kB of source on
a C64..) which was nothing like I have available on Unix today, so I've
munged the original source into something that cc65's ca65 assembler
likes, and managed to produce a byte-perfect copy to G-Pascal v3.1

My edited assembler source is available from:

http://kildall.apana.org.au/~cjb/G-Pascal/

For those of you who don't know which is the correct end of a
executable to hold, there's a gpascal.prg available in the
above directory as well. To run it in VICE:

x64 gpascal.prg (or whatever..)
click/escape into the monitor
> 0000 37 36
goto $8000
/kml
skype pseudo : kamelitoloveless
jorodr
Flying Officer
Posts: 169
Joined: Thu Aug 09, 2007 9:04 pm
Contact:

Re: C64 Pascal source code available

Post by jorodr »

There is real Merlin assembler port to Oric. It's name is Big Mac and it works with Dos 8D OS. If someone want to port the compiler may use emul8d emulator or real 8D drive I will send for a present to work :)
I thing I could transfer the source of the compiler to 8D disc or disc-image.
JamesD
Flight Lieutenant
Posts: 358
Joined: Tue Nov 07, 2006 7:38 am

Re: C64 Pascal source code available

Post by JamesD »

Sorry to dig up an old topic but I just took a look at the assembly code for the compiler.

For the most part the compiler portion should be easy enough to port.
It appears to have two parts, a tokenizer and the compiler.
It uses the usual character in/out, line in/out type I/O which is easy enough to replace.
You would have to alter the memory map and the compiler itself supports extensions exclusive to the C64 (sprites for example).
There appears to be many ROM calls supported by the compiler which would all need to be changed or removed where they aren't relevant.
The biggest issue I see with the compiler is file I/O and someone could certainly provide the required routines for doing that.

The editor would obviously need a lot of mods for file I/O and screen differences.

Since this compiler generates P-Code instead of native assembly, it may be a bigger issue to convert the P-Code interpreter section since it deals with all the native computer calls. The core is there but you'd need to remove all the custom extensions to Pascal.
Sprites seem to be the major addition.

Technically, the separate assembly modules appear to be resident in memory at the same time so if you patch some things on one file you may be patching them for all of the files but I couldn't be sure without looking at it closer.


I haven't fully looked at the P-Code itself but if it's any indication of what to expect, just losing the parser phase on Apple by using a BASIC compiler offers about a 30% speed increase over the standard Applesoft interpreter.
Apple Pascal (aka UCSD Pascal) is also a P-Code compiler and it offers a slight improvement over compiled BASIC but not a huge amount. Pascal itself is geared towards a 16 bit CPU to begin with, but the biggest problem with Apple Pascal is the virtual machine uses a stack based processor. All variables are stored on the stack and directly operated on from there and the 6502 doesn't have stack relative addressing. You end up indexing off of page zero which is slow. Using virtual registers on page zero could make the code faster and smaller but I only see reference to two work registers which may be better or worse than Apple Pascal depending on what the source is doing and the quality of code the compiler generates. Since I don't see a peephole optimizer I'm guessing it's more for ease of interpretation than speed though. You probably need a minimum of 4 16 bit virtual registers to reduce swapping to/from the stack enough to offer a significant speed increase and 6 or 8 would be better.

From a porting standpoint, UCSD might be easier to port since it is a bit more generic and much of the environment is written in Pascal itself, making it easy to bootstrap from a UCSD compiler on another system. Later versions of UCSD have the added advantages of supporting native code modules and support for programs larger than memory. If you have more than 64K of RAM like on the Apple II, you can cache the modules that are swapped in and out from disk to make very large programs that take advantage of your extended RAM. Patches were available for Apple Pascal to support the larger RAM cards. I think that was one of the popular uses for such cards.
JamesD
Flight Lieutenant
Posts: 358
Joined: Tue Nov 07, 2006 7:38 am

Re: C64 Pascal source code available

Post by JamesD »

BTW, if I remember right, Java Bytecodes use a mix of 4 temporary variables and stack so I guess you could say it uses 4 registers of sorts.
JamesD
Flight Lieutenant
Posts: 358
Joined: Tue Nov 07, 2006 7:38 am

Re: C64 Pascal source code available

Post by JamesD »

I take back my earlier comment.
I can't find the portable source for the 6502 portion of the UCSD interpreter (yet) and the disassembly of Apple Pascal is in a less than usable state so it would probably be easier to port G-Pascal.
I also looked at the G-Pascal source a little longer and I think it would be easier to remove the C64 stuff. If the author ever finds the Apple II source it would be even easier to port since all the C64 extras would be absent.
Post Reply