cc65 / cc65

cc65 - a freeware C compiler for 6502 based systems

Home Page:https://cc65.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

ProxyPlayerHD opened this issue · comments

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

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.

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

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_**.

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