changeset 156:a68751e6e84f src

Use more common sense values for div 0. I.E. As close to infinity as a 16 bit number can get! Also avoid div 0 exception for MOD operation. I.E. 10 % 0 gives a crash with the message "Floating point exception" on my PC.
author jcdutton
date Sat, 05 Apr 2003 21:23:02 +0000
parents 840e99bfb57d
children 7094c8661c05
files decoder.c
diffstat 1 files changed, 9 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/decoder.c	Sat Apr 05 16:45:45 2003 +0000
+++ b/decoder.c	Sat Apr 05 21:23:02 2003 +0000
@@ -426,21 +426,25 @@
       break;
     case 5:
       tmp = get_GPRM(command->registers, reg) * data;
-      if(tmp >= shortmax) tmp = shortmax;
+      if(tmp > shortmax) tmp = shortmax;
       set_GPRM(command->registers, reg, (uint16_t)tmp);
       break;
     case 6:
       if (data != 0) {
         set_GPRM(command->registers, reg, (get_GPRM(command->registers, reg) / data) );
       } else {
-        set_GPRM(command->registers, reg, 0); /* Avoid that divide by zero! */
+        set_GPRM(command->registers, reg, 0xffff); /* Avoid that divide by zero! */
       }
       break;
     case 7:
-      set_GPRM(command->registers, reg, (get_GPRM(command->registers, reg) % data) );
+      if (data != 0) {
+        set_GPRM(command->registers, reg, (get_GPRM(command->registers, reg) % data) );
+      } else {
+        set_GPRM(command->registers, reg, 0xffff); /* Avoid that divide by zero! */
+      }
       break;
-    case 8: /* SPECIAL CASE - RND! */
-      set_GPRM(command->registers, reg, ((uint16_t) ((float) data * rand()/(RAND_MAX+1.0))) );
+    case 8: /* SPECIAL CASE - RND! Return numbers between 1 and data. */
+      set_GPRM(command->registers, reg, 1 + ((uint16_t) ((float) data * rand()/(RAND_MAX+1.0))) );
       break;
     case 9:
       set_GPRM(command->registers, reg, (get_GPRM(command->registers, reg) & data) );