Jump to content

Recommended Posts

Every so often I go back and revisit Quest for the Key of Nightshade, a type-in game by David Schmidt that won a prize for teenage coders back in 1983. The original listing from 80 Microcomputing is here, and the game circulated pretty widely, I think -- enough so that I got to play it for a few months back in the late 1980s when my family briefly had a Model III on loan.

For some reason circulating files of this game always seem to come with four different versions, named QNITESH1.BAS through QNITESH4.BAS, with no explanation as to which is which. I've been playing it over the past day using the Javascript emulator here, which also provides the BASIC source code for all four files in plaintext.

I ran some comparisons and found that QNITESH4.BAS was generally the closest to the original listing, as the other versions fix spelling errors, tweak the formatting -- and sometimes introduce typos in the code.

However, none of the files match Schmidt's original code when it comes to a line that may be crucial to the program's successful operation. The original magazine listing has the following at line 119:

DEFDBLG,JK

Here's what the four files have instead:

QNITESH1.BAS - DEFDBLG,J,K (moved to line 120)
QNITESH2.BAS - DEFDBLG,J,K (moved to line 120)
QNITESH3.BAS - DEFDBLG
QNITESH4.BAS - DEFDBLG,J

So my questions are as follows:

  • Am I correct that the original magazine listing is probably an error, and should have been either DEFDBLG,J,K or DEFDBLG,J-K?

EDIT: Looks almost certain to me.

  • If so, will the original listing refuse to run on real hardware, because it's trying to define an illegal variable JK?

EDIT: Confirmed, the command DEFDBLG,JK returns a ?SN ERROR.

  • Am I correct that QNITESH3 and QNITESH4 are both likely to cause a crash if the game tries to store a number above 65,535 in variable K (and/or variable J in QNITESH3)? I had the game crash once with an overflow or out-of-range error, and I'm guessing this was the cause.

EDIT: Yep, that seems to happen too -- passing values over 65,535 to a variable that hasn't been DEFDBL-ed returns an ?OV error. Hey, I guess I answered my own questions! :)

 

EDIT #2: Oh, now I get it: J is used to store money, K is used to store # of keys. K doesn't need to be a double-precision variable, so the K was probably just a typo to begin with, and the line should be DEFDBLG,J. QNITESH4.BAS is the right file to use, then!

I'm also curious whether this game was intended to be as absurdly, stupidly hard as it is. On anything but the lowest difficulty setting (which is already quite hard), you're swarmed by insane numbers of enemies from the start, with no real chance to build up enough of an army to defend yourself.

The only hope seems to be burglarizing the castles and getting as much gold as you can, but that's more or less what caused the overflow error I encountered -- as soon as I actually conquered a castle, the game crashed, I'm guessing because I was going to exceed 65,535 gold.

 

EDIT: QNITESH2.BAS seemed at first like it might be a bugfixed version of the code. Now I don't think so, and it also introduces a new typo:

 

2700 PRINT@239,"- WHAT DO YOU";:PRINT@303,"WHISH TO DO?";:RETURN

What do I "whish" to do? I don't know, let me ask Hwil Hweaton.

Just to add a refinement or two on your result note that the variables are must more limited because of the DEFINT A-Z which appears first. That makes the default type INT which can only store in the range -32768 .. 32767. So even going to 32768 gold would cause an overflow.

 

The DEFDBL might be overkill as even single precision (SNG - the default type) can store about 23 or 24 bits of integer values and then less precise integers when exponents get involved. Or any single precision floating point number, too, of course.

  • Like 2

Just to add a refinement or two on your result note that the variables are must more limited because of the DEFINT A-Z which appears first. That makes the default type INT which can only store in the range -32768 .. 32767. So even going to 32768 gold would cause an overflow.

 

Thanks for your reply! I did some more experimenting and was able to go well above 32678 gold by BREAKING out of the game and setting a new value for G -- the in-game routine supports an 8-digit total, with commas even.

 

But, I also got another ?OV ERROR crash that seems associated with the gold you get after successfully attacking a tomb (or maybe a castle). That makes me suspect there's another bug buried in the code -- I think it was this line:

 

 

2520 B$="SOLDIER":N=RND(CT%*5)+CT%*5:B=15:GOSUB7000:PRINT@866,"* BATTLE! *";:GOSUB8500:GOSUB7500:J=RND(N*3000)+N*1000:C=0:FORA=1TO5:

IFL(A)=M(X,Y)-6THENC=1:L(A)=0:GOSUB7600:GOTO6020:ELSENEXT:GOSUB7600:GOTO6020

 

Is there something happening with J=RND(N*3000)+N*1000 that would lead to a likely overflow error?

 

And: if DEFINT overrules DEFDBL, is that entire line of code moot? And then, how on earth does the game work at all? :D

 

EDIT: By the way, trying to run QNITESH1.BAS in the JavaScript emulator I linked earlier causes an immediate crash with an "?L3 Error in 10". Here's line 10:

 

10 CLEAR100:CMD"LC,N":RANDOM:DEFINTA-Z:DEFDBLP:DIMM(31,31),M$(11),T$(11),FT%(11),WM%(11),MO$(11,3),MO%(11,3)

 

I'm guessing it's the CMD"LC,N" that's tripping the error. It's a Level III command, if I understand correctly? What does it do?

RND() takes an INT parameter so if N >= 12 there will be a problem. That depends on %CT so hard to say if that can happen.

 

DEFINT doesn't override DEFDBL. It's just that it comes first to set the default but then DEFDBL comes later and changes G, J and K.

 

That CMD statement would be causing the ?L3 error. Don't know what it does, though. The Model I had a number of DOS variants so what it means will depend on whether it was meant for TRS-DOS, NEWDOS, LDOS or MULTIDOS.

  • Like 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...