Skip to content

Commit

Permalink
Initial support for a PET target (#109)
Browse files Browse the repository at this point in the history
* Initial support for a PET target

* Created user-definable symbol for RAM size to add support for 8k and 16k PETs

* Added variables to the commodore linker file to be defined in the concrete targets specifying the start and end of the free zero page

* Pushed zero page flag in clang.cfg down from commodore into concrete targets as all targets no longer share the same amount of free zero page

* Added mention of PET support to README
  • Loading branch information
williamw4096 authored Apr 2, 2023
1 parent 857294f commit adafbc0
Show file tree
Hide file tree
Showing 15 changed files with 105 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The LLVM-MOS compiler toolchain and platform libraries.
- 8-KiB or 16-KiB standard cartridge
- Commander X16
- Commodore 64
- Commodore PET
- MEGA65
- NES
- NES-NROM
Expand Down Expand Up @@ -119,6 +120,7 @@ executables and libraries for that target.
| Atari 8-bit Standard cartridge | `mos-atari8-stdcart` |
| Commander X16 | `mos-cx16-clang` |
| Commodore 64 | `mos-c64-clang` |
| Commodore PET | `mos-pet-clang` |
| MEGA65 | `mos-mega65-clang` |
| NES-CNROM | `mos-nes-cnrom-clang` |
| NES-MMC1 | `mos-nes-mmc1-clang` |
Expand Down
1 change: 1 addition & 0 deletions mos-platform/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ add_subdirectory(nes-mmc1)
add_subdirectory(nes-mmc3)
add_subdirectory(osi-c1p)
add_subdirectory(dodo)
add_subdirectory(pet)
1 change: 1 addition & 0 deletions mos-platform/c64/clang.cfg
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
-mlto-zp=110
-D__C64__
3 changes: 3 additions & 0 deletions mos-platform/c64/link.ld
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
* Produces a PRG file with a SYS command to start the program.
*/

__basic_zp_start = 0x0002;
__basic_zp_end = 0x0090;

MEMORY {
ram (rw) : ORIGIN = 0x0801, LENGTH = 0xC7FF
}
Expand Down
1 change: 0 additions & 1 deletion mos-platform/commodore/clang.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
-mlto-zp=110
-D__CBM__
6 changes: 3 additions & 3 deletions mos-platform/commodore/commodore.ld
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
*/

/* Provide imaginary (zero page) registers in the BASIC area. */
__rc0 = 0x0002;
__rc0 = __basic_zp_start;
INCLUDE imag-regs.ld
ASSERT(__rc31 == 0x0021, "Inconsistent zero page map.")
ASSERT(__rc31 == (__rc0 + 0x1F), "Inconsistent zero page map.")

MEMORY { zp : ORIGIN = __rc31 + 1, LENGTH = 0x90 - (__rc31 + 1) }
MEMORY { zp : ORIGIN = __rc31 + 1, LENGTH = __basic_zp_end - (__rc31 + 1) }

INPUT(basic-header.o)

Expand Down
1 change: 1 addition & 0 deletions mos-platform/cx16/clang.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
-mlto-zp=110
-D__CX16__
-mcpu=mos65c02
3 changes: 3 additions & 0 deletions mos-platform/cx16/link.ld
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
* Produces a PRG file with a SYS command to start the program.
*/

__basic_zp_start = 0x0002;
__basic_zp_end = 0x0090;

MEMORY {
ram (rw) : ORIGIN = 0x0801, LENGTH = 0x96ff
}
Expand Down
1 change: 1 addition & 0 deletions mos-platform/mega65/clang.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
-mlto-zp=110
-D__MEGA65__
-mcpu=mos65ce02
3 changes: 3 additions & 0 deletions mos-platform/mega65/link.ld
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* Produces a PRG file with a SYS command to start the program.
*/

__basic_zp_start = 0x0002;
__basic_zp_end = 0x0090;

MEMORY {
/*
* Allocate in $2001 - $7fff (bank 0)
Expand Down
12 changes: 12 additions & 0 deletions mos-platform/pet/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
platform(pet COMPLETE HOSTED PARENT commodore)

if(NOT CMAKE_CROSSCOMPILING)
return()
endif()

install(FILES link.ld TYPE LIB)

add_platform_object_file(pet-basic-header basic-header.o basic-header.S)

add_platform_library(pet-c kernal.S)
target_include_directories(pet-c BEFORE PUBLIC .)
13 changes: 13 additions & 0 deletions mos-platform/pet/basic-header.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
; PET BASIC header that jumps to _start

.section .basic_header,"aR",@progbits
.short next_line ; address of next BASIC line
.short 7773 ; line number: l33t for LLVM, a hint that this program was
; compiled with LLVM
.byte 0x9e ; SYS keyword BASIC token
.mos_addr_asciz _start, 4 ; the location of the _start symbol, in 4 decimal
; ASCII digits
next_line:
.short 0 ; end of basic program


2 changes: 2 additions & 0 deletions mos-platform/pet/clang.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-mlto-zp=107
-D__PET__
32 changes: 32 additions & 0 deletions mos-platform/pet/kernal.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
; Copyright 2022 LLVM-MOS Project
; Licensed under the Apache License, Version 2.0 with LLVM Exceptions,
; See https://github.com/llvm-mos/llvm-mos-sdk/blob/main/LICENSE for license
; information.

; Originally from cc65. Modified from original version.

;
; Ullrich von Bassewitz, 19.11.2002
;
; PET Kernal functions
;

#define __PET__ 1
#include <cbm_kernal.inc>

.macro weakdef name:req
.weak \name
__\name = \name
.global __\name
.endm

weakdef CLRCH
weakdef BASIN
weakdef CHRIN
weakdef STOP
weakdef GETIN
weakdef CLALL
weakdef UDTIM
weakdef CHROUT
weakdef BSOUT
weakdef CHRIN
28 changes: 28 additions & 0 deletions mos-platform/pet/link.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* Commodore PET PRG file linker script.
*
* Produces a PRG file with a SYS command to start the program.
*/

PROVIDE(__ram_size = 32);
ASSERT(__ram_size <= 32,
"RAM size must be <= 32 (8x96 and SuperPETs are not supported by this target)")
ASSERT(__ram_size >= 8,
"RAM size must be at least 8")

__basic_zp_start = 0x0002;
__basic_zp_end = 0x008D;

MEMORY {
ram (rw) : ORIGIN = 0x0401, LENGTH = (__ram_size * 1024) - 0x0401
}

INCLUDE commodore.ld

/* Grow stack downwards from end of RAM */
__stack = (__ram_size * 1024) - 1;

OUTPUT_FORMAT {
/* Tells the PET LOAD command where to place the file's contents. */
SHORT(0x0401)
TRIM(ram)
}

0 comments on commit adafbc0

Please sign in to comment.