⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 miniker.asm

📁 自己动手写操作系统源代码,不可多得的代码
💻 ASM
📖 第 1 页 / 共 5 页
字号:
    out dx,al                    ;;Now,we have set the cursor's positon regi-
                                 ;;sters.
    jmp .ll_ok

.ll_error:
    mov eax,DEF_FALSE
    jmp .ll_end
.ll_ok:
    mov eax,DEF_TRUE
.ll_end:
    pop edx
    leave
    sti
    ret                          ;;End of the procedure.

np_gotoxy:                       ;;The procedure goes to x,y
                                 ;;GotoXY(word x,word y)
    cli
    push ebp
    mov ebp,esp
    push ebx
    mov ax,word [ebp + 0x08]
    cmp ax,DEF_NUM_COLUMN
    jae .ll_error
    mov bx,word [ebp + 0x0c]
    cmp bx,DEF_NUM_LINE
    jae .ll_error
    mov word [gl_x],ax
    mov word [gl_y],bx
    call np_setcursor            ;;Now reset cursor's position.
    jmp .ll_end
    
.ll_error:
    mov eax,DEF_FALSE
    pop ebx
    leave
    sti
    ret
.ll_end:
    mov eax,DEF_TRUE
    pop ebx
    leave
    sti
    ret                          ;;End of the procedure.

np_setorgaddr:                   ;;Modify the start address of the display
                                 ;;memory.
                                 ;;SetOrgAddr(dword dwOrgAddr)
    cli
    push ebp
    mov ebp,esp
    mov eax,dword [ebp + 0x08]
    cmp eax,dword [gl_dispmem_start]
    jb .ll_error
    cmp eax,dword [gl_dispmem_end]
    ja .ll_error
    mov dword [gl_curr_start],eax

    push edx                     ;;Now,change the display card's original
                                 ;;display memory.
    sub eax,dword [gl_dispmem_start]
    push eax
    push eax
    mov dx,DEF_INDEX_PORT
    mov al,DEF_REG_MEM_H
    out dx,al
    mov dx,DEF_VALUE_PORT
    pop eax
    shr ax,0x09                  ;;The original's address is fucking ???
    out dx,al

    mov dx,DEF_INDEX_PORT
    mov al,DEF_REG_MEM_L
    out dx,al
    mov dx,DEF_VALUE_PORT
    pop eax
    shr ax,0x01
    out dx,al
    pop edx
    jmp .ll_end
.ll_error:
    mov eax,DEF_FALSE
    leave
    sti
    ret
.ll_end:
    mov eax,DEF_TRUE
    leave
    sti
    ret                          ;;End of the procedure.

np_movup:                        ;;This procedure moves the end part of the
                                 ;;display memory to up,used by scrool****
                                 ;;procedure.
                                 ;;MovUp(dword currAddr).
    cli
    push ebp
    mov ebp,esp
    push ecx
    push esi
    push edi
    mov eax,dword [ebp + 0x08]
    mov ecx,dword [gl_dispmem_end]
    sub ecx,eax
    mov esi,eax
    mov edi,dword [gl_dispmem_start]
    cld
    rep movsb                    ;;Move the end part of the display memory
                                 ;;to up part.
    mov ah,byte [gl_default_attr]
    mov al,' '
    mov ecx,dword [gl_dispmem_end]
    ;add ecx,dword [gl_dispmem_start]
    sub ecx,edi
    shr ecx,0x01
    rep stosw                   ;;Fill the rest part as space.
    pop edi
    pop esi
    pop ecx
    leave
    sti
    ret                          ;;End of the procedure.

np_scrollupl:                    ;;Scroll up one line.
                                 ;;ScrollUpl().
    mov eax,DEF_NUM_COLUMN * 2
    add eax,dword [gl_curr_start]
    add eax,dword [gl_onescrn_size]
    cmp eax,dword [gl_dispmem_end]
    ja .ll_needscroll
    sub eax,dword [gl_onescrn_size]
    mov dword [gl_curr_start],eax
    push eax
    call np_setorgaddr
    pop eax
    jmp .ll_end
