Login
Forum Help



Post Your Message
="hidden" name="cat" value="Programming">
Username: (Login)

Topic:
Message:
 


Previous Messages
Posted By

Harry Potter
on 2023-07-27
14:14:02
 AdvSkel65/Plus4 128k: executing code for the wrong verb?

Hi! I am still trying to get AdvSkel65 to work on the Plus4 with 256k Hannes memory. It seems that, for all but the first verb in its database, the wrong verb code is being executed. I added debug code, and both the verb name and its entry # are correct. Also, the addresses of the verb-handling functions are correct. I changed the address of Verb #1 ("go") to Verb #0's address ("look") and type "go," it executes the code for "look," so that's not the problem. When I moved the code for some verbs from Low memory to the program's main memory, some verbs execute properly but not all. I really want to put some code into Low memory via my Cubbyhole optimization technique. I don't know why this is happening. sad I included the code to handle player input:
--------------------
while (1)
{
//Display the score board.
DispScoreBoard();
//Get user input and loop if empty.
if (!GetInput (&Input,38)) continue;
//Get verb #.
Vrb = FindVerb ();
//Verbs are assumed to be positive. If negative, invalid verb.
if (Vrb==255) {
//Print error and loop.
prints ("I don't know how to ");
prints (Input);
printperiod ();
continue;
}
// printu (Vrb);
//Skip space if it's after verb.
eatwhitei ();
//Set default value to item as no item.
Itm1=0xFF;
//If character at current pos. in input is not 0,
if (Input[CurPos])
{
//Get item #.
if ((Itm1 = FindItem ())==255) {
//If no item, error and loop.
prints ("I don't know what a ");
prints (inx);
printscr (" is.");
continue;
}
//Get item information ptr. to current item's entry.
ItemPtr=&Item[Itm1];
}
//printu (Itm1);
//Get verb member handling routine's address.
runverb:
//If using memory extension, the data is in ext. memory
//except for the C128, where they are stored in
//a stub.
// printu (Vrb); printcr();
#if defined __USEFARMEM__ && !defined __C128__
func=hidereadw((void*)&Verb[Vrb].vdo);
#else
func=Verb[Vrb].vdo;
#endif
(*func) ();
}
}
-------------------------
the declaration and definition of the verbs:
-------------------------
//Holds each verb entry.
typedef struct verb_
{
//Verb name.
unsigned char* Name;
//Routine to perform action.
void (*vdo) (void);
};

//Declares verbs.
//NumVerbs is defined in aconst.h. If you need more
//verbs, increase this number and add the verbs to the "wordsdb.c"
//file.
extern const struct verb_ Verb [NumVerbs];

const struct verb_ Verb[] ={
{"look", &vLook},
{"go", &vGo},

{"get", &vGet},
{"grab", &vGet},
{"take", &vGet},
{"put", &vPut},
{"place", &vPut},
{"drop", &vPut},
{"inventory", &vItems},
{"i", &vItems},

{"intro", &vIntro},
{"help", &vHelp},
{"read", &vRead},

{"n", &vGoNorth},
{"s", &vGoSouth},
{"e", &vGoEast},
{"w", &vGoWest}
};
---------------------------
and the code that interprets the verb and returns its #:
---------------------------
//Searches for the verb given at the start of Input and returns the verb #.
//Returns 0xFF if not found.
unsigned char FindVerb (void)
{
//j holds the current scan verb.
j=0;
//Loop to scan for matching verb.
for (; j < NumVerbs; ++j)
{
//Start at pos. 0 in scans.
for (CurPos=0;
//C128's verbs are in a stub.
#ifdef __C128__
//Load current character in both input verb and
//test verb while comparing.
(e=Input[CurPos]) == (c=(Verb[j].Name[CurPos])) &&
#else
(c=(hidereadb((unsigned)hidereadw((char*)&Verb[j].Name)+CurPos))) &&
(e=Input[CurPos]) == c &&
#endif
//If ==, check for end of verb and either space or NUL in input.
e >= 33 && c
; ++CurPos);
//If so, return verb #. Current pos. points to the character
//after the input noun.
if (Input[CurPos]<33 && c==0)
{
return j;
}
}
//If no match found, skip to after verb and write 0
//so that the main player function can print just the verb
//in the error message.
__asm__ (
"\tldx\t_CurPos\n"
"a00:\n"
"\tlda\t_Input,x\n"
"\tcmp\t#33\n"
"\tbcc\ta01\n"
"\tinx\n"
"\tbne\ta00\n"
"a01:\n"
"\tstx\t_CurPos\n"
"\tlda\t#0\n"
"\tsta\t_Input,x\n"
);
//Return no verb.
return -1;
}
-----------------------------


Copyright © Plus/4 World Team, 2001-2024. Support Plus/4 World on Patreon