Jump to content
IGNORED

Split words with mads


ivop

Recommended Posts

Hi,

 

Is there a way to easily "split" words into two separate tables? Here's what I mean:

 


table
	.word $0123, $4567, $89ab, $cdef

; becomes:

tablelo
	.byte $23, $67, $ab, $ef
tablehi
	.byte $01, $45, $89, $cd

With four words, it is not that much of a problem to do it by hand, but with eight or more, it becomes a burden. Especially if you are bound to change and tweak those values to match what you are trying to achieve :)

 

 

Edited by ivop
Link to comment
Share on other sites

Not sure if this would do, it's MAC/65, but I assume MADS will do something similar

 

A1       =   $0123
A2       =   $4567
A3       =   $89AB
A4       =   $CDEF
TABLELO  .BYTE  <A1, <A2, <A3, <A4
TABLEHI  .BYTE  >A1, >A2, >A3, >A4

 

assembles into:-

 

    =0123       10 A1    =   $0123
    =4567       20 A2    =   $4567
    =89AB       30 A3    =   $89AB
    =CDEF       40 A4    =   $CDEF
0000 2367ABEF   50 TABLELO .BYTE  <A1, <A2, <A3, <A4
0004 014589CD   60 TABLEHI .BYTE  >A1, >A2, >A3, >A4

  • Like 2
Link to comment
Share on other sites

I had totally forgotten about l() and h(). That's a 50% solution IMHO ;)

 

Would you consider implementing something like this:

table
	.startsplitword
		.splitword $0123, $4567, $89ab, $cdef
		.splitword $8976, $afe0, $dead, $beef
		; etc...
	.endsplitword
tableend

tablelo = table
tablehi = table + (tableend - table) / 2

Syntax is debatable of course :)

 

 

Link to comment
Share on other sites

    opt h-
    .macro splitwords
  
;    :%%0 dta #              ; # works, counts from 0 to number of parameters-1

    :%%0 dta l(:#+1)        ; # in an expression does not work
    :%%0 dta h(:.R+1)       ; neither does .R

    .endm

    splitwords $dead, $beef, $0123, $4567, $89ab, $cdef

 

Edit: this happens to be my 2048th post :)

Edited by ivop
  • Like 2
Link to comment
Share on other sites

I could only get as far as this:

 

mads 2.1.1 build 17 (18 Nov 20)
Source: test.asm
     1                     org $2000, $600
     2                     
     3                     .macro splitwords
     4                 
     5                 :1_LO: 
     6                 :(:0-1)    .byte <(%%(# + 2))
     7                 :1_HI: 
     8                     .rept :0-1
     9                     .byte >(%%(# + 2))
    10                     .endr
    11                 
    12                     .endm
    13                     
    14                     org *
    15                     
    16                 .proc main
    17                 endless
    18 FFFF> 2000-200E> 4C 00 +     jmp endless
    19 2003                splitwords table $dead, $beef, $0123, $4567, $89ab, $cdef
Macro: SPLITWORDS [Source: test.asm]
     2 2003            TABLE_LO: 
     3 2003 02 03 04 05 06 07    :(7-1)    .byte <(%%(# + 2))
     4 2009            TABLE_HI: 
     6 2009 00                .BYTE >(%%(# + 2))
     6 200A 00                .BYTE >(%%(# + 2))
     6 200B 00                .BYTE >(%%(# + 2))
     6 200C 00                .BYTE >(%%(# + 2))
     6 200D 00                .BYTE >(%%(# + 2))
     6 200E 00                .BYTE >(%%(# + 2))
Source: test.asm
    20                 .endp
    21
    22 02E0-02E1> 00 20            run main

So it seems that the %% can't handle resolution of the brackets to give it the index.

 

Using ':' instead makes this worse:

    splitwords table $dead, $beef, $0123, $4567, $89ab, $cdef
        .BYTE >(:(# + 2))
test.asm (9) ERROR: Extra characters on line

The other thing I could think of that would be useful would be if the repeat could be passed all the arguments from the macro as ':*' with an option to start from a given position, e.g. something like this to start from the second parameter:

    .macro splitwords

:1_LO: 
    .rept :0-1 :*+2
    .byte <(:.R)
    .endr
:1_HI: 
    .rept :0-1 :*+2
    .byte >(:.R)
    .endr

    .endm

But this still needs ":.R" or ":#" or "%%#" to be understood... one for @tebe

Edited by Wrathchild
this->thing
Link to comment
Share on other sites

Hi!

1 hour ago, ivop said:

Is there a way to easily "split" words into two separate tables?

 

I don't know much about MADS syntax, but this is easy in CA65:

.define MyTable TableItem0, TableItem1, TableItem2, TableItem3

        TableLookupLo:   .lobytes MyTable
        TableLookupHi:   .hibytes MyTable

Perhaps there is something like the "define" keyword in MADS?

 

Have Fun!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...