sortof bounds-check while moving
authorJohn Tsiombikas <nuclear@member.fsf.org>
Sun, 13 Oct 2019 16:20:42 +0000 (19:20 +0300)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Sun, 13 Oct 2019 16:20:42 +0000 (19:20 +0300)
src/keyb.asm
src/keyb.inc
src/main.asm

index d9fdd4e..b953474 100644 (file)
@@ -41,15 +41,11 @@ kbintr:
        and bl, 07fh
        add ebx, keystate
 
        and bl, 07fh
        add ebx, keystate
 
-       ; determine if it's a press or release
-       test al, 80h
-       jz .press
-       ; key release
-       mov byte [ebx], 0
-       jmp .eoi
-.press: ; key press
-       mov byte [ebx], 1
-
+       ; determine if it's a press or release (high bit set on release)
+       rol al, 1
+       and al, 1
+       xor al, 1
+       mov byte [ebx], al
 .eoi:
        cli
        end_of_irq KB_IRQ
 .eoi:
        cli
        end_of_irq KB_IRQ
index 6ecb5d9..abd38d0 100644 (file)
@@ -14,6 +14,6 @@ SC_SPACE equ 57
        ; carry set if key is pressed
 %macro check_key 1
        mov ebx, keystate + %1
        ; carry set if key is pressed
 %macro check_key 1
        mov ebx, keystate + %1
-       mov al, [ebx]
-       add al, 0xff
+       mov bl, [ebx]
+       add bl, 0xff
 %endmacro
 %endmacro
index c3ab902..a5e0754 100644 (file)
@@ -5,6 +5,8 @@
 %include "intr.inc"
 %include "dbglog.inc"
 
 %include "intr.inc"
 %include "dbglog.inc"
 
+PLAYER_MOVE_SPEED equ 5
+
        ; 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
        section .startup
        ; 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
        section .startup
@@ -41,19 +43,36 @@ main_loop:
        jmp main_loop
 
 update:
        jmp main_loop
 
 update:
+       mov eax, [ship_y]
+
        check_key SC_W
        jnc .not_w
        check_key SC_W
        jnc .not_w
-       dec dword [ship_y]
+       sub eax, PLAYER_MOVE_SPEED
+       jns .not_w
+       xor eax, eax
 .not_w:        check_key SC_S
        jnc .not_s
 .not_w:        check_key SC_S
        jnc .not_s
-       inc dword [ship_y]
-.not_s: check_key SC_A
+       add eax, PLAYER_MOVE_SPEED
+       cmp eax, 200 << 8
+       jb .not_s
+       mov eax, 200 << 8
+.not_s:
+       mov [ship_y], eax
+       mov eax, [ship_x]
+
+       check_key SC_A
        jnc .not_a
        jnc .not_a
-       dec dword [ship_x]
+       sub eax, PLAYER_MOVE_SPEED
+       jns .not_a
+       xor eax, eax
 .not_a: check_key SC_D
        jnc .not_d
 .not_a: check_key SC_D
        jnc .not_d
-       inc dword [ship_x]
+       add eax, PLAYER_MOVE_SPEED
+       cmp eax, 320 << 8
+       jb .not_d
+       mov eax, 320 << 8
 .not_d:
 .not_d:
+       mov [ship_x], eax
        ret
 
        section .data
        ret
 
        section .data