Skip to content

Commit

Permalink
Update Git to 1.3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
ptomato committed Oct 20, 2023
1 parent 121bea7 commit 7799b15
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 640 deletions.
29 changes: 29 additions & 0 deletions interpreters/git/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Git

Git is an interpreter for the [Glulx](https://eblong.com/zarf/glulx/) virtual machine, which is widely used to play interactive fiction (text adventure) games created with [Inform 7](http://inform7.com/).

Git's main goal in life is to be fast. It's about five times faster than [Glulxe](https://github.com/erkyrath/glulxe), and about twice as fast as Frotz (using the same Inform source compiled for the Z-machine). It also tries to be reasonably careful with memory: it's possible to trade speed off against memory by changing the sizes of Git's internal buffers.

To be compiled into a useable program, Git needs to be built against a [Glk](https://eblong.com/zarf/glk/) library to provide it with a user interface. Included with Git are the source files needed to compile against [Windows Glk](https://github.com/DavidKinder/Windows-Glk), and the latest release on this GitHub project also includes a Windows executable build of Git with Windows Glk.

![Windows Git playing Alabaster](Alabaster.png)

## Building on Windows

Download and install Visual Studio 2019 Community edition from https://visualstudio.microsoft.com/. In the installer, make sure that "C++ Clang Compiler for Windows" and "C++ Clang tools for Windows" are selected.

To be able to build the CHM help file, download and install Microsoft's [HTML Help Workshop](https://web.archive.org/web/20200810052030/https://www.microsoft.com/en-us/download/confirmation.aspx?id=21138). Note that this is a link to the version on the Internet Archive as the link to this on Microsoft's site does not work at the moment.

Install git (that is, the distributed version control system). I use the version of git that is part of Cygwin, a Linux-like environment for Windows, but Git for Windows can be used from a Windows command prompt.

Open the environment that you are using git from (e.g. Cygwin), and switch to the root directory that the build environment will be created under (from here referred to as "\<root>"). Clone this repository with git:
```
git clone https://github.com/DavidKinder/Git.git Adv/Git
```

Download the latest release of the Windows Glk library from https://github.com/DavidKinder/Windows-Glk/releases/ and copy everything in the WindowsGlk-nnn.zip archive to "\<root>/Adv/Git/win/WindowsGlk".

### Compiling the project

Start Visual Studio, open the solution "\<root>/Adv/Git/win/Git.sln", then build and run the "Git" project.

5 changes: 4 additions & 1 deletion interpreters/git/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,10 @@ also to Eliuk Blau for tracking down bugs in the memory management opcodes.

* Version History

1.3.7 ####-##-## Added new undo and double precision math related opcodes
1.3.8 2023-10-12 Use either a native random number generator, or the
xoshiro128** algorithm, taken from Glulxe.

1.3.7 2022-07-12 Added new undo and double precision math related opcodes
(VM spec 3.1.3), contributed by Andrew Plotkin.

1.3.6 2021-05-25 Direct threading now works for 64 bit builds.
Expand Down
3 changes: 3 additions & 0 deletions interpreters/git/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
// Define this if we can use the "inline" keyword.
// #define USE_INLINE

// Define this to use a function native_random() to get random numbers.
// #define USE_NATIVE_RANDOM

// Define this to memory-map the game file to speed up loading. (Unix-specific)
// #define USE_MMAP

Expand Down
3 changes: 1 addition & 2 deletions interpreters/git/git.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ extern git_sint32* gStackPointer;

extern enum IOMode gIoMode;

extern glui32 lo_random ();
extern void lo_seed_random (glui32 seed);
extern glui32 native_random ();

extern void startProgram (size_t cacheSize);

Expand Down
9 changes: 9 additions & 0 deletions interpreters/git/git_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,12 @@ void glk_main ()
}

#endif // USE_MMAP

#ifdef USE_NATIVE_RANDOM

glui32 native_random()
{
return arc4random();
}

#endif // USE_NATIVE_RANDOM
8 changes: 5 additions & 3 deletions interpreters/git/glkop.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@

#define glulx_malloc malloc
#define glulx_free free
#define glulx_random lo_random

#ifndef TRUE
#define TRUE 1
Expand All @@ -109,6 +108,7 @@
#define FALSE 0
#endif

#include <time.h>
#include "glk.h"
#include "git.h"
#include "gi_dispa.h"
Expand Down Expand Up @@ -270,7 +270,8 @@ static maybe_unused char *get_game_id(void);
int git_init_dispatch()
{
int ix;

int randish;

/* What with one thing and another, this *could* be called more than
once. We only need to allocate the tables once. */
if (git_classes)
Expand All @@ -289,8 +290,9 @@ int git_init_dispatch()
if (!git_classes)
return FALSE;

randish = time(NULL) % 101;
for (ix=0; ix<num_classes; ix++) {
git_classes[ix] = new_classtable((glulx_random() % (glui32)(101)) + 1);
git_classes[ix] = new_classtable(1+120*ix+randish);
if (!git_classes[ix])
return FALSE;
}
Expand Down
2 changes: 1 addition & 1 deletion interpreters/git/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
git_version = configuration_data({
'GIT_MAJOR': 1,
'GIT_MINOR': 3,
'GIT_PATCH': 7,
'GIT_PATCH': 8,
})
git_version_h = configure_file(configuration: git_version, output: 'version.h')

Expand Down
122 changes: 89 additions & 33 deletions interpreters/git/terp.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,38 +35,85 @@ enum IOMode gIoMode = IO_NULL;
// -------------------------------------------------------------
// Random number generator, from Glulxe

static glui32 rand_table[55]; /* State for the RNG. */
static int rand_index1, rand_index2;
static glui32 xo_random(void);
static void xo_seed_random(glui32 seed);

glui32 lo_random()
static int rand_use_native = 1;

/* Set the random-number seed, and also select which RNG to use.
*/
void git_seed_random(glui32 seed)
{
rand_index1 = (rand_index1 + 1) % 55;
rand_index2 = (rand_index2 + 1) % 55;
rand_table[rand_index1] = rand_table[rand_index1] - rand_table[rand_index2];
return rand_table[rand_index1];
if (seed == 0)
{
rand_use_native = 1;
xo_seed_random(time(NULL));
}
else
{
rand_use_native = 0;
xo_seed_random(seed);
}
}

void lo_seed_random(glui32 seed)
/* Return a random number in the range 0 to 2^32-1. */
glui32 git_random()
{
glui32 k = 1;
int i, loop;

rand_table[54] = seed;
rand_index1 = 0;
rand_index2 = 31;

for (i = 0; i < 55; i++) {
int ii = (21 * i) % 55;
rand_table[ii] = k;
k = seed - k;
seed = rand_table[ii];
}
for (loop = 0; loop < 4; loop++) {
for (i = 0; i < 55; i++)
rand_table[i] = rand_table[i] - rand_table[ (1 + i + 30) % 55];
#ifdef USE_NATIVE_RANDOM
if (rand_use_native)
return native_random();
#endif
return xo_random();
}

/* This is the "xoshiro128**" random-number generator and seed function.
Adapted from: https://prng.di.unimi.it/xoshiro128starstar.c
About this algorithm: https://prng.di.unimi.it/
*/
static uint32_t xo_table[4];

static void xo_seed_random(glui32 seed)
{
int ix;
/* Set up the 128-bit state from a single 32-bit integer. We rely
on a different RNG, SplitMix32. This isn't high-quality, but we
just need to get a bunch of bits into xo_table. */
for (ix=0; ix<4; ix++) {
seed += 0x9E3779B9;
glui32 s = seed;
s ^= s >> 15;
s *= 0x85EBCA6B;
s ^= s >> 13;
s *= 0xC2B2AE35;
s ^= s >> 16;
xo_table[ix] = s;
}
}

static glui32 xo_random(void)
{
/* I've inlined the utility function:
rotl(x, k) => (x << k) | (x >> (32 - k))
*/

const uint32_t t1x5 = xo_table[1] * 5;
const uint32_t result = ((t1x5 << 7) | (t1x5 >> (32-7))) * 9;

const uint32_t t1s9 = xo_table[1] << 9;

xo_table[2] ^= xo_table[0];
xo_table[3] ^= xo_table[1];
xo_table[1] ^= xo_table[2];
xo_table[0] ^= xo_table[3];

xo_table[2] ^= t1s9;

const uint32_t t3 = xo_table[3];
xo_table[3] = ((t3 << 11) | (t3 >> (32-11)));

return result;
}

// -------------------------------------------------------------
// Floating point support

Expand Down Expand Up @@ -135,6 +182,18 @@ static int doubleCompare(git_sint32 L1, git_sint32 L2, git_sint32 L3, git_sint32
return ((D1 <= D2) && (D1 >= -D2));
}

static void testDouble()
{
glui32 PI_hi = 0x400921FB;
glui32 PI_lo = 0x54442D18;
git_double pi = DECODE_DOUBLE(PI_hi, PI_lo);
if (!(pi > 3.1415 && pi < 3.1416)) {
// If this fails, on a big-endian system, check that USE_BIG_ENDIAN
// or USE_BIG_ENDIAN_UNALIGNED have been defined in config.h
fatalError("Test decode of double precision value failed");
}
}

// -------------------------------------------------------------
// Functions

Expand Down Expand Up @@ -186,10 +245,11 @@ void startProgram (size_t cacheSize)
# endif
#endif

testDouble ();
initCompiler (cacheSize);

// Initialise the random number generator.
lo_seed_random (time(NULL));
git_seed_random (0);

// Set up the stack.

Expand All @@ -214,10 +274,6 @@ void startProgram (size_t cacheSize)
#define NEXT goto next
//#define NEXT do { CHECK_USED(0); CHECK_FREE(0); goto next; } while (0)
next:
#ifdef GIT_NEED_TICK
glk_tick();
#endif

switch (*pc++)
{
#define LABEL(foo) case label_ ## foo: goto do_ ## foo;
Expand Down Expand Up @@ -1262,17 +1318,17 @@ do_S1_addr8: memWrite8 (READ_PC, S1); NEXT;

do_random:
if (L1 > 0)
S1 = lo_random () % L1;
S1 = git_random () % L1;
else if (L1 < 0)
S1 = -(lo_random () % -L1);
S1 = -(git_random () % -L1);
else
{
S1 = lo_random ();
S1 = git_random ();
}
NEXT;

do_setrandom:
lo_seed_random (L1 ? L1 : time(NULL));
git_seed_random (L1);
NEXT;

do_glk:
Expand Down
Binary file removed interpreters/git/test/Alabaster.gblorb
Binary file not shown.
Loading

0 comments on commit 7799b15

Please sign in to comment.