floobydust wrote:
Well, here's another baker's routine to fill a memory area from $0200 - $05FF with a byte value:
Code:
; fill screen memory from $0200 - $05FF with a byte value
;
LDA #$02 ;Get start page of $02
STA $02 ;Store to high byte pointer
STZ $01 ;Zero low byte pointer ($0200 start)
LDX #$06 ;Get page limit of $06 ($0600)
;
LDA #$00 ;Load A reg with fill byte (or any other value)
;
LOOP
STA ($01) ;Store fill byte to fill area
INC $01 ;Increment low byte pointer
BNE LOOP ;Loop back until rollover to zero
INC $02 ;Increment high byte pointer
CPX $02 ;Compare against page limit of $06
BNE LOOP ;Loop back back and start next page fill
RTS ;Return to caller
;
23 bytes in all with an RTS, else 22 bytes without it, assuming inline code with something else. Note CMOS processor required.
The more and more I see of the 65C02, the more I realize that I don't think there's much point in using the NMOS unless you really like using illegal opcodes. I would give my right arm to be about to set an address to 0 with a single opcode and being able to use indirect addressing for anything other than JMP opcodes lol
Its all so nice.
BigEd wrote:
Nice one EvilSandwich. Be sure to initialise Y!
I think there might be another notch of improvement available. As you are counting up, and filling whole pages, INY can probably be part of an inner loop.
You may well then also find that you can BNE or BEQ (as appropriate) without needing to compare against a constant: the Z flag will already be what you want, in the inner loop.
I took your advice and got it all the way down to 26 bytes:
Code:
LDA #$01
LDX #$01
LDY #$00
STX $02
STY $01
count:
INC $02
LDX $02
CPX #$06
BNE main
BRK
main:
STA ($01),y
INY
BNE main
BEQ count
I even shaved a little more off by initializing Y and using the 0 in Y for the indirect addressing AND setting the pointer's low byte at the same time.