From: John Tsiombikas Date: Sun, 13 Oct 2019 00:38:47 +0000 (+0300) Subject: foo X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=ld45_start_nothing;a=commitdiff_plain;h=371bbe72cccdd5c40d5118bd0417fab062f3699a foo --- diff --git a/src/dbglog.asm b/src/dbglog.asm new file mode 100644 index 0000000..0753631 --- /dev/null +++ b/src/dbglog.asm @@ -0,0 +1,67 @@ +; vi:filetype=nasm ts=8 sts=8 sw=8: + section .text + + ; expects the address of a zero-terminated string in esi + global dbglog_str +dbglog_str: + mov al, [esi] + cmp al, 0 + jz .end + inc esi + call ser_putchar + jmp dbglog_str +.end: ret + + global dbglog_str_num +dbglog_str_num: + pusha + call dbglog_str + mov eax, [esp + 28] ; eax pushed by pusha + + mov esi, numbuf + 16 + mov byte [esi], 0 + mov ebx, 10 +.convloop: + xor edx, edx + div ebx + add dl, '0' + dec esi + mov [esi], dl + cmp eax, 0 + jnz .convloop + + call dbglog_str + popa + ret + + +UART_DATA equ 3f8h +UART_LSTAT equ 3fdh +LST_TREG_EMPTY equ 20h + +ser_putchar: + push edx + cmp al, 10 + jnz .notlf + push eax + mov al, 13 + call ser_putchar + pop eax + +.notlf: mov ah, al + ; wait until the transmit register is empty + mov dx, UART_LSTAT +.wait: in al, dx + and al, LST_TREG_EMPTY + jz .wait + mov dx, UART_DATA + mov al, ah + out dx, al + + pop edx + ret + + + + section .data +numbuf: times 16 db 0 diff --git a/src/dbglog.inc b/src/dbglog.inc new file mode 100644 index 0000000..c0699dc --- /dev/null +++ b/src/dbglog.inc @@ -0,0 +1,23 @@ +; vi:filetype=nasm ts=8 sts=8 sw=8: + + extern dbglog_str + extern dbglog_str_num + +%macro dbglog 1 + mov esi, %%msg + call dbglog_str + + section .data +%%msg: db %1,0 + section .text +%endmacro + +%macro dbglog 2 + mov esi, %%msg + mov eax, %2 + call dbglog_str_num + + section .data +%%msg: db %1,0 + section .text +%endmacro diff --git a/src/intr.asm b/src/intr.asm index 0c8acf7..58ef37f 100644 --- a/src/intr.asm +++ b/src/intr.asm @@ -40,14 +40,29 @@ set_intr: ; selector (kcode:1) goes to the second dword of the descriptor mov dword [ebx + 4], 08h + ; install dummy interrupt handlers for all IRQ vectors +%assign i 0 +%rep 8 + set_irq_vector i, dummy_intr_pic1 + set_irq_vector i+8, dummy_intr_pic2 +%assign i i+1 +%endrep + pop ebx pop ebp ret -PIC1_CMD equ 20h -PIC1_DATA equ 21h -PIC2_CMD equ 0a0h -PIC2_DATA equ 0a1h +dummy_intr_pic1: + push eax + end_of_irq 0 + pop eax + iret + +dummy_intr_pic2: + push eax + end_of_irq 8 + pop eax + iret ; PIC initialization command word 1 bits ICW1_ICW4_NEEDED equ 01h @@ -61,8 +76,6 @@ ICW4_AUTO_EOI equ 02h ICW4_BUF_SLAVE equ 08h ICW4_BUF_MASTER equ 0ch ICW4_SPECIAL equ 10h -; PIC operation command word 2 bits -OCW2_EOI equ 20h init_pic: ; send ICW1 saying we'll follow with ICW4 later on diff --git a/src/intr.inc b/src/intr.inc index ac57934..a96b164 100644 --- a/src/intr.inc +++ b/src/intr.inc @@ -1,7 +1,9 @@ ; vi:filetype=nasm ts=8 sts=8 sw=8: PIC1_CMD equ 020h +PIC1_DATA equ 021h PIC2_CMD equ 0a0h +PIC2_DATA equ 0a1h OCW2_EOI equ 020h OCW3_ISR equ 00bh IRQ_OFFSET equ 32 @@ -10,35 +12,34 @@ IRQ_OFFSET equ 32 %macro set_irq_vector 2 - push dword IRQ_TO_INTR(%1) push dword %2 + push dword IRQ_TO_INTR(%1) call set_intr + add esp, 8 %endmacro %macro mask_irq 1 %if %1 < 8 -%assign port PIC1_DATA -%assign mask (1 << %1) + in al, PIC1_DATA + or al, (1 << %1) + out PIC1_DATA, al %else -%assign port PIC2_DATA -%assign mask (1 << (%1 - 8)) + in al, PIC2_DATA + or al, (1 << (%1 - 8)) + out PIC2_DATA, al %endif - in al, port - or al, mask - out port, al %endmacro %macro unmask_irq 1 %if %1 < 8 -%assign port PIC1_DATA -%assign mask ~(1 << %1) + in al, PIC1_DATA + and al, ~(1 << %1) + out PIC1_DATA, al %else -%assign port PIC2_DATA -%assign mask ~(1 << (%1 - 8)) + in al, PIC2_DATA + and al, ~(1 << (%1 - 8)) + out PIC2_DATA, al %endif - in al, port - and al, mask - out port, al %endmacro %macro end_of_irq 1 @@ -52,5 +53,6 @@ IRQ_OFFSET equ 32 extern idt %ifndef INTR_ASM_ + extern init_intr extern set_intr %endif diff --git a/src/keyb.asm b/src/keyb.asm index 0f1d498..c41a2b6 100644 --- a/src/keyb.asm +++ b/src/keyb.asm @@ -4,10 +4,7 @@ global kb_init kb_init: - push kbintr - push dword IRQ_TO_INTR(KB_IRQ) - call set_intr - add esp, 8 + set_irq_vector KB_IRQ, kbintr ; enable keyboard interrupt mov eax, KB_CMD_GET_CMDBYTE @@ -25,6 +22,8 @@ kb_init: jz .skipread call read_data .skipread: + + unmask_irq KB_IRQ ret ; keyboard interrupt handler diff --git a/src/keyb.inc b/src/keyb.inc index 0a6b9a7..c022e43 100644 --- a/src/keyb.inc +++ b/src/keyb.inc @@ -1,3 +1,4 @@ ; vi:filetype=nasm: + extern kb_init extern keystate diff --git a/src/main.asm b/src/main.asm index 1cf9d6a..ce5e5ad 100644 --- a/src/main.asm +++ b/src/main.asm @@ -1,6 +1,9 @@ ; vi:filetype=nasm ts=8 sts=8 sw=8: bits 32 %include "gfx.inc" +%include "keyb.inc" +%include "intr.inc" +%include "dbglog.inc" ; this is placed at the beginning of our binary at 1mb (see game.ld) ; and it's what gets executed directly by the boot loader @@ -10,14 +13,21 @@ ; start of main section .text main: + call init_intr + call kb_init call init_gfx + dbglog `hello\n` + + sti main_loop: + call update + call clear push dword 0 - push dword 100 - push dword 160 + push dword [ship_y] + push dword [ship_x] push dword FRAMEBUF_ADDR call sprsheet add esp, 16 @@ -25,3 +35,11 @@ main_loop: call wait_vsync call swap_buffers jmp main_loop + +update: + ret + + section .data + align 4 +ship_x: dd 160 +ship_y: dd 100