ÿþ{{ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % DOL3 Core V003 in alpha % % Author: Steven Messenger % % Copyright (c) 2010 Steven Messenger % % See end of file for terms of use. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% This is DOL3 (Dynamic Object Launcher). A big improvement on the original DOL and DOL2, well it would be if I tested it... This version cuts back on everything so it will be more useful. ************** *Known Issues* ************** 0001 - Found in versions: V001 beta - Description: Not finished yet! - Workaround: Wait for me to finish it! - Fixed in version: - Credit: Steven 0002 - Found in versions: V002 - Description: Need to compile using Sphinx to get the object address constants and object referencing working. - Workaround: Wait for someone else to modify other spin compilers! - Fixed in version: V003 - No long an issue in DOL itself, now only a problem in objects you want to load. - Credit: Steven ********** *Versions* ********** V003 - Released: not yet - New features - Much simplified, DOL should now be used as a child rather than a parent. - It is now up to the parent application to deallocate memory. - Bug fixes - N/A - Other improvements - N/A - API changes - Removed everything except "loadObject" and that has been significantly changed. When you want to load an object simply call this with a pointer to a file name in "fileNamePtr" and a "0" in "mode" to load an entire object. If you put a current object address in "mode" than only space for the var part of the object will be allocated, just like happens when you compile a spin program on a p.c. The value returned is the object address that you would use as demonstrated in the objTemp.spn file. }} CON 'abort values. If something goes wrong, aborted gets set to TRUE and one of these values is returned. #0 AbortNotEnoughMemory 'There is not enough memory left to complete the operation AbortCouldNotFindFile 'The file could not be found FULL=0 OBJ sd : "fsrwDOL" mem : "heap" VAR long aborted PUB loadObject(fileNamePtr,mode)|objectLength,varSize,objectStartBase,objectAddr 'open file if sd.popen(fileNamePtr,"r")<>0 long[@aborted]:=true abort AbortCouldNotFindFile 'read ProgramStart, VARStart and StackStart from header 'subtracting these will give us program length and var length 'set objectSize - from header 'read all the data in the header and use whatever we need repeat 8 sd.pgetc objectLength:=sd.pgetc '8 'byte of varBASE objectLength.byte[1]:=sd.pgetc '9 'byte of varBase objectLength:=objectLength-$10 varSize:=sd.pgetc 'A 'byte of stack start varSize.byte[1]:=sd.pgetc 'B 'byte of stack start varSize:=VARSize-$10-objectLength-8 '-$8 fudge factor to be figured out repeat 4 'get to end of header sd.pgetc if mode==FULL 'allocate space for methods objectStartBase:=mem.allocate(objectLength+3) 'need the extra 3 bytes so we can make sure that the object is long aligned if objectStartBase<10 long[@aborted]:=true mem.free(objectStartBase) sd.pclose abort AbortNotEnoughMemory 'long align the object space objectStartBase:=(objectStartBase+3)&!%11 'load methods sd.pread(objectStartBase,objectLength) else objectStartBase:=mode.word[0] sd.pclose 'allocate space for VAR objectVarBase:=mem.allocate(varSize+3) 'need the extra 3 to ensure vars are long aligned if objectVarBase<10 long[@aborted]:=true mem.free(objectVarBase) if mode==FULL mem.free(objectStartBase) abort AbortNotEnoughMemory 'long align the variables objectVarBase:=(objectVarBase+objectVarBase+3)&!%11 'zero the var area bytefill(objectVarBase,0,varSize) objectAddr.word[0]:=objectStartBase objectAddr.word[1]:=objectVarBase return objectAddr {{ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % TERMS OF USE: MIT License % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%$% %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. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% }}