41 MCODE Question



#24

Hi MCODE addicts out there... here's a question for you.

Q: How to call ANUM on the CX as a subroutine (from within another MCODE function), and still get it to return to the calling point?

ANUM has XROM A6:42, so I tried both [XEQAX] and [RAK70] mainframe routines. This method works with the X-Functions module (on a CV) but but it appears that the bank-switching code in the CX stops it from returning.

Here's the first snippet:

130	LDI S&X	        build ANUM's fnc id# 
342 CON:
0A6 C<>A S&X
130 LDI S&X
300 CON: XROM 25,02 = A6:42
206 C=C+A S&X ANUM
01C PT= 3 complete the fnc. "code"
290 LD@PT- A (not needed for GTRMAD)
029 ?NC XQ Execute function!
01C ->070A [RAK70]


and here's the second:

130	LDI S&X	         build ANUM's fnc id#
342 CON:
0A6 C<>A S&X
130 LDI S&X
300 CON: XROM 25,02 = A6:42
206 C=C+A S&X ANUM
001 ?NC XQ
020 ->0800 [GTRMAD]
381 ?NC XQ
008 ->02E0 [ERRNE]
2ED ?NC XQ Execute it
0BC ->2FBB [XEQAX]

It responds as if the return stack fills over, or maybe the CX-ANUM code ends with a call to [NFRU] (or equivalent).

Any ideas?

Cheers.
ÁM


#25

did u try singlestepping it on mm41? not sure that supports the CX... other than that I don't have any immediate ideas for the cause...

Cheers

PeterP


#26

@ PeterP - mm41?? I assume a typo and you ment Emu41 from JFG.

@ Angel Martin - tonite I wanted to make a trace with my NutEm of your 2 examples but was bussy with other things until falling asleep. If it's not too late I may send it on Monday. Otherwise see PeterP's suggestion.

Ciao.....Mike


#27

I think Peter was referring to M41 of the 41SDK (an amazing tool for MCODE development)


#28

yes indeed, I was :-)

#29

Guys this is frustrating:- I've never used M41 so I'm not up to speed with it, but regardless: I supect there's just the dreadful call to NFRNU (or equivalent) throwing away any chance to return to the calling point... a shame because the way it is I have to copy the ANUM code into the 41Z, about 140 "bytes" - quite some taxing deed.

I'm also stuck with - shame on me, even the simplest routine!- BLINK1. It's supposed to always work but alas, it doesn't - and I dunno why/when not. Never mind that I'm using it within nested loops of partial key sequence calls, it's still demoralizing :(

Ok, the updated 41Z is posted at TOS - take it for a spin if you'd like - a nice week-end treat :)

Best,
'AM


#30

angel, I will try to take a look this weekend but I think your suspicion could be correct. It really is a dreadful end to many a useful routine...

Cheers

Peter

#31

Ángel,

I think you can use the Windows version of my HP-41E emulator for this purpose because it has a very powerful debugger and tracer, which are also very simple to use.

First, download the latest version here http://www.hrastprogrammer.com/hp41e/hp41epc.zip and unpack it into some directory ... You should use this version because it has some capabilities not present in the old version floating around.

Let's say you want to trace BCDBIN routine at 02E3 hex ... Edit HP41E.INI file and add the following section:

[Tracer]
Activate=$02E3
Deactivate=
Powoff=0

You should close HP-41E prior to this otherwise it will rewrite INI file on exit. The above means "start tracer at $02E3 and deactivate it on the first POWOFF instruction". You can also deactivate it on a specific address if you specify Deactivate=$ADDR ... $ means hexadecimal.

Then start HP-41E, type 12 RCL IND X and you'll have HP41E.LOG file in the same directory. It looks like that:

02E3 27E C=C-1 S DAdd=003 PfAd=00 Base=16
A=000000000690F3 B=00000000000020 C=01200000000001 Stack=0024 004E 00F0 122E
M=01200000000001 N=01200000000003 Cy=0 P=1 Q=D G=90 FO=00 ST=00100011110011
02E4 27E C=C-1 S DAdd=003 PfAd=00 Base=16
A=000000000690F3 B=00000000000020 C=F1200000000001 Stack=0024 004E 00F0 122E
M=01200000000001 N=01200000000003 Cy=1 P=1 Q=D G=90 FO=00 ST=00100011110011
02E5 389 GOLC =ERRAD 14E2 DAdd=003 PfAd=00 Base=16
A=000000000690F3 B=00000000000020 C=E1200000000001 Stack=0024 004E 00F0 122E
M=01200000000001 N=01200000000003 Cy=0 P=1 Q=D G=90 FO=00 ST=00100011110011
02E7 106 A=C X DAdd=003 PfAd=00 Base=16
A=000000000690F3 B=00000000000020 C=E1200000000001 Stack=0024 004E 00F0 122E
M=01200000000001 N=01200000000003 Cy=0 P=1 Q=D G=90 FO=00 ST=00100011110011
...

You can also debug the code directly. Edit HP41E.INI and add the following:

[Debugger]
Activate=$02E3

Then start HP-41E, type 12 RCL IND X and the debugger will be automatically activated on the address $02E3. You can then SST the machine code from this point onwards.

Of course, debugger and tracer can be used simultaneously, tracer can be activated/deactivated from the debugger, etc. The debugger can be also be activated on-demand if you double-click on that overlay "latch" inside the emulator.

I hope this can be of some help to you ...

Best regards.

HrastProgrammer


Edited: 20 Nov 2010, 5:07 a.m.


#32

Many thanks Hrast, appreciate the tip. It's a very powerful implementation - I wasn't aware of it but sure enough I'll add it to my bag of tricks from now on.

I guess I have a humongous trace file to study now :-0 Regardless, does the trace mode mean what I think it does? Can a MCODE routine be executed using the SST key, one line at a time???

W.r.t. the ANUM code I've given up = I\m leaving the copied code within the 41Z anyway, so be it.

Cheers,
'AM


#33

Quote:
Regardless, does the trace mode mean what I think it does? Can a MCODE routine be executed using the SST key, one line at a time???

That's what a debugger is for and yes, among the other things, you can single-step machine code one instruction at the time, look at the contents of all registers (stack, memory, ...), even change their values to see what happens, animate the execution etc. See this:

Tracer is a different thing - it writes the complete machine code execution path to a text file. You can then load this file into a text editor and analyze it, do searches etc. HP-41E doesn't have the ability to set breakpoints for debugger/tracer inside the emulator (most likely because I didn't find a need to do this), but you can set them from the INI file, as described in my previous post.

I used HP-41E debugger+tracer capabilities hundreds of times while developing my HP-41E/X emulators for HP-48GX/49G/... And that's the main reason why I developed it - to have a good test/debug/simulation platform for hunting bugs and test various enhanced features I implemented in HP-41E/X ...


#34

Awesome! I wish I had known about this before, well I guess it's never too late.

One question: in your CX ROM things seem to be different from the "real" one, or at least from V41's NUTCX module. For instance, ANUM's code is not the same in both... would that be true?


#35

Quote:
One question: in your CX ROM things seem to be different from the "real" one, or at least from V41's NUTCX module.

They are the same (mainframe ROM version NFL, XFUNCS 2D, TIME 2C).

Quote:
For instance, ANUM's code is not the same in both... would that be true?

Hmmm, both look the same to me:

31C2 08D         CON 08D M
31C3 015 CON 015 U
31C4 00E CON 00E N
31C5 001 CON 001 A
31C6 279 GSUBNC L319E 319E
31C7 0C4 *
31C8 20C ?ST=1 2
31C9 360 RTNC
31CA 00B GONC L31CB +01 31CB
31CB 180 L31CB ENROM1
31CC 211 GOLNC 5884
31CD 162 *

Edited: 22 Nov 2010, 8:16 a.m. after one or more responses were posted


#36

I think the difference you see is because I am calculating relative jumps from the address after the instruction so, for example, you see GONC L31CB +00 instead of GONC L31CB +01. Now changed in this public version ...

#37

You're of course correct, sorry I got confused. So the ROM files have the same format as those used by V41 (and Clonix, MLDL, etc...) then it should be possible to add any of them to the 41E configuration INI file, right?

PS.- I went and checked after I first posted this (also read the README file, which I should have to begin with). Indeed it all works as expected - another great tool so useful for development!

Thanks.


Edited: 22 Nov 2010, 8:59 a.m.


#38

Quote:
So the ROM files have the same format as those used by V41 (and Clonix, MLDL, etc...) then it should be possible to add any of them to the 41E configuration INI file, right?

To some extent ... HP-41E is very old piece of software (most of it was developed in 1998), so it supports only two formats: packed (four 10-bit instructions are stored in 5 bytes, module size must be a multiple of 5K) and unpacked (each 10-bit instruction occupies 2 bytes, module size must be a multiple of 8K). MOD files are not supported.

Quote:
another great tool so useful for development!

Thanks and keep up the good work ... What you have done is really excellent!

#39

Remember that V41 has good tracing options for nailing down this problem


#40

Hi Meindert, I didn't know there was a tracing facility in MLDL2k - I guess I need to RTFM :)

Whereabouts are the settings/options for it?

Cheers,
'AM


#41

Angel,

Tracing will be included in the new MLDL2000 (code name MLDL3000 ;). I actually have a working tracer, but the software is a bit of a hack and requires seperate hardware, there is no need to RTFM as is is not in the FM at all ;)
I was referring to V41, the PC emulator from TOS. With the menu you may choose Options, and then select Trace Dump to generate a trace file, with Console you can really single step through code. There is also an option for breakpoints but I have never used it, so there lies a challenge for you ...

Meindert


#42

Sorry Meindert, I misread your post - saw your name and automatically assumed it was about MLDL2k instead of V41... my bad (you gotta love this vernacular american-english expression, BTW). I wonder how would it be in german, "mein schlecht" perhaps?? :)

BTW the issue with the [BLINK1] routine is solved. This was supposed to be a trivial thing but for whatever reason it got very complicated. As it turns out, the routine [BLINK1] doesn't work most of the times when called from within a partial key sequence "loop". It took me quite a long time (and lots of frustration) to understand that DSPOFF simply does not work when used inside of the [NEXTn] code, ergo neither did [BLINK1]- surely my fault, it's probably well-documented somewhere I have no access to - but anyway I finally solved the issue just by calling [BLINK1] TWICE - that sort of does the trick in every circumstance... go figure.

Cheers,
"AM

Edited: 21 Nov 2010, 1:09 p.m.


#43

Angel, unfortunately m41 does not have labels and I don't know the starting point for ANUM in the CX. If you know that I could easily trace the exit on the CX for you.

Cheers

Peter


#44

$31C6


#45

...[NFRPU]....


#46

there you go... a shame.

Many thanks for the sleuth work!


Possibly Related Threads...
Thread Author Replies Views Last Post
  HP-41 MCODE: The Last Function - at last! Ángel Martin 0 147 11-08-2013, 05:11 AM
Last Post: Ángel Martin
  Non-Prime question alert: Hp-41 and synthetic instructions Marcel Samek 11 527 11-04-2013, 09:31 PM
Last Post: sjthomas
  41-MCODE: Auto XEQ+ALPHA possible? Ángel Martin 5 270 05-29-2013, 06:15 AM
Last Post: Ángel Martin
  HP 41 Mcode related Questions Michael Fehlhammer 4 248 05-10-2013, 07:09 PM
Last Post: Michael Fehlhammer
  41-MCODE: Breaking the FAT barrier. Ángel Martin 0 116 09-03-2012, 06:31 AM
Last Post: Ángel Martin
  41-MCODE: Dr. Jekyll & Mr. Hyde Ángel Martin 9 371 07-09-2012, 09:41 AM
Last Post: Monte Dalrymple
  hp 41 series wire-wrapped connector question. Matt Kernal 3 181 06-19-2012, 01:48 AM
Last Post: Luiz C. Vieira (Brazil)
  HP41C: Factorial (kind of) in MCODE Frido Bohn 7 331 05-26-2012, 09:18 AM
Last Post: Frido Bohn
  41-MCODE: SOLVE & INTEG - 4k ROM Ángel Martin 9 363 04-19-2012, 05:29 AM
Last Post: fhub
  41-MCODE: a weekend challenge Ángel Martin 3 178 03-19-2012, 06:49 AM
Last Post: Mike (Stgt)

Forum Jump: