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

0 Members and 1 Guest are viewing this topic.

Offline Frederick J. Harris

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1012
  • 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 »

Offline Patrice Terrier

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2396
  • 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

Offline Patrice Terrier

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2396
  • 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: 672
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

Offline Patrice Terrier

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2396
  • 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

Offline Patrice Terrier

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2396
  • Gender: Male
    • www.zapsolution.com
Re: TCLib update for Patrice
« Reply #36 on: March 25, 2017, 05:13:40 PM »
James, Fred,

I have attached the latest Visual Studio 2015/2017 TCLIB version of my 64-bit OpenGL plugins
to this post
C++bbp_plugins64.zip

The smallest dll is only 13 Kb.
« Last Edit: March 25, 2017, 05:51:38 PM by Patrice Terrier »
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Offline James C. Fuller

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 672
Re: TCLib update for Patrice
« Reply #37 on: March 26, 2017, 07:32:59 PM »
Thanks Patrice,
  I realize now why you were having problems with rand and srand as I found issues with my own work.
I assume one of your included files:
  #include <gl/GL.h>
  #include <gl/GLU.h>
is pulling in <stdlib.h> or one of the other msvcrt include files.

I had done a lot of successful testing originally with my port of José's CWindow and Afx framework but when I tried with my latest version of TCLib I had a number of redefinition errors.
I was including:
   #include <psapi.h>
   #include <Shlobj.h>
   #include <KnownFolders.h>
   #include <shlwapi.h>
   #include <commctrl.h>
   #include <uxtheme.h>
and at least one of them is pulling in msvcrt include files.

I write all my bc9Basic code as ansi. I then parse the c++ translated code with the ULEX utility which does all the transformations. I can name the library function tcl_rand and translate the source "rand" call to tcl_rand on the fly.
I am scratching my head though as only a few are a causing problems.

James