t-edson / P65Pas

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

Please Add Mega65 support - 45GS02 processor #45

Open CptnRoughnight opened 1 year ago

CptnRoughnight commented 1 year ago

Hi,

love the project. Can you please add support for Mega65? It uses a 45GS02, so there are some more opcodes.

https://files.mega65.org/manuals-upload/mega65-book.pdf the processor and instruction set is described in the appendix.

greetings

t-edson commented 1 year ago

Hi. Currently I'm working in including support for the 65c02. After that I can think on including support for new CPU.

BruderJo commented 1 year ago

If you are fine with the current 6502 Opcodes only, you could start using the Mega65 with a simple unit A "hello" program was working fine :-) Copy the code as "Mega65.pas" into the unit directory and insert "uses Mega65" into your code.

{Mega65 unit    
Set P65PAS compiler to work in a Mega65 system.
Include some routines from the Kernal. 
}
{$ORG $2001}
{$BOOTLOADER $1E,$20,$0A,$00,$DE,$9C,58,$FE,$02,48,58,$9E,'COD_4A',58,$8F,32,80,54,53,80,65,83,49,48,49,$00,$00,$00}
{$STRING NULL_TERMINATED}
//Set RAM for Mega65
//{$CLEAR_STATE_RAM} If we clears, we'll need to define all RAM map
{$SET_DATA_ADDR ''}
{$SET_DATA_ADDR '00FB-00FE'}  //Some bytes from Zero page
{$SET_STATE_RAM '0100-01FF:SFR'} //Stack
unit Mega65;
interface
type 
  pointer = word;
var
  screenBorder: byte absolute 53280;  
  screenBack  : byte absolute 53281;  
  screen: [2000]byte absolute $800;
  //////////// KERNAL FUNCTIONS //////////

  //Initialize VIC; restore default input/output to keyboard/screen; clear screen; set PAL/NTSC switch and interrupt timer.
  procedure CINT;
  //Initialize CIA's, SID volume; setup memory configuration; set and start interrupt timer.
  procedure IOINIT;
  //Read byte from default input (for keyboard, read a line from the screen). (If not keyboard, must call OPEN and CHKIN beforehands.)
  procedure CHRIN: char;
  //Write byte to default output. (If not screen, must call OPEN and CHKOUT beforehands.)
  procedure CHROUT(c: char register);
  //Read byte from default input. 
  procedure GETIN: byte;

implementation
  procedure CINT;
  begin
    asm
    JSR $FF81
    end
  end; 

  procedure IOINIT;
  begin
    asm 
    JSR $FF84  
    end 
  end; 
  procedure CHRIN: char;
  begin
    asm
    JSR $FFCF  ;return char in A register
    end
  end; 

  procedure CHROUT(c: char register);
  begin
    asm 
    JSR $FFD2  ;argument already in A register
    end 
  end; 
  procedure GETIN: byte;
  {Read byte from default input. (If not keyboard, must call OPEN and CHKIN beforehands.)
  Input: <none>
  Output: A = Byte read.}
  begin
    asm 
          JSR $FFE4
    end 
  end; 

end.