HREPLP - HEPAX replace program

whuyse
Posts: 198
Joined: Thu Dec 21, 2017 1:23 pm

HREPLP - HEPAX replace program

Post by whuyse »

Update 2: remember it again. Angel has provided a new function PCOPY, and now it works. The program has been altered slightly, so make sure to copy it again.
obsolete: Update: forget it, it doesn’t work. Culprit is HGETP, which copies the program file to main memory and executes it - which doesn’t make sense at all.

The HEPAX manual warns you for it: when you make changes to a program file and save it again (with HSAVEP), it will be moved to the end of the file chain (or to the first available free space if you have more than 1 page? I don't know), and your XROM numbers may be messed up.
If the number and order of programs in your files don't change, the following routine will 'replace' a program in the HEPAX file chain, by saving the program you want and all programs between its old and new position, so that they are again in the same order and XROM numbering is kept.
Caveats:
- it works only if all your files bear program names, not file names,
- only for program names not exceeding 6 characters, and not ending in a blank.
- only with Angel's HEPAX Plus that has PCOPY
- can not be used as a subroutine

There will probably be file chain scenarios for which this doesn't work, but for the time being, it serves my purpose ;-)

In: A: program name to save

Code: Select all

01>LBL "HUPDP"
-- 102 Bytes including END
-- 1. find out the file's HEPDIR index number n. ie it is the nth file in the chain.
-- result of HEPDIRX is padded with trailing blanks, though..
--              L       X       Y       Z       T       A
02 CLX
03 ABS
04 ASTO T
05 +"     "
06 ASTO X

07>LBL 02       n       "P "    -       -       "P"
08 R^
09 LASTX
10 1
11 +
12 HEPDIRX      n       TYPE    "P"    "P "
13 0
14 X=Y?
15 GTO 00
16 ASTO X
17 R^           n       "P "    "Fn"    TYPE    "P"
18 X#Y?
19 GTO 02

20 RDN
21 CLX
22 LASTX                        n       "PR"    "P"     "P "

23 LBL 00               n       0       0       "P"     "P "
24 CLA
25 ARCL Z
--
-- 2. Save the file, putting it LAST in the chain, or at least, further up
--
26 HSAVEP
27 X=0?
28 RTN
-- 3. do
--      HEPDIRX n
--      is it a PR? 
--      then
--        is that our replaced file? then exit;
--        HGETP, HSAVEP and PCLPS
--      end;
--      else n := n+1;
--    loop;
--
--              L       X       Y       Z       T       A
--                      n       "PR"    -       "P "
29 LBL 03
30 HEPDIRX      n       TYPE    "PR"    -       "P "    "Fn "
31 X#Y?
32 GTO 00
33 ASTO X
34 R^           n       "P "    "Fn "   "PR"
35 X=Y?
36 RTN
37 RCL Z
38 32
39 ENTER
-- remove trailing blanks
--              n       -       32      "PR"    "P "    "Fn "
40 LBL 04
41 CLX
42 -1
43 AROT
44 CLX
45 ATOX
46 X=Y?
47 GTO 04
48 XTOA
49 X<> T
50 PCOPY        destroys T
51 HSAVEP
52 PCLPS
53 RDN
54 GTO 01

55>LBL 00
56 ISG L
57 LBL 01       n       -       "PR"    -       "P "
58 CLX
59 LASTX
60 GTO 03
61 END
In the hope someone will find this useful ;-)
Werner
Last edited by whuyse on Fri Mar 19, 2021 3:16 pm, edited 6 times in total.
41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE, DM15L
Ángel Martin
Posts: 145
Joined: Mon Apr 24, 2017 8:19 pm

Re: HREPLP - HEPAX replace program

Post by Ángel Martin »

Nice utility Werner, taking advantage of the file relocation that results in the sequence:

HGETP
HSAVEP

If you don't mind I'd like to include it in my next HEPAX APPS module in preparation...

Cheers,
ÁM
whuyse
Posts: 198
Joined: Thu Dec 21, 2017 1:23 pm

Re: HREPLP - HEPAX replace program

Post by whuyse »

I’d be honoured, Angel!
Werner
41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE, DM15L
hpgene
Posts: 36
Joined: Mon May 29, 2017 3:02 pm

Re: HREPLP - HEPAX replace program

Post by hpgene »

HEPAX Apps module? Now that sounds interesting! :-)
whuyse
Posts: 198
Joined: Thu Dec 21, 2017 1:23 pm

Re: HREPLP - HEPAX replace program

Post by whuyse »

I made a massive improvement to the program: I reduced the

Code: Select all

+"      "
 to
+"     "
;-) that is, 5 blanks instead of 6.
Added the condition that program names may not exceed 6 characters, and not end in a blank.
Also, probably AROT, ATOX, and XTOA should be replaced by their HEPAX XF counterparts.

Cheers, Werner
41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE, DM15L
whuyse
Posts: 198
Joined: Thu Dec 21, 2017 1:23 pm

Re: HREPLP - HEPAX replace program

Post by whuyse »

Unfortunately it doesn’t work.
HGETP transfers execution to the program copied..
Too bad. Doesn’t make sense..
Werner
41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE, DM15L
Ángel Martin
Posts: 145
Joined: Mon Apr 24, 2017 8:19 pm

Re: HREPLP - HEPAX replace program

Post by Ángel Martin »

I've prepared an update that corrects the issue in HGETP.
Use the function PCOPY instead, available in the attached module and let us know how it goes.

Now the step sequence:

PCOPY (with the program name in ALPHA)
HSAVEP

works as intended, the program pointer remains in the running program.
PCOPY destroys the stack T register, be aware of that.

With this change I've tried your routine and works as expected, but you should do some additional testing to cover all scenarios.

BTW your routine is also loaded in the attached MOD, I've named it HUPDP - Hepax Update Program

Cheers,
ÁM

ps. Edited with an updated MOD file
Attachments
HPX_PLUS (2).zip
(3.48 KiB) Downloaded 186 times
whuyse
Posts: 198
Joined: Thu Dec 21, 2017 1:23 pm

Re: HREPLP - HEPAX replace program

Post by whuyse »

Thanks, Angel!
I had made a workaround, requiring all HEPAX program files to start with STO b, and to call HGETP with:

Code: Select all

SF 25
CLX
RCL b
FS?C 25
HGETP
Then at least I could verify that my program worked ;-)

I have - in the meantime - altered the program (I'll call it HUPDP as well from now on), and posted a new version in the first post here. It used L as well as T, so I did have to make changes to make it work with PCOPY ;-)

Cheers, Werner
41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE, DM15L
Ángel Martin
Posts: 145
Joined: Mon Apr 24, 2017 8:19 pm

Re: HREPLP - HEPAX replace program

Post by Ángel Martin »

Not sure the RCL b does any help because I believe HGETP will still execute the copied program, right?
That's why you should use PCOPY instead, which preserves the program pointer of the routine that calls it.

I'll check your new version but the original one was working just fine after I modified the MCODE to use register T for scratch, leaving LastX untouched.

ÁM
whuyse
Posts: 198
Joined: Thu Dec 21, 2017 1:23 pm

Re: HREPLP - HEPAX replace program

Post by whuyse »

The RCL b alone, no:
whuyse wrote:
Fri Mar 19, 2021 1:24 pm
I had made a workaround, requiring all HEPAX program files to start with STO b,
Cheers, Werner
41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE, DM15L
Post Reply