更新小程序: 钟表

This commit is contained in:
xiaoyi1212 2024-04-10 01:18:08 +08:00
parent f318ff7c13
commit b197e88cb4
8 changed files with 48 additions and 9 deletions

View File

@ -2,8 +2,6 @@
#include "../include/common.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_column;
@ -16,7 +14,7 @@ static inline uint8_t vga_entry_color(enum vga_color fg, enum vga_color bg) {
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;
}

6
include/date.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef CRASHPOWEROS_DATE_H
#define CRASHPOWEROS_DATE_H
int setup_date();
#endif //CRASHPOWEROS_DATE_H

View File

@ -9,6 +9,7 @@ enum task_state {
TASK_SLEEPING = 1, // 睡眠中
TASK_RUNNABLE = 2, // 可运行(也许正在运行)
TASK_ZOMBIE = 3, // 僵尸状态
TASK_DEATH = 4 // 终止状态
} task_state;
struct context {

View File

@ -5,6 +5,9 @@
#include <stdint.h>
#include <stdarg.h>
#define VGA_WIDTH 80
#define VGA_HEIGHT 25
#define FLAG_ALTNT_FORM 0x01
#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_writestring(const char* data);
void vga_write_dec(uint32_t dec);
uint16_t vga_entry(unsigned char uc, uint8_t color);
void vga_clear();
void move_cursor();
void printf(const char *formet, ...);

View File

@ -8,6 +8,7 @@
#include "../include/cmos.h"
#include "../include/keyboard.h"
#include "../include/shell.h"
#include "../include/date.h"
extern uint32_t end;
uint32_t placement_address = (uint32_t) & end;
@ -33,7 +34,7 @@ void kernel_main() {
clock_sleep(25);
kernel_thread(setup_shell,NULL,"CPOS-Shell");
kernel_thread(setup_date,NULL,"CPOS-Date");
for (;;){
io_hlt();

View File

@ -25,6 +25,9 @@ void print_proc_t(int *i,struct task_struct *base,struct task_struct *cur){
case TASK_ZOMBIE:
printf("%s %d %s\n",cur->name,cur->pid,"Zombie");
break;
case TASK_DEATH:
printf("%s %d %s\n",cur->name,cur->pid,"Death");
break;
}
(*i)++;
} else{
@ -41,6 +44,9 @@ void print_proc_t(int *i,struct task_struct *base,struct task_struct *cur){
case TASK_ZOMBIE:
printf("%s %d %s\n",cur->name,cur->pid,"Zombie");
break;
case TASK_DEATH:
printf("%s %d %s\n",cur->name,cur->pid,"Death");
break;
}
(*i)++;
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() {
register uint32_t val asm ("eax");
printf("Thread exited with value %d\n", val);
printf("Task exited with value %d\n", val);
current->state = TASK_DEATH;
while (1);
}

View File

@ -5,6 +5,7 @@
#include "../include/task.h"
uint32_t tick = 0;
extern struct task_struct *current;
static void timer_handle(registers_t *regs) {
io_cli();

23
sysapp/date.c Normal file
View File

@ -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;
}