HP-41 MCODE: Making an MCODE program call another MCODE program



#2

I am writing an MCODE program (in a NoV-32) that will be called upon turning my HP-41 on. This program will return if user flag 0 is not set. If user flag 0 is set, it will call another MCODE program (not just jump to its first executable) - a prompting function that will ask for a password to be entered. It will then check to see if the password is equal to a hard coded password in the program. If yes it will return, if no it will turn the calc off. Turning the calc back on will of course make it autostart the first MCODE program all over, and it will call the prompting password function etc. And so it goes until the right password is entered.

This will effectively lock the NoV-32 down, protecting any sensitive data on it. The calc is of course not locked as the NoV-32 can be removed before turning the calc on and the calc is then fully usable. But as long as the module is plugged in before turning the 41 on, the password function is again blocking entry.

Now, how do I make the first function call the prompting password-entry function?


#3

Usually by the long "gosub" instruction (HP mnemonic, "?NC XQ" user community mnemonic) instruction, provided that the previous instruction couldn't set the carry flag.

To do a subroutine call in a ROM that isn't at a fixed address, you need to use a mainframe ROM subroutine to do a "port-dependent" call.
To call a subroutine within the same 1K portion of the ROM, do
a long gosub to 0FDD, followed by a ten-bit constant for the low
ten bits of the target address.

To call a subroutine in a different 1K portion, call 23D2, 23DB, 23E4, or 23ED for the 1st through 4th 1K portions, also followed by the ten-bit constant.


#4

So, would those jumps keep the "prompting nature" of the function that is called? I.e. does the jump "know" that the function name called is prompting (having added 200h to the first character in the name)?

If not, I would have to write the prompting routine myself (as in the appendix on advanced routines in Ken Emry's book).


#5

The semi-automatic prompting upon specific keyword start patterns is an OS feature

for user accessible functions or commands.

If you want the actual prompting code to be somewhere else, say in a subroutine,

you'll have to write your own code, or use a given one.

In your case, prompting for a user password at turn-on, the latter will be mandatory,

since there won't be a user function call before your prompt,
at least if you start your code using the ON interrupt;-)

I don't know Emery's code, but I know there are some input routines available as source, like HEXKB or HEXKN . Check TOS for details.


HTH

Raymond


#6

But, there should be an entry point in the mainframe where a call could be made to another function "from the outside" (i.e. the call would be aware of the promting nature of the function). In this way I could set up the code in the ON-area of the page to jump to the starting point for the password checker. Here, user flag 0 is checked. If it is cleared, it returns control to the mainframe (so that it continues on its quest for possible jobs to do on startup). If user flag 0 is set, it calls the fuction named "PIN" that prompts for... you guessed it, a pin code to be entered. If the code entered is incorrect, it turns the calc off. If a correct pin code is entered, it returns control to the mainframe.

Any further thoughts?


#7

(XROM) Functions using the built-in prompting mechanism are working this way in interactive mode usually,

that is, when called from the keyboard via XEQ, or from a key assignment.

As Eric indicated, it's very likely that this mechanism can't be called as a subroutine,

but this would have to be checked against the VASM listings first, of course.

OTOH, there must be a reason why so many ML input routines exist;-)

HTH

Raymond


#8

Right. I guess this feature (to call functions within functions) should be useful to others... Anyone finding the entry point in the mainframe for such calls, please post it here - not just for me, but for posterity :)


#9

Hi,

Below an excerpt from the HEXKB function of MLROM. I am certain that this is borrowed from another ROM, but I do not know which. I have added some comments for system entry points, so use your VASM listings for further explanation. The function actually gives you a programmable prompting HEX keyboard.
The original ROM is available on TOS or on www.kuiprs.nl/hp41. You may disassemble it with the tools inside the MLDL2000 Manager, althouigh it will not give you the comments just yet ...


Let me know if you have questions!

Description:

HEXKB Hexadecimal Keyboard: Alpha is put in the display with a prompt and a hexadecimal keyboard is now active. Digits may be removed by pressing <- and R/S ends the input and continues the program, [shift] R/S stops the program. Digits entered will be in alpha ‘HHHH’ and X: “HHHH”.


F 05E6 3B8 ... ... READ (14)d
F 05E7 130 01F ... LDI 01F
F 05E9 3E8 ... ... WRIT (15)e
F 05EA 3DD 0AC ... ?NC XQ 2BF7 ; LEFTJ 2BF7
F 05EC 149 024 ... ?NC XQ 0952 ; ENCP00 0952
F 05EE 09C ... ... R= 5
F 05EF 238 ... ... READ ( 8)P
F 05F0 3D8 ... ... C<>ST
F 05F1 3CA ... ... RSHFC R<-
F 05F2 3CA ... ... RSHFC R<-
F 05F3 228 ... ... WRIT ( 8)P
F 05F4 1F8 ... ... READ ( 7)O
F 05F5 3D8 ... ... C<>ST
F 05F6 23C ... ... RCR 2
F 05F7 1E8 ... ... WRIT ( 7)O
F 05F8 1B8 ... ... READ ( 6)N
F 05F9 3D8 ... ... C<>ST
F 05FA 23C ... ... RCR 2
F 05FB 1A8 ... ... WRIT ( 6)N
F 05FC 178 ... ... READ ( 5)M
F 05FD 3D8 ... ... C<>ST
F 05FE 23C ... ... RCR 2
F 05FF 168 ... ... WRIT ( 5)M
F 0600 06B ... ... JNC +0D 060D
FUNCTION 0606 ... ... ... "HEXKB"
F 0606 125 01C ... ?NC XQ 0749 ; OFSHFT 0749
F 0608 108 ... ... SETF 8
F 0609 041 0B0 ... ?NC XQ 2C10 ; ARGOUT 2C10
F 060B 345 040 ... ?NC XQ 10D1 ; CLA 10D1
F 060D 04E ... ... C=0 ALL
F 060E 058 ... ... G=C
F 060F 149 038 ... ?NC XQ 0E52 ; just after NEXT 0E50
F 0611 2AB ... ... JNC -2B 05E6
F 0612 14C ... ... ?FSET 6
F 0613 197 ... ... JC +32 0645
F 0614 0B0 ... ... C=N
F 0615 3D8 ... ... C<>ST
F 0616 284 ... ... CLRF 7
F 0617 3D8 ... ... C<>ST
F 0618 3C6 ... ... RSHFC S&X
F 0619 0A6 ... ... A<>C S&X
F 061A 130 037 ... LDI 037
F 061C 366 ... ... ?A#C S&X
F 061D 16B ... ... JNC +2D 064A
F 061E 130 050 ... LDI 050
F 0620 39C ... ... R= 0
F 0621 00C ... ... ?FSET 3
F 0622 013 ... ... JNC +02 0624
F 0623 210 ... ... LD@R- 8
F 0624 206 ... ... C=C+A S&X
F 0625 01C ... ... R= 3
F 0626 050 ... ... LD@R- 1
F 0627 150 ... ... LD@R- 5
F 0628 1BC ... ... RCR 11
F 0629 330 ... ... FETCH
F 062A 106 ... ... A=C S&X
F 062B 00C ... ... ?FSET 3
F 062C 03F ... ... JC +07 0633
F 062D 04C ... ... ?FSET 4
F 062E 08B ... ... JNC +11 063F
F 062F 130 047 ... LDI 047
F 0631 306 ... ... ?A<C S&X
F 0632 06B ... ... JNC +0D 063F
F 0633 0A6 ... ... A<>C S&X
F 0634 39C ... ... R= 0
F 0635 058 ... ... G=C
F 0636 149 024 ... ?NC XQ 0952 ; ENCP00 0952
F 0638 051 0B4 ... ?NC XQ 2D14 ; APNDNW 2D14
F 063A 0A6 ... ... A<>C S&X
F 063B 3D9 01C ... ?NC XQ 07F6 ; ENLCD 07F6
F 063D 221 0B0 ... ?NC XQ 2C88 ; MASK 2C88
F 063F 130 01F ... LDI 01F
F 0641 3E8 ... ... WRIT (15)e
F 0642 3DD 0AC ... ?NC XQ 2BF7 ; LEFTJ 2BF7
F 0644 24B ... ... JNC -37 060D
F 0645 395 07C ... ?NC XQ 1FE5 ; TOGSHF 1FE5
F 0647 3D9 01C ... ?NC XQ 07F6 ; ENLCD 07F6
F 0649 3B3 ... ... JNC -0A 063F
F 064A 130 01F ... LDI 01F
F 064C 3E8 ... ... WRIT (15)e
F 064D 3DD 0AC ... ?NC XQ 2BF7 ; LEFTJ 2BF7
F 064F 149 024 ... ?NC XQ 0952 ; ENCP00 0952
F 0651 261 000 ... ?NC XQ 0098 ; RSTKB 0098
F 0653 379 03C ... ?NC XQ 0FDE ; GOSUB 08C4
F 0655 1C4 ... ... CLRF 14 ; belongs to GOSUB 08C4
F 0656 18C ... ... ?FSET 11
F 0657 3B5 051 ... ?C XQ 14ED ; R^SUB 14ED
F 0659 0EE ... ... C<>B ALL
F 065A 0E8 ... ... WRIT ( 3)X
F 065B 3B8 ... ... READ (14)d
F 065C 33C ... ... RCR 1
F 065D 3D8 ... ... C<>ST
F 065E 04C ... ... ?FSET 4
F 065F 29D 00D ... ?C XQ 03A7 ; STOPS 03A7
F 0661 215 00C ... ?NC XQ 0385 ; RSTSQ 0385
F 0663 381 042 ... ?NC GO 10E0 ; CLDSP 10E0

#10

The closest I have seen to calling an autoprompt is Clifford Sterns "XROM" function: PPC V12N3P37. Although even this function does not actually "call" an autoprompt, you might want to take a look at it, it's interesting.

#11

No, the prompting normally only happens when the mainframe code invokes an XROM function (or a built-in). If you study the VASM listings, you might be able to figure out a way to jump into the code and make that happen. I'm not sure whether you'll be able to get control back; that code path isn't expected to be called as a subroutine, so it (or the called function) might use the full stack depth, and the called function might exit by jumping into mainframe code.

You're probably best off doing your own prompting, though there probably are some mainframe subroutines that can help.

#12

To simplify things for the user or programmer, he could use one of the available programming aids.

If programming on the HP-41 directly, there's nothing comparable to the David Assembler.

Just enter a local label name at the jump destination,

then press the XEQ key at the address where you want to call the destination label.

The David Assembler will automatically produce the correct jump instruction,

be it port dependent or absolute.

If you're programming on the PC, I'd suggest to use SDK41 from Warren Furlow,

where you have text files as source files.

SDK41 also fills in the correct jump type for port dependent jumps.

For moredetails, please refer to the David Assembler and SDK41 docs, both available on TOS.

HTH

Raymond


Possibly Related Threads...
Thread Author Replies Views Last Post
  HP35s Program Four Slings Lift Calculation Jean-Marc Biram (Australia) 2 286 12-16-2013, 07:21 PM
Last Post: Jean-Marc Biram (Australia)
  Last call for 41Z/SandMath Overlays... plus new ones Ángel Martin 0 179 12-12-2013, 10:27 AM
Last Post: Ángel Martin
  HP35s Calculator Max Rope Tension Program Jean-Marc Biram (Australia) 10 533 12-12-2013, 12:03 AM
Last Post: Jean-Marc Biram (Australia)
  Sending little images to the Prime (...and Program name bug?) Erwin Ried 19 664 12-10-2013, 05:35 PM
Last Post: Erwin Ried
  WP-34S (Emulator Program Load/Save) Barry Mead 1 193 12-09-2013, 05:29 PM
Last Post: Marcus von Cube, Germany
  Problem with debug HP prime program, somebody help me? Carlos CM (Mexico) 6 393 12-05-2013, 03:07 PM
Last Post: Carlos CM (Mexico)
  HP-41(CL): The easiest way to transfer FOCAL programs from a Linux PC to the HP-41 Geir Isene 13 710 12-05-2013, 02:40 AM
Last Post: Hans Brueggemann
  Difficulties with IRR Program Jose Gonzalez Divasson 4 281 12-02-2013, 02:34 AM
Last Post: cyrille de Brébisson
  HP PRIME: APP program code DISAPPEARS !! Joseph Ec 0 140 11-25-2013, 11:35 AM
Last Post: Joseph Ec
  Polynomial program Michael Carey 12 469 11-20-2013, 08:43 PM
Last Post: CR Haeger

Forum Jump: