Author Topic: TCLib update for Patrice  (Read 608 times)

0 Members and 1 Guest are viewing this topic.

Offline Frederick J. Harris

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1005
  • Gender: Male
    • Frederick J. Harris
Re: TCLib update for Patrice
« Reply #30 on: March 10, 2017, 10:22:07 PM »
Quote
The ISO standard declares a compatible C rand() function's exact range to be entirely compiler implementation dependent but states that it be at least 0 thru 32767 inclusive. As it happens, both VC and GCC define their RAND_MAX value as 0x7FFF, which is exactly 32767 decimal.

That's the number I thought RAND_MAX was equal to for VC and GCC Mike, but I didn't want to state it without checking.  At the time I needed it (rand()), I needed numbers from about a million to 50,000,000, so I had to devise something to produce them.  I'm not really sure what's in the C++ Standard Library (if anything), relating to a C++ version of rand().

Offline Charles Pegge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 734
    • Charles Pegge
Re: TCLib update for Patrice
« Reply #31 on: March 11, 2017, 01:58:55 AM »
This is a satisfactory, though home-made 32-bit pseudo-randomizer. It churns integers but scales them to return floats -1.0 to +1.0. To return 32bit integer ranges, omit the float scaler and return the raw integer value in eax instead.

Code: [Select]
  int seed=0x12345678
  '
  function Rnd() as float
  =======================
  Static As float f, d=1/0x7fffffff
  mov eax,seed
  inc eax
  rol eax,13
  xor eax,0xdab5ca3a
  mov seed,eax
  push eax
  fild dword [esp]
  pop eax
  fmul dword d
  fstp dword f
  return f
  end function

You are probably familiar with this one from the web, based on mul overflows into edx.
The 2 inputs are the lower and upper range limits:

Code: [Select]
  function irnd(int z1, z2) as int
  ================================
  mov    eax,z2
  sub    eax,z1
  inc    eax
  imul   edx,Seed,0x8088405
  inc    edx
  mov    Seed,edx 'store new seed
  mul    edx 'multiply eax by edx
  return edx+z1
  end Function
« Last Edit: March 11, 2017, 02:07:09 AM by Charles Pegge »

Online Patrice Terrier

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2370
  • Gender: Male
    • www.zapsolution.com
Re: TCLib update for Patrice
« Reply #32 on: March 11, 2017, 10:46:59 AM »
The TCLib version of the Visual Studio community 2015 has been attached to this post
http://www.jose.it-berater.org/smfforum/index.php?topic=5176.msg22444#msg22444

Thank you all, for having helped me to produce these amazing small 64-bit DLL(s), without using any compressor !
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Online Patrice Terrier

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2370
  • Gender: Male
    • www.zapsolution.com
Re: TCLib update for Patrice
« Reply #33 on: March 21, 2017, 11:03:06 AM »
So far i have been able to create my smallest OpenGL 64-bit plugin, only 13 Kb.

And i was able to reduce the size of my PNGanim project from 140 Kb down to 60 Kb, using GetprocAdress to access directly to MSVCRT, the only thing that is causing me havoc, is when there are multiple optional parameters like for swprintf, and i don't know the syntax to use to create the prototype to use the "...".

« Last Edit: March 21, 2017, 11:05:13 AM by Patrice Terrier »
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Offline James C. Fuller

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 658
Re: TCLib update for Patrice
« Reply #34 on: March 21, 2017, 11:11:18 AM »
Patrice,
  Take a look at the TCLib\stdio.h file.

James

Online Patrice Terrier

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2370
  • Gender: Male
    • www.zapsolution.com
Re: TCLib update for Patrice
« Reply #35 on: March 21, 2017, 02:21:47 PM »
James--

I have seen it already, but what i am looking for is a replacement for the PowerBASIC statement "AS ANY"
without using va_list


Currently i am doing this to use swprintf with long, and i must have another function for float, double, etc.
Code: [Select]
#define long_proc_c typedef long (__cdecl *zProc)

HMODULE MSVCRT() {
    static HMODULE hModule;
    if (hModule == 0) { hModule = LoadLibrary(L"MSVCRT"); }
    return hModule;
}

long long_swprintf(OUT WCHAR* buffer, IN WCHAR* format, IN long N) {
    long nRet = -1; // Error
    HMODULE hModule = MSVCRT();
    if (hModule) {
        long_proc_c (WCHAR*, WCHAR*, long);
        zProc hProc = (zProc)GetProcAddress(hModule, "swprintf");
        if (hProc) { nRet = hProc(buffer, format, N); }
    }
    return nRet;
}
« Last Edit: March 21, 2017, 02:28:20 PM by Patrice Terrier »
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com