MegaProcessor

Check-in [2dacb66e8e]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:More and more opcodes are now evaluated correctly.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:2dacb66e8e74ce174a66327f2cabcb62cb3ac7fc
User & Date: jos 2015-07-29 16:01:01
Context
2015-07-30
14:39
This version assembles about half of the instructions, good moment to commit :-) check-in: b07bb1c70e user: jos tags: trunk
2015-07-29
16:01
More and more opcodes are now evaluated correctly. check-in: 2dacb66e8e user: jos tags: trunk
2015-07-17
21:03
yet another small tool. check-in: 9b1ea624ff user: jos tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to asm.lua.

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

function ProcessLine( l )
    local asm_instr;
    local n,f1,f2,f3,f4 = Fields(l);

    if( n == 0 ) then return; end

    print( string.format("%d=%s - %s - %s - %s",n,f1,f2,f3,f4) );

    asm_instr = Directive[ string.lower(f2 or f3) ];
    if( asm_instr ) then print( asm_instr() ); end
    
    asm_instr = CPU_instr[ string.upper(f2 or f3) ];
   -- if( asm_instr ) then asm_instr = asm_instr[2]; print( asm_instr[2](f2,f3,f4) ); end
    if( asm_instr ) then 
        local b1, b2, b3 = asm_instr[2](f2,f3,f4);
        if( b1 ) then b1 = string.format("%02x",b1); end
        b1 = b1 or " ";
        if( b2 ) then b2 = string.format("%02x",b2); end
        b2 = b2 or "  ";
        if( b3 ) then b3 = string.format("%03x",b1); end
        b3 = b3 or "  ";

        print( string.format( "%s %s %s", b1, b2, b3 ) );
    end



end


-- Main line
--
if( not arg[1] ) then







<
<

|












|


>







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

function ProcessLine( l )
    local asm_instr;
    local n,f1,f2,f3,f4 = Fields(l);

    if( n == 0 ) then return; end



    asm_instr = Directive[ string.lower(f2 or f3) ];
    if( asm_instr ) then print( asm_instr() ); return; end
    
    asm_instr = CPU_instr[ string.upper(f2 or f3) ];
   -- if( asm_instr ) then asm_instr = asm_instr[2]; print( asm_instr[2](f2,f3,f4) ); end
    if( asm_instr ) then 
        local b1, b2, b3 = asm_instr[2](f2,f3,f4);
        if( b1 ) then b1 = string.format("%02x",b1); end
        b1 = b1 or " ";
        if( b2 ) then b2 = string.format("%02x",b2); end
        b2 = b2 or "  ";
        if( b3 ) then b3 = string.format("%03x",b1); end
        b3 = b3 or "  ";

        io.write( string.format( "%s %s %s", b1, b2, b3 ) );
    end

    io.write( string.format("%d=%s - %s - %s - %s\n",n,f1,f2,f3,f4) );

end


-- Main line
--
if( not arg[1] ) then

Changes to opcodes.lua.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
..
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
...
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
...
199
200
201
202
203
204
205
206





207
208
209
210
211
212
213
214
215
216
217
218

219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254


255
256
257
258


259
260
261
262


263
264
265
266
267
268
269
...
299
300
301
302
303
304
305
306

307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327


function do_ABS(f1, f2, f3)
    local retVal = 0x70;
    -- process f2 to select 0x75, 0x7a or 0x7f
    return retVal ; 
end

function do_ADD(f1, f2, f3)
    local retVal = 0x40;
    -- process f2 to select 0x40..0x4f
    return retVal ; 
end

function do_ADDI(f1, f2, f3)
    -- process f2 to determine value of 2nd returnvalue;
    return 0xf6, 0x00 ;
end

................................................................................
end

function do_ADDX(f1, f2, f3)
    return 0xfc;
end

function do_AND(f1, f2, f3)
    local retVal = 0x10;
    -- process f2 to select 0x10..0x1f
    return retVal ; 
end

function do_ASL(f1, f2, f3)


  print( f1, f2, f3 );

end

function do_ASL_WT(f1, f2, f3)

  print( f1, f2, f3 );

end

function do_ASR(f1, f2, f3)
  print( f1, f2, f3 );


end

function do_ASR_WT(f1, f2, f3)
  print( f1, f2, f3 );


end

function do_BCC(f1, f2, f3)
    return 0xe4, 0x00 ;
end

function do_BCHG(f1, f2, f3)
................................................................................
    return 0xe8, 0x00  ;
end

function do_BVS(f1, f2, f3)
    return 0xe9, 0x00  ;
end

function do_CLR(f1, f2, f3)
  print( f1, f2, f3 );

