Hey all,
Just for fun, I am attempting to make a 'compiler' (called Pas2C64) that will compile a simple Pascal-like language into C64 (6510 processor) assembly instructions.
The assembly instructions will assembled by Win2C64, a windows cross-assembler that creates T64 (tape format) programs that can be run by a C64 emulator. There are Linux/Mac versions too apparently on request...
I knew that there were a bunch of cross compilers (like cc65, a 6502 C compiler) that generate C64 programs using a C/C++ language, but I wanted good old Pascal damn-it! LOL
I have started creating a TCodeGenerator_C64 class which I have been directly testing (no Pascal -> ML yet..):
Input:
Code:
cg.WriteMainProgramStart(49152);
cg.WriteComment('Copy the background color to the border');
cg.LoadReg_Mem(regA,$D021);
cg.StoreReg(regA,$D020);
cg.OpCode(opRTS);
Output:
Code:
.org $C000
main
;Copy the background color to the border
LDA $D021
STA $D020
RTS
I can then assemble the code using Win2C64, and run it on the WinVICE C64 emulator doing this:
To save time for myself (or others), I can also add in a Basic loader at the beginning of the code by doing this:
Code:
cg.WriteBasicLoader;
cg.WriteMainProgramStart;
cg.WriteComment('Copy the background color to the border');
cg.LoadReg_Mem(regA,$D021);
cg.StoreReg(regA,$D020);
cg.OpCode(opRTS);
which produces this:
Code:
.org $0800 ; start at BASIC
.byte $00 $0c $08 $0a $00 $9e $20 $32 ; encode SYS 2064
.byte $30 $36 $34 $00 $00 $00 $00 $00 ; as BASIC line
Lab2064
JMP main
;Copy the background color to the border
LDA $D021
STA $D020
RTS
This means that when the program loads in WinVICE, it automatically runs due to the line of basic code that does the system call to the machine code program
This should be an interesting little diversion for me LOL
cheers,
Paul
Bookmarks