From 2ff677c5d345d95366b88c783362a6edb6e288b5 Mon Sep 17 00:00:00 2001 From: crc Date: Mon, 14 Oct 2019 15:17:43 +0000 Subject: [PATCH] proper rng device in retro-unix FossilOrigin-Name: fc95ae344b6ea961c9e65426b0b8820104c4b9f9a74a35a125635f207fff2b16 --- example/edit.retro | 12 +- source/interfaces/io/rng.retro | 25 +++-- source/interfaces/retro-image.c | 176 +++++++++++++++--------------- source/interfaces/retro-runtime.c | 39 ++++++- source/interfaces/retro-unix.c | 36 +++++- 5 files changed, 180 insertions(+), 108 deletions(-) diff --git a/example/edit.retro b/example/edit.retro index 80557d8..3c803be 100755 --- a/example/edit.retro +++ b/example/edit.retro @@ -1,4 +1,11 @@ -#!/usr/bin/env retro +#!/bin/sh + +stty cbreak +/usr/bin/env retro $0 $1 +stty -cbreak +exit + +--------------------------------------------------------------- _ _ | | | |_ _ __ _ | |_| | | | |/ _` | @@ -348,11 +355,10 @@ top level loop. $h [ &CurrentLine v:inc constrain ] case $t [ &CurrentLine v:dec constrain ] case $g [ goto constrain ] case - $q [ 'stty_-cbreak unix:system bye ] case + $q [ bye ] case drop ; :edit - 'stty_cbreak unix:system repeat display help handler again ; diff --git a/source/interfaces/io/rng.retro b/source/interfaces/io/rng.retro index f54b787..e1e6711 100644 --- a/source/interfaces/io/rng.retro +++ b/source/interfaces/io/rng.retro @@ -1,17 +1,20 @@ ## Random Value +~~~ +{{ + 'io var + :identify + @io n:zero? [ + #10 io:scan-for dup n:negative? + [ drop 'IO_DEVICE_TYPE_0010_NOT_FOUND s:put nl ] + [ !io ] choose ] if ; + ---reveal--- + :io:rng identify @io io:invoke ; +}} +~~~ + Return a random value from /dev/urandom ~~~ -{{ - :random:byte - '/dev/urandom file:R file:open - &file:read sip file:close ; ----reveal--- - :n:random - random:byte #-8 shift - random:byte + #-8 shift - random:byte + #8 shift - random:byte + ; -}} +:n:random (-n) io:rng ; ~~~ diff --git a/source/interfaces/retro-image.c b/source/interfaces/retro-image.c index 10c8735..69da8cb 100644 --- a/source/interfaces/retro-image.c +++ b/source/interfaces/retro-image.c @@ -2,8 +2,8 @@ #ifndef CELL #define CELL int32_t #endif -CELL ngaImageCells = 15920; -CELL ngaImage[] = { 1793,15666,15897,15919,201909,0,10,1,10,2,10,3,10,4,10,5,10,6,10, +CELL ngaImageCells = 15966; +CELL ngaImage[] = { 1793,15712,15943,15965,201909,0,10,1,10,2,10,3,10,4,10,5,10,6,10, 7,10,8,10,9,10,10,10,11,10,12,10,13,10,14,10,15,10,16,10, 17,10,18,10,19,10,20,10,21,10,22,10,23,10,24,10,25,10,68223234,1, 2575,85000450,1,656912,140,139,268505089,64,63,135205121,64,10,101384453,0,9,10,2049,57,25,459011, @@ -11,7 +11,7 @@ CELL ngaImage[] = { 1793,15666,15897,15919,201909,0,10,1,10,2,10,3,10,4,10,5,10, 17565186,85,524545,89,65,167838467,-1,134287105,3,60,659457,3,459023,106,2049,57,25,2049,106,1793, 113,2049,113,117506307,0,106,0,524545,25,111,168820993,0,125,1642241,125,134283523,7,111,1793,106, 7,524545,2049,106,1793,106,16846593,125,140,139,1793,65,16846593,125,111,139,1793,65,7,10, - 659713,1,659713,2,659713,3,1793,10467,2,524559,106,2049,106,2049,106,2049,120,168820998,2,14763, + 659713,1,659713,2,659713,3,1793,10467,2,524559,106,2049,106,2049,106,2049,120,168820998,2,14809, 1025,167841793,178,5,17826049,0,178,2,15,25,524546,163,134287105,179,94,2305,180,459023,188,134287361, 179,183,659201,178,2049,57,25,84152833,48,286458116,10,459014,203,184618754,45,25,16974851,-1,168886532,1, 134284289,1,212,134284289,0,203,660227,32,0,0,112,114,101,102,105,120,58,105,0,285278479, @@ -162,7 +162,7 @@ CELL ngaImage[] = { 1793,15666,15897,15919,201909,0,10,1,10,2,10,3,10,4,10,5,10, 3122,8,10,1,3120,2049,2076,10,1,3118,2049,2076,4,16,10,3099,3146,145,118,58, 117,112,100,97,116,101,0,4,1793,3153,15,4,8,10,1,3149,2049,2088,16,10, 3134,3167,145,99,111,112,121,0,1793,3176,1,57,2049,2076,2049,60,10,1,3169,2049, - 2256,3,3,10,3159,3196,145,83,99,111,112,101,76,105,115,116,0,15710,15762,10, + 2256,3,3,10,3159,3196,145,83,99,111,112,101,76,105,115,116,0,15756,15808,10, 3183,3205,145,123,123,0,2049,1570,2,1,3196,2049,60,16,10,3199,3230,145,45,45, 45,114,101,118,101,97,108,45,45,45,0,2049,1570,1,3196,2049,2914,16,10,3214, 3244,145,125,125,0,1,3196,2049,57,4,15,11,1793,3258,3841,3196,4097,2,10,1, @@ -182,7 +182,7 @@ CELL ngaImage[] = { 1793,15666,15897,15919,201909,0,10,1,10,2,10,3,10,4,10,5,10, 2076,4097,3312,10,3480,3538,132,84,101,109,112,83,116,114,105,110,103,115,0,32, 3523,3556,132,84,101,109,112,83,116,114,105,110,103,77,97,120,0,512,3539,3568, 145,83,84,82,73,78,71,83,0,2049,1543,3841,3538,3841,3556,19,18,10,3557,3588, - 132,67,117,114,114,101,110,116,0,5,10,3577,3603,145,115,58,112,111,105,110, + 132,67,117,114,114,101,110,116,0,7,10,3577,3603,145,115,58,112,111,105,110, 116,101,114,0,3841,3588,3841,3556,19,2049,3568,17,10,3590,3622,145,115,58,110,101, 120,116,0,1,3588,2049,3015,3841,3588,3841,3538,11,1793,3638,1,0,4097,3588,10,1, 3633,9,10,3557,3652,145,115,58,116,101,109,112,0,2,2049,80,2049,2914,2049,3603, @@ -497,7 +497,7 @@ CELL ngaImage[] = { 1793,15666,15897,15919,201909,0,10,1,10,2,10,3,10,4,10,5,10, 104,63,0,1,3,1793,9838,2,2049,7058,1,13,2049,2076,2049,7988,2049,9774,10,1, 9826,2049,3113,10,9804,9859,145,97,58,101,110,100,115,45,119,105,116,104,63,0, 1,3,1793,9875,2,2049,7058,1,13,2049,2076,2049,8033,2049,9774,10,1,9863,2049,3113, - 10,9843,9886,132,76,80,0,0,9880,9896,132,73,110,100,101,120,0,0,8,0, + 10,9843,9886,132,76,80,0,0,9880,9896,132,73,110,100,101,120,0,0,9,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,9887,9936,145,110,101,120,116,0,3841,9886,1, 9896,17,2049,3015,10,9928,9952,145,112,114,101,112,0,1,9886,2049,3015,1,0,3841, @@ -719,84 +719,86 @@ CELL ngaImage[] = { 1793,15666,15897,15919,201909,0,10,1,10,2,10,3,10,4,10,5,10, 108,111,99,107,58,117,116,99,58,104,111,117,114,0,1,29,2049,13473,10,14255, 14298,145,99,108,111,99,107,58,117,116,99,58,109,105,110,117,116,101,0,1, 30,2049,13473,10,14278,14323,145,99,108,111,99,107,58,117,116,99,58,115,101,99, - 111,110,100,0,1,31,2049,13473,10,14303,14343,145,114,97,110,100,111,109,58,98, - 121,116,101,0,2049,3697,47,100,101,118,47,117,114,97,110,100,111,109,0,1, - 14345,1,0,2049,10669,1,10706,2049,2088,2049,10688,10,14303,14383,145,110,58,114,97,110, - 100,111,109,0,2049,14343,1,-8,24,2049,14343,17,1,-8,24,2049,14343,17,1,8, - 24,2049,14343,17,10,14371,14418,132,105,111,58,83,111,99,107,101,116,115,0,0, - 14404,14431,145,105,100,101,110,116,105,102,121,0,3841,14418,2049,2573,1793,14498,1,7, - 2049,10192,2,2049,2608,1793,14486,3,2049,3697,73,79,32,68,69,86,73,67,69,32, - 84,89,80,69,32,48,48,48,52,32,78,79,84,32,70,79,85,78,68,0, - 1,14449,2049,10285,2049,10248,10,1,14446,1793,14493,4097,14418,10,1,14490,2049,65,10,1, - 14437,9,10,14371,14525,145,105,111,58,115,111,99,107,101,116,45,111,112,101,114, - 97,116,105,111,110,0,2049,14431,3841,14418,2049,10166,10,14502,14556,145,115,111,99,107, - 101,116,58,103,101,116,104,111,115,116,98,121,110,97,109,101,0,1,0,2049, - 14525,10,14532,14578,145,115,111,99,107,101,116,58,99,114,101,97,116,101,0,1, - 1,2049,14525,10,14561,14598,145,115,111,99,107,101,116,58,98,105,110,100,0,1, - 2,2049,14525,10,14583,14620,145,115,111,99,107,101,116,58,108,105,115,116,101,110, - 0,1,3,2049,14525,10,14603,14642,145,115,111,99,107,101,116,58,97,99,99,101, - 112,116,0,1,4,2049,14525,10,14625,14665,145,115,111,99,107,101,116,58,99,111, - 110,110,101,99,116,0,1,5,2049,14525,10,14647,14685,145,115,111,99,107,101,116, - 58,115,101,110,100,0,1,6,2049,14525,10,14670,14705,145,115,111,99,107,101,116, - 58,114,101,99,118,0,1,8,2049,14525,10,14690,14726,145,115,111,99,107,101,116, - 58,99,108,111,115,101,0,1,10,2049,14525,10,14710,14751,145,115,111,99,107,101, - 116,58,99,111,110,102,105,103,117,114,101,0,1,11,2049,14525,10,14731,1024,132, - 84,73,66,0,14756,14777,145,105,109,97,103,101,58,115,97,118,101,0,1,1000, - 2049,10192,2049,10166,10,14763,14799,132,105,111,58,75,101,121,98,111,97,114,100,0, - 0,14784,14812,145,105,100,101,110,116,105,102,121,0,3841,14799,2049,2573,1793,14879,1, - 1,2049,10192,2,2049,2608,1793,14867,3,2049,3697,73,79,32,68,69,86,73,67,69, - 32,84,89,80,69,32,48,48,48,49,32,78,79,84,32,70,79,85,78,68, - 0,1,14830,2049,10285,2049,10248,10,1,14827,1793,14874,4097,14799,10,1,14871,2049,65,10, - 1,14818,9,10,14763,14892,145,99,58,103,101,116,0,2049,14812,3841,14799,2049,10166,10, - 14883,14909,145,103,97,116,104,101,114,0,2,1793,14916,1,8,11,10,1,14912,1793, - 14924,1,127,11,10,1,14920,2049,2103,22,1793,14933,3,10,1,14931,1793,14940,2049,3383, - 10,1,14937,2049,65,10,14899,14954,145,99,121,99,108,101,0,2049,14892,2049,2066,4, - 8,2049,2726,25,3,2049,14909,1,14954,7,10,14883,14985,145,112,97,114,115,101,45, - 117,110,116,105,108,0,1793,14997,2049,3678,2049,3475,2049,14954,771,2049,3349,10,1,14987, - 2049,3499,10,14970,15011,145,115,58,103,101,116,0,1793,15033,1793,15019,1,10,11,10, - 1,15015,1793,15027,1,13,11,10,1,15023,2049,2103,22,10,1,15013,2049,14985,10,15002, - 15054,132,105,111,58,83,99,114,105,112,116,105,110,103,0,4,15038,15067,145,105, - 100,101,110,116,105,102,121,0,3841,15054,2049,2573,1793,15134,1,9,2049,10192,2,2049, - 2608,1793,15122,3,2049,3697,73,79,32,68,69,86,73,67,69,32,84,89,80,69, - 32,48,48,48,57,32,78,79,84,32,70,79,85,78,68,0,1,15085,2049,10285, - 2049,10248,10,1,15082,1793,15129,4097,15054,10,1,15126,2049,65,10,1,15073,9,10,15002, - 15150,145,115,121,115,58,97,114,103,99,0,2049,15067,1,0,3841,15054,2049,10166,10, - 15138,15171,145,115,121,115,58,97,114,103,118,0,2049,3678,4,2049,15067,1,1,3841, - 15054,2049,10166,10,15159,15194,145,105,110,99,108,117,100,101,0,2049,15067,1,2,3841, - 15054,2049,10166,10,15183,15215,145,115,121,115,58,110,97,109,101,0,2049,3678,2049,15067, - 1,3,3841,15054,2049,10166,10,15203,15235,145,99,108,101,97,114,0,1,27,2049,10235, - 2049,3697,91,50,74,0,1,15241,2049,10285,1,27,2049,10235,2049,3697,91,48,59,48, - 72,0,1,15255,2049,10285,10,15226,15276,132,78,111,69,99,104,111,0,0,15266,15284, - 145,98,121,101,0,1,0,2049,13607,10,15277,15300,145,118,101,114,115,105,111,110, - 0,3841,4,1,100,20,10,15289,15315,145,100,111,110,101,63,0,1793,15321,1,13, - 11,10,1,15317,1793,15329,1,10,11,10,1,15325,1793,15337,1,32,11,10,1,15333, - 2049,2140,22,22,10,15306,15354,145,118,97,108,105,100,63,0,2,2049,80,2049,2655, - 10,15344,15373,145,99,104,101,99,107,45,101,111,102,0,2,1793,15380,1,-1,11, - 10,1,15376,1793,15388,1,4,11,10,1,15384,2049,2103,22,1,15284,9,10,15360,15403, - 145,98,115,0,2049,3407,2049,3407,771,10,15397,15421,145,99,104,101,99,107,45,98, - 115,0,2,1793,15428,1,8,11,10,1,15424,1793,15436,1,127,11,10,1,15432,2049, - 2103,22,1,15403,9,10,15409,15454,145,99,104,101,99,107,0,2049,15373,2049,15421,10, - 15445,15472,145,99,104,97,114,97,99,116,101,114,0,2049,14892,2,2049,3383,10,15459, - 15488,145,98,117,102,102,101,114,0,1793,15498,1,1024,2049,3475,8,2049,3349,10,1, - 15490,2049,3499,10,15478,15517,145,114,101,97,100,45,116,111,107,101,110,0,1793,15533, - 1793,15528,2049,15472,2049,15454,2049,15315,10,1,15521,2049,2231,10,1,15519,2049,15488,2049,3790, - 10,15503,15549,145,105,110,112,117,116,0,2049,15517,2049,15354,10,15540,15565,145,112,114, - 111,99,101,115,115,0,1,365,1,11,2049,65,10,15277,15582,145,98,97,110,110, - 101,114,0,2049,15300,2049,3697,82,69,84,82,79,32,49,50,32,40,37,110,46, - 37,110,41,92,110,0,1,15586,2049,6724,2049,10285,2049,1543,2049,1847,18,2049,1847,2049, - 1543,2049,3697,37,110,32,77,97,120,44,32,37,110,32,85,115,101,100,44,32, - 37,110,32,70,114,101,101,92,110,0,1,15622,2049,6724,2049,10285,10,15572,15666,145, - 108,105,115,116,101,110,0,3841,15276,1793,15673,2049,15582,10,1,15670,2049,71,2049,15549, - 2049,15565,1,15677,7,10,15656,15696,145,100,58,119,111,114,100,115,0,1793,15705,2049, - 163,2049,10285,2049,10259,10,1,15698,2049,6966,10,15685,15726,145,100,58,119,111,114,100, - 115,45,119,105,116,104,0,2049,1847,2049,4746,1793,15757,2049,163,2,2049,1847,2049,4348, - 1793,15746,2049,10285,2049,10259,10,1,15741,1793,15752,3,10,1,15750,2049,65,10,1,15732, - 2049,6966,10,15710,15781,145,100,105,115,112,108,97,121,45,105,102,45,108,101,102, - 116,0,2,2049,1847,2049,4662,1793,15793,2049,10285,2049,10259,10,1,15788,1793,15799,3,10, - 1,15797,2049,65,10,15710,15830,145,100,58,119,111,114,100,115,45,98,101,103,105, - 110,110,105,110,103,45,119,105,116,104,0,2049,1847,2049,4746,1793,15841,2049,163,2049, - 15781,10,1,15836,2049,6966,10,15804,15860,145,117,110,105,120,58,119,114,105,116,101, - 0,1793,15866,2,2049,80,10,1,15862,2049,2076,1,12,2049,13473,10,15846,15892,145,117, - 110,105,120,58,105,111,58,110,58,112,117,116,0,1,17,2049,13473,10,15875,15914, - 145,117,110,105,120,58,105,111,58,115,58,112,117,116,0,1,18,2049,13473,10, - 0 }; + 111,110,100,0,1,31,2049,13473,10,14303,14334,132,105,111,0,0,14328,14347,145,105, + 100,101,110,116,105,102,121,0,3841,14334,2049,2573,1793,14414,1,10,2049,10192,2,2049, + 2608,1793,14402,3,2049,3697,73,79,32,68,69,86,73,67,69,32,84,89,80,69, + 32,48,48,49,48,32,78,79,84,32,70,79,85,78,68,0,1,14365,2049,10285, + 2049,10248,10,1,14362,1793,14409,4097,14334,10,1,14406,2049,65,10,1,14353,9,10,14303, + 14428,145,105,111,58,114,110,103,0,2049,14347,3841,14334,2049,10166,10,14418,14447,145,110, + 58,114,97,110,100,111,109,0,2049,14428,10,14435,14464,132,105,111,58,83,111,99, + 107,101,116,115,0,0,14450,14477,145,105,100,101,110,116,105,102,121,0,3841,14464, + 2049,2573,1793,14544,1,7,2049,10192,2,2049,2608,1793,14532,3,2049,3697,73,79,32,68, + 69,86,73,67,69,32,84,89,80,69,32,48,48,48,52,32,78,79,84,32, + 70,79,85,78,68,0,1,14495,2049,10285,2049,10248,10,1,14492,1793,14539,4097,14464,10, + 1,14536,2049,65,10,1,14483,9,10,14435,14571,145,105,111,58,115,111,99,107,101, + 116,45,111,112,101,114,97,116,105,111,110,0,2049,14477,3841,14464,2049,10166,10,14548, + 14602,145,115,111,99,107,101,116,58,103,101,116,104,111,115,116,98,121,110,97, + 109,101,0,1,0,2049,14571,10,14578,14624,145,115,111,99,107,101,116,58,99,114, + 101,97,116,101,0,1,1,2049,14571,10,14607,14644,145,115,111,99,107,101,116,58, + 98,105,110,100,0,1,2,2049,14571,10,14629,14666,145,115,111,99,107,101,116,58, + 108,105,115,116,101,110,0,1,3,2049,14571,10,14649,14688,145,115,111,99,107,101, + 116,58,97,99,99,101,112,116,0,1,4,2049,14571,10,14671,14711,145,115,111,99, + 107,101,116,58,99,111,110,110,101,99,116,0,1,5,2049,14571,10,14693,14731,145, + 115,111,99,107,101,116,58,115,101,110,100,0,1,6,2049,14571,10,14716,14751,145, + 115,111,99,107,101,116,58,114,101,99,118,0,1,8,2049,14571,10,14736,14772,145, + 115,111,99,107,101,116,58,99,108,111,115,101,0,1,10,2049,14571,10,14756,14797, + 145,115,111,99,107,101,116,58,99,111,110,102,105,103,117,114,101,0,1,11, + 2049,14571,10,14777,1024,132,84,73,66,0,14802,14823,145,105,109,97,103,101,58,115, + 97,118,101,0,1,1000,2049,10192,2049,10166,10,14809,14845,132,105,111,58,75,101,121, + 98,111,97,114,100,0,0,14830,14858,145,105,100,101,110,116,105,102,121,0,3841, + 14845,2049,2573,1793,14925,1,1,2049,10192,2,2049,2608,1793,14913,3,2049,3697,73,79,32, + 68,69,86,73,67,69,32,84,89,80,69,32,48,48,48,49,32,78,79,84, + 32,70,79,85,78,68,0,1,14876,2049,10285,2049,10248,10,1,14873,1793,14920,4097,14845, + 10,1,14917,2049,65,10,1,14864,9,10,14809,14938,145,99,58,103,101,116,0,2049, + 14858,3841,14845,2049,10166,10,14929,14955,145,103,97,116,104,101,114,0,2,1793,14962,1, + 8,11,10,1,14958,1793,14970,1,127,11,10,1,14966,2049,2103,22,1793,14979,3,10, + 1,14977,1793,14986,2049,3383,10,1,14983,2049,65,10,14945,15000,145,99,121,99,108,101, + 0,2049,14938,2049,2066,4,8,2049,2726,25,3,2049,14955,1,15000,7,10,14929,15031,145, + 112,97,114,115,101,45,117,110,116,105,108,0,1793,15043,2049,3678,2049,3475,2049,15000, + 771,2049,3349,10,1,15033,2049,3499,10,15016,15057,145,115,58,103,101,116,0,1793,15079, + 1793,15065,1,10,11,10,1,15061,1793,15073,1,13,11,10,1,15069,2049,2103,22,10, + 1,15059,2049,15031,10,15048,15100,132,105,111,58,83,99,114,105,112,116,105,110,103, + 0,4,15084,15113,145,105,100,101,110,116,105,102,121,0,3841,15100,2049,2573,1793,15180, + 1,9,2049,10192,2,2049,2608,1793,15168,3,2049,3697,73,79,32,68,69,86,73,67, + 69,32,84,89,80,69,32,48,48,48,57,32,78,79,84,32,70,79,85,78, + 68,0,1,15131,2049,10285,2049,10248,10,1,15128,1793,15175,4097,15100,10,1,15172,2049,65, + 10,1,15119,9,10,15048,15196,145,115,121,115,58,97,114,103,99,0,2049,15113,1, + 0,3841,15100,2049,10166,10,15184,15217,145,115,121,115,58,97,114,103,118,0,2049,3678, + 4,2049,15113,1,1,3841,15100,2049,10166,10,15205,15240,145,105,110,99,108,117,100,101, + 0,2049,15113,1,2,3841,15100,2049,10166,10,15229,15261,145,115,121,115,58,110,97,109, + 101,0,2049,3678,2049,15113,1,3,3841,15100,2049,10166,10,15249,15281,145,99,108,101,97, + 114,0,1,27,2049,10235,2049,3697,91,50,74,0,1,15287,2049,10285,1,27,2049,10235, + 2049,3697,91,48,59,48,72,0,1,15301,2049,10285,10,15272,15322,132,78,111,69,99, + 104,111,0,0,15312,15330,145,98,121,101,0,1,0,2049,13607,10,15323,15346,145,118, + 101,114,115,105,111,110,0,3841,4,1,100,20,10,15335,15361,145,100,111,110,101, + 63,0,1793,15367,1,13,11,10,1,15363,1793,15375,1,10,11,10,1,15371,1793,15383, + 1,32,11,10,1,15379,2049,2140,22,22,10,15352,15400,145,118,97,108,105,100,63, + 0,2,2049,80,2049,2655,10,15390,15419,145,99,104,101,99,107,45,101,111,102,0, + 2,1793,15426,1,-1,11,10,1,15422,1793,15434,1,4,11,10,1,15430,2049,2103,22, + 1,15330,9,10,15406,15449,145,98,115,0,2049,3407,2049,3407,771,10,15443,15467,145,99, + 104,101,99,107,45,98,115,0,2,1793,15474,1,8,11,10,1,15470,1793,15482,1, + 127,11,10,1,15478,2049,2103,22,1,15449,9,10,15455,15500,145,99,104,101,99,107, + 0,2049,15419,2049,15467,10,15491,15518,145,99,104,97,114,97,99,116,101,114,0,2049, + 14938,2,2049,3383,10,15505,15534,145,98,117,102,102,101,114,0,1793,15544,1,1024,2049, + 3475,8,2049,3349,10,1,15536,2049,3499,10,15524,15563,145,114,101,97,100,45,116,111, + 107,101,110,0,1793,15579,1793,15574,2049,15518,2049,15500,2049,15361,10,1,15567,2049,2231,10, + 1,15565,2049,15534,2049,3790,10,15549,15595,145,105,110,112,117,116,0,2049,15563,2049,15400, + 10,15586,15611,145,112,114,111,99,101,115,115,0,1,365,1,11,2049,65,10,15323, + 15628,145,98,97,110,110,101,114,0,2049,15346,2049,3697,82,69,84,82,79,32,49, + 50,32,40,37,110,46,37,110,41,92,110,0,1,15632,2049,6724,2049,10285,2049,1543, + 2049,1847,18,2049,1847,2049,1543,2049,3697,37,110,32,77,97,120,44,32,37,110,32, + 85,115,101,100,44,32,37,110,32,70,114,101,101,92,110,0,1,15668,2049,6724, + 2049,10285,10,15618,15712,145,108,105,115,116,101,110,0,3841,15322,1793,15719,2049,15628,10, + 1,15716,2049,71,2049,15595,2049,15611,1,15723,7,10,15702,15742,145,100,58,119,111,114, + 100,115,0,1793,15751,2049,163,2049,10285,2049,10259,10,1,15744,2049,6966,10,15731,15772,145, + 100,58,119,111,114,100,115,45,119,105,116,104,0,2049,1847,2049,4746,1793,15803,2049, + 163,2,2049,1847,2049,4348,1793,15792,2049,10285,2049,10259,10,1,15787,1793,15798,3,10,1, + 15796,2049,65,10,1,15778,2049,6966,10,15756,15827,145,100,105,115,112,108,97,121,45, + 105,102,45,108,101,102,116,0,2,2049,1847,2049,4662,1793,15839,2049,10285,2049,10259,10, + 1,15834,1793,15845,3,10,1,15843,2049,65,10,15756,15876,145,100,58,119,111,114,100, + 115,45,98,101,103,105,110,110,105,110,103,45,119,105,116,104,0,2049,1847,2049, + 4746,1793,15887,2049,163,2049,15827,10,1,15882,2049,6966,10,15850,15906,145,117,110,105,120, + 58,119,114,105,116,101,0,1793,15912,2,2049,80,10,1,15908,2049,2076,1,12,2049, + 13473,10,15892,15938,145,117,110,105,120,58,105,111,58,110,58,112,117,116,0,1, + 17,2049,13473,10,15921,15960,145,117,110,105,120,58,105,111,58,115,58,112,117,116, + 0,1,18,2049,13473,10,0 }; diff --git a/source/interfaces/retro-runtime.c b/source/interfaces/retro-runtime.c index f36622b..9fcf841 100644 --- a/source/interfaces/retro-runtime.c +++ b/source/interfaces/retro-runtime.c @@ -33,7 +33,7 @@ #include #include #include - +#include /*--------------------------------------------------------------------- Configuration @@ -60,7 +60,7 @@ #define D_OFFSET_CLASS 2 #define D_OFFSET_NAME 3 -#define NUM_DEVICES 7 /* Set the number of I/O devices */ +#define NUM_DEVICES 8 /* Set the number of I/O devices */ #define MAX_OPEN_FILES 128 @@ -108,6 +108,8 @@ void io_scripting_handler(); void io_scripting_query(); void io_image(); void io_image_query(); +void io_random(); +void io_random_query(); #if defined __GNU_LIBRARY__ || defined __GLIBC__ size_t strlcat(char *dst, const char *src, size_t dsize); @@ -130,7 +132,8 @@ Handler IO_deviceHandlers[NUM_DEVICES + 1] = { io_floatingpoint_handler, io_scripting_handler, io_unix_handler, - io_image + io_image, + io_random, }; Handler IO_queryHandlers[NUM_DEVICES + 1] = { @@ -140,7 +143,8 @@ Handler IO_queryHandlers[NUM_DEVICES + 1] = { io_floatingpoint_query, io_scripting_query, io_unix_query, - io_image_query + io_image_query, + io_random_query, }; @@ -276,6 +280,33 @@ void io_image_query() { } +/*=====================================================================*/ + +/*--------------------------------------------------------------------- + Random Number Generator + ---------------------------------------------------------------------*/ + +void io_random() { + CELL r = 0; + char buffer[8]; + int fd = open("/dev/urandom", O_RDONLY); + read(fd, buffer, 8); + close(fd); + for(int i = 0; i < 8; ++i) { + r = r << 8; + r += ((CELL)buffer[i] & 0xFF); + } + stack_push(abs(r)); +} + +void io_random_query() { + stack_push(0); + stack_push(10); +} + +/*=====================================================================*/ + + /*=====================================================================*/ diff --git a/source/interfaces/retro-unix.c b/source/interfaces/retro-unix.c index 0e270aa..3607f1c 100644 --- a/source/interfaces/retro-unix.c +++ b/source/interfaces/retro-unix.c @@ -33,6 +33,7 @@ #include #include #include +#include /*--------------------------------------------------------------------- Configuration @@ -59,7 +60,7 @@ #define D_OFFSET_CLASS 2 #define D_OFFSET_NAME 3 -#define NUM_DEVICES 8 /* Set the number of I/O devices */ +#define NUM_DEVICES 9 /* Set the number of I/O devices */ #define MAX_OPEN_FILES 128 @@ -107,6 +108,8 @@ void io_scripting_handler(); void io_scripting_query(); void io_image(); void io_image_query(); +void io_random(); +void io_random_query(); void io_socket(); void query_socket(); @@ -129,7 +132,8 @@ Handler IO_deviceHandlers[NUM_DEVICES + 1] = { io_scripting_handler, io_unix_handler, io_image, - io_socket + io_socket, + io_random, }; Handler IO_queryHandlers[NUM_DEVICES + 1] = { @@ -140,7 +144,8 @@ Handler IO_queryHandlers[NUM_DEVICES + 1] = { io_scripting_query, io_unix_query, io_image_query, - query_socket + query_socket, + io_random_query, }; @@ -1506,6 +1511,31 @@ void query_socket() { stack_push(7); } + +/*=====================================================================*/ + +/*--------------------------------------------------------------------- + Random Number Generator + ---------------------------------------------------------------------*/ + +void io_random() { + CELL r = 0; + char buffer[8]; + int fd = open("/dev/urandom", O_RDONLY); + read(fd, buffer, 8); + close(fd); + for(int i = 0; i < 8; ++i) { + r = r << 8; + r += ((CELL)buffer[i] & 0xFF); + } + stack_push(abs(r)); +} + +void io_random_query() { + stack_push(0); + stack_push(10); +} + /*=====================================================================*/