Skip to content

Commit d5b5007

Browse files
committed
Initial commit
0 parents  commit d5b5007

File tree

8 files changed

+272
-0
lines changed

8 files changed

+272
-0
lines changed

.github/workflows/build.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
16+
- name: Install Nix
17+
uses: cachix/install-nix-action@v31
18+
with:
19+
nix_path: nixpkgs=channel:nixos-unstable
20+
21+
- name: Build inside nix-shell
22+
run: nix-shell --run './build.sh'

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build/

.vscode/settings.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"cmake.generator": "Ninja",
3+
"cmake.showSystemKits": false,
4+
"cmake.useCMakePresets": "never",
5+
"cmake.buildDirectory": "${workspaceFolder}/build",
6+
"cmake.configureArgs": [
7+
"-DCMAKE_TOOLCHAIN_FILE=cc65-toolchain.cmake"
8+
],
9+
}

CMakeLists.txt

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
3+
project(xex_boot ASM)
4+
5+
set(app_name ${CMAKE_PROJECT_NAME})
6+
7+
add_executable(${app_name} boot.s)
8+
9+
set_target_properties(${app_name} PROPERTIES SUFFIX ".sys")
10+
11+
target_link_options(${app_name} PRIVATE -C atari-cassette.cfg)
12+
target_link_options(${app_name} PRIVATE --start-addr 0x0700)
13+
target_link_options(${app_name} PRIVATE -m ${app_name}.map)
14+
15+
set_property(TARGET ${app_name} APPEND PROPERTY ADDITIONAL_CLEAN_FILES ${app_name}.map)
16+
17+
# Post-build step: convert .sys file to .c array using xxd -i
18+
add_custom_command(
19+
TARGET ${app_name}
20+
POST_BUILD
21+
COMMAND ${CMAKE_COMMAND} -E echo "// Automatically generated file" > ${app_name}.c
22+
COMMAND ${CMAKE_COMMAND} -E echo "// clang-format off" >> ${app_name}.c
23+
COMMAND ${CMAKE_COMMAND} -E echo "" >> ${app_name}.c
24+
COMMAND xxd -i ${app_name}.sys >> ${app_name}.c
25+
COMMENT "Generating C array from ${app_name}.sys"
26+
)
27+
28+
# Post-build step: copy generated .c file to the parent directory
29+
30+
add_custom_command(
31+
TARGET ${app_name}
32+
POST_BUILD
33+
COMMAND ${CMAKE_COMMAND} -E copy ${app_name}.c ../../${app_name}.c
34+
COMMENT "Copying generated C array to parent directory"
35+
)

boot.s

+149
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
2+
.include "atari.inc"
3+
4+
.macpack generic
5+
.macpack longbranch
6+
7+
CHUNK_SIZE = 1024
8+
HEADER_SIZE = 4
9+
10+
; ========================================================================
11+
.zeropage
12+
13+
blk_addr: .word 0
14+
blk_size: .word 0
15+
16+
17+
; ========================================================================
18+
.segment "CASHDR"
19+
20+
.export _cas_hdr
21+
22+
_cas_hdr: .byte 0
23+
.byte ((end - start) + 6 + 127) / 128
24+
.word _cas_hdr
25+
.word init
26+
27+
; ========================================================================
28+
.code
29+
30+
start:
31+
clc ; success
32+
rts
33+
34+
error:
35+
lda #37
36+
sta 40000
37+
jmp error
38+
39+
init:
40+
lda #$31 ; set device D1:
41+
sta DDEVIC
42+
lda #1
43+
sta DUNIT
44+
lda #5
45+
sta DTIMLO
46+
47+
lda #$00 ; initialize block index
48+
sta DAUX1
49+
50+
read_block:
51+
lda #$00 ; initialize chunk index
52+
sta DAUX2
53+
54+
lda #$F0 ; set command <- 0xF0
55+
sta DCOMND
56+
57+
lda #<blk_addr ; set block header address
58+
sta DBUFLO
59+
lda #>blk_addr
60+
sta DBUFHI
61+
62+
lda #<HEADER_SIZE ; set buffer size
63+
sta DBYTLO
64+
lda #>HEADER_SIZE
65+
sta DBYTHI
66+
67+
lda #$40 ; set direction to read
68+
sta DSTATS
69+
70+
jsr SIOV ; receive a header
71+
jmi error
72+
73+
lda #<start ; set INITAD to do nothing
74+
sta INITAD
75+
lda #>start
76+
sta INITAD + 1
77+
lda #<start ; set INITAD to do nothing
78+
sta RUNAD
79+
lda #>start
80+
sta RUNAD + 1
81+
82+
83+
read_chunk:
84+
lda #<CHUNK_SIZE ; calculate chunk size
85+
sta DBYTLO
86+
sub blk_size
87+
lda #>CHUNK_SIZE
88+
sta DBYTHI
89+
sbc blk_size + 1
90+
91+
bcc copy_full ; full sized chunk?
92+
93+
lda blk_size ; just few bytes left
94+
sta DBYTLO
95+
lda blk_size + 1
96+
sta DBYTHI
97+
98+
copy_full:
99+
lda #$F1 ; set command <- 0xF1
100+
sta DCOMND
101+
lda blk_addr ; set buffer address
102+
sta DBUFLO
103+
lda blk_addr + 1
104+
sta DBUFHI
105+
lda #$40 ; set direction to read
106+
sta DSTATS
107+
108+
jsr SIOV ; receive a chunk of data
109+
jmi error
110+
111+
inc DAUX2 ; increment chunk index
112+
113+
lda blk_addr ; advance block address
114+
add DBYTLO
115+
sta blk_addr
116+
lda blk_addr + 1
117+
adc DBYTHI
118+
sta blk_addr + 1
119+
120+
lda blk_size ; adjust remaining block size
121+
sub DBYTLO
122+
sta blk_size
123+
lda blk_size + 1
124+
sbc DBYTHI
125+
sta blk_size + 1
126+
127+
cmp #0
128+
jne read_chunk ; read next chunk if not done
129+
lda blk_size
130+
cmp #0
131+
jne read_chunk
132+
133+
jsr init_block
134+
jsr run_block
135+
136+
inc DAUX1 ; increment block index
137+
138+
jmp read_block ; read next block
139+
140+
init_block:
141+
jmp (INITAD)
142+
143+
run_block:
144+
jmp (RUNAD)
145+
146+
rts_addr:
147+
rts
148+
149+
end:

build.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cmake -G Ninja -DCMAKE_TOOLCHAIN_FILE=cc65-toolchain.cmake -B build
2+
cd build
3+
cmake --build .

cc65-toolchain.cmake

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# https://github.com/fo-fo/cc65-toolchain-example
2+
3+
# CMake toolchain file for cc65
4+
# This is largely a result of experimentation, so some things may be done
5+
# suboptimally/wrong. Some compilation options/CMake features may not work.
6+
# Some generators will also not work (like MSVS). Ninja has been tested to work.
7+
# What is supported: C, assembly, static libraries
8+
9+
set( CMAKE_SYSTEM_NAME Generic )
10+
11+
macro( __compilerCc65 lang )
12+
set( CMAKE_${lang}_COMPILER cl65 CACHE PATH "${lang} compiler" )
13+
set( CMAKE_${lang}_COMPILER_ID cc65 )
14+
15+
# We cannot run tests for the cc65 compiler, because of cross-compilation,
16+
# so force the compiler tests to passed.
17+
set( CMAKE_${lang}_COMPILER_ID_RUN TRUE )
18+
# Don't know if these are necessary.
19+
set( CMAKE_${lang}_COMPILER_ID_WORKS TRUE )
20+
set( CMAKE_${lang}_COMPILER_ID_FORCED TRUE )
21+
22+
set( CMAKE_DEPFILE_FLAGS_${lang} "--create-dep <DEPFILE>")
23+
set( CMAKE_${lang}_VERBOSE_FLAG "-v" )
24+
set( CMAKE_${lang}_FLAGS_DEBUG_INIT "-g -D DEBUG --asm-define DEBUG" )
25+
endmacro()
26+
27+
__compilerCc65( C )
28+
__compilerCc65( ASM )
29+
30+
set( CMAKE_ASM_SOURCE_FILE_EXTENSIONS s;S;asm )
31+
32+
# Not sure why CMake by default looks for the compilers, but not the archiver.
33+
# Force it to try to find the archiver.
34+
find_program( CMAKE_AR ar65 )
35+
36+
# \note Need to delete the old file first because ar65 can only add files
37+
# into an archive (or remove named files, but we don't know the names).
38+
set( CMAKE_C_CREATE_STATIC_LIBRARY
39+
"<CMAKE_COMMAND> -E remove <TARGET> "
40+
"<CMAKE_AR> a <TARGET> <LINK_FLAGS> <OBJECTS>"
41+
)
42+
set( CMAKE_ASM_CREATE_STATIC_LIBRARY ${CMAKE_C_CREATE_STATIC_LIBRARY} )

shell.nix

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# shell.nix
2+
{ pkgs ? import <nixpkgs> {} }:
3+
4+
pkgs.mkShell {
5+
buildInputs = with pkgs; [
6+
git
7+
cmake
8+
ninja
9+
cc65
10+
];
11+
}

0 commit comments

Comments
 (0)