X-Git-Url: http://www2.svjatoslav.eu/gitweb/?p=fifth.git;a=blobdiff_plain;f=doc%2Fvirtual%20machine.html;fp=doc%2Fvirtual%20machine.html;h=fbf1f6cf9e6f6ce963b83c42253f591edec177e7;hp=0000000000000000000000000000000000000000;hb=0df562d446afbd2094012c8e57fb4144c510c434;hpb=be12874c4742b31507e81536b80db7de4b800d24 diff --git a/doc/virtual machine.html b/doc/virtual machine.html new file mode 100644 index 0000000..fbf1f6c --- /dev/null +++ b/doc/virtual machine.html @@ -0,0 +1,677 @@ + + + + + + + +Fifth - virtual machine + + + + + + +
+

Fifth - virtual machine

+
+

Table of Contents

+ +
+

+Current emulator emulates: +

+ + + +

+While I tried to keep instruction set simple, I was forced to put in +some complex instructions to make performance acceptable on +emulator. +

+ +

+CPU has following registers: +

+
+
IP
instruction pointer
+
DSP
data stack pointer
+
RSP
return stack pointer
+
+ +
+

1. Instructions overview

+
+

+Virtual CPU, commands (most of them are avaiable as ordinary commands +in programming language): +

+ + + + + +++ ++ ++ ++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#namestack footprintdescription
0nop--does nothing
1halt--halt CPU ( return to DOS on emulator )
2kbd@– cread scancode of pressed or released key
3num <dword>– nput immidiate number into datastack
4jmp <dword>--jump to specified code
5call <dword> jump to specified code, save return address to return stack
61+n – n+1 
71-n – n-1 
8dupn – n nduplicate top of data stack
9dropn --drop last element in data stack
10if <dword>n --jump to addr if top element was 0
11ret jump to code, specified in return stack.
12c@addr – nread byte from memory at specified address
13c!n addr --store byte to specified memory
14pushDSTK -> RSTKmove top of datastack to returnstack
15popRSTK -> DSTKmove top of returnstack to datastack
16<unused>  
17rotn1 n2 n3 – n2 n3 n1rotate stack elements
18disk@FromDiskSect ToMem --read 1KB from disk into RAM
19disk!FromMem ToDiskSect --write 1KB to disk
20@addr – nread 32 bit number from memory
21!n addr --store 32 bit number to memory
22overn1 n2 – n1 n2 n1 
23swapn1 n2 – n2 n1 
24+n1 n2 – n1+n2 
25-n1 n2 – n1-n2 
26*n1 n2 – n1*n2 
27/n1 n2 – n1/n2 
28>n1 n2 – resultis true when n1 > n2
29<n1 n2 – resultis true when n1 < n2
30notn1 – not_n1logical not
31i– ncopies top of return stack into datastack
32cprt@addr – nread one byte from hardware port
33cprt!n addr --store one byte to hardware port
34i2– nlike "i" but takes second top stack element
35i3– nlike "i" but takes third top stack element.
36shln amount – nleft bit shift
37shrn amount – nright bit shift
38orn1 n2 – nlogical or
39xorn1 n2 – nexclusive logical or
40vidmapaddr --copy memory from "addr" to video memory.
41mouse@– x y buttonread mouse coordinates & buttons
42vidputaddr1 addr2 x y --put image1 into image2, at location x, y
43cmoveaddr1 addr2 amountmove memory from addr1 to addr2
44cfillc addr amount --fill memory starting at "addr" with "c" bytes.
45tvidputaddr1 addr2 x y --put image with transparency support
46depth– depthreturns current depth of data stack.
47charputcolorfg colorbg addrsrc addrdest x ydraw text character
+
+ +
+

1.1. kbd@ - read scancode of pressed or released key

+
+

+Returns 0 if no data available. +

+
+
+
+

1.2. vidput - put image1 into image2, at location x, y

+
+

+Does clipping, so part of a big image can be mapped into smaller one. +

+
+
+
+

1.3. cmove - copy memory array

+
+

+Move memory from addr1 to addr2. If addr1 is greater than addr2 then +count address foward while moving, elseway starts from end and counts +backwards, so no data loss occurs when memory regions partially +overlap. +

+
+
+
+

1.4. tvidput - put image with transparency support

+
+

+Stack footprint +

+
+addr1 addr2 x y --
+
+ + +

+Put image1 into image2, at location x, y with transparency support +

+ +

+Color 255 in source image is treated as transparent. +

+
+
+
+

1.5. charput - draw text character

+
+

+Draw character to image buffer located at "addrdest" to specified x & +y location. Decodes 8 bytes from source to bits, used to draw +character. +

+
+
+
+
+
+

Author: Svjatoslav Agejenko

+

Created: 2023-09-18 Mon 01:46

+

Validate

+
+ +