• Lucid Dreaming - Dream Views




    Page 1 of 2 1 2 LastLast
    Results 1 to 25 of 34

    Thread: C++ Problem

    1. #1
      Banned
      Join Date
      May 2007
      LD Count
      Loads
      Gender
      Location
      Digital Forest.
      Posts
      6,864
      Likes
      386

      C++ Problem

      I have a problem in this function, on the red line:

      Code:
      void CreateDivTable()
      {
        DivTbl[0] = 0x7fffffff;
        DivTbl[1] = 0x7fffffff;
        DivTbl[2] = 0x7fffffff;
        for( int i = 3; i < 10240; i++ )
           DivTbl[i] = (int) ( float(0x100000000 )/ i);
      
        for (int y=0; y<32; y++)
         for (int x=0; x<32; x++)
          RandomMap[y][x] = rand()%1024;
      }
      Here's the declaration of DivTbl:

      Code:
      _EXTORNOT   int     DivTbl[10240];
      The error states that:

      "integer constant is too large for 'long' type" on the red line, but changing the variable type (To something larger, like long long) has no effect.

      Help plz?

    2. #2
      Banned
      Join Date
      May 2007
      LD Count
      Loads
      Gender
      Location
      Digital Forest.
      Posts
      6,864
      Likes
      386
      Heh nvm.

      Had one too many zeros. (0x100000000)

    3. #3
      Member kichu's Avatar
      Join Date
      Oct 2005
      Gender
      Posts
      1,803
      Likes
      25
      DJ Entries
      40
      Yeah, that's what I was going to suggest.

      That, or this:

      Both are the solution, I'm pretty sure.

    4. #4
      Banned
      Join Date
      May 2007
      LD Count
      Loads
      Gender
      Location
      Digital Forest.
      Posts
      6,864
      Likes
      386
      New problem:

      Code:
      void Audio_MixSound(int DestAddr, int SrcAddr, int MixLen, int LVolume, int RVolume)
      {
      _asm {
             mov      edi, DestAddr
             mov      ecx, MixLen
             mov      esi, SrcAddr
           }
      
      SOUND_CYCLE :
      
      _asm {
             movsx    eax, word ptr [esi]
             imul     LVolume
             sar      eax, 16
             mov      bx, word ptr [edi]
      
             add      ax, bx
             jo       LEFT_CHECK_OVERFLOW
             mov      word ptr [edi], ax
             jmp      CYCLE_RIGHT
       }
      LEFT_CHECK_OVERFLOW :
      __asm {
             cmp      bx, 0
             js       LEFT_MAX_NEGATIVE
             mov      ax, 32767
             mov      word ptr [edi], ax
             jmp      CYCLE_RIGHT
      }
      LEFT_MAX_NEGATIVE :
      __asm  mov      word ptr [edi], -32767
      
      
      
      
      CYCLE_RIGHT :
      __asm {
             movsx    eax, word ptr [esi]
             imul     dword ptr RVolume
             sar      eax, 16
             mov      bx, word ptr [edi+2]
      
             add      ax, bx
             jo       RIGHT_CHECK_OVERFLOW
             mov      word ptr [edi+2], ax
             jmp      CYCLE_CONTINUE
      }
      RIGHT_CHECK_OVERFLOW :
      __asm {
             cmp      bx, 0
             js       RIGHT_MAX_NEGATIVE
             mov      word ptr [edi+2], 32767
             jmp      CYCLE_CONTINUE
      }
      RIGHT_MAX_NEGATIVE :
      __asm  mov      word ptr [edi+2], -32767
      
      CYCLE_CONTINUE :
      __asm {
             add      edi, 4
             add      esi, 2
             dec      ecx
             jnz      SOUND_CYCLE
      }
      My compiler (MinGW) doesn't recognize _asm; What linker/ compiler command do I need for this...?

    5. #5
      FBI agent Ynot's Avatar
      Join Date
      Oct 2005
      Gender
      Location
      Southend, Essex
      Posts
      4,337
      Likes
      14
      the GCC (including MinGW & Cygwin on Windows) uses the AT&T (UNIX) assembly format
      while MS uses the Intel format

      http://www.ibiblio.org/gferg/ldp/GCC...-HOWTO.html#s4

      btw,
      any particular reason you're using inline assembly?
      Last edited by Ynot; 08-13-2008 at 02:08 AM.

    6. #6
      Banned
      Join Date
      May 2007
      LD Count
      Loads
      Gender
      Location
      Digital Forest.
      Posts
      6,864
      Likes
      386
      Oh well shit.

      I'm not going to re-write 3000 Assembly functions!

      I'll use the compiler the code was originally used with then...

    7. #7
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935
      I think GNU is the standard. I know that you can do _asm with GNU.

      Also, are you doing command line compilation? I think you have to add a whole ton of crap to the make to do inline assembly.

      Also, maybe it's different for your compiler, but I always use references for parameters in inline assembly. I don't remember if you need to do that with GNU, I know one of them required you to do that.
      Code:
      mov      edi, [DestAddr]
             mov      ecx, [MixLen]
             mov      esi, [SrcAddr]

    8. #8
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935
      Why are you using your own sound routines? It might be easier to use OpenAL

    9. #9
      Banned
      Join Date
      May 2007
      LD Count
      Loads
      Gender
      Location
      Digital Forest.
      Posts
      6,864
      Likes
      386
      So I can or I can't keep the functions as-is?

      I didn't write the Assembly code-- This is apart of a game enginge I'm editing and adding to.

    10. #10
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935
      I would use OpenAL for a game, that way you are guaranteed that it will work.

      3000 audio commands in asm? What is the name of this engine that you're working on, it sounds really big.

    11. #11
      FBI agent Ynot's Avatar
      Join Date
      Oct 2005
      Gender
      Location
      Southend, Essex
      Posts
      4,337
      Likes
      14
      Quote Originally Posted by Seismosaur View Post
      So I can or I can't keep the functions as-is?
      you cannot use Intel style assembly with GCC

      I believe there are some pre-processor macros around to convert between the two syntaxes, but I have near zero experience with assembly inside C++

    12. #12
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935
      Yes you can I forget how though, some type of compiler flags. Try
      Code:
      -xchip=pentium5
      I' think that's actually something else, but there is a similar flag for the asm. I don't do command line, my IDE takes care of that.

    13. #13
      FBI agent Ynot's Avatar
      Join Date
      Oct 2005
      Gender
      Location
      Southend, Essex
      Posts
      4,337
      Likes
      14
      Quote Originally Posted by ninja9578 View Post
      Yes you can
      you're right,
      I just googled it

      Code:
      gcc -o my_program -masm=intel my_program.c

    14. #14
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935
      I find intel asm soooo much easier than the unix style one. How do people read that junk?

      You can do misp asm inline too if you are on a PPC computer like me

    15. #15
      FBI agent Ynot's Avatar
      Join Date
      Oct 2005
      Gender
      Location
      Southend, Essex
      Posts
      4,337
      Likes
      14
      I like to think I'm a fairly competent programmer
      but I draw the line at assembly

      now, I've never done anything game orientated
      I'm primarily database and web server middleware

      but seriously,
      does DIY assembly *really* make that much of a difference?
      (with all it's portability & bug pitfalls and show-stoppers)

      maybe it's cause I change my mind too often
      A minor re-jig to C code vs. scraping and re-writing pages of assembly

      anyway....

    16. #16
      Banned
      Join Date
      May 2007
      LD Count
      Loads
      Gender
      Location
      Digital Forest.
      Posts
      6,864
      Likes
      386
      Ausome, now I don't have to phuck around with other compilers!

    17. #17
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935
      Quote Originally Posted by Ynot View Post
      does DIY assembly *really* make that much of a difference?
      Assembly code is INSANELY fast. It also has a better memory footprint. I've never had a compiler make better asm than me (for small routines obviously.) Compilers are very liberal with the stack (liveliness analysis isn't very good), when I do something in asm I try to use the stack as little as possible, that usually means moving parts of the code around, which compilers have a hard time doing.

      I do graphics and when doing extensions for OpenGL or shaders, you have to use assembly because C just isn't fast enough, even with the 3 pass optimizer turned on.
      Last edited by ninja9578; 08-13-2008 at 03:02 AM.

    18. #18
      Banned
      Join Date
      May 2007
      LD Count
      Loads
      Gender
      Location
      Digital Forest.
      Posts
      6,864
      Likes
      386
      Okay, it worked, but it's taking forever to compile

    19. #19
      Banned
      Join Date
      May 2007
      LD Count
      Loads
      Gender
      Location
      Digital Forest.
      Posts
      6,864
      Likes
      386
      Actually, it didn't work.

      It just took forever and gave me 5x the errors...

    20. #20
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935
      Must be your C++ code, asm should be really fast to compiler. What other flags did you set, are you doing multiple passes?

      As for your errors: see post above about referencing with asm.

    21. #21
      Banned
      Join Date
      May 2007
      LD Count
      Loads
      Gender
      Location
      Digital Forest.
      Posts
      6,864
      Likes
      386
      None and no.

      I just put gcc -o my_program -masm=intel my_program.c twice for the two (huge) files that use inline assembly.

      It still doesn't recognize __asm { }

    22. #22
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935
      I see some errors in the programmer, are you sure this program worked once?

      Code:
      mov bx, word ptr [edi]
      Pointers are 64-bit, bx is 16-bit

    23. #23
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935
      Quote Originally Posted by Seismosaur View Post
      It still doesn't recognize __asm { }
      GCC accepts either asm or _asm_. You need either no underscores or two.

    24. #24
      Banned
      Join Date
      May 2007
      LD Count
      Loads
      Gender
      Location
      Digital Forest.
      Posts
      6,864
      Likes
      386
      Oh okay.

      Well I sure hope it did as it's a game engine for a video game that was once produced

      A few other people have managed to get it working, but I have limited contact with them.

    25. #25
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935
      I think most games are written in .NET which means a M$ compiler. I'm not sure if you can get that for free.

    Page 1 of 2 1 2 LastLast

    Bookmarks

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •