create_file and read_file
This commit is contained in:
parent
8bcbc876bb
commit
4107b2e393
27
docs/api.md
27
docs/api.md
|
@ -1,4 +1,5 @@
|
|||
# V86Starter
|
||||
- [`add_file(boolean no_async)`](#add_fileboolean-no_async)
|
||||
- [`run()`](#run)
|
||||
- [`stop()`](#stop)
|
||||
- [`restart()`](#restart)
|
||||
|
@ -12,6 +13,8 @@
|
|||
- [`mouse_set_status(boolean enabled)`](#mouse_set_statusboolean-enabled)
|
||||
- [`keyboard_set_status(boolean enabled)`](#keyboard_set_statusboolean-enabled)
|
||||
- [`serial0_send(string data)`](#serial0_sendstring-data)
|
||||
- [`create_file(string file, Uint8Array data, Function callback)`](#create_filestring-file-uint8array-data-function-callback)
|
||||
- [`read_file(string file, Function callback)`](#read_filestring-file-function-callback)
|
||||
|
||||
***
|
||||
## `V86Starter`
|
||||
|
@ -61,6 +64,13 @@ There are two ways to load images (`bios`, `vga_bios`, `cdrom`, `hda`, ...):
|
|||
|
||||
1. **`Object`** options – Options to initialize the emulator with.
|
||||
|
||||
***
|
||||
#### `add_file(boolean no_async)`
|
||||
|
||||
**Parameters:**
|
||||
|
||||
1. **`boolean`** no_async
|
||||
|
||||
***
|
||||
#### `run()`
|
||||
Start emulation. Do nothing if emulator is running already. Can be
|
||||
|
@ -204,6 +214,23 @@ Send a string to the first emulated serial terminal.
|
|||
|
||||
1. **`string`** data
|
||||
|
||||
***
|
||||
#### `create_file(string file, Uint8Array data, Function callback)`
|
||||
|
||||
**Parameters:**
|
||||
|
||||
1. **`string`** file
|
||||
2. **`Uint8Array`** data
|
||||
3. **`Function`** callback
|
||||
|
||||
***
|
||||
#### `read_file(string file, Function callback)`
|
||||
|
||||
**Parameters:**
|
||||
|
||||
1. **`string`** file
|
||||
2. **`Function`** callback
|
||||
|
||||
<!-- src/browser/starter.js-->
|
||||
|
||||
<!-- vim: set tabstop=2 shiftwidth=2 softtabstop=2: -->
|
||||
|
|
|
@ -630,6 +630,82 @@ V86Starter.prototype.serial0_send = function(data)
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} file
|
||||
* @param {Uint8Array} data
|
||||
* @param {Function=} callback
|
||||
*/
|
||||
V86Starter.prototype.create_file = function(file, data, callback)
|
||||
{
|
||||
var fs = this.fs9p;
|
||||
|
||||
var parts = file.split("/");
|
||||
var filename = parts[parts.length - 1];
|
||||
|
||||
var path_infos = fs.SearchPath(file);
|
||||
var parent_id = path_infos.parentid;
|
||||
var not_found = filename === "" || parent_id === -1
|
||||
|
||||
if(!not_found)
|
||||
{
|
||||
fs.CreateBinaryFile(filename, parent_id, data);
|
||||
}
|
||||
|
||||
if(callback)
|
||||
{
|
||||
setTimeout(function()
|
||||
{
|
||||
if(not_found)
|
||||
{
|
||||
callback(new FileNotFoundError());
|
||||
}
|
||||
else
|
||||
{
|
||||
callback(null);
|
||||
}
|
||||
}, 0);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} file
|
||||
* @param {Function=} callback
|
||||
*/
|
||||
V86Starter.prototype.read_file = function(file, callback)
|
||||
{
|
||||
var fs = this.fs9p;
|
||||
var path_infos = fs.SearchPath(file);
|
||||
var id = path_infos.id;
|
||||
|
||||
if(id === -1)
|
||||
{
|
||||
callback(new FileNotFoundError(), null);
|
||||
}
|
||||
else
|
||||
{
|
||||
fs.OpenInode(id, undefined);
|
||||
fs.AddEvent(
|
||||
id,
|
||||
function()
|
||||
{
|
||||
callback(null, fs.inodedata[id]);
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
* @constructor
|
||||
*
|
||||
* @param {string=} message
|
||||
*/
|
||||
function FileNotFoundError(message)
|
||||
{
|
||||
this.message = message || "File not found";
|
||||
}
|
||||
FileNotFoundError.prototype = Error.prototype;
|
||||
|
||||
// Closure Compiler's way of exporting
|
||||
if(typeof window !== "undefined")
|
||||
{
|
||||
|
@ -657,3 +733,5 @@ V86Starter.prototype["lock_mouse"] = V86Starter.prototype.lock_mouse;
|
|||
V86Starter.prototype["mouse_set_status"] = V86Starter.prototype.mouse_set_status;
|
||||
V86Starter.prototype["keyboard_set_status"] = V86Starter.prototype.keyboard_set_status;
|
||||
V86Starter.prototype["serial0_send"] = V86Starter.prototype.serial0_send;
|
||||
V86Starter.prototype["create_file"] = V86Starter.prototype.create_file;
|
||||
V86Starter.prototype["read_file"] = V86Starter.prototype.read_file;
|
||||
|
|
Loading…
Reference in a new issue