Pristine Ack-5.5
[Ack-5.5.git] / mach / z80 / as / mach5.c
1 /*
2  * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3  * See the copyright notice in the ACK home directory, in the file "Copyright".
4  */
5 #define RCSID5 "$Id: mach5.c,v 3.4 1994/06/24 13:54:57 ceriel Exp $"
6
7 /*
8  * Zilog Z80 special routines
9  */
10
11 xyreg(r,byte) {
12
13         if (r==IX)
14                 emit1(0335);
15         else if (r==IY)
16                 emit1(0375);
17         else if (r!=HL)
18                 serror("register error");
19         emit1(byte);
20 }
21
22 xymem(r,byte) {
23
24         xyreg(r,byte);
25         if (r != HL) {
26 #ifdef RELOCATION
27                 RELOMOVE(relonami, rel_ind);
28                 newrelo(exp_ind.typ, RELO1);
29 #endif
30                 emit1(exp_ind.val);
31         }
32 }
33
34 branch(opc,exp) register opc; expr_t exp; {
35         register sm,dist;
36
37         dist = exp.val - (DOTVAL + 2);
38         if (pass == PASS_2 && dist > 0 && !(exp.typ & S_DOT))
39                 dist -= DOTGAIN;
40         sm = fitb(dist);
41         if ((exp.typ & ~S_DOT) != DOTTYP)
42                 sm = 0;
43         if (opc == 020) {               /* DJNZ must be short */
44                 fit(sm);
45                 sm = 1;
46         } else if ((sm = small(sm,1)) == 0) {
47                 if (opc == 030)         /* 'JR exp' */
48                         opc = 0303;     /* replace by 'JP exp' */
49                 else                    /* 'JR CC,exp' */
50                         opc ^= 0342;    /* replace by 'JP CC,exp' */
51         }
52         emit1(opc);
53         if (sm == 0) {
54 #ifdef RELOCATION
55                 newrelo(exp.typ, RELO2);
56 #endif
57                 emit2(exp.val);
58         } else {
59                 emit1(lowb(dist));
60         }
61 }