Sjasm - special use of argument in macro

Página 1/2
| 2

Por Metalion

Paragon (1433)

imagem de Metalion

14-07-2021, 18:50

Hi everyone,

I would like to know if it's possible to manipulate a macro argument in Sjasm, in order to "split"' it in different arguments. Let's say I have this macro, which adds 'hl' and 'a'

macro	add16
	add	l	;  5
	jr	nc,$+3	;  8/13
	inc	h	;  5
	ld	l,a	;  5
endmacro

I'd like to be able to test the argument, so that the macro can handle 'bc' and 'de' as well. So far, the only solution I have found is this one :

macro	add16	2
	add	@2	;  5
	jr	nc,$+3	;  8/13
	inc	@1	;  5
	ld	@2,a	;  5
endmacro

But then, in order to use it, I have to write, for example :

	add16	d,e

I would like to pass only 1 argument ('de' in this example), have the macro test it, and then split the argument into 'd' and 'e' where applicable. So I would like to be able to write :

	add16	de

Do you know a solution ?

Entrar ou registrar-se para comentar

Por Grauw

Ascended (10024)

imagem de Grauw

14-07-2021, 18:57

Perhaps the low and high operators work on 16-bit registers as well?

Por Metalion

Paragon (1433)

imagem de Metalion

14-07-2021, 19:01

I don't think so ... those operators are meant to use on numbers, not registers.
But I'll give it a try just for the sake of it.

EDIT: nope, illegal operand

Por Metalion

Paragon (1433)

imagem de Metalion

14-07-2021, 19:08

The problem comes from the fact that Sjasm does not provide any operators on strings.
If there was some, I could use them and split the single argument.

Por santiontanon

Paragon (1469)

imagem de santiontanon

14-07-2021, 21:08

Can you use the usual in-line conditionals (condition ? a:b) in sjasm? if you can, then you can probably define a "text macro" ( http://www.xl2s.tk/sjasmman11.html#s1 ) that returns "h" for "hl", "d" for "de", etc. and similar for the low byte. But it might probably be overkill... what I do in my projects is just to have three macros: "ADD_HL_A", "ADD_DE_A", and "ADD_BC_A".

Por Metalion

Paragon (1433)

imagem de Metalion

14-07-2021, 21:21

No, because any type of text macro involved would require string operators of some kind.
Which are not available in Sjasm.

You're right about overkill, although the example I gave was a very simple one, so that discussing the topic could be easier. I have got more complex macros where a solution to this problem might have helped the clarity of the code.

Por santiontanon

Paragon (1469)

imagem de santiontanon

15-07-2021, 00:28

oh, I see! yeah, then I'm not sure. sjasmplus allows you to add extensions via Lua scripting, so, probably that's more flexible. However, sjasmplus is not fully compatible with sjasm (despite their names), so, not sure if it'll be a problem to switch?

Por jltursan

Prophet (2537)

imagem de jltursan

15-07-2021, 08:25

To allow multiple register combinations in sjasm's macros I usually do the following:

	; Set VDP for write (based on DE or HL)
	macro SETWRT reg
	ifdifi reg,de
		ld a,l
		di
		out (MSX_VDPCW),a
		ld a,h
	else
		ld a,e
		di
		out (MSX_VDPCW),a
		ld a,d
	endif
		or 64
		out (MSX_VDPCW),a
		ei		
	endmacro

Not sure if this is what you need...

Por Metalion

Paragon (1433)

imagem de Metalion

15-07-2021, 09:45

Hi jltursan,
Yes, that's what I use also for most cases.
But I wanted to know if there was another solution.

Por jltursan

Prophet (2537)

imagem de jltursan

15-07-2021, 15:14

I'm afraid that only sjoerd could enlighten us Smile

Por Ped7g

Resident (36)

imagem de Ped7g

04-08-2021, 07:35

santiontanon wrote:

oh, I see! yeah, then I'm not sure. sjasmplus allows you to add extensions via Lua scripting, so, probably that's more flexible. However, sjasmplus is not fully compatible with sjasm (despite their names), so, not sure if it'll be a problem to switch?

The stuff you can do in lua is not that flexible, like adding new operators for regular code, so I'm not sure if it would help in this particular case, except doing like whole macro in lua function, ie. emitting code from there, which has its own biolerplate and syntax cruft costs.

But zoom's sjasmplus supports register pairs as input for `high/low` operators, so you can actually do `add a,low hl` -> `add a,l` and `add a,high hl` -> `add a,h`

Lately I have been reading a bit more through original sjasm documentation, and it seems Sjoerd did extend the syntax in many details very neatly (I especially love how he dealt with extra label functionality like "!" and "@" inside macros) after the sjasmplus was forked out of it, and I'm stealing some of that back into zoom's fork, but the sad fact of life is that some differences are now too deep and clashing against other extensions of sjasmplus, so a chance to sync the syntax of the two completely is zero. But some details could be taken... both ways IMHO. So maybe you can try to suggest to sjasm author to check if he can add that register pair splitting to high/low operators. Smile

Página 1/2
| 2