aboutsummaryrefslogtreecommitdiff
path: root/tools/iDSK/src/Dams.cpp
blob: 52cad9bd232675ad6bfc48487e1af768e870077e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;


//
// Convertir le buffer en listing au format Dams
// Adaptation des sources de Thierry JOUIN ( Ramlaid )
//
void Dams( unsigned char * BufFile, int TailleFic, char * Listing )
{
    const char * MotCleDams[ 0x80 ] =
        {
        "LD","INC","DEC","ADD","ADC","SUB","SBC","AND","XOR","OR","CP",
        "PUSH","POP","BIT","RES","SET","RLC","RRC","RL","RR","SLA","SRA",
        "SRL","IN","OUT","RST","DJNZ","EX","IM","JR","CALL","RET","JP",
        "NOP","RLCA","RRCA","RLA","RRA","DAA","CPL","SCF","CCF","HALT",
        "EXX","DI","EI","NEG","RETN","RETI","RRD","RLD","LDI","CPI","INI",
        "OUTI","LDD","CPD","IND","OUTD","LDIR","CPIR","INIR","OTIR","LDDR",
        "CPDR","INDR","OTDR","DB","DW","DM","DS","EQU","ORG","ENT",
        "IF","ELSE","END"
        };
    char Tmp[ 32 ];
    int PosFile = 0;
    int PosDest = 0;
    unsigned char c;

    * Listing = 0;
    c = BufFile[ PosFile++ ];
    while( c )
        {
        if ( c == 0xFF )
            {
            // Commentaire ligne
            Listing[ PosDest++ ] = ';';
            c = BufFile[ PosFile++ ];
            while( c != 0x0D && PosFile < TailleFic )
                {
                Listing[ PosDest++ ] = c;
                c = BufFile[ PosFile++ ];
                }
            Listing[ PosDest++ ] = '\r';
            Listing[ PosDest++ ] = '\n';
            }
        else
            {
            if ( c >= 0x80 && c != 0x0D )
                {
                // Mnemonique sans label
                // ENT
                if ( c == 0xC9 )
                    Listing[ PosDest++ ] = ';';

                sprintf( Tmp, "\t%s\t", MotCleDams[ c & 0x7F ] );
                int l = strlen( Tmp );
                memcpy( &Listing[ PosDest ], Tmp, l );
                PosDest += l;
                // DS ?,?
                if ( c == 0xC6 )
                    {
                    c = BufFile[ PosFile++ ];
                    // Fin de ligne
                    while( c != 0x0D && PosFile < TailleFic )
                        {
                        if ( c == ',' )
                            {
                            while( c != 0x0D && c != 0xFF && PosFile < TailleFic )
                                c = BufFile[ PosFile++ ];
                            }
                        if ( c != 0x0D )
                            {
                            if ( c == 0xFF )
                                Listing[ PosDest++ ] = '\t';
                            else
                                Listing[ PosDest++ ] = c;

                            c = BufFile[ PosFile++ ];
                            }
                        }
                    }
                else
                    {
                    c = BufFile[ PosFile++ ];
                    // Fin de ligne
                    while( c != 0x0D && PosFile < TailleFic )
                        {
                        if ( c == 0xFF )
                            Listing[ PosDest++ ] = '\t';
                        else
                                Listing[ PosDest++ ] = c;

                        c = BufFile[ PosFile++ ];
                        }
                    }
                Listing[ PosDest++ ] = '\r';
                Listing[ PosDest++ ] = '\n';
                }
            else
                {
                // Label
                while( c < 0x80 && c != 0x0D && PosFile < TailleFic )
                    {
                    Listing[ PosDest++ ] = c;
                    c = BufFile[ PosFile++ ];
                    }
                if ( c != 0x0D )
                    {
                    // Mnemonique apres label
                    // ENT
                    if ( c == 0xC9 )
                        Listing[ PosDest++ ] = ';';

                    if ( c != 0xFF )
                        {
                        sprintf( Tmp, "\t%s\t", MotCleDams[ c & 0x7F ] );
                        int l = strlen( Tmp );
                        memcpy( &Listing[ PosDest ], Tmp, l );
                        PosDest += l;
                        }
                    else
                        {
                        Listing[ PosDest++ ] = '\t';
                        Listing[ PosDest++ ] = '\t';
                        Listing[ PosDest++ ] = '\t';
                        }
                    // DS ?,?
                    if ( c == 0xC6 )
                        {
                        c = BufFile[ PosFile++ ];
                        // Fin de ligne
                        while( c != 0x0D && PosFile < TailleFic )
                            {
                            if ( c == ',' )
                                {
                                while( c != 0x0D && c != 0xFF && PosFile < TailleFic )
                                    c = BufFile[ PosFile++ ];
                                }
                            if ( c != 0x0D )
                                {
                                if ( c == 0xFF )
                                    {
                                    Listing[ PosDest++ ] = '\t';
                                    Listing[ PosDest++ ] = ';';
                                    }
                                else
                                    Listing[ PosDest++ ] = c;

                                c = BufFile[ PosFile++ ];
                                }
                            }
                        }
                    else
                        {
                        c = BufFile[ PosFile++ ];
                        // Fin de ligne
                        while( c != 0x0D && PosFile < TailleFic )
                            {
                            if ( c == 0xFF )
                                {
                                Listing[ PosDest++ ] = '\t';
                                Listing[ PosDest++ ] = ';';
                                }
                            else
                                Listing[ PosDest++ ] = c;

                            c = BufFile[ PosFile++ ];
                            }
                        }
                    Listing[ PosDest++ ] = '\r';
                    Listing[ PosDest++ ] = '\n';
                    }
                else
                    {
                    Listing[ PosDest++ ] = '\r';
                    Listing[ PosDest++ ] = '\n';
                    }
                }
            }
        c = BufFile[ PosFile++ ];
        if ( PosFile > TailleFic )
            break;
        }
}