1 /*
2   PC
3 */
4 
5 #include "pc.h"
6 
7 #include "mem.h"
8 
9 static word page, offset;
10 
pc_page(void)11 word pc_page(void)
12 {
13   return page;
14 }
15 
pc_offset(void)16 word pc_offset(void)
17 {
18   return offset;
19 }
20 
move_pc(word d)21 void move_pc(word d)
22 {
23   set_pc(page, offset + d);
24 }
25 
set_pc(word p,signed_word o)26 void set_pc(word p, signed_word o)
27 {
28   while(o < 0)
29   {
30     o += BLOCK_SIZE;
31     p -= 1;
32   }
33   while(o >= BLOCK_SIZE)
34   {
35     o -= BLOCK_SIZE;
36     p += 1;
37   }
38   page   = p;
39   offset = o;
40 }
41 
next_byte(void)42 byte next_byte(void)
43 {
44   byte b = rd_byte_seg(page, offset);
45 #if 0 /* This is slow */
46   move_pc(1);
47 #else
48   if(++offset == BLOCK_SIZE)
49   {
50     offset = 0;
51     ++page;
52   }
53 #endif
54   return b;
55 }
56 
next_word(void)57 word next_word(void)
58 {
59   byte hi = next_byte();
60   byte lo = next_byte();
61   return make_word(hi, lo);
62 }
63