RSS icon Home icon
  • Hacking the SjASMPlus Z80 assembler

    Posted on November 1st, 2016 admin No comments

    I like SjASMPlus because it is small, portable (one exe, no install) and supports writing SNA format, which means it can directly assemble the source into SNA emulator snapshot file. This is very handy if disassembling a snapshot, reverse engineering the code, then comparing the compiled source with the original snapshot. However it has a minor drawback.

    SjASMPlus prepares the stack at the end of 48K RAM (from 0xFF2D) to be able to return into Basic after executing the machine code in the snapshot. The stack is very similar when calling “RANDOMIZE USR N” after a cold restart. When you save into SNA format the compiler will warn you if this stack frame has been overwritten. Or to be exact, when the first 4 bytes has been altered from 0xFF2D. This warning is misleading: “[SAVESNA] RAM <0x4000-0x4001> will be overriden due to 48k snapshot imperfect format.”. This means, the SP points to 0x4000 (screen start) and the machine code start address will be stored here. This is due SNA does not store the PC register (program counter) but the SP (stack pointer) which points to the start address (where the program has interrupted), and to start (or continue) the program a RETN instruction is executed by the emulator. Moreover, SjASMPlus does not support to set the SP register. It sets SP to 0xFF2D or 0x4000 automatically. You have no control over this behaviour.

    My solution to this problem is a modified SAVESNA command which supports setting the SP register. The original SAVESNA command has two parameters: filename and start address. I modified it to accept a third parameter for the SP register. If SAVESNA is called with two parameters it works like before. If you specify the third parameter it will save as SP in the snapshot file, put the start address into there and warn you by this message: “[SAVESNA] RAM <0x%x-0x%x> will be overridden with start address”.

    You can download the modified binary and the source code modification to the v1.07 RC7 version as unified diff format.

    The original source can be found at SourceForge: sourceforge.net/projects/sjasmplus/

    Edit:

    After posting this entry I found the project has a new home at GitHub: github.com/z00m128/sjasmplus

    There is a slightly newer v1.07 RC9 version of the compiler so I applied the modification to it. You can download the new V1.07 RC9 binary and the diffs.

    Leave a Reply

    Your email address will not be published.