The latest ZXDB update will be applied this evening at 1800 BST. The update takes around 30 minutes, and the site goes down whilst this happens.

Any way to do this in Pasmo?

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
presh
Manic Miner
Posts: 237
Joined: Tue Feb 25, 2020 8:52 pm
Location: York, UK

Any way to do this in Pasmo?

Post by presh »

Suppose I have an unrolled loop, plus a table pointing to it, e.g.

Code: Select all

ldi_3:  
  LDI
ldi_2:  
  LDI
ldi_1:  
  LDI
  RET
  
ldi_table:
  DW ldi_1
  DW ldi_2
  DW ldi_3
Is there any way for Pasmo to automatically generate the labels? Pseudocode example of the kinda thing I'd like:

Code: Select all

%for i=3 to 1
ldi_{i}:
  LDI
%next i
  RET

ldi_table:  
%for i=1 to 3
  DW ldi_{i}
%next i
I can't tell how to do it from the docs :|

TIA :)
User avatar
Joefish
Rick Dangerous
Posts: 2080
Joined: Tue Nov 14, 2017 10:26 am

Re: Any way to do this in Pasmo?

Post by Joefish »

I seem to remember trying something where I used '##' to concatenate a text label with the number of the loop, but I don't think I ever got it to work!
It's mentioned in the documentation under 'Parameter expansion'.
presh
Manic Miner
Posts: 237
Joined: Tue Feb 25, 2020 8:52 pm
Location: York, UK

Re: Any way to do this in Pasmo?

Post by presh »

Thanks @Joefish.

Yeah, I've just tried ## and & but they give me:

Code: Select all

ERROR: Unexpected '##' used as instruction
ERROR: Unexpected '&' used as instruction
Frustrating that there are no examples in the docs! :(
User avatar
bobs
Microbot
Posts: 107
Joined: Thu Dec 28, 2017 8:26 am
Location: UK
Contact:

Re: Any way to do this in Pasmo?

Post by bobs »

I’ve used that stuff in Melkhior’s, but not near the code right now to check just how. Will post something up later…
User avatar
bobs
Microbot
Posts: 107
Joined: Thu Dec 28, 2017 8:26 am
Location: UK
Contact:

Re: Any way to do this in Pasmo?

Post by bobs »

Sorry, but I can’t get this to work as you like. I think the problem is that ## only works within MACRO statements, as I use it, but IRP & REPT both effectively use a local DEFL to hold the iteration/parameter, which you can’t then pass to macros.
User avatar
RMartins
Manic Miner
Posts: 776
Joined: Thu Nov 16, 2017 3:26 pm

Re: Any way to do this in Pasmo?

Post by RMartins »

presh wrote: Tue Aug 16, 2022 1:59 am ...
I can't tell how to do it from the docs :|

TIA :)
As far as I remember you can do it, but you have to use a macro and the ## operator.

However, with the REPT and current documentation it will probably work too. I need to try though, to be sure.
User avatar
bobs
Microbot
Posts: 107
Joined: Thu Dec 28, 2017 8:26 am
Location: UK
Contact:

Re: Any way to do this in Pasmo?

Post by bobs »

You can do it with a combination of MACROs and IRPs…

Code: Select all

MACRO DEFLABEL_LDI, _idx
LDI_##_idx EQU $
ENDM

MACRO DWLABEL_LDI, _idx
DEFW LDI_##_idx
ENDM

IRP _idx, 3, 2, 1
DEFLABEL_LDI _idx
ldi
ENDM
ret

IRP _idx, 1, 2, 3
DWLABEL_LDI _idx
ENDM
However, there are much easier ways if you know that your labels are alway n bytes apart, as your look-up table is simply a numeric sequence based on a base address.
User avatar
RMartins
Manic Miner
Posts: 776
Joined: Thu Nov 16, 2017 3:26 pm

Re: Any way to do this in Pasmo?

Post by RMartins »

Working sample

Code: Select all

IDXLABEL MACRO prefix, name, suffix
	prefix ## name ## suffix:
ENDM

DW_IDXLABEL MACRO prefix, name, suffix
	DW prefix ## name ## suffix
ENDM

main_start EQU $6000

ORG main_start

main:
	LD HL, $5800
	LD DE, $5820

IRP count, 3
IDXLABEL ldi_, count, _idx
  	LDI
ENDM
  	RET

ldi_table:  
IRP count, 3
	DW_IDXLABEL ldi_, count, _idx
ENDM

END main_start
Save it as "test.asm"

Run it with "-1" parameter, to see the macro expansion working.

Code: Select all

pasmo -1 --tapbas test.asm test.bin
NOTE:
It copies the first 3 Attributes from Attribute row 1 into first 3 Attributes in attribute row 2.

WARNING:
REPT can not be used since the manual states that it's not a macro parameter, so it can't be used as such, which is required in this case to concat the label name.
To concat a label into a single unit, we need to use the ## operator that is only available inside a Macro.
User avatar
Bubu
Manic Miner
Posts: 542
Joined: Fri Apr 02, 2021 8:24 pm
Location: Spain

Re: Any way to do this in Pasmo?

Post by Bubu »

I don't understand the real problem. Your code is:

Code: Select all

ldi_3:  
  LDI
ldi_2:  
  LDI
ldi_1:  
  LDI
  RET
  
ldi_table:
  DW ldi_1
  DW ldi_2
  DW ldi_3
Is this what you want? :

Code: Select all

address_1:
instructions...
address_2:
instructions...
address_3:
instructions...

table:
DW address_1
DW address_2
DW address_3
And what's the problem with PASMO?
If something works, don't touch it !!!! at all !!!
User avatar
Stefan
Manic Miner
Posts: 823
Joined: Mon Nov 13, 2017 9:51 pm
Location: Belgium
Contact:

Re: Any way to do this in Pasmo?

Post by Stefan »

Bubu wrote: Tue Aug 16, 2022 11:27 pm I don't understand the real problem.
<snip>
If you had first read the answers already given, then you may have had a better idea of the problem.

The question was how to use PASMO macros to automatically generate source code. So while the example is for [ 1, 2, 3 ], the actual use case is probably for a higher number, like [ 1, 2, ... 191, 192 ]
User avatar
Joefish
Rick Dangerous
Posts: 2080
Joined: Tue Nov 14, 2017 10:26 am

Re: Any way to do this in Pasmo?

Post by Joefish »

RMartins wrote: Tue Aug 16, 2022 10:05 pm Working sample...
Is that right? As I'm reading it for how IRP (rather than REPT) works, shouldn't the syntax be???:

IRP count, 1, 2, 3

not:

IRP count, 3

Still, this is gripping stuff! I could never figure it out.
User avatar
RMartins
Manic Miner
Posts: 776
Joined: Thu Nov 16, 2017 3:26 pm

Re: Any way to do this in Pasmo?

Post by RMartins »

Joefish wrote: Wed Aug 17, 2022 12:11 pm Is that right? As I'm reading it for how IRP (rather than REPT) works, shouldn't the syntax be???:

IRP count, 1, 2, 3
I haven't tried that, but according to the documentation, I think you would get 6 repetitions (1+2+3 = 6).

Or maybe you are confusing IRP with IRPC ?

But you can always take a look at the sample/test files that are in the Zip in the website.
Post Reply