1 /*
2 Support
3 */
4
5 #include "support.h"
6
7 #include "addr.h"
8 #include "console.h"
9 #include "head.h"
10 #include "input.h"
11 #include "interp.h"
12 #include "jump.h"
13 #include "message.h"
14 #include "page.h"
15 #include "pc.h"
16 #include "print.h"
17 #include "mem.h"
18 #include "shared.h"
19 #include "stack.h"
20 #include "stop.h"
21 #include "wio.h"
22
restart(void)23 void restart(void)
24 {
25 int i;
26 new_line();
27 for(i = 0; i < hd_save_blocks(); ++i)
28 hd_load(i, 1, pg_fetch(i));
29 hd_init();
30 init_interpreter(1);
31 }
32
33 #define HEADER_SIZE 64
34
verify(void)35 void verify(void)
36 {
37 word sum = 0;
38 long_word finish = ad_code_addr(hd_verify());
39 long_word addr = HEADER_SIZE;
40 while(addr != finish)
41 {
42 byte pg[BLOCK_SIZE];
43 word off = pg_offset(addr);
44 hd_load(pg_page(addr), 1, pg);
45 while(addr != finish && off != BLOCK_SIZE)
46 {
47 sum += pg[off];
48 ++off;
49 ++addr;
50 }
51 }
52 ret_value(sum == hd_check());
53 }
54
ncrypt(word param1,word param2,word param3,word param4)55 void ncrypt(word param1, word param2, word param3, word param4)
56 {
57 int i;
58 word coded[PLUS_ENCODED_SIZE];
59 long_word src = param1 + (long_word) param3;
60 long_word dst = param4;
61 (void) get_code(&src, PLUS_CHARS_PER_WORD, coded);
62
63 for(i = 0; i < PLUS_ENCODED_SIZE; i++)
64 {
65 wr_word_addr(dst, coded[i]);
66 dst += 2;
67 }
68 USE(param2);
69 }
70
block_copy(word src_offset,word dst_offset,signed_word num_words)71 void block_copy(word src_offset, word dst_offset, signed_word num_words)
72 {
73 if(src_offset != dst_offset && num_words != 0)
74 {
75 bool negative = num_words < 0;
76 if(negative)
77 num_words = -num_words;
78 if(dst_offset == 0)
79 {
80 while(num_words--)
81 wr_byte_addr(src_offset++, 0);
82 }
83 #if 0
84 /*
85 The extra guards mean copy upwards if no overlap, but that
86 is not needed ... they should be the same speed
87 */
88 else if(negative
89 || src_offset > dst_offset
90 || (word) ((signed_word) src_offset + num_words) < dst_offset)
91 #else
92 else if(negative)
93 #endif
94 {
95 while(num_words--)
96 wr_byte_addr(dst_offset++, rd_byte_addr(src_offset++));
97 }
98 else
99 {
100 dst_offset += num_words;
101 src_offset += num_words;
102 while(num_words--)
103 wr_byte_addr(--dst_offset, rd_byte_addr(--src_offset));
104 }
105 }
106 }
107
print_text(void)108 void print_text(void)
109 {
110 extern word param_stack[];
111
112 int align = con.cursor.align;
113 int cursor_x, cursor_y;
114 int num_params = param_stack[0];
115 word address = param_stack[1];
116 word line_width = param_stack[2];
117 word num_lines = num_params < 3 ? 1 : param_stack[3];
118 start_update();
119 get_xy(&cursor_x, &cursor_y);
120 /* save_attributes(2); */
121 if(line_width > 0)
122 while(num_lines--)
123 {
124 int count = line_width;
125 goto_xy(cursor_x, cursor_y++);
126 while(count--)
127 print_char((word) rd_byte_addr(address++));
128 }
129 /* restore_attributes(2); */
130 con.cursor.align = align;
131 finish_update();
132 }
133
134