diff os9/mc09/crtos9.asm @ 105:6eef99bb4771

fix runtime
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 29 Dec 2018 12:25:26 +0900
parents 096b3fc7aa66
children 613615c9b946
line wrap: on
line diff
--- a/os9/mc09/crtos9.asm	Fri Dec 28 17:43:55 2018 +0900
+++ b/os9/mc09/crtos9.asm	Sat Dec 29 12:25:26 2018 +0900
@@ -31,14 +31,42 @@
         pshs    x,y             POINT TO CONTENT OF ARGUMENT VECTOR
         leay    ,u 
 	PSHS	Y
+        leay    _GLOBALS,y
+        sty     heapp,y
+
+*       allocate memory and change stack
+*       try to allocate maximum memory if not specified
+    ifndef  __MEMSIZ
+        LDD     #(1024*48) 
+    else
+        LDD     #__MEMSIZ
+    endif
+        pshs     d
+__0C004
+        os9      F$Mem
+        bcc     __0C005
+        ldd      ,s
+        subd     #$1000
+        blo      exit           can't get any memroy
+        std      ,s
+        bra     __0C004
+__0C005
+*       y is heap upper bound
+*  copy saved arg into new stack
+*  and change the stack
+        leax    ,y
+        ldy     2,s
+        ldd     4,s
+        std     ,--x
+        ldd     6,s
+        std     ,--x
+        leas    ,x
 *                         	clear globals on Y
-	LDX	#_GLOBALS
-_0C002	BEQ	_0C003
-	CLR	,Y+
-	LEAX	-1,X
-	BRA	_0C002
-
-_0C003	PULS	Y
+	LDD	#_GLOBALS
+_0C002	CLR	D,Y
+        subd     #1
+	BNE	_0C002
+_0C003	
 	LBSR	_INITIALIZE	call initializer
 	LBSR	_main
 exit	clrb
@@ -68,6 +96,7 @@
 	ADDA	5,S
 	
 	LEAS	6,S
+initheap
 	RTS
 *
 _00002	CLR	,-S		signed divide