
Midas, part 2.

|Pseudo instructions octal, decimal, noinput, frontloading,
|readin, and relocatable

frl,	lda rlp
	trn ilf
	lda loc
	add (trn-21
	trn ilf
	load ino, -17755
	move thirty, loc
	slr org
	tra cfr

rdi,	sto rim
	lda rlp
	tze .+2
	trn cfr		|if reloc
	clc
	sto ini
	sto rlp
	tra cfr

oct,	llr (opr
	tra .+2

dec,	load n1, lad
	tra cfr

noi,	sto ini
	tsx pub
	tsx rst+1
	stz rim
	tra cfr

rel,	lda rlp
	tze re1
	load ino, -756
	lda mon
	sto rlp
	sto ini
re1,	ado x5
	add (-tvn-ntv+trn
	trn sce
	load bs, tra rst
	stz wrd
	stz pci
	stz rim
	lda one
	sto syl
	tra b5

|Pseudo-instruction entry

ent,	lda rli
	tze ilf
	add pci
	trn ilf
	load en6, tra rsw
	lxr
enz,	sxa en0		|set up pgm card
	load org, opr
	tsx sts
	tra en2
	tra en1
	load ts, sto loc+1
	slr srt
en0,	tra .

en1,	ldx qq9
	sxa enx
	sto pci
	lda chc
	tze pc1
	load en6, opr
en2,	lda syl
	tze ile
	lda let
	trn ile
	tsx evl
	trn use

en3,	move wrd, t1
	move rlc, t2
	lda pss
	tze enp
	tsx rck
	trn ire
enp,	move fsm, wrd
	stz rlc
	tsx enc
	move t1, wrd
	move t2, rlc
	lda loc
	add (trn-76
	trn tme
	tsx enc
en6,	xx		|tra rsw or opr
	stz rlc
	lda pss
	tze en8
	ldx x5
	lax 0		|lda tvn
en8,	sto wrd
	tsx enc

en9,	ldx pc
	sxa bs
	stz wrd
	lda one
	sto syl
	tra pun

enx,	tra .

enc,	sxa bs
	tra tb4

|Pseudo-instruction exit

exi,	lda rli
	tze ilf
	add pci
	trn ilf
	lda pci
	trn exa
	ldx .-1
pc,	sxa enx
	tsx enz
	load en6, opr
pc1,	ldx x5
	llx 0		|llr tvn
	slr t1
	move one, t2	|construct main program entry
	cal
	tra enp+1

exa,	tsx sts
	tra x0
	tra x1
	move exb, x4
exb,	tra rsw

x1,	load x4, lda loc
x0,	lda liu
	tze mdx
	llr loc
	slr tvl
	tsx ck
	tra ilx
	trn mdx
exr,	llr fsm
	slr wrd
	stz rlc
	tsx enc
x4,	xx		|tra rsw or lda loc
x5,	xx		|sto tvn
	move mon, pci
	tra rst

|Pseudo-instruction equals a, b: makes a same as b.

osn,	llr pss
	tplr itc
eq,	tsx sts
	tra osa
	tsx ilf
	tra rsw

osa,	lda syl
	tze ipa
	lda let
	trn ipa
	tsx sav
	sym l
	sym r
	tra .+1
osb,	tsx sts
	tsx ilf
	tra os1
	tra rsw

os1,	lda syl
	tze ipa
	lda let
	trn ipa
	tsx es
	tze usq
	xac
	sto t2
	tsx uns
	tra osb
	ldx t2
	lax low-1
	llr (opr
	ana
	add sym l
	sto tsm l
	lax low
	ana
	add sym r
	sto tsm r
	llr num
	tra qq4

|Pseudo-instruction repeat

rpt,	tsx svs
rqd,	tsx sts
	tra rqa
	tra rqa
	tsx rsw+1
	tra cfr

rqa,	tsx evl
	lda def
	trn usr
rqb,	tsx sav
	wc1
	wcc
	tra .+1
rpz,	move rqp, wc1
	stz wcc

rqr,	tsx rch
	tsx wch
	add sbp
	trn sce
	lac
	add (-404004
	tze rq1
	tra rqr

rq1,	tsx svr
	rcc
	rce
	rcl
	rex
	rc8
	rqc
	rqp
	rqq
	tra .+1
rq2,	move rqp, rqq
	move wc1, rce
	slr rqp
	move wcc, rcl
	init rex, rqt
	move wrd, rqc
	tsx rst+1
	tsx uns
	tra rpz
	tsx uns
	tra svx
	lda rqc
	trn rqx

rqt,	ldx rqc
	tix rq3
rqx,	tsx unr
	tra rq2
rqz,	tra cfr

rq3,	sxa rqc
	ldx rqq
	sxa rc8
	stz rcc
rqw,	tra rr

|Pseudo-instruction word

wd,	tsx sts
	tra wd2
	tra wd1
	tsx pub
	load bs, tra rsw
	slr wd3
	tsx rsw+1
	tra cfr

wd1,	load wd3, opr
wd2,	tsx evl
	trn wdu
	lda pss
	add pch
	add mon
	trn wd3
	lda wrd
	punch
wd3,	xx
	tra rst

|Pseudo-instruction character

ch,	tsx rch
	llr fxr
	add (-char lr
	tze ch1
	llr (opr
	add (char lr-char lm
	tze ch1
	llr fxl
	add (char lm-char ll
	tze ch1
	tsx ilf

ch1,	slr ch4
	tsx rch
	cyr
ch4,	xx
	sto num
	tra fxx

|Pseudo instruction flexo

fx,	stz num
	load t2, -2
	tsx rch
fxl,	cyl
	add num
fxr,	cyr
	sto num
	ado t2
	trn fxl-1

fxx,	ado chc
	tra rr

|Pseudo-instruction text

txt,	load bs, tra txq
	tsx rch
	com
	sto t2

txq,	stz wrd
	ldx (2

txw,	sxa t0
	tsx rch
	add t2
	tze txk
	ldx t0
	lal
	cyr
	tix .-1
	add wrd
	sto wrd
	ldx t0
	tix txw
	tra tb3

txk,	ldx qq9
	sxa bs
	ldx t0
	aux (-2
	tix tb3
	tra rst

|Pseudo-instruction print

pf,	lda (flex pnt
	llr (tra .+2
	tra ale
	tsx tb
pf0,	tsx rch
	com
	sto t2
pf1,	tsx rch
	add t2
	tze pf2
	tac+cyr-opr
	cyr
	trn pf1
	lar
	cyr
	pno
	tra pf1

pf2,	lda (101001
	pno
	tra rsw

|Pseudo-instruction start

sta,	tsx sts
	tsx ilf
	tra s
	tsx rsw+1
	tra cfr

s,	lda pss
	tze 1st
	tsx evl
	trn uss

s2,	move wrd, t3
	tsx pub
	load sov, tra np2
	hlt+cal 1-opr
	add pch
	trn s6
	feed 40
	lda (add
	add t3
	punch
	feed 100
	load sov, tra ps1

s6,	clc+xro-opr
	hlt+alo-opr
	tsx res
	tra ps1

1st,	load sov, tra np2
	hlt+cal 1-opr

|Begin new pass

ps2,	lda one		|restart begin pass 2
	sto pss
	sto pch
	sto tit
	llr ini
	slr inp

ps4,			|test begin pass 2
	tra np1

ps5,	tsx res		|initial entry here
ps3,			|symbol punch entry here
	load sov, tra ps2

s5,	clc+xro-opr
	sto pss
	hlt+alo-opr

ps1,	cal+com-opr	|start pass 1
	sto pss
	sto pch
	slr rim
	slr ino
	clear tvn, tvn+ntv-1
	move one, ini
	slr rlp

np1,	cal+com-opr	|begin pass
	stz nca
	sto nco
	stz vct
	stz mii
	stz mdi
	stz cnl
	stz vax
	stz asm l
	stz asm r
	sto rli
	stz gst+4
	stz gst+5
	load gst+3, 12
	move mon, pci
	move twenty, org
	slr loc
	load x5, sto tvn-1
	load n1, opr
	load sap, sto pd1+1
	load sbp, sto pd2+1

np2,	stz api l
	stz api r
	stz rlw
	stz igi
	lda (sto loc
	add rli
	sto srt
	sto ts
	sto tbc
	stz rcc
	load rc8, lda flx
	load rce, flx
	init rex, rfb
	load rlm, opr
	load dpx, dsp
	load rqp, rqs-1
	slr rqq
	load cfx, clc
	load cf9, tra cfm
	load rch, sxa rmx
	clc+lro-opr
	sto cas
	add pss
	add pch
	add tit
	add (-2
	rn pt2
	feed 40

|Print and punch title

pt2,	tsx rch
	add (373773
	tze pt2
	add (337773-373773
	tze pt2

pt5,	lac
	add (773773
	tze ptq

pt6,	add (377777
	tze ptr
	tac+cyr-opr
	cyr
	trn .+4
	lar
	cyr
	pno
	lda pss
	add pch
	add tit
	add (M_2
	TRN PTP

PT7(	LDA LCH
	TSX SQZ
	LAL/LRO_OPR
	AXO
	LAX FTP
	TRN PTP
	P6H
	P6O
	LAX FTP/1
	P6H
	P6H
	P6O
	P6S

PTP(	TSX RCH
	TRA PT5

PTQ(	STZ TIT
	TRA PT6

PTR(	STZ TIT

|Print pass 1 or pass 2

pps,	lda cas
	tze pp9
	lda (char r	|l. c.
	pno
pp9,	lda (flexo  -
	tsx pp3
	lda (flexo  pa
	tsx pp3
	lda (flexo ss 
	tsx pp3
	ldx pss
	lax pp4
	tsx pp3

|Punch input routine

	lda pss
	add pch
	add mon
	trn rst

pi3,	feed 40
	lda inp
	trn pi4
	load t2, 17756

pia,	lda t2
	add ino
	punch
	ldx t2
	lax 0
	llr forty
	ana
	tze pi2
	lda ino
pi2,	adx 0
	punch
	ado t2
	add (-17777
	trn pia

pi4,	lda inp
	tze rst
	lda (trn 17756
	add ino
	punch
	sto inp
	tra pi3

p3c,	p7h
	p7h
	p7o 40
	trx

pp3,	pnt
	pnt
	pno
	trx

pp4,	flexo 1
	flexo 2

|Pseudo-instruction define

dfn,	load cfx, tra df2
	lda mai
	com
	add low
	add (low+trn-5
	trn .+2
	tsx gc
	ldx mai
	clc
	stx 1
	stz dsk
	tra rsw

df2,	lda chc
	tze rr
	move2 sym,api
	tsx sav
	sym l
	sym r
	tra .+1
df3,	load cfx, tra df4
	tsx rsw+1
	tra cfr

df4,	lda lch
	add (-404004	|c. r.
	tze dmi
	add (404004-400404	|tab
	tze dmi
	add cas
	add (400404-044004	|comma
	tze dfc
	add (044004-000404	|slash
	tze dfs
	tra rsw

dfs,	tsx dfd
	ldx mai		|begin crs
	lda dsk
	stx 1
	tra rsw

dfc,	ldx .-1		|comma

dfd,	sxa dfx
	lda chc
	tze dfx
	ldx dsk		|write d s
	llr sym l
	slx dsm l
	llr sym r
	slx dsm r
	aux (2
	xac
	sto dsk
	add (-nds-nds+trn
	trn tmp
dfx,	tra .

dmi,	tsx dfd
	load cfx, clc
	move one, mdi	|end of dummy syms
	ldx mai
	lda dsk
	stx 2
	aux four
	xac
	sto wc1
	sto wf1
	stz wcc
	stz wf2
	stz wf3
	tra rsw

|Pseudo-instruction terminate

ter,	tra tsn
te5,	tsx uns
	tra df3
	move2 sym, tsm
	lda lch
	add (-004000
	tze te1
te2,	lda wf1
	axr
	llr wf2
	slx
	llr mai
	sto mai
	lcd+xro-opr
	com
	stx 3
	lda wf3
	stx 4
	tra qq4

te1,	load cfx, tra te3
	tra rsw

te3,	lda chc
	tze rsw
	load cfx, clc
	lda sym l
	llr tsm l
	lpd
	tze .+2
	tra tee
	lda sym r
	llr tsm r
	lpd
	tze te4
tee,	error alq, te4, flex mnd

te4,	move2 tsm, sym
	tra te2

|Macro call

mac,	lax low+1
	sto t0
	tsx ma0
	lda lch
	add (-004000
	tze mr1
	add (004000-404004
	tze mr2
	add (404004-400404
	tze mr2
	tra .+2

mr1,	tsx rch
	tsx mas

mr2,	ldx t0
	llx 2		|end arg
	slr t2
	lax 1		|origin crs
	trn .+2
	alr
	slr t1

mrc,	ldx dpa		|clear unspecified args
	xcc
	add dpx
	add t1
	trn mrg
	tsx maa
	tra mrc

mrg,	xcc
	add dpx
	add t2
	trn mrs

gs,	ldx (2		|generate crs
	lda one

gsl,	adx gst+3
	stx gst+3
	add (-44+trn
	trn gsc
	cla
	tix gsl
	init gsg, gst

gsg,	ldx
	lax spl+1
	cyl
	cyl
	tsx wch
	add (dsv+nac
	trn sce
	ado gsg
	add (-ldx-gst-5
	trn gsg
	tsx maa
	tra mrg

gsc,	cla
	stx gst+3
	lda one
	tix gsl
	tra tmp

gst,	repeat 6, 0

mrs,	ado mii
	tsx uns
	tra ma8
	tsx svr
	dpx
	arc
	rcc
	rce
	rcl
	rex
	rc8
	rch
	tra .+1
mr9,	move dpx, arc
	move dpa, dpx
	ldx t0
	lax 3
	xad
	sto rce
	lax 4
	sto rcl
	stz rcc
	xac
	add (lda 4
	sto rc8
	init rex, mat
	load rch, tra rm
	tra rr

mat,	tsx unr
	tra mr9
	lda mii
	add mon
	sto mii
	tra rr

|Write arguments subroutine

ma0,	sxa mxy
	tsx sav
	wc1
	wcc
	rmx		|save exit for irp
	tra .+1
ma8,	ldx dpx
	sxa dpa
	lax 0
	sto wc1
	stz wcc
	stz ati
mxy,	tra .

mas,	sxa mxx		|argument scan
	llr lch
	lda lch
	tra ma5

mal,	tsx rch		|get arguments
ma5,	add (-444004
	tze ma2
	add cas
	add (444004-440441	|9
	tze mae
	add (440440-044044	|6
	tze mad
	lda igi
	tze ma1

maw,	stz wf1
ma3,	tsx wch-1
	add (con
	add nco
	trn sce
	sto ati
	tra mal

ma2,	tsx csx		|upper case
	tra ma3

ma1,	lac
	add (-404004	|c.r.
	tze maz
	add (404004-400404	|tab
	tze maz
	add (400404-044004	|comma
	add cas
	tze mab
	tra maw

mae,	lda mon		|9
	add igi
	sto igi
	tze ma4
	tra maw

mad,	ado igi		|6
	add mon
	tze ma4
	tra maw

ma4,	lda one
	sto ati
	lda wf1
	tze mal
	tsx rch
	add (-444404
	tze .+3
	lac
	tra ma5
	tsx csu
	tra mal

mab,	ldx .-1		|comma

maa,	sxa max		|terminate argument
	stz ati
	ldx dpa
	llr wc1
	slx 2
	lda wcc
	cyr
	cyr
	lad
	stx 1
	aux (2
	xac
	sto dpa
	com
	add sap
	trn tmp
	stz wcc
max,	tra .

maz,	tsx maa		|end of arguments
mxx,	tra .

ati,	0
dpa,	0

|Indefinite repeat

ir,	tra tsn		|not in macro call
ir1,	tsx rcb		|read irp arg dsn
	add (-444444
	tze ir2
	tra ir1

ir2,	tsx svr
	ip8
	ipc
	ipo
	ipl
	ipn
	ir5
	dpx
	tra .+1
ir6,	llr (tra ir4
	tsx rma		|set to read arg
	lda rmh
	sto ipn
	add one
	sto ir5
	tsx ma0		|set to write args
	sxa ipo
	tsx rch
	tsx mas		|write arguments
	tra mal

ir4,	lda ati
	tze .+2
	tsx maa
	ldx dpa
	sxa dpx
	xcc
	sto ipl
	tsx uns
	tra ma8
	tsx svr
ipn,	0
ir5,	0
	tra .+1
ir8,	move rc8, ip8
	move rcc, ipc

ir7,	move ip8, rc8
	move ipc, rcc
	ldx ipo		|substitute substring for arg
	lax 0
	llx 1
	ldx ipn
	stx 0
	slx 1
	tra rm1

ipe,	tra tsn
ip1,	ado ipo		|endirp
	ado ipo
	add ipl
	add one
	trn ir7
	tsx unr
	tra ir8
	tsx unr		|restore argument
	tra ir6
	tra rm1

ip8,	0		|reader switches
ipc,	0
ipo,	0		|substring pointer
ipl,	0		|pointer limit

|Read characters for macro call

rm,	sxa rmx
rm1,	tsx rcb
	add (-444444	|arg indicator
	tze rmg

rm2,	tac+cyr-opr
	com+cyr-opr
	trn .+4
	lar
	cyr
	prt
	lac
rmx,	tra .

rmg,	llr .+2
	tsx rma
	tra rm1

rma,	sxa rmb		|set to read argument
	slr rmc
	tsx rcb
	tsx sqz
	tze ip1
	add mon
	tze ir1
	cyl
	add arc
	add (lda-2
	sto rmh
	tsx svr
	rcc
	rce
	rcl
	rex
	rc8
	tra .+1
rmh,	xx		|lda dsp
	add (lda-sto
	sto rc8
	ldx rmh
	lax 1
	llr (opr
	anp
	sto rce
	lal
	cyl
	sto rcl
	stz rcc
	init rex, rmk
rmb,	tra .

rmk,	tsx unr
	tra rmh
rmc,	tra .

|Read and write characters from table

rch,	sxa rmx
	tsx rcb
	tra rm2

rcb,	sxa rcx
	ldx rcc
	tix rc8
	ldx (2
	ado rc8
	com
	add (lda-sto
	add rce		|endcheck
	tze rcn
rex,	trn .		|empty exit

rc8,	xx		|lda table
	sxa rcc
	cyr
	cyl
	tix .-1
	llr (444444
	ano 20
	sto lch
	add (-444004
	tze rcu
	add (444004-444404
	tze rcd
	lac
rcx,	tra .

rcu,	lda one
rcd,	sto cas
	tra rcx-1

rcn,	lda rcl
	add (-2
	com
	axr
	tra rc8

	lda lch
wch,	alo
	sxa wcx
	ldx wcc
	tix wc2
	ado wc1
	cla
wc1,	xx		|sto table
	ldx (2
wc2,	sxa wcc
	lal
	ldx wc1
	adx 0
	cyr
	stx 0
	xcc
wcx,	tra .

|Stretch and squeeze

str,	sxa stu
	ldx (-4
st1,	alo
	lax stt+4
	cry
	cyr
	tix st1
	cyl
	llr (222222
	ana-10
stu,	tra .

stt,	177700
	17740
	1760
	170
	14


sqz,	sxa sqx
	cyl
	ldx (-4
sq1,	alo
	lax sqt+4
	cry
	tix sq1
	cll+alr-opr
sqx,	tra .

sqt,	666660
	666660
	666740
	666000
	666000

|Save and unsave

sav,	sxa sa1
	ldx (sap
	tra sae

svr,	sxa sa1
	ldx (sbp
sae,	sxa sal
	sxa saf

sal,	lda
	add mon
saf,	sto
sa1,	llr		|get addr
	ial+xro-opr
	trn sa3
	lax 0		|get datum
	lxr
	stx 0		|sto pdl
	ado sa1
	tra sal

sa3,	lxr
	stx 0
	lda dpx
	com
	add sap
	trn sce
	lda rqp
	com
	add sbp
	trn sce
	trx 0


uns,	llr (sap
	tra .+2
unr,	llr (sbp
	lax 0
	aux one
	sxa unx
	com+lxr-opr
	sxa unb
	sxa unc
unb,	ldx
	adx 0
	tze un1
	tsx se
un1,	lax 0		|get addr
	add (lda-tra-1
	sto una

unl,	ldx una
	tix .+1
	sxa una
unc,	ado
	axr
	llx		|get datum
una,	lda		|get addr
unx,	trn .
	axr
	slx
	tra unl

start
t