Initial commit

The compiler is working. That's all :D
master
Marcin Gasperowicz 12 years ago
commit 047a7a96d9

3
.gitignore vendored

@ -0,0 +1,3 @@
.DS_Store
*.o
*.img

@ -0,0 +1,15 @@
CC = bin/cc65
AS = bin/ca65
LD = bin/ld65
export CPU = 65c02
.PHONY: all
all: lib test
.PHONY: test
test:
make -C test/
.PHONY: lib
lib:
make -C lib/

@ -0,0 +1,3 @@
Nothing to see here.
Find me on #redpower at espernet IRC.

@ -0,0 +1,14 @@
#!/bin/bash
BS=128
COUNT=`wc -c $1`
BYTES=${COUNT//[^0-9]/}
BLOCKS=$(( BYTES / BS ))
SECTORS=$(( BLOCKS + 1 ))
echo "Code size = " $BYTES
echo "Image size = " $SECTORS " * " $BS " = " $(( SECTORS * BS ))
dd if=/dev/zero of=$1.pad bs=$BS count=$SECTORS > /dev/null 2>&1
dd if=$1 of=$1.pad conv=notrunc > /dev/null 2>&1
rm $1
mv $1.pad $1
#echo $BLOCKS " bytes aligned to " $NEWBLOCKS " blocks"
#dd if=/dev/zero oflag=seek_bytes seek=$BLOCKS of=$1 bs=16 count=$NEWBLOCKS conv=notrunc

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -0,0 +1,3 @@
#!/bin/bash
cp test/$1.img /Applications/MultiMC.app/Contents/Resources/instances/1.2.5\ ftb/minecraft/saves/cpu\ test/redpower/disk_1b63bbbd8ce6001f.img

@ -0,0 +1,48 @@
//console.h
// 0x00 Memory access row. Used to set which line of characters appears in the display memory window.
// 0x01 cursor x
// 0x02 cursor y
// 0x03 cursor mode (0: hidden, 1: solid, 2: blink)
// 0x04 key buffer start (16 byte buffer)
// 0x05 key buffer position
// 0x06 key value at buffer start
// 0x07 blit mode (1: fill, 2: invert; 3: shift)
// 0x08 blit x start / fill value
// 0x09 blit y start
// 0x0A blit x offset
// 0x0B blit y offset
// 0x0C blit width
// 0x0D blit height
// 0x10 -> 0x60 display memory window
typedef struct Console {
char line;
char cursor_x;
char cursor_y;
char cursor_mode;
char kb_start;
char kb_pos;
char kb_key;
char blit_mode;
char blit_start_x;
char blit_start_y;
char blit_offset_x;
char blit_offset_y;
char blit_width;
char blit_height;
unsigned int padding;
char display[0x50];
} Console;
//character with inverted colors
#define inv(c) ((c) | 0x80)

@ -0,0 +1,29 @@
//disk.h
// 0x00-0x7F: Disk sector buffer
// 0x80-0x81: Sector number
// 0x82: Disk command:
// 0: Idle/success
// 1: Read Disk Name
// 2: Write Disk Name
// 3: Read Disk Serial
// 4: Read Disk Sector
// 5: Write Disk Sector
// 0xFF: Command failure
typedef enum {
IDLE = 0,
READ_NAME = 1,
WRITE_NAME = 2,
READ_SERIAL = 3,
READ = 4,
WRITE = 5,
FAIL = 0xFF
} DiskCommand;
typedef struct Disk {
char sector[0x80];
unsigned int sector_num;
DiskCommand command;
} Disk;

@ -0,0 +1,46 @@
// iox.h
// device struct
typedef struct Iox {
unsigned int in;
unsigned int out;
} Iox;
// Bit Dec Hex Color
// 0 1 0x1 White
// 1 2 0x2 Orange
// 2 4 0x4 Magenta
// 3 8 0x8 Light Blue
// 4 16 0x10 Yellow
// 5 32 0x20 Lime
// 6 64 0x40 Pink
// 7 128 0x80 Gray
// 8 256 0x100 Light Gray
// 9 512 0x200 Cyan
// 10 1024 0x400 Purple
// 11 2048 0x800 Blue
// 12 4096 0x1000 Brown
// 13 8192 0x2000 Green
// 14 16384 0x4000 Red
// 15 32768 0x8000 Black
typedef enum {
WHITE = 0x0001,
ORANGE = 0x0002,
MAGENTA = 0x0004,
LBLUE = 0x0008,
YELLOW = 0x0010,
LIME = 0x0020,
PINK = 0x0040,
GRAY = 0x0080,
LGRAY = 0x0100,
CYAN = 0x0200,
PURPLE = 0x0400,
BLUE = 0x0800,
BROWN = 0x1000,
GREEN = 0x2000,
RED = 0x4000,
BLACK = 0x8000
} WireColor;

@ -0,0 +1,33 @@
// redbus.h
void rb_enable(void);
void rb_disable(void);
void __fastcall__ rb_set_window(void* address);
void __fastcall__ rb_map_device(unsigned char id);
// 0x00 Map device in Reg A to redbus window.
// 0x80 Get mapped device to A.
// 0x01 Redbus Window offset to A
// 0x81 Get RB window offset to A.
// 0x02 Enable redbus
// 0x82 Disable redbus
// 0x03 Set external memory mapped window to A.
// 0x83 Get memory mapped window to A.
// 0x04 Enable external memory mapped window.
// 0x84 Disable external memory mapped window.
// 0x05 Set BRK address to A
// 0x85 Get BRK address to A
// 0x06 Set POR address to A
// 0x86 Get POR address to A
// 0xFF Output A register to MC logfile.

@ -0,0 +1,21 @@
AR = ../bin/ar65
export CPU = 65c02
#.PHONY: all
all: rpc8e.lib
rpc8e.lib: runtime common rpc8e
rm -f rpc8e.lib
$(AR) a rpc8e.lib runtime/*.o rpc8e/*.o common/*.o
.PHONY: runtime rpc8e common
rpc8e:
make -C rpc8e/
runtime:
make -C runtime/
common:
make -C common/

@ -0,0 +1,4 @@
.macro mmu command
.byte $EF
.byte command
.endmacro

@ -0,0 +1,21 @@
;
; zeropage.inc
;
; (C) Copyright 2002 Ullrich von Bassewitz (uz@cc65.org)
;
; Assembler include file that imports the runtime zero page locations used
; by the compiler, ready for usage in asm code.
.importzp sp, sreg, regsave
.importzp ptr1, ptr2, ptr3, ptr4
.importzp tmp1, tmp2, tmp3, tmp4
.importzp regbank
; The total amount of zero page space used
zpspace = 26

@ -0,0 +1,217 @@
#
# makefile for CC65 runtime library
#
.SUFFIXES: .o .s .c
#--------------------------------------------------------------------------
# Programs and flags
SYS = none
AS = ../../bin/ca65
CC = ../../bin/cc65
LD = ../../bin/ld65
AFLAGS = -t $(SYS) --forget-inc-paths -I../asminc --cpu $(CPU)
CFLAGS = -Osir -g -T -t $(SYS) --forget-inc-paths -I . -I ../../include --cpu $(CPU)
#--------------------------------------------------------------------------
# Rules
%.o: %.c
@$(CC) $(CFLAGS) $<
@$(AS) -g -o $@ $(AFLAGS) $(*).s
%.o: %.s
@$(AS) -g -o $@ $(AFLAGS) $<
#--------------------------------------------------------------------------
# Rules to help us see what code the compiler and assembler make.
%.s : %.c
@$(CC) $(CFLAGS) -S $<
%.lst : %.s
@$(AS) $(AFLAGS) -l -o /dev/null $<
#--------------------------------------------------------------------------
# Object files
# From C source-files
# C_OBJS = _afailed.o \
# _hextab.o \
# _poserror.o \
# _scanf.o \
# abort.o \
# asctime.o \
# bsearch.o \
# errormsg.o \
# fdopen.o \
# fgetc.o \
# fgetpos.o \
# fgets.o \
# fputc.o \
# fputs.o \
# freopen.o \
# fseek.o \
# fsetpos.o \
# ftell.o \
# getchar.o \
# gets.o \
# gmtime.o \
# locale.o \
# localtime.o \
# mktime.o \
# perror.o \
# pmemalign.o \
# puts.o \
# qsort.o \
# realloc.o \
# rewind.o \
# sleep.o \
# strftime.o \
# strtok.o \
# strtol.o \
# strtoul.o \
# strxfrm.o \
# system.o \
# timezone.o
# From assembly source-files
S_OBJS = zerobss.o copydata.o
#_cwd.o \
# _environ.o \
# _fdesc.o \
# _file.o \
# _fopen.o \
# _heap.o \
# _heapadd.o \
# _heapblocksize.o\
# _heapmaxavail.o \
# _heapmemavail.o \
# _oserror.o \
# _printf.o \
# _seterrno.o \
# _swap.o \
# _sys.o \
# abs.o \
# atexit.o \
# atoi.o \
# calloc.o \
# chdir.o \
# copydata.o \
# creat.o \
# ctime.o \
# divt.o \
# errno.o \
# fclose.o \
# fmisc.o \
# fopen.o \
# fprintf.o \
# fread.o \
# free.o \
# fscanf.o \
# fwrite.o \
# getcpu.o \
# getcwd.o \
# getenv.o \
# interrupt.o \
# isalnum.o \
# isalpha.o \
# isblank.o \
# iscntrl.o \
# isdigit.o \
# isgraph.o \
# islower.o \
# isprint.o \
# ispunct.o \
# isspace.o \
# isupper.o \
# isxdigit.o \
# itoa.o \
# labs.o \
# longjmp.o \
# ltoa.o \
# malloc.o \
# maperrno.o \
# memchr.o \
# memcmp.o \
# memcpy.o \
# memmove.o \
# memset.o \
# mkdir.o \
# modfree.o \
# modload.o \
# oserrcheck.o \
# printf.o \
# putchar.o \
# putenv.o \
# rand.o \
# raise.o \
# remove.o \
# rename.o \
# rmdir.o \
# scanf.o \
# searchenv.o \
# setjmp.o \
# signal.o \
# sigtable.o \
# snprintf.o \
# sprintf.o \
# sscanf.o \
# strcat.o \
# strchr.o \
# strcmp.o \
# strcoll.o \
# strcpy.o \
# strcspn.o \
# strdup.o \
# strerror.o \
# stricmp.o \
# strlen.o \
# strlower.o \
# strncat.o \
# strncmp.o \
# strncpy.o \
# strnicmp.o \
# stroserr.o \
# strpbrk.o \
# strrchr.o \
# strspn.o \
# strstr.o \
# strtoimax.o \
# strtoumax.o \
# strupper.o \
# time.o \
# tolower.o \
# toupper.o \
# uname.o \
# ungetc.o \
# unlink.o \
# utscopy.o \
# vfprintf.o \
# vfscanf.o \
# vprintf.o \
# vscanf.o \
# vsnprintf.o \
# vsprintf.o \
# vsscanf.o \
# zerobss.o
#--------------------------------------------------------------------------
# Targets
.PHONY: all clean zap
all: $(C_OBJS) $(S_OBJS)
clean:
@$(RM) *~ *.lst
@$(RM) $(C_OBJS:.o=.s)
@$(RM) $(C_OBJS)
@$(RM) $(S_OBJS)
zap: clean

@ -0,0 +1,49 @@
;
; Ullrich von Bassewitz, 1998-12-07, 2004-12-01
;
; Copy the data segment from the LOAD to the RUN location
;
.export copydata
.import __DATA_LOAD__, __DATA_RUN__, __DATA_SIZE__
.importzp ptr1, ptr2, tmp1
copydata:
lda #<__DATA_LOAD__ ; Source pointer
sta ptr1
lda #>__DATA_LOAD__
sta ptr1+1
lda #<__DATA_RUN__ ; Target pointer
sta ptr2
lda #>__DATA_RUN__
sta ptr2+1
ldx #<~__DATA_SIZE__
lda #>~__DATA_SIZE__ ; Use -(__DATASIZE__+1)
sta tmp1
ldy #$00
; Copy loop
@L1: inx
beq @L3
@L2: lda (ptr1),y
sta (ptr2),y
iny
bne @L1
inc ptr1+1
inc ptr2+1 ; Bump pointers
bne @L1 ; Branch always (hopefully)
; Bump the high counter byte
@L3: inc tmp1
bne @L2
; Done
rts

@ -0,0 +1,46 @@
;
; Ullrich von Bassewitz, 1998-09-17, 2005-02-26.
;
; Zero the bss segment.
;
.export zerobss
.import __BSS_RUN__, __BSS_SIZE__
.importzp ptr1
.segment "INIT"
zerobss:
lda #<__BSS_RUN__
sta ptr1
lda #>__BSS_RUN__
sta ptr1+1
lda #0
tay
; Clear full pages
L1: ldx #>__BSS_SIZE__
beq L3
L2: sta (ptr1),y
iny
bne L2
inc ptr1+1
dex
bne L2
; Clear remaining page (y is zero on entry)
L3: cpy #<__BSS_SIZE__
beq L4
sta (ptr1),y
iny
bne L3
; Done
L4: rts

@ -0,0 +1,40 @@
MEMORY {
ZEROPAGE: start = $0006, size = $00FA;
STACK: start = $0100, size = $0100, define = yes;
RAM: start = $0500, size = $FAFF, define = yes;
}
SEGMENTS {
ZEROPAGE: load = ZEROPAGE, type = zp, define = yes;
STARTUP: load = RAM, type = ro;
CODE: load = RAM, type = ro;
INIT: load = RAM, type = ro;
DATA: load = RAM, type = rw, define = yes, run = RAM;
RODATA: load = RAM, type = ro;
BSS: load = RAM, type = bss, define = yes;
HEAP: load = RAM, type = bss, optional = yes;
# VECTOR: load = RAM, type = ro, start = $C000;
}
FEATURES {
CONDES: segment = STARTUP,
type = constructor,
label = __CONSTRUCTOR_TABLE__,
count = __CONSTRUCTOR_COUNT__;
CONDES: segment = STARTUP,
type = destructor,
label = __DESTRUCTOR_TABLE__,
count = __DESTRUCTOR_COUNT__;
}
SYMBOLS {
# Define the stack size for the application
__STACKSIZE__: value = $0200, weak = yes;
}
# 0x0000 Zero page
# 0x0100 P-stack
# 0x0200 R-stack
# 0x0300 bus output
# 0x0400 bus input (also Bootloader space)
# 0x0500 Ram (the bootloader loads the disk image here)

Binary file not shown.

@ -0,0 +1,45 @@
#
# makefile for CC65 runtime library
#
.SUFFIXES: .o .s .c
#--------------------------------------------------------------------------
# Programs and flags
SYS = none
AS = ../../bin/ca65
CC = ../../bin/cc65
LD = ../../bin/ld65
AFLAGS = -t $(SYS) --forget-inc-paths -I../asminc --cpu $(CPU)
CFLAGS = -Osir -g -T -t $(SYS) --forget-inc-paths -I . -I ../../include --cpu $(CPU)
#--------------------------------------------------------------------------
# Rules
.c.s:
@$(CC) $(CFLAGS) $<
.s.o:
@$(AS) -g -o $@ $(AFLAGS) $<
#--------------------------------------------------------------------------
# Object files
OBJS = crt0.o \
redbus.o
#--------------------------------------------------------------------------
# Targets
.PHONY: all clean zap
all: $(OBJS)
clean:
@$(RM) *~ $(COBJS:.o=.s) $(OBJS)
zap: clean

@ -0,0 +1,95 @@
; ---------------------------------------------------------------------------
; crt0.s
; ---------------------------------------------------------------------------
;
; Startup code for c65el02
.export _init, _exit
.import _main
.export __STARTUP__ : absolute = 1 ; Mark as startup
.import __STACK_START__, __STACK_SIZE__ ; Linker generated
.import copydata, zerobss, initlib, donelib
.include "zeropage.inc"
.macro MMU command
.byte $EF
.byte command
.endmacro
.macro XCE
.byte $FB
.endmacro
; ---------------------------------------------------------------------------
; Place the startup code in a special segment
.segment "STARTUP"
;.byte $DB
; ---------------------------------------------------------------------------
; A little light 6502 housekeeping
_init: LDX #$FF ; Initialize stack pointer to $01FF
TXS
CLD ; Clear decimal mode
; ---------------------------------------------------------------------------
; Set cc65 argument stack pointer
LDA #<(__STACK_START__ + __STACK_SIZE__ - 1)
STA sp
LDA #>(__STACK_START__ + __STACK_SIZE__ - 1)
STA sp+1
; ---------------------------------------------------------------------------
; Initialize memory storage
JSR zerobss ; Clear BSS segment
JSR copydata ; Initialize DATA segment
JSR initlib ; Run constructors
; ---------------------------------------------------------------------------
; Initialize redbus
; from foth boot disk
;000500 18 CLC
;000501 FB XCE
;000502 C2 30 REP #$30
;000504 A9 00 03 LDA #$0300
;000507 EF 01 MMU $01
;000509 EF 02 MMU $02
;00050B A9 00 04 LDA #$0400
;00050E EF 03 MMU $03
;000510 EF 04 MMU $04
;000512 A9 00 05 LDA #$0500
;000515 EF 06 MMU $06
;000517 4C 56 1D JMP $1D56
;LDA $01 ; Get the main console ID
;MMU $00
;LDA #$00 ; Select first line
;STA $0300
;LDA #$42 ; Seems to work
;STA $0310
;.byte $DB
; ---------------------------------------------------------------------------
; Call main()
JSR _main
; ---------------------------------------------------------------------------
; Back from main (this is also the _exit entry): force a software break
_exit: JSR donelib ; Run destructors
BRK

@ -0,0 +1,55 @@
.include "mmu.inc"
.export _rb_enable, _rb_disable, _rb_map_device, _rb_set_window
.segment "CODE"
;------------------------------------------
; void __inline__ rb_enable(void);
;------------------------------------------
_rb_enable:
mmu $02
rts
;------------------------------------------
; void __inline__ rb_disable(void);
;------------------------------------------
_rb_disable:
mmu $82
rts
;------------------------------------------
; void __fastcall__ rb_set_window(void* address);
;------------------------------------------
_rb_set_window:
;switch to native 16bit
clc
.byte $FB ; XCE
.byte $C2, $30 ; REP #$30
; init redstone window at $0300
;.byte $A9, $00, $03 ; LDA #$0300
.byte $EB ; XBA
stx $55
ora $55
.byte $EB ; XBA
mmu $01
;switch to emulated 8bit
.byte $E2, $30 ; SEP #$30
sec
.byte $FB ; XCE
rts
;------------------------------------------
; void __fastcall__ rb_map_device(unsigned char id);
;------------------------------------------
_rb_map_device:
mmu $00
rts

@ -0,0 +1,234 @@
#
# makefile for CC65 runtime library
#
.SUFFIXES: .o .s .c
#--------------------------------------------------------------------------
# Programs and flags
SYS = none
AS = ../../bin/ca65
CC = ../../bin/cc65
LD = ../../bin/ld65
AFLAGS = -t $(SYS) --forget-inc-paths -I../asminc --cpu $(CPU)
CFLAGS = -Osir -g -T -t $(SYS) --forget-inc-paths -I . -I ../../include --cpu $(CPU)
#--------------------------------------------------------------------------
# Rules
.c.s:
@$(CC) $(CFLAGS) $<
.s.o:
@$(AS) -g -o $@ $(AFLAGS) $<
#--------------------------------------------------------------------------
# Object files
OBJS = add.o \
addeqsp.o \
addysp.o \
along.o \
and.o \
aslax1.o \
aslax2.o \
aslax3.o \
aslax4.o \
asleax1.o \
asleax2.o \
asleax3.o \
asleax4.o \
asr.o \
asrax1.o \
asrax2.o \
asrax3.o \
asrax4.o \
asreax1.o \
asreax2.o \
asreax3.o \
asreax4.o \
axlong.o \
bneg.o \
bpushbsp.o \
call.o \
callirq.o \
callmain.o \
compl.o \
condes.o \
decax1.o \
decax2.o \
decax3.o \
decax4.o \
decax5.o \
decax6.o \
decax7.o \
decax8.o \
decaxy.o \
decsp1.o \
decsp2.o \
decsp3.o \
decsp4.o \
decsp5.o \
decsp6.o \
decsp7.o \
decsp8.o \
div.o \
enter.o \
eq.o \
ge.o \
gt.o \
icmp.o \
incax1.o \
incax2.o \
incax3.o \
incax5.o \
incax6.o \
incax7.o \
incax8.o \
incaxy.o \
incsp1.o \
incsp2.o \
incsp3.o \
incsp4.o \
incsp5.o \
incsp6.o \
incsp7.o \
incsp8.o \
jmpvec.o \
ladd.o \
laddeq.o \
laddeqsp.o \
land.o \
lasr.o \
lbneg.o \
lcmp.o \
lcompl.o \
ldai.o \
ldau0sp.o \
ldaui.o \
ldauisp.o \
ldaxi.o \
ldaxsp.o \
ldeaxi.o \
ldeaxysp.o \
ldec.o \
ldiv.o \
le.o \
leaaxsp.o \
leave.o \
leq.o \
lge.o \
lgt.o \
linc.o \
lle.o \
llt.o \
lmod.o \
lmul.o \
lne.o \
lneg.o \
lor.o \
lpop.o \
lpush.o \
lrsub.o \
lsave.o \
lshelp.o \
lshl.o \
lshr.o \
lsub.o \
lsubeq.o \
lsubeqsp.o \
lt.o \
ltest.o \
ludiv.o \
luge.o \
lugt.o \
lule.o \
lult.o \
lumod.o \
lxor.o \
makebool.o \
mod.o \
mul.o \
mul8.o \
mulax3.o \
mulax5.o \
mulax6.o \
mulax7.o \
mulax9.o \
mulax10.o \
ne.o \
neg.o \
or.o \
popa.o \
popsreg.o \
push1.o \
push2.o \
push3.o \
push4.o \
push5.o \
push6.o \
push7.o \
pusha.o \
pushaff.o \
pushax.o \
pushb.o \
pushbsp.o \
pushc0.o \
pushc1.o \
pushc2.o \
pushlysp.o \
pushw.o \
pushwsp.o \
regswap.o \
regswap1.o \
regswap2.o \
return0.o \
return1.o \
rsub.o \
shelp.o \
shl.o \
shr.o \
shrax1.o \
shrax2.o \
shrax3.o \
shrax4.o \
shreax1.o \
shreax2.o \
shreax3.o \
shreax4.o \
staspidx.o \
staxsp.o \
staxspi.o \
steaxsp.o \
steaxspi.o \
stkchk.o \
sub.o \
subeqsp.o \
subysp.o \
swap.o \
tosint.o \
toslong.o \
udiv.o \
uge.o \
ugt.o \
ule.o \
ult.o \
umod.o \
xor.o \
zeropage.o
#--------------------------------------------------------------------------
# Targets
.PHONY: all clean zap
all: $(OBJS)
clean:
@$(RM) *~ $(COBJS:.o=.s) $(OBJS)
zap: clean

@ -0,0 +1,39 @@
;
; Ullrich von Bassewitz, 05.08.1998
;
; CC65 runtime: add ints
;
; Make this as fast as possible, even if it needs more space since it's
; called a lot!
.export tosadda0, tosaddax
.importzp sp
.macpack cpu
tosadda0:
ldx #0
tosaddax:
clc
.if (.cpu .bitand CPU_ISET_65SC02)
adc (sp) ; 65SC02 version - saves 2 cycles
ldy #1
.else
ldy #0
adc (sp),y ; lo byte
iny
.endif
pha ; save it
txa
adc (sp),y ; hi byte
tax
clc
lda sp
adc #2
sta sp
bcc L1
inc sp+1
L1: pla ; Restore low byte
rts

@ -0,0 +1,24 @@
;
; Ullrich von Bassewitz, 08.10.1998
;
; CC65 runtime: += operator for ints on the stack
;
.export addeq0sp, addeqysp
.importzp sp
addeq0sp:
ldy #0
addeqysp:
clc
adc (sp),y
sta (sp),y
pha
iny
txa
adc (sp),y
sta (sp),y
tax
pla
rts

@ -0,0 +1,21 @@
;
; Ullrich von Bassewitz, 25.10.2000
;
; CC65 runtime: Increment the stackpointer by value in y
;
.export addysp1, addysp
.importzp sp
addysp1:
iny
addysp: pha ; Save A
clc
tya ; Get the value
adc sp ; Add low byte
sta sp ; Put it back
bcc @L1 ; If no carry, we're done
inc sp+1 ; Inc high byte
@L1: pla ; Restore A
rts

@ -0,0 +1,24 @@
;
; Ullrich von Bassewitz, 23.11.2002
;
; CC65 runtime: Convert char in ax into a long
;
.export aulong, along
.importzp sreg
; Convert A from char to long in EAX
aulong: ldx #0
stx sreg
stx sreg+1
rts
along: cmp #$80 ; Positive?
bcc aulong ; Yes, handle like unsigned type
ldx #$ff
stx sreg
stx sreg+1
rts

@ -0,0 +1,30 @@
;
; Ullrich von Bassewitz, 05.08.1998
;
; CC65 runtime: and on ints
;
.export tosanda0, tosandax
.import addysp1
.importzp sp, ptr4
.macpack cpu
tosanda0:
ldx #$00
tosandax:
.if (.cpu .bitand CPU_ISET_65SC02)
and (sp) ; 65SC02 version, saves 2 cycles and 1 byte
ldy #1
.else
ldy #0
and (sp),y
iny
.endif
pha
txa
and (sp),y
tax
pla
jmp addysp1 ; drop TOS, set condition codes

@ -0,0 +1,17 @@
;
; Ullrich von Bassewitz, 06.08.1998
;
; CC65 runtime: Scale the primary register
;
.export aslax1, shlax1
.importzp tmp1
aslax1:
shlax1: stx tmp1
asl A
rol tmp1
ldx tmp1
rts

@ -0,0 +1,18 @@
;
; Ullrich von Bassewitz, 06.08.1998
;
; CC65 runtime: Scale the primary register by 4
;
.export aslax2, shlax2
.importzp tmp1
aslax2:
shlax2: stx tmp1
asl a
rol tmp1
asl a
rol tmp1
ldx tmp1
rts

@ -0,0 +1,20 @@
;
; Ullrich von Bassewitz, 06.08.1998
;
; CC65 runtime: Scale the primary register by 8
;
.export aslax3, shlax3
.importzp tmp1
aslax3:
shlax3: stx tmp1
asl a
rol tmp1
asl a
rol tmp1
asl a
rol tmp1
ldx tmp1
rts

@ -0,0 +1,22 @@
;
; Ullrich von Bassewitz, 25.07.2001
;
; CC65 runtime: Scale the primary register by 16
;
.export aslax4, shlax4
.importzp tmp1
aslax4:
shlax4: stx tmp1
asl a
rol tmp1
asl a
rol tmp1
asl a
rol tmp1
asl a
rol tmp1
ldx tmp1
rts

@ -0,0 +1,19 @@
;
; Ullrich von Bassewitz, 06.08.1998
;
; CC65 runtime: Scale the 32 bit primary register by 2
;
.export asleax1, shleax1
.importzp sreg, tmp1
asleax1:
shleax1:
stx tmp1
asl a
rol tmp1
rol sreg
rol sreg+1
ldx tmp1
rts

@ -0,0 +1,23 @@
;
; Ullrich von Bassewitz, 06.08.1998
;
; CC65 runtime: Scale the 32 bit primary register by 4
;
.export asleax2, shleax2
.importzp sreg, tmp1
asleax2:
shleax2:
stx tmp1
asl a
rol tmp1
rol sreg
rol sreg+1
asl a
rol tmp1
rol sreg
rol sreg+1
ldx tmp1
rts

@ -0,0 +1,27 @@
;
; Ullrich von Bassewitz, 06.08.1998
;
; CC65 runtime: Scale the 32 bit primary register by 8
;
.export asleax3, shleax3
.importzp sreg, tmp1
asleax3:
shleax3:
stx tmp1
asl a
rol tmp1
rol sreg
rol sreg+1
asl a
rol tmp1
rol sreg
rol sreg+1
asl a
rol tmp1
rol sreg
rol sreg+1
ldx tmp1
rts

@ -0,0 +1,22 @@
;
; Ullrich von Bassewitz, 25.07.2001
;
; CC65 runtime: Scale the 32 bit primary register by 16
;
.export asleax4, shleax4
.importzp sreg, tmp1
asleax4:
shleax4:
stx tmp1
ldx #4
@L1: asl a
rol tmp1
rol sreg
rol sreg+1
dex
bne @L1
ldx tmp1
rts

@ -0,0 +1,60 @@
;
; Ullrich von Bassewitz, 2004-06-30
;
; CC65 runtime: right shift support for ints
;
; Note: The standard declares a shift count that is negative or >= the
; bitcount of the shifted type for undefined behaviour.
;
; Note^2: The compiler knowns about the register/zero page usage of this
; function, so you need to change the compiler source if you change it!
;
.export tosasrax
.import popax
.importzp tmp1
tosasrax:
and #$0F ; Bring the shift count into a valid range
sta tmp1 ; Save it
jsr popax ; Get the left hand operand
ldy tmp1 ; Get shift count
beq L9 ; Bail out if shift count zero
cpy #8 ; Shift count 8 or greater?
bcc L1 ; Jump if not
; Shift count is greater 8. The carry is set when we enter here.
tya
sbc #8
tay ; Adjust shift count
txa
ldx #$00 ; Shift by 8 bits
cmp #$00 ; Test sign bit
bpl L1
dex ; Make X the correct sign extended value
; Save the high byte so we can shift it
L1: stx tmp1 ; Save high byte
jmp L3
; Do the actual shift
L2: cpx #$80 ; Copy bit 15 into the carry
ror tmp1
ror a
L3: dey
bpl L2
; Done with shift
ldx tmp1
L9: rts

@ -0,0 +1,16 @@
;
; Ullrich von Bassewitz, 06.08.1998
;
; CC65 runtime: Scale the primary register
;
.export asrax1
.importzp tmp1
asrax1: stx tmp1
cpx #$80 ; Put bit 7 into carry
ror tmp1
ror a
ldx tmp1
rts

@ -0,0 +1,19 @@
;
; Ullrich von Bassewitz, 06.08.1998
;
; CC65 runtime: Scale the primary register by 4
;
.export asrax2
.importzp tmp1
asrax2: stx tmp1
cpx #$80 ; Put bit 7 into carry
ror tmp1
ror a
cpx #$80
ror tmp1
ror a
ldx tmp1
rts

@ -0,0 +1,23 @@
;
; Piotr Fusik, 24.10.2003
; originally by Ullrich von Bassewitz
;
; CC65 runtime: Scale the primary register by 8
;
.export asrax3
.importzp tmp1
asrax3: stx tmp1
cpx #$80 ; Put bit 7 into carry
ror tmp1
ror a
cpx #$80
ror tmp1
ror a
cpx #$80
ror tmp1
ror a
ldx tmp1
rts

@ -0,0 +1,26 @@
;
; Piotr Fusik, 24.10.2003
; originally by Ullrich von Bassewitz
;
; CC65 runtime: Scale the primary register by 16
;
.export asrax4
.importzp tmp1
asrax4: stx tmp1
cpx #$80 ; Put bit 7 into carry
ror tmp1
ror a
cpx #$80
ror tmp1
ror a
cpx #$80
ror tmp1
ror a
cpx #$80
ror tmp1
ror a
ldx tmp1
rts

@ -0,0 +1,20 @@
;
; Ullrich von Bassewitz, 06.08.1998
;
; CC65 runtime: Scale the primary register
;
.export asreax1
.importzp sreg, tmp1
asreax1:
stx tmp1
ldx sreg+1
cpx #$80 ; Get bit 7 into carry
ror sreg+1
ror sreg
ror tmp1
ror a
ldx tmp1
rts

@ -0,0 +1,25 @@
;
; Ullrich von Bassewitz, 06.08.1998
;
; CC65 runtime: Scale the 32 bit primary register by 4
;
.export asreax2
.importzp sreg, tmp1
asreax2:
stx tmp1
ldx sreg+1
cpx #$80 ; Get bit 7 into carry
ror sreg+1
ror sreg
ror tmp1
ror a
cpx #$80 ; Get bit 7 into carry
ror sreg+1
ror sreg
ror tmp1
ror a
ldx tmp1
rts

@ -0,0 +1,30 @@
;
; Ullrich von Bassewitz, 06.08.1998
;
; CC65 runtime: Scale the 32 bit primary register by 8
;
.export asreax3
.importzp sreg, tmp1
asreax3:
stx tmp1
ldx sreg+1
cpx #$80 ; Get bit 7 into carry
ror sreg+1
ror sreg
ror tmp1
ror a
cpx #$80 ; Get bit 7 into carry
ror sreg+1
ror sreg
ror tmp1
ror a
cpx #$80 ; Get bit 7 into carry
ror sreg+1
ror sreg
ror tmp1
ror a
ldx tmp1
rts

@ -0,0 +1,23 @@
;
; Ullrich von Bassewitz, 25.07.2001
;
; CC65 runtime: Scale the 32 bit primary register by 16
;
.export asreax4
.importzp sreg, tmp1
asreax4:
stx tmp1
ldx sreg+1
ldy #4
@L1: cpx #$80 ; Get bit 7 into carry
ror sreg+1
ror sreg
ror tmp1
ror a
dey
bne @L1
ldx tmp1
rts

@ -0,0 +1,26 @@
;
; Ullrich von Bassewitz, 25.10.2000
;
; CC65 runtime: Convert int in ax into a long
;
.export axulong, axlong
.importzp sreg
; Convert AX from int to long in EAX
axulong:
ldy #0
sty sreg
sty sreg+1
rts
axlong: cpx #$80 ; Positive?
bcc axulong ; Yes, handle like unsigned type
ldy #$ff
sty sreg
sty sreg+1
rts

@ -0,0 +1,20 @@
;
; Ullrich von Bassewitz, 05.08.1998
;
; CC65 runtime: boolean negation
;
.export bnega, bnegax
.import return0, return1
bnegax: cpx #0
bne L0
bnega: tax
bne L0
L1: lda #1 ; Zero already in X
rts
L0: ldx #0
txa
rts

@ -0,0 +1,18 @@
;
; Ullrich von Bassewitz, 31.08.1998
;
; CC65 runtime: Load a from stack slot and push as byte
;
.export bpushbsp, bpushbysp
.import pusha
.importzp sp
bpushbsp:
ldy #0
bpushbysp:
lda (sp),y
jmp pusha

@ -0,0 +1,13 @@
;
; Ullrich von Bassewitz, 06.08.1998
;
; CC65 runtime: call function via pointer in ax
;
.export callax
.importzp ptr1
callax: sta ptr1
stx ptr1+1
jmp (ptr1) ; jump there

@ -0,0 +1,63 @@
;
; Ullrich von Bassewitz, 2004-04-04
;
; CC65 runtime: Support for calling special irq routines declared as condes
; type 2.
;
; There are two reasons, why this is a separate routine, and the generic
; condes routine in condes.s is not used:
;
; 1. Speed. Having several things hardcoded makes it faster. This is
; important if it is called in each interrupt.
;
; 2. Reentrancy. The condes routines must use self modyfiying code, which
; means it is not reentrant. An IRQ using condes, that interrupts
; another use of condes will cause unpredicatble behaviour. The current
; code avoids this by using locking mechanisms, but it's complex and
; has a size and performance penalty.
;
; 3. Special semantics: An interruptor called by callirq must tell by
; setting or resetting the carry flag if the interrupt has been handled
; (which means that the interrupt is no longer active at the interrupt
; source). callirq will call no other interruptors if this happens. To
; simplify code, all interrupt routines will be called with carry clear
; on entry.
;
; As the normal condes routine, this one has the limitation of 127 table
; entries.
;
.export callirq
.export callirq_y ; Same but with Y preloaded
.import __INTERRUPTOR_TABLE__, __INTERRUPTOR_COUNT__
.code
; --------------------------------------------------------------------------
; Call all IRQ routines. The function needs to use self modifying code and
; is thereforce placed in the data segment. It will return carry set if the
; interrupt was handled and carry clear if not. The caller may choose to
; ignore this at will.
; NOTE: The routine must not be called if the table is empty!
.data
callirq:
ldy #.lobyte(__INTERRUPTOR_COUNT__*2)
callirq_y:
clc ; Preset carry flag
loop: dey
lda __INTERRUPTOR_TABLE__,y
sta jmpvec+2 ; Modify code below
dey
lda __INTERRUPTOR_TABLE__,y
sta jmpvec+1 ; Modify code below
sty index+1 ; Modify code below
jmpvec: jsr $FFFF ; Patched at runtime
bcs done ; Bail out if interrupt handled
index: ldy #$FF ; Patched at runtime
bne loop
done: rts

@ -0,0 +1,40 @@
;
; Ullrich von Bassewitz, 2003-03-07
;
; Push arguments and call main()
;
.export callmain
.export __argc, __argv
.import _main, pushax
;---------------------------------------------------------------------------
; Setup the stack for main(), then jump to it
.proc callmain
lda __argc
ldx __argc+1
jsr pushax ; Push argc
lda __argv
ldx __argv+1
jsr pushax ; Push argv
ldy #4 ; Argument size
jmp _main
.endproc
;---------------------------------------------------------------------------
; Data
.bss
__argc: .res 2
__argv: .res 2

@ -0,0 +1,17 @@
;
; Ullrich von Bassewitz, 06.08.1998
;
; CC65 runtime: integer complement
;
.export complax
complax:
eor #$FF ; Not A
pha
txa
eor #$FF ; Not X
tax
pla
rts

@ -0,0 +1,84 @@
;
; Ullrich von Bassewitz, 20.11.2000
;
; CC65 runtime: Support for calling module constructors/destructors
;
; The condes routine must be called with the table address in a/x and the
; size of the table (which must not be zero!) in y. The current implementation
; limits the table size to 254 bytes (127 vectors) but this shouldn't be
; problem for now and may be changed later.
;
; libinit and libdone call condes with the predefined module constructor and
; destructor tables, they must be called from the platform specific startup
; code.
.export initlib, donelib, condes
.import __CONSTRUCTOR_TABLE__, __CONSTRUCTOR_COUNT__
.import __DESTRUCTOR_TABLE__, __DESTRUCTOR_COUNT__
.macpack cpu
; --------------------------------------------------------------------------
; Initialize library modules
.segment "INIT"
.proc initlib
ldy #<(__CONSTRUCTOR_COUNT__*2)
beq exit
lda #<__CONSTRUCTOR_TABLE__
ldx #>__CONSTRUCTOR_TABLE__
jmp condes
exit: rts
.endproc
; --------------------------------------------------------------------------
; Cleanup library modules
.code
.proc donelib
ldy #<(__DESTRUCTOR_COUNT__*2)
beq exit
lda #<__DESTRUCTOR_TABLE__
ldx #>__DESTRUCTOR_TABLE__
jmp condes
exit: rts
.endproc
; --------------------------------------------------------------------------
; Generic table call handler. The code uses self modifying code and goes
; into the data segment for this reason.
; NOTE: The routine must not be called if the table is empty!
.data
.proc condes
sta fetch1+1
stx fetch1+2
sta fetch2+1
stx fetch2+2
loop: dey
fetch1: lda $FFFF,y ; Patched at runtime
sta jmpvec+2
dey
fetch2: lda $FFFF,y ; Patched at runtime
sta jmpvec+1
sty index+1
jmpvec: jsr $FFFF ; Patched at runtime
index: ldy #$FF ; Patched at runtime
bne loop
rts
.endproc

@ -0,0 +1,18 @@
;
; Ullrich von Bassewitz, 29.12.1999
;
; CC65 runtime: Decrement ax by 1
;
.export decax1
.macpack generic
.proc decax1
sub #1
bcs @L9
dex
@L9: rts
.endproc

@ -0,0 +1,18 @@
;
; Ullrich von Bassewitz, 29.12.1999
;
; CC65 runtime: Decrement ax by 2
;
.export decax2
.macpack generic
.proc decax2
sub #2
bcs @L9
dex
@L9: rts
.endproc

@ -0,0 +1,18 @@
;
; Ullrich von Bassewitz, 26.03.2001
;
; CC65 runtime: Decrement ax by 3
;
.export decax3
.macpack generic
.proc decax3
sub #3
bcs @L9
dex
@L9: rts
.endproc

@ -0,0 +1,18 @@
;
; Ullrich von Bassewitz, 26.03.2001
;
; CC65 runtime: Decrement ax by 4
;
.export decax4
.macpack generic
.proc decax4
sub #4
bcs @L9
dex
@L9: rts
.endproc

@ -0,0 +1,18 @@
;
; Ullrich von Bassewitz, 26.03.2001
;
; CC65 runtime: Decrement ax by 5
;
.export decax5
.macpack generic
.proc decax5
sub #5
bcs @L9
dex
@L9: rts
.endproc

@ -0,0 +1,18 @@
;
; Ullrich von Bassewitz, 26.03.2001
;
; CC65 runtime: Decrement ax by 6
;
.export decax6
.macpack generic
.proc decax6
sub #6
bcs @L9
dex
@L9: rts
.endproc

@ -0,0 +1,18 @@
;
; Ullrich von Bassewitz, 26.03.2001
;
; CC65 runtime: Decrement ax by 7
;
.export decax7
.macpack generic
.proc decax7
sub #7
bcs @L9
dex
@L9: rts
.endproc

@ -0,0 +1,18 @@
;
; Ullrich von Bassewitz, 26.03.2001
;
; CC65 runtime: Decrement ax by 8
;
.export decax8
.macpack generic
.proc decax8
sub #8
bcs @L9
dex
@L9: rts
.endproc

@ -0,0 +1,21 @@
;
; Ullrich von Bassewitz, 29.12.1999
;
; CC65 runtime: Decrement ax by value in Y
;
.export decaxy
.importzp tmp1
.macpack generic
.proc decaxy
sty tmp1
sub tmp1
bcs @L9
dex
@L9: rts
.endproc

@ -0,0 +1,23 @@
;
; Ullrich von Bassewitz, 25.10.2000
;
; CC65 runtime: Decrement the stackpointer by 1
;
.export decsp1
.importzp sp
.proc decsp1
ldy sp
bne @L1
dec sp+1
@L1: dec sp
rts
.endproc

@ -0,0 +1,27 @@
;
; Ullrich von Bassewitz, 25.10.2000
;
; CC65 runtime: Decrement the stackpointer by 2
;
.export decsp2
.importzp sp
.proc decsp2
lda sp
sec
sbc #2
sta sp
bcc @L1
rts
@L1: dec sp+1
rts
.endproc

@ -0,0 +1,27 @@
;
; Ullrich von Bassewitz, 25.10.2000
;
; CC65 runtime: Decrement the stackpointer by 3
;
.export decsp3
.importzp sp
.proc decsp3
lda sp
sec
sbc #3
sta sp
bcc @L1
rts
@L1: dec sp+1
rts
.endproc

@ -0,0 +1,27 @@
;
; Ullrich von Bassewitz, 25.10.2000
;
; CC65 runtime: Decrement the stackpointer by 4
;
.export decsp4
.importzp sp
.proc decsp4
lda sp
sec
sbc #4
sta sp
bcc @L1
rts
@L1: dec sp+1
rts
.endproc

@ -0,0 +1,27 @@
;
; Ullrich von Bassewitz, 25.10.2000
;
; CC65 runtime: Decrement the stackpointer by 5
;
.export decsp5
.importzp sp
.proc decsp5
lda sp
sec
sbc #5
sta sp
bcc @L1
rts
@L1: dec sp+1
rts
.endproc

@ -0,0 +1,27 @@
;
; Ullrich von Bassewitz, 25.10.2000
;
; CC65 runtime: Decrement the stackpointer by 6
;
.export decsp6
.importzp sp
.proc decsp6
lda sp
sec
sbc #6
sta sp
bcc @L1
rts
@L1: dec sp+1
rts
.endproc

@ -0,0 +1,25 @@
;
; Ullrich von Bassewitz, 25.10.2000
;
; CC65 runtime: Decrement the stackpointer by 7
;
.export decsp7
.importzp sp
.proc decsp7
lda sp
sec
sbc #7
sta sp
bcc @L1
rts
@L1: dec sp+1
rts
.endproc

@ -0,0 +1,27 @@
;
; Ullrich von Bassewitz, 25.10.2000
;
; CC65 runtime: Decrement the stackpointer by 8
;
.export decsp8
.importzp sp
.proc decsp8
lda sp
sec
sbc #8
sta sp
bcc @L1
rts
@L1: dec sp+1
rts
.endproc

@ -0,0 +1,37 @@
;
; Ullrich von Bassewitz, 07.08.1998
;
; CC65 runtime: division for signed ints
;
; When negating values, we will ignore the possibility here, that one of the
; values if $8000, in which case the negate will fail.
.export tosdiva0, tosdivax
.import popsargs, udiv16, negax
.importzp sreg, tmp1, tmp2
tosdiva0:
ldx #0
tosdivax:
jsr popsargs ; Get arguments from stack, adjust sign
jsr udiv16 ; Do the division
ldx sreg+1 ; Load high byte of result
; Adjust the sign of the result. tmp1 contains the high byte of the left
; operand, tmp2 contains the high byte of the right operand.
lda tmp1
eor tmp2
bpl Pos ; Jump if sign of result positive
; Result is negative
lda sreg ; Load low byte of result
jmp negax ; Adjust the sign
; Result is positive
Pos: lda sreg
rts

@ -0,0 +1,18 @@
;
; Ullrich von Bassewitz, 06.08.1998
;
; CC65 runtime: function prologue
;
.export enter
.importzp sp
enter: tya ; get arg size
ldy sp
bne L1
dec sp+1
L1: dec sp
ldy #0
sta (sp),y ; Store the arg count
rts

@ -0,0 +1,17 @@
;
; Ullrich von Bassewitz, 06.08.1998
;
; CC65 runtime: Compare == for ints
;
.export toseq00, toseqa0, toseqax
.import tosicmp, booleq
.importzp sp, tmp1
toseq00:
lda #$00
toseqa0:
ldx #$00
toseqax:
jsr tosicmp ; Set flags
jmp booleq ; Convert to boolean

@ -0,0 +1,17 @@
;
; Ullrich von Bassewitz, 06.08.1998
;
; CC65 runtime: Compare >= for signed ints
;
.export tosge00, tosgea0, tosgeax
.import tosicmp, boolge
tosge00:
lda #$00
tosgea0:
ldx #$00
tosgeax:
jsr tosicmp ; Set flags
jmp boolge ; Convert to boolean

@ -0,0 +1,18 @@
;
; Ullrich von Bassewitz, 06.08.1998
;
; CC65 runtime: Compare > for signed ints
;
.export tosgt00, tosgta0, tosgtax
.import tosicmp, boolgt
tosgt00:
lda #$00
tosgta0:
ldx #$00
tosgtax:
jsr tosicmp ; Set the flags
jmp boolgt ; Convert to boolean

@ -0,0 +1,47 @@
;
; Piotr Fusik, 15.04.2002
; originally by Ullrich von Bassewitz
;
; Integer compare function - used by the compare operators
;
.export tosicmp, tosicmp0
.importzp sp, sreg
tosicmp0:
ldx #$00
tosicmp:
sta sreg
stx sreg+1 ; Save ax
ldy #$00
lda (sp),y ; Get low byte
tax
inc sp ; 5
bne @L1 ; 3
inc sp+1 ; (5)
@L1:
lda (sp),y ; Get high byte
inc sp ; 5
bne @L2 ; 3
inc sp+1 ; (5)
; Do the compare.
@L2: sec
sbc sreg+1 ; Compare high byte
bne @L4
cpx sreg ; Compare low byte
beq @L3
adc #$FF ; If the C flag is set then clear the N flag
ora #$01 ; else set the N flag
@L3: rts
@L4: bvc @L3
eor #$FF ; Fix the N flag if overflow
ora #$01 ; Clear the Z flag
rts

@ -0,0 +1,24 @@
;
; Ullrich von Bassewitz, 05.08.1998
;
; CC65 runtime: Increment ax by 1
;
.export incax1
.macpack generic
.macpack cpu
.proc incax1
.if (.cpu .bitand ::CPU_ISET_65SC02)
ina ; 65C02 version
bne @L9
.else
add #1
bcc @L9
.endif
inx
@L9: rts
.endproc

@ -0,0 +1,18 @@
;
; Ullrich von Bassewitz, 05.08.1998
;
; CC65 runtime: Increment ax by 2
;
.export incax2
.macpack generic
.proc incax2
add #2
bcc @L9
inx
@L9: rts
.endproc

@ -0,0 +1,16 @@
;
; Ullrich von Bassewitz, 05.08.1998
;
; CC65 runtime: Increment ax by 3
;
.export incax3
.import incaxy
.proc incax3
ldy #3
jmp incaxy
.endproc

@ -0,0 +1,16 @@
;
; Ullrich von Bassewitz, 05.08.1998
;
; CC65 runtime: Increment ax by 5
;
.export incax5
.import incaxy
.proc incax5
ldy #5
jmp incaxy
.endproc

@ -0,0 +1,16 @@
;
; Ullrich von Bassewitz, 05.08.1998
;
; CC65 runtime: Increment ax by 6
;
.export incax6
.import incaxy
.proc incax6
ldy #6
jmp incaxy
.endproc

@ -0,0 +1,16 @@
;
; Ullrich von Bassewitz, 05.08.1998
;
; CC65 runtime: Increment ax by 7
;
.export incax7
.import incaxy
.proc incax7
ldy #7
jmp incaxy
.endproc

@ -0,0 +1,16 @@
;
; Ullrich von Bassewitz, 05.08.1998
;
; CC65 runtime: Increment ax by 8
;
.export incax8
.import incaxy
.proc incax8
ldy #8
jmp incaxy
.endproc

@ -0,0 +1,17 @@
;
; Ullrich von Bassewitz, 05.08.1998
;
; CC65 runtime: Increment ax by valie in y
;
.export incaxy, incax4
.importzp tmp1
.macpack generic
incax4: ldy #4
incaxy: sty tmp1
add tmp1
bcc @L9
inx
@L9: rts

@ -0,0 +1,22 @@
;
; Ullrich von Bassewitz, 25.10.2000
;
; CC65 runtime: Increment the stackpointer by 1
;
.export incsp1
.importzp sp
.proc incsp1
inc sp
bne @L1
inc sp+1
@L1: rts
.endproc

@ -0,0 +1,47 @@
;
; Ullrich von Bassewitz, 25.10.2000
;
; CC65 runtime: Increment the stackpointer by 2. For performance reasons,
; this modules does also contain the popax function.
.export popax, incsp2
.importzp sp
.macpack cpu
; Pop a/x from stack. This function will run directly into incsp2
.proc popax
ldy #1
lda (sp),y ; get hi byte
tax ; into x
.if (.cpu .bitand ::CPU_ISET_65SC02)
lda (sp) ; get lo byte
.else
dey
lda (sp),y ; get lo byte
.endif
.endproc
.proc incsp2
inc sp ; 5
beq @L1 ; 2
inc sp ; 5
beq @L2 ; 2
rts
@L1: inc sp ; 5
@L2: inc sp+1 ; 5
rts
.endproc

@ -0,0 +1,20 @@
;
; Ullrich von Bassewitz, 25.10.2000
;
; CC65 runtime: Increment the stackpointer by 3
;
.export incsp3
.import addysp
.proc incsp3
ldy #3
jmp addysp
.endproc

@ -0,0 +1,20 @@
;
; Ullrich von Bassewitz, 25.10.2000
;
; CC65 runtime: Increment the stackpointer by 4
;
.export incsp4
.import addysp
.proc incsp4
ldy #4
jmp addysp
.endproc

@ -0,0 +1,20 @@
;
; Ullrich von Bassewitz, 25.10.2000
;
; CC65 runtime: Increment the stackpointer by 5
;
.export incsp5
.import addysp
.proc incsp5
ldy #5
jmp addysp
.endproc

@ -0,0 +1,20 @@
;
; Ullrich von Bassewitz, 25.10.2000
;
; CC65 runtime: Increment the stackpointer by 6
;
.export incsp6
.import addysp
.proc incsp6
ldy #6
jmp addysp
.endproc

@ -0,0 +1,20 @@
;
; Ullrich von Bassewitz, 25.10.2000
;
; CC65 runtime: Increment the stackpointer by 7
;
.export incsp7
.import addysp
.proc incsp7
ldy #7
jmp addysp
.endproc

@ -0,0 +1,17 @@
;
; Ullrich von Bassewitz, 25.10.2000
;
; CC65 runtime: Increment the stackpointer by 8
;
.export incsp8
.import addysp
.proc incsp8
ldy #8
jmp addysp
.endproc

@ -0,0 +1,14 @@
;
; Ullrich von Bassewitz, 2002-12-26
;
; CC65 runtime: Jump vector that resides in the data segment so it's address
; may be patched at runtime.
;
.export jmpvec
.data
jmpvec: jmp $FFFF

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save