On Tuesday, October 20, 2015 at 9:22:53 AM UTC-7, fadden wrote:
> On Monday, October 19, 2015 at 7:50:09 PM UTC-7,
jamesiw...@gmail.com wrote:
> > I know this is an old thread, but I just thought I'd post my solution to this problem, in case anyone would like to see it.
>
> Since anything worth doing is worth overdoing...
>
> Discussion:
>
https://github.com/fadden/fdraw/blob/master/docs/manual.md#notes
>
> Screen clear code, written two different ways (size vs. speed):
>
https://github.com/fadden/fdraw/blob/master/FDRAW.S#L271
>
> The hi-res screen is a quirky beast... which is what makes it so much fun to play with.
>
> It's always fun to solve something then see how other people have solved it. Having gone through the process yourself, you appreciate the subtleties in the other solutions. For example: nice job switching the graphics screen on *after* the clear -- looks much better that way.
> Since anything worth doing is worth overdoing...
> Screen clear code, written two different ways (size vs. speed):
>
https://github.com/fadden/fdraw/blob/master/FDRAW.S#L271
> It's always fun to solve something then see how other people have solved it.
I like it! Here's another approach:
*-------------------------------------------------
* Fast, small, right-to-left hires screen clear
* By John Brooks 10/20/2015
* Size: 136 bytes
* Speed: ~5.4 cycles per hires byte. Unrolled 32x.
* >5x faster than ROM HGR
* Inputs: A=color byte for even columns
* Y=color byte for odd columns
*-------------------------------------------------
Clear
sta :_EvenColor+1
sty :_OddColor+1
ldy #3*40-1 ;3x 40-byte rows in a half-page: 128/40=3
:OddColorClc clc ;c=0 on odd columns
:_OddColor lda #$DD ;MOD color for odd columns
:ClearEven
]Offset equ 31*$400
lup 32 ;# of pages in hires screen: 8k/256
sta ]Offset/$2000*$100+]Offset&$1fff+$2000,y
]Offset equ ]Offset-$400
--^
bcs :NextHalfPage
:_EvenColor
lda #$DD ;MOD color for even columns
dey
sec ;c=1 during even columns
bcs :ClearEven ;always
:NextHalfPage
tya
bmi :NextRow
adc #$80+1-1 ;$80=to 2nd half-page. +1 goes back to odd column. -1 due to c=1
tay
bmi :OddColorClc ;always
:NextRow
adc #$80+1-40-1 ;$80=to 1st half-page. +1 goes back to odd column. -40=next row. -1 due to c=1
tay
bpl :OddColorClc ;branch if in same page
adc #3*40-2 ;3*40=# of rows in a half-age. -2 decrements to prev odd/even column
tay
cmp #2*40 ;loop if we're not done with all 40 bytes in all the 3rd row
bcs :OddColorClc
rts
And here's the Merlin32 listing:
+-----------------------+-------------------------------------------------------------------
| Address Object Code | Source Code
+-----------------------+-------------------------------------------------------------------
| 00/8000 | *-------------------------------------------------
| 00/8000 | * Fast, small, right-to-left hires screen clear
| 00/8000 | * By John Brooks 10/20/2015
| 00/8000 | * Size: 136 bytes
| 00/8000 | * Speed: ~5.4 cycles per hires byte. Unrolled 32x.
| 00/8000 | * >5x faster than ROM HGR
| 00/8000 | * Inputs: A=color byte for even columns
| 00/8000 | * Y=color byte for odd columns
| 00/8000 | *-------------------------------------------------
| 00/8000 |
| 00/8000 | org $300
| 00/0300 | Clear
| 00/0300 : 8D 6E 03 | sta __EvenColor+1
| 00/0303 : 8C 0A 03 | sty __OddColor+1
| 00/0306 |
| 00/0306 : A0 77 | ldy #3*40-1 ;3x 40-byte rows in a half-page: 128/40=3
| 00/0308 : 18 | _OddColorClc clc ;c=0 on odd columns
| 00/0309 : A9 DD | __OddColor lda #$DD ;MOD color for odd columns
| 00/030B | _ClearEven
| 00/030B | ]Offset equ 31*$400
| 00/030B : 99 00 3F | sta 31744/$2000*$100+31744&$1fff+$2000,y
| 00/030E : 99 00 3B | sta 30720/$2000*$100+30720&$1fff+$2000,y
| 00/0311 : 99 00 37 | sta 29696/$2000*$100+29696&$1fff+$2000,y
| 00/0314 : 99 00 33 | sta 28672/$2000*$100+28672&$1fff+$2000,y
| 00/0317 : 99 00 2F | sta 27648/$2000*$100+27648&$1fff+$2000,y
| 00/031A : 99 00 2B | sta 26624/$2000*$100+26624&$1fff+$2000,y
| 00/031D : 99 00 27 | sta 25600/$2000*$100+25600&$1fff+$2000,y
| 00/0320 : 99 00 23 | sta 24576/$2000*$100+24576&$1fff+$2000,y
| 00/0323 : 99 00 3E | sta 23552/$2000*$100+23552&$1fff+$2000,y
| 00/0326 : 99 00 3A | sta 22528/$2000*$100+22528&$1fff+$2000,y
| 00/0329 : 99 00 36 | sta 21504/$2000*$100+21504&$1fff+$2000,y
| 00/032C : 99 00 32 | sta 20480/$2000*$100+20480&$1fff+$2000,y
| 00/032F : 99 00 2E | sta 19456/$2000*$100+19456&$1fff+$2000,y
| 00/0332 : 99 00 2A | sta 18432/$2000*$100+18432&$1fff+$2000,y
| 00/0335 : 99 00 26 | sta 17408/$2000*$100+17408&$1fff+$2000,y
| 00/0338 : 99 00 22 | sta 16384/$2000*$100+16384&$1fff+$2000,y
| 00/033B : 99 00 3D | sta 15360/$2000*$100+15360&$1fff+$2000,y
| 00/033E : 99 00 39 | sta 14336/$2000*$100+14336&$1fff+$2000,y
| 00/0341 : 99 00 35 | sta 13312/$2000*$100+13312&$1fff+$2000,y
| 00/0344 : 99 00 31 | sta 12288/$2000*$100+12288&$1fff+$2000,y
| 00/0347 : 99 00 2D | sta 11264/$2000*$100+11264&$1fff+$2000,y
| 00/034A : 99 00 29 | sta 10240/$2000*$100+10240&$1fff+$2000,y
| 00/034D : 99 00 25 | sta 9216/$2000*$100+9216&$1fff+$2000,y
| 00/0350 : 99 00 21 | sta 8192/$2000*$100+8192&$1fff+$2000,y
| 00/0353 : 99 00 3C | sta 7168/$2000*$100+7168&$1fff+$2000,y
| 00/0356 : 99 00 38 | sta 6144/$2000*$100+6144&$1fff+$2000,y
| 00/0359 : 99 00 34 | sta 5120/$2000*$100+5120&$1fff+$2000,y
| 00/035C : 99 00 30 | sta 4096/$2000*$100+4096&$1fff+$2000,y
| 00/035F : 99 00 2C | sta 3072/$2000*$100+3072&$1fff+$2000,y
| 00/0362 : 99 00 28 | sta 2048/$2000*$100+2048&$1fff+$2000,y
| 00/0365 : 99 00 24 | sta 1024/$2000*$100+1024&$1fff+$2000,y
| 00/0368 : 99 00 20 | sta 0/$2000*$100+0&$1fff+$2000,y
| 00/036B |
| 00/036B : B0 06 | bcs _NextHalfPage
| 00/036D | __EvenColor
| 00/036D : A9 DD | lda #$DD ;MOD color for even columns
| 00/036F : 88 | dey
| 00/0370 : 38 | sec ;c=1 during even columns
| 00/0371 : B0 98 | bcs _ClearEven ;always
| 00/0373 | _NextHalfPage
| 00/0373 : 98 | tya
| 00/0374 : 30 05 | bmi _NextRow
| 00/0376 : 69 80 | adc #$80+1-1 ;$80=to 2nd half-page. +1 goes back to odd column. -1 due to c=1
| 00/0378 : A8 | tay
| 00/0379 : 30 8D | bmi _OddColorClc ;always
| 00/037B | _NextRow
| 00/037B : 69 58 | adc #$80+1-40-1 ;$80=to 1st half-page. +1 goes back to odd column. -40=next row. -1 due to c=1
| 00/037D : A8 | tay
| 00/037E : 10 88 | bpl _OddColorClc ;branch if in same page
| 00/0380 : 69 76 | adc #3*40-2 ;3*40=# of rows in a half-age. -2 decrements to prev odd/even column
| 00/0382 : A8 | tay
| 00/0383 : C9 50 | cmp #2*40 ;loop if we're not done with all 40 bytes in all the 3rd row
| 00/0385 : B0 81 | bcs _OddColorClc
| 00/0387 |
| 00/0387 : 60 | rts
+-----------------------+-------------------------------------------------------------------
-JB
@JBrooksBSI