;:sys36864
	;.opt oo
	*= 52000
vic	=$d000
strout	=$ab1e
nmivec	=$318
nmiposs	=$dd0d
endnmi	=$febc
konf	=1
milli	=$eeb3
tmp	=166
grafik	=$a000
bs	=$8400
tmp2	=tmp+2
bank	=$dd00
shift	=$28d
farbram	=$d800
tmp3	=247
tmp4	=249
joy	=56321
reset	=$fffc
	jmp setup
hallo	.byt 13
	.byte "  ; unigrab v1.2"
	.byt 13
	.byte "  ; von nikolaus heusler"
	.byt 13
	.byte "  ;     tel. 089/792940"
	.byt 13
	.byte "  ; (c) nss 240789\x11"
	brk
nmiflag	brk
bmerk	brk
data	brk
font	brk
screen	brk
backgn	brk
expx	brk
expy	brk
snum	brk
x1	.word 0
yy	brk
xx	.word 0
counter	brk
hiba	brk
si	brk
sm	brk
sa	brk
offx	brk
offy	.word 0
gbit	.byt 1,2,4,8,$10,$20,$40,$80
mult	.word $0000,$0140,$0280,$03c0
	.word $0500,$0640,$0780,$08c0
	.word $0a00,$0b40,$0c80,$0dc0
	.word $0f00,$1040,$1180,$12c0
	.word $1400,$1540,$1680,$17c0
	.word $1900,$1a40,$1b80,$1cc0
	.word $1e00
setup	lda #<neunmi
	ldy #>neunmi
	sta nmivec
	sty nmivec+1
	lda #0
	sta nmiflag
	lda #<hallo
	ldy #>hallo
	jmp strout
pause	jsr milli
	dex
	bne pause
	rts
copy	sta tmp+1
	stx tmp2+1
	tya
	tax
	ldy #0
	sty tmp
	sty tmp2
	php
	sei
	lda konf
	pha
	lda #48
	sta konf
cop	lda (tmp),y
	sta (tmp2),y
	dey
	bne cop
	inc tmp+1
	inc tmp2+1
	dex
	bne cop
	pla
	sta konf
	plp
	rts
neunmi	sei
	pha
	txa
	pha
	tya
	pha
	lda nmiflag
	beq cango
	jmp endnmi
cango	inc nmiflag
	lda #$7f
	sta nmiposs
	lda #55
	sta konf
	lda vic+33
	and #$f
	sta backgn
	ldx #15
	jsr pause
	lda shift
	bne start
	ldy #0
	sty tmp
	lda #>grafik
	sta tmp+1
	tya
	ldx #32
clear	sta (tmp),y
	dey
	bne clear
	inc tmp+1
	dex
	bne clear
start	lda bank
	and #3
	eor #3
	asl
	asl
	asl
	asl
	asl
	asl
	sta hiba
	jsr text
	jsr sprites
	ldx #4
	lda #>bs
	sta tmp+1
	lda #1
	ldy #0
	sty tmp
clin	sta (tmp),y
	iny
	bne clin
	inc tmp+1
	dex
	bne clin
	lda #0
	sta vic+21
	lda #1
	sta bank
	lda #59
	sta vic+17
	lda #29
	sta vic+24
	lda #200
	sta vic+22
gky	lda joy
	and #31
	eor #31
	beq gky
	jmp (reset)
lores	lda vic+17
	and #32
	bne graphik
	jmp text
graphik	lda vic+24
	and #8
	asl
	asl
	ora hiba
	ldx #>grafik
	ldy #32
	jsr copy
eot	rts
text	lda bank
	and #3
	eor #3
	sta bmerk
	lda vic+24
	and #14
	asl
	asl
	ldx #48
	cmp #$10
	beq sonder
	cmp #$18
	bne usual
sonder	ldy bmerk
	cpy #1
	beq usual
	cpy #3
	beq usual
	ldx #51
	clc
	adc #$c0
	bne goon
usual	ora hiba
goon	sta font
	lda vic+24
	and #$f0
	lsr
	lsr
	ora hiba
	sta screen
	php
	sei
	lda konf
	pha
	stx konf
	lda #4
	sta counter
	lda #0
	sta tmp3
	sta tmp
	lda screen
	sta tmp3+1
	lda #>grafik
	sta tmp+1
loop0	lda #0
	sta tmp2
	lda font
	sta tmp2+1
	jsr allwtest
	beq nix
	lda (tmp3),y
	tax
	beq loop1
loop2	lda tmp2
	clc
	adc #8
	sta tmp2
	bcc loop4
	inc tmp2+1
loop4	dex
	bne loop2
loop1	ldy #7
loop5	lda (tmp2),y
	sta (tmp),y
	dey
	bpl loop5
nix	lda tmp
	clc
	adc #8
	sta tmp
	bcc loop7
	inc tmp+1
loop7	inc tmp3
	bne loop0
	inc tmp3+1
	dec counter
	bne loop0
	pla
	sta konf
	plp
	rts
allwtest	lda tmp3
	sta tmp4
	lda tmp3+1
	and #3
	ora #>farbram
	sta tmp4+1
	ldy #0
	ldx konf
	lda #55
	sta konf
	lda (tmp4),y
	and #$f
	stx konf
	cmp backgn
	rts
sprites	lda #7
	sta snum
sp0	lda vic+21
	ldx snum
	and gbit,x
	bne sp1
	jmp sp2
tobi	jmp sp2
sp1	lda vic+39,x
	and #$f
	cmp backgn
	beq tobi
	lda vic+23
	and gbit,x
	sta expy
	lda vic+29
	and gbit,x
	sta expx
	lda vic+16
	and gbit,x
	beq t
	lda #1
t	pha
	txa
	asl
	tax
	lda vic,x
	sec
	sbc #24
	sta x1
	pla
	sbc #0
	sta x1+1
	lda vic+1,x
	sec
	sbc #50
	sta yy
	lda vic+24
	and #$f0
	lsr
	lsr
	ora hiba
	clc
	adc #3
	sta tmp4+1
	lda #$f8
	sta tmp4
	ldy snum
	lda (tmp4),y
	ldx #6
	sta tmp3
	lda #0
	sta tmp3+1
mal64	asl tmp3
	rol tmp3+1
	dex
	bne mal64
	lda tmp3+1
	ora hiba
	sta tmp3+1
	lda #0
	sta si
sp3	lda #0
	sta sm
	lda x1
	sta xx
	lda x1+1
	sta xx+1
sp4	php
	sei
	lda konf
	pha
	lda #48
	sta konf
	ldy #0
	lda (tmp3),y
	sta data
	pla
	sta konf
	plp
	lda #7
	sta sa
sp5	lda data
	ldx sa
	and gbit,x
	beq sp6
	jsr qplot
sp6	inc xx
	bne sp6a
	inc xx+1
sp6a	lda expx
	beq sp6aa
	inc xx
	bne sp6aa
	inc xx+1
sp6aa	dec sa
	bpl sp5
	inc tmp3
	bne sp7
	inc tmp3+1
sp7	inc sm
	lda sm
	cmp #3
	bcc sp4
	inc yy
	lda expy
	beq sp7a
	inc yy
sp7a	inc si
	lda si
	cmp #21
	bcc sp3
sp2	dec snum
	bmi eos
	jmp sp0
eos	rts
plot	ldx yy
	cpx #200
	bcs ngut
	lda xx+1
	cmp #1
	bcc okay
	beq test2
ngut	rts
test2	lda xx
	cmp #64
	bcs ngut
okay	txa
	lsr
	lsr
	lsr
	asl
	tay
	lda mult,y
	sta offy
	lda mult+1,y
	sta offy+1
	txa
	and #7
	clc
	adc offy
	sta offy
	lda xx
	and #$f8
	sta offx
	clc
	lda #0
	adc offy
	sta tmp
	lda #>grafik
	adc offy+1
	sta tmp+1
	clc
	lda tmp
	adc offx
	sta tmp
	lda tmp+1
	adc xx+1
	sta tmp+1
	php
	sei
	lda konf
	pha
	lda #48
	sta konf
	lda xx
	and #7
	eor #7
	tax
	lda gbit,x
	ldy #0
	ora (tmp),y
	sta (tmp),y
	pla
	sta konf
	plp
	rts
qqplot	jsr plot
	lda expx
	beq noex
	inc xx
	bne v2
	inc xx+1
v2	jsr plot
	lda xx
	bne v2a
	dec xx+1
v2a	dec xx
noex	rts
qplot	jsr qqplot
	lda expy
	beq noex
	inc yy
	jsr qqplot
	dec yy
	rts
