Canola  0.8.D001
lib/calculator/on_opcode_ope_che.cc
Go to the documentation of this file.
00001 //
00002 // canola - canon canola 1614p emulator
00003 // Copyright (C) 2011, 2012 Peter Miller
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License, version 3, as
00007 // published by the Free Software Foundation.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License along
00015 // with this program. If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 
00018 #include <lib/calculator.h>
00019 
00020 
00021 void
00022 calculator::on_opcode_ope_che(opcode_t op, const location::pointer &where)
00023 {
00024     switch (op)
00025     {
00026     case opcode_zero:
00027         assert(!"this isn't supposed to be possible");
00028         break;
00029 
00030     case opcode_plus_equals:
00031     case opcode_minus_equals:
00032     case opcode_mul:
00033     case opcode_div:
00034     case opcode_sqrt:
00035         //
00036         // In clock_tick_mode == clock_tick_mode_entry, all sorts of
00037         // things are accepatable.  Otherwise is undefined, so take the
00038         // easy way out.
00039         //
00040         same_as_ope:
00041         on_opcode_ope(op, where);
00042         break;
00043 
00044     case opcode_ent:
00045         // <question>
00046         // What happens in OPE CHE when an ENT opcode is seen?
00047         // Does it display the x-register so you can enter a number?
00048         // Does the SJ key take you to address 1, like in OPE mode?
00049         // </question>
00050         goto same_as_ope;
00051 
00052     case opcode_sj:
00053         // <question>
00054         // What happens in OPE CHE when an SJ opcode is seen?
00055         // Does it display the x-register so you can decide?
00056         // Does the SJ key take you to the branch destination?
00057         // </question>
00058         switch (clock_tick_mode)
00059         {
00060         case clock_tick_mode_sj:
00061             address = find_flag_jump(next_opcode());
00062             clock_tick_mode = clock_tick_mode_disabled;
00063             break;
00064 
00065         case clock_tick_mode_disabled:
00066         case clock_tick_mode_running:
00067         case clock_tick_mode_entry:
00068         case clock_tick_mode_ej:
00069         default:
00070             on_error("'%s' not valid at the moment", opcode_name(op).c_str());
00071             break;
00072         }
00073         break;
00074 
00075     case opcode_ej:
00076         // <question>
00077         // What happens in OPE CHE when an EJ opcode is seen?
00078         // Does it display the x-register so you can enter a number?
00079         // Does the SJ key take you to address 1, like in OPE mode?
00080         // </question>
00081         goto same_as_ope;
00082 
00083     case opcode_mj:
00084     case opcode_uj:
00085     case opcode_fj:
00086     case opcode_suj:
00087     case opcode_sfj:
00088     case opcode_srj:
00089     case opcode_m1:
00090     case opcode_m2:
00091     case opcode_m3:
00092     case opcode_m4:
00093     case opcode_m5:
00094     case opcode_m6:
00095     case opcode_m7:
00096     case opcode_m8:
00097     case opcode_m9:
00098     case opcode_m10:
00099     case opcode_m11:
00100     case opcode_m12:
00101     case opcode_m13:
00102     case opcode_m14:
00103     case opcode_mm1:
00104     case opcode_mm2:
00105     case opcode_sm3:
00106     case opcode_sm4:
00107     case opcode_sm5:
00108     case opcode_sm6:
00109     case opcode_sm7:
00110     case opcode_sm8:
00111     case opcode_sm9:
00112     case opcode_sm10:
00113     case opcode_sm11:
00114     case opcode_sm12:
00115     case opcode_sm13:
00116     case opcode_sm14:
00117     case opcode_rm1:
00118     case opcode_rm2:
00119     case opcode_rm3:
00120     case opcode_rm4:
00121     case opcode_rm5:
00122     case opcode_rm6:
00123     case opcode_rm7:
00124     case opcode_rm8:
00125     case opcode_rm9:
00126     case opcode_rm10:
00127     case opcode_rm11:
00128     case opcode_rm12:
00129     case opcode_rm13:
00130     case opcode_rm14:
00131     case opcode_clear_indicator:
00132     case opcode_cm1:
00133     case opcode_cm2:
00134     case opcode_cm3:
00135     case opcode_cm4:
00136     case opcode_cm5:
00137     case opcode_cm6:
00138     case opcode_cm7:
00139     case opcode_cm8:
00140     case opcode_cm9:
00141     case opcode_cm10:
00142     case opcode_cm11:
00143     case opcode_cm12:
00144     case opcode_cm13:
00145     case opcode_cm14:
00146     case opcode_dot:
00147     case opcode_rv:
00148     case opcode_right:
00149     case opcode_chg_sign:
00150     case opcode_round_down:
00151     case opcode_round_off:
00152     case opcode_round_up:
00153     case opcode_print:
00154     case opcode_fd:
00155     case opcode_n0:
00156     case opcode_n1:
00157     case opcode_n2:
00158     case opcode_n3:
00159     case opcode_n4:
00160     case opcode_n5:
00161     case opcode_n6:
00162     case opcode_n7:
00163     case opcode_n8:
00164     case opcode_n9:
00165     case opcode_n10:
00166     case opcode_n11:
00167     case opcode_n12:
00168     case opcode_n13:
00169     case opcode_n14:
00170         goto same_as_ope;
00171 
00172     case opcode_extended_c:
00173         // Instruction Manual, p. 9
00174         //
00175         // "When the program is in OPERATION CHECK MODE (Program Mode Switch is
00176         // set in OPE CHE), the program is returned to step zero."
00177         //
00178         // <question>
00179         // In OPE CHE mode, does the C key also clear overflow?
00180         // Does it also clear x-register and y-register?
00181         // </question>
00182         address = 0;
00183         break;
00184 
00185     case opcode_extended_start:
00186         // Instruction Manual, p. 12
00187         //
00188         // "With the Program Mode Switch set to OPE CHE, depressing this
00189         // key checks the program calculation.  Each operation of this
00190         // key advances the program one step, followed by arithmetic
00191         // operation and display of the result."
00192         //
00193         switch (clock_tick_mode)
00194         {
00195         case clock_tick_mode_disabled:
00196         case clock_tick_mode_running:
00197         default:
00198             execute_one_instruction();
00199             break;
00200 
00201         case clock_tick_mode_entry:
00202             switch (mstate)
00203             {
00204             default:
00205                 assert(!"unknown mstate");
00206             case mstate_reset:
00207                 break;
00208 
00209             case mstate_lhs_digits_before_dot:
00210             case mstate_lhs_digits_after_dot:
00211             case mstate_lhs_complete:
00212                 mstate = mstate_lhs_complete;
00213                 // See the Printer Unit Instruction Manual, p. 11
00214                 //
00215                 // FIXME: it isn't that simple, see the Instruction manual,
00216                 // p. 45.  It would appear that any calculation performed also
00217                 // counts as entry for the purposes of "entry".
00218                 start_implies_print:
00219                 derived_print(x_register.get_display());
00220                 break;
00221 
00222             case mstate_mul:
00223                 break;
00224 
00225             case mstate_mul_digits_before_dot:
00226             case mstate_mul_digits_after_dot:
00227             case mstate_mul_complete:
00228                 mstate = mstate_mul_complete;
00229                 goto start_implies_print;
00230             }
00231             break;
00232 
00233         case clock_tick_mode_sj:
00234             next_opcode();
00235             break;
00236 
00237         case clock_tick_mode_ej:
00238             {
00239                 unsigned char label = next_opcode();
00240                 if (number_of_keys_since_ej > 0)
00241                 {
00242                     derived_print(x_register.get_display());
00243                     address = find_flag_jump(label);
00244                 }
00245             }
00246             break;
00247         }
00248         clock_tick_mode = clock_tick_mode_disabled;
00249         break;
00250 
00251     case opcode_extended_m3_tilde:
00252     case opcode_extended_sm3_tilde:
00253     case opcode_extended_rm3_tilde:
00254     case opcode_extended_cm3_tilde:
00255         assert(!"interpose_stateful was meant to fix this");
00256         break;
00257 
00258     case opcode_extended_off:
00259         goto same_as_ope;
00260 
00261     case opcode_extended_program_print:
00262         program_print();
00263         break;
00264 
00265     case opcode_extended_display_print:
00266     case opcode_extended_paper_feed:
00267         on_opcode_lrn(op, where);
00268         break;
00269 
00270     case opcode_extended_rounding_switch_up:
00271     case opcode_extended_rounding_switch_off:
00272     case opcode_extended_rounding_switch_down:
00273     case opcode_extended_decimal_point_selector_0:
00274     case opcode_extended_decimal_point_selector_1:
00275     case opcode_extended_decimal_point_selector_2:
00276     case opcode_extended_decimal_point_selector_3:
00277     case opcode_extended_decimal_point_selector_4:
00278     case opcode_extended_decimal_point_selector_5:
00279     case opcode_extended_decimal_point_selector_6:
00280     case opcode_extended_decimal_point_selector_7:
00281     case opcode_extended_decimal_point_selector_8:
00282     case opcode_extended_decimal_point_selector_9:
00283     case opcode_extended_decimal_point_selector_10:
00284     case opcode_extended_decimal_point_selector_11:
00285     case opcode_extended_decimal_point_selector_12:
00286     case opcode_extended_decimal_point_selector_float:
00287         goto same_as_ope;
00288 
00289     case opcode_extended_goto_000:
00290     case opcode_extended_goto_001:
00291     case opcode_extended_goto_002:
00292     case opcode_extended_goto_003:
00293     case opcode_extended_goto_004:
00294     case opcode_extended_goto_005:
00295     case opcode_extended_goto_006:
00296     case opcode_extended_goto_007:
00297     case opcode_extended_goto_008:
00298     case opcode_extended_goto_009:
00299     case opcode_extended_goto_010:
00300     case opcode_extended_goto_011:
00301     case opcode_extended_goto_012:
00302     case opcode_extended_goto_013:
00303     case opcode_extended_goto_014:
00304     case opcode_extended_goto_015:
00305     case opcode_extended_goto_100:
00306     case opcode_extended_goto_101:
00307     case opcode_extended_goto_102:
00308     case opcode_extended_goto_103:
00309     case opcode_extended_goto_104:
00310     case opcode_extended_goto_105:
00311     case opcode_extended_goto_106:
00312     case opcode_extended_goto_107:
00313     case opcode_extended_goto_108:
00314     case opcode_extended_goto_109:
00315     case opcode_extended_goto_110:
00316     case opcode_extended_goto_111:
00317     case opcode_extended_goto_112:
00318     case opcode_extended_goto_113:
00319     case opcode_extended_goto_114:
00320     case opcode_extended_goto_115:
00321     case opcode_extended_goto_200:
00322     case opcode_extended_goto_201:
00323     case opcode_extended_goto_202:
00324     case opcode_extended_goto_203:
00325     case opcode_extended_goto_204:
00326     case opcode_extended_goto_205:
00327     case opcode_extended_goto_206:
00328     case opcode_extended_goto_207:
00329     case opcode_extended_goto_208:
00330     case opcode_extended_goto_209:
00331     case opcode_extended_goto_210:
00332     case opcode_extended_goto_211:
00333     case opcode_extended_goto_212:
00334     case opcode_extended_goto_213:
00335     case opcode_extended_goto_214:
00336     case opcode_extended_goto_215:
00337     case opcode_extended_goto_300:
00338     case opcode_extended_goto_301:
00339     case opcode_extended_goto_302:
00340     case opcode_extended_goto_303:
00341     case opcode_extended_goto_304:
00342     case opcode_extended_goto_305:
00343     case opcode_extended_goto_306:
00344     case opcode_extended_goto_307:
00345     case opcode_extended_goto_308:
00346     case opcode_extended_goto_309:
00347     case opcode_extended_goto_310:
00348     case opcode_extended_goto_311:
00349     case opcode_extended_goto_312:
00350     case opcode_extended_goto_313:
00351     case opcode_extended_goto_314:
00352     case opcode_extended_goto_315:
00353     case opcode_extended_goto_400:
00354     case opcode_extended_goto_401:
00355     case opcode_extended_goto_402:
00356     case opcode_extended_goto_403:
00357     case opcode_extended_goto_404:
00358     case opcode_extended_goto_405:
00359     case opcode_extended_goto_406:
00360     case opcode_extended_goto_407:
00361     case opcode_extended_goto_408:
00362     case opcode_extended_goto_409:
00363     case opcode_extended_goto_410:
00364     case opcode_extended_goto_411:
00365     case opcode_extended_goto_412:
00366     case opcode_extended_goto_413:
00367     case opcode_extended_goto_414:
00368     case opcode_extended_goto_415:
00369     case opcode_extended_goto_500:
00370     case opcode_extended_goto_501:
00371     case opcode_extended_goto_502:
00372     case opcode_extended_goto_503:
00373     case opcode_extended_goto_504:
00374     case opcode_extended_goto_505:
00375     case opcode_extended_goto_506:
00376     case opcode_extended_goto_507:
00377     case opcode_extended_goto_508:
00378     case opcode_extended_goto_509:
00379     case opcode_extended_goto_510:
00380     case opcode_extended_goto_511:
00381     case opcode_extended_goto_512:
00382     case opcode_extended_goto_513:
00383     case opcode_extended_goto_514:
00384     case opcode_extended_goto_515:
00385     case opcode_extended_goto_600:
00386     case opcode_extended_goto_601:
00387     case opcode_extended_goto_602:
00388     case opcode_extended_goto_603:
00389     case opcode_extended_goto_604:
00390     case opcode_extended_goto_605:
00391     case opcode_extended_goto_606:
00392     case opcode_extended_goto_607:
00393     case opcode_extended_goto_608:
00394     case opcode_extended_goto_609:
00395     case opcode_extended_goto_610:
00396     case opcode_extended_goto_611:
00397     case opcode_extended_goto_612:
00398     case opcode_extended_goto_613:
00399     case opcode_extended_goto_614:
00400     case opcode_extended_goto_615:
00401     case opcode_extended_goto_700:
00402     case opcode_extended_goto_701:
00403     case opcode_extended_goto_702:
00404     case opcode_extended_goto_703:
00405     case opcode_extended_goto_704:
00406     case opcode_extended_goto_705:
00407     case opcode_extended_goto_706:
00408     case opcode_extended_goto_707:
00409     case opcode_extended_goto_708:
00410     case opcode_extended_goto_709:
00411     case opcode_extended_goto_710:
00412     case opcode_extended_goto_711:
00413     case opcode_extended_goto_712:
00414     case opcode_extended_goto_713:
00415     case opcode_extended_goto_714:
00416     case opcode_extended_goto_715:
00417         goto same_as_ope;
00418 
00419     default:
00420         on_error("%s: %d: undefined 0x%02X opcode", __FILE__, __LINE__, op);
00421         break;
00422     }
00423 }