santiontanon / mdlz80optimizer

MDL (a Z80 assembler optimizer)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WLA-DX Z80 dialect support

maxim-zhao opened this issue · comments

commented

WLA-DX is commonly used for Sega 8-bit homebrew, as it has good support for ROM paging. The project is here: https://github.com/vhelin/wla-dx and the docs are here: https://wla-dx.readthedocs.io/en/latest/ - it is mostly very standard mnemonics but there's a lot of assembler directives, I guess macros will be the hardest thing to support.

Thanks for the pointers, very useful! Quick question, do you know any site, or GitHub repo where I could find an example such 8-bit project codebase to test things out?

commented

I have a bunch but they depend on specific tools for asset conversion. I have a binary package for building them at https://github.com/maxim-zhao/sms-build-tools/releases. The ones below have makefiles, which may make it easy for you:

https://github.com/maxim-zhao/smsgraphicboard
https://github.com/maxim-zhao/zexall-sms

Many of my older ones also have automatic builds via batch files, eg:

https://github.com/maxim-zhao/chip8-sms
https://github.com/maxim-zhao/bocks-birthday-2004

These tend to have appveyor.yml describing the build process, and rely on the same tools package.

Ouch, I tried to build those projects, but many of the build tools assume access to a Windows machine (which I don't have). I can still work with this, since I don't really need to produce working binaries to test it (I'm just going to provide dummy data files (the output of bmp2tile) and just compare the output of WLA-DX and mdl for now. Might be great to have unix build systems for those projects for portability :)

Quick question, there are a few undefined behavior in the documentation. When you define a symbol like: ".define FOO", without specifying a value, what value does it assign it by default? 0?

In any case, I just started working on this, and I have already a bunch of WLA-DX syntax supported. Not yet enough as for processing a whole project, but almost! I think I only have the .asciitable / .enda commands to support for being able to fully process chip8-sms :) I'll continue later/tomorrow :)

Alright, I just added enough support so that the "chip8-sms" project can be processed with MDL now! I don't think the sections, banks, etc. are properly handled, so, I would not trust binary generation, but at least we can get some optimizations :)

If there is any project in particular you want to use MDL on and it is not working, do let me know, and I can expand the current WLA-DX support! :)

commented

Quick question, there are a few undefined behavior in the documentation. When you define a symbol like: ".define FOO", without specifying a value, what value does it assign it by default? 0?

If you omit the definition value (in our example DEFAULTV), WLA will default to 0.
from https://wla-dx.readthedocs.io/en/latest/#define-if-ff0f

Perfect, thanks! I missed that line!

Btw, thanks for making me aware of this assembler. WLA-DX has some interesting features! I particularly like the idea of the .asciitable!

If I am allowed a small critique, I would recommend removing/deprecating the reusable labels (-, --, +, ++, etc.) that (like the reusable numeric labels in sjasm) are a bug-magnet. But that's a small detail, it's a pretty nice assembler! thanks again for pointing it to me, I'll keep going through its features and try to support mode directives in MDL over time!

commented

Yes, they are a real bug magnet, I second this. But too much code uses those already to remove or deprecate them - we can only suggest avoiding them as much as possible, with the exception of very short loops, probably.
But hey, that's offtopic here! 😉

indeed off topic, haha. In any case, I'll keep this issue open until I manage to support enough WLA-DX as for processing all four projects linked above!

commented

If you like .asciitable you'll love .stringmap! (I added it recently to support translation work, so you can enter text in UTF-8 and map sequences of text to sequences of bytes.)

I don't have a Z80 project on the go right now, apart from the eternal https://github.com/maxim-zhao/psrp, but I'd love to see it cover a whole disassembly of a commercial game. Which I'm somewhat working on now; Emulicious can do a decent job of producing a 90% test case for that.

commented

Oh, and -, --, +, ++ etc are super excellent until you screw them up. It's a lot better than having to think up unique _loop variables (although @loop can help).

Cool! I'll check the psrp project and see if I can make mdl process the whole thing!

And about the project being "eternal", haha, I recently did my first disassembly of a commercial game (a small ZX Spectrum one), and man, that was a LOT of work. So, I hear you :)

I added sufficient support as for processing a few of the wladx projects you linked above! So, I am going to close this issue. But feel free to reopen if there is any particular project that does not work, and I'd be happy to look into it! I'll release a new version (2.5) soon, which will include all of the new code for wladx.

commented

I just tried latest version but it seems it doesn't like the command line option when specifying the wladx or wladxz80 dialect:

$ java -jar mdl.jar test.asm -dialect wladx

$ java -jar mdl.jar test.asm -dialect wladxz80

I just get this output:

INFO: MDL v2.5 (A Z80 assembler optimizer) by Santiago Ontañón (Brain Games, 2020-2022)
https://github.com/santiontanon/mdlz80optimizer

Command Line Arguments:
java -jar mdl.jar <input file name(s)> [options]

- -help: for an exhaustive list of flags (just type java -jar mdl.jar -help).
- -dialect <dialect>: selects which assembler dialect to use (mdl/asmsx/asmsx-zilog/glass/sjasm/sjasmplus/tniasm/winape/pasmo/sdcc/sdasz80/macro80/wladx/wladxz80).
- -so: Runs the search-based-based optimizer (optimizes code if the input is an assembler file; generates code if the input file is a specification file).
- -ro: Runs the code reoganizer optimizer.
- -po: Runs the pattern-based optimizer.
- -do: Runs the data optimizer (only provides potential ideas for space saving).
- -asm <output file>: saves the resulting assembler code in a single asm file.
- -bin <output file>: generates an assembled binary.

Ah, yes! You need to tell MDL what should it do. If you want to run the pattern-based optimizer, for example, you should add a "-po" flag (otherwise, it it just loading the assembler file, but doing nothing with it). I should add a warning message in this case to help the user figure out what is happening! Will add a to-do item to do it :)

commented

Yeah, a "no optimizer options specified" would help the user to understand that at least one of those needs to be picked.
Thanks!