Skip to content

Commit

Permalink
[NFC] Use .zeropage directive throughout SDK.
Browse files Browse the repository at this point in the history
  • Loading branch information
mysterymath committed Dec 9, 2022
1 parent c851b3f commit f795a2f
Show file tree
Hide file tree
Showing 41 changed files with 634 additions and 548 deletions.
1 change: 1 addition & 0 deletions mos-platform/atari8/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ merge_libraries(atari8-crt0
common-zero-bss
common-exit-return
)
target_link_libraries(atari8-crt0 PRIVATE common-asminc)

add_platform_library(atari8-c
abort.c
Expand Down
6 changes: 4 additions & 2 deletions mos-platform/atari8/init-stack.S
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
.include "imag.inc"

.global __do_init_stack

; Initialize soft stack pointer to MEMTOP
.section .init.100,"axR",@progbits
__do_init_stack:
lda $2e5
sta mos8(__rc0)
sta __rc0
lda $2e6
sta mos8(__rc1)
sta __rc1
1 change: 1 addition & 0 deletions mos-platform/commodore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ add_platform_library(commodore-c
# unneccessarily. It can also be called in an interrupt.
set_property(SOURCE abort.c PROPERTY COMPILE_OPTIONS -fno-lto -fno-static-stack)
target_include_directories(commodore-c BEFORE PUBLIC .)
target_link_libraries(commodore-c PRIVATE common-asminc)
24 changes: 13 additions & 11 deletions mos-platform/commodore/cbm_k_iobase.s
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
.text

;
; unsigned cbm_k_iobase (void);
;
.global cbm_k_iobase
jsr __IOBASE
txa
sty __rc2
ldx __rc2
rts
.include "imag.inc"

.text

;
; unsigned cbm_k_iobase (void);
;
.global cbm_k_iobase
jsr __IOBASE
txa
sty __rc2
ldx __rc2
rts

20 changes: 11 additions & 9 deletions mos-platform/commodore/cbm_k_load.s
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
.text

;
; unsigned int cbm_k_load(unsigned char flag, unsigned addr);
;
.global cbm_k_load
cbm_k_load:
ldy __rc2
jmp __LOAD
.include "imag.inc"

.text

;
; unsigned int cbm_k_load(unsigned char flag, unsigned addr);
;
.global cbm_k_load
cbm_k_load:
ldy __rc2
jmp __LOAD
31 changes: 14 additions & 17 deletions mos-platform/commodore/cbm_k_save.s
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
.text

__rs1 = __rc2
__rs2 = __rc4

;
; unsigned char cbm_k_save(unsigned int start, unsigned int end);
;
.global cbm_k_save
cbm_k_save:
sta __rs2
stx __rs2 + 1
ldx __rc2
ldy __rc2 + 1
lda #__rs2
jmp __SAVE

.include "imag.inc"
.text

;
; unsigned char cbm_k_save(unsigned int start, unsigned int end);
;
.global cbm_k_save
cbm_k_save:
sta __rc4
stx __rc5
ldx __rc2
ldy __rc3
lda #__rc4
jmp __SAVE
20 changes: 11 additions & 9 deletions mos-platform/commodore/cbm_k_setlfs.s
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
.text

;
; void cbm_k_setlfs (unsigned char LFN, unsigned char DEV, unsigned char SA);
;
.global cbm_k_setlfs
cbm_k_setlfs:
ldy __rc2
jmp __SETLFS
.include "imag.inc"

.text

;
; void cbm_k_setlfs (unsigned char LFN, unsigned char DEV, unsigned char SA);
;
.global cbm_k_setlfs
cbm_k_setlfs:
ldy __rc2
jmp __SETLFS
42 changes: 21 additions & 21 deletions mos-platform/commodore/cbm_k_setnam.s
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
.text

__rs1 = __rc2

;
; void cbm_k_setnam (const char* Name);
;
.global cbm_k_setnam
cbm_k_setnam:
lda __rs1
pha
lda __rs1 + 1
pha
jsr strlen
sta __rc2
pla
tay
pla
tax
lda __rc2
jmp __SETNAM
.include "imag.inc"

.text

;
; void cbm_k_setnam (const char* Name);
;
.global cbm_k_setnam
cbm_k_setnam:
lda __rc2
pha
lda __rc3
pha
jsr strlen
sta __rc2
pla
tay
pla
tax
lda __rc2
jmp __SETNAM
1 change: 1 addition & 0 deletions mos-platform/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ install(DIRECTORY ${INCLUDE_DIR}/ TYPE INCLUDE)
# Math library; just a stub for now.
add_platform_library(common-m)

add_subdirectory(asminc)
add_subdirectory(crt0)
add_subdirectory(crt)
add_subdirectory(c)
Expand Down
3 changes: 3 additions & 0 deletions mos-platform/common/asminc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_library(common-asminc INTERFACE)
target_include_directories(common-asminc BEFORE INTERFACE .)
install(FILES imag.inc DESTINATION ${ASMINCDIR})
4 changes: 4 additions & 0 deletions mos-platform/common/asminc/imag.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.zeropage __rc0, __rc1, __rc2, __rc3, __rc4, __rc5, __rc6, __rc7, __rc8, __rc9
.zeropage __rc10, __rc11, __rc12, __rc13, __rc14, __rc15, __rc16, __rc17, __rc18
.zeropage __rc19, __rc20, __rc21, __rc22, __rc23, __rc24, __rc25, __rc26, __rc27
.zeropage __rc28, __rc29, __rc30, __rc31
1 change: 1 addition & 0 deletions mos-platform/common/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ set_property(SOURCE printf.c PROPERTY COMPILE_DEFINITIONS
PRINTF_DISABLE_SUPPORT_EXPONENTIAL
)
target_include_directories(common-c SYSTEM BEFORE PUBLIC ${INCLUDE_DIR})
target_link_libraries(common-c PRIVATE common-asminc)
74 changes: 38 additions & 36 deletions mos-platform/common/c/setjmp.S
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.include "imag.inc"

.section .text.setjmp
.global setjmp
setjmp:
Expand All @@ -16,54 +18,54 @@ setjmp:
sta (__rc2),y

; Save soft stack pointer
lda mos8(__rc0)
lda __rc0
iny
sta (__rc2),y
lda mos8(__rc1)
lda __rc1
iny
sta (__rc2),y

; Save CSRs
lda mos8(__rc18)
lda __rc18
iny
sta (__rc2),y
lda mos8(__rc19)
lda __rc19
iny
sta (__rc2),y
lda mos8(__rc20)
lda __rc20
iny
sta (__rc2),y
lda mos8(__rc21)
lda __rc21
iny
sta (__rc2),y
lda mos8(__rc22)
lda __rc22
iny
sta (__rc2),y
lda mos8(__rc23)
lda __rc23
iny
sta (__rc2),y
lda mos8(__rc24)
lda __rc24
iny
sta (__rc2),y
lda mos8(__rc25)
lda __rc25
iny
sta (__rc2),y
lda mos8(__rc26)
lda __rc26
iny
sta (__rc2),y
lda mos8(__rc27)
lda __rc27
iny
sta (__rc2),y
lda mos8(__rc28)
lda __rc28
iny
sta (__rc2),y
lda mos8(__rc29)
lda __rc29
iny
sta (__rc2),y
lda mos8(__rc30)
lda __rc30
iny
sta (__rc2),y
lda mos8(__rc31)
lda __rc31
iny
sta (__rc2),y

Expand All @@ -76,60 +78,60 @@ setjmp:
.global longjmp
longjmp:
; Save return value
sta mos8(__rc16)
stx mos8(__rc17)
sta __rc16
stx __rc17

; Restore CSRs
ldy #18
lda (__rc2),y
sta mos8(__rc31)
sta __rc31
dey
lda (__rc2),y
sta mos8(__rc30)
sta __rc30
dey
lda (__rc2),y
sta mos8(__rc29)
sta __rc29
dey
lda (__rc2),y
sta mos8(__rc28)
sta __rc28
dey
lda (__rc2),y
sta mos8(__rc27)
sta __rc27
dey
lda (__rc2),y
sta mos8(__rc26)
sta __rc26
dey
lda (__rc2),y
sta mos8(__rc25)
sta __rc25
dey
lda (__rc2),y
sta mos8(__rc24)
sta __rc24
dey
lda (__rc2),y
sta mos8(__rc23)
sta __rc23
dey
lda (__rc2),y
sta mos8(__rc22)
sta __rc22
dey
lda (__rc2),y
sta mos8(__rc21)
sta __rc21
dey
lda (__rc2),y
sta mos8(__rc20)
sta __rc20
dey
lda (__rc2),y
sta mos8(__rc19)
sta __rc19
dey
lda (__rc2),y
sta mos8(__rc18)
sta __rc18

; Restore soft stack pointer
dey
lda (__rc2),y
sta mos8(__rc1)
sta __rc1
dey
lda (__rc2),y
sta mos8(__rc0)
sta __rc0

; Restore hard stack pointer
dey
Expand All @@ -146,7 +148,7 @@ longjmp:
sta $101,x

; Restore return value
lda mos8(__rc16)
ldx mos8(__rc17)
lda __rc16
ldx __rc17

rts
1 change: 1 addition & 0 deletions mos-platform/common/crt0/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ merge_libraries(common-copy-data common-copy-zp-data)

# Initialize the soft stack pointer to __stack.
add_platform_library(common-init-stack init-stack.S)
target_link_libraries(common-init-stack PRIVATE common-asminc)

add_subdirectory(exit)
6 changes: 4 additions & 2 deletions mos-platform/common/crt0/init-stack.S
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
.include "imag.inc"

.global __do_init_stack

; Initialze soft stack pointer from __stack symbol.
.section .init.100,"axR",@progbits
__do_init_stack:
lda #mos16lo(__stack)
sta mos8(__rc0)
sta __rc0
lda #mos16hi(__stack)
sta mos8(__rc1)
sta __rc1
2 changes: 2 additions & 0 deletions mos-platform/dodo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ endif()
install(FILES api.h TYPE INCLUDE)

add_platform_object_file(dodo-crt0-o crt0.o crt0.s)
target_link_libraries(dodo-crt0-o PRIVATE common-asminc)

add_platform_library(dodo-crt0)
merge_libraries(dodo-crt0
Expand All @@ -20,6 +21,7 @@ add_platform_library(dodo-c api.s)
merge_libraries(dodo-c
common-c
)
target_link_libraries(dodo-c PRIVATE common-asminc)

target_include_directories(dodo-c SYSTEM BEFORE PUBLIC .)
target_compile_options(dodo-c PUBLIC -mcpu=mos65c02)
Loading

0 comments on commit f795a2f

Please sign in to comment.