New Owner DM42

Discussion around the SwissMicros DM42 calculator
Post Reply
peacecalc
Posts: 13
Joined: Sun Jun 28, 2020 10:25 pm

New Owner DM42

Post by peacecalc »

Hello all,

what a surprise I'm a newbee! since one month I own a DM42 and I appreciate that machine much. Although the HP50g has more functions and CAS.
The DM42 is a very cool gadget for me.

I learned RPN programming with the Hp 15c 35 years ago. So I my first project with DM42 was the pic below (I developed the wheel a second time, because I saw that pic for a graphic package and I wanted to program the pic on my DM42 by myself).

What I learned doing this:

- How the Bresenham algorithm works.
- That labels und register named by numbers aren't real locals (they only not shown in the menues).
- PIXEL hates all numbers after the decimal point (if they not all are zeros)
- how subtil the mangement of matrix elements is, if you want to store or recall them. Especially if you use them in a program.

and so on...
20200621-17352611.bmp
20200621-17352611.bmp (12.31 KiB) Viewed 3968 times
dlachieze
Posts: 613
Joined: Thu May 04, 2017 12:20 pm
Location: France

Re: New Owner DM42

Post by dlachieze »

Cool, would you mind sharing your program?
DM42: 00425 - DM41X: β00066 - WP43: 00042
peacecalc
Posts: 13
Joined: Sun Jun 28, 2020 10:25 pm

Re: New Owner DM42

Post by peacecalc »

Hello dlachieze,

I will do my very best (@Diner for one). But I warn you, it is brut force spaghetti-code. I've tried to split it into modules. For sharing, I need a little bit more time, wait a some days...
peacecalc
Posts: 13
Joined: Sun Jun 28, 2020 10:25 pm

Re: New Owner DM42

Post by peacecalc »

Hello all,

now I try to share the program I made, at first we need a graph mode to use the whole display. I have to use indirect adressing because the storage is in so called "virtual" registers:

Code: Select all

1	▸LBL	INVIR	
2		CLA	
3		GrMod	
4		ASTO	10
5		CLA	
6		ResX	
7		ASTO	11
8		CLA	
9		ResY	
10		ASTO	12
11		CLA	
12		RTN	
I use his program for initialising the virtual registers.
The next little program helps to feed the command PIXEL with integer coordinates:

Code: Select all

1	▸LBL	RNDO	
2		ENTER	
3		FP	
4		10	
5		×	
6		5	
7		X>Y?	
8		GTO	8
9		R↓	
10		R↓	
11		IP	
12		1	
13		+	
14		GTO	9
15	▸LBL	8	
16		R↓	
17		R↓	
18		IP	
19		RTN	


Don't forget that is my first attempt in programming that beast. This function above geht an arbitrary real and made i. e. out of 23.49 23.00 or with 23.67 you get 24.00 with using the commands IP and FP. I'm shure that this can be solved more efficient.

I work with vectors (as a 1 row and 2 coloums matrix). For this purpose a use an extra routine to input the values to such a matrix, called INM(atrix).

Code: Select all

 
1	▸LBL	INM		
2		ASTO	VX	
3		0		
4		EDITN	IND	VX
5		R↓		
6		→		
7		X<>Y		
8		→		
9		EXITALL		
10		RTN		
This short routine attend a name of a matrix in the alpha register and the values in the x an y registers.
The coordinates for the function DLINE which sets the line from a starting point to an end point are stored in the global variables: xs, ys and xe, ye.
That are the two little programs managing that:

Code: Select all

 
1	▸LBL	STOAP		
2		ASTO	VX	
3		EDITN	IND	VX
4		XEQ	RNDO	
5		STO	XS	
6		→		
7		XEQ	RNDO	
8		STO	YS	
9		EXITALL		
10		RTN		
				
				
1	▸LBL	STOEP		
2		ASTO	VX	
3		EDITN	IND	VX
4		XEQ	RNDO	
5		STO	XE	
6		→		
7		XEQ	RNDO	
8		STO	YE	
9		EXITALL		
10		RTN		


Here is the other way round: In alpha register there is the name off the vector, from which we want to get the coordinates. STOAP stores the values in xs and ys. STOEP stores in xe and ye.

There is a main calculating program which calculates using the old four points coordinates the new ones, it is called NEWV:

Code: Select all

1	▸LBL	NEWV	
2		RCL	K
3		STO×	VDA
4		RCL	VDA
5		STO+	VD
6		RCL	K
7		STO×	VAB
8		RCL	VAB
9		STO+	VA
10		RCL	VDA
11		STO-	VB
12		RCL	VAB
13		STO-	VC
14		RCL	VA
15		RCL	VD
16		-	
17		STO	VDA
18		RCL	VB
19		RCL	VA
20		-	
21		STO	VAB
22		RTN	
The structure of the names is easy: V stands for vector, if one more letter follow, than that is a position vector, and if two letters are following, then its a difference vector between two positions. I. e. VBA means a vector from the B(beginning point) to the position A(end point) . In register "K" is the scaling factor for the next quadrate stored. So far part one of that story.
grsbanks
Posts: 1122
Joined: Tue Apr 25, 2017 11:23 am
Location: Preston, Lancs, UK
Contact:

Re: New Owner DM42

Post by grsbanks »

peacecalc wrote:
Wed Jul 01, 2020 12:18 am
now I try to share the program I made, at first we need a graph mode to use the whole display. I have to use indirect adressing because the storage is in so called "virtual" registers:
You don't have to address the virtual variables indirectly. It just makes it much easier for you (and the program much smaller) if you have to access the variables more than once in your program because you have to type out the variable name each time otherwise.
peacecalc wrote:
Wed Jul 01, 2020 12:18 am

Code: Select all

1	▸LBL	INVIR	
2		CLA	
3		GrMod	
4		ASTO	10
5		CLA	
6		ResX	
7		ASTO	11
8		CLA	
9		ResY	
10		ASTO	12
11		CLA	
12		RTN	
No need for CLA statements here. When you enter something into the alpha register it will automatically replace what was in there before unless you use the append alpha command. Also, if you want people to be able to copy/paste this into the web-based decoder then please surround alpha strings with quotes and use spaces rather than tabs. So the first section of code becomes:

Code: Select all

01 LBL "INVIR"
02 "GrMod"
03 ASTO 10
04 "ResX"
05 ASTO 11
06 "ResY"
07 ASTO 12
08 RTN
There are only 10 kinds of people in the world: those who understand binary and those who do not.
dlachieze
Posts: 613
Joined: Thu May 04, 2017 12:20 pm
Location: France

Re: New Owner DM42

Post by dlachieze »

Thanks for sharing your program. I'll look at the core calculations. But for now just a small comment :
peacecalc wrote:
Mon Jan 19, 1970 11:39 am
This function above geht an arbitrary real and made i. e. out of 23.49 23.00 or with 23.67 you get 24.00 with using the commands IP and FP. I'm shure that this can be solved more efficient.
.5 + IP should do what you need. Or you can set the display mode to FIX 00 and use RND.
DM42: 00425 - DM41X: β00066 - WP43: 00042
peacecalc
Posts: 13
Joined: Sun Jun 28, 2020 10:25 pm

Re: New Owner DM42

Post by peacecalc »

Hello all,

@grsbanks: I tried the conversion from raw to txt with free42 and I was successfull. Now the strings are surrounded with quotes. But there is a little triangle in front of the keyword LBL. Is that a problem?

@dlachieze: Of course this elegant solution does it. I simply forgot it over the years. Hm, I was so concentrated in programming, How a german
saying tells us: Why should one keeps it simple, when there exists an intricate way!

I already use your suggestions for the code:

That is the main program. It can be terminated by R/S. It first set the global variables for the vectors. It was new for me, the arguments for DIM are left on the stack (the HP50g acts in another way), so the command DIM can be used without a repeated setting of the dimentions.
In the global var. N are the number of squares stored, which has to be drawn. In the var. K is stored how much the next square is smaller than the ancestor square.

Code: Select all

00 { 687-Byte Prgm }
01▸LBL "DRQUA"
02 MVAR "K"
03 CLA
04 2
05 1
06 DIM "VA"
07 DIM "VB"
08 DIM "VC"
09 DIM "VD"
10 DIM "VDA"
11 DIM "VAB"
12 3
13 STO IND 10
14 CLLCD
15 CF 35
16 CF 34
17 11
18 91
19 "VA"
20 XEQ "INM"
21 11
22 310
23 "VD"
24 XEQ "INM"
25 230
26 310
27 "VC"
28 XEQ "INM"
29 230
30 91
31 "VB"
32 XEQ "INM"
33 RCL "VA"
34 RCL "VD"
35 -
36 STO "VDA"
37 RCL "VB"
38 RCL "VA"
39 -
40 STO "VAB"
41 RCL "N"
42 1ᴇ-5
43 +
44 STO 09
45▸LBL 99
46 XEQ "FLINE"
47 XEQ "NEWV"
48 DSE 09
49 GTO 99
50 STOP
51 CLST
52 RTN
FLINE draws one square on the screen and initializes the new directions for the next generation square.

Code: Select all

