Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; multi-segment executable file template.
  2.  
  3. data segment
  4.     name_contents db "c:\contents.bin", 0                        
  5.     string_formula db "Formula", 0
  6.     string_result db "Result", 0
  7.     string_menu db "Menu", 0
  8.     num_hcell dw 04h
  9.     matrix_lenght dw 200 ;estava 240 antes
  10.     matrix_height dw 64
  11.     ;formula_lenght 88
  12. ends
  13.  
  14. stack segment
  15.     dw   128  dup(0)
  16. ends
  17.  
  18. code segment
  19. start:
  20. ; set segment registers:
  21.     mov ax, data
  22.     mov ds, ax
  23.     mov es, ax
  24.    
  25.     ;open contents.bin
  26.         call open_contents
  27.    
  28.     ;iniciate video mode
  29.         mov ah, 00h
  30.         mov al, 13h
  31.         int 10h
  32.    
  33.     ;draw spreadsheet    
  34.         call createMatrix
  35.        
  36.         call createMenuBox
  37.        
  38.         call createFormulaBox
  39.        
  40.         call createResultBox
  41.        
  42.         call showLetters
  43.        
  44.         mov ax, 00h
  45.         int 33h
  46.                                    
  47.     keep_checking:
  48.         mov ax, 03h
  49.         int 33h
  50.         shr cx, 1       ; x/2 - in this mode the value of CX is doubled.
  51.         cmp bx, 1
  52.         jnz keep_checking      
  53.    
  54.     ;saves contents.bin
  55.         ;call save_contents  
  56.    
  57.     mov ax, 4c00h ; exit to operating system.
  58.     int 21h
  59.  
  60.    
  61. ;*****************************************************************
  62. ; hLine -
  63. ; descricao: creates horizontal lines for the matrix
  64. ; input - bx= numero de linhas ; cx = horizontal margin ; dx = vertical margin ; ax = line lenght
  65. ; output -
  66. ; destroi -
  67. ;*****************************************************************        
  68.    
  69.     hLine proc
  70.            
  71.         n_hlines:
  72.             push ax
  73.             push cx
  74.            
  75.             h_change_pixel:
  76.             push ax
  77.             mov ah, 0Ch
  78.             mov al, 0Fh
  79.             int 10h
  80.            
  81.             pop ax
  82.             dec ax
  83.             jz h_done
  84.             inc cx
  85.             jmp h_change_pixel
  86.        
  87.         h_done:
  88.         pop cx
  89.         pop ax
  90.         add dx, 16
  91.         dec bx
  92.         jnz n_hlines
  93.         ret
  94.     hLine endp
  95.    
  96.  
  97. ;*****************************************************************
  98. ; vLine -
  99. ; descricao: creates vertical lines for the matrix
  100. ; input - bx= numero de linhas ; cx = horizontal margin ; dx = vertical margin ; ax = matrix_height
  101. ; output -
  102. ; destroi -
  103. ;*****************************************************************        
  104.    
  105.     vLine proc
  106.        
  107.         n_vlines:
  108.             push ax
  109.             push dx
  110.            
  111.             v_change_pixel:
  112.             push ax
  113.             mov ah, 0Ch
  114.             mov al, 0Fh
  115.             int 10h
  116.            
  117.             pop ax
  118.             dec ax
  119.             jz v_done
  120.             inc dx
  121.             jmp v_change_pixel
  122.            
  123.         v_done:
  124.         pop dx
  125.         pop ax
  126.         add cx, 50
  127.         dec bx
  128.         jnz n_vlines      
  129.         ret
  130.     vLine endp
  131.    
  132.    
  133.    
  134. ;*****************************************************************
  135. ; createMatrix -
  136. ; descricao: creates horizontal lines for the matrix
  137. ; input - bx= numero de linhas ; cx = horizontal margin ; dx = vertical margin ; ax = line lenght
  138. ; output -
  139. ; destroi -
  140. ;*****************************************************************        
  141.  
  142.   createMatrix proc
  143.     mov bx, 05h ; se calhar temos de remover isto
  144.     mov dx, 23
  145.     mov cx, 23
  146.     mov ax, matrix_lenght
  147.     call hLine
  148.    
  149.     mov bx, 05h
  150.     mov cx, 23
  151.     mov dx, 23
  152.     mov ax, matrix_height
  153.     call vLine
  154.    
  155.     ret
  156.  
  157.   createMatrix endp
  158.  
  159. ;*****************************************************************
  160. ; createMatrix -
  161. ; descricao: creates horizontal lines for the matrix
  162. ; input - bx= numero de linhas ; cx = horizontal margin ; dx = vertical margin ; ax = line lenght
  163. ; output -
  164. ; destroi -
  165. ;*****************************************************************        
  166.  
  167.  
  168.   createMenuBox proc
  169.    
  170.     mov bx, 2
  171.     mov ax, 50
  172.     mov cx, 23
  173.     mov dx, 164
  174.     call hLine
  175.    
  176.     mov bx, 2
  177.     mov ax, 16
  178.     mov cx, 23
  179.     mov dx, 164                              
  180.     call vLine
  181.    
  182.     ;writes "Menu" inside the cell
  183.         mov al, 1
  184.         mov bl, 0Fh
  185.         mov cx, 5    ;string lenght
  186.         mov dh, 21
  187.         mov dl, 4
  188.         mov ah, 13h
  189.         mov bp, offset string_menu
  190.         int 10h
  191.  
  192.   ret
  193.    
  194.   createMenuBox endp
  195.    
  196. ;*****************************************************************
  197. ; createFormulaBox -
  198. ; descricao: creates a box where the user will input operations
  199. ; input -
  200. ; output -
  201. ; destroi -
  202. ;*****************************************************************
  203.  
  204.     createFormulaBox proc ;Provavelmente vamos ter de alterar o
  205.                           ;tamanho da caixa da formula
  206.            
  207.         mov ax, 120 ; formula lenght
  208.         mov cx, 23
  209.         mov dx, 140
  210.         mov bx, 02h
  211.         call hLine
  212.        
  213.         mov ax, 16 ; formula height
  214.         mov cx, 23
  215.         mov dx, 140
  216.         mov bx, 01h
  217.         call vLine
  218.        
  219.         mov ax, 16 ; formula height
  220.         mov cx, 143
  221.         mov dx, 140
  222.         mov bx, 01h
  223.         call vLine
  224.        
  225.     ret    
  226.        
  227.     createFormulaBox endp
  228.    
  229.  
  230. ;*****************************************************************
  231. ; createResultBox -
  232. ; descricao: creates a box to output the result
  233. ; input -
  234. ; output -
  235. ; destroi -
  236. ;*****************************************************************
  237.  
  238.     createResultBox proc
  239.        
  240.         mov ax, 60 ;cell lenght
  241.         mov cx, 200
  242.         mov dx, 140
  243.         mov bx, 02h
  244.         call hLine
  245.        
  246.         mov ax, 16 ; formula height
  247.         mov cx, 200
  248.         mov dx, 140
  249.         mov bx, 01h
  250.         call vLine
  251.        
  252.         mov ax, 16 ; formula height
  253.         mov cx, 260
  254.         mov dx, 140
  255.         mov bx, 01h
  256.         call vLine
  257.    
  258.     ret
  259.        
  260.     createResultBox endp
  261.    
  262. ;*****************************************************************
  263. ; showLetter -
  264. ; descricao: prints a letter for each matrix collumn,
  265. ;            also prints "Formula" and "Result"
  266. ; input -
  267. ; output -
  268. ; destroi -
  269. ;*****************************************************************
  270.  
  271.     showLetters proc
  272.        
  273.         xor bh, bh
  274.         mov bl, 0Fh
  275.         mov cx, 1
  276.         mov dl, 06
  277.         mov al, 'A'
  278.        
  279.         new_letter:
  280.             ;set cursor position
  281.             mov dh, 01h
  282.             mov ah, 02h
  283.             int 10h
  284.            
  285.             ;write char at cursor position
  286.             mov ah, 09h
  287.             int 10h
  288.            
  289.             inc al
  290.             add dl, 6
  291.             cmp al, 'E'
  292.             jnz new_letter
  293.        
  294.         ;writes "Formula" above the big cell
  295.         mov al, 1
  296.         mov bl, 0Fh
  297.         mov cx, 8    ;string lenght
  298.         mov dh, 16
  299.         mov dl, 3
  300.         mov ah, 13h
  301.         mov bp, offset string_formula
  302.         int 10h
  303.        
  304.         ;writes "Result" aove the small cell
  305.         mov dl, 25
  306.         mov cx, 7   ;string lenght
  307.         mov bp, offset string_result    
  308.         int 10h  
  309.    
  310.     ret
  311.        
  312.     showLetters endp
  313.    
  314. ;*****************************************************************
  315. ; showNumbers -
  316. ; descricao: prints a number for each matrix row
  317. ; input -
  318. ; output -
  319. ; destroi -
  320. ;*****************************************************************    
  321.  
  322.     showNumbers proc
  323.                    
  324.         xor bh, bh
  325.         mov bl, 0Fh
  326.         mov cx, 1
  327.         mov dh, 03h
  328.         mov al, '1'
  329.        
  330.         new_number:
  331.         ;set cursor position
  332.         mov dl, 01h
  333.         mov ah, 02h
  334.         int 10h
  335.        
  336.         ;write char at cursor position
  337.         mov ah, 09h
  338.         int 10h
  339.        
  340.         inc al
  341.         add dh, 2
  342.         cmp al, '5'
  343.         jnz new_number                    
  344.    
  345.     ret
  346.        
  347.     showNumbers endp    
  348.  
  349. ;*****************************************************************
  350. ; fopen -
  351. ; descricao: abre um ficheiro em modo read(al==0), write(al==1) ou append(al==2)
  352. ; input - dx=offset nome ficheiro
  353. ; output - ax=file_handle
  354. ; destroi -
  355. ;*****************************************************************    
  356.  
  357.     fopen proc
  358.         mov ah, 3Dh
  359.         mov al, 02h
  360.         mov cx, 00h
  361.         int 21h      
  362.        
  363.         ret
  364.     fopen endp
  365.  
  366. ;*****************************************************************
  367. ; fclose -
  368. ; descricao:
  369. ; input - bx= file handle
  370. ; output -
  371. ; destroi -
  372. ;*****************************************************************    
  373.  
  374.     fclose proc
  375.         mov ah, 3Eh
  376.         int 21h      
  377.        
  378.         ret
  379.     fclose endp
  380.    
  381. ;*****************************************************************
  382. ; fcreate -
  383. ; descricao: cria um ficheiro
  384. ; input - dx=offset nome ficheiro
  385. ; output - ax=file_handle
  386. ; destroi -
  387. ;*****************************************************************        
  388.  
  389.     fcreate proc
  390.         mov ah, 3Ch
  391.         mov cx, 00h
  392.         int 21h      
  393.  
  394.         ret    
  395.     fcreate endp
  396.    
  397. ;*****************************************************************
  398. ; save_contents -
  399. ; descricao: saves contents.bin or creates it
  400. ; input -
  401. ; output -
  402. ; destroi -
  403. ;*****************************************************************    
  404.  
  405.     save_contents proc
  406.         ;tries to open file
  407.         mov dx, offset name_contents
  408.         call fopen
  409.         jnc save
  410.        
  411.         ;in case it doesn't exist, creates it
  412.         call fcreate
  413.        
  414.         save:
  415.         mov bx, ax ;move handle
  416.        
  417.         mov cx, 0 ;number of bytes
  418.         mov dx, 0 ;offset to write to
  419.         mov ah, 40h
  420.         int 21h
  421.                    
  422.         ;closes file                  
  423.         call fclose
  424.        
  425.         ret
  426.     save_contents endp
  427.  
  428. ;*****************************************************************
  429. ; open_contents -
  430. ; descricao: opens contents.bin if it exists
  431. ; input -
  432. ; output -
  433. ; destroi -
  434. ;*****************************************************************    
  435.    
  436.     open_contents proc
  437.         ;tries to open file
  438.         mov dx, offset name_contents
  439.         call fopen
  440.         jc end_open_cont ;in case it doesn't exist yet
  441.        
  442.         mov bx, ax
  443.        
  444.         mov cx, 0 ;number of bytes
  445.         mov dx, 0 ;offset to write to
  446.         mov ah, 3Fh  
  447.        
  448.         call fclose
  449.         end_open_cont:
  450.         ret
  451.     open_contents endp
  452.    
  453. ends
  454.  
  455. end start ; set entry point and stop the assembler.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement