Compare commits

..

1 Commits

Author SHA1 Message Date
CrazyEttin 1b2cc0667b Add Templeng. 2021-07-11 23:20:49 +03:00
2 changed files with 226 additions and 226 deletions

View File

@ -1,47 +1,47 @@
TEMPLENG
========
TEMPLENG is a text adventure game engine based on TEMPLE, also included
in EttinOS-extra.
Syntax: TEMPLENG DATAFILE.DAT
Press any key to start or to return back to the beginning after an
ending, the corresponding number to choose an option in a scene, or
escape to quit the game.
TEMPLE
------
Included in the package is TEMPLE, a TEMPLENG port of the web-based text
adventure game In the Temple by nortti. Its original readme is
reproduced here:
A small game about a visit to a temple and the reasons for doing so.
Can be played online at https://ahti.space/~nortti/in-the-temple/ or at
https://nortti.itch.io/in-the-temple
The game is distributed under the Creative Commons Zero 1.0 Universal
license.
The data files
--------------
A data file consists of an intro text ending in a null followed by any
number of scenes. See the included TEMPLE.DAT for an example.
A scene begins with a start of heading (0x1) and consists of its ID, the
number of options it has, and the scene text, all ending in a null. The
ID of a scene consists of a string of numbers representing the choices
that lead to it, and can be between 2 and 255 characters long including
the null. The ID of the first scene is 0. The number of options can be
anything between 0 and 9, 0 indicating an ending. The options of a scene
must point to scenes placed after it in the data file. The scene text
should not exceed 24 lines or all of it won't fit on the screen at once.
***
This package is part of EttinOS-extra, a collection of programs for
EttinOS, the git repository of which can be found at
https://ahti.space/git/crazyettin/EttinOS-extra.
TEMPLENG
========
TEMPLENG is a text adventure game engine based on TEMPLE, also included
in EttinOS-extra.
Syntax: TEMPLENG DATAFILE.DAT
Press any key to start or to return back to the beginning after an
ending, the corresponding number to choose an option in a scene, or
escape to quit the game.
TEMPLE
------
Included in the package is TEMPLE, a TEMPLENG port of the web-based text
adventure game In the Temple by nortti. Its original readme is
reproduced here:
A small game about a visit to a temple and the reasons for doing so.
Can be played online at https://ahti.space/~nortti/in-the-temple/ or at
https://nortti.itch.io/in-the-temple
The game is distributed under the Creative Commons Zero 1.0 Universal
license.
The data files
--------------
A data file consists of an intro text ending in a null followed by any
number of scenes. See the included TEMPLE.DAT for an example.
A scene begins with a start of heading (0x1) and consists of its ID, the
number of options it has, and the scene text, all ending in a null. The
ID of a scene consists of a string of numbers representing the choices
that lead to it, and can be between 2 and 255 characters long including
the null. The ID of the first scene is 0. The number of options can be
anything between 0 and 9, 0 indicating an ending. The options of a scene
must point to scenes placed after it in the data file. The scene text
should not exceed 24 lines or all of it won't fit on the screen at once.
***
This package is part of EttinOS-extra, a collection of programs for
EttinOS, the git repository of which can be found at
https://ahti.space/git/crazyettin/EttinOS-extra.

View File

@ -1,179 +1,179 @@
cpu 8086
org 0x3000
;Set the stack
cli
mov sp, stack + 0x100
sti
;Check for an empty tail
;Check
cmp byte [si], 0x0
jne extract
;Print an error message and abort if the tail is empty
mov si, errormsg
mov ah, 0x2
int 0x21
je done
;Find the end of the data file name and add a null if needed
;Set DI at the tail
extract:
mov di, si
findend:
;Check for the string end
cmp byte [di], 0x0
je load
;Check for a space
cmp byte [di], 0x20
je addnull
inc di
jmp findend
;Add a null
addnull:
mov al, 0x0
stosb
;Load the data file
;Load
load:
mov bx, stack + 0x100
mov ah, 0x0
int 0x22
;Check for errors
cmp al, 0x0
jne done
;Setup
start:
;Set SI to the beginning of the data file
mov si, stack + 0x100
;Initialise the scene ID with zeroes and set DI at its beginning
mov di, sceneid
mov cx, 0xff
mov al, 0x0
rep stosb
mov di, sceneid
;Intro
;Print the intro
mov ah, 0x0
int 0x21
;Read any key to start
mov ah, 0x0
int 0x16
call readquit
;Set the ID of the first scene
mov al, "0"
stosb
;Search for the current scene
searchscene:
lodsb
cmp al, 0x1
je checkscene
jmp searchscene
;Check for the current scene
;Set DI to the current scene id
checkscene:
mov di, sceneid
;Load the current characters
checkloop:
mov al, [si]
mov bl, [di]
;Compare the characters
cmp al, bl
jne searchscene
;Check for the string end
cmp al, 0x0
je loadoptions
;Compare the next characters
inc si
inc di
jmp checkloop
;Load the number of options to BL
loadoptions:
inc si
lodsb
mov bl, al
;Print the scene
;Move SI to the beginning of the scene text
inc si
;Print the scene
mov ah, 0x0
int 0x21
;Read the player choice
;Set DI at the options key
readchoice:
mov di, options
;Set the maximum number of options
mov cx, 0x9
;Read a keypress
mov ah, 0x0
int 0x16
;Check for quitting
call readquit
;Check for an ending scene
cmp bl, "0"
je ending
;Compare the keypress to the key
cmpchoice:
cmp al, [di]
je setscene
cmp bl, [di]
je readchoice
inc di
loop cmpchoice
jmp readchoice
;Set the next scene
;Find the end of the current scene id
setscene:
mov di, sceneid
findidend:
cmp byte [di], 0x0
je addoption
inc di
jmp findidend
;Add the chosen option
addoption:
stosb
;Go to the next scene
jmp searchscene
ending:
mov si, crlf
mov ah, 0x0
int 0x21
jmp start
;Return to the system
done:
int 0x20
;Data
errormsg db "File not found", 0x0
sceneid times 0xff db 0x0
options db "123456789"
crlf db 0xd, 0xa, 0x0
;***
;Quit the game
readquit:
;Check for keypress escape
cmp al, 0x1b
je done
;Return
ret
;***
;Stack
stack:
cpu 8086
org 0x3000
;Set the stack
cli
mov sp, stack + 0x100
sti
;Check for an empty tail
;Check
cmp byte [si], 0x0
jne extract
;Print an error message and abort if the tail is empty
mov si, errormsg
mov ah, 0x2
int 0x21
je done
;Find the end of the data file name and add a null if needed
;Set DI at the tail
extract:
mov di, si
findend:
;Check for the string end
cmp byte [di], 0x0
je load
;Check for a space
cmp byte [di], 0x20
je addnull
inc di
jmp findend
;Add a null
addnull:
mov al, 0x0
stosb
;Load the data file
;Load
load:
mov bx, stack + 0x100
mov ah, 0x0
int 0x22
;Check for errors
cmp al, 0x0
jne done
;Setup
start:
;Set SI to the beginning of the data file
mov si, stack + 0x100
;Initialise the scene ID with zeroes and set DI at its beginning
mov di, sceneid
mov cx, 0xff
mov al, 0x0
rep stosb
mov di, sceneid
;Intro
;Print the intro
mov ah, 0x0
int 0x21
;Read any key to start
mov ah, 0x0
int 0x16
call readquit
;Set the ID of the first scene
mov al, "0"
stosb
;Search for the current scene
searchscene:
lodsb
cmp al, 0x1
je checkscene
jmp searchscene
;Check for the current scene
;Set DI to the current scene id
checkscene:
mov di, sceneid
;Load the current characters
checkloop:
mov al, [si]
mov bl, [di]
;Compare the characters
cmp al, bl
jne searchscene
;Check for the string end
cmp al, 0x0
je loadoptions
;Compare the next characters
inc si
inc di
jmp checkloop
;Load the number of options to BL
loadoptions:
inc si
lodsb
mov bl, al
;Print the scene
;Move SI to the beginning of the scene text
inc si
;Print the scene
mov ah, 0x0
int 0x21
;Read the player choice
;Set DI at the options key
readchoice:
mov di, options
;Set the maximum number of options
mov cx, 0x9
;Read a keypress
mov ah, 0x0
int 0x16
;Check for quitting
call readquit
;Check for an ending scene
cmp bl, "0"
je ending
;Compare the keypress to the key
cmpchoice:
cmp al, [di]
je setscene
cmp bl, [di]
je readchoice
inc di
loop cmpchoice
jmp readchoice
;Set the next scene
;Find the end of the current scene id
setscene:
mov di, sceneid
findidend:
cmp byte [di], 0x0
je addoption
inc di
jmp findidend
;Add the chosen option
addoption:
stosb
;Go to the next scene
jmp searchscene
ending:
mov si, crlf
mov ah, 0x0
int 0x21
jmp start
;Return to the system
done:
int 0x20
;Data
errormsg db "File not found", 0x0
sceneid times 0xff db 0x0
options db "123456789"
crlf db 0xd, 0xa, 0x0
;***
;Quit the game
readquit:
;Check for keypress escape
cmp al, 0x1b
je done
;Return
ret
;***
;Stack
stack: