Skip to content

Commit

Permalink
Merge pull request #76 from curiousdannii/glkkit
Browse files Browse the repository at this point in the history
IE-0012: Glk foundations
  • Loading branch information
ganelson authored Jul 23, 2024
2 parents 23bc125 + c56f0fe commit 3120746
Show file tree
Hide file tree
Showing 24 changed files with 2,093 additions and 1,015 deletions.
190 changes: 187 additions & 3 deletions inform7/Internal/Extensions/Graham Nelson/Basic Inform.i7x
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ Use dictionary resolution of at least 6 translates as the configuration value
DICT_RESOLUTION in BasicInformKit.
Use no automatic plural synonyms translates as the configuration flag
NO_AUTO_PLURAL_NAMES in BasicInformKit.
Use no status window translates as the configuration flag NO_STATUS_WINDOW
in BasicInformKit.
Use manual line input echoing translates as the configuration flag
MANUAL_INPUT_ECHOING in BasicInformKit.

Use dynamic memory allocation of at least 8192 translates as the configuration
value STACK_FRAME_CAPACITY in BasicInformKit.
Expand Down Expand Up @@ -171,11 +175,14 @@ Section - Startup C (for Glulx only)
The recover Glk objects rule is listed in the before starting the virtual machine rules.
The recover Glk objects rule translates into Inter as "GGRecoverObjects".

The set default stylehints rule is listed in the before starting the virtual machine rules.
The set default stylehints rule translates into Inter as "SET_DEFAULT_STYLEHINTS_R".

The sound channel initialisation rule is listed in the for starting the virtual machine rules.
The sound channel initialisation rule translates into Inter as "SOUND_CHANNEL_INIT_R".

The open built-in windows rule is listed in the for starting the virtual machine rules.
The open built-in windows rule translates into Inter as "OPEN_BUILT_IN_WINDOWS_R".
The open built in windows rule is listed in the for starting the virtual machine rules.
The open built in windows rule translates into Inter as "OPEN_BUILT_IN_WINDOWS_R".

The display captured startup text rule is listed in the for starting the virtual machine rules.
The display captured startup text rule translates into Inter as "END_CAPTURE_STARTUP_TEXT_R".
Expand Down Expand Up @@ -1521,7 +1528,184 @@ Section 1 - Numerical Value
To decide what number is the numerical value of (U - a use option):
(- USE_OPTION_VALUES-->({U}) -).

Part Four - Adjectival Definitions
Part Four - Glulx and Glk (for Glulx only)

Chapter - Glk and Glulx feature testing

To decide whether (F - glk feature) is/are supported:
(- Cached_Glk_Gestalts-->({F}) -).

To decide what number is the glk version number/--:
(- Cached_Glk_Gestalts-->gestalt_Version -).

To decide whether buffer window graphics are/is supported:
(- glk_gestalt(gestalt_DrawImage, wintype_TextBuffer) -).

To decide whether graphics window graphics are/is supported:
(- glk_gestalt(gestalt_DrawImage, wintype_Graphics) -).

To decide whether buffer window hyperlinks are/is supported:
(- glk_gestalt(gestalt_HyperlinkInput, wintype_TextBuffer) -).

To decide whether grid window hyperlinks are/is supported:
(- glk_gestalt(gestalt_HyperlinkInput, wintype_TextGrid) -).

To decide whether graphics window mouse input is supported:
(- glk_gestalt(gestalt_MouseInput, wintype_Graphics) -).

To decide whether grid window mouse input is supported:
(- glk_gestalt(gestalt_MouseInput, wintype_TextGrid) -).

To decide whether (F - glulx feature) is/are supported:
(- Cached_Glulx_Gestalts-->({F}) -).

To decide what number is the glulx version number/--:
(- Cached_Glulx_Gestalts-->GLULX_GESTALT_GlulxVersion -).

To decide what number is the interpreter version number/--:
(- Cached_Glulx_Gestalts-->GLULX_GESTALT_TerpVersion -).

Chapter - Glk windows

A glk window is a kind of abstract object.
The glk window kind is accessible to Inter as "K_Glk_Window".
The specification of a glk window is "Models the Glk window system."

A glk window has a glk window type called the type.
The type property translates into Inter as "glk_window_type".

A glk window has a number called the rock number.
The rock number property translates into Inter as "glk_rock".

A glk window has a number called the reference number.
The reference number property translates into Inter as "glk_ref".

The main window is a glk window.
The main window object is accessible to Inter as "Main_Window".
The type of the main window is text buffer.

The status window is a glk window.
The status window object is accessible to Inter as "Status_Window".
The type of the status window is text grid.

The quote window is a glk window.
The quote window object is accessible to Inter as "Quote_Window".
The type of the quote window is text buffer.

The unknown window is a glk window.
The unknown window object is accessible to Inter as "Unknown_Glk_Window".

Section - Glk windows

To clear (win - a glk window):
(- glk_window_clear({win}.glk_ref); -).

To focus (win - a glk window):
(- glk_set_window({win}.glk_ref); -).

To decide what number is the height of (win - a glk window):
(- GetWindowSize({win}, 1) -).

To decide what number is the width of (win - a glk window):
(- GetWindowSize({win}, 0) -).

To set (win - a glk window) cursor to row (row - a number) and/-- column (col - a number):
(- glk_window_move_cursor({win}.glk_ref, {col} - 1, {row} - 1); -).

Chapter - Glk events

The glk event handling rules is a glk event based rulebook.
The glk event handling rules is accessible to Inter as "GLK_EVENT_HANDLING_RB".

The glk event type is a glk event variable.
The glk event type variable translates into Inter as "Glk_Event_Struct_type".
The glk event window is a glk window variable.
The glk event window variable translates into Inter as "Glk_Event_Struct_win".
The glk event value 1 is a number variable.
The glk event value 1 variable translates into Inter as "Glk_Event_Struct_val1".
The glk event value 2 is a number variable.
The glk event value 2 variable translates into Inter as "Glk_Event_Struct_val2".

Definition: a glk event is dependent on the player rather than independent of the player if
it is character event or
it is line event or
it is mouse event or
it is hyperlink event.

To set the/-- glk event type to (t - glk event):
(- SetGlkEventType({t}); -).

To decide what text is the current line input of (w - glk window):
(- CopyWindowBufferToText({w}, {-new:text}) -).

To set the current line input of (w - glk window) to (t - text):
(- CopyTextToWindowBuffer({w}, {-by-reference:t}); -).

First glk event handling rule (this is the update text input status rule):
if the glk event type is character event or the glk event type is line event:
now the text input status of the glk event window is inactive text input;
if the glk event type is hyperlink event:
now the glk event window is not requesting hyperlink input;
if the glk event type is mouse event:
now the glk event window is not requesting mouse input;

Chapter - Suspending and resuming input

A glk window has a text input status.
The text input status property translates into Inter as "text_input_status".
A glk window can be requesting hyperlink input.
The requesting hyperlink input property translates into Inter as "requesting_hyperlink".
A glk window can be requesting mouse input.
The requesting mouse input property translates into Inter as "requesting_mouse".

To suspend text input in (win - a glk window), without input echoing:
(- SuspendTextInput({win}, {phrase options}); -).

To resume text input in (win - a glk window):
(- ResumeTextInput({win}); -).

Chapter - Glk object recovery

The current glk object rock number is a number that varies.
The current glk object rock number variable translates into Inter as "current_glk_object_rock".
The current glk object reference number is a number that varies.
The current glk object reference number variable translates into Inter as "current_glk_object_reference".

The reset glk references rules is a rulebook.
The reset glk references rules is accessible to Inter as "RESET_GLK_REFERENCES_RB".
The identify glk windows rules is a rulebook.
The identify glk windows rules is accessible to Inter as "IDENTIFY_WINDOWS_RB".
The identify glk streams rules is a rulebook.
The identify glk streams rules is accessible to Inter as "IDENTIFY_STREAMS_RB".
The identify glk filerefs rules is a rulebook.
The identify glk filerefs rules is accessible to Inter as "IDENTIFY_FILEREFS_RB".
The identify glk sound channels rules is a rulebook.
The identify glk sound channels rules is accessible to Inter as "IDENTIFY_SCHANNELS_RB".
The glk object updating rules is a rulebook.
The glk object updating rules is accessible to Inter as "GLK_OBJECT_UPDATING_RB".

The reset glk references for built in objects rule is listed first in the reset glk references rules.
The reset glk references for built in objects rule translates into Inter as "RESET_GLK_REFERENCES_R".

The cache gestalts rule is listed in the reset glk references rules.
The cache gestalts rule translates into Inter as "CACHE_GESTALTS_R".

The identify built in windows rule is listed first in the identify glk windows rules.
The identify built in windows rule translates into Inter as "IDENTIFY_WINDOWS_R".

The identify built in streams rule is listed first in the identify glk streams rules.
The identify built in streams rule translates into Inter as "IDENTIFY_STREAMS_R".

The identify built in filerefs rule is listed first in the identify glk filerefs rules.
The identify built in filerefs rule translates into Inter as "IDENTIFY_FILEREFS_R".

The identify built in sound channels rule is listed first in the identify glk sound channels rules.
The identify built in sound channels rule translates into Inter as "IDENTIFY_SCHANNELS_R".

The stop built in sound channels rule is listed in the glk object updating rules.
The stop built in sound channels rule translates into Inter as "STOP_SCHANNELS_R".

Part Five - Adjectival Definitions

Section 1 - Miscellaneous Useful Adjectives

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,16 @@
%Index.Elements.St.TurnSequenceRules = Turn sequence rules
%Index.Elements.St.ShutdownRules = Shutdown rules

%Index.Elements.St.GlkHeading = Glk rules
%Index.Elements.St.GlkRubric = Rulebooks for handling the Glk systems.
%Index.Elements.St.ResetGlkReferencesRules = Reset glk references rules
%Index.Elements.St.IdentifyWindowsRules = Identify glk windows rules
%Index.Elements.St.IdentifyStreamsRules = Identify glk streams rules
%Index.Elements.St.IdentifyFilerefsRules = Identify glk filerefs rules
%Index.Elements.St.IdentifySchannelsRules = Identify glk sound channels rules
%Index.Elements.St.GlkObjectUpdatingRules = Glk object updating rules
%Index.Elements.St.GlkEventHandlingRules = Glk event handling rules

%Index.Elements.St.CheckRules =
Check rules are tied to specific actions, and there are too many to index here.
For instance, the check taking rules can only ever affect the taking action, so
Expand Down
1 change: 1 addition & 0 deletions inform7/Internal/Inter/Architecture32Kit/Contents.w
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Web Syntax Version: 2

Sections
Capabilities
InfGlk
Glk
Startup
State
Expand Down
20 changes: 18 additions & 2 deletions inform7/Internal/Inter/Architecture32Kit/Sections/Capabilities.i6t
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@ The 32-bit architecture is currently the default targeted by Inform, and is
used both for programs compiled via Inform 6 to the Glulx virtual machine, and
also for programs compiled via C.

@h Glulx gestalts.
While most Glulx gestalts are defined in the Glk.neptune file, a few would not
make sense as an kind of value, and are defined here instead.

=
Constant GLULX_GESTALT_GlulxVersion = 0;
Constant GLULX_GESTALT_TerpVersion = 1;
Constant GLULX_GESTALT_IOSystem = 4;
Constant GLULX_GESTALT_MAllocHeap = 8;
Constant GLULX_GESTALT_AccelFunc = 10;

[ Glulx_Gestalt sel arg res;
@gestalt sel arg res;
return res;
];

@h Header layout.
The VM is expected to contain certain special constants and variables at fixed
position in its "header"; the addresses of these are given below.
Expand Down Expand Up @@ -64,14 +80,14 @@ is viable on recent revisions of Glulx.

=
[ VM_AllocateMemory amount i;
@gestalt 7 0 i;
@gestalt GLULX_GESTALT_MAlloc 0 i;
if (i == 0) return i;
@malloc amount i;
return i;
];

[ VM_FreeMemory address i;
@gestalt 7 0 i;
@gestalt GLULX_GESTALT_MAlloc 0 i;
if (i == 0) return;
@mfree address;
];
Expand Down
Loading

0 comments on commit 3120746

Please sign in to comment.