Advertisement
FlyFar

kernel.asm

Mar 21st, 2023
1,332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ASM (NASM) 2.34 KB | Cybersecurity | 0 0
  1. use16
  2. org 0x7c00
  3.  
  4. %include "decompress.asm" ; Include decompressor part
  5.  
  6. %macro sleep 2
  7.     ; Use BIOS interrupt to sleep
  8.     push dx
  9.     mov ah, 86h
  10.     mov cx, %1
  11.     mov dx, %2
  12.     int 15h
  13.     pop dx
  14. %endmacro
  15.  
  16. %macro beepfreq 0
  17.     out 42h, al
  18.     mov al, ah
  19.     out 42h, al
  20. %endmacro
  21.  
  22. %macro beepon 0
  23.     in al, 61h
  24.     or al, 00000011b
  25.     out 61h, al
  26. %endmacro
  27.  
  28. %macro beepoff 0
  29.     in al, 61h
  30.     and al, 11111100b
  31.     out 61h, al
  32. %endmacro
  33.  
  34. startanimation:
  35.     ; Init PC speaker
  36.     mov al, 182
  37.     out 43h, al
  38.    
  39.     ; Remove blinking
  40.     mov ax, 1003h
  41.     mov bl, 0
  42.     int 10h
  43.  
  44.     mov di, 0
  45.  
  46.     mov dx, image+24000
  47.    
  48.     mov cx, 0xb800 ; Set base address for video memory
  49.     mov es, cx
  50.    
  51.     ; Clear screen
  52.     mov ax, 0
  53.     mov cx, 2000
  54.     rep stosw
  55.    
  56.     mov si, image+24000+476
  57.     mov di, 0
  58.    
  59.     beepon
  60.     mov bl, 1
  61.    
  62.     startmsg:
  63.         sleep 0x0, 0x6000
  64.        
  65.         cmp si, image+24000+476+msglen
  66.         jge note
  67.        
  68.         lodsb
  69.         mov ah, 0xf0
  70.         stosw
  71.        
  72.         note:
  73.             dec bl
  74.             cmp bl, 0
  75.             jne startmsg
  76.            
  77.             push si
  78.             mov si, dx
  79.            
  80.             lodsw
  81.             mov cx, ax
  82.             and ah, 0b00011111
  83.            
  84.             beepfreq
  85.            
  86.             shr ch, 5
  87.             shl ch, 2
  88.             mov bl, ch
  89.            
  90.             mov dx, si
  91.            
  92.             pop si
  93.            
  94.             cmp dx, image+24000+26*2
  95.             jne startmsg
  96.        
  97.     ; Set image address
  98.     mov si, image
  99.     mov di, 0
  100.    
  101.     mov ax, daddr
  102.     mov ds, ax
  103.    
  104.     mov ax, 0xb800
  105.     mov es, ax
  106.    
  107.     dec bl
  108.     jmp transition
  109.    
  110.     wrimg:
  111.         ; Write character
  112.         mov al, 220
  113.         stosb
  114.        
  115.         ; Write attributes
  116.         lodsb
  117.         stosb
  118.        
  119.         ; Check if animation is done
  120.         cmp si, image+24000
  121.         je repeat
  122.    
  123.         ; Check if the next frame is reached
  124.         cmp di, 4000
  125.         je nextframe
  126.    
  127.         ; Repeat the loop
  128.         jmp wrimg
  129.    
  130.     nextframe:
  131.         sleep 0x1, 0x6000 ; Sleep some time
  132.        
  133.         transition:
  134.         mov di, 0         ; Reset video memory address
  135.        
  136.         cmp dx, image+24000+476
  137.         jne nextnote
  138.        
  139.         mov dx, image+24000+26*2 ; Loop song
  140.        
  141.         nextnote:
  142.             dec bl
  143.             cmp bl, 0
  144.             jne wrimg
  145.            
  146.             push si
  147.             mov si, dx
  148.            
  149.             lodsw
  150.             mov cx, ax
  151.             and ah, 0b00011111
  152.            
  153.             beepfreq
  154.            
  155.             shr ch, 5
  156.             mov bl, ch
  157.            
  158.             mov dx, si
  159.            
  160.             pop si
  161.             jmp wrimg         ; Go back
  162.    
  163.     repeat:
  164.         mov si, image
  165.         jmp nextframe
  166.    
  167. daddr: equ 0x07e0
  168. compressed: equ 0x0000
  169. image: equ 0x4000
  170. msglen: equ 76
  171.  
  172. times 510 - ($ - $$) db 0
  173. dw 0xAA55 ; Boot sector signature
  174.  
  175. comp: incbin "Data/compressed.bin"
  176. compsize: equ $-comp
  177.  
  178. times 4*1024 - ($ - $$) db 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement