EttinOS-extra/TEMPLENG/TEMPLENG.ASM

180 lines
2.6 KiB
NASM

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: