News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_krusty_benediction

How do you manage cyclic dependencies in your ASM code ?

Started by krusty_benediction, 20:43, 19 December 17

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

krusty_benediction

Hello,in my current CPC project, I have some cyclic dependencies.
I had no such things since Wake Up! I guess and at this time I managed them with a script shell that updated source code when needed. Here is an extract:

function check {


if ! test -e $SOURCE ;
then
    echo "$SOURCE does not exist !"
    exit -1
fi

for symbol in $LIST; do
    source_line=$(grep "^$symbol:" $SOURCE)
    destination_line=$(grep "^$symbol:" $DESTINATION)
    source_value=$(echo $source_line | sed -e 's/.*: equ //')
    destination_value=$(echo $destination_line| sed -e 's/.*: equ //')

    if test -z $destination_value ;
    then
        echo "ERROR - You did not add the line !! $source_line"
            echo 'TRY an automatic repair => you need to build again' ;
        echo $source_line
        echo $source_line >> $DESTINATION;
        exit 1
    fi

#   echo "$SOURCE => $DESTINATION [$symbol] ($source_value, $destination_value)"
    test $source_value = $destination_value || (\
        echo 'ERROR - Different values for symbol' $symbol;
        echo 'TRY an automatic repair => you need tobuild again' ;
        sed -i $DESTINATION -e "s/^$destination_line.*/$source_line/"
        exit 1)
done
}


# Dependance to framework in cheat part
LIST='FRAMEWORK_WAIT_VBL FRAMEWORK_RETURN_AFTER_CHEAT_PART'
SOURCE='framework.sym'
DESTINATION='src/cheat/cheat.asm'
check

# Music splitted in two banks
LIST='ADRZIKEND ADRZIK FREESPACE_FOR_MUSIC ZIKNB '
SOURCE='C4.sym'
DESTINATION='src/framework/C5.asm'
check


I'm not satisfied at all of this solution and I'm not sure to want to use it this year.
I guess other guys had met such kind of problem. How have you solved it ?I may be interested by your solution.
Thanks

Targhan

I had some problems like that, found some dirty trick too.


Mmmh, shouldn't simple check on labels on the start of the file be enough?
Targhan/Arkos

Arkos Tracker 3.2.6 now released! - Follow the news on Twitter!
Disark - A cross-platform Z80 disassembler/source converter
FDC Tool 1.1 - Read Amsdos files without the system

Imperial Mahjong
Orion Prime


MaV

I'm not sure if I understood your code well enough (I do not do shell scripting myself), but your solution looks close to what OOP calls the observer pattern. You just need to build upon it.

Here's a simple example that's not too abstract:
https://www.tutorialspoint.com/design_pattern/observer_pattern.htm

In your example the script should register all the files that need to change (i.e. the "Subject" object), and the observers (i.e. source code) need a function of what they actually need to change which the script then calls in each function.

Now I understand shell scripting does not use OOP but the pattern might give you an idea how to expand your code.

MaV
Black Mesa Transit Announcement System:
"Work safe, work smart. Your future depends on it."

andycadley


Can you not do the old:



IFNDEF label
DEFINE label
... code ...
ENDIF



Or am I missing something?

Targhan

Exactly, that's what I was talking about. Within the same compilation unit, it should work fine.
Targhan/Arkos

Arkos Tracker 3.2.6 now released! - Follow the news on Twitter!
Disark - A cross-platform Z80 disassembler/source converter
FDC Tool 1.1 - Read Amsdos files without the system

Imperial Mahjong
Orion Prime

krusty_benediction

Quote from: andycadley on 11:32, 20 December 17
Can you not do the old:



IFNDEF label
DEFINE label
... code ...
ENDIF

I think I have badly explained, becaus esadly this solution does not solve my issue ;)
lets say we have A.asm and B.asmA.asm call a function defined in B.asmB.asm include A.exo (the crunched version of A.asm when compiled).
Here is my dependency : - B depends on A (becauseit includes its binary) - A depends on B (because it calls stuff from A)
Or am I missing something?

