Compiling asmx

Talk about development tools here

Moderator: BigEvilCorporation

Post Reply
Pascal
Very interested
Posts: 200
Joined: Wed Nov 29, 2006 11:29 am
Location: Belgium
Contact:

Compiling asmx

Post by Pascal » Fri Jun 11, 2010 9:28 am

hello again :)

I'm trying to recompile asmx on windows (so i can modify it). I downloaded mingw.

So everytime i compile using mingw32-gcc *.c -o asmx

i got
asmguts.h:275: error: storage size of `opcdTab2' isn't known
asmz80.c:60: error: storage size of `opcdTab' isn't known

anyone got idea how to get rid of those error, knowing i can not define the size (dynamic) as the tabs are define like this:

struct OpcdRec opcdTab[] =
{
...

thanks in advance

pascal

User avatar
ronin68k
Interested
Posts: 25
Joined: Mon Nov 02, 2015 5:28 am
Location: Krasnodar, Russia

Re: Compiling asmx

Post by ronin68k » Thu Dec 28, 2017 12:50 pm

Good 2 see someone else with asmx problems (even if the thread is almost 8 years old :lol: )
When it comes to compilation, i don't have any troubles - not even warnings.
The problem is "incbin".
When I'm including binary, asmx cuts it at first seen "1A" byte there... That happens only on windows, when i compile asmx with mingw.
Another question is - there is a sonic hack, named "wtf lame" - its source consist asmx.exe which includes binaries without any problems and its size is pretty small... How did they do it!?

User avatar
Sik
Very interested
Posts: 705
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: Compiling asmx

Post by Sik » Thu Dec 28, 2017 1:56 pm

I'm guessing the file is opened in text mode ("r") instead of binary mode ("rb"). On *nix they're identical, but Windows converts between CRLF and LF. It'll also stop whenever it sees DOS EOF (which happens to be 0x1A).

You'll have to hunt down that fopen and replace the "r" with "rb".
Sik is pronounced as "seek", not as "sick".

User avatar
ronin68k
Interested
Posts: 25
Joined: Mon Nov 02, 2015 5:28 am
Location: Krasnodar, Russia

Re: Compiling asmx

Post by ronin68k » Thu Dec 28, 2017 11:47 pm

Sik wrote:
Thu Dec 28, 2017 1:56 pm
You'll have to hunt down that fopen and replace the "r" with "rb".
Thank you so much for solving my problem! I finally got rid of this annoying bug.
found it at asmx.c, line 4695

upd.
There also was a bug, adding 0D before 0A, replacing 0Fs with 00 and it probably did something else. I fixed it the same way:

Code: Select all

replaced
object = fopen(cl_ObjName, "w");

with
object = fopen(cl_ObjName, "wb");
And it solved a problem. Anyway, guys, tell me If i did something bad, haha :D

User avatar
Sik
Very interested
Posts: 705
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: Compiling asmx

Post by Sik » Sat Dec 30, 2017 2:32 pm

Yeah, literally the same issue (conversion of control codes). Didn't think 0x0F would be affected too though.

I'd have suggested to just go change all calls to fopen, but I imagine that you're probably using CRLF newlines in your source code and the assembler expecting LF and hence you need to keep the fopen to the source files as just "r" (so the conversion happens), so blindly changing everything would be a bad idea. For anything binary though it absolutely should be "rb"/"wb".
Sik is pronounced as "seek", not as "sick".

User avatar
ronin68k
Interested
Posts: 25
Joined: Mon Nov 02, 2015 5:28 am
Location: Krasnodar, Russia

Re: Compiling asmx

Post by ronin68k » Tue Jan 02, 2018 9:53 am

I'm so glad that I can use properly working native win-asmx, without Cygwin environment now! Thank you!
Asmx itself works just everywhere (even on my android, where I've built it with c4droid and even assembled a hack with it :lol: ).

User avatar
ronin68k
Interested
Posts: 25
Joined: Mon Nov 02, 2015 5:28 am
Location: Krasnodar, Russia

Re: Compiling asmx

Post by ronin68k » Thu Jan 04, 2018 2:18 pm

Ok, i found another bug (i think its also asmx source question).
asmx sees too big difference between "move.w 0(a1),d1" and "move.w 1(a1),d1".
When it's 1 or more, it gives correct code - 32 29 00 01, but when it's 0, it just gives 32 11 instead of 32 29 00 00.
How comes? :|

I'm trying to assemble original ROM from sources, so I found out there is a difference.
Asmx has interesting comments at 657 line - // 0(PC,Xn) 0(An,Xn) and // FIXME: reg1 can't be PC here?...

Code: Select all

            else if (token == ',')
            { // 0(PC,Xn) 0(An,Xn)
            // FIXME: reg1 can't be PC here?
                val = 0;
                reg2 = GetReg(DA_regs);
                if (reg2 == 16) reg2 = 15; // SP -> A7
                if (reg2 >= 0)
                {
                    // get Xn forced size if any
                    width = WID_W;
                    if (linePtr[0] == '.' && toupper(linePtr[1]) == 'L')
                    {
                        linePtr = linePtr + 2;
                        width = WID_L;
                    }
                    else if (linePtr[0] == '.' && toupper(linePtr[1]) == 'W')
                        linePtr = linePtr + 2;

                    //CheckByte(val); // zero IS a byte
                    if (RParen()) return FALSE;

                    if (reg1 == 9)
                    {
                        // (PC,Xn)
                        if (!store)
                        {
                            // val = val - locPtr - 2; // don't offset from PC
                            ea -> mode = 0x3B;
                            ea -> len = 1;
                            ea -> extra[0] = (reg2 << 12) + (val & 0xFF);
                            if (width == WID_L)
                                ea -> extra[0] |= 0x0800;
                            return TRUE;
                        }
                    }
                    else
                    {
                        // (An,Xn)
                        ea -> mode = 0x30 + reg1;
                        ea -> len = 1;
                        ea -> extra[0] = (reg2 << 12) + (val & 0xFF);
                        if (width == WID_L)
                            ea -> extra[0] |= 0x0800;
                        return TRUE;
                    }
                }
            }

User avatar
Sik
Very interested
Posts: 705
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: Compiling asmx

Post by Sik » Thu Jan 04, 2018 5:29 pm

Yeaaaaaah whenever it sees 0(An) it always optimizes it into (An) regardless of settings. Ran into it the hard way because it effectively makes MOVEP unusable with an offset of 0 >_> (MOVEP only supports nn(An) and not (An), so 0(An) becoming (An) literally made it not build). I had to fix it in my own copy.

I have a modified asmx to make it closer to asm68k syntax but the author never used a proper license and I lost contact with him so looks like I'm unable to release it legally for now.


EDIT: since we're talking about asmx bugs, another bug I had to fix is that it misassembles CMP An, An into CMP (An)+, (An)+. Was wondering why the code didn't work (expecting some dumb mistake) until I got so fed up I decided to look into the disassembler in Regen and noticed something was off there.
Sik is pronounced as "seek", not as "sick".

User avatar
ronin68k
Interested
Posts: 25
Joined: Mon Nov 02, 2015 5:28 am
Location: Krasnodar, Russia

Re: Compiling asmx

Post by ronin68k » Fri Jan 05, 2018 1:43 am

Have you uploaded the fixed asmx to github? I'd like to have it too, with your permission.

User avatar
Sik
Very interested
Posts: 705
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: Compiling asmx

Post by Sik » Fri Jan 05, 2018 7:38 am

That's the part I can't do because asmx doesn't have any proper license =/
Sik is pronounced as "seek", not as "sick".

User avatar
ronin68k
Interested
Posts: 25
Joined: Mon Nov 02, 2015 5:28 am
Location: Krasnodar, Russia

Re: Compiling asmx

Post by ronin68k » Sat Jan 06, 2018 6:28 am

Oh... Well then, can u guide me how to solve 0(an) / cmp(an)+ bugs? (if u don't mind ofc)

Chilly Willy
Very interested
Posts: 2586
Joined: Fri Aug 17, 2007 9:33 pm

Re: Compiling asmx

Post by Chilly Willy » Sat Jan 06, 2018 9:38 pm

Post a diff file, then. That should be fine regardless of the license (or lack thereof).

User avatar
Sik
Very interested
Posts: 705
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: Compiling asmx

Post by Sik » Sun Jan 07, 2018 4:57 am

Good call... especially because I forgot what change I had made was the one that fixed the CMP issue =/

asm68k.c:

Code: Select all

--- asm68k-asmx.c	2016-07-12 22:05:50.444463000 -0300
+++ asm68k-sikasm.c	2016-07-28 05:19:36.954015000 -0300
@@ -892,12 +892,14 @@
                             }
                             else
                             {
+                                /*
                                 if (evalKnown && val == 0)
                                 {
                                     // 010 (An)
                                     ea -> mode = 0x10 + reg1;
                                     return TRUE;
                                 }
+                                */
 
                                 // d16(An)
                                 CheckWord(val);
@@ -1159,7 +1161,8 @@
                     val = EvalBranch(2);
                     if (val == 0)
                     {
-                        Warning("Short branch can not have zero offset!");
+                        //Warning("Short branch can not have zero offset!");
+                        Error("Short branch can not have zero offset!");
                         InstrW(0x4E71); // assemble a NOP instead of a zero branch
                     }
                     else InstrW((parm & 0xFF00) + (val & 0x00FF));
@@ -1182,8 +1185,8 @@
                          InstrW((parm & 0xFF00) + (val & 0x00FF));
                     else
                     {
-                        if (val != 0 && -128 <= val && val <= 129) // max is +129 because short branch saves 2 bytes
-                            Warning("Short branch could be used here");
+                        //if (val != 0 && -128 <= val && val <= 129) // max is +129 because short branch saves 2 bytes
+                        //    Warning("Short branch could be used here");
                         InstrWW(parm & 0xFF00,val);
                     }
 #endif
@@ -1191,8 +1194,8 @@
 #endif
                 case WID_W:
                     val = EvalWBranch(2);
-                    if (val != 0 && -128 <= val && val <= 129) // max is +129 because short branch saves 2 bytes
-                        Warning("Short branch could be used here");
+                    //if (val != 0 && -128 <= val && val <= 129) // max is +129 because short branch saves 2 bytes
+                    //    Warning("Short branch could be used here");
                     InstrWW(parm & 0xFF00,val);
                     break;
 
@@ -1510,8 +1513,8 @@
                                 case 0xB000: // CMP/EOR
                                     if (reg2 & 0x8000) // disallow EOR
                                     {
-                                        InstrWE((parm & 0xF000) + (reg1 << 9) + (size << 7) + 0x40, &ea1);
-                                    //    IllegalOperand();
+                                        //InstrWE((parm & 0xF000) + (reg1 << 9) + (size << 7) + 0x40, &ea1);
+                                        InstrWE((parm & 0xF000) + (reg1 << 9) + (size << 7) + 0xC0, &ea1);
                                         break;
                                     }
                                 default:
@@ -1771,6 +1774,18 @@
                 {
                     reg1 = ea1.mode & 7;
                     reg2 = ea2.mode & 7;
+                    
+                    if ((ea1.mode & 0x38) == 0x10) {
+                        ea1.mode &= ~0x38;
+                        ea1.mode |= 0x28;
+                        ea1.extra[0] = 0;
+                    }
+                    if ((ea2.mode & 0x38) == 0x10) {
+                        ea2.mode &= ~0x38;
+                        ea2.mode |= 0x28;
+                        ea2.extra[0] = 0;
+                    }
+                    
                     if ((ea1.mode & 0x38) == 0x00 && (ea2.mode & 0x38) == 0x28)
                         InstrWW(parm + (reg1 << 9) + reg2 + 0x0080, ea2.extra[0]); // Dx,(d16,Ay)
                     else if ((ea1.mode & 0x38) == 0x28 && (ea2.mode & 0x38) == 0x00)
Sik is pronounced as "seek", not as "sick".

User avatar
ronin68k
Interested
Posts: 25
Joined: Mon Nov 02, 2015 5:28 am
Location: Krasnodar, Russia

Re: Compiling asmx

Post by ronin68k » Sun Jan 07, 2018 7:57 am

thanks, guys :D

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests