Sfoglia il codice sorgente

Add display info command

Johannes Zellner 8 mesi fa
parent
commit
c2d5eee88c
3 ha cambiato i file con 100 aggiunte e 2 eliminazioni
  1. 5 2
      Makefile
  2. 76 0
      display.c
  3. 19 0
      terminal.c

+ 5 - 2
Makefile

@@ -62,13 +62,16 @@ vga.o: vga.c vga.h
 clock.o: clock.c io.h rtc.h timer.h vga.h
 	$(CC) $(CFLAGS) -o $@ $<
 
+display.o: display.c io.h vga.h fbtext.h
+	$(CC) $(CFLAGS) -o $@ $<
+
 boot.elf: boot.o
 	$(LD) $(BOOT_LDFLAGS) -o $@ $<
 
 timer.o: timer.S
 	$(AS) $(ASFLAGS) -o $@ $<
 
-kernel.elf: kernel.o timer.o io.o rtc.o terminal.o hello.o reboot.o disk.o fat.o ls.o cat.o vga.o font_8x16.o fbtext.o clock.o
+kernel.elf: kernel.o timer.o io.o rtc.o terminal.o hello.o reboot.o disk.o fat.o ls.o cat.o vga.o font_8x16.o fbtext.o clock.o display.o
 	$(LD) $(KERNEL_LDFLAGS) -o $@ $^
 
 boot.bin: boot.elf
@@ -107,4 +110,4 @@ run: image.bin root.img
 	qemu-system-x86_64 -M pc -drive file=image.bin,format=raw,if=floppy -drive file=root.img,format=raw,if=floppy
 
 clean:
-	rm -f boot.o kernel.o timer.o io.o rtc.o terminal.o hello.o reboot.o fat.o ls.o cat.o disk.o vga.o font_8x16.o fbtext.o clock.o boot.elf kernel.elf boot.bin kernel.bin boot.bin.tmp boot.bin.patched image.bin final.bin root.img
+	rm -f boot.o kernel.o timer.o io.o rtc.o terminal.o hello.o reboot.o fat.o ls.o cat.o disk.o vga.o font_8x16.o fbtext.o clock.o display.o boot.elf kernel.elf boot.bin kernel.bin boot.bin.tmp boot.bin.patched image.bin final.bin root.img

+ 76 - 0
display.c

@@ -0,0 +1,76 @@
+/* display command: print resolution, color depth, and other graphics info. */
+
+#include "io.h"
+#include "vga.h"
+#include "fbtext.h"
+
+static void put_uint(unsigned int n)
+{
+	char buf[12];
+	char *p = buf + sizeof(buf) - 1;
+	*p = '\0';
+	if (n == 0) {
+		io_putchar('0');
+		return;
+	}
+	while (n) {
+		*--p = (char)('0' + (n % 10));
+		n /= 10;
+	}
+	while (*p)
+		io_putchar(*p++);
+}
+
+static void put_hex(unsigned int n)
+{
+	static const char hex[] = "0123456789ABCDEF";
+	io_putstr("0x");
+	if (n == 0) {
+		io_putchar('0');
+		return;
+	}
+	{
+		char buf[9];
+		char *q = buf + 8;
+		*q = '\0';
+		while (n) {
+			*--q = hex[n & 0xF];
+			n >>= 4;
+		}
+		while (*q)
+			io_putchar(*q++);
+	}
+}
+
+void program_display_main(void)
+{
+	if (vga_has_vesa()) {
+		io_putstr("resolution ");
+		put_uint(vga_fb_width());
+		io_putstr(" x ");
+		put_uint(vga_fb_height());
+		io_putchar('\n');
+		io_putstr("color depth ");
+		put_uint(vga_fb_bpp());
+		io_putstr(" bpp\n");
+		io_putstr("pitch ");
+		put_uint(vga_fb_pitch());
+		io_putstr(" bytes/line\n");
+		io_putstr("LFB ");
+		put_hex((unsigned int)(unsigned long)vga_fb_ptr());
+		io_putchar('\n');
+		if (fbtext_active()) {
+			io_putstr("text ");
+			put_uint(fbtext_get_cols());
+			io_putstr(" x ");
+			put_uint(fbtext_get_rows());
+			io_putstr(" chars\n");
+		}
+	} else {
+		io_putstr("VESA not available; VGA text ");
+		put_uint(io_get_cols());
+		io_putstr(" x ");
+		put_uint(io_get_rows());
+		io_putstr(" chars\n");
+	}
+}

+ 19 - 0
terminal.c

@@ -10,6 +10,7 @@ extern void program_reboot_main(void);
 extern void program_ls_main(void);
 extern void program_cat_main(const char *filename);
 extern void program_clock_main(void);
+extern void program_display_main(void);
 extern void disk_set_drive(unsigned int drive);
 extern unsigned int disk_get_drive(void);
 
@@ -131,6 +132,22 @@ static int is_cmd_clock(const char *line, unsigned int line_len)
 	return (i == line_len);
 }
 
+static int is_cmd_display(const char *line, unsigned int line_len)
+{
+	unsigned int i = 0;
+	while (i < line_len && line[i] == ' ')
+		i++;
+	if (i + 7 > line_len)
+		return 0;
+	if (line[i] != 'd' || line[i+1] != 'i' || line[i+2] != 's' || line[i+3] != 'p' ||
+	    line[i+4] != 'l' || line[i+5] != 'a' || line[i+6] != 'y')
+		return 0;
+	i += 7;
+	while (i < line_len && line[i] == ' ')
+		i++;
+	return (i == line_len);
+}
+
 #define CAT_FNAME_MAX 64
 static int is_cmd_cat(const char *line, unsigned int line_len, char *filename_buf, unsigned int buf_size)
 {
@@ -254,6 +271,8 @@ void terminal_run(void)
 						program_cat_main(cat_fname);
 						io_drain_keyboard();
 						draw_header_row();
+					} else if (is_cmd_display(line, line_len)) {
+						program_display_main();
 					} else if (is_cmd_drive(line, line_len, &drive_sel)) {
 						disk_set_drive(drive_sel);
 						io_putstr("drive ");