Не совсем понятен общий вид, но вообще длину данных можно узнать
Код:org 0x8000
macro ma1 parm1
temp = $
db parm1
tlen = $-temp
org temp
db tlen,parm1
endm
ma1 "test"
savebin "test.bin", 0x8000,$-0x8000
Вид для печати
Не совсем понятен общий вид, но вообще длину данных можно узнать
Код:org 0x8000
macro ma1 parm1
temp = $
db parm1
tlen = $-temp
org temp
db tlen,parm1
endm
ma1 "test"
savebin "test.bin", 0x8000,$-0x8000
I'm really failing to replicate this:
I know this is not important for you, but makes me wonder what is happening and if there is some other bug in sjasmplus, that's why I'm poking into this detail. The trailing spaces should be now removed from DEFINEs. Maybe you have the DEFINE in some other code path like IF/ENDIF block or inside MACRO, or I don't know... interesting. If you will find some time, can you try to produce full example where v1.18.3 fails to remove the trailing space? Thank you.Код:ped@ped7g-sb:~$ sjasmplus-1.18.3 --version
SjASMPlus Z80 Cross-Assembler v1.18.3 (https://github.com/z00m128/sjasmplus)
ped@ped7g-sb:~$ sjasmplus-1.18.3 - --msg=lst
define appName testapp ; Краткое название приложения
LUA ALLPASS
sj.insert_define("SAVEPATH", '"install/bin/' .. sj.get_define("appName") .. '1"')
ENDLUA
db SAVEPATH
# file opened: console_input
1 0000 define appName testapp ; Краткое название приложения
2 0000 LUA ALLPASS
3 0000 ~ sj.insert_define("SAVEPATH", '"install/bin/' .. sj.get_define("appName") .. '1"')
4 0000 ENDLUA
5 0000 69 6E 73 74 db "install/bin/testapp1"
5 0004 61 6C 6C 2F
5 0008 62 69 6E 2F
5 000C 74 65 73 74
5 0010 61 70 70 31
6 0014
# file closed: console_input
About string operators in sjasmplus - there are none, unfortunately. For any complex string manipulation the best way is to use lua script. The hack to figure out length by `ORG` macro is usable when in DEVICE mode, but would ruin the output in raw/OUTPUT mode (although you can open OUTPUT file for rewrite and rewind position back, I would probably rather opt for lua solution instead).
Macro arguments to lua -> definitely possible, there is some test/example somewhere... Check this test in particular and whole folder "lua_examples" and maybe also "macro_examples": https://github.com/z00m128/sjasmplus...macro_arg2.asm
Not sure if it will answer all your questions/issues, but maybe you will be able to pick up some trick or two.
I'm following this conversation a bit half-minded as I'm focusing on some work stuff, so in case you are waiting for some example from me or you are stuck with final version of your attempt, post that as new post clearly saying you expect specific help from me, otherwise I may miss it (right now I think you are trying to resolve it all yourself, so I'm giving you just pointers where to look, not preparing any full example).
EDIT: actually going through that example, that's not useful for string manipulation... the older https://github.com/z00m128/sjasmplus..._macro_arg.asm is then probably more relevant, but I'm still not sure how well the string is passed through, I would have to write some actual code and test it to be 100% sure how it works. "It should be possible" is all I can say at this moment. :)
Да я сам не люблю переставлять орг, по мне сам device режим это убожество.
В принципе нормально работает и так
Нужно по обстановке смотреть. Просто помнить что = можно в макросах, а просто метки и equ нельзя.Код:org 0x8000
db tend -$-1
db "test"
tend
savebin "test.bin", 0x8000,$-0x8000
uhm... what exactly is not possible about labels in macros?
Regular label means the macro can be emitted only once (second emit would create duplicate label, at least in the same module), but you can define normal label in macro *once* (per module).
The local labels inside macro are automatically per-instance so every use of macro has its own independent labels.
And since v1.18.3 you can create non-macro local labels from inside macro by using "@" prefix ( https://github.com/z00m128/sjasmplus...cal_labels.asm ):
resulting listing:Код:macro test
@.kip3 ; prevent macro-local label and create regular local label instead
kip0
.kip1
@.kip2
endm
module main
; should produce labels: main.hoi, main.kip0, 0>kip1, main.kip0.kip2, main.hoi.kip3
hoi test
endmodule
So, labels in macros is just another available tool, should "work". It has somewhat specific rules and outcome, being affected by "inside macro", but I hope those rules are reasonably simple and usable.Код:
# file opened: local_labels.asm
1 0000 macro test
2 0000 ~ @.kip3 ; prevent macro-local label and create regular local label instead
3 0000 ~ kip0
4 0000 ~ .kip1
5 0000 ~ @.kip2
6 0000 endm
7 0000
8 0000 module main
9 0000 ; should produce labels: main.hoi, main.kip0, 0>kip1, main.kip0.kip2, main.hoi.kip3
10 0000 hoi test
10 0000 >@.kip3 ; prevent macro-local label and create regular local label instead
10 0000 >kip0
10 0000 >.kip1
10 0000 >@.kip2
11 0000 endmodule
12 0000
# file closed: local_labels.asm
Value Label
------ - -----------------------------------------------------------
0x0000 X 0>kip1ing
0x0000 X main.hoi
0x0000 X main.hoi.kip3
0x0000 X main.kip0
0x0000 X main.kip0.kip2
If you have source where labels inside macros don't work as designed, let me know, then it may be bug or misunderstanding and we can usually resolve that together.
I'm not so into changing the rules, because every time I did some "fix" since 1.10.4 to today and the fix did some slight modification of old behaviour, even if technically it is now more correct, there are always some users with project which gets broken and requires fixing, and that's very annoying (sorry guys). So I'm trying hard to keep original behaviour and do only "fixes" and "extensions", if possible. But the current syntax of sjasmplus is quite powerful, like 7/10 IMHO. There're some things I would design a bit differently, if I was starting from scratch a new assembler. And there are definitely things I would implement differently. But overall the decent base quality was one of the reasons, why I did start fixing and extending sjasmplus, it was already quite good, just a bit bugged... :) (just my personal opinion, and I don't care if other people prefer other assembler, I just tried to make sjasmplus viable option)
edit: not even sure what I was trying to say with that last paragraph... I think the main point is:
reporting your issues and bugs with sjasmplus is welcome. I can't promise to answer/fix/extend everything as quickly as you need it, but I like to see sjasmplus used in your projects, so I will usually try to find some solution, if you have problem. :)
Aw **** here we go again =)
result:Код:DEVICE ZXSPECTRUM128
org #8000
appStart
define appName cursor ; comment
LUA ALLPASS
sj.insert_define("SAVEPATH", '"install/bin/' .. sj.get_define("appName") .. '"')
ENDLUA
db SAVEPATH
appEnd
SAVEBIN "test.bin", appStart, appEnd-appStart
test.lstКод:sjasmplus.exe test.asm --lst=test.lst
SjASMPlus Z80 Cross-Assembler v1.18.3 (https://github.com/z00m128/sjasmplus)
Pass 1 complete (0 errors)
Pass 2 complete (0 errors)
Pass 3 complete
Errors: 0, warnings: 0, compiled: 17 lines, work time: 0.015 seconds
now also got trailing space before appName =)Код:# file opened: test.asm
1 0000 DEVICE ZXSPECTRUM128
2 0000
3 0000 org #8000
4 8000
5 8000 appStart
6 8000
7 8000 define appName cursor ; comment
8 8000
9 8000 LUA ALLPASS
10 8000 ~ sj.insert_define("SAVEPATH", '"install/bin/' .. sj.get_define("appName") .. '"')
11 8000 ENDLUA
12 8000
13 8000 69 6E 73 74 db "install/bin/ cursor "
13 8004 61 6C 6C 2F
13 8008 62 69 6E 2F
13 800C 20 20 20 63
13 8010 75 72 73 6F
13 8014 72 09 09 09
13 8018 09
14 8019
15 8019 appEnd
16 8019
17 8019 SAVEBIN "test.bin", appStart, appEnd-appStart
# file closed: test.asm
ahh... ok... now it makes sense to *me*... ;)
The space ahead is intentional, I don't expect value to be indented, so only one space is removed and following space is considered define value.
But the trailing stuff is tab vs space, I have space-as-tabs everywhere, and seems I forgot to test the trailing space trimming with tabulators...
I will take a look on it. (and I know the leading space preservation is not intuitive, but I'm not sure what to do about it... it's a bit unclear. In macro arguments I guess it's safe to trim everything, because you can use `<>` syntax to enclose argument value which contains leading/trailing space, but in DEFINE there's no delimiter syntax, everything is just new value for DEFINE (the trailing space trimming is a bit dubious extra, but nobody objected about it so far).
edit: or maybe I will just add to docs that DEFINE and macro arguments trim whitespace (and fix the code), and there will be no possible way to set up DEFINE value with leading/trailing white space.
@Ped7g is it possible access to DEFARRAY's element from LUA?
Hmm, had to look into source, but unfortunately, not.
If it is numeric value (32bit int result), you can at least evaluate it through `_c("test_array[2]")`, but if you need string, I was unable to find any decent workaround. I tried also some trick to define single temporary define from one element, but that doesn't substitute during evaluation the way how it would be needed for lua script.
@Ped7g and AGAin very strange problem :)
Got error — (16): error: [LUA] attempt to call global 'gsub' (a nil value)Код:db_u "Test"
macro db_u text
define _t text
lua allpass
local str = sj.get_define("_t")
print(type(str))
print(str)
str = str:gsub(".?$","")
str = str:gsub("^.?","")
print(str)
endlua
undefine _t
endm
16 line → str = str:gsub("^.?","")
But if i add ; in begin like:
no error:Код:; str = str:gsub(".?$","")
; str = str:gsub("^.?","")
WTF???? :DКод:SjASMPlus Z80 Cross-Assembler v1.18.3 (https://github.com/z00m128/sjasmplus)
string
"Test"
Test
Pass 1 complete (0 errors)
string
"Test"
Test
Pass 2 complete (0 errors)
string
"Test"
Test
- - - Добавлено - - -
Solution found :D
replace code in style LUA 5.3:
Poof! and error was gone!Код:str = string.gsub(str, ".?$","")
str = string.gsub(str, "^.?","")