TK2048/src/tk2k_startup.s

105 lines
No EOL
3.6 KiB
ArmAsm

.rtmodel cstartup,"tk2k"
.rtmodel version, "1"
.rtmodel core, "*"
;; External declarations
.section cstack
.section heap
.section data_init_table
.section registers ; pseudo registers in zero page
.extern main, exit, __low_level_init
.extern _Zp, _Vsp, _Vfp
.pubweak __program_root_section, __program_start
call: .macro dest
jsr \dest
.endm
.section programStart, root
__program_root_section:
.word nextLine
.byte 0x0a, 0x00 ; 10
.byte 0x8c, 0x32, 0x30, 0x36, 0x32, 0x00 ; CALL 2062
nextLine: .byte 0x00, 0x00 ; end of program
.section startup, root, noreorder
__program_start:
.section startup, noreorder
jsr __low_level_init
;;; Initialize data sections if needed.
.section startup, noroot, noreorder
.pubweak __data_initialization_needed
.extern __initialize_sections
__data_initialization_needed:
lda #.byte0 (.sectionStart data_init_table)
sta zp:_Zp
lda #.byte1 (.sectionStart data_init_table)
sta zp:_Zp+1
lda #.byte0 (.sectionEnd data_init_table)
sta zp:_Zp+2
lda #.byte1 (.sectionEnd data_init_table)
sta zp:_Zp+3
call __initialize_sections
.section startup, noroot, noreorder
.pubweak __call_initialize_global_streams
.extern __initialize_global_streams
__call_initialize_global_streams:
call __initialize_global_streams
;;; **** Initialize heap if needed.
.section startup, noroot, noreorder
.pubweak __call_heap_initialize
.extern __heap_initialize, __default_heap
__call_heap_initialize:
lda #.byte0 __default_heap
sta zp:_Zp+0
lda #.byte1 __default_heap
sta zp:_Zp+1
lda #.byte0 (.sectionStart heap)
sta zp:_Zp+2
lda #.byte1 (.sectionStart heap)
sta zp:_Zp+3
lda #.byte0 (.sectionSize heap)
sta zp:_Zp+4
lda #.byte1 (.sectionSize heap)
sta zp:_Zp+5
call __heap_initialize
.section startup, root, noreorder
tsx
stx _InitialStack ; for exit()
lda #0 ; argc = 0
sta zp:_Zp
sta zp:_Zp+1
jsr main
jmp exit
;;; ***************************************************************************
;;;
;;; __low_level_init - custom low level initialization
;;;
;;; This default routine just returns doing nothing. You can provide your own
;;; routine, either in C or assembly for doing custom low leve initialization.
;;;
;;; ***************************************************************************
.section code
.pubweak __low_level_init
__low_level_init:
rts
;;; ***************************************************************************
;;;
;;; Keep track of the initial stack pointer so that it can be restores to make
;;; a return back on exit().
;;;
;;; ***************************************************************************
.section zdata, bss
.pubweak _InitialStack
_InitialStack:
.space 1