From cddcbf202b2edc877afcf87a25a3a715f504a860 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Sat, 14 Feb 2026 10:57:28 +0200 Subject: [PATCH] Added new disk file structure details. Updated `.gitignore`. --- .gitignore | 1 + AGENTS.md | 0 doc/index.org | 61 ++-- doc/virtual machine.html | 677 --------------------------------------- 4 files changed, 37 insertions(+), 702 deletions(-) create mode 100644 AGENTS.md delete mode 100644 doc/virtual machine.html diff --git a/.gitignore b/.gitignore index 1099ea5..a776fc9 100755 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /.idea/ bin/ +.aider* diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..e69de29 diff --git a/doc/index.org b/doc/index.org index 18c4996..522d669 100644 --- a/doc/index.org +++ b/doc/index.org @@ -130,31 +130,42 @@ system. See also: [[https://en.wikipedia.org/wiki/Bibi-binary][Bibi-binary]]. -* Disk file map, and it's data structures -Core and high-level boot code is stored outside of the filesystem to -allow easy access to it, at early booting time, when filesystem is not -yet initialized. -** Disk allocation -| offset | length | description | -|--------+--------+----------------------| -| 0 | ~4 Kb | Fifth core | -| 4 Kb | ~32 Kb | high-level boot code | -| 37 Kb | ~65 Kb | FAT | -| 101 Kb | ~16 MB | filesystem data area | -** FAT entry format: -| code | meaning | -|------+--------------------------| -| -2 | last sector | -| -1 | empty sector | -| 0 -- | .. pointer to next block | -** File entry format -| offset | length | description | -|--------+--------+------------------------| -| 0 | 4 | extension | -| 4 | 16 | name | -| 20 | 4 | entry point | -| 24 | 4 | size | -| 28 | 4 | last modification time | +* Disk file map and its data structures + +The `disk.raw` file is a raw disk image that contains both the boot +code (loaded before filesystem initialization) and the filesystem +structure. The disk layout is as follows: + +** Disk Allocation Table +| Offset | Length | Description | +|---------+---------+----------------------------------------------------------------------| +| 0 | ~4 KiB | Operating system kernel in virtual CPU byte-code | +| 4 KiB | ~32 KiB | Human readable, early system initialization code | +| 37 KiB | ~65 KiB | FAT (File Allocation Table) | +| 101 KiB | ~16 MiB | Filesystem data area (stores file contents and directory structures) | + +** FAT Entry Format + +The FAT tracks which disk sectors belong to each file. + +| Code | Meaning | +|----------+----------------------------------------------| +| -2 | Last sector of a file chain | +| -1 | Unused (empty) sector | +| 0 -- ... | Pointer to the next sector in the file chain | + +** File Directory Entry Format +| Offset | Length | Description | +|--------+--------+-----------------------------------------------------| +| 0 | 4 | File extension (4-byte FSCII string, e.g., "TXT ") | +| 4 | 16 | Filename (16-byte FSCII string, padded with spaces) | +| 20 | 4 | First block address | +| 24 | 4 | File size in bytes | +| 28 | 4 | Last modification timestamp (seconds since epoch) | + +The directory entries are stored within the filesystem data +area. Directory is just a file that list other files. + * Core architecture Fifth core is simply some amount of already compiled into machine code and linked together modules (entries in other words). In compilation diff --git a/doc/virtual machine.html b/doc/virtual machine.html deleted file mode 100644 index fbf1f6c..0000000 --- a/doc/virtual machine.html +++ /dev/null @@ -1,677 +0,0 @@ - - - - - - - -Fifth - virtual machine - - - - - - -
-

Fifth - virtual machine

- -

-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

-
- - -- 2.20.1