--- /dev/null
+; 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
--- /dev/null
+; 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
; 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
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
; 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
%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
extern idt
%ifndef INTR_ASM_
+ extern init_intr
extern set_intr
%endif
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
jz .skipread
call read_data
.skipread:
+
+ unmask_irq KB_IRQ
ret
; keyboard interrupt handler
; vi:filetype=nasm:
+ extern kb_init
extern keystate
; 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
; 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
call wait_vsync
call swap_buffers
jmp main_loop
+
+update:
+ ret
+
+ section .data
+ align 4
+ship_x: dd 160
+ship_y: dd 100