Code: Select all
REMark Program to Re-order names to match the original order
:
dev$ = "ram5_" : REMark change to suit
:
REMark dev$ & "QLIB_origina_obj" 46158 bytes
REMark add in CLEAR somewhere to below BAS file, before LIBERATE / QSAVE ing
REMark dev$ & "QLIB_BAS"
REMark dev$ & "QLIB_BAS_wrk" to update by overwriting
REMark dev$ & "QLIB_BAS_wrk_a" to input from - A COPY made from above file
:
COPY_O dev$ & "QLIB_BAS_wrk" TO dev$ & "QLIB_BAS_wrk_a"
a = FOP_IN(dev$ & "QLIB_BAS_wrk_a") : IF a<0 : REPORT a : STOP
b = FOPEN (dev$ & "QLIB_BAS_wrk") : IF b<0 : REPORT b : STOP
:
OPEN_IN #9,dev$ & "QLIB_origina_obj" : L = 673
SET_POSITION #9,44746 : orig$ = INPUT$(#9,L) : x$ = orig$
CLOSE #9 : L = 1
FOR ct = 1 TO 1E9: k = L+CODE(x$(L))+1: x$(L)=" ": L = k: IF L>LEN(x$): EXIT ct
OPEN_OVER #9,dev$ & "orig_names" : CLS
PRINT "QLIB_origina_obj" !!! LEN(x$) ! "bytes" !!! ct ! "names"\ x$ \""
PRINT #9,"QLIB_origina_obj" !!! LEN(x$) ! "bytes" !!! ct ! "names"\ x$ \""
CLOSE #9
: REMark 23456
REMark (5)CLEAR L = 5 the length of "CLEAR" orig$(2 TO 6)
:
max_i = ct-1 : REMark 101 names counted from origina_obj file
DIM redirect%(max_i)
GET #b\10 : REMark start of name table
REMark Re-order names to match the order in the original file
FOR i = 0 TO max_i
L = CODE(orig$(1))
name$ = orig$(2 TO L+1)
orig$ = orig$(L+2 TO LEN(orig$))
transfer (i),(name$)
END FOR i
IF orig$<>"" : PRINT #0,"More names found than expected" : STOP
update_program_name_indexes
CLOSE #a,#b
PRINT #0,dev$ & "QLIB_BAS_wrk successfully patched"
STOP
:
REMark transfer:
REMark search through #a name table to find the entry
REMark write that entry to #b - overwriting existing details
REMark redirect%(that entry) = i so can update names in program
:
DEFine PROCedure transfer(i%, name$)
LOCal n%, num1%, num2%, n$(255)
GET #a\10
FOR n% = 0 TO max_i
GET #a, num1%, num2%, n$ : IF n$ = name$ : EXIT n%
IF LEN(n$) && 1 : n$ = INKEY$(#a)
END FOR n%
PUT #b, num1%, num2%, n$
IF LEN(n$) && 1 : PRINT #b, CHR$(0);
redirect%(n%) = i%
END DEFine transfer
:
DEFine PROCedure update_program_name_indexes
LOCal s, scan, token, length%
GET #a\6, length% : REMark length of name table
s = 10 + length% + 2 : REMark start address of program
REPeat scan
GET #a\s : IF EOF(#a) : EXIT scan
token = CODE(INKEY$(#a))
SELect ON token
= 132 : REMark symbol
s = s+2 : token = CODE(INKEY$(#a)) : IF token = 10 : s = s+2
= 136 : REMark name
GET #a\s+2, i% : IF i% <= max_i : PUT #b\s+2, redirect%(i%)
s = s+4
= 138, 141 : s = s+4 : REMark integer, line_num
= 208 TO 255 : s = s+6 : REMark float, hex, bin
= 139, 140 : GET #a\(s+2), length% : REMark string, text
s = s+4 + length% + (length% && 1)
= REMAINDER : s = s+2
END SELect
END REPeat scan
END DEFine update_program_name_indexes
First, I got the files QLIB_BAS and the original QLIB_obj (46158 bytes) into ram5_
LOAD in ram5_QLIB_BAS and make any changes
LIBERATE ram5_QLIB_BAS ... to get the message work file created
LOAD in my attached program
RUN ... to get the message ram5_QLIB_BAS_wrk successfully patched
LIBERATE
Enter in ram5_QLIB_BAS
COMPILE
... compiles to ram5_QLIB_obj
For best results, run the above in Q-emuLator. I have used Minerva 1.97. There are earlier versions of Minerva on Dilwyn's site that might give better results.