foo master
authorJohn Tsiombikas <nuclear@member.fsf.org>
Mon, 21 Nov 2022 00:55:32 +0000 (02:55 +0200)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Mon, 21 Nov 2022 00:55:32 +0000 (02:55 +0200)
kern/src/con.c [new file with mode: 0644]
kern/src/intr.asm [new file with mode: 0644]
kern/src/intrent.asm [deleted file]
kern/src/main.c
kern/src/vid.c

diff --git a/kern/src/con.c b/kern/src/con.c
new file mode 100644 (file)
index 0000000..8b5a244
--- /dev/null
@@ -0,0 +1,126 @@
+#if 0
+#include "con.h"
+
+
+
+#define NCOLS                  80
+#define NROWS                  25
+
+/* must be pow2 */
+#define TEXTBUF_SIZE   256
+
+static char textbuf[TEXTBUF_SIZE][NCOLS];
+static int tbuf_first, tbuf_last;
+
+static int curx, cury, scroll;
+
+#define CURSTACK_SIZE  16
+static unsigned int savecur[CURSTACK_SIZE];
+static int savecur_top;
+
+
+static void newline(void);
+
+
+void con_init(void)
+{
+       con_reset();
+}
+
+void con_reset(void)
+{
+       vga_reset();
+
+       curx = cury = scroll = 0;
+       tbuf_first = tbuf_last = 0;
+       memset(textbuf[0], 0, sizeof textbuf[0]);
+
+       savecur_top = 0;
+}
+
+void con_setcur(int x, int y)
+{
+       curx = x < 0 ? 0 : (x >= NCOLS ? NCOLS - 1 : x);
+       cury = y < 0 ? 0 : (y >= NROWS ? NROWS - 1 : y);
+}
+
+void con_getcur(int *x, int *y)
+{
+       *x = curx;
+       *y = cury;
+}
+
+void con_pushcur(void)
+{
+       if(savecur_top >= CURSTACK_SIZE) return;
+
+       savecur[savecur_top++] = curx | (cury << 16);
+}
+
+void con_popcur(void)
+{
+       if(savecur_top <= 0) return;
+
+       savecur_top--;
+       curx = savecur[savecur_top] & 0xffff;
+       cury = savecur[savecur_top] >> 16;
+}
+
+void con_putchar(int c)
+{
+       switch(c) {
+       case '\t':
+               curx = (curx + 8) & 0xfffffff8;
+               if(curx >= NCOLS) {
+                       newline();
+               }
+               break;
+
+       case '\r':
+               curx = 0;
+               break;
+
+       case '\n':
+               newline();
+               break;
+
+       case '\b':
+               if(curx > 0) {
+                       textbuf[tbuf_last][--curx] = 0;
+                       vga_drawchar(curx, cury, 0);
+               }
+               break;
+
+       default:
+               textbuf[tbuf_last][curx] = c;
+               vga_drawchar(curx, cury, c);
+               if(++curx >= NCOLS) {
+                       newline();
+               }
+               break;
+       }
+
+       if(cury >= NROWS) {
+               cury--;
+               vga_scroll(++scroll);
+               vga_clearline(NROWS - 1);
+       }
+
+       vid_set_cursor(curx, cury);
+}
+
+static void newline(void)
+{
+       int num;
+
+       curx = 0;
+       cury++;
+
+       num = (tbuf_last + 1) & (TEXTBUF_SIZE - 1);
+
+       if(tbuf_last == tbuf_first) {
+               tbuf_first = num;
+       }
+       tbuf_last = num;
+}
+#endif
diff --git a/kern/src/intr.asm b/kern/src/intr.asm
new file mode 100644 (file)
index 0000000..b30bfa3
--- /dev/null
@@ -0,0 +1,114 @@
+; interrupt entry routines
+       cpu 8086
+       bits 16
+       section .text
+
+extern dispatch_intr
+
+%macro INTR_ENTRY 2
+global intr_entry_%2
+intr_entry_%2:
+       push bp
+       push ax
+       push bp
+       mov bp, sp
+       mov ax, %1
+       mov [bp + 4], ax
+       pop bp
+       pop ax
+       jmp intr_entry_common
+%endmacro
+
+intr_entry_common:
+       push ax
+       mov ax, sp
+       add ax, 2
+       push cx
+       push dx
+       push bx
+       push ax ; saved sp
+       push bp
+       push si
+       push di
+       call dispatch_intr
+       pop di
+       pop si
+       pop bp
+       pop bx  ; throw away saved sp
+       pop bx
+       pop dx
+       pop cx
+       pop ax
+       add sp, 2       ; remove interrupt number from the stack
+       iret
+
+; CPU exceptions
+INTR_ENTRY 0, div
+INTR_ENTRY 1, trap
+INTR_ENTRY 2, nmi
+INTR_ENTRY 3, break
+INTR_ENTRY 4, ovf
+INTR_ENTRY 5, bound
+INTR_ENTRY 6, ill
+; IRQs
+INTR_ENTRY 8, irq0
+INTR_ENTRY 9, irq1
+INTR_ENTRY 10, irq2
+INTR_ENTRY 11, irq3
+INTR_ENTRY 12, irq4
+INTR_ENTRY 13, irq5
+INTR_ENTRY 14, irq6
+INTR_ENTRY 15, irq7
+
+       ; int86 implementation
+       global int86
+int86:
+       push bp
+       mov bp, sp
+       push bx
+       push si
+       push di
+       pushf
+
+       mov ax, [bp + 4]
+       mov [cs:.intop + 1], al ; modify int instruction
+
+       mov [saved_sp], sp
+       mov sp, [bp + 6]
+       pop ax
+       pop bx
+       pop cx
+       pop dx
+       pop si
+       pop di
+       popf
+       mov sp, [saved_sp]
+
+.intop:        int 0xff
+
+       mov [saved_ax], ax
+       pushf
+       pop ax
+       mov sp, [bp + 8]
+       add sp, 14      ; sp at end of outregs
+       push ax         ; flags
+       mov ax, [saved_ax]
+       push di
+       push si
+       push dx
+       push cx
+       push bx
+       push ax
+
+       mov sp, [saved_sp]
+       popf
+       pop di
+       pop si
+       pop bx
+       pop bp
+       ret
+
+saved_sp dw 0
+saved_ax dw 0
+
+; vi:ts=8 sts=8 sw=8 ft=nasm:
diff --git a/kern/src/intrent.asm b/kern/src/intrent.asm
deleted file mode 100644 (file)
index 0fd515d..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-; interrupt entry routines
-       cpu 8086
-       bits 16
-       section .text
-
-extern dispatch_intr
-
-%macro INTR_ENTRY 2
-global intr_entry_%2
-intr_entry_%2:
-       push bp
-       push ax
-       push bp
-       mov bp, sp
-       mov ax, %1
-       mov [bp + 4], ax
-       pop bp
-       pop ax
-       jmp intr_entry_common
-%endmacro
-
-intr_entry_common:
-       push ax
-       mov ax, sp
-       add ax, 2
-       push cx
-       push dx
-       push bx
-       push ax ; saved sp
-       push bp
-       push si
-       push di
-       call dispatch_intr
-       pop di
-       pop si
-       pop bp
-       pop bx  ; throw away saved sp
-       pop bx
-       pop dx
-       pop cx
-       pop ax
-       add sp, 2       ; remove interrupt number from the stack
-       iret
-
-; CPU exceptions
-INTR_ENTRY 0, div
-INTR_ENTRY 1, trap
-INTR_ENTRY 2, nmi
-INTR_ENTRY 3, break
-INTR_ENTRY 4, ovf
-INTR_ENTRY 5, bound
-INTR_ENTRY 6, ill
-; IRQs
-INTR_ENTRY 8, irq0
-INTR_ENTRY 9, irq1
-INTR_ENTRY 10, irq2
-INTR_ENTRY 11, irq3
-INTR_ENTRY 12, irq4
-INTR_ENTRY 13, irq5
-INTR_ENTRY 14, irq6
-INTR_ENTRY 15, irq7
-
-; vi:ts=8 sts=8 sw=8 ft=nasm:
index ea4ffac..f89cd5d 100644 (file)
@@ -3,22 +3,19 @@
 
 void kmain(void)
 {
-       /*
        int i, j;
        unsigned short __far *vmem = (void __far*)0xb8000000ul;
        unsigned short c;
-       */
 
        vid_init();
        vid_text(0, 0, "hello!", VID_ATTR(LTRED, BLACK));
        init_intr();
 
-       /*
-       for(i=0; i<25; i++) {
+       vmem += 80;
+       for(i=1; i<25; i++) {
                c = ((i & 0xf) << 8) | '@';
                for(j=0; j<80; j++) {
                        *vmem++ = c;
                }
        }
-       */
 }
index f4eb723..25c7cf1 100644 (file)
@@ -45,6 +45,7 @@ static void detect_video(void)
 {
        mono = 0;
        vid_type = VID_UNK;
+       return;         /* XXX */
 
        if(detect_vgainfo() == 0) {
                return;
@@ -211,7 +212,7 @@ void vid_bgcolor(int color)
 void vid_glyph(int x, int y, int c, int attr)
 {
        uint16_t __far *ptr;
-       uint16_t val = (c & 0xff) | attr;
+       uint16_t val = c | (attr << 8);
 
        y += cur_scroll;
 
@@ -234,7 +235,7 @@ void vid_text(int x, int y, const char *s, int attr)
 
        ptr = vmem + y * 80 + x;
        while(*s) {
-               *ptr++ = (*s++ & 0xff) | attr;
+               *ptr++ = *s++ | (attr << 8);
                len++;
        }
 
@@ -243,7 +244,7 @@ void vid_text(int x, int y, const char *s, int attr)
                ptr -= 80 * 32 + len;
                s -= len;
                while(*s) {
-                       *ptr++ = (*s++ & 0xff) | attr;
+                       *ptr++ = *s++ | (attr << 8);
                }
        }
 }