-
Notifications
You must be signed in to change notification settings - Fork 3
/
cpos.c
92 lines (89 loc) · 3.02 KB
/
cpos.c
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
/*
*******************************************************************
*** This software is copyright 2021 by Michael H Riley ***
*** You have permission to use, modify, copy, and distribute ***
*** this software so long as this copyright notice is retained. ***
*** This software may not be used in commercial applications ***
*** without express written permission from the author. ***
*******************************************************************
*/
#include "header.h"
char* cpos(char* line) {
byte fnum;
line = trim(line);
if (*line != '#') {
showError("Syntax error");
*line = 0;
return line;
}
line++;
if (*line < '1' || *line > '8') {
showError("Syntax error");
*line = 0;
return line;
}
fnum = *line - '1';
line++;
line = trim(line);
line = cexpr(line, 0);
if (exprErrors > 0) return line;
if (use32Bits) {
Asm(" inc r7 ; Retrieve address");
Asm(" lda r7");
Asm(" plo rc");
Asm(" lda r7");
Asm(" phi rc");
Asm(" lda r7");
Asm(" plo r8");
Asm(" ldn r7");
Asm(" phi r8");
Asm(" ghi r7 ; save R7");
Asm(" stxd");
Asm(" glo r7");
Asm(" stxd");
Asm(" glo rc ; transfer low word to R7");
Asm(" plo r7");
Asm(" ghi rc");
Asm(" phi r7");
}
else {
Asm(" inc r7 ; Retrieve address");
Asm(" lda r7");
Asm(" plo rc");
Asm(" ldn r7");
Asm(" phi rc");
Asm(" ghi r7 ; save R7");
Asm(" stxd");
Asm(" glo r7");
Asm(" stxd");
Asm(" glo rc ; transfer low word to R7");
Asm(" plo r7");
Asm(" ghi rc");
Asm(" phi r7");
Asm(" ldi 0 ; clear high word");
Asm(" plo r8");
Asm(" phi r8");
}
Asm(" ldi 0 ; Seek from beginning");
Asm(" plo rc");
Asm(" phi rc");
sprintf(buffer," ldi (file1_+%d*2).0 ; Point to file handle",fnum % 256);
Asm(buffer);
Asm(" plo rf");
sprintf(buffer," ldi (file1_+%d*2).1",fnum / 256);
Asm(buffer);
Asm(" phi rf");
Asm(" lda rf ; Retrieve FILDES");
Asm(" phi rd");
Asm(" lda rf");
Asm(" plo rd");
Asm(" sep scall ; Call Elf/OS to set file position");
Asm(" dw 030fh");
Asm(" irx ; recover R7");
Asm(" ldxa");
Asm(" plo r7");
Asm(" ldx");
Asm(" phi r7");
while (*line != ':' && *line != 0) line++;
return line;
}