53▸LBL "FLINE"
54 "VD"
55 XEQ "STOAP"
56 "VA"
57 XEQ "STOEP"
58 XEQ "DLINE"
59 "VA"
60 XEQ "STOAP"
61 "VB"
62 XEQ "STOEP"
63 XEQ "DLINE"
64 "VB"
65 XEQ "STOAP"
66 "VC"
67 XEQ "STOEP"
68 XEQ "DLINE"
69 "VC"
70 XEQ "STOAP"
71 "VD"
72 XEQ "STOEP"
73 XEQ "DLINE"
74 RTN
75▸LBL "NEWV"
76 RCL "K"
77 STO× "VDA"
78 RCL "VDA"
79 STO+ "VD"
80 RCL "K"
81 STO× "VAB"
82 RCL "VAB"
83 STO+ "VA"
84 RCL "VDA"
85 STO- "VB"
86 RCL "VAB"
87 STO- "VC"
88 RCL "VA"
89 RCL "VD"
90 -
91 STO "VDA"
92 RCL "VB"
93 RCL "VA"
94 -
95 STO "VAB"
96 RTN
About these two programs I already talked about

Code: Select all

97▸LBL "STOAP"
98 ASTO "VX"
99 EDITN IND "VX"
100 XEQ "RNDO"
101 STO "XS"
102 →
103 XEQ "RNDO"
104 STO "YS"
105 EXITALL
106 RTN

107▸LBL "STOEP"
108 ASTO "VX"
109 EDITN IND "VX"
110 XEQ "RNDO"
111 STO "XE"
112 →
113 XEQ "RNDO"
114 STO "YE"
115 EXITALL
116 RTN
Thank you dlachieze!

Code: Select all

117▸LBL "RNDO"
118 0,5
119 +
120 IP
121 RTN
That one is also known.

Code: Select all

122▸LBL "INM"
123 ASTO "VX"
124 0
125 EDITN IND "VX"
126 R↓
127 →
128 X<>Y
129 →
130 EXITALL
131 RTN
Thank you gsrbanks for your hints and advices

Code: Select all

132▸LBL "INVIR"
133 "GrMod"
134 ASTO 10
135 "ResX"
136 ASTO 11
137 "ResY"
138 ASTO 12
139 RTN
And DLINE is the heart of whole programming here! The routine works with (named for his inventor) the Bresenham algorithm, in an extended form, so the user doesn't have to control, in which direction the line has to be drawn. The algorithm only uses + or - and works without any multiplication or division.

Code: Select all

140▸LBL "DLINE"
141 RCL "XE"
142 RCL "XS"
143 -
144 STO 00
145 RCL "YE"
146 RCL "YS"
147 -
148 STO 01
149 RCL 00
150 SIGN
151 STO 02
152 RCL 01
153 SIGN
154 STO 03
155 RCL 02
156 X<0?
157 STO× 00
158 RCL 03
159 X<0?
160 STO× 01
161 RCL 01
162 RCL 00
163 X≥Y?
164 GTO 00
165 RCL 00
166 STO 04
167 0
168 STO 05
169 RCL 03
170 STO 06
171 GTO 01
172▸LBL 00
173 RCL 01
174 STO 04
175 RCL 00
176 STO 01
177 0
178 STO 06
179 RCL 02
180 STO 05
181▸LBL 01
182 RCL 01
183 2
184 ÷
185 STO 00
186 RCL "YS"
187 RCL "XS"
188 PIXEL
189 RCL 01
190 1ᴇ-5
191 +
192 STO 07
193▸LBL 02
194 DSE 07
195 GTO 03
196 GTO 06
197▸LBL 03
198 RCL 04
199 STO- 00
200 RCL 00
201 X≥0?
202 GTO 04
203 RCL 01
204 STO+ 00
205 RCL 02
206 STO+ "XS"
207 RCL 03
208 STO+ "YS"
209 GTO 05
210▸LBL 04
211 RCL 05
212 STO+ "XS"
213 RCL 06
214 STO+ "YS"
215▸LBL 05
216 RCL "YS"
217 RCL "XS"
218 PIXEL
219 GTO 02
220▸LBL 06
221 RTN
222 END
Sincerely peacecalc
grsbanks
Posts: 1122
Joined: Tue Apr 25, 2017 11:23 am
Location: Preston, Lancs, UK
Contact:

Re: New Owner DM42

Post by grsbanks »

peacecalc wrote:
Wed Jul 01, 2020 8:32 pm
@grsbanks: I tried the conversion from raw to txt with free42 and I was successfull. Now the strings are surrounded with quotes. But there is a little triangle in front of the keyword LBL. Is that a problem?
Nope. It's absolutely normal. It's there on printed listings too.
There are only 10 kinds of people in the world: those who understand binary and those who do not.
Post Reply