Before I go any further, here's some data and code:
Code:
1st letter loaded into ram:
00 FF 22 C3 52 8D 30 D7 8C 77 44 33 88 07 00 FF
00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF
2nd letter shifted:
00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 01 FE 00 FF
00 FF 02 C3 50 8D 22 99 8C 0B 40 3F 00 7F 00 FF
How it should be:
00 FF 22 C3 52 8D 30 D7 8C 77 44 33 89 06 00 FF
00 FF 02 C3 50 8D 22 99 8C 0B 40 3F 00 7F 00 FF
00 FF 22 C3 52 8D 30 D7 8C 77 44 33 88 07 00 FF
00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF
2nd letter shifted:
00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 01 FE 00 FF
00 FF 02 C3 50 8D 22 99 8C 0B 40 3F 00 7F 00 FF
How it should be:
00 FF 22 C3 52 8D 30 D7 8C 77 44 33 89 06 00 FF
00 FF 02 C3 50 8D 22 99 8C 0B 40 3F 00 7F 00 FF
The 1st letter is combined with the shifted 2nd letter to create the final product. Now for the code that is responsible for doing this:
Code:
combine_buffers:
ldx #$0000
sep #$20
combine_loop:
;if(!vwf_buffer,x or !draw_buffer,x == #$ff)
;take the value of whichever != #$ff and
;store that in the draw_buffer
lda !vwf_buffer,x ;if(!vwf_buffer,x == #$ff)
cmp #$ff ;keep what's already in the draw_buffer
beq inc_and_loop ;i.e. do nothing
lda !draw_buffer,x ;if(!vwf_buffer,x && !draw_buffer,x != #$ff)
cmp #$ff ;combine the two to get the correct value
bne combine_pixels
lda !vwf_buffer,x ;if(!vwf_buffer,x != #$ff && !draw_buffer,x == #$ff)
bra store_pixels ;store value of !vwf_buffer
combine_pixels:
ora !vwf_buffer,x
store_pixels:
sta !draw_buffer,x
inc_and_loop:
inx
cpx #$0020
bne combine_loop
rts
ldx #$0000
sep #$20
combine_loop:
;if(!vwf_buffer,x or !draw_buffer,x == #$ff)
;take the value of whichever != #$ff and
;store that in the draw_buffer
lda !vwf_buffer,x ;if(!vwf_buffer,x == #$ff)
cmp #$ff ;keep what's already in the draw_buffer
beq inc_and_loop ;i.e. do nothing
lda !draw_buffer,x ;if(!vwf_buffer,x && !draw_buffer,x != #$ff)
cmp #$ff ;combine the two to get the correct value
bne combine_pixels
lda !vwf_buffer,x ;if(!vwf_buffer,x != #$ff && !draw_buffer,x == #$ff)
bra store_pixels ;store value of !vwf_buffer
combine_pixels:
ora !vwf_buffer,x
store_pixels:
sta !draw_buffer,x
inc_and_loop:
inx
cpx #$0020
bne combine_loop
rts
That works perfectly except for one little bitty problem. Here's the output of this routine using the 1st and 2nd letters (which I'll reprint, along with what it's supposed to be, for convenience) mentioned above:
Code:
1st letter loaded into ram:
00 FF 22 C3 52 8D 30 D7 8C 77 44 33 88 07 00 FF
00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF
2nd letter shifted:
00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 01 FE 00 FF
00 FF 02 C3 50 8D 22 99 8C 0B 40 3F 00 7F 00 FF
How it should be:
00 FF 22 C3 52 8D 30 D7 8C 77 44 33 89 [b]06[/b] 00 FF
00 FF 02 C3 50 8D 22 99 8C 0B 40 3F 00 7F 00 FF
How it currently is (ORing):
00 FF 22 C3 52 8D 30 D7 8C 77 44 33 89 [b]FF[/b] 00 FF
00 FF 02 C3 50 8D 22 99 8C 0B 40 3F 00 7F 00 FF
00 FF 22 C3 52 8D 30 D7 8C 77 44 33 88 07 00 FF
00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF
2nd letter shifted:
00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 01 FE 00 FF
00 FF 02 C3 50 8D 22 99 8C 0B 40 3F 00 7F 00 FF
How it should be:
00 FF 22 C3 52 8D 30 D7 8C 77 44 33 89 [b]06[/b] 00 FF
00 FF 02 C3 50 8D 22 99 8C 0B 40 3F 00 7F 00 FF
How it currently is (ORing):
00 FF 22 C3 52 8D 30 D7 8C 77 44 33 89 [b]FF[/b] 00 FF
00 FF 02 C3 50 8D 22 99 8C 0B 40 3F 00 7F 00 FF
I've made the problem byte bold. As you can see, it should be $06, but as we all know $07 OR $FE equals $FF. If I change the ora under combine_pixels to an and, that byte is fixed, but everything else is messed up. At the moment, I'm fresh out of things to try. So, anybody got any ideas?
EDIT:
After the first character is loaded into ram (top two tiles are !vwf_buffer, bottom two are !draw_buffer):
After the second character is loaded into ram: