The Museum of HP Calculators

HP Articles Forum

[Return to the Index ]
[ Previous | Next ]


41-CL Routine of the week: MMUSWAP

Posted by Ángel Martin on 4 Nov 2012, 5:57 a.m.

Swapping MMU Pages

Often I get in a situation with my CL setup where I need to exchange the location of two pages; the virtual equivalent to swapping two 4k-modules plugged in the "normal" 41 machine ports.

The short routine below is a practical solution using a couple of functions from the AMC_OS/X (can be replaced with the same functions in the CDD or standard OS/X Modules).

It works by exchanging the MMU mappings to the page pointers, as simple as that: no need to type the ROM ID's, or do any data copying - such is the power of the MMU design.

Simply enter the FROM:/TO: page numbers in Y and X respectively (in decimal), then execute MMUSWP and the job is done.

Valid inputs are 8 to 15. The CL will prevent you from re-mapping the OS, but stay clear form 0-5 in the inputs to avoid getting in trouble. Better yet, modify the program to prevent any accidental invalid page range.

Page 4 is definitely to be excluded. It's up to you to allow 6 and 7 as well, just remember the OS rules about the printer and HPIL pages.

See the code below, short and sweet as promised:

01	LBL "MMUSWP"
02	8
03	WSIZE
04	RDN
05	XEQ 00
06	ASTO T
07	XEQ 00
08	ASTO L
09	XEQ 02
10	R^
11	STO L
12	RDN
13	LBL 02
14	"804"
15	ARCLH
16	"|-0"
17	ARCL L
18	YPOKE
19	X<>Y
20	RTN
21	LBL 00
22	"804"
23	ARCLH
24	"|-0-1111"
25	YPEEK
26	ASHF
27	X<>Y
28	END

Note: first byte in lines 16 and 24 is the APPEND character, "|-"

Caveat Emptor:

First off, this is for single pages and not for complete modules. Using it on multiple-page modules will of course create havoc with their FATs and general arrangements.

Second, if including the AMC_OS/X itself in the swapping it should be in the FROM: location (Y register). Otherwise it’ll get unmapped before the program ends, and won’t be possible to use the remaining ARCLH instruction.

For the same reason swapping the page mapped to the YFNS will be a problem if it's first un-mapped, as the following YPOKE instruction will NOT be found by the OS. Moreover, even using it in the FROM: location won't suffice: the last YPOKE line will be found but it'll then attempt to "re-map YFNS from itself", which will freeze the calculator just the same. In summary, do NOT attempt to swap the YFNS page at all.

Better safe than sorry: insert this subroutine before line 21:

23	*LBL 01	
24	"OS AREA"	
25	6	can use 7/8 to protect
26	X>Y?	the HPIL and PRINTER
27	PROMPT	
28	X>Y?	
29	GTEND	go to .END.
30	RDN	
31	"PG=YFNS"	
32	YFNZ?	
33	X=Y?	
34	PROMPT	
35	X=Y?	
36	GTEND	go to .END.
37	RDN	
38	X<>Y	swap FROM:/TO:
39	RTN	

And insert these two lines before line 01 to "anchor" YFNS to its current page:-

01 XEQ 01
02 XEQ 01

./

Edited: 4 Nov 2012, 2:55 p.m.

Password:

[ Return to the Message Index ]

Go back to the main exhibit hall