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
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
|
type environment {
search-terms: (handle gap-buffer)
tabs: (handle array tab)
current-tab-index: int # index into tabs
dirty?: boolean
# search mode
cursor-in-search?: boolean
# channel mode
cursor-in-channels?: boolean
channel-cursor-index: int
}
type tab {
type: int
# type 0: all items
# type 1: items in a channel
# type 2: search for a term
# type 3: comments in a single thread
item-index: int # what item in the corresponding list we start rendering
# the current page at
# only for type 0, 1
hidden-items: (handle stream int)
# only for type 1
channel-index: int
# only for type 2
search-terms: (handle gap-buffer)
search-items: (handle array int)
search-items-first-free: int
# only for type 3
root-index: int
}
# static buffer sizes in this file:
# main-panel-hor # in characters
# item-padding-hor # in pixels
# item-padding-ver # in characters
# avatar-side # in pixels
# avatar-space-hor # in characters
# avatar-space-ver # in characters
# search-position-x # in characters
# search-space-ver # in characters
# author-name-padding-ver # in characters
# post-right-coord # in characters
# channel-offset-x # in characters
# menu-space-ver # in characters
# max-search-results
fn initialize-environment _self: (addr environment), _items: (addr item-list) {
var self/esi: (addr environment) <- copy _self
var search-terms-ah/eax: (addr handle gap-buffer) <- get self, search-terms
allocate search-terms-ah
var search-terms/eax: (addr gap-buffer) <- lookup *search-terms-ah
initialize-gap-buffer search-terms, 0x30/search-capacity
var items/eax: (addr item-list) <- copy _items
var items-data-first-free-a/eax: (addr int) <- get items, data-first-free
var final-item/edx: int <- copy *items-data-first-free-a
final-item <- decrement
var tabs-ah/ecx: (addr handle array tab) <- get self, tabs
populate tabs-ah, 0x10/max-history
# current-tab-index implicitly set to 0
var tabs/eax: (addr array tab) <- lookup *tabs-ah
var first-tab/eax: (addr tab) <- index tabs, 0/current-tab-index
var dest/edi: (addr int) <- get first-tab, item-index
copy-to *dest, final-item
}
### Render
fn render-environment screen: (addr screen), _env: (addr environment), users: (addr array user), channels: (addr array channel), items: (addr item-list) {
var env/esi: (addr environment) <- copy _env
{
var dirty?/eax: (addr boolean) <- get env, dirty?
compare *dirty?, 0/false
break-if-!=
# minimize repaints when typing into the search bar
{
var cursor-in-search?/eax: (addr boolean) <- get env, cursor-in-search?
compare *cursor-in-search?, 0/false
break-if-=
render-search-input screen, env
clear-rect screen, 0/x 0x2f/y, 0x80/x 0x30/y, 0/bg
render-search-menu screen, env
return
}
# minimize repaints when focus in channel nav
{
var cursor-in-channels?/eax: (addr boolean) <- get env, cursor-in-channels?
compare *cursor-in-channels?, 0/false
break-if-=
render-channels screen, env, channels
clear-rect screen, 0/x 0x2f/y, 0x80/x 0x30/y, 0/bg
render-channels-menu screen, env
return
}
}
# full repaint
clear-screen screen
render-search-input screen, env
render-channels screen, env, channels
render-item-list screen, env, users, channels, items
render-menu screen, env
var dirty?/eax: (addr boolean) <- get env, dirty?
copy-to *dirty?, 0/false
}
fn render-channels screen: (addr screen), _env: (addr environment), _channels: (addr array channel) {
var env/esi: (addr environment) <- copy _env
var cursor-index/edi: int <- copy -1
{
var cursor-in-search?/eax: (addr boolean) <- get env, cursor-in-search?
compare *cursor-in-search?, 0/false
break-if-!=
var cursor-in-channels?/eax: (addr boolean) <- get env, cursor-in-channels?
compare *cursor-in-channels?, 0/false
break-if-=
var cursor-index-addr/eax: (addr int) <- get env, channel-cursor-index
cursor-index <- copy *cursor-index-addr
}
var channels/esi: (addr array channel) <- copy _channels
var y/ebx: int <- copy 2/search-space-ver
y <- add 1/item-padding-ver
var i/ecx: int <- copy 0
var max/edx: int <- length channels
{
compare i, max
break-if->=
var offset/eax: (offset channel) <- compute-offset channels, i
var curr/eax: (addr channel) <- index channels, offset
var name-ah/eax: (addr handle array byte) <- get curr, name
var name/eax: (addr array byte) <- lookup *name-ah
compare name, 0
break-if-=
set-cursor-position screen, 2/x y
{
compare cursor-index, i
break-if-=
draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, "#", 7/grey 0/black
draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, name, 7/grey 0/black
}
{
compare cursor-index, i
break-if-!=
# cursor; reverse video
draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, "#", 0/black 0xf/white
draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, name, 0/black 0xf/white
}
y <- add 2/channel-padding
i <- increment
loop
}
}
fn render-item-list screen: (addr screen), _env: (addr environment), users: (addr array user), channels: (addr array channel), items: (addr item-list) {
var env/esi: (addr environment) <- copy _env
var tmp-width/eax: int <- copy 0
var tmp-height/ecx: int <- copy 0
tmp-width, tmp-height <- screen-size screen
var screen-width: int
copy-to screen-width, tmp-width
var screen-height: int
copy-to screen-height, tmp-height
#
var tabs-ah/eax: (addr handle array tab) <- get env, tabs
var _tabs/eax: (addr array tab) <- lookup *tabs-ah
var tabs/edx: (addr array tab) <- copy _tabs
var current-tab-index-a/eax: (addr int) <- get env, current-tab-index
var current-tab-index/eax: int <- copy *current-tab-index-a
var current-tab-offset/eax: (offset tab) <- compute-offset tabs, current-tab-index
var current-tab/edx: (addr tab) <- index tabs, current-tab-offset
var show-cursor?: boolean
{
var cursor-in-search?/eax: (addr boolean) <- get env, cursor-in-search?
compare *cursor-in-search?, 0/false
break-if-!=
var cursor-in-channels?/eax: (addr boolean) <- get env, cursor-in-channels?
compare *cursor-in-channels?, 0/false
break-if-!=
copy-to show-cursor?, 1/true
}
render-tab screen, current-tab, show-cursor?, users, channels, items, screen-height
var top/eax: int <- copy screen-height
top <- subtract 2/menu-space-ver
clear-rect screen, 0 top, screen-width screen-height, 0/bg
}
fn render-tab screen: (addr screen), _current-tab: (addr tab), show-cursor?: boolean, users: (addr array user), channels: (addr array channel), items: (addr item-list), screen-height: int {
var current-tab/esi: (addr tab) <- copy _current-tab
var current-tab-type/eax: (addr int) <- get current-tab, type
compare *current-tab-type, 0/all-items
{
break-if-!=
render-all-items screen, current-tab, show-cursor?, items, users, screen-height
return
}
compare *current-tab-type, 1/channel
{
break-if-!=
render-channel-tab screen, current-tab, show-cursor?, users, channels, items, screen-height
return
}
compare *current-tab-type, 2/search
{
break-if-!=
render-search-tab screen, current-tab, show-cursor?, users, channels, items, screen-height
return
}
compare *current-tab-type, 3/thread
{
break-if-!=
render-thread-tab screen, current-tab, show-cursor?, users, channels, items, screen-height
return
}
}
fn render-all-items screen: (addr screen), _current-tab: (addr tab), show-cursor?: boolean, _items: (addr item-list), users: (addr array user), screen-height: int {
var current-tab/esi: (addr tab) <- copy _current-tab
var items/edi: (addr item-list) <- copy _items
var newest-item/eax: (addr int) <- get current-tab, item-index
var i/ebx: int <- copy *newest-item
var items-data-first-free-addr/eax: (addr int) <- get items, data-first-free
render-progress screen, i, *items-data-first-free-addr
var items-data-ah/eax: (addr handle array item) <- get items, data
var _items-data/eax: (addr array item) <- lookup *items-data-ah
var items-data/edi: (addr array item) <- copy _items-data
var y/ecx: int <- copy 2/search-space-ver
y <- add 1/item-padding-ver
$render-all-items:loop: {
compare i, 0
break-if-<
{
var hide?/eax: boolean <- should-hide? current-tab, i, _items
compare hide?, 0/false
break-if-=
i <- decrement
loop $render-all-items:loop
}
compare y, screen-height
break-if->=
var offset/eax: (offset item) <- compute-offset items-data, i
var curr-item/eax: (addr item) <- index items-data, offset
y <- render-item screen, curr-item, users, show-cursor?, y, screen-height
# cursor always at top item
copy-to show-cursor?, 0/false
i <- decrement
loop
}
}
fn render-channel-tab screen: (addr screen), _current-tab: (addr tab), show-cursor?: boolean, users: (addr array user), _channels: (addr array channel), _items: (addr item-list), screen-height: int {
var current-tab/esi: (addr tab) <- copy _current-tab
var items/edi: (addr item-list) <- copy _items
var channels/ebx: (addr array channel) <- copy _channels
var channel-index-addr/eax: (addr int) <- get current-tab, channel-index
var channel-index/eax: int <- copy *channel-index-addr
var channel-offset/eax: (offset channel) <- compute-offset channels, channel-index
var current-channel/ecx: (addr channel) <- index channels, channel-offset
var current-channel-posts-ah/eax: (addr handle array int) <- get current-channel, posts
var _current-channel-posts/eax: (addr array int) <- lookup *current-channel-posts-ah
var current-channel-posts/edx: (addr array int) <- copy _current-channel-posts
var current-channel-first-channel-item-addr/eax: (addr int) <- get current-tab, item-index
var i/ebx: int <- copy *current-channel-first-channel-item-addr
var current-channel-posts-first-free-addr/eax: (addr int) <- get current-channel, posts-first-free
set-cursor-position 0/screen, 0x68/x 0/y
draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, "channel", 7/fg 0/bg
render-progress screen, i, *current-channel-posts-first-free-addr
var items-data-ah/eax: (addr handle array item) <- get items, data
var _items-data/eax: (addr array item) <- lookup *items-data-ah
var items-data/edi: (addr array item) <- copy _items-data
var y/ecx: int <- copy 2/search-space-ver
y <- add 1/item-padding-ver
{
compare i, 0
break-if-<
compare y, screen-height
break-if->=
var item-index-addr/eax: (addr int) <- index current-channel-posts, i
var item-index/eax: int <- copy *item-index-addr
var item-offset/eax: (offset item) <- compute-offset items-data, item-index
var curr-item/eax: (addr item) <- index items-data, item-offset
y <- render-item screen, curr-item, users, show-cursor?, y, screen-height
# cursor always at top item
copy-to show-cursor?, 0/false
i <- decrement
loop
}
}
fn render-search-tab screen: (addr screen), _current-tab: (addr tab), show-cursor?: boolean, users: (addr array user), channels: (addr array channel), _items: (addr item-list), screen-height: int {
var current-tab/esi: (addr tab) <- copy _current-tab
var items/edi: (addr item-list) <- copy _items
var current-tab-search-items-ah/eax: (addr handle array int) <- get current-tab, search-items
var _current-tab-search-items/eax: (addr array int) <- lookup *current-tab-search-items-ah
var current-tab-search-items/ebx: (addr array int) <- copy _current-tab-search-items
var current-tab-top-item-addr/eax: (addr int) <- get current-tab, item-index
var i/edx: int <- copy *current-tab-top-item-addr
var current-tab-search-items-first-free-addr/eax: (addr int) <- get current-tab, search-items-first-free
set-cursor-position 0/screen, 0x68/x 0/y
draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, "search", 7/fg 0/bg
render-progress screen, i, *current-tab-search-items-first-free-addr
{
compare *current-tab-search-items-first-free-addr, 0x100/max-search-results
break-if-<
set-cursor-position 0/screen, 0x68/x 1/y
draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, "too many results", 4/fg 0/bg
}
var items-data-ah/eax: (addr handle array item) <- get items, data
var _items-data/eax: (addr array item) <- lookup *items-data-ah
var items-data/edi: (addr array item) <- copy _items-data
var y/ecx: int <- copy 2/search-space-ver
y <- add 1/item-padding-ver
{
compare i, 0
break-if-<
compare y, screen-height
break-if->=
var item-index-addr/eax: (addr int) <- index current-tab-search-items, i
var item-index/eax: int <- copy *item-index-addr
var item-offset/eax: (offset item) <- compute-offset items-data, item-index
var curr-item/eax: (addr item) <- index items-data, item-offset
y <- render-item screen, curr-item, users, show-cursor?, y, screen-height
# cursor always at top item
copy-to show-cursor?, 0/false
i <- decrement
loop
}
}
fn render-thread-tab screen: (addr screen), _current-tab: (addr tab), show-cursor?: boolean, users: (addr array user), channels: (addr array channel), _items: (addr item-list), screen-height: int {
var current-tab/esi: (addr tab) <- copy _current-tab
var items/eax: (addr item-list) <- copy _items
var items-data-ah/eax: (addr handle array item) <- get items, data
var _items-data/eax: (addr array item) <- lookup *items-data-ah
var items-data/edi: (addr array item) <- copy _items-data
var post-index-addr/eax: (addr int) <- get current-tab, root-index
var post-index/eax: int <- copy *post-index-addr
var post-offset/eax: (offset item) <- compute-offset items-data, post-index
var post/ebx: (addr item) <- index items-data, post-offset
var current-tab-top-item-addr/eax: (addr int) <- get current-tab, item-index
var i/edx: int <- copy *current-tab-top-item-addr
var post-comments-first-free-addr/eax: (addr int) <- get post, comments-first-free
set-cursor-position 0/screen, 0x68/x 0/y
draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, "thread", 7/fg 0/bg
render-progress screen, i, *post-comments-first-free-addr
var post-comments-ah/eax: (addr handle array int) <- get post, comments
var post-comments/eax: (addr array int) <- lookup *post-comments-ah
var y/ecx: int <- copy 2/search-space-ver
y <- add 1/item-padding-ver
{
compare i, 0
break-if-<
compare y, screen-height
break-if->=
var item-index-addr/eax: (addr int) <- index post-comments, i
var item-index/eax: int <- copy *item-index-addr
var item-offset/eax: (offset item) <- compute-offset items-data, item-index
var curr-item/eax: (addr item) <- index items-data, item-offset
y <- render-item screen, curr-item, users, show-cursor?, y, screen-height
# cursor always at top item
copy-to show-cursor?, 0/false
i <- decrement
loop
}
# finally render the parent -- though we'll never focus on it
y <- render-item screen, post, users, 0/no-cursor, y, screen-height
}
# side-effect: mutates cursor position
fn render-progress screen: (addr screen), curr: int, max: int {
set-cursor-position 0/screen, 0x70/x 0/y
var top-index/eax: int <- copy max
top-index <- subtract curr # happy accident: 1-based
draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen screen, top-index, 7/fg 0/bg
draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, "/", 7/fg 0/bg
draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen screen, max, 7/fg 0/bg
}
fn render-search-input screen: (addr screen), _env: (addr environment) {
var env/esi: (addr environment) <- copy _env
var cursor-in-search?/ecx: (addr boolean) <- get env, cursor-in-search?
set-cursor-position 0/screen, 0x22/x=search-position-x 1/y
draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, "search ", 7/fg 0/bg
var search-terms-ah/eax: (addr handle gap-buffer) <- get env, search-terms
var search-terms/eax: (addr gap-buffer) <- lookup *search-terms-ah
rewind-gap-buffer search-terms
var x/eax: int <- render-gap-buffer screen, search-terms, 0x2a/x 1/y, *cursor-in-search?, 0xf/fg 0/bg
{
compare x, 0x4a/end-search
break-if->
var y/ecx: int <- copy 0
x, y <- render-code-point screen, 0x5f/underscore, 0/xmin 1/ymin, 0x80/xmax, 1/ymax, x, 1/y, 0xf/fg 0/bg
loop
}
}
# not used in search mode
fn render-menu screen: (addr screen), _env: (addr environment) {
var env/edi: (addr environment) <- copy _env
{
var cursor-in-search?/eax: (addr boolean) <- get env, cursor-in-search?
compare *cursor-in-search?, 0/false
break-if-=
render-search-menu screen, env
return
}
var cursor-in-channels?/eax: (addr boolean) <- get env, cursor-in-channels?
compare *cursor-in-channels?, 0/false
{
break-if-=
render-channels-menu screen, env
return
}
render-main-menu screen, env
}
fn render-main-menu screen: (addr screen), _env: (addr environment) {
var width/eax: int <- copy 0
var y/ecx: int <- copy 0
width, y <- screen-size screen
y <- decrement
set-cursor-position screen, 2/x, y
{
var env/edi: (addr environment) <- copy _env
var num-tabs/edi: (addr int) <- get env, current-tab-index
compare *num-tabs, 0
break-if-<=
draw-text-rightward-from-cursor screen, " Esc ", width, 0/fg 0xf/bg
draw-text-rightward-from-cursor screen, " go back ", width, 0xf/fg, 0/bg
}
draw-text-rightward-from-cursor screen, " / ", width, 0/fg 0xf/bg
draw-text-rightward-from-cursor screen, " search ", width, 0xf/fg, 0/bg
draw-text-rightward-from-cursor screen, " Tab ", width, 0/fg 0xf/bg
draw-text-rightward-from-cursor screen, " go to channels ", width, 0xf/fg, 0/bg
draw-text-rightward-from-cursor screen, " Enter ", width, 0/fg 0xf/bg
draw-text-rightward-from-cursor screen, " go to thread ", width, 0xf/fg, 0/bg
{
{
var is-all-items-or-channel?/eax: boolean <- current-tab-is-all-items-or-channel? _env
compare is-all-items-or-channel?, 0/false
}
break-if-=
draw-text-rightward-from-cursor screen, " ^h ", width, 0/fg 0xf/bg
draw-text-rightward-from-cursor screen, " hide thread ", width, 0xf/fg, 0/bg
draw-text-rightward-from-cursor screen, " ^u ", width, 0/fg 0xf/bg
draw-text-rightward-from-cursor screen, " unhide all ", width, 0xf/fg, 0/bg
}
draw-text-rightward-from-cursor screen, " ^b ", width, 0/fg 0xf/bg
draw-text-rightward-from-cursor screen, " << page ", width, 0xf/fg, 0/bg
draw-text-rightward-from-cursor screen, " ^f ", width, 0/fg 0xf/bg
draw-text-rightward-from-cursor screen, " page >> ", width, 0xf/fg, 0/bg
}
fn render-channels-menu screen: (addr screen), _env: (addr environment) {
var width/eax: int <- copy 0
var y/ecx: int <- copy 0
width, y <- screen-size screen
y <- decrement
set-cursor-position screen, 2/x, y
{
var env/edi: (addr environment) <- copy _env
var num-tabs/edi: (addr int) <- get env, current-tab-index
compare *num-tabs, 0
break-if-<=
draw-text-rightward-from-cursor screen, " Esc ", width, 0/fg 0xf/bg
draw-text-rightward-from-cursor screen, " go back ", width, 0xf/fg, 0/bg
}
draw-text-rightward-from-cursor screen, " / ", width, 0/fg 0xf/bg
draw-text-rightward-from-cursor screen, " search ", width, 0xf/fg, 0/bg
draw-text-rightward-from-cursor screen, " Tab ", width, 0/fg 0xf/bg
draw-text-rightward-from-cursor screen, " go to items ", width, 0xf/fg, 0/bg
draw-text-rightward-from-cursor screen, " Enter ", width, 0/fg 0xf/bg
draw-text-rightward-from-cursor screen, " select ", width, 0xf/fg, 0/bg
}
fn render-search-menu screen: (addr screen), _env: (addr environment) {
var width/eax: int <- copy 0
var y/ecx: int <- copy 0
width, y <- screen-size screen
y <- decrement
set-cursor-position screen, 2/x, y
draw-text-rightward-from-cursor screen, " Esc ", width, 0/fg 0xf/bg
draw-text-rightward-from-cursor screen, " cancel ", width, 0xf/fg, 0/bg
draw-text-rightward-from-cursor screen, " Enter ", width, 0/fg 0xf/bg
draw-text-rightward-from-cursor screen, " select ", width, 0xf/fg, 0/bg
draw-text-rightward-from-cursor screen, " ^a ", width, 0/fg, 0xf/bg
draw-text-rightward-from-cursor screen, " << ", width, 0xf/fg, 0/bg
draw-text-rightward-from-cursor screen, " ^b ", width, 0/fg, 0xf/bg
draw-text-rightward-from-cursor screen, " <word ", width, 0xf/fg, 0/bg
draw-text-rightward-from-cursor screen, " ^f ", width, 0/fg, 0xf/bg
draw-text-rightward-from-cursor screen, " word> ", width, 0xf/fg, 0/bg
draw-text-rightward-from-cursor screen, " ^e ", width, 0/fg, 0xf/bg
draw-text-rightward-from-cursor screen, " >> ", width, 0xf/fg, 0/bg
draw-text-rightward-from-cursor screen, " ^u ", width, 0/fg, 0xf/bg
draw-text-rightward-from-cursor screen, " clear ", width, 0xf/fg, 0/bg
}
fn render-item screen: (addr screen), _item: (addr item), _users: (addr array user), show-cursor?: boolean, y: int, screen-height: int -> _/ecx: int {
var item/esi: (addr item) <- copy _item
var users/edi: (addr array user) <- copy _users
var author-index-addr/ecx: (addr int) <- get item, by
var author-index/ecx: int <- copy *author-index-addr
var author-offset/ecx: (offset user) <- compute-offset users, author-index
var author/ecx: (addr user) <- index users, author-offset
# author avatar
var author-avatar-ah/eax: (addr handle image) <- get author, avatar
var _author-avatar/eax: (addr image) <- lookup *author-avatar-ah
var author-avatar/ebx: (addr image) <- copy _author-avatar
{
compare author-avatar, 0
break-if-=
var y/edx: int <- copy y
y <- shift-left 4/log2font-height
var x/eax: int <- copy 0x20/main-panel-hor
x <- shift-left 3/log2font-width
x <- add 0x18/item-padding-hor
render-image screen, author-avatar, x, y, 0x50/avatar-side, 0x50/avatar-side
}
# channel
var channel-name-ah/eax: (addr handle array byte) <- get item, channel
var channel-name/eax: (addr array byte) <- lookup *channel-name-ah
{
var x/eax: int <- copy 0x20/main-panel-hor
x <- add 0x40/channel-offset-x
set-cursor-position screen, x y
}
draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, "#", 7/grey 0/black
draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, channel-name, 7/grey 0/black
# author name
{
var author-real-name-ah/eax: (addr handle array byte) <- get author, real-name
var author-real-name/eax: (addr array byte) <- lookup *author-real-name-ah
var x/ecx: int <- copy 0x20/main-panel-hor
x <- add 0x10/avatar-space-hor
set-cursor-position screen, x y
draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, author-real-name, 0xf/white 0/black
}
increment y
# text
var text-ah/eax: (addr handle array byte) <- get item, text
var _text/eax: (addr array byte) <- lookup *text-ah
var text/edx: (addr array byte) <- copy _text
var text-y/eax: int <- render-slack-message screen, text, show-cursor?, y, screen-height
# flush
add-to y, 6/avatar-space-ver
compare y, text-y
{
break-if-<
return y
}
return text-y
}
fn render-slack-message screen: (addr screen), text: (addr array byte), highlight?: boolean, ymin: int, ymax: int -> _/eax: int {
var x/eax: int <- copy 0x20/main-panel-hor
x <- add 0x10/avatar-space-hor
var y/ecx: int <- copy ymin
y <- add 1/author-name-padding-ver
$render-slack-message:draw: {
compare highlight?, 0/false
{
break-if-=
x, y <- draw-json-text-wrapping-right-then-down screen, text, x y, 0x70/xmax=post-right-coord ymax, x y, 0/fg 7/bg
break $render-slack-message:draw
}
x, y <- draw-json-text-wrapping-right-then-down screen, text, x y, 0x70/xmax=post-right-coord ymax, x y, 7/fg 0/bg
}
y <- add 2/item-padding-ver
return y
}
# draw text in the rectangle from (xmin, ymin) to (xmax, ymax), starting from (x, y), wrapping as necessary
# return the next (x, y) coordinate in raster order where drawing stopped
# that way the caller can draw more if given the same min and max bounding-box.
# if there isn't enough space, truncate
fn draw-json-text-wrapping-right-then-down screen: (addr screen), _text: (addr array byte), xmin: int, ymin: int, xmax: int, ymax: int, _x: int, _y: int, color: int, background-color: int -> _/eax: int, _/ecx: int {
var stream-storage: (stream byte 0x4000/print-buffer-size)
var stream/edi: (addr stream byte) <- address stream-storage
var text/esi: (addr array byte) <- copy _text
var len/eax: int <- length text
compare len, 0x4000/print-buffer-size
{
break-if-<
write stream, "ERROR: stream too small in draw-text-wrapping-right-then-down"
}
compare len, 0x4000/print-buffer-size
{
break-if->=
write stream, text
}
var x/eax: int <- copy _x
var y/ecx: int <- copy _y
x, y <- draw-json-stream-wrapping-right-then-down screen, stream, xmin, ymin, xmax, ymax, x, y, color, background-color
return x, y
}
# draw a stream in the rectangle from (xmin, ymin) to (xmax, ymax), starting from (x, y), wrapping as necessary
# return the next (x, y) coordinate in raster order where drawing stopped
# that way the caller can draw more if given the same min and max bounding-box.
# if there isn't enough space, truncate
fn draw-json-stream-wrapping-right-then-down screen: (addr screen), stream: (addr stream byte), xmin: int, ymin: int, xmax: int, ymax: int, x: int, y: int, color: int, background-color: int -> _/eax: int, _/ecx: int {
var xcurr/ecx: int <- copy x
var ycurr/edx: int <- copy y
var c/ebx: code-point <- copy 0
var next-c/esi: code-point <- copy 0
{
# read c from either next-c or stream
$draw-json-stream-wrapping-right-then-down:read-base: {
compare next-c, 0
{
break-if-=
c <- copy next-c
next-c <- copy 0
break $draw-json-stream-wrapping-right-then-down:read-base
}
c <- read-json-code-point stream
}
compare c, 0xffffffff/end-of-file
break-if-=
$draw-json-stream-wrapping-right-then-down:render-code-point-utf8: {
compare c, 0x5c/backslash
{
break-if-!=
xcurr, ycurr <- render-json-escaped-code-point screen, stream, xmin, ymin, xmax, ymax, xcurr, ycurr, color, background-color
break $draw-json-stream-wrapping-right-then-down:render-code-point-utf8
}
compare c, 0xa/newline
{
break-if-!=
# minimum effort to clear cursor
var dummy/eax: int <- draw-code-point screen, 0x20/space, xcurr, ycurr, color, background-color
xcurr <- copy xmin
ycurr <- increment
break $draw-json-stream-wrapping-right-then-down:render-code-point-utf8
}
var offset/eax: int <- draw-code-point screen, c, xcurr, ycurr, color, background-color
# overlay a combining character if necessary
$draw-json-stream-wrapping-right-then-down:read-combiner: {
var done?/eax: boolean <- stream-empty? stream
compare done?, 0/false
break-if-!=
# read a character
# no combining character allowed here
var g/eax: code-point-utf8 <- read-code-point-utf8 stream
var c/eax: code-point <- to-code-point g
# if not a combining character, save for next iteration and loop
{
var combining-code-point?/eax: boolean <- combining-code-point? c
compare combining-code-point?, 0/false
}
{
break-if-!=
next-c <- copy c
break $draw-json-stream-wrapping-right-then-down:read-combiner
}
# otherwise overlay it without saving its width
# This means strange results if a base and its combiner have different
# widths. We'll always follow the base width.
var dummy/eax: int <- overlay-code-point screen, c, xcurr, ycurr, color, background-color
}
xcurr <- add offset
compare xcurr, xmax
{
break-if-<
xcurr <- copy xmin
ycurr <- increment
}
}
loop
}
set-cursor-position screen, xcurr, ycurr
return xcurr, ycurr
}
# just return a different register
fn read-json-code-point stream: (addr stream byte) -> _/ebx: code-point {
var g/eax: code-point-utf8 <- read-code-point-utf8 stream
var result/eax: code-point <- to-code-point g
return result
}
# '\' encountered
# https://www.json.org/json-en.html
fn render-json-escaped-code-point screen: (addr screen), stream: (addr stream byte), xmin: int, ymin: int, xmax: int, ymax: int, xcurr: int, ycurr: int, color: int, background-color: int -> _/ecx: int, _/edx: int {
var g/ebx: code-point <- read-json-code-point stream
compare g, 0xffffffff/end-of-file
{
break-if-!=
return xcurr, ycurr
}
# \n = newline
compare g, 0x6e/n
var x/eax: int <- copy xcurr
{
break-if-!=
increment ycurr
return xmin, ycurr
}
# ignore \t \r \f \b
{
compare g, 0x74/t
break-if-!=
return xcurr, ycurr
}
{
compare g, 0x72/r
break-if-!=
return xcurr, ycurr
}
{
compare g, 0x66/f
break-if-!=
return xcurr, ycurr
}
{
compare g, 0x62/b
break-if-!=
return xcurr, ycurr
}
var y/ecx: int <- copy 0
# \u = Unicode
{
compare g, 0x75/u
break-if-!=
x, y <- render-json-escaped-unicode-code-point screen, stream, xmin, ymin, xmax, ymax, xcurr, ycurr, color, background-color
var y/edx: int <- copy y
return x, y
}
# most characters escape to themselves
# combining characters not supported after backslash
x, y <- render-code-point screen, g, xmin, ymin, xmax, ymax, xcurr, ycurr, color, background-color
var y/edx: int <- copy y
return x, y
}
# '\u' encountered
fn render-json-escaped-unicode-code-point screen: (addr screen), stream: (addr stream byte), xmin: int, ymin: int, xmax: int, ymax: int, xcurr: int, ycurr: int, color: int, background-color: int -> _/eax: int, _/ecx: int {
var hex-digits-storage: (array byte 4)
var hex-digits/esi: (addr array byte) <- address hex-digits-storage
# slurp 4 bytes exactly
var src/eax: byte <- read-byte stream
var dest/ecx: (addr byte) <- index hex-digits, 0
copy-byte-to *dest, src
src <- read-byte stream
dest <- index hex-digits, 1
copy-byte-to *dest, src
src <- read-byte stream
dest <- index hex-digits, 2
copy-byte-to *dest, src
src <- read-byte stream
dest <- index hex-digits, 3
copy-byte-to *dest, src
# \u2013 = -
{
var endash?/eax: boolean <- string-equal? hex-digits, "2013"
compare endash?, 0/false
break-if-=
var x/eax: int <- copy 0
var y/ecx: int <- copy 0
x, y <- render-code-point screen, 0x2d/dash, xmin, ymin, xmax, ymax, xcurr, ycurr, color, background-color
return x, y
}
# \u2014 = -
{
var emdash?/eax: boolean <- string-equal? hex-digits, "2014"
compare emdash?, 0/false
break-if-=
var x/eax: int <- copy 0
var y/ecx: int <- copy 0
x, y <- render-code-point screen, 0x2d/dash, xmin, ymin, xmax, ymax, xcurr, ycurr, color, background-color
return x, y
}
# \u2018 = '
{
var left-quote?/eax: boolean <- string-equal? hex-digits, "2018"
compare left-quote?, 0/false
break-if-=
var x/eax: int <- copy 0
var y/ecx: int <- copy 0
x, y <- render-code-point screen, 0x27/quote, xmin, ymin, xmax, ymax, xcurr, ycurr, color, background-color
return x, y
}
# \u2019 = '
{
var right-quote?/eax: boolean <- string-equal? hex-digits, "2019"
compare right-quote?, 0/false
break-if-=
var x/eax: int <- copy 0
var y/ecx: int <- copy 0
x, y <- render-code-point screen, 0x27/quote, xmin, ymin, xmax, ymax, xcurr, ycurr, color, background-color
return x, y
}
# \u201c = "
{
var left-dquote?/eax: boolean <- string-equal? hex-digits, "201c"
compare left-dquote?, 0/false
break-if-=
var x/eax: int <- copy 0
var y/ecx: int <- copy 0
x, y <- render-code-point screen, 0x22/dquote, xmin, ymin, xmax, ymax, xcurr, ycurr, color, background-color
return x, y
}
# \u201d = "
{
var right-dquote?/eax: boolean <- string-equal? hex-digits, "201d"
compare right-dquote?, 0/false
break-if-=
var x/eax: int <- copy 0
var y/ecx: int <- copy 0
x, y <- render-code-point screen, 0x22/dquote, xmin, ymin, xmax, ymax, xcurr, ycurr, color, background-color
return x, y
}
# \u2022 = *
{
var bullet?/eax: boolean <- string-equal? hex-digits, "2022"
compare bullet?, 0/false
break-if-=
var x/eax: int <- copy 0
var y/ecx: int <- copy 0
x, y <- render-code-point screen, 0x2a/asterisk, xmin, ymin, xmax, ymax, xcurr, ycurr, color, background-color
return x, y
}
# \u2026 = ...
{
var ellipses?/eax: boolean <- string-equal? hex-digits, "2026"
compare ellipses?, 0/false
break-if-=
var x/eax: int <- copy 0
var y/ecx: int <- copy 0
x, y <- draw-text-wrapping-right-then-down screen, "...", xmin, ymin, xmax, ymax, xcurr, ycurr, color, background-color
return x, y
}
var n/eax: int <- parse-hex-int hex-digits
var c/edx: code-point <- copy n
var x/eax: int <- copy 0
var y/ecx: int <- copy 0
x, y <- render-code-point screen, c, xmin, ymin, xmax, ymax, xcurr, ycurr, color, background-color
return x, y
}
### Edit
fn update-environment _env: (addr environment), key: byte, users: (addr array user), channels: (addr array channel), items: (addr item-list) {
var env/edi: (addr environment) <- copy _env
# first dispatch to search mode if necessary
{
var cursor-in-search?/eax: (addr boolean) <- get env, cursor-in-search?
compare *cursor-in-search?, 0/false
break-if-=
update-search env, key, users, channels, items
return
}
{
compare key, 0x2f/slash
break-if-!=
# enter search mode
var cursor-in-search?/eax: (addr boolean) <- get env, cursor-in-search?
copy-to *cursor-in-search?, 1/true
# do one more repaint
var dirty?/eax: (addr boolean) <- get env, dirty?
copy-to *dirty?, 1/true
return
}
{
compare key, 0x1b/esc
break-if-!=
# back in history
previous-tab env
return
}
var cursor-in-channels?/eax: (addr boolean) <- get env, cursor-in-channels?
{
compare key, 9/tab
break-if-!=
# toggle cursor between main panel and channels nav
not *cursor-in-channels? # bitwise NOT; only works if you never assign 1/true to this variable
# do one more repaint
var dirty?/eax: (addr boolean) <- get env, dirty?
copy-to *dirty?, 1/true
return
}
{
compare *cursor-in-channels?, 0/false
break-if-!=
update-main-panel env, key, users, channels, items
return
}
{
compare *cursor-in-channels?, 0/false
break-if-=
update-channels-nav env, key, users, channels, items
return
}
}
fn update-main-panel env: (addr environment), key: byte, users: (addr array user), channels: (addr array channel), items: (addr item-list) {
{
compare key, 0xa/newline
break-if-!=
new-thread-tab env, users, channels, items
return
}
{
compare key, 8/ctrl-h
break-if-!=
var is-all-items-or-channel?/eax: boolean <- current-tab-is-all-items-or-channel? env
compare is-all-items-or-channel?, 0/false
break-if-=
hide-thread env, users, channels, items
return
}
{
compare key, 0x15/ctrl-u
break-if-!=
var is-all-items-or-channel?/eax: boolean <- current-tab-is-all-items-or-channel? env
compare is-all-items-or-channel?, 0/false
break-if-=
new-all-items-tab env, users, channels, items
return
}
{
compare key, 0x81/down-arrow
break-if-!=
next-item env, users, channels, items
return
}
{
compare key, 0x82/up-arrow
break-if-!=
previous-item env, users, channels, items
return
}
{
compare key, 6/ctrl-f
break-if-!=
page-down env, users, channels, items
return
}
{
compare key, 2/ctrl-b
break-if-!=
page-up env, users, channels, items
return
}
}
fn current-tab-is-all-items-or-channel? _env: (addr environment) -> _/eax: boolean {
var env/esi: (addr environment) <- copy _env
var tabs-ah/eax: (addr handle array tab) <- get env, tabs
var _tabs/eax: (addr array tab) <- lookup *tabs-ah
var tabs/edx: (addr array tab) <- copy _tabs
var current-tab-index-a/eax: (addr int) <- get env, current-tab-index
var current-tab-index/eax: int <- copy *current-tab-index-a
var current-tab-offset/eax: (offset tab) <- compute-offset tabs, current-tab-index
var current-tab/edx: (addr tab) <- index tabs, current-tab-offset
var current-tab-type/eax: (addr int) <- get current-tab, type
{
compare *current-tab-type, 0/all-items
break-if-!=
return 1/true
}
{
compare *current-tab-type, 1/channel
break-if-!=
return 1/true
}
return 0/false
}
# TODO: clamp cursor within bounds
fn update-channels-nav _env: (addr environment), key: byte, users: (addr array user), channels: (addr array channel), items: (addr item-list) {
var env/edi: (addr environment) <- copy _env
var channel-cursor-index/eax: (addr int) <- get env, channel-cursor-index
{
compare key, 0x81/down-arrow
break-if-!=
increment *channel-cursor-index
return
}
{
compare key, 0x82/up-arrow
break-if-!=
decrement *channel-cursor-index
return
}
{
compare key, 0xa/newline
break-if-!=
new-channel-tab env, *channel-cursor-index, channels
var cursor-in-channels?/eax: (addr boolean) <- get env, cursor-in-channels?
copy-to *cursor-in-channels?, 0/false
return
}
}
fn update-search _env: (addr environment), key: byte, users: (addr array user), channels: (addr array channel), items: (addr item-list) {
var env/edi: (addr environment) <- copy _env
var cursor-in-search?/eax: (addr boolean) <- get env, cursor-in-search?
{
compare key 0x1b/esc
break-if-!=
# get out of search mode
copy-to *cursor-in-search?, 0/false
return
}
{
compare key, 0xa/newline
break-if-!=
# perform a search, then get out of search mode
new-search-tab env, items
copy-to *cursor-in-search?, 0/false
return
}
# otherwise delegate
var search-terms-ah/eax: (addr handle gap-buffer) <- get env, search-terms
var search-terms/eax: (addr gap-buffer) <- lookup *search-terms-ah
var g/ecx: code-point-utf8 <- copy key
edit-gap-buffer search-terms, g
}
fn new-all-items-tab _env: (addr environment), users: (addr array user), channels: (addr array channel), _items: (addr item-list) {
var env/edi: (addr environment) <- copy _env
var current-tab-index-addr/ecx: (addr int) <- get env, current-tab-index
increment *current-tab-index-addr
var tabs-ah/eax: (addr handle array tab) <- get env, tabs
var tabs/eax: (addr array tab) <- lookup *tabs-ah
var max-tabs/ebx: int <- length tabs
{
compare *current-tab-index-addr, max-tabs
break-if-<
abort "history overflow; grow max-history (we should probably improve this)"
}
var current-tab-index/ecx: int <- copy *current-tab-index-addr
var current-tab-offset/ecx: (offset tab) <- compute-offset tabs, current-tab-index
var current-tab/ecx: (addr tab) <- index tabs, current-tab-offset
clear-object current-tab
var items/eax: (addr item-list) <- copy _items
var items-data-first-free-a/eax: (addr int) <- get items, data-first-free
var final-item/edx: int <- copy *items-data-first-free-a
final-item <- decrement
var dest/edi: (addr int) <- get current-tab, item-index
copy-to *dest, final-item
}
fn new-thread-tab _env: (addr environment), users: (addr array user), channels: (addr array channel), _items: (addr item-list) {
var env/edi: (addr environment) <- copy _env
var current-tab-index-addr/ecx: (addr int) <- get env, current-tab-index
var tabs-ah/eax: (addr handle array tab) <- get env, tabs
var tabs/eax: (addr array tab) <- lookup *tabs-ah
var current-tab-index/ecx: int <- copy *current-tab-index-addr
var current-tab-offset/ecx: (offset tab) <- compute-offset tabs, current-tab-index
var current-tab/ecx: (addr tab) <- index tabs, current-tab-offset
var item-index/esi: int <- item-index env, _items, channels
var post-index/ecx: int <- post-index _items, item-index
var current-tab-index-addr/eax: (addr int) <- get env, current-tab-index
increment *current-tab-index-addr
var current-tab-index/edx: int <- copy *current-tab-index-addr
var tabs-ah/eax: (addr handle array tab) <- get env, tabs
var tabs/eax: (addr array tab) <- lookup *tabs-ah
var max-tabs/ebx: int <- length tabs
compare current-tab-index, max-tabs
{
compare current-tab-index, max-tabs
break-if-<
abort "history overflow; grow max-history (we should probably improve this)"
}
var current-tab-offset/edi: (offset tab) <- compute-offset tabs, current-tab-index
var current-tab/edi: (addr tab) <- index tabs, current-tab-offset
clear-object current-tab
var current-tab-type/eax: (addr int) <- get current-tab, type
copy-to *current-tab, 3/thread
var current-tab-root-index/eax: (addr int) <- get current-tab, root-index
copy-to *current-tab-root-index, post-index
var items/eax: (addr item-list) <- copy _items
var items-data-ah/eax: (addr handle array item) <- get items, data
var items-data/eax: (addr array item) <- lookup *items-data-ah
var offset/ecx: (offset item) <- compute-offset items-data, post-index
var post/eax: (addr item) <- index items-data, offset
var post-comments-first-free-addr/ecx: (addr int) <- get post, comments-first-free
# terminology:
# post-comment-index = index of a comment in a post's comment array
# comment-index = index of a comment in the global item list
var final-post-comment-index/ecx: int <- copy *post-comments-first-free-addr
final-post-comment-index <- decrement
var post-comments-ah/eax: (addr handle array int) <- get post, comments
var post-comments/eax: (addr array int) <- lookup *post-comments-ah
# look for item-index in post-comments[0..final-post-comment-index]
var curr-post-comment-index/edx: int <- copy final-post-comment-index
{
compare curr-post-comment-index, 0
{
break-if->=
# if we didn't find the current item in a post's comments, it must be
# the parent post itself which isn't in the comment list but hackily
# rendered at the bottom. Just render the whole comment list.
var tab-item-index-addr/edi: (addr int) <- get current-tab, item-index
copy-to *tab-item-index-addr, curr-post-comment-index
return
}
var curr-comment-index/ecx: (addr int) <- index post-comments, curr-post-comment-index
compare *curr-comment-index, item-index
{
break-if-!=
# item-index found
var tab-item-index-addr/edi: (addr int) <- get current-tab, item-index
copy-to *tab-item-index-addr, curr-post-comment-index
return
}
curr-post-comment-index <- decrement
loop
}
abort "new-thread-tab: should never leave previous loop without returning"
}
# hide a thread in a (channel or all-items) tab
fn hide-thread _env: (addr environment), users: (addr array user), channels: (addr array channel), items: (addr item-list) {
var env/edi: (addr environment) <- copy _env
var current-tab-index-addr/eax: (addr int) <- get env, current-tab-index
var current-tab-index/ecx: int <- copy *current-tab-index-addr
var tabs-ah/eax: (addr handle array tab) <- get env, tabs
var tabs/eax: (addr array tab) <- lookup *tabs-ah
var current-tab-offset/ecx: (offset tab) <- compute-offset tabs, current-tab-index
var current-tab/ebx: (addr tab) <- index tabs, current-tab-offset
var current-tab-hidden-items-ah/edx: (addr handle stream int) <- get current-tab, hidden-items
var current-tab-hidden-items/eax: (addr stream int) <- lookup *current-tab-hidden-items-ah
{
compare current-tab-hidden-items, 0
break-if-!=
populate-stream current-tab-hidden-items-ah, 0x10/max-hidden-threads
current-tab-hidden-items <- lookup *current-tab-hidden-items-ah
}
{
var too-many-hidden-items?/eax: boolean <- stream-full? current-tab-hidden-items
compare too-many-hidden-items?, 0/false
break-if-=
abort "too many hidden threads in this tab" # TODO: create a space for flash error messages on screen
return
}
var current-item-index/esi: int <- item-index env, items, channels
var current-post-index-value/ecx: int <- post-index items, current-item-index
# . turn current-post-index into an addr
var current-post-index-storage: int
copy-to current-post-index-storage, current-post-index-value
var current-post-index-addr/ecx: (addr int) <- address current-post-index-storage
#
write-to-stream current-tab-hidden-items, current-post-index-addr
# current-tab's item-index is now on a hidden item
# try to position it on a visible item
var item-index-addr/esi: (addr int) <- get current-tab, item-index
var old-item-index/eax: int <- copy *item-index-addr
next-item env, users, channels, items
compare *item-index-addr, old-item-index
break-if-!=
previous-item env, users, channels, items
}
fn should-hide? _tab: (addr tab), item-index: int, items: (addr item-list) -> _/eax: boolean {
var post-index/ecx: int <- post-index items, item-index
var tab/esi: (addr tab) <- copy _tab
var tab-hidden-items-ah/edx: (addr handle stream int) <- get tab, hidden-items
var tab-hidden-items/eax: (addr stream int) <- lookup *tab-hidden-items-ah
compare tab-hidden-items, 0
{
break-if-!=
# either we haven't hidden anything, or we're in a tab type that doesn't
# support hiding
return 0/false
}
rewind-stream tab-hidden-items
{
{
var done?/eax: boolean <- stream-empty? tab-hidden-items
compare done?, 0/false
}
break-if-!=
var curr-item: int
var curr-item-addr/edx: (addr int) <- address curr-item
read-from-stream tab-hidden-items, curr-item-addr
# if curr-item == post-index, return true
compare curr-item, post-index
{
break-if-!=
return 1/true
}
loop
}
return 0/false
}
# what index in the global items list is the cursor at in the current tab?
fn item-index _env: (addr environment), _items: (addr item-list), _channels: (addr array channel) -> _/esi: int {
var env/eax: (addr environment) <- copy _env
var current-tab-index-addr/esi: (addr int) <- get env, current-tab-index
var tabs-ah/eax: (addr handle array tab) <- get env, tabs
var tabs/eax: (addr array tab) <- lookup *tabs-ah
var tab-index/esi: int <- copy *current-tab-index-addr
var tab-offset/esi: (offset tab) <- compute-offset tabs, tab-index
var tab/esi: (addr tab) <- index tabs, tab-offset
var tab-type/eax: (addr int) <- get tab, type
{
compare *tab-type, 0/all-items
break-if-!=
var tab-item-index/eax: (addr int) <- get tab, item-index
return *tab-item-index
}
{
compare *tab-type, 1/channel
break-if-!=
var channel-index-addr/eax: (addr int) <- get tab, channel-index
var channel-index/eax: int <- copy *channel-index-addr
var channels/ecx: (addr array channel) <- copy _channels
var channel-offset/eax: (offset channel) <- compute-offset channels, channel-index
var current-channel/eax: (addr channel) <- index channels, channel-offset
var current-channel-posts-ah/eax: (addr handle array int) <- get current-channel, posts
var current-channel-posts/eax: (addr array int) <- lookup *current-channel-posts-ah
var channel-item-index-addr/ecx: (addr int) <- get tab, item-index
var channel-item-index/ecx: int <- copy *channel-item-index-addr
var channel-item-index/eax: (addr int) <- index current-channel-posts, channel-item-index
return *channel-item-index
}
{
compare *tab-type, 2/search
break-if-!=
var tab-search-items-ah/eax: (addr handle array int) <- get tab, search-items
var tab-search-items/eax: (addr array int) <- lookup *tab-search-items-ah
var tab-search-items-index-addr/ecx: (addr int) <- get tab, item-index
var tab-search-items-index/ecx: int <- copy *tab-search-items-index-addr
var src/eax: (addr int) <- index tab-search-items, tab-search-items-index
return *src
}
{
compare *tab-type, 3/thread
break-if-!=
var items/eax: (addr item-list) <- copy _items
var items-data-ah/eax: (addr handle array item) <- get items, data
var _items-data/eax: (addr array item) <- lookup *items-data-ah
var items-data/edi: (addr array item) <- copy _items-data
var tab-root-index-addr/eax: (addr int) <- get tab, root-index
var tab-root-index/eax: int <- copy *tab-root-index-addr
var tab-root-offset/eax: (offset item) <- compute-offset items-data, tab-root-index
var post/eax: (addr item) <- index items-data, tab-root-offset
var post-comments-ah/eax: (addr handle array int) <- get post, comments
var post-comments/eax: (addr array int) <- lookup *post-comments-ah
var tab-item-index-addr/ecx: (addr int) <- get tab, item-index
var tab-item-index/ecx: int <- copy *tab-item-index-addr
var src/eax: (addr int) <- index post-comments, tab-item-index
return *src
}
abort "item-index: unknown tab type"
return -1
}
# go from a comment item to its parent post
fn post-index _items: (addr item-list), item-index: int -> _/ecx: int {
var items/eax: (addr item-list) <- copy _items
var items-data-ah/eax: (addr handle array item) <- get items, data
var items-data/eax: (addr array item) <- lookup *items-data-ah
var index/ecx: int <- copy item-index
var offset/ecx: (offset item) <- compute-offset items-data, index
var item/eax: (addr item) <- index items-data, offset
var parent/eax: (addr int) <- get item, parent
compare *parent, 0
{
break-if-=
return *parent
}
return item-index
}
fn new-channel-tab _env: (addr environment), channel-index: int, _channels: (addr array channel) {
var env/edi: (addr environment) <- copy _env
var current-tab-index-addr/eax: (addr int) <- get env, current-tab-index
increment *current-tab-index-addr
var current-tab-index/ecx: int <- copy *current-tab-index-addr
var tabs-ah/eax: (addr handle array tab) <- get env, tabs
var tabs/eax: (addr array tab) <- lookup *tabs-ah
var max-tabs/edx: int <- length tabs
compare current-tab-index, max-tabs
{
compare current-tab-index, max-tabs
break-if-<
abort "history overflow; grow max-history (we should probably improve this)"
}
var current-tab-offset/ecx: (offset tab) <- compute-offset tabs, current-tab-index
var current-tab/ecx: (addr tab) <- index tabs, current-tab-offset
clear-object current-tab
var current-tab-type/eax: (addr int) <- get current-tab, type
copy-to *current-tab, 1/channel
var current-tab-channel-index/eax: (addr int) <- get current-tab, channel-index
var curr-channel-index/edx: int <- copy channel-index
copy-to *current-tab-channel-index, curr-channel-index
var channels/esi: (addr array channel) <- copy _channels
var curr-channel-offset/eax: (offset channel) <- compute-offset channels, curr-channel-index
var curr-channel/eax: (addr channel) <- index channels, curr-channel-offset
var curr-channel-posts-first-free-addr/eax: (addr int) <- get curr-channel, posts-first-free
var curr-channel-final-post-index/eax: int <- copy *curr-channel-posts-first-free-addr
curr-channel-final-post-index <- decrement
var dest/edi: (addr int) <- get current-tab, item-index
copy-to *dest, curr-channel-final-post-index
}
fn new-search-tab _env: (addr environment), items: (addr item-list) {
var env/edi: (addr environment) <- copy _env
var current-tab-index-addr/eax: (addr int) <- get env, current-tab-index
increment *current-tab-index-addr
var current-tab-index/ecx: int <- copy *current-tab-index-addr
var tabs-ah/eax: (addr handle array tab) <- get env, tabs
var tabs/eax: (addr array tab) <- lookup *tabs-ah
var max-tabs/edx: int <- length tabs
compare current-tab-index, max-tabs
{
compare current-tab-index, max-tabs
break-if-<
abort "history overflow; grow max-history (we should probably improve this)"
}
var current-tab-offset/ecx: (offset tab) <- compute-offset tabs, current-tab-index
var current-tab/ecx: (addr tab) <- index tabs, current-tab-offset
clear-object current-tab
var current-tab-type/eax: (addr int) <- get current-tab, type
copy-to *current-tab, 2/search
var current-tab-search-terms-ah/edx: (addr handle gap-buffer) <- get current-tab, search-terms
allocate current-tab-search-terms-ah
var current-tab-search-terms/eax: (addr gap-buffer) <- lookup *current-tab-search-terms-ah
initialize-gap-buffer current-tab-search-terms, 0x30/search-capacity
var search-terms-ah/ebx: (addr handle gap-buffer) <- get env, search-terms
copy-gap-buffer search-terms-ah, current-tab-search-terms-ah
var search-terms/eax: (addr gap-buffer) <- lookup *search-terms-ah
search-items current-tab, items, search-terms
}
fn search-items _tab: (addr tab), _items: (addr item-list), search-terms: (addr gap-buffer) {
var tab/edi: (addr tab) <- copy _tab
var tab-items-first-free-addr/esi: (addr int) <- get tab, search-items-first-free
var tab-items-ah/eax: (addr handle array int) <- get tab, search-items
populate tab-items-ah, 0x100/max-search-results
var _tab-items/eax: (addr array int) <- lookup *tab-items-ah
var tab-items/edi: (addr array int) <- copy _tab-items
# preprocess search-terms
var search-terms-stream-storage: (stream byte 0x100)
var search-terms-stream-addr/ecx: (addr stream byte) <- address search-terms-stream-storage
emit-gap-buffer search-terms, search-terms-stream-addr
var search-terms-text-h: (handle array byte)
var search-terms-text-ah/eax: (addr handle array byte) <- address search-terms-text-h
stream-to-array search-terms-stream-addr, search-terms-text-ah
var tmp/eax: (addr array byte) <- lookup *search-terms-text-ah
var search-terms-text: (addr array byte)
copy-to search-terms-text, tmp
#
var items/ecx: (addr item-list) <- copy _items
var items-data-ah/eax: (addr handle array item) <- get items, data
var _items-data/eax: (addr array item) <- lookup *items-data-ah
var items-data/ebx: (addr array item) <- copy _items-data
var items-data-first-free-a/edx: (addr int) <- get items, data-first-free
var i/ecx: int <- copy 0
{
compare i, *items-data-first-free-a
break-if->=
var curr-offset/eax: (offset item) <- compute-offset items-data, i
var curr-item/eax: (addr item) <- index items-data, curr-offset
var found?/eax: boolean <- search-terms-match? curr-item, search-terms-text
compare found?, 0/false
{
break-if-=
var tab-items-first-free/eax: int <- copy *tab-items-first-free-addr
compare tab-items-first-free, 0x100/max-search-results
break-if->=
var dest/eax: (addr int) <- index tab-items, tab-items-first-free
copy-to *dest, i
increment *tab-items-first-free-addr
}
i <- increment
loop
}
var tab/edi: (addr tab) <- copy _tab
var tab-item-index-addr/edi: (addr int) <- get tab, item-index
var tab-items-first-free/eax: int <- copy *tab-items-first-free-addr
tab-items-first-free <- decrement
copy-to *tab-item-index-addr, tab-items-first-free
}
fn search-terms-match? _item: (addr item), search-terms: (addr array byte) -> _/eax: boolean {
var item/esi: (addr item) <- copy _item
var item-text-ah/eax: (addr handle array byte) <- get item, text
var item-text/eax: (addr array byte) <- lookup *item-text-ah
var i/ecx: int <- copy 0
var max/edx: int <- length item-text
var search-terms2/ebx: (addr array byte) <- copy search-terms
var slen/ebx: int <- length search-terms2
max <- subtract slen
{
compare i, max
break-if->
var found?/eax: boolean <- substring-match? item-text, search-terms, i
compare found?, 0/false
{
break-if-=
return 1/true
}
i <- increment
loop
}
return 0/false
}
fn substring-match? _s: (addr array byte), _pat: (addr array byte), start: int -> _/eax: boolean {
var s/esi: (addr array byte) <- copy _s
var pat/edi: (addr array byte) <- copy _pat
var s-idx/edx: int <- copy start
var pat-idx/ebx: int <- copy 0
var pat-len: int
var tmp/eax: int <- length pat
copy-to pat-len, tmp
{
compare pat-idx, pat-len
break-if->=
var s-ab/eax: (addr byte) <- index s, s-idx
var s-b/eax: byte <- copy-byte *s-ab
var pat-ab/ecx: (addr byte) <- index pat, pat-idx
var pat-b/ecx: byte <- copy-byte *pat-ab
compare s-b, pat-b
{
break-if-=
return 0/false
}
s-idx <- increment
pat-idx <- increment
loop
}
return 1/true
}
fn previous-tab _env: (addr environment) {
var env/edi: (addr environment) <- copy _env
var current-tab-index-addr/ecx: (addr int) <- get env, current-tab-index
compare *current-tab-index-addr, 0
{
break-if-<=
decrement *current-tab-index-addr
# if necessary restore search state
var tabs-ah/eax: (addr handle array tab) <- get env, tabs
var tabs/eax: (addr array tab) <- lookup *tabs-ah
var current-tab-index/ecx: int <- copy *current-tab-index-addr
var current-tab-offset/ecx: (offset tab) <- compute-offset tabs, current-tab-index
var current-tab/ecx: (addr tab) <- index tabs, current-tab-offset
var current-tab-type/eax: (addr int) <- get current-tab, type
compare *current-tab-type, 2/search
break-if-!=
var current-tab-search-terms-ah/ecx: (addr handle gap-buffer) <- get current-tab, search-terms
var search-terms-ah/edx: (addr handle gap-buffer) <- get env, search-terms
var search-terms/eax: (addr gap-buffer) <- lookup *search-terms-ah
clear-gap-buffer search-terms
copy-gap-buffer current-tab-search-terms-ah, search-terms-ah
}
}
fn next-item _env: (addr environment), users: (addr array user), _channels: (addr array channel), _items: (addr item-list) {
var env/edi: (addr environment) <- copy _env
var tabs-ah/eax: (addr handle array tab) <- get env, tabs
var _tabs/eax: (addr array tab) <- lookup *tabs-ah
var tabs/edx: (addr array tab) <- copy _tabs
var current-tab-index-a/eax: (addr int) <- get env, current-tab-index
var current-tab-index/eax: int <- copy *current-tab-index-a
var current-tab-offset/eax: (offset tab) <- compute-offset tabs, current-tab-index
var current-tab/edx: (addr tab) <- index tabs, current-tab-offset
var dest/ebx: (addr int) <- get current-tab, item-index
# if current-tab isn't all-items or channel, no need to worry about hidden items
var current-tab-type/eax: (addr int) <- get current-tab, type
{
compare *current-tab-type, 0/all-items
break-if-=
compare *current-tab-type, 1/channel
break-if-=
{
compare *dest, 0
break-if-<=
decrement *dest
}
return
}
var old-value/ecx: int <- copy *dest
# do { --*dest } while *dest > 0 and should-hide?(current-tab, *dest)
{
compare *dest, 0
break-if-<=
decrement *dest
# if current item is not hidden, return
var current-item-index/esi: int <- item-index env, _items, _channels
var should-hide?/eax: boolean <- should-hide? current-tab, current-item-index, _items
compare should-hide?, 0/false
loop-if-!=
return
}
# couldn't find a visible item. Restore.
copy-to *dest, old-value
}
fn previous-item _env: (addr environment), users: (addr array user), _channels: (addr array channel), _items: (addr item-list) {
var env/edi: (addr environment) <- copy _env
var tabs-ah/eax: (addr handle array tab) <- get env, tabs
var _tabs/eax: (addr array tab) <- lookup *tabs-ah
var tabs/edx: (addr array tab) <- copy _tabs
var current-tab-index-a/eax: (addr int) <- get env, current-tab-index
var current-tab-index/eax: int <- copy *current-tab-index-a
var current-tab-offset/eax: (offset tab) <- compute-offset tabs, current-tab-index
var current-tab/edx: (addr tab) <- index tabs, current-tab-offset
var current-tab-type/eax: (addr int) <- get current-tab, type
compare *current-tab-type, 0/all-items
{
break-if-!=
var items/esi: (addr item-list) <- copy _items
var items-data-first-free-a/ecx: (addr int) <- get items, data-first-free
var final-item-index/ecx: int <- copy *items-data-first-free-a
final-item-index <- decrement
var dest/ebx: (addr int) <- get current-tab, item-index
var old-value/eax: int <- copy *dest
# do { ++*dest } while *dest < final-index and should-hide?(current-tab, *dest)
{
compare *dest, final-item-index
break-if->=
increment *dest
# if current item is not hidden, return
var current-item-index/esi: int <- item-index env, _items, _channels
var should-hide?/eax: boolean <- should-hide? current-tab, current-item-index, _items
compare should-hide?, 0/false
loop-if-!=
return
}
# couldn't find a visible item. Restore.
copy-to *dest, old-value
return
}
compare *current-tab-type, 1/channel
{
break-if-!=
var current-channel-index-addr/eax: (addr int) <- get current-tab, channel-index
var current-channel-index/eax: int <- copy *current-channel-index-addr
var channels/esi: (addr array channel) <- copy _channels
var current-channel-offset/eax: (offset channel) <- compute-offset channels, current-channel-index
var current-channel/eax: (addr channel) <- index channels, current-channel-offset
var current-channel-posts-first-free-addr/eax: (addr int) <- get current-channel, posts-first-free
var final-item-index/ecx: int <- copy *current-channel-posts-first-free-addr
final-item-index <- decrement
var dest/ebx: (addr int) <- get current-tab, item-index
var old-value/eax: int <- copy *dest
# do { ++*dest } while *dest < final-index and should-hide?(current-tab, *dest)
{
compare *dest, final-item-index
break-if->=
increment *dest
# if current item is not hidden, return
var current-item-index/esi: int <- item-index env, _items, _channels
var should-hide?/eax: boolean <- should-hide? current-tab, current-item-index, _items
compare should-hide?, 0/false
loop-if-!=
return
}
# couldn't find a visible item. Restore.
copy-to *dest, old-value
return
}
compare *current-tab-type, 2/search
{
break-if-!=
var current-tab-search-items-first-free-addr/eax: (addr int) <- get current-tab, search-items-first-free
var final-item-index/ecx: int <- copy *current-tab-search-items-first-free-addr
final-item-index <- decrement
var dest/eax: (addr int) <- get current-tab, item-index
compare *dest, final-item-index
break-if->=
increment *dest
return
}
compare *current-tab-type, 3/thread
{
break-if-!=
var items/eax: (addr item-list) <- copy _items
var items-data-ah/eax: (addr handle array item) <- get items, data
var _items-data/eax: (addr array item) <- lookup *items-data-ah
var items-data/esi: (addr array item) <- copy _items-data
var current-tab-root-index-addr/eax: (addr int) <- get current-tab, root-index
var current-tab-root-index/eax: int <- copy *current-tab-root-index-addr
var current-tab-root-offset/eax: (offset item) <- compute-offset items-data, current-tab-root-index
var post/eax: (addr item) <- index items-data, current-tab-root-offset
var post-comments-first-free-addr/ecx: (addr int) <- get post, comments-first-free
var final-item-index/ecx: int <- copy *post-comments-first-free-addr
final-item-index <- decrement
var dest/eax: (addr int) <- get current-tab, item-index
compare *dest, final-item-index
break-if->=
increment *dest
return
}
}
fn page-down _env: (addr environment), users: (addr array user), channels: (addr array channel), _items: (addr item-list) {
var env/edi: (addr environment) <- copy _env
var items/eax: (addr item-list) <- copy _items
var items-data-ah/eax: (addr handle array item) <- get items, data
var _items-data/eax: (addr array item) <- lookup *items-data-ah
var items-data/ebx: (addr array item) <- copy _items-data
var _old-item-index/esi: int <- item-index env, _items, channels
var old-item-index/ecx: int <- copy _old-item-index
var y/edx: int <- copy 2
{
compare y, 0x28/screen-height-minus-menu
break-if->=
var item-index/esi: int <- item-index env, _items, channels
{
compare y, 2
break-if-= # skip this condition on first iteration
compare item-index, old-item-index
break-if-!=
# no forward progress; we're at the bottom of the current tab
return
}
var item-offset/eax: (offset item) <- compute-offset items-data, item-index
var item/eax: (addr item) <- index items-data, item-offset
var item-text-ah/eax: (addr handle array byte) <- get item, text
var item-text/eax: (addr array byte) <- lookup *item-text-ah
var h/eax: int <- estimate-height item-text
y <- add h
next-item env, users, channels, _items
loop
}
# we're past the end of the screen now, so bounce back for some continuity
previous-item env, users, channels, _items
{
# HACK: make sure we make forward progress even if a single post takes up
# the whole screen.
# We can't see the rest of that single post at the moment. But at least we
# can go past it.
var old-item-index/eax: int <- copy old-item-index
var item-index/esi: int <- item-index env, _items, channels
compare item-index, old-item-index
break-if-!=
next-item env, users, channels, _items
}
}
fn page-up _env: (addr environment), users: (addr array user), channels: (addr array channel), _items: (addr item-list) {
var env/edi: (addr environment) <- copy _env
var items/eax: (addr item-list) <- copy _items
var items-data-ah/eax: (addr handle array item) <- get items, data
var _items-data/eax: (addr array item) <- lookup *items-data-ah
var items-data/ebx: (addr array item) <- copy _items-data
var _old-item-index/esi: int <- item-index env, _items, channels
var old-item-index/ecx: int <- copy _old-item-index
var y/edx: int <- copy 2
{
compare y, 0x28/screen-height-minus-menu
break-if->=
var item-index/esi: int <- item-index env, _items, channels
{
compare y, 2
break-if-= # skip this condition on first iteration
compare item-index, old-item-index
break-if-!=
# no forward progress; we're at the bottom of the current tab
return
}
var item-offset/eax: (offset item) <- compute-offset items-data, item-index
var item/eax: (addr item) <- index items-data, item-offset
var item-text-ah/eax: (addr handle array byte) <- get item, text
var item-text/eax: (addr array byte) <- lookup *item-text-ah
var h/eax: int <- estimate-height item-text
y <- add h
previous-item env, users, channels, _items
loop
}
}
# keep sync'd with render-item
fn estimate-height _message-text: (addr array byte) -> _/eax: int {
var message-text/esi: (addr array byte) <- copy _message-text
var result/eax: int <- length message-text
var remainder/edx: int <- copy 0
result, remainder <- integer-divide result, 0x40/post-width
compare remainder, 0
{
break-if-=
result <- increment
}
result <- add 2/item-padding-ver
compare result, 6/avatar-space-ver
{
break-if->
return 6/avatar-space-ver
}
return result
}
|