; the BeerMon V0.28 sourcecode, placed in public domain
;
; note: use Buddha's Masterseka (the one and only...)
; you may modify as much as you want, but PLEASE don't rape
; it corrupt...

work512=$74000			;30.6.90
work1mb=$f4000

readlen=$18d0
scrsize=640*256/8
dsksize=readlen*2
sprsize=76
copsize=15*4
worksize=scrsize+dsksize+sprsize+copsize

sndintstep=$10
fkeylen=20
retry=3
stepdel=3800*100/141

base:
run:	movem.l d0-d7/a0-a7,regs	;the jmp entry,flags ok
	sub.l a0,a0			;'x' resets/returns to cli
	bra.s mutil0
thehit:	movem.l d0-d7/a0-a7,regs	;interrupt entry,flags ok
	lea -1.w,a0			;'x' returns into prg
	move.w (a7),a5			;the sr
	move.l 2(a7),a4			;the pc
mutil0:	lea $bfe000,a1
	lea 3.w,a3			;don't change any flags
	lea 2.w,a2
	movem.w a3-a3,$0200(a1)		;$bfe201:lmouse,ovl
	movem.w a2-a2,(a1)		;$bfe001
	lea base(pc),a6
	movem.w a0-a0,frzflag-base(a6)	;flags ok

	lea stackend,a7		;lea $80000,a7

	lea $80.w,a0
	move.l (a0),a1
	lea savereg(pc),a2
	movem.l a2-a2,(a0)		;?flags ok
	trap #0				;hang the pope,go sv
	move.w a5,d2			;sr(int),now change flags...
	tst.b frzflag-base(a6)
	bne.s mutil2
	sub.l a4,a4			;interrupt?beer?
	move.w d0,d2			;sr(jmp)
mutil2:	move.l a4,regs+64+8-base(a6)	;pc
	move.w d2,startsr-base(a6)
	move.w d2,regs+64+12-base(a6)	;sr
	move.l a1,(a0)
	move.l a7,d1			;in sv
	move.l regs+60(pc),a0		;a7
	btst #13,d0
	beq.s wasusr
	move.l a0,d1
	move.l usp,a0
wasusr:	move.l d1,regs+64-base(a6)
	move.l d1,startssp-base(a6)
	move.l a0,regs+64+4-base(a6)
	move.l a0,startusp-base(a6)

	moveq #0,d0			;make pointers even..
	bclr d0,regs+64+3-base(a6)	;ssp
	bclr d0,regs+64+4+3-base(a6)	;usp
	bclr d0,regs+64+8+3-base(a6)	;pc

	lea $10.w,a0		;illegal vector, check which cpu is
	move.l (a0),a1		;installed, because of stackformat
	lea chkcpu(pc),a2
	move.l a2,(a0)
	moveq #12,d0		;is68010
	moveq #10,d1
	moveq #24,d2
	moveq #0,d3
	moveq #2,d4
	moveq #$3e,d5
	moveq #"1",d6
	movec vbr,d7		;68010 oder illegal,moveq #1,d4
	move.l a1,(a0)		;thanks to buddha for the masterseka
	move.w d0,cpu68a+2-base(a6);patch lea xx(a7),a7
	move.w d1,cpu68b+2-base(a6)
	move.w d2,cpu68c+2-base(a6)
	move.w d3,cpu68d+2-base(a6)
	move.w d4,cpu68e+2-base(a6)
	move.w d5,cpu68f+2-base(a6)
	lea initxt+24(pc),a3
	move.b d6,(a3)
;init
	lea $bfd100,a0
	st $200(a0)		;ddr
	st (a0)			;all drives off
	move.b #%10000111,(a0)
	st (a0)

	lea rdff002(pc),a0
	lea $dff002,a1
	moveq #7,d0		;set the setbit
	move.w (a1),(a0)+	;rdff002
	bset d0,-2(a0)
	move.w $0e(a1),(a0)+	;rdff010
	bset d0,-2(a0)
	move.w $1a(a1),(a0)+	;rdff01c
	bset d0,-2(a0)
	move.w $1c(a1),(a0)+	;rdff01e
	bset d0,-2(a0)

	move.l #$7fff7fff,$98(a1)	;$dff09a
	move.w #$7fff,$94(a1)		;$dff096 all dma off
	clr.w $34(a1)			;$dff036
	clr.w $17e(a1)			;$dff180

	moveq #$08,d0		;move.l #$80000,d0; megachip?
	swap d0
	move.l d0,himem-base(a6)
	move.l #work512,defwork-base(a6)
	move.l #"512K",d5
	btst #5,2(a1)		;$dff004
	beq.s nobig
	move.l #"1 MB",d5
	bsr.L memtest		;test if 1mb, bufadr useless
	beq.s nobig
	move.l #$100000,himem-base(a6)
	move.l #work1mb,defwork-base(a6)
nobig:	move.l d5,4(a3)		;xxxx agnus

	lea initmod(pc),a0
	lea muttxt(pc),a1
	tst.b frzflag-base(a6)
	beq.s mutil1
	lea frztxt(pc),a1
mutil1:	bsr.l txttobuf		;xx mode

	move.l #stackend,d0
	cmp.l #$f00000,d0	;dont buf if in mod
	bcs.s mem7
	bsr.s memtest
	bne.L mem1

mem7:	lea $bfe001,a0		;if left mouse during startup
	btst #6,(a0)		;no backup is done
	bne.s mem4 
	clr.l bufadr-base(a6)	;clr bufadr if no buf wanted
	lea $dff006,a1
	lea $017a(a1),a2	;$dff180
mem5:	move.b (a1),(a2)
	btst #6,(a0)	
	beq.s mem5
	bra.s mem1
mem4:	move.l #$274000,d0	;512k banks
	bsr.s memtest
	bne.s mem1
	move.l #$c74000,d0
	bsr.s memtest
	bne.s mem1
	cmp.l #"1 MB",d5	;1mbchip:work f4000,no backup at all
	beq.s mem1
	move.l #$f4000,d0	;if no mod available
	pea mem1(pc)
memtest:clr.l bufadr-base(a6)
	sub.l a1,a1
	move.l d0,a2
	and.l #$f80000,d0
	move.l d0,a0
	move.l (a0),d6
	move.l (a1),d7
	move.l #"beer",d0	;the ramtest values...
	move.l #"gore",d1
	move.l d0,(a1)
	move.l d1,(a0)
	cmp.l (a0),d1
	bne.s memfail
	cmp.l (a1),d0
	bne.s memfail
	move.l a2,bufadr-base(a6)
memfail:move.l d6,(a0)
	move.l d7,(a1) 
	tst.l bufadr-base(a6)
	rts

mem1:	move.l bufadr(pc),para+8-base(a6)
	beq.s mem2
	move.l defwork(pc),a0
	move.l a0,para-base(a6)
	add.l #worksize,a0
	move.l a0,para+4-base(a6)
	moveq #3,d3
	bsr.L t			;transfer workspace to backupmem

mem2:	sub.l a0,a0
	lea zeromem(pc),a1
	moveq #16-1,d0
saveexc:move.l (a0)+,(a1)+
	dbf d0,saveexc

	lea $64.w,a0
	lea intraps(pc),a1
	moveq #16+7-1,d0
savetrp:move.l (a0)+,(a1)+
	dbf d0,savetrp
	
	move.l defwork(pc),d0
	sf row-base(a6)
	bra.l calchip		;jmp warm

warm:	lea stackend-4,a7
move.l regs+64+8-base(a6),para-base(a6)	;set pc for disasm

	lea $dff000,a2
	move.l #$7fff7fff,$9a(a2)
	move.w #$0c00,$34(a2)	;r. mouse

	lea $bfd000,a0		;set cia regs
	move.b #3,$1201(a0)	;$bfe201 l. mouse,ovl
	st $1301(a0)		;$bfe301 printer port
	st $0300(a0)		;$bfd300 drive port
sf $1c01(a0)			;$bfec01
move.b #$80,$1e01(a0)		;$bfee01
move.b #$88,$1d01(a0)		;$bfed01
tst.b $1d01(a0)			;$bfed01
	sf $0e00(a0)		;$bfde00 ciab cra
	move.b #$7f,$0d00(a0)	;$bfdd00 ciab icr
	tst.b $0d00(a0)		;$bfdd00

	sf ascii-base(a6)
	lea $68.w,a1
	lea keyint(pc),a3	;$68
	lea vblint(pc),a4	;$6c
	lea audint(pc),a5	;$70
	movem.l a3-a5,(a1)
	lea thehit(pc),a0
	move.l a0,$14(a1)	;$7c level 7 intvec

	lea except-2+[2*11](pc),a0	;10+trap
	lea $8.w,a1
	moveq #10-1,d0
setex:	move.l a0,(a1)+
	subq.l #2,a0		;bsr.s xx
	dbf d0,setex

	lea except+[6*0](pc),a0
	lea $80.w,a1
	moveq #16-1,d0
settrp:	move.l a0,(a1)+
	dbf d0,settrp

	lea mousespr(pc),a0
	move.l spradr(pc),a1
	moveq #34+4-1,d0	;34/2=sprhigh
cpspr:	move.w (a0)+,(a1)+
	dbf d0,cpspr

	lea coplst(pc),a1
	move.l scradr(pc),d0
	move.w d0,6(a1)
	swap d0
	move.w d0,2(a1)
	move.l copadr(pc),a0
	moveq #copsize-1,d0
cpycop:	move.b (a1)+,(a0)+
	dbf d0,cpycop

	move.w #$c028,$9a(a2)
waitvbl:btst #5,$1f(a2)
	beq.s waitvbl

	tst.b frzflag-base(a6)	;set coplist if jmpmode
	bne.s mutil4		;or interruptlist if breakmode
	move.l copadr(pc),$80(a2)
	clr.w $88(a2)
	move.w #$8080,$96(a2)	;cop on
mutil4:	move.w #$8340,$96(a2)	;bpl/blt on

	sf col-base(a6)
	clr.l d3
	bsr.l r			;output registers
	moveq #">",d0
	bsr.L rawchr
	bsr curson
	clr.w buflen-base(a6)

loop:	tst.w buflen-base(a6)
	beq.s nokeys
	clr.w d1
	lea keybuf(pc),a0
dobuf:	move.b (a0,d1.w),d0

	bsr cursoff
	bsr prtasc
	bsr curson

	addq.w #1,d1
	cmp.w buflen(pc),d1
	bcs.s dobuf
	clr.w buflen-base(a6)
nokeys:	bra.s loop

exit:	move.w #$7fff,$dff096
	move.w #$4000,$dff09a

	move.l bufadr(pc),d0
	beq.s mem3
	move.l d0,para-base(a6)
	add.l #worksize,d0
	move.l d0,para+4-base(a6)
	move.l scradr(pc),para+8-base(a6)
	moveq #3,d3
	bsr.L t			;retransfer workspace, if any
mem3:
	lea intraps(pc),a0
	lea $64.w,a1
	moveq #16+7-1,d0
resetrp:move.l (a0)+,(a1)+
	dbf d0,resetrp

	lea zeromem(pc),a0
	sub.l a1,a1
	moveq #16-1,d0
resetex:move.l (a0)+,(a1)+
	dbf d0,resetex

tst.b frzflag-base(a6)	;freezemode?
bne.s endfrz

	lea run(pc),a0	;in module? then reset
	cmp.l #$f00002,a0
	bne.s nomod
	jmp $fc00fe

nomod:
move.l 4.w,a6		;exit to the poor one, not too consistent
lea gfxname(pc),a1	;but hey poor, you don't have to be poor
jsr -408(a6)		;anymore, jesus is here...
move.l d0,a0
lea $dff000,a2

move.w #$0080,$96(a2)
move.l 38(a0),$80(a2)
clr.w $88(a2)
move.w #$8080,$96(a2)
move.w #$83f0,$96(a2)
move.w #$e02c,$9a(a2)
bclr #1,$bfe001
	move.l startusp(pc),a0	;restore initial? regs
	move.l a0,usp
	move.l startssp(pc),a7
	move.w startsr(pc),sr
	rts

endfrz:	move.l startusp(pc),a0	;restore initial? regs
	move.l a0,usp
	move.l startssp(pc),a7
;move.w startsr(pc),sr		;no need for it, rte!
	lea $dff000,a2
	move.w #$7fff,d0
	move.w d0,$96(a2)
	move.w d0,$9e(a2)
	move.w d0,$9a(a2)
	move.w d0,$9c(a2)
xxx:	move.w $6(a2),$180(a2)	;nice, eh?
	dbf d0,xxx
	move.w rdff002(pc),$96(a2)
	move.w rdff010(pc),$9e(a2)
	move.w rdff01c(pc),$9a(a2)
	move.w rdff01e(pc),$9c(a2)
	movem.l regs(pc),d0-d7/a0-a6
	rte

chkcpu:	moveq #10,d0	;is68000? magic bytes down here..
	moveq #2,d1
	moveq #6,d2
	moveq #8,d3
	moveq #10,d4
	moveq #$12,d5
	moveq #"0",d6
	addq.l #4,2(a7)	;skip movec vbr,d7
	rte
savereg:move.w (a7),d0		;the trick to grab the system
	move.w d0,regs+64+12	;sr
	move.l 2(a7),regs+64+8	;pc
	move.w #$2000,(a7)		;stay in sv
	rte

incexc:	addq.b #1,excnum		;no a6!
	rts
except:	bsr.s incexc			;well, it looks funny, but
	bsr.s incexc			;there are SOME entries here
	bsr.s incexc
	bsr.s incexc
	bsr.s incexc
	bsr.s incexc
	bsr.s incexc
	bsr.s incexc
	bsr.s incexc
	bsr.s incexc
	bsr.s incexc
	cmp.b #2,excnum			;adr/bus err
	bhi.s exc0
cpu68b:	move.l 0(a7),excadr	;68000:02,68010:10, we are patched
cpu68c:	move.w 0(a7),excinstr	;68000:06,68010:24
cpu68d:	move.w 0(a7),exceptsr	;68000:08,68010:00
cpu68e:	move.l 0(a7),exceptpc	;68000:10,68010,02
cpu68f:	lea 0(a7),a7		;68000:12,68010:3e
	bra.s exc3
exc0:	cmp.b #6,excnum			;trapv
	beq.s exc2
	cmp.b #11,excnum		;trap #x
	bne.s exc1
exc2:	subq.l #2,2(a7)
exc1:	move.w (a7),exceptsr
	move.l 2(a7),exceptpc
cpu68a:	lea 0(a7),a7		;68000:10,68010:12
exc3:	bclr #0,exceptpc+3
	bra.l g1

prtasc:	bsr.s doctrl
	tst.b d7
	beq.s prtasc0
	bra.L rawchr
prtasc0:rts

doctrl:	sf d7			;no a0,d1,d7 allowed down here
	cmp.b #$13,d0
	beq.L csright
	cmp.b #$12,d0
	beq.l csleft
	cmp.b #$11,d0
	beq.L csdown
	cmp.b #$10,d0
	beq.l csup
	cmp.b #1,d0
	beq.L cstop
	cmp.b #2,d0
	beq.L csbot
	cmp.b #3,d0
	beq.L csbeg
	cmp.b #4,d0
	beq.l csend
	cmp.b #$0d,d0
	beq.l enter
	cmp.b #$0e,d0
	beq.l shenter
	cmp.b #$07,d0	;sh-bs
	beq.l clrhome
	cmp.b #$08,d0	;bs
	beq.l backspc
	cmp.b #$09,d0	;del
	beq.l del
	cmp.b #$0a,d0	;sh-del
	beq.l insert
	cmp.b #$05,d0
	beq.s tab	;tab	
	cmp.b #$80,d0
	bcs.s nofkey
	cmp.b #$89,d0
	bls.s dofkey
nofkey:	st d7
	rts

dofkey:	move.w #1,buflen-base(a6)	;funky keys..
	lea fkeybuf(pc),a5
	sub.b #$80,d0
	ext.w d0
	mulu #fkeylen,d0
	lea (a5,d0.w),a5
	moveq #fkeylen-1,d2
dofk0:	move.b (a5)+,d0
	beq.s dofk1
	cmp.b #"|",d0			;more than one cmd?
	bne.s dofk2
	moveq #13,d0
dofk2:	bsr.L bufit
	dbf d2,dofk0
dofk1:	moveq #13,d0
	bra.L bufit

tab:	bsr.s tab0			;skips spaces 'til next data
	bne.s tab
tab1:	cmp.b #79,col-base(a6)
	beq.s tab2
	bsr.s tab0
	beq.s tab1
	cmp.b #"'",(a5)
	beq.s tab1
	rts
tab2:	sf col-base(a6)
tab0:	bsr.s csright
	bsr.L crsrtxt
	cmp.b #" ",(a5)
	rts

csbeg:	sf col-base(a6)
	rts
cstop:	sf row-base(a6)
	rts
csbot:	move.b #31,row-base(a6)
csr0:	rts
csright:addq.b #1,col-base(a6)
	cmp.b #80,col-base(a6)
	bne.s csr0
	sf col-base(a6)
csdown:	addq.b #1,row-base(a6)
	cmp.b #32,row-base(a6)
	bne.s csr0
	subq.b #1,row-base(a6)
	bra.l scroll

csleft:	tst.b col-base(a6)
	beq.s csl0
	subq.b #1,col-base(a6)
	rts
csl0:	tst.b row-base(a6)
	beq.s csl1
	subq.b #1,row-base(a6)
csend:	move.b #79,col-base(a6)
csl1:	rts
csup:	tst.b row-base(a6)
	beq.s csu0
	subq.b #1,row-base(a6)
csu0:	rts

clrhome:move.l scradr(pc),a5	;the lame stuff...
	move.w #640*256/8/4-1,d5
ch0:	clr.l (a5)+
	dbf d5,ch0
	lea txtscr(pc),a5
	move.w #80*32-1,d5
ch1:	move.b #" ",(a5)+
	dbf d5,ch1
	lea linebuf(pc),a5
	moveq #80-1,d5
ch2:	move.b #" ",(a5)+
	dbf d5,ch2
	sf row-base(a6)
	sf col-base(a6)
	moveq #">",d0
	bra.L rawchr

insert:	bsr.L crsrtxt
	move.l a5,a4
	bsr.L crsrbm
	moveq #79-1,d2
	move.b col(pc),d3
	ext.w d3
	sub.w d3,d2
	lea (a5,d2.w),a5
	lea (a4,d2.w),a4
	bcs.s ins2
ins0:	moveq #8-1,d3
ins3:	move.b (a5),1(a5)
	lea 640/8(a5),a5
	dbf d3,ins3
	lea -641(a5),a5
	move.b (a4)+,(a4)
	subq.l #2,a4
	dbf d2,ins0
ins2:	moveq #8-1,d5
ins1:	sf 1(a5)
	lea 640/8(a5),a5
	dbf d5,ins1
	move.b #" ",1(a4)
bs0:	rts			;two
backspc:tst.b col-base(a6)
	beq.s bs0
	bsr.l csleft
del:	bsr.L crsrtxt
	move.l a5,a4
	bsr.L crsrbm
	moveq #79-1,d2
	sub.b col(pc),d2
	bcs.s del2
del0:	moveq #8-1,d5
del4:	move.b 1(a5),(a5)
	lea 640/8(a5),a5
	dbf d5,del4
	lea -639(a5),a5
	move.b 1(a4),(a4)+
	dbf d2,del0
del2:	moveq #8-1,d5
del3:	sf (a5)
	lea 640/8(a5),a5
	dbf d5,del3
	move.b #" ",(a4)
	rts

enter:	movem.l d1/d7/a0,-(a7)
	move.b col(pc),d6
	sf col-base(a6)
	bsr.l csdown
	bsr.L crsrtxt	;a5 !
	lea -80(a5),a5

	cmp.b #">",(a5)
	bne.l igncmd

	lea cmd(pc),a4
scancmd:move.b (a4)+,d0
	beq.l igncmd
	cmp.b 1(a5),d0
	bne.s scancmd
	cmp.b #" ",d0
	beq.s again
	move.b d0,lastcmd-base(a6)
again:	lea cmd+1(pc),a3
	sub.l a3,a4
	add.l a4,a4
	add.l a4,a4
	lea cmdjmp(pc),a3
	move.l (a4,a3.l),a4

	lea 2(a5),a0
	lea para(pc),a3
	sub.l a2,a2
	clr.l d3
skpblk:	lea 79(a5),a1
ah3:	cmp.b #"'",(a0)
	beq.s ah5
	cmp.b #" ",(a0)
	bne.s endskip
	addq.l #1,a0
	cmp.l a0,a1
	bne.s ah3
endskip:
	moveq #8-1,d2		;maxlen	; convert cmd data
	clr.l d0
ah0:	cmp.l a0,a1
	beq.s endline
	move.b (a0)+,d1
	cmp.b #" ",d1
	beq.s ah1
	sub.b #"0",d1
	bcs.s ah5
	cmp.b #9,d1
	ble.s ah2
	bclr #5,d1
	cmp.b #"A"-"0",d1
	blt.s ah5
	cmp.b #"F"-"0",d1
	bgt.s ah5
	subq.b #"A"-"0"-10,d1	
ah2:	lsl.l #4,d0
	or.b d1,d0
	dbf d2,ah0
ah1:	move.l d0,(a3)+

	addq.b #1,d3
ah4:	cmp.b #16,d3
	bne.s ah3
ah5:
	sf d7
	subq.l #1,a0

	move.l a5,a2
ah6:	cmp.b #34,(a2)+
	beq.s ah7
	cmp.l a2,a1
	bne.s ah6
	sub.l a2,a2
ah7:

	;d3:#para,d6:oldcol,a0:stop,a2:quote,a5:cmdtxt / st d7:ok

endline:jsr (a4)	;execute cmd...
	tst.b d7
	bne.s truecmd

	moveq #"?",d0
	bsr.L rawchr
igncmd:	moveq #"?",d0
	bsr.L rawchr
shent:	bsr.l csdown
	sf col-base(a6)
truecmd:tst.b col-base(a6)
	bne.s nnspec
	moveq #">",d0
	bsr.L rawchr
nnspec:	movem.l (a7)+,d1/d7/a0
	rts
shenter:movem.l d1/d7/a0,-(a7)	;no cmd execution
	bra.s shent

cursoff:btst #1,nocrsr-base(a6)
	beq.s coff0
	bsr.l chgcrsr
coff0:	bset #0,nocrsr-base(a6)
	rts
curson:	bsr.l chgcrsr
	bclr #0,nocrsr-base(a6)
	rts

rawprt:	moveq #79,d1		;print onto printer if online
	lea linebuf(pc),a0
rp0:	btst #0,$bfd000
	bne.s noprt
	move.b (a0)+,d0
	bsr.s chrprt
	dbf d1,rp0
	moveq #13,d0		;CR
	bsr.s chrprt
	moveq #11,d0		;LF
chrprt:	move.b d0,$bfe101
	moveq #100,d0
waitprt:dbf d0,waitprt
wprt2:	btst #0,$bfd000
	beq.s noprt
	btst #2,$dff016
	bne.s wprt2
noprt:	rts
	
rawline:tst.b prtflag-base(a6)
	beq.s noprint
	bsr.s rawprt
noprint:moveq #79,d1
	lea linebuf(pc),a0
rl0:	move.b (a0),d0
	move.b #" ",(a0)+
	bsr.s rawchr
	dbf d1,rl0
	lea linebuf(pc),a0
	rts	
crsrtxt:lea txtscr(pc),a5	;gimme pointers
	moveq #0,d5
	move.b col(pc),d5
	add.l d5,a5
	move.b row(pc),d5
	mulu #80,d5
	add.l d5,a5
	rts

rawchr:	movem.l d0-d1/d5/a2/a5,-(a7)
	bsr.s crsrtxt

	moveq #$60,d1
	and.b d0,d1		;0-1f,80-9f?
	bne.s rc1
	moveq #" ",d0
rc1:	moveq #" ",d1
	move.b d0,(a5)		;ascii
	bpl.s rc2
	sub.b d1,d0
rc2:	sub.b d1,d0	
	and.w #$ff,d0		;fontindex

	bsr.s crsrbm
	lea font(pc),a2

	moveq #8-1,d1
rc0:	move.b (a2,d0.w),(a5)
	lea 192(a2),a2
	lea 640/8(a5),a5
	dbf d1,rc0

	bsr.L csright
	movem.l (a7)+,d0-d1/d5/a2/a5
	rts
crsrbm:	move.l scradr(pc),a5	;more pointers
	moveq #0,d5
	move.b col(pc),d5
	add.l d5,a5
	move.b row(pc),d5
	mulu #640/8*8,d5
	add.l d5,a5
	rts

scroll:	movem.l d0/a1-a2,-(a7)
	lea $dff000,a2
waitfrm:btst #0,5(a2)			;$dff005, screen done?
	bne.s waitfrm
	bsr.s waitblt
	move.l #$09f00000,$40(a2)	;$dff040 scroll up
	moveq #-1,d0	
	move.l d0,$44(a2)		;$dff044
	clr.l $64(a2)			;$dff064
	move.l scradr(pc),a1
	move.l a1,$54(a2)		;$dff054
	lea 640/8*8(a1),a1
	move.l a1,$50(a2)		;$dff050
	move.w #[256-8]*64+40,$58(a2)	;$dff058

	lea txtscr(pc),a1
	move.w #80*31/4-1,d0
scup2:	move.l 80(a1),(a1)+
	dbf d0,scup2

	moveq #80-1,d0
scup3:	move.b #" ",(a1)+
	dbf d0,scup3

	bsr.s waitblt

	clr.w $74(a2)			;$dff074
	move.l #$01f00000,$40(a2)	;$dff040 clr bottom
	move.l scradr(pc),a1
	lea  640/8*8*31(a1),a1
	move.l a1,$54(a2)		;$dff054
	move.w #8*64+40,$58(a2)		;$dff058

	bsr.s waitblt
	movem.l (a7)+,d0/a1-a2
	rts
waitblt:move.w #$8400,$96(a2)		;$dff096, we are nasty
	btst #14,$02(a2)		;$dff002
	bne.s waitblt
	move.w #$0400,$96(a2)		;$dff096
	rts

audint:	movem.l d0/d1/a0,-(a7)		;the soundint
	lea $dff000,a0			;play any length(>128k!)

	moveq #127,d0
au0:	dbf d0,au0

	move.l para+4(pc),d1
	move.l para(pc),d0
	sub.l d0,d1
	bls.s au1

	moveq #sndintstep,d0
	cmp.l d0,d1
	bls.s au3
	move.l d0,d1
au3:	move.l para(pc),$a0(a0)	;$dff0a0
	move.l para(pc),$b0(a0)	;$dff0b0
	add.l d1,para		;the online counter...
	lsr.l #1,d1
	move.w d1,$a4(a0)	;$dff0a4
	move.w d1,$b4(a0)	;$dff0b4

	move.w para+10(pc),d0
	moveq #124,d1
	cmp.w d1,d0
	bcc.s au4
	move.w d1,d0
au4:	move.w d0,$a6(a0)	;$dff0a6
	move.w d0,$b6(a0)	;$dff0b6
	moveq #64,d0		;volume
	move.w d0,$a8(a0)	;$dff0a8
	move.w d0,$b8(a0)	;$dff0b8
	move.w #$8003,$96(a0)	;$dff096
	bra.s au2
	
au1:	clr.l para+4
	move.w #$0080,$9a(a0)	;$dff09a
au2:	move.w #$0080,$9c(a0)	;$dff09c clr sndint
	movem.l (a7)+,d0/d1/a0
	rte

vblint:	movem.l d0-d7/a0-a6,-(a7)
	lea base(pc),a6
	lea $dff000,a5

	tst.b frzflag-base(a6)		;did we freeze?
	beq.s mutil3
	move.l scradr(pc),$e0(a5)	;cpu=copper?
	move.l #$2c812cc1,$8e(a5)
	move.l copadr(pc),a0
	move.w cop92-coplst+2(a0),$92(a5)
	move.w cop94-coplst+2(a0),$94(a5)
	move.w cop100-coplst+2(a0),$100(a5)
	clr.w $102(a5)
	clr.w $108(a5)
	move.w bgcol+2(pc),$180(a5)
	move.w fgcol+2(pc),$182(a5)
	move.w #$ff0,$1a2(a5)
	clr.w $1a4(a5)
	move.w #$0f0,$1a6(a5)
mutil3:
	lea $bfe001,a4
	move.l spradr(pc),a0
	lea $120(a5),a1		;$dff120
	move.l a0,(a1)+
	lea 72(a0),a0
	moveq #7-1,d0
sprptr:	move.l a0,(a1)+
	dbf d0,sprptr

	move.b $0a(a5),d0	;$dff00a set mousecursor
	move.b mousexy+1(pc),d1
	move.b d0,mousexy+1-base(a6)
	sub.b d1,d0
	ext.w d0
	add.w d0,msypos-base(a6)
	cmp.b #1,d0
	bls.s mou5
	cmp.b #-1,d0
	bcc.s mou5
	add.w d0,d0
mou5:	muls #640/8,d0
	sub.l d0,msycnt-base(a6)
	move.b $0b(a5),d0	;$dff00b
	move.b mousexy(pc),d1
	move.b d0,mousexy-base(a6)
	sub.b d1,d0
	ext.w d0
	ext.l d0
	move.l d0,d1
	divs #2,d0
	add.w d0,msxpos-base(a6)
	sub.l d1,msycnt-base(a6)
	bpl.s mou4
	clr.l msycnt-base(a6)
mou4:	move.w msypos(pc),d0
	cmp.w #40,d0
	bhi.s mou2
	moveq #40,d0
mou2:	cmp.w #295,d0
	bls.s mou3
	move.w #295,d0
mou3:	move.w d0,msypos-base(a6)
	move.w msxpos(pc),d1
	cmp.w #60,d1
	bhi.s mou0
	moveq #60,d1
mou0:	cmp.w #219,d1
	bls.s mou1
	move.w #219,d1
mou1:	move.w d1,msxpos-base(a6)

	btst #0,nocrsr-base(a6)
	bne.s nosetcs
	move.w #$0020,$96(a5)	;$dff096
	move.w $0a(a5),d0	;$dff00a
	cmp.w lastms(pc),d0
	beq.s noblnk
	move.w d0,lastms-base(a6)
	move.b #50,msdel-base(a6)
noblnk:	tst.b msdel-base(a6)
	beq.s nosetcs
	subq.b #1,msdel-base(a6)
	move.w #$8020,$96(a5)	;$dff096

	btst #6,(a4)		;$bfe001
	bne.s nosetcs
	bsr.l cursoff
	move.b msxpos+1(pc),d0
	sub.b #60,d0	
	lsr.b #1,d0
	move.b d0,col-base(a6)
	move.w msypos(pc),d0
	sub.w #40,d0
	lsr.w #3,d0
	move.b d0,row-base(a6)
	bsr.L curson
nosetcs:
	move.l spradr(pc),a0	;setspr
	move.w msypos(pc),d0
	sf 3(a0)
	btst #8,d0
	beq.s mvert0
	bset #2,3(a0)
mvert0:	move.b d0,(a0)
	add.w #17,d0
	btst #8,d0
	beq.s mvert1
	bset #1,3(a0)
mvert1:	move.b d0,2(a0)
	move.b msxpos+1(pc),1(a0)

	move.b ascii(pc),d0	;keysub,delay and repeat...
	beq.s rk0
	cmp.b #$1b,d0		;escape
	beq.s rk0
	cmp.b lastkey(pc),d0
	bne.s rk1
	cmp.b #20,repdel-base(a6)
	beq.s rk2
	addq.b #1,repdel-base(a6)
	bra.s rk3
rk2:	addq.b #1,keydel-base(a6)
	cmp.b #2,keydel-base(a6)
	blt.s rk3
	sf keydel-base(a6)
	bsr.s bufit
	bra.s rk3
rk1:	move.b d0,lastkey-base(a6)
rk0:	sf repdel-base(a6)
rk3:

	btst #0,nocrsr-base(a6)
	bne.s filter
	bchg #1,(a4)		;$bfe001
	bra.s noflt
filter:	bset #1,(a4)		;$bfe001
noflt:	bsr.s cursor

novbl:	move.w #$0070,$9c(a5)	;$dff09c
	movem.l (a7)+,d0-d7/a0-a6
	rte

cursor:	btst #0,nocrsr-base(a6)
	bne.s crsr0
	subq.b #1,crsrdel-base(a6)
	bne.s crsr0
	move.b #10,crsrdel-base(a6)
chgcrsr:movem.l d5/a5,-(a7)
	bsr.L crsrbm
	moveq #8-1,d5
chgcsln:not.b (a5)
	lea 640/8(a5),a5
	dbf d5,chgcsln
	bchg #1,nocrsr-base(a6)
	movem.l (a7)+,d5/a5
crsr0:	rts

bufit:	movem.l d0-d1/a0,-(a7)
	lea keybuf(pc),a0
	move.w buflen(pc),d1
	beq.s bufit0
	cmp.w #40,d1
	bge.s ign0
	cmp.b #13,d0
	bne.s bufit0
	cmp.b -1(a0,d1.w),d0
	beq.s ign0
bufit0:	move.b d0,(a0,d1.w)
	addq.w #1,buflen-base(a6)
ign0:	movem.l (a7)+,d0-d1/a0
	rts

keyint:	move.w #$0008,$dff09a
	movem.l d0/d1/a0/a6,-(a7)
	lea base(pc),a6
	btst #3,$bfed01		;ciaa icr sp?
	beq.l key0
	clr.l d0
	move.b $bfec01,d0
	bset #6,$bfee01		;cia sp out
	st $bfec01
	not.b d0
	lsr.w #1,d0
	bcs.s keyoff
	cmp.b #$60,d0		;any shifting?
	blt.s key2
	cmp.b #$68,d0
	bge.s key3
	bset d0,shflag-base(a6)
	bra.s key3
key2:	move.b shflag(pc),d1
	and.b #7,d1
	beq.s key4
	add.w #$60,d0
key4:	lea keytab(pc),a0
	move.b (a0,d0.w),d0
	beq.s key3
	move.b d0,ascii-base(a6)
	cmp.b #$1b,d0		;escape
	beq.s key3
	bsr.L bufit
	bra.s key3
keyoff:	cmp.b #$60,d0		;any shifting?
	blt.s key5
	cmp.b #$68,d0
	bge.s key3
	bclr d0,shflag-base(a6)
	bra.s key3
key5:	sf ascii-base(a6)
key3:	moveq #100,d0
key1:	dbf d0,key1
	bclr #6,$bfee01		;ciaa sp in
key0:	movem.l (a7)+,d0/d1/a0/a6
	move.w #$0008,$dff09c	;next one,please
	move.w #$8008,$dff09a
	rte
; here come the commands..

cmd:	dc.b "SLVCslDipgh?rm:a;xXoecfFtWd,nKBbMPk ",0
even
cmdjmp:	dc.l save,load,syncw,check,sblk,lblk,drive,i,p,g,hunk
	dc.l calc,r,m,mm,a,aa,x,xclr,o,e,c,f,frel,t
	dc.l work,d,n,nass,setkey,color,bpl,map,print,setmap,spc

save:	lea 2(a5),a0	;hi ffc, that's what you need?
	bsr.L getfilename	;a0:txt>a0:endname,a2:name,d4.w:len
	move.w d4,para+12-base(a6)
	beq.L svq
	cmp.w #30,d4
	bhi.L svq

	bsr.L skipspc
	move.l a0,a3
	bsr.l atolong
	move.l d0,para-base(a6)
	move.l a3,a0
	bsr.L skipspc
	move.l a0,a3
	bsr.l atolong
	move.l d0,para+4-base(a6)
	beq.l svq

	move.l para(pc),d1
	cmp.l d0,d1
	bhi.L svq
	move.l d1,para+8-base(a6)

	st wrcmd-base(a6)
	st wrflag-base(a6)

	bsr.L initdosdrive	;reads root/dir
	beq.L sv1

	move.l a2,a0
	bsr.L fnhash		;a0:str,d4.w:fnlen>d4.w:rootidx,d5:blk
	beq.s sv5

	bsr.L searchfile	;d5:1st hash,a2:fname
				;>prevchain,a4:header
	beq.s sv5
	bsr.L fexists
	bra.L sv1
	
sv5:	bsr.l tsterr
	beq.L sv1

	move.l roothash(pc),a0
	move.l (a0),d5		;d4:hashindex

	bsr.L getfreehead	;fileheader
	beq.L savfull
	move.l d0,a3		;headerkey
	move.l d0,fheader-base(a6)
	clr.w datanum-base(a6)	;cnt datablk

	lea header(pc),a5
	move.l a5,a0
	moveq #512/4-1,d6
sv2:	clr.l (a0)+
	dbf d6,sv2
	moveq #2,d6
	move.l d6,(a5)		;type:fh

	lea linebuf+1(pc),a0
	lea savetxt(pc),a1
	bsr.l txttobuf
	move.w para+12(pc),d0	;fnlen!
	subq.w #1,d0
	lea $1b1(a5),a1		;copy bcplname
sv4:	move.b (a2),(a1)+
	move.b (a2)+,(a0)+
	addq.b #1,$1b0(a5)
	dbf d0,sv4
	move.b #34,(a0)+
	bsr.L rawline
	bsr.L csdown

	move.l d5,$1f0(a5)		;hashchain
	move.l dirkey(pc),$1f4(a5)	;fileheader parent

	move.l para+4(pc),d0
	sub.l para(pc),d0
	move.l d0,$144(a5)	;filesize

	bsr.L getfree
	beq.L savfull
	move.l d0,d4

;;;;;;;	take care of registers...
sv14:	moveq #-3,d6
	move.l d6,$1fc(a5)	;type
	move.l a3,4(a5)		;own key

	lea $134+4(a5),a4	;1st data

sv8:	move.l d4,-(a4)
	addq.l #1,8(a5)		;datas in this header

	lea rootblk+512(pc),a0
	moveq #512/4-1,d6	
sv9:	clr.l -(a0)
	dbf d6,sv9

	moveq #8,d6
	move.l d6,(a0)			;type
	move.l d4,4(a0)			;ownkey:fileheader ! (temp)
	move.l para+4(pc),d0
	sub.l para+8(pc),d0
	divu #488,d0
	tst.w d0		;another data?
	beq.s sv17
	
	bsr.L getfree
	beq.L savfull
	move.l d0,d4
	move.l d4,$10(a0)	;nextdata	
	
sv17:	move.l para+8(pc),a1
	lea $18(a0),a2

sv10:	cmp.l para+4(pc),a1
	bcc.s sv11
	move.b (a1)+,(a2)+
	addq.l #1,12(a0)	;bytes inblk
	cmp.w #488,14(a0)	;has been cleared
	bne.s sv10

sv11:	move.l a1,para+8-base(a6)
	addq.w #1,datanum-base(a6)
	move.w datanum(pc),8+2(a0)	;datanum

	move.l #rootblk,d6

	move.l 4(a0),d5
	move.l fheader(pc),4(a0)	;dataownkey=fileheader!
	bsr.L datasum
	move.l d3,20(a0)
	
	bsr.L putsec		;save data
	bsr.L tsterr
	beq.L sv1

	lea linebuf+1(pc),a0
	move.l para(pc),d0
	move.l para+8(pc),d1
	bsr.l csup
	bsr.L twoadr_
	bsr.L rawline
	bsr.L stopit
	beq.L sv1

	cmp.l para+4(pc),a1	;next filelist or eof?
	beq.s sv15

	moveq #72,d6
	cmp.l 8(a5),d6
	bne.s sv12

	bsr.L getfreehead
	beq.L savfull
	move.l d0,a3
	move.l d0,$1f8(a5)	;filelist

sv15:	move.l a5,a0
	move.l $134(a0),$10(a0)	;1st data
	bsr.L datasum
	move.l d3,20(a0)
	move.l 4(a0),d5
	move.l a0,d6
	bsr.L putsec		;save header
	bsr.L tsterr
	beq.s sv1

	cmp.l para+4(pc),a1	;eof
	beq.s sv16

	moveq #512/4-1,d6
sv13:	clr.l (a0)+
	dbf d6,sv13
	move.l fheader(pc),$1f4(a5)
	moveq #$10,d6
	move.l d6,(a5)		;type:filelist
	bra.L sv14

sv12:	cmp.l para+4(pc),a1	;eof
	bcs.L sv8
	
sv16:	move.l #rootblk,d6		;rootblk/dirblk
	move.l dirkey(pc),d5
	bsr.L getsec
	bsr.L tsterr
	beq.s sv1
	move.l roothash(pc),a0
	move.l fheader(pc),(a0)
	lea rootblk(pc),a0		;root chk
	bsr.L datasum
	move.l d3,20(a0)
	bsr.L putsec		;write root
	bsr.L tsterr
	beq.L sv1

	bsr.L bitsum
	lea bitmap(pc),a0
	move.l a0,d6
	move.l bitsec(pc),d5
	bsr.L putsec
	bsr.L tsterr
	beq.s sv1

	bsr.L updatedisk
sv1:	bsr.L motoff
	st d7
svq:	rts
savfull:bsr.L dskfull
	bra.s sv1

freeblk:lea 1759.w,a0		;too much is too much...
	cmp.l a0,d0
	bhi.s freeb0
	lea bitmap(pc),a0
	subq.l #2,d0
	bmi.s freeb0
	move.l d0,d1
	lsr.w #5,d1
	lsl.w #2,d1	
	move.l 4(a0,d1.w),d2
	bset d0,d2
	bne.s freeb0
	move.l d2,4(a0,d1.w)
	moveq #-1,d0
	rts
freeb0:	clr.l d0
	rts

getfreehead:move.l #882-2,d0	;collect the headers a bit..
	bsr.s getf2
	beq.s getfree
	rts
getfree:clr.l d0		;a0,d0,d1>d0
getf2:	move.l a0,-(a7)
	lea bitmap(pc),a0
getf1:	move.w d0,d1
	lsr.w #5,d1
	lsl.w #2,d1
	move.l 4(a0,d1.w),d2
	bclr d0,d2
	bne.s getf0
	addq.l #1,d0
	cmp.w #1760-2,d0
	bne.s getf1
	moveq #-2,d0
getf0:	move.l d2,4(a0,d1.w)
	addq.l #2,d0
	move.l (a7)+,a0
	tst.l d0
	rts

bitsum:	lea bitmap(pc),a0		;a0:bitmap
	lea 4(a0),a1
	clr.l d1
	moveq #512/4-1-1,d0
bms0:	sub.l (a1)+,d1
	dbf d0,bms0
	move.l d1,(a0)
	rts

getfilename:
	bsr.s skipspc
	move.l a0,a2
	cmp.b #34,(a0)
	bne.s fnquo0
	clr.w d4
	addq.l #1,a2
	addq.l #1,a0
fnquo1:	cmp.b #34,(a0)+
	beq.s fnquo2
	addq.w #1,d4
	bra.s fnquo1
fnquo0:	bsr.s findspc
	move.l a0,d4
	sub.l a2,d4	;fnlen
fnquo2:	tst.w d4
	rts
skipspc:cmp.b #" ",(a0)
	bne.s skspc0
	addq.l #1,a0
	bra.s skipspc
skspc0:	rts
findspc:cmp.b #" ",(a0)
	beq.s fnspc0
	addq.l #1,a0
	bra.s findspc
fnspc0:	rts

load:	lea 2(a5),a0		;load a file, usual stuff...

	bsr.s getfilename	;a0:txt>a0:endname,a2:name,d4.w:len
	move.w d4,para+12-base(a6)
	beq.L ldq
	cmp.w #30,d4
	bhi.L ldq

	bsr.s skipspc
	move.l a0,a3
	bsr.l atolong
	move.l d0,para-base(a6)
	move.l d0,para+4-base(a6)
	beq.l ldq

	sf wrcmd-base(a6)
	sf wrflag-base(a6)
	bsr.L initdosdrive	;reads root/dir
	beq.L ld1

	move.l a2,a0
	bsr.L fnhash	;a0:str,d4.w:fnlen>d4.w:rootidx,d5:blk
	beq.s ld5

	bsr.L searchfile	;d5:1st hash,a2:fname
				;>prevchain,a4:header
	bne.s ld3

ld5:	bsr.L fnotfnd
	bra.L ld1

ld3:	bsr.L tsterr
	beq.L ld1

	moveq #2,d0
	cmp.l $1fc(a4),d0
	bne.s ld2
	bsr.L fisdir
	bra.L ld1

ld2:	lea linebuf+1(pc),a0
	lea loadtxt(pc),a1
	bsr.l txttobuf
	move.w para+12(pc),d0		;fnlen!
	subq.w #1,d0
	move.l a2,a1
ld4:	move.b (a1)+,(a0)+
	dbf d0,ld4
	move.b #34,(a0)+
	bsr.L rawline
	bsr.L csdown

ld6:	move.l 8(a4),d3		;#blk in header
	lea $134+4(a4),a3	;blkmap

ld8:	lea linebuf+1(pc),a0
	move.l para(pc),d0
	move.l para+4(pc),d1
	bsr.L twoadr_
	bsr.L csup
	bsr.L rawline

	bsr.L stopit
	beq.s ld1

	subq.l #1,d3
	bmi.s ld7
	move.l -(a3),d5
	lea rootblk(pc),a0
	move.l a0,d6		;databuf

	bsr.l getsec
	bsr.s tsterr
	beq.s ld1
	
	move.l $c(a0),d0	;bytes in blk
	lea $18(a0),a0		;datastart
	move.l para+4(pc),a1
ld10:	subq.w #1,d0
	bmi.s ld11
	move.b (a0)+,(a1)+
	bra.s ld10
ld11:	move.l a1,para+4-base(a6)
	bra.s ld8

ld7:	move.l $1f8(a4),d5	;file extension
	beq.s ld1
	move.l a4,d6
	bsr.L getsec
	bra.s ld6

ld1:	bsr.L motoff
	st d7
ldq:	rts

searchfile:			;d5:1st hash,a2:fname
	lea header(pc),a4	;>prevchain,a4:header
	move.l a4,d6
	move.l dirkey(pc),prevchain-base(a6)	;rootchain!
srfile2:bsr.L getsec
	lea $1b0(a4),a0		;filename
	move.b (a0)+,d0
	move.l a2,a1
srfile0:subq.b #1,d0
	bmi.s srfile1
	move.b (a0)+,d2
	bsr.L upcase
	move.b d2,d3
	move.b (a1)+,d2
	bsr.L upcase
	cmp.b d2,d3
	beq.s srfile0
	move.l 4(a4),prevchain-base(a6)		;prevchain
	move.l $1f0(a4),d5
	bne.s srfile2
	clr.l d0		;beq.s notfnd
	rts
srfile1:moveq #-1,d0
	rts

tsterr:	tst.b dskerr-base(a6)
	beq.s tste0
	movem.l d1/a0-a1,-(a7)
	lea werrtxt(pc),a1
	tst.b wrflag-base(a6)
	bne.s tste1
	lea rerrtxt(pc),a1
tste1:	bsr.s fnf0
	sf dskerr-base(a6)
	movem.l (a7)+,d1/a0-a1
	rts			;beq.s error
tste0:	moveq #-1,d0
	rts

bmaperr:lea bittxt(pc),a1	;the errors are cummin'
	bra.s fnf0
dskfull:lea dskftxt(pc),a1
	bra.s fnf0
dnotmt:	lea dnmtxt(pc),a1
	bra.s fnf0
dexists:lea dextxt(pc),a1
	bra.s fnf0
disfile:lea diftxt(pc),a1
	bra.s fnf0
dnotfnd:lea dnftxt(pc),a1
	bra.s fnf0
fexists:lea fextxt(pc),a1
	bra.s fnf0
fisdir:	lea fidtxt(pc),a1
	bra.s fnf0
fnotfnd:lea fnftxt(pc),a1
fnf0:	lea linebuf+1(pc),a0
	bsr.l txttobuf
	bra.L rawline

fnhash:	move.l d4,d0
	clr.w d2
	subq.w #1,d0
fn1:	mulu #13,d4
	move.b (a0)+,d2
	bsr.s upcase
	add.w d2,d4
	and.w #$7ff,d4
	dbf d0,fn1
	divu #72,d4
	swap d4
	addq.w #6,d4
	lsl.w #2,d4
	lea rootblk(pc),a0
	lea (a0,d4.w),a0
	move.l a0,roothash-base(a6)
	move.l (a0),d5
	rts
upcase:	cmp.b #"a",d2
	bcs.s fn2
	cmp.b #"z",d2
	bhi.s fn2
	bclr #5,d2
fn2:	rts

syncw:	cmp.b #1,d3		;yo, we have a new syncword
	bhi.s syq
	tst.b d3
	beq.s sy0
	move.w para+2(pc),sync-base(a6)
sy0:	lea linebuf+1(pc),a0
	lea synctxt(pc),a1
	bsr.l txttobuf
	move.w sync(pc),d0
	bsr.l wordtoa_
	bsr.l rawline

	st d7
syq:	rts

check:	cmp.b #2,d3		;lets calc some checksums
	bne.s chkq
	move.l para(pc),d4
	btst #0,d4
	bne.s chkq

	moveq #$b,d5
	cmp.l para+4(pc),d5
	bne.s chk0
	
	move.l d4,a0
	bsr.s bootsum		;d2:old,d3:new
	move.l d3,4(a0)
	bra.s chk1

chk0:	moveq #$d,d5
	cmp.l para+4(pc),d5
	bne.s chkq
	move.l d4,a0
	bsr.l datasum
	move.l d3,20(a0)	;d2:old,d3:new

chk1:	lea linebuf+1(pc),a0
	lea chktxt1(pc),a1
	bsr.l txttobuf
	move.l d2,d0
	bsr.l longtoa_
	lea chktxt2(pc),a1
	bsr.l txttobuf
	move.l d3,d0
	bsr.l longtoa_
	bsr.l rawline

	st d7
chkq:	rts

bootsum:move.l a0,-(a7)
	move.l 4(a0),d2
	clr.l 4(a0)
	clr.l d3
	move.w #$ff,d1
boots0:	add.l (a0)+,d3
	bcc.s boots1
	addq.l #1,d3
boots1:	dbf d1,boots0
	not.l d3
	move.l (a7)+,a0
	rts

sblk:	st wrcmd-base(a6)	; we want to load/save tracks
	bra.s rds6
lblk:	sf wrcmd-base(a6)
rds6:	cmp.b #1,d3
	bls.L rdsq
	cmp.b #3,d3
	bhi.L rdsq
	move.l para(pc),d6	;loadadr
	btst #0,d6
	bne.L rdsq

	move.l para+4(pc),d5
	moveq #1,d4
	cmp.b #3,d3
	bne.s rds0
	move.l para+8(pc),d4
rds0:	cmp.b #"s",(a0)		;para=sectors?
	beq.s rds9
	moveq #22,d0
	mulu d0,d4	;numcyl
	mulu d0,d5	;1st cyl
rds9:	cmp.l #83*22-1,d5
	bhi.s rdsq

	add.l d5,d4
	cmp.l #83*22,d4
	bls.s rds1
	move.l #83*22,d4
rds1:
	bsr.L moton	;stays selected
	bsr.L stepup
	bsr.L trk0
	sf dskerr-base(a6)
	sf truebuf-base(a6)
	clr.w secinbuf-base(a6)
	move.b wrcmd(pc),wrflag-base(a6)
	bsr.L testindrive
	beq.s rds7

rds3:	cmp.l d5,d4
	bls.s rds2

	tst.b wrcmd-base(a6)
	bne.s rds4
	bsr.L getsec	;d5.l:blk,d6:adr ;del:d0,d1,a1;dskerr
	bra.s rds5
rds4:	bsr.l putsec		;d5.l:blk,d6:adr

rds5:	move.b dskerr(pc),d3

	move.l d6,d0		;loadadr
	bsr.s thsinfo

	cmp.b #29,d3
	beq.s rds7

	lea $200.w,a0
	add.l a0,d6
	addq.l #1,d5

	bsr.L stopit
	bne.s rds3

rds2:	bsr.L updatedisk
rds7:	bsr.L motoff		;deselect
	st d7
rdsq:	rts


thsinfo:move.l d0,d1
	lea $200.w,a0
	add.l a0,d1
	lea linebuf+1(pc),a0
	bsr.l twoadr_
	lea trktxt(pc),a1
	bsr.l txttobuf
	move.b trk(pc),d0
	lsr.b #1,d0
	bsr.l bytetod
	lea hedtxt(pc),a1
	bsr.l txttobuf
	move.b trk(pc),d0
	and.b #1,d0
	add.b #"0",d0
	move.b d0,(a0)+
	lea sectxt(pc),a1
	bsr.L txttobuf
	move.b sec(pc),d0
	bsr.l bytetod
	lea errtxt(pc),a1
	bsr.L txttobuf
	move.b dskerr(pc),d0
	sf dskerr-base(a6)
	bsr.l bytetod
	lea blktxt(pc),a1
	bsr.L txttobuf
	move.w d5,d0
	bsr.L wordtoa_
	move.b #"=",(a0)+
	bsr.L wordtod
	bra.L rawline

calcts:	move.l d5,d0
	divu #11,d0
	move.b d0,d1		;trk
	cmp.b trk(pc),d1
	beq.s cal1
	sf truebuf-base(a6)
cal1:	swap d0
	move.b d0,sec-base(a6)
	rts

testindrive:
	btst #2,$bfe001
	bne.s tid0
	lea nodisk(pc),a1
tid2:	lea linebuf(pc),a0
	bsr.L drvnum
	bsr.L txttobuf
	bsr.L rawline
	clr.l d0
	rts		;beq.s error
tid0:	tst.b wrflag-base(a6)
	beq.s tid1
	lea wrdisk(pc),a1
	btst #3,$bfe001
	beq.s tid2
tid1:	moveq #-1,d0
	rts		;beq.s error

testdosdsk:
	lea rootblk(pc),a0
	move.l a0,d6
	clr.l d5
	bsr.l getsec

	move.l rootblk(pc),d0	;the magic word
	cmp.l #"DOS"*256,d0
	beq.s tdd0

nodos:	lea ndostxt(pc),a1
nodos2:	lea linebuf(pc),a0
	bsr.l drvnum
	bsr.L txttobuf
	bsr.L rawline
	clr.l d0
	rts

tdd0:	move.l #880,d5
	bsr.L getsec

	move.l d6,a0
	bsr.s datasum		;d2:old,d3:new
	cmp.l d3,d2
	beq.s tdd2
	lea chktxt(pc),a1
	bra.s nodos2
tdd2:	tst.b wrcmd-base(a6)
	beq.s tdd1
	tst.l $138(a0)
	bne.s tdd1
	lea dskvtxt(pc),a1
	bra.s nodos2
tdd1:	move.l $13c(a0),d5
	move.l d5,bitsec-base(a6)
	lea bitmap(pc),a1
	move.l a1,d6
	bsr.L getsec 	
	bra.L tsterr

datasum:move.l a0,-(a7)
	moveq #512/4-1,d1
	move.l 20(a0),d2
	clr.l 20(a0)
	clr.l d3
datsum0:sub.l (a0)+,d3
	dbf d1,datsum0
	move.l (a7)+,a0
	rts
	
putsec:	movem.l d0-d7/a0-a6,-(a7)	;puts sectors into buffer
	st wrflag-base(a6)

	move.l d5,d0		;blk
	divu #11,d0
	cmp.b trk(pc),d0	;do we change tracks?
	beq.s puts1
	
	tst.w secinbuf-base(a6)
	beq.s puts1		;nutin' to write
	bsr.L updatedisk
	clr.w secinbuf-base(a6)

puts1:	move.l d6,a0
	lea dostrkbuf(pc),a1
	move.l d5,d4
	divu #11,d4
	swap d4
	move.w secinbuf(pc),d0
	bset d4,d0
	move.w d0,secinbuf-base(a6)
	mulu #512,d4
	moveq #512/4-1,d0
puts5:	move.l (a0)+,(a1,d4.w)
	addq.w #4,d4
	dbf d0,puts5
puts4:	bsr.L calcts		;d5
	bsr.L dotrk
	movem.l (a7)+,d0-d7/a0-a6
	rts

updatedisk:movem.l d0-d7/a0-a6,-(a7)
	tst.w secinbuf-base(a6)	;reads in missing sectors and writes
	beq.L updat3
	st wrflag-base(a6)
	sf truebuf-base(a6)
	sf dskerr-base(a6)

	lea dostrkbuf(pc),a1
	move.l a1,d6
	move.b trk(pc),d5
	ext.w d5
	mulu #11,d5
	clr.b d4
updat0:	bsr.L calcts		;d5.l>d1.b=trk;del:d0
	bsr.L dotrk		;del:a1,d1,d0
	tst.b dskerr-base(a6)
	bne.s updat1
	move.w secinbuf(pc),d0
	btst d4,d0
	bne.s updat2
	bsr.L readsec		;d6:adr
updat2:	addq.l #1,d5
	lea $200.w,a1
	add.l a1,d6
	addq.b #1,d4
	cmp.b #11,d4
	bne.s updat0

updat1:	tst.b dskerr-base(a6)
	beq.s updat4

	move.w #$1000,d0	;there has been a readerror
badread:move.w d0,$dff180
	dbf d0,badread

updat4:	cmp.b #29,dskerr-base(a6)
	beq.s updat3

	lea dostrkbuf(pc),a0
	bsr.L codemfm
	bsr.L writemfm	;wait >1.2 ms before sel/step/...
	lea $bfd100,a1
	bsr.L mytime
updat3:	movem.l (a7)+,d0-d7/a0-a6
	rts

getsec:	tst.w secinbuf-base(a6)	;get a sector (and write buffer)
	beq.s gets1
	bsr.L updatedisk
	clr.w secinbuf-base(a6)
gets1:	sf wrflag-base(a6)
	bsr.L calcts		;d5.l>d1.b=trk;del:d0
	bsr.L dotrk		;del:a1,d1,d0
	tst.b dskerr-base(a6)
	beq.s readsec		;d6:adr
	rts
readsec:movem.l d0-d6/a1-a3,-(a7)
	moveq #retry,d5
rsec7:	tst.b truebuf-base(a6)
	bne.s rsec1
	bsr.L readmfm		;del:d0,a2
rsec1:	move.l dskadr(pc),a2
	lea readlen*2(a2),a3
	moveq #11-1,d2
rsec2:	move.w sync(pc),d0
	cmp.l a3,a2
	bhi.s rsec8		;no sync found
	cmp.w (a2)+,d0
	bne.s rsec2
	cmp.w (a2),d0
	beq.s rsec2
	movem.l (a2),d0-d1
	bsr.s getlong
	lsr.w #8,d0
			;cmp.b #10,d0,bhi.s >11 sec
	cmp.b sec(pc),d0
	beq.s rsec4
	lea $43c(a2),a2	;skip blk
	bra.s rsec5
rsec4:	lea $30(a2),a2	;skip header
	movem.l (a2)+,d0-d1	;datachk
	bsr.s getlong
	move.l d0,-(a7)
	move.l d6,a1
	moveq #128-1,d3
	clr.l d4
rsec3:	move.l 512(a2),d1
	move.l (a2)+,d0
	eor.l d0,d4
	eor.l d1,d4
	bsr.s getlong
	move.l d0,(a1)+	
	dbf d3,rsec3
	and.l mask55(pc),d4
	cmp.l (a7)+,d4		;chk
	beq.s rsec0
	move.b #25,dskerr-base(a6)	;chksum wrong
	bra.s rsec6
rsec5:	dbf d2,rsec2
rsec8:	move.b #21,dskerr-base(a6)	;no sync found
rsec6:	sf truebuf-base(a6)
	dbf d5,rsec7

rsec0:	movem.l (a7)+,d0-d6/a1-a3
	rts

getlong:and.l mask55(pc),d0	;convert some gore
	and.l mask55(pc),d1
	add.l d0,d0
	or.l d1,d0
	rts

codemfm:movem.l d0-d7/a0-a4,-(a7)	;haha, this builds mfmbuffer
	move.l dskadr(pc),a1
	move.w #[readlen*2-[$440*11+4]]/4-1,d0
mfmlp2:	move.l maskaa(pc),(a1)+
	dbf d0,mfmlp2
	clr.b d1		;startsecnum
	moveq #11-1,d3
	moveq #11,d2		;sec till gap
mfmlp1:	move.l maskaa(pc),(a1)+
	move.w sync(pc),(a1)+
	move.w sync(pc),(a1)+
	st d7			;format byte
	asl.l #8,d7
	move.b trk(pc),d7	;track 0-159
	asl.l #8,d7
	move.b d1,d7		;secnum	
	asl.l #8,d7
	move.b d2,d7		;sec till gap
	move.l a1,a2
	bsr.s makelong
	move.l d6,(a1)+
	move.l d7,(a1)+
	moveq #1,d5
	bsr.s setclock		;we DO need clockbits...
	eor.l d6,d7
	move.l a1,a2
	clr.l (a1)+
	clr.l (a1)+
	clr.l (a1)+
	clr.l (a1)+
	clr.l (a1)+
	clr.l (a1)+
	clr.l (a1)+
	clr.l (a1)+
	bsr.s makelong
	move.l d6,(a1)+		;headerchk
	move.l d7,(a1)+
	moveq #5,d5
	bsr.s setclock
	move.l a1,a3
	addq.l #8,a1		;skip datachk
	move.l a1,a4
	moveq #512/4-1,d5
	clr.l d4
mfmlp0:	move.l (a0)+,d7		;get data
	bsr.s makelong
	move.l d7,512(a1)
	move.l d6,(a1)+
	eor.l d6,d4		;build chksum
	eor.l d7,d4
	dbf d5,mfmlp0
	move.l d4,d7
	bsr.l makelong
	move.l a3,a2
	move.l d6,(a3)+		;write datachk
	move.l d7,(a3)
	moveq #1,d5
	bsr.s setclock
	move.l a4,a2
	move.w #512/4,d5
	bsr.s setclock
	addq.b #1,d1
	subq.b #1,d2
	lea $200(a1),a1
	dbf d3,mfmlp1
	move.l maskaa(pc),(a1)	;famous last words
	movem.l (a7)+,d0-d7/a0-a4
	rts
makelong:move.l d7,d6
	lsr.l #1,d6
	and.l mask55(pc),d6
	and.l mask55(pc),d7
	rts
setclock:movem.l d0-d5/a2,-(a7)	;well this is quite nasty down here
	add.w d5,d5
	subq.w #1,d5
	move.b -1(a2),d0
setclk0:move.l (a2),d4
	move.l d4,d1
	move.l d4,d2
	not.l d1
	and.l mask55(pc),d1
	asl.l #1,d1
	move.l d1,d3
	roxr.b #1,d0
	roxr.l #1,d4		;you know what I do?
	eor.l d4,d1
	and.l d3,d1
	or.l d1,d2
	move.l d2,(a2)+
	move.b d2,d0
	dbf d5,setclk0
	movem.l (a7)+,d0-d5/a2
	rts

writemfm:move.b #29,dskerr-base(a6)
	lea $dff09e,a2
	bsr.l dskrdy
	tst.l d0
	beq.L rmfm0
	move.w #$4000,d0
	move.w #$7fff,(a2)		;$dff09e
	move.w #$9100,(a2)		;$dff09e syncwait off
	bra.s wmfm

readmfm:move.b #29,dskerr-base(a6)
	lea $dff09e,a2
	bsr.L dskrdy			;timeout
	tst.l d0
	beq.s rmfm0
	clr.w d0
	move.w #$7fff,(a2)		;$dff09e
	move.w #$9500,(a2)		;$dff09e syncwait on
wmfm:	move.w #$4000,$24-$9e(a2)	;$dff024
	move.w #$8010,$96-$9e(a2)	;$dff096 disk dma on
	move.l dskadr(pc),$20-$9e(a2)	;$dff020
	move.w sync(pc),$7e-$9e(a2)	;$dff07e
	move.w #$0002,$9c-$9e(a2)	;$dff09c
	or.w #$8000!readlen,d0
	move.w d0,$24-$9e(a2)		;$dff024		
	move.w d0,$24-$9e(a2)		;$dff024		

	move.b #26,dskerr-base(a6)
	move.l #$10000,d0		;timeout
rmfm2:	subq.l #1,d0
	beq.s rmfm1
	btst #1,$1f-$9e(a2)		;$dff01f
	beq.s rmfm2
rmfm1:	move.w #$4000,$24-$9e(a2)	;$dff024
	tst.l d0
	beq.s rmfm0
	sf dskerr-base(a6)
	st truebuf-base(a6)
rmfm0:	rts
initdosdrive:			;do some init stuff
	bsr.L moton
	bsr.l stepup
	bsr.l trk0
	sf dskerr-base(a6)
	clr.w secinbuf-base(a6)
	sf truebuf-base(a6)
	bsr.l testindrive
	beq.s inidd0
	bsr.L testdosdsk	;reads root
	beq.s inidd0
	move.l #rootblk,d6
	move.l dirkey(pc),d5
	bsr.L getsec
	bsr.L tsterr
inidd0:	rts			;beq.s error

cd:	lea 3(a5),a0
	bsr.L getfilename
	beq.s cdqq
	cmp.w #30,d4
	bhi.s cdqq

	cmp.b #":",(a2)		;back to the roots..
	bne.s cd3
	move.l #880,dirkey-base(a6)
	addq.l #1,a2
	subq.w #1,d4
	beq.s cdq

cd3:	sf wrflag-base(a6)
	sf wrcmd-base(a6)
	bsr.s initdosdrive
	beq.s cdq

	move.l a2,a0
	bsr.L fnhash		;a0:str,d4.w:len>d4.w:rootidx,d5:blk
	beq.s cd1

	bsr.L searchfile	;d5:1st hash,a2:fname
				;>prevchain,a4:header
	beq.s cd1
	moveq #-3,d0
	cmp.l $1fc(a4),d0
	bne.s cd2
	bsr.l disfile
	bra.s cdq
cd2:	move.l 4(a4),dirkey-base(a6)

cdq:	bsr.L motoff
	st d7
cdqq:	rts
cd1:	bsr.L dnotfnd
	bra.s cdq

delete:	lea 4(a5),a0
	bsr.L getfilename
	move.w d4,para+12-base(a6)
	beq.L deleteq
	cmp.w #30,d4
	bhi.L deleteq

	st wrflag-base(a6)
	st wrcmd-base(a6)
	bsr.L initdosdrive
	beq.L delete0

	move.l a2,a0
	bsr.L fnhash		;a0:str,d4.w:len>d4.w:rootidx,d5:blk
	beq.s delete1

	bsr.L searchfile	;d5:1st hash,a2:fname
				;>prevchain,a4:header
	bne.s delete2

delete1:bsr.L fnotfnd
	bra.L delete0

delete2:move.l 4(a4),d0
	bsr.L freeblk
	beq.L delbm

	moveq #2,d0
	cmp.l $1fc(a4),d0
	beq.s delete5

	move.l a4,a5
delete9:lea $134+4(a5),a3
	move.l 8(a5),d3

delete7:subq.l #1,d3
	bmi.s delete6
	move.l -(a3),d0
	bsr.L freeblk
	beq.L delbm
	bra.s delete7

delete6:move.l $1f8(a5),d5
	beq.s delete8		;eof
	lea rootblk(pc),a5
	move.l a5,d6
	bsr.L getsec
	bsr.L tsterr
	beq.s delete0
	move.l d5,d0
	bsr.L freeblk
	bne.s delete9
	bra.s delete0

delete5:lea $18(a4),a0		;dir
	moveq #72-1,d0
delete4:tst.l (a0)+
	bne.s delnmt
	dbf d0,delete4

delete8:lea rootblk(pc),a0
	move.l a0,d6
	move.l prevchain(pc),d5		;prevchain
	bsr.L getsec
	bsr.L tsterr
	beq.s delete0

	move.l roothash(pc),a0
	move.l $1f0(a4),(a0)		;hashchain

	move.l d6,a0
	bsr.L datasum
	move.l d3,20(a0)
	bsr.L putsec
	bsr.L tsterr
	beq.s delete0

	bsr.L bitsum
	lea bitmap(pc),a0
	move.l a0,d6
	move.l bitsec(pc),d5
	bsr.L putsec
	bsr.L tsterr
	beq.s delete0

	bsr.l updatedisk

delete0:bsr.L motoff
	st d7
deleteq:rts
delnmt:	bsr.L dnotmt
	bra.s delete0
delbm:	bsr.l bmaperr
	bra.s delete0

makedir:lea 3(a5),a0
	bsr.L getfilename
	move.w d4,para+12-base(a6)
	beq.L mdq
	cmp.w #30,d4
	bhi.L mdq

	st wrflag-base(a6)
	st wrcmd-base(a6)
	bsr.L initdosdrive
	beq.L md0

	move.l a2,a0
	bsr.L fnhash		;a0:str,d4.w:len>d4.w:rootidx,d5:blk
	beq.s md1

	bsr.L searchfile	;d5:1st hash,a2:fname,
				;>prevchain,a4:header
	beq.s md1
	bsr.L dexists
	bra.L md0
md1:	bsr.L getfreehead
	beq.L mdfull
	move.l roothash(pc),a0
	move.l (a0),d1
	move.l d0,(a0)		;link dir

	lea header(pc),a4
	move.l a4,a0
	moveq #512/4-1,d6
md2:	clr.l (a0)+
	dbf d6,md2
	moveq #2,d6
	move.l d6,(a4)		;type
	move.l (a4),$1fc(a4)	;type
	move.l d0,4(a4)		;ownkey
	move.l d1,$1f0(a4)
	move.l dirkey(pc),$1f4(a4)
	lea $1b1(a4),a0
	move.w para+12(pc),d0
	subq.w #1,d0
md3:	move.b (a2)+,(a0)+
	addq.b #1,$1b0(a4)
	dbf d0,md3
	move.l a4,a0
	bsr.L datasum
	move.l d3,20(a0)
	move.l 4(a4),d5
	move.l a4,d6
	bsr.L putsec
	bsr.L tsterr
	beq.s md0
	lea rootblk(pc),a0	;here, too
	move.l a0,d6
	bsr.L datasum
	move.l d3,20(a0)
	move.l dirkey(pc),d5
	bsr.L putsec
	bsr.L tsterr
	beq.s md0

	bsr.L bitsum
	lea bitmap(pc),a0
	move.l a0,d6
	move.l bitsec(pc),d5
	bsr.L putsec
	bsr.L tsterr
	beq.s md0

	bsr.l updatedisk
md0:	bsr.L motoff
	st d7
mdq:	rts
mdfull:	bsr.L dskfull
	bra.s md0

map:	sf wrflag-base(a6)
	sf wrcmd-base(a6)
	bsr.l initdosdrive
	beq.L mapq

	lea linebuf+1(pc),a0
	lea maptxt(pc),a1
	bsr.L txttobuf
	move.l bitsec(pc),d0
	bsr.L wordtoa_
	move.b #"=",(a0)+
	bsr.l wordtod

	move.l #" is ",(a0)+	
	lea dskvtxt(pc),a1
	tst.l rootblk+$138-base(a6)
	beq.s isnval
	addq.l #4,a1
isnval:	bsr.l txttobuf
	bsr.L rawline

	moveq #"0"-1,d2
	moveq #8-1,d1
map2:	addq.b #1,d2
	moveq #10-1,d0
map1:	move.b d2,(a0)+
	dbf d0,map1	
	dbf d1,map2
	bsr.l rawline
	moveq #"0",d2
	moveq #80-1,d1
map4:	move.b d2,(a0)+
	addq.b #1,d2
	cmp.b #"9"+1,d2
	bne.s map3
	moveq #"0",d2
map3:	dbf d1,map4
	bsr.l rawline

	moveq #22-1,d4
map7:	moveq #80-1,d3
	moveq #22-2-1,d0
	sub.l d4,d0
	bpl.s map5
	move.b #"#",(a0)+
	bra.s map6
map5:	move.b #".",(a0)+	;free
	bsr.s tstfree
	bne.s map6
	move.b #"#",-1(a0)	;used
map6:	moveq #22,d5
	add.l d5,d0
	dbf d3,map5
	bsr.l rawline
	cmp.b #11,d4
	bne.s map8
	bsr.l rawline
map8:	dbf d4,map7

mapq:	bsr.L motoff
	st d7
	rts
tstfree:move.l a0,-(a7)
	lea bitmap(pc),a0
	move.l d0,d1
	lsr.w #5,d1
	lsl.w #2,d1
	move.l 4(a0,d1.w),d2
	btst d0,d2
	move.l (a7)+,a0
	rts

catalog:sf lastcmd-base(a6)
	sf wrflag-base(a6)
	sf wrcmd-base(a6)
	bsr.L initdosdrive
	beq.L catq

	lea rootblk(pc),a3
	lea linebuf+2(pc),a0
	lea voltxt(pc),a1
	bsr.l txttobuf
	lea $1b0(a3),a1
	bsr.l bcpltobuf
	move.b #34,(a0)+
	bsr.l rawline

	lea header(pc),a4
	lea 24(a3),a2
	moveq #72-1,d2
cat0:	move.l (a2)+,d5
	beq.L cat1
cat2:	move.l a4,d6
	bsr.L getsec
	bsr.L tsterr
	beq.L catq

	move.l #">  "*256+34,(a0)+
	lea $1b0(a4),a1
	bsr.l bcpltobuf		;file/dirname
	move.b #34,(a0)+

	lea linebuf+36(pc),a0

	move.l $1fc(a4),d3
	moveq #-3,d0
	cmp.l d0,d3		;file
	bne.s cat4
	move.l $144(a4),d0
	bsr.l hextod
cat4:	moveq #2,d0
	cmp.l d0,d3		;dir
	bne.s cat3
	lea dirtxt(pc),a1
	bsr.l txttobuf
cat3:
	lea linebuf+44(pc),a0
	move.l $1a4(a4),d0
	bsr.L todate
	addq.l #2,a0
	move.l $1a8(a4),d0
	divu #60,d0
	bsr.L bytetod
	swap d0
	move.b #":",(a0)+
	bsr.L bytetod
	move.l $1ac(a4),d0
	divu #50,d0
	move.b #":",(a0)+
	bsr.l bytetod
	bsr.l rawline

	bsr.L stopit
	beq.s cat5

	move.l $1f0(a4),d5
	bne.L cat2
cat1:	dbf d2,cat0

cat5:	lea bitmap+4(pc),a1		;how many free blk?
	addq.l #1,a0
	clr.l d0
	moveq #1760/32-1,d2
cat8:	move.l (a1)+,d3
	moveq #32-1,d1
cat6:	add.l d3,d3
	bcs.s cat7
	addq.l #1,d0
cat7:	dbf d1,cat6
	dbf d2,cat8
	move.l #1760,d4
	sub.l d0,d4
	addq.l #1,a0
	bsr.L hextod
	lea usdtxt(pc),a1
	bsr.L txttobuf
	move.l d4,d0
	bsr.l hextod
	lea fretxt(pc),a1
	bsr.L txttobuf
	bsr.l rawline

catq:	bsr.L motoff
	st d7
	rts

todate:	movem.l d0-d3,-(a7)	;funky code, not easy...
	lea 28431.w,a1		;d0:days since 1.1.78
	add.l a1,d0
	lsl.l #2,d0
	move.l d0,d2
	subq.l #1,d2
	divu #1461,d2
	and.l #$0000ffff,d2
	addq.l #3,d0
	move.l d2,d3
	mulu #1461,d3
	sub.l d3,d0
	lsr.l #2,d0
	move.l d0,d3
	lsl.l #2,d0
	add.l d3,d0		;5*days
	move.l d0,d1
	subq.l #3,d1
	divu #153,d1
	and.l #$0000ffff,d1
	addq.l #2,d0
	move.l d1,d3
	mulu #153,d3
	sub.l d3,d0
	divu #5,d0
	and.l #$0000ffff,d0
	moveq #10,d3
	cmp.l d3,d1
	bge.s date1
	addq.l #3,d1		;month+3
	bra.s date2
date1:	subq.l #8,d1
	subq.l #1,d1		;month-9
	addq.l #1,d2		;year+1
date2:	bsr.l bytetod
	lea months(pc),a1
	move.w d1,d0
	add.w d0,d0
	add.w d1,d0
	lea -3(a1,d0.w),a1
	move.b #"-",(a0)+
	move.b (a1)+,(a0)+	;the month
	move.b (a1)+,(a0)+
	move.b (a1)+,(a0)+
	move.b #"-",(a0)+
	move.l d2,d0
	bsr.l bytetod
	movem.l (a7)+,d0-d3
	rts

drive:	cmp.b #1,d3
	bhi.L drvq
	tst.b d3
	beq.s drv0
	move.l para(pc),d0
drv1:	moveq #3,d1
	cmp.l d1,d0
	bhi.L drvq
	addq.b #3,d0
	move.b d0,drvbit-base(a6)
drv0:	lea linebuf(pc),a0
	bsr.L drvnumx

	lea $bfd100,a1
	st (a1)
	move.b drvbit(pc),d1
	moveq #7,d3
	bclr d3,(a1)
	bclr d1,(a1)
	bset d1,(a1)
	bset d3,(a1)
	bclr d1,(a1)
	bset d1,(a1)
	moveq #-1,d4
	cmp.b #3,d1
	beq.s con1

	moveq #31,d3
con0:	bclr d1,(a1)
	move.b $0f01(a1),d2	;$bfe001
	lsl.b #3,d2
	roxl.l #1,d4		;get the drive msg
	bset d1,(a1)
	dbf d3,con0
	not.l d4
con1:	lea logtxt(pc),a1
	tst.l d4
	bne.s con2
	lea mnttxt(pc),a1
con2:	bsr.L txttobuf
	bsr.l rawline
	tst.l d4
	bne.s drv2		;drive is present
	move.b #3,drvbit-base(a6)
	bra.s drv0

drv2:	bsr.s moton
	bsr.s trk0
	bsr.s motoff
	clr.w secinbuf-base(a6)
	move.l #880,dirkey-base(a6)
	sf truebuf-base(a6)
	st d7
drvq:	rts

moton:	lea $bfd100,a1
	bclr #7,(a1)
sel:	move.b drvbit(pc),d0
	bclr d0,(a1)
	rts

motoff:	lea $bfd100,a1
	st (a1)
	bsr.s sel
	bset d0,(a1)
	rts

dskrdy:	move.l #$18000,d0	;timeout
mot1:	subq.l #1,d0
	beq.s mot2
	btst #5,$bfe001
	bne.s mot1
mot2:	rts

trk0:	lea $bfd100,a1
	bclr #7,(a1)
trk2:	btst #4,$0f01(a1)	;$bfe001
	beq.s trk1
	bsr.s stepdwn
	bra.s trk2
trk1:	sf trk-base(a6)
	rts
	
stepup:	bclr #1,(a1)
	addq.b #2,trk-base(a6)
	bra.s dostep
stepdwn:bset #1,(a1)		;down
	subq.b #2,trk-base(a6)
dostep:	sf truebuf-base(a6)
	bclr #0,(a1)
	bset #0,(a1)

mytime:	move.b #$7f,$c00(a1)		;$bfdd00 clr int
	bset #3,$d00(a1)		;$bfde00 oneshot
	move.b #stepdel&255,$300(a1)	;$bfd400 timerlo
	move.b #stepdel/256,$400(a1)	;$bfd500 timerhi
stp0:	btst #0,$c00(a1)		;$bfdd00 wait timerint
	beq.s stp0
	rts

dotrk:	lea $bfd100,a1	
	bset #2,(a1)
	moveq #0,d0
	bclr d0,trk-base(a6)
	btst d0,d1
	beq.s dtrk0
	bclr #2,(a1)
	bset d0,trk-base(a6)
dtrk0:	lsr.b #1,d1
dtrk2:	cmp.b #82,d1
	bls.s dtrk1
	move.b #82,d1
dtrk1:	move.b trk(pc),d0
	lsr.b #1,d0
	cmp.b d0,d1
	beq.s dtrk3
	bhi.s dtrk5
	bsr.L stepdwn
	bra.s dtrk2
dtrk5:	bsr.L stepup
	bra.s dtrk2

dtrk3:	btst #2,$0f01(a1)	;$bfe001,disk removed ?
	bne.s dtrk4
	move.b #29,dskerr-base(a6)
dtrk4:	rts


drvnumx:moveq #8,d1
	bra.s drvnum0
drvnum:	clr.l d1
drvnum0:move.l a1,-(a7)
	lea drvtxt(pc),a1
	move.b drvbit(pc),d0
	add.b #"0"-3,d0
	move.b d0,17(a1)
	add.l d1,a1
	bsr.L txttobuf
	move.l (a7)+,a1
	rts

i:	tst.b d3
	bne.L iq

	lea linebuf+1(pc),a0	;info about agnus regs/cpu vectors
	lea $dff096,a1
	move.l a1,d0
	bsr.l adrtoa_
	moveq #":",d4
	move.b d4,(a0)+
	move.w rdff002(pc),d0
	bsr.l wordtoa_

	addq.l #2,a0
	addq.l #4,a1		;$dff09a
	move.l a1,d0
	bsr.l adrtoa_
	move.b d4,(a0)+
	move.w rdff01c(pc),d0
	bsr.l wordtoa_

	addq.l #2,a0
	addq.l #2,a1		;$dff09c
	move.l a1,d0
	bsr.l adrtoa_
	move.b d4,(a0)+
	move.w rdff01e(pc),d0
	bsr.l wordtoa_

	addq.l #2,a0
	addq.l #2,a1		;$dff09e
	move.l a1,d0
	bsr.l adrtoa_
	move.b d4,(a0)+
	move.w rdff010(pc),d0
	bsr.l wordtoa_
	bsr.l rawline
	bsr.L csdown

	addq.l #1,a0
	clr.l d0
	moveq #$40,d1
	bsr.l twoadr_
	bsr.l rawline

	lea zeromem(pc),a1		;$0-$20,$20-$40
	bsr.s iblkout
	bsr.L csdown

	lea inttxt(pc),a1
	bsr.L txttobuf
	bsr.l rawline

	lea intraps(pc),a1			;level1-7
	moveq #7-1,d2
i0:	addq.l #1,a0
	move.l (a1)+,d0
	bsr.l longtoa_
	dbf d2,i0	
	bsr.l rawline
	bsr.L csdown

	lea trptxt(pc),a1
	bsr.L txttobuf
	bsr.l rawline

	lea intraps+$1c(pc),a1		;trap #0-7,#8-15
	bsr.s iblkout
	st d7
iq:	rts
iblkout:moveq #16-1,d2
i3:	addq.l #1,a0
	move.l (a1)+,d0
	bsr.l longtoa_
	cmp.w #8,d2
	bne.s i5
	bsr.s i1			;rawline
i5:	dbf d2,i3	
i1:	bra.l rawline


p:	cmp.b #2,d3
	bcs.L pq
	cmp.b #3,d3
	bhi.L pq
	beq.s p2
	move.w #256,para+10-base(a6)
p2:	moveq #0,d0
	btst d0,para+3-base(a6)
	bne.s pq
	btst d0,para+7-base(a6)
	bne.s pq

	move.l para(pc),d0
	cmp.l para+4(pc),d0
	bcc.s pq

	cmp.l himem(pc),d0	;sound in chipmem!
	bcc.s pq
	move.l para+4(pc),d1
	cmp.l himem(pc),d1
	bhi.s pq

	move.l #$80808080,$dff09a

p0:	bsr.s sndpos
p3:	cmp.b #$1b,ascii-base(a6)
	beq.s p1
	tst.l para+4-base(a6)
	bne.s p0
	btst #7,$dff01f
	beq.s p0
p1:	move.l #$00800080,$dff09a
	move.w #$0003,$dff096
	bsr.s sndpos
	bsr.L csdown
	st d7
pq:	rts
sndpos:	lea linebuf+1(pc),a0
	lea sndtxt(pc),a1
	bsr.L txttobuf
	move.l para(pc),d0
	bsr.L adrtoa_
	bsr.L rawline
	bra.L csup
	
g:	cmp.b #1,d3
	bne.L gq

	move.l para(pc),d0
	btst #0,d0
	bne.s gq

	move.l regs+64(pc),a7	;ssp
	pea g1(pc)		;sv cont
	move.l regs+64+4(pc),a0	;usp
	lea g1(pc),a1
	move.l a1,-(a0)		;user cont	
	move.l a0,usp
	move.l para(pc),jmpin+2-base(a6)
	movem.l regs(pc),d0-d7/a0-a6	
	move.w regs+64+12(pc),sr
jmpin:	jmp 0
g1:	movem.l d0-d7/a0-a7,regs;all flags ok
	lea base(pc),a6
	lea $80.w,a3
	move.l (a3),a1
	lea savereg(pc),a2
	movem.l a2-a2,(a3)
	trap #0			;stays in sv
wrongpc:move.l a1,(a3)

	lea regs+64(pc),a0
	move.l a7,(a0)		;ssp
	move.l usp,a1
	move.l a1,4(a0)		;usp
	btst #13,d0		;sr
	beq.s g2
	addq.l #4,a0
g2:	addq.l #4,(a0)
	lea wrongpc(pc),a1
	cmp.l regs+64+8-base(a6),a1
	bne.s g3
	clr.l regs+64+8-base(a6)
g3:	bra.l warm
gq:	rts

hunk:	cmp.b #1,d3
	bls.L hnq
	cmp.b #2,d3
	bne.s hn3
	move.l para(pc),para+8-base(a6)
hn3:	cmp.b #4,d3
	bhi.L nq
	beq.s hn0
	move.l para+8(pc),para+12-base(a6)
hn0:
	move.l para+8(pc),hunkmem+2-base(a6)
	move.l para+12(pc),hunkjmp+2-base(a6)

	move.l para(pc),a1	;start
	lea $c0.w,a2
	cmp.l a2,a1
	bcs.s hnq
	move.l para+4(pc),a2	;end

	move.l a2,d0
	sub.l a1,d0
	bmi.s hnq
	move.l d0,hunksize+2-base(a6)
	addq.l #3,d0
	lsr.l #2,d0
	lea hunkend-hunkmov/4.w,a3
	add.l a3,d0
	move.l d0,hunklong1-base(a6)
	move.l d0,hunklong2-base(a6)
	lsl.l #2,d0
	move.l a1,a3
	add.l d0,a3
	lea hunkmov-hunkdata(a3),a3
	lea $3f2.w,a0
	move.l a0,(a3)+
	move.l a0,(a3)+

	move.l hunksize+2(pc),d0	;prgbytes
	move.l a2,a0
hn1:	subq.l #1,d0
	bmi.s hn2
	move.b -(a0),hunkend-hunkdata(a0)	
	bra.s hn1
hn2:	lea hunkdata(pc),a0
	moveq #hunkend-hunkdata-1,d0
hn4:	move.b (a0)+,(a1)+
	dbf d0,hn4

	lea linebuf+1(pc),a0
	lea objtxt(pc),a1
	bsr.L txttobuf
	move.l para(pc),d0
	move.l a3,d1
	bsr.L twoadr_
	bsr.L rawline
	st d7
hnq:	rts
hunkdata:dc.l $3f3,0,1,0,0	;datalen=:4!
hunklong1:dc.l 0,$3e9
hunklong2:dc.l 0
hunkmov:move.l #$7fff7fff,$dff09a	;you may edit this
	move.w #$0000,$dff096		;after hunking data
hunksize:move.l #0,d7		;sizeinbytes
	lea hunkend(pc),a4
hunkmem:lea $000000,a5		;prgdest
	lea $80000,a7
hunkjmp:pea $000000
	movem.w mover(pc),d0-d4
	cmp.l a5,a4
	bhi.s mvdown
	eor.w #$01f8,d2		;move.b -(a4),-(a5)
	add.l d7,a4
	add.l d7,a5
mvdown:	lea $c0.w,a1
	movem.w d0-d4,(a1)
	jmp (a1)
	dc.b "BEER1990"		;don't change size, better nothing
mover:	subq.l #1,d7		;this is located somewhere at $c0...
	bmi.s endmov
	move.b (a4)+,(a5)+
	bra.s mover
endmov:	rts		;prgstart
hunkend:

calc:	lea linebuf+1(pc),a0
	lea 2(a5),a3
	bsr.s getval
	move.l d0,d5

calc1:	bsr.s skipit
	beq.s calcout
	move.b (a3)+,d4

	lea calctab(pc),a4
	lea calccpu(pc),a1
calc0:	move.b (a4)+,d0
	beq.s calcerr
	move.w (a1)+,calcins-base(a6)
	cmp.b d4,d0
	bne.s calc0

	moveq #"/",d3
	bsr.s getval
	move.l d0,d6
	tst.w d6		;divs:16 bit
	bne.s calcins
	cmp.b d3,d4		;divs?
	beq.s calcovl	
calcins:dc.w 0
	bvc.s calc5		;no ovl
	cmp.b d3,d4		;ovl from divs?
	beq.s calcovl
calc5:	cmp.b d3,d4		;divs?
	bne.s calc1
	ext.l d5
	bra.s calc1

skipit:	cmp.b #" ",(a3)
	bne.s calc2
	addq.l #1,a3
	lea 80(a5),a1
	cmp.l a1,a3
	bcs.s skipit		;beq.s endtxt
calc2:	rts
getval:	bsr.s skipit
	cmp.b #"#",(a3)
	bne.s calc3
	addq.l #1,a3
	bra.l atodlong
calc3:	bra.l atolong

calcout:move.l d5,d0
	bsr longtoa_
	move.l #" = #",(a0)+
	move.l d5,d0
	bpl.s calc6
	move.b #"-",(a0)+
	neg.l d0
calc6:	bsr hextod
	addq.l #1,a0
	move.b #"=",(a0)+
	addq.l #1,a0
	move.b #"%",(a0)+
	move.l d5,d0
	bsr hextob
calc4:	bsr rawline
	st d7
calcerr:rts
calcovl:lea calctxt(pc),a1
	bsr.l txttobuf
	bra.s calc4
		
calctab:dc.b "+-*/!&=<>",0	;what we can do
even
calccpu:add.l d6,d5		;what it means..
	sub.l d6,d5
	muls d6,d5
	divs d6,d5
	or.l d6,d5
	and.l d6,d5
	eor.l d6,d5
	lsl.l d6,d5
	lsr.l d6,d5

r:	lea regs(pc),a2
	cmp.b #2,d3
	bhi.l rq
	tst.b d3
	beq.l r0

	cmp.b #1,d3
	bne.s r6

	clr.l d2
	moveq #3-1,d0
r7:	move.b (a0)+,d1
	cmp.b #" ",d1
	beq.s r8
	bclr #5,d1
	lsl.l #8,d2
	or.b d1,d2
	dbf d0,r7
r8:	lea 64(a2),a1		;sspadr
	move.l para(pc),d0
	cmp.l #"SSP",d2
	beq.s r9
	addq.l #4,a1
	cmp.l #"USP",d2
	beq.s r9
	addq.l #4,a1
	cmp.l #"PC",d2
	bne.s r10
r9:	bclr #0,d0
	move.l d0,(a1)
r10:	cmp.w #"SR",d2
	bne.s r0
	move.w d0,64+12(a2)
	bra.s r0

r6:	move.w para+6(pc),d1		;d0-a7
	and.w #%1111111111111000,d1
	cmp.w #$a0,d1
	beq.s r5
	cmp.w #$d0,d1
	bne.l rq
r5:	move.w para+6(pc),d1
	sub.w #$d0,d1
	bcc.s r4
	add.w #$38,d1	
r4:	lsl.w #2,d1
	move.l para(pc),(a2,d1.w)	;write value
	cmp.w #60,d1			;a7?
	bne.s r0
	lea 64(a2),a1			;sspadr
	btst #13,64+12(a2)		;sr
	bne.s r23
	addq.l #4,a1
r23:	move.l para(pc),(a1)		;store ssp/usp
r0:	tst.b excnum
	beq.s r21
	move.w exceptsr(pc),64+12(a2)	;sr
	move.l exceptpc(pc),64+8(a2)	;pc
	move.l exceptpc(pc),para-base(a6)

r21:	move.l 64(a2),d0	;ssp
	btst #13,64+12(a2)	;a7:ssp?
	bne.s r22
	move.l 64+4(a2),d0	;usp
r22:	move.l d0,64-4(a2)	;a7
	move.l #" D0:",d4
	moveq #4-1,d6
r2:	lea linebuf(pc),a0
	moveq #4-1,d5
r1:	move.l d4,(a0)+
	move.l (a2)+,d0
	bsr longtoa
	addq.l #2,a0
	add.w #$100,d4
	dbf d5,r1
	cmp.b #2,d6
	bne.s r3
	sub.l #$00030800,d4
r3:	bsr rawline
	dbf d6,r2

	move.l #"SSP:",(a0)+
	move.l (a2)+,d0
	bsr longtoa
	addq.l #2,a0
	move.l #"USP:",(a0)+
	move.l (a2)+,d0
	bsr longtoa
	addq.l #2,a0
	move.l #" PC:",(a0)+
	move.l (a2)+,d0
	bsr longtoa
	addq.l #2,a0
	move.l #" SR:",(a0)+
	move.w (a2)+,d0
	move.w d0,d2
	bsr wordtoa

	move.l #" T=0",d0
	btst #15,d2
	beq.s r19
	addq.b #1,d0
r19:	move.l d0,(a0)+
	move.l #" S=0",d0
	btst #13,d2
	beq.s r20
	addq.b #1,d0
r20:	move.l d0,(a0)+
	lsl.b #3,d2
	lea flgtxt(pc),a1
	moveq #5-1,d0
r13:	addq.l #1,a0
	move.b (a1)+,(a0)+
	move.w #"=0",d1
	add.b d2,d2
	bcc.s r12
	addq.b #1,d1
r12:	move.w d1,(a0)+
	dbf d0,r13
	bsr.L rawline

	move.b excnum(pc),d0
	beq.s r14

	lea exctxt(pc),a0
r15:	move.l (a0)+,a1
	subq.b #1,d0
	bne.s r15
	lea linebuf+1(pc),a0
	bsr.l txttobuf
	cmp.b #2,excnum-base(a6)	;adr err
	bne.s r18
	lea linebuf+29(pc),a0
	move.w excinstr(pc),d0
	bsr.l wordtoa
	lea linebuf+44(pc),a0
	move.l excadr(pc),d0
	bsr.l longtoa
r18:	bsr.l rawline
	sf excnum-base(a6)

r14:	move.l regs+64+8(pc),a5
	bsr.L disasm
	bsr.L rawline

	st d7
rq:	rts
flgtxt:	dc.b "XNZVC"
even

rbit:	move.w #"=0",(a0)+
	beq.s rb0
	bset #0,-1(a0)
rb0:	rts

