Pick three bugfixes from next branch to trunk for inclusion in 4.5.0 RC2, as discusse...
[sdcc.git] / sdcc / support / regression / tests / io.c
blob7b7aacab0ceb66596a50aa893196a7df90386b58
1 /* io.c
2 Some source code extracted from the ColecoVision / Sega 8-bit game Io.
3 This file has been included in the tests, since it uses some z80 peephole rules
4 not used elsewhere in the regression tests.
5 */
7 #include <testfwk.h>
9 #ifdef __SDCC
10 #pragma std_c99
11 #endif
13 #include <stdint.h>
14 #include <stdbool.h>
16 void f16(uint16_t i)
18 ASSERT(i == 0x55aa);
21 void f16_2(uint16_t i)
23 ASSERT(i == 0xaa55);
26 void f8(uint8_t i)
28 ASSERT(i == 0x5a);
31 uint16_t assemble(uint8_t i, uint8_t j)
33 return(j | ((uint16_t)i << 8));
36 #ifndef __SDCC_pdk14 // Lack of memory
37 // Sequence of function calls with stack parameters close to stack end.
38 void callsequencestack(uint16_t i, uint16_t j, uint8_t k)
40 f16(i);
41 f16_2(j);
42 f8(k);
43 f16(i);
46 // Sequence of function calls with stack parameters far from stack end.
47 void callsequencestack2(uint32_t dummy1, uint16_t i, uint16_t j, uint8_t k, uint32_t dummy2)
49 dummy1;
50 dummy2;
51 f16(i);
52 f16_2(j);
53 f8(k);
54 f16(i);
57 // Sequence of function calls with stack parameters far from stack end.
58 void callsequencestack3(uint32_t dummy1, uint8_t i, uint8_t j, uint8_t k, uint32_t dummy2)
60 callsequencestack(assemble(i, j), assemble(j, i), k);
61 callsequencestack2(dummy1, assemble(i, j), assemble(j, i), k, dummy2);
64 // Sequence of function calls with with literals parameters
65 void callsequencelit(void)
67 f16(0x55aa);
68 f16_2(0xaa55);
69 f8(0x5a);
70 f16(0x55aa);
71 callsequencestack(0x55aa, 0xaa55, 0x5a);
72 callsequencestack2(0, 0x55aa, 0xaa55, 0x5a, 0);
73 callsequencestack(assemble(0x55,0xaa), assemble(0xaa,0x55), 0x5a);
74 callsequencestack3(0, 0x55, 0xaa, 0x5a, 0);
76 #endif
78 struct flags
80 uint8_t a;
81 uint8_t b;
84 uint8_t *c;
86 void setflags(struct flags *f)
88 f->a = 0x55;
89 f->b = 0xaa;
90 c = &(f->b);;
93 // Test a bit in a location accessed stough struct / by pointer
94 void pointerbit(void)
96 struct flags f;
98 setflags(&f);
100 if(f.a & 8)
101 ASSERT(0);
102 if(!(f.a & 4))
103 ASSERT(0);
104 if(f.b & 4)
105 ASSERT(0);
106 if(!(f.b & 8))
107 ASSERT(0);
108 if(*c & 4)
109 ASSERT(0);
110 if(!(*c & 8))
111 ASSERT(0);
114 void testBug(void)
116 #ifndef __SDCC_pdk14 // Lack of memory
117 callsequencelit();
118 #endif
119 pointerbit();