Stubbed in the opcodes needed to view the intro to Zork.

This commit is contained in:
Scott Duensing 2024-01-26 20:56:06 -06:00
parent 23ce075d34
commit 730c3ec441
20 changed files with 901 additions and 17 deletions

View file

@ -2,18 +2,40 @@ cmake_minimum_required(VERSION 3.12)
project(zip LANGUAGES C)
set(ZIP_SOURCE
set(HEADERS
memory.h
oc_0op.h
oc_1op.h
oc_2op.h
oc_var_op.h
oc_ext.h
opcodes.h
state.h
stddclmr.h
story.h
text.h
zork1.h
)
list(TRANSFORM HEADERS PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/include/")
set(SOURCE
main.c
memory.c
oc_0op.c
oc_1op.c
oc_2op.c
oc_var_op.c
oc_ext.c
opcodes.c
state.c
story.c
text.c
)
list(TRANSFORM SOURCE PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/src/")
set(ALL_SOURCE
${ZIP_SOURCE}
add_executable(${CMAKE_PROJECT_NAME}
${HEADERS}
${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)

View file

@ -31,8 +31,22 @@
#define MEMORY_ROUTINE 0
#define MEMORY_PRINT 1
#define true 1
#define false 0
#define PEEK(a) memoryByte(a)
#define POKE(a,v) memorySetByte(a,v)
#define PEEKW(a) memoryWord(a)
#define POKEW(a,v) memorySetWord(a,v)
typedef unsigned char byte;
typedef unsigned char bool;
uint8_t memoryByte(uint16_t address);
void memorySetByte(uint16_t address, uint8_t value);
void memorySetWord(uint16_t address, uint16_t value);
uint32_t memoryUnpackAddress(uint16_t address, uint8_t type);
uint16_t memoryWord(uint16_t address);
void memoryLoadStory(void);

32
include/oc_0op.h Normal file
View file

@ -0,0 +1,32 @@
/*
* 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 OC_0OP_H
#define OC_0OP_H
void opcodes_new_line(void);
void opcodes_print(void);
#endif // OC_0OP_H

33
include/oc_1op.h Normal file
View file

@ -0,0 +1,33 @@
/*
* 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 OC_1OP_H
#define OC_1OP_H
void opcodes_jump(void);
void opcodes_jz(void);
void opcodes_ret(void);
#endif // OC_1OP_H

36
include/oc_2op.h Normal file
View file

@ -0,0 +1,36 @@
/*
* 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 OC_2OP_H
#define OC_2OP_H
void opcodes_add(void);
void opcodes_je(void);
void opcodes_loadw(void);
void opcodes_store(void);
void opcodes_sub(void);
void opcodes_test_attr(void);
#endif // OC_2OP_H

27
include/oc_ext.h Normal file
View file

@ -0,0 +1,27 @@
/*
* 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 OC_EXT_H
#define OC_EXT_H
#endif // OC_EXT_H

34
include/oc_var_op.h Normal file
View file

@ -0,0 +1,34 @@
/*
* 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 OC_VAR_OP_H
#define OC_VAR_OP_H
void opcodes_call(void);
void opcodes_put_prop(void);
void opcodes_storew(void);
#endif // OC_VAR_OP_H

34
include/opcodes.h Normal file
View file

@ -0,0 +1,34 @@
/*
* 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 OPCODES_H
#define OPCODES_H
typedef void (*opcodeT)(void);
void opcodesSetup(void);
#endif // OPCODES_H

45
include/state.h Normal file
View file

@ -0,0 +1,45 @@
/*
* 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 STATE_H
#define STATE_H
#include "memory.h"
#include "opcodes.h"
typedef struct stateS {
byte stack[2048]; //***TODO*** How big does this really need to be? Old games are 1024, new...?
bool quit;
uint16_t pc;
uint16_t sp;
opcodeT opcodes[256];
opcodeT extOpcodes[30];
} stateT;
extern stateT __state;
#endif // STATE_H

95
include/stddclmr.h Normal file
View file

@ -0,0 +1,95 @@
#ifndef STDDCLMR_H
#define STDDCLMR_H
/*
Action figures sold separately. Add toner. All models over 18 years of age.
All rights reserved. Allow four to six weeks for delivery. An equal
opportunity employer. Any resemblance to actual persons, living or dead, is
unintentional and purely coincidental. Apply only to affected area. Approved
for veterans. As seen on TV. At participating locations only. Avoid contact
with mucous membranes. Avoid contact with skin. Avoid extreme temperatures
and store in a cool dry place. Batteries not included. Be sure each item is
properly endorsed. Beware of dog. Booths for two or more. Breaking seal
constitutes acceptance of agreement. Call toll free number before digging.
Caveat emptor. Check here if tax deductible. Close cover before striking
Colors may fade. Contains a substantial amount of non-tobacco ingredients.
Contents may settle during shipment. Contestants have been briefed on some
questions before the show. Copyright 1995 Joker's Wild. Disclaimer does
not cover hurricane, lightning, tornado, tsunami, volcanic eruption,
earthquake, flood, and other Acts of God, misuse, neglect, unauthorized
repair, damage from improper installation, broken antenna or marred cabinet,
incorrect line voltage, missing or altered serial numbers, sonic boom
vibrations, electromagnetic radiation from nuclear blasts, customer
adjustments that are not covered in the joke list, and incidents owing to
airplane crash, ship sinking, motor vehicle accidents, leaky roof, broken
glass, falling rocks, mud slides, forest fire, flying projectiles, or
dropping the item. Do not bend, fold, mutilate, or spindle. Do not place
near flammable or magnetic source. Do not puncture, incinerate, or store
above 120 degrees Fahrenheit. Do not stamp. Use other side for additional
listings. Do not use while operating a motor vehicle or heavy equipment. Do
not write below this line. Documents are provided "as is" without any
warranties expressed or implied. Don't quote me on anything. Don't quote me
on that. Driver does not carry cash. Drop in any mailbox. Edited for
television. Employees and their families are not eligible. Falling rock.
First pull up, then pull down. Flames redirected to /dev/null. For a
limited time only. For external use only. For off-road use only. For office
use only. For recreational use only. Do not disturb. Freshest if eaten
before date on carton. Hand wash only, tumble dry on low heat. If a rash,
redness, irritation, or swelling develops, discontinue use. If condition
persists, consult your physician. If defects are discovered, do not attempt
to fix them yourself, but return to an authorized service center. If
ingested, do not induce vomiting, if symptoms persist, consult a doctor.
Keep away from open flames and avoid inhaling fumes. Keep away from
sunlight, pets, and small children. Keep cool; process promptly. Limit
one-per-family please. Limited time offer, call now to ensure prompt
delivery. List at least two alternate dates. List each check separately by
bank number. List was current at time of printing. Lost ticket pays maximum
rate. May be too intense for some viewers. Must be 18 to enter. No Canadian
coins. No alcohol, dogs or horses. No anchovies unless otherwise specified.
No animals were harmed in the production of these documents. No money down.
No other warranty expressed or implied. No passes accepted for this
engagement. No postage necessary if mailed in the United States. No
preservatives added. No purchase necessary. No salt, MSG, artificial color
or flavor added. No shoes, no shirt, no service, no kidding. No solicitors.
No substitutions allowed. No transfers issued until the bus comes to a
complete stop. No user-serviceable parts inside. Not affiliated with the
American Red Cross. Not liable for damages due to use or misuse. Not
recommended for children. Not responsible for direct, indirect, incidental
or consequential damages resulting from any defect, error or failure to
perform. Not the Beatles. Objects in mirror may be closer than they appear.
One size fits all. Many suitcases look alike. Other copyright laws for
specific entries apply wherever noted. Other restrictions may apply. Package
sold by weight, not volume. Parental advisory - explicit lyrics. Penalty for
private use. Place stamp here. Please remain seated until the ride has come
to a complete stop. Possible penalties for early withdrawal. Post office will
not deliver without postage. Postage will be paid by addressee. Prerecorded
for this time zone. Price does not include taxes. Processed at location
stamped in code at top of carton. Quantities are limited while supplies last.
Read at your own risk. Record additional transactions on back of previous
stub. Replace with same type. Reproduction strictly prohibited. Restaurant
package, not for resale. Return to sender, no forwarding order on file,
unable to forward. Safety goggles may be required during use. Sanitized for
your protection. Sealed for your protection, do not use if the safety seal is
broken. See label for sequence. Shading within a garment may occur. Sign here
without admitting guilt. Simulated picture. Slightly enlarged to show detail.
Slightly higher west of the Rockies. Slippery when wet. Smoking these may be
hazardous to your health. Some assembly required. Some equipment shown is
optional. Some of the trademarks mentioned in this product appear for
identification purposes only. Subject to FCC approval. Subject to change
without notice. Substantial penalty for early withdrawal. Text may contain
material some readers may find objectionable, parental guidance is advised.
Text used in these documents is made from 100% recycled electrons and magnetic
particles. These documents do not reflect the thoughts or opinions of either
myself, my company, my friends, or my rabbit. This is not an offer to sell
securities. This offer is void where prohibited, taxed, or otherwise
restricted. This product is meant for educational purposes only. Times
approximate. Unix is a registered trademark of AT&T. Use only as directed. Use
only in a well-ventilated are. User assumes full liabilities. Void where
prohibited. We have sent the forms which seem right for you. You must be
present to win. You need not be present to win. Your canceled check is your
receipt. Your mileage may vary. I didn't do it. You can't prove anything.
This supersedes all previous notices.
*/
#endif // STDDCLMR_H

View file

@ -31,6 +31,8 @@
#define STORY_STATUS_SCORE_TURNS 0
#define STORY_STATUS_HOURS_MINUTES 1
#define STORY_FLAG_V3 0x01
#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)
@ -72,7 +74,7 @@
#define STORY_FLAG_3_USE_TRANSPARENCY (1 << 0)
#define storyVersion() memoryByte(0x0)
#define storyFlags() memoryByte(0x1)
#define storyFlags() memoryByte(STORY_FLAG_V3)
#define storyHightMemory() memoryWord(0x4)
#define storyInitialPC() memoryWord(0x6) // V1-5
#define storyInitialPackedPC() memoryUnpackAddress(memoryWord(0x6), MEMORY_ROUTINE) // V6

View file

@ -37,12 +37,18 @@
#include <stdio.h>
#include "stddclmr.h"
#include "memory.h"
#include "story.h"
#include "state.h"
#include "opcodes.h"
int main(void) {
memoryLoadStory();
printf("%d\n", storyVersion());
opcodesSetup();
return 0;
}

View file

@ -21,18 +21,32 @@
*/
#include <string.h>
#include "memory.h"
#include "story.h"
#include "state.h"
#include "zork1.h"
// The F256 has 512k of RAM. We use everything except the lower 64k.
static uint8_t RAM[1024 * (512 - 64)];
static uint8_t _RAM[1024 * (512 - 64)];
uint8_t memoryByte(uint16_t address) {
return RAM[address];
return _RAM[address];
}
void memorySetByte(uint16_t address, uint8_t value) {
_RAM[address] = value;
}
void memorySetWord(uint16_t address, uint16_t value) {
_RAM[address] = (value & 0xff00) << 8; // MSB first.
_RAM[address + 1] = value & 0x00ff;
}
@ -47,25 +61,42 @@ uint32_t memoryUnpackAddress(uint16_t address, uint8_t type) {
return (uint32_t)address * 4;
case 6:
if (type == MEMORY_ROUTINE) {
return ((uint32_t)address * 4) + storyRoutineOffset;
return ((uint32_t)address * 4) + storyRoutinesOffset();
} else {
return ((uint32_t)address * 4) + storyStringOffset;
return ((uint32_t)address * 4) + storyStringsOffset();
}
case 8:
return (uint32_t)address * 8;
}
return ((uint16_t)RAM[address] << 8) | ((uint16_t)RAM[address + 1]);
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]);
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];
memcpy(_RAM, zork1, zork1_len);
// Later, we probably want to see if the user has a memory expansion
// installed. If they do, we can use it and then use the lower memory
// for graphics and sound.
// Zero out all state data.
memset(&__state, 0, sizeof(stateT));
// Currently no status bar.
POKE(STORY_FLAG_V3, PEEK(STORY_FLAG_V3) | STORY_FLAG_V3_STATUS_LINE_NOT_AVAILABLE);
// Uncomment for status bar and window splitting.
//POKE(STORY_FLAG_V3, PEEK(STORY_FLAG_V3) & ~STORY_FLAG_V3_STATUS_LINE_NOT_AVAILABLE);
//POKE(STORY_FLAG_V3, PEEK(STORY_FLAG_V3) | STORY_FLAG_V3_SCREEN_SPLITTING);
// V6+ this is the address of main(), not just a raw starting address.
__state.pc = storyInitialPC();
__state.sp = 0;
}

35
src/oc_0op.c Normal file
View file

@ -0,0 +1,35 @@
/*
* 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 "oc_0op.h"
void opcodes_new_line(void) {
}
void opcodes_print(void) {
}

41
src/oc_1op.c 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.
*/
#include "oc_1op.h"
void opcodes_jump(void) {
}
void opcodes_jz(void) {
}
void opcodes_ret(void) {
}

54
src/oc_2op.c Normal file
View file

@ -0,0 +1,54 @@
/*
* 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 "oc_2op.h"
void opcodes_add(void) {
}
void opcodes_je(void) {
}
void opcodes_loadw(void) {
}
void opcodes_store(void) {
}
void opcodes_sub(void) {
}
void opcodes_test_attr(void) {
}

24
src/oc_ext.c Normal file
View file

@ -0,0 +1,24 @@
/*
* 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 "oc_ext.h"

39
src/oc_var_op.c Normal file
View file

@ -0,0 +1,39 @@
/*
* 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 "oc_var_op.h"
void opcodes_call(void) {
}
void opcodes_put_prop(void) {
}
void opcodes_storew(void) {
}

253
src/opcodes.c Normal file
View file

@ -0,0 +1,253 @@
/*
* 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 <stdint.h>
#include "story.h"
#include "state.h"
#include "opcodes.h"
#include "oc_0op.h"
#include "oc_1op.h"
#include "oc_2op.h"
#include "oc_var_op.h"
#include "oc_ext.h"
// Macros to declare implemented opcodes.
#define OP(name) __state.opcodes[_nextOpcode++] = opcodes_##name
#define OPn(num, name) __state.opcodes[num] = opcodes_##name
#define OPX(name) __state.extOpcodes[_nextOpcode++] = opcodes_ext_##name
#define OPXn(num, name) __state.extOpcodes[num] = opcodes_ext_##name
// Macros to declare un-implemented opcodes.
#define mOP(name) _nextOpcode++
#define mOPn(num, name)
#define mOPX(name) _nextOpcode++
#define mOPXn(num, name)
int16_t _nextOpcode;
void opcodesSetup(void) {
// 2-operand instructions...
_nextOpcode = 1;
OP(je);
mOP(jl);
mOP(jg);
mOP(dec_chk);
mOP(inc_chk);
mOP(jin);
mOP(test);
mOP(or);
mOP(and);
OP(test_attr);
mOP(set_attr);
mOP(clear_attr);
OP(store);
mOP(insert_obj);
OP(loadw);
mOP(loadb);
mOP(get_prop);
mOP(get_prop_addr);
mOP(get_next_prop);
OP(add);
OP(sub);
mOP(mul);
mOP(div);
mOP(mod); // oc# 24
// 1-operand instructions...
_nextOpcode = 128;
OP(jz);
mOP(get_sibling);
mOP(get_child);
mOP(get_parent);
mOP(get_prop_len);
mOP(inc);
mOP(dec); // oc# 135
_nextOpcode = 137;
mOP(print_addr);
mOP(remove_obj);
mOP(print_obj);
OP(ret);
OP(jump);
mOP(print_paddr);
mOP(load);
mOP(not); // oc# 143
// 0-operand instructions...
_nextOpcode = 176;
mOP(rtrue);
mOP(rfalse);
OP(print);
mOP(print_ret);
mOP(nop);
mOP(save);
mOP(restore);
mOP(restart);
mOP(ret_popped);
mOP(pop);
mOP(quit);
OP(new_line); // oc# 187
// variable operand instructions...
_nextOpcode = 224;
OP(call);
OP(storew);
mOP(storeb);
OP(put_prop);
mOP(read);
mOP(print_char);
mOP(print_num);
mOP(random);
mOP(push);
mOP(pull); // oc# 233
if (storyVersion() < 3) return;
_nextOpcode = 188;
mOP(show_status);
mOP(verify); // oc# 189
_nextOpcode = 234;
mOP(split_window);
mOP(set_window); // oc# 235
_nextOpcode = 243;
mOP(output_stream);
mOP(input_stream);
mOP(sound_effect); // oc# 245
if (storyVersion() < 4) return;
// show_status is illegal in ver4+, but a build of Wishbringer
// accidentally calls it, so always treat it as NOP instead.
mOPn(188, opcode_nop);
mOPn(25, call_2s);
mOPn(180, save_ver4);
mOPn(224, call_vs);
mOPn(228, sread_ver4);
_nextOpcode = 236;
mOP(call_vs2);
mOP(erase_window);
mOP(erase_line);
mOP(set_cursor);
mOP(get_cursor);
mOP(set_text_style);
mOP(buffer_mode); // oc# 242
_nextOpcode = 246;
mOP(read_char);
mOP(scan_table); // oc# 247
if (storyVersion() < 5) return;
_nextOpcode = 26;
mOP(call_2n);
mOP(set_colour);
mOP(throw);
mOPn(136, call_1s);
mOPn(143, call_1n);
mOPn(185, catch);
mOPn(191, piracy);
mOPn(228, aread);
mOPn(243, output_stream_ver5);
mOPn(245, sound_effect_ver5);
_nextOpcode = 248;
mOP(not_ver5);
mOP(call_vn);
mOP(call_vn2);
mOP(tokenise);
mOP(encode_text);
mOP(copy_table);
mOP(print_table);
mOP(check_arg_count); // oc# 255
// this is the "save" and "restore" opcodes in ver1-4; illegal in ver5+.
// in ver5+, they use extended opcodes 0 and 1 for these.
__state.opcodes[180] = 0;
__state.opcodes[181] = 0;
// extended opcodes in ver5+ ...
_nextOpcode = 0;
mOPX(save_ext);
mOPX(restore_ext);
mOPX(log_shift);
mOPX(art_shift);
mOPX(set_font); // xop# 4
_nextOpcode = 9;
mOPX(save_undo);
mOPX(restore_undo);
mOPX(print_unicode);
mOPX(check_unicode);
mOPX(set_true_colour); // xop# 13
if (storyVersion() < 6) return;
_nextOpcode = 27;
mOP(set_colour_ver6);
mOP(throw_ver6); // op# 28
mOPn(185, catch_ver6);
mOPn(233, pull_ver6);
_nextOpcode = 238;
mOP(erase_line_ver6);
mOP(set_cursor_ver6); // op# 239
mOPn(243, output_stream_ver6);
mOPn(248, not_ver6);
_nextOpcode = 4;
mOPX(set_font_ver6);
mOPX(draw_picture);
mOPX(picture_data);
mOPX(erase_picture);
mOPX(set_margins); // xop# 8
mOPXn(13, set_true_colour_ver6);
_nextOpcode = 16;
mOPX(move_window);
mOPX(window_size);
mOPX(window_style);
mOPX(get_wind_prop);
mOPX(scroll_window);
mOPX(pop_stack);
mOPX(read_mouse);
mOPX(mouse_window);
mOPX(push_stack);
mOPX(put_wind_prop);
mOPX(print_form);
mOPX(make_menu);
mOPX(picture_table);
mOPX(buffer_screen); // xop# 29
}

27
src/state.c Normal file
View file

@ -0,0 +1,27 @@
/*
* 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 "state.h"
stateT __state;