Jelajahi Sumber

Added halfres rendering mode to gpu and mu. Added millis counter to mu. Raycaster now renders at half resolution and many improvements. Now at 40 to 70fps.

bart 1 tahun lalu
induk
melakukan
0fd222280a

+ 667 - 202
BCC/userBDOS/DATA/RAYDAT.C

@@ -4,212 +4,677 @@
  */
 
 // x-coordinate in camera space
-fixed_point_t LUTcameraX[320] = {
-    -65536, -65125, -64714, -64303, -63892, -63482, -63071, -62660, -62249,
-    -61838, -61427, -61016, -60605, -60195, -59784, -59373, -58962, -58551,
-    -58140, -57729, -57318, -56907, -56497, -56086, -55675, -55264, -54853,
-    -54442, -54031, -53620, -53209, -52799, -52388, -51977, -51566, -51155,
-    -50744, -50333, -49922, -49512, -49101, -48690, -48279, -47868, -47457,
-    -47046, -46635, -46224, -45814, -45403, -44992, -44581, -44170, -43759,
-    -43348, -42937, -42526, -42116, -41705, -41294, -40883, -40472, -40061,
-    -39650, -39239, -38829, -38418, -38007, -37596, -37185, -36774, -36363,
-    -35952, -35541, -35131, -34720, -34309, -33898, -33487, -33076, -32665,
-    -32254, -31844, -31433, -31022, -30611, -30200, -29789, -29378, -28967,
-    -28556, -28146, -27735, -27324, -26913, -26502, -26091, -25680, -25269,
-    -24858, -24448, -24037, -23626, -23215, -22804, -22393, -21982, -21571,
-    -21161, -20750, -20339, -19928, -19517, -19106, -18695, -18284, -17873,
-    -17463, -17052, -16641, -16230, -15819, -15408, -14997, -14586, -14175,
-    -13765, -13354, -12943, -12532, -12121, -11710, -11299, -10888, -10478,
-    -10067, -9656,  -9245,  -8834,  -8423,  -8012,  -7601,  -7190,  -6780,
-    -6369,  -5958,  -5547,  -5136,  -4725,  -4314,  -3903,  -3493,  -3082,
-    -2671,  -2260,  -1849,  -1438,  -1027,  -616,   -205,   205,    616,
-    1027,   1438,   1849,   2260,   2671,   3082,   3493,   3903,   4314,
-    4725,   5136,   5547,   5958,   6369,   6780,   7190,   7601,   8012,
-    8423,   8834,   9245,   9656,   10067,  10478,  10888,  11299,  11710,
-    12121,  12532,  12943,  13354,  13765,  14175,  14586,  14997,  15408,
-    15819,  16230,  16641,  17052,  17463,  17873,  18284,  18695,  19106,
-    19517,  19928,  20339,  20750,  21161,  21571,  21982,  22393,  22804,
-    23215,  23626,  24037,  24448,  24858,  25269,  25680,  26091,  26502,
-    26913,  27324,  27735,  28146,  28556,  28967,  29378,  29789,  30200,
-    30611,  31022,  31433,  31844,  32254,  32665,  33076,  33487,  33898,
-    34309,  34720,  35131,  35541,  35952,  36363,  36774,  37185,  37596,
-    38007,  38418,  38829,  39239,  39650,  40061,  40472,  40883,  41294,
-    41705,  42116,  42526,  42937,  43348,  43759,  44170,  44581,  44992,
-    45403,  45814,  46224,  46635,  47046,  47457,  47868,  48279,  48690,
-    49101,  49512,  49922,  50333,  50744,  51155,  51566,  51977,  52388,
-    52799,  53209,  53620,  54031,  54442,  54853,  55264,  55675,  56086,
-    56497,  56907,  57318,  57729,  58140,  58551,  58962,  59373,  59784,
-    60195,  60605,  61016,  61427,  61838,  62249,  62660,  63071,  63482,
-    63892,  64303,  64714,  65125,  65536
-};
+fixed_point_t LUTcameraX[160] = {
+    -65536, -64712, -63887, -63063, -62239, -61414, -60590, -59766, -58941,
+    -58117, -57292, -56468, -55644, -54819, -53995, -53171, -52346, -51522,
+    -50698, -49873, -49049, -48225, -47400, -46576, -45752, -44927, -44103,
+    -43278, -42454, -41630, -40805, -39981, -39157, -38332, -37508, -36684,
+    -35859, -35035, -34211, -33386, -32562, -31738, -30913, -30089, -29265,
+    -28440, -27616, -26791, -25967, -25143, -24318, -23494, -22670, -21845,
+    -21021, -20197, -19372, -18548, -17724, -16899, -16075, -15251, -14426,
+    -13602, -12777, -11953, -11129, -10304, -9480,  -8656,  -7831,  -7007,
+    -6183,  -5358,  -4534,  -3710,  -2885,  -2061,  -1237,  -412,   412,
+    1237,   2061,   2885,   3710,   4534,   5358,   6183,   7007,   7831,
+    8656,   9480,   10304,  11129,  11953,  12777,  13602,  14426,  15251,
+    16075,  16899,  17724,  18548,  19372,  20197,  21021,  21845,  22670,
+    23494,  24318,  25143,  25967,  26791,  27616,  28440,  29265,  30089,
+    30913,  31738,  32562,  33386,  34211,  35035,  35859,  36684,  37508,
+    38332,  39157,  39981,  40805,  41630,  42454,  43278,  44103,  44927,
+    45752,  46576,  47400,  48225,  49049,  49873,  50698,  51522,  52346,
+    53171,  53995,  54819,  55644,  56468,  57292,  58117,  58941,  59766,
+    60590,  61414,  62239,  63063,  63887,  64712,  65536};
 
-word LUTdirX[360] = {
-    -65526, -65496, -65446, -65376, -65287, -65177, -65048, -64898, -64729,
-    -64540, -64332, -64104, -63856, -63589, -63303, -62997, -62672, -62328,
-    -61966, -61584, -61183, -60764, -60326, -59870, -59396, -58903, -58393,
-    -57865, -57319, -56756, -56175, -55578, -54963, -54332, -53684, -53020,
-    -52339, -51643, -50931, -50203, -49461, -48703, -47930, -47143, -46341,
-    -45525, -44695, -43852, -42995, -42126, -41243, -40348, -39441, -38521,
-    -37590, -36647, -35693, -34729, -33754, -32768, -31772, -30767, -29753,
-    -28729, -27697, -26656, -25607, -24550, -23486, -22415, -21336, -20252,
-    -19161, -18064, -16962, -15855, -14742, -13626, -12505, -11380, -10252,
-    -9121,  -7987,  -6850,  -5712,  -4572,  -3430,  -2287,  -1144,  0,
-    1144,   2287,   3430,   4572,   5712,   6850,   7987,   9121,   10252,
-    11380,  12505,  13626,  14742,  15855,  16962,  18064,  19161,  20252,
-    21336,  22415,  23486,  24550,  25607,  26656,  27697,  28729,  29753,
-    30767,  31772,  32768,  33754,  34729,  35693,  36647,  37590,  38521,
-    39441,  40348,  41243,  42126,  42995,  43852,  44695,  45525,  46341,
-    47143,  47930,  48703,  49461,  50203,  50931,  51643,  52339,  53020,
-    53684,  54332,  54963,  55578,  56175,  56756,  57319,  57865,  58393,
-    58903,  59396,  59870,  60326,  60764,  61183,  61584,  61966,  62328,
-    62672,  62997,  63303,  63589,  63856,  64104,  64332,  64540,  64729,
-    64898,  65048,  65177,  65287,  65376,  65446,  65496,  65526,  65536,
-    65526,  65496,  65446,  65376,  65287,  65177,  65048,  64898,  64729,
-    64540,  64332,  64104,  63856,  63589,  63303,  62997,  62672,  62328,
-    61966,  61584,  61183,  60764,  60326,  59870,  59396,  58903,  58393,
-    57865,  57319,  56756,  56175,  55578,  54963,  54332,  53684,  53020,
-    52339,  51643,  50931,  50203,  49461,  48703,  47930,  47143,  46341,
-    45525,  44695,  43852,  42995,  42126,  41243,  40348,  39441,  38521,
-    37590,  36647,  35693,  34729,  33754,  32768,  31772,  30767,  29753,
-    28729,  27697,  26656,  25607,  24550,  23486,  22415,  21336,  20252,
-    19161,  18064,  16962,  15855,  14742,  13626,  12505,  11380,  10252,
-    9121,   7987,   6850,   5712,   4572,   3430,   2287,   1144,   0,
-    -1144,  -2287,  -3430,  -4572,  -5712,  -6850,  -7987,  -9121,  -10252,
-    -11380, -12505, -13626, -14742, -15855, -16962, -18064, -19161, -20252,
-    -21336, -22415, -23486, -24550, -25607, -26656, -27697, -28729, -29753,
-    -30767, -31772, -32768, -33754, -34729, -35693, -36647, -37590, -38521,
-    -39441, -40348, -41243, -42126, -42995, -43852, -44695, -45525, -46341,
-    -47143, -47930, -48703, -49461, -50203, -50931, -51643, -52339, -53020,
-    -53684, -54332, -54963, -55578, -56175, -56756, -57319, -57865, -58393,
-    -58903, -59396, -59870, -60326, -60764, -61183, -61584, -61966, -62328,
-    -62672, -62997, -63303, -63589, -63856, -64104, -64332, -64540, -64729,
-    -64898, -65048, -65177, -65287, -65376, -65446, -65496, -65526, -65536};
+word LUTdirX[1440] = {
+    -65535, -65534, -65530, -65526, -65520, -65514, -65505, -65496, -65485,
+    -65474, -65461, -65446, -65431, -65414, -65396, -65376, -65356, -65334,
+    -65311, -65287, -65261, -65234, -65206, -65177, -65146, -65115, -65082,
+    -65048, -65012, -64975, -64937, -64898, -64858, -64816, -64773, -64729,
+    -64684, -64637, -64589, -64540, -64490, -64439, -64386, -64332, -64277,
+    -64220, -64163, -64104, -64044, -63983, -63920, -63856, -63791, -63725,
+    -63658, -63589, -63520, -63449, -63376, -63303, -63228, -63152, -63075,
+    -62997, -62918, -62837, -62755, -62672, -62588, -62503, -62416, -62328,
+    -62239, -62149, -62058, -61966, -61872, -61777, -61681, -61584, -61485,
+    -61386, -61285, -61183, -61080, -60976, -60870, -60764, -60656, -60547,
+    -60437, -60326, -60214, -60100, -59986, -59870, -59753, -59635, -59516,
+    -59396, -59274, -59152, -59028, -58903, -58777, -58650, -58522, -58393,
+    -58263, -58131, -57999, -57865, -57730, -57594, -57457, -57319, -57180,
+    -57040, -56898, -56756, -56612, -56468, -56322, -56175, -56028, -55879,
+    -55729, -55578, -55426, -55273, -55118, -54963, -54807, -54650, -54491,
+    -54332, -54171, -54010, -53847, -53684, -53519, -53354, -53187, -53020,
+    -52851, -52682, -52511, -52339, -52167, -51993, -51819, -51643, -51467,
+    -51289, -51111, -50931, -50751, -50569, -50387, -50203, -50019, -49834,
+    -49648, -49461, -49273, -49084, -48894, -48703, -48511, -48318, -48125,
+    -47930, -47735, -47538, -47341, -47143, -46944, -46744, -46543, -46341,
+    -46138, -45935, -45730, -45525, -45319, -45112, -44904, -44695, -44486,
+    -44275, -44064, -43852, -43639, -43425, -43211, -42995, -42779, -42562,
+    -42344, -42126, -41906, -41686, -41465, -41243, -41021, -40797, -40573,
+    -40348, -40122, -39896, -39669, -39441, -39212, -38982, -38752, -38521,
+    -38289, -38057, -37824, -37590, -37355, -37120, -36884, -36647, -36410,
+    -36172, -35933, -35693, -35453, -35212, -34971, -34729, -34486, -34242,
+    -33998, -33754, -33508, -33262, -33015, -32768, -32520, -32271, -32022,
+    -31772, -31522, -31271, -31019, -30767, -30515, -30261, -30007, -29753,
+    -29498, -29242, -28986, -28729, -28472, -28214, -27956, -27697, -27437,
+    -27177, -26917, -26656, -26394, -26132, -25870, -25607, -25343, -25080,
+    -24815, -24550, -24285, -24019, -23753, -23486, -23219, -22951, -22683,
+    -22415, -22146, -21876, -21607, -21336, -21066, -20795, -20524, -20252,
+    -19980, -19707, -19434, -19161, -18887, -18613, -18339, -18064, -17789,
+    -17514, -17238, -16962, -16686, -16409, -16132, -15855, -15577, -15299,
+    -15021, -14742, -14464, -14185, -13905, -13626, -13346, -13066, -12785,
+    -12505, -12224, -11943, -11662, -11380, -11098, -10817, -10534, -10252,
+    -9970,  -9687,  -9404,  -9121,  -8838,  -8554,  -8271,  -7987,  -7703,
+    -7419,  -7135,  -6850,  -6566,  -6281,  -5997,  -5712,  -5427,  -5142,
+    -4857,  -4572,  -4286,  -4001,  -3715,  -3430,  -3144,  -2859,  -2573,
+    -2287,  -2001,  -1716,  -1430,  -1144,  -858,   -572,   -286,   0,
+    286,    572,    858,    1144,   1430,   1716,   2001,   2287,   2573,
+    2859,   3144,   3430,   3715,   4001,   4286,   4572,   4857,   5142,
+    5427,   5712,   5997,   6281,   6566,   6850,   7135,   7419,   7703,
+    7987,   8271,   8554,   8838,   9121,   9404,   9687,   9970,   10252,
+    10534,  10817,  11098,  11380,  11662,  11943,  12224,  12505,  12785,
+    13066,  13346,  13626,  13905,  14185,  14464,  14742,  15021,  15299,
+    15577,  15855,  16132,  16409,  16686,  16962,  17238,  17514,  17789,
+    18064,  18339,  18613,  18887,  19161,  19434,  19707,  19980,  20252,
+    20524,  20795,  21066,  21336,  21607,  21876,  22146,  22415,  22683,
+    22951,  23219,  23486,  23753,  24019,  24285,  24550,  24815,  25080,
+    25343,  25607,  25870,  26132,  26394,  26656,  26917,  27177,  27437,
+    27697,  27956,  28214,  28472,  28729,  28986,  29242,  29498,  29753,
+    30007,  30261,  30515,  30767,  31019,  31271,  31522,  31772,  32022,
+    32271,  32520,  32768,  33015,  33262,  33508,  33754,  33998,  34242,
+    34486,  34729,  34971,  35212,  35453,  35693,  35933,  36172,  36410,
+    36647,  36884,  37120,  37355,  37590,  37824,  38057,  38289,  38521,
+    38752,  38982,  39212,  39441,  39669,  39896,  40122,  40348,  40573,
+    40797,  41021,  41243,  41465,  41686,  41906,  42126,  42344,  42562,
+    42779,  42995,  43211,  43425,  43639,  43852,  44064,  44275,  44486,
+    44695,  44904,  45112,  45319,  45525,  45730,  45935,  46138,  46341,
+    46543,  46744,  46944,  47143,  47341,  47538,  47735,  47930,  48125,
+    48318,  48511,  48703,  48894,  49084,  49273,  49461,  49648,  49834,
+    50019,  50203,  50387,  50569,  50751,  50931,  51111,  51289,  51467,
+    51643,  51819,  51993,  52167,  52339,  52511,  52682,  52851,  53020,
+    53187,  53354,  53519,  53684,  53847,  54010,  54171,  54332,  54491,
+    54650,  54807,  54963,  55118,  55273,  55426,  55578,  55729,  55879,
+    56028,  56175,  56322,  56468,  56612,  56756,  56898,  57040,  57180,
+    57319,  57457,  57594,  57730,  57865,  57999,  58131,  58263,  58393,
+    58522,  58650,  58777,  58903,  59028,  59152,  59274,  59396,  59516,
+    59635,  59753,  59870,  59986,  60100,  60214,  60326,  60437,  60547,
+    60656,  60764,  60870,  60976,  61080,  61183,  61285,  61386,  61485,
+    61584,  61681,  61777,  61872,  61966,  62058,  62149,  62239,  62328,
+    62416,  62503,  62588,  62672,  62755,  62837,  62918,  62997,  63075,
+    63152,  63228,  63303,  63376,  63449,  63520,  63589,  63658,  63725,
+    63791,  63856,  63920,  63983,  64044,  64104,  64163,  64220,  64277,
+    64332,  64386,  64439,  64490,  64540,  64589,  64637,  64684,  64729,
+    64773,  64816,  64858,  64898,  64937,  64975,  65012,  65048,  65082,
+    65115,  65146,  65177,  65206,  65234,  65261,  65287,  65311,  65334,
+    65356,  65376,  65396,  65414,  65431,  65446,  65461,  65474,  65485,
+    65496,  65505,  65514,  65520,  65526,  65530,  65534,  65535,  65536,
+    65535,  65534,  65530,  65526,  65520,  65514,  65505,  65496,  65485,
+    65474,  65461,  65446,  65431,  65414,  65396,  65376,  65356,  65334,
+    65311,  65287,  65261,  65234,  65206,  65177,  65146,  65115,  65082,
+    65048,  65012,  64975,  64937,  64898,  64858,  64816,  64773,  64729,
+    64684,  64637,  64589,  64540,  64490,  64439,  64386,  64332,  64277,
+    64220,  64163,  64104,  64044,  63983,  63920,  63856,  63791,  63725,
+    63658,  63589,  63520,  63449,  63376,  63303,  63228,  63152,  63075,
+    62997,  62918,  62837,  62755,  62672,  62588,  62503,  62416,  62328,
+    62239,  62149,  62058,  61966,  61872,  61777,  61681,  61584,  61485,
+    61386,  61285,  61183,  61080,  60976,  60870,  60764,  60656,  60547,
+    60437,  60326,  60214,  60100,  59986,  59870,  59753,  59635,  59516,
+    59396,  59274,  59152,  59028,  58903,  58777,  58650,  58522,  58393,
+    58263,  58131,  57999,  57865,  57730,  57594,  57457,  57319,  57180,
+    57040,  56898,  56756,  56612,  56468,  56322,  56175,  56028,  55879,
+    55729,  55578,  55426,  55273,  55118,  54963,  54807,  54650,  54491,
+    54332,  54171,  54010,  53847,  53684,  53519,  53354,  53187,  53020,
+    52851,  52682,  52511,  52339,  52167,  51993,  51819,  51643,  51467,
+    51289,  51111,  50931,  50751,  50569,  50387,  50203,  50019,  49834,
+    49648,  49461,  49273,  49084,  48894,  48703,  48511,  48318,  48125,
+    47930,  47735,  47538,  47341,  47143,  46944,  46744,  46543,  46341,
+    46138,  45935,  45730,  45525,  45319,  45112,  44904,  44695,  44486,
+    44275,  44064,  43852,  43639,  43425,  43211,  42995,  42779,  42562,
+    42344,  42126,  41906,  41686,  41465,  41243,  41021,  40797,  40573,
+    40348,  40122,  39896,  39669,  39441,  39212,  38982,  38752,  38521,
+    38289,  38057,  37824,  37590,  37355,  37120,  36884,  36647,  36410,
+    36172,  35933,  35693,  35453,  35212,  34971,  34729,  34486,  34242,
+    33998,  33754,  33508,  33262,  33015,  32768,  32520,  32271,  32022,
+    31772,  31522,  31271,  31019,  30767,  30515,  30261,  30007,  29753,
+    29498,  29242,  28986,  28729,  28472,  28214,  27956,  27697,  27437,
+    27177,  26917,  26656,  26394,  26132,  25870,  25607,  25343,  25080,
+    24815,  24550,  24285,  24019,  23753,  23486,  23219,  22951,  22683,
+    22415,  22146,  21876,  21607,  21336,  21066,  20795,  20524,  20252,
+    19980,  19707,  19434,  19161,  18887,  18613,  18339,  18064,  17789,
+    17514,  17238,  16962,  16686,  16409,  16132,  15855,  15577,  15299,
+    15021,  14742,  14464,  14185,  13905,  13626,  13346,  13066,  12785,
+    12505,  12224,  11943,  11662,  11380,  11098,  10817,  10534,  10252,
+    9970,   9687,   9404,   9121,   8838,   8554,   8271,   7987,   7703,
+    7419,   7135,   6850,   6566,   6281,   5997,   5712,   5427,   5142,
+    4857,   4572,   4286,   4001,   3715,   3430,   3144,   2859,   2573,
+    2287,   2001,   1716,   1430,   1144,   858,    572,    286,    0,
+    -286,   -572,   -858,   -1144,  -1430,  -1716,  -2001,  -2287,  -2573,
+    -2859,  -3144,  -3430,  -3715,  -4001,  -4286,  -4572,  -4857,  -5142,
+    -5427,  -5712,  -5997,  -6281,  -6566,  -6850,  -7135,  -7419,  -7703,
+    -7987,  -8271,  -8554,  -8838,  -9121,  -9404,  -9687,  -9970,  -10252,
+    -10534, -10817, -11098, -11380, -11662, -11943, -12224, -12505, -12785,
+    -13066, -13346, -13626, -13905, -14185, -14464, -14742, -15021, -15299,
+    -15577, -15855, -16132, -16409, -16686, -16962, -17238, -17514, -17789,
+    -18064, -18339, -18613, -18887, -19161, -19434, -19707, -19980, -20252,
+    -20524, -20795, -21066, -21336, -21607, -21876, -22146, -22415, -22683,
+    -22951, -23219, -23486, -23753, -24019, -24285, -24550, -24815, -25080,
+    -25343, -25607, -25870, -26132, -26394, -26656, -26917, -27177, -27437,
+    -27697, -27956, -28214, -28472, -28729, -28986, -29242, -29498, -29753,
+    -30007, -30261, -30515, -30767, -31019, -31271, -31522, -31772, -32022,
+    -32271, -32520, -32768, -33015, -33262, -33508, -33754, -33998, -34242,
+    -34486, -34729, -34971, -35212, -35453, -35693, -35933, -36172, -36410,
+    -36647, -36884, -37120, -37355, -37590, -37824, -38057, -38289, -38521,
+    -38752, -38982, -39212, -39441, -39669, -39896, -40122, -40348, -40573,
+    -40797, -41021, -41243, -41465, -41686, -41906, -42126, -42344, -42562,
+    -42779, -42995, -43211, -43425, -43639, -43852, -44064, -44275, -44486,
+    -44695, -44904, -45112, -45319, -45525, -45730, -45935, -46138, -46341,
+    -46543, -46744, -46944, -47143, -47341, -47538, -47735, -47930, -48125,
+    -48318, -48511, -48703, -48894, -49084, -49273, -49461, -49648, -49834,
+    -50019, -50203, -50387, -50569, -50751, -50931, -51111, -51289, -51467,
+    -51643, -51819, -51993, -52167, -52339, -52511, -52682, -52851, -53020,
+    -53187, -53354, -53519, -53684, -53847, -54010, -54171, -54332, -54491,
+    -54650, -54807, -54963, -55118, -55273, -55426, -55578, -55729, -55879,
+    -56028, -56175, -56322, -56468, -56612, -56756, -56898, -57040, -57180,
+    -57319, -57457, -57594, -57730, -57865, -57999, -58131, -58263, -58393,
+    -58522, -58650, -58777, -58903, -59028, -59152, -59274, -59396, -59516,
+    -59635, -59753, -59870, -59986, -60100, -60214, -60326, -60437, -60547,
+    -60656, -60764, -60870, -60976, -61080, -61183, -61285, -61386, -61485,
+    -61584, -61681, -61777, -61872, -61966, -62058, -62149, -62239, -62328,
+    -62416, -62503, -62588, -62672, -62755, -62837, -62918, -62997, -63075,
+    -63152, -63228, -63303, -63376, -63449, -63520, -63589, -63658, -63725,
+    -63791, -63856, -63920, -63983, -64044, -64104, -64163, -64220, -64277,
+    -64332, -64386, -64439, -64490, -64540, -64589, -64637, -64684, -64729,
+    -64773, -64816, -64858, -64898, -64937, -64975, -65012, -65048, -65082,
+    -65115, -65146, -65177, -65206, -65234, -65261, -65287, -65311, -65334,
+    -65356, -65376, -65396, -65414, -65431, -65446, -65461, -65474, -65485,
+    -65496, -65505, -65514, -65520, -65526, -65530, -65534, -65535, -65536,
+};
 
-word LUTdirY[360] = {
-    1144,   2287,   3430,   4572,   5712,   6850,   7987,   9121,   10252,
-    11380,  12505,  13626,  14742,  15855,  16962,  18064,  19161,  20252,
-    21336,  22415,  23486,  24550,  25607,  26656,  27697,  28729,  29753,
-    30767,  31772,  32768,  33754,  34729,  35693,  36647,  37590,  38521,
-    39441,  40348,  41243,  42126,  42995,  43852,  44695,  45525,  46341,
-    47143,  47930,  48703,  49461,  50203,  50931,  51643,  52339,  53020,
-    53684,  54332,  54963,  55578,  56175,  56756,  57319,  57865,  58393,
-    58903,  59396,  59870,  60326,  60764,  61183,  61584,  61966,  62328,
-    62672,  62997,  63303,  63589,  63856,  64104,  64332,  64540,  64729,
-    64898,  65048,  65177,  65287,  65376,  65446,  65496,  65526,  65536,
-    65526,  65496,  65446,  65376,  65287,  65177,  65048,  64898,  64729,
-    64540,  64332,  64104,  63856,  63589,  63303,  62997,  62672,  62328,
-    61966,  61584,  61183,  60764,  60326,  59870,  59396,  58903,  58393,
-    57865,  57319,  56756,  56175,  55578,  54963,  54332,  53684,  53020,
-    52339,  51643,  50931,  50203,  49461,  48703,  47930,  47143,  46341,
-    45525,  44695,  43852,  42995,  42126,  41243,  40348,  39441,  38521,
-    37590,  36647,  35693,  34729,  33754,  32768,  31772,  30767,  29753,
-    28729,  27697,  26656,  25607,  24550,  23486,  22415,  21336,  20252,
-    19161,  18064,  16962,  15855,  14742,  13626,  12505,  11380,  10252,
-    9121,   7987,   6850,   5712,   4572,   3430,   2287,   1144,   0,
-    -1144,  -2287,  -3430,  -4572,  -5712,  -6850,  -7987,  -9121,  -10252,
-    -11380, -12505, -13626, -14742, -15855, -16962, -18064, -19161, -20252,
-    -21336, -22415, -23486, -24550, -25607, -26656, -27697, -28729, -29753,
-    -30767, -31772, -32768, -33754, -34729, -35693, -36647, -37590, -38521,
-    -39441, -40348, -41243, -42126, -42995, -43852, -44695, -45525, -46341,
-    -47143, -47930, -48703, -49461, -50203, -50931, -51643, -52339, -53020,
-    -53684, -54332, -54963, -55578, -56175, -56756, -57319, -57865, -58393,
-    -58903, -59396, -59870, -60326, -60764, -61183, -61584, -61966, -62328,
-    -62672, -62997, -63303, -63589, -63856, -64104, -64332, -64540, -64729,
-    -64898, -65048, -65177, -65287, -65376, -65446, -65496, -65526, -65536,
-    -65526, -65496, -65446, -65376, -65287, -65177, -65048, -64898, -64729,
-    -64540, -64332, -64104, -63856, -63589, -63303, -62997, -62672, -62328,
-    -61966, -61584, -61183, -60764, -60326, -59870, -59396, -58903, -58393,
-    -57865, -57319, -56756, -56175, -55578, -54963, -54332, -53684, -53020,
-    -52339, -51643, -50931, -50203, -49461, -48703, -47930, -47143, -46341,
-    -45525, -44695, -43852, -42995, -42126, -41243, -40348, -39441, -38521,
-    -37590, -36647, -35693, -34729, -33754, -32768, -31772, -30767, -29753,
-    -28729, -27697, -26656, -25607, -24550, -23486, -22415, -21336, -20252,
-    -19161, -18064, -16962, -15855, -14742, -13626, -12505, -11380, -10252,
-    -9121,  -7987,  -6850,  -5712,  -4572,  -3430,  -2287,  -1144,  0};
+word LUTdirY[1440] = {
+    286,    572,    858,    1144,   1430,   1716,   2001,   2287,   2573,
+    2859,   3144,   3430,   3715,   4001,   4286,   4572,   4857,   5142,
+    5427,   5712,   5997,   6281,   6566,   6850,   7135,   7419,   7703,
+    7987,   8271,   8554,   8838,   9121,   9404,   9687,   9970,   10252,
+    10534,  10817,  11098,  11380,  11662,  11943,  12224,  12505,  12785,
+    13066,  13346,  13626,  13905,  14185,  14464,  14742,  15021,  15299,
+    15577,  15855,  16132,  16409,  16686,  16962,  17238,  17514,  17789,
+    18064,  18339,  18613,  18887,  19161,  19434,  19707,  19980,  20252,
+    20524,  20795,  21066,  21336,  21607,  21876,  22146,  22415,  22683,
+    22951,  23219,  23486,  23753,  24019,  24285,  24550,  24815,  25080,
+    25343,  25607,  25870,  26132,  26394,  26656,  26917,  27177,  27437,
+    27697,  27956,  28214,  28472,  28729,  28986,  29242,  29498,  29753,
+    30007,  30261,  30515,  30767,  31019,  31271,  31522,  31772,  32022,
+    32271,  32520,  32768,  33015,  33262,  33508,  33754,  33998,  34242,
+    34486,  34729,  34971,  35212,  35453,  35693,  35933,  36172,  36410,
+    36647,  36884,  37120,  37355,  37590,  37824,  38057,  38289,  38521,
+    38752,  38982,  39212,  39441,  39669,  39896,  40122,  40348,  40573,
+    40797,  41021,  41243,  41465,  41686,  41906,  42126,  42344,  42562,
+    42779,  42995,  43211,  43425,  43639,  43852,  44064,  44275,  44486,
+    44695,  44904,  45112,  45319,  45525,  45730,  45935,  46138,  46341,
+    46543,  46744,  46944,  47143,  47341,  47538,  47735,  47930,  48125,
+    48318,  48511,  48703,  48894,  49084,  49273,  49461,  49648,  49834,
+    50019,  50203,  50387,  50569,  50751,  50931,  51111,  51289,  51467,
+    51643,  51819,  51993,  52167,  52339,  52511,  52682,  52851,  53020,
+    53187,  53354,  53519,  53684,  53847,  54010,  54171,  54332,  54491,
+    54650,  54807,  54963,  55118,  55273,  55426,  55578,  55729,  55879,
+    56028,  56175,  56322,  56468,  56612,  56756,  56898,  57040,  57180,
+    57319,  57457,  57594,  57730,  57865,  57999,  58131,  58263,  58393,
+    58522,  58650,  58777,  58903,  59028,  59152,  59274,  59396,  59516,
+    59635,  59753,  59870,  59986,  60100,  60214,  60326,  60437,  60547,
+    60656,  60764,  60870,  60976,  61080,  61183,  61285,  61386,  61485,
+    61584,  61681,  61777,  61872,  61966,  62058,  62149,  62239,  62328,
+    62416,  62503,  62588,  62672,  62755,  62837,  62918,  62997,  63075,
+    63152,  63228,  63303,  63376,  63449,  63520,  63589,  63658,  63725,
+    63791,  63856,  63920,  63983,  64044,  64104,  64163,  64220,  64277,
+    64332,  64386,  64439,  64490,  64540,  64589,  64637,  64684,  64729,
+    64773,  64816,  64858,  64898,  64937,  64975,  65012,  65048,  65082,
+    65115,  65146,  65177,  65206,  65234,  65261,  65287,  65311,  65334,
+    65356,  65376,  65396,  65414,  65431,  65446,  65461,  65474,  65485,
+    65496,  65505,  65514,  65520,  65526,  65530,  65534,  65535,  65536,
+    65535,  65534,  65530,  65526,  65520,  65514,  65505,  65496,  65485,
+    65474,  65461,  65446,  65431,  65414,  65396,  65376,  65356,  65334,
+    65311,  65287,  65261,  65234,  65206,  65177,  65146,  65115,  65082,
+    65048,  65012,  64975,  64937,  64898,  64858,  64816,  64773,  64729,
+    64684,  64637,  64589,  64540,  64490,  64439,  64386,  64332,  64277,
+    64220,  64163,  64104,  64044,  63983,  63920,  63856,  63791,  63725,
+    63658,  63589,  63520,  63449,  63376,  63303,  63228,  63152,  63075,
+    62997,  62918,  62837,  62755,  62672,  62588,  62503,  62416,  62328,
+    62239,  62149,  62058,  61966,  61872,  61777,  61681,  61584,  61485,
+    61386,  61285,  61183,  61080,  60976,  60870,  60764,  60656,  60547,
+    60437,  60326,  60214,  60100,  59986,  59870,  59753,  59635,  59516,
+    59396,  59274,  59152,  59028,  58903,  58777,  58650,  58522,  58393,
+    58263,  58131,  57999,  57865,  57730,  57594,  57457,  57319,  57180,
+    57040,  56898,  56756,  56612,  56468,  56322,  56175,  56028,  55879,
+    55729,  55578,  55426,  55273,  55118,  54963,  54807,  54650,  54491,
+    54332,  54171,  54010,  53847,  53684,  53519,  53354,  53187,  53020,
+    52851,  52682,  52511,  52339,  52167,  51993,  51819,  51643,  51467,
+    51289,  51111,  50931,  50751,  50569,  50387,  50203,  50019,  49834,
+    49648,  49461,  49273,  49084,  48894,  48703,  48511,  48318,  48125,
+    47930,  47735,  47538,  47341,  47143,  46944,  46744,  46543,  46341,
+    46138,  45935,  45730,  45525,  45319,  45112,  44904,  44695,  44486,
+    44275,  44064,  43852,  43639,  43425,  43211,  42995,  42779,  42562,
+    42344,  42126,  41906,  41686,  41465,  41243,  41021,  40797,  40573,
+    40348,  40122,  39896,  39669,  39441,  39212,  38982,  38752,  38521,
+    38289,  38057,  37824,  37590,  37355,  37120,  36884,  36647,  36410,
+    36172,  35933,  35693,  35453,  35212,  34971,  34729,  34486,  34242,
+    33998,  33754,  33508,  33262,  33015,  32768,  32520,  32271,  32022,
+    31772,  31522,  31271,  31019,  30767,  30515,  30261,  30007,  29753,
+    29498,  29242,  28986,  28729,  28472,  28214,  27956,  27697,  27437,
+    27177,  26917,  26656,  26394,  26132,  25870,  25607,  25343,  25080,
+    24815,  24550,  24285,  24019,  23753,  23486,  23219,  22951,  22683,
+    22415,  22146,  21876,  21607,  21336,  21066,  20795,  20524,  20252,
+    19980,  19707,  19434,  19161,  18887,  18613,  18339,  18064,  17789,
+    17514,  17238,  16962,  16686,  16409,  16132,  15855,  15577,  15299,
+    15021,  14742,  14464,  14185,  13905,  13626,  13346,  13066,  12785,
+    12505,  12224,  11943,  11662,  11380,  11098,  10817,  10534,  10252,
+    9970,   9687,   9404,   9121,   8838,   8554,   8271,   7987,   7703,
+    7419,   7135,   6850,   6566,   6281,   5997,   5712,   5427,   5142,
+    4857,   4572,   4286,   4001,   3715,   3430,   3144,   2859,   2573,
+    2287,   2001,   1716,   1430,   1144,   858,    572,    286,    0,
+    -286,   -572,   -858,   -1144,  -1430,  -1716,  -2001,  -2287,  -2573,
+    -2859,  -3144,  -3430,  -3715,  -4001,  -4286,  -4572,  -4857,  -5142,
+    -5427,  -5712,  -5997,  -6281,  -6566,  -6850,  -7135,  -7419,  -7703,
+    -7987,  -8271,  -8554,  -8838,  -9121,  -9404,  -9687,  -9970,  -10252,
+    -10534, -10817, -11098, -11380, -11662, -11943, -12224, -12505, -12785,
+    -13066, -13346, -13626, -13905, -14185, -14464, -14742, -15021, -15299,
+    -15577, -15855, -16132, -16409, -16686, -16962, -17238, -17514, -17789,
+    -18064, -18339, -18613, -18887, -19161, -19434, -19707, -19980, -20252,
+    -20524, -20795, -21066, -21336, -21607, -21876, -22146, -22415, -22683,
+    -22951, -23219, -23486, -23753, -24019, -24285, -24550, -24815, -25080,
+    -25343, -25607, -25870, -26132, -26394, -26656, -26917, -27177, -27437,
+    -27697, -27956, -28214, -28472, -28729, -28986, -29242, -29498, -29753,
+    -30007, -30261, -30515, -30767, -31019, -31271, -31522, -31772, -32022,
+    -32271, -32520, -32768, -33015, -33262, -33508, -33754, -33998, -34242,
+    -34486, -34729, -34971, -35212, -35453, -35693, -35933, -36172, -36410,
+    -36647, -36884, -37120, -37355, -37590, -37824, -38057, -38289, -38521,
+    -38752, -38982, -39212, -39441, -39669, -39896, -40122, -40348, -40573,
+    -40797, -41021, -41243, -41465, -41686, -41906, -42126, -42344, -42562,
+    -42779, -42995, -43211, -43425, -43639, -43852, -44064, -44275, -44486,
+    -44695, -44904, -45112, -45319, -45525, -45730, -45935, -46138, -46341,
+    -46543, -46744, -46944, -47143, -47341, -47538, -47735, -47930, -48125,
+    -48318, -48511, -48703, -48894, -49084, -49273, -49461, -49648, -49834,
+    -50019, -50203, -50387, -50569, -50751, -50931, -51111, -51289, -51467,
+    -51643, -51819, -51993, -52167, -52339, -52511, -52682, -52851, -53020,
+    -53187, -53354, -53519, -53684, -53847, -54010, -54171, -54332, -54491,
+    -54650, -54807, -54963, -55118, -55273, -55426, -55578, -55729, -55879,
+    -56028, -56175, -56322, -56468, -56612, -56756, -56898, -57040, -57180,
+    -57319, -57457, -57594, -57730, -57865, -57999, -58131, -58263, -58393,
+    -58522, -58650, -58777, -58903, -59028, -59152, -59274, -59396, -59516,
+    -59635, -59753, -59870, -59986, -60100, -60214, -60326, -60437, -60547,
+    -60656, -60764, -60870, -60976, -61080, -61183, -61285, -61386, -61485,
+    -61584, -61681, -61777, -61872, -61966, -62058, -62149, -62239, -62328,
+    -62416, -62503, -62588, -62672, -62755, -62837, -62918, -62997, -63075,
+    -63152, -63228, -63303, -63376, -63449, -63520, -63589, -63658, -63725,
+    -63791, -63856, -63920, -63983, -64044, -64104, -64163, -64220, -64277,
+    -64332, -64386, -64439, -64490, -64540, -64589, -64637, -64684, -64729,
+    -64773, -64816, -64858, -64898, -64937, -64975, -65012, -65048, -65082,
+    -65115, -65146, -65177, -65206, -65234, -65261, -65287, -65311, -65334,
+    -65356, -65376, -65396, -65414, -65431, -65446, -65461, -65474, -65485,
+    -65496, -65505, -65514, -65520, -65526, -65530, -65534, -65535, -65536,
+    -65535, -65534, -65530, -65526, -65520, -65514, -65505, -65496, -65485,
+    -65474, -65461, -65446, -65431, -65414, -65396, -65376, -65356, -65334,
+    -65311, -65287, -65261, -65234, -65206, -65177, -65146, -65115, -65082,
+    -65048, -65012, -64975, -64937, -64898, -64858, -64816, -64773, -64729,
+    -64684, -64637, -64589, -64540, -64490, -64439, -64386, -64332, -64277,
+    -64220, -64163, -64104, -64044, -63983, -63920, -63856, -63791, -63725,
+    -63658, -63589, -63520, -63449, -63376, -63303, -63228, -63152, -63075,
+    -62997, -62918, -62837, -62755, -62672, -62588, -62503, -62416, -62328,
+    -62239, -62149, -62058, -61966, -61872, -61777, -61681, -61584, -61485,
+    -61386, -61285, -61183, -61080, -60976, -60870, -60764, -60656, -60547,
+    -60437, -60326, -60214, -60100, -59986, -59870, -59753, -59635, -59516,
+    -59396, -59274, -59152, -59028, -58903, -58777, -58650, -58522, -58393,
+    -58263, -58131, -57999, -57865, -57730, -57594, -57457, -57319, -57180,
+    -57040, -56898, -56756, -56612, -56468, -56322, -56175, -56028, -55879,
+    -55729, -55578, -55426, -55273, -55118, -54963, -54807, -54650, -54491,
+    -54332, -54171, -54010, -53847, -53684, -53519, -53354, -53187, -53020,
+    -52851, -52682, -52511, -52339, -52167, -51993, -51819, -51643, -51467,
+    -51289, -51111, -50931, -50751, -50569, -50387, -50203, -50019, -49834,
+    -49648, -49461, -49273, -49084, -48894, -48703, -48511, -48318, -48125,
+    -47930, -47735, -47538, -47341, -47143, -46944, -46744, -46543, -46341,
+    -46138, -45935, -45730, -45525, -45319, -45112, -44904, -44695, -44486,
+    -44275, -44064, -43852, -43639, -43425, -43211, -42995, -42779, -42562,
+    -42344, -42126, -41906, -41686, -41465, -41243, -41021, -40797, -40573,
+    -40348, -40122, -39896, -39669, -39441, -39212, -38982, -38752, -38521,
+    -38289, -38057, -37824, -37590, -37355, -37120, -36884, -36647, -36410,
+    -36172, -35933, -35693, -35453, -35212, -34971, -34729, -34486, -34242,
+    -33998, -33754, -33508, -33262, -33015, -32768, -32520, -32271, -32022,
+    -31772, -31522, -31271, -31019, -30767, -30515, -30261, -30007, -29753,
+    -29498, -29242, -28986, -28729, -28472, -28214, -27956, -27697, -27437,
+    -27177, -26917, -26656, -26394, -26132, -25870, -25607, -25343, -25080,
+    -24815, -24550, -24285, -24019, -23753, -23486, -23219, -22951, -22683,
+    -22415, -22146, -21876, -21607, -21336, -21066, -20795, -20524, -20252,
+    -19980, -19707, -19434, -19161, -18887, -18613, -18339, -18064, -17789,
+    -17514, -17238, -16962, -16686, -16409, -16132, -15855, -15577, -15299,
+    -15021, -14742, -14464, -14185, -13905, -13626, -13346, -13066, -12785,
+    -12505, -12224, -11943, -11662, -11380, -11098, -10817, -10534, -10252,
+    -9970,  -9687,  -9404,  -9121,  -8838,  -8554,  -8271,  -7987,  -7703,
+    -7419,  -7135,  -6850,  -6566,  -6281,  -5997,  -5712,  -5427,  -5142,
+    -4857,  -4572,  -4286,  -4001,  -3715,  -3430,  -3144,  -2859,  -2573,
+    -2287,  -2001,  -1716,  -1430,  -1144,  -858,   -572,   -286,   0,
+};
 
-word LUTplaneX[360] = {
-    755,    1510,   2264,   3017,   3770,   4521,   5271,   6020,   6766,
-    7511,   8253,   8993,   9730,   10464,  11195,  11922,  12646,  13366,
-    14082,  14794,  15501,  16203,  16901,  17593,  18280,  18961,  19637,
-    20306,  20970,  21627,  22277,  22921,  23558,  24187,  24809,  25424,
-    26031,  26630,  27220,  27803,  28377,  28942,  29499,  30047,  30585,
-    31114,  31634,  32144,  32644,  33134,  33614,  34084,  34544,  34993,
-    35431,  35859,  36276,  36681,  37076,  37459,  37831,  38191,  38539,
-    38876,  39201,  39514,  39815,  40104,  40381,  40645,  40897,  41137,
-    41364,  41578,  41780,  41969,  42145,  42309,  42459,  42597,  42721,
-    42833,  42931,  43017,  43089,  43148,  43194,  43227,  43247,  43254,
-    43247,  43227,  43194,  43148,  43089,  43017,  42931,  42833,  42721,
-    42597,  42459,  42309,  42145,  41969,  41780,  41578,  41364,  41137,
-    40897,  40645,  40381,  40104,  39815,  39514,  39201,  38876,  38539,
-    38191,  37831,  37459,  37076,  36681,  36276,  35859,  35431,  34993,
-    34544,  34084,  33614,  33134,  32644,  32144,  31634,  31114,  30585,
-    30047,  29499,  28942,  28377,  27803,  27220,  26630,  26031,  25424,
-    24809,  24187,  23558,  22921,  22277,  21627,  20970,  20306,  19637,
-    18961,  18280,  17593,  16901,  16203,  15501,  14794,  14082,  13366,
-    12646,  11922,  11195,  10464,  9730,   8993,   8253,   7511,   6766,
-    6020,   5271,   4521,   3770,   3017,   2264,   1510,   755,    0,
-    -755,   -1510,  -2264,  -3017,  -3770,  -4521,  -5271,  -6020,  -6766,
-    -7511,  -8253,  -8993,  -9730,  -10464, -11195, -11922, -12646, -13366,
-    -14082, -14794, -15501, -16203, -16901, -17593, -18280, -18961, -19637,
-    -20306, -20970, -21627, -22277, -22921, -23558, -24187, -24809, -25424,
-    -26031, -26630, -27220, -27803, -28377, -28942, -29499, -30047, -30585,
-    -31114, -31634, -32144, -32644, -33134, -33614, -34084, -34544, -34993,
-    -35431, -35859, -36276, -36681, -37076, -37459, -37831, -38191, -38539,
-    -38876, -39201, -39514, -39815, -40104, -40381, -40645, -40897, -41137,
-    -41364, -41578, -41780, -41969, -42145, -42309, -42459, -42597, -42721,
-    -42833, -42931, -43017, -43089, -43148, -43194, -43227, -43247, -43254,
-    -43247, -43227, -43194, -43148, -43089, -43017, -42931, -42833, -42721,
-    -42597, -42459, -42309, -42145, -41969, -41780, -41578, -41364, -41137,
-    -40897, -40645, -40381, -40104, -39815, -39514, -39201, -38876, -38539,
-    -38191, -37831, -37459, -37076, -36681, -36276, -35859, -35431, -34993,
-    -34544, -34084, -33614, -33134, -32644, -32144, -31634, -31114, -30585,
-    -30047, -29499, -28942, -28377, -27803, -27220, -26630, -26031, -25424,
-    -24809, -24187, -23558, -22921, -22277, -21627, -20970, -20306, -19637,
-    -18961, -18280, -17593, -16901, -16203, -15501, -14794, -14082, -13366,
-    -12646, -11922, -11195, -10464, -9730,  -8993,  -8253,  -7511,  -6766,
-    -6020,  -5271,  -4521,  -3770,  -3017,  -2264,  -1510,  -755,   0};
+word LUTplaneX[1440] = {
+    189,    377,    566,    755,    944,    1132,   1321,   1510,   1698,
+    1887,   2075,   2264,   2452,   2641,   2829,   3017,   3205,   3394,
+    3582,   3770,   3958,   4146,   4334,   4521,   4709,   4896,   5084,
+    5271,   5459,   5646,   5833,   6020,   6207,   6393,   6580,   6766,
+    6953,   7139,   7325,   7511,   7697,   7882,   8068,   8253,   8438,
+    8623,   8808,   8993,   9177,   9362,   9546,   9730,   9914,   10097,
+    10281,  10464,  10647,  10830,  11012,  11195,  11377,  11559,  11741,
+    11922,  12104,  12285,  12466,  12646,  12827,  13007,  13187,  13366,
+    13546,  13725,  13903,  14082,  14260,  14438,  14616,  14794,  14971,
+    15148,  15324,  15501,  15677,  15853,  16028,  16203,  16378,  16552,
+    16727,  16901,  17074,  17247,  17420,  17593,  17765,  17937,  18109,
+    18280,  18451,  18621,  18791,  18961,  19131,  19300,  19468,  19637,
+    19805,  19972,  20140,  20306,  20473,  20639,  20805,  20970,  21135,
+    21299,  21463,  21627,  21790,  21953,  22115,  22277,  22439,  22600,
+    22761,  22921,  23081,  23240,  23399,  23558,  23716,  23873,  24031,
+    24187,  24343,  24499,  24655,  24809,  24964,  25118,  25271,  25424,
+    25576,  25728,  25880,  26031,  26181,  26331,  26481,  26630,  26778,
+    26926,  27074,  27220,  27367,  27513,  27658,  27803,  27947,  28091,
+    28234,  28377,  28519,  28661,  28802,  28942,  29082,  29222,  29361,
+    29499,  29637,  29774,  29911,  30047,  30182,  30317,  30451,  30585,
+    30718,  30851,  30983,  31114,  31245,  31375,  31505,  31634,  31762,
+    31890,  32017,  32144,  32270,  32395,  32520,  32644,  32768,  32890,
+    33013,  33134,  33255,  33376,  33495,  33614,  33733,  33851,  33968,
+    34084,  34200,  34316,  34430,  34544,  34657,  34770,  34882,  34993,
+    35104,  35214,  35323,  35431,  35539,  35647,  35753,  35859,  35964,
+    36069,  36173,  36276,  36378,  36480,  36581,  36681,  36781,  36880,
+    36978,  37076,  37173,  37269,  37364,  37459,  37553,  37646,  37739,
+    37831,  37922,  38012,  38102,  38191,  38279,  38367,  38453,  38539,
+    38625,  38709,  38793,  38876,  38959,  39040,  39121,  39201,  39281,
+    39359,  39437,  39514,  39591,  39666,  39741,  39815,  39889,  39961,
+    40033,  40104,  40175,  40244,  40313,  40381,  40448,  40515,  40580,
+    40645,  40709,  40773,  40835,  40897,  40958,  41019,  41078,  41137,
+    41195,  41252,  41308,  41364,  41419,  41473,  41526,  41578,  41630,
+    41681,  41731,  41780,  41828,  41876,  41923,  41969,  42014,  42059,
+    42102,  42145,  42187,  42228,  42269,  42309,  42347,  42385,  42423,
+    42459,  42495,  42529,  42563,  42597,  42629,  42661,  42691,  42721,
+    42750,  42779,  42806,  42833,  42859,  42884,  42908,  42931,  42954,
+    42976,  42997,  43017,  43036,  43055,  43072,  43089,  43105,  43120,
+    43135,  43148,  43161,  43173,  43184,  43194,  43204,  43213,  43220,
+    43227,  43234,  43239,  43243,  43247,  43250,  43252,  43253,  43254,
+    43253,  43252,  43250,  43247,  43243,  43239,  43234,  43227,  43220,
+    43213,  43204,  43194,  43184,  43173,  43161,  43148,  43135,  43120,
+    43105,  43089,  43072,  43055,  43036,  43017,  42997,  42976,  42954,
+    42931,  42908,  42884,  42859,  42833,  42806,  42779,  42750,  42721,
+    42691,  42661,  42629,  42597,  42563,  42529,  42495,  42459,  42423,
+    42385,  42347,  42309,  42269,  42228,  42187,  42145,  42102,  42059,
+    42014,  41969,  41923,  41876,  41828,  41780,  41731,  41681,  41630,
+    41578,  41526,  41473,  41419,  41364,  41308,  41252,  41195,  41137,
+    41078,  41019,  40958,  40897,  40835,  40773,  40709,  40645,  40580,
+    40515,  40448,  40381,  40313,  40244,  40175,  40104,  40033,  39961,
+    39889,  39815,  39741,  39666,  39591,  39514,  39437,  39359,  39281,
+    39201,  39121,  39040,  38959,  38876,  38793,  38709,  38625,  38539,
+    38453,  38367,  38279,  38191,  38102,  38012,  37922,  37831,  37739,
+    37646,  37553,  37459,  37364,  37269,  37173,  37076,  36978,  36880,
+    36781,  36681,  36581,  36480,  36378,  36276,  36173,  36069,  35964,
+    35859,  35753,  35647,  35539,  35431,  35323,  35214,  35104,  34993,
+    34882,  34770,  34657,  34544,  34430,  34316,  34200,  34084,  33968,
+    33851,  33733,  33614,  33495,  33376,  33255,  33134,  33013,  32890,
+    32768,  32644,  32520,  32395,  32270,  32144,  32017,  31890,  31762,
+    31634,  31505,  31375,  31245,  31114,  30983,  30851,  30718,  30585,
+    30451,  30317,  30182,  30047,  29911,  29774,  29637,  29499,  29361,
+    29222,  29082,  28942,  28802,  28661,  28519,  28377,  28234,  28091,
+    27947,  27803,  27658,  27513,  27367,  27220,  27074,  26926,  26778,
+    26630,  26481,  26331,  26181,  26031,  25880,  25728,  25576,  25424,
+    25271,  25118,  24964,  24809,  24655,  24499,  24343,  24187,  24031,
+    23873,  23716,  23558,  23399,  23240,  23081,  22921,  22761,  22600,
+    22439,  22277,  22115,  21953,  21790,  21627,  21463,  21299,  21135,
+    20970,  20805,  20639,  20473,  20306,  20140,  19972,  19805,  19637,
+    19468,  19300,  19131,  18961,  18791,  18621,  18451,  18280,  18109,
+    17937,  17765,  17593,  17420,  17247,  17074,  16901,  16727,  16552,
+    16378,  16203,  16028,  15853,  15677,  15501,  15324,  15148,  14971,
+    14794,  14616,  14438,  14260,  14082,  13903,  13725,  13546,  13366,
+    13187,  13007,  12827,  12646,  12466,  12285,  12104,  11922,  11741,
+    11559,  11377,  11195,  11012,  10830,  10647,  10464,  10281,  10097,
+    9914,   9730,   9546,   9362,   9177,   8993,   8808,   8623,   8438,
+    8253,   8068,   7882,   7697,   7511,   7325,   7139,   6953,   6766,
+    6580,   6393,   6207,   6020,   5833,   5646,   5459,   5271,   5084,
+    4896,   4709,   4521,   4334,   4146,   3958,   3770,   3582,   3394,
+    3205,   3017,   2829,   2641,   2452,   2264,   2075,   1887,   1698,
+    1510,   1321,   1132,   944,    755,    566,    377,    189,    0,
+    -189,   -377,   -566,   -755,   -944,   -1132,  -1321,  -1510,  -1698,
+    -1887,  -2075,  -2264,  -2452,  -2641,  -2829,  -3017,  -3205,  -3394,
+    -3582,  -3770,  -3958,  -4146,  -4334,  -4521,  -4709,  -4896,  -5084,
+    -5271,  -5459,  -5646,  -5833,  -6020,  -6207,  -6393,  -6580,  -6766,
+    -6953,  -7139,  -7325,  -7511,  -7697,  -7882,  -8068,  -8253,  -8438,
+    -8623,  -8808,  -8993,  -9177,  -9362,  -9546,  -9730,  -9914,  -10097,
+    -10281, -10464, -10647, -10830, -11012, -11195, -11377, -11559, -11741,
+    -11922, -12104, -12285, -12466, -12646, -12827, -13007, -13187, -13366,
+    -13546, -13725, -13903, -14082, -14260, -14438, -14616, -14794, -14971,
+    -15148, -15324, -15501, -15677, -15853, -16028, -16203, -16378, -16552,
+    -16727, -16901, -17074, -17247, -17420, -17593, -17765, -17937, -18109,
+    -18280, -18451, -18621, -18791, -18961, -19131, -19300, -19468, -19637,
+    -19805, -19972, -20140, -20306, -20473, -20639, -20805, -20970, -21135,
+    -21299, -21463, -21627, -21790, -21953, -22115, -22277, -22439, -22600,
+    -22761, -22921, -23081, -23240, -23399, -23558, -23716, -23873, -24031,
+    -24187, -24343, -24499, -24655, -24809, -24964, -25118, -25271, -25424,
+    -25576, -25728, -25880, -26031, -26181, -26331, -26481, -26630, -26778,
+    -26926, -27074, -27220, -27367, -27513, -27658, -27803, -27947, -28091,
+    -28234, -28377, -28519, -28661, -28802, -28942, -29082, -29222, -29361,
+    -29499, -29637, -29774, -29911, -30047, -30182, -30317, -30451, -30585,
+    -30718, -30851, -30983, -31114, -31245, -31375, -31505, -31634, -31762,
+    -31890, -32017, -32144, -32270, -32395, -32520, -32644, -32768, -32890,
+    -33013, -33134, -33255, -33376, -33495, -33614, -33733, -33851, -33968,
+    -34084, -34200, -34316, -34430, -34544, -34657, -34770, -34882, -34993,
+    -35104, -35214, -35323, -35431, -35539, -35647, -35753, -35859, -35964,
+    -36069, -36173, -36276, -36378, -36480, -36581, -36681, -36781, -36880,
+    -36978, -37076, -37173, -37269, -37364, -37459, -37553, -37646, -37739,
+    -37831, -37922, -38012, -38102, -38191, -38279, -38367, -38453, -38539,
+    -38625, -38709, -38793, -38876, -38959, -39040, -39121, -39201, -39281,
+    -39359, -39437, -39514, -39591, -39666, -39741, -39815, -39889, -39961,
+    -40033, -40104, -40175, -40244, -40313, -40381, -40448, -40515, -40580,
+    -40645, -40709, -40773, -40835, -40897, -40958, -41019, -41078, -41137,
+    -41195, -41252, -41308, -41364, -41419, -41473, -41526, -41578, -41630,
+    -41681, -41731, -41780, -41828, -41876, -41923, -41969, -42014, -42059,
+    -42102, -42145, -42187, -42228, -42269, -42309, -42347, -42385, -42423,
+    -42459, -42495, -42529, -42563, -42597, -42629, -42661, -42691, -42721,
+    -42750, -42779, -42806, -42833, -42859, -42884, -42908, -42931, -42954,
+    -42976, -42997, -43017, -43036, -43055, -43072, -43089, -43105, -43120,
+    -43135, -43148, -43161, -43173, -43184, -43194, -43204, -43213, -43220,
+    -43227, -43234, -43239, -43243, -43247, -43250, -43252, -43253, -43254,
+    -43253, -43252, -43250, -43247, -43243, -43239, -43234, -43227, -43220,
+    -43213, -43204, -43194, -43184, -43173, -43161, -43148, -43135, -43120,
+    -43105, -43089, -43072, -43055, -43036, -43017, -42997, -42976, -42954,
+    -42931, -42908, -42884, -42859, -42833, -42806, -42779, -42750, -42721,
+    -42691, -42661, -42629, -42597, -42563, -42529, -42495, -42459, -42423,
+    -42385, -42347, -42309, -42269, -42228, -42187, -42145, -42102, -42059,
+    -42014, -41969, -41923, -41876, -41828, -41780, -41731, -41681, -41630,
+    -41578, -41526, -41473, -41419, -41364, -41308, -41252, -41195, -41137,
+    -41078, -41019, -40958, -40897, -40835, -40773, -40709, -40645, -40580,
+    -40515, -40448, -40381, -40313, -40244, -40175, -40104, -40033, -39961,
+    -39889, -39815, -39741, -39666, -39591, -39514, -39437, -39359, -39281,
+    -39201, -39121, -39040, -38959, -38876, -38793, -38709, -38625, -38539,
+    -38453, -38367, -38279, -38191, -38102, -38012, -37922, -37831, -37739,
+    -37646, -37553, -37459, -37364, -37269, -37173, -37076, -36978, -36880,
+    -36781, -36681, -36581, -36480, -36378, -36276, -36173, -36069, -35964,
+    -35859, -35753, -35647, -35539, -35431, -35323, -35214, -35104, -34993,
+    -34882, -34770, -34657, -34544, -34430, -34316, -34200, -34084, -33968,
+    -33851, -33733, -33614, -33495, -33376, -33255, -33134, -33013, -32890,
+    -32768, -32644, -32520, -32395, -32270, -32144, -32017, -31890, -31762,
+    -31634, -31505, -31375, -31245, -31114, -30983, -30851, -30718, -30585,
+    -30451, -30317, -30182, -30047, -29911, -29774, -29637, -29499, -29361,
+    -29222, -29082, -28942, -28802, -28661, -28519, -28377, -28234, -28091,
+    -27947, -27803, -27658, -27513, -27367, -27220, -27074, -26926, -26778,
+    -26630, -26481, -26331, -26181, -26031, -25880, -25728, -25576, -25424,
+    -25271, -25118, -24964, -24809, -24655, -24499, -24343, -24187, -24031,
+    -23873, -23716, -23558, -23399, -23240, -23081, -22921, -22761, -22600,
+    -22439, -22277, -22115, -21953, -21790, -21627, -21463, -21299, -21135,
+    -20970, -20805, -20639, -20473, -20306, -20140, -19972, -19805, -19637,
+    -19468, -19300, -19131, -18961, -18791, -18621, -18451, -18280, -18109,
+    -17937, -17765, -17593, -17420, -17247, -17074, -16901, -16727, -16552,
+    -16378, -16203, -16028, -15853, -15677, -15501, -15324, -15148, -14971,
+    -14794, -14616, -14438, -14260, -14082, -13903, -13725, -13546, -13366,
+    -13187, -13007, -12827, -12646, -12466, -12285, -12104, -11922, -11741,
+    -11559, -11377, -11195, -11012, -10830, -10647, -10464, -10281, -10097,
+    -9914,  -9730,  -9546,  -9362,  -9177,  -8993,  -8808,  -8623,  -8438,
+    -8253,  -8068,  -7882,  -7697,  -7511,  -7325,  -7139,  -6953,  -6766,
+    -6580,  -6393,  -6207,  -6020,  -5833,  -5646,  -5459,  -5271,  -5084,
+    -4896,  -4709,  -4521,  -4334,  -4146,  -3958,  -3770,  -3582,  -3394,
+    -3205,  -3017,  -2829,  -2641,  -2452,  -2264,  -2075,  -1887,  -1698,
+    -1510,  -1321,  -1132,  -944,   -755,   -566,   -377,   -189,   0,
+};
 
-word LUTplaneY[360] = {
-    43247,  43227,  43194,  43148,  43089,  43017,  42931,  42833,  42721,
-    42597,  42459,  42309,  42145,  41969,  41780,  41578,  41364,  41137,
-    40897,  40645,  40381,  40104,  39815,  39514,  39201,  38876,  38539,
-    38191,  37831,  37459,  37076,  36681,  36276,  35859,  35431,  34993,
-    34544,  34084,  33614,  33134,  32644,  32144,  31634,  31114,  30585,
-    30047,  29499,  28942,  28377,  27803,  27220,  26630,  26031,  25424,
-    24809,  24187,  23558,  22921,  22277,  21627,  20970,  20306,  19637,
-    18961,  18280,  17593,  16901,  16203,  15501,  14794,  14082,  13366,
-    12646,  11922,  11195,  10464,  9730,   8993,   8253,   7511,   6766,
-    6020,   5271,   4521,   3770,   3017,   2264,   1510,   755,    0,
-    -755,   -1510,  -2264,  -3017,  -3770,  -4521,  -5271,  -6020,  -6766,
-    -7511,  -8253,  -8993,  -9730,  -10464, -11195, -11922, -12646, -13366,
-    -14082, -14794, -15501, -16203, -16901, -17593, -18280, -18961, -19637,
-    -20306, -20970, -21627, -22277, -22921, -23558, -24187, -24809, -25424,
-    -26031, -26630, -27220, -27803, -28377, -28942, -29499, -30047, -30585,
-    -31114, -31634, -32144, -32644, -33134, -33614, -34084, -34544, -34993,
-    -35431, -35859, -36276, -36681, -37076, -37459, -37831, -38191, -38539,
-    -38876, -39201, -39514, -39815, -40104, -40381, -40645, -40897, -41137,
-    -41364, -41578, -41780, -41969, -42145, -42309, -42459, -42597, -42721,
-    -42833, -42931, -43017, -43089, -43148, -43194, -43227, -43247, -43254,
-    -43247, -43227, -43194, -43148, -43089, -43017, -42931, -42833, -42721,
-    -42597, -42459, -42309, -42145, -41969, -41780, -41578, -41364, -41137,
-    -40897, -40645, -40381, -40104, -39815, -39514, -39201, -38876, -38539,
-    -38191, -37831, -37459, -37076, -36681, -36276, -35859, -35431, -34993,
-    -34544, -34084, -33614, -33134, -32644, -32144, -31634, -31114, -30585,
-    -30047, -29499, -28942, -28377, -27803, -27220, -26630, -26031, -25424,
-    -24809, -24187, -23558, -22921, -22277, -21627, -20970, -20306, -19637,
-    -18961, -18280, -17593, -16901, -16203, -15501, -14794, -14082, -13366,
-    -12646, -11922, -11195, -10464, -9730,  -8993,  -8253,  -7511,  -6766,
-    -6020,  -5271,  -4521,  -3770,  -3017,  -2264,  -1510,  -755,   0,
-    755,    1510,   2264,   3017,   3770,   4521,   5271,   6020,   6766,
-    7511,   8253,   8993,   9730,   10464,  11195,  11922,  12646,  13366,
-    14082,  14794,  15501,  16203,  16901,  17593,  18280,  18961,  19637,
-    20306,  20970,  21627,  22277,  22921,  23558,  24187,  24809,  25424,
-    26031,  26630,  27220,  27803,  28377,  28942,  29499,  30047,  30585,
-    31114,  31634,  32144,  32644,  33134,  33614,  34084,  34544,  34993,
-    35431,  35859,  36276,  36681,  37076,  37459,  37831,  38191,  38539,
-    38876,  39201,  39514,  39815,  40104,  40381,  40645,  40897,  41137,
-    41364,  41578,  41780,  41969,  42145,  42309,  42459,  42597,  42721,
-    42833,  42931,  43017,  43089,  43148,  43194,  43227,  43247,  43254};
+word LUTplaneY[1440] = {
+    43253,  43252,  43250,  43247,  43243,  43239,  43234,  43227,  43220,
+    43213,  43204,  43194,  43184,  43173,  43161,  43148,  43135,  43120,
+    43105,  43089,  43072,  43055,  43036,  43017,  42997,  42976,  42954,
+    42931,  42908,  42884,  42859,  42833,  42806,  42779,  42750,  42721,
+    42691,  42661,  42629,  42597,  42563,  42529,  42495,  42459,  42423,
+    42385,  42347,  42309,  42269,  42228,  42187,  42145,  42102,  42059,
+    42014,  41969,  41923,  41876,  41828,  41780,  41731,  41681,  41630,
+    41578,  41526,  41473,  41419,  41364,  41308,  41252,  41195,  41137,
+    41078,  41019,  40958,  40897,  40835,  40773,  40709,  40645,  40580,
+    40515,  40448,  40381,  40313,  40244,  40175,  40104,  40033,  39961,
+    39889,  39815,  39741,  39666,  39591,  39514,  39437,  39359,  39281,
+    39201,  39121,  39040,  38959,  38876,  38793,  38709,  38625,  38539,
+    38453,  38367,  38279,  38191,  38102,  38012,  37922,  37831,  37739,
+    37646,  37553,  37459,  37364,  37269,  37173,  37076,  36978,  36880,
+    36781,  36681,  36581,  36480,  36378,  36276,  36173,  36069,  35964,
+    35859,  35753,  35647,  35539,  35431,  35323,  35214,  35104,  34993,
+    34882,  34770,  34657,  34544,  34430,  34316,  34200,  34084,  33968,
+    33851,  33733,  33614,  33495,  33376,  33255,  33134,  33013,  32890,
+    32768,  32644,  32520,  32395,  32270,  32144,  32017,  31890,  31762,
+    31634,  31505,  31375,  31245,  31114,  30983,  30851,  30718,  30585,
+    30451,  30317,  30182,  30047,  29911,  29774,  29637,  29499,  29361,
+    29222,  29082,  28942,  28802,  28661,  28519,  28377,  28234,  28091,
+    27947,  27803,  27658,  27513,  27367,  27220,  27074,  26926,  26778,
+    26630,  26481,  26331,  26181,  26031,  25880,  25728,  25576,  25424,
+    25271,  25118,  24964,  24809,  24655,  24499,  24343,  24187,  24031,
+    23873,  23716,  23558,  23399,  23240,  23081,  22921,  22761,  22600,
+    22439,  22277,  22115,  21953,  21790,  21627,  21463,  21299,  21135,
+    20970,  20805,  20639,  20473,  20306,  20140,  19972,  19805,  19637,
+    19468,  19300,  19131,  18961,  18791,  18621,  18451,  18280,  18109,
+    17937,  17765,  17593,  17420,  17247,  17074,  16901,  16727,  16552,
+    16378,  16203,  16028,  15853,  15677,  15501,  15324,  15148,  14971,
+    14794,  14616,  14438,  14260,  14082,  13903,  13725,  13546,  13366,
+    13187,  13007,  12827,  12646,  12466,  12285,  12104,  11922,  11741,
+    11559,  11377,  11195,  11012,  10830,  10647,  10464,  10281,  10097,
+    9914,   9730,   9546,   9362,   9177,   8993,   8808,   8623,   8438,
+    8253,   8068,   7882,   7697,   7511,   7325,   7139,   6953,   6766,
+    6580,   6393,   6207,   6020,   5833,   5646,   5459,   5271,   5084,
+    4896,   4709,   4521,   4334,   4146,   3958,   3770,   3582,   3394,
+    3205,   3017,   2829,   2641,   2452,   2264,   2075,   1887,   1698,
+    1510,   1321,   1132,   944,    755,    566,    377,    189,    0,
+    -189,   -377,   -566,   -755,   -944,   -1132,  -1321,  -1510,  -1698,
+    -1887,  -2075,  -2264,  -2452,  -2641,  -2829,  -3017,  -3205,  -3394,
+    -3582,  -3770,  -3958,  -4146,  -4334,  -4521,  -4709,  -4896,  -5084,
+    -5271,  -5459,  -5646,  -5833,  -6020,  -6207,  -6393,  -6580,  -6766,
+    -6953,  -7139,  -7325,  -7511,  -7697,  -7882,  -8068,  -8253,  -8438,
+    -8623,  -8808,  -8993,  -9177,  -9362,  -9546,  -9730,  -9914,  -10097,
+    -10281, -10464, -10647, -10830, -11012, -11195, -11377, -11559, -11741,
+    -11922, -12104, -12285, -12466, -12646, -12827, -13007, -13187, -13366,
+    -13546, -13725, -13903, -14082, -14260, -14438, -14616, -14794, -14971,
+    -15148, -15324, -15501, -15677, -15853, -16028, -16203, -16378, -16552,
+    -16727, -16901, -17074, -17247, -17420, -17593, -17765, -17937, -18109,
+    -18280, -18451, -18621, -18791, -18961, -19131, -19300, -19468, -19637,
+    -19805, -19972, -20140, -20306, -20473, -20639, -20805, -20970, -21135,
+    -21299, -21463, -21627, -21790, -21953, -22115, -22277, -22439, -22600,
+    -22761, -22921, -23081, -23240, -23399, -23558, -23716, -23873, -24031,
+    -24187, -24343, -24499, -24655, -24809, -24964, -25118, -25271, -25424,
+    -25576, -25728, -25880, -26031, -26181, -26331, -26481, -26630, -26778,
+    -26926, -27074, -27220, -27367, -27513, -27658, -27803, -27947, -28091,
+    -28234, -28377, -28519, -28661, -28802, -28942, -29082, -29222, -29361,
+    -29499, -29637, -29774, -29911, -30047, -30182, -30317, -30451, -30585,
+    -30718, -30851, -30983, -31114, -31245, -31375, -31505, -31634, -31762,
+    -31890, -32017, -32144, -32270, -32395, -32520, -32644, -32768, -32890,
+    -33013, -33134, -33255, -33376, -33495, -33614, -33733, -33851, -33968,
+    -34084, -34200, -34316, -34430, -34544, -34657, -34770, -34882, -34993,
+    -35104, -35214, -35323, -35431, -35539, -35647, -35753, -35859, -35964,
+    -36069, -36173, -36276, -36378, -36480, -36581, -36681, -36781, -36880,
+    -36978, -37076, -37173, -37269, -37364, -37459, -37553, -37646, -37739,
+    -37831, -37922, -38012, -38102, -38191, -38279, -38367, -38453, -38539,
+    -38625, -38709, -38793, -38876, -38959, -39040, -39121, -39201, -39281,
+    -39359, -39437, -39514, -39591, -39666, -39741, -39815, -39889, -39961,
+    -40033, -40104, -40175, -40244, -40313, -40381, -40448, -40515, -40580,
+    -40645, -40709, -40773, -40835, -40897, -40958, -41019, -41078, -41137,
+    -41195, -41252, -41308, -41364, -41419, -41473, -41526, -41578, -41630,
+    -41681, -41731, -41780, -41828, -41876, -41923, -41969, -42014, -42059,
+    -42102, -42145, -42187, -42228, -42269, -42309, -42347, -42385, -42423,
+    -42459, -42495, -42529, -42563, -42597, -42629, -42661, -42691, -42721,
+    -42750, -42779, -42806, -42833, -42859, -42884, -42908, -42931, -42954,
+    -42976, -42997, -43017, -43036, -43055, -43072, -43089, -43105, -43120,
+    -43135, -43148, -43161, -43173, -43184, -43194, -43204, -43213, -43220,
+    -43227, -43234, -43239, -43243, -43247, -43250, -43252, -43253, -43254,
+    -43253, -43252, -43250, -43247, -43243, -43239, -43234, -43227, -43220,
+    -43213, -43204, -43194, -43184, -43173, -43161, -43148, -43135, -43120,
+    -43105, -43089, -43072, -43055, -43036, -43017, -42997, -42976, -42954,
+    -42931, -42908, -42884, -42859, -42833, -42806, -42779, -42750, -42721,
+    -42691, -42661, -42629, -42597, -42563, -42529, -42495, -42459, -42423,
+    -42385, -42347, -42309, -42269, -42228, -42187, -42145, -42102, -42059,
+    -42014, -41969, -41923, -41876, -41828, -41780, -41731, -41681, -41630,
+    -41578, -41526, -41473, -41419, -41364, -41308, -41252, -41195, -41137,
+    -41078, -41019, -40958, -40897, -40835, -40773, -40709, -40645, -40580,
+    -40515, -40448, -40381, -40313, -40244, -40175, -40104, -40033, -39961,
+    -39889, -39815, -39741, -39666, -39591, -39514, -39437, -39359, -39281,
+    -39201, -39121, -39040, -38959, -38876, -38793, -38709, -38625, -38539,
+    -38453, -38367, -38279, -38191, -38102, -38012, -37922, -37831, -37739,
+    -37646, -37553, -37459, -37364, -37269, -37173, -37076, -36978, -36880,
+    -36781, -36681, -36581, -36480, -36378, -36276, -36173, -36069, -35964,
+    -35859, -35753, -35647, -35539, -35431, -35323, -35214, -35104, -34993,
+    -34882, -34770, -34657, -34544, -34430, -34316, -34200, -34084, -33968,
+    -33851, -33733, -33614, -33495, -33376, -33255, -33134, -33013, -32890,
+    -32768, -32644, -32520, -32395, -32270, -32144, -32017, -31890, -31762,
+    -31634, -31505, -31375, -31245, -31114, -30983, -30851, -30718, -30585,
+    -30451, -30317, -30182, -30047, -29911, -29774, -29637, -29499, -29361,
+    -29222, -29082, -28942, -28802, -28661, -28519, -28377, -28234, -28091,
+    -27947, -27803, -27658, -27513, -27367, -27220, -27074, -26926, -26778,
+    -26630, -26481, -26331, -26181, -26031, -25880, -25728, -25576, -25424,
+    -25271, -25118, -24964, -24809, -24655, -24499, -24343, -24187, -24031,
+    -23873, -23716, -23558, -23399, -23240, -23081, -22921, -22761, -22600,
+    -22439, -22277, -22115, -21953, -21790, -21627, -21463, -21299, -21135,
+    -20970, -20805, -20639, -20473, -20306, -20140, -19972, -19805, -19637,
+    -19468, -19300, -19131, -18961, -18791, -18621, -18451, -18280, -18109,
+    -17937, -17765, -17593, -17420, -17247, -17074, -16901, -16727, -16552,
+    -16378, -16203, -16028, -15853, -15677, -15501, -15324, -15148, -14971,
+    -14794, -14616, -14438, -14260, -14082, -13903, -13725, -13546, -13366,
+    -13187, -13007, -12827, -12646, -12466, -12285, -12104, -11922, -11741,
+    -11559, -11377, -11195, -11012, -10830, -10647, -10464, -10281, -10097,
+    -9914,  -9730,  -9546,  -9362,  -9177,  -8993,  -8808,  -8623,  -8438,
+    -8253,  -8068,  -7882,  -7697,  -7511,  -7325,  -7139,  -6953,  -6766,
+    -6580,  -6393,  -6207,  -6020,  -5833,  -5646,  -5459,  -5271,  -5084,
+    -4896,  -4709,  -4521,  -4334,  -4146,  -3958,  -3770,  -3582,  -3394,
+    -3205,  -3017,  -2829,  -2641,  -2452,  -2264,  -2075,  -1887,  -1698,
+    -1510,  -1321,  -1132,  -944,   -755,   -566,   -377,   -189,   0,
+    189,    377,    566,    755,    944,    1132,   1321,   1510,   1698,
+    1887,   2075,   2264,   2452,   2641,   2829,   3017,   3205,   3394,
+    3582,   3770,   3958,   4146,   4334,   4521,   4709,   4896,   5084,
+    5271,   5459,   5646,   5833,   6020,   6207,   6393,   6580,   6766,
+    6953,   7139,   7325,   7511,   7697,   7882,   8068,   8253,   8438,
+    8623,   8808,   8993,   9177,   9362,   9546,   9730,   9914,   10097,
+    10281,  10464,  10647,  10830,  11012,  11195,  11377,  11559,  11741,
+    11922,  12104,  12285,  12466,  12646,  12827,  13007,  13187,  13366,
+    13546,  13725,  13903,  14082,  14260,  14438,  14616,  14794,  14971,
+    15148,  15324,  15501,  15677,  15853,  16028,  16203,  16378,  16552,
+    16727,  16901,  17074,  17247,  17420,  17593,  17765,  17937,  18109,
+    18280,  18451,  18621,  18791,  18961,  19131,  19300,  19468,  19637,
+    19805,  19972,  20140,  20306,  20473,  20639,  20805,  20970,  21135,
+    21299,  21463,  21627,  21790,  21953,  22115,  22277,  22439,  22600,
+    22761,  22921,  23081,  23240,  23399,  23558,  23716,  23873,  24031,
+    24187,  24343,  24499,  24655,  24809,  24964,  25118,  25271,  25424,
+    25576,  25728,  25880,  26031,  26181,  26331,  26481,  26630,  26778,
+    26926,  27074,  27220,  27367,  27513,  27658,  27803,  27947,  28091,
+    28234,  28377,  28519,  28661,  28802,  28942,  29082,  29222,  29361,
+    29499,  29637,  29774,  29911,  30047,  30182,  30317,  30451,  30585,
+    30718,  30851,  30983,  31114,  31245,  31375,  31505,  31634,  31762,
+    31890,  32017,  32144,  32270,  32395,  32520,  32644,  32768,  32890,
+    33013,  33134,  33255,  33376,  33495,  33614,  33733,  33851,  33968,
+    34084,  34200,  34316,  34430,  34544,  34657,  34770,  34882,  34993,
+    35104,  35214,  35323,  35431,  35539,  35647,  35753,  35859,  35964,
+    36069,  36173,  36276,  36378,  36480,  36581,  36681,  36781,  36880,
+    36978,  37076,  37173,  37269,  37364,  37459,  37553,  37646,  37739,
+    37831,  37922,  38012,  38102,  38191,  38279,  38367,  38453,  38539,
+    38625,  38709,  38793,  38876,  38959,  39040,  39121,  39201,  39281,
+    39359,  39437,  39514,  39591,  39666,  39741,  39815,  39889,  39961,
+    40033,  40104,  40175,  40244,  40313,  40381,  40448,  40515,  40580,
+    40645,  40709,  40773,  40835,  40897,  40958,  41019,  41078,  41137,
+    41195,  41252,  41308,  41364,  41419,  41473,  41526,  41578,  41630,
+    41681,  41731,  41780,  41828,  41876,  41923,  41969,  42014,  42059,
+    42102,  42145,  42187,  42228,  42269,  42309,  42347,  42385,  42423,
+    42459,  42495,  42529,  42563,  42597,  42629,  42661,  42691,  42721,
+    42750,  42779,  42806,  42833,  42859,  42884,  42908,  42931,  42954,
+    42976,  42997,  43017,  43036,  43055,  43072,  43089,  43105,  43120,
+    43135,  43148,  43161,  43173,  43184,  43194,  43204,  43213,  43220,
+    43227,  43234,  43239,  43243,  43247,  43250,  43252,  43253,  43254,
+};
 
 word texture[8][texWidth * texHeight] = {
     // eagle

+ 14 - 0
BCC/userBDOS/LIB/GFX.C

@@ -485,6 +485,20 @@ void GFX_initVram()
 }
 
 
+// Clear parameters
+void GFX_setHalfRes(word halfRes)
+{
+  asm(
+
+
+  "; vram address\n"
+  "load32 0xC02749 r2    ; r2 = halfRes addr\n"
+  "write 0 r2 r4       ; write arg to halfRes addr\n"
+
+  );
+}
+
+
 // convert x and y to position for window table
 word GFX_WindowPosFromXY(word x, word y)
 {

+ 14 - 0
BCC/userBDOS/LIB/STDLIB.C

@@ -473,6 +473,20 @@ void delay(word ms)
   while (timer1Value == 0);
 }
 
+// Returns milliseconds since last reset
+word millis() 
+{
+  word retval = 0;
+
+  asm(
+    "load32 0xC0274A r2\n"  // millis addr
+    "read 0 r2 r2\n"        // read millis
+    "write -4 r14 r2\n"     // write to stack to return
+    );
+
+  return retval;
+}
+
 
 // Returns interrupt ID by using the readintid asm instruction
 word getIntID()

+ 96 - 54
BCC/userBDOS/RAYCAST.C

@@ -19,8 +19,8 @@
 
 // Note: these are also hardcoded in the render assembly, so update there as well!
 #define FB_ADDR       0xD00000
-#define screenWidth   320
-#define screenHeight  240
+#define screenWidth   160
+#define screenHeight  120
 #define texWidth      64
 #define texHeight     64
 #define mapWidth  24
