aboutsummaryrefslogtreecommitdiff
path: root/render.s
blob: 2faf755a801ebae8e64978ed8a8431425adfe51e (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
95
96
97
98
99
;;; Subroutine: render
;;; Convert 1px per byte array at pixarray to packed 8px/byte at screen.
; pixarray is 170x170. screen is 256x170.
; each screen line is: 43 blank px, 170 graphics px, 43 blank.

; This is slow. It takes around 40 jiffies (0.6 sec). However, it only
; happens once per generate. So not worth optimizing, really.

 screenbyte = FR0
 colcount = FR0+1

; RENDER_PROFILE = 1

render:
.ifdef RENDER_PROFILE
 lda RTCLOK+1
 sta $0600
 lda RTCLOK+2
 sta $0601
.endif

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

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

; 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 (5 bytes in)...
 lda #5
 sta screenbyte
 lda #$10 ; ...plus, mask starts out 0001000, 3 more columns to the right.
 sta pixmask

rpix_loop:
 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
 bcc pmok
 ror pixmask
 inc screenbyte
pmok:

 inc colcount
 lda colcount
 cmp #$aa
 bne rpix_loop

 ; 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_loop ; if not, go render next line.

.ifdef RENDER_PROFILE
 lda RTCLOK+1
 sta $0602
 lda RTCLOK+2
 sta $0603
.endif
 rts