Skip to content

Commit

Permalink
add atari8-stdcart target (#92)
Browse files Browse the repository at this point in the history
* add atari8-stdcart target

* cleanup/fix atari8-stdcart target

* atari8-stdcart typo

* atari8-stdcart fix crt0 and .*data copies

* atari8-stdcart avoid duplicate symbols, expose _cart_init

tweak to avoid duplicate symbols (tested with --whole-archive)

allow override of _cart_init; this won't be used most of the time but
is useful in cases where you want to taint memory in order to test
that the data copy functions are working

* reference copy-data.c from mos-common
  • Loading branch information
cwedgwood authored Dec 10, 2022
1 parent f795a2f commit 02514bf
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 0 deletions.
1 change: 1 addition & 0 deletions mos-platform/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ endif()

add_subdirectory(common)
add_subdirectory(atari8)
add_subdirectory(atari8-stdcart)
add_subdirectory(commodore)
add_subdirectory(c64)
add_subdirectory(cpm65)
Expand Down
16 changes: 16 additions & 0 deletions mos-platform/atari8-stdcart/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
20 changes: 20 additions & 0 deletions mos-platform/atari8-stdcart/cart-rom-fixed.ld
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 8 additions & 0 deletions mos-platform/atari8-stdcart/link.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* Atari800 cartridge linker scripts. */

INCLUDE stdcart.ld
INCLUDE cart-rom-fixed.ld

OUTPUT_FORMAT {
FULL(cart_rom)
}
41 changes: 41 additions & 0 deletions mos-platform/atari8-stdcart/stdcart.ld
Original file line number Diff line number Diff line change
@@ -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
}
10 changes: 10 additions & 0 deletions mos-platform/atari8-stdcart/syms.s
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 02514bf

Please sign in to comment.