	NOLIST
; ---------------------------------------------------------------------------
;   idata.S - routine for 8 bit multiplication

;   Copyright (C) 2005, Raphael Neider <rneider AT web.de>

;   This library is free software; you can redistribute it and/or modify it
;   under the terms of the GNU General Public License as published by the
;   Free Software Foundation; either version 2, or (at your option) any
;   later version.

;   This library is distributed in the hope that it will be useful,
;   but WITHOUT ANY WARRANTY; without even the implied warranty of
;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;   GNU General Public License for more details.
;
;   You should have received a copy of the GNU General Public License 
;   along with this library; see the file COPYING. If not, write to the
;   Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
;   MA 02110-1301, USA.

;   As a special exception, if you link this library with other files,
;   some of which are compiled with SDCC, to produce an executable,
;   this library does not by itself cause the resulting executable to
;   be covered by the GNU General Public License. This exception does
;   not however invalidate any other reasons why the executable file
;   might be covered by the GNU General Public License.
;-------------------------------------------------------------------------

include macros_a.inc     
include mc8x_common.inc

	global	__zccc_gsinit_startup
	extern	_main
	extern	_cinit
	
ID_idata_0	idata
_force_cinit	db	0x00
	
	CODE
	
__zccc_gsinit_startup:   
;       num = cinit.records;
	MOVIA   (_cinit + 0)
	MOVAR   STK01
	MOVIA   high (_cinit + 0)
	MOVAR   STK00
	ACALL   __codeptrget2
	MOVAR   STK11
	MOVR    STK00,0
	MOVAR   STK10
;       cptr = &cinit.entry[0];
	MOVIA   (_cinit + 2)
	MOVAR   STK04
	MOVIA   high (_cinit + 2)
	MOVAR   STK05
	
__datanumloop:
;       while (num--) {
	MOVR    STK10,0
	ORAR    STK11,0
	JBTS0   _STATUS,2
	AGOTO   __returnmain
	MOVIA   0xff
	ADDAR   STK10,1
	JBTS1   _STATUS,0
	DECR    STK11,1
;       size = cptr->size;
	MOVIA   0x04
	ADDAR   STK04,0
	MOVAR   STK01
	CLRR    STK00
	RLR     STK00,1
	MOVR    STK05,0
	ADDAR   STK00,1
	ACALL   __codeptrget2
	MOVAR   STK06
	MOVR    STK00,0
	MOVAR   STK07
;       src = (__code char *) cptr->src;
	MOVR    STK04,0
	MOVAR   STK01
	MOVR    STK05,0
	MOVAR   STK00
	ACALL   __codeptrget2
	MOVAR   STK08
	MOVR    STK00,0
	MOVAR   STK09
;       dst = (__data char *) cptr->dst;
	MOVIA   0x02
	ADDAR   STK04,0
	MOVAR   STK01
	CLRR    STK00
	RLR     STK00,1
	MOVR    STK05,0
	ADDAR   STK00,1
	ACALL   __codeptrget2
	
__datasizeloop:
;       while (size--) {
	MOVR    STK07,0
	ORAR    STK06,0
	JBTS0   _STATUS,2
	AGOTO   __datacptradd
	MOVIA   0xff
	ADDAR   STK07,1
	JBTS1   _STATUS,0
	DECR    STK06,1
;       *dst = *src;
	MOVR    STK09,0
	MOVAR   STK01
	MOVR    STK08,0
	MOVAR   STK00
	ACALL   __codeptrget1
	MOVAR   STK00
	MOVR    STK03,0
	MOVAR   _BSR1
	MOVR    STK02,0	
	MOVAR   _FSR1
	MOVR    STK00,0
	MOVAR   _INDF1
;       src++;
	INCR    STK09,1
	JBTS0   _STATUS,2
	INCR    STK08,1
;       dst++;
	INCR    STK02,1
	JBTS0   _STATUS,2
	INCR    STK03,1
	AGOTO   __datasizeloop
	
__datacptradd:
;       cptr++;
  MOVIA   0x06
	ADDAR   STK04,1
	JBTS0   _STATUS,0
	INCR    STK05,1
	AGOTO   __datanumloop
	
__codeptrget2:
	ACALL	  __codeptrget1
	MOVAR	  STK02
	JZR	    STK01, 1
	DECR	  STK00, 1
	INCR	  STK00, 1
	ACALL	  __codeptrget1
	MOVAR	  STK03
	MOVR	  STK02, 0
	MOVAR	  STK00
	MOVR	  STK03, 0
	RETURN
	
__codeptrget1:
	MOVR	  STK00, 0
	MOVAR	  _EEADRH
	MOVR	  STK01, 0
	MOVAR	  _EEADRL
	RDT
	RETURN
	
__returnmain:
	AGOTO   _main
        
        END