Advertisement
Guest User

Untitled

a guest
Aug 7th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Alarm
  2.  
  3. cseg    segment para public 'code'
  4. org 100h
  5. alarm   proc far
  6.  
  7.  
  8. intaddr equ 1ch*4      
  9. segaddr equ 62h*4      
  10. mfactor equ 17478      
  11. whozat  equ 1234h      
  12. color   equ 14h        
  13.  
  14.     assume cs:cseg,ds:cseg,ss:nothing,es:nothing
  15.     jmp p150       
  16.  
  17. jumpval dd 0           
  18. signature dw whozat    
  19. state   db 0           
  20. wait    dw 18          
  21. hour    dw 0           
  22. atime   dw 0ffffh      
  23. acount  dw 0           
  24. atone   db 5           
  25.                
  26. aleng   dw 8080h       
  27.  
  28. dhours  dw 0           
  29.     db ':'
  30. dmins   dw 0           
  31.     db ':'
  32. dsecs   dw 0           
  33.     db '-'
  34. ampm    db 0           
  35.     db 'm'
  36.  
  37. tstack  db 16 dup('stack   ')  
  38. estack  db 0           
  39. holdsp  dw 0           
  40. holdss  dw 0           
  41.  
  42. p000:              
  43.     push ax        
  44.     push ds
  45.     pushf
  46.  
  47.     push cs
  48.     pop ds         
  49.     mov ax,wait    
  50.     dec ax         
  51.     jz p010        
  52.     mov wait,ax    
  53.     jmp p080       
  54.  
  55. p010:   cli        
  56.     mov ax,ss      
  57.     mov holdss,ax
  58.     mov holdsp,sp
  59.     mov ax,ds
  60.     mov ss,ax      
  61.     mov sp,offset estack
  62.     sti        
  63.  
  64.     push bx    
  65.     push cx
  66.     push dx
  67.     push es
  68.     push si
  69.     push di
  70.     push bp
  71.  
  72.     mov ax,18      
  73.     mov wait,ax
  74.  
  75.     mov al,state   
  76.     cmp al,'-'
  77.     jnz p015       
  78.     jmp p070
  79.  
  80. p015:   mov ah,0   
  81.     int 1ah        
  82.     mov ax,dx      
  83.     mov dx,cx      
  84.     mov cl,4
  85.     shl dx,cl      
  86.     mov bx,ax
  87.     mov cl,12
  88.     shr bx,cl      
  89.     add dx,bx      
  90.     mov cl,4
  91.     shl ax,cl      
  92.     mov bx,mfactor 
  93.     div bx         
  94.     cmp ax,atime   
  95.     jnz p020       
  96.     call p100      
  97.     push ax
  98.     mov ax,acount  
  99.     dec ax         
  100.     mov acount,ax  
  101.     cmp ax,0       
  102.     jnz p018       
  103.     mov ax,0ffffh  
  104.     mov atime,ax
  105. p018:   pop ax
  106.  
  107. p020:   mov dsecs,dx
  108.     mov bx,60      
  109.     xor dx,dx      
  110.     div bx         
  111.     mov dmins,dx   
  112.  
  113.     cmp ax,0       
  114.     jnz p030       
  115.     mov ax,12      
  116.     jmp p040a      
  117.  
  118. p030:   cmp ax,12  
  119.     jb p040a       
  120.     jz p040p       
  121.     sub ax,12      
  122. p040p:  mov bl,'p'
  123.     jmp p040x
  124.  
  125. p040a:  mov bl,'a'
  126.  
  127. p040x:  mov ampm,bl
  128.     aam        
  129.     cmp ax,hour    
  130.     jz p060        
  131.  
  132.     mov hour,ax
  133.     call p120      
  134.  
  135. p060:   add ax,3030h
  136.     xchg ah,al
  137.     mov dhours,ax
  138.  
  139.     mov ax,dmins   
  140.     aam
  141.     add ax,3030h   
  142.     xchg ah,al
  143.     mov dmins,ax
  144.  
  145.     mov ax,dsecs   
  146.     xor dx,dx
  147.     mov bx,60
  148.     mul bx
  149.     mov bx,mfactor
  150.     div bx         
  151.     aam
  152.     add ax,3030h
  153.     xchg ah,al
  154.     mov dsecs,ax
  155.  
  156.     xor ax,ax      
  157.     mov es,ax
  158.     mov ax,es:[410h]
  159.     and al,30h     
  160.     cmp al,30h     
  161.     mov ax,0b000h  
  162.     jz p061        
  163.  
  164.     mov ax,0b800h  
  165.  
  166. p061:   mov dx,es:[463h]
  167.     add dx,6       
  168.  
  169.     mov es,ax      
  170.     mov bh,color       
  171.     mov si,offset dhours
  172.     mov di,138     
  173.     cld
  174.     mov cx,11      
  175.  
  176. p062:   mov bl,[si]    
  177.  
  178. p063:   in al,dx       
  179.     test al,1  
  180.     jnz p063   
  181.     cli        
  182.  
  183. p064:   in al,dx       
  184.     test al,1      
  185.     jz p064        
  186.  
  187.     mov ax,bx  
  188.     stosw      
  189.     sti        
  190.     inc si         
  191.     loop p062      
  192.  
  193. p070:   pop bp         
  194.     pop di
  195.     pop si
  196.     pop es
  197.     pop dx
  198.     pop cx
  199.     pop bx
  200.     cli        
  201.     mov ax,holdss
  202.     mov ss,ax
  203.     mov sp,holdsp
  204.     sti        
  205.  
  206. p080:   popf
  207.     pop ds
  208.     pop ax
  209.     jmp cs:[jumpval]
  210.  
  211. p100    proc near      
  212.     call p120
  213.     push cx
  214.     mov cx,20000
  215. p105:   loop p105      
  216.     pop cx
  217.     call p120
  218.     push cx
  219.     mov cx,20000
  220. p106:   loop p106      
  221.     pop cx
  222.     call p120
  223.     ret
  224. p100    endp
  225.  
  226. p120    proc near      
  227.     push ax
  228.     push cx
  229.     mov al,182
  230.     out 43h,al     
  231.     mov al,0
  232.     out 42h,al     
  233.     mov al,atone   
  234.     out 42h,al     
  235.     in al,61h
  236.     push ax        
  237.     or al,3
  238.     out 61h,al     
  239.     mov cx,aleng   
  240. p125:   loop p125  
  241.     pop ax         
  242.     out 61h,al     
  243.     pop cx
  244.     pop ax
  245.     ret
  246. p120    endp
  247.  
  248. p150:              
  249.     mov dx,offset copyr
  250.     call p220      
  251.     mov ax,0
  252.     mov es,ax      
  253.     mov di,segaddr+2   
  254.     mov ax,es:[di]     
  255.     mov es,ax      
  256.     mov di,offset signature
  257.     mov cx,es:[di] 
  258.     cmp cx,whozat
  259.     jnz p160       
  260.     call p200      
  261.     int 20h        
  262.  
  263. p160:   mov di,segaddr+2
  264.     mov ax,0
  265.     mov es,ax      
  266.     mov ax,ds      
  267.     mov es:[di],ax     
  268.     mov si,offset jumpval
  269.     mov di,intaddr     
  270.     mov bx,es:[di]     
  271.     mov ax,es:[di+2]   
  272.     mov [si],bx    
  273.     mov [si+2],ax      
  274.     mov bx,offset p000
  275.     mov ax,ds
  276.     cli        
  277.     mov es:[di],bx     
  278.     mov es:[di+2],ax
  279.     sti        
  280.     push ds
  281.     pop es
  282.     call p200  
  283.     mov dx,offset p150 
  284.     inc dx
  285.     int 27h        
  286.  
  287. p200    proc near  
  288.     mov si,80h     
  289.     mov ax,0
  290.     mov di,0ffffh      
  291.     mov bh,0
  292.     mov ch,0
  293.     mov dh,0       
  294.     mov es:[state],bh  
  295.     mov cl,[si]    
  296.     jcxz p210      
  297.  
  298. p203:   inc si         
  299.     mov bl,[si]    
  300.     cmp bl,'-'              
  301.     jnz p204       
  302.     mov es:[state],bl  
  303.     push dx
  304.     mov dx,offset msg3 
  305.     call p220
  306.     pop dx
  307.     jmp p206
  308.  
  309. p204:   cmp dh,2       
  310.     jz p206        
  311.     cmp bl,':'              
  312.     jnz p205       
  313.     inc dh
  314.     cmp dh,2       
  315.     jz p206        
  316.     push cx
  317.     push dx
  318.     mov cx,60
  319.     mul cx         
  320.     pop dx
  321.     pop cx
  322.     mov di,ax      
  323.     mov ax,0
  324.     jmp p206
  325. p205:   cmp bl,'0'
  326.     jb p206        
  327.     cmp bl,'9'
  328.     ja p206        
  329.     sub bl,'0'              
  330.     push cx
  331.     push dx
  332.     mov cx,10
  333.     mul cx         
  334.     add ax,bx      
  335.     pop dx
  336.     pop cx
  337. p206:   loop p203      
  338.     cmp di,0ffffh      
  339.     jz p210        
  340.     add ax,di      
  341.     cmp ax,24*60
  342.     jb p209        
  343.     mov dx,offset msg1 
  344.     call p220
  345.     jmp p210
  346.  
  347. p209:   mov es:[atime],ax  
  348.     mov ax,5
  349.     mov es:[acount],ax 
  350.     mov dx,offset msg2 
  351.     call p220
  352. p210:   ret
  353. p200    endp
  354.  
  355. p220    proc near      
  356.     push ax
  357.     mov ah,9
  358.     int 21h
  359.     pop ax
  360.     ret
  361. p220    endp
  362.  
  363. copyr   db 'Alarm - Clock',10,13,'$'
  364. msg1    db 'Invalid time - must be from 00:00 to 23:59',10,13,'$'
  365. msg2    db 'Resetting alarm time',10,13,'$'
  366. msg3    db 'Turning clock display off',10,13,'$'
  367.  
  368. alarm   endp
  369. cseg    ends
  370. end alarm
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement