-
Notifications
You must be signed in to change notification settings - Fork 1
/
zmim_cm1.bas
1278 lines (1208 loc) · 20.7 KB
/
zmim_cm1.bas
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
' Autogenerated on 11-07-2020 21:20:15
If Mm.Device$<>"Colour Maximite"Then
Option Explicit On
Option Default Integer
EndIf
Mode 1
Dim fsz
Dim bst
Dim fsp
Dim m(88*512\4)
Dim pf
Dim mf$
Dim mpv(88-1)
Dim mvp(256-1)
Dim mnx
Function rp()
Local pp,vp
vp=pc\512
pp=mvp(vp)
If pp=0 Then pp=mem_load(vp):pf=pf+1
rp=Peek(Var m(0),pp*512+(pc Mod 512))
pc=pc+1
End Function
Function rb(a)
Local pp,vp
If a<bst Then rb=Peek(Var m(0),a):Exit Function
vp=a\512
pp=mvp(vp)
If pp=0 Then pp=mem_load(vp):pf=pf+1
rb=Peek(Var m(0),pp*512+(a Mod 512))
End Function
Function rw(a)
rw=rb(a)*256+rb(a+1)
End Function
Sub wb(a,x)
Poke Var m(0),a,x
End Sub
Sub ww(a,x)
Poke Var m(0),a,x\256
Poke Var m(0),a+1,x Mod 256
End Sub
Function mem_load(vp)
Local ad,buf$,buf_sz,i,pp,to_read
pp=mnx
mnx=mnx+1
If mnx=88 Then mnx=fsp
Open mf$ For random As #1
Seek #1,vp*512+1
ad=pp*512
to_read=512
buf_sz=255
Do While to_read>0
If to_read<255 Then buf_sz=to_read
buf$=Input$(buf_sz,1)
For i=1 To buf_sz
Poke Var m(0),ad,Peek(Var buf$,i)
ad=ad+1
Next i
to_read=to_read-buf_sz
Loop
Close #1
mvp(mpv(pp))=0
mvp(vp)=pp
mpv(pp)=vp
mem_load=pp
End Function
Sub mem_init(f$)
Local i
mf$=f$
cou("Loading '"+mf$+"'"):cen()
cou(" Header page: 0"):cen()
mnx=0
If mem_load(0)<>0 Then Error
bst=Peek(Var m(0),&h0E)*256+Peek(Var m(0),&h0F)
fsz=(Peek(Var m(0),&h1A)*256+Peek(Var m(0),&h1B))*2
fsp=bst\512
If bst Mod 512>0 Then fsp=fsp+1
cou(" Dynamic pages: ")
For i=1 To fsp-1
If i>1 Then cou(", ")
cou(Str$(i))
If mem_load(i)<>i Then Error
Next i
cen()
cou(" Paged memory starts at page "+Str$(fsp)):cen()
End Sub
Dim stk(511)
Dim sp
Function spo()
sp=sp-1
spo=stk(sp)
End Function
Sub spu(x)
stk(sp)=x
sp=sp+1
End Sub
Function spe(i)
If i>=sp Then Error"Attempt to peek beyond stack pointer"
spe=stk(i)
End Function
Sub spk(i,x)
If i>=sp Then Error"Attempt to poke beyond stack pointer"
If x<0 Or x>&hFFFF Then Error"Invalid unsigned 16-bit value"
stk(i)=x
End Sub
Dim gva
Function vge(i)
If i=0 Then
vge=spo()
ElseIf i<&h10 Then
vge=stk(fp+i+4)
ElseIf i<=&hFF Then
vge=rw(gva+2*(i-&h10))
Else
Error"Unknown variable "+Str$(i)
EndIf
End Function
Sub vse(i,x)
If i=0 Then
spu(x)
ElseIf i<&h10 Then
stk(fp+i+4)=x
ElseIf i<=&hFF Then
ww(gva+2*(i-&h10),x)
Else
Error"Unknown variable "+Str$(i)
EndIf
End Sub
Dim pc
Dim oc=0
Dim osz=0
Dim oa(4)
Dim ot(4)
Dim ov(4)
Dim st=0
Dim br=0
Sub de_init()
Local i,s$,x
Read x
Dim o0$(x-1)LENGTH 12
For i=0 To x-1:Read s$:o0$(i)=de_format$(s$):Next i
Read x
Dim o1$(x-1)LENGTH 14
For i=0 To x-1:Read s$:o1$(i)=de_format$(s$):Next i
Read x
Dim o2$(x-1)LENGTH 15
For i=0 To x-1:Read s$:o2$(i)=de_format$(s$):Next i
Read x
Dim o3$(x-1)LENGTH 14
For i=0 To x-1:Read s$:o3$(i)=de_format$(s$):Next i
End Sub
Function dec(tr)
Local op,s$
If tr Then cou(Hex$(pc)+": ")
op=rp()
If op<&h80 Then
dlo(op)
s$=o2$(oc)
ElseIf op<&hC0 Then
dsh(op)
If op<&hB0 Then s$=o1$(oc)Else s$=o0$(oc)
Else
dva(op)
If op<&hE0 Then s$=o2$(oc)Else s$=o3$(oc)
EndIf
If Left$(s$,1)="B"Then
st=-1
br=dbr()
ElseIf Left$(s$,1)="S"Then
st=rp()
br=0
ElseIf Left$(s$,1)="X"Then
st=rp()
br=dbr()
Else
st=-1
br=0
EndIf
If tr Then dmp_op(Mid$(s$,2))
dec=op
End Function
Sub dlo(op)
oc=op And &b11111
osz=2
ov(0)=rp()
ov(1)=rp()
If op<=&h1F Then
ot(0)=&b01:oa(0)=ov(0)
ot(1)=&b01:oa(1)=ov(1)
ElseIf op<=&h3F Then
ot(0)=&b01:oa(0)=ov(0)
ot(1)=&b10:oa(1)=vge(ov(1))
ElseIf op<=&h5F Then
ot(0)=&b10:oa(0)=vge(ov(0))
ot(1)=&b01:oa(1)=ov(1)
Else
ot(0)=&b10:oa(0)=vge(ov(0))
ot(1)=&b10:oa(1)=vge(ov(1))
EndIf
End Sub
Sub dsh(op)
oc=op And &b1111
osz=1
If op<=&h8F Then
ot(0)=&b00:ov(0)=rp()*256+rp():oa(0)=ov(0)
ElseIf op<=&h9F Then
ot(0)=&b01:ov(0)=rp():oa(0)=ov(0)
ElseIf op<=&hAF Then
ot(0)=&b10:ov(0)=rp():oa(0)=vge(ov(0))
Else
osz=0
EndIf
End Sub
Sub dva(op)
Local i,x
oc=op And &b11111
osz=4
x=rp()
For i=0 To 3
ot(i)=(x And &b11000000)\64
If ot(i)=&b00 Then
ov(i)=rp()*256+rp():oa(i)=ov(i)
ElseIf ot(i)=&b01 Then
ov(i)=rp():oa(i)=ov(i)
ElseIf ot(i)=&b10 Then
ov(i)=rp():oa(i)=vge(ov(i))
Else
osz=osz-1
EndIf
x=x*4
Next i
End Sub
Function dbr()
Local a,of,x
a=rp()
of=a And &b111111
If(a And &b1000000)=0 Then
of=256*of+rp()
If a And &b100000 Then of=of-16384
EndIf
x=pc+of-2
If a And &h80 Then x=x Or &h80000
dbr=x
End Function
Function de_format$(a$)
Local p,s$
If Instr(a$," SB")>0 Then
s$="X"
ElseIf Instr(a$," B")>0 Then
s$="B"
ElseIf Instr(a$," S")>0 Then
s$="S"
Else
s$=" "
EndIf
p=Instr(a$," ")
If p=0 Then p=Len(a$)+1
s$=s$+Left$(a$,p-1)
de_format$=s$
End Function
Data 14
Data"RTRUE","RFALSE","PRINT","PRINT_RET","NOP"
Data"SAVE B","RESTORE B","RESTART","RET_POPPED","POP"
Data"QUIT","NEW_LINE","SHOW_STATUS","VERIFY B"
Data 16
Data"JZ B","GET_SIBLING SB","GET_CHILD SB","GET_PARENT S","GET_PROP_LEN S"
Data"INC","DEC","PRINT_ADDR","Unknown&h8","REMOVE_OBJ"
Data"PRINT_OBJECT","RET","JUMP","PRINT_PADDR","LOAD S"
Data"NOT S"
Data 25
Data"Unknown&h0","JE B","JL B","JG B","DEC_CHK B"
Data"INC_CHK B","JIN B","TEST B","OR S","AND S"
Data"TEST_ATTR B","SET_ATTR","CLEAR_ATTR","STORE","INSERT_OBJ"
Data"LOADW S","LOADB S","GET_PROP S","GET_PROP_ADDR S","GEN_NEXT_PROP S"
Data"ADD S","SUB S","MUL S","DIV S","MOD S"
Data 22
Data"CALL S","STOREW","STOREB","PUT_PROP","READ"
Data"PRINT_CHAR","PRINT_NUM","RANDOM S","PUSH","PULL"
Data"SPLIT_WINDOW","SET_WINDOW","Unknown&hC","Unknown&hD","Unknown&hE"
Data"Unknown&hF","Unknown&h10","Unknown&h11","Unknown&h12","OUTPUT_STREAM"
Data"INPUT_STREAM","SOUND_EFFECT"
Dim fp
Dim num_bp
Dim nop
Dim ztrace
Function exe(tr)
Local op,pc_old,sp_old
pc_old=pc:sp_old=sp
op=dec(tr)
nop=nop+1
If op<&h80 Then
exe=e2o()
ElseIf op<&hB0 Then
exe=e1o()
ElseIf op<&hC0 Then
exe=e0o()
ElseIf op<&hE0 Then
exe=e2o()
Else
exe=evo()
EndIf
If exe=1 Then
cou("Unsupported instruction "+hx$(op,2)):cen()
ElseIf exe=2 Then
cou("Unimplemented instruction "+hx$(op,2)):cen()
EndIf
If exe<>0 Then pc=pc_old:sp=sp_old
End Function
Function e2o()
Local a,b,x,y,_
a=oa(0)
b=oa(1)
If oc=&h1 Then
x=(a=b)
If(Not x)And(osz>2)Then x=(a=oa(2))
If(Not x)And(osz>3)Then x=(a=oa(3))
ebr(x,br)
ElseIf oc=&h2 Then
If a>32767 Then a=a-65536
If b>32767 Then b=b-65536
ebr(a<b,br)
ElseIf oc=&h3 Then
If a>32767 Then a=a-65536
If b>32767 Then b=b-65536
ebr(a>b,br)
ElseIf oc=&h4 Then
x=vge(a)
If x>32767 Then x=x-65536
If b>32767 Then b=b-65536
x=x-1
y=x<b
If x<0 Then x=65536+x
vse(a,x)
ebr(y,br)
ElseIf oc=&h5 Then
x=vge(a)
If x>32767 Then x=x-65536
If b>32767 Then b=b-65536
x=x+1
y=x>b
If x<0 Then x=65536+x
vse(a,x)
ebr(y,br)
ElseIf oc=&h6 Then
x=ob_rel(a,4)
ebr(x=b,br)
ElseIf oc=&h7 Then
ebr((a And b)=b,br)
ElseIf oc=&h8 Then
vse(st,a Or b)
ElseIf oc=&h9 Then
vse(st,a And b)
ElseIf oc=&hA Then
x=oat(a,b)
ebr(x=1,br)
ElseIf oc=&hB Then
_=oat(a,b,1,1)
ElseIf oc=&hC Then
_=oat(a,b,1,0)
ElseIf oc=&hD Then
If a=0 Then spk(sp-1,b)Else vse(a,b)
ElseIf oc=&hE Then
oin(a,b)
ElseIf oc=&hF Then
x=rw(a+2*b)
vse(st,x)
ElseIf oc=&h10 Then
x=rb(a+b)
vse(st,x)
ElseIf oc=&h11 Then
x=opg(a,b)
vse(st,x)
ElseIf oc=&h12 Then
x=opa(a,b)
vse(st,x)
ElseIf oc=&h13 Then
x=onp(a,b)
vse(st,x)
ElseIf oc<&h19 Then
If a>32767 Then a=a-65536
If b>32767 Then b=b-65536
If oc=&h14 Then
x=a+b
ElseIf oc=&h15 Then
x=a-b
ElseIf oc=&h16 Then
x=a*b
ElseIf oc=&h17 Then
x=a\b
Else
x=a Mod b
EndIf
If x<0 Then x=65536+x
vse(st,x)
Else
e2o=1
EndIf
End Function
Function e1o()
Local a,x
a=oa(0)
If oc=&h0 Then
ebr(a=0,br)
ElseIf oc=&h1 Then
x=ob_rel(a,5)
vse(st,x)
ebr(x<>0,br)
ElseIf oc=&h2 Then
x=ob_rel(a,6)
vse(st,x)
ebr(x<>0,br)
ElseIf oc=&h3 Then
x=ob_rel(a,4)
vse(st,x)
ElseIf oc=&h4 Then
x=opl(a)
vse(st,x)
ElseIf oc=&h5 Then
x=vge(a)
If x>32767 Then x=x-65536
x=x+1
If x<0 Then x=65536+x
vse(a,x)
ElseIf oc=&h6 Then
x=vge(a)
If x>32767 Then x=x-65536
x=x-1
If x<0 Then x=65536+x
vse(a,x)
ElseIf oc=&h7 Then
pzs(a)
ElseIf oc=&h9 Then
ore(a)
ElseIf oc=&hA Then
opr(a)
ElseIf oc=&hB Then
ert(a)
ElseIf oc=&hC Then
If a And &h8000 Then a=a-65536
pc=pc+a-2
ElseIf oc=&hD Then
pzs(a*2)
ElseIf oc=&hE Then
If a=0 Then x=spe(sp-1)Else x=vge(a)
vse(st,x)
ElseIf oc=&hF Then
x=a Xor &b1111111111111111
vse(st,x)
Else
e1o=1
EndIf
End Function
Function e0o()
Local x
If oc=&h0 Then
ert(1)
ElseIf oc=&h1 Then
ert(0)
ElseIf oc=&h2 Then
pzs(pc)
ElseIf oc=&h3 Then
pzs(pc)
cen()
ert(1)
ElseIf oc=&h4 Then
ElseIf oc=&h5 Then
If csc AND &b10 Then
cou("IGNORED 'save' command read from script"):cen()
Else
x=zsv()
ebr(x,br)
EndIf
ElseIf oc=&h6 Then
If csc AND &b10 Then
cou("IGNORED 'restore' command read from script"):cen()
Else
x=zsv(1)
EndIf
ElseIf oc=&h7 Then
If csc AND &b10 Then
cou("IGNORED 'restart' command read from script"):cen()
Else
main_init()
For x=0 To 10:cen():Next x
EndIf
ElseIf oc=&h8 Then
x=spo()
ert(x)
ElseIf oc=&h9 Then
sp=sp-1
ElseIf oc=&hA Then
e0o=4
ElseIf oc=&hB Then
cen()
ElseIf oc=&hC Then
ess()
ElseIf oc=&hD Then
ebr(1,br)
Else
e0o=1
EndIf
End Function
Function evo()
Local x,_
If oc=&h0 Then
ecl(st)
ElseIf oc=&h1 Then
ww(oa(0)+2*oa(1),oa(2))
ElseIf oc=&h2 Then
wb(oa(0)+oa(1),oa(2))
ElseIf oc=&h3 Then
ob_prop_set(oa(0),oa(1),oa(2))
ElseIf oc=&h4 Then
evo=erd(oa(0),oa(1))
ElseIf oc=&h5 Then
cou(Chr$(oa(0)))
ElseIf oc=&h6 Then
x=oa(0)
If x>32767 Then x=x-65536
cou(Str$(x))
ElseIf oc=&h7 Then
x=oa(0)
If x>32767 Then x=x-65536
x=era(x)
vse(st,x)
ElseIf oc=&h8 Then
spu(oa(0))
ElseIf oc=&h9 Then
x=spo()
If oa(0)=0 Then spk(sp-1,x)Else vse(oa(0),x)
ElseIf oc=&h13 Then
evo=2
ElseIf oc=&h14 Then
evo=2
ElseIf oc=&h15 Then
Else
evo=1
EndIf
End Function
Sub ebr(z,br)
Local x
If Not(z=(br And &h80000)>0)Then Exit Sub
x=br And &h7FFFF
If x=pc-1 Then ert(1):Exit Sub
If x=pc-2 Then ert(0):Exit Sub
pc=x
End Sub
Sub ert(x)
Local st,_
sp=fp+4
pc=spo()*&h10000+spo()
st=spo()
fp=spo()
vse(st,x)
If ztrace Then dmp_stack()
End Sub
Sub ecl(st)
Local i,nl,x
If oa(0)=0 Then vse(st,0):Exit Sub
spu(fp)
fp=sp-1
spu(st)
spu(pc Mod &h10000)
spu(pc\&h10000)
pc=2*oa(0)
nl=rp()
spu(nl)
For i=1 To nl
x=rp()*256+rp()
If i<osz Then spu(oa(i))Else spu(x)
Next i
If ztrace Then dmp_routine(2*oa(0)):dmp_stack()
End Sub
Function erd(text_buf,parse_buf)
Local ad,c,i,n,word$,s$,t,wc
t=Timer
s$=LCase$(ci$("> ",1))
If Left$(s$,1)="*"Then erd=esp(s$)
Timer=t
If erd<>0 Then Exit Function
n=Len(s$)
For i=1 To n:wb(text_buf+i,Peek(Var s$,i)):Next i
wb(text_buf+n+1,0)
s$=s$+" "
For i=1 To n+1
c=Peek(Var s$,i)
If c=&h20 Or Instr(ds$(0),Chr$(c))>0 Then
If Len(word$)>0 Then
ad=dlk(word$)
ww(parse_buf+2+wc*4,ad)
wb(parse_buf+4+wc*4,Len(word$))
wb(parse_buf+5+wc*4,i-Len(word$))
wc=wc+1
word$=""
EndIf
If c<>&h20 Then
ad=dlk(Chr$(c))
ww(parse_buf+2+wc*4,ad)
wb(parse_buf+4+wc*4,1)
wb(parse_buf+5+wc*4,i-1)
wc=wc+1
EndIf
Else
word$=word$+Chr$(c)
EndIf
Next i
wb(parse_buf+1,wc)
End Function
Function esp(cmd$)
Local f$,_
esp=6
If cmd$="*break"Then
esp=0
ElseIf cmd$="*credits"Then
cecho(ss$(1)+"\cred_cm1.txt")
ElseIf cmd$="*replay"Then
If csc AND &b10 Then
cou("IGNORED '*replay' command read from script")
Else
cou("Select a script file from '")
cou(ss$(3)+"\"+ss$(5)+"':")
cen()
f$=fi_choose$(ss$(3)+"\"+ss$(5),"*.scr")
If f$<>""Then
Open f$ For Input As #3
csc=csc Or &b10
EndIf
EndIf
cen()
ElseIf cmd$="*status"Then
ess()
Else
esp=0
EndIf
If esp=6 Then cou(">")
End Function
Function era(range)
If range=0 Then
Randomize Timer
Exit Function
ElseIf range<0 Then
Randomize Abs(range)
Exit Function
EndIf
era=1+CInt((range-1)*Rnd())
End Function
Sub ess()
Local x
x=vge(&h10):opr(x):cou(", ")
x=vge(&h11):cou("Score: "+Str$(x)+", ")
x=vge(&h12):cou("Moves: "+Str$(x))
cen()
End Sub
Dim csc
Dim cb$
Dim csp
Dim cli
Dim cco
Dim cx=1
Dim csi
Function ci$(p$,r)
Local s$
cou(p$)
cfl()
cli=0
If csc And &b10 Then
Line Input #3,s$
If s$=""Then
csc=csc And &b01
Close #3
Else
cou(s$):cen()
EndIf
EndIf
If Not(csc And &b10)Then Line Input s$:cx=1
If(r=1)And(csc AND &b01)And(s$<>"")Then Print #2,s$
ci$=s$
End Function
Sub cou(s$)
cco=0
If Len(s$)=1 Then
If(s$=" ")Xor csp Then cfl():csp=(s$=" ")
cb$=cb$+s$
Else
Local c$,i
For i=1 To Len(s$)
c$=Mid$(s$,i,1)
If(c$=" ")Xor csp Then cfl():csp=(c$=" ")
cb$=cb$+c$
Next i
EndIf
End Sub
Sub cfl()
If csi Then Print Chr$(8);" ";Chr$(8);:csi=0
Do
If cx=1 And cli>36-2 Then
Print"[MORE] ";
Do While Inkey$<>"":Loop
Do While Inkey$="":Loop
Print
cli=0
EndIf
If cx+Len(cb$)>80 Then
Print
cli=cli+1
cx=1
If csp Then cb$="":Exit Sub
Else
Print cb$;
cx=cx+Len(cb$)
cb$=""
Exit Sub
EndIf
Loop
End Sub
Sub cen()
cfl()
If cco<0 Then
Exit Sub
ElseIf cco>=10 Then
Local i
For i=0 To 36-cco-1:Print:Next i
cco=-999
cli=0
Exit Sub
EndIf
Print
cco=cco+1
cli=cli+1
cx=1
End Sub
Sub cecho(f$)
Local s$
Open f$ For Input As #1
Do
Line Input #1,s$
cou(s$)
cen()
Loop While Not Eof(#1)
Close #1
End Sub
Dim al$(2)LENGTH 32
al$(0)=" 123[]abcdefghijklmnopqrstuvwxyz"
al$(1)=" 123[]ABCDEFGHIJKLMNOPQRSTUVWXYZ"
al$(2)=" 123[]@^0123456789.,!?_#'"+Chr$(34)+"/\-:()"
Sub pzs(a)
Local b,c,i,s,x,zc(2)
For x=0 To 0 Step 0
x=rw(a)
zc(0)=(x And &h7C00)\&h400
zc(1)=(x And &h3E0)\&h20
zc(2)=(x And &h1F)
x=x\&h8000
For i=0 To 2
c=zc(i)
If s<3 Then
If c=0 Then
cou(" ")
ElseIf c<4 Then
s=c+2
ElseIf c<6 Then
s=c-3
Else
If c=6 And s=2 Then
s=6
ElseIf c=7 And s=2 Then
cen()
s=0
Else
cou(Mid$(al$(s),c+1,1))
s=0
EndIf
EndIf
ElseIf s<6 Then
b=a
pab((s-3)*32+c)
a=b
s=0
ElseIf s=6 Then
s=c+7
Else
cou(Chr$((s-7)*32+c))
s=0
EndIf
Next i
a=a+2
Next x
End Sub
Sub pab(x)
Local a,b
a=rw(&h18)
b=rw(a+x*2)
pzs(b*2)
End Sub
Function oat(o,a,s,x)
Local ad,m,y
If o=0 Then Exit Function
ad=rw(&h0A)+62+(o-1)*9+a\8
y=rb(ad)
m=2^(7-a Mod 8)
If s=0 Then oat=(y And m)>0:Exit Function
If x=0 Then y=(y And(m Xor &hFF))Else y=(y Or m)
wb(ad,y)
oat=x
End Function
Function ob_rel(o,r,s,x)
Local ad
ad=rw(&h0A)+62+(o-1)*9+r
If s=0 Then ob_rel=rb(ad):Exit Function
wb(ad,x)
ob_rel=x
End Function
Function onp(o,p)
Local ad,x
If o=0 Then
Exit Function
ElseIf p=0 Then
ad=opb(o)
ad=ad+1+2*rb(ad)
Else
ad=opa(o,p)
If ad=0 Then Error"Property does not exist"
x=rb(ad-1)
ad=ad+1+x\32
EndIf
x=rb(ad)
onp=x And &b11111
End Function
Function opl(ad)
Local x
If ad=0 Then Exit Function
x=rb(ad-1)
opl=x\32+1
End Function
Function opb(o)
Local ad
ad=rw(&h0A)+62+(o-1)*9+7
opb=rw(ad)
End Function
Function opa(o,p)
Local ad,x
ad=opb(o)
ad=ad+1+2*rb(ad)
Do
x=rb(ad)
If(x And &b11111)=p Then opa=ad+1:Exit Function
If(x And &b11111)<p Then opa=0:Exit Function
ad=ad+2+x\32
Loop
End Function
Function opg(o,p)
Local ad,sz,x
ad=opa(o,p)
If ad>0 Then
x=rb(ad-1)
If(x And &b11111)<>p Then Error
sz=x\32+1
If sz=1 Then opg=rb(ad):Exit Function
If sz=2 Then opg=rw(ad):Exit Function
Error"Property length > 2"
EndIf
ad=rw(&h0A)+2*(p-1)
opg=rw(ad)
End Function
Sub ob_prop_set(o,p,x)
Local a,sz
a=opa(o,p)
If a=0 Then Error"Object "+Str$(o)+" does not have property "+Str$(p)
sz=opl(a)
If sz<0 Or sz>2 Then Error"Object "+Str$(o)+" has length "+Str$(sz)
If sz=1 Then wb(a,x And &hFF)
If sz=2 Then ww(a,x)
End Sub
Sub opr(o)
Local ad
ad=opb(o)+1
pzs(ad)
End Sub
Sub oin(o,d)
Local c,_
ore(o)
c=ob_rel(d,6)
_=ob_rel(d,6,1,o)
_=ob_rel(o,4,1,d)
_=ob_rel(o,5,1,c)
End Sub
Sub ore(o)
Local c,p,s,_
p=ob_rel(o,4)
s=ob_rel(o,5)
c=ob_rel(p,6)
_=ob_rel(o,4,1,0)
_=ob_rel(o,5,1,0)
If o=c Then
_=ob_rel(p,6,1,s)
Else
Do
If ob_rel(c,5)=o Then _=ob_rel(c,5,1,s):Exit Do
c=ob_rel(c,5)
Loop Until c=0
EndIf
End Sub
Function lp$(s$,i,c$)
Local a
a=Len(s$)
If c$=""Then c$=" "
If a<i Then lp$=String$(i-a,c$)+s$ Else lp$=s$
End Function
Function rd$(s$,i,c$)
Local a
a=Len(s$)
If c$=""Then c$=" "
If a<i Then rd$=s$+String$(i-a,c$)Else rd$=s$
End Function
Function hx$(x,i)
If i<1 Then i=4
hx$="&h"+lp$(Hex$(x),i,"0")
End Function
Dim dad
Dim ds$(1)Length 5
Dim del
Dim dsz
Dim dea
Sub di_init()
Local i,ns
dad=rw(&h08)
ns=rb(dad)
Poke Var ds$(0),0,ns
For i=1 To ns:Poke Var ds$(0),i,rb(dad+i):Next i
del=rb(dad+ns+1)
dsz=rw(dad+ns+2)
dea=dad+ns+4
End Sub
Function dlk(w$)
Local c,i,j,nz,sz,z(9)
sz=Len(w$):If sz>6 Then sz=6
i=1