don't click here

Win32 version of Psy-Q Tools

Discussion in 'Engineering & Reverse Engineering' started by Puto, Aug 11, 2007.

Thread Status:
Not open for further replies.
  1. Puto

    Puto

    Shin'ichi Kudō, detective. Tech Member
    2,013
    0
    16
    Portugal, Oeiras
    Part of Team Megamix, but haven't done any actual work in ages.
    Apparently, there's a win32 version of the psy-q collection of assemblers. This is the assembler that was used to assemble most genesis games, however the only versions of it that I found were DOS, and they didn't work on XP... well, until now. Apparently, this saturn documentation page includes amongst a shitload of stuff, a fully native win32 version of it, which works fine in XP, and it's complete with support for long filenames. The full set of tools is here, and asm68k.exe alone (which is the only thing most people here would be interested in anyway) can be found here.

    The only thing that snasm68k has that asm68k doesn't seem to support, is the "align" directive, as well as negative cnops. The align issue can be fixed with a simple macro:

    align macro
    cnop 0,\1
    endm

    ...and this thread by xenowhirl shows how to get rid of the negative cnops in the s2 disassembly. So for the love of god guys, stop using that abomination known as snasm68k. This is better in pretty much every way.

    As proof of this, I took Hivebrain's S1 Disassembly, and replaced the following line in build.bat:

    Code (Text):
    1. snasm68k.exe -emax 0 -p -o ae- s1comb.asm, s1built.bin
    with this:

    Code (Text):
    1. asm68k /o op+ /o os+ /o ow+ /o oz+ /o oaq+ /o osq+ /o omq+ /p /o ae- s1comb.asm, s1built.bin
    and then in the source file itself replaced this incorrect line:

    Code (Text):
    1.         move    a6,usp    ; set usp to $0
    with the proper

    Code (Text):
    1.         move.l  a6,usp    ; set usp to $0
    which results in a perfectly assembling rom, which assembles so quickly I can barely have time to see the window open.

    Better yet, since this supports long filenames, I can then replace the include.exe directives (in the format of ; include=xxx) with proper "include" directives, which allows me to completely skip the creation of s1comb.asm! This is very useful, because it means when you get a compiling error, you'll no longer have to check the line in s1comb.asm, and then track the location to sonic1.asm.

    As such, this entire line becomes unneeded:

    Code (Text):
    1. include.exe sonic1.asm s1comb.asm
    and the asm68k line can be changed to assemble sonic1.asm directly.

    As such, here's a .rar file containing hivebrain's 2005 disassembly, with asm68k replacing snasm68k, and with the changes referred in this thread.

    And for the record, I note that in several cases has asm68k been recommended over snasm68k.
     
  2. Qjimbo

    Qjimbo

    Your friendly neighbourhood lemming. Oldbie
    This is a great find Puto, should stop people winging about snasm68k not working on XP/Vista/their Toaster. Woot for psygnosis!
     
  3. Tweaker

    Tweaker

    Banned
    12,387
    3
    0
    I think I've tried compiling Megamix with asm68k at one point, but it didn't work too well. I'll try giving it a shot now, though, if it really is that much better.
     
  4. Hivebrain

    Hivebrain

    Administrator
    3,068
    204
    43
    53.4N, 1.5W
    Github
    I'll use asm68k in the next S1 disassembly, making my inclusion program obsolete :(
    Does "even" still work or does it need replacing?
     
  5. Tweaker

    Tweaker

    Banned
    12,387
    3
    0
    Okay, so I've tried assembling the ROM, including adding the align macro, and the only error I get is "Possible Illegal Address" with absolutely no info on the line there was an error on, or anything else particularly useful in correcting the assembly error. Is there some sort of parameter I need to set, or is it just generally unhelpful like that?
     
  6. Puto

    Puto

    Shin'ichi Kudō, detective. Tech Member
    2,013
    0
    16
    Portugal, Oeiras
    Part of Team Megamix, but haven't done any actual work in ages.
    Since my replies were lost, for anyone who has the same problem, the illegal address problem is due to using a DOS version of ASM68K on XP. Use the one on the top link, which is a full fledged 32-bit application, and it should work fine.
     
  7. Nemesis

    Nemesis

    Tech Member
    That win32 build of asm68k is groovy. Unfortunately, although it supports long filenames, it doesn't support filenames with spaces, due to the way the command line parser was written. I've modified the asm68k executable to get around this annoying limitation. You can download the modified version from the following URL:
    http://www.mediafire.com/?1gb36mznxtm
     
  8. Puto

    Puto

    Shin'ichi Kudō, detective. Tech Member
    2,013
    0
    16
    Portugal, Oeiras
    Part of Team Megamix, but haven't done any actual work in ages.
    ...yeah it does, you just need to put the filenames inside quotes =P
     
  9. Tweaker

    Tweaker

    Banned
    12,387
    3
    0
    Would you be able to modify the executable further to get rid of the limitation on how many paths you can use in an include? I'm unable to use the include directive because my source is in "C:\Documents and Settings\Dustin\Desktop\S1 Megamix\" (4 subdirectories, not including _inc). Trying to compile will lead to an "out of memory" error, and I'd rather not have to move my source just because of this.

    Note that I AM using relative paths, just like every other include/incbin used.
     
  10. Nemesis

    Nemesis

    Tech Member
    No, it doesn't. For most programs that would be the case, but asm68k tokenizes the command line itself, it doesn't use the argument separation provided by Windows. Their command line parser is written in such a way that when a space is encountered as part of a filename or path, it considers that it must have reached the end of the filename. In the case of the comma-separated filename list at the end of the command line, the first time it encounters a space, it considers it must have reached the end of the entire list. If you send it the following command line:
    asm68k "source file.asm", "object file.bin"
    It will read in "source", but as soon as it reaches the first space, it will think it has reached the end of the list of filenames. When it encounters the start of the word "file", it will terminate and give you the error "Unexpected characters at end of command line".

    I don't know what the maximum number of include paths is, but it's a lot more than 4. One thing to be careful about is I've had to modify the way the /j option works to specify additional include paths. The command line parser needs to know when it has reached the end of the path. You might be getting the error you are getting because it can't find the end of the path.

    For include paths, asm68k originally knew it had reached the end of the path when it encountered a space. That rule no longer applies. I was going to make it mandatory to have to enclose all include paths with quotes, but due to the way their parser works, I would have had to make major modifications to pull that off. Instead, I made it necessary to terminate all include paths with an asterisk. Eg, if you want to specify an include path with my modified version, you need to use the following form:
    asm68k /j ".\Folder\Subfolder with spaces in name\*" "source.asm", "target.bin"

    Note the '*' at the end of the path. I modified the usage instructions for the program to indicate this. Yes, this rule kinda sux. I only did a simple modification to the binary to make these corrections however. Removing the need to give some kind of special character to indicate the end of the include path would have required rebuilding their command line parser. It wasn't worth it from my point of view.
     
  11. Puto

    Puto

    Shin'ichi Kudō, detective. Tech Member
    2,013
    0
    16
    Portugal, Oeiras
    Part of Team Megamix, but haven't done any actual work in ages.
    Uhm, this compiles. Quoting from it:

    Code (Text):
    1.         include "_inc\Special stage mappings and VRAM pointers.asm"
    I think that qualifies as "having spaces".

    EDIT: Oh, wait, you mean actually assembling a file with spaces rather than putting it in an include. Never mind then...
     
  12. Nemesis

    Nemesis

    Tech Member
    Heh, I just realised Tweaker was talking about the include directive too, not the command line.

    Yeah, it seems like asm68k has some fairly small buffers allocated for storing paths at several points, and since it fully resolves and stores the paths to all files it references, that severely limits the maximum path depth. The maximum path depth of any file referenced by an include seems to be around 65 characters. The maximum depth of any path specified on the command line seems to be around 100 characters.

    I'll see what I can do about raising the maximum. It could be really simple, or it could be an absolute nightmare. Depends on how they've coded it.
     
  13. nineko

    nineko

    I am the Holy Cat Tech Member
    6,364
    522
    93
    italy
    Guys, if you want to limit the number of subfolders you can just fake using the subst command.

    Subst Q: C:\batman\goku\vegeta\freepornforeveryone\lol\rofl\ftw\1337\turd\sup

    You'll get a virtual redirect to that long folder, so if you run something from Q: (or any other free letter) it will think that it's in the root folder.
     
  14. Nemesis

    Nemesis

    Tech Member
    Ok, the issue with path lengths was actually fairly simple. The problem occurred when the asm68k executable itself was in a deep subdirectory. A small buffer was being used to store the current working directory of the program in order to build relative paths. I've increased the buffer size from 0x60 bytes to 0xFF bytes. What that means is that this program should be able to reference any path up to 255 characters, either passed from the command line or specified in an include statement. That's the maximum path length that this program can possibly support, without shifting it to use a newer class of file I/o API.

    You can download the new edit from http://www.mediafire.com/?1gb36mznxtm
     
  15. Sik

    Sik

    Sik is pronounced as "seek", not as "sick". Tech Member
    6,718
    10
    0
    being an asshole =P
    Uh, bad news for you... Windows doesn't parse the command line, it just takes away the program name and sends the string straight to you in lpszCmdLine as one of the arguments of WinMain(). It's included in GetCommandLine(), but Windows never gives you all arguments separated. The program has to do it manually.

    Later I'll write here the parser I made for the ASL. It handles everything properly (as long as it's ASCII :P), takes into account quotes (single and double) and even more, doesn't have any limit on the number of arguments (it allocates as many memory as arguments are there), so the only limit you can have is imposed by Windows itself.
     
  16. Nemesis

    Nemesis

    Tech Member
    Well, first of all, asm68k is built as a console application, not a windows GUI application. This means they use the main() function, not WinMain(), so they are provided with argument separation. Secondly, all windows apps, even GUI apps which use WinMain, have access to the CommandLineToArgvW() function nowadays, which provides standard tokenization of the command line in unicode.

    Doing manual tokenization of the command line is rarely a good idea. There are times when it is justified, however there are quite a few subtleties to Windows command line parsing that are rarely emulated fully. Eg, does your parser acknowledge escape codes, such as \" to preserve quotes passed on the command line?
     
Thread Status:
Not open for further replies.