Blame | Last modification | View Log | Download | RSS feed
;; $Id: Cstartup.s01 1.24 2001/01/04 12:19:06 IPEO Exp $;;----------------------------------------------------------;; ;; CSTARTUP.S01 ;; ;; This file contains the Z80/HD64180 C startup routine ;; and must usually be tailored to suit customer's hardware.;; ;; Version: 4.00 [ 28/Apr/94 IJAR] ;;----------------------------------------------------------;#define proc64180 ((__TID__&0x010)==0x010)NAME CSTARTUPEXTERN main ; where to begin executionEXTERN ?C_EXIT ; where to go when program is done#ifdef banking#if proc64180CBAR_addr EQU 3AH ; define I/O ports to MMU registersCBR_addr EQU 38H ; (See also defines in debug.s01 and l08.s01)EXTERN CBAR_valueEXTERN CBR_value#endifEXTERN ?BANK_CALL_DIRECT_L08#endif;---------------------------------------------------------------;; CSTACK - The C stack segment ;; ;; Please, see in the link file lnk*.xcl how to increment ;; the stack size without having to reassemble cstartup.s01 ! ;;---------------------------------------------------------------;RSEG CSTACKDEFS 0 ; a bare minimum !;---------------------------------------------------------------;; Forward declarations of segment used during initialization ;;---------------------------------------------------------------;RSEG UDATA0RSEG IDATA0RSEG ECSTRRSEG TEMPRSEG DATA0RSEG WCSTRRSEG CDATA0RSEG CCSTRRSEG CONSTRSEG CSTRASEGORG 0x6000init_ADIJP init_C;---------------------------------------------------------------;; RCODE - where the execution actually begins ;;---------------------------------------------------------------;RSEG RCODEinit_CLD SP,.SFE.(CSTACK-1) ; from high to low address;---------------------------------------------------------------;; If hardware must be initiated from assembly or if interrupts ;; should be on when reaching main, this is the place to insert ;; such code. ;;---------------------------------------------------------------;#ifdef banking#if proc64180;---------------------------------------------------------------;; Setting of MMU registers - see chapter "Linking" of manual. ;;---------------------------------------------------------------;LD A,CBAR_value ; set CBAR valueOUT0 (CBAR_addr),ALD A,CBR_value ; set CBR valueOUT0 (CBR_addr),A#endif#endif;---------------------------------------------------------------;; If it is not a requirement that static/global data is set ;; to zero or to some explicit value at startup, the following ;; line refering to seg_init can be deleted, or commented. ;;---------------------------------------------------------------;CALL seg_init#ifdef bankingLD HL,LWRD(main) ; banked call to main()LD A,BYTE3(main)CALL ?BANK_CALL_DIRECT_L08#elseCALL main ; non-banked call to main()#endif;---------------------------------------------------------------;; Now when we are ready with our C program we must perform a ;; system-dependent action. In this case we just stop. ;;---------------------------------------------------------------;; DO NOT CHANGE THE NEXT LINE OF CSTARTUP IF YOU WANT TO RUN ;; YOUR SOFTWARE WITH THE HELP OF THE C-SPY HLL DEBUGGER. ;;---------------------------------------------------------------;JP ?C_EXIT;---------------------------------------------------------------;; Copy initialized PROMmed code to shadow RAM and clear ;; uninitialized variables. ;;---------------------------------------------------------------;seg_init;---------------------------------------;; Zero out UDATA0 ;;---------------------------------------;LD HL,.SFE.(UDATA0)LD DE,.SFB.(UDATA0)CALL zero_mem;---------------------------------------;; Copy CDATA0 into IDATA0 ;;---------------------------------------;LD DE,.SFB.(IDATA0) ;destination addressLD HL,.SFE.(CDATA0)LD BC,.SFB.(CDATA0)CALL copy_mem;---------------------------------------;; Copy CCSTR into ECSTR ;;---------------------------------------;LD DE,.SFB.(ECSTR) ;destination addressLD HL,.SFE.(CCSTR)LD BC,.SFB.(CCSTR); Just fall in to the copy_mem function;---------------------------------------;; Copy memory ;;---------------------------------------;copy_memXOR ASBC HL,BCPUSH BCLD C,LLD B,H ; BC - that many bytesPOP HL ; source addressRET Z ; If block size = 0 return nowLDIRRET;---------------------------------------;; Clear memory ;;---------------------------------------;zero_memXOR Aagain PUSH HLSBC HL,DEPOP HLRET ZLD (DE),AINC DEJR again;---------------------------------------------------------------;; Interrupt vectors must be inserted here by the user. ;;---------------------------------------------------------------;COMMON INTVECENDMOD init_A;---------------------------------------------------------------;; Function/module: exit (int code) ;; ;; When C-SPY is used this code will automatically be replaced ;; by a 'debug' version of exit(). ;;---------------------------------------------------------------;MODULE exitPUBLIC exitPUBLIC ?C_EXITRSEG RCODE?C_EXITexit EQU ?C_EXIT;--------------------------------------------------------------;; The next line can be replaced by user defined code. ;;--------------------------------------------------------------;NOPJR $ ; loop foreverEND