├── .gitattributes ├── .gitignore ├── .gitmodules ├── README ├── data.py ├── dcode ├── header.py └── optables.py ├── fonts ├── bzork.ttf ├── font.py └── noto │ ├── mono │ ├── NotoSansMono-Bold.ttf │ └── NotoSansMono-Regular.ttf │ └── serif │ ├── NotoSerif-Bold.ttf │ ├── NotoSerif-BoldItalic.ttf │ ├── NotoSerif-Italic.ttf │ └── NotoSerif-Regular.ttf ├── settings.py ├── setup.py ├── sounds ├── beep.aiff └── boop.aiff ├── vio ├── __init__.py └── zcode.py ├── viola.py └── zcode ├── __init__.py ├── constants.py ├── dictionary.py ├── error.py ├── game.py ├── header.py ├── input.py ├── instructions.py ├── memory.py ├── numbers.py ├── objects.py ├── opcodes.py ├── optables.py ├── output.py ├── routines.py ├── screen.py ├── sounds.py └── text.py /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | 46 | [Dd]ebug/ 47 | [Rr]elease/ 48 | x64/ 49 | build/ 50 | [Bb]in/ 51 | [Oo]bj/ 52 | 53 | # MSTest test Results 54 | [Tt]est[Rr]esult*/ 55 | [Bb]uild[Ll]og.* 56 | 57 | *_i.c 58 | *_p.c 59 | *.ilk 60 | *.meta 61 | *.obj 62 | *.pch 63 | *.pdb 64 | *.pgc 65 | *.pgd 66 | *.rsp 67 | *.sbr 68 | *.tlb 69 | *.tli 70 | *.tlh 71 | *.tmp 72 | *.tmp_proj 73 | *.log 74 | *.vspscc 75 | *.vssscc 76 | .builds 77 | *.pidb 78 | *.log 79 | *.scc 80 | 81 | # Visual C++ cache files 82 | ipch/ 83 | *.aps 84 | *.ncb 85 | *.opensdf 86 | *.sdf 87 | *.cachefile 88 | 89 | # Visual Studio profiler 90 | *.psess 91 | *.vsp 92 | *.vspx 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | 101 | # TeamCity is a build add-in 102 | _TeamCity* 103 | 104 | # DotCover is a Code Coverage Tool 105 | *.dotCover 106 | 107 | # NCrunch 108 | *.ncrunch* 109 | .*crunch*.local.xml 110 | 111 | # Installshield output folder 112 | [Ee]xpress/ 113 | 114 | # DocProject is a documentation generator add-in 115 | DocProject/buildhelp/ 116 | DocProject/Help/*.HxT 117 | DocProject/Help/*.HxC 118 | DocProject/Help/*.hhc 119 | DocProject/Help/*.hhk 120 | DocProject/Help/*.hhp 121 | DocProject/Help/Html2 122 | DocProject/Help/html 123 | 124 | # Click-Once directory 125 | publish/ 126 | 127 | # Publish Web Output 128 | *.Publish.xml 129 | *.pubxml 130 | 131 | # NuGet Packages Directory 132 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 133 | #packages/ 134 | 135 | # Windows Azure Build Output 136 | csx 137 | *.build.csdef 138 | 139 | # Windows Store app package directory 140 | AppPackages/ 141 | 142 | # Others 143 | sql/ 144 | *.Cache 145 | ClientBin/ 146 | [Ss]tyle[Cc]op.* 147 | ~$* 148 | *~ 149 | *.dbmdl 150 | *.[Pp]ublish.xml 151 | *.pfx 152 | *.publishsettings 153 | 154 | # RIA/Silverlight projects 155 | Generated_Code/ 156 | 157 | # Backup & report files from converting an old project file to a newer 158 | # Visual Studio version. Backup files are not needed, because we have git ;-) 159 | _UpgradeReport_Files/ 160 | Backup*/ 161 | UpgradeLog*.XML 162 | UpgradeLog*.htm 163 | 164 | # SQL Server files 165 | App_Data/*.mdf 166 | App_Data/*.ldf 167 | 168 | ############# 169 | ## Windows detritus 170 | ############# 171 | 172 | # Windows image file caches 173 | Thumbs.db 174 | ehthumbs.db 175 | 176 | # Folder config file 177 | Desktop.ini 178 | 179 | # Recycle Bin used on file shares 180 | $RECYCLE.BIN/ 181 | 182 | # Mac crap 183 | .DS_Store 184 | 185 | 186 | ############# 187 | ## Python 188 | ############# 189 | 190 | *.py[co] 191 | 192 | # Packages 193 | *.egg 194 | *.egg-info 195 | dist/ 196 | build/ 197 | eggs/ 198 | parts/ 199 | var/ 200 | sdist/ 201 | develop-eggs/ 202 | .installed.cfg 203 | 204 | # Installer logs 205 | pip-log.txt 206 | 207 | # Unit test / coverage reports 208 | .coverage 209 | .tox 210 | 211 | #Translations 212 | *.mo 213 | 214 | #Mr Developer 215 | .mr.developer.cfg 216 | 217 | #PyCharm 218 | venv/ 219 | .idea/ 220 | 221 | # Viola 222 | glk/ 223 | glulx/ 224 | games/ 225 | misc/ 226 | future/ 227 | zcode/lgop.txt 228 | icons/ 229 | 230 | *.txt 231 | 232 | *.zblorb 233 | *.z1 234 | *.z2 235 | *.z3 236 | *.z4 237 | *.z5 238 | *.z6 239 | *.z7 240 | *.z8 241 | *.blorb 242 | *.blb 243 | *.zblb 244 | 245 | viola 246 | 247 | dcode/details 248 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "ififf"] 2 | path = ififf 3 | url = https://github.com/DFillmore/ififf 4 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | VIOLA 0.8.1 2 | 3 | Written by David Fillmore. 4 | 5 | Viola is a Z-Machine Interpreter. That is, it interprets programs written for the virtual 6 | machine known as the Z-Machine. There's a brief history of the Z-Machine at the bottom of 7 | this file, for some reason. 8 | 9 | The latest code for Viola is available at https://github.com/DFillmore/viola. 10 | 11 | FEATURES 12 | 13 | * Z-Machine Versions 1-8 support 14 | * Z-Machine Standards Document 1.1 compliance 15 | * Blorb Resource Format 2.0 compliance 16 | * Quetzal Saved Game Format 1.4 compliance 17 | * Support (via Blorb) for sounds and, in Version 6, images. 18 | 19 | 20 | INSTALLATION 21 | 22 | Some brief notes on getting the program up and running. 23 | 24 | You will need Python 3 (I use version 3.3.5), which you can get at http://www.python.org, and 25 | pygame (I use version 1.9.2), which you can get at http://www.pygame.org/. I genuinely don't 26 | know if the setup.py file does anything useful. 27 | 28 | BRIEF HISTORY OF THE Z-MACHINE FOR SOME REASON 29 | 30 | The Z-Machine was created in the early Eighties by Infocom in order to run 31 | text adventures. 32 | 33 | Infocom evolved the design of the Z-Machine gradually, and created six distinct versions, 34 | each with more capabilites than the previous. Versions 1, 2 and 3 are almost identical, 35 | with slight changes to certain parts of the design that make them incompatible. Most of 36 | Infocom's games were released for version 3. Version 3 was a fairly simple design, but a 37 | seperate upper window was introduced for one game, and support for sound effects (which 38 | was really part of the Version 5 design, but a scaled down version was stuck into Version 39 | 3). 40 | Version 4 introduced text styles, better upper window support and a few other features, 41 | as well as allowing games to be larger. Version 5 allowed even larger games, with several 42 | new features including better sound support. Version 6 allowed for graphics, up to eight 43 | windows which could be moved and resized, bigger games, and other less obvious features. 44 | 45 | Then Infocom went out of business, more or less. 46 | 47 | Several years later, Graham Nelson created Inform, which allowed anyone to create 48 | Z-Machine games. Two new Versions were created, numbered 7 and 8. These have none of the 49 | extra features of z6, but instead are identical to the z5 model, except that they both 50 | allow larger games. z7 was never really used. 51 | 52 | Most games created for the Z-Machine since Infocom stopped business are z5 games. 53 | -------------------------------------------------------------------------------- /data.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2001 - 2024 David Fillmore 2 | # 3 | # This file is part of Viola. 4 | # 5 | # Viola is free software; you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation; either version 2 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # Viola is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | 15 | import re 16 | from urllib.request import urlopen 17 | 18 | 19 | ifdb_url = "https://ifdb.org/search?searchgo=Search+Games&searchfor=ifid:" 20 | 21 | legacy_serials = ("00", "01", "02", "03", "04", "05") 22 | 23 | 24 | def getcode(gamedata): 25 | release = (gamedata[2] << 8) + gamedata[3] 26 | serial = gamedata[0x12:0x18].decode('latin-1') 27 | return str(release) + '.' + serial 28 | 29 | 30 | def getifid(gamedata): 31 | serial: list[str] = list(gamedata[0x12:0x18].decode('latin-1')) 32 | if serial[0] == "8" or serial[0] == "9" or ''.join(serial[0:2]) in legacy_serials: 33 | pass 34 | else: 35 | expr = r"(?<=UUID:\/\/)[a-zA-z\d\-]+(?=\/\/)" 36 | r = re.compile(expr, re.M | re.S) 37 | match = r.search(gamedata.decode('latin-1')) 38 | if match is not None: 39 | return match.string[match.start():match.end()] 40 | for a in range(len(serial)): 41 | if not serial[a].isalnum(): 42 | serial[a] = "-" 43 | release = int.from_bytes(gamedata[2:4], byteorder="big") 44 | checksum = int.from_bytes(gamedata[0x1c:0x1e], byteorder="big") 45 | i = "ZCODE-" + str(release) + "-" + ''.join(serial) 46 | 47 | if serial[0].isnumeric() and serial[0] != "8" and ''.join(serial) not in ("000000", "999999", "------"): 48 | i += "-" + hex(checksum)[2:] 49 | return i 50 | 51 | 52 | def getpage(ifid): 53 | response = urlopen(ifdb_url+ifid) 54 | page = response.read().decode('latin-1') 55 | if 'No results were found.' in page and 'Can\'t find the game you\'re looking for?' in page: 56 | page = None 57 | return page 58 | 59 | 60 | def gettitle(ifdb_page): 61 | expr = r"(?<=\