@@ -55,7 +55,7 @@
 #include "DATA/RAYDAT.C"
 
 // Framebuffer. fb[Y][X] (bottom right is [239][319])
-char (*fb)[screenWidth] = (char (*)[screenWidth])FB_ADDR;
+char (*fb)[320] = (char (*)[320])FB_ADDR;
 
 word worldMap[mapWidth][mapHeight] = {
     {4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 7, 7, 7, 7, 7, 7, 7, 7},
@@ -83,8 +83,7 @@ word worldMap[mapWidth][mapHeight] = {
     {4, 0, 0, 0, 0, 0, 0, 0, 0, 4, 6, 0, 6, 2, 0, 0, 0, 0, 0, 2, 0, 0, 0, 2},
     {4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3}};
 
-word frameCounter = 0;
-word frameCounterLoop = 0;
+word frameDone = 0;
 
 // Global render variables
 word drawStart = 0;
@@ -290,7 +289,7 @@ void RAYFX_renderScreen()
     // leaving to use: 4, 5, 8, 9, 11, 12, 13, 14, 15
 
     // r4: lineHeight
-    "load32 240 r15\n"          // r15 = screenHeight
+    "load32 120 r15\n"          // r15 = screenHeight
     "shiftl r15 16 r15\n"       // r15 = FP(screenHeight)
     "load32 0xC02742 r14\n"     // r14 = addr fpdiv_writea
     "write 0 r14 r15\n"         // write a (FP(screenHeight) to divider
@@ -301,24 +300,24 @@ void RAYFX_renderScreen()
     "shiftrs r4 1 r15\n"        // r15 = lineHeight >> 1
     "load32 -1 r14\n"           // r14 = -1
     "mults r15 r14 r15\n"       // r15 = -r15
-    "load32 120 r14\n"          // r14 = screenHeight >> 1
+    "load32 60 r14\n"          // r14 = screenHeight >> 1
     "add r14 r15 r15\n"         // r15 = drawStart value (r14+r15)
     "bges r15 r0 2\n"           // skip next line if drawStart >= 0
       "load 0 r15\n"            // set drawStart to 0 if < 0
     "addr2reg drawStart r14\n"  // r14 = drawStart addr
     "write 0 r14 r15\n"         // write drawStart value
 
-    // skip render if start > 238
-    "load32 238 r14\n"
+    // skip render if start > 118
+    "load32 118 r14\n"
     "blts r15 r14 2 \n"
       "jump RAYFX_skipRenderLine\n"
 
     "shiftrs r4 1 r15\n"        // r15 = lineHeight >> 1
-    "load32 120 r14\n"          // r14 = screenHeight >> 1
+    "load32 60 r14\n"          // r14 = screenHeight >> 1
     "add r14 r15 r15\n"         // r15 = drawEnd value (r14+r15)
-    "load32 240 r14\n"          // r14 = screenHeight
+    "load32 120 r14\n"          // r14 = screenHeight
     "blts r15 r14 2\n"          // skip next line if drawEnd < screenHeight
-      "load 239 r15\n"          // set drawEnd to screenHeight - 1
+      "load 120 r15\n"          // set drawEnd to screenHeight - 1
     "addr2reg drawEnd r14\n"    // r14 = drawEnd addr
     "write 0 r14 r15\n"         // write drawEnd value
 
@@ -368,21 +367,20 @@ void RAYFX_renderScreen()
     "shiftl r15 16 r15\n"       // r15 = FP(texHeight)
     "shiftl r4 16 r14\n"        // r14 = FP(lineHeight)
     "load32 0xC02742 r13\n"     // r13 = addr fpdiv_writea
-    "write 0 r13 r15\n"         // write a (FP(screenHeight) to divider
+    "write 0 r13 r15\n"         // write a (FP(texHeight) to divider
     "write 1 r13 r14\n"         // write b (FP(lineHeight)) to divider and perform division
     "read 1 r13 r5\n"           // read result to r5
 
     // r4: texPos
     "addr2reg drawStart r15\n"  // r15 = drawStart addr
     "read 0 r15 r15\n"          // r15 = drawStart value
-    "sub r15 120 r15\n"         // r15 -= (screenHeight >> 1)
+    "sub r15 60 r15\n"          // r15 -= (screenHeight >> 1)
     "shiftrs r4 1 r14\n"        // r14 = lineHeight >> 1
     "add r15 r14 r15\n"         // r15 += lineHeight >> 1
     "shiftl r15 16 r15\n"       // r15 = FP(r15)
     "multfp r15 r5 r4\n"        // r4 = r15 * step
 
-    "or r1 r0 r7\n"             // move x to r7
-
+    "shiftl r1 0 r7\n"          // move x to r7
 
     // Render vertical line in pixel plane with textures
     // Registers:
@@ -430,6 +428,8 @@ void RAYFX_renderScreen()
     "addr2reg side r15      ; r15 = side addr\n"
     "read 0 r15 r15         ; r15 = side value\n"
 
+    "ble r2 r0 5           ; skip ceiling if wall starts at first pixel\n"
+
     // draw until start
     "RAYFX_drawVlineLoopCeiling:\n"
     "  write 0 r8 r14     ; write ceiling pixel\n"
@@ -470,9 +470,10 @@ void RAYFX_renderScreen()
     "  jump RAYFX_drawVlineLoopWall\n"
 
 
+    "load32 120 r11\n"
+    "bge r3 r11 10           ; skip floor if wall ends at bottom of screen\n"
 
-
-    "load32 239 r9          ; r9 = last y position\n"
+    "load32 119 r9          ; r9 = last y position\n"
     "multu r9 320 r9        ; r9 = screen end VRAM offset\n"
     "add r9 r1 r9           ; r9 = last FB pos of line\n"
 
@@ -493,7 +494,7 @@ void RAYFX_renderScreen()
     
 
     "add r1 1 r1\n"             // r1 = x++
-    "load32 320 r15\n"          // r15 = stop x loop (screenWidth)
+    "load32 160 r15\n"          // r15 = stop x loop (screenWidth)
     "bge r1 r15 2\n"            // keep looping until reached final vline (x) of screen
     "jump RAYFX_screenXloop\n"
   );
@@ -519,6 +520,7 @@ int main() {
   GFX_clearWindowpaletteTable();
   GFX_clearBGtileTable();
   GFX_clearBGpaletteTable();
+  GFX_setHalfRes(1);
 
     // x and y start position
   RAY_posX = FP_intToFP(15);
@@ -534,59 +536,64 @@ int main() {
 
   // rotation angle (loops at 360)
   word rotationAngle = 0;
-  word rotationSpeed = 5;  // degrees per frame
+  word rotationSpeed = 0;  // degrees per frame
 
-  fixed_point_t moveSpeed = FP_StringToFP("0.15");
-  fixed_point_t movePadding = 0;//FP_StringToFP("0.3");
+  fixed_point_t moveSpeed = 0;
+  fixed_point_t movePadding = FP_StringToFP("0.15");
 
   word quitGame = 0;
 
+  word prevMillis = millis();
+
   while (!quitGame) {
-    
+
+    // wait until at least one frame has passed
+    while (!frameDone);
+    frameDone = 0;
+
     // render screen
     RAYFX_renderScreen();
 
     // calculate and draw FPS
-    if (frameCounterLoop == 10)
-    {
-      word fps = MATH_div(600, frameCounter);
-      frameCounter = 0;
-      char buffer[11];
-      itoa(fps, buffer);
-      // clear fps digits (assumes fps <= 999)
-      asm(
-      "push r1\n"
-      "load32 0xC01420 r1       ; r1 = vram addr\n"
-      "write 0 r1 r0            ; write char to vram\n"
-      "write 1 r1 r0            ; write char to vram\n"
-      "write 2 r1 r0            ; write char to vram\n"
-      "pop r1\n"
-      );
-      
-      GFX_printWindowColored(buffer, strlen(buffer), 0, 0);
-      frameCounterLoop = 0;
-    }
-    else
-    {
-      frameCounterLoop++;
-    }
+    word currentMillis = millis();
+    word renderMillis = currentMillis - prevMillis;
+    prevMillis = currentMillis;
+    word fps = FP_FPtoInt(FP_Div(FP_intToFP(1000), FP_intToFP(renderMillis)));
+
+    char buffer[11];
+    itoa(fps, buffer);
+    // clear fps digits (assumes fps <= 999)
+    asm(
+    "push r1\n"
+    "load32 0xC01420 r1       ; r1 = vram addr\n"
+    "write 0 r1 r0            ; write char to vram\n"
+    "write 1 r1 r0            ; write char to vram\n"
+    "write 2 r1 r0            ; write char to vram\n"
+    "pop r1\n"
+    );
+    
+    GFX_printWindowColored(buffer, strlen(buffer), 0, 0);
+
+    // adjust movement and rotation speed based on FPS
+    moveSpeed = FP_Mult(FP_Div(FP_intToFP(renderMillis), FP_intToFP(1000)), FP_intToFP(3));
+    rotationSpeed = renderMillis >> 1;
 
     // check which button is held
-    if (BDOS_USBkeyHeld(BTN_LEFT)) {
+    if (BDOS_USBkeyHeld('a')) {
       // both camera direction and camera plane must be rotated
       rotationAngle -= rotationSpeed;
       if (rotationAngle < 0) {
-        rotationAngle += 360;
+        rotationAngle += 1440;
       }
       RAY_dirX = LUTdirX[rotationAngle];
       RAY_dirY = LUTdirY[rotationAngle];
       RAY_planeX = LUTplaneX[rotationAngle];
       RAY_planeY = LUTplaneY[rotationAngle];
-    } else if (BDOS_USBkeyHeld(BTN_RIGHT)) {
+    } else if (BDOS_USBkeyHeld('d')) {
       // both camera direction and camera plane must be rotated
       rotationAngle += rotationSpeed;
-      if (rotationAngle >= 360) {
-        rotationAngle -= 360;
+      if (rotationAngle >= 1440) {
+        rotationAngle -= 1440;
       }
       RAY_dirX = LUTdirX[rotationAngle];
       RAY_dirY = LUTdirY[rotationAngle];
@@ -594,7 +601,7 @@ int main() {
       RAY_planeY = LUTplaneY[rotationAngle];
     }
 
-    if (BDOS_USBkeyHeld(BTN_UP)) {
+    if (BDOS_USBkeyHeld('w')) {
       word worldMapX = FP_FPtoInt(RAY_posX + FP_Mult(RAY_dirX, moveSpeed + movePadding));
       word worldMapY = FP_FPtoInt(RAY_posY);
 
@@ -607,7 +614,7 @@ int main() {
       if (worldMap[worldMapX][worldMapY] == 0) {
         RAY_posY += FP_Mult(RAY_dirY, moveSpeed);
       }
-    } else if (BDOS_USBkeyHeld(BTN_DOWN)) {
+    } else if (BDOS_USBkeyHeld('s')) {
       word worldMapX = FP_FPtoInt(RAY_posX - FP_Mult(RAY_dirX, moveSpeed + movePadding));
       word worldMapY = FP_FPtoInt(RAY_posY);
 
@@ -620,6 +627,32 @@ int main() {
       if (worldMap[worldMapX][worldMapY] == 0) {
         RAY_posY -= FP_Mult(RAY_dirY, moveSpeed);
       }
+    } else if (BDOS_USBkeyHeld('e')) {
+      word worldMapX = FP_FPtoInt(RAY_posX + FP_Mult(RAY_planeX, moveSpeed + movePadding));
+      word worldMapY = FP_FPtoInt(RAY_posY);
+
+      if (worldMap[worldMapX][worldMapY] == 0) {
+        RAY_posX += FP_Mult(RAY_planeX, moveSpeed);
+      }
+
+      worldMapX = FP_FPtoInt(RAY_posX);
+      worldMapY = FP_FPtoInt(RAY_posY + FP_Mult(RAY_planeY, moveSpeed + movePadding));
+      if (worldMap[worldMapX][worldMapY] == 0) {
+        RAY_posY += FP_Mult(RAY_planeY, moveSpeed);
+      }
+    } else if (BDOS_USBkeyHeld('q')) {
+      word worldMapX = FP_FPtoInt(RAY_posX - FP_Mult(RAY_planeX, moveSpeed + movePadding));
+      word worldMapY = FP_FPtoInt(RAY_posY);
+
+      if (worldMap[worldMapX][worldMapY] == 0) {
+        RAY_posX -= FP_Mult(RAY_planeX, moveSpeed);
+      }
+
+      worldMapX = FP_FPtoInt(RAY_posX);
+      worldMapY = FP_FPtoInt(RAY_posY - FP_Mult(RAY_planeY, moveSpeed + movePadding));
+      if (worldMap[worldMapX][worldMapY] == 0) {
+        RAY_posY -= FP_Mult(RAY_planeY, moveSpeed);
+      }
     }
 
     if (HID_FifoAvailable()) {
@@ -633,8 +666,17 @@ int main() {
         GFX_clearWindowpaletteTable();
         GFX_clearBGtileTable();
         GFX_clearBGpaletteTable();
+        GFX_setHalfRes(0);
         quitGame = 1;
       }
+      else if (c == '1')
+      {
+        GFX_setHalfRes(0);
+      }
+      else if (c == '2')
+      {
+        GFX_setHalfRes(1);
+      }
     }
   }
 
@@ -656,7 +698,7 @@ void interrupt() {
       break;
 
     case INTID_GPU:
-      frameCounter++;
+      frameDone++;
       break;
 
     case INTID_TIMER3:

+ 4 - 2
Documentation/docs/Hardware/Logic/Memory/Map.md

@@ -99,8 +99,10 @@ $C02722 +------------------------+
         | I_div_divbs    $C02745 |
         | I_div_divbu    $C02746 |
         | I_div_mods     $C02747 |
-        | I_div_modu     $C02748 | $C02748
-$C02742 +------------------------+
+        | I_div_modu     $C02748 |
+        | halfRes        $C02749 |
+        | millis         $C0274A | $C0274A
+$C0274B +------------------------+
         |                        |
         |        Nothing         |
         |                        | $CFFFFF

+ 1 - 1
Graphics/Raycast/generateCameraX.py

@@ -1,6 +1,6 @@
 # Script to precalculate cameraX values
 
-screenWidth = 320
+screenWidth = 160
 
 def doubleToFP16(x):
     return round(x * pow(2,16))

+ 2 - 2
Graphics/Raycast/generateDirPlaneValues.py

@@ -48,8 +48,8 @@ def moveRight(rotSpeed, function):
         print(str(doubleToFP16(planeY)) + ", ", end='')
 
 # pi/180 means 360 even steps -> one per degree (so use 360 as looplength)
-rotSpeed = pi/180
-loopLength = 360
+rotSpeed = pi/720
+loopLength = 1440
 
 # Create lookup table for each function
 for function in functionsToCreateTableOf:

+ 1 - 0
Quartus/FPGC.qsf

@@ -229,6 +229,7 @@ set_global_assignment -name NUM_PARALLEL_PROCESSORS ALL
 set_global_assignment -name ALM_REGISTER_PACKING_EFFORT LOW
 set_global_assignment -name SDC_FILE FPGC.sdc
 set_global_assignment -name VERILOG_FILE modules/FPGC.v
+set_global_assignment -name VERILOG_FILE modules/IO/MillisCounter.v
 set_global_assignment -name VERILOG_FILE modules/IO/IDivider.v
 set_global_assignment -name VERILOG_FILE modules/IO/FPDivider.v
 set_global_assignment -name VERILOG_FILE modules/Memory/L1Icache.v

TEMPAT SAMPAH
Quartus/FPGC.qws


+ 5 - 1
Quartus/modules/FPGC.v

@@ -485,7 +485,7 @@ SDRAMcontroller sdramcontroller(
 
 //-----------------------FSX-------------------------
 // FSX I/O
-
+wire        halfRes;
 //wire [7:0]  composite;              // NTSC composite video signal
 
 FSX fsx(
@@ -506,6 +506,8 @@ FSX fsx(
 // Select output method
 //.selectOutput   (selectOutput),
 
+.halfRes(halfRes),
+
 // VRAM32
 .vram32_addr    (vram32_gpu_addr),
 .vram32_q       (vram32_gpu_q),
@@ -675,6 +677,8 @@ MemoryUnit mu(
 .PS2_data   (PS2_data),
 .PS2_int    (PS2_int), //Scan code ready signal
 
+.halfRes(halfRes),
+
 // Boot mode
 .boot_mode  (boot_mode_stable)
 );

+ 3 - 0
Quartus/modules/GPU/FSX.v

@@ -20,6 +20,8 @@ module FSX(
     //Select output method
     //input selectOutput,
 
+    input halfRes,
+
     //VRAM32
     output [13:0]       vram32_addr,
     input  [31:0]       vram32_q, 
@@ -172,6 +174,7 @@ PixelEngine pixelEngine(
     .blank(blank),
 
     .scale2x(selectOutput),
+    .halfRes(halfRes),
     
     // Output colors
     .r(PX_r),

+ 3 - 1
Quartus/modules/GPU/PixelEngine.v

@@ -9,6 +9,7 @@ module PixelEngine(
     input               blank,
     input               scale2x,    // render vertically in 2x scaling (e.g. for HDMI to get full screen 320x240 on a 640x480 signal)
                                     // note: horizontally this scaling is always applied
+    input               halfRes,    // render half res at full res (160x120 as 320x240), basically zooms in at top left corner
 
     // Output pixels
     output wire [7:0]   r,
@@ -38,7 +39,8 @@ wire v_active = (v_count > v_start);
 wire [9:0] line_active = (v_active) ? v_count-(v_start+1'b1) : 10'd0;
 wire [9:0] pixel_active = (h_active && v_active) ? h_count-h_start : 10'd0;
 
-wire [16:0] pixel_idx = ( (line_active >> scale2x) *320) + (pixel_active >> 1);
+wire [16:0] pixel_idx = (halfRes) ? ( ((line_active >> scale2x) >> 1) *320) + (pixel_active >> 2):
+                            ( (line_active >> scale2x) *320) + (pixel_active >> 1);
 
 assign vram_addr = pixel_idx;
 

+ 32 - 0
Quartus/modules/IO/MillisCounter.v

@@ -0,0 +1,32 @@
+// 32 bit millisecond counter starting from reset
+
+module MillisCounter(
+    input clk,
+    input reset,
+    output reg [31:0] millis = 32'd0
+);
+
+reg [15:0] delayCounter = 16'd0; // counter for timing 1 ms
+
+always @(posedge clk)
+begin
+    if (reset)
+    begin
+        millis          <= 32'd0;
+        delayCounter    <= 16'd0;
+    end
+    else
+    begin
+        if (delayCounter == 16'd49999)
+        begin
+            delayCounter <= 16'd0;
+            millis <= millis + 1'b1;
+        end
+        else
+        begin
+            delayCounter <= delayCounter + 1'b1;
+        end
+    end
+end
+
+endmodule

+ 26 - 1
Quartus/modules/Memory/MemoryUnit.v

@@ -115,6 +115,8 @@ module MemoryUnit(
     input           PS2_clk, PS2_data,
     output          PS2_int,            //Scan code ready signal
 
+    output reg halfRes = 1'b0,
+
     //Boot mode
     input           boot_mode
 
@@ -167,7 +169,9 @@ localparam
     A_IDIVSTARTS = 42,
     A_IDIVSTARTU = 43,
     A_IDIVMODS = 44,
-    A_IDIVMODU = 45;
+    A_IDIVMODU = 45,
+    A_HALFRES = 46,
+    A_MILLIS = 47;
 
 //------------
 //SPI0 (flash) TODO: move this to a separate module
@@ -493,7 +497,16 @@ OStimer OST3(
 );
 
 
+//------------
+//Millis counter
+//------------
+wire [31:0] millis;
 
+MillisCounter millisCounter(
+.clk        (clk),
+.reset      (reset),
+.millis     (millis)
+);
 
 //------------
 //SNES controller
@@ -730,6 +743,8 @@ begin
     if (bus_addr == 27'hC02746) a_sel = A_IDIVSTARTU;
     if (bus_addr == 27'hC02747) a_sel = A_IDIVMODS;
     if (bus_addr == 27'hC02748) a_sel = A_IDIVMODU;
+    if (bus_addr == 27'hC02749) a_sel = A_HALFRES;
+    if (bus_addr == 27'hC0274A) a_sel = A_MILLIS;
     if (bus_addr >= 27'hD00000 && bus_addr < 27'hD12C00) a_sel = A_VRAMPX;
 end
 
@@ -782,6 +797,7 @@ begin
         A_IDIVSTARTU:   bus_q_wire = idiv_q;
         A_IDIVMODS:     bus_q_wire = idiv_r;
         A_IDIVMODU:     bus_q_wire = idiv_r;
+        A_MILLIS:       bus_q_wire = millis;
         default:        bus_q_wire = 32'd0;
     endcase
 end
@@ -997,6 +1013,15 @@ begin
                         if (!bus_done_next) bus_done_next <= 1'b1;
                 end
 
+                A_HALFRES:
+                begin
+                    if (bus_we)
+                    begin
+                        halfRes <= bus_data[0];
+                    end
+                        if (!bus_done_next) bus_done_next <= 1'b1;
+                end
+
                 default:
                 begin
                     if (!bus_done_next) bus_done_next <= 1'b1;

TEMPAT SAMPAH
Quartus/output_files/output_file.jic


+ 5 - 0
Verilog/modules/FPGC6.v

@@ -433,6 +433,7 @@ SDRAMcontroller sdramcontroller(
 //FSX I/O
 wire [7:0]  composite; // NTSC composite video signal
 reg         selectOutput = 1'b1; // 1 -> HDMI, 0 -> Composite
+wire        halfRes;
 
 FSX fsx(
 //Clocks
@@ -453,6 +454,8 @@ FSX fsx(
 //Select output method
 //.selectOutput   (selectOutput),
 
+.halfRes(halfRes),
+
 //VRAM32
 .vram32_addr    (vram32_gpu_addr),
 .vram32_q       (vram32_gpu_q),
@@ -621,6 +624,8 @@ MemoryUnit mu(
 .PS2_data   (PS2_data),
 .PS2_int    (PS2_int), //Scan code ready signal
 
+.halfRes(halfRes),
+
 //Boot mode
 .boot_mode  (boot_mode_stable)
 );

+ 3 - 0
Verilog/modules/GPU/FSX.v

@@ -20,6 +20,8 @@ module FSX(
     //Select output method
     //input selectOutput,
 
+    input halfRes,
+
     //VRAM32
     output [13:0]       vram32_addr,
     input  [31:0]       vram32_q, 
@@ -183,6 +185,7 @@ PixelEngine pixelEngine(
     .blank(blank),
 
     .scale2x(selectOutput),
+    .halfRes(halfRes),
     
     // Output colors
     .r(PX_r),

+ 3 - 1
Verilog/modules/GPU/PixelEngine.v

@@ -9,6 +9,7 @@ module PixelEngine(
     input               blank,
     input               scale2x,    // render vertically in 2x scaling (e.g. for HDMI to get full screen 320x240 on a 640x480 signal)
                                     // note: horizontally this scaling is always applied
+    input               halfRes,    // render half res at full res (160x120 as 320x240), basically zooms in at top left corner
 
     // Output pixels
     output wire [7:0]   r,
@@ -38,7 +39,8 @@ wire v_active = (v_count > v_start);
 wire [9:0] line_active = (v_active) ? v_count-(v_start+1'b1) : 10'd0;
 wire [9:0] pixel_active = (h_active && v_active) ? h_count-h_start : 10'd0;
 
-wire [16:0] pixel_idx = ( (line_active >> scale2x) *320) + (pixel_active >> 1);
+wire [16:0] pixel_idx = (halfRes) ? ( ((line_active >> scale2x) >> 1) *320) + (pixel_active >> 2):
+                            ( (line_active >> scale2x) *320) + (pixel_active >> 1);
 
 assign vram_addr = pixel_idx;
 

+ 32 - 0
Verilog/modules/IO/MillisCounter.v

@@ -0,0 +1,32 @@
+// 32 bit millisecond counter starting from reset
+
+module MillisCounter(
+    input clk,
+    input reset,
+    output reg [31:0] millis = 32'd0
+);
+
+reg [15:0] delayCounter = 16'd0; // counter for timing 1 ms
+
+always @(posedge clk)
+begin
+    if (reset)
+    begin
+        millis          <= 32'd0;
+        delayCounter    <= 16'd0;
+    end
+    else
+    begin
+        if (delayCounter == 16'd49999)
+        begin
+            delayCounter <= 16'd0;
+            millis <= millis + 1'b1;
+        end
+        else
+        begin
+            delayCounter <= delayCounter + 1'b1;
+        end
+    end
+end
+
+endmodule

+ 26 - 1
Verilog/modules/Memory/MemoryUnit.v

@@ -115,6 +115,8 @@ module MemoryUnit(
     input           PS2_clk, PS2_data,
     output          PS2_int,            //Scan code ready signal
 
+    output reg halfRes = 1'b0,
+
     //Boot mode
     input           boot_mode
 
@@ -167,7 +169,9 @@ localparam
     A_IDIVSTARTS = 42,
     A_IDIVSTARTU = 43,
     A_IDIVMODS = 44,
-    A_IDIVMODU = 45;
+    A_IDIVMODU = 45,
+    A_HALFRES = 46,
+    A_MILLIS = 47;
 
 //------------
 //SPI0 (flash) TODO: move this to a separate module
@@ -493,7 +497,16 @@ OStimer OST3(
 );
 
 
+//------------
+//Millis counter
+//------------
+wire [31:0] millis;
 
+MillisCounter millisCounter(
+.clk        (clk),
+.reset      (reset),
+.millis     (millis)
+);
 
 //------------
 //SNES controller
@@ -730,6 +743,8 @@ begin
     if (bus_addr == 27'hC02746) a_sel = A_IDIVSTARTU;
     if (bus_addr == 27'hC02747) a_sel = A_IDIVMODS;
     if (bus_addr == 27'hC02748) a_sel = A_IDIVMODU;
+    if (bus_addr == 27'hC02749) a_sel = A_HALFRES;
+    if (bus_addr == 27'hC0274A) a_sel = A_MILLIS;
     if (bus_addr >= 27'hD00000 && bus_addr < 27'hD12C00) a_sel = A_VRAMPX;
 end
 
@@ -782,6 +797,7 @@ begin
         A_IDIVSTARTU:   bus_q_wire = idiv_q;
         A_IDIVMODS:     bus_q_wire = idiv_r;
         A_IDIVMODU:     bus_q_wire = idiv_r;
+        A_MILLIS:       bus_q_wire = millis;
         default:        bus_q_wire = 32'd0;
     endcase
 end
@@ -997,6 +1013,15 @@ begin
                         if (!bus_done_next) bus_done_next <= 1'b1;
                 end
 
+                A_HALFRES:
+                begin
+                    if (bus_we)
+                    begin
+                        halfRes <= bus_data[0];
+                    end
+                        if (!bus_done_next) bus_done_next <= 1'b1;
+                end
+
                 default:
                 begin
                     if (!bus_done_next) bus_done_next <= 1'b1;

+ 1 - 0
Verilog/testbench/FPGC_tb.v

@@ -47,6 +47,7 @@
 `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/IO/LEDvisualizer.v"
 `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/IO/FPDivider.v"
 `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/IO/IDivider.v"
+`include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/IO/MillisCounter.v"
 
 // gpu
 `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/GPU/FSX.v"