root/doc_inner/doxygen/latex/disassemble_8c_source.tex

/* [<][>][^][v][top][bottom][index][help] */
\doxysection{disassemble.\+c}
\label{disassemble_8c_source}\index{src/disassemble.c@{src/disassemble.c}}
\textbf{ Go to the documentation of this file.}
\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{preprocessor}{\#include\ "{}disassemble.h"{}}}
\DoxyCodeLine{00002\ }
\DoxyCodeLine{00006\ \textcolor{keywordtype}{int}\ codecol\ =\ 32;}
\DoxyCodeLine{00007\ }
\DoxyCodeLine{00016\ WORD\ zero\_data\_cnt(\textcolor{keyword}{const}\ WORD\ *data,\ WORD\ wordlen);}
\DoxyCodeLine{00017\ }
\DoxyCodeLine{00026\ \textcolor{keywordtype}{void}\ disassemble\_puts\_code(\textcolor{keywordtype}{int}\ ascol,\ WORD\ pradr,\ \textcolor{keywordtype}{int}\ wordc,\ WORD\ wordv[]);}
\DoxyCodeLine{00027\ }
\DoxyCodeLine{00037\ \textcolor{keywordtype}{void}\ disassemble\_cmd\_adr\_x(CMDTYPE\ cmdtype,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *cmdname,\ WORD\ word,\ WORD\ adr,\ WORD\ pradr);}
\DoxyCodeLine{00038\ }
\DoxyCodeLine{00047\ \textcolor{keywordtype}{void}\ disassemble\_cmd\_r(CMDTYPE\ cmdtype,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *cmdname,\ WORD\ word,\ WORD\ pradr);}
\DoxyCodeLine{00048\ }
\DoxyCodeLine{00055\ \textcolor{keywordtype}{void}\ disassemble\_dc(WORD\ word,\ WORD\ pradr);}
\DoxyCodeLine{00056\ }
\DoxyCodeLine{00057\ \textcolor{keywordtype}{void}\ disassemble\_puts\_code(\textcolor{keywordtype}{int}\ ascol,\ WORD\ pradr,\ \textcolor{keywordtype}{int}\ wordc,\ WORD\ wordv[])}
\DoxyCodeLine{00058\ \{}
\DoxyCodeLine{00059\ \ \ \ \ \textcolor{keywordflow}{for}(\textcolor{keywordtype}{int}\ i\ =\ 0;\ i\ <\ codecol-\/ascol;\ i++)\{}
\DoxyCodeLine{00060\ \ \ \ \ \ \ \ \ fprintf(stdout,\ \textcolor{stringliteral}{"{}\ "{}});}
\DoxyCodeLine{00061\ \ \ \ \ \}}
\DoxyCodeLine{00062\ \ \ \ \ \textcolor{keywordflow}{if}(wordc\ ==\ 1)\ \{}
\DoxyCodeLine{00063\ \ \ \ \ \ \ \ \ fprintf(stdout,\ \textcolor{stringliteral}{"{};\ \#\%04X:\ \#\%04X"{}},\ pradr,\ wordv[0]);}
\DoxyCodeLine{00064\ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}(wordc\ ==\ 2)\ \{}
\DoxyCodeLine{00065\ \ \ \ \ \ \ \ \ fprintf(stdout,\ \textcolor{stringliteral}{"{};\ \#\%04X:\ \#\%04X\ \#\%04X"{}},\ pradr,\ wordv[0],\ wordv[1]);}
\DoxyCodeLine{00066\ \ \ \ \ \}}
\DoxyCodeLine{00067\ \}}
\DoxyCodeLine{00068\ }
\DoxyCodeLine{00069\ \textcolor{keywordtype}{void}\ disassemble\_cmd\_adr\_x(CMDTYPE\ cmdtype,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *cmdname,\ WORD\ word,\ WORD\ adr,\ WORD\ pradr)}
\DoxyCodeLine{00070\ \{}
\DoxyCodeLine{00071\ \ \ \ \ WORD\ x\ =\ 0;}
\DoxyCodeLine{00072\ \ \ \ \ \textcolor{keywordtype}{char}\ *g\ =\ NULL;}
\DoxyCodeLine{00073\ \ \ \ \ \textcolor{keywordtype}{int}\ cnt\ =\ 0;}
\DoxyCodeLine{00074\ }
\DoxyCodeLine{00075\ \ \ \ \ cnt\ +=\ fprintf(stdout,\ \textcolor{stringliteral}{"{}\ \ \ \ \ \ \ \ \%-\/7s\ "{}},\ cmdname);}
\DoxyCodeLine{00076\ \ \ \ \ \textcolor{keywordflow}{if}(cmdtype\ ==\ R\_ADR\_X)\ \{}
\DoxyCodeLine{00077\ \ \ \ \ \ \ \ \ cnt\ +=\ fprintf(stdout,\ \textcolor{stringliteral}{"{}\%s,"{}},\ g\ =\ grstr((word\ \&\ 0x00F0)\ >>\ 4));}
\DoxyCodeLine{00078\ \ \ \ \ \ \ \ \ FREE(g);}
\DoxyCodeLine{00079\ \ \ \ \ \}}
\DoxyCodeLine{00080\ \ \ \ \ cnt\ +=\ fprintf(stdout,\ \textcolor{stringliteral}{"{}\#\%04X"{}},\ adr);}
\DoxyCodeLine{00081\ \ \ \ \ \textcolor{keywordflow}{if}((x\ =\ (word\ \&\ 0x000F))\ !=\ 0)\ \{}
\DoxyCodeLine{00082\ \ \ \ \ \ \ \ \ cnt\ +=\ fprintf(stdout,\ \textcolor{stringliteral}{"{},\%s"{}},\ g\ =\ grstr(x));}
\DoxyCodeLine{00083\ \ \ \ \ \ \ \ \ FREE(g);}
\DoxyCodeLine{00084\ \ \ \ \ \}}
\DoxyCodeLine{00085\ \ \ \ \ disassemble\_puts\_code(cnt,\ pradr,\ 2,\ (WORD\ [])\{word,\ adr\});}
\DoxyCodeLine{00086\ \}}
\DoxyCodeLine{00087\ }
\DoxyCodeLine{00088\ \textcolor{keywordtype}{void}\ disassemble\_cmd\_r(CMDTYPE\ cmdtype,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *cmdname,\ WORD\ word,\ WORD\ pradr)}
\DoxyCodeLine{00089\ \{}
\DoxyCodeLine{00090\ \ \ \ \ \textcolor{keywordtype}{char}\ *g\ =\ NULL;}
\DoxyCodeLine{00091\ \ \ \ \ \textcolor{keywordtype}{char}\ *g1\ =\ NULL;}
\DoxyCodeLine{00092\ \ \ \ \ \textcolor{keywordtype}{char}\ *g2\ =\ NULL;}
\DoxyCodeLine{00093\ \ \ \ \ \textcolor{keywordtype}{int}\ cnt\ =\ 0;}
\DoxyCodeLine{00094\ }
\DoxyCodeLine{00095\ \ \ \ \ cnt\ +=\ fprintf(stdout,\ \textcolor{stringliteral}{"{}\ \ \ \ \ \ \ \ \%-\/7s\ "{}},\ cmdname);}
\DoxyCodeLine{00096\ \ \ \ \ \textcolor{keywordflow}{if}(cmdtype\ ==\ R1\_R2)\ \{}
\DoxyCodeLine{00097\ \ \ \ \ \ \ \ \ g1\ =\ grstr((word\ \&\ 0x00F0)\ >>\ 4);}
\DoxyCodeLine{00098\ \ \ \ \ \ \ \ \ g2\ =\ grstr(word\ \&\ 0x000F);}
\DoxyCodeLine{00099\ \ \ \ \ \ \ \ \ cnt\ +=\ fprintf(stdout,\ \textcolor{stringliteral}{"{}\%s,\%s"{}},\ g1,\ g2);}
\DoxyCodeLine{00100\ \ \ \ \ \ \ \ \ FREE(g1);}
\DoxyCodeLine{00101\ \ \ \ \ \ \ \ \ FREE(g2);}
\DoxyCodeLine{00102\ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}(cmdtype\ ==\ R\_)\ \{}
\DoxyCodeLine{00103\ \ \ \ \ \ \ \ \ g\ =\ grstr((word\ \&\ 0x00F0)\ >>\ 4);}
\DoxyCodeLine{00104\ \ \ \ \ \ \ \ \ cnt\ +=\ fprintf(stdout,\ \textcolor{stringliteral}{"{}\%s"{}},\ g);}
\DoxyCodeLine{00105\ \ \ \ \ \ \ \ \ FREE(g);}
\DoxyCodeLine{00106\ \ \ \ \ \}}
\DoxyCodeLine{00107\ \ \ \ \ disassemble\_puts\_code(cnt,\ pradr,\ 1,\ (WORD\ [])\{word\});}
\DoxyCodeLine{00108\ \}}
\DoxyCodeLine{00109\ }
\DoxyCodeLine{00110\ \textcolor{keywordtype}{void}\ disassemble\_dc(WORD\ word,\ WORD\ pradr)}
\DoxyCodeLine{00111\ \{}
\DoxyCodeLine{00112\ \ \ \ \ \textcolor{keywordtype}{int}\ cnt\ =\ 0;}
\DoxyCodeLine{00113\ }
\DoxyCodeLine{00114\ \ \ \ \ cnt\ =\ fprintf(stdout,\ \textcolor{stringliteral}{"{}\ \ \ \ \ \ \ \ DC\ \ \ \ \ \ \%-\/5d\ "{}},\ word);}
\DoxyCodeLine{00115\ \ \ \ \ disassemble\_puts\_code(cnt,\ pradr,\ 1,\ (WORD\ [])\{word\});}
\DoxyCodeLine{00116\ \ \ \ \ fprintf(stdout,\ \textcolor{stringliteral}{"{}\ ::"{}}\ );}
\DoxyCodeLine{00117\ \ \ \ \ print\_dumpword(word,\ \textcolor{keyword}{true});}
\DoxyCodeLine{00118\ \}}
\DoxyCodeLine{00119\ }
\DoxyCodeLine{00120\ \textcolor{keywordtype}{void}\ disassemble\_ds(WORD\ wcnt,\ WORD\ pradr)}
\DoxyCodeLine{00121\ \{}
\DoxyCodeLine{00122\ \ \ \ \ \textcolor{keywordtype}{int}\ cnt\ =\ 0;}
\DoxyCodeLine{00123\ }
\DoxyCodeLine{00124\ \ \ \ \ cnt\ =\ fprintf(stdout,\ \textcolor{stringliteral}{"{}\ \ \ \ \ \ \ \ DS\ \ \ \ \ \ \%-\/5d\ "{}},\ wcnt);}
\DoxyCodeLine{00125\ \ \ \ \ disassemble\_puts\_code(cnt,\ pradr,\ 1,\ (WORD\ [])\{0\});}
\DoxyCodeLine{00126\ \ \ \ \ \textcolor{keywordflow}{for}(\textcolor{keywordtype}{int}\ i\ =\ 1;\ i\ <\ wcnt;\ i++)\ \{}
\DoxyCodeLine{00127\ \ \ \ \ \ \ \ \ fprintf(stdout,\ \textcolor{stringliteral}{"{}\(\backslash\)n"{}});}
\DoxyCodeLine{00128\ \ \ \ \ \ \ \ \ disassemble\_puts\_code(0,\ pradr+i,\ 1,\ (WORD\ [])\{0\});}
\DoxyCodeLine{00129\ \ \ \ \ \}}
\DoxyCodeLine{00130\ \}}
\DoxyCodeLine{00131\ }
\DoxyCodeLine{00132\ WORD\ zero\_data\_cnt(\textcolor{keyword}{const}\ WORD\ *data,\ WORD\ wordlen)}
\DoxyCodeLine{00133\ \{}
\DoxyCodeLine{00134\ \ \ \ \ WORD\ cnt\ =\ 0;}
\DoxyCodeLine{00135\ \ \ \ \ \textcolor{keywordflow}{for}(cnt\ =\ 0;\ cnt\ <\ wordlen\ \&\&\ data[cnt]\ ==\ 0;\ cnt++)\ \{}
\DoxyCodeLine{00136\ \ \ \ \ \ \ \ \ ;}
\DoxyCodeLine{00137\ \ \ \ \ \}}
\DoxyCodeLine{00138\ \ \ \ \ \textcolor{keywordflow}{return}\ cnt;}
\DoxyCodeLine{00139\ \}}
\DoxyCodeLine{00140\ }
\DoxyCodeLine{00141\ \textcolor{keywordtype}{void}\ disassemble\_file(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *file)}
\DoxyCodeLine{00142\ \{}
\DoxyCodeLine{00143\ \ \ \ \ WORD\ *buf\ =\ NULL;}
\DoxyCodeLine{00144\ \ \ \ \ WORD\ endptr\ =\ 0;}
\DoxyCodeLine{00145\ \ \ \ \ WORD\ w\ =\ 0;}
\DoxyCodeLine{00146\ \ \ \ \ FILE\ *fp\ =\ NULL;}
\DoxyCodeLine{00147\ }
\DoxyCodeLine{00148\ \ \ \ \ assert(file\ !=\ NULL);}
\DoxyCodeLine{00149\ \ \ \ \ \textcolor{keywordflow}{if}((fp\ =\ fopen(file,\ \textcolor{stringliteral}{"{}rb"{}}))\ ==\ NULL)\ \{}
\DoxyCodeLine{00150\ \ \ \ \ \ \ \ \ perror(file);}
\DoxyCodeLine{00151\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return};}
\DoxyCodeLine{00152\ \ \ \ \ \}}
\DoxyCodeLine{00153\ }
\DoxyCodeLine{00154\ \ \ \ \ buf\ =\ calloc\_chk(MAX\_MEMSIZE,\ \textcolor{keyword}{sizeof}(WORD),\ \textcolor{stringliteral}{"{}disassemble\_file"{}});}
\DoxyCodeLine{00155\ \ \ \ \ \textcolor{keywordflow}{while}(fread(\&w,\ \textcolor{keyword}{sizeof}(WORD),\ 1,\ fp)\ ==\ 1)\ \{}
\DoxyCodeLine{00156\ \ \ \ \ \ \ \ \ buf[endptr++]\ =\ w;}
\DoxyCodeLine{00157\ \ \ \ \ \}}
\DoxyCodeLine{00158\ \ \ \ \ fclose(fp);}
\DoxyCodeLine{00159\ \ \ \ \textcolor{keywordflow}{if}\ (endptr\ ==\ 0)\ \{}
\DoxyCodeLine{00160\ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}\%s:\ empty\ or\ unreadable\ file\(\backslash\)n"{}},\ file);}
\DoxyCodeLine{00161\ \ \ \ \}\ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00162\ \ \ \ \ \ \ \ fprintf(stdout,\ \textcolor{stringliteral}{"{}MAIN\ \ \ \ START\(\backslash\)n"{}});}
\DoxyCodeLine{00163\ \ \ \ \ \ \ \ disassemble\_memory(buf,\ 0,\ endptr\ -\/\ 1);}
\DoxyCodeLine{00164\ \ \ \ \ \ \ \ fprintf(stdout,\ \textcolor{stringliteral}{"{}\ \ \ \ \ \ \ \ END\(\backslash\)n"{}});}
\DoxyCodeLine{00165\ \ \ \ \}}
\DoxyCodeLine{00166\ \ \ \ FREE(buf);}
\DoxyCodeLine{00167\ \}}
\DoxyCodeLine{00168\ }
\DoxyCodeLine{00169\ \textcolor{keywordtype}{void}\ disassemble\_memory(WORD\ *memory,\ WORD\ start,\ WORD\ end)}
\DoxyCodeLine{00170\ \{}
\DoxyCodeLine{00171\ \ \ \ \ WORD\ cmd\ =\ 0;}
\DoxyCodeLine{00172\ \ \ \ \ CMDTYPE\ cmdtype\ =\ 0;}
\DoxyCodeLine{00173\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *cmdname\ =\ NULL;}
\DoxyCodeLine{00174\ \ \ \ \ \textcolor{keywordtype}{bool}\ inprogram\ =\ \textcolor{keyword}{true};}
\DoxyCodeLine{00175\ \ \ \ \ WORD\ zcnt\ =\ 0;}
\DoxyCodeLine{00176\ }
\DoxyCodeLine{00177\ \ \ \ \ WORD\ ptr\ =\ start;}
\DoxyCodeLine{00178\ \ \ \ \ \textcolor{keywordflow}{while}(ptr\ <=\ end)\ \{}
\DoxyCodeLine{00179\ \ \ \ \ \ \ \ \ cmd\ =\ memory[ptr]\ \&\ 0xFF00;}
\DoxyCodeLine{00180\ \ \ \ \ \ \ \ \ cmdname\ =\ getcmdname(cmd);}
\DoxyCodeLine{00181\ \ \ \ \ \ \ \ \ cmdtype\ =\ getcmdtype(cmd);}
\DoxyCodeLine{00182\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}((cmd\ >\ 0\ \&\&\ cmdname\ !=\ NULL\ \&\&\ code\_gr\_valid(memory[ptr])\ ==\ \textcolor{keyword}{true})\ ||\ (inprogram\ ==\ \textcolor{keyword}{true}\ \&\&\ memory[ptr]\ ==\ 0))\ \{}
\DoxyCodeLine{00183\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}(cmdtype\ ==\ R\_ADR\_X\ ||\ cmdtype\ ==\ ADR\_X)\ \{}
\DoxyCodeLine{00184\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ disassemble\_cmd\_adr\_x(cmdtype,\ cmdname,\ memory[ptr],\ memory[ptr\ +\ 1],\ ptr);}
\DoxyCodeLine{00185\ \ \ \ \ \ \ \ \ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00186\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ disassemble\_cmd\_r(cmdtype,\ cmdname,\ memory[ptr],\ ptr);}
\DoxyCodeLine{00187\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00188\ \ \ \ \ \ \ \ \ \ \ \ \ ptr\ +=\ code2cmdwordlen(cmd);}
\DoxyCodeLine{00189\ \ \ \ \ \ \ \ \ \ \ \ \ inprogram\ =\ (cmd\ !=\ 0x8100)\ ?\ \textcolor{keyword}{true}\ :\ \textcolor{keyword}{false};}
\DoxyCodeLine{00190\ \ \ \ \ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00191\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}(memory[ptr]\ ==\ 0\ \&\&\ ((zcnt\ =\ zero\_data\_cnt(memory\ +\ ptr,\ end\ -\/\ ptr\ +\ 1))\ >\ 1\ ||\ ptr\ ==\ end))\ \{\ \textcolor{comment}{/*\ 0が2つ以上の場合とメモリー末尾の場合は、DSとみなす\ */}}
\DoxyCodeLine{00192\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ disassemble\_ds(zcnt,\ ptr);}
\DoxyCodeLine{00193\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ptr\ +=\ zcnt;}
\DoxyCodeLine{00194\ \ \ \ \ \ \ \ \ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00195\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ disassemble\_dc(memory[ptr],\ ptr);}
\DoxyCodeLine{00196\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ptr++;}
\DoxyCodeLine{00197\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00198\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00199\ \ \ \ \ \ \ \ \ fprintf(stdout,\ \textcolor{stringliteral}{"{}\(\backslash\)n"{}});}
\DoxyCodeLine{00200\ \ \ \ \ \}}
\DoxyCodeLine{00201\ \}}

\end{DoxyCode}

/* [<][>][^][v][top][bottom][index][help] */