Difference between revisions of "Foenix Kernel Documentation"
(→DOS Calling Conventions) |
(→File Descriptor) |
||
Line 252: | Line 252: | ||
| SIZE || 18 || 4 || The size of the file in bytes. | | SIZE || 18 || 4 || The size of the file in bytes. | ||
|- | |- | ||
− | | CREATE_DATE || 22 || | + | | CREATE_DATE || 22 || 2 || The creation date in the same format as used by FAT. |
|- | |- | ||
− | | CREATE_TIME || | + | | CREATE_TIME || 24 || 2 || The creation time in the same format as used by FAT. |
|- | |- | ||
− | | MODIFIED_DATE || | + | | MODIFIED_DATE || 26 || 2 || The modification date in the same format as used by FAT. |
|- | |- | ||
− | | MODIFIED_TIME || | + | | MODIFIED_TIME || 28 || 2 || The modification time in the same format as used by FAT. |
|} | |} | ||
Revision as of 15:30, 11 April 2020
Contents
Foenix Kernel Documentation
Kernel Essentials
Source Code: https://github.com/Trinity-11/Kernel_FMX
On the FMX, the Foenix Kernel resides in bank $39 of the system RAM. It provides for the initialization of the hardware and a certain minimalist level of access to the hardware. Kernel routines are called through a kernel jump table that starts at $00:1000. All kernel routines must be called using the JSL instruction (long, or 24-bit subroutine call), since they all terminate with an RTL. This allows the kernel routines to be called from anywhere in system memory.
Kernel Calls
Name | Address | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
BOOT | $00:1000 | Cold boot routine | ||||||||||||
PUTC | $00:1018 | Print a character to the currently selected channel
| ||||||||||||
PUTS | $00:101C | Print a null-terminated ASCII string to the currently selected channel
| ||||||||||||
SETIN | $00:1038 | Set the current input channel used by the GET subroutines
| ||||||||||||
SETOUT | $00:103C | Set the current output channel used by the PUT subroutines
| ||||||||||||
GETCHW | $00:104C | Get a character from the input channel. Waits until data received. A=0 and Carry=1 if no data is waiting | ||||||||||||
GETCHE | $00:1050 | Get a character from the input channel and echo to the screen. Wait if data is not ready. | ||||||||||||
PRINTCR | $00:106C | Print Carriage Return | ||||||||||||
PRINTH | $00:1078 | Print hex value in memory.
| ||||||||||||
PRINTAH | $00:1080 | Prints hex value in A. Printed value is 2 wide if M flag is 1, 4 wide if M | ||||||||||||
LOCATE | $00:1084 | Move the cursor to a new position on the screen.
| ||||||||||||
CSRRIGHT | $00:1090 | Move the cursor one position to the right | ||||||||||||
CSRLEFT | $00:1094 | Move the cursor one position to the left | ||||||||||||
CSRUP | $00:1098 | Move the cursor up one row | ||||||||||||
CSRDOWN | $00:109C | Move the cursor down one row | ||||||||||||
CSRHOME | $00:10A0 | Move the cursor to the upper-left corner | ||||||||||||
SCROLLUP | $00:10A4 | Scroll the screen up one line. Creates an empty line at the bottom. | ||||||||||||
CLRSCREEN | $00:10B0 | Clear the screen | ||||||||||||
INITCHLUT | $00:10B4 | Init character look-up table | ||||||||||||
INITSUPERIO | $00:10B8 | Init Super-IO chip | ||||||||||||
INITKEYBOARD | $00:10BC | Init keyboard | ||||||||||||
INITRTC | $00:10C0 | Init Real-Time Clock | ||||||||||||
INITCURSOR | $00:10C4 | Init the Cursors registers | ||||||||||||
INITFONTSET | $00:10C8 | Init the Internal FONT Memory | ||||||||||||
INITGAMMATABLE | $00:10CC | Init the RGB GAMMA Look Up Table | ||||||||||||
INITALLLUT | $00:10D0 | Init the Graphic Engine (Bitmap/Tile/Sprites) LUT | ||||||||||||
INITVKYTXTMODE | $00:10D4 | Init the Text Mode @ Reset Time | ||||||||||||
INITVKYGRPMODE | $00:10D8 | Init the Basic Registers for the Graphic Mode | ||||||||||||
F_OPEN | $00:10F0 | Open a file for reading/writing. DOS_FD_PTR points to a file descriptor for the file. | ||||||||||||
F_CREATE | $00:10F4 | Create a new file and write its first cluster. DOS_FD_PTR points to a file descriptor for the file. | ||||||||||||
F_CLOSE | $00:10F8 | Close a file (make sure last cluster is written). DOS_FD_PTR points to a file descriptor for the file. | ||||||||||||
F_WRITE | $00:10FC | Write the current cluster to the file. DOS_FD_PTR points to a file descriptor for the file. | ||||||||||||
F_READ | $00:1100 | Read the next cluster from the file. DOS_FD_PTR points to a file descriptor for the file. | ||||||||||||
F_DELETE | $00:1104 | Delete a file / directory. DOS_PATH_BUFF = a buffer containing the full path to the file (NULL terminated). | ||||||||||||
F_DIROPEN | $00:1108 | Open a directory and seek the first directory entry. NOTE: currently only works with the root directory.
| ||||||||||||
F_DIRNEXT | $00:110C | seek to the next directory of an open directory
| ||||||||||||
F_DIRREAD | $00:1110 | Read the directory entry for the specified file
| ||||||||||||
F_DIRWRITE | $00:1114 | Write any changes in the current directory cluster back to the drive | ||||||||||||
F_LOAD | $00:1118 | load a binary file into memory, supports multiple file formats
| ||||||||||||
F_SAVE | $00:111C | Save memory to a binary file
|
DOS Calling Conventions
The DOS file routines use several variables to communicate with the calling program. All DOS routines will return with the carry bit set on success. If the routine was unable to complete successfully or needs to return a negative condition, the carry bit will be clear and DOS_STATUS and BIOS_STATUS variables may contain non-zero status codes describing the nature of the failure.
Variable | Address | Width (bytes) | Purpose |
---|---|---|---|
DOS_FD_PTR | $00:0340 | 4 | A pointer to a file descriptor structure (defined below). |
DOS_PATH_BUFF | $00:0400 | 256 | A buffer space for storing a path to a file or directory. |
DOS_DIR_PTR | $00:0338 | 4 | A pointer to a directory entry. The layout of the entry is identical to that used in the FAT file system. |
DOS_DST_PTR | $00:0354 | 4 | A pointer to a block of memory to be filled from the disk. |
DOS_SRC_PTR | $00:0350 | 4 | A pointer to a block of memory to write to disk. |
DOS_END_PTR | $00:0358 | 4 | A pointer to the last byte of a block of memory. |
DOS_STATUS | $00:032E | 1 | A status code for DOS operations. $00 = success |
BIOS_STATUS | $00:0320 | 1 | A status code for sector level operations. $00 = success |
File Descriptor
Most DOS subroutines take a pointer to a file descriptor as an argument. This file descriptor contains several elements needed to manage a file, including the buffer containing the current cluster of the file:
Name | Offset | Width (bytes) | Purpose | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
STATUS | 0 | 1 | A special status byte containing information about the file's state
| ||||||||||||||||||
DEV | 1 | 1 | A byte containing the device number for the file (should not be modified by the user program). | ||||||||||||||||||
PATH | 2 | 4 | A pointer to a null-terminated string containing the path to the file. Set by the user program. | ||||||||||||||||||
CLUSTER | 6 | 4 | The ID of the current cluster being read or written. Usually set by DOS. | ||||||||||||||||||
FIRST_CLUSTER | 10 | 4 | The ID of the first cluster of the file. Usually set by DOS. | ||||||||||||||||||
BUFFER | 14 | 4 | Pointer to the buffer containing a cluster's worth of data. Provided by the user program. Used by DOS to read or write the disk. | ||||||||||||||||||
SIZE | 18 | 4 | The size of the file in bytes. | ||||||||||||||||||
CREATE_DATE | 22 | 2 | The creation date in the same format as used by FAT. | ||||||||||||||||||
CREATE_TIME | 24 | 2 | The creation time in the same format as used by FAT. | ||||||||||||||||||
MODIFIED_DATE | 26 | 2 | The modification date in the same format as used by FAT. | ||||||||||||||||||
MODIFIED_TIME | 28 | 2 | The modification time in the same format as used by FAT. |
Console Special Characters
The console routines support several special control codes for both input and output. When the key on the keyboard is pressed, the associated code is returned by the GET routines. If the code is printed through the PUTC or PUTS, the associated operation will be performed on the screen. Note that this means that any graphics characters associated with those code points will not be displayed by PUTC or PUTS. If those characters must be displayed, they would have to be written to the text memory directly.
Code | Name | Keyboard | Description |
---|---|---|---|
$08 | BS | Backspace | Deletes the character to the left of the cursor, pulling characters in from the right. |
$09 | TAB | TAB | Moves the cursor right to the next tabulated column (every eight columns). |
$0A | LF | N/A | Puts the cursor at column 0 on the next line on the same column. |
$0D | CR | RETURN | Creates a newline on the screen. Puts the cursor at column 0 on the next line. |
$0F | INS | Insert | Inserts a blank space under the cursor (pushing characters to the right). |
$11 | UP | Up Arrow | Moves the cursor up one row. |
$1D | RIGHT | Right Arrow | Moves the cursor right one column. May wrap to the next line. |
$7F | DEL | Delete | Deletes the character under the cursor, pulling characters in from the right. |
$91 | DOWN | Down Arrow | Moves the cursor down one row. May scroll the screen. |
$9D | LEFT | Left Arrow | Moves the cursor left one column. |
Special Kernel Variables
The kernel keeps track of several variables. Most kernel variables should be left alone by applications, but there are some which an application might want to set or read.
Start Address | End Address | Name | R/W | Description |
---|---|---|---|---|
$00:000C | $00:000E | SCREENBEGIN | RO | Address of the first character of the text display |
$00:000C | $00:000E | SCREENBEGIN | RO | Address of the first character of the text display |
$00:000F | $00:0010 | COLS_VISIBLE | RW | The number of columns currently displayed |
$00:0013 | $00:0014 | LINES_VISIBLE | RW | The number of rows currently displayed |
$00:0017 | $00:0018 | CURSORPOS | RO | The address of the text character under the cursor |
$00:001A | $00:001B | CURSORX | RO | The address of the text character under the cursor |
$00:001C | $00:001D | CURSORY | RO | The address of the text character under the cursor |
$00:001E | CURCOLOR | RW | The foreground and background colors to be used when printing via PUTC and PUTS | |
$00:001F | $00:0020 | COLORPOS | RO | The address of the text color cell under the cursor |