//
// This file is part of the CC8 OS/8 C compiler.
//
// The CC8 OS/8 C compiler 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 3 of the
// License, or (at your option) any later version.
//
// The CC8 OS/8 C compiler 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 the CC8 OS/8 C compiler as ../GPL3.txt.  If not, see
// <http://www.gnu.org/licenses/>.
//

/ SABR DEFINITIONS
/ FRONT END (2.0:1/4/2017)

/ BEWARE: THIS MUST MATCH OPDEF TABLE IN ../cross/code8.c.
OPDEF ANDI 0400
OPDEF TADI 1400
OPDEF ISZI 2400
OPDEF DCAI 3400
OPDEF JMSI 4400
OPDEF JMPI 5400
OPDEF MQL 7421
OPDEF ACL 7701
OPDEF MQA 7501
OPDEF SWP 7521
OPDEF CDF1 6211
OPDEF CDF0 6201
OPDEF CDF4 6241
OPDEF RIF 6224
OPDEF CAF0 6203
OPDEF BSW 7002
OPDEF CAM 7621
OPDEF DILX 6053
OPDEF DILY 6054
OPDEF DIXY 6055

/ DECLARE INIT CODE GLOBALS.  SEE INIT.H COMMENTARY.
ABSYM TLOC 156
ABSYM STRV 157
ABSYM POP 160
ABSYM PSH 161
ABSYM JLC 162
ABSYM STKP 163
ABSYM PTSK 164
ABSYM POPR 165
ABSYM PCAL 166
ABSYM TMP 167
ABSYM GBL 170
ABSYM ZTMP 171
/
/
STK,    COMMN 7400
/
/
/
        ENTRY MAIN
MAIN,   BLOCK 2
        TAD GBLS
        DCA STKP
        TAD GBLS
        DCA GBL
        ISZ GBL     / LOCAL LITERALS = STKP+1
        TAD PVL
        DCA PSH
        TAD OVL
        DCA POP
        TAD MVL
        DCA PTSK
        TAD PVR
        DCA POPR
        TAD PVC
        DCA PCAL
        RIF
        TAD (6201           / BUILD CDF + IF INSTR
        DCA PCL1
        TAD PCL1
        DCA DCC0
        JMS MCC0
        CLA CMA
        MQL
        CALL 1,LIBC
        ARG STKP
        CALL 0,OPEN
        JMSI PCAL
        XMAIN
        CALL 0,EXIT
/
PUSH,   0
        CDF1
        ISZ STKP
        DCAI STKP
        TADI STKP
        JMPI PUSH
PPOP,   0
        CDF1
        DCA TMP
        TADI STKP
        MQL
        CMA
        TAD STKP
        DCA STKP
        TAD TMP
        JMPI PPOP
PUTSTK, 0
        JMSI POP
        SWP
        DCA JLC
        SWP
        DCAI JLC
        TADI JLC
        JMPI PUTSTK
POPRET, JMSI POP
        SWP
        DCA ZTMP
        SWP
        JMPI ZTMP
PCALL,  0
        CLA CLL
PCL1,   0
        TADI PCALL
        DCA ZTMP
        TAD PCALL
        IAC
        JMSI PSH    / PUSH RETURN
        CLA CLL
        JMPI ZTMP
PVL,    PUSH
OVL,    PPOP
MVL,    PUTSTK
SVL,    STK
PVR,    POPRET
PVC,    PCALL
		/ THESE ARE RATHER LONG FUNCTIONS
		/ INSERTED HERE IN USER SPACE
		/ AS SUBROUTINES RATHER THAN
		/ INLINE CODE.
		/
		/ XOR '^'
XXOR,	CMA
	TAD STKP
	DCA JLC
	TADI JLC
	MQA
	CMA CLL
	SWP 
	ANDI JLC
	MQA
	CMA 
	JMPI POPR

		/ >> AND << ROUTINES

XXRL,	DCA ZTMP
	CMA
	TAD STKP
	DCA JLC
	TADI JLC
XXRD,	CLL RAR
	ISZ ZTMP
	JMP XXRD
	JMPI POPR

XXLL,	ACL
	SPA
	JMP XXRL
	CIA
	DCA ZTMP
	CMA
	TAD STKP
	DCA JLC
	TADI JLC
	SNL
	JMPI POPR
XXLD,	CLL RAL
	ISZ ZTMP
	JMP XXLD
	JMPI POPR

IINIT,	CLA
	TAD STKP
	TAD (-1
	DCA JLC
	TADI JLC
	DCA STRV
	JMPI POPR
STRI,	CLA
	TAD STKP
	TAD (-1
	DCA JLC
	TADI JLC
        CDF4
        DCAI STRV
        CDF1
        ISZ STRV
        NOP
        JMPI POPR
STRD,   CDF4
        CLA
        TADI STRV
        CDF1
        ISZ STRV
        NOP
        JMPI POPR       
STRL,   CDF4
        CLA
        TADI STRV
        CDF1
        JMPI POPR      
/
