]> Shamusworld >> Repos - thunder/blob - test/union.cpp
Fixes to makefile, file permissions.
[thunder] / test / union.cpp
1 // Union bit fields...
2
3 #include <dos.h>
4 #include <conio.h>
5 #include <fstream.h>
6 #include <string.h>
7 #include <iomanip.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10
11 union {
12   struct {
13     unsigned char C: 1;   // Carry flag 
14     unsigned char V: 1;   // oVerflow flag
15     unsigned char Z: 1;   // Zero flag
16     unsigned char N: 1;   // Negative flag
17     unsigned char I: 1;   // IRQ flag
18     unsigned char H: 1;   // Half carry flag
19     unsigned char F: 1;   // Fast IRQ flag
20     unsigned char E: 1;   // Entire flag
21     } flag;
22   unsigned char byte; } cc;
23
24 union BYTE {
25   struct {
26     unsigned char b0: 1;  unsigned char b1: 1;  unsigned char b2: 1;
27     unsigned char b3: 1;  unsigned char b4: 1;  unsigned char b5: 1;
28     unsigned char b6: 1;  unsigned char b7: 1;
29     } bit;
30   unsigned char byte; };
31
32 union WORD {
33   struct { unsigned char lo: 8;  unsigned char hi: 8; } b;
34   unsigned int word; } hilo;
35
36 void main()
37 {
38   for(int i=0; i<256; i++)
39   {
40     cc.byte = i;
41     cout << cc.flag.E << " " << cc.flag.F << " "
42          << cc.flag.H << " " << cc.flag.I << " "
43          << cc.flag.N << " " << cc.flag.Z << " "
44          << cc.flag.V << " " << cc.flag.C << endl;
45   }
46   hilo.word = 0x6A44;
47   cout << hex << hilo.word << " "
48        << (int) hilo.b.lo << " " << (int) hilo.b.hi << endl;
49 }