setkey:	cmp.b #1,d3
	bhi.L setkq
	tst.b d3
	beq.s setk0
	move.l para(pc),d0
	lea $f1.w,a0
	sub.l a0,d0
	bmi.L setkq
	lea $f10-$f1.w,a0
	cmp.l a0,d0
	bne.s setk1
	moveq #9,d0
setk1:	moveq #9,d1
	cmp.l d1,d0
	bhi.s setkq
	move.l a2,d1
	beq.s setkq

	lea fkeybuf(pc),a0
	mulu #fkeylen,d0
	lea (a0,d0.w),a0
	moveq #fkeylen-1,d1
setk2:	cmp.b #34,(a2)
	beq.s setk3
	move.b (a2)+,(a0)+
	dbf d1,setk2
setk3:	tst.w d1
	bmi.s setk0
	sf (a0)
setk0:	lea fkeybuf(pc),a2
	moveq #10-1,d2
setk6:	move.l a2,a1
	moveq #fkeylen-1,d3
	lea linebuf+1(pc),a0
	move.b #"F",(a0)+
	move.b d2,d0
	not.b d0
	subq.b #5,d0
	bsr.L nibtod
	lea linebuf+5(pc),a0
	move.b #34,(a0)+
setk4:	tst.b (a1)
	beq.s setk5
	move.b (a1)+,(a0)+
	dbf d3,setk4
setk5:	move.b #34,(a0)+
	lea fkeylen(a2),a2
	bsr.L rawline
	dbf d2,setk6
	st d7
setkq:	rts
color:	cmp.b #2,d3
	bne.s colorq
	move.w para+2(pc),d0
	move.w para+6(pc),d1
	move.w d0,bgcol+2-base(a6)	;in tab
	move.w d1,fgcol+2-base(a6)
	move.l copadr(pc),a0
	move.w d0,bgcol-coplst+2(a0)
	move.w d1,fgcol-coplst+2(a0)	
	st d7
colorq:	rts

print:	lea linebuf+1(pc),a0
	lea prttxt(pc),a1
	bsr.L txttobuf
	not.b prtflag-base(a6)	;toggle printer
	bne.s prt0
	move.w #"ff",-1(a0)	;off
prt0:	bsr.L rawline
	st d7
	rts

setmap:	lea keytab+$0a(pc),a0		;swaps german and usa keymap
	eor.l #"0ß'\"~"0-=\",(a0)
	eor.w #"tz"~"ty",$14-$0a(a0)
	eor.w #"ü+"~"[]",$1a-$0a(a0)
	eor.l #"löä#"~["l;'"*256],$28-$0a(a0)
	eor.w #"<y"~"z",$30-$0a(a0)	
	eor.w #"- "~"/ ",$3a-$0a(a0)

	eor.w #34*256+"§"~"@#",$62-$0a(a0)
	eor.l #"&/()"~"^&*(",$66-$0a(a0)
	eor.l #"=?`|"~")_+|",$6a-$0a(a0)
	eor.w #"TZ"~"TY",$74-$0a(a0)
	eor.w #"Ü*"~"{}",$7a-$0a(a0)
	eor.l #"LÖÄ^"~["L:"*256+34*256],$88-$0a(a0)
	eor.w #">Y"~"Z",$90-$0a(a0)
	eor.l #";:_ "~"<>? ",$98-$0a(a0)
	st d7
	rts

spc:	clr.l d3
	bsr.l csup
	cmp.b #"a",lastcmd-base(a6)	;these can be repeated
	beq.l a
	cmp.b #"m",lastcmd-base(a6)
	beq.s m
	cmp.b #"d",lastcmd-base(a6)
	beq.L d
	bsr.l csdown
	st d7
	rts

m:	cmp.b #"k",2(a5)
	beq.L makedir
	cmp.b #2,d3
	bgt.l mq

	moveq #16-1,d5
m1:	lea linebuf(pc),a0
	move.b #">",(a0)+
	move.b #":",(a0)+
	move.l para(pc),d0
	bsr adrtoa

	addq.l #1,a0

	moveq #8-1,d6
	move.l para(pc),a1
m0:	move.b #" ",(a0)+
	move.b (a1)+,d0
	lsl.w #8,d0
	move.b (a1)+,d0
	bsr wordtoa
	dbf d6,m0

	addq.l #2,a0
	move.b #"'",(a0)+

	move.l para(pc),a1
	moveq #16-1,d1
m4:	move.b (a1)+,d0
	cmp.b #" ",d0
	blt.s m5
	cmp.b #"z",d0
	ble.s m6
m5:	move.b #".",d0
m6:	move.b d0,(a0)+
	dbf d1,m4
	move.b #"'",(a0)+

	moveq #$10,d0
	add.l d0,para-base(a6)

	bsr rawline

	bsr.L stopit
	beq.s m3

	cmp.b #2,d3
	bne.s m2
	move.l para(pc),a0
	cmp.l para+4(pc),a0
	bcs.l m1
	bra.s m3

m2:	dbf d5,m1
m3:	st d7
mq:	rts

mm:	cmp.b #9,d3
	bne.s mm1
	lea para(pc),a0
	move.l (a0),a1
	cmp.b #52,d6		;asc edit ?
	bge.s mm2

	addq.l #6,a0
	moveq #8-1,d0
mm0:	move.b (a0)+,(a1)+
	move.b (a0)+,(a1)+
	addq.l #2,a0
	dbf d0,mm0
mm1:	clr.w d5
	clr.b d3
	bsr.l csup
	bra.l m1
mm2:	moveq #16-1,d0
	moveq #52,d6		;beg asc edit
mm3:	move.b (a5,d6.w),d1
	cmp.b #".",d1		;skip it
	beq.s mm4
	move.b d1,(a1)
mm4:	addq.w #1,d6
	addq.l #1,a1
	dbf d0,mm3
	bra.s mm1

a:	cmp.b #2,d3
	bgt.l adq

	moveq #16-1,d5
ad1:	lea linebuf(pc),a0
	move.b #">",(a0)+
	move.b #";",(a0)+
	move.l para(pc),d0
	bsr adrtoa

	addq.l #2,a0
	move.b #"'",(a0)+

	move.l para(pc),a1
	moveq #64-1,d1
ad4:	move.b (a1)+,d0
	cmp.b #" ",d0
	blt.s ad5
	cmp.b #"z",d0
	ble.s ad6
ad5:	move.b #".",d0
ad6:	move.b d0,(a0)+
	dbf d1,ad4

	move.b #"'",(a0)+

	moveq #$40,d0
	add.l d0,para-base(a6)
	bsr rawline

	bsr.L stopit
	beq.s ad3

	cmp.b #2,d3
	bne.s ad2
	move.l para(pc),a0
	cmp.l para+4(pc),a0
	bcs.l ad1
	bra.s ad3
ad2:	dbf d5,ad1
ad3:	st d7
adq:	rts

aa:	cmp.b #1,d3
	bne.s aaq
	cmp.b #"'",10(a5)
	bne.s aaq

	move.l para(pc),a1
	moveq #64-1,d0
	moveq #11,d6		;beg asc edit
aa0:	move.b (a5,d6.w),d1
	cmp.b #".",d1		;skip it
	beq.s aa1
	move.b d1,(a1)
aa1:	addq.w #1,d6
	addq.l #1,a1
	dbf d0,aa0

	st d7
aaq:	rts

x:	bra.l exit
xclr:	sub.l a0,a0	;noguru&clrmem
	clr.l (a0)+
	clr.l (a0)+
	lea $40000,a7	;just gore for the rom stuff
	lea $fc00fe,a0
	reset		;hui, all ram is away, BUT we have prefetch
	jmp (a0)

bpl:	clr.l d0
	cmp.b #1,d3
	bhi.L bplq
	bne.s bpl1
	move.l para(pc),d0
bpl1:	move.l d0,msycnt-base(a6)
	sf bplflag-base(a6)
	bra.s bpl13		;def:lores
bpl0:	moveq #10,d0
	lea $dff016,a0
	btst d0,(a0)		;$dff016
	bne.s bpl12
bpl4:	btst d0,(a0)		;$dff016
	beq.s bpl4
bpl13:	move.l copadr(pc),a0
	moveq #2,d0
	bchg d0,cop92-coplst+3(a0)	;$0092003x
	bchg d0,cop94-coplst+3(a0)	;$009400dx
	bchg #7,cop100-coplst+2(a0)	;$0100x200
	not.b bplflag-base(a6)
bpl12:	lea linebuf+1(pc),a0
	lea bpltxt(pc),a1
	bsr.L txttobuf

bpl9:	move.l msycnt(pc),d0
	bclr #0,d0
	move.l d0,a4
	move.l #256*320/8,d1
	tst.b bplflag-base(a6)
	bne.s bpl3
	add.l d1,d1
bpl3:	lea $c80000,a1
	sub.l d1,a1
	add.l d0,d1
	cmp.l a1,d0
	bls.s bpl8
	move.l a1,msycnt-base(a6)
	bra.s bpl9
bpl8:	bsr.l twoadr_

	move.l scradr(pc),a5
	clr.l d0
	lea font-32(pc),a1	;start=spc
	moveq #8-1,d2
bpl11:	moveq #26-1,d1
	lea linebuf(pc),a0
	lea [40-26](a5),a5
	tst.b bplflag-base(a6)
	bne.s bpl10
	lea 40(a5),a5
bpl10:	move.b (a0)+,d0
	move.b (a1,d0.w),(a5)+
	dbf d1,bpl10	
	lea 192(a1),a1
	dbf d2,bpl11

	move.l scradr(pc),a5
	moveq #8-1,d2
bpl7:	moveq #80-26-1,d1
	move.w #[256-8]*80/40-1,d0
	tst.b bplflag-base(a6)
	beq.s bpl6
	moveq #40-26-1,d1
	move.w #[256-8]*40/40-1,d0
bpl6:	move.b (a4)+,(a5)+
	dbf d1,bpl6
	lea 26(a4),a4
	lea 26(a5),a5
	dbf d2,bpl7

bpl2:	movem.l (a4)+,d1-d7/a0-a2
	movem.l d1-d7/a0-a2,(a5)
	lea 40(a5),a5
	dbf d0,bpl2
	cmp.b #$1b,ascii-base(a6)
	bne.L bpl0

	move.l copadr(pc),a0
	moveq #2,d0
	bset d0,cop92-coplst+3(a0)	;$0092003x
	bset d0,cop94-coplst+3(a0)	;$009400dx
	bset #7,cop100-coplst+2(a0)	;$01009200

	bsr.L clrhome
	st d7
bplq:	rts

work:	cmp.b #1,d3	;we change the workspace, restore the old
	bhi.l woq
	tst.b d3
	beq.L wo0
	move.l para(pc),d0
	lea $c0.w,a0
	cmp.l a0,d0
	bcs.l woq
	move.l himem(pc),d1
	sub.l #worksize,d1
	cmp.l d1,d0
	bhi.L woq
	btst #0,d0
	bne.L woq

	move.w #$0180,$dff096		;cop/bpl off
	move.w #$4000,$dff09a		;ughh, celtic frost
	tst.l bufadr-base(a6)
	beq.s calchip

	move.l scradr(pc),a1		;old
	move.l d0,a2			;new
	move.l bufadr(pc),a3		;buf
	lea $dff006,a4
	lea $017a(a4),a5	;$dff180
	move.l #worksize,d2
	cmp.l a1,a2
	beq.s calchip
	bhi.s cpyrev		;it goes up or down?
	subq.w #1,d2		;dbf !
swapup:	move.b (a2)+,d1		;new
	move.b (a3),(a1)+	;buf to old
	move.b d1,(a3)+		;new to buf
	move.b (a4),(a5)
	dbf d2,swapup
	bra.s calchip

cpyrev:	add.l d2,a1		;old
	add.l d2,a2		;new
	add.l d2,a3		;buf
	subq.w #1,d2		;dbf !
swapdwn:move.b -(a2),d1		;new
	move.b -(a3),-(a1)	;buf to old
	move.b d1,(a3)		;new to buf
	move.b (a4),(a5)
	dbf d2,swapdwn

calchip:move.l d0,a0
	move.l a0,scradr-base(a6)
	lea scrsize(a0),a0
	move.l a0,dskadr-base(a6)
	lea dsksize(a0),a0
	move.l a0,spradr-base(a6)
	lea sprsize(a0),a0
	move.l a0,copadr-base(a6)
	sf prtflag-base(a6)	;printer off
	bsr.L rawline
	bsr.L cursoff
	bsr.l clrhome
	sf col-base(a6)
	lea initxt(pc),a1
	bsr.L txttobuf
	bsr.l rawline
	bsr.s wo0

	clr.l d0
	bsr.L drv1	;set df0:

	bsr csdown
	bra.l warm

wo0:
	lea linebuf+1(pc),a0
	lea worktxt(pc),a1
	bsr.L txttobuf
	move.l scradr(pc),d0
	move.l d0,d1
	add.l #worksize,d1
	bsr.L twoadr_

	lea progtxt(pc),a1
	bsr.L txttobuf
	lea run(pc),a1
	move.l a1,d0
	move.l #stackend,d1
	bsr.L twoadr_

	lea buftxt(pc),a1
	bsr.L txttobuf
	move.l bufadr(pc),d0
	bne.s bufmem
	lea svnotxt(pc),a1
	bsr.L txttobuf
	bra.s nobufm
bufmem:	move.l d0,d1
	add.l #worksize,d1
	bsr.L twoadr_
nobufm:	sf col-base(a6)
	bsr.l rawline
	st d7
woq:	rts

d:	cmp.w #"ir",2(a5)
	beq.L catalog
nocat:	cmp.w #"el",2(a5)
	beq.L delete
nodelet:cmp.b #2,d3
	bhi.s dq

	move.b (a0)+,d0
	cmp.b #"s",d0
	bne.s dd9
	bchg #0,dissign-base(a6)
	bra.s dd3
dd9:	cmp.b #"m",d0
	bne.s dd8
	bchg #1,dissign-base(a6)
	bra.s dd3
dd8:
	moveq #16-1,d5
dd0:	move.l para(pc),d0
	btst #0,d0
	bne.s dq

	move.l d0,a5
	bsr.l disasm
	move.l a5,para-base(a6)
	bsr.l rawline

	bsr.L stopit
	beq.s dd3

	cmp.b #2,d3
	bne.s dd2
	move.l para(pc),a0
	cmp.l para+4(pc),a0
	bcs.l dd0
	bra.s dd3

dd2:	dbf d5,dd0
dd3:	st d7
dq:	rts

s67 =$0000
s6  =$0100
s8  =$0200
stab=$0300
snop=$0400

nass:	tst.b d3
	beq.s nassq
	move.l para(pc),d0
	btst #0,d0
	bne.s nassq
	lea linebuf(pc),a0
	move.w #">,",(a0)+
	bsr.L adrtoa
	bra.L newdis
nassq:	rts
n:	tst.b d3
	beq.s nassq
	move.l a5,a0

	move.l a5,lineend-base(a6)
	moveq #80,d0
	add.l d0,lineend-base(a6)
	

	addq.l #2,a0		;skip >,
	bsr.L skipspc
nn0:	cmp.l lineend(pc),a0
	bhi.s nassq
	cmp.b #" ",(a0)+	;search spc
	bne.s nn0
nn1:	cmp.l lineend(pc),a0	
	bhi.L endn
	cmp.b #" ",(a0)		;skip spc
	bne.s nn1_
	addq.l #1,a0
	bra.s nn1
nn1_:	move.l a0,a5		;cmdadr!
nn3:	cmp.l lineend(pc),a0
	bhi.s nn4
	move.b (a0)+,d0
	cmp.b #"Z",d0
	bhi.s nn3
	cmp.b #"A",d0
	bcs.s nn3
	bset #5,d0
	move.b d0,-1(a0)
	bra.s nn3
nn4:	
	lea instr(pc),a4
nn7:	btst #0,para+3-base(a6)
	bne.s nassq
	move.l a5,a0
	lea 6(a4),a1
nn6:	move.b (a1),d0
	bclr #7,d0
	cmp.b (a0)+,d0
	bne.L nn5
	btst #7,(a1)+
	beq.s nn6

	lea op68000-2(pc),a1
	clr.w (a1)+		;oplen!
	clr.w (a1)
	move.w 4(a4),d0		;info
	and.w #$700,d0
	cmp.w #snop,d0
	beq.L nnsnop
	cmp.w #stab,d0
				;bne.s nnstab
	beq.L nn9
nnstab:	cmp.b #".",(a0)+
	bne.L nn5
	cmp.w #s67,d0
	bne.s nns67
	sf imsize-base(a6)	;%00
	cmp.b #"b",(a0)+	;op68000:0
	beq.s nn9
	addq.b #1,imsize-base(a6)	;%01
	move.w #%01000000,(a1)
	cmp.b #"w",-1(a0)
	beq.s nn9
	addq.b #1,imsize-base(a6)	;%10
	move.w #%10000000,(a1)
	cmp.b #"l",-1(a0)
	beq.s nn9	
nns67:	cmp.w #s6,d0
	bne.s nns6
	move.b #%01,imsize-base(a6)
	cmp.b #"w",(a0)+
	beq.s nn9
	addq.b #1,imsize-base(a6)	;%10
	move.w #%1000000,(a1)
	cmp.b #"l",-1(a0)
	beq.s nn9
nns6:	cmp.w #s8,d0
	bne.s nn5		;ill instrtab or cmd
	move.b #%01,imsize-base(a6)
	cmp.b #"w",(a0)+
	beq.s nn9
	addq.b #1,imsize-base(a6)	;%10
	move.w #%100000000,(a1)
	cmp.b #"l",-1(a0)
	bne.s nn5
nn9:	cmp.b #" ",(a0)
	bne.s nn5
nn10:	addq.l #1,a0
	cmp.l lineend(pc),a0
	bhi.s nn5
	cmp.b #" ",(a0)
	beq.s nn10

nnsnop:	st d7
	move.l a0,a3
	move.w 4(a4),d0
	ext.w d0			 ;no a4,a5
	add.w d0,d0
	lea assoffs(pc),a0
	move.w (a0,d0.w),d0
	lea assubs(pc),a0

	jsr (a0,d0.w)	;a4:instrtabentry,a5:cmdtxt,a3:cnttxt
			;a6:notmodify!!
	tst.b d7	
	bne.s nn8
nn5:	sf d7
	tst.l (a4)
	beq.s nretry		;unknown
	lea 12(a4),a4
	bra.L nn7
nn8:	

	lea op68000-2(pc),a0
	move.w (a0)+,d0		;oplen!
	move.l para(pc),a1
	move.l a1,a5
	move.w (a0),d1
	or.w 2(a4),d1
	move.w d1,(a0)
nnmem:	move.w (a0)+,(a1)+
	dbf d0,nnmem
	bsr.L csup
	bsr.L disasm
	bsr.L rawline
	move.l a5,para-base(a6)
	move.l para(pc),a5
	bsr.L disasm
newdis:	bsr.L rawline
nretry:	bsr.L csup
	move.b #9,col-base(a6)
endn:	st d7
nq:	rts

c:	cmp.b #"d",2(a5)
	beq.L cd

	cmp.b #3,d3
	bne.s cq

	move.l para(pc),a1
	move.l para+4(pc),a2
	move.l para+8(pc),a3

	lea linebuf+1(pc),a0
	lea linebuf+74(pc),a4

c0:	move.b (a1)+,d0
	cmp.b (a3)+,d0
	beq.s c1

	move.l a1,d0
	subq.l #1,d0
	bsr.l adrtoa_
	addq.l #2,a0

	cmp.l a4,a0
	bcs.s c1
	
	bsr.l rawline
	addq.l #1,a0

c1:	bsr.L stopit
	beq.s c3

	cmp.l a2,a1
	bcs.s c0

c3:	lea linebuf+1(pc),a1
	cmp.l a1,a0
	beq.s c2
	bsr.l rawline
c2:	st d7
cq:	rts

f:	clr.l d0
	cmp.l d0,a2		;asc ?
	beq.s f7

	cmp.b #2,d3
	bne.l fq

	lea para+8(pc),a1
	clr.l d0

	moveq #2,d3
f9:	move.b (a2)+,d0
	cmp.b #34,d0
	beq.s f7
	move.l d0,(a1)+	
	addq.w #1,d3
	cmp.b #16,d3
	bne.s f9

f7:	cmp.b #3,d3
	blt.l fq

	lea para+8(pc),a1
	lea linebuf(pc),a0
	move.l #" sea",(a0)+
	move.l #"rchi",(a0)+
	move.l #"ng f",(a0)+
	move.l #"or: ",(a0)+
	move.w d3,d2
	subq.w #3,d2
f5:	move.l (a1)+,d0
	bsr.l bytetoa_
	move.b #" ",(a0)+
	dbf d2,f5
	bsr.l rawline
	addq.l #1,a0

	move.l para(pc),a1
	move.l para+4(pc),a2
	move.b para+11(pc),d4

f0:	cmp.b (a1),d4			;quickfind
	bne.s f6

	move.l a1,a4
	
	lea para+11(pc),a3

	move.w d3,d2
	subq.w #3,d2
f4:	move.b (a4)+,d0
	cmp.b (a3),d0
	bne.s f1
	addq.l #4,a3
	dbf d2,f4

	move.l a1,d0
	bsr.l adrtoa_
	addq.l #2,a0

	lea linebuf+74(pc),a4
	cmp.l a4,a0
	bcs.s f1
	
	bsr.l rawline
	addq.l #1,a0

f1:	bsr.L stopit
	beq.s f3

f6:	addq.l #1,a1
	cmp.l a2,a1
	bcs.s f0

f3:	lea linebuf+1(pc),a1
	cmp.l a1,a0
	beq.s f2
	bsr.l rawline
f2:	st d7
fq:	rts

frel:	cmp.b #1,d3
	bne.l frq

	sf d4
	moveq #5,d0
	bclr d0,(a0)	;uppercase
	cmp.b #"P",(a0)+
	bne.s fr3
	bclr d0,(a0)	;uppercase
	cmp.b #"C",(a0)
	bne.s fr3
	st d4

fr3:	move.l para(pc),d0

	bclr #0,d0
	move.l d0,a1

	sub.l a2,a2
	cmp.l #$8000,d0
	bls.s fr9
	lea -$8000(a1),a2	;min
fr9:	lea $7ffe(a1),a4	;max
fr1:	tst.b d4
	bne.s fr4

	move.w (a2),d1
	and.w #%1111000011111000,d1
	cmp.w #%0101000011001000,d1		;dbxx
	beq.s fr5
	move.b (a2),d1
	and.w #%11110000,d1
	cmp.w #%01100000,d1	;bxx.x
	bne.s fr0

	move.b 1(a2),d1
	ext.w d1
	beq.s fr5		;bxx.l
	bra.s fr6		;bxx.s

fr4:	move.w (a2),d1		;adr(pc)
	and.w #%111110,d1
	cmp.w #%111010,d1
	bne.s fr0
fr5:	move.w 2(a2),d1
fr6:	lea 2(a2,d1.w),a3
	cmp.l para(pc),a3
	bne.s fr0

	move.l a2,a5
	bsr.L disasm
	bsr.L rawline

fr0:	bsr.L stopit
	beq.s fr8

	addq.l #2,a2
	cmp.l a2,a4
	bcc.s fr1

fr8:	st d7
frq:	rts

t:	cmp.b #3,d3
	bne.s tq

	move.l para(pc),a0
	move.l para+4(pc),a1
	cmp.l a1,a0
	bcc.s tq
	move.l para+8(pc),a2
	cmp.l a0,a2
	bcc.s t0

t1:	move.b (a0)+,(a2)+
	cmp.l a1,a0
	bcs.s t1
	bra.s t2

t0:	add.l a1,a2
	sub.l a0,a2
t3:	move.b -(a1),-(a2)
	cmp.l a0,a1
	bne.s t3		;t 0 x x

t2:	st d7
tq:	rts

o:	cmp.b #3,d3
	bne.s oq

	move.l para(pc),a0
	move.l para+4(pc),a1
o0:	move.b para+10(pc),(a0)+
	cmp.l a1,a0
	bcc.s o1
	move.b para+11(pc),(a0)+
	cmp.l a1,a0
	bcs.s o0
o1:	move.l a0,para+4-base(a6)	;real end
	lea filltxt(pc),a2
	bsr.s areamsg

	st d7
oq:	rts

e:	cmp.b #3,d3
	bne.s exq

	move.l para(pc),a0
	move.l para+4(pc),a1
	move.b para+10(pc),d0
	move.b para+11(pc),d1
ex0:	eor.b d0,(a0)+
	cmp.l a1,a0
	bcc.s ex1
	eor.b d1,(a0)+
	cmp.l a1,a0
	bcs.s ex0
ex1:
	move.l a0,para+4-base(a6)	;real end
	lea eortxt(pc),a2
	bsr.s areamsg

	st d7
exq:	rts

areamsg:lea linebuf+1(pc),a0
	move.l para(pc),d0
	move.l para+4(pc),d1
	bsr.l twoadr_
	move.l a2,a1
	bsr.l txttobuf
	move.w para+10(pc),d0
	bsr.l wordtoa_
	bra.l rawline

stopit:	cmp.b #$1b,ascii-base(a6)
	beq.s stopit0
	btst #10,$dff016
	beq.s stopit
	rts
stopit0:clr.w buflen-base(a6)
	rts


twoadr_:bsr.s adrtoa_
	move.b #"-",(a0)+
	move.l d1,d0
	bra.s adrtoa_
nibtoa_:move.b #"$",(a0)+
nibtoa:	movem.l d0-d2,-(a7)
	moveq #1-1,d2
	ror.l #4,d0
	bra.s lta0
bytetoa_:move.b #"$",(a0)+
bytetoa:movem.l d0-d2,-(a7)
	moveq #2-1,d2
	ror.l #8,d0
	bra.s lta0
wordtoa_:move.b #"$",(a0)+
wordtoa:movem.l d0-d2,-(a7)
	moveq #4-1,d2
	swap d0
	bra.s lta0
adrtoa_:move.b #"$",(a0)+
adrtoa:	movem.l d0-d2,-(a7)
	moveq #6-1,d2
	lsl.l #8,d0
	bra.s lta0
longtoa_:move.b #"$",(a0)+
longtoa:movem.l d0-d2,-(a7)
	moveq #8-1,d2
lta0:	rol.l #4,d0
	move.l d0,d1
	and.b #$0f,d1
	cmp.b #9,d1
	ble.s num
	add.b #"a"-"0"-10,d1
num:	add.b #"0",d1
	move.b d1,(a0)+
	dbf d2,lta0
	movem.l (a7)+,d0-d2
	rts

wordtod:move.l d0,-(a7)
	ext.l d0
	divu #1000,d0
	add.b #"0",d0
	move.b d0,(a0)+
	clr.w d0
	swap d0
	divu #100,d0
	add.b #"0",d0
	move.b d0,(a0)+
	swap d0
	bra.s btd0
bytetod:move.l d0,-(a7)
btd0:	cmp.b #99,d0
	bls.s btd1
	moveq #99,d0	
btd1:	ext.w d0
	ext.l d0
	divu #10,d0
	bra.s ntd1
nibtod:	move.l d0,-(a7)
	and.l #%1111,d0
	divu #10,d0
	beq.s ntd0
ntd1:	add.b #"0",d0
	move.b d0,(a0)+
ntd0:	swap d0
	add.b #"0",d0
	move.b d0,(a0)+
	move.l (a7)+,d0
	rts
hextod:	movem.l d0-d4/a1,-(a7)
	lea divtab(pc),a1
	moveq #10-1,d1
	sf d4
hd0:	moveq #"0",d2
	move.l (a1)+,d3
hd1:	cmp.l d3,d0
	bcs.s hd2
	st d4
	sub.l d3,d0
	addq.b #1,d2
	bra.s hd1
hd2:	tst.w d1
	beq.s hd4
	tst.b d4
	beq.s hd3
hd4:	move.b d2,(a0)+
hd3:	dbf d1,hd0
	movem.l (a7)+,d0-d4/a1
	rts
divtab:	dc.l 1000000000,100000000,10000000,1000000
	dc.l 100000,10000,1000,100,10,1

hextob:	movem.l d0-d4,-(a7)
	sf d4
	bsr.s hb3	
	bsr.s hb3	
	bsr.s hb3	
	st d4
	bsr.s hb3	
	movem.l (a7)+,d0-d4
	rts
hb3:	rol.l #8,d0
	move.b d0,d3
	bne.s hb2
	tst.b d4
	beq.s hb4
hb2:	st d4
	moveq #8-1,d2
hb0:	moveq #"0",d1
	add.b d3,d3
	bcc.s hb1
	moveq #"1",d1
hb1:	move.b d1,(a0)+
	dbf d2,hb0
	move.b #" ",(a0)+
hb4:	rts

disasm:	movem.l d0-d7/a0-a4/a6,-(a7)	;yo, funky again...
	lea instr(pc),a4	;a5:pc
	move.l a5,d6
dis2:	moveq #80-1,d0		;redis
	lea linebuf(pc),a0
dis3:	move.b #" ",(a0)+
	dbf d0,dis3
	move.l d6,a5
	move.w (a5)+,d1		;instr.w
dis0:			
	move.w d1,d0
	and.w (a4),d0		;mask
	cmp.w 2(a4),d0		;instrframe
	lea 12(a4),a4
	bne.s dis0		;scan instr
	move.w 4-12(a4),d2		;info.w
	move.l d6,d0
	lea linebuf(pc),a0
	move.w #">,",(a0)+
	bsr.l adrtoa
	addq.l #1,a0

	move.l a4,-(a7)
	lea -12+6(a4),a4
dis1:	move.b (a4)+,(a0)
	bclr #7,(a0)+		;end
	beq.s dis1
	move.l (a7)+,a4

	st d7
	move.w d2,d4
	and.w #$ff00,d4		;sizeopt
	cmp.w #s67,d4
	bne.s nos67
	bsr.L size67
nos67:	cmp.w #s6,d4
	bne.s nos6
	bsr.L size6
nos6:	cmp.w #s8,d4
	bne.s nos8
	bsr.L size8
nos8:	cmp.w #stab,d4
	bne.s nostab
	bsr.L opspos
nostab:	;cmp.w #snop,d4
	;bne.s nosnop
nosnop:

	lea disoffs(pc),a1
	ext.w d2		;clr sizeopt
	add.w d2,d2
	move.w (a1,d2.w),d2
	lea dissubs(pc),a1
	move.l d6,-(a7)
	jsr (a1,d2.w)		;no d7,a4
	move.l (a7)+,d6
	tst.b d7
	beq.L dis2

	movem.l (a7)+,d0-d7/a0-a4/a6
	rts

dissubs:
opfail=*-dissubs
	moveq #-1,d0
opf0:	move.w d0,$dff180
	dbf d0,opf0
noops=*-dissubs
	rts	

dcwop=*-dissubs
	move.w d1,d0
	bra.L wordtoa_

eatoccr=*-dissubs
	sf imsize-base(a6)
	bsr.L doea
	bra.L optoccr

eatosr=*-dissubs
	move.b #1,imsize-base(a6)
	bsr.L doea
	bra.L optosr

srtoea=*-dissubs
	bsr.L opsr
	bra.L dotoea

ccodelongrel=*-dissubs
	move.w d1,d0
	bsr.L docc
	bsr.L opspos
	bsr.L opdx02
	move.b #",",(a0)+
	bra.s lbx3

longcc=*-dissubs
	move.w d1,d0
	bsr.L docc
	move.b #".",(a0)+
	move.b #"l",(a0)+
	bsr.L opspos
longbxx=*-dissubs
lbx3:	move.w (a5)+,d0
	lea -2(a5,d0.w),a1
lbx2:	move.l a1,d0
	bra.L adrtoa_

shortcc=*-dissubs
	move.w d1,d0
	bsr.L docc
	move.b #".",(a0)+
	move.b #"s",(a0)+
	bsr.L opspos
shortbxx=*-dissubs
	move.b d1,d0
	ext.w d0
	lea (a5,d0.w),a1
	bra.s lbx2

eatoax=*-dissubs
	bsr.L doea
	bra.L optoax9b

eatodx=*-dissubs
	move.b #1,imsize-base(a6)
size67eatodx=*-dissubs
	bsr.L doea
	bra.L optodx9b

dxtoea=*-dissubs		;no im possible
	bsr.L opdx9b
	bra.L dotoea

iwordtoccr=*-dissubs
	move.b #"#",(a0)+
	move.w (a5)+,d0
	bsr.L bytetoa_
	bra.L optoccr

iwordtosr=*-dissubs
	bsr.s iwrd
	bra.L optosr
iword=*-dissubs
iwrd:	move.b #"#",(a0)+
	move.w (a5)+,d0
	bra.L wordtoa_

inibtoea=*-dissubs
	move.b #"#",(a0)+
	move.w (a5)+,d0
	and.l #%11111,d0		;#0-31(7)
	bsr.l hextod
	bra.L dotoea
ccodeea=*-dissubs
	move.w d1,d0
	bsr.L docc
	bsr.L opspos
srcea=*-dissubs
	bra.L doea

size67ixtoea=*-dissubs
	move.w d1,-(a7)
	moveq #%111100,d1	;#$xx.x
	bsr.L doea
	move.w (a7)+,d1
	bra.l dotoea

size67i9btoea=*-dissubs
	bsr.L opi9b
	bra.L dotoea

size67x9btodx02=*-dissubs
	btst #5,d1
	beq.s shi9b
	bsr.l opdx9b
	bra.s shdx9b
shi9b:	bsr.L opi9b
shdx9b:	bra.L optodx02

itrap=*-dissubs
	move.b #"#",(a0)+
	move.w d1,d0
	bra.l nibtod

srcdx02=*-dissubs
	bra.L opdx02

imusp=*-dissubs
	btst #3,d1
	beq.s imusp0
	bsr.L opusp
	bra.L optoax02
imusp0:	bsr.L opax02
	bra.L optousp

imove=*-dissubs
	move.w d1,d0
	and.w #%0011000000000000,d0
	rol.w #4,d0
	bne.s imo0
	sf d7
	rts
imo0:	lea sizemov(pc),a1
	move.b (a1,d0.w),(a0)+
	move.b 4(a1,d0.w),imsize-base(a6)

	bsr.L opspos
	bsr.L doea

	move.w d1,d0
	rol.w #7,d0
	and.w #%111,d0
	move.w d1,d3
	lsr.w #3,d3
	and.w #%111000,d3
	or.w d3,d0

	move.w d0,d1
	bra.L dotoea

imoveq=*-dissubs
	move.b #"#",(a0)+
	move.b d1,d0
	bsr.L bytetoa_
	bra.L optodx9b	

icmpm=*-dissubs
	or.w #%011000,d1	;(ax)+
	bsr.l doea
	rol.w #7,d1		;(ax)+
	bra.l dotoea

xbcd=*-dissubs
	bclr #14,d1
	bclr #3,d1		;dx
	beq.s xbcdx	
	bset #5,d1		;-(ax)
	bset #14,d1
xbcdx:	bsr.L doea		;no im possible
	rol.w #7,d1
	bra.L dotoea

size67adsbx=*-dissubs
	bclr #14,d1
	bclr #12,d1
	bclr #3,d1		;dx
	beq.s adsbxdx
	bset #14,d1		;-(ax)
	bset #5,d1
adsbxdx:bsr.l doea
	rol.w #7,d1
	bra.l dotoea	

size6movep=*-dissubs
	bset #5,d1		;d(ax)
	btst #7,d1
	beq.s mptodx
	bsr.L opdx9b
	bra.L dotoea
mptodx:	bsr.l doea
	bra.L optodx9b

imovem=*-dissubs
	move.w (a5)+,d3		;regbits
	btst #10,d1		;dir
	bne.s torx
	bsr.L dorx
	bra.L dotoea
torx:	bsr.L doea
	move.b #",",(a0)+
	bra.L dorx

dx9btodx02=*-dissubs
	bsr.L opdx9b
	bra.L optodx02
ax9btoax02=*-dissubs
	bsr.L opax9b
	bra.L optoax02
dx9btoax02=*-dissubs
	bsr.L opdx9b
	bra.L optoax02

ilink=*-dissubs
	bsr.s iunl0
	move.b #",",(a0)+
	bra.L iwrd
iunlk=*-dissubs
iunl0:	bra.L opax02

size8eatoax9b=*-dissubs
	bsr.L doea
	bra.s optoax9b

opspos:	lea linebuf+17(pc),a0
	rts
size8:	moveq #"w",d0
	move.b #1,imsize-base(a6)
	btst #8,d1
	beq.s siz60
	bra.s siz61
size6:	moveq #"w",d0
	move.b #1,imsize-base(a6)
	btst #6,d1
	beq.s siz60
siz61:	moveq #"l",d0
	move.b #2,imsize-base(a6)
siz60:	move.b #".",(a0)+
	move.b d0,(a0)+
	bra.s opspos
size67:	move.w d1,d0
	and.w #%11000000,d0
	cmp.w #%11000000,d0
	bne.s siz0
	sf d7
siz0:	lsr.w #6,d0
	move.b d0,imsize-base(a6)	;00.b,01.w,10.l,11.*
	move.b #".",(a0)+
	lea sizetxt(pc),a1
	move.b (a1,d0.w),(a0)+
	bra.s opspos

opi9b:	move.b #"#",(a0)+
	move.w d1,d0
	and.w #%111000000000,d0
	rol.w #7,d0
	bne.s i9b0
	moveq #8,d0
i9b0:	bra.L nibtod
optoax9b:move.b #",",(a0)+
opax9b:	move.b #"a",(a0)+
	bra.s opxx
optodx9b:move.b #",",(a0)+
opdx9b:	move.b #"d",(a0)+
opxx:	move.w d1,d0
	and.w #%111000000000,d0
	rol.w #7,d0
	add.b #"0",d0
	move.b d0,(a0)+
	rts
optoax02:move.b #",",(a0)+
opax02:	move.b #"a",(a0)+
	bra.s opxx02
optodx02:move.b #",",(a0)+
opdx02:	move.b #"d",(a0)+
opxx02:	move.w d1,d0
	and.w #%111,d0
	add.b #"0",d0
	move.b d0,(a0)+
	rts
optousp:move.b #",",(a0)+
opusp:	lea usptxt(pc),a1
	bra.s txttobuf
optoccr:lea toccrtxt(pc),a1
	bra.s txttobuf
optosr:	move.b #",",(a0)+
opsr:	lea srtxt(pc),a1
txttobuf:
	move.b (a1)+,(a0)
	bclr #7,(a0)+
	beq.s txttobuf
txtq:	rts	
bcpltobuf:move.b (a1)+,d0
bcpl0:	subq.b #1,d0
	bmi.s bcpl1
	move.b (a1)+,(a0)+
	bra.s bcpl0		
bcpl1:	rts

dorx:	move.w d1,d0
	and.w #%111000,d0
	cmp.w #%100000,d0	;-(ax)
	bne.s drx8
	moveq #16-1,d2
drx9:	lsr.w #1,d3
	roxl.w #1,d0
	dbf d2,drx9	
	move.w d0,d3
drx8:	sf d5
	clr.w d2
	moveq #"d",d0
	bsr.s drx0
	moveq #"a",d0
drx0:	moveq #8,d4
drx1:	tst.w d4
	beq.s drx5
	btst d2,d3
	bne.s drx2
	addq.w #1,d2
	subq.w #1,d4
	bra.s drx1
drx2:	tas d5
	beq.s drx3
	move.b #"/",(a0)+
drx3:	move.b d0,(a0)+
	move.b d2,(a0)
	add.b #"0",(a0)
	bclr #3,(a0)+
	sf d6
drx4:	addq.w #1,d2
	subq.w #1,d4
	beq.s drx6
	btst d2,d3
	beq.s drx6
	st d6
	bra.s drx4
drx6:	tst.b d6
	beq.s drx7
	move.b #"-",(a0)+
	move.b d0,(a0)+
	move.b d2,(a0)
	add.b #"0"-1,(a0)
	bclr #3,(a0)+
drx7:	tst.w d4
	beq.s drx5
	subq.w #1,d4
	addq.w #1,d2
	bra.s drx1
drx5:	rts

docc:	lea ccodetxt(pc),a1
	and.w #%111100000000,d0
	lsr.w #7,d0
	lea (a1,d0.w),a1
	move.b (a1)+,(a0)+
	move.b (a1)+,(a0)+
	rts

dotoea:	move.w d1,d0
	and.w #%111111,d0
	cmp.w #%111001,d0	;dest:(pc),d(pc),#xx
	bls.s doto0
	sf d7 
	rts
doto0:	move.b #",",(a0)+
doea:	movem.l d1-d6,-(a7)
	move.w d1,d5
	and.w #%111111,d5
	move.w d5,d4	;ea:bit0-5
	and.b #7,d4
	add.b #"0",d4	;regnum, if avail
	move.w d5,d3
	lsr.w #3,d3
	bne.s ea0
	move.b #"d",(a0)+
	move.b d4,(a0)+
ea0:	subq.b #1,d3
	bne.s ea1
	move.b #"a",(a0)+
	move.b d4,(a0)+
ea1:	subq.b #1,d3
	bne.s ea2
	move.b #"(",(a0)+
	move.b #"a",(a0)+
	move.b d4,(a0)+
	move.b #")",(a0)+
ea2:	subq.b #1,d3
	bne.s ea3
	move.b #"(",(a0)+
	move.b #"a",(a0)+
	move.b d4,(a0)+
	move.b #")",(a0)+
	move.b #"+",(a0)+
ea3:	subq.b #1,d3
	bne.s ea4
	move.b #"-",(a0)+
	move.b #"(",(a0)+
	move.b #"a",(a0)+
	move.b d4,(a0)+
	move.b #")",(a0)+
ea4:	subq.b #1,d3
	bne.s ea5
	move.w (a5)+,d0		;d.w(ax)
	bsr.L swordtoa_
	move.b #"(",(a0)+
	move.b #"a",(a0)+
	move.b d4,(a0)+
	move.b #")",(a0)+
ea5:	subq.b #1,d3
	bne.s ea6

	move.w (a5)+,d0		;d.b(ax,rx.x)
	bsr.l sbytetoa_
	move.b #"(",(a0)+
	move.b #"a",(a0)+
	move.b d4,(a0)+
	move.b #",",(a0)+
	moveq #"d",d4
	btst #15,d0
	beq.s eal0
	moveq #"a",d4
eal0:	move.b d4,(a0)+
	move.w d0,d4
	and.w #$7000,d4
	lsr.w #8,d4
	lsr.w #4,d4
	add.b #"0",d4
	move.b d4,(a0)+
	move.b #".",(a0)+
	moveq #"w",d4
	btst #11,d0
	beq.s eal1
	moveq #"l",d4
eal1:	move.b d4,(a0)+
	move.b #")",(a0)+

ea6:	cmp.w #%111000,d5
	bne.s ea7
	move.w (a5)+,d0
	bsr.l wordtoa_
	move.b #".",(a0)+
	move.b #"w",(a0)+
ea7:	cmp.w #%111001,d5
	bne.s ea8
	move.l (a5)+,d0
	bsr.l adrtoa_
ea8:	cmp.w #%111010,d5
	bne.s ea9

	move.w (a5)+,d0		;adr(pc)
	lea -2(a5,d0.w),a1
	move.l a1,d0
	bsr.l adrtoa_

	move.b #"(",(a0)+
	move.b #"p",(a0)+
	move.b #"c",(a0)+
	move.b #")",(a0)+
ea9:	cmp.w #%111011,d5
	bne.s ea10

	move.w (a5)+,d0		;d.b(pc,rx.x)
	bsr.l sbytetoa_
	move.b #"(",(a0)+
	move.b #"p",(a0)+
	move.b #"c",(a0)+
	move.b #",",(a0)+
	moveq #"d",d4
	btst #15,d0
	beq.s eal2
	moveq #"a",d4
eal2:	move.b d4,(a0)+
	move.w d0,d4
	and.w #$7000,d4
	lsr.w #8,d4
	lsr.w #4,d4
	add.b #"0",d4
	move.b d4,(a0)+
	move.b #".",(a0)+
	moveq #"w",d4
	btst #11,d0
	beq.s eal3
	moveq #"l",d4
eal3:	move.b d4,(a0)+
	move.b #")",(a0)+

ea10:	cmp.w #%111100,d5
	bhi.s ea14		;eafail
	bne.s ea11
	move.b #"#",(a0)+
	move.w (a5)+,d0
	move.b imsize(pc),d3
	bne.s ea12
	bsr.L bytetoa_
	bra.s ea11
ea12:	cmp.b #1,d3
	bne.s ea13
	bsr.L wordtoa_
	bra.s ea11
ea13:	cmp.b #2,d3
	bhi.s ea11		;11.*
	swap d0
	move.w (a5)+,d0
	bsr.l longtoa_
ea11:	movem.l (a7)+,d1-d6
	rts
ea14:	sf d7
	bra.s ea11

sbytetoa_:move.l d0,-(a7)
	btst #0,dissign-base(a6)
	beq.s sby0
	tst.b d0
	bpl.s sby0
	neg.b d0	
	move.b #"-",(a0)+
sby0:	btst #1,dissign-base(a6)
	beq.s sby1
	and.l #$ff,d0
	bsr.l hextod
	bra.s sby2
sby1:	bsr.l bytetoa_
sby2:	move.l (a7)+,d0
	rts

swordtoa_:move.l d0,-(a7)
	btst #0,dissign-base(a6)
	beq.s swo0
	tst.w d0
	bpl.s swo0
	neg.w d0
	move.b #"-",(a0)+	
swo0:	btst #1,dissign-base(a6)
	beq.s swo1
	and.l #$ffff,d0
	bsr.l hextod
	bra.s swo2
swo1:	bsr.l wordtoa_
swo2:	move.l (a7)+,d0
	rts

assubs:
aopfail=*-assubs
anoops=*-assubs
	rts
adcwop=*-assubs
	bsr.L atoword_
	move.w d0,op68000-base(a6)
	rts
aeatoccr=*-assubs
	sf imsize-base(a6)
	bsr.L assea
	lea toccrtxt(pc),a0
	bra.L cmptxt
aeatosr=*-assubs
	move.b #1,imsize-base(a6)
	bsr.L assea
	lea tosrtxt(pc),a0
	bra.L cmptxt

asrtoea=*-assubs
	lea srtxt(pc),a0
	bsr.l cmptxt
	bra.L asstoea

alongcc=*-assubs
	bsr.l assccode
	cmp.b #".",(a3)+
	bne.s algbxx1		;fail
	cmp.b #"l",(a3)+
	bne.s algbxx1		;fail
	bsr.L asstab
alongbxx=*-assubs
algrel:	bsr.L atoadr_
	subq.l #2,d0
	sub.l para(pc),d0
	move.l d0,d1
	beq.s algbxx1
	bpl.s algbxx0
	not.l d1
algbxx0:cmp.l #$7fff,d1
	bhi.s algbxx1
	bra.L storeword 
algbxx1:sf d7
	rts
ashortcc=*-assubs
	bsr.L assccode
	cmp.b #".",(a3)+
	bne.s ashbxx1		;fail
	cmp.b #"s",(a3)+
	bne.s ashbxx1		;fail
	bsr.L asstab
ashortbxx=*-assubs
ashbxx:	bsr.L atoadr_
	subq.l #2,d0
	sub.l para(pc),d0
	or.b d0,op68000+1-base(a6)
	beq.s ashbxx1
	bpl.s ashbxx0
	not.l d0
ashbxx0:moveq #$7f,d1
	cmp.l d1,d0
	bls.s ashbxx2
