public:computers:6502:ca65_setup
Table of Contents
CA65 Setup
Using CA65 in place of VASM
Support Files
- firmware.cfg
MEMORY { # Zero page ZP: start = $00, size = $100, type = rw, define = yes; RAM: start = $200, size = $3dff define=yes; ROM: start=$8000, size=$8000, type=ro, define=yes, fill=yes, fillval=$00, file=%O; } SEGMENTS { ZEROPAGE: load = ZP, type = zp; BSS: load=RAM, type=bss, define=yes; CODE: load=ROM, type=ro, define=yes; VECTORS: load=ROM, type=ro, define=yes, offset=$7ffa, optional=yes; }
- cc65.rules.mk
include /home/gm4slv/6502/ca65src/tools.mk BUILD_FOLDER=../build TEMP_FOLDER=$(BUILD_FOLDER)/$(ROM_NAME) ROM_FILE=$(BUILD_FOLDER)/$(ROM_NAME).bin MAP_FILE=$(TEMP_FOLDER)/$(ROM_NAME).map ASM_OBJECTS=$(ASM_SOURCES:%.s=$(TEMP_FOLDER)/%.o) # Compile assembler sources $(TEMP_FOLDER)/%.o: %.s @$(MKDIR_BINARY) $(MKDIR_FLAGS) $(TEMP_FOLDER) $(CA65_BINARY) $(CA65_FLAGS) -o $@ -l $(@:.o=.lst) $< # Link ROM image $(ROM_FILE): $(ASM_OBJECTS) $(FIRMWARE_CFG) @$(MKDIR_BINARY) $(MKDIR_FLAGS) $(BUILD_FOLDER) $(LD65_BINARY) $(LD65_FLAGS) -C $(FIRMWARE_CFG) -o $@ -m $(MAP_FILE) $(ASM_OBJECTS) # Default target all: $(ROM_FILE) # Build and dump output test: $(ROM_FILE) $(HEXDUMP_BINARY) $(HEXDUMP_FLAGS) $< $(MD5_BINARY) $< # Clean build artifacts clean: $(RM_BINARY) -f $(ROM_FILE) \ $(MAP_FILE) \ $(ASM_OBJECTS) \ $(ASM_OBJECTS:%.o=%.lst)
- tools.mk
# cc65 utilities used in this example CA65_BINARY=ca65 CC65_BINARY=cc65 LD65_BINARY=ld65 AR65_BINARY=ar65 VASM_BINARY=vasm6502_oldstyle CPU_FLAG=--cpu 65C02 ARCH_FLAG=-t none CC65_FLAGS=$(CPU_FLAG) $(ARCH_FLAG) $(EXTRA_FLAGS) -O CA65_FLAGS=$(CPU_FLAG) $(EXTRA_FLAGS) LD65_FLAGS= AR65_FLAGS=r VASM_FLAGS=-Fbin -dotdir # Hexdump is used for "testing" the ROM HEXDUMP_BINARY=hexdump HEXDUMP_FLAGS=-C # Checksum generator MD5_BINARY=md5sum # Standard utilities (rm/mkdir) RM_BINARY=rm RM_FLAGS=-f MKDIR_BINARY=mkdir MKDIR_FLAGS=-p CP_BINARY=cp CP_FLAGS=-f
- project
makefile
CONF_DIR=/home/gm4slv/6502/ca65src ROM_NAME=monitor_dev ASM_SOURCES=monitor_dev.s FIRMWARE_CFG=$(CONF_DIR)/firmware.cfg include $(CONF_DIR)/cc65.rules.mk
A typical project
monitor_dev.s setup
- Put the asm source for the project in a folder (
/home/gm4slv/6502/ca65src/src/monitor/monitor_dev.s
) - Put the
makefile
in the same folder - put any source files to be included in the assembly process in the
includes
folder/home/gm4slv/6502/ca65src/src/includes/rtc.inc
/home/gm4slv/6502/ca65src/src/includes/ioports.inc
- make a
build
main folder/home/gm4slv/6502/ca65src/build/
The general tree:
/home/gm4slv/6502/ca65src/
= base folder for ca65 projects aka $CA65SRC
- config files : firmware.cfg, cc65.rules.mk, tools.mk are in
$(CA65SRC)
- sources directory :
src
is in$(CA65SRC)
→$(CA65SRC)/src
- inside sources directory are
build
,includes
and the individual project source directories.$(CA65SRC)/src/build/
,$(CA65SRC)/src/includes/
and (eg)$(CA65SRC)/src/monitor/
- inside each
project
source directory are the asm source file egmonitor_dev.s
and a specificmakefile
To include sources from the includes
directory first define the variables, then the includes
:
Variables
define zeropage
variables:
.zeropage DUMP_POINTER: .res 2 FLAGS: .res 1 TOGGLE_TIME: .res 1 CLOCK_LAST: .res 1 MESSAGE_POINTER: .res 2 TICKS: .res 4 CENTISEC: .res 1 HUNDRED_HRS: .res 1 TEN_HRS: .res 1 HRS: .res 1 TEN_MINUTES: .res 1 MINUTES: .res 1 TEN_SECONDS: .res 1 SECONDS: .res 1 MEM_POINTER: .res 2
and define the other .bss
variables:
.bss INKEY: .res 1 ASCII: .res 4 BYTE: .res 2 TENS: .res 1 HUNDREDS: .res 1 HEX: .res 2 HEXB: .res 2 TEMP: .res 1 TEMP2: .res 1
Then the includes
.include "../includes/ioports.inc" .include "../includes/lcd.inc" .include "../includes/getkey.inc" .include "../includes/functions.inc" .include "../includes/rtc.inc"
make sure the include
files have appropriate .code
directive to put it in the right place when its all assembled together:
e.g. in functions.inc
:
.code ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; convert a binary number from Accumulator, in range 00000000 -> 11111111 ($00 to $FF) ;; to its HEX number encode as ASCII - using a simple lookup table and print it on LCD ;; bintohex: pha lsr lsr lsr lsr tax lda hexascii,x jsr print_char pla and #$0f tax lda hexascii,x jsr print_char rts hexascii: .byte "0123456789ABCDEF"
monitor_dev.s source code
— John Pumford-Green 05/09/22 14:23
Further Information
public/computers/6502/ca65_setup.txt · Last modified: 05/09/22 15:02 BST by 127.0.0.1