ivop Posted February 25, 2021 Share Posted February 25, 2021 (edited) 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 February 25, 2021 by ivop Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted February 25, 2021 Share Posted February 25, 2021 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 2 Quote Link to comment Share on other sites More sharing options...
tebe Posted February 25, 2021 Share Posted February 25, 2021 dta l(a,b,c,d) dta h(a,b,c,d) 2 Quote Link to comment Share on other sites More sharing options...
ivop Posted February 25, 2021 Author Share Posted February 25, 2021 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 Quote Link to comment Share on other sites More sharing options...
ivop Posted February 26, 2021 Author Share Posted February 26, 2021 (edited) 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 February 26, 2021 by ivop 2 Quote Link to comment Share on other sites More sharing options...
+Stephen Posted February 26, 2021 Share Posted February 26, 2021 17 minutes ago, ivop said: Edit: this happens to be my 2048th post Way to go Robotron! Quote Link to comment Share on other sites More sharing options...
Wrathchild Posted February 26, 2021 Share Posted February 26, 2021 (edited) 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 February 26, 2021 by Wrathchild this->thing Quote Link to comment Share on other sites More sharing options...
dmsc Posted February 26, 2021 Share Posted February 26, 2021 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! Quote Link to comment Share on other sites More sharing options...
Rybags Posted February 26, 2021 Share Posted February 26, 2021 I like the l( h( method - it's recognisable for what you're trying to achieve. And you just copy/paste and change the h to l in the copy - remembering we'd be using a modern PC based editor in most cases. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.