                              1 ; /*-------------------------------------------------------------------------
                              2 ;
                              3 ;   crtxinit.asm :- C run-time: copy XINIT to XISEG
                              4 ;
                              5 ;    This library is free software; you can redistribute it and/or modify it
                              6 ;    under the terms of the GNU Library General Public License as published by the
                              7 ;    Free Software Foundation; either version 2, or (at your option) any
                              8 ;    later version.
                              9 ;
                             10 ;    This library is distributed in the hope that it will be useful,
                             11 ;    but WITHOUT ANY WARRANTY; without even the implied warranty of
                             12 ;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                             13 ;    GNU Library General Public License for more details.
                             14 ;
                             15 ;    You should have received a copy of the GNU Library General Public License
                             16 ;    along with this program; if not, write to the Free Software
                             17 ;    Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
                             18 ;
                             19 ;    In other words, you are welcome to use, share and improve this program.
                             20 ;    You are forbidden to forbid anyone else to use, share and improve
                             21 ;    what you give them.   Help stamp out software-hoarding!
                             22 ; -------------------------------------------------------------------------*/
                             23 
                             24 ; Set DUAL_DPTR to 1 and reassemble if your derivative has dual data pointers
                             25 ; Especially useful if movx @Ri cannot go beyond the first 256 bytes of xdata
                             26 ; due to lack of P2 or _XPAGE
                             27 ; If the derivative has auto-toggle or auto-increment it can be further optimized
                    0000     28 	DUAL_DPTR = 0
                             29 
                             30 	.area CSEG    (CODE)
                             31 	.area GSINIT0 (CODE)
                             32 	.area GSINIT1 (CODE)
                             33 	.area GSINIT2 (CODE)
                             34 	.area GSINIT3 (CODE)
                             35 	.area GSINIT4 (CODE)
                             36 	.area GSINIT5 (CODE)
                             37 	.area GSINIT  (CODE)
                             38 	.area GSFINAL (CODE)
                             39 
                             40 	.area GSINIT3 (CODE)
                             41 
                    0000     42 	.if DUAL_DPTR
                             43 
                             44 	.globl _DPS			; assume DPSEL is in DPS bit0
                             45 
                             46 __mcs51_genXINIT::
                             47 	mov	r1,#l_XINIT
                             48 	mov	a,r1
                             49 	orl	a,#(l_XINIT >> 8)
                             50 	jz	00003$
                             51 	mov	r2,#((l_XINIT+255) >> 8)
                             52 	orl	_DPS,#0x01		; set DPSEL, select DPTR1
                             53 	mov	dptr,#s_XINIT		; DPTR1 for code
                             54 	dec	_DPS			; clear DPSEL, select DPTR0
                             55 	mov	dptr,#s_XISEG		; DPTR0 for xdata
                             56 00001$:	clr	a
                             57 	inc	_DPS			; set DPSEL, select DPTR1
                             58 	movc	a,@a+dptr
                             59 	inc	dptr
                             60 	dec	_DPS			; clear DPSEL, select DPTR0
                             61 	movx	@dptr,a
                             62 	inc	dptr
                             63 	djnz	r1,00001$
                             64 	djnz	r2,00001$
                             65 00003$:
                             66 
                             67 	.else
                             68 
                             69 	.globl __XPAGE
                             70 
   0000                      71 __mcs51_genXINIT::
   0000 79r00                72 	mov	r1,#l_XINIT
   0002 E9                   73 	mov	a,r1
   0003 44s00                74 	orl	a,#(l_XINIT >> 8)
   0005 60 1B                75 	jz	00003$
   0007 7As00                76 	mov	r2,#((l_XINIT+255) >> 8)
   0009 90s00r00             77 	mov	dptr,#s_XINIT
   000C 78r00                78 	mov	r0,#s_XISEG
   000E 75*00s00             79 	mov	__XPAGE,#(s_XISEG >> 8)
   0011 E4                   80 00001$:	clr	a
   0012 93                   81 	movc	a,@a+dptr
   0013 F2                   82 	movx	@r0,a
   0014 A3                   83 	inc	dptr
   0015 08                   84 	inc	r0
   0016 B8 00 02             85 	cjne	r0,#0,00002$
   0019 05*00                86 	inc	__XPAGE
   001B D9 F4                87 00002$:	djnz	r1,00001$
   001D DA F2                88 	djnz	r2,00001$
   001F 75*00 FF             89 	mov	__XPAGE,#0xFF
   0022                      90 00003$:
                             91 
                             92 	.endif
