💾 Archived View for thrig.me › blog › 2023 › 11 › 12 › kernel.asm captured on 2024-07-09 at 01:59:09.
⬅️ Previous capture (2023-11-14)
-=-=-=-=-=-=-
; kernel - this is where the action happens. assemble with nasm BITS 16 org 0x500 call cursor_hide call rand_seed call rand_position call disp_hero loop: call key_read call key_handle jmp loop char_emit: ; al=char mov ah, 0x02 ; fn: set cursor position xor bh, bh ; page number mov dx, [pos_x] ; dh=row, dl=col int 0x10 mov ah, 0x09 ; fn: write char mov bl, [color] mov cx, 1 ; reps int 0x10 ret cursor_hide: mov ah, 0x01 mov ch, 0x3F int 0x10 ret disp_clear: mov al, 0x20 call char_emit ret disp_hero: mov al, 0x40 call char_emit ret key_handle: ; input al=char mov bp, actions add al, al ; byte to word size xor ah, ah add bp, ax ; apply the key offset cmp word [bp], 0 ; action for this key? jz .nope call [bp] .nope: ret key_read: ; out: al=char xor ah, ah int 0x16 ret move_ss: cmp byte [pos_y], 23 jae .nope call disp_clear inc byte [pos_y] call disp_hero .nope: ret move_nn: cmp byte [pos_y], 0 jz .nope call disp_clear dec byte [pos_y] call disp_hero .nope: ret move_ww: cmp byte [pos_x], 0 jz .nope call disp_clear dec byte [pos_x] call disp_hero .nope: ret move_ee: cmp byte [pos_x], 79 jae .nope call disp_clear inc byte [pos_x] call disp_hero .nope: ret ; NOTE these "glide" on an edge. avoiding that would be more complicated move_sw: call move_ss call move_ww ret move_se: call move_ss call move_ee ret move_nw: call move_nn call move_ww ret move_ne: call move_nn call move_ee ret rand_seed: xor ax, ax int 0x1a ; fn: system time mov [seed], dx ret ; the "RNG" from rogue 3.6.3 rand_value: ; in=bx, out=dx (or dl) mov ax, [seed] mov cx, 11109 mul cx add ax, 13849 mov [seed], ax ror ax, 1 xor dx, dx div bx ret rand_position: mov bx, 80 call rand_value mov [pos_x], dl mov bx, 24 call rand_value mov [pos_y], dl ret ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; VARIABLES color: db 0xf ; white pos_x: db 40 ; position - must be grouped with y for DX pos_y: db 12 seed: dw 0 ; traditional rogue(6) keys. remap them if you want something else actions: times 98 dw 0 dw move_sw ; b times 5 dw 0 dw move_ww ; h dw 0 dw move_ss ; j dw move_nn ; k dw move_ee ; l dw 0 dw move_se ; n times 6 dw 0 dw move_ne ; u times 3 dw 0 dw move_nw ; y