diff --git a/mos-platform/CMakeLists.txt b/mos-platform/CMakeLists.txt index 3cdf6fcc8..a76208ecf 100644 --- a/mos-platform/CMakeLists.txt +++ b/mos-platform/CMakeLists.txt @@ -46,6 +46,7 @@ endif() add_subdirectory(common) add_subdirectory(atari8) +add_subdirectory(atari8-stdcart) add_subdirectory(commodore) add_subdirectory(c64) add_subdirectory(cpm65) diff --git a/mos-platform/atari8-stdcart/CMakeLists.txt b/mos-platform/atari8-stdcart/CMakeLists.txt new file mode 100644 index 000000000..5f508e7ab --- /dev/null +++ b/mos-platform/atari8-stdcart/CMakeLists.txt @@ -0,0 +1,16 @@ +# TODO; refactor atari8, remove copy-data.c +platform(atari8-stdcart COMPLETE PARENT atari8) + +if(NOT CMAKE_CROSSCOMPILING) + return() +endif() + +install(FILES + cart-rom-fixed.ld + link.ld + stdcart.ld +TYPE LIB) + +# ../common/crt0/copy-data; see above +add_platform_library(atari8-stdcart-crt0 syms.s ../common/crt0/copy-data.c) +target_compile_options(atari8-stdcart-crt0 PRIVATE -fno-lto) diff --git a/mos-platform/atari8-stdcart/cart-rom-fixed.ld b/mos-platform/atari8-stdcart/cart-rom-fixed.ld new file mode 100644 index 000000000..c62e0d8b6 --- /dev/null +++ b/mos-platform/atari8-stdcart/cart-rom-fixed.ld @@ -0,0 +1,20 @@ +ASSERT(__cart_rom_size == 8 || __cart_rom_size == 16, + "ATARI 800 STDCART: Only 8 KiB and 16 KiB ROM supported") + +MEMORY { + cart_rom_vma (rx) : ORIGIN = __cart_rom_size == 16 ? 0x8000 : 0xA000, + LENGTH = __cart_rom_size * 1024 +} + +REGION_ALIAS("c_rom_vma", cart_rom_vma) +REGION_ALIAS("c_rom_lma", cart_rom) + +SECTIONS { + .cart_rom_fixed : { *(.cart_rom_fixed .cart_rom_fixed.*) } >cart_rom + .vector 0xbffa - ORIGIN(cart_rom_vma) + ORIGIN(cart_rom) : { + SHORT(_start) /* START entrypoint (after OS setup) */ + BYTE(0x0) /* "Inserted" */ + BYTE(0x04) /* Bits: 7=diag, 2=start, 0=Enable_DOS */ + SHORT(_cart_init) /* INIT entrpoint (before OS setup) */ + } >cart_rom +} diff --git a/mos-platform/atari8-stdcart/link.ld b/mos-platform/atari8-stdcart/link.ld new file mode 100644 index 000000000..2f6886ac3 --- /dev/null +++ b/mos-platform/atari8-stdcart/link.ld @@ -0,0 +1,8 @@ +/* Atari800 cartridge linker scripts. */ + +INCLUDE stdcart.ld +INCLUDE cart-rom-fixed.ld + +OUTPUT_FORMAT { + FULL(cart_rom) +} diff --git a/mos-platform/atari8-stdcart/stdcart.ld b/mos-platform/atari8-stdcart/stdcart.ld new file mode 100644 index 000000000..32be0b49e --- /dev/null +++ b/mos-platform/atari8-stdcart/stdcart.ld @@ -0,0 +1,41 @@ +/* Provide imaginary (zero page) registers. */ +__rc0 = 0x80; +INCLUDE imag-regs.ld +ASSERT(__rc31 == 0x9f, "Inconsistent zero page map.") + +ASSERT(__cart_rom_size == 1 << LOG2CEIL(__cart_rom_size), + "ATARI 800 STDCART: ROM size must be a power of 2.") + +MEMORY { + zp : ORIGIN = __rc31 + 1, LENGTH = 0x100 - (__rc31 + 1) + + /* 0x700 works w/o DOS. */ + ram : ORIGIN = 0x700, LENGTH = 0x2000 - 0x700 + + /* CART-ROM LMA. */ + cart_rom : ORIGIN = 0x01000000, LENGTH = __cart_rom_size * 1024 +} + +SECTIONS { + .text : { + INCLUDE text-sections.ld + } >c_rom_vma AT>c_rom_lma + .rodata : { INCLUDE rodata-sections.ld } >c_rom_vma AT>c_rom_lma + .data : { INCLUDE data-sections.ld } >ram AT>c_rom_lma + __data_load_start = LOADADDR(.data) - LOADADDR(.rodata) + ADDR(.rodata); + __data_size = SIZEOF(.data); + .zp.data : { INCLUDE zp-data-sections.ld } >zp AT>c_rom_lma + __zp_data_load_start = LOADADDR(.zp.data) - LOADADDR(.rodata) + ADDR(.rodata); + __zp_data_size = SIZEOF(.zp.data); + /* The data initializers take up space at the C_ROM_VMA too, not just in RAM. */ + .data_initializers ADDR(.rodata) + SIZEOF(.rodata) + __data_size + + __zp_data_size : {} >c_rom_vma + .zp.bss (NOLOAD) : { + INCLUDE zp-bss-sections.ld + } >zp + INCLUDE zp-bss-symbols.ld + INCLUDE zp-noinit.ld + .bss (NOLOAD) : { INCLUDE bss-sections.ld } >ram AT>ram + INCLUDE bss-symbols.ld + .noinit (NOLOAD) : { INCLUDE noinit-sections.ld } >ram AT>ram +} diff --git a/mos-platform/atari8-stdcart/syms.s b/mos-platform/atari8-stdcart/syms.s new file mode 100644 index 000000000..3a387c3eb --- /dev/null +++ b/mos-platform/atari8-stdcart/syms.s @@ -0,0 +1,10 @@ +; defaults + +; ROM size, only 8 and 16 KiB are supported +.weak __cart_rom_size +__cart_rom_size = 8 + +; INIT typically isn't used but allow override +.weak _cart_init +_cart_init: + rts