I second this. Wanna slap myself around all Sunday for X < 128.
My Favorite Instruction of 2023
Moderator: Moderators
Re: My Favorite Instruction of 2023 / 2024
A man without talent or ambition is most easily pleased. Others set his path and he is content.
https://github.com/SvenMichaelKlose
https://github.com/SvenMichaelKlose
- Mike
- Herr VC
- Posts: 5134
- Joined: Wed Dec 01, 2004 1:57 pm
- Location: Munich, Germany
- Occupation: electrical engineer
Re: My Favorite Instruction of 2023 / 2024
Using (ZP,X) with X<>0 comes around with reserving a larger part of the ZP as data stack and using X as data stack pointer. Especially ($00,X) can be used to work on memory data with a set of pointers contained in said data stack. INC ZP,X and DEC ZP,X are available to conveniently increment or decrement these pointers - $00,X and $01,X address the respective low- and high-byte of the pointers. Other offsets can be used to probe deeper into parameter lists: as indirect-ZP wraps, the "base address" actually works as signed byte offset on the data stack pointer in X!pixel wrote:I second this.
If one dispenses with BASIC as built-in language and only uses KERNAL routines, the addresses $00..$8F are free for that purpose.
A rather benign use of that is found in MINIMON, where I use INC $00,X and INC $01,X to increment two pointers in ZP by the same amount (this is necessary in the T command when copying backwards, then the pointers to source and target block are moved to their respective end). Instead of:
Code: Select all
CLC
LDA src :ADC size :STA src
STA src+1:ADC size+1:STA src+1
CLC
LDA dst :ADC size :STA dst
STA dst+1:ADC size+1:STA dst+1
Code: Select all
[...]
LDX #src:JSR Adjust
LDX #dst:JSR Adjust
[...]
.Adjust
CLC
LDA $00,X
ADC size
STA $00,X
LDA $01,X
ADC size+1
STA $01,X
RTS

Another use in MINIGRAFIK, with X either 0 or 1, lets the current pixel co-ordinates in $FD/$FE run into the direction of the endpoint in $F9/$FA, or stop when both are equal (and signal that condition to the caller in the Z flag):
Code: Select all
.2417 B5 FD LDA $FD,X
.2419 D5 F9 CMP $F9,X
.241B F0 09 BEQ $2426
.241D 08 PHP
.241E B0 03 BCS $2423
.2420 F6 FD INC $FD,X
>2422 2C
.2423 D6 FD DEC $FD,X
.2425 28 PLP
.2426 60 RTS

Re: My Favorite Instruction of 2023 / 2024
https://github.com/SvenMichaelKlose/tun ... src/lib/zp
That's cute. But combine pointers and stacks with indexed indirect X...

A man without talent or ambition is most easily pleased. Others set his path and he is content.
https://github.com/SvenMichaelKlose
https://github.com/SvenMichaelKlose
- Mike
- Herr VC
- Posts: 5134
- Joined: Wed Dec 01, 2004 1:57 pm
- Location: Munich, Germany
- Occupation: electrical engineer
Re: My Favorite Instruction of 2023
One instruction shorter:pixel wrote:Code: Select all
.proc zpw_dec_x dec 0,x lda 0,x cmp #$ff bne :+ dec 1,x : rts .endproc
Code: Select all
.proc zpw_dec_x
lda 0,x
bne :+
dec 1,x
: dec 0,x
rts
.endproc

Re: My Favorite Instruction of 2023
m)Mike wrote: ↑Sun Nov 17, 2024 8:40 am One instruction shorter:Code: Select all
.proc zpw_dec_x lda 0,x bne :+ dec 1,x : dec 0,x rts .endproc
![]()
A man without talent or ambition is most easily pleased. Others set his path and he is content.
https://github.com/SvenMichaelKlose
https://github.com/SvenMichaelKlose