更新小程序: 钟表
This commit is contained in:
parent
f318ff7c13
commit
b197e88cb4
|
@ -2,8 +2,6 @@
|
||||||
#include "../include/common.h"
|
#include "../include/common.h"
|
||||||
#include "../include/io.h"
|
#include "../include/io.h"
|
||||||
|
|
||||||
static const size_t VGA_WIDTH = 80;
|
|
||||||
static const size_t VGA_HEIGHT = 25;
|
|
||||||
|
|
||||||
size_t terminal_row;
|
size_t terminal_row;
|
||||||
size_t terminal_column;
|
size_t terminal_column;
|
||||||
|
@ -16,7 +14,7 @@ static inline uint8_t vga_entry_color(enum vga_color fg, enum vga_color bg) {
|
||||||
return fg | bg << 4;
|
return fg | bg << 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint16_t vga_entry(unsigned char uc, uint8_t color) {
|
uint16_t vga_entry(unsigned char uc, uint8_t color) {
|
||||||
return (uint16_t) uc | (uint16_t) color << 8;
|
return (uint16_t) uc | (uint16_t) color << 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,8 +36,8 @@ void vga_install(void) {
|
||||||
terminal_color = vga_entry_color(VGA_COLOR_DARK_GREY, VGA_COLOR_BLACK);
|
terminal_color = vga_entry_color(VGA_COLOR_DARK_GREY, VGA_COLOR_BLACK);
|
||||||
terminal_buffer = (uint16_t *) 0xB8000;
|
terminal_buffer = (uint16_t *) 0xB8000;
|
||||||
//terminal_buffer = (uint16_t*) 0xA0000;
|
//terminal_buffer = (uint16_t*) 0xA0000;
|
||||||
for (size_t y = 0; y < VGA_HEIGHT; y++) {
|
for (size_t y = 0; y < VGA_HEIGHT ; y++) {
|
||||||
for (size_t x = 0; x < VGA_WIDTH; x++) {
|
for (size_t x = 0; x < VGA_WIDTH ; x++) {
|
||||||
const size_t index = y * VGA_WIDTH + x;
|
const size_t index = y * VGA_WIDTH + x;
|
||||||
terminal_buffer[index] = vga_entry(' ', terminal_color);
|
terminal_buffer[index] = vga_entry(' ', terminal_color);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
#ifndef CRASHPOWEROS_DATE_H
|
||||||
|
#define CRASHPOWEROS_DATE_H
|
||||||
|
|
||||||
|
int setup_date();
|
||||||
|
|
||||||
|
#endif //CRASHPOWEROS_DATE_H
|
|
@ -9,6 +9,7 @@ enum task_state {
|
||||||
TASK_SLEEPING = 1, // 睡眠中
|
TASK_SLEEPING = 1, // 睡眠中
|
||||||
TASK_RUNNABLE = 2, // 可运行(也许正在运行)
|
TASK_RUNNABLE = 2, // 可运行(也许正在运行)
|
||||||
TASK_ZOMBIE = 3, // 僵尸状态
|
TASK_ZOMBIE = 3, // 僵尸状态
|
||||||
|
TASK_DEATH = 4 // 终止状态
|
||||||
} task_state;
|
} task_state;
|
||||||
|
|
||||||
struct context {
|
struct context {
|
||||||
|
|
|
@ -5,6 +5,9 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#define VGA_WIDTH 80
|
||||||
|
#define VGA_HEIGHT 25
|
||||||
|
|
||||||
#define FLAG_ALTNT_FORM 0x01
|
#define FLAG_ALTNT_FORM 0x01
|
||||||
#define FLAG_ALTNT_FORM_CH '#'
|
#define FLAG_ALTNT_FORM_CH '#'
|
||||||
|
|
||||||
|
@ -58,6 +61,7 @@ void vga_putchar(char c);
|
||||||
void vga_write(const char* data, size_t size);
|
void vga_write(const char* data, size_t size);
|
||||||
void vga_writestring(const char* data);
|
void vga_writestring(const char* data);
|
||||||
void vga_write_dec(uint32_t dec);
|
void vga_write_dec(uint32_t dec);
|
||||||
|
uint16_t vga_entry(unsigned char uc, uint8_t color);
|
||||||
void vga_clear();
|
void vga_clear();
|
||||||
void move_cursor();
|
void move_cursor();
|
||||||
void printf(const char *formet, ...);
|
void printf(const char *formet, ...);
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "../include/cmos.h"
|
#include "../include/cmos.h"
|
||||||
#include "../include/keyboard.h"
|
#include "../include/keyboard.h"
|
||||||
#include "../include/shell.h"
|
#include "../include/shell.h"
|
||||||
|
#include "../include/date.h"
|
||||||
|
|
||||||
extern uint32_t end;
|
extern uint32_t end;
|
||||||
uint32_t placement_address = (uint32_t) & end;
|
uint32_t placement_address = (uint32_t) & end;
|
||||||
|
@ -33,7 +34,7 @@ void kernel_main() {
|
||||||
clock_sleep(25);
|
clock_sleep(25);
|
||||||
|
|
||||||
kernel_thread(setup_shell,NULL,"CPOS-Shell");
|
kernel_thread(setup_shell,NULL,"CPOS-Shell");
|
||||||
|
kernel_thread(setup_date,NULL,"CPOS-Date");
|
||||||
|
|
||||||
for (;;){
|
for (;;){
|
||||||
io_hlt();
|
io_hlt();
|
||||||
|
|
|
@ -25,6 +25,9 @@ void print_proc_t(int *i,struct task_struct *base,struct task_struct *cur){
|
||||||
case TASK_ZOMBIE:
|
case TASK_ZOMBIE:
|
||||||
printf("%s %d %s\n",cur->name,cur->pid,"Zombie");
|
printf("%s %d %s\n",cur->name,cur->pid,"Zombie");
|
||||||
break;
|
break;
|
||||||
|
case TASK_DEATH:
|
||||||
|
printf("%s %d %s\n",cur->name,cur->pid,"Death");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
(*i)++;
|
(*i)++;
|
||||||
} else{
|
} else{
|
||||||
|
@ -41,6 +44,9 @@ void print_proc_t(int *i,struct task_struct *base,struct task_struct *cur){
|
||||||
case TASK_ZOMBIE:
|
case TASK_ZOMBIE:
|
||||||
printf("%s %d %s\n",cur->name,cur->pid,"Zombie");
|
printf("%s %d %s\n",cur->name,cur->pid,"Zombie");
|
||||||
break;
|
break;
|
||||||
|
case TASK_DEATH:
|
||||||
|
printf("%s %d %s\n",cur->name,cur->pid,"Death");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
(*i)++;
|
(*i)++;
|
||||||
print_proc_t(i,base,cur->next);
|
print_proc_t(i,base,cur->next);
|
||||||
|
@ -107,9 +113,8 @@ int32_t kernel_thread(int (*fn)(void *), void *arg,char* name) {
|
||||||
|
|
||||||
void kthread_exit() {
|
void kthread_exit() {
|
||||||
register uint32_t val asm ("eax");
|
register uint32_t val asm ("eax");
|
||||||
|
printf("Task exited with value %d\n", val);
|
||||||
printf("Thread exited with value %d\n", val);
|
current->state = TASK_DEATH;
|
||||||
|
|
||||||
while (1);
|
while (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "../include/task.h"
|
#include "../include/task.h"
|
||||||
|
|
||||||
uint32_t tick = 0;
|
uint32_t tick = 0;
|
||||||
|
extern struct task_struct *current;
|
||||||
|
|
||||||
static void timer_handle(registers_t *regs) {
|
static void timer_handle(registers_t *regs) {
|
||||||
io_cli();
|
io_cli();
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
#include "../include/date.h"
|
||||||
|
#include "../include/cmos.h"
|
||||||
|
#include "../include/vga.h"
|
||||||
|
#include "../include/timer.h"
|
||||||
|
|
||||||
|
extern uint16_t *terminal_buffer;
|
||||||
|
extern uint8_t terminal_color;
|
||||||
|
|
||||||
|
int setup_date(){
|
||||||
|
char* date_info;
|
||||||
|
int i;
|
||||||
|
while (1){
|
||||||
|
clock_sleep(5);
|
||||||
|
date_info = get_date_time(); //11
|
||||||
|
i = 0;
|
||||||
|
for(size_t x = VGA_WIDTH - 17; x < VGA_WIDTH ; x++){
|
||||||
|
const size_t index = (VGA_HEIGHT - 1) * VGA_WIDTH + x;
|
||||||
|
terminal_buffer[index] = vga_entry(date_info[i],terminal_color);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue