Skip to content

Commit

Permalink
Update Glulxe to 0.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ptomato committed Oct 20, 2023
1 parent a7727e8 commit 121bea7
Show file tree
Hide file tree
Showing 13 changed files with 294 additions and 118 deletions.
2 changes: 1 addition & 1 deletion interpreters/glulxe/LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License

Copyright (c) 1999-2016, Andrew Plotkin
Copyright (c) 1999-2023, Andrew Plotkin

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
22 changes: 18 additions & 4 deletions interpreters/glulxe/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Glulxe: the Glulx VM interpreter

- Version 0.6.0
- Version 0.6.1
- Designed by Andrew Plotkin <[email protected]>
- [Glulx home page][glulx]

Expand All @@ -14,8 +14,11 @@ the [Glk home page][glk].

The Unix Makefile that comes with this package is designed to link any
of the Unix libraries (CheapGlk, GlkTerm, RemGlk, etc.) You'll have to go
into the Makefile and set three variables to find the library. There are
instructions at the top of the Makefile. Then just type
into the Makefile and set three variables to find the library. You'll also
want to set the appropriate OS_* constants on the OPTIONS line. There are
instructions at the top of the Makefile.

Then just type

make glulxe

Expand Down Expand Up @@ -117,8 +120,19 @@ display the update, and then (without delay) exit.

## Version

0.6.1 (Oct 9, 2023)

- Added a --rngseed argument to fix the RNG setting from the command
line.
- Changed the built-in RNG to xoshiro**. Added configuration defs to
use a native OS RNG where possible.
- Fixed obscure corner case in pow(), powf() on some platforms.
- Configuration improvements for Windows.

0.6.0 (Jun 25, 2022):

- Added @hasundo and @discardundo opcodes. (Glulx spec 3.1.3.)
- Added the double-precision opcodes. (Glulx spec 3.1.3.)
- Added autosave support to the Unix startup code. (Previously the
autosave support only existed in the iOS startup code, which was
ObjC.) Autosave now works with the RemGlk library.
Expand Down Expand Up @@ -274,7 +288,7 @@ display the update, and then (without delay) exit.

## Permissions

The source code in this package is copyright 1999-2016 by Andrew Plotkin.
The source code in this package is copyright 1999-2023 by Andrew Plotkin.
It is distributed under the MIT license; see the "[LICENSE][]" file.

