This little utility will allow you to address an 8000-byte bitmap buffer linearly. That means you can access the bitmap buffer like

0  1  2  3  ... (decimal offsets)
40 41 42 43 ...
80 81 82 83 ...
.. .. .. ..
instead of the ghastly

0  8  16 24 ...
1  9  17 25 ...
2  10 18 26 ...
.. .. .. ..
When you're done drawing to the buffer, call the routine and it will copy from the nice linear layout to the nasty cell layout. Here's the BASIC prototype:

SR,DE = SRC AND DEST LOCATIONS
R=ROW,C=COL,B=BYTE 0-7
10 SR=16192:DE=8192
20 FORR=0TO24:FORC=0TO39:FORB=0TO7
30 POKEDE+R*320+C*8+B,PEEK(SR+R*320+C+B*40)
40 NEXT:NEXT:NEXT

You can see the relationship between two bytes in each buffer from the copy in line 30. Now, this implementation is slow and pretty useless because if you want a linear buffer, it's probably because you want to access the bitmap screen quickly. Enter Assembly. :-) I always do a pseudo-code hybrid between BASIC and Assembly first:

No multiplication whatsoever. We should probably also unroll the inner loop. Heck, we don't even need any tables! Cool...I did this much more complicatedly last time. So let's go on to the final run of assembly.
;Initialize dest and src (and .X for indirect zp accesses)
lda #buf1
sta src+1
lda #buf2
sta dest+1
ldx #$00

;Set up loops
lda #24 ;rows
sta R

loopr:

lda #40 ;cols
sta C

loopc:

;(8 times, unrolled) Copy,src=src+40,inc dest
;We'll use .Y for keeping track of the 8 "inc dest"s.

;1)
ldy #$00
lda (src,x)
sta (dest),y

clc
lda src
adc #40
sta src
bcc *+2
inc src+1

;2)
iny
lda (src,x)
sta (dest),y

clc
lda src
adc #40
sta src
bcc *+2
inc src+1

;3)...
;4)...
;5)...
;6)...
;7)...

;8)
iny
lda (src,x)
sta (dest),y

;src=src-319 (actually src=src-279 because we didn't do the last +40)
sec
lda src
sbc #$17
sta src
lda src+1
sbc #$01
sta src+1

;Reflect all of our "iny"s back into dest
clc
lda dest
adc #$08
sta dest
bcc *+2
inc dest+1

;Loop C down to 0
dec C
bpl loopc

;src=src+320,dest=dest+320
clc
lda src
adc #$40
sta src
lda src+1
adc #$01
sta src+1

lda dest
adc #$40
sta dest
lda dest+1
adc #$01
sta dest+1

;Loop R down to 0
dec R
bpl loopr

rts
Hmm... some more room for optimization remains. Be back later!
All pages were generated with a text editor.
All images (except counter art and host ads) are generated, owned and (c) by me.

Home - Files - Scratchpad
1