More progress on sanity checks

This commit is contained in:
claudio 2015-08-21 14:21:17 -04:00
parent d96e89ea4e
commit ea56c40062
7 changed files with 132 additions and 26 deletions

View file

@ -10,20 +10,10 @@
#include "libraries.h"
const WORD const dir_start_bint[]=
{
(WORD)DIR_START_MARKER
};
const WORD const dir_end_bint[]=
{
(WORD)DIR_END_MARKER
};
const WORD const dir_parent_bint[]=
{
(WORD)DIR_PARENT_MARKER
};
extern const WORD const dir_start_bint[];
extern const WORD const dir_end_bint[];
extern const WORD const dir_parent_bint[];
extern const WORD const root_dir_handle[];
// GROW THE DIRECTORY REGION
@ -110,8 +100,6 @@ void rplCreateGlobal(WORDPTR nameobj,WORDPTR value)
WORDPTR *rplFindDirbyHandle(WORDPTR handle)
{
if(!handle) return 0;
WORDPTR *scan=Directories;
while(scan<DirsTop) {
@ -178,7 +166,7 @@ WORDPTR *rplMakeNewDir()
direntry[0]=(WORDPTR)dir_start_bint;
direntry[1]=(WORDPTR)dirobj;
direntry[2]=(WORDPTR)dir_parent_bint;
direntry[3]=0; // NO PARENT!!!
direntry[3]=(WORDPTR)root_dir_handle; // NO PARENT!!!
direntry[4]=(WORDPTR)dir_end_bint;
direntry[5]=(WORDPTR)dirobj;
@ -362,9 +350,10 @@ void rplPurgeGlobal(WORDPTR nameobj)
WORDPTR rplGetDirName(WORDPTR *dir)
{
WORDPTR *parent=dir+3;
if(!*parent) return 0;
parent=rplFindDirbyHandle(*parent);
if(!parent) return 0;
while(*parent!=dir_end_bint) {
if(*(parent+1)==*(dir+1)) return *parent;

View file

@ -21,6 +21,7 @@
#define LIB_NAMES lib24_names
#define LIB_HANDLER lib24_handler
#define LIB_NUMBEROFCMDS LIB24_NUMBEROFCMDS
#define ROMPTR_TABLE romptr_table24
// LIST OF LIBRARY NUMBERS WHERE THIS LIBRARY REGISTERS TO
// HAS TO BE A HALFWORD LIST TERMINATED IN ZERO
@ -75,6 +76,16 @@ const WORD const empty_string[]={
MKPROLOG(DOSTRING,0)
};
// EXTERNAL EXPORTED OBJECT TABLE
// UP TO 64 OBJECTS ALLOWED, NO MORE
const WORDPTR const ROMPTR_TABLE[]={
(WORDPTR)empty_string,
0
};
// COMPUTE THE STRING LENGTH IN CHARACTERS
BINT rplStrLen(WORDPTR string)
@ -473,7 +484,7 @@ void LIB_HANDLER()
// LIBBRARY RETURNS: ObjectID=new ID, RetNum=OK_CONTINUE
// OR RetNum=ERR_NOTMINE IF THE OBJECT IS NOT RECOGNIZED
RetNum=ERR_NOTMINE;
libGetRomptrID(LIBRARY_NUMBER,(WORDPTR *)ROMPTR_TABLE,ObjectPTR);
return;
case OPCODE_ROMID2PTR:
// THIS OPCODE GETS A UNIQUE ID AND MUST RETURN A POINTER TO THE OBJECT IN ROM
@ -481,7 +492,7 @@ void LIB_HANDLER()
// LIBRARY RETURNS: ObjectPTR = POINTER TO THE OBJECT, AND RetNum=OK_CONTINUE
// OR RetNum= ERR_NOTMINE;
RetNum=ERR_NOTMINE;
libGetPTRFromID((WORDPTR *)ROMPTR_TABLE,ObjectID);
return;
case OPCODE_CHECKOBJ:

View file

@ -22,6 +22,7 @@
#define LIB_NAMES lib28_names
#define LIB_HANDLER lib28_handler
#define LIB_NUMBEROFCMDS LIB28_NUMBEROFCMDS
#define ROMPTR_TABLE romptr_table28
// LIST OF LIBRARY NUMBERS WHERE THIS LIBRARY REGISTERS TO
// HAS TO BE A HALFWORD LIST TERMINATED IN ZERO
@ -71,6 +72,43 @@ const char * const LIB_NAMES[]= { CMD_LIST /*, CMD_EXTRANAME*/ };
#undef CMD
const WORD const dir_start_bint[]=
{
(WORD)DIR_START_MARKER
};
const WORD const dir_end_bint[]=
{
(WORD)DIR_END_MARKER
};
const WORD const dir_parent_bint[]=
{
(WORD)DIR_PARENT_MARKER
};
const WORD const root_dir_handle[]=
{
(WORD)MKPROLOG(DODIR,1),
(WORD)0
};
// EXTERNAL EXPORTED OBJECT TABLE
// UP TO 64 OBJECTS ALLOWED, NO MORE
const WORDPTR const ROMPTR_TABLE[]={
(WORDPTR)dir_start_bint,
(WORDPTR)dir_parent_bint,
(WORDPTR)dir_end_bint,
(WORDPTR)root_dir_handle,
0
};
void LIB_HANDLER()
{
if(ISPROLOG(CurOpcode)) {
@ -432,7 +470,7 @@ void LIB_HANDLER()
// LIBBRARY RETURNS: ObjectID=new ID, RetNum=OK_CONTINUE
// OR RetNum=ERR_NOTMINE IF THE OBJECT IS NOT RECOGNIZED
RetNum=ERR_NOTMINE;
libGetRomptrID(LIBRARY_NUMBER,(WORDPTR *)ROMPTR_TABLE,ObjectPTR);
return;
case OPCODE_ROMID2PTR:
// THIS OPCODE GETS A UNIQUE ID AND MUST RETURN A POINTER TO THE OBJECT IN ROM
@ -440,7 +478,7 @@ void LIB_HANDLER()
// LIBRARY RETURNS: ObjectPTR = POINTER TO THE OBJECT, AND RetNum=OK_CONTINUE
// OR RetNum= ERR_NOTMINE;
RetNum=ERR_NOTMINE;
libGetPTRFromID((WORDPTR *)ROMPTR_TABLE,ObjectID);
return;
case OPCODE_CHECKOBJ:

View file

@ -130,3 +130,32 @@ void libGetInfo2(WORD opcode,char *libnames[],BINT tokeninfo[],int numcmds)
}
RetNum=ERR_NOTMINE;
}
void libGetRomptrID(BINT libnum,WORDPTR *table,WORDPTR ptr)
{
BINT idx=0;
while(table[idx]) {
if( (ptr>=table[idx]) && (ptr<table[idx]+OBJSIZE(*table[idx])+1)) {
BINT offset=ptr-table[idx];
ObjectID=MKROMPTRID(libnum,idx,offset);
RetNum=OK_CONTINUE;
return;
}
++idx;
}
RetNum=ERR_NOTMINE;
return;
}
void libGetPTRFromID(WORDPTR *table,WORD id)
{
BINT idx;
while(table[idx]) ++idx;
if(ROMPTRID_IDX(id)>=idx) {
RetNum=ERR_NOTMINE;
return;
}
ObjectPTR=table[ROMPTRID_IDX(id)]+ROMPTRID_OFF(id);
RetNum=OK_CONTINUE;
}

View file

@ -19,6 +19,7 @@
#define LIB_NAMES lib12_names
#define LIB_HANDLER lib12_handler
#define LIB_NUMBEROFCMDS LIB12_NUMBEROFCMDS
#define ROMPTR_TABLE romptr_table12
// LIST OF LIBRARY NUMBERS WHERE THIS LIBRARY REGISTERS TO
// HAS TO BE A HALFWORD LIST TERMINATED IN ZERO
@ -92,6 +93,21 @@ const WORD const three_bint[]=
(WORD)MAKESINT(3)
};
// EXTERNAL EXPORTED OBJECT TABLE
// UP TO 64 OBJECTS ALLOWED, NO MORE
const WORDPTR const ROMPTR_TABLE[]={
(WORDPTR)zero_bint,
(WORDPTR)one_bint,
(WORDPTR)two_bint,
(WORDPTR)three_bint,
(WORDPTR)minusone_bint,
0
};
const char const alldigits[]="0123456789ABCDEF";
WORDPTR rplNewSINT(int num,int base)
@ -1206,7 +1222,7 @@ void LIB_HANDLER()
// LIBBRARY RETURNS: ObjectID=new ID, RetNum=OK_CONTINUE
// OR RetNum=ERR_NOTMINE IF THE OBJECT IS NOT RECOGNIZED
RetNum=ERR_NOTMINE;
libGetRomptrID(LIBRARY_NUMBER,(WORDPTR *)ROMPTR_TABLE,ObjectPTR);
return;
case OPCODE_ROMID2PTR:
// THIS OPCODE GETS A UNIQUE ID AND MUST RETURN A POINTER TO THE OBJECT IN ROM
@ -1214,7 +1230,7 @@ void LIB_HANDLER()
// LIBRARY RETURNS: ObjectPTR = POINTER TO THE OBJECT, AND RetNum=OK_CONTINUE
// OR RetNum= ERR_NOTMINE;
RetNum=ERR_NOTMINE;
libGetPTRFromID((WORDPTR *)ROMPTR_TABLE,ObjectID);
return;
case OPCODE_CHECKOBJ:

View file

@ -45,6 +45,8 @@ extern const LIBHANDLER ROMLibs[];
#define MKOPCODE(lib,op) (WORD)((((lib)&0xFFF)<<20)|((op)&0x7FFFF))
#define MKPROLOG(lib,size) ((((lib)&0xFFF)<<20)|((size)&0x3FFFF)|0x80000)
#define OPCODE(p) ( (p)&0x7FFFF)
#define OBJSIZE(p) ((p)&0x3FFFF)
#define LIBNUM(p) ((((WORD)(p))>>20)&0xFFF)
@ -114,6 +116,11 @@ extern void libDecompileCmds( char *libnames[], WORD libopcodes[], int
extern void libProbeCmds(char *libnames[], BINT tokeninfo[], int numcmds);
extern void libGetInfo(WORD opcode,char *libnames[],WORD libopcodes[],BINT tokeninfo[],int numcmds);
extern void libGetInfo2(WORD opcode, char *libnames[], BINT tokeninfo[], int numcmds);
extern void libGetRomptrID(BINT libnum,WORDPTR *table,WORDPTR ptr);
extern void libGetPTRFromID(WORDPTR *table,WORD id);
#define APPROX_BIT 1
@ -169,6 +176,7 @@ extern void libGetInfo2(WORD opcode, char *libnames[], BINT tokeninfo[], int num
#define MAKESINT(a) MKOPCODE(DECBINT,(a)&0x3ffff)
// CONVENIENCE MACRO TO GET SIZE OF A MATRIX
#define MATMKSIZE(rows,cols) ( (((rows)&0xffff)<<16)|((cols)&0xffff) )
#define MATROWS(size) ( ((size)>>16)&0xffff )
@ -189,7 +197,19 @@ extern void libGetInfo2(WORD opcode, char *libnames[], BINT tokeninfo[], int num
#define LIB_LOCALENV 4080
// DEFINE OVERLOADABLE OPERATORS
#define LIB_OVERLOADABLE 4090
// ROMPTR ID'S
#define LIB_ROMPTR 0xfe0
// MACRO TO CREATE/EXTRACT ROMPTR ID'S
// ROMPTR IDS HAVE THE HIGH BYTE = 0XFE
// NO LIBRARIES CAN USE THE NUMBERS ABOVE 0XFE0 (4064 TO 4079 ARE ROMPTR ID'S, 4080 TO 4095 ARE SYSTEM LIBS)
// ROMPTR ID ENCODES UP TO 63 ROM OBJECTS, WITH MAXIMUM SIZE OF 31 WORDS EACH
#define MKROMPTRID(lib,idx,off) MKOPCODE(LIB_ROMPTR+(((lib)>>8)&0xf), ((((lib)&0xFF)<<11)|(((idx)<<5)&0x3f)|(((off)&0x1f))) )
#define ROMPTRID_IDX(id) (((id)>>5)&0x3f)
#define ROMPTRID_OFF(id) ((id)&0x1f)
#define ROMPTRID_LIB(id) ((((id)>>16)&0xf00)|(((id)>>11)&0xff))
// COMMANDS THAT NEED TO BE ACCESSED FROM MULTIPLE LIBRARIES
// WARNING: IF COMMANDS ARE REORGANIZED WITHIN LIBRARIES, THIS WILL BREAK

View file

@ -238,6 +238,7 @@ return obj;
extern const WORD const dir_start_bint[];
extern const WORD const dir_end_bint[];
extern const WORD const dir_parent_bint[];
extern const WORD const root_dir_handle[];
BINT rplVerifyDirectories(BINT fix)
{
@ -340,10 +341,11 @@ while(dirptr<DirsTop) {
parent=dirptr[3];
if(!rplIsTempObPointer(parent)) {
if(parent!=root_dir_handle) {
// BAD HANDLE POINTER
if(!fix) return 0;
// SCAN FOR A POSSIBLE PARENT DIR ENTRY WITH OUR HANDLE
parent=root_dir_handle;
WORDPTR *scan=Directories+1;
while(scan<DirsTop) {
if( (scan>=dirptr)&&(scan<dirend)) { scan=dirend+3; continue; }
@ -367,8 +369,9 @@ while(dirptr<DirsTop) {
}
}
// HERE EITHER WE HAVE A NEW PARENT HANDLE OR IT'S UNCHANGED
// HERE EITHER WE HAVE A NEW PARENT HANDLE OR IT'S ROOT
dirptr[3]=parent;
}
}