[LICENSE]: ./LICENSE
18 changes: 9 additions & 9 deletions interpreters/glulxe/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ void execute_loop()
first. They have to be unsigned values, too, otherwise the
0x80000000 case goes wonky. */
if (vals0 < 0) {
val0 = (-vals0);
val0 = (-(glui32)vals0);
if (vals1 < 0) {
val1 = (-vals1);
val1 = (-(glui32)vals1);
value = val0 / val1;
}
else {
Expand All @@ -137,7 +137,7 @@ void execute_loop()
else {
val0 = vals0;
if (vals1 < 0) {
val1 = (-vals1);
val1 = (-(glui32)vals1);
value = -(val0 / val1);
}
else {
Expand All @@ -153,13 +153,13 @@ void execute_loop()
if (vals1 == 0)
fatal_error("Division by zero doing remainder.");
if (vals1 < 0) {
val1 = -vals1;
val1 = -(glui32)vals1;
}
else {
val1 = vals1;
}
if (vals0 < 0) {
val0 = (-vals0);
val0 = (-(glui32)vals0);
value = -(val0 % val1);
}
else {
Expand All @@ -170,7 +170,7 @@ void execute_loop()
break;
case op_neg:
vals0 = inst[0].value;
value = (-vals0);
value = (-(glui32)vals0);
store_operand(inst[1].desttype, inst[1].value, value);
break;

Expand Down Expand Up @@ -527,7 +527,7 @@ void execute_loop()
vals1 = (vals0) - vals1;
}
else {
vals1 = (-vals1) % vals0;
vals1 = (-(glui32)vals1) % vals0;
}
if (vals1 == 0)
break;
Expand Down Expand Up @@ -663,7 +663,7 @@ void execute_loop()
else if (vals0 >= 1)
value = glulx_random() % (glui32)(vals0);
else
value = -(glulx_random() % (glui32)(-vals0));
value = -(glulx_random() % (glui32)(-(glui32)vals0));
store_operand(inst[1].desttype, inst[1].value, value);
break;
case op_setrandom:
Expand Down Expand Up @@ -1198,7 +1198,7 @@ void execute_loop()
case op_dpow:
vald1 = decode_double(inst[0].value, inst[1].value);
vald2 = decode_double(inst[2].value, inst[3].value);
encode_double(pow(vald1, vald2), &val0hi, &val0lo);
encode_double(glulx_pow(vald1, vald2), &val0hi, &val0lo);
store_operand(inst[4].desttype, inst[4].value, val0lo);
store_operand(inst[5].desttype, inst[5].value, val0hi);
break;
Expand Down
6 changes: 4 additions & 2 deletions interpreters/glulxe/gestalt.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ glui32 do_gestalt(glui32 val, glui32 val2)
return 0x00030103; /* Glulx spec version 3.1.3 */

case gestulx_TerpVersion:
return 0x00000600; /* Glulxe version 0.6.0 */
return 0x00000601; /* Glulxe version 0.6.1 */

case gestulx_ResizeMem:
#ifdef FIXED_MEMSIZE
Expand All @@ -25,7 +25,9 @@ glui32 do_gestalt(glui32 val, glui32 val2)
#endif /* FIXED_MEMSIZE */

case gestulx_Undo:
return 1; /* We can handle saveundo and restoreundo. */
if (max_undo_level > 0)
return 1; /* We can handle saveundo and restoreundo. */
return 0; /* Got "--undo 0", so nope. */

case gestulx_IOSystem:
switch (val2) {
Expand Down
7 changes: 5 additions & 2 deletions interpreters/glulxe/glkop.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
#define ReleaseVMUstring(ptr) \
(free_temp_ustring(ptr))

#include <time.h>
#include "glk.h"
#include "glulxe.h"
#include "gi_dispa.h"
Expand Down Expand Up @@ -178,6 +179,7 @@ static char *get_game_id(void);
int 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. */
Expand All @@ -196,9 +198,10 @@ int init_dispatch()
* sizeof(classtable_t *));
if (!classes)
return FALSE;


randish = time(NULL) % 101;
for (ix=0; ix<num_classes; ix++) {
classes[ix] = new_classtable((glulx_random() % (glui32)(101)) + 1);
classes[ix] = new_classtable(1+120*ix+randish);
if (!classes[ix])
return FALSE;
}
Expand Down
16 changes: 7 additions & 9 deletions interpreters/glulxe/glulxe.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ typedef int16_t glsi16;
/* Some macros to read and write integers to memory, always in big-endian
format. */
#define Read4(ptr) \
( (glui32)(((unsigned char *)(ptr))[0] << 24) \
| (glui32)(((unsigned char *)(ptr))[1] << 16) \
| (glui32)(((unsigned char *)(ptr))[2] << 8) \
| (glui32)(((unsigned char *)(ptr))[3]))
( (glui32)((glui32)((unsigned char *)(ptr))[0] << 24) \
| (glui32)((glui32)((unsigned char *)(ptr))[1] << 16) \
| (glui32)((glui32)((unsigned char *)(ptr))[2] << 8) \
| (glui32)((glui32)((unsigned char *)(ptr))[3]))
#define Read2(ptr) \
( (glui16)(((unsigned char *)(ptr))[0] << 8) \
| (glui16)(((unsigned char *)(ptr))[1]))
Expand Down Expand Up @@ -195,6 +195,7 @@ extern void (*stream_char_handler)(unsigned char ch);
extern void (*stream_unichar_handler)(glui32 ch);

/* main.c */
extern glui32 init_rng_seed;
extern void set_library_start_hook(void (*)(void));
extern void set_library_autorestore_hook(void (*)(void));
extern void fatal_error_handler(char *str, char *arg, int useval, glsi32 val) GLK_ATTRIBUTE_NORETURN;
Expand Down Expand Up @@ -383,11 +384,6 @@ extern int init_float(void);
extern glui32 encode_float(gfloat32 val);
extern gfloat32 decode_float(glui32 val);

/* Uncomment this definition if your powf() function does not support
all the corner cases specified by C99. If you uncomment this,
osdepend.c will provide a safer implementation of glulx_powf(). */
/* #define FLOAT_COMPILE_SAFER_POWF (1) */

extern gfloat32 glulx_powf(gfloat32 val1, gfloat32 val2);

#ifdef DOUBLE_SUPPORT
Expand All @@ -399,6 +395,8 @@ typedef double gfloat64;
extern void encode_double(gfloat64 val, glui32 *reshi, glui32 *reslo);
extern gfloat64 decode_double(glui32 valhi, glui32 vallo);

extern gfloat64 glulx_pow(gfloat64 val1, gfloat64 val2);

#endif /* DOUBLE_SUPPORT */

#endif /* FLOAT_SUPPORT */
Expand Down
4 changes: 3 additions & 1 deletion interpreters/glulxe/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ glui32 gamefile_len = 0; /* The length within the stream. */
char *init_err = NULL;
char *init_err2 = NULL;

glui32 init_rng_seed = 0;

/* The library_start_hook is called at the beginning of glk_main. This
is not normally necessary -- the library can do all its setup work
before calling glk_main -- but iosglk has some weird cases which
Expand Down Expand Up @@ -49,7 +51,7 @@ void glk_main()
return;
}

glulx_setrandom(0);
glulx_setrandom(init_rng_seed);
#ifdef FLOAT_SUPPORT
if (!init_float()) {
return;
Expand Down
3 changes: 1 addition & 2 deletions interpreters/glulxe/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ glulxe = shared_module('glulxe', 'accel.c', 'debugger.c', 'exec.c', 'files.c',
'operand.c', 'osdepend.c', 'profile.c', 'search.c', 'serial.c', 'string.c',
'unixautosave.c', 'unixstrt.c', 'vm.c',
name_prefix: '',
# Workaround for float issue https://github.com/erkyrath/glulxe/issues/31
c_args: ['-DOS_UNIX', '-DFLOAT_COMPILE_SAFER_POWF', glulxe_extraflags],
c_args: ['-DOS_UNIX', '-DUNIX_RAND_GETRANDOM', glulxe_extraflags],
include_directories: '../../libchimara',
link_args: plugin_link_args, link_depends: plugin_link_depends,
install: true, install_dir: plugindir)
Expand Down
Loading

0 comments on commit 121bea7

Please sign in to comment.