annotate a09.c @ 34:2032755628dc

fix for nitros9
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 15 Jul 2018 14:18:19 +0900
parents 7c5379eb406e
children 01519215ec70
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
33
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
1 /* A09, 6809 Assembler2
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 created 1993,1994 by L.C. Benschop.
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 copyleft (c) 1994-2014 by the sbc09 team, see AUTHORS for more details.
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 license: GNU General Public License version 2, see LICENSE for more details.
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 THERE IS NO WARRANTY ON THIS PROGRAM.
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 Generates binary image file from the lowest to
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 the highest address with actually assembled data.
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
5
35028b396a35 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
11 Machin edependencies:
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 char is 8 bits.
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 short is 16 bits.
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 integer arithmetic is twos complement.
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 syntax a09 [-o filename] [-l filename] sourcefile.
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 Options
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 -o filename name of the output file (default name minus a09 suffix)
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 -s filename name of the s-record output file (default its a binary file)
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 -l filename list file name (default no listing)
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 -d enable debugging
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 recognized pseudoops:
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 extern public
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 macro endm if else endif
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 org equ set setdp
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 fcb fcw fdb fcc rmb
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 end include title
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 Not all of these are actually IMPLEMENTED!!!!!!
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 Revisions:
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 1993-11-03 v0.1
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 Initial version.
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 1994/03/21 v0.2
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 Fixed PC relative addressing bug
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 Added SET, SETDP, INCLUDE. IF/ELSE/ENDIF
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 No macros yet, and no separate linkable modules.
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 2012-06-04 j at klasek at
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 New: debugging parameter/option.
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 Fixed additional possible issue PC relative addressing.
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 Compatibility: Octal number prefix "&".
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 2014-07-15 j at klasek at
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 Fixed usage message.
29
3c14d647bb51 assembler and emulator fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
46 2018-07-11
3c14d647bb51 assembler and emulator fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
47 leax $ED00/256,x kernel offset in map
3c14d647bb51 assembler and emulator fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
48 should be positive offset expr should be int(32bit)
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 */
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 #include <stdlib.h>
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 #include <stdio.h>
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 #include <string.h>
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 #include <ctype.h>
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 #define NLABELS 2048
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 #define MAXIDLEN 16
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 #define MAXLISTBYTES 8
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 #define FNLEN 30
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 #define LINELEN 128
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 static int debug=0;
33
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
63 static struct incl {
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
64 char *name;
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
65 struct incl *next;
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
66 } *incls = 0;
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
67
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
68 static struct longer {
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
69 int gline;
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
70 int change;
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
71 struct longer *next;
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
72 } *lglist = 0;
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
73
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
74 void makelonger(int gl) {
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
75 for(struct longer *p=lglist;p;p=p->next) {
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
76 if (p->gline==gl) { // already fixed
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
77 p->change = 1;
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
78 return;
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
79 }
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
80 }
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
81 struct longer *p = (struct longer *)calloc(sizeof(struct longer *),1);
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
82 p->gline=gl;
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
83 p->next = lglist;
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
84 lglist = p;
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
85 }
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
86
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
87 int longer() {
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
88 for(struct longer *p=lglist;p;p=p->next) {
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
89 if (p->change == 0) return 1;
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
90 }
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
91 return 0;
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
92 }
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
93
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 struct oprecord{char * name;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 unsigned char cat;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 unsigned short code;};
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 /* Instruction categories:
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 0 one byte oprcodes NOP
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 1 two byte opcodes SWI2
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 2 opcodes w. imm byte ANDCC
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 3 LEAX etc.
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 4 short branches. BGE
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 5 long branches 2byte opc LBGE
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 6 long branches 1byte opc LBRA
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 7 accumulator instr. ADDA
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 8 double reg instr 1byte opc LDX
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 9 double reg instr 2 byte opc LDY
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 10 single address instrs NEG
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 11 TFR, EXG
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 12 push,pull
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 13 pseudoops
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 */
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
114
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 struct oprecord optable[]={
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 {"ABX",0,0x3a},{"ADCA",7,0x89},{"ADCB",7,0xc9},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 {"ADDA",7,0x8b},{"ADDB",7,0xcb},{"ADDD",8,0xc3},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 {"ANDA",7,0X84},{"ANDB",7,0xc4},{"ANDCC",2,0x1c},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 {"ASL",10,0x08},{"ASLA",0,0x48},{"ASLB",0,0x58},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 {"ASR",10,0x07},{"ASRA",0,0x47},{"ASRB",0,0x57},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 {"BCC",4,0x24},{"BCS",4,0x25},{"BEQ",4,0x27},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 {"BGE",4,0x2c},{"BGT",4,0x2e},{"BHI",4,0x22},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 {"BHS",4,0x24},{"BITA",7,0x85},{"BITB",7,0xc5},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 {"BLE",4,0x2f},{"BLO",4,0x25},{"BLS",4,0x23},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 {"BLT",4,0x2d},{"BMI",4,0x2b},{"BNE",4,0x26},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 {"BPL",4,0x2a},{"BRA",4,0x20},{"BRN",4,0x21},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 {"BSR",4,0x8d},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 {"BVC",4,0x28},{"BVS",4,0x29},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 {"CLC",1,0x1cfe},{"CLF",1,0x1cbf},{"CLI",1,0x1cef},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 {"CLIF",1,0x1caf},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 {"CLR",10,0x0f},{"CLRA",0,0x4f},{"CLRB",0,0x5f},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 {"CLV",1,0x1cfd},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 {"CMPA",7,0x81},{"CMPB",7,0xc1},{"CMPD",9,0x1083},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 {"CMPS",9,0x118c},{"CMPU",9,0x1183},{"CMPX",8,0x8c},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 {"CMPY",9,0x108c},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 {"COM",10,0x03},{"COMA",0,0x43},{"COMB",0,0x53},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 {"CWAI",2,0x3c},{"DAA",0,0x19},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 {"DEC",10,0x0a},{"DECA",0,0x4a},{"DECB",0,0x5a},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 {"DES",1,0x327f},{"DEU",1,0x335f},{"DEX",1,0x301f},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 {"DEY",1,0x313f},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 {"ELSE",13,1},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 {"EMOD",13,25},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
143 {"END",13,2},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 {"ENDC",13,3},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 {"ENDIF",13,3},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 {"ENDM",13,4},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 {"EORA",7,0x88},{"EORB",7,0xc8},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 {"EQU",13,5},{"EXG",11,0x1e},{"EXTERN",13,6},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 {"FCB",13,7},{"FCC",13,8},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 {"FCS",13,23},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
151 {"FCW",13,9},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 {"FDB",13,9},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 {"IF",13,10},
33
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
154 {"IFEQ",13,30},
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
155 {"IFGT",13,29},
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
156 {"IFNDEF",13,33},
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 {"IFNE",13,28},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 {"IFP1",13,21},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 {"INC",10,0x0c},{"INCA",0,0x4c},{"INCB",0,0x5c},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 {"INCLUDE",13,16},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 {"INS",1,0x3261},{"INU",1,0x3341},{"INX",1,0x3001},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 {"INY",1,0x3121},{"JMP",10,0x0e},{"JSR",8,0x8d},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 {"LBCC",5,0x1024},{"LBCS",5,0x1025},{"LBEQ",5,0x1027},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 {"LBGE",5,0x102c},{"LBGT",5,0x102e},{"LBHI",5,0x1022},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
165 {"LBHS",5,0x1024},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 {"LBLE",5,0x102f},{"LBLO",5,0x1025},{"LBLS",5,0x1023},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 {"LBLT",5,0x102d},{"LBMI",5,0x102b},{"LBNE",5,0x1026},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 {"LBPL",5,0x102a},{"LBRA",6,0x16},{"LBRN",5,0x1021},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 {"LBSR",6,0x17},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 {"LBVC",5,0x1028},{"LBVS",5,0x1029},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
171 {"LDA",7,0x86},{"LDB",7,0xc6},{"LDD",8,0xcc},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 {"LDS",9,0x10ce},{"LDU",8,0xce},{"LDX",8,0x8e},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
173 {"LDY",9,0x108e},{"LEAS",3,0x32},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 {"LEAU",3,0x33},{"LEAX",3,0x30},{"LEAY",3,0x31},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 {"LSL",10,0x08},{"LSLA",0,0x48},{"LSLB",0,0x58},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 {"LSR",10,0x04},{"LSRA",0,0x44},{"LSRB",0,0x54},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 {"MACRO",13,11},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
178 {"MOD",13,24},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
179 {"MUL",0,0x3d},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
180 {"NAM",13,26},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 {"NEG",10,0x00},{"NEGA",0,0x40},{"NEGB",0,0x50},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 {"NOP",0,0x12},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 {"OPT",13,19},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
184 {"ORA",7,0x8a},{"ORB",7,0xca},{"ORCC",2,0x1a},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 {"ORG",13,12},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 {"OS9",13,32},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
187 {"PAG",13,20}, {"PAGE",13,20},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
188 {"PSHS",12,0x34},{"PSHU",12,0x36},{"PUBLIC",13,13},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 {"PULS",12,0x35},{"PULU",12,0x37},{"RMB",13,0},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 {"ROL",10,0x09},{"ROLA",0,0x49},{"ROLB",0,0x59},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 {"ROR",10,0x06},{"RORA",0,0x46},{"RORB",0,0x56},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 {"RTI",0,0x3b},{"RTS",0,0x39},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 {"SBCA",7,0x82},{"SBCB",7,0xc2},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 {"SEC",1,0x1a01},{"SEF",1,0x1a40},{"SEI",1,0x1a10},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 {"SEIF",1,0x1a50},{"SET",13,15},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 {"SETDP",13,14},{"SEV",1,0x1a02},{"SEX",0,0x1d},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 {"STA",7,0x87},{"STB",7,0xc7},{"STD",8,0xcd},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 {"STS",9,0x10cf},{"STU",8,0xcf},{"STX",8,0x8f},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 {"STY",9,0x108f},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 {"SUBA",7,0x80},{"SUBB",7,0xc0},{"SUBD",8,0x83},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
201 {"SWI",0,0x3f},{"SWI2",1,0x103f},{"SWI3",1,0x113f},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 {"SYNC",0,0x13},{"TFR",11,0x1f},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 {"TITLE",13,18},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 {"TST",10,0x0d},{"TSTA",0,0x4d},{"TSTB",0,0x5d},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 {"TTL",13,18},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 {"USE",13,27},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
207 };
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
208
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
209 struct symrecord{char name[MAXIDLEN+1];
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
210 char cat;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
211 unsigned short value;
33
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
212 struct symrecord *next;
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
213 };
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
214
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
215 int symcounter=0;
34
2032755628dc fix for nitros9
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
216 int os9 = 0; // os9 flag
2032755628dc fix for nitros9
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
217 int rmbmode = 0; // in os9 work area
26
51a35f0347f6 fix label
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 25
diff changeset
218 struct symrecord * prevlp = 0;
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
219
8
96a067cf4c4f level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
220 /* expression categories...
96a067cf4c4f level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
221 ECORD all zeros is ordinary constant.
96a067cf4c4f level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
222 ECADR bit 1 indicates address within module.
96a067cf4c4f level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
223 ECEXT bit 2 indicates external address.
96a067cf4c4f level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
224 ECLBL bit 3 public label
96a067cf4c4f level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
225 ECABS bit 4 indicates this can't be relocated if it's an address.
96a067cf4c4f level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
226 ECNEG bit 5 indicates address (if any) is negative.
96a067cf4c4f level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
227 */
96a067cf4c4f level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
228
96a067cf4c4f level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
229
96a067cf4c4f level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
230 /* Symbol categories. exprcat ( symcat & 0xe )
96a067cf4c4f level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
231 0 SCC Constant value (from equ). ECORD
96a067cf4c4f level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
232 1 SCV Variable value (from set) ECORD
96a067cf4c4f level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
233 2 SCC__ADR Address within program module (label). ECADR
96a067cf4c4f level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
234 3 SCV__ADR Variable containing address. ECADR
96a067cf4c4f level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
235 4 SC_E_ADR Adress in other program module (extern) ECEXT
96a067cf4c4f level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
236 5 SCVE_ADR Variable containing external address. ECEXT
96a067cf4c4f level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
237 6 SCU _ADR Unresolved address. ECEXT+ECADR
96a067cf4c4f level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
238 7 SCV_UADR Variable containing unresolved address. ECEXT+ECADR
96a067cf4c4f level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
239 8 SC___LBL Public label. ECLBL
96a067cf4c4f level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
240 9 SCMACRO Macro definition. xxx
96a067cf4c4f level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
241 10 SCU__LBL Public label (yet undefined). ECADR+ECLBL
96a067cf4c4f level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
242 11 SCPARAM parameter name. ECADR+ECLBL
96a067cf4c4f level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
243 12 SCLOCAL local label. ECEXT+ECLBL
96a067cf4c4f level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
244 13 SCEMPTY empty. xxx
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
245 */
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
246
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
247 struct symrecord symtable[NLABELS];
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
248
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
249 void processfile(char *name);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
250
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
251 struct oprecord * findop(char * nm)
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
252 /* Find operation (mnemonic) in table using binary search */
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
253 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
254 int lo,hi,i,s;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
255 lo=0;hi=sizeof(optable)/sizeof(optable[0])-1;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
256 do {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
257 i=(lo+hi)/2;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
258 s=strcmp(optable[i].name,nm);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
259 if(s<0) lo=i+1;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
260 else if(s>0) hi=i-1;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
261 else break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
262 } while(hi>=lo);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
263 if (s) return NULL;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
264 return optable+i;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
265 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
266
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
267 struct symrecord * findsym(char * nm)
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
268 /* finds symbol table record; inserts if not found
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
269 uses binary search, maintains sorted table */
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
270 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
271 int lo,hi,i,j,s;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
272 lo=0;hi=symcounter-1;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
273 s=1;i=0;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
274 while (hi>=lo) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
275 i=(lo+hi)/2;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
276 s=strcmp(symtable[i].name,nm);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
277 if(s<0) lo=i+1;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
278 else if(s>0) hi=i-1;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
279 else break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
280 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
281 if(s) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
282 i=(s<0?i+1:i);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
283 if(symcounter==NLABELS) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
284 fprintf(stderr,"Sorry, no storage for symbols!!!");
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
285 exit(4);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
286 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
287 for(j=symcounter;j>i;j--) symtable[j]=symtable[j-1];
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
288 symcounter++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
289 strcpy(symtable[i].name,nm);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
290 symtable[i].cat=13;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
291 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
292 return symtable+i;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
293 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
294
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
295 FILE *listfile,*objfile;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
296 char *listname,*objname,*srcname,*curname;
33
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
297 int lineno,glineno;
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
298
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
299 void
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
300 outsymtable()
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
301 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
302 int i,j=0;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
303 fprintf(listfile,"\nSYMBOL TABLE");
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
304 for(i=0;i<symcounter;i++)
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
305 if(symtable[i].cat!=13) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
306 if(j%4==0)fprintf(listfile,"\n");
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
307 fprintf(listfile,"%10s %02d %04x",symtable[i].name,symtable[i].cat,
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
308 symtable[i].value);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
309 j++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
310 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
311 fprintf(listfile,"\n");
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
312 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
313
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
314 struct regrecord{char *name;unsigned char tfr,psh;};
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
315 struct regrecord regtable[]=
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
316 {{"D",0x00,0x06},{"X",0x01,0x10},{"Y",0x02,0x20},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
317 {"U",0x03,0x40},{"S",0x04,0x40},{"PC",0x05,0x80},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
318 {"A",0x08,0x02},{"B",0x09,0x04},{"CC",0x0a,0x01},
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
319 {"CCR",0x0a,0x01},{"DP",0x0b,0x08},{"DPR",0x0b,0x08}};
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
320
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
321 struct regrecord * findreg(char *nm)
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
322 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
323 int i;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
324 for(i=0;i<12;i++) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
325 if(strcmp(regtable[i].name,nm)==0) return regtable+i;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
326 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
327 return 0;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
328 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
329
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
330
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
331 char pass; /* Assembler pass=1 or 2 */
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
332 char listing; /* flag to indicate listing */
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
333 char relocatable; /* flag to indicate relocatable object. */
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
334 char terminate; /* flag to indicate termination. */
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
335 char generating; /* flag to indicate that we generate code */
34
2032755628dc fix for nitros9
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
336 unsigned short loccounter,oldlc,prevloc,rmbcounter; /* Location counter */
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
337
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
338 char inpline[128]; /* Current input line (not expanded)*/
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
339 char srcline[128]; /* Current source line */
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
340 char * srcptr; /* Pointer to line being parsed */
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
341
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
342 char unknown; /* flag to indicate value unknown */
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
343 char certain; /* flag to indicate value is certain at pass 1*/
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
344 int error; /* flags indicating errors in current line. */
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
345 int errors; /* number of errors */
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
346 char exprcat; /* category of expression being parsed, eg.
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
347 label or constant, this is important when
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
348 generating relocatable object code. */
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
349
6
9c2602e1d716 level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 5
diff changeset
350 void generate()
9c2602e1d716 level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 5
diff changeset
351 {
9c2602e1d716 level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 5
diff changeset
352 generating = 1;
34
2032755628dc fix for nitros9
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
353 if (rmbmode) {
2032755628dc fix for nitros9
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
354 rmbcounter = loccounter;
2032755628dc fix for nitros9
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
355 oldlc = loccounter = prevloc;
2032755628dc fix for nitros9
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
356 rmbmode = 0;
6
9c2602e1d716 level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 5
diff changeset
357 }
9c2602e1d716 level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 5
diff changeset
358 }
9c2602e1d716 level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 5
diff changeset
359
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
360
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
361 char namebuf[MAXIDLEN+1];
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
362
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
363 void
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
364 err(int er) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
365 error |= er ;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
366 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
367
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
368 void
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
369 scanname()
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
370 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
371 int i=0;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
372 char c;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
373 while(1) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
374 c=*srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
375 if(c>='a'&&c<='z')c-=32;
33
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
376 if(c!='_'&&c!='@'&&c!='.'&&c!='$'&&(c<'0'||c>'9')&&(c<'A'||c>'Z'))break;
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
377 if(i<MAXIDLEN)namebuf[i++]=c;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
378 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
379 namebuf[i]=0;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
380 srcptr--;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
381 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
382
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
383 void
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
384 skipspace()
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
385 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
386 char c;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
387 do {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
388 c=*srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
389 } while(c==' '||c=='\t');
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
390 srcptr--;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
391 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
392
29
3c14d647bb51 assembler and emulator fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
393 int scanexpr(int);
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
394
29
3c14d647bb51 assembler and emulator fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
395 int scandecimal()
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
396 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
397 char c;
29
3c14d647bb51 assembler and emulator fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
398 int t=0;
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
399 c=*srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
400 while(isdigit(c)) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
401 t=t*10+c-'0';
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
402 c=*srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
403 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
404 srcptr--;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
405 return t;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
406 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
407
29
3c14d647bb51 assembler and emulator fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
408 int scanhex()
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
409 {
29
3c14d647bb51 assembler and emulator fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
410 int t=0,i=0;
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
411 srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
412 scanname();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
413 while(namebuf[i]>='0'&&namebuf[i]<='F') {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
414 t=t*16+namebuf[i]-'0';
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
415 if(namebuf[i]>'9')t-=7;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
416 i++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
417 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
418 if(i==0)error|=1;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
419 return t;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
420 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
421
29
3c14d647bb51 assembler and emulator fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
422 int scanchar()
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
423 {
29
3c14d647bb51 assembler and emulator fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
424 int t;
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
425 srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
426 t=*srcptr;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
427 if(t)srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
428 if (*srcptr=='\'')srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
429 return t;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
430 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
431
29
3c14d647bb51 assembler and emulator fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
432 int scanbin()
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
433 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
434 char c;
29
3c14d647bb51 assembler and emulator fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
435 int t=0;
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
436 srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
437 c=*srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
438 while(c=='0'||c=='1') {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
439 t=t*2+c-'0';
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
440 c=*srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
441 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
442 srcptr--;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
443 return t;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
444 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
445
29
3c14d647bb51 assembler and emulator fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
446 int scanoct()
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
447 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
448 char c;
29
3c14d647bb51 assembler and emulator fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
449 int t=0;
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
450 srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
451 c=*srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
452 while(c>='0'&&c<='7') {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
453 t=t*8+c-'0';
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
454 c=*srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
455 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
456 srcptr--;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
457 return t;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
458 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
459
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
460
29
3c14d647bb51 assembler and emulator fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
461 int scanlabel()
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
462 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
463 struct symrecord * p;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
464 scanname();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
465 p=findsym(namebuf);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
466 if(p->cat==13) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
467 p->cat=6;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
468 p->value=0;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
469 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
470 if(p->cat==9||p->cat==11)error|=1;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
471 exprcat=p->cat&14;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
472 if(exprcat==6||exprcat==10)unknown=1;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
473 if(((exprcat==2||exprcat==8)
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
474 && (unsigned short)(p->value)>(unsigned short)loccounter)||
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
475 exprcat==4)
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
476 certain=0;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
477 if(exprcat==8||exprcat==6||exprcat==10)exprcat=2;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
478 return p->value;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
479 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
480
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
481
29
3c14d647bb51 assembler and emulator fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
482 int scanfactor()
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
483 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
484 char c;
29
3c14d647bb51 assembler and emulator fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
485 int t;
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
486 skipspace();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
487 c=*srcptr;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
488 if(isalpha(c))return scanlabel();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
489 else if(isdigit(c))return scandecimal();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
490 else switch(c) {
34
2032755628dc fix for nitros9
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
491 case '*' : srcptr++;exprcat|=2; if(rmbmode) return prevloc; else return loccounter;
2032755628dc fix for nitros9
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
492 case '.' : srcptr++;exprcat|=2; if(os9&&!rmbmode) return rmbcounter; else return loccounter;
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
493 case '$' : return scanhex();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
494 case '%' : return scanbin();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
495 case '&' : /* compatibility */
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
496 case '@' : return scanoct();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
497 case '\'' : return scanchar();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
498 case '(' : srcptr++;t=scanexpr(0);skipspace();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
499 if(*srcptr==')')srcptr++;else error|=1;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
500 return t;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
501 case '-' : srcptr++;exprcat^=32;return -scanfactor();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
502 case '+' : srcptr++;return scanfactor();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
503 case '!' : srcptr++;exprcat|=16;return !scanfactor();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
504 case '^' :
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
505 case '~' : srcptr++;exprcat|=16;return ~scanfactor();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
506 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
507 error|=1;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
508 return 0;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
509 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
510
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
511 #define EXITEVAL {srcptr--;return t;}
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
512
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
513 #define RESOLVECAT if((oldcat&15)==0)oldcat=0;\
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
514 if((exprcat&15)==0)exprcat=0;\
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
515 if((exprcat==2&&oldcat==34)||(exprcat==34&&oldcat==2)) {\
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
516 exprcat=0;\
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
517 oldcat=0;}\
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
518 exprcat|=oldcat;\
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
519 /* resolve such cases as constant added to address or difference between
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
520 two addresses in same module */
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
521
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
522
29
3c14d647bb51 assembler and emulator fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
523 int scanexpr(int level) /* This is what you call _recursive_ descent!!!*/
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
524 {
29
3c14d647bb51 assembler and emulator fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
525 int t,u;
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
526 char oldcat,c;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
527 exprcat=0;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
528 if(level==10)return scanfactor();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
529 t=scanexpr(level+1);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
530 while(1) {
5
35028b396a35 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
531 // skipspace();
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
532 c=*srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
533 switch(c) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
534 case '*':oldcat=exprcat;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
535 t*=scanexpr(10);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
536 exprcat|=oldcat|16;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
537 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
538 case '/':oldcat=exprcat;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
539 u=scanexpr(10);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
540 if(u)t/=u;else error|=1;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
541 exprcat|=oldcat|16;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
542 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
543 case '%':oldcat=exprcat;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
544 u=scanexpr(10);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
545 if(u)t%=u;else error|=1;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
546 exprcat|=oldcat|16;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
547 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
548 case '+':if(level==9)EXITEVAL
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
549 oldcat=exprcat;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
550 t+=scanexpr(9);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
551 RESOLVECAT
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
552 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
553 case '-':if(level==9)EXITEVAL
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
554 oldcat=exprcat;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
555 t-=scanexpr(9);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
556 exprcat^=32;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
557 RESOLVECAT
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
558 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
559 case '<':if(*(srcptr)=='<') {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
560 if(level>=8)EXITEVAL
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
561 srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
562 oldcat=exprcat;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
563 t<<=scanexpr(8);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
564 exprcat|=oldcat|16;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
565 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
566 } else if(*(srcptr)=='=') {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
567 if(level>=7)EXITEVAL
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
568 srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
569 oldcat=exprcat;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
570 t=t<=scanexpr(7);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
571 exprcat|=oldcat|16;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
572 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
573 } else {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
574 if(level>=7)EXITEVAL
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
575 oldcat=exprcat;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
576 t=t<scanexpr(7);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
577 exprcat|=oldcat|16;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
578 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
579 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
580 case '>':if(*(srcptr)=='>') {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
581 if(level>=8)EXITEVAL
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
582 srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
583 oldcat=exprcat;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
584 t>>=scanexpr(8);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
585 exprcat|=oldcat|16;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
586 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
587 } else if(*(srcptr)=='=') {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
588 if(level>=7)EXITEVAL
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
589 srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
590 oldcat=exprcat;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
591 t=t>=scanexpr(7);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
592 exprcat|=oldcat|16;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
593 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
594 } else {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
595 if(level>=7)EXITEVAL
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
596 oldcat=exprcat;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
597 t=t>scanexpr(7);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
598 exprcat|=oldcat|16;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
599 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
600 }
5
35028b396a35 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
601 case '!':if(level>=6) {
35028b396a35 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
602 if (*srcptr=='=') {
35028b396a35 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
603 srcptr++;
35028b396a35 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
604 oldcat=exprcat;
35028b396a35 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
605 t=t!=scanexpr(6);
35028b396a35 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
606 exprcat|=oldcat|16;
35028b396a35 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
607 } else {
35028b396a35 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
608 oldcat=exprcat;
35028b396a35 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
609 t|=scanexpr(6);
35028b396a35 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
610 exprcat|=oldcat|16;
35028b396a35 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
611 }
35028b396a35 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
612 }
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
613 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
614 case '=':if(level>=6)EXITEVAL
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
615 if(*srcptr=='=')srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
616 oldcat=exprcat;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
617 t=t==scanexpr(6);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
618 exprcat|=oldcat|16;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
619 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
620 case '&':if(level>=5)EXITEVAL
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
621 oldcat=exprcat;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
622 t&=scanexpr(5);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
623 exprcat|=oldcat|16;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
624 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
625 case '^':if(level>=4)EXITEVAL
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
626 oldcat=exprcat;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
627 t^=scanexpr(4);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
628 exprcat|=oldcat|16;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
629 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
630 case '|':if(level>=3)EXITEVAL
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
631 oldcat=exprcat;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
632 t|=scanexpr(3);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
633 exprcat|=oldcat|16;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
634 default: EXITEVAL
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
635 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
636 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
637 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
638
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
639 char mode; /* addressing mode 0=immediate,1=direct,2=extended,3=postbyte
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
640 4=pcrelative(with postbyte) 5=indirect 6=pcrel&indirect*/
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
641 char opsize; /*desired operand size 0=dunno,1=5,2=8,3=16*/
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
642 short operand;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
643 unsigned char postbyte;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
644
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
645 int dpsetting;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
646
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
647
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
648 int scanindexreg()
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
649 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
650 char c;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
651 c=*srcptr;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
652 if(islower(c))c-=32;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
653 if (debug) fprintf(stderr,"DEBUG: scanindexreg: indexreg=%d, mode=%d, opsize=%d, error=%d, postbyte=%02X\n",c,mode,opsize,error,postbyte);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
654 switch(c) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
655 case 'X':return 1;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
656 case 'Y':postbyte|=0x20;return 1;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
657 case 'U':postbyte|=0x40;return 1;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
658 case 'S':postbyte|=0x60;return 1;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
659 default: return 0;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
660 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
661 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
662
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
663 void
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
664 set3()
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
665 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
666 if(mode<3)mode=3;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
667 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
668
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
669 void
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
670 scanspecial()
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
671 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
672 set3();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
673 skipspace();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
674 if(*srcptr=='-') {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
675 srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
676 if(*srcptr=='-') {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
677 srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
678 postbyte=0x83;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
679 } else postbyte=0x82;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
680 if(!scanindexreg())error|=2;else srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
681 } else {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
682 postbyte=0x80;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
683 if(!scanindexreg())error|=2;else srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
684 if(*srcptr=='+') {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
685 srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
686 if(*srcptr=='+') {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
687 srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
688 postbyte+=1;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
689 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
690 } else postbyte+=4;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
691 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
692 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
693
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
694 void
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
695 scanindexed()
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
696 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
697 set3();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
698 postbyte=0;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
699 if(scanindexreg()) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
700 srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
701 if(opsize==0) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
702 if(unknown||!certain)opsize=3;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
703 else if(operand>=-16&&operand<16&&mode==3)opsize=1;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
704 else if(operand>=-128&&operand<128)opsize=2;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
705 else opsize=3;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
706 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
707 switch(opsize) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
708 case 1:postbyte+=(operand&31);opsize=0;break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
709 case 2:postbyte+=0x88;break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
710 case 3:postbyte+=0x89;break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
711 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
712 } else { /*pc relative*/
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
713 if(toupper(*srcptr)!='P')error|=2;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
714 else {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
715 srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
716 if(toupper(*srcptr)!='C')error|=2;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
717 else {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
718 srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
719 if(toupper(*srcptr)=='R')srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
720 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
721 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
722 mode++;postbyte+=0x8c;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
723 if(opsize==1)opsize=2;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
724 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
725 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
726
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
727 #define RESTORE {srcptr=oldsrcptr;c=*srcptr;goto dodefault;}
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
728
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
729 void
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
730 scanoperands()
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
731 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
732 char c,d,*oldsrcptr;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
733 unknown=0;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
734 opsize=0;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
735 certain=1;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
736 skipspace();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
737 c=*srcptr;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
738 mode=0;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
739 if(c=='[') {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
740 srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
741 c=*srcptr;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
742 mode=5;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
743 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
744 if (debug) fprintf(stderr,"DEBUG: scanoperands: c=%c (%02X)\n",c,c);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
745 switch(c) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
746 case 'D': case 'd':
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
747 oldsrcptr=srcptr;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
748 srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
749 skipspace();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
750 if(*srcptr!=',')RESTORE else {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
751 postbyte=0x8b;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
752 srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
753 if(!scanindexreg())RESTORE else {srcptr++;set3();}
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
754 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
755 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
756 case 'A': case 'a':
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
757 oldsrcptr=srcptr;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
758 srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
759 skipspace();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
760 if(*srcptr!=',')RESTORE else {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
761 postbyte=0x86;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
762 srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
763 if(!scanindexreg())RESTORE else {srcptr++;set3();}
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
764 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
765 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
766 case 'B': case 'b':
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
767 oldsrcptr=srcptr;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
768 srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
769 skipspace();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
770 if(*srcptr!=',')RESTORE else {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
771 postbyte=0x85;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
772 srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
773 if (debug) fprintf(stderr,"DEBUG: scanoperands: breg preindex: c=%c (%02X)\n",*srcptr,*srcptr);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
774 if(!scanindexreg())RESTORE else {srcptr++;set3();}
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
775 if (debug) fprintf(stderr,"DEBUG: scanoperands: breg: postindex c=%c (%02X)\n",*srcptr,*srcptr);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
776 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
777 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
778 case ',':
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
779 srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
780 scanspecial();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
781 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
782 case '#':
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
783 if(mode==5)error|=2;else mode=0;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
784 srcptr++;
5
35028b396a35 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
785 if (*srcptr=='"') {
35028b396a35 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
786 operand = (srcptr[1]<<8) + srcptr[2] ;
35028b396a35 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
787 srcptr += 3;
35028b396a35 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
788 break;
35028b396a35 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
789 }
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
790 operand=scanexpr(0);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
791 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
792 case '<':
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
793 srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
794 if(*srcptr=='<') {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
795 srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
796 opsize=1;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
797 } else opsize=2;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
798 goto dodefault;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
799 case '>':
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
800 srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
801 opsize=3;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
802 default: dodefault:
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
803 operand=scanexpr(0);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
804 skipspace();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
805 if(*srcptr==',') {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
806 srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
807 scanindexed();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
808 } else {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
809 if(opsize==0) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
810 if(unknown||!certain||dpsetting==-1||
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
811 (unsigned short)(operand-dpsetting*256)>=256)
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
812 opsize=3; else opsize=2;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
813 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
814 if(opsize==1)opsize=2;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
815 if(mode==5){
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
816 postbyte=0x8f;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
817 opsize=3;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
818 } else mode=opsize-1;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
819 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
820 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
821 if (debug) fprintf(stderr,"DEBUG: scanoperands: mode=%d, error=%d, postbyte=%02X\n",mode,error,postbyte);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
822 if(mode>=5) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
823 skipspace();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
824 postbyte|=0x10;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
825 if(*srcptr!=']')error|=2;else srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
826 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
827 if(pass==2&&unknown)error|=4;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
828 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
829
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
830 unsigned char codebuf[128];
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
831 int codeptr; /* byte offset within instruction */
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
832 int suppress; /* 0=no suppress 1=until ENDIF 2=until ELSE 3=until ENDM */
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
833 int ifcount; /* count of nested IFs within suppressed text */
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
834
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
835 unsigned char outmode; /* 0 is binary, 1 is s-records */
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
836
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
837 unsigned short hexaddr;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
838 int hexcount;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
839 unsigned char hexbuffer[16];
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
840 unsigned int chksum;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
841
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
842 extern int os9crc(unsigned char c, int crcp);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
843 int crc;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
844
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
845 void
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
846 reset_crc()
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
847 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
848 crc = -1;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
849 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
850
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
851
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
852 void
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
853 flushhex()
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
854 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
855 int i;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
856 if(hexcount){
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
857 fprintf(objfile,"S1%02X%04X",(hexcount+3)&0xff,hexaddr&0xffff);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
858 for(i=0;i<hexcount;i++)fprintf(objfile,"%02X",hexbuffer[i]);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
859 chksum+=(hexaddr&0xff)+((hexaddr>>8)&0xff)+hexcount+3;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
860 fprintf(objfile,"%02X\n",0xff-(chksum&0xff));
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
861 hexaddr+=hexcount;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
862 hexcount=0;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
863 chksum=0;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
864 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
865 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
866
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
867 void
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
868 outhex(unsigned char x)
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
869 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
870 if(hexcount==16)flushhex();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
871 hexbuffer[hexcount++]=x;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
872 chksum+=x;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
873 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
874
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
875 void
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
876 outbuffer()
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
877 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
878 int i;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
879 for(i=0;i<codeptr;i++) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
880 crc = os9crc(codebuf[i],crc);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
881 if(!outmode)fputc(codebuf[i],objfile);else outhex(codebuf[i]);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
882 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
883 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
884
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
885 char *errormsg[]={"Error in expression",
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
886 "Illegal addressing mode",
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
887 "Undefined label",
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
888 "Multiple definitions of label",
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
889 "Relative branch out of range",
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
890 "Missing label",
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
891 "","","","","","","","","",
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
892 "Illegal mnemonic"
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
893 };
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
894
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
895 void
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
896 report()
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
897 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
898 int i;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
899 fprintf(stderr,"File %s, line %d:%s\n",curname,lineno,srcline);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
900 for(i=0;i<16;i++) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
901 if(error&1) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
902 fprintf(stderr,"%s\n",errormsg[i]);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
903 if(pass==2&&listing)fprintf(listfile,"**** %s\n",errormsg[i]);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
904 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
905 error>>=1;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
906 }
5
35028b396a35 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
907 error = 0;
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
908 errors++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
909 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
910
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
911 void
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
912 outlist()
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
913 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
914 int i;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
915 fprintf(listfile,"%04X: ",oldlc);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
916 for(i=0;i<codeptr&&i<MAXLISTBYTES;i++)
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
917 fprintf(listfile,"%02X",codebuf[i]);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
918 for(;i<=MAXLISTBYTES;i++)
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
919 fprintf(listfile," ");
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
920 fprintf(listfile,"%s\n",srcline);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
921 while(i<codeptr) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
922 fprintf(listfile,"%04X: ",oldlc + i);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
923 for(int j=0;i<codeptr&&j<MAXLISTBYTES;j++) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
924 fprintf(listfile,"%02X",codebuf[i]); i++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
925 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
926 fprintf(listfile,"\n");
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
927 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
928 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
929
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
930 void
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
931 setlabel(struct symrecord * lp)
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
932 {
33
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
933 while (prevlp) {
26
51a35f0347f6 fix label
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 25
diff changeset
934 struct symrecord *l = prevlp;
33
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
935 prevlp = prevlp->next;
26
51a35f0347f6 fix label
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 25
diff changeset
936 setlabel(l);
51a35f0347f6 fix label
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 25
diff changeset
937 }
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
938 if(lp) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
939 if(lp->cat!=13&&lp->cat!=6) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
940 if(lp->cat!=2||lp->value!=loccounter)
33
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
941 ; // error|=8;
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
942 } else {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
943 lp->cat=2;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
944 lp->value=loccounter;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
945 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
946 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
947 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
948
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
949 void
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
950 putbyte(unsigned char b)
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
951 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
952 codebuf[codeptr++]=b;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
953 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
954
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
955 void
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
956 putword(unsigned short w)
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
957 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
958 codebuf[codeptr++]=w>>8;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
959 codebuf[codeptr++]=w&0x0ff;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
960 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
961
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
962 void
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
963 doaddress() /* assemble the right addressing bytes for an instruction */
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
964 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
965 int offs;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
966 switch(mode) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
967 case 0: if(opsize==2)putbyte(operand);else putword(operand);break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
968 case 1: putbyte(operand);break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
969 case 2: putword(operand);break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
970 case 3: case 5: putbyte(postbyte);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
971 switch(opsize) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
972 case 2: putbyte(operand);break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
973 case 3: putword(operand);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
974 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
975 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
976 case 4: case 6: offs=(unsigned short)operand-loccounter-codeptr-2;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
977 if(offs<-128||offs>=128||opsize==3||unknown||!certain) {
33
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
978 if((!unknown)&&opsize==2&&(offs<-128||offs>=128) ) {
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
979 error|=16; makelonger(glineno);
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
980 }
12
111e5defb8ab boot is called, rti failed
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
981 offs--;
111e5defb8ab boot is called, rti failed
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
982 opsize=3;
111e5defb8ab boot is called, rti failed
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
983 postbyte++;
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
984 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
985 putbyte(postbyte);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
986 if (debug) fprintf(stderr,"DEBUG: doaddress: mode=%d, opsize=%d, error=%d, postbyte=%02X, operand=%04X offs=%d\n",mode,opsize,error,postbyte,operand,offs);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
987 if(opsize==3)putword(offs);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
988 else putbyte(offs);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
989 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
990 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
991
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
992 void
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
993 onebyte(int co)
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
994 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
995 putbyte(co);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
996 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
997
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
998 void
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
999 twobyte(int co)
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1000 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1001 putword(co);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1002 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1003
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1004 void
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1005 oneimm(int co)
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1006 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1007 scanoperands();
5
35028b396a35 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
1008 if(mode>=3)
35028b396a35 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
1009 error|=2;
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1010 putbyte(co);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1011 putbyte(operand);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1012 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1013
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1014 void
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1015 lea(int co)
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1016 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1017 putbyte(co);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1018 scanoperands();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1019 if(mode==0) error|=2;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1020 if(mode<3) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1021 opsize=3;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1022 postbyte=0x8f;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1023 mode=3;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1024 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1025 if (debug) fprintf(stderr,"DEBUG: lea: mode=%d, opsize=%d, error=%d, postbyte=%02X, *src=%c\n",mode,opsize,error,postbyte,*srcptr);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1026 doaddress();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1027 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1028
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1029 void
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1030 sbranch(int co)
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1031 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1032 int offs;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1033 scanoperands();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1034 if(mode!=1&&mode!=2)error|=2;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1035 offs=(unsigned short)operand-loccounter-2;
33
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
1036 if(!unknown&&(offs<-128||offs>=128)) {
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
1037 error|=16;makelonger(glineno);
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
1038 if (co==0x20) {
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
1039 if(mode!=1&&mode!=2)error|=2;
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
1040 putbyte(0x16);
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
1041 putword(operand-loccounter-3);
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
1042 } else {
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
1043 if(mode!=1&&mode!=2)error|=2;
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
1044 putbyte(0x10);
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
1045 putbyte(co);
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
1046 putword(operand-loccounter-4);
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
1047 }
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
1048 return;
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
1049 }
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1050 if(pass==2&&unknown)error|=4;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1051 putbyte(co);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1052 putbyte(offs);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1053 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1054
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1055 void
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1056 lbra(int co)
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1057 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1058 scanoperands();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1059 if(mode!=1&&mode!=2)error|=2;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1060 putbyte(co);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1061 putword(operand-loccounter-3);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1062 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1063
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1064 void
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1065 lbranch(int co)
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1066 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1067 scanoperands();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1068 if(mode!=1&&mode!=2)error|=2;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1069 putword(co);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1070 putword(operand-loccounter-4);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1071 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1072
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1073 void
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1074 arith(int co)
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1075 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1076 scanoperands();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1077 switch(mode) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1078 case 0:opsize=2;putbyte(co);break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1079 case 1:putbyte(co+0x010);break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1080 case 2:putbyte(co+0x030);break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1081 default:putbyte(co+0x020);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1082 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1083 doaddress();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1084 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1085
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1086 void
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1087 darith(int co)
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1088 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1089 scanoperands();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1090 switch(mode) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1091 case 0:opsize=3;putbyte(co);break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1092 case 1:putbyte(co+0x010);break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1093 case 2:putbyte(co+0x030);break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1094 default:putbyte(co+0x020);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1095 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1096 doaddress();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1097 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1098
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1099 void
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1100 d2arith(int co)
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1101 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1102 scanoperands();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1103 switch(mode) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1104 case 0:opsize=3;putword(co);break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1105 case 1:putword(co+0x010);break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1106 case 2:putword(co+0x030);break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1107 default:putword(co+0x020);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1108 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1109 doaddress();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1110 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1111
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1112 void
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1113 oneaddr(int co)
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1114 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1115 scanoperands();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1116 switch(mode) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1117 case 0: error|=2;break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1118 case 1: putbyte(co);break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1119 case 2: putbyte(co+0x70);break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1120 default: putbyte(co+0x60);break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1121 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1122 doaddress();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1123 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1124
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1125 void
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1126 tfrexg(int co)
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1127 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1128 struct regrecord * p;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1129 putbyte(co);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1130 skipspace();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1131 scanname();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1132 if((p=findreg(namebuf))==0)error|=2;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1133 else postbyte=(p->tfr)<<4;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1134 skipspace();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1135 if(*srcptr==',')srcptr++;else error|=2;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1136 skipspace();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1137 scanname();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1138 if((p=findreg(namebuf))==0)error|=2;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1139 else postbyte|=p->tfr;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1140 putbyte(postbyte);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1141 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1142
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1143 void
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1144 pshpul(int co)
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1145 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1146 struct regrecord *p;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1147 putbyte(co);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1148 postbyte=0;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1149 do {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1150 if(*srcptr==',')srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1151 skipspace();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1152 scanname();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1153 if((p=findreg(namebuf))==0)error|=2;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1154 else postbyte|=p->psh;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1155 skipspace();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1156 }while (*srcptr==',');
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1157 putbyte(postbyte);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1158 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1159
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1160 void
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1161 skipComma()
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1162 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1163 while(*srcptr && *srcptr!='\n' && *srcptr!=',')srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1164 if (*srcptr==',') {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1165 srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1166 } else {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1167 error|=1;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1168 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1169 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1170
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1171 void os9begin()
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1172 {
6
9c2602e1d716 level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 5
diff changeset
1173 generate();
3
831ac057ea86 before mmu
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
1174 os9=1; // contiguous code generation ( i.e. ignore org nor rmb )
34
2032755628dc fix for nitros9
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
1175 oldlc = loccounter = rmbcounter = rmbmode = 0;
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1176 reset_crc();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1177 putword(0x87cd);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1178 putword(scanexpr(0)-loccounter); // module size
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1179 skipComma();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1180 putword(scanexpr(0)-loccounter); // offset to module name
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1181 skipComma();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1182 putbyte(scanexpr(0)); // type / language
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1183 skipComma();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1184 putbyte(scanexpr(0)); // attribute
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1185 int parity=0;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1186 for(int i=0; i< 8; i++) parity^=codebuf[i];
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1187 putbyte(parity^0xff); // header parity
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1188 skipspace();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1189 while (*srcptr==',') { // there are some more
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1190 srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1191 putword(scanexpr(0));
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1192 skipspace();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1193 }
34
2032755628dc fix for nitros9
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
1194 prevloc = codeptr;
2032755628dc fix for nitros9
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
1195 rmbmode = 1; // next org works on rmb
2032755628dc fix for nitros9
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
1196 loccounter = 0x10000-codeptr; // should start at 0
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1197 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1198
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1199 void os9end()
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1200 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1201 crc = crc ^ 0xffffff;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1202
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1203 putbyte((crc>>16)&0xff);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1204 putbyte((crc>>8)&0xff);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1205 putbyte(crc&0xff);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1206 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1207
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1208
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1209 void
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1210 pseudoop(int co,struct symrecord * lp)
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1211 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1212 int i;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1213 char c;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1214 char *fname;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1215 int locsave;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1216
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1217 switch(co) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1218 case 0:/* RMB */
3
831ac057ea86 before mmu
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
1219 // in OS9 mode, this generates no data
831ac057ea86 before mmu
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
1220 // loccounter will be reset after any code to the current code generation
34
2032755628dc fix for nitros9
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
1221 if (os9 && !rmbmode) {
2032755628dc fix for nitros9
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
1222 prevloc = loccounter;
2032755628dc fix for nitros9
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
1223 oldlc = loccounter = rmbcounter;
2032755628dc fix for nitros9
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 33
diff changeset
1224 rmbmode = 1;
33
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
1225 }
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1226 setlabel(lp);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1227 operand=scanexpr(0);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1228 if(unknown)error|=4;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1229 loccounter+=operand;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1230 if(generating&&pass==2) {
6
9c2602e1d716 level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 5
diff changeset
1231 if(!outmode && !os9 ) {
9c2602e1d716 level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 5
diff changeset
1232 for(i=0;i<operand;i++) { fputc(0,objfile); }
9c2602e1d716 level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 5
diff changeset
1233 } else
9c2602e1d716 level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 5
diff changeset
1234 flushhex();
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1235 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1236 hexaddr=loccounter;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1237 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1238 case 5:/* EQU */
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1239 operand=scanexpr(0);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1240 if(!lp)error|=32;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1241 else {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1242 if(lp->cat==13||lp->cat==6||
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1243 (lp->value==(unsigned short)operand&&pass==2)) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1244 if(exprcat==2)lp->cat=2;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1245 else lp->cat=0;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1246 lp->value=operand;
33
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
1247 } // else error|=8;
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1248 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1249 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1250 case 7:/* FCB */
6
9c2602e1d716 level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 5
diff changeset
1251 generate();
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1252 setlabel(lp);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1253 do {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1254 if(*srcptr==',')srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1255 skipspace();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1256 if(*srcptr=='\"') {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1257 srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1258 while(*srcptr!='\"'&&*srcptr)
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1259 putbyte(*srcptr++);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1260 if(*srcptr=='\"')srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1261 } else {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1262 putbyte(scanexpr(0));
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1263 if(unknown&&pass==2)error|=4;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1264 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1265 skipspace();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1266 } while(*srcptr==',');
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1267 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1268 case 8:/* FCC */
6
9c2602e1d716 level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 5
diff changeset
1269 generate();
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1270 setlabel(lp);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1271 skipspace();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1272 c=*srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1273 while(*srcptr!=c&&*srcptr)
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1274 putbyte(*srcptr++);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1275 if(*srcptr==c)srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1276 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1277 case 9:/* FDB */
6
9c2602e1d716 level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 5
diff changeset
1278 generate();
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1279 setlabel(lp);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1280 do {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1281 if(*srcptr==',')srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1282 skipspace();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1283 putword(scanexpr(0));
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1284 if(unknown&&pass==2)error|=4;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1285 skipspace();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1286 } while(*srcptr==',');
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1287 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1288 case 23 :/* FCS */
6
9c2602e1d716 level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 5
diff changeset
1289 generate();
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1290 setlabel(lp);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1291 skipspace();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1292 int sep = *srcptr;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1293 if(sep=='\"' || sep=='/') {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1294 srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1295 while(*srcptr!=sep&&*srcptr)
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1296 putbyte(*srcptr++);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1297 if(*srcptr==sep)srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1298 codebuf[codeptr-1] |= 0x80; // os9 string termination
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1299 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1300 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1301 case 1: /* ELSE */
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1302 suppress=1;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1303 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1304 case 21: /* IFP1 */
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1305 if(pass==2)suppress=2;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1306 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1307 case 29: /* IFGT */
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1308 operand=scanexpr(0);
33
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
1309 if(operand<=0)suppress=2;
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1310 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1311 case 31: /* IFLT */
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1312 operand=scanexpr(0);
33
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
1313 if(operand>=0)suppress=2;
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1314 break;
3
831ac057ea86 before mmu
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
1315 case 30: /* IFEQ */
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1316 operand=scanexpr(0);
33
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
1317 if(operand!=0)suppress=2;
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1318 break;
3
831ac057ea86 before mmu
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
1319 case 28: /* IFNE */
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1320 case 10: /* IF */
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1321 operand=scanexpr(0);
33
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
1322 if(operand==0)suppress=2;
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
1323 break;
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
1324 case 33: /* IFNDEF */
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
1325 operand=scanexpr(0);
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
1326 if(!unknown)suppress=2;
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1327 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1328 case 12: /* ORG */
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1329 operand=scanexpr(0);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1330 if(unknown)error|=4;
3
831ac057ea86 before mmu
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
1331 if(generating&&pass==2&&!outmode&&!os9) {
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1332 for(i=0;i<(unsigned short)operand-loccounter;i++)
3
831ac057ea86 before mmu
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
1333 fputc(0,objfile);
831ac057ea86 before mmu
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
1334 } else flushhex();
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1335 loccounter=operand;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1336 hexaddr=loccounter;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1337 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1338 case 14: /* SETDP */
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1339 operand=scanexpr(0);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1340 if(unknown)error|=4;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1341 if(!(operand&255))operand=(unsigned short)operand>>8;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1342 if((unsigned)operand>255)operand=-1;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1343 dpsetting=operand;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1344 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1345 case 15: /* SET */
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1346 operand=scanexpr(0);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1347 if(!lp)error|=32;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1348 else {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1349 if(lp->cat&1||lp->cat==6) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1350 if(exprcat==2)lp->cat=3;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1351 else lp->cat=1;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1352 lp->value=operand;
33
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
1353 } // else error|=8;
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1354 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1355 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1356 case 2: /* END */
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1357 terminate=1;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1358 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1359 case 27: /* USE */
6
9c2602e1d716 level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 5
diff changeset
1360 // locsave = loccounter ;
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1361 case 16: /* INCLUDE */
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1362 skipspace();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1363 if(*srcptr=='"')srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1364 i = 0;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1365 for(i=0; !(srcptr[i]==0||srcptr[i]=='"'); i++);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1366 int len = i;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1367 fname = calloc(1,len);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1368 for(i=0;i<len;i++) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1369 if(*srcptr==0||*srcptr=='"')break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1370 fname[i]=*srcptr++;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1371 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1372 fname[i]=0;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1373 processfile(fname);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1374 codeptr=0;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1375 srcline[0]=0;
3
831ac057ea86 before mmu
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
1376 // if (co==27) loccounter = locsave;
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1377 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1378 case 24: /* MOD */
6
9c2602e1d716 level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 5
diff changeset
1379 oldlc = loccounter = 0;
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1380 setlabel(lp);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1381 os9begin();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1382 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1383 case 25: /* EMOD */
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1384 os9end();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1385 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1386 case 32: /* OS9 */
6
9c2602e1d716 level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 5
diff changeset
1387 generate();
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1388 setlabel(lp);
3
831ac057ea86 before mmu
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
1389 putword(0x103f); // SWI2
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1390 putbyte(scanexpr(0));
15
bb6a2a9f59f1 boot ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
1391 if(unknown&&pass==2)error|=4;
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1392 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1393 case 18: /* TTL */
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1394 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1395 case 19: /* OPT */
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1396 case 26: /* NAM */
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1397 case 20: /* PAG */
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1398 case 3: /* ENDIF/ENDC */
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1399 break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1400 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1401 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1402
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1403
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1404 void
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1405 processline()
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1406 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1407 struct symrecord * lp;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1408 struct oprecord * op;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1409 int co;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1410 char c;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1411 srcptr=srcline;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1412 oldlc=loccounter;
5
35028b396a35 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
1413 // error=0;
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1414 unknown=0;certain=1;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1415 lp=0;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1416 codeptr=0;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1417 if(isalnum(*srcptr)) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1418 scanname();lp=findsym(namebuf);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1419 if(*srcptr==':') srcptr++;
26
51a35f0347f6 fix label
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 25
diff changeset
1420 if(lp && pass==2) {
51a35f0347f6 fix label
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 25
diff changeset
1421 oldlc = lp->value;
51a35f0347f6 fix label
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 25
diff changeset
1422 }
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1423 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1424 skipspace();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1425 if(isalnum(*srcptr)) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1426 scanname();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1427 op=findop(namebuf);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1428 if(op) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1429 if(op->cat!=13){
6
9c2602e1d716 level2 rom done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 5
diff changeset
1430 generate();
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1431 setlabel(lp);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1432 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1433 co=op->code;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1434 switch(op->cat) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1435 case 0:onebyte(co);break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1436 case 1:twobyte(co);break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1437 case 2:oneimm(co);break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1438 case 3:lea(co);break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1439 case 4:sbranch(co);break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1440 case 5:lbranch(co);break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1441 case 6:lbra(co);break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1442 case 7:arith(co);break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1443 case 8:darith(co);break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1444 case 9:d2arith(co);break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1445 case 10:oneaddr(co);break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1446 case 11:tfrexg(co);break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1447 case 12:pshpul(co);break;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1448 case 13:pseudoop(co,lp);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1449 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1450 c=*srcptr;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1451 if (debug) fprintf(stderr,"DEBUG: processline: mode=%d, opsize=%d, error=%d, postbyte=%02X c=%c\n",mode,opsize,error,postbyte,c);
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1452 if(c!=' '&&*(srcptr-1)!=' '&&c!=0&&c!=';')error|=2;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1453 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1454 else error|=0x8000;
26
51a35f0347f6 fix label
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 25
diff changeset
1455 } else {
33
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
1456 if (lp) {
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
1457 lp->next = prevlp;
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
1458 prevlp = lp; // os9 mode label can be data or code
7c5379eb406e nitors9 version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
1459 }
26
51a35f0347f6 fix label
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 25
diff changeset
1460 }
0
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1461 if(pass==2) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1462 outbuffer();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1463 if(listing)outlist();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1464 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1465 if(error)report();
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1466 loccounter+=codeptr;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1467 }
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1468
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1469 void
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1470 suppressline()
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1471 {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1472 struct oprecord * op;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1473 srcptr=srcline;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1474 oldlc=loccounter;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1475 codeptr=0;
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1476 if(isalnum(*srcptr)) {
9a224bd9b45f os9 emulation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff