From ea56c4006211ba788ee3c24e0808f3319eae2095 Mon Sep 17 00:00:00 2001 From: claudio Date: Fri, 21 Aug 2015 14:21:17 -0400 Subject: [PATCH] More progress on sanity checks --- newrpl/directory.c | 25 +++++++----------------- newrpl/lib-24-string.c | 15 ++++++++++++-- newrpl/lib-28-dirs.c | 42 ++++++++++++++++++++++++++++++++++++++-- newrpl/lib-common.c | 29 +++++++++++++++++++++++++++ newrpl/lib-twelve-bint.c | 20 +++++++++++++++++-- newrpl/libraries.h | 20 +++++++++++++++++++ newrpl/sanity.c | 7 +++++-- 7 files changed, 132 insertions(+), 26 deletions(-) diff --git a/newrpl/directory.c b/newrpl/directory.c index 9db3581..6e2f443 100644 --- a/newrpl/directory.c +++ b/newrpl/directory.c @@ -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=table[idx]) && (ptr=idx) { + RetNum=ERR_NOTMINE; + return; + } + ObjectPTR=table[ROMPTRID_IDX(id)]+ROMPTRID_OFF(id); + RetNum=OK_CONTINUE; +} diff --git a/newrpl/lib-twelve-bint.c b/newrpl/lib-twelve-bint.c index 7dda7c4..50fe6a5 100644 --- a/newrpl/lib-twelve-bint.c +++ b/newrpl/lib-twelve-bint.c @@ -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: diff --git a/newrpl/libraries.h b/newrpl/libraries.h index c2edc51..7ecf65f 100644 --- a/newrpl/libraries.h +++ b/newrpl/libraries.h @@ -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 diff --git a/newrpl/sanity.c b/newrpl/sanity.c index c776aa9..c4ae54e 100644 --- a/newrpl/sanity.c +++ b/newrpl/sanity.c @@ -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=dirptr)&&(scan