fixed URLs
[fifth.git] / doc / emulator.html
1 <html><head><title>FIFTH</title></head>\r
2 <body>\r
3 \r
4 <pre>\r
5 \r
6     <h2>Emulator & virtual CPU</h2>\r
7 \r
8 \r
9 \r
10 Using CPU emulator slows it down but I shouldn't now\r
11 think too mutch about, and waste my time on batteling with problems whitch\r
12 results on complex design of PC hardware. Also it allows me to use existing DOS and\r
13 resident drivers services in real mode. So I don't need to deal with\r
14 hardware too mutch. It also allows me to use all free XMS for flat\r
15 code & data storage.\r
16 \r
17 Current emulator emulates 1 CPU. It has 2 stacks,\r
18 ~50 instructions, and 4GB flat address space (theoretically).\r
19 I'm not sure that DOS 6.22 that I currently prefer can handle more than\r
20 64 MB of RAM. While I tried to keep instructionset simple,\r
21 I was forced to put in lot of complex instructions to make it's performance\r
22 acceptable on emulator. On actual silicon ~20 instructions is enaugh\r
23 (I think).\r
24 \r
25 Maybe one day similar system will run directly on custom silicon chip :)\r
26 \r
27 \r
28 CPU has following registers:\r
29 \r
30 IP      - instruction pointer\r
31 DSP     - data stack pointer\r
32 RSP     - return stack pointer\r
33 \r
34 Virtual CPU, commands (most of them are avaiable as ordinary commands in\r
35 programming lanquage):\r
36 \r
37 code    mnemonic        description\r
38 \r
39 0       nop                     does notheing\r
40 1       halt            halt CPU ( return to DOS on emulator )\r
41 \r
42 2       kbd@            ( -- c ) read scancode of pressed or released key.\r
43                                 Returns 0, if no data avaiable. \r
44 3       num <dword>     ( -- n ) put immidiate number into datastack\r
45 \r
46 4       jmp <dword>     jump to specified code\r
47 5       call <dword>jump to specified code, save return address to\r
48                                 return stack.\r
49 \r
50 6       1+                      ( n -- n+1 )\r
51 7       1-                      ( n -- n-1 )\r
52 \r
53 8       dup                     ( n -- n n ) duplicate top of data stack\r
54 9       drop            ( n -- ) drop last element in data stack\r
55 \r
56 10      if <dword>      ( n -- ) jump to addr if top element was 0\r
57 11      ret                     jump to code, specified in return stack.\r
58 \r
59 12      c@                      ( addr -- n ) read byte from memory at specified address\r
60 13      c!                      ( n addr -- ) store byte to specified memory\r
61 \r
62 14      push            ( DSTK -> RSTK ) move top of datastack to returnstack\r
63 15      pop                     ( RSTK -> DSTK ) move top of returnstack to datastack\r
64 \r
65 16      <unused>\r
66 17      rot                     ( n1 n2 n3 -- n2 n3 n1) rotate stack elements\r
67 \r
68 18      disk@           ( FromDiskSect ToMem -- ) read 1KB from disk into RAM\r
69 19      disk!           ( FromMem ToDiskSect -- ) write 1KB to disk\r
70 \r
71 20      @                       ( addr -- n ) read 32 bit number from memory\r
72 21      !                       ( n addr -- ) store 32 bit number to memory\r
73 \r
74 22      over            ( n1 n2 -- n1 n2 n1 ) self explaining ...\r
75 23      swap            ( n1 n2 -- n2 n1 ) -,,-\r
76 \r
77 24      +                       ( n1 n2 -- n1+n2 ) -,,-\r
78 25      -                       ( n1 n2 -- n1-n2 ) -,,-\r
79 \r
80 26      *                       ( n1 n2 -- n1*n2 ) -,,-\r
81 27      /                       ( n1 n2 -- n1/n2 ) -,,-\r
82 \r
83 28      >                       ( n1 n2 -- result ) is true when n1 > n2\r
84 29      <                       ( n1 n2 -- result ) is true when n1 < n2\r
85 \r
86 30      not                     ( n1 -- not_n1 ) logical not\r
87 31      i                       ( -- n ) copies top of return stack into datastack\r
88 \r
89 32      cprt@           ( addr -- n ) read one byte from hardware port\r
90 33      cprt!           ( n addr -- ) store one byte to hardware port\r
91 \r
92 34      i2                      ( -- n ) like "i" but takes socond top stack element.\r
93 35      i3                      ( -- n ) like "i" but takes third top stack element.\r
94 \r
95 36      shl                     ( n amount -- n ) left bit shift\r
96 37      shr                     ( n amount -- n ) right bit shift\r
97 \r
98 38      or                      ( n1 n2 -- n ) logical or\r
99 39      xor                     ( n1 n2 -- n ) exclusive logical or\r
100         \r
101 40      vidmap          ( addr -- ) copy memory from "addr" to video memory.\r
102 \r
103 41      mouse@          ( -- x y button ) read mouse coordinates & buttons\r
104 \r
105 42      vidput          ( addr1 addr2 x y -- ) put image1 into image2, at\r
106                                 location x, y. Does clipping, so part of a big image\r
107                                 can be mapped into smaller one.\r
108 \r
109 43      cmove           ( addr1 addr2 amount ) move memory from addr1 to addr2\r
110                                 if addr1 is greater than addr2 then count address\r
111                                 foward while moving, elseway starts from end and\r
112                                 counts backwards, so no data loss will occure on\r
113                                 overlapping.\r
114 \r
115 44      cfill           ( c addr amount -- ) fill memory starting at "addr"\r
116                                 with "c" bytes.\r
117 \r
118 45      tvidput         ( addr1 addr2 x y -- ) same as "vidput" but treats\r
119                                 color 255 in source image as transparent.\r
120 \r
121 46      depth           ( -- depth ) returns current depth of data stack.\r
122 \r
123 47      charput         ( colorfg colorbg addrsrc addrdest x y )\r
124                                 draw character to image buffer located at "addrdest"\r
125                                 to specified x & y location. Decodes 8 bytes from\r
126                                 source to bits, used to draw character.\r
127 \r
128 </pre>\r
129 </body>\r
130 </html>