CS‑02 calc stack gamesprograms to play, for every calculator
game #1 — HP-15C · Elektronika MK-52 / MK-61

Twin Peaks

Twin Peaks is a small North American town of about 500 people, and two sides are fighting over it. You play one of them. Recruit as many townspeople as you can, find the key, break into the enemy encampment with it, win the battle, and get out alive.

The game was written in 1994 for the Soviet Elektronika MK-52 and MK-61 by Evgeny Vek, as one of a series called Good and Evil. The MK-52/61 listing below is his program, with his name on it; the HP-15C version is a re-implementation from his description of the game, not a translation. The original leans on hidden-code tricks and on words spelled out in the calculator’s display, neither of which the HP-15C can do, and the HP-15C’s odds and battle formulas are new.

Ported game. Twin Peaks is not an HP game. It was written in 1994 by Evgeny Vek (Lord_BSS) for the Soviet Elektronika MK-52 and MK-61, and this page is based on his work. The MK listing below is his program as he published it, and the original page, in Russian, is at lordbss.narod.ru/pmk13.html. The HP-15C version is a re-implementation built from his description of the game, so its odds and battle formulas are not his, and it is not endorsed by him.

How a game goes

  1. Recruiting. Each turn you choose a persuasion method, 1 to 10. How many people it wins you depends on the ground you are standing on, and on luck. Forest is worth the least, then swamp, then the village, and a house is worth the most. The enemy recruits from the same pool.
  2. Exploring. Then you move one square. The map is a grid of 100 squares, and the house you are being drawn towards is shown as a square number.
  3. The key. One square holds the key to the encampment. Step on it and the calculator shows a code of 4 to 7 digits. Copy it down.
  4. The encampment. Another square is the enemy encampment, and the display tells you when you reach it. Key in the code to storm it, or press R/S to carry on recruiting.
  5. The battle. Each round you pick a strategy, 1 to 10, and both armies shrink. Run out of people and you lose.
  6. The escape. If you win, you are still inside the encampment. Images of the exits flash past on the display, and you must stop on the right one.
# Persuasion Battle strategy
1 rally offensive
2 supporters’ march assault
3 demonstration attack
4 presentation sortie
5 printed leaflets regrouping
6 radio ad dispersal
7 TV appearance ambush
8 hypnosis repel attack
9 threats withdrawal
10 bribery retreat

The original’s own word for the first column is “propaganda” (Russian пропаганда, which means winning people over to your cause); “persuasion” is closer to how English speakers use it. Those names come from the original’s instructions. The HP-15C port takes the same 1 to 10 choices, but it does not name them: a number only matters through how it plays against the luck factor.

Playing on the HP-15C

Key in the program, then:

  1. Seed the random generator once: type any number, then STO RAN#.
  2. Press f A. Each turn, the display flashes for a second each: the terrain code (1 forest, 2 swamp, 3 village, 4 house), then your square . house square (37.52 means you are on 37 and the house is on 52), then the enemy’s people, then the neutral people left. It then stops on your people.
  3. Type a persuasion number from 1 to 10 and press R/S. The recruits flash, and it stops on your people again.
  4. Type a move and press R/S: 1 north, 2 east, 3 south, 4 west. Squares are numbered 00 to 99. North and south move by 10 and east and west by 1, wrapping around the range, so east of 09 is 10.
  5. A number of 4 to 7 digits means you are on the key square: write it down and press R/S. 507.00 is the enemy encampment: type the key code and press R/S to storm it, or just R/S to move on.
  6. In the battle it flashes the enemy’s people, then stops on yours. Type a strategy, 1 to 10, and press R/S, until one side is gone. Error 0 means your side lost.
  7. If you win, the digits 1, 2, 3 and 507 flash past. Press R/S while 507.00 is showing, then press f D to check. If you stopped on it, the display shows 7777.00; if not, the flashing carries on.

Playing on the MK-52 / MK-61

Key in the program in program mode (F PRG), switch to run mode (F AVT), key in the register setup, and start with GOTO 39 R/S. The first number to appear is your people. Following the original’s own instructions:

  • Type a persuasion number from 1 to 10, then R/S. Houses are worth dozens of people, open ground only a few, and swamp more than forest but less than the village. After the move the display shows your people again. If the whole town has been recruited, it shows your square with a negative warning number.
  • Type a movement code, then R/S.
  • A 4 to 7 digit number means you are on the key square. Copy it, then R/S.
  • An encampment message (BICЧ 507, in the original’s spelled-out letters) is the enemy base. Key in the key code and press R/S to storm it, or R/S to keep exploring.
  • In the battle, X is your people and Y is the enemy’s. Type a strategy, 1 to 10, then R/S.
  • ЕГГОГ (the MK’s “error” message) means you lost.
  • If you won, scenes from the encampment flash past. Press R/S to stop on the encampment exit (BICЧ 507) and R/S again to return to Earth: ВЕЗЛО- В (“lucky”) means you made it. If any other number sticks on the display, press B/O then R/S to carry on.

Reading the MK listing

The listing is the author’s table, one line per program step, with the step number on the left. Cells that are Cyrillic are the Russian key labels; the comment gives the English name.

Russian English Russian English
Пх n RCL n БП GOTO
хП n STO n ПП GSB
С/П R/S В/О RTN
ВП EEX /–/ CHS
↔ x<>y Сх CLX
F Вх LASTX F lg LOG
К {x} FRAC К [x] INT
К |x| ABS К ЗН SIGN
К БП, К ПП, К Пх, К хП indirect GOTO, GSB, RCL, STO К x=0 indirect test

Registers A to E are the calculator’s 11th to 15th, keyed with the ., /-/, ВП, Cx and В↑ keys after Пх or хП. The conditional jumps (F x=0, F x≠0, F x≥0, F L0) take the next step as their address, and the MK jumps when the condition is false.

One thing in the listing is not a typo. The address of the GOTO at step 50 is the byte at step 51, and that byte is also a perfectly good instruction (RCL 3) that the test at step 37 jumps straight into. The author reuses it, so step 51 is written once as 63: enter it as a normal GOTO 63.

HP-15C port

Program 284 lines

Numbered as the HP-15C numbers its program lines: every digit, decimal point and EEX is a line of its own, 284 in all. Run it with f A.

001LBL A  ; init: 500 neutral, random start/house/key/encampment squares, random key code
002FIX 2
0035
0040
0050
006STO 2
0070
008STO 0
009STO 1
010GSB 0
011STO 3
012GSB 0
013STO 4
014GSB 0
015STO 5
016GSB 0
017STO 6
018RAN#
0199
020EEX
0216
022×
023INT
0241
025EEX
0263
027+
028STO 7
029LBL 1  ; turn start: arrival events
030RCL 3
031RCL 6
032x=y?
033GTO 5
034LBL 7
035RCL 3
036RCL 5
037x=y?
038GTO 6
039LBL 4  ; status flashes, then ask persuasion number
040GSB 2
041PSE
042x²
0433
044×
045STO 8
046RCL 4
0471
0480
0490
050÷
051RCL 3
052+
053PSE
054RCL 1
055PSE
056RCL 2
057PSE
058RCL 0
059R/S
060RAN#
0611
0620
063×
064INT
0651
066+
067−
068ABS
0691
0700
071÷
072CHS
0731
074+
075.
0761
077x<y?
078x<>y
079RCL 8
080×
081RAN#
082.
0835
084+
085×
086INT
087RCL 2
088x≥y?
089x<>y
090STO+ 0
091STO− 2
092PSE
093RAN#
0942
0950
096×
097INT
098RCL 2
099x≥y?
100x<>y
101STO+ 1
102STO− 2
103RCL 0
104R/S
105STO 8
1062
107÷
108FRAC
109x=0?
110GTO B
111RCL 8
1122
113−
1141
1150
116×
117GTO C
118LBL B  ; move: even codes
1193
120RCL 8
121−
122LBL C  ; apply move, wrap on 0-99
123STO+ 3
124RCL 3
1251
1260
1270
128+
1291
1300
1310
132÷
133FRAC
1341
1350
1360
137×
138STO 3
139GTO 1
140LBL 5  ; encampment found
1415
1420
1437
144R/S
145RCL 7
146x=y?
147GTO 8
148GTO 7
149LBL 6  ; key square
150RCL 7
151R/S
152GTO 4
153LBL 0  ; subroutine: random square 0-99
154RAN#
1551
1560
1570
158×
159INT
160RTN
161LBL 2  ; subroutine: terrain code 1-3, or 4 at house
162RCL 3
163RCL 4
164x=y?
165GTO 3
166R↓
1673
168÷
169INT
1703
171×
172RCL 3
173x<>y
174−
1751
176+
177RTN
178LBL 3  ; house
1794
180RTN
181LBL 8  ; BATTLE
182RCL 1
183PSE
184RCL 0
185R/S
186RAN#
1871
1880
189×
190INT
1911
192+
193−
194ABS
1951
1960
197÷
198CHS
1991
200+
201.
2021
203x<y?
204x<>y
205STO 8
206RCL 0
207×
208.
2094
210×
211RAN#
212.
2135
214+
215×
216INT
2171
218+
219STO 9
2201
221.
2221
223RCL 8
224−
225RCL 1
226×
227.
2284
229×
230RAN#
231.
2325
233+
234×
235INT
2361
237+
238STO− 0
239RCL 9
240STO− 1
241RCL 0
242x≤0?
243GTO E
244RCL 1
245x≤0?
246GTO 9
247GTO 8
248LBL E  ; defeat: Error 0
2491
250ENTER
2510
252÷
253LBL 9  ; escape: flashing codes
254RAN#
2554
256×
257INT
2581
259+
2604
261x=y?
262GTO .0
263x<>y
264PSE
265GTO 9
266LBL .0
2675
2680
2697
270PSE
271GTO 9
272LBL D  ; press f D to freeze-check the displayed code
2735
2740
2757
276x=y?
277GTO .2
278GTO 9
279LBL .2  ; victory
2807
2817
2827
2837
284R/S

Elektronika MK-52 / MK-61 original program

Program (105 steps) 105 lines

The author's own program, step for step as published. Start it with GOTO 39 R/S.

00Пх7  ; RCL 7
01Пх8  ; RCL 8
02Пх9  ; RCL 9
03ПхД  ; RCL D
04КБПВ  ; GTO indirect via RB
05Кинв  ; K INV
06С/П  ; R/S
07ВП  ; EEX
08/–/  ; CHS
091
10K{x}  ; FRAC
11ПхС  ; RCL C
12F10x  ; 10^x
13K{x}  ; FRAC
14хПС  ; STO C
15–  ; −
16K|x|  ; ABS
17ПхЕ  ; RCL E
18х  ; ×
19K[х]  ; INT
20В/О  ; RTN
21Пх6  ; RCL 6
22Fx≥o  ; x≥0 ?
2370  ; address
24↔  ; x<>y
25–  ; −
26хП6  ; STO 6
27FBx  ; LASTX
28В/О  ; RTN
29КППД  ; GSB indirect via RD
30КПП7  ; GSB indirect via R7
31ПхВ  ; RCL B
32+  ; +
33хПВ  ; STO B
34Пх3  ; RCL 3
35Пх1  ; RCL 1
36–  ; −
37Fx=o  ; x=0 ?
3851  ; address
39Пх0  ; RCL 0
402
41F10x  ; 10^x
42+  ; +
43хПЕ  ; STO E
44Сх  ; CLX
45КППД  ; GSB indirect via RD
46КхПЕ  ; STO indirect via RE
47FL0  ; L0 loop
4839  ; address
49хПЕ  ; STO E
50БП  ; GTO
5163  ; address byte (the 37/38 test also lands here, where 63 runs as RCL 3)
52хП3  ; STO 3
53ВП  ; EEX
54Fx≠o  ; x≠0 ?
5559  ; address
564
57–  ; −
58Кзн  ; SIGN
598
60+  ; +
61хПЕ  ; STO E
62КПхЕ  ; RCL indirect via RE
63ПхА  ; RCL A
64КПП8  ; GSB indirect via R8
65КПП7  ; GSB indirect via R7
66ПхА  ; RCL A
67+  ; +
68хПА  ; STO A
69Пх1  ; RCL 1
70Пх3  ; RCL 3
71С/П  ; R/S
72Пх3  ; RCL 3
73+  ; +
74хП3  ; STO 3
75Пх2  ; RCL 2
76–  ; −
77Fx=o  ; x=0 ?
7884  ; address
79ПхС  ; RCL C
80ВП  ; EEX
817
82хП5  ; STO 5
83С/П  ; R/S
84Пх3  ; RCL 3
85Пх4  ; RCL 4
86–  ; −
87Kx=o9  ; x=0 ? (indirect, address in R9)
88ПхД  ; RCL D
89С/П  ; R/S
90Пх5  ; RCL 5
91–  ; −
92Kx=o9  ; x=0 ? (indirect, address in R9)
93ПхВ  ; RCL B
94ПхА  ; RCL A
95хПЕ  ; STO E
96КПП8  ; GSB indirect via R8
97хПА  ; STO A
98Flg  ; LOG
99ПхВ  ; RCL B
A0хПЕ  ; STO E
A1КППД  ; GSB indirect via RD
A2хПВ  ; STO B
A3Fx=o  ; x=0 ?
A493  ; address
Register setup (key in once, in run mode) 43 lines

Run this after keying in the program and before the first game. Several of the constants are hidden-code numbers that the program uses as on-screen text and as jump addresses.

4  ; R0 = 4
хП0
Fex  ; F e^x  (e^4)
хП5  ; R5
500  ; the town's residents
хП6  ; R6
Сх  ; your people
хПА  ; RA
Сх  ; enemy people
хПВ  ; RB
0,12345  ; any number from 0 to 1: the random factor
хПС  ; RC
66080706  ; the next four stores build the "text" constants in R8, R7, RD and R9
В↑
3003
К∨  ; written "KV" on the original page
К{x}
ВП
7
хП8
888888
В↑
3364221
К∨
К{x}
ВП
7
хП7
80808
В↑
11447507
К∨
ВП
7
хПД
888808
В↑
44630229
К∨
К{x}
ВП
7
хП9
HP-15CElektronika MK-52 / MK-61Good and Evil seriesstrategyrecruitingbattle

Original game by Evgeny Vek (Lord_BSS), 1994. Source page.