Targhan

I must not be clever enough, but how B can use anything about A while it is exomized??


But I would refactor this and have a C.asm with the code needed by A and B...
Targhan/Arkos

Arkos Tracker 3.2.6 now released! - Follow the news on Twitter!
Disark - A cross-platform Z80 disassembler/source converter
FDC Tool 1.1 - Read Amsdos files without the system

Imperial Mahjong
Orion Prime

roudoudou

Quote from: krusty_benediction on 17:16, 20 December 17
I think I have badly explained, becaus esadly this solution does not solve my issue ;)
lets say we have A.asm and B.asmA.asm call a function defined in B.asmB.asm include A.exo (the crunched version of A.asm when compiled).
Here is my dependency : - B depends on A (becauseit includes its binary) - A depends on B (because it calls stuff from A)
Or am I missing something?


Use Rasm  :D


You can compile at the same time A.asm and B.asm
Crunch with exomizer a portion of code in B.asm and include it in A.asm
Even use labels from A.asm in the crunched code of B.asm


Elle est pas belle la vitre?


krusty_benediction

Quote from: Targhan on 18:04, 20 December 17
I must not be clever enough, but how B can use anything about A while it is exomized??
Because at some point B is uncrunched somwhere ;)

Quote from: Targhan on 18:04, 20 December 17But I would refactor this and have a C.asm with the code needed by A and B...
For my current case,C is a generated code that need to read/write at some addresses in A (and I cannot fix them).For my previous cases, C was a demo effect, and A was the demosytem. It is a quite common pattern

krusty_benediction

Quote from: roudoudou on 20:24, 20 December 17

Use Rasm  :D


You can compile at the same time A.asm and B.asm
Crunch with exomizer a portion of code in B.asm and include it in A.asm
Even use labels from A.asm in the crunched code of B.asm


Elle est pas belle la vitre?
Yes, I asked myself this question yesterday.
I'm not sure to be ready to swap from vasm to rasm for my current project. Maybe for the next one in 5 years ;)

Targhan

Well, I think it's bad practice :). I had such stuff in Orion Prime, it quickly became a mess.


In your use case, what about an indirection table (maybe at the beginning of A) so that any other "plugin" can address it without caring about the underlying architecture?
Targhan/Arkos

Arkos Tracker 3.2.6 now released! - Follow the news on Twitter!
Disark - A cross-platform Z80 disassembler/source converter
FDC Tool 1.1 - Read Amsdos files without the system

Imperial Mahjong
Orion Prime


Targhan

Well you could use a constant like #100 or whatever. You can include a "constants.asm", common to every file, with such addresses.
Targhan/Arkos

Arkos Tracker 3.2.6 now released! - Follow the news on Twitter!
Disark - A cross-platform Z80 disassembler/source converter
FDC Tool 1.1 - Read Amsdos files without the system

Imperial Mahjong
Orion Prime

andycadley


Traditionally that's the point at which you start needing a proper linker to tie modules together, although I don't know how well existing Z80 linkers would cope with compressed blocks (and you'd still end up needing to change assembler)


Having a small, well defined, indirection block at a fixed address is probably an easier solution.

CloudStrife

#15
Do you use vlink with vasm ?
Probably possible with section and a custom linker script and using the "output each section in an individual file" option (-osec).
(And in this case, without including A.exo in B.asm but linking a second time with another linker script)

krusty_benediction

Quote from: CloudStrife on 23:47, 21 December 17
Do you use vlink with vasm ?
Probably possible with section and a custom linker script and using the "output each section in an individual file" option (-osec).
(And in this case, without including A.exo in B.asm but linking a second time with another linker script)
Nope I have not used vlink since years and I do not recall how to use it.

Powered by SMFPacks Menu Editor Mod