Previous 199869 Revisions Next

r26264 Monday 18th November, 2013 at 16:11:49 UTC by Jürgen Buchmüller
Fix the alu_74181 function. Now using ALU.a10 as lookup for accuracy.
[/branches/alto2/src/emu/cpu/alto2]alto2.c alto2.h

branches/alto2/src/emu/cpu/alto2/alto2.c
r26263r26264
23462346 * </PRE>
23472347 */
23482348
2349enum {
2350    A10_UNUSED  = (1 << 0),
2351    A10_TSELECT = (1 << 1),
2352    A10_ALUCI   = (1 << 2),
2353    A10_ALUM    = (1 << 3),
2354    A10_ALUS0   = (1 << 4),
2355    A10_ALUS1   = (1 << 5),
2356    A10_ALUS2   = (1 << 6),
2357    A10_ALUS3   = (1 << 7),
2358    A10_ALUIN   = (A10_ALUM|A10_ALUCI|A10_ALUS0|A10_ALUS1|A10_ALUS2|A10_ALUS3)
2359};
2360
23492361//! S function, M flag and C carry in
2350#define   SMC(s3,s2,s1,s0,m,c) (((s3)<<7)|((s2)<<6)|((s1)<<5)|((s0)<<4)|((m)<<3)|((c)<<2))
2362#define   SMC(s3,s2,s1,s0,m,ci) (s3*A10_ALUS3 + s2*A10_ALUS2 + s1*A10_ALUS1 + s0*A10_ALUS0 + m*A10_ALUM + ci*A10_ALUCI)
23512363
23522364/**
2353 * @brief Compute the 74181 ALU operation smc
2365 * @brief Compute the 74181 ALU operation smc for inputs a and b
2366 *
2367 * The function, arithmetic / logic flag and carry in define the
2368 * ALU operation. The carry in is irrelevant for the logic operations.
2369 * The result is 17 bit, where bit #16 is the carry out.
2370 *
23542371 * @param smc S function [0-15], M arithmetic/logic flag, C carry
23552372 * @return resulting ALU output
23562373 */
2357UINT32 alto2_cpu_device::alu_74181(UINT32 smc)
2374UINT32 alto2_cpu_device::alu_74181(UINT32 a, UINT32 b, UINT8 smc)
23582375{
2359   register UINT32 a = m_bus;
2360   register UINT32 b = m_t;
2361   register UINT32 s = 0;
2362   register UINT32 f = 0;
2376   register UINT32 f;
2377   register const UINT32 cout = 1 << 16;
23632378
2364   switch (smc & SMC(1,1,1,1, 1, 1)) {
2379   switch (smc & A10_ALUIN) {
23652380   case SMC(0,0,0,0, 0, 0): // 0000: A + 1
23662381      f = a + 1;
23672382      break;
r26263r26264
23702385      f = a;
23712386      break;
23722387
2388   case SMC(0,0,0,0, 1, 0): // 0000: A'
2389   case SMC(0,0,0,0, 1, 1):
2390      f = (~a) | cout;
2391      break;
2392
23732393   case SMC(0,0,0,1, 0, 0): // 0001: (A | B) + 1
23742394      f = (a | b) + 1;
23752395      break;
r26263r26264
23782398      f = a | b;
23792399      break;
23802400
2401   case SMC(0,0,0,1, 1, 0): // 0001: A' | B'
2402   case SMC(0,0,0,1, 1, 1):
2403      f = (~a | ~b) | cout;
2404      break;
2405
23812406   case SMC(0,0,1,0, 0, 0): // 0010: (A | B') + 1
23822407      f = (a | ~b) + 1;
23832408      break;
r26263r26264
23862411      f = a | ~b;
23872412      break;
23882413
2414   case SMC(0,0,1,0, 1, 0): // 0010: A' & B
2415   case SMC(0,0,1,0, 1, 1):
2416      f = (~a & b) | cout;
2417      break;
2418
23892419   case SMC(0,0,1,1, 0, 0): // 0011: -1 + 1
2390      s = 1;
2391      f = -1 + 1;
2420      f = (-1 + 1) | cout;
23922421      break;
23932422
23942423   case SMC(0,0,1,1, 0, 1): // 0011: -1
2395      s = 1;
2396      f = -1;
2424      f = (-1) | cout;
23972425      break;
23982426
2427   case SMC(0,0,1,1, 1, 0): // 0011: logic 0
2428   case SMC(0,0,1,1, 1, 1):
2429      f = cout;
2430      break;
2431
23992432   case SMC(0,1,0,0, 0, 0): // 0100: A + (A & B') + 1
24002433      f = a + (a & ~b) + 1;
24012434      break;
r26263r26264
24042437      f = a + (a & ~b);
24052438      break;
24062439
2440   case SMC(0,1,0,0, 1, 0): // 0100: (A & B)'
2441   case SMC(0,1,0,0, 1, 1):
2442      f = ~(a & b) | cout;
2443      break;
2444
24072445   case SMC(0,1,0,1, 0, 0): // 0101: (A | B) + (A & B') + 1
24082446      f = (a | b) + (a & ~b) + 1;
24092447      break;
r26263r26264
24122450      f = (a | b) + (a & ~b);
24132451      break;
24142452
2453   case SMC(0,1,0,1, 1, 0): // 0101: B'
2454   case SMC(0,1,0,1, 1, 1):
2455      f = (~b) | cout;
2456      break;
2457
24152458   case SMC(0,1,1,0, 0, 0): // 0110: A - B - 1 + 1
2416      s = 1;
2417      f = a - b - 1 + 1;
2459      f = (a - b - 1 + 1)  ^ cout;
24182460      break;
24192461
24202462   case SMC(0,1,1,0, 0, 1): // 0110: A - B - 1
2421      s = 1;
2422      f = a - b - 1;
2463      f = (a - b - 1) ^ cout;
24232464      break;
24242465
2466   case SMC(0,1,1,0, 1, 0): // 0110: A ^ B
2467   case SMC(0,1,1,0, 1, 1):
2468      f = (a ^ b) | cout;
2469      break;
2470
24252471   case SMC(0,1,1,1, 0, 0): // 0111: (A & B) - 1 + 1
2426      s = 1;
2427      f = (a & b) - 1 + 1;
2472      f = ((a & b) - 1 + 1) ^ cout;
24282473      break;
24292474
24302475   case SMC(0,1,1,1, 0, 1): // 0111: (A & B) - 1
2431      s = 1;
2432      f = (a & b) - 1;
2476      f = ((a & b) - 1) ^ cout;
24332477      break;
24342478
2479   case SMC(0,1,1,1, 1, 0): // 0111: A & B'
2480   case SMC(0,1,1,1, 1, 1):
2481      f = (a & ~b) | cout;
2482      break;
2483
24352484   case SMC(1,0,0,0, 0, 0): // 1000: A + (A & B) + 1
24362485      f = a + (a & b) + 1;
24372486      break;
r26263r26264
24402489      f = a + (a & b);
24412490      break;
24422491
2492   case SMC(1,0,0,0, 1, 0): // 1000: A' | B
2493   case SMC(1,0,0,0, 1, 1):
2494      f = (~a | b) | cout;
2495      break;
2496
24432497   case SMC(1,0,0,1, 0, 0): // 1001: A + B + 1
24442498      f = a + b + 1;
24452499      break;
r26263r26264
24482502      f = a + b;
24492503      break;
24502504
2505   case SMC(1,0,0,1, 1, 0): // 1001: A' ^ B'
2506   case SMC(1,0,0,1, 1, 1):
2507      f = (~a ^ ~b) | cout;
2508      break;
2509
24512510   case SMC(1,0,1,0, 0, 0): // 1010: (A | B') + (A & B) + 1
24522511      f = (a | ~b) + (a & b) + 1;
24532512      break;
r26263r26264
24562515      f = (a | ~b) + (a & b);
24572516      break;
24582517
2518   case SMC(1,0,1,0, 1, 0): // 1010: B
2519   case SMC(1,0,1,0, 1, 1):
2520      f = (b) | cout;
2521      break;
2522
24592523   case SMC(1,0,1,1, 0, 0): // 1011: (A & B) - 1 + 1
2460      s = 1;
2461      f = (a & b) - 1 + 1;
2524      f = ((a & b) - 1 + 1) ^ cout;
24622525      break;
24632526
24642527   case SMC(1,0,1,1, 0, 1): // 1011: (A & B) - 1
2465      s = 1;
2466      f = (a & b) - 1;
2528      f = ((a & b) - 1)  ^ cout;
24672529      break;
24682530
2531   case SMC(1,0,1,1, 1, 0): // 1011: A & B
2532   case SMC(1,0,1,1, 1, 1):
2533      f = (a & b) | cout;
2534      break;
2535
24692536   case SMC(1,1,0,0, 0, 0): // 1100: A + A + 1
24702537      f = a + a + 1;
24712538      break;
r26263r26264
24742541      f = a + a;
24752542      break;
24762543
2544   case SMC(1,1,0,0, 1, 0): // 1100: logic 1
2545   case SMC(1,1,0,0, 1, 1):
2546      f = (~0) | cout;
2547      break;
2548
24772549   case SMC(1,1,0,1, 0, 0): // 1101: (A | B) + A + 1
24782550      f = (a | b) + a + 1;
24792551      break;
r26263r26264
24822554      f = (a | b) + a;
24832555      break;
24842556
2557   case SMC(1,1,0,1, 1, 0): // 1101: A | B'
2558   case SMC(1,1,0,1, 1, 1):
2559      f = (a | ~b) | cout;
2560      break;
2561
24852562   case SMC(1,1,1,0, 0, 0): // 1110: (A | B') + A + 1
24862563      f = (a | ~b) + a + 1;
24872564      break;
r26263r26264
24902567      f = (a | ~b) + a;
24912568      break;
24922569
2570   case SMC(1,1,1,0, 1, 0): // 1110: A | B
2571   case SMC(1,1,1,0, 1, 1):
2572      f = (a | b) | cout;
2573      break;
2574
24932575   case SMC(1,1,1,1, 0, 0): // 1111: A - 1 + 1
2494      s = 1;
2495      f = a - 1 + 1;
2576      f = (a - 1 + 1) ^ cout;
24962577      break;
24972578
24982579   case SMC(1,1,1,1, 0, 1): // 1111: A - 1
2499      s = 1;
2500      f = a - 1;
2580      f = (a - 1) ^ cout;
25012581      break;
25022582
2503   case SMC(0,0,0,0, 1, 0): // 0000: A'
2504   case SMC(0,0,0,0, 1, 1):
2505      f = ~a;
2506      break;
2507
2508   case SMC(0,0,0,1, 1, 0): // 0001: A' | B'
2509   case SMC(0,0,0,1, 1, 1):
2510      f = ~a | ~b;
2511      break;
2512
2513   case SMC(0,0,1,0, 1, 0): // 0010: A' & B
2514   case SMC(0,0,1,0, 1, 1):
2515      f = ~a & b;
2516      break;
2517
2518   case SMC(0,0,1,1, 1, 0): // 0011: logic 0
2519   case SMC(0,0,1,1, 1, 1):
2520      f = 0;
2521      break;
2522
2523   case SMC(0,1,0,0, 1, 0): // 0100: (A & B)'
2524   case SMC(0,1,0,0, 1, 1):
2525      f = ~(a & b);
2526      break;
2527
2528   case SMC(0,1,0,1, 1, 0): // 0101: B'
2529   case SMC(0,1,0,1, 1, 1):
2530      f = ~b;
2531      break;
2532
2533   case SMC(0,1,1,0, 1, 0): // 0110: A ^ B
2534   case SMC(0,1,1,0, 1, 1):
2535      f = a ^ b;
2536      break;
2537
2538   case SMC(0,1,1,1, 1, 0): // 0111: A & B'
2539   case SMC(0,1,1,1, 1, 1):
2540      f = a & ~b;
2541      break;
2542
2543   case SMC(1,0,0,0, 1, 0): // 1000: A' | B
2544   case SMC(1,0,0,0, 1, 1):
2545      f = ~a | b;
2546      break;
2547
2548   case SMC(1,0,0,1, 1, 0): // 1001: A' ^ B'
2549   case SMC(1,0,0,1, 1, 1):
2550      f = ~a ^ ~b;
2551      break;
2552
2553   case SMC(1,0,1,0, 1, 0): // 1010: B
2554   case SMC(1,0,1,0, 1, 1):
2555      f = b;
2556      break;
2557
2558   case SMC(1,0,1,1, 1, 0): // 1011: A & B
2559   case SMC(1,0,1,1, 1, 1):
2560      f = a & b;
2561      break;
2562
2563   case SMC(1,1,0,0, 1, 0): // 1100: logic 1
2564   case SMC(1,1,0,0, 1, 1):
2565      f = ~0;
2566      break;
2567
2568   case SMC(1,1,0,1, 1, 0): // 1101: A | B'
2569   case SMC(1,1,0,1, 1, 1):
2570      f = a | ~b;
2571      break;
2572
2573   case SMC(1,1,1,0, 1, 0): // 1110: A | B
2574   case SMC(1,1,1,0, 1, 1):
2575      f = a | b;
2576      break;
2577
25782583   case SMC(1,1,1,1, 1, 0): // 1111: A
25792584   case SMC(1,1,1,1, 1, 1):
2580      f = a;
2585      f = (a) | cout;
25812586      break;
25822587   }
2583   if (smc & 2) {
2584      m_aluc0 = ((f >> 16) ^ s) & 1;
2585   } else {
2586      m_aluc0 = 1;
2587   }
25882588   return f;
25892589}
25902590#endif
25912591
25922592/** @brief flag that tells whether to load the T register from BUS or ALU */
2593#define   TSELECT   (1 << 1)
2593#define   TSELECT   A10_TSELECT
25942594
25952595/** @brief flag that tells wheter operation was 0: logic (M=1) or 1: arithmetic (M=0) */
2596#define   ALUM2   (1 << 3)
2596#define   ALUM2   A10_ALUM
25972597
25982598/** @brief execute the CPU for at most nsecs nano seconds */
25992599void alto2_cpu_device::execute_run()
r26263r26264
26032603
26042604   do {
26052605      int do_bs, flags;
2606      UINT32 alu;
26072606
26082607      /*
26092608       * Subtract the microcycle time from the display time accu.
r26263r26264
27342733      // B4: ALUS0'   B5: ALUS1'   B6: ALUS2'   B7: ALUS3'
27352734      // B3-B7 are inverted on loading the PROM
27362735      UINT8 a10 = m_alu_a10[(m_emu.skip << 4) | aluf];
2737      alu = alu_74181(a10);
2736      UINT32 alu = alu_74181(m_bus, m_t, a10);
2737      m_aluc0 = (alu >> 16) & 1;
27382738      flags = (a10 ^ ALUM2) & (TSELECT | ALUM2);
2739      m_alu = static_cast<UINT16>(alu);
27392740#else
2741      UINT32 alu;
27402742      /* compute the ALU function */
27412743      switch (aluf) {
27422744      /**
r26263r26264
29242926      /**
29252927       * 16: ALU ← BUS
29262928       * PROM data for S3-0:1111 M:1 C:0 T:1
2927       * 74181 perhaps F=0 (0011/0/0)
2928       * T source is BUS
2929       * 74181 function F=A
2930       * T source is ALU
29292931       */
29302932      case aluf_undef_16:
29312933         alu = m_bus;
r26263r26264
29372939      /**
29382940       * 17: ALU ← BUS
29392941       * PROM data for S3-0:1111 M:1 C:0 T:1
2940       * 74181 perhaps F=~0 (0011/0/1)
2941       * T source is BUS
2942       * 74181 function F=A
2943       * T source is ALU
29422944       */
29432945      case aluf_undef_17:
29442946      default:
r26263r26264
29472949         flags = TSELECT;
29482950         LOG((LOG_CPU,0,"   ALU← 0 (illegal aluf in task %s, mpc:%05o aluf:%02o)\n", task_name(m_task), m_mpc, aluf));
29492951      }
2952      m_alu = static_cast<UINT16>(alu);
29502953#endif
2951      m_alu = static_cast<UINT16>(alu);
29522954
29532955      /* WRTRAM now, before L is changed */
29542956      if (m_wrtram_flag)
branches/alto2/src/emu/cpu/alto2/alto2.h
r26263r26264
2424#endif
2525
2626#define   USE_PRIO_F9318         0   //!< define to 1 to use the F9318 priority encoder code
27#define   USE_ALU_74181         0   //!< define to 1 to use the SN74181 ALU code
27#define   USE_ALU_74181         1   //!< define to 1 to use the SN74181 ALU code
2828#define   DEBUG_DISPLAY_TIMING   0   //!< define to 1 to debug the display timing
2929#define   USE_BITCLK_TIMER      0   //!< define to 1 to use a very high rate timer for the disk bit clock
3030#define   ALTO2_HAMMING_CHECK      0   //!< define to 1 to incorporate the Hamming code and Parity check
r26263r26264
11111111   void f2_load_md_1();                     //!< f2_load_md late: load memory data
11121112
11131113   UINT8* m_alu_a10;                        //!< ALU function to 74181 operation lookup PROM
1114   UINT32 alu_74181(UINT32 smc);
1114   UINT32 alu_74181(UINT32 a, UINT32 b, UINT8 smc);
11151115
11161116   void rdram();                           //!< read the microcode ROM/RAM halfword
11171117   void wrtram();                           //!< write the microcode RAM from M register and ALU

Previous 199869 Revisions Next


© 1997-2024 The MAME Team