📄 s1mp3_crt0.asm
字号:
; Startup Code for Embedded Targets
;
; Daniel Wallner March 2002
;
; $Id: crt0.asm,v 1.3 2005/12/13 18:44:26 aaron Exp $
;
; 02/03/2006 01:44 fc: code length is now fixed by conv.exe
; added support for floating points.
; added support for heap (due to the fp support).
;-------
; Some general scope declarations
;-------
XREF _main ;main() is always external to crt0 code
;XREF ram_start
;-------------------------------------------------------------------------------
; definitions
;-------------------------------------------------------------------------------
DEFC Header_Length = 0x0600
DEFC Application_Start = Header_Length
DEFC Stack_Top = 0x8000 ; Stack starts at 0x8000
DEFC Stack_Size = 0x0800 ; 2k of stack
DEFC HEAP_Start = (Stack_Top - Stack_Size * 2) ; Heap starts at 0x7000
DEFC HEAP_Length = Stack_Size ; 2k of heap
MODULE crt0
.header
DEFW 0x0050 ; header id
DEFW 0x4757 ;
DEFW 0x9719 ;
DEFW 0x0003 ;
DEFW Header_Length ; text fileoffset (lo)
DEFW 0 ; text fileoffset (hi)
DEFW 0 ; Entry point (will be fixed by conv.exe)
DEFW Application_Start ; text address
DEFW 0 ; data fileoffset (lo)
DEFW 0 ; data fileoffset (hi)
DEFW 0 ; data length
DEFW 0 ; data address
DEFW 0 ; bss length
DEFW 0 ; bss address
DEFW start ; entry point
DEFB 0 ; entry bank
DEFB 0 ; number of banks
DEFS (Header_Length - ASMPC)
;-------------------------------------------------------------------------------
; code segment
;-------------------------------------------------------------------------------
.start ;push bc
;push de
; Switch all interrupts off
di
xor a
out (0x27), a ; MINT_ENABLE_REG
ld hl, Stack_Top
ld sp, hl
; Clear heap memory
ld hl, HEAP_Start
ld de, HEAP_Start + 1
ld bc, HEAP_Length - 1
ld (hl), 0
ldir
; Save the stack for exit()
ld (exitsp),sp
;;IF !DEFINED_nostreams
;;IF DEFINED_ANSIstdio
;; Set up the std* stuff so we can be called again
;; ld hl,__sgoioblk+2
;; ld (hl),19 ;stdin
;; ld hl,__sgoioblk+6
;; ld (hl),21 ;stdout
;; ld hl,__sgoioblk+10
;; ld (hl),21 ;stderr
;;ENDIF
;;ENDIF
;; ld hl,$8080
;; ld (fp_seed),hl
;; xor a
;; ld (exitcount),a
; Entry to the user code
call _main
.cleanup
;pop af
;pop bc
; pop de
; pop bc
;ex de, hl
;ex (sp), hl
;ex de, hl
;push hl
;ld hl, 0x1008
;rst 0x10
;pop hl
;pop de
ret
;
; Deallocate memory which has been allocated here!
;
; push hl
;IF !DEFINED_nostreams
;IF DEFINED_ANSIstdio
;LIB closeall
; call closeall
;ENDIF
;ENDIF
;.endloop
; jr endloop
;.l_dcal
; jp (hl)
;---------------------------------
; Select which printf core we want
;---------------------------------
._vfprintf
;IF DEFINED_floatstdio
; LIB vfprintf_fp
; jp vfprintf_fp
;ELSE
; IF DEFINED_complexstdio
; LIB vfprintf_comp
; jp vfprintf_comp
; ELSE
; IF DEFINED_ministdio
; LIB vfprintf_mini
; jp vfprintf_mini
; ENDIF
; ENDIF
;ENDIF
; Static variables kept in safe workspace
DEFVARS HEAP_Start
{
__sgoioblk ds.b 40 ;stdio control block
int_seed ds.w 1 ;Integer seed
oldsp ds.w 1
exitsp ds.w 1 ;atexit() stack
exitcount ds.b 1 ;Number of atexit() routines
fp_seed ds.w 3 ;Floating point seed (not used ATM)
extra ds.w 3 ;Floating point spare register
fa ds.w 3 ;Floating point accumulator
fasign ds.b 1 ;Floating point variable
heapblocks ds.w 1 ;Number of free blocks
heaplast ds.w 1 ;Pointer to linked blocks
}
;--------
; Now, include the math routines if needed..
;--------
;IF NEED_floatpack
INCLUDE "#float.asm"
;ENDIF
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -