X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=rtl%2FSYSTEM.java;h=20cbe60f2115f1167d1076d32f81b2f7a3040386;hb=789adb9354da345b13aa284f3f4f8f1046cadbc4;hp=68f82bd0983c3ee348507e7903023dc63318cf8c;hpb=75d0fd92a5342358f37ed9369ccce9355273e51a;p=dsw-obn.git diff --git a/rtl/SYSTEM.java b/rtl/SYSTEM.java index 68f82bd..20cbe60 100644 --- a/rtl/SYSTEM.java +++ b/rtl/SYSTEM.java @@ -17,18 +17,24 @@ public class SYSTEM return i; } + public static String STRING(byte[] x) + { + return new String(x, 0, LEN(x)); + } + public static void COPY(byte[] x, byte[] v) { - int len_x = LEN(x); - int len_v = v.length - 1; + int ix = LEN(x); + int iv = v.length - 1; - int len = (len_x < len_v) ? (len_x) : (len_v); - for(int i = 0; i < len; i++) + int i = 0; + int len = (ix < iv) ? (ix) : (iv); + while(i < len) { v[i] = x[i]; + i += 1; } - - v[len] = 0; + v[i] = 0; } public static int STRCMP(byte[] a, byte[] b) @@ -66,9 +72,59 @@ public class SYSTEM { throw new RuntimeException("WITH TRAP"); } + else if(n == -3) + { + throw new RuntimeException("NOT IMPLEMENTED"); + } else { throw new RuntimeException("TRAP CODE " + n); } } + + public static int ASH(int x, int n) + { + return (n > 0) ? (x << n) : (x >> Math.abs(n)); + } + + public static long ASH(long x, long n) + { + return (n > 0) ? (x << n) : (x >> Math.abs(n)); + } + + public static int LSH(int x, int n) + { + return (n > 0) ? (x << n) : (x >>> Math.abs(n)); + } + + public static long LSH(long x, long n) + { + return (n > 0) ? (x << n) : (x >>> Math.abs(n)); + } + + public static int ROT(int x, int n) + { + if(n > 0) + { + return (x << n) | (x >>> (Integer.SIZE - n)); + } + else + { + n = Math.abs(n); + return (x >>> n) | (x << (Integer.SIZE - n)); + } + } + + public static long ROT(long x, long n) + { + if(n > 0) + { + return (x << n) | (x >>> (Long.SIZE - n)); + } + else + { + n = Math.abs(n); + return (x >>> n) | (x << (Long.SIZE - n)); + } + } }