ashbxx1:sf d7
ashbxx2:rts

aeatoax=*-assubs
	bsr.L assea
	bra.L asstoax9b

aeatodx=*-assubs
	move.b #1,imsize-base(a6)
asize67eatodx=*-assubs
	bsr.L assea
	bra.L asstodx9b

adxtoea=*-assubs
	bsr.L assdx9b
	bra.L asstoea

aiwordtoccr=*-assubs
	cmp.b #"#",(a3)+
	bne.L fail
	bsr.L atobyte_
	bsr.L storeword
	lea toccrtxt(pc),a0
	bra.L cmptxt
aiwordtosr=*-assubs
	bsr.s aiwrd
	lea tosrtxt(pc),a0
	bra.l cmptxt
aiword=*-assubs
aiwrd:	cmp.b #"#",(a3)+
	bne.L fail
	bsr.L atoword_
	bra.L storeword
accodelongrel=*-assubs
	bsr.L assccode
	bsr.L asstab
	bsr.L assdx02
	cmp.b #",",(a3)+
	beq.L algrel
	sf d7
	rts
ainibtoea=*-assubs
	cmp.b #"#",(a3)+
	bne.L fail
	bsr.L atodnib
	cmp.b #31,d0
	bhi.l fail
	bsr.L storeword
	bra.L asstoea

accodeea=*-assubs
	bsr.L assccode
	bsr.L asstab
asrcea=*-assubs
	bra.l assea

asize8eatoax9b=*-assubs
	bsr.L assea
	bra.L asstoax9b

asize67ixtoea=*-assubs
	cmp.b #"#",(a3)
	bne.L fail
	bsr.L assea		;#$xx.x
	bra.L asstoea		;clr previous ea !

asize67i9btoea=*-assubs
	cmp.b #"#",(a3)+
	bne.l fail
	bsr.L atobyte
	beq.l fail
	cmp.b #8,d0
	bhi.l fail	
	bne.s ai9b0
	sf d0
ai9b0:	add.b d0,d0
	or.b d0,op68000-base(a6)
	bra.l asstoea

asize67x9btodx02=*-assubs
	cmp.b #"#",(a3)+
	bne.s ashft0
	bsr.L atobyte
	beq.L fail
	cmp.b #8,d0
	bhi.L fail
	bne.s ashft1
	sf d0
ashft1:	add.b d0,d0
	or.b d0,op68000-base(a6)
	bra.L asstodx02
ashft0:	bset #5,op68000+1-base(a6)
	subq.l #1,a3
	bsr.L assdx9b
	bra.l asstodx02

aitrap=*-assubs
	cmp.b #"#",(a3)+
	bne.L fail
	bsr.L atodnib
	cmp.b #15,d0
	bhi.L fail
	or.b d0,op68000+1-base(a6)
	rts
asrcdx02=*-assubs
	bra.L assdx02
aimusp=*-assubs
	lea usptxt(pc),a0
	cmp.b #"a",(a3)
	beq.s aimusp0
	bset #3,op68000+1-base(a6)
	bsr.s aimusp1
	cmp.b #",",(a3)+
	bra.L assax02
aimusp0:bsr.L assax02
	cmp.b #",",(a3)+
	bne.L fail
aimusp1:bra.L cmptxt

aimove=*-assubs
	moveq #%01,d0
	sf imsize-base(a6)
	cmp.b #"b",(a3)
	beq.s aimov0
	moveq #%11,d0
	addq.b #1,imsize-base(a6)
	cmp.b #"w",(a3)
	beq.s aimov0
	moveq #%10,d0
	addq.b #1,imsize-base(a6)
	cmp.b #"l",(a3)
	bne.l fail
aimov0:	lsl.b #4,d0
	or.b d0,op68000-base(a6)
	addq.l #1,a3
	bsr.L asstab
	bsr.L assea
	move.w op68000(pc),-(a7)
	bsr.L asstoea
	move.w op68000(pc),d1
	move.w (a7)+,op68000-base(a6)
	move.w d1,d0
	and.w #%111,d0
	ror.w #7,d0
	or.w d0,op68000-base(a6)
	and.w #%111000,d1
	lsl.w #3,d1
	or.w d1,op68000-base(a6)
	rts
aimoveq=*-assubs
	sf imsize-base(a6)
	bsr.l assea
	move.w op68000(pc),d0
	clr.l oplen
	and.w #%111111,d0	;#x
	cmp.w #%111100,d0
	bne.l fail
	move.b op68000+3(pc),op68000+1-base(a6)
	bra.L asstodx9b
aicmpm=*-assubs
	cmp.b #"(",(a3)+
	bne.l fail
	bsr.L assax02
	lea cmpmtxt(pc),a0
	bsr.L cmptxt
	bsr.L assax9b
	cmp.b #")",(a3)+
	bne.l fail
	cmp.b #"+",(a3)+
	bne.l fail
	rts

asize67adsbx=*-assubs		;same!
axbcd=*-assubs
aasxbcd:cmp.b #"-",(a3)+
	bne.s axbcd0
	bset #3,op68000+1-base(a6)
	cmp.b #"(",(a3)+
	bne.s axbcd2		;fail
	bsr.L assax02
	lea xbcdtxt(pc),a0
	bsr.L cmptxt
	bsr.L assax9b
	cmp.b #")",(a3)+
	beq.s axbcd1		;no fail
axbcd2:	sf d7
axbcd1:	rts
axbcd0:	subq.l #1,a3
	bsr.L assdx02
	bra.L asstodx9b

asize6movep=*-assubs
	cmp.b #"d",(a3)
	beq.s amovp0
	bsr.L assea
	move.w op68000(pc),d0
	bclr #5,op68000+1-base(a6)
	and.w #%111000,d0
	cmp.w #%101000,d0
	bne.l fail
	bra.L asstodx9b
amovp0:	bset #7,op68000+1-base(a6)
	bsr.L assdx9b
	bsr.L asstoea
	move.w op68000(pc),d0
	bclr #5,op68000+1-base(a6)
	and.w #%111000,d0
	cmp.w #%101000,d0
	bne.l fail
	rts
aimovem=*-assubs
	cmp.b #"d",(a3)
	beq.s aimovm0
	cmp.b #"a",(a3)
	beq.s aimovm0
	bset #10,op68000-base(a6)
	bsr.L assea
	cmp.b #",",(a3)+
	bne.l fail
	bsr.s assrx
	lea op68000+2(pc),a0
	move.l (a0),2(a0)
	move.w d0,(a0)
	move.w op68000(pc),d0
	and.w #%111111,d0
	cmp.w #%111010,d0	;movem.x x(pc)
	bne.s aimovm7	
	subq.w #2,2(a0)
	bra.s aimovm7
aimovm0:bsr.s assrx
	bsr.L asstoea
aimovm7:move.w op68000(pc),d0
	and.w #%111000,d0
	cmp.w #%100000,d0
	bne.s aimovm8
	move.w op68000+2(pc),d1	;rl
	moveq #16-1,d0
aimovm9:lsr.w #1,d1
	roxl.w #1,d2
	dbf d0,aimovm9
	move.w d2,op68000+2-base(a6)
aimovm8:rts
assrx:	clr.w d0
aimovm2:move.b 1(a3),d1
	sub.b #"0",d1
	bcs.L fail
	cmp.b #7,d1
	bhi.L fail
	cmp.b #"d",(a3)
	beq.s aimovm5
	cmp.b #"a",(a3)
	bne.L fail
	addq.b #8,d1
aimovm5:addq.l #2,a3
	bset d1,d0
aimovm4:cmp.b #",",(a3)
	beq.s aimovm1
	cmp.b #"/",(a3)+
	beq.s aimovm2
	cmp.b #"-",-1(a3)
	bne.s aimovm1
	move.b 1(a3),d2
	sub.b #"0",d2
	bcs.L fail
	cmp.b #7,d2
	bhi.L fail
	cmp.b #"d",(a3)
	beq.s aimovm6
	cmp.b #"a",(a3)
	bne.l fail
	addq.b #8,d2
aimovm6:addq.l #2,a3
	cmp.b d1,d2
	bls.l fail
aimovm3:addq.b #1,d1
	bset d1,d0	
	cmp.b d1,d2
	bne.s aimovm3
	bra.s aimovm4
aimovm1:bra.L storeword

adx9btodx02=*-assubs
	bsr.s assdx9b
	bra.s asstodx02
aax9btoax02=*-assubs
	bsr.s assax9b
	bra.s asstoax02
adx9btoax02=*-assubs
	bsr.s assdx9b
	bra.s asstoax02
aiunlk=*-assubs
	bra.s assax02
ailink=*-assubs
	bsr.s assax02
	cmp.b #",",(a3)+
	bne.s fail
	cmp.b #"#",(a3)+
	bne.s fail
	bsr.L atoword_
	bra.L storeword

asstoax9b:cmp.b #",",(a3)+
	bne.s fail
assax9b:cmp.b #"a",(a3)+
	beq.s assxx9b
	bra.s fail
asstodx9b:cmp.b #",",(a3)+
	bne.s fail
assdx9b:cmp.b #"d",(a3)+
	bne.s fail
assxx9b:move.b (a3)+,d0
	sub.b #"0",d0
	bcs.s fail
	cmp.b #7,d0
	bhi.s fail	
	asl.w #8,d0
	asl.w #1,d0
	or.w d0,op68000-base(a6)
	rts
asstoax02:cmp.b #",",(a3)+
	bne.s fail
assax02:cmp.b #"a",(a3)+
	bne.s fail
	bra.s assxx02
asstodx02:cmp.b #",",(a3)+
	bne.s fail
assdx02:cmp.b #"d",(a3)+
	bne.s fail
assxx02:move.b (a3)+,d0
	sub.b #"0",d0
	bcs.s fail
	cmp.b #7,d0
	bhi.s fail
	or.b d0,op68000+1-base(a6)
	rts
fail:	sf d7
	rts
assccode:clr.w d0
	lea ccodetxt(pc),a0
	move.b (a3)+,d1
	lsl.w #8,d1
	move.b (a3)+,d1
asscc0:	cmp.w (a0)+,d1
	beq.s asscc1
	add.w #$0100,d0
	cmp.w #$1000,d0
	bne.s asscc0
	bra.s fail
asscc1:	or.w d0,op68000-base(a6)
	rts

cmpt0:	cmp.b (a3)+,d0
	bne.s fail
cmptxt:	move.b (a0)+,d0
	bclr #7,d0
	beq.s cmpt0
	cmp.b (a3)+,d0
	bne.s fail 
	rts

storeword:
	lea op68000-2(pc),a0
	move.w (a0),d1		;oplen!
	addq.w #1,(a0)+
	add.w d1,d1
	move.w d0,2(a0,d1.w)
	rts

asstab:	cmp.l lineend(pc),a3
	bhi.s fail
	cmp.b #" ",(a3)+
	beq.s asstab
asstab0:subq.l #1,a3
	rts	

atolong_:cmp.b #"$",(a3)+
	bne.s fail
atolong:moveq #8-1,d2
	bra.s atob2
atoadr_:cmp.b #"$",(a3)+
	bne.s fail
atoadr:	moveq #6-1,d2
	bra.s atob2
atoword_:cmp.b #"$",(a3)+
	bne.s fail
atoword:moveq #4-1,d2
	bra.s atob2
atobyte_:cmp.b #"$",(a3)+
	bne.s fail
atobyte:moveq #2-1,d2
atob2:	clr.l d0
atob1:	move.b (a3),d1
	cmp.b #"f",d1
	bhi.s atob3
	sub.b #"0",d1
	bcs.s atob3
	cmp.b #9,d1
	bls.s atob0
	cmp.b #"a"-"0",d1
	bcs.s atob3
	sub.b #"a"-"0"-10,d1
atob0:	lsl.l #4,d0
	or.b d1,d0
	addq.l #1,a3
	dbf d2,atob1
atob3:	tst.l d0
	rts
atodnib:clr.l d0		;0-99
	move.b (a3),d1
	sub.b #"0",d1
	bcs.s atdnb0
	cmp.b #9,d1
	bhi.s atdnb0
	addq.l #1,a3
	move.b d1,d0
	move.b (a3),d1
	sub.b #"0",d1
	bcs.s atdnb0
	cmp.b #9,d1
	bhi.s atdnb0
	addq.l #1,a3
	mulu #10,d0
	add.b d1,d0
atdnb0:	rts
atodlong:
	clr.l d0
	clr.l d1
	moveq #10-1,d2
atol1:	move.b (a3),d1
	sub.b #"0",d1
	bcs.s atodl0
	cmp.b #9,d1
	bhi.s atodl0
	addq.l #1,a3
	add.l d0,d0		;*2
	move.l d0,-(a7)
	lsl.l #2,d0		;*2*4
	add.l (a7)+,d0
	add.l d1,d0
	dbf d2,atol1
atodl0:	rts

asstoea:cmp.b #",",(a3)+
	bne.L fail
assea:	and.w #$ffc0,op68000-base(a6)
	cmp.b #"d",(a3)			;dx
	beq.L assdx02
	or.w #$0008,op68000-base(a6)
	cmp.b #"a",(a3)			;ax
	beq.L assax02
	and.w #$ffc0,op68000-base(a6)
	cmp.b #"(",(a3)			;(ax)|(ax)+
	bne.s assea0
	addq.l #1,a3
	or.w #$0010,op68000-base(a6)
	bsr.L assax02
	cmp.b #")",(a3)+
	bne.L fail
	cmp.b #"+",(a3)
	bne.s assea1
	addq.l #1,a3
	or.w #$0018,op68000-base(a6)
assea1:	rts
assea0:	cmp.b #"-",(a3)		;-(ax)
	bne.s assea2
	cmp.b #"(",1(a3)	;skip -d(ax)
	bne.s assea2
	addq.l #2,a3
	or.w #$0020,op68000-base(a6)
	bsr.L assax02
	cmp.b #")",(a3)+
	bne.L fail
	rts
assea2:	cmp.b #"#",(a3)
	bne.s assea3
	addq.l #1,a3
	or.w #$003c,op68000-base(a6)
	cmp.b #34,(a3)
	bne.s assea16
	addq.l #1,a3
	clr.l d0
	moveq #5-1,d1
assea18:cmp.b #34,(a3)+
	beq.s assea17
	lsl.l #8,d0
	move.b -1(a3),d0
	dbf d1,assea18
	bra.L fail
assea16:cmp.b #"$",(a3)
	beq.s assea22
	bsr.l atodlong
	bra.s assea17
assea22:bsr.L atolong_
assea17:move.b imsize(pc),d1
	beq.s assea13
	cmp.b #%01,d1
	beq.s assea14
	cmp.b #%10,d1
	bne.l fail
	swap d0
	bsr.s assea15
	swap d0
	bra.s assea15
assea13:cmp.l #$ff,d0
	bhi.l fail
assea14:cmp.l #$ffff,d0
	bhi.L fail
assea15:bra.L storeword	

assea3:	sf d2
	cmp.b #"-",(a3)		;skip-(ax)
	bne.s assea19
	addq.l #1,a3
	st d2
assea19:move.w d2,-(a7)
	cmp.b #"$",(a3)
	beq.s assea24
	bsr.L atodlong
	bra.s assea23
assea24:bsr.L atolong_
assea23:move.w (a7)+,d2
	cmp.b #"(",(a3)		;d(
	bne.L assea4
	tst.b d2
	beq.s assea20
	neg.l d0
assea20:addq.l #1,a3
	cmp.b #"a",(a3)		;d(ax
	bne.L assea5
	move.l d0,-(a7)
	bsr.L assax02
	move.l (a7)+,d0
	move.l d0,d1
	bpl.s assea21
	neg.l d1
assea21:cmp.b #")",(a3)+	;d(ax)
	bne.s assea6
	or.w #$0028,op68000-base(a6)
	cmp.l #$ffff,d1		;abs(d0)
	bhi.L fail
	bra.L storeword
assea6:	cmp.b #",",-1(a3)
	bne.L fail
	or.w #$0030,op68000-base(a6)
assea9:	cmp.l #$ff,d1		;abs(d0)
	bhi.L fail
	and.w #$ff,d0
	cmp.b #"d",(a3)+
	beq.s assea7
	cmp.b #"a",-1(a3)
	bne.L fail
	bset #15,d0
assea7:	move.b (a3)+,d1
	sub.b #"0",d1
	bcs.L fail		
	cmp.b #7,d1
	bhi.L fail
	ext.w d1
	ror.w #4,d1
	or.w d1,d0
	cmp.b #".",(a3)+
	bne.L fail
	cmp.b #"w",(a3)+
	beq.s assea8
	cmp.b #"l",-1(a3)
	bne.L fail
	bset #11,d0
assea8:	cmp.b #")",(a3)+	;d(ax,rx.x)
	bne.L fail
	bra.L storeword
assea5:	cmp.b #"p",(a3)+
	bne.L fail
	cmp.b #"c",(a3)+
	bne.L fail
	cmp.b #")",(a3)+		;d(pc)
	bne.s assea10
	or.w #$003a,op68000-base(a6)
	subq.l #2,d0
	sub.l para(pc),d0
	bsr.L storeword
	tst.l d0
	bpl.s assea12
	not.l d0
assea12:cmp.l #$7fff,d0
	bhi.L fail
	rts
assea10:or.w #$003b,op68000-base(a6)
	cmp.b #",",-1(a3)
	beq.L assea9			;d(pc,rx.x)
	sf d7
	rts
assea4:	cmp.b #".",(a3)
	beq.s assea11
	or.w #$0039,op68000-base(a6)
	swap d0
	bsr.L storeword
	swap d0
	bra.L storeword
assea11:addq.l #1,a3
	cmp.b #"w",(a3)+	
	bne.L fail
	or.w #$0038,op68000-base(a6)
	cmp.l #$ffff,d0
	bhi.L fail
	bra.L storeword

	xopfail=0		;dummy
	xnoops=1
	xdcwop=2
	xeatoccr=3
	xeatosr=4
	xsrtoea=5
	xlongbxx=6
	xlongcc=7
	xshortbxx=8
	xshortcc=9
	xeatoax=10
	xeatodx=11
	xdxtoea=12
	xiwordtoccr=13
	xiwordtosr=14
	xiword=15
	xccodelongrel=16
	xinibtoea=17
	xccodeea=18
	xsrcea=19
	xsize67eatodx=20
	xsize8eatoax9b=21
	xsize67adsbx=22
	xsize67ixtoea=23
	xsize67i9btoea=24
	xsize67x9btodx02=25
	xitrap=26
	xsrcdx02=27
	ximusp=28
	ximove=29
	ximoveq=30
	xicmpm=31
	xxbcd=32
	xsize6movep=33
	ximovem=34
	xdx9btodx02=35
	xax9btoax02=36
	xdx9btoax02=37
	xiunlk=38
	xilink=39

disoffs:dc.w opfail,noops,dcwop,eatoccr,eatosr,srtoea,longbxx,longcc
	dc.w shortbxx,shortcc,eatoax,eatodx,dxtoea,iwordtoccr
	dc.w iwordtosr,iword,ccodelongrel,inibtoea,ccodeea,srcea
	dc.w size67eatodx,size8eatoax9b,size67adsbx,size67ixtoea
	dc.w size67i9btoea,size67x9btodx02,itrap,srcdx02,imusp
	dc.w imove,imoveq,icmpm,xbcd,size6movep
	dc.w imovem,dx9btodx02,ax9btoax02,dx9btoax02
	dc.w iunlk,ilink

assoffs:dc.w aopfail,anoops,adcwop,aeatoccr,aeatosr,asrtoea
	dc.w alongbxx,alongcc
	dc.w ashortbxx,ashortcc,aeatoax,aeatodx,adxtoea,aiwordtoccr
	dc.w aiwordtosr,aiword,accodelongrel,ainibtoea,accodeea,asrcea
	dc.w asize67eatodx,asize8eatoax9b,asize67adsbx,asize67ixtoea
	dc.w asize67i9btoea,asize67x9btodx02,aitrap,asrcdx02,aimusp
	dc.w aimove,aimoveq,aicmpm,axbcd,asize6movep
	dc.w aimovem,adx9btodx02,aax9btoax02,adx9btoax02
	dc.w aiunlk,ailink

instr:	dc.w $ffff,$4afc,snop!xnoops
	dc.b "illega"!128
	dc.w $ffff,$4e70,snop!xnoops
	dc.b "reset"!128,0
	dc.w $ffff,$4e71,snop!xnoops
	dc.b "nop"!128,0,0,0
	dc.w $ffff,$4e73,snop!xnoops
	dc.b "rte"!128,0,0,0
	dc.w $ffff,$4e75,snop!xnoops
	dc.b "rts"!128,0,0,0
	dc.w $ffff,$4e76,snop!xnoops
	dc.b "trapv"!128,0
	dc.w $ffff,$4e77,snop!xnoops
	dc.b "rtr"!128,0,0,0

	dc.w $ffff,$003c,stab!xiwordtoccr
	dc.b "ori"!128,0,0,0
	dc.w $ffff,$023c,stab!xiwordtoccr
	dc.b "andi"!128,0,0
	dc.w $ffff,$0a3c,stab!xiwordtoccr
	dc.b "eori"!128,0,0

	dc.w $ffff,$007c,stab!xiwordtosr
	dc.b "ori"!128,0,0,0
	dc.w $ffff,$027c,stab!xiwordtosr
	dc.b "andi"!128,0,0
	dc.w $ffff,$0a7c,stab!xiwordtosr
	dc.b "eori"!128,0,0

	dc.w $f1f8,$c140,stab!xdx9btodx02
	dc.b "exg"!128,0,0,0
	dc.w $f1f8,$c148,stab!xax9btoax02
	dc.b "exg"!128,0,0,0
	dc.w $f1f8,$c188,stab!xdx9btoax02
	dc.b "exg"!128,0,0,0

	dc.w $fff8,$4e58,stab!xiunlk
	dc.b "unlk"!128,0,0
	dc.w $fff8,$4e50,stab!xilink
	dc.b "link"!128,0,0

	dc.w $fff0,$4e40,stab!xitrap
	dc.b "trap"!128,0,0	

	dc.w $f100,$7000,stab!ximoveq
	dc.b "moveq"!128,0

	dc.w $ffff,$4e72,stab!xiword
	dc.b "stop"!128,0,0

	dc.w $fff8,$4840,stab!xsrcdx02
	dc.b "swap"!128,0,0	
	dc.w $ffb8,$4880,s6!xsrcdx02
	dc.b "ext"!128,0,0,0

	dc.w $f138,$b108,s67!xicmpm
	dc.b "cmpm"!128,0,0

	dc.w $f1f0,$c100,stab!xxbcd
	dc.b "abcd"!128,0,0
	dc.w $f1f0,$8100,stab!xxbcd
	dc.b "sbcd"!128,0,0

	dc.w $f130,$d100,s67!xsize67adsbx
	dc.b "addx"!128,0,0
	dc.w $f130,$9100,s67!xsize67adsbx
	dc.b "subx"!128,0,0

	dc.w $ffc0,$40c0,stab!xsrtoea
	dc.b "move"!128,0,0
	dc.w $ffc0,$44c0,stab!xeatoccr
	dc.b "move"!128,0,0
	dc.w $ffc0,$46c0,stab!xeatosr
	dc.b "move"!128,0,0

	dc.w $fff0,$4e60,stab!ximusp
	dc.b "move"!128,0,0

	dc.w $fb80,$4880,s6!ximovem
	dc.b "movem"!128,0

	dc.w $f138,$0108,s6!xsize6movep
	dc.b "movep"!128,0

	dc.w $f1c0,$41c0,stab!xeatoax
	dc.b "lea"!128,0,0,0

	dc.w $ffff,$6000,stab!xlongbxx	;order !
	dc.b "bra.l"!128,0
	dc.w $ffff,$6100,stab!xlongbxx
	dc.b "bsr.l"!128,0
	dc.w $ff00,$6000,stab!xshortbxx
	dc.b "bra.s"!128,0
	dc.w $ff00,$6100,stab!xshortbxx
	dc.b "bsr.s"!128,0
	dc.w $f0ff,$6000,snop!xlongcc
	dc.b "b"!128,0,0,0,0,0
	dc.w $f000,$6000,snop!xshortcc
	dc.b "b"!128,0,0,0,0,0

	dc.w $f0f8,$50c8,snop!xccodelongrel	;order !
	dc.b "db"!128,0,0,0,0
	dc.w $f0c0,$50c0,snop!xccodeea
	dc.b "s"!128,0,0,0,0,0

	dc.w $ffc0,$4800,stab!xsrcea
	dc.b "nbcd"!128,0,0
	dc.w $ffc0,$4840,stab!xsrcea
	dc.b "pea"!128,0,0,0
	dc.w $ffc0,$4ac0,stab!xsrcea
	dc.b "tas"!128,0,0,0
	dc.w $ffc0,$4e80,stab!xsrcea
	dc.b "jsr"!128,0,0,0
	dc.w $ffc0,$4ec0,stab!xsrcea
	dc.b "jmp"!128,0,0,0
	dc.w $ffc0,$e0c0,stab!xsrcea
	dc.b "asr"!128,0,0,0
	dc.w $ffc0,$e1c0,stab!xsrcea
	dc.b "asl"!128,0,0,0
	dc.w $ffc0,$e2c0,stab!xsrcea
	dc.b "lsr"!128,0,0,0
	dc.w $ffc0,$e3c0,stab!xsrcea
	dc.b "lsl"!128,0,0,0
	dc.w $ffc0,$e4c0,stab!xsrcea
	dc.b "roxr"!128,0,0
	dc.w $ffc0,$e5c0,stab!xsrcea
	dc.b "roxl"!128,0,0
	dc.w $ffc0,$e6c0,stab!xsrcea
	dc.b "ror"!128,0,0,0
	dc.w $ffc0,$e7c0,stab!xsrcea
	dc.b "rol"!128,0,0,0

	dc.w $f1c0,$80c0,stab!xeatodx
	dc.b "divu"!128,0,0
	dc.w $f1c0,$81c0,stab!xeatodx
	dc.b "divs"!128,0,0
	dc.w $f1c0,$c0c0,stab!xeatodx
	dc.b "mulu"!128,0,0
	dc.w $f1c0,$c1c0,stab!xeatodx
	dc.b "muls"!128,0,0
	dc.w $f1c0,$4180,stab!xeatodx
	dc.b "chk"!128,0,0,0

	dc.w $f0c0,$90c0,s8!xsize8eatoax9b
	dc.b "suba"!128,0,0
	dc.w $f0c0,$b0c0,s8!xsize8eatoax9b
	dc.b "cmpa"!128,0,0
	dc.w $f0c0,$d0c0,s8!xsize8eatoax9b
	dc.b "adda"!128,0,0

	dc.w $f100,$8000,s67!xsize67eatodx
	dc.b "or"!128,0,0,0,0
	dc.w $f100,$9000,s67!xsize67eatodx
	dc.b "sub"!128,0,0,0
	dc.w $f100,$b000,s67!xsize67eatodx
	dc.b "cmp"!128,0,0,0
	dc.w $f100,$c000,s67!xsize67eatodx
	dc.b "and"!128,0,0,0
	dc.w $f100,$d000,s67!xsize67eatodx
	dc.b "add"!128,0,0,0

	dc.w $f100,$8100,s67!xdxtoea
	dc.b "or"!128,0,0,0,0
	dc.w $f100,$9100,s67!xdxtoea
	dc.b "sub"!128,0,0,0
	dc.w $f100,$b100,s67!xdxtoea
	dc.b "eor"!128,0,0,0
	dc.w $f100,$c100,s67!xdxtoea
	dc.b "and"!128,0,0,0
	dc.w $f100,$d100,s67!xdxtoea
	dc.b "add"!128,0,0,0

	dc.w $ffc0,$0800,stab!xinibtoea
	dc.b "btst"!128,0,0
	dc.w $ffc0,$0840,stab!xinibtoea
	dc.b "bchg"!128,0,0
	dc.w $ffc0,$0880,stab!xinibtoea
	dc.b "bclr"!128,0,0
	dc.w $ffc0,$08c0,stab!xinibtoea
	dc.b "bset"!128,0,0

	dc.w $f100,$5000,s67!xsize67i9btoea
	dc.b "addq"!128,0,0
	dc.w $f100,$5100,s67!xsize67i9btoea
	dc.b "subq"!128,0,0

	dc.w $f118,$e000,s67!xsize67x9btodx02
	dc.b "asr"!128,0,0,0
	dc.w $f118,$e008,s67!xsize67x9btodx02
	dc.b "lsr"!128,0,0,0
	dc.w $f118,$e010,s67!xsize67x9btodx02
	dc.b "roxr"!128,0,0
	dc.w $f118,$e018,s67!xsize67x9btodx02
	dc.b "ror"!128,0,0,0
	dc.w $f118,$e100,s67!xsize67x9btodx02
	dc.b "asl"!128,0,0,0
	dc.w $f118,$e108,s67!xsize67x9btodx02
	dc.b "lsl"!128,0,0,0
	dc.w $f118,$e110,s67!xsize67x9btodx02
	dc.b "roxl"!128,0,0
	dc.w $f118,$e118,s67!xsize67x9btodx02
	dc.b "rol"!128,0,0,0

	dc.w $ff00,$0000,s67!xsize67ixtoea
	dc.b "ori"!128,0,0,0
	dc.w $ff00,$0200,s67!xsize67ixtoea
	dc.b "andi"!128,0,0
	dc.w $ff00,$0400,s67!xsize67ixtoea
	dc.b "subi"!128,0,0
	dc.w $ff00,$0600,s67!xsize67ixtoea
	dc.b "addi"!128,0,0
	dc.w $ff00,$0a00,s67!xsize67ixtoea
	dc.b "eori"!128,0,0
	dc.w $ff00,$0c00,s67!xsize67ixtoea
	dc.b "cmpi"!128,0,0

	dc.w $f1c0,$0100,stab!xdxtoea
	dc.b "btst"!128,0,0
	dc.w $f1c0,$0140,stab!xdxtoea
	dc.b "bchg"!128,0,0
	dc.w $f1c0,$0180,stab!xdxtoea
	dc.b "bclr"!128,0,0
	dc.w $f1c0,$01c0,stab!xdxtoea
	dc.b "bset"!128,0,0

	dc.w $ff00,$4000,s67!xsrcea
	dc.b "negx"!128,0,0
	dc.w $ff00,$4200,s67!xsrcea
	dc.b "clr"!128,0,0,0
	dc.w $ff00,$4400,s67!xsrcea
	dc.b "neg"!128,0,0,0
	dc.w $ff00,$4600,s67!xsrcea
	dc.b "not"!128,0,0,0
	dc.w $ff00,$4a00,s67!xsrcea
	dc.b "tst"!128,0,0,0

	dc.w $c000,$0000,snop!ximove
	dc.b "move."!128,0

	dc.w $f000,$a000,stab!xdcwop
	dc.b "line-a"!128
	dc.w $f000,$f000,stab!xdcwop
	dc.b "line-f"!128
	dc.w $0000,$0000,stab!xdcwop
	dc.b "dc.w"!128,0,0,0
even
	;temp
gfxname:dc.b "graphics.library",0
even

	;chips
scradr:	dc.l 0
dskadr:	dc.l 0
spradr:	dc.l 0
copadr:	dc.l 0

	;mod
regs:	blk.l 16+2+1+1,0	;regs/ssp/usp/pc/sr.w
startssp:dc.l 0			;prgstart
startusp:dc.l 0			;prgstart
startsr:dc.w 0			;prgstart
rdff002:dc.w 0			;prgstart union
rdff010:dc.w 0			;prgstart   "
rdff01c:dc.w 0			;prgstart   "
rdff01e:dc.w 0			;prgstart   "
lastms:	dc.w 0
mousexy:dc.w 0
msxpos:	dc.w 0
msypos:	dc.w 0
msycnt:	dc.l 0
buflen:	dc.w 0
excinstr:dc.w 0			;except info instr
excadr:	dc.l 0			;except info adr
exceptsr:dc.w 0			;except info sr
exceptpc:dc.l 0			;except info pc
excnum:	dc.b 0			;0=no exc
imsize:	dc.b 0			;%00.b,%01.w,%10.l,%11.*
dissign:dc.b 1			;bit0:nosign/sign,bit1:hex/dez
bplflag:dc.b 0			;0:medres,ff:lores
row:	dc.b 0
col:	dc.b 0
drvbit:	dc.b 0			;3:df0
trk:	dc.b 0			;trk 0-159 of sel drv
sec:	dc.b 0			;0-10
truebuf:dc.b 0			;0:reread mfm
dskerr:	dc.b 0			;25:datachk,21:sec not found
				;29:dsk removed,26:timeout
wrflag:	dc.b 0			;0:read,ff:write
wrcmd:	dc.b 0			;blkread/wr cmd
keydel:	dc.b 0
repdel:	dc.b 0
crsrdel:dc.b 1
nocrsr:	dc.b 0
msdel:	dc.b 0
lastkey:dc.b 0
lastcmd:dc.b 0
ascii:	dc.b 0
shflag:	dc.b 0
prtflag:dc.b 0
keybuf:	blk.b 40,0
	;     01234567890123456789
fkeybuf:dc.b "l 40000 0 1",0,"        "
	dc.b "a 40000",0,"            "
	dc.b "d 40000",0,"            "
	dc.b "L oi 40000",0,"         "
	dc.b "cd:|dir",0,"            "
	blk.b [10-5]*fkeylen,0
even
oplen:	dc.w 0			;0:noop,1.w,2.l,3.wl,4.ll;union!
op68000:dc.w 0,0,0,0,0		;68000 rawopcode+paras
mask55:	dc.l $55555555
maskaa:	dc.l $aaaaaaaa
sync:	dc.w $4489
bitsec:	dc.l 0			;key of bitmap
fheader:dc.l 0			;key of fileHEADER
dirkey:	dc.l 0			;key of subdir/root
prevchain:
	dc.l 0			;key of previous chain (delete)
roothash:
	dc.l 0			;absadr of filehash in root
datanum:dc.w 0			;cnt datablk
secinbuf:
	dc.w 0			;%1:read sec before update
frzflag:dc.w 0			;0:normal start,-1:freeze!
bufadr:	dc.l 0			;adr swapmem
himem:	dc.l 0			;max workspc end
defwork:dc.l 0			;start of screenmem: work1/work2
lineend:dc.l 0			;end of cmdline
para:	blk.l 16,0
zeromem:blk.l 16,0
intraps:blk.l 16+7,0		;$64-$c0

linebuf:blk.b 80,0		;even !
txtscr:	blk.l 80*32/4,0
exctxt:	dc.l exberr,exaerr,exill,exdiv,exchk,extrv,expri,extra,exlna
	dc.l exlnf,extrp
initxt:	dc.b " BeerMon V 0.28 CPU: 680x0, xxxx Agnus,"	;even!
initmod:dc.b "xxxxxxxxxx mode"
	dc.b ", necromantic version"!$80
exberr:	dc.b "BUS ERROR"!$80
exaerr:	dc.b "ADDRESS ERROR: INSTRUCTION $     ACCESSED $"!$80
exill:	dc.b "ILLEGAL INSTRUCTION"!$80
exdiv:	dc.b "DIVISION BY ZERO"!$80
exchk:	dc.b "CHK INSTRUCTION"!$80
extrv:	dc.b "TRAPV INSTRUCTION"!$80
expri:	dc.b "PRIVILEGE VIOLATION"!$80
extra:	dc.b "TRACE MODE"!$80
exlna:	dc.b "LINE-A EMULATION"!$80
exlnf:	dc.b "LINE-F EMULATION"!$80
extrp:	dc.b "TRAP INSTRUCTION"!$80

even
ccodetxt:	dc.b "t f hilscccsneeqvcvsplmigeltgtle"	;even!
usptxt:		dc.b "usp"!$80
toccrtxt:	dc.b ",ccr"!$80
tosrtxt:	dc.b ","
srtxt:		dc.b "sr"!$80
xbcdtxt:	dc.b "),-("!$80
cmpmtxt:	dc.b ")+,("!$80
sizetxt:	dc.b "bwl*"
sizemov:	dc.b "*blw",%11,%00,%10,%01

trktxt:	dc.b ": track "!$80
hedtxt:	dc.b " head "!$80
sectxt:	dc.b " sector "!$80
errtxt:	dc.b " error "!$80
blktxt:	dc.b " block "!$80
drvtxt:	dc.b " Disk in drive DFx: is "!$80
nodisk:	dc.b "not present"!$80
ndostxt:dc.b "not a dos disk"!$80
dskvtxt:dc.b "not validated"!$80
chktxt:	dc.b "without correct checksum"!$80
wrdisk:	dc.b "writeprotected"!$80
logtxt:	dc.b "logged"!$80
mnttxt:	dc.b "not mounted"!$80
inttxt:	dc.b " INT 1-7"!$80
trptxt:	dc.b " TRAP #0-15"!$80
bpltxt:	dc.b "Bitplane: "!$80
worktxt:dc.b "Workspace "!$80
progtxt:dc.b "  Program "!$80
buftxt:	dc.b "  Backupmem "!$80
svnotxt:dc.b "not available"!$80
filltxt:dc.b " filled with "!$80
eortxt:	dc.b " exored with "!$80
objtxt:	dc.b "object created: "!$80
chktxt1:dc.b "old chksum: "!$80
chktxt2:dc.b " new chksum: "!$80
maptxt:	dc.b "Bitmapblock: "!$80
synctxt:dc.b "Sync: "!$80
voltxt:	dc.b "Volume: ",34!$80
dirtxt:	dc.b "(Dir)"!$80
usdtxt:	dc.b " used blocks, "!$80
fretxt:	dc.b " free blocks"!$80
savetxt:dc.b "saving: ",34!$80
loadtxt:dc.b "loading: ",34!$80
rerrtxt:dc.b "read error"!$80
werrtxt:dc.b "write error"!$80
bittxt:	dc.b "bad bitmap"!$80
dskftxt:dc.b "disk full"!$80
dnmtxt:	dc.b "directory not empty"!$80
dextxt:	dc.b "directory exists"!$80
diftxt:	dc.b "directory is a file"!$80
dnftxt:	dc.b "directory not found"!$80
fextxt:	dc.b "file exists"!$80
fidtxt:	dc.b "file is a directory"!$80
fnftxt:	dc.b "file not found"!$80
calctxt:dc.b "Overflow"!$80
prttxt:	dc.b "Printer on"!$80
sndtxt:	dc.b "Soundaddress "!$80
muttxt:	dc.b "mutilating"!$80
frztxt:	dc.b "deep frost"!$80		;one of the celtic ones?
months:	dc.b "JanFebMarAprMayJunJulAugSepOctNovDec"
gortxt:	dc.b "Being massacred, mutilated and hacked to death, "
	dc.b "that's what we all like..."
even	; yo that's true
keytab:	dc.b "`1234567890ß'\",0,"0"	;keycodes increase...
	dc.b "qwertzuiopü+",0,"123"	;all this is patched...
	dc.b "asdfghjklöä#",0,"456"
	dc.b "<yxcvbnm,.-",0,".789"
	dc.b " ",8,5,13,13,$1b,9,0,0,0,"-",0,$10,$11,$13,$12
	dc.b $80,$81,$82,$83,$84,$85,$86,$87,$88,$89,"[]/*+",0

	dc.b "~!",34,"§$%&/()=?`|",0,"0"	;$60...
	dc.b "QWERTZUIOPÜ*",0,"123"
	dc.b "ASDFGHJKLÖÄ^",0,"456"
	dc.b ">YXCVBNM;:_",0,".789"
	dc.b " ",7,0,0,14,0,10,0,0,0,"-",0,1,2,4,3
	dc.b 0,0,0,0,0,0,0,0,0,0,"{}/*+",0
even
coplst:	dc.w $e0,0,$e2,0,$8e,$2c81,$90,$2cc1
cop92:	dc.w $92,$3c
cop94:	dc.w $94,$d4
cop100:	dc.w $100,$9200,$102,0,$108,0
bgcol:	dc.w $180,$ccc
fgcol:	dc.w $182,$444,$1a2,$f00,$1a4,0,$1a6,$0f0
	dc.w $ffff,$fffe
mousespr:
dc.w $8080,$9200
dc.l $00000000,$00000000,$00000000,$000001c0,$008001c0,$00800140 
dc.l $00800140,$00800140,$00800140,$00800140,$00800140,$00800770 
dc.l $03e00410,$00800770,$00800140,$000001c0,$00000000,$00000000 
font:	;thanx for the font must go to the terminator (you rule)
dc.l $00186c66,$18c33818,$0c300000,$00000003 
dc.l $3c183c7e,$1c7e0c7e,$3c3c0000,$0c00303c,$3e3c7c3c,$783e3e3c 
dc.l $66180666,$6063663c,$7c3c7c3c,$7e666663,$63667e3c,$c03c1000 
dc.l $18006000,$06001c00,$60181860,$30000000,$00000000,$00000000 
dc.l $0000000e,$187072cc
dc.l $00180c1c,$42c3183c 
dc.l $667e7800,$7e007e7e,$3c18f0f0,$18007e00,$00307000,$4060c018 
dc.l $300c1832,$663c7f3c,$300c1866,$300c1866,$7832300c,$18326600 
dc.l $3d300c18,$cc06607c,$300c1832,$663c0000,$180c0c36,$300c1866 
dc.l $3032300c,$18326600,$00300c18,$000c3066
dc.l $00186c66,$3ec66c18,$18186618,$00000006,$66386606 
dc.l $3c601806,$66661800,$18001866,$63666666,$6c606066,$66180666 
dc.l $60777666,$66666666,$18666663,$63660630,$600c3800,$18006000 
dc.l $06003000,$60000060,$30000000,$00000000,$00000000,$00000018 
dc.l $18189c33
dc.l $00003e36,$3c661840,$0081d833 
dc.l $06008100,$66181818,$3000f400,$007088cc,$c6e62300,$0810244c 
dc.l $3c66cc66,$08102400,$08102400,$6c4c0810,$244c3c00,$66081024 
dc.l $00086066,$0810244c,$00660000,$04101200,$08102400,$7c4c0810 
dc.l $244c0018,$01081024,$66103000
dc.l $001800ff,$600c6830,$300c3c18,$0000000c,$6e18060c,$6c7c3006 
dc.l $66661818,$307e0c06,$6f666660,$66606060,$6618066c,$607f7e66 
dc.l $66666660,$18666663,$36660c30,$300c6c00,$0c3c7c3c,$3e3e3c3e 
dc.l $66181866,$3063663c,$7c3e7c3e,$7e666663,$63667e18,$181800cc 
dc.l $00186c30,$663c183c,$00bdd866,$007ebd00 
dc.l $3c7e3030,$00c6f400,$00308866,$4c6c6618,$3c3c3c3c,$663ccc60 
dc.l $3e3e3e3e,$18181818,$66763c3c,$3c3c6663,$6e666666,$cc667c66 
dc.l $00000000,$3c3c7f3c,$1e1e1e1e,$00000000,$18000000,$00003c00 
dc.l $3e000000,$00003c66
dc.l $00180066 
dc.l $3c187600,$300cff7e,$007e0018,$7e180c1c,$cc067c0c,$3c3e0018 
dc.l $6000060c,$6f7e7c60,$667c7c6e,$7e180678,$606b6e66,$7c667c3c 
dc.l $1866666b,$1c3c1830,$180cc600,$00666666,$66603066,$6618186c 
dc.l $30777666,$66666660,$1866666b,$36660c70,$080e0033
dc.l $00186c78,$3c180066,$00b17ccc,$007ea500,$00186018 
dc.l $00c67418,$00307033,$58782c30,$66666666,$6666ff60,$60606060 
dc.l $18181818,$f67e6666,$66666636,$7e666666,$cc66666c,$3c3c3c3c 
dc.l $663ccc66,$30303030,$18181818,$3c763c3c,$3c3c667e,$67666666 
dc.l $66663666
dc.l $001800ff,$0630dc00 
dc.l $300c3c18,$00000030,$76181806,$fe066618,$660c0000,$30000c18 
dc.l $6f666660,$66606066,$6618066c,$60636666,$60667806,$18666c7f 
dc.l $36183030,$0c0c0000,$007e6660,$667e3066,$7e181878,$307f7e66 
dc.l $66667c3c,$18666c6b,$1c661818,$181800cc
dc.l $00183e30,$423c183c,$00bd0066,$0000b900,$0018f8f0,$00c61418 
dc.l $00300066,$323fd960,$7e7e7e7e,$7e7ecc66,$7c7c7c7c,$18181818 
dc.l $666e6666,$6666661c,$76666666,$cc3c6666,$66666666,$7e66ff60 
dc.l $3e3e3e3e,$18181818,$667e6666,$66666600,$6b666666,$66663666 
dc.l $00000066,$7c63cc00,$18186618 
dc.l $18001860,$66183066,$0c666618,$66181818,$187e1800,$60666666 
dc.l $6c606066,$66186666,$60636666,$606e6c66,$18667877,$63186030 
dc.l $060c0000,$00666666,$6660303e,$6618186c,$306b6e66,$7c3e6c06 
dc.l $18667836,$363e3018,$18180033
dc.l $00180c30 
dc.l $00181802,$0081fc33,$0000ad00,$00000000,$00ee1400,$0000f8cc 
dc.l $666b3366,$66666666,$6666cc3c,$60606060,$18181818,$6c666666 
dc.l $66666636,$66666666,$cc187c66,$7e7e7e7e,$667ecc66,$30303030 
dc.l $18181818,$666e6666,$66666618,$73666666,$663e3c3e
dc.l $00180066,$18c37600,$0c300000,$180018c0 
dc.l $3c187e3c,$0c3c3c18,$3c301818,$0c003018,$3e667c3c,$783e603e 
dc.l $66183c66,$3e63663c,$603c663c,$183c7063,$63187e3c,$033c00fe 
dc.l $00667c3c,$3e3e3006,$66181866,$1c63663c,$6006667c,$183c7036 
dc.l $63067e0e,$187000cc
dc.l $0018007e,$003c183c 
dc.l $007e0000,$00008100,$007e0000,$00fa1400,$18000000,$cfc6673c 
dc.l $66666666,$6666cf08,$3e3e3e3e,$18181818,$78663c3c,$3c3c3c63 
dc.l $bc3c3c3c,$7818606c,$66666666,$6666cf3c,$1e1e1e1e,$18181818 
dc.l $3c663c3c,$3c3c3c00,$3e3c3c3c,$3c063006
dc.l $00000000,$00000000,$00000000,$30000000,$00000000 
dc.l $00000000,$00000030,$00000000,$00000000,$00000000,$00000000 
dc.l $00000000,$00060000,$00000000,$00000000,$00000000,$00000000 
dc.l $0000003c,$00007000,$00000000,$60060000,$00000000,$003c0000 
dc.l $00000033
dc.l $00000000,$00000000,$00000000 
dc.l $00007e00,$00000000,$00c00000,$30000000,$020f0100,$00000000 
dc.l $00000030,$00000000,$00000000,$00000000,$00000000,$00000000 
dc.l $00006060,$00000000,$00000010,$00000000,$00000000,$00000000 
dc.l $00000000,$40000000,$003c303c
endprg:	;don't DATA this, because one segment is better
dostrkbuf:blk.b 512*11,0
rootblk:blk.b 512,0
header:	blk.b 512,0
bitmap:	blk.b 512,0
enddat:
stacksize=$10000-[enddat-run]-worksize-2	;magic
stack:	blk.b stacksize,0
stackend:

