Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request, ca65] Add ".if" directives for register sizes #2432

Open
ProxyPlayerHD opened this issue Mar 8, 2024 · 4 comments
Open

Comments

@ProxyPlayerHD
Copy link

similar to .ifp02, .ifpC02, and .ifp816 it would just take the register size directives and add an "if" at the front. so .ifa8 and .ifa16 for the accumulator, and .ifi8 and .ifi16 for the index registers.

this would be very useful for creating univeral macros by evaluating to either true or false depending on the current size of the registers at assemble time.

for example:

; Moves a given 32-bit word from "src" to "dst"
; Works with both 8 or 16-bit Accumulator
.macro MOV32	dst, src
	.ifa16		; 16-bit Accumulator
		.if (.match(.right(1, {src}), #))
			LDA # .LOWORD(src)
			STA dst
			LDA # .HIWORD(src)
			STA dst + 2
		.else
			LDA src
			STA dst
			LDA src + 2
			STA dst + 2
		.endif
	.else		; 8-bit Accumulator
		.if (.match(.right(1, {src}), #))
			LDA # <.LOWORD(src)
			STA dst
			LDA # >.LOWORD(src)
			STA dst + 1
			LDA # <.HIWORD(src)
			STA dst + 2
			LDA # >.HIWORD(src)
			STA dst + 3
		.else
			LDA src
			STA dst
			LDA src + 1
			STA dst + 1
			LDA src + 2
			STA dst + 2
			LDA src + 3
			STA dst + 3
		.endif
	.endif
.endmacro

use example:

.A16
MOV32 $1000, $2000

assembles to:
	LDA $1000
	STA $2000
	LDA $1002
	STA $2002

.A8
MOV32 $1000, $2000

assembles to:
	LDA $1000
	STA $2000
	LDA $1001
	STA $2001
	LDA $1002
	STA $2002
	LDA $1003
	STA $2003
@ProxyPlayerHD
Copy link
Author

oops, i didn't know .asize and .isize existed. so technically this is already solved i guess...

but i still think adding register size specific .if directives is a good idea since CPU types also have their own .if directives despite .cpu existing (probably to make it simplier to type and read), so i don't see why the register sizes couldn't get the same treatment.

@mrdudz
Copy link
Contributor

mrdudz commented Mar 9, 2024

I don't like the idea of adding extra directives for something that already exists

@ProxyPlayerHD
Copy link
Author

ProxyPlayerHD commented Mar 9, 2024

i mean that's fair but then i'm confused why the .ifp** directives exist if they are the same as .if .cpu & CPU_ISET_**.

@mrdudz
Copy link
Contributor

mrdudz commented Mar 9, 2024

I don't know, those exist for a long long time - and its always hard to remove something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants