EASy68K
http://www.easy68k.com/EASy68Kforum/

Assert that the current position is an expected address
http://www.easy68k.com/EASy68Kforum/viewtopic.php?f=5&t=1671
Page 1 of 1

Author:  2WaterGuns [ Wed Apr 24, 2019 2:10 am ]
Post subject:  Assert that the current position is an expected address

I'm using EASy68K to learn about homebrew on the Sega Mega Drive (Genesis). In this format, the game's header must begin at address $100, immediately following the interrupt vector table.

Initially, I simply used the ORG directive to ensure the header started at the correct position, e.g.:

Code:
    ORG $100
    DC.B    'SEGA MEGA DRIVE '  ; $100: System Name: trailing space to align on 16 bytes
    DC.B    '(C)2WG  2019.APR'  ; $110: Copyright/Date: empirically no space after (C)


However, looking at the list file, I realized I had mistakenly made the preceding vector table too short, and that there was a gap between the end of the table and the start of the game header, meaning I had missed some entries in the table.

So I felt the ORG shouldn't be used, and I should instead just have the assembly fail if the current position *isn't* what I specify.
Basically, I want to assert that the current position is an expected address.

I've tried using the various IF directives but haven't had success. For example:

Code:
    ORG $100                   
                           
IFEQ *-$100
    FAIL    "Genesis Header must start at $100"
ENDI


My goal is to use a construct similar to this and assemble without error, because the position is set to $100 by the ORG directive, so the current position (*) minus $100 should be equal to 0.
I would then remove the ORG directive, allowing the assertion code to actually check that the preceding content lines up with what I expect.

However, in this example, the assembler fails with the "Genesis Header must start at $100", even when the ORG directive is left in.

Is there a way to use the current position of the assembler in conditional comparisons like this?

Author:  profkelly [ Fri May 03, 2019 1:55 pm ]
Post subject:  Re: Assert that the current position is an expected address

Hmm, while looking into this I may have discovered a bug in conditional assembly. I'll try to look at the problem this weekend.

Author:  profkelly [ Mon May 06, 2019 9:13 am ]
Post subject:  Re: Assert that the current position is an expected address

My mistake, there is no error in EASy68K. The code to do what you want is something like this:
Code:
    ORG    $1000
START:
    dc.b 'stuff'
    ifne *-$1000
    FAIL "address not $1000"
    endc
    SIMHALT             ; halt simulator

    END    START        ; last line of source
ifne executes FAIL if the current location does not equal $1000.
endc is the last line of the conditional directive.

Author:  2WaterGuns [ Sat Jun 01, 2019 4:41 pm ]
Post subject:  Re: Assert that the current position is an expected address

Great, thanks. Sorry for the late response.

Author:  RyanFaeScotland [ Wed Jul 17, 2019 3:49 pm ]
Post subject:  Re: Assert that the current position is an expected address

Interesting stuff 2WaterGuns, as a fellow Megadrive programmer please keep us updated with your progress.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/