1 ;; Show "6502" on the screen waving up and down.
2 ;; Jeremy English 29-December-2007
4 ;; Each digit is stored as a pattern of vertical bits.
7 ;; 111111 This is the digit six. We think of the digit
8 ;; 111111 by it's column pattern. The column patterns
9 ;; 110000 are labeled at the bottom of the example.
10 ;; 110000 Pattern B is 1100110011. The basic algorithm
11 ;; 111111 is that we get the pattern, paint the first
12 ;; 111111 bit (1 foreground, 0 background) then dec y
13 ;; 110011 and get the next bit.
15 ;; 111111 The pattern for each digit is:
21 ;; Addresses $0 and $1 are used by the paint subroutine.
22 ;; Addresses $2 through $6 are used by the display pattern subroutine
23 ;; Address $7 is used in the main loop
24 ;; Address $8 through $1a are used for the start positions
25 ;; Address $1b is used by the display pattern subroutine
26 ;; Address $1c is used as the color row offset.
27 ;; Addresses $d0 through $ef store the font table
32 ;; Initialize the pointers to the start position.
67 lda #0 ; start position to use
71 inc $1c ; increment the color offset.
72 inc $1d ; increment the starting x position
73 ldy $8 ; load the current start position index
74 ldx $b,y ; get the lsb from the table
76 sta $9 ; store the msb of the start position pointer
77 iny ; move to the next position in the table
78 ldx $b,y ; get the msb from the table
80 sta $a ; store the lsb of the start position pointer
81 iny ; move the index up by one
83 cmp #$10 ; have we looked at all 16 start positions?
84 bne store_idx ; if not then keep the index and store it
85 lda #0 ; set the index back to zero
87 sta $8 ; save the index back in memory
91 sta $4 ; initialize the column to FF
93 inc $4 ; increment the column
94 ldx $d0,y ; load the lsb from the font table
97 ldx $d0,y ; load the msb from the font table
99 sty $7 ; save y in memory
100 jsr dis_pat ; Jump to the display pattern subroutine.
101 inc $4 ; increment the column
102 jsr dis_pat ; Each pattern gets painted twice so we have a thicker font
103 ldy $7 ; get y out of memory
104 iny ; increment the index
106 cmp #$20 ; Did we display all of the columns?
107 bne display_loop ;if not continue
112 ;;Setup a table in the zero page that contains the string "6502"
113 lda #<pattern_a ;start with digit 6. It's pattern is aabbcc
125 lda #<pattern_null ;We want to space everything out with blanks
129 lda #<pattern_d ;load memory for digit 5 ddbbcc
145 lda #<pattern_a ;load memory for digit 0 aaeeaa
161 lda #<pattern_c ;load memory for digit 2 ccbbdd
180 ;; Display a pattern on the screen. The pattern to use is
181 ;; stored at $2 and $3. The current column is stored at $4.
183 ldy $4 ; Load the current column into y
184 lda ($9),y ; Get the start position for y
186 sty $5 ; Store the starting position in memory
187 ldy #0 ; We have 12 bits that need to be painted
189 lda ($2),y ; get a bit from the pattern
190 pha ; save the color on the stack
191 tya ; move the index into the accumulator
192 clc ; clear the carry
193 adc $5 ; add the starting position to the index
194 sty $6 ; store the index
195 tay ; The calculated y position
196 ldx $4 ; The x position is the current column
197 pla ; pop the color off of the stack
198 beq go_paint ; black just paint it
199 clc ; get rid of any carry bit
200 sty $1b ; save the y coordinate
203 adc $1c ; add the color offset
204 and #$7 ; make sure the look up is in range
205 tay ; move the new index into y so we can look up the color
206 lda color_row,y ; if not black get the row color
207 ldy $1b ; restore the y coordinate
209 jsr paint ; paint the pixel on the screen
210 ldy $6 ; get the index out of memory
211 iny ; increment the index
213 cmp #12 ; Have we looked at all of the bits?
214 bne dis_pat_loop ; if not then continue looking
215 rts ; else return from the subroutine
217 ;; Paint - Put a pixel on the screen by using the x registry for
218 ;; the x position, the y registry for the y position and
219 ;; the accumulator for the color.
222 lda yl,y ; Get the LSB of the memory address for y
223 sta $0 ; Store it first
224 lda yh,y ; Get the MSB of the memory address for y
225 sta $1 ; Store it next
226 txa ; We want x in the y registry so we transfer it to A
227 tay ; and then A into y.
228 pla ; Pop the color off of the stack
229 sta ($0),y ; Store the color at the correct y + x address.
230 rts ; return from the subroutine.
232 ;; Paint uses the following two tables to look up the
233 ;; correct address for a y coordinate between
238 dcb $02, $02, $02, $02, $02, $02, $02, $02
239 dcb $03, $03, $03, $03, $03, $03, $03, $03
240 dcb $04, $04, $04, $04, $04, $04, $04, $04
241 dcb $05, $05, $05, $05, $05, $05, $05, $05
244 dcb $00, $20, $40, $60, $80, $a0, $c0, $e0
245 dcb $00, $20, $40, $60, $80, $a0, $c0, $e0
246 dcb $00, $20, $40, $60, $80, $a0, $c0, $e0
247 dcb $00, $20, $40, $60, $80, $a0, $c0, $e0
249 ;; A zero is on the end of each pattern to clean up
250 ;; residue left by waving.
252 dcb 0,1,1,1,1,1,1,1,1,1,1,0
255 dcb 0,1,1,0,0,1,1,0,0,1,1,0
258 dcb 0,1,1,0,0,1,1,1,1,1,1,0
261 dcb 0,1,1,1,1,1,1,0,0,1,1,0
264 dcb 0,1,1,0,0,0,0,0,0,1,1,0
267 dcb 0,0,0,0,0,0,0,0,0,0,0,0
269 ;; Table that store the current start position
272 dcb 10,10,9,9,8,8,7,7,6,6,7,7,8,8,9,9,10,10,9,9,8,8,7,7
276 dcb 9,9,8,8,8,8,8,8,7,7,8,8,8,8,8,8,9,9,8,8,8,8,8,8
280 dcb 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8
284 dcb 7,7,8,8,8,8,8,8,9,9,8,8,8,8,8,8,7,7,8,8,8,8,8,8
288 dcb 6, 6,7,7,8,8,9,9,10,10,9,9,8,8,7,7, 6, 6,7,7,8,8,9,9
292 dcb $7,$8,$9,$2,$4,$6,$e,$3,$d,$5