about summary refs log tree commit diff stats
path: root/082scenario_screen.cc
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2018-06-15 22:16:09 -0700
committerKartik Agaram <vc@akkartik.com>2018-06-15 22:16:09 -0700
commitce9b2b0515eaf92a9c68c8608fd9bf392c941d50 (patch)
treeeb1899f86308c712e54ef94a1c85243c26621c45 /082scenario_screen.cc
parent0edd9b9fc60440213e4df926ea511419ee291f1e (diff)
downloadmu-ce9b2b0515eaf92a9c68c8608fd9bf392c941d50.tar.gz
4258 - undo 4257
Diffstat (limited to '082scenario_screen.cc')
-rw-r--r--082scenario_screen.cc69
1 files changed, 24 insertions, 45 deletions
diff --git a/082scenario_screen.cc b/082scenario_screen.cc
index dc015fed..31cbfcc9 100644
--- a/082scenario_screen.cc
+++ b/082scenario_screen.cc
@@ -145,14 +145,8 @@ assert(Next_predefined_global_for_scenarios < Reserved_for_tests);
 
 :(before "End Globals")
 // Scenario Globals.
-extern const int SCREEN = next_predefined_global_for_scenarios(/*size_of(address:screen)*/2);
+extern const int SCREEN = Next_predefined_global_for_scenarios++;
 // End Scenario Globals.
-:(code)
-int next_predefined_global_for_scenarios(int size) {
-  int result = Next_predefined_global_for_scenarios;
-  Next_predefined_global_for_scenarios += size;
-  return result;
-}
 
 //: give 'screen' a fixed location in scenarios
 :(before "End Special Scenario Variable Names(r)")
@@ -256,27 +250,19 @@ struct raw_string_stream {
 
 :(code)
 void check_screen(const string& expected_contents, const int color) {
-  int screen_location = get_or_insert(Memory, SCREEN+/*skip address alloc id*/1) + /*skip payload alloc id*/1;
-  reagent screen("x:screen");  // just to ensure screen.type is reclaimed
-  int screen_data_location = find_element_location(screen_location, "data", screen.type, "check_screen");  // type: address:array:character
-  assert(screen_data_location >= 0);
-//?   cerr << "screen data is at location " << screen_data_location << '\n';
-  int screen_data_start = get_or_insert(Memory, screen_data_location+/*skip address alloc id*/1) + /*skip payload alloc id*/1;  // type: array:character
-//?   cerr << "screen data start is at " << screen_data_start << '\n';
-  int screen_width_location = find_element_location(screen_location, "num-columns", screen.type, "check_screen");
-//?   cerr << "screen width is at location " << screen_width_location << '\n';
-  int screen_width = get_or_insert(Memory, screen_width_location);
-//?   cerr << "screen width: " << screen_width << '\n';
-  int screen_height_location = find_element_location(screen_location, "num-rows", screen.type, "check_screen");
-//?   cerr << "screen height is at location " << screen_height_location << '\n';
-  int screen_height = get_or_insert(Memory, screen_height_location);
-//?   cerr << "screen height: " << screen_height << '\n';
-  int top_index_location= find_element_location(screen_location, "top-idx", screen.type, "check_screen");
-//?   cerr << "top of screen is at location " << top_index_location << '\n';
-  int top_index = get_or_insert(Memory, top_index_location);
-//?   cerr << "top of screen is index " << top_index << '\n';
+  int screen_location = get_or_insert(Memory, SCREEN);
+  int data_offset = find_element_name(get(Type_ordinal, "screen"), "data", "");
+  assert(data_offset >= 0);
+  int screen_data_location = screen_location+data_offset;  // type: address:array:character
+  int screen_data_start = get_or_insert(Memory, screen_data_location);  // type: array:character
+  int width_offset = find_element_name(get(Type_ordinal, "screen"), "num-columns", "");
+  int screen_width = get_or_insert(Memory, screen_location+width_offset);
+  int height_offset = find_element_name(get(Type_ordinal, "screen"), "num-rows", "");
+  int screen_height = get_or_insert(Memory, screen_location+height_offset);
   raw_string_stream cursor(expected_contents);
   // todo: too-long expected_contents should fail
+  int top_index_offset = find_element_name(get(Type_ordinal, "screen"), "top-idx", "");
+  int top_index = get_or_insert(Memory, screen_location+top_index_offset);
   for (int i=0, row=top_index/screen_width;  i < screen_height;  ++i, row=(row+1)%screen_height) {
     cursor.skip_whitespace_and_comments();
     if (cursor.at_end()) break;
@@ -399,25 +385,18 @@ case _DUMP_SCREEN: {
 
 :(code)
 void dump_screen() {
-  int screen_location = get_or_insert(Memory, SCREEN+/*skip address alloc id*/1) + /*skip payload alloc id*/1;
-  reagent screen("x:screen");  // just to ensure screen.type is reclaimed
-  int screen_data_location = find_element_location(screen_location, "data", screen.type, "check_screen");  // type: address:array:character
-  assert(screen_data_location >= 0);
-//?   cerr << "screen data is at location " << screen_data_location << '\n';
-  int screen_data_start = get_or_insert(Memory, screen_data_location+/*skip address alloc id*/1) + /*skip payload alloc id*/1;  // type: array:character
-//?   cerr << "screen data start is at " << screen_data_start << '\n';
-  int screen_width_location = find_element_location(screen_location, "num-columns", screen.type, "check_screen");
-//?   cerr << "screen width is at location " << screen_width_location << '\n';
-  int screen_width = get_or_insert(Memory, screen_width_location);
-//?   cerr << "screen width: " << screen_width << '\n';
-  int screen_height_location = find_element_location(screen_location, "num-rows", screen.type, "check_screen");
-//?   cerr << "screen height is at location " << screen_height_location << '\n';
-  int screen_height = get_or_insert(Memory, screen_height_location);
-//?   cerr << "screen height: " << screen_height << '\n';
-  int top_index_location= find_element_location(screen_location, "top-idx", screen.type, "check_screen");
-//?   cerr << "top of screen is at location " << top_index_location << '\n';
-  int top_index = get_or_insert(Memory, top_index_location);
-//?   cerr << "top of screen is index " << top_index << '\n';
+  int screen_location = get_or_insert(Memory, SCREEN);
+  int width_offset = find_element_name(get(Type_ordinal, "screen"), "num-columns", "");
+  int screen_width = get_or_insert(Memory, screen_location+width_offset);
+  int height_offset = find_element_name(get(Type_ordinal, "screen"), "num-rows", "");
+  int screen_height = get_or_insert(Memory, screen_location+height_offset);
+  int data_offset = find_element_name(get(Type_ordinal, "screen"), "data", "");
+  assert(data_offset >= 0);
+  int screen_data_location = screen_location+data_offset;  // type: address:array:character
+  int screen_data_start = get_or_insert(Memory, screen_data_location);  // type: array:character
+  assert(get_or_insert(Memory, screen_data_start) == screen_width*screen_height);
+  int top_index_offset = find_element_name(get(Type_ordinal, "screen"), "top-idx", "");
+  int top_index = get_or_insert(Memory, screen_location+top_index_offset);
   for (int i=0, row=top_index/screen_width;  i < screen_height;  ++i, row=(row+1)%screen_height) {
     cerr << '.';
     int curr = screen_data_start+/*length*/1+row*screen_width* /*size of screen-cell*/2;
/cpp/literate/tangle/030tangle.cc?h=hlt&id=515309164793b2e03c15954bf8a89f0f288a7f2c'>51530916 ^
d6852155 ^



51530916 ^


d6852155 ^
51530916 ^


d6852155 ^

51530916 ^



d6852155 ^
51530916 ^



d6852155 ^
51530916 ^



















30ab0297 ^
51530916 ^

2813da63 ^























30ab0297 ^
2813da63 ^


51530916 ^



































































f4b6b2c2 ^
51530916 ^
97f3bbac ^



25d10ece ^
51530916 ^









79a7ad4f ^



51530916 ^











51530916 ^



97f3bbac ^



51530916 ^





























ad796a56 ^






51530916 ^































51530916 ^





































d6852155 ^








































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418