;
; hand-coded things from newobj.c
;

; ot(str)
;	.word	0
;	.globl	_ot
;_ot:
;	jsr	popax
;	sta	_ot-2
;	stx	_ot-1
;ot1:
;	lda	_ot-2
;	ldx	_ot-1
;	jsr	ldai		; get a byte
;	beq	ot9
;	inc	_ot-2
;	beq	ot2
;	inc	_ot-1
;ot2:
;	jsr	pushax
;	ldy	#1		; one arg
;	jsr	_outchar
;	jmp	ot1
;ot9:
;	rts
	
; nl();
	.globl	_nl
_nl:
	lda	#155		; eol
	jsr	pushax
	ldy	#1		; one arg
	jsr	_outchar
	rts

; ol(str)
	.globl	_ol
_ol:
	jsr	_ot		; let him pop the arg...
	jmp	_nl		; let him return...

; oljsr(str)
	.globl	_oljsr
_oljsr:
	ldax	#k_jsr
	jsr	pushax		; push "jsr"
	jsr	_ot		; out that
	jmp	_ol		; let him out the string and return
k_jsr:
	.byte	$7F,"jsr",$7F,0

;
; common entry for code generating routines of the form oljsr(foo);
;
olxxx:
	jsr	pushax		; push the real string
	jmp	_oljsr		; out in and the jsr, return

;
; common entry for code generating routines of the form oljsr(foo); pop;
;
olxxxpop:
	jsr	pushax		; push the real string
	jsr	_oljsr		; out in and the jsr
	jmp	_popsp		; pop the local stack index

; swap()
;	.globl	_swap
;_swap:
;	ldax	#z_swaptos
;	jmp	olxxx
;z_swaptos:
;	.byte	"swaptos",0

; save()
	.globl	_save
_save:
	ldax	#z_saveax
	jmp	olxxx
z_saveax:
	.byte	"saveax",0

; rstr()
	.globl	_rstr
_rstr:
	ldax	#z_restax
	jmp	olxxx
z_restax:
	.byte	"restax",0

; tst()
	.globl	_tst
_tst:
	ldax	#z_tstax
	jmp	olxxx
z_tstax:
	.byte	"tstax",0

; swapstk()
	.globl	_swapstk
_swapstk:
	ldax	#z_swapstk
	jmp	olxxx
z_swapstk:
	.byte	"swapstk",0

; casejump()
	.globl	_casejump
_casejump:
	ldax	#z_casejump
	jmp	olxxx
z_casejump:
	.byte	"casejump",0

; doublereg()
	.globl	_doublere
_doublere:
	ldax	#z_doublereg
	jmp	olxxx
z_doublereg:
	.byte	"aslax",0

; add()
	.globl	_add
_add:
	ldax	#z_addtos
	jmp	olxxxpop
z_addtos:
	.byte	"addtos",0

; sub()
	.globl	_sub
_sub:
	ldax	#z_subtos
	jmp	olxxxpop
z_subtos:
	.byte	"subtos",0

; mult()
	.globl	_mult
_mult:
	ldax	#z_multos
	jmp	olxxxpop
z_multos:
	.byte	"multos",0

	.globl	_div
_div:
	ldax	#z_divtos
	jmp	olxxxpop
z_divtos:
	.byte	"divtos",0

	.globl	_mod
_mod:
	ldax	#z_modtos
	jmp	olxxxpop
z_modtos:
	.byte	"modtos",0

	.globl	_or
_or:
	ldax	#z_ortos
	jmp	olxxxpop
z_ortos:
	.byte	"ortos",0

	.globl	_xor
_xor:
	ldax	#z_xortos
	jmp	olxxxpop
z_xortos:
	.byte	"xortos",0

	.globl	_and
_and:
	ldax	#z_andtos
	jmp	olxxxpop
z_andtos:
	.byte	"andtos",0

	.globl	_asr
_asr:
	ldax	#z_asrtos
	jmp	olxxxpop
z_asrtos:
	.byte	"asrtos",0

	.globl	_asl
_asl:
	ldax	#z_asltos
	jmp	olxxxpop
z_asltos:
	.byte	"asltos",0

	.globl	_neg
_neg:
	ldax	#z_negax
	jmp	olxxx		; no pop here
z_negax:
	.byte	"negax",0

	.globl	_lneg
_lneg:
	ldax	#z_negax
	jmp	olxxx		; no pop here
z_negax:
	.byte	"lnegax",0

	.globl	_com
_com:
	ldax	#z_complax
	jmp	olxxx		; no pop here
z_complax:
	.byte	"complax",0

	.globl	_inc
_inc:
	ldax	#z_incax1
	jmp	olxxx		; no pop here
z_incax1:
	.byte	"incax1",0

	.globl	_dec
_dec:
	ldax	#z_decax1
	jmp	olxxx
z_decax1:
	.byte	"decax1",0

	.globl	_eq
_eq:
	ldax	#z_toseqax
	jmp	olxxxpop	; popping again
z_toseqax:
	.byte	"toseqax",0

	.globl	_eq0
_eq0:
	ldax	#z_axzerop
	jmp	olxxx		; exc this one...
z_axzerop:
	.byte	"axzerop",0

	.globl	_ne
_ne:
	ldax	#z_tosneax
	jmp	olxxxpop
z_tosneax:
	.byte	"tosneax",0

;
; end of code generators...
;

	.globl	_popsp
_popsp:
	clc
	lda	_oursp
	adc	#2
	sta	_oursp
	bcc	pop_1
	inc	_oursp+1
pop_1:
	ldx	_oursp+1
	rts

	.globl	_pushsp
_pushsp:
	sec
	lda	_oursp
	sbc	#2
	sta	_oursp
	bcs	push_1
	dec	_oursp+1
push_1:
	ldx	_oursp+1
	rts

;
; that's it...
;
