-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutility.cpp
3429 lines (2904 loc) · 99.8 KB
/
utility.cpp
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
// Zork I: The Great Underground Empire
// (c) 1980 by INFOCOM, Inc.
// C port and parser (c) 2021 by Donnie Russell II
// This source code is provided for personal, educational use only.
// You are welcome to use this source code to develop your own works,
// but the story-related content belongs to the original authors of Zork.
#ifdef COMPILE_WINDOWS
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <conio.h> // getch
int ConsoleW, ConsoleH, CursorColumn, CursorRow;
HANDLE hStdOutput;
#elif COMPILE_DOS
#include <conio.h> // getch
#include <dos.h> // REGS int386 (open watcom)
int ConsoleW, ConsoleH, CursorColumn, CursorRow;
#elif __AVR_ATmega2560__
#include <Arduino.h>
#include <EEPROM.h>
int ConsoleW = 40, ConsoleH = 24, CursorColumn = 0, CursorRow = 0;
uint8_t ConsoleData[40*24];
#else
#define NO_CONIO
int ConsoleW = 80, ConsoleH = 25, CursorColumn = 0, CursorRow = 0;
#endif
#include "def.h"
#include "_enum.h"
int TextColor = 7 | (1<<4); // gray on blue
int StatusLineColor = 1 | (7<<4); // blue on gray
int NumPrintedLines = 0;
uint8_t AutoPlayMode = 0;
const char *AutoPlayP;
extern struct GAMEFLAGS GameFlags;
extern struct GAMEVARS GameVars;
extern struct ROOM_STRUCT Room[NUM_ROOMS];
extern struct OBJ_STRUCT Obj[NUM_OBJECTS];
void DeactivateAutoPlay(void);
//#############################################################################
#ifdef COMPILE_DOS
int SetupDOSConsoleRoutine(int c)
{
int i, row = 0, prev_row, col = 0, prev_col;
{
union REGS regs;
regs.h.ah = 0x02; // set cursor position
regs.h.bh = 0; // page number
regs.h.dh = row; // row
regs.h.dl = col; // column
int386(0x10, ®s, ®s);
}
for (i=0; i<1024; i++)
{
prev_row = row;
prev_col = col;
fputc(c, stdout);
fflush(stdout);
{
union REGS regs;
regs.h.ah = 0x03; // get cursor position and shape
regs.h.bh = 0; // page number
int386(0x10, ®s, ®s);
// ignore ax,ch,cl
row = regs.h.dh; // row
col = regs.h.dl; // column
}
if (c == ' ' && prev_col > col) return prev_col+1;
if (c == '\n' && prev_row == row) return prev_row+1;
}
return 0; // something's weird
}
#endif
void SetupConsole(void)
{
#ifdef COMPILE_WINDOWS
hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
if (hStdOutput == INVALID_HANDLE_VALUE) exit(1);
{
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(hStdOutput, &csbi);
ConsoleW = csbi.srWindow.Right - csbi.srWindow.Left + 1;
ConsoleH = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
CursorColumn = csbi.dwCursorPosition.X;
CursorRow = csbi.dwCursorPosition.Y;
}
{
WORD atr = TextColor;
SetConsoleTextAttribute(hStdOutput, atr);
}
#ifdef USE_CHAR_CURSOR
{
CONSOLE_CURSOR_INFO cci;
cci.dwSize = 25;
cci.bVisible = 0;
SetConsoleCursorInfo(hStdOutput, &cci);
}
#endif
#elif COMPILE_DOS
ConsoleW = SetupDOSConsoleRoutine( ' '); if (ConsoleW == 0) ConsoleW = 80;
ConsoleH = SetupDOSConsoleRoutine('\n'); if (ConsoleH == 0) ConsoleH = 25;
{
union REGS regs;
regs.h.ah = 0x03; // get cursor position and shape
regs.h.bh = 0; // page number
int386(0x10, ®s, ®s);
// ignore ax,ch,cl
CursorRow = regs.h.dh; // row
CursorColumn = regs.h.dl; // column
}
#ifdef USE_CHAR_CURSOR
{
union REGS regs;
regs.h.ah = 0x01; // set text-mode cursor shape
regs.h.ch = 0x07; // scan row start (> end hides cursor)
regs.h.cl = 0x00; // scan row end
int386(0x10, ®s, ®s);
}
#endif
#endif
}
#ifndef __AVR_ATmega2560__
int main(void)
{
SetupConsole();
SetRandomSeed(0);
GameLoop();
return 0;
}
#endif
//#############################################################################
//*****************************************************************************
// low level output functions
#ifdef __AVR_ATmega2560__
void ShiftScreenUp(void)
{
#ifdef NO_STATUS_LINE
uint16_t i = 0;
#else
uint16_t i = ConsoleW; // skip top line of console
#endif
for ( ; i<ConsoleW*(ConsoleH-1); i++)
ConsoleData[i] = ConsoleData[i+ConsoleW];
for (; i<ConsoleW*ConsoleH; i++)
ConsoleData[i] = 0;
}
void PutNewLine(void)
{
CursorColumn = 0;
if (CursorRow == ConsoleH-1)
ShiftScreenUp();
else
CursorRow++;
}
void PutChar(uint8_t c)
{
switch (c)
{
case '\n':
PutNewLine();
break;
case '\b':
if (CursorColumn > 0)
CursorColumn--;
break;
default:
ConsoleData[ConsoleW*CursorRow+CursorColumn] = c;
if (CursorColumn == ConsoleW-1)
PutNewLine();
else
CursorColumn++;
break;
}
}
#elif COMPILE_DOS
void ShiftScreenUp(void)
{
union REGS regs;
regs.h.ah = 0x06; // scroll up window
regs.h.al = 1; // lines to scroll
regs.h.bh = TextColor; // background and foreground color
regs.h.cl = 0; // left column
regs.h.dl = ConsoleW-1; // right column
#ifdef NO_STATUS_LINE
regs.h.ch = 0; // top row
#else
regs.h.ch = 1; // top row; skip top line of console
#endif
regs.h.dh = ConsoleH-1; // bottom row
int386(0x10, ®s, ®s);
}
void PutNewLine(void)
{
CursorColumn = 0;
if (CursorRow == ConsoleH-1)
ShiftScreenUp();
else
CursorRow++;
}
void PutChar(uint8_t c)
{
switch (c)
{
case '\n':
PutNewLine();
break;
case '\b':
if (CursorColumn > 0)
CursorColumn--;
break;
default:
{
union REGS regs;
regs.h.ah = 0x02; // set cursor position
regs.h.bh = 0; // page number
regs.h.dh = CursorRow; // row
regs.h.dl = CursorColumn; // column
int386(0x10, ®s, ®s);
}
{
union REGS regs;
regs.h.ah = 0x09; // write character and attribute at cursor position
regs.h.al = c; // character
regs.h.bh = 0; // page number
regs.h.bl = TextColor; // background and foreground color
regs.w.cx = 1; // number of times to print character
int386(0x10, ®s, ®s);
}
if (CursorColumn == ConsoleW-1)
PutNewLine();
else
CursorColumn++;
break;
}
{
union REGS regs;
regs.h.ah = 0x02; // set cursor position
regs.h.bh = 0; // page number
regs.h.dh = CursorRow; // row
regs.h.dl = CursorColumn; // column
int386(0x10, ®s, ®s);
}
}
#elif COMPILE_WINDOWS
void ShiftScreenUp(void)
{
SMALL_RECT sr;
COORD d;
CHAR_INFO ci;
sr.Left = 0;
sr.Right = ConsoleW-1;
#ifdef NO_STATUS_LINE
sr.Top = 1;
#else
sr.Top = 2;
#endif
sr.Bottom = ConsoleH-1;
d.X = 0,
d.Y = sr.Top-1;
ci.Char.AsciiChar = ' ';
ci.Attributes = TextColor;
ScrollConsoleScreenBuffer(hStdOutput, &sr, 0, d, &ci);
}
void PutNewLine(void)
{
CursorColumn = 0;
if (CursorRow == ConsoleH-1)
ShiftScreenUp();
else
CursorRow++;
}
void PutChar(uint8_t c)
{
switch (c)
{
case '\n':
PutNewLine();
break;
case '\b':
if (CursorColumn > 0)
CursorColumn--;
break;
default:
{
char chr[2] = {(char)c, 0};
WORD atr[2] = {(WORD)TextColor, 0};
COORD cp;
DWORD num;
cp.X = CursorColumn;
cp.Y = CursorRow;
WriteConsoleOutputCharacter(hStdOutput, chr, 1, cp, &num);
WriteConsoleOutputAttribute(hStdOutput, atr, 1, cp, &num);
}
if (CursorColumn == ConsoleW-1)
PutNewLine();
else
CursorColumn++;
break;
}
{
COORD cp;
cp.X = CursorColumn;
cp.Y = CursorRow;
SetConsoleCursorPosition(hStdOutput, cp);
}
}
#else
void PutChar(uint8_t c)
{
fputc(c, stdout);
fflush(stdout);
switch (c)
{
case '\n':
CursorColumn = 0;
break;
case '\b':
if (CursorColumn > 0)
CursorColumn--;
break;
default:
if (CursorColumn == ConsoleW-1)
CursorColumn = 0;
else
CursorColumn++;
break;
}
}
#endif
//*****************************************************************************
//*****************************************************************************
// low level input functions
void MyDelay(int ms)
{
int key_pressed = 0;
#if defined(COMPILE_DOS) || defined(COMPILE_WINDOWS)
clock_t start;
static int factor = 9;
ms = ms * (1+factor) / 10;
start = clock();
while (clock() - start < ms)
{
if (kbhit())
{
int c = getch();
if (c == 0) getch();
else if (c >= '0' && c <= '9') factor = c - '0';
else key_pressed = 1;
break;
}
#ifdef COMPILE_DOS
delay(1);
}
#elif COMPILE_WINDOWS
Sleep(1);
}
#endif
#endif
if (key_pressed && AutoPlayMode)
{
// fast forward to end of autoplay string
for (;;)
{
if (pgm_read_byte(AutoPlayP) == 0) break;
else AutoPlayP++;
}
}
}
#ifdef NO_CONIO
char *GetString(void)
{
static char buffer[80];
if (AutoPlayMode)
MyDelay(1000*NumPrintedLines);
if (AutoPlayMode && pgm_read_byte(AutoPlayP) == 0)
DeactivateAutoPlay();
NumPrintedLines = 0;
memset(buffer, 0, 80);
if (AutoPlayMode)
{
char *p = buffer;
int c;
for (;;)
{
MyDelay(200);
c = pgm_read_byte(AutoPlayP++);
if (p < buffer+80-1)
{
*p++ = c;
if (c) PutChar(c);
}
if (c == 0)
{
DeactivateAutoPlay();
break;
}
else if (c == '\n')
break;
}
}
else
fgets(buffer, 80, stdin);
return buffer;
}
// actually wait for enter
void WaitForKey(void)
{
if (AutoPlayMode == 0)
while (fgetc(stdin) != '\n') {}
}
#else
#ifdef __AVR_ATmega2560__
#define SAVER_FRAMES (5*60*30) // 5 minutes ~30 frames per second (NTSC)
#define INVERT_FRAMES (1*60*30) // 1 minute
extern uint32_t VideoFrame;
uint8_t IR_ReadKey(void);
void PlayTone(uint8_t freq, uint8_t cycles);
void InvertScreen(void)
{
uint16_t i;
for (i=0; i<ConsoleW*ConsoleH; i++)
ConsoleData[i] ^= 128;
}
#else
void PlayTone(uint8_t /* freq */ , uint8_t /* cycles */ )
{
}
#endif
int GetKey(uint8_t more)
{
int c;
#ifdef __AVR_ATmega2560__
uint8_t inverted = 0, saver = 0;
uint32_t start, elapsed;
#endif
if (AutoPlayMode)
{
if (more) return '\n';
MyDelay(200);
c = pgm_read_byte(AutoPlayP++);
if (c == 0)
DeactivateAutoPlay();
return c;
}
#ifdef __AVR_ATmega2560__
start = VideoFrame;
for (;;)
{
c = IR_ReadKey();
if (c) break;
elapsed = VideoFrame;
if (elapsed-start >= (saver ? INVERT_FRAMES : SAVER_FRAMES))
{
InvertScreen();
saver = 1;
inverted ^= 1;
start = VideoFrame;
}
}
if (inverted)
InvertScreen();
// translate arrow key codes to conio
if (c == 28) c = -72;
else if (c == 29) c = -80;
else if (c == 30) c = -75;
else if (c == 31) c = -77;
#else
for (;;)
{
// non-standard c
c = getch();
if (c == 0)
c = -getch();
if (c) break;
}
#endif
return c;
}
#define NUM_STRING_BUFFERS 6
char StringBuffer[80*NUM_STRING_BUFFERS];
void CopyStringBuffer(int8_t dir, uint8_t *curbuf, uint8_t *pos)
{
if (*curbuf+dir > 0 && *curbuf+dir < NUM_STRING_BUFFERS && StringBuffer[80*(*curbuf+dir)])
{
uint8_t i;
*curbuf += dir;
#ifdef USE_CHAR_CURSOR
PutChar(' ');
PutChar('\b');
#endif
for (i=0; i<*pos; i++)
{
PutChar(' ');
PutChar('\b');
PutChar('\b');
}
*pos = 0;
for (i=0; i<80; i++)
{
uint8_t c = StringBuffer[80*(*curbuf) + i];
if (CursorColumn >= ConsoleW-2)
c = 0;
StringBuffer[i] = c;
if (c)
{
PutChar(c);
(*pos)++;
}
}
#ifdef USE_CHAR_CURSOR
PutChar('_');
PutChar('\b');
#endif
}
}
char *GetString(void)
{
uint8_t curbuf = 0, pos = 0, i, j;
if (AutoPlayMode)
MyDelay(1000*NumPrintedLines);
NumPrintedLines = 0;
for (j=0; j<80; j++)
StringBuffer[j] = 0;
#ifdef USE_CHAR_CURSOR
PutChar('_');
PutChar('\b');
#endif
for (;;)
{
int c = GetKey(0);
if (c == -72) CopyStringBuffer( 1, &curbuf, &pos); // up
else if (c == -80) CopyStringBuffer(-1, &curbuf, &pos); // down
else if (c == -75) {} // left
else if (c == -77) {} // right
else if (c == '\r' || c == '\n')
{
#ifdef USE_CHAR_CURSOR
PutChar(' ');
#endif
PutChar('\n');
PlayTone(15, 8);
break;
}
else if (c == '\b')
{
if (pos > 0)
{
#ifdef USE_CHAR_CURSOR
PutChar(' ');
PutChar('\b');
PutChar('\b');
PutChar('_');
PutChar('\b');
#else
PutChar('\b');
PutChar(' ');
PutChar('\b');
#endif
StringBuffer[--pos] = 0;
PlayTone(15, 8);
}
else
PlayTone(12, 8);
}
else if (c >= ' ' && c <= '~')
{
if (pos < 80-1 && CursorColumn < ConsoleW-2)
{
PutChar(c);
#ifdef USE_CHAR_CURSOR
PutChar('_');
PutChar('\b');
#endif
StringBuffer[pos++] = c;
StringBuffer[pos] = 0;
PlayTone(15, 8);
}
else
PlayTone(12, 8);
}
}
if (*StringBuffer == 0)
return StringBuffer;
for (i=1; i<NUM_STRING_BUFFERS; i++)
{
for (j=0; j<80; j++)
if (StringBuffer[80*i+j] != StringBuffer[j]) break;
if (j == 80) return StringBuffer;
}
for (i=NUM_STRING_BUFFERS-1; i>0; i--)
for (j=0; j<80; j++)
StringBuffer[80*i+j] = StringBuffer[80*(i-1)+j];
return StringBuffer;
}
void WaitForKey(void)
{
GetKey(1);
PlayTone(15, 8);
}
#endif
//*****************************************************************************
//*****************************************************************************
// compressed text streaming functions
const uint8_t *StreamP;
uint8_t StreamB, StreamC1, StreamC2, StreamC3;
const uint8_t *SavedStreamP;
uint8_t SavedStreamB, SavedStreamC1, SavedStreamC2, SavedStreamC3;
extern const uint8_t HuffmanTree[];
extern const uint8_t TreeStartIndex;
void OpenStream(const uint8_t *p)
{
StreamP = p;
StreamB = 0;
StreamC1 = 0;
StreamC2 = 0;
StreamC3 = 0;
}
void SaveStream(void)
{
SavedStreamP = StreamP;
SavedStreamB = StreamB;
SavedStreamC1 = StreamC1;
SavedStreamC2 = StreamC2;
SavedStreamC3 = StreamC3;
}
void RestoreStream(void)
{
StreamP = SavedStreamP;
StreamB = SavedStreamB;
StreamC1 = SavedStreamC1;
StreamC2 = SavedStreamC2;
StreamC3 = SavedStreamC3;
}
uint8_t GetStream(void)
{
uint8_t node, byte, c;
if (StreamC1) {c = StreamC1; StreamC1 = 0; return c;}
if (StreamC2) {c = StreamC2; StreamC2 = 0; return c;}
if (StreamC3) {c = StreamC3; StreamC3 = 0; return c;}
node = TreeStartIndex;
byte = pgm_read_byte(StreamP);
for (;;)
{
if (byte & (1<<StreamB)) node = pgm_read_byte(HuffmanTree + 3*node+2);
else node = pgm_read_byte(HuffmanTree + 3*node+1);
if (StreamB == 7) {byte = pgm_read_byte(++StreamP); StreamB = 0;} else StreamB++;
c = pgm_read_byte(HuffmanTree + 3*node);
switch (c)
{
case 0: break;
case 1: return 0;
case 2: c = 't'; StreamC1 = 'h'; StreamC2 = 'e'; StreamC3 = ' '; return c;
case 3: c = 'T'; StreamC1 = 'h'; StreamC2 = 'e'; StreamC3 = ' '; return c;
case 4: c = 'i'; StreamC1 = 'n'; StreamC2 = 'g'; StreamC3 = ' '; return c;
case 5: c = 'y'; StreamC1 = 'o'; StreamC2 = 'u'; StreamC3 = ' '; return c;
case 6: c = 'Y'; StreamC1 = 'o'; StreamC2 = 'u'; StreamC3 = ' '; return c;
case 7: c = 'a'; StreamC1 = 'n'; StreamC2 = 'd'; StreamC3 = ' '; return c;
case 8: c = ' '; StreamC1 = 'i'; StreamC2 = 's'; StreamC3 = ' '; return c;
case 9: c = ' '; StreamC1 = 't'; StreamC2 = 'o'; StreamC3 = ' '; return c;
case 11: c = ' '; StreamC1 = 'o'; StreamC2 = 'f'; StreamC3 = ' '; return c;
case 12: c = 'h'; StreamC1 = 'e'; StreamC2 = 'r'; StreamC3 = 'e'; return c;
case 13: c = 'y'; StreamC1 = 'o'; StreamC2 = 'u'; StreamC3 = 'r'; return c;
case 14: c = 'w'; StreamC1 = 'i'; StreamC2 = 't'; StreamC3 = 'h'; return c;
default: return c;
}
}
}
void AdvanceStream(int16_t i)
{
uint8_t node = TreeStartIndex, byte = pgm_read_byte(StreamP), c;
while (i)
{
if (byte & (1<<StreamB)) node = pgm_read_byte(HuffmanTree + 3*node+2);
else node = pgm_read_byte(HuffmanTree + 3*node+1);
if (StreamB == 7) {byte = pgm_read_byte(++StreamP); StreamB = 0;} else StreamB++;
c = pgm_read_byte(HuffmanTree + 3*node);
if (c)
{
if (c == 1) i--;
node = TreeStartIndex;
}
}
StreamC1 = 0;
StreamC2 = 0;
StreamC3 = 0;
}
//*****************************************************************************
//*****************************************************************************
#ifdef NO_STATUS_LINE
#define MAX_PRINTED_LINES (ConsoleH-1)
#else
#define MAX_PRINTED_LINES (ConsoleH-2)
#endif
void HandleMore(void)
{
uint8_t i;
if (NumPrintedLines < MAX_PRINTED_LINES) return;
i = ConsoleW-1 - 4; while (i--) PutChar(' ');
PutChar('M'); PutChar('O'); PutChar('R'); PutChar('E');
if (AutoPlayMode)
MyDelay(1000*NumPrintedLines);
NumPrintedLines = 0;
WaitForKey();
PutChar('\b'); PutChar('\b'); PutChar('\b'); PutChar('\b');
PutChar(' '); PutChar(' '); PutChar(' '); PutChar(' ');
i = ConsoleW-1; while (i--) PutChar('\b');
}
void PrintNewLine(void)
{
PutChar('\n');
NumPrintedLines++;
HandleMore();
}
void PrintChar(uint8_t c)
{
PutChar(c);
if (CursorColumn == 0)
{
NumPrintedLines++;
HandleMore();
}
}
// does word wrapping; recognizes newline char
// print terminated by '^' or nullchar
void PrintText(const char *p)
{
int flag = 0;
for (;;)
{
const char *q = p;
while (*q != ' ' && *q != '\n' && *q != 0 && *q != '^')
q++;
if (q - p)