added some graphics routines
authorJohn Tsiombikas <nuclear@member.fsf.org>
Sat, 5 Oct 2019 19:40:14 +0000 (22:40 +0300)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Sat, 5 Oct 2019 19:40:14 +0000 (22:40 +0300)
Makefile
src/data.asm [new file with mode: 0644]
src/gfx.asm [new file with mode: 0644]
src/main.asm

index 4d180c9..6d20b28 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -10,7 +10,7 @@ bootldr: src/boot/boot.asm $(bin)
        nasm -o $@ -f bin -DBINSIZE=`ls -l $(bin) | awk '{print $$5}'` $<
 
 $(bin): $(src)
        nasm -o $@ -f bin -DBINSIZE=`ls -l $(bin) | awk '{print $$5}'` $<
 
 $(bin): $(src)
-       nasm -o $@ -f bin src/main.asm
+       nasm -o $@ -f bin -i src/ src/main.asm
 
 boot.img: bootldr $(bin)
        cat $^ >$@
 
 boot.img: bootldr $(bin)
        cat $^ >$@
diff --git a/src/data.asm b/src/data.asm
new file mode 100644 (file)
index 0000000..8e60c0c
--- /dev/null
@@ -0,0 +1 @@
+; vi:filetype=nasm ts=8 sts=8 sw=8
diff --git a/src/gfx.asm b/src/gfx.asm
new file mode 100644 (file)
index 0000000..d352139
--- /dev/null
@@ -0,0 +1,88 @@
+; vi:filetype=nasm ts=8 sts=8 sw=8:
+;
+; list of functions
+; -----------------
+; init_gfx
+;    initializes the video hardware and graphics routines
+; clear
+;    clears the framebuffer (not vmem)
+;    clobbers: ax, cx, di
+; swap_buffers
+;    copies the framebuffer to video memory
+;    clobbers: ax, cx, di, si
+; wait_vsync
+;    clobbers: al, dx
+; set_palette_entry(idx[al], r[ah], g[bl], b[bh])
+;    colors are 0-255
+
+VIDMEM_SEG     equ 0a000h
+FRAMEBUF_SEG   equ 09000h
+
+REG_CRTC_STATUS        equ 3dah
+CRTC_VBLANK_BIT        equ 08h
+
+REG_DAC_ADDR   equ 3c8h
+REG_DAC_DATA   equ 3c9h
+
+init_gfx:
+       ; video mode 13h (320x200 8bpp)
+       mov ax, 13h
+       int 10h
+
+       call clear
+       ret
+
+clear:
+       push es
+       mov ax, FRAMEBUF_SEG
+       mov es, ax
+       xor di, di
+       xor ax, ax
+       mov cx, 16000
+       rep stosd
+       pop es
+       ret
+
+swap_buffers:
+       push ds
+       push es
+       mov ax, FRAMEBUF_SEG
+       mov ds, ax
+       xor si, si
+       mov ax, VIDMEM_SEG
+       mov es, ax
+       xor di, di
+       mov cx, 16000
+       rep movsd
+       pop es
+       pop ds
+       ret
+
+wait_vsync:
+       mov dx, REG_CRTC_STATUS
+.wait_vblank_end:
+       in al, dx
+       and al, CRTC_VBLANK_BIT
+       jnz .wait_vblank_end
+.wait_vblank_start:
+       in al, dx
+       and al, CRTC_VBLANK_BIT
+       jz .wait_vblank_start
+       ret
+
+set_palette_entry:
+       push dx
+       mov dx, REG_DAC_ADDR
+       out dx, al
+       inc dx  ; dx <- REG_DAC_DATA
+       mov al, ah
+       shr al, 2
+       out dx, al
+       mov al, bl
+       shr al, 2
+       out dx, al
+       mov al, bh
+       shr al, 2
+       out dx, al
+       pop dx
+       ret
index ade0e52..51bcbfa 100644 (file)
@@ -2,15 +2,13 @@
        bits 16
        org 7e00h ; that's where our boot loader puts us (see src/boot/boot.asm)
 
        bits 16
        org 7e00h ; that's where our boot loader puts us (see src/boot/boot.asm)
 
-       mov ax, 13h
-       int 10h
+       call init_gfx
 
 
-       mov ax, 0a000h
-       mov es, ax
-       xor di, di
-       mov ax, 0x404
-       mov cx, 32000
-       rep stosw
+main_loop:
+       call wait_vsync
+       call swap_buffers
+       jmp main_loop
 
 
-       cli
-       hlt
+%include "gfx.asm"
+
+%include "data.asm"