.ll_needscroll:
    sub eax,dword [gl_onescrn_size]
    push eax
    call np_movup
    pop eax
    mov eax,dword [gl_dispmem_start]
    push eax
    call np_setorgaddr
    pop eax
.ll_end:
    mov eax,DEF_TRUE
    ret

np_changeline:                   ;;Change the current line to next.
                                 ;;ChangeLine().
    mov ax,word [gl_y]
    inc ax
    cmp ax,DEF_NUM_LINE
    jae .ll_scrollup             ;;If the current line exceed the max lines,
                                 ;;then scrolls up one line.
    mov word [gl_y],ax
    jmp .ll_end
.ll_scrollup:
    call np_scrollupl            ;;Scroll up one line,the current line keep
                                 ;;no change.
.ll_end:
    call np_setcursor            ;;Reset the cursor's position.
    ret                          ;;End of the procedure.

np_gotohome:                     ;;This procedure goto one line's head.
    mov word [gl_x],0x00
    call np_setcursor
    ret                          ;;End of the procedure.

np_gotonext:                     ;;This procedure moves the current position
                                 ;;to next.
    mov ax,word [gl_x]
    inc ax
    cmp ax,DEF_NUM_COLUMN
    jae .ll_changeline
    mov word [gl_x],ax
    jmp .ll_end

.ll_changeline:
    mov word [gl_x],0x00
    call np_changeline
.ll_end:
    call np_setcursor
    ret                          ;;End of the procedure.

np_gotoprev:                     ;;This procedure changes the current positi-
                                 ;;on to the previous,which can be used by
                                 ;;DEL,BackSpace key handler.
    push ebp
    mov ebp,esp
    push edx
    mov ax,word [gl_y]
    add ax,word [gl_x]
    cmp ax,0x0000
    jz .ll_end                   ;;If the current position is locating the
                                 ;;begin of one screen,this procedure only
                                 ;;returns.
    cmp word [gl_x],0x00
    jz .ll_needscroll
    dec word [gl_x]
    jmp .ll_adjust
.ll_needscroll:
    mov word [gl_x],DEF_NUM_COLUMN - 1
    dec word [gl_y]              ;;Adjust to the up lines.
.ll_adjust:
    xor eax,eax
    mov ax,word [gl_y]
    mov dl,DEF_NUM_COLUMN
    mul dl
    add ax,word [gl_x]
    shl eax,0x01
    mov edx,dword [gl_curr_start]
    add edx,eax
    mov al,' '
    mov ah,byte [gl_default_attr]
    cli
    mov word [edx],ax
    call np_setcursor            ;;Update the cursor's position to the curr-
                                 ;;ent position.
    sti
.ll_end:
    pop edx
    leave
    ret                          ;;End of the procedure.


np_printstr:                     ;;Print one string at current position.
                                 ;;PrintStr(string str).
    push ebp
    mov ebp,esp
    push ecx
    push esi
    mov esi,dword [ebp + 0x08]
    push esi
    call np_hlp_strlen
    pop esi
    cmp eax,DEF_MAX_STR_LEN
    ja .ll_adjust
    jmp .ll_continue
.ll_adjust:
    mov eax,DEF_MAX_STR_LEN
.ll_continue:
    mov ecx,eax
    mov ah,byte [gl_default_attr]
.ll_begin:
    mov al,byte [esi]
    push eax
    call np_printch
    pop eax
    inc esi
    loop .ll_begin
    pop esi
    pop ecx
    leave
    ret                          ;;End of the procedure.

np_changeattr:                   ;;Change the default character attribute.
                                 ;;ChangeAttr(byte attr).
    push ebp
    mov ebp,esp
    mov al,byte [ebp + 0x08]
    mov byte [gl_default_attr],al
    leave
    ret                          ;;End of the procedure.

np_printch:                      ;;Print out a character.
                                 ;;PrintCh(word ch),the variable ch countains
                                 ;;the character's ascii code and it's attri-
                                 ;;bute.
    push ebp
    mov ebp,esp
    push ebx
    xor eax,eax
    mov ax,word [gl_y]
    mov bl,DEF_NUM_COLUMN
    mul bl
    add ax,word [gl_x]
    shl ax,0x01                  ;;Form the offset address of the current pos-
                                 ;;ition.
    add eax,dword [gl_curr_start]  ;;Now,eax countains the address where to be
                                   ;;print the character.

    ;mov eax,dword [gl_curr_start]  ;;------------ ** debug ** -----------

    mov ebx,dword [ebp + 0x08]
    mov word [eax],bx
    call np_gotonext
    pop ebx
    leave
    ret                          ;;End of the procedure.

np_clearscreen:                  ;;This procedure clear the whole display
                                 ;;memory,so the whole is cleared.
    push ebp
    mov ebp,esp
    push ecx
    push edi
    mov edi,dword [gl_dispmem_start]
    mov dword [gl_curr_start],edi
    mov word [gl_x],0x00
    mov word [gl_y],0x00
    mov al,' '
    mov ah,byte [gl_default_attr]
    mov ecx,dword [gl_dispmem_end]
    sub ecx,dword [gl_dispmem_start]
    shr ecx,0x01
    cli
    cld
    rep stosw                    ;;Fill the whole display memory as space.
    push dword [gl_dispmem_start]
    call np_setorgaddr           ;;Adjust the current display start address.
    pop dword [gl_dispmem_start]
    call np_setcursor            ;;Adjust the position of the cursor.
    sti
    pop ecx
    pop edi
    leave
    ret                          ;;End of the procedure.

;;------------------------------------------------------------------------
;;    The following code is a key board driver.
;;------------------------------------------------------------------------
    
    %define VK_ESC          0x01
    %define VK_MINIS_SIGN   '-'
    %define VK_EQUAL_SIGN   '='
    %define VK_BACKSPACE    0x0e
    %define VK_TAB          0x0f
    %define VK_RETURN       0x0a
    %define VK_LEFT_CTRL    0x1d
    %define VK_LEFT_SHIFT   0x2a
    %define VK_DOT          '.'
    %define VK_RIGHT_SHIFT  0x2a
    %define VK_LEFT_ALT     0x38
    %define VK_SPACE        ' '
    %define VK_CAPS_LOCK    0x3a
    %define VK_F1           0x3b
    %define VK_F2           0x3c
    %define VK_F3           0x3d
    %define VK_F4           0x3e
    %define VK_F5           0x3f
    %define VK_F6           0x40
    %define VK_F7           0x41
    %define VK_F8           0x42
    %define VK_F9           0x43
    %define VK_F10          0x44
    %define VK_F11          0x57
    %define VK_F12          0x58

    %define VK_KP_NUM        0x45
    %define VK_KP_DOT        '.'
    %define VK_KP_RETURN     0x0a
    %define VK_KP_ADD_SIGN   '+'
    %define VK_KP_MINIS_SIGN '-'
    %define VK_KP_0          '0'
    %define VK_KP_1          '1'
    %define VK_KP_2          '2'
    %define VK_KP_3          '3'
    %define VK_KP_4          '4'
    %define VK_KP_5          '5'
    %define VK_KP_6          '6'
    %define VK_KP_7          '7'
    %define VK_KP_8          '8'
    %define VK_KP_9          '9'
    %define VK_KP_SCROLL     0x46

align 8

gl_kdrv_datasection:             ;;The following section defines some variab-
                                 ;;les and global storage.

    gl_normalqueue:              ;;This queue is used for normal key buffer.
                    dd 0x00000000 ;;These 64 byte space is reserved for key-
                    dd 0x00000000 ;;board buffer.
                    dd 0x00000000
                    dd 0x00000000
                    dd 0x00000000
                    dd 0x00000000

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -