r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[rebcode] Rebcode discussion

Coccinelle
23-Feb-2007
[1810x2]
Usefull to call sub routine :
test: rebcode [
	i [integer!]
	/local ret-ofs begin
][
label begin
	brab [lab-1 lab-2] i

label lab-1
	print "call from lab-1"
	setl ret-ofs ret-1
	bra sub
label ret-1
	print "returned to ret-1"
	exit

label lab-2
	print "call from lab-2"
	setl ret-ofs ret-2
	bra sub
label ret-2
	print "returned to ret-2"
	exit

label sub
	print "pass thru sub"
	brab begin ret-ofs
]
>> test 0
call from lab-1
pass thru sub
returned to ret-1
>> test 1
call from lab-2
pass thru sub
returned to ret-2
>>
Steeve
23-Feb-2007
[1812x6]
hum, i'm not sure of  the utility of your code. Currently,  the development 
of the Z80 virtual machine is achieved and is very simple.
label Start
xcv
label start
pickz op-code memory adress
brab [          ;list of opcode
	...
             ...
             LD_A_B
            ... 
] op-code
label LD_A_B set.i _a _b bra start
the new rebcode version, is several times faster than the old, i'm 
happy !,  and I did not convert the video emulation into rebcode 
yet  , so ,   I think that we will be able to play in a screen much 
larger while keeping fluidity.
i could share my work, is the Altme Filesharing  working ? i think 
not
BrianH
23-Feb-2007
[1818x2]
A direct interpreter, or I guess a tokenized interpreter using the 
original opcodes as tokens, which amounts to the same thing. Interesting. 
I suppose that would be simplest way to do it, and a threaded interpreter 
would be a little hard in rebcode because of the relative branches. 
Good job!
I notice that your example doesn't adjust the program counter - I 
assume that these adjustments are performed by your real code.
Steeve
23-Feb-2007
[1820]
yeah it was a sample, my code is a little more complex
BrianH
23-Feb-2007
[1821x2]
Your new version also deals with the too-many-words backwards-compatibility 
problem that the old approach had, by just having words for opcodes 
rather than addresses. It should also have much less memory overhead 
than my compiled suggestion, and not require generating the rebcode 
of the interpreter - it is probably hand-codeable.
Are all opcodes distinguishable by a single byte, or do you have 
a more complex instruction decoding process?
Steeve
23-Feb-2007
[1823x4]
current state of my work http://perso.orange.fr/rebol/code.r
op-code may be on several bytes
i use several brab in sequence
if needed
BrianH
23-Feb-2007
[1827x2]
Several branches for every instruction, but probably optimizable 
on a special-case basis. Definitely slower than compiled rebcode, 
but much less complex and without the compiler overhead, so perhaps 
not that much slower. Much more compatible with self-modifying code. 
Also likely more compatible with JIT-compiled rebcode when that happens. 
Some code-generation on your interpreter, but mostly hand-coded. 
Overall, nice.
Your VM is single-instance right now, but that won't be a problem 
until R3's threading. For now, multiple interpreters can be in different 
REBOL processes. I don't know enough about what you are interpreting 
to know whether that matters :)
Steeve
23-Feb-2007
[1829x2]
mostly Game roms
they don't need multi trheading
BrianH
23-Feb-2007
[1831]
Probably not, then. You might want to wrap this all in a context 
statement to capture the global variables you're using.
Steeve
23-Feb-2007
[1832x3]
currently i'm looking for a good implementation of DDA opcode (Decimal 
adjust for BDC numbers)
quite difficult
*BCD numbers
BrianH
23-Feb-2007
[1835]
BCD numbers in games?
Steeve
23-Feb-2007
[1836]
yes for displaying score or other human readable numbers
BrianH
23-Feb-2007
[1837]
That platform has BCD-based output opcodes? Surprising - most use 
integers and string conversion.
Steeve
23-Feb-2007
[1838x4]
i found one that uses a look-up table of 4096 entries... little big
yes but addition and substractions are performed on char! (byte)
so, this instruction is used to addapt the result in a bcd form
for example if you add 06h and 04h, you get 0Ah which is the correct 
result in byte form, using DAA after such addition, convert the result 
into 10h which is the correct result in BCD form
BrianH
23-Feb-2007
[1842]
DDA operates on a per-byte basis?
Steeve
23-Feb-2007
[1843x2]
yep
DAA instead of DDA (made a mispell)
BrianH
23-Feb-2007
[1845]
How does it handle out-of-range values?
Steeve
23-Feb-2007
[1846]
it sets a flag which we calls carry (like the T flag in rebcode)
BrianH
23-Feb-2007
[1847]
I would think a pickz on a 256-byte binary would do for a lookup 
table, putting a flag value in the invalid slots. Then you could 
react to the flag afterwards.
Steeve
23-Feb-2007
[1848x4]
yes but it's a little more difficult
DAA react diffenrently after an addition or a cubstraction
*substraction
256 entries for the lookup table is not enough
BrianH
23-Feb-2007
[1852]
More than one lookup table, depending on circumstances?
Steeve
23-Feb-2007
[1853]
4096 entries are requested to cover all possiblities
BrianH
23-Feb-2007
[1854]
Perhaps some math to do much of the work would be preferable.
Steeve
23-Feb-2007
[1855]
finally, 4ko, is not so huge
BrianH
23-Feb-2007
[1856]
You are right there...
Steeve
23-Feb-2007
[1857]
*4 kb :-)
BrianH
23-Feb-2007
[1858]
I forget (and don't have rebcode installed on this PC), what happens 
if you pick out-of-range in rebcode?
Steeve
23-Feb-2007
[1859]
don't konw , never occured