There was INX and INY, why no INA?

You can talk about almost anything that you want to on this board.

Moderator: Moderators

User avatar
Hamtaro126
Posts: 818
Joined: Thu Jan 19, 2006 5:08 pm

Re: There was INX and INY, why no INA?

Post by Hamtaro126 »

tokumaru wrote:That's only one addressing mode though, and offers no speed improvements.
Got any other bright ideas for him (pubby)?

EDIT: This is not to come as any way offensive, Just trying to let others (including me) find other ideas!
AKA SmilyMZX/AtariHacker.
User avatar
nicklausw
Posts: 376
Joined: Sat Jan 03, 2015 5:58 pm
Location: ...
Contact:

Re: There was INX and INY, why no INA?

Post by nicklausw »

From ca65's generic macpack:

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
You nailed it as best as it seems possible for other assemblers.
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: There was INX and INY, why no INA?

Post by tokumaru »

Hamtaro126 wrote:Got any other bright ideas for him (pubby)?
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).

As for the addressing modes...
nicklausw wrote:You nailed it as best as it seems possible for other assemblers.
Yeah, AFAIK only ca65 is flexible enough to handle multiple addressing modes in macros like this.
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: There was INX and INY, why no INA?

Post by Oziphantom »

64TASS will let you do a lot of things, you can use default params to set the extra args to known things for example.
I have one that gives me an auto size length for STZ, so if I define a word and STZ the word it will clear both bytes. If I declare an int it will clear all 4 etc

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
so

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
You can also make whole functions like so

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	
these allow me to do things like
.dfont "##_##___"
.dfont "##_##___"
.dfont "#####___"
.dfont "##_##___"
.dfont "##_##___"
and it will convert it to
%11011000
%11011000
%11111000
%11011000
%11011000
The 2nd one lets me specify multicolour graphics

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
lets me specify ,x or ,y on the params list.
You can also get it to do array of structs to struct of arrays conversions for you

Code: Select all

sorted  = sort([(60, irq1), (50, irq2)])
lines   .byte sorted[:, 0] ; 50, 60
irqs    .addr sorted[:, 1] ; irq2, irq1
However if one really wants scripting power KICKASS is the insane one

It has a optimiser that you can enable which will point out most of the things you can skip, so if you want to break the macros out into full code to save a clc or sec or A is already 0 etc it will give you a nice list.
User avatar
Sumez
Posts: 919
Joined: Thu Sep 15, 2016 6:29 am
Location: Denmark (PAL)

Re: There was INX and INY, why no INA?

Post by Sumez »

lidnariq wrote:Because SEC/ADC #0 isn't that much bigger.
Curious why you'd chose SEC/ADC#0 over CLC/ADC#1?
I get that they do the same, but the latter just seems to give a much better visual on what you are actually trying to do.
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: There was INX and INY, why no INA?

Post by lidnariq »

Because "INX" can only add one, and likewise the Carry bit only can add one.

Not saying it's a great reason.
Post Reply