end

function do_CMP(f1, f2, f3)
  print( f1, f2, f3 );
end

function do_DEC(f1, f2, f3)
  print( f1, f2, f3 );
end

function do_DIVS(f1, f2, f3)
    return 0xfb  ;
end

function do_DIVU(f1, f2, f3)
    return 0xfa  ;
end

function do_INC(f1, f2, f3)
  print( f1, f2, f3 );
end

function do_INV(f1, f2, f3)
  print( f1, f2, f3 );

end

function do_JMP(f1, f2, f3)
  print( f1, f2, f3 );
end

function do_JSR(f1, f2, f3)
................................................................................
end

function do_LSR_WT(f1, f2, f3)
  print( f1, f2, f3 );
end

function do_MOVE(f1, f2, f3)
  print( f1, f2, f3 );





end

function do_MULS(f1, f2, f3)
    return 0xf9  ;
end

function do_MULU(f1, f2, f3)
    return 0xf8  ;
end

function do_NEG(f1, f2, f3)
  print( f1, f2, f3 );

end

function do_NEGX(f1, f2, f3)
    return 0xfe  ;
end

function do_OR(f1, f2, f3)
  print( f1, f2, f3 );
end

function do_NOP(f1, f2, f3)
  return 0xff  ;
end

function do_POP(f1, f2, f3)
  local b = f2:sub(-1);
  if( b == 'S' or b == 's' ) then return 0xc4 end
  return( 0xc0 + tonumber(b) );
end

function do_PUSH(f1, f2, f3)
  local b = f2:sub(-1);
  if( b == 'S' or b == 's' ) then return 0xcc end
  return( 0xc8 + tonumber(b) );
end

function do_RET(f1, f2, f3)
    return 0xc6 ;
end

function do_RETI(f1, f2, f3)
    return 0xc7 ;
end

function do_ROL(f1, f2, f3)
  print( f1, f2, f3 );


end

function do_ROL_WT(f1, f2, f3)
  print( f1, f2, f3 );


end

function do_ROR(f1, f2, f3)
  print( f1, f2, f3 );


end

function do_ROR_WT(f1, f2, f3)
  print( f1, f2, f3 );
end

function do_ROXL(f1, f2, f3)
................................................................................
end

function do_SUBX(f1, f2, f3)
  print( f1, f2, f3 );
end

function do_SXT(f1, f2, f3)
  print( f1, f2, f3 );

end

function do_TEST(f1, f2, f3)
    local retVal = 0x10; -- same as AND
    -- process f2 to select 0x10, 0x15, 0x1a, 0x1f
    return retVal ; 
end

function do_TRAP(f1, f2, f3)
  return 0xcd  ;
end

function do_XOR(f1, f2, f3)
  print( f1, f2, f3 );
end

CPU_instr = {
  ['ABS'] = { 1, do_ABS },
  ['ADD'] = { 1, do_ADD },
  ['ADDI'] = { 1, do_ADDI },
  ['ADDQ'] = { 1, do_ADDQ },
>


|
<
|



|
<
<







 







|
<
<



>
>

>



>

>




>
>




>
>







 







|
|
>



|


|
|










|
|



|
>







 







|
>
>
>
>
>











|
>







|








|





|













>
>




>
>




>
>







 







|
>



|
|
<



|



|







1
2
3
4

5
6
7
8
9


10
11
12
13
14
15
16
..
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
...
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
...
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
...
318
319
320
321
322
323
324
325
326
327
328
329
330
331

332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
require('eval_op');

function do_ABS(f1, f2, f3)
    local retVal = { [0] = 0x70, 0x75, 0x7a, 0x7f };

    return retVal[ isReg(f2) ] ; 
end

function do_ADD(f1, f2, f3)
    return( 0x40 + isReg2(f2,f3) );


end

function do_ADDI(f1, f2, f3)
    -- process f2 to determine value of 2nd returnvalue;
    return 0xf6, 0x00 ;
end

................................................................................
end

function do_ADDX(f1, f2, f3)
    return 0xfc;
end

function do_AND(f1, f2, f3)
    return( 0x10 + isReg2(f2,f3) );


end

function do_ASL(f1, f2, f3)
    local b1,b2 = 0xdc, 0x40;
    -- process f2 to select 0x40..0x4f, 0x50..0x5f, 0x60..0x63
  print( f1, f2, f3 );
    return b1, b2 ;
end

function do_ASL_WT(f1, f2, f3)
    local b1,b2 = 0x68, 0x00;
  print( f1, f2, f3 );
    return b1, b2 ;
end

function do_ASR(f1, f2, f3)
  print( f1, f2, f3 );
    local b1,b2 = 0x40, 0x00;
    return b1, b2 ;
end

function do_ASR_WT(f1, f2, f3)
  print( f1, f2, f3 );
    local b1,b2 = 0x40, 0x00;
    return b1, b2 ;
end

function do_BCC(f1, f2, f3)
    return 0xe4, 0x00 ;
end

function do_BCHG(f1, f2, f3)
................................................................................
    return 0xe8, 0x00  ;
end

function do_BVS(f1, f2, f3)
    return 0xe9, 0x00  ;
end

function do_CLR(f1, f2, f3)  -- alias for XOR Rx,Rx (xoring register with itself)
    local retVal = { [0]=0x20, 0x25, 0x2a, 0x2f };
    return( retVal[ isReg(f2) ] );
end

function do_CMP(f1, f2, f3)
    return( 0x70 + isReg2(f2,f3) );
end

function do_DEC(f1, f2, f3)  -- alias for ADDQ Rx,#-1
    return( 0x5c + isReg(f2) );
end

function do_DIVS(f1, f2, f3)
    return 0xfb  ;
end

function do_DIVU(f1, f2, f3)
    return 0xfa  ;
end

function do_INC(f1, f2, f3)  -- alias for ADDQ Rx,#1
    return( 0x54 + isReg(f2) );
end

function do_INV(f1, f2, f3)
    local retVal = { [0]=0x30, 0x35, 0x3a, 0x3f };
    return( retVal[ isReg(f2) ] );
end

function do_JMP(f1, f2, f3)
  print( f1, f2, f3 );
end

function do_JSR(f1, f2, f3)
................................................................................
end

function do_LSR_WT(f1, f2, f3)
  print( f1, f2, f3 );
end

function do_MOVE(f1, f2, f3)
    local n1 = isReg(f2);
    local n2 = isReg(f3);
    if( n1 == n2 ) then
        error("Cannot move register to itself");
    end
    return( 0x00 + n2*4 + n1 );
end

function do_MULS(f1, f2, f3)
    return 0xf9  ;
end

function do_MULU(f1, f2, f3)
    return 0xf8  ;
end

function do_NEG(f1, f2, f3)
    local retVal = { [0]=0x60, 0x65, 0x6a, 0x6f };
    return( retVal[ isReg(f2) ] );
end

function do_NEGX(f1, f2, f3)
    return 0xfe  ;
end

function do_OR(f1, f2, f3)
    return( 0x30 + isReg2(f2,f3) );
end

function do_NOP(f1, f2, f3)
  return 0xff  ;
end

function do_POP(f1, f2, f3)
  local b = f2:sub(-1);
  if( b == 'S' or b == 's' ) then return 0xc4 end   -- for POP PS
  return( 0xc0 + tonumber(b) );
end

function do_PUSH(f1, f2, f3)
  local b = f2:sub(-1);
  if( b == 'S' or b == 's' ) then return 0xcc end  -- for PUSH PS
  return( 0xc8 + tonumber(b) );
end

function do_RET(f1, f2, f3)
    return 0xc6 ;
end

function do_RETI(f1, f2, f3)
    return 0xc7 ;
end

function do_ROL(f1, f2, f3)
  print( f1, f2, f3 );
    local b1,b2 = 0xdc, 0x80;
    return b1, b2 ;
end

function do_ROL_WT(f1, f2, f3)
  print( f1, f2, f3 );
    local b1,b2 = 0xa8, 0x00;
    return b1, b2 ;
end

function do_ROR(f1, f2, f3)
  print( f1, f2, f3 );
    local b1,b2 = 0xb0, 0x00;
    return b1, b2 ;
end

function do_ROR_WT(f1, f2, f3)
  print( f1, f2, f3 );
end

function do_ROXL(f1, f2, f3)
................................................................................
end

function do_SUBX(f1, f2, f3)
  print( f1, f2, f3 );
end

function do_SXT(f1, f2, f3)
    local retVal = { [0]=0x00, 0x05, 0x0a, 0x0f };
    return( retVal[ isReg(f2) ] );
end

function do_TEST(f1, f2, f3)
    local retVal = { [0]=0x10, 0x15, 0x1a, 0x1f };
    return( retVal[ isReg(f2) ] );

end

function do_TRAP(f1, f2, f3)
  return 0xcd ;
end

function do_XOR(f1, f2, f3)
    return( 0x20 + isReg2(f2,f3) );
end

CPU_instr = {
  ['ABS'] = { 1, do_ABS },
  ['ADD'] = { 1, do_ADD },
  ['ADDI'] = { 1, do_ADDI },
  ['ADDQ'] = { 1, do_ADDQ },