• Lucid Dreaming - Dream Views




    Results 1 to 25 of 34

    Thread: C++ Problem

    Hybrid View

    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.

    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
    •