mirror of
https://github.com/emptyynes/LIVM.git
synced 2025-10-28 21:28:55 +03:00
Console Device is ready to use
+ started doing clock devices + console device is now located at devices[1], devices[0] is clock
This commit is contained in:
parent
219af6eb76
commit
d02a5d3dfd
6 changed files with 124 additions and 52 deletions
36
device/clock.c
Normal file
36
device/clock.c
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
#define CLOCK vm->devices[0]
|
||||
|
||||
void clock_write(struct VMinst* vm, void* data, uint64_t length) {
|
||||
|
||||
}
|
||||
|
||||
void clock_out(struct VMinst* vm) {
|
||||
|
||||
}
|
||||
|
||||
void clock_read(struct VMinst* vm, void* buffer, uint64_t length, uint64_t where) {
|
||||
|
||||
}
|
||||
|
||||
void clock_wait(struct VMinst* vm, uint64_t data) {
|
||||
|
||||
}
|
||||
|
||||
void clock_poweroff(struct VMinst* vm) {
|
||||
#ifdef LLLIVMDEBUG
|
||||
puts("clock_poweroff<");
|
||||
#endif
|
||||
free(CLOCK.buffer);
|
||||
#ifdef LLLIVMDEBUG
|
||||
puts("clock_poweroff>");
|
||||
#endif
|
||||
}
|
||||
|
||||
void setup_clock(struct VMinst* vm) {
|
||||
CLOCK.buffer = malloc(10240);
|
||||
CLOCK.write = &clock_write;
|
||||
CLOCK.out = &clock_out;
|
||||
CLOCK.read = &clock_read;
|
||||
CLOCK.wait = &clock_wait;
|
||||
CLOCK.poweroff = &clock_poweroff;
|
||||
}
|
||||
50
device/console.c
Normal file
50
device/console.c
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
#define CONSOLE vm->devices[1]
|
||||
|
||||
void console_write(struct VMinst* vm, void* data, uint64_t length) {
|
||||
uint16_t* write_bс = ((uint16_t*)CONSOLE.buffer);
|
||||
uint8_t* write_b = (uint8_t*)(CONSOLE.buffer + 2);
|
||||
for (uint64_t i = 0; i < length; ++i) {
|
||||
if (*write_bс == 5120) return;
|
||||
write_b[(*write_bс)++] = ((uint8_t*)data)[i];
|
||||
}
|
||||
}
|
||||
|
||||
void console_out(struct VMinst* vm) {
|
||||
puts((char*)(CONSOLE.buffer + 2));
|
||||
}
|
||||
|
||||
void console_read(struct VMinst* vm, void* buffer, uint64_t length, uint64_t where) {
|
||||
uint16_t* read_bс = ((uint16_t*)(CONSOLE.buffer + 5120));
|
||||
uint8_t* read_b = ((uint8_t*)(CONSOLE.buffer + 5120) + where) + 2;
|
||||
for (uint64_t i = 0; i < length; ++i) {
|
||||
((uint8_t*)buffer)[i] = read_b[i];
|
||||
}
|
||||
*read_bс = 0;
|
||||
}
|
||||
|
||||
void console_wait(struct VMinst* vm, uint64_t data) {
|
||||
uint16_t* read_bс = ((uint16_t*)(vm->devices[1].buffer + 5120));
|
||||
uint8_t* read_b = ((uint8_t*)vm->devices[1].buffer + 5120 + 2);
|
||||
printf("enter data: ");
|
||||
for (; *read_bс < data;)
|
||||
read_b[(*read_bс)++] = getchar();
|
||||
}
|
||||
|
||||
void console_poweroff(struct VMinst* vm) {
|
||||
#ifdef LLLIVMDEBUG
|
||||
puts("console_poweroff<");
|
||||
#endif
|
||||
free(CONSOLE.buffer);
|
||||
#ifdef LLLIVMDEBUG
|
||||
puts("console_poweroff>");
|
||||
#endif
|
||||
}
|
||||
|
||||
void setup_console(struct VMinst* vm) {
|
||||
CONSOLE.buffer = malloc(10240);
|
||||
CONSOLE.write = &console_write;
|
||||
CONSOLE.out = &console_out;
|
||||
CONSOLE.read = &console_read;
|
||||
CONSOLE.wait = &console_wait;
|
||||
CONSOLE.poweroff = &console_poweroff;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue