1 /* pMARS -- a portable Memory Array Redcode Simulator
2  * Copyright (C) 1993-1996 Albert Ma, Na'ndor Sieben, Stefan Strack and Mintardjo Wangsawidjaja
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  */
18 
19 /*
20  * disasm.c: functions to turn core cell data into printable string
21  * $Id: disasm.c,v 1.1.1.1 2000/08/20 13:29:32 iltzu Exp $
22  */
23 
24 #include "global.h"
25 #include "asm.h"
26 #include "sim.h"
27 
28 #define denormalize(x) \
29     ((x) > coreSize / 2 ? ((int) (x) - coreSize) : (int) (x))
30 
31 #ifdef DOS16
32 typedef mem_struct FAR mem_st;
33 #else
34 typedef mem_struct mem_st;
35 #endif
36 
37 /* whether INITIALINST is displayed or not */
38 #define HIDE 0
39 #define SHOW 1
40 
41 /* ******************************************************************** */
42 
43 char   *
cellview(cell,outp,emptyDisp)44 cellview(cell, outp, emptyDisp)
45 #ifdef DOS16
46   mem_struct far *cell;
47 #else
48   mem_struct *cell;
49 #endif
50   char   *outp;
51   int     emptyDisp;
52 {
53   FIELD_T opcode, modifier;
54 
55   opcode = ((FIELD_T) (cell->opcode & 0xf8)) >> 3;
56   modifier = (cell->opcode & 0x07);
57 
58   if ((emptyDisp == SHOW) || (cell->opcode != INITIALINST.opcode) ||
59       (cell->A_mode != INITIALINST.A_mode) || (cell->A_value != INITIALINST.A_value) ||
60       (cell->B_mode != INITIALINST.B_mode) || (cell->B_value != INITIALINST.B_value) ||
61       (cell->debuginfo != INITIALINST.debuginfo))
62     sprintf(outp, "%3s%c%-2s %c%6d, %c%6d %4s",
63             opname[opcode],
64             SWITCH_8 ? ' ' : '.', SWITCH_8 ? "  " : modname[modifier],
65 #ifdef NEW_MODES
66             INDIR_A(cell->A_mode) ? addr_sym[INDIR_A_TO_SYM(cell->A_mode)] :
67 #endif
68             addr_sym[cell->A_mode], denormalize(cell->A_value),
69 #ifdef NEW_MODES
70             INDIR_A(cell->B_mode) ? addr_sym[INDIR_A_TO_SYM(cell->B_mode)] :
71 #endif
72             addr_sym[cell->B_mode], denormalize(cell->B_value),
73 #ifdef SERVER
74             "");
75 #else
76             cell->debuginfo ? "T" : "");
77 #endif
78   else
79     *outp = 0;
80 
81   return (outp);
82 }
83 
84 /* ******************************************************************** */
85 
86 char   *
locview(loc,outp)87 locview(loc, outp)
88   ADDR_T  loc;
89   char   *outp;
90 {
91   char    buf[MAXALLCHAR];
92   sprintf(outp, "%05d   %s\n", loc, cellview(memory + loc, buf, HIDE));
93   return (outp);
94 }
95 
96 /* ******************************************************************** */
97 
98 void
disasm(cells,n,offset)99 disasm(cells, n, offset)
100   mem_struct *cells;
101   ADDR_T  n, offset;
102 {
103   ADDR_T  i;
104   char    buf[MAXALLCHAR];
105 
106   if (SHOW && !SWITCH_8 && (offset >= 0) && (offset < n))
107     fprintf(STDOUT, "%-6s %3s%3s  %6s\n", "", "ORG", "", "START");
108 
109   for (i = 0; i < n; ++i)
110     fprintf(STDOUT, "%-6s %s\n", i == offset ? "START" : "",
111 #ifdef DOS16
112             cellview((mem_struct far *) cells + i, buf, SHOW));
113 #else
114             cellview((mem_struct *) cells + i, buf, SHOW));
115 #endif
116 
117   if (SHOW && SWITCH_8 && (offset >= 0) && (offset < n))
118     fprintf(STDOUT, "%-6s %3s%3s  %6s\n", "", "END", "", "START");
119 }
120