t-edson / P65Pas

CPU 6502 Pascal Compiler/IDE/Debugger
GNU General Public License v3.0
125 stars 27 forks source link

Help compiling for Commodore 128 #21

Closed odflor closed 2 years ago

odflor commented 4 years ago

Hi: I try this program and work very fine on C64 emulator:

{Change the back color of a Commodore 64 screen} {$ORG $0801} {$COMMODORE64} //Commodore 64 mode program C64ChamgeBack; var screenBorder: byte absolute 53280;
screenBack : byte absolute 53281;
screen: [1000] byte absolute $400; color : [1000] byte absolute 55296; i : word; begin while true do begin inc(screenBorder); inc(screenBack);

for i := 0 to 999 do
  screen[i] := screenBorder;
  color[i] := screenBorder;
end;

delay_ms(256);

end; end;

end.

But when I want to run con C128 emulator this don't work.

I change the lines:

{Change the back color of a Commodore 64 screen} //{$ORG $0801} {$ORG $1C01} //{$COMMODORE64} //Commodore 64 mode

But still don't work.

There is basic routine that start the machine language program, ¿that may be change for c128?

odflor commented 4 years ago

I find that to support c128 I must modify the compiler itself.

In the file Compiler_PIC16.pas there is:

if Commodore64 then begin //En modo Commodore 64 if pic.iRam = $801 then begin //Se pide compilar en el espacio de memoria del BASIC PutTopComm(' ;BASIC starter code: 10 SYS 2062'); pic.codByte($0C, true); //Dirección de siguiente línea pic.codByte($08, true); pic.codByte($0A, true); //Número de línea pic.codByte($00, true); pic.codByte($9e, true); //Token de instrucción SYS pic.codByte($20, true); //Espacio pic.codByte($32, true); //2 pic.codByte($30, true); //0 pic.codByte($36, true); //6 pic.codByte($32, true); //2 pic.codByte($00, true); //Fin de instrucción pic.codByte($00, true); //Sgte línea BASIC pic.codByte($00, true); //Sgte línea BASIC end; end;

That's is the basic ML loader. It need to change the default address to $1C01 and check the basic tokens to adjust to C128 basic 7

t-edson commented 4 years ago

Yes. There is a loader code: 10 SYS 2062 in Commodore64 mode. It was designed to be temporal, until support for units will be more complete, and can include INITIALIZATION section. The idea is to remove this section in the future. You can include, directly, your own loader code in the compiler for the C128. Initially, the compiler just compile the program at some location ( like $1000). And then, after loaded the code, you had to type SYS 4096 to run the program, in the Commodore 64. Maybe you can do some similar (not using Commodore64 mode) in the Commodore 128.

odflor commented 4 years ago

I don't understand that you propose to me.

Something like that?

program testc128p {$ORG $1C01} uses c128; begin asm < asm code for "SYS DEC("1C01")" > end; < next of the program > end.

Or do do mean that I need to do my fork of the p65pas compiler to support c128 mode?

t-edson commented 4 years ago

I propose two options:

  1. Do your fork of P65pas (or submit patchs).
  2. Do something like:
    program testc128p
    {$ORG $1C01}
    uses c128;
    begin
    < your program >
    end.

    Then Run your program with the command: SYS ?????

odflor commented 4 years ago

I made it! thanks to you help!

The only thing is that to run the program con c128 mode must be loaded from disk using BOOT command or dload"< program file>" then "SYS ORG address". Or make a "basic loader" program apart.

The basic loader can have: 10 scnclr:print "booting program file..." 20 boot "program file"

I will wait for the initialize section of the units to be available to insert the correct "basic loader" bytes onto the compiled program. Just as Commodore64 will do.

In the meantime, now that i can run programs on c128 mode, i will be construct my own Commodore128 unit to add to the p65pas project.

mvdhoning commented 3 years ago

I made #29 and now read this. Having a seperate {$BASIC} directive could solve this. It should obay the ORG that is in 'front' of it or use a parameter refering to a start label or function.

t-edson commented 2 years ago

Hi. New version of the compiler can generate a BASIC header for the C128. There is a unit called Commodore128.pas in the /units directory you can use to generate code in a similar way to the C64. You can write a Hello World like this:

uses Commodore128;
begin
  CHROUT('H');
  CHROUT('E');
  CHROUT('L');
  CHROUT('L');
  CHROUT('O');
  asm rts end;
end.

Tested in VICE: image