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

📄 kernel.asm

📁 Menuet 操作系统源代码。 非常难得的东西
💻 ASM
📖 第 1 页 / 共 5 页
字号:
    mov   edi,[0x3010]
    add   ebx,[edi+0x10]
    mov   esi,ebx
    mov   edi,ecx
    add   ecx,edx
    cmp   ecx,0x100000-16
    jbe   nsb52
    ret
   nsb52:
    add   edi,0x300000
    mov   ecx,edx
    cmp   ecx,0x100000-16
    jbe   nsb51
    ret
   nsb51:
    mov   [bgrchanged],1
    cld
    rep   movsb
    ret
  nosb5:
   
    ret
   
   
align 4
   
sys_getbackground:
   
    cmp   eax,1                                  ; SIZE
    jnz   nogb1
    mov   eax,[0x400000-8]
    shl   eax,16
    mov   ax,[0x400000-4]
    mov   [esp+36],eax
    ret
  nogb1:
   
    cmp   eax,2                                  ; PIXEL
    jnz   nogb2
    mov   edx,0x100000-16
    cmp   edx,ebx
    jbe   nogb2
    mov   eax,[ebx+0x300000]
    and   eax,255*256*256+255*256+255
    mov   [esp+36],eax
    ret
  nogb2:
   
    cmp   eax,4                                  ; TILED / STRETCHED
    jnz   nogb4
    mov   eax,[0x400000-12]
  nogb4:
    mov   [esp+36],eax
    ret
   
   
align 4
   
sys_getkey:
   
    movzx ebx,word [0x3000]                      ; TOP OF WINDOW STACK
    shl   ebx,1
    mov   [esp+36],dword 1
    add   ebx,0xc000
    movzx ecx,word [ebx]
    mov   edx,[0x3004]
    cmp   ecx,edx
    je    sysgkl1
    ret
  sysgkl1:
    cmp   [0xf400],byte 0
    jne   gkc1
    ret
  gkc1:
    movzx eax,byte [0xf401]
    shl   eax,8
    mov   [0xf400],byte 0
    mov   [esp+36],eax
    ret
   
   
align 4
   
sys_getbutton:
   
    movzx ebx,word [0x3000]                      ; TOP OF WINDOW STACK
    mov   [esp+36],dword 1
    shl   ebx,1
    add   ebx,0xc000
    movzx ecx,word[ebx]
    movzx edx,word[0x3004]
    cmp   ecx,edx
    je    gbot
    ret
  gbot:
    movzx eax,byte [0xf500]
    test  eax,eax
    jnz   gbc1
    ret
  gbc1:
    mov   eax,[0xf501]
    shl   eax,8
    mov   [0xf500],byte 0
    mov   [esp+36],eax
    ret
   
   
align 4
   
sys_cpuusage:
   
;  RETURN:
;
;  +00 dword     process cpu usage
;  +04  word     position in windowing stack
;  +06  word     windowing stack value at current position (cpu nro)
;  +10 12 bytes  name
;  +22 dword     start in mem
;  +26 dword     used mem
;  +30 dword     PID , process idenfification number
;
   
    mov  edi,[0x3010]   ; eax = return area
    add  edi,0x10
    add  eax,[edi]
   
    cmp  ebx,-1         ; who am I ?
    jne  no_who_am_i
    mov  ebx,[0x3000]
  no_who_am_i:
   
    push eax            ; return area
    push ebx            ; process number
   
    push ebx
    push ebx
    push eax
   
    ; return memory usage
   
    xor  edx,edx
    mov  eax,0x20
    mul  ebx
    add  eax,0x3000+0x1c
    mov  ebx,eax
    pop  eax
    mov  ecx,[ebx]
    mov  [eax],ecx
    mov  ebx,[esp]
    shl  ebx,1
    add  ebx,0xc000
    mov  cx,[ebx]
    mov  [eax+4],cx
    mov  ebx,[esp]
    shl  ebx,1
    add  ebx,0xc400
    mov  cx,[ebx]
    mov  [eax+6],cx
    pop  ebx
    push eax
    mov  eax,ebx
    shl  eax,8
    add  eax,0x80000
    pop  ebx
    add  ebx,10
    mov  ecx,11
    call memmove
   
    ; memory usage
   
    xor    eax,eax
    mov    edx,0x100000*16-4096
    pop    ecx                                   ; get gdt of tss
    cmp    ecx,1
    je     os_mem
    ;shl    ecx,8
    ;add    ecx,0x80000+0x88
    ;mov    ecx,[ecx]
    shl    ecx,3
    ; eax run base -> edx used memory
    mov    al,[ecx+gdts+ app_code-3 +4]            ;  base  23:16
    mov    ah,[ecx+gdts+ app_code-3 +7]            ;  base  31:24
    shl    eax,16
    mov    ax,[ecx+gdts+ app_code-3 +2]            ;  base  0:15
    movzx  edx,word [ecx+gdts+ app_code-3 +0]
    shl    edx,12
  os_mem:
    mov    [ebx+12],eax
    mov    [ebx+16],edx
   
    ; PID (+30)
   
    mov    eax,[esp]
    shl    eax,5
    add    eax,0x3000+0x4
    mov    eax,[eax]
    mov    [ebx+20],eax
   
    ; window position and size
   
    mov    esi,[esp]
    shl    esi,5
    add    esi,0x2000
    mov    edi,[esp+4]
    add    edi,34
    mov    ecx,4*4
    cld
    rep    movsb
   
    pop    ebx
    pop    eax
   
    ; return number of processes
   
    mov    eax,[0x3004]
    mov    [esp+36],eax
    ret
   
checkimage:
   
        push  eax
        push  ebx
        push  ecx
        push  edx
        xor   edx,edx
        xor   ecx,ecx
        mov   cx,[0x3000]
        shl   ecx,1
        add   ecx,0xc000
        mov   dx,[ecx]
        mov   ax,[0x3004]
        cmp   dx,ax
        jz    imok
        jmp   imcheckinside
      imok:                  ; first in stack
        pop   edx
        pop   ecx
        pop   ebx
        pop   eax
   
        xor  ecx,ecx
        ret
   
      imcheckinside:
   
        mov   esi,edx        ; window of image -position in windowing stack
        pop   edx
        pop   ecx
        pop   ebx
        pop   eax
        call  cilimit
        ret
   
cilimit:
   
        push eax
        push ebx
        xor  eax,eax
        xor  ebx,ebx
        mov  al,[0xe000]
        cmp  eax,1
        jz   cilc
        pop  ebx
        pop  eax
        xor  ecx,ecx
        ret
      cilc:
        push  ecx
        push  edx
        mov   edi,[0x3010]
        mov   ecx,0xd000-0x3000
        add   edi,ecx
        mov   eax,[esp+12]
        mov   ebx,[esp+8]
        mov   ecx,[esp+04]
        mov   edx,[esp+00]
        mov   ecx,[edi+12]
        cmp   edx,ecx
        jbe   cici1
        jmp   cicino
      cici1:
        mov   ecx,[edi+4]
        cmp   ecx,ebx
        jbe   cici2
        jmp   cicino
      cici2:
        mov   eax,[esp+12]
        mov   ebx,[esp+8]
        mov   ecx,[esp+04]
        mov   edx,[esp+00]
        mov   edx,[edi+8]
        cmp   ecx,edx
        jbe   cici3
        jmp   cicino
      cici3:
        mov   edx,[edi+0]
        cmp   edx,eax
        jbe   cici4
        jmp   cicino
      cici4:
        pop   edx
        pop   ecx
        pop   ebx
        pop   eax
        xor   ecx,ecx   ;inside of draw limits
        ret
      cicino:
        pop   edx
        pop   ecx
        pop   ebx
        pop   eax
        mov   ecx,1     ;outside of draw limits
        ret
   
   
dececx:
   
    push eax
    push edx
    push ecx
   
    mov  edx,1
   
  dececl:
   
    movzx eax,byte [esp+edx]
    cmp   eax,0x20
    jge   deccl1
    mov   [esp+edx],byte 0x20
   deccl1:
    sub   [esp+edx],byte 0x20
   
    add  edx,1
    cmp  edx,4
    jbe  dececl
   
    pop  ecx
    pop  edx
    pop  eax
    ret
   
   
drawbuttonframes:
   
        push  esi
        push  edi
        push  eax
        push  ebx
        push  ecx
        push  edx
   
        shr   eax,16
        shr   ebx,16
        mov   edx,[0x3010]
   
        add   eax,[edx-0x1000]
        add   ebx,[edx-0x1000+4]
        mov   cx,ax
        mov   dx,bx
        shl   eax,16
        shl   ebx,16
        mov   ax,cx
        mov   bx,dx
        add   ax,word [esp+12]
        mov   esi,ebx
        mov   edi,0
        mov   ecx,[esp+0]
        add   ecx,0x202020
        call  draw_line
   
        movzx edx,word [esp+8]
        add   ebx,edx
        shl   edx,16
        add   ebx,edx
        mov   ecx,[esp+0]
        call  dececx
        call  draw_line
   
        mov   ebx,esi
        push  edx
        mov   edx,eax
        shr   edx,16
        mov   ax,dx
        mov   edx,ebx
        shr   edx,16
        mov   bx,dx
        mov   dx,[esp+8+4]
        add   bx,dx
        pop   edx
        mov   edi,0
        mov   ecx,[esp+0]
        add   ecx,0x202020
        call  draw_line
   
        mov   esi,edx
        mov   dx,[esp+12]
        add   ax,dx
        shl   edx,16
        add   eax,edx
        add   ebx,1*65536
        mov   edx,esi
        mov   ecx,[esp+0]
        call  dececx
        call  draw_line
   
        pop   edx
        pop   ecx
        pop   ebx
        pop   eax
        pop   edi
        pop   esi
   
        ret
   
button_dececx:
   
        cmp   [buttontype],dword 1
        je    bdece
        ret
      bdece:
        push  eax
        mov   eax,0x01
        cmp   edi,20
        jg    bdl9
        mov   eax,0x02
      bdl9:
        test  ecx,0xff
        jz    bdl1
        sub   ecx,eax
      bdl1:
        shl   eax,8
        test  ecx,0xff00
        jz    bdl2
        sub   ecx,eax
      bdl2:
        shl   eax,8
        test  ecx,0xff0000
        jz    bdl3
        sub   ecx,eax
      bdl3:
        pop    eax
        ret
   
   
sys_button:
   
        test  ecx,0x80000000
        jnz   remove_button
   
        push  esi
        push  edi
        push  eax
        push  ebx
        push  ecx
        push  edx
   
        test  ecx,0x40000000
        jnz   button_no_draw
   
        pusha                       ; button body
        push  ebx
        shr   eax,16
        shr   ebx,16
        mov   edx,[0x3010]
        mov   esi,[edx-0x1000]
        mov   edi,[edx-0x1000+4]
        add   eax,esi
        add   ebx,edi
        mov   cx,ax
        mov   dx,bx
        shl   eax,16
        shl   ebx,16
        mov   ax,cx
        mov   bx,dx
        movzx ecx,word [4+32+esp+12]
        add   eax,ecx
        mov   ecx,[4+32+esp+0]
        cmp   [buttontype],dword 0
        je    bdecel1
        add   ecx,0x141414
       bdecel1:
        movzx edi,word [esp]
       bnewline:
        call  button_dececx
        push  edi
        mov   edi,0
        call  draw_line
        pop   edi
        add   ebx,1*65536+1
        dec   word [esp]
        mov   dx,[esp]
        cmp   dx,0
        jnz   bnewline
        pop   ebx
        popa
   
        call  drawbuttonframes
   
      button_no_draw:
   
        and   ecx,0xffff
   
        mov   edi,[0x3010]
        sub   edi,0x1000
   
        mov   edi,[0xfe88]
        movzx eax,word [edi]
        cmp   eax,1000
        jge   noaddbutt
        inc   eax
        mov   [edi],ax
   
        shl   eax,4
        add   eax,edi
   
        mov   bx,[0x3000]
        mov   [eax],bx
   
        add   eax,2         ; save button id number
        mov   ebx,[esp+4]
        mov   [eax],bx      ; bits 0-15
        shr   ebx,16
        mov   [eax-2+0xc],bx; bits 16-31
        add   eax,2         ; x start
        mov   bx,[esp+12+2]
        mov   [eax],bx
        add   eax,2         ; x size
        mov   bx,[esp+12+0]
        mov   [eax],bx
        add   eax,2         ; y start
        mov   bx,[esp+8+2]
        mov   [eax],bx
        add   eax,2         ; y size
        mov   bx,[esp+8+0]
        mov   [eax],bx
   
     noaddbutt:
   
        pop   edx
        pop   ecx
        pop   ebx
        pop   eax
        pop   edi
        pop   esi
   
        ret
   
   
remove_button:
   
    and  ecx,0x7fffffff
   
  rnewba2:
   
    mov   edi,[0xfe88]
    mov   eax,edi
    movzx ebx,word [edi]
    inc   bx
   
  rnewba:
   
    dec   bx
    jz    rnmba
   
    add   eax,0x10
   
    mov   dx,[0x3000]
    cmp   dx,[eax]
    jnz   rnewba
   
    cmp   cx,[eax+2]
    jnz   rnewba
   
    pusha
    mov   ecx,ebx
    inc   ecx
    shl   ecx,4
    mov   ebx,eax
    add   eax,0x10
    call  memmove
    dec   dword [edi]
    popa
   
    jmp   rnewba2
   
  rnmba:
   
    ret
   
   
align 4
   
sys_clock:
   
        cli
        xor   al,al           ; seconds
        out   0x70,al
        in    al,0x71
        movzx ecx,al
        mov   al,02           ; minutes
        shl   ecx,16
        out   0x70,al
        in    al,0x71
        movzx edx,al
        mov   al,04           ; hours
        shl   edx,8
        out   0x70,al

⌨️ 快捷键说明

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