Skip to content

Commit

Permalink
[X16EDIT] initial commit, in-rom build
Browse files Browse the repository at this point in the history
  • Loading branch information
mooinglemur committed Oct 8, 2023
1 parent ea02bbf commit fc17315
Show file tree
Hide file tree
Showing 42 changed files with 14,140 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ jobs:
cd cc65
make -j4
sudo make install
cd ..
git clone https://github.com/emmanuel-marty/lzsa
cd lzsa
make
cp -av lzsa /usr/local/bin
- name: Build ROM
if: startsWith(github.ref, 'refs/tags/r') != true
run: |
Expand Down
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ BANK_BINS = \
$(BUILD_DIR)/demo.bin \
$(BUILD_DIR)/audio.bin \
$(BUILD_DIR)/util.bin \
$(BUILD_DIR)/bannex.bin
$(BUILD_DIR)/bannex.bin \
$(BUILD_DIR)/x16edit-rom.bin

ROM_LABELS=$(BUILD_DIR)/rom_labels.h
ROM_LST=$(BUILD_DIR)/rom_lst.h
Expand Down Expand Up @@ -382,6 +383,11 @@ $(BUILD_DIR)/bannex.bin: $(BANNEX_OBJS) $(BANNEX_DEPS) $(CFG_DIR)/bannex-x16.cfg
`${BUILD_DIR}/../../findsymbols ${BUILD_DIR}/kernal.sym mode`
./scripts/relist.py $(BUILD_DIR)/bannex.map $(BUILD_DIR)/bannex

# Bank D-E: X16 Edit
$(BUILD_DIR)/x16edit-rom.bin:
@mkdir -p $$(dirname $@)
(cd x16-edit && make clean rom)
cp x16-edit/build/x16edit-rom.bin $(BUILD_DIR)/x16edit-rom.bin

$(BUILD_DIR)/rom_labels.h: $(BANK_BINS)
./scripts/symbolize.sh 0 build/x16/kernal.sym > $@
Expand Down
33 changes: 33 additions & 0 deletions x16-edit/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
BUILD_DIR=build
CONF_DIR=conf

SRC_FILES=$(wildcard *.asm) $(wildcard *.inc)

# Commands
ram: $(BUILD_DIR)/X16EDIT.PRG
rom: $(BUILD_DIR)/x16edit-rom.bin
all: $(BUILD_DIR)/X16EDIT.PRG $(BUILD_DIR)/x16edit-rom.bin

# Target that compresses default help file
$(BUILD_DIR)/help.bin: help.txt
@mkdir -p $(BUILD_DIR)
lzsa -r -f2 $? $@

# Target that compresses condensed help file for low res screens
$(BUILD_DIR)/help_short.bin: help_short.txt
@mkdir -p $(BUILD_DIR)
lzsa -r -f2 $? $@

# Target for RAM program
$(BUILD_DIR)/X16EDIT.PRG: $(BUILD_DIR)/help.bin $(BUILD_DIR)/help_short.bin $(SRC_FILES)
@mkdir -p $(BUILD_DIR)
cl65 --asm-args -Dtarget_mem=1 -o $@ -u __EXEHDR__ -t cx16 -C $(CONF_DIR)/cx16-asm.cfg --mapfile $(BUILD_DIR)/x16edit-ram.map -Ln $(BUILD_DIR)/x16edit-ram.sym main.asm

# Target for ROM program
$(BUILD_DIR)/x16edit-rom.bin: $(BUILD_DIR)/help.bin $(BUILD_DIR)/help_short.bin $(SRC_FILES)
@mkdir -p $(BUILD_DIR)
cl65 --asm-args -Dtarget_mem=2 -o $@ -t cx16 -C $(CONF_DIR)/x16edit-rom.cfg --mapfile $(BUILD_DIR)/x16edit-rom.map main.asm

# Clean-up target
clean:
rm -f $(BUILD_DIR)/*
59 changes: 59 additions & 0 deletions x16-edit/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# X16 Edit

X16 Edit is a simple text editor for the Commander X16 platform inspired by GNU Nano.

The program's primary design goal is to handle large text files with good performance.
The text buffer is stored in banked RAM (512 KB, expandable to 2 MB).

# Building

The program is written in 65c02 assembly for the ca65 compiler. To build the project
you also need the lzsa compression and Makefile utilities.

Currently, there are three build targets.

* **make** or **make ram** builds the standard version that is loaded into RAM and
started in the same way as a BASIC program.

* **make hiram** builds a version of the program that is to be loaded into RAM address
$6000.

* **make rom** builds an image to be stored in the X16 ROM (32 kB).


# Required Kernal/Emulator version

The current version of the editor requires Kernal/Emulator version R43 or later.


# Running the RAM version

Run the RAM version with the following command:

x16emu -prg X16EDIT.PRG -run


# Running the HI RAM version

The HI RAM version can be loaded and started with the following commands:

In host computer terminal: x16emu -prg X16EDIT.PRG,6000
On the X16: SYS $6000

# Running the ROM version

There are a few more steps to set up and try the ROM version.

Please see the supplemented manual for details.


# Further reading

Refer to the X16 Edit Manual for further help using the program.


# X16 Community

You may read more about the Commander X16 Platform on the website

https://www.commanderx16.com/
9 changes: 9 additions & 0 deletions x16-edit/appversion.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.define appversion_major 0
.define appversion_minor 7
.define appversion_patch 1

.if target_mem=target_rom
.segment "APPSIG"
.byt "x16edit", appversion_major, appversion_minor, appversion_patch
.CODE
.endif
121 changes: 121 additions & 0 deletions x16-edit/bridge.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
;*******************************************************************************
;Copyright 2022-2023, Stefan Jakobsson
;
;Redistribution and use in source and binary forms, with or without modification,
;are permitted provided that the following conditions are met:
;
;1. Redistributions of source code must retain the above copyright notice, this
; list of conditions and the following disclaimer.
;
;2. Redistributions in binary form must reproduce the above copyright notice,
; this list of conditions and the following disclaimer in the documentation
; and/or other materials provided with the distribution.
;
;THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
;AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
;IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
;DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
;FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
;DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
;SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
;CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
;OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
;OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;*******************************************************************************

;******************************************************************************
;Function name.......: bridge_copy
;Purpose.............: Copies bridge code to RAM, necessary to make the program
; run in ROM
;Input...............: Nothing
;Returns.............: Nothing
;Error returns.......: None
.proc bridge_copy
ldx #bridge_end-bridge_kernal
: lda bridge_kernal-1,x
sta bridge_code-1,x
dex
bne :-
rts
.endproc

;******************************************************************************
;Function name.......: bridge_kernal
;Purpose.............: Bridge code to be copied to RAM on program startup.
; Necessary to make the program run in ROM
;Input...............: Use macro BRIDGE_SETADDR to set the Kernal address
; to call before using this function
;Returns.............: Nothing
;Error returns.......: None

;Bridge for Kernal function calls
bridge_kernal:
stz ROM_SEL ;Kernal is ROM bank 0
jsr $ffff ;$ffff is just placeholder
pha
lda rom_bank ;Set ROM select to our bank again
sta ROM_SEL
pla
rts ;Size: 13 bytes


;Bridge for calling functions in another ROM bank
bridge_jsrfar:
sta tempvars
lda rom_bank
pha
lda #$ff
sta rom_bank
sta ROM_SEL
lda tempvars
jsr $ffff
pla
sta rom_bank
sta ROM_SEL
rts ;Size: 27 bytes

;Bridge for interrupt handling, called by the Kernal
;on interrupt, switches to X16 Edit's ROM bank and then
;calls the custom interrupt handler stored in ROM
bridge_irq:
lda ROM_SEL
pha
lda rom_bank
sta ROM_SEL
jsr irq_handler
pla
sta ROM_SEL
jmp (irq_default_handler) ;Size: 17 bytes

;Bridge for custom keyboard scan code handler
bridge_scancode:
php
pha

lda ROM_SEL
sta bridge_temp
lda rom_bank
sta ROM_SEL
pla
plp
jsr scancode_handler
php
pha

lda bridge_temp
sta ROM_SEL

pla
plp
rts ;Size: 27 bytes

bridge_end: ;Total size: 84 bytes

.segment "VARS"
bridge_temp: .res 1
.CODE

.segment "IRQ"
.byt $ff, $ff, $ff, $ff, $8b, $03
.CODE
77 changes: 77 additions & 0 deletions x16-edit/bridge_macro.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
;*******************************************************************************
;Copyright 2022-2023, Stefan Jakobsson
;
;Redistribution and use in source and binary forms, with or without modification,
;are permitted provided that the following conditions are met:
;
;1. Redistributions of source code must retain the above copyright notice, this
; list of conditions and the following disclaimer.
;
;2. Redistributions in binary form must reproduce the above copyright notice,
; this list of conditions and the following disclaimer in the documentation
; and/or other materials provided with the distribution.
;
;THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
;AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
;IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
;DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
;FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
;DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
;SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
;CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
;OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
;OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;*******************************************************************************

bridge_call = bridge_code
bridge_addr = bridge_call+3

.if target_mem=target_rom
bridge_jsrfar_call = bridge_code+bridge_jsrfar-bridge_kernal
bridge_jsrfar_bank = bridge_jsrfar_call+8
bridge_jsrfar_addr = bridge_jsrfar_call+18
.endif

.if target_mem=target_rom
.macro bridge_setaddr addr
lda #<addr
sta bridge_addr
lda #>addr
sta bridge_addr+1
.endmacro

.macro bridge_jsrfar_setaddr addr
sta bridge_jsrfar_bank
lda #<addr
sta bridge_jsrfar_addr
lda #>addr
sta bridge_jsrfar_addr+1
.endmacro
.else
.macro bridge_setaddr addr
;Do nothing
.endmacro

.macro bridge_jsrfar_setaddr addr
;Do nothing
.endmacro
.endif

.if target_mem=target_ram
.macro bridge_call addr
jsr addr
.endmacro

.macro bridge_jsrfar_call addr
jsr addr
.endmacro

.else
.macro bridge_call addr
jsr bridge_call
.endmacro

.macro bridge_jsrfar_call addr
jsr bridge_jsrfar_call
.endmacro
.endif
Loading

0 comments on commit fc17315

Please sign in to comment.