Got any other bright ideas for him (pubby)?tokumaru wrote:That's only one addressing mode though, and offers no speed improvements.
EDIT: This is not to come as any way offensive, Just trying to let others (including me) find other ideas!
Moderator: Moderators
Got any other bright ideas for him (pubby)?tokumaru wrote:That's only one addressing mode though, and offers no speed improvements.
Code: Select all
; add - Add without carry
.macro add Arg1, Arg2
clc
.if .paramcount = 2
adc Arg1, Arg2
.else
adc Arg1
.endif
.endmacro
; sub - subtract without borrow
.macro sub Arg1, Arg2
sec
.if .paramcount = 2
sbc Arg1, Arg2
.else
sbc Arg1
.endif
.endmacro
There's nothing that can be done about speed, which's why I prefer to not use a macro like this and instead optimize the CLC/SEC out whenever the logic allows (for example, in multiplication and division routines you usually know the state of the carry before adding or subtracting).Hamtaro126 wrote:Got any other bright ideas for him (pubby)?
Yeah, AFAIK only ca65 is flexible enough to handle multiple addressing modes in macros like this.nicklausw wrote:You nailed it as best as it seems possible for other assemblers.
Code: Select all
STZ .macro
lda #0
.proff
;.if type(\1) == bits
.if IsParamDirectAddress(\1)
.pron
sta \1
.proff
.else
.pron
sta (\1)+range(size(\1))
.proff
.endif
.pron
.endm
Code: Select all
myVar .byte ?
myWordVar .word ?
myWordVarHL .dunion HLWord
#STZ myVar = lda #0 sta myVar
#STZ myWordVar = lda #0 sta myWordVar sta myWordVar+1
#STZ myWordVarHL = lda #0 sta myWordVarHL sta myWordVarHL +1
#STZ myWordVarHL.lo = lda #0 sta myWordVarHL.lo
where HLWord is defined as
HLWord .union
.word ?
.struct
lo .byte ?
hi .byte ?
.ends
.endu
Code: Select all
dfont .function f
.proff
i := f
.for n = 0, n < len(f)/8, n = n + 1
r := bits(0)
.for m = 0, m < 8, m = m + 1
r ..= (i[0] == '#') ? %1 : %0
i := i[1:]
.if i == ''
.break
.endif
.next
.pron
.byte r
.proff
.next
.pron
.endf
dfontM .function f
.proff
i := f
.for n = 0, n < len(f)/4, n = n + 1
r := bits(0)
.for m = 0, m < 4, m = m + 1
.if (i[0] == '#')
r ..= %10
.elsif (i[0] == '@')
r ..= %01
.elsif (i[0] == '*')
r ..= %11
.else
r ..= %00
.endif
i := i[1:]
.if i == ''
.break
.endif
.next
.pron
.byte r
.proff
.next
.pron
.endf
Code: Select all
ILIW .macro
.proff
.if \2 == x
.pron
ldy \1.lo,\2
sty \3.lo
ldy \1.hi,\2
sty \3.hi
.proff
.elsif \2 == y
.pron
ldx \1.lo,\2
stx \3.lo
ldx \1.hi,\2
stx \3.hi
.else
.pron
.cerror "invalid index input"
.endif
.endm
Code: Select all
sorted = sort([(60, irq1), (50, irq2)])
lines .byte sorted[:, 0] ; 50, 60
irqs .addr sorted[:, 1] ; irq2, irq1
Curious why you'd chose SEC/ADC#0 over CLC/ADC#1?lidnariq wrote:Because SEC/ADC #0 isn't that much bigger.