aboutsummaryrefslogtreecommitdiff
path: root/render.s
blob: 867003e6e76f0129cc186592cab3c6162017d640 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
;;; Subroutine: render
;;; Convert 1px per byte array at pixarray to packed 8px/byte at screen.
; pixarray is 170x170. screen is 256x170 (TODO: fix display list).
; each screen line is: 43 blank px, 170 graphics px, 43 blank.
 screenbyte = FR0
 colcount = FR0+1

render:
 lda #<screen
 sta screenptr
 lda #>screen
 sta screenptr+1
 lda #<pixarray
 sta pixptr
 lda #>pixarray
 sta pixptr+1

 ldx #0
rline:
 lda #0
 sta colcount
 sta screenbyte

; ; clear 40px on left
; ldy #4
;lclr:
; sta (screenptr),y
; dey
; bpl lclr
;
; ; clear 40px on right
; ldy #$1b
;rclr:
; sta (screenptr),y
; iny
; cpy #$20
; bne rclr

; clear whole line. this is why pixarray is offset from screen by
; one screen line.
 ldy #$1f
rclr:
 sta (screenptr),y
 dey
 bpl rclr

 ; first pixels start at column 40, plus...
 lda #5
 sta screenbyte
 lda #$10 ; ...mask starts out 0001000, 3 more blank px on left
 sta pixmask

rpix:
 ldy colcount ; ranges 0 to 169
 lda (pixptr),y
 beq notset     ; 0 = not set, non-zero = set
 ; if we found a set pixel, set it in the bitmap
 ldy screenbyte
 lda (screenptr),y
 ora pixmask
 sta (screenptr),y
notset:
 ; pixmask >>= 1; if(pixmask == 0) { pixmask = 0x80; screenbyte++; }
 lsr pixmask
 bne pmok
 ;ror pixmask
 lda #$80
 sta pixmask
 inc screenbyte
pmok:
 inc colcount
 lda colcount
 cmp #$aa
 bne rpix
 ; pixptr += 0xaa;
 clc
 adc pixptr
 sta pixptr
 lda pixptr+1
 adc #0
 sta pixptr+1
 ; screenptr += 0x20;
 clc
 lda screenptr
 adc #$20
 sta screenptr
 lda screenptr+1
 adc #0
 sta screenptr+1
 inx
 cpx #$aa ; hit last line yet?
 bne rline ; if not, go render next line.

 rts