;:sys36864
;
; oszilloskop simulator
;
; (c) nss 1.12.1985
;
	;.opt oo
	*= 49152
tmp	= 254
xcoord	= $14
flag	= $97
collo	= $400
colhi	= $800
gralo	= $2000
grahi	= $4000
clrscr	= $e544
ink	= 646
video	= 53248
offx	= 2
offy	= 3
padx	= $d419
pady	= $d41a
saege	= 167
f1	= 4
f3	= 5
key	= 203
endirq	= $ea81
autores	= 168
systemirq	= $ea31
irqvek	= 788
oldx	= 181
oldy	= 182
getx	= 251
gety	= 252
latch	= 52992
autoclr	= 169
joy	= 56321
oldjoy	= 170
;
	jsr init 
	 jsr clear 
	 jsr fillr
	lda #255
	sta 56325
	jsr irqset
end	lda key
	cmp #f1
	bne nof1
	sei 
	 jsr clear 
	 jsr fillr
	cli 
	 jmp end
nof1	cmp #f3
	bne end
	sei
	lda #< systemirq
	ldy #> systemirq
	sta irqvek
	sty irqvek+1
	cli 
	 jmp off
clear	ldy #0
	ldx #> gralo
	sty tmp
	stx tmp+1
	tya
clr	sta (tmp),y
	iny
	bne clr
	inc tmp+1
	dex
	bne clr
	rts
ok	txa
	lsr 
	 lsr 
	 lsr 
	 asl
	tay
	lda mult,y
	sta offy
	lda mult,y
	sta offy
	lda mult+1,y
	sta offy+1
	txa
	and #7
	clc 
	 adc offy
	sta offy
	lda xcoord
	and #%11111000
	sta offx
	lda #<gralo
	clc 
	 adc offy
	sta tmp
	lda #>gralo
	adc offy+1
	sta tmp+1
	lda tmp
	clc 
	 adc offx
	sta tmp
	lda tmp+1
	adc xcoord+1
	sta tmp+1
	lda xcoord
	and #7
	eor #7
	tax
	lda grbit,x
	ldy #0
	bit flag
	bpl setl
	eor #$ff
	and (tmp),y
	.byt $2c
setl	ora (tmp),y
	sta (tmp),y
	rts
mult	= *
	.byt 0,0,$40,1,$80,2,$c0,3
	.byt 0,5,$40,6,$80,7,$c0,8
	.byt 0,10,$40,11,$80,12,$c0,13
	.byt 0,15,$40,16,$80,17,$c0,18
	.byt 0,20,$40,21,$80,22,$c0,23
	.byt 0,25,$40,26,$80,27,$c0,28
	.byt 0,30
grbit	.byt 1,2,4,8,$10,$20,$40,$80
col	ldy #0
	lda #>collo
	sty tmp
	sta tmp+1
	txa
	ldx #>colhi-collo
coll	sta (tmp),y
	iny
	bne coll
	inc tmp+1
	dex
	bne coll
	rts
irqset	sei
	lda #<irqnew
	ldy #>irqnew
	sta irqvek
	sty irqvek+1
	cli
	rts
irqnew	jsr irq 
	 jsr joystick
	jmp systemirq
irq2	bit autores
	bpl noclr
	lda #0
	sta xcoord+1
	lda oldx
	sta xcoord
	ldx oldy
	lda #128
	sta flag
	jsr ok
noclr	lda getx
	sta oldx
	sta xcoord
	lda #0
	sta xcoord+1
	ldx gety
	cpx #200
	bcc yok
	ldx #199
yok	stx oldy
	ldy #0
	sty flag
	jmp ok
irq	lda padx 
	 sec 
	 sbc #1
	sta getx
	lda pady 
	 sec 
	 sbc #1
	sta gety
	bit saege
	bmi on
	jmp irq2
on	ldx #0
loop	stx getx
	lda pady 
	 sec 
	 sbc #1
	sta gety 
	 sta latch,x
	jsr irq2
	ldx getx
	inx
	bne loop
	bit autoclr
	bpl unclr
	ldy #0
loop2	sty getx
	lda latch,y
	tax
	cpx #200
	bcc unt
	ldx #199
unt	lda #0
	sta xcoord+1
	lda #128
	sta flag
	sty xcoord
	jsr ok
	ldy getx
	iny
	bne loop2
unclr	rts
joystick	lda joy
	cmp oldjoy
	beq unclr
	sta oldjoy
	and #16
	bne nofire
	lda saege
	eor #255
	sta saege
nofire	lda oldjoy
	and #4
	bne no1
	lda autores
	eor #255
	sta autores
no1	lda oldjoy
	and #8
	bne unclr
	lda autoclr
	eor #255
	sta autoclr
	rts
fillr	sei 
	 lda #1
	sta xcoord+1
	lda #0 
	 sta flag
	lda #63
	sta xcoord
loopx	lda #199
	sta gety
loopy	ldx gety
	jsr ok
	dec gety 
	 ldx gety 
	 cpx #255
	bne loopy
	dec xcoord
	bpl loopx
	ldx #31
wo	lda words,x
	eor #255
	sta 15192,x
	dex
	bpl wo
	rts
off	lda #21
	sta video+24
	lda #27
	sta video+17
	lda #53
	sta 56325
	lda #0 
	 sta ink
	jmp clrscr
init	lda #59
	sta video+17
	lda #29
	sta video+24
	ldx #1
	jsr col
	lda #1
	sta video+33
	lda #0
	sta video+32
	rts
words	= *
	.byt %00111100
	.byt %01000010
	.byt %10011001
	.byt %10100001
	.byt %10100001
	.byt %10011001
	.byt %01000010
	.byt %00111100
	.byt %01100110
	.byt %01110110
	.byt %01111110
	.byt %01111110
	.byt %01101110
	.byt %01100110
	.byt %01100110
	.byt %00000000
	.byt %00111100
	.byt %01100110
	.byt %01100000
	.byt %00111100
	.byt %00000110
	.byt %01100110
	.byt %00111100
	.byt %00000000
	.byt %00111100
	.byt %01100110
	.byt %01100000
	.byt %00111100
	.byt %00000110
	.byt %01100110
	.byt %00111100
	.byt %00000000
