Initial commit

This commit is contained in:
Scott Duensing 2024-01-13 19:29:54 -06:00
commit 23ce075d34
12 changed files with 7649 additions and 0 deletions

4
.gitattributes vendored Normal file
View file

@ -0,0 +1,4 @@
*.png filter=lfs diff=lfs merge=lfs -text
*.jpg filter=lfs diff=lfs merge=lfs -text
*.gif filter=lfs diff=lfs merge=lfs -text
*.bmp filter=lfs diff=lfs merge=lfs -text

12
.gitignore vendored Normal file
View file

@ -0,0 +1,12 @@
# Backup files
*~
# Stuff I've downloaded
stuff/
# Story files
stories/
# Dumb QtCreator junk
build-*/
*.user

19
CMakeLists.txt Normal file
View file

@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.12)
project(zip LANGUAGES C)
set(ZIP_SOURCE
main.c
memory.c
text.c
)
set(ALL_SOURCE
${ZIP_SOURCE}
)
list(TRANSFORM ALL_SOURCE PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/src/")
add_executable(${CMAKE_PROJECT_NAME} ${ALL_SOURCE}
src/story.c)
target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)

BIN
icon.gif (Stored with Git LFS) Normal file

Binary file not shown.

41
include/memory.h Normal file
View file

@ -0,0 +1,41 @@
/*
* Copyright (c) 2024 Scott Duensing, scott@kangaroopunch.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef MEMORY_H
#define MEMORY_H
#include <stdint.h>
#define MEMORY_ROUTINE 0
#define MEMORY_PRINT 1
uint8_t memoryByte(uint16_t address);
uint32_t memoryUnpackAddress(uint16_t address, uint8_t type);
uint16_t memoryWord(uint16_t address);
void memoryLoadStory(void);
#endif // MEMORY_H

116
include/story.h Normal file
View file

@ -0,0 +1,116 @@
/*
* Copyright (c) 2024 Scott Duensing, scott@kangaroopunch.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef STORY_H
#define STORY_H
#include "memory.h"
#define STORY_STATUS_SCORE_TURNS 0
#define STORY_STATUS_HOURS_MINUTES 1
#define STORY_FLAG_V3_STATUS (1 << 1)
#define STORY_FLAG_V3_TWO_DISKS (1 << 2)
#define STORY_FLAG_V3_STATUS_LINE_NOT_AVAILABLE (1 << 4)
#define STORY_FLAG_V3_SCREEN_SPLITTING (1 << 5)
#define STORY_FLAG_V3_VARIABLE_PITCH_FONT (1 << 6)
#define STORY_FLAG_V4_COLOR (1 << 0)
#define STORY_FLAG_V4_PICTURE (1 << 1)
#define STORY_FLAG_V4_BOLDFACE (1 << 2)
#define STORY_FLAG_V4_ITALIC (1 << 3)
#define STORY_FLAG_V4_FIXED_SPACE (1 << 4)
#define STORY_FLAG_V4_SOUND (1 << 5)
#define STORY_FLAG_V4_TIMED_INPUT (1 << 7)
#define STORY_FLAG_2_V1_TRANSCRIPTING (1 << 0)
#define STORY_FLAG_2_V3_FORCE_FIXED_PITCHED (1 << 1)
#define STORY_FLAG_2_V6_FORCE_REDRAW (1 << 2)
#define STORY_FLAG_2_V5_USE_PICTURES (1 << 3)
#define STORY_FLAG_2_V5_USE_UNDO (1 << 4)
#define STORY_FLAG_2_V5_USE_MOUSE (1 << 5)
#define STORY_FLAG_2_V5_USE_COLOR (1 << 6)
#define STORY_FLAG_2_V5_USE_SOUND (1 << 7)
#define STORY_FLAG_2_V6_USE_MENUS (1 << 8)
#define STORY_SCREEN_HEIGHT_INFINITE 255
#define STORY_INTERPRETER_NUMBER_DECSYSTEM_20 1
#define STORY_INTERPRETER_NUMBER_APPLE_IIE 2
#define STORY_INTERPRETER_NUMBER_MACINTOSH 3
#define STORY_INTERPRETER_NUMBER_AMIGA 4
#define STORY_INTERPRETER_NUMBER_ATARI_ST 5
#define STORY_INTERPRETER_NUMBER_IBM_PC 6
#define STORY_INTERPRETER_NUMBER_COMMODORE_128 7
#define STORY_INTERPRETER_NUMBER_COMMODORE_64 8
#define STORY_INTERPRETER_NUMBER_APPLE_IIC 9
#define STORY_INTERPRETER_NUMBER_APPLE_IIGS 10
#define STORY_INTERPRETER_NUMBER_TANDY_COLOR 11
#define STORY_FLAG_3_USE_TRANSPARENCY (1 << 0)
#define storyVersion() memoryByte(0x0)
#define storyFlags() memoryByte(0x1)
#define storyHightMemory() memoryWord(0x4)
#define storyInitialPC() memoryWord(0x6) // V1-5
#define storyInitialPackedPC() memoryUnpackAddress(memoryWord(0x6), MEMORY_ROUTINE) // V6
#define storyDictionaryAddress() memoryWord(0x8)
#define storyObjectTableAddress() memoryWord(0xa)
#define storyGlobalVariableTableAddress() memoryWord(0xc)
#define storyStaticMemoryBaseAddress() memoryWord(0xe)
#define storyFlags2() memoryWord(0x10)
#define storyAbbreviationTableAddress() memoryWord(0x18)
#define storyChecksum() memoryWord(0x1c)
#define storyInterpreterNumber() memoryByte(0x1e)
#define storyInterpreterVersion() memoryByte(0x1f)
#define storyScreenHeightLines() memoryByte(0x20)
#define storyScreenWidthCharacters() memoryByte(0x21)
#define storyScreenHeightUnits() memoryWord(0x22)
#define storyScreenWidthUnits() memoryWord(0x24)
#define storyFontHeightUnits() (storyVersion() == 5 ? memoryByte(0x27) ? memoryByte(0x26)) // WTF Infocom?
#define storyFontWidthUnits() (storyVersion() == 5 ? memoryByte(0x26) ? memoryByte(0x27))
#define storyRoutinesOffset() memoryWord(0x28)
#define storyStringsOffset() memoryWord(0x2a)
#define storyDefaultBackgroundColor() memoryByte(0x2c)
#define storyDefaultForegroundColor() memoryByte(0x2d)
#define storyTerminatingCharactersTableAddress() memoryWord(0x2e)
#define storyWidthInPixelsToOutputStream3() memoryByte(0x30)
#define storyStandardRevisionNumber() memoryByte(0x32)
#define storyAlphabetTableAddress() memoryWord(0x34)
#define storyHeaderExtensionTableAddress() memoryWord(0x36)
#define storyHXWordsInTable() memoryWord(storyHeaderExtensionTableAddress())
#define storyHXMouseXClick() memoryWord(storyHeaderExtensionTableAddress() + 2)
#define storyHXMouseYClick() memoryWord(storyHeaderExtensionTableAddress() + 4)
#define storyHXUnicodeTranslationTableAddress() memoryWord(storyHeaderExtensionTableAddress() + 6)
#define storyHXFlags3() memoryWord(storyHeaderExtensionTableAddress() + 8)
#define storyHXTrueDefaultForegroundColor() memoryWord(storyHeaderExtensionTableAddress() + 10)
#define storyHXTrueDefaultBackgroundColor() memoryWord(storyHeaderExtensionTableAddress() + 12)
uint32_t storyLength();
#endif // STORY_H

31
include/text.h Normal file
View file

@ -0,0 +1,31 @@
/*
* Copyright (c) 2024 Scott Duensing, scott@kangaroopunch.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef TEXT_H
#define TEXT_H
void textPrint(char *what);
#endif // TEXT_H

7251
include/zork1.h Normal file

File diff suppressed because it is too large Load diff

48
src/main.c Normal file
View file

@ -0,0 +1,48 @@
/*
* Copyright (c) 2024 Scott Duensing, scott@kangaroopunch.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/*
* Z-Machine for the Foenix F256 computers.
*
* F256 machines are 65c02 based systems with 512k of banked RAM.
* As such, this ZIP is going to load the story entirely into "high"
* memory (above the 64k accessable to the CPU) and page things in
* and out as needed.
*
* To keep library code at a minimum, we'll also statically allocate
* as much as possible and do other "bad" things now frowned upon in
* modern development. :-)
*/
#include <stdio.h>
#include "memory.h"
#include "story.h"
int main(void) {
memoryLoadStory();
printf("%d\n", storyVersion());
return 0;
}

71
src/memory.c Normal file
View file

@ -0,0 +1,71 @@
/*
* Copyright (c) 2024 Scott Duensing, scott@kangaroopunch.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "memory.h"
#include "story.h"
#include "zork1.h"
// The F256 has 512k of RAM. We use everything except the lower 64k.
static uint8_t RAM[1024 * (512 - 64)];
uint8_t memoryByte(uint16_t address) {
return RAM[address];
}
uint32_t memoryUnpackAddress(uint16_t address, uint8_t type) {
switch (storyVersion()) {
case 1:
case 2:
case 3:
return (uint32_t)address * 2;
case 4:
case 5:
return (uint32_t)address * 4;
case 6:
if (type == MEMORY_ROUTINE) {
return ((uint32_t)address * 4) + storyRoutineOffset;
} else {
return ((uint32_t)address * 4) + storyStringOffset;
}
case 8:
return (uint32_t)address * 8;
}
return ((uint16_t)RAM[address] << 8) | ((uint16_t)RAM[address + 1]);
}
uint16_t memoryWord(uint16_t address) {
return ((uint16_t)RAM[address] << 8) | ((uint16_t)RAM[address + 1]);
}
void memoryLoadStory(void) {
uint32_t x;
// For now, we just copy an embedded Zork 1 into RAM.
for (x=0; x<zork1_len; x++) RAM[x] = zork1[x];
}

23
src/story.c Normal file
View file

@ -0,0 +1,23 @@
#include "story.h"
uint32_t storyLength() {
uint32_t m = (uint32_t)memoryWord(0x1a);
switch (storyVersion()) {
case 1:
case 2:
case 3:
m *= 2;
break;
case 4:
case 5:
m *= 4;
break;
case 6:
m *= 8;
break;
}
return m;
}

30
src/text.c Normal file
View file

@ -0,0 +1,30 @@
/*
* Copyright (c) 2024 Scott Duensing, scott@kangaroopunch.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include <stdio.h>
#include "text.h"
void textPrint(char *what) {
printf("%s", what);
}