cpu 6502
nam Plot
page 128,128
	
* = $0900  ; assemble at $900
code
	
	lda #$01		;white
	sta color		; for character colors
	lda #$05		;green
	sta $D020
	lda #$00		;black
	sta $D021
	
	;; clear screen
	lda #$20
	
	ldy #$18

.nxtcol	ldx #$27
.nxtrow	jsr .plot
	dex
	cpx #$FF
	bne .nxtrow
	dey
	cpy #$FF
	bne .nxtcol

	ldx #$00
	stx _i
.hop	ldy hoop, x
	sty _x
	inx
	ldy hoop, x
	sty _y
	inx
	ldy hoop, x
	sty _a
	inx
	
	ldy _x
	
	cpy #$FF
	beq .done
	stx _i
	ldx _x
	ldy _y
	lda _a
	jsr .plot
	ldx _i
	jmp .hop

.done	rts
	_i db $00
	_x db $00
	_y db $00
	_a db $00
	
	hoop db $1C, $04, $4F, $1D, $04, $77, $1E, $04, $77, $1F, $04, $77, $20, $04, $50
	     db $1C, $05, $74, $20, $05, $6A, $1C, $06, $74, $20, $06, $6A, $1C, $07, $74
	     db $20, $07, $6A, $1C, $08, $74, $20, $08, $6A, $1C, $09, $4C, $1D, $09, $64
	     db $1E, $09, $64, $1F, $09, $64, $20, $09, $7A, $1E, $0A, $5D, $1E, $0B, $5D
	     db $1E, $0C, $5D, $1E, $0D, $5D, $1E, $0D, $5D, $1E, $0E, $5D, $1E, $0F, $5D
	     db $1E, $10, $5D, $1E, $11, $5D, $FF
	
	;; ===================================================
	;; .plot : plot a character somewhere in screen memory
	;;         given the column (col), row, and ascii (chr)
	;;
	
.plot	sta plota
	sta olda
	stx plotc
	stx oldx
	sty oldy
	
	tya
	;; col=x  row=y   chr=a
	cpy #$18
	bcs .twentyfour
	cpy #$12
	bcs .eighteen
	cpy #$0C
	bcs .twelve
	cpy #$06
	bcs .six
	cpy #$00
	bcs .br_zero
	
._plot	lda olda
	ldy oldy
	ldx oldx
	rts
	
.twentyfour ldx plotc
	lda plota
	sta $07C0,x
	lda color
	sta $DBC0,x
	jmp ._plot
	rts
	
.eighteen sbc #$12		;subtract 18 from the row
	tax			;add row * 40
.loop18 cpx #$00
	beq .lop18o
	adc #$26
	dex
	jmp .loop18

.lop18o	adc plotc
	tax
	lda plota
	sta $06CF,x
	lda color
	sta $DACF,x
	jmp ._plot	
	rts

.twelve sbc #$0C		;subtract 12 from the row
	tax
.loop12 cpx #$00
	beq .lop12o
	adc #$26
	dex
	jmp .loop12

.br_zero jmp .zero
	
.lop12o	adc plotc
	tax
	lda plota
	sta $05DF,x
	lda color
	sta $D9DF,x
	jmp ._plot
	rts

.six    sbc #$06		;subtract 6 from the row
	tax
.loop6	cpx #$00
	beq .lop6o
	adc #$26
	dex
	jmp .loop6
	
.lop6o	adc plotc
	tax
	lda plota
	sta $04EF,x
	lda color
	sta $D8EF,x
	jmp ._plot
	rts

.zero	tax
.loop0	cpx #$00
	beq .lop0o
	adc #$26
	dex
	jmp .loop0
	
.lop0o	adc plotc
	tax
	lda plota
	sta $03FF,x
	lda color
	sta $D7FF,x
	jmp ._plot
	rts

	;; =====================================
	;; 
	;;     .muladd
	;; 
	;; MULTIPLY A BY 40
	;; 
	;; mltplcnd = the number to multiply
	;; result = answer
	
.muladd	clc			; clear the carry flag
	clv			; clear the overflow flag
	;; 
	lda mltplcnd		; load the number to mult from mem

	;; multiply by 32 decimal
	ldx #$05
.mltlp1 asl			; multiply by 2

	bcs .cry		; jump on carry
	dex			; decrement index

	cpx #$00		; compare the index against #$00
	bne .mltlp1		; if not equal, repeat the loop
	
	
	;; add the number 8 times to it
	ldx #$08		; set index for 8
.multlp clc
	clv
	adc mltplcnd
	bvs .cry		; jump out on overflow
	dex
	cpx #$00
	bne .multlp
.cry	sta result
	rts			; then return
	
	;; DATA
	
	plotc	db $00			;column
	plota	db $00			;character
	
	oldx	db $00
	oldy	db $00
	olda	db $00
	
	mltplcnd db $00
	result   db $00
	color	 db $00
	         db $DE, $AD

code