Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; multi-segment executable file template.
- data segment
- name_contents db "c:\contents.bin", 0
- handler dw 0
- string_menu_1 db "- Import Spreadsheet" ;length=20
- string_menu_2 db "- Show spreadsheet" ;length=18
- string_menu_3 db "- Edit spreadsheet" ;length=18
- string_menu_4 db "- Export spreadsheet" ;length=20
- string_menu_5 db "- About" ;length=7
- string_menu_6 db "- Exit" ;length=6
- string_formula db "Formula"
- string_result db "Result"
- string_menu db "Menu"
- string_filename db "Filename"
- string_error db "ERROR FILE UNEXISTENT"
- string_remainder db ";R:"
- string_about_1 db "Programa feito por:" ;length=19
- string_about_2 db "Francisco Peres N: 50034";length=25
- string_about_3 db "Joao Ferreira N: 50608" ;length=23
- str_buffer db 6 dup(0)
- str_buffer2 db 7 dup(0)
- str_buffer_result db 6 dup(0)
- remainder dw 00h
- num_hcell dw 04h
- matrix_lenght dw 160 ;estava 240 antes
- matrix_height dw 65
- column_number db 'A','1',':','0',';',"FOR:" ;buffer para export e import
- cell db 16 dup(-128) ;format A1, A2, A3, A4, B1, etc
- formula_var db 3 dup(-1) ;formato (ctre 1 e 16 de seguimento A1=0, A2=1, etc)
- ;coluna_var: cell_1; operation; cell_2. coluna//linha. operacao=0 formula vazia
- name_file db "c:\", ?
- ends
- stack segment
- dw 128 dup(0)
- ends
- code segment
- start:
- ; set segment registers:
- mov ax, data
- mov ds, ax
- mov es, ax
- ;open contents.bin
- call open_contents
- draw_menu:
- call reiniciateVideo
- call menu
- nothing_clicked:
- call keepCheckingMouse
- call checkMenu
- cmp dh, 02h
- je nothing_clicked
- cmp dh, 01h
- jne draw_menu
- ;saves contents.bin
- call save_contents
- mov ax, 4c00h ; exit to operating system.
- int 21h
- ;*****************************************************************
- ; menu -
- ; descricao: prints menu
- ; input - no input needed
- ; output - nothing
- ; destroi - ax, bx, cx, dx
- ;*****************************************************************
- menu proc
- mov al, 01h
- mov bx, 0Fh
- mov dx, 02h
- mov cx, 14h;length of string_1
- mov bp, offset string_menu_1
- imprime_string:
- inc dh
- inc dh ;goes to next line
- push bx ;bh is used as an index of how many strings
- ;have been printed so it must be pushed before
- xor bh, bh ;printing a string due to the int's parametres
- mov ah, 13h
- int 10h ;prints string
- pop bx
- inc bh ;next string
- cmp bh, 02h
- je menu_2
- cmp bh, 03h
- je menu_3
- cmp bh, 04h
- je menu_4
- cmp bh, 05h
- je menu_5
- ja end_of_menu
- mov cx, 12h
- mov bp, offset string_menu_2
- jmp imprime_string
- menu_2:
- mov bp, offset string_menu_3
- jmp imprime_string
- menu_3:
- mov cx, 14h
- mov bp, offset string_menu_4
- jmp imprime_string
- menu_4:
- mov cx, 07h
- mov bp, offset string_menu_5
- jmp imprime_string
- menu_5:
- mov cx, 06h
- mov bp, offset string_menu_6
- jmp imprime_string
- end_of_menu:
- ret
- menu endp
- ;*****************************************************************
- ; checkMenu -
- ; descricao: checks position clicked on menu window
- ; input - no input needed
- ; output - nothing
- ; destroi - cx, dx
- ;*****************************************************************
- checkMenu proc
- xor dh, dh
- ;checks if program is clicked anywhere outside the area of the printed strings
- cmp cx, 13h ;left limit x
- jb exit_checking_menu
- cmp cx, 178 ;right limit x
- ja exit_checking_menu
- cmp dx, 12h ;superior limit y
- jb exit_checking_menu
- cmp dx, 6Ch ;inferior limit y
- ja exit_checking_menu
- ;then tests to see if the click is between the superior limit (y)
- cmp dx, 1Bh ;and another y value, both delimitating the first string
- ja test_show
- call import_spreadsheet
- jmp done_checking_menu
- ;if it's not there then it tests to see if it's between the superior limit
- test_show: ;and an y value, delimitating the first two strings
- cmp dx, 2Bh
- ja test_edit
- call show_spreadsheet
- jmp done_checking_menu
- test_edit:
- cmp dx, 3Bh
- ja test_export
- call edit_spreadsheet
- jmp done_checking_menu
- test_export:
- cmp dx, 4Bh
- ja test_about
- call export_spreadsheet
- jmp done_checking_menu
- test_about:
- cmp dx, 5Bh
- ja test_mmenu
- call show_about
- jmp done_checking_menu
- test_mmenu:
- cmp dx, 6Bh
- ja exit_checking_menu
- jmp definitely_exit:
- exit_checking_menu:
- mov dh, 02h
- jmp done_checking_menu
- definitely_exit:
- mov dh, 01h
- done_checking_menu:
- ret
- checkMenu endp
- ;*****************************************************************
- ; import_spreadsheet -
- ; descricao: imports a file with the extension .txt
- ; input - no input needed
- ; output - dh=02h if file non-existent
- ; destroi - ax, dx, cx, dx, bp, di
- ;*****************************************************************
- import_spreadsheet proc
- call importExportFilename ;gets filename which stays in string pointed by bp
- call fopen ;tries to open file
- jc file_unexistent
- mov handler, ax
- mov dx, offset column_number ;this vector is used for both temporary values and
- add dx, 03h ;reading from file point to temporary position in vector
- import_next_column:
- mov di, offset cell
- mov ah, 3Fh ;get next column char (or F (OR) if all columsn have been read)
- mov bx, handler
- mov cx, 01h
- int 21h
- mov bx, dx ;copies the address of temporary position to bx
- ;so it can be directly referenced
- cmp ax, 00h ;if at EOF jumps to end, should not be needed
- je end_of_import
- ;checks what character was read
- cmp [bx], 'A'
- je import_number
- add di, 04h ;the first 4 values from vector cell belong to column A
- ;so by adding to di 4 we are now referencing column B
- cmp [bx], 'B'
- je import_number
- add di, 04h
- cmp [bx], 'C'
- je import_number
- add di, 04h
- cmp [bx], 'D'
- je import_number
- ;if it's none of the columns, we've finished reading all the columns
- ;and are now reading the formula
- ;formula start
- mov di, offset formula_var
- mov cx, 01h
- eat_for: ;reads until ':' is found
- mov ah, 3Fh
- mov bx, handler
- int 21h
- mov bx, dx
- cmp [bx], ':'
- jne eat_for
- next_formula_var_0: ;reads character belonging to column
- push cx
- mov ah, 3Fh
- mov bx, handler
- mov cx, 01h
- int 21h
- mov [di], 00h
- cmp ax, 00h ;if formula has no value
- jne not_eof
- pop cx
- mov [di+1], -1
- jmp end_of_import
- not_eof:
- mov bx, dx
- cmp [bx], 'B'
- jb next_formula_var_1 ;if it's 'A'
- pushf
- add [di], 04h
- popf
- je next_formula_var_1 ;if it's 'B'
- cmp [bx], 'C'
- pushf
- add [di], 04h
- popf
- je next_formula_var_1 ;if it's 'C'
- add [di], 08h ;if it's 'D'
- next_formula_var_1: ;reads character belonging to line
- mov ah, 3Fh
- mov bx, handler
- int 21h
- pop cx
- mov bx, dx
- cmp [bx], '2'
- jb next_formula_var_2
- pushf
- inc [di]
- popf
- je next_formula_var_2
- cmp [bx], '3'
- pushf
- inc [di]
- popf
- je next_formula_var_2
- inc [di]
- next_formula_var_2: ;if ch=1 it means we've already read the column and number twice
- cmp ch, 01h
- je end_of_import
- inc di ;reads operation sign
- mov ah, 3Fh
- mov bx, handler
- int 21h
- mov bx, dx
- inc ch
- mov ah, [bx] ;puts operation sign in var
- mov [di], ah
- inc di
- jmp next_formula_var_0
- ;formula
- import_number: ;we know the column now we read the line
- mov ah, 3Fh
- mov bx, handler
- int 21h ;read the character of the line
- mov bx, dx
- xor al, al
- ;alike what we did with the column we compare the character
- cmp [bx], '1' ;and the di is set to increase accordingly
- je pre_import_next_number
- cmp [bx], '2'
- jne import_number_3
- inc di
- jmp pre_import_next_number
- import_number_3:
- cmp [bx], '3'
- jne import_number_4
- add di, 02h
- jmp pre_import_next_number
- import_number_4:
- add di, 03h
- pre_import_next_number: ;reads the character ':'
- mov [di], 00h ;resets value in cell
- mov ah, 3Fh
- mov bx, handler
- int 21h
- import_next_number: ;reads the actual ascii characters belonging to the number
- push ax ;and converts them to decimal
- push cx ;al tells us if number is negative or not and cx
- mov ah, 3Fh
- mov bx, handler
- mov cx, 01h
- int 21h ;reads a character
- mov bx, dx
- pop cx
- pop ax
- cmp [bx], ';' ;if all characters of the number have been read
- je pre_import_next_column
- cmp [bx], '-' ;if number is negative
- je import_num_negative
- mov bl, [bx] ;puts the character read in bl
- cmp cx, 01h ;cx=1 on the first ascii number
- je import_tens
- push ax
- sub bl, '0' ;converts ascii character to decimal
- mov ax, [di]
- push dx
- mul cx ;it will multiply the value either by 10
- add bl, al ;depending if it's the first or third character
- pop dx ;adds calculated value to value in cell
- mov [di], bl
- pop ax
- jmp import_next_number
- import_tens: ;if it's the first character read
- sub bl, '0' ;converts it
- mov [di], bl ;then puts value in cell
- mov cx, 0Ah ;
- jmp import_next_number
- import_num_negative: ;if it's negative we put -1 in al
- mov al, -1
- jmp import_next_number
- pre_import_next_column: ;if number read is negative
- cmp al, -1 ;converts it before going to the next number
- jne import_next_column
- neg [di]
- jmp import_next_column
- file_unexistent: ;prints error in case file does not exist
- mov ax, 1301h
- mov bx, 000Fh
- mov cx, 0015h
- mov dx, 1003h
- mov bp, offset string_error
- int 10h
- mov dh, 02h ;due to the way the menu works this will make it so
- jmp end_for_file_unexistent ;the menu isn't redrawn and the error keeps on screen
- end_of_import:
- call fclose
- end_for_file_unexistent:
- ret
- import_spreadsheet endp
- ;*****************************************************************
- ; show_spreadsheet -
- ; descricao: shows the spreadsheet on memory
- ; input -
- ; output -
- ; destroi -
- ;*****************************************************************
- show_spreadsheet proc
- call reiniciateVideo
- call createMatrix
- call createMenuBox
- call createFormulaBox
- call createResultBox
- call showLetters
- call showNumbers
- call loadValues
- mov ax, 00h ;initialize mouse
- int 33h
- keep_checking_show:
- call keepCheckingMouse
- call checkMenuClicked
- cmp bx, 255
- jne keep_checking_show
- ret
- show_spreadsheet endp
- ;*****************************************************************
- ; edit_spreadsheet -
- ; descricao: shows and allows the user to edit the spreadsheet
- ; input -
- ; output -
- ; destroi -
- ;*****************************************************************
- edit_spreadsheet proc
- call reiniciateVideo
- call createMatrix
- call createMenuBox
- call createFormulaBox
- call createResultBox
- call showLetters
- call showNumbers
- call loadValues
- mov ax, 00h ;initialize mouse
- int 33h
- ;wait for user input
- keep_checking_edit:
- call keepCheckingMouse
- call cANDeCell ;check and evaluate cell
- cmp bx, 255 ;exit to MENU
- jne keep_checking_edit
- ret
- edit_spreadsheet endp
- ;*****************************************************************
- ; export_spreadsheet -
- ; descricao: exports a file with the extension .txt the spreadsheet in the memory
- ; input - no input needed
- ; output -
- ; destroi - ax, dx, cx, dx, bp, di
- ;*****************************************************************
- export_spreadsheet proc
- call importExportFilename
- call fcreate
- write_export:
- mov handler, ax
- xor ax, ax
- mov dx, offset column_number ;this vector is used for both temporary values and
- mov bx, dx ;reading from file point to temporary position in vector
- mov di, offset cell
- dec di ;compensates first increment
- mov [bx], 'A' ;resets the first two variables in the vector
- mov [bx+1], '1'
- next_cell: ;di is incremented to point to the next cell to write
- inc di
- mov al, [di]
- cmp al, -128 ;if the value=/= -128 then it writes the cell info
- jne write_cell_info
- test_next_cell: ;if we're not at [column/'4'] then
- cmp [bx+1], '4'
- je export_form_resu
- inc [bx+1] ;we increment it and test the next cell
- jmp next_cell
- export_form_resu: ;if we're at [column/'4'] then
- mov [bx+1], '1' ;we increment the column and put line='0'
- inc [bx] ;and test to see if we've read all the columns
- cmp [bx], 'E' ;by checking if column='E'
- jne next_cell
- ;FORMULA
- add dx, 05h ;writes in file "FOR:"
- mov cx, 04h
- mov bx, handler
- mov ah, 40h
- int 21h
- mov di, offset formula_var
- dec dx
- dec dx
- cmp [di+1], -1 ;if formula is empty don't write anything
- jne next_formula_var_ex_0
- jmp end_of_export
- next_formula_var_ex_0: ;divides the cell in formula by 4
- mov al, [di]
- push dx
- xor dx, dx
- mov cl, 04h
- div cl
- pop dx
- mov bx, dx
- push ax
- cmp al, 01h ;depending on the result we know the column
- jb next_formula_var_ex_1
- je next_formula_var_ex_2
- cmp al, 02h
- je next_formula_var_ex_3
- mov [bx], 'D'
- jmp next_formula_var_ex_4
- next_formula_var_ex_1:
- mov [bx], 'A'
- jmp next_formula_var_ex_4
- next_formula_var_ex_2:
- mov [bx], 'B'
- jmp next_formula_var_ex_4
- next_formula_var_ex_3:
- mov [bx], 'C'
- next_formula_var_ex_4: ;writes column
- push cx
- mov ah, 40h
- mov bx, handler
- mov cx, 01h
- int 21h
- pop cx
- mov bx, dx
- pop ax
- cmp ah, 01h ;depending on the remainder we know the line
- jb next_formula_var_ex_5
- je next_formula_var_ex_6
- cmp ah, 02h
- je next_formula_var_ex_7
- mov [bx], '4'
- jmp next_formula_var_ex_8
- next_formula_var_ex_5:
- mov [bx], '1'
- jmp next_formula_var_ex_8
- next_formula_var_ex_6:
- mov [bx], '2'
- jmp next_formula_var_ex_8
- next_formula_var_ex_7:
- mov [bx], '3'
- next_formula_var_ex_8: ;writes line
- push cx
- xor ch, ch
- mov bx, handler
- mov cl, 01h
- mov ah, 40h
- int 21h
- pop cx
- cmp ch, 01h ;if the both cells info as been written
- je end_of_export
- inc di ;writes operand
- mov bx, dx
- mov ah, [di]
- mov [bx], ah
- mov ah, 40h
- mov bx, handler
- mov cl, 01h
- int 21h
- inc di
- inc ch ;too make sure we jump to the end after writing
- jmp next_formula_var_ex_0 ;the second cell's info
- ;formula end
- write_cell_info: ;writes the first 3 characters of column_number [column, line, ':']
- push ax
- push bx
- mov ah, 40h
- mov bx, handler
- mov cx, 03h
- int 21h
- pop bx
- pop ax
- mov cx, 0Ah
- cmp al, 1000_0000b ;checks if cell value is negative
- jb test_tens
- mov [bx+3], '-' ;writes '-' in the file
- push bx
- mov bx, handler
- add dx, 03h
- mov cx, 01h
- push ax
- mov ah, 40h
- int 21h
- pop ax
- pop bx ;turns the negative value into a positive value so it's
- neg al ;processed like a positive number
- xor ah, ah
- mov cx, 0Ah
- test_tens: ;checks if number is <10
- cmp al, 0Ah
- jae test_hundreds
- add al, '0' ;if number is <10, it's converted from decimal to ascii
- mov [bx+3], al ;put on the vector and then written in the file
- push bx
- mov dx, bx
- mov bx, handler
- mov ah, 40h
- mov cx, 01h
- add dx, 03h
- int 21h
- jmp pre_next_cell
- test_hundreds: ;checks if number is <100
- xor dx, dx
- cmp al, 64h
- jae hundreds
- div cx ;if number is <100, it is divided by 10
- mov dx, bx ;the result (al) is converted and written
- add al, '0'
- mov [bx+3], al
- mov al, ah
- push ax
- push bx
- mov bx, handler
- mov ah, 40h
- mov cx, 01h
- add dx, 03h
- int 21h
- pop bx ;the remainder (previously ah) is converted and written
- pop ax
- add al, '0'
- mov [bx+3], al
- push bx
- mov bx, handler
- mov ah, 40h
- int 21h
- jmp pre_next_cell
- hundreds: ;if number is >100
- div cx ;it is divided by 10 twice and the remainder put in the stack
- push dx
- xor dx, dx
- div cx
- push dx
- mov dx, bx
- add al, '0' ;the result, as before, is written in the file
- mov [bx+3], al
- push bx
- mov bx, handler
- add dx, 03h
- mov cx, 01h
- mov ah, 40h
- int 21h
- pop bx ;then like before the remainder is poped from the stack
- pop ax ;and written in the file twice
- add al, '0'
- mov [bx+3], al
- push bx
- mov bx, handler
- mov ah, 40h
- int 21h
- pop bx
- pop ax
- add al, '0'
- mov [bx+3], al
- push bx
- mov bx, handler
- mov ah, 40h
- int 21h
- pre_next_cell: ;writes ';'
- inc dx
- mov ah, 40h
- int 21h
- pop bx
- sub dx, 4
- jmp test_next_cell
- end_of_export:
- mov bx, handler
- call fclose
- ret
- export_spreadsheet endp
- ;*****************************************************************
- ; show_about -
- ; descricao: displays information about the creaters
- ; input -
- ; output -
- ; destroi -
- ;*****************************************************************
- show_about proc
- call reiniciateVideo
- mov dh, 01h
- mov al, 01h
- mov bh, 00h
- mov bl, 0Fh
- mov dl, 04h
- mov cx, 13h ;length of string_1
- mov bp, offset string_about_1
- imprime_string_about:
- inc dh
- inc dh ;next line
- push bx
- xor bh, bh
- mov ah, 13h
- int 10h
- pop bx
- inc bh ;next string
- cmp bh, 02h
- je about_3
- ja end_of_writing_about
- mov cx, 19h
- mov bp, offset string_about_2
- jmp imprime_string_about
- about_3:
- mov cx, 17h
- mov bp, offset string_about_3
- jmp imprime_string_about
- end_of_writing_about:
- call createMenuBox
- keep_checking_about:
- xor ax, ax
- int 16h
- cmp al, 0Dh ;check if ENTER was pressed
- je about_done
- cmp al, 1Bh ;check if ESC was pressed
- jne keep_checking_about
- about_done:
- ret
- show_about endp
- ;*****************************************************************
- ; hLine -
- ; descricao: creates horizontal lines for the matrix
- ; input - bx= number of lines ; cx = horizontal margin ; dx = vertical margin ; ax = line lenght
- ; output -
- ; destroi -
- ;*****************************************************************
- hLine proc
- n_hlines:
- push ax
- push cx
- h_change_pixel:
- push ax
- mov ah, 0Ch
- mov al, 0Fh
- int 10h
- pop ax
- dec ax
- jz h_done
- inc cx
- jmp h_change_pixel
- h_done:
- pop cx
- pop ax
- add dx, 16
- dec bx
- jnz n_hlines
- ret
- hLine endp
- ;*****************************************************************
- ; vLine -
- ; descricao: creates vertical lines for the matrix
- ; input - bx= number of lines ; cx = horizontal margin ; dx = vertical margin ; ax = matrix_height
- ; output -
- ; destroi -
- ;*****************************************************************
- vLine proc
- n_vlines:
- push ax
- push dx
- v_change_pixel:
- push ax
- mov ah, 0Ch
- mov al, 0Fh
- int 10h
- pop ax
- dec ax
- jz v_done
- inc dx
- jmp v_change_pixel
- v_done:
- pop dx
- pop ax
- add cx, 40
- dec bx
- jnz n_vlines
- ret
- vLine endp
- ;*****************************************************************
- ; createMatrix -
- ; descricao: creates horizontal lines for the matrix
- ; input - bx= number of lines ; cx = horizontal margin ; dx = vertical margin ; ax = line lenght
- ; output -
- ; destroi -
- ;*****************************************************************
- createMatrix proc
- mov bx, 05h ; se calhar temos de remover isto
- mov dx, 28
- mov cx, 20
- mov ax, 160 ;Matrix Lenght
- call hLine
- mov bx, 05h
- mov cx, 20
- mov dx, 28
- mov ax, 65 ;Matrix Height
- call vLine
- ret
- createMatrix endp
- ;*****************************************************************
- ; createMatrix -
- ; descricao: creates horizontal lines for the matrix
- ; input - bx= number of lines ; cx = horizontal margin ; dx = vertical margin ; ax = line lenght
- ; output -
- ; destroi -
- ;*****************************************************************
- createMenuBox proc
- mov bx, 2
- mov ax, 40
- mov cx, 20
- mov dx, 156
- call hLine
- mov bx, 2
- mov ax, 17
- mov cx, 20
- mov dx, 156
- call vLine
- ;writes "Menu" inside the cell
- mov al, 1
- mov bl, 0Fh
- mov cx, 4 ;string lenght
- mov dh, 20
- mov dl, 3
- mov ah, 13h
- mov bp, offset string_menu
- int 10h
- ret
- createMenuBox endp
- ;*****************************************************************
- ; createFormulaBox -
- ; descricao: creates a box where the user will input operations
- ; input -
- ; output -
- ; destroi - ax, bx, cx, dx
- ;*****************************************************************
- createFormulaBox proc ;Provavelmente vamos ter de alterar o
- ;tamanho da caixa da formula
- mov ax, 80 ; formula lenght
- mov cx, 20
- mov dx, 124
- mov bx, 02h
- call hLine
- mov ax, 17 ; formula height + 1
- mov cx, 20
- mov dx, 124
- mov bx, 01h
- call vLine
- mov ax, 17 ; formula height + 1
- mov cx, 100
- mov dx, 124
- mov bx, 01h
- call vLine
- ret
- createFormulaBox endp
- ;*****************************************************************
- ; createResultBox -
- ; descricao: creates a box to output the result
- ; input -
- ; output -
- ; destroi - ax, bx, cx, dx
- ;*****************************************************************
- createResultBox proc
- mov ax, 80 ;cell lenght
- mov cx, 140
- mov dx, 124
- mov bx, 02h
- call hLine
- mov ax, 17 ; formula height + 1
- mov cx, 140
- mov dx, 124
- mov bx, 01h
- call vLine
- mov ax, 17 ; formula height + 1
- mov cx, 220
- mov dx, 124
- mov bx, 01h
- call vLine
- ret
- createResultBox endp
- ;*****************************************************************
- ; showLetter -
- ; descricao: prints a letter for each matrix collumn,
- ; also prints "Formula" and "Result"
- ; input -
- ; output -
- ; destroi - ax, bx, cx, dx
- ;*****************************************************************
- showLetters proc
- xor bh, bh
- mov bl, 0Fh
- mov cx, 1
- mov dl, 04
- mov al, 'A'
- new_letter:
- ;set cursor position
- mov dh, 02h
- mov ah, 02h
- int 10h
- ;write char at cursor position
- mov ah, 09h
- int 10h
- inc al
- add dl, 5
- cmp al, 'E'
- jnz new_letter
- ;writes "Formula" above the big cell
- mov al, 1
- mov bl, 0Fh
- mov cx, 7 ;string lenght
- mov dh, 14
- mov dl, 3
- mov ah, 13h
- mov bp, offset string_formula
- int 10h
- ;writes "Result" aove the small cell
- mov dl, 18
- mov cx, 6 ;string lenght deve ser 6
- mov bp, offset string_result
- int 10h
- ret
- showLetters endp
- ;*****************************************************************
- ; showNumbers -
- ; descricao: prints a number for each matrix row
- ; input -
- ; output -
- ; destroi - ax, bx, cx, dx
- ;*****************************************************************
- showNumbers proc
- xor bh, bh
- mov bl, 0Fh
- mov cx, 1
- mov dh, 04h
- mov al, '1'
- new_number:
- ;set cursor position
- mov dl, 01h
- mov ah, 02h
- int 10h
- ;write char at cursor position
- mov ah, 09h
- int 10h
- inc al
- add dh, 2
- cmp al, '5'
- jnz new_number
- ret
- showNumbers endp
- ;*****************************************************************
- ; loadValues -
- ; descricao: prints cells and formula from memory and calculates result and prints it
- ; input - no input needed
- ; output - none
- ; destroi - ax, bx, cx, dx, di, bp
- ;*****************************************************************
- loadValues proc
- mov bp, offset str_buffer_result
- mov di, offset cell
- mov dx, 0403h ;initial cell position
- loadNextNum:
- cmp [di], -128 ;if cell has value -128 it tests the next cell
- je loadNextCell
- mov al, [di]
- xor ah, ah
- cmp al, 00h ;if cell is negative we convert a
- jge signedBitAx ;8bit negative into a 16bit negative
- mov ah, 1111_1111b
- signedBitAx:
- push dx
- push di
- call decimalToASCII ;returns the decimal value in ascii value in a string
- pop di ;pointed to by bp
- pop dx
- mov ax, 1301h ;prints string with value
- mov bx, 0Fh
- int 10h
- loadNextCell: ;loads next value by incrementing the pointer to the
- inc di ;next cell and updates the cell position
- add dh, 02h
- cmp dh, 0Ch
- jne loadNextNum
- add dl, 05h ;next column
- mov dh, 04h
- cmp dl, 17h
- jne loadNextNum
- ;formula start
- mov di, offset formula_var
- mov bx, bp
- cmp [di+1], -1 ;checks if there's a formula loaded
- je end_loading
- xor cx, cx
- load_next_form_value:
- mov [bx], 'A' ;the 'A' is put as an initial value
- inc cx ;and incremented acording to the column on memory
- mov dl, [di]
- cmp dl, 03h
- ja notA
- jmp load_next_form_value_0
- notA:
- inc [bx]
- cmp dl, 07h
- ja notB
- sub dl, 04h
- jmp load_next_form_value_0
- notB:
- inc [bx]
- cmp dl, 0Bh
- jb load_next_form_value_0
- sub dl, 08h
- inc [bx]
- sub dl, 0Ch
- load_next_form_value_0: ;does the same thing as before but for the line
- inc bx
- mov [bx], '1'
- cmp dl, 01h
- ja not2
- jmp load_next_form_value_1
- not2:
- inc [bx]
- cmp dl, 02h
- jb load_next_form_value_1
- not3:
- inc [bx]
- cmp dl, 03h
- jb load_next_form_value_1
- inc [bx]
- load_next_form_value_1:
- inc bx
- cmp cx, 02h ;checks if both cells have been checked
- je end_loading_form
- mov al, [di+1] ;puts operand in string
- mov [bx], al
- inc bx
- add di, 02h
- jmp load_next_form_value
- end_loading_form: ;prints formula
- mov ax, 1301h
- mov bx, 0Fh
- mov cx, 05h
- mov dx, 1003h
- int 10h ;formula end
- mov al, [di-2] ;prepares ah, bh, ch for calculate
- xor ah, ah
- mov bl, [di]
- xor bh, bh
- mov cl, [di-1]
- xor ch, ch
- call calculate
- mov ax, dx
- call writeNumber ;prints result
- end_loading:
- ret
- loadValues endp
- ;*****************************************************************
- ; checkCell - Check and Evaluate Cell
- ; descricao: checks and eveluates what to do with the cell clicked by the user
- ; input - cx;dx = mouse coordenates
- ; output -
- ; destroi -
- ;*****************************************************************
- cANDeCell proc
- ;check if user clicked on the margin
- cmp cx, 20
- jb done_checking
- cmp dx, 28
- jb done_checking
- call checkMenuClicked
- cmp bx, 255
- je done_checking
- ;check if user clicked on a matrix cell
- cmp cx, 3
- ja not_matrix
- cmp dx, 3
- ja not_matrix
- call matrixCellClicked ;the cell clicked is described by its coordenates (cx and dx)
- jmp done_checking
- ;check if user clicked on the formula or result cell
- not_matrix:
- cmp dx, 6
- jnz done_checking ;not formula
- cmp cx, 1
- ja done_checking ;not formula
- call formulaCellClicked
- jmp done_checking
- done_checking:
- ret
- cANDeCell endp
- ;*****************************************************************
- ; checkMenuClicked -
- ; descricao: check if user clicked on MENU
- ; input -
- ; output - bx=0(exit to menu)
- ; destroi -
- ;*****************************************************************
- checkMenuClicked proc
- ;check if user clicked on the margin
- cmp cx, 20
- jb donechecking_menu
- cmp dx, 28
- jb donechecking_menu
- mov ax, cx
- sub ax, 20
- mov bx, 40
- div bl
- xor ah, ah ;sabemos agora a celula das letras
- mov cx, ax ;o resultado esta em cx
- mov ax, dx
- sub ax, 28
- mov bx, 16
- div bl
- xor ah, ah
- mov dx, ax ;coordonates are now stored in cx(x) and dx(y)
- cmp dx, 8 ;esta na linha do menu
- jnz donechecking_menu
- cmp cx, 0
- jnz donechecking_menu
- mov bx, 255
- donechecking_menu:
- ret
- checkMenuClicked endp
- ;*****************************************************************
- ; matrixCellClicked -
- ; descricao: performs operations to get and print the cell value
- ; it also re calculates the result
- ; input -
- ; output -
- ; destroi -
- ;*****************************************************************
- matrixCellClicked proc
- push cx
- push dx
- ;update cursor position and clear cell clicked
- call setCursorPOS
- call clearCell
- pop dx
- pop cx
- push cx
- push dx
- call setCursorPOS
- push dx
- call blinkingCursor
- call getCellValue
- pop dx
- call evaluateInput ;user input value gets stored in bx
- pop dx
- pop cx
- push cx
- push dx
- push bx
- xor bx, bx
- mov al, 4
- mul cl
- mov bl, al
- add bx, dx
- pop cx
- mov cell[bx], cl ;number is now in cl
- cmp cl, -128 ;check if it's a valid number
- pop dx
- pop cx
- jnz mCC_done
- call setCursorPOS
- mov al, ' '
- xor bh, bh
- mov cx, 4
- mov ah, 0Ah
- int 10h
- mCC_done: ;recalculates formula
- mov di, offset formula_var
- mov al, [di]
- inc di
- mov cl, [di]
- inc di
- mov bl, [di]
- xor ah, ah
- xor bh, bh
- xor ch, ch
- cmp cl, -1
- je evaluate_done
- call calculate
- cmp ax, -1
- je invalid_input3
- mov ax, dx
- call writeNumber
- jmp evaluate_done
- invalid_input3:
- call invalidInput
- evaluate_done:
- ret
- matrixCellClicked endp
- ;*****************************************************************
- ; getCellValue -
- ; descricao: read a number from the user (from -127 to 127)
- ; input -
- ; output - cell[cell number] = user input
- ; destroi - ax, bx, cx
- ;*****************************************************************
- getCellValue proc
- xor cx, cx ;contador
- ask_new_input:
- xor ax, ax
- int 16h
- cmp al, 8 ;check if char is backspace
- jnz not_backspace
- cmp cx, 0
- jz ask_new_input
- call writeSpace
- dec cx
- jmp ask_new_input
- not_backspace:
- cmp al, 13
- jnz not_enter
- jmp input_done
- not_enter:
- cmp al, '-'
- jnz not_minus
- cmp cx, 0
- jnz ask_new_input
- jmp accept_input
- not_minus:
- cmp al, '0'
- jb ask_new_input
- cmp al, '9'
- ja ask_new_input
- accept_input:
- mov bx, offset str_buffer
- inc bx
- inc bx
- add bx, cx
- mov [bx], al ;store char in "string" position
- ;write char al = char in ascii
- push ax
- push bx
- push cx
- mov bh, 0
- mov bx, 0Fh
- mov cx, 1
- mov ah, 09h
- int 10h
- pop cx
- pop bx
- pop ax
- ;done
- ;update cursor position dl,dh must already have previous mouse position
- push ax
- push bx
- inc dl
- xor bx, bx
- mov ah, 02h
- int 10h
- pop bx
- pop ax
- ;done
- sub bl, cl
- mov al, [bx]
- inc cx
- cmp al, '-'
- jnz positive_num
- cmp cx, 4
- jz input_done
- jmp ask_new_input
- positive_num:
- cmp cx, 3
- jnz ask_new_input
- input_done:
- mov bx, offset str_buffer
- inc bx
- mov [bx], cl
- ret
- getCellValue endp
- ;*****************************************************************
- ; writeSpace -
- ; descricao: writes a space at cursor position to erase a char
- ; input - dl;dx must have the cursor position
- ; output -
- ; destroi -
- ;*****************************************************************
- writeSpace proc
- push ax
- push bx
- push cx
- dec dl ;update cursor position
- xor bx, bx
- mov ah, 02h
- int 10h
- mov bh, 0 ;write space to "hide" the char
- mov bx, 0Fh
- mov cx, 1
- mov ah, 09h
- mov al, 32
- int 10h
- pop cx
- pop bx
- pop ax
- ret
- writeSpace endp
- ;*****************************************************************
- ; clearCell -
- ; descricao: erases the cell clicked
- ; input -
- ; output -
- ; destroi -
- ;*****************************************************************
- clearCell proc
- push ax
- push bx
- push cx
- mov al, ' '
- xor bh, bh
- mov cx, 4
- mov ah, 0Ah
- int 10h
- pop cx
- pop bx
- pop ax
- ret
- clearCell endp
- ;*****************************************************************
- ; setCursorPOS -
- ; descricao: updates cursor position
- ; input -
- ; output -
- ; destroi -
- ;*****************************************************************
- setCursorPOS proc
- push ax
- push bx
- mov al, 05h ;lenght of a cell (in characters)
- mul cl ;multiply the lenght by its position
- add al, 03h ;sum cell displacement
- mov bl, al ;we now have the x value
- mov al, 02h ;pretty much the same now but using the height
- mul dl
- add al, 04h ;we now have the y value
- mov dl, bl ;from cx
- mov dh, al ;from dx
- xor bx, bx
- mov ah, 02h
- int 10h
- pop bx
- pop ax
- ret
- setCursorPOS endp
- ;*****************************************************************
- ; evaluateInput -
- ; descricao: checks if input is valid
- ; input -
- ; output - BX = number inouted by the user, if invalid bx = -128
- ; destroi -
- ;*****************************************************************
- evaluateInput proc
- xor bx, bx
- mov si, 0
- mov ch, str_buffer[si + 1]
- cmp ch, 0
- jz invalid_input
- mov ch, str_buffer[si + 2] ;in case of ch = '-'
- cmp ch, '-'
- jz negative_num
- jmp input_checked
- negative_num:
- mov ax, 1
- input_checked:
- push ax
- call asciiToDecimal ;number is now in bx
- pop ax
- cmp di, 1
- jz invalid_input
- cmp ax, 1 ;if number is negative (ax = 1) then bx > 127
- jz skip_test
- cmp bx, 127
- ja invalid_input
- jmp valid_input
- skip_test:
- cmp bl, 128 ;else bx < 128
- jb invalid_input
- jmp valid_input
- invalid_input:
- xor bx, bx
- mov bl, -128
- valid_input:
- ret
- evaluateInput endp
- ;*****************************************************************
- ; formulaCellClicked -
- ; descricao:
- ; input - performs operations to get and print a formula
- ; output -
- ; destroi -
- ;*****************************************************************
- formulaCellClicked proc
- ;meter o cursor no sitio certo
- cmp cx, 1
- jnz already_at_start
- dec cx
- already_at_start:
- push cx
- push dx
- call setCursorPOS
- call clearFormula
- pop dx
- pop cx
- push cx
- push dx
- call setCursorPOS
- mov ch, 06h
- mov cl, 0000_1111b
- mov ah, 01h
- int 10h
- call getFormula
- cmp ax, 1 ;check if getFormula returned an error
- jnz evaluateFormula
- pop dx
- pop cx
- call setCursorPOS
- call clearFormula
- mov di, offset formula_var
- mov [di+1], -1
- jmp f_done
- evaluateFormula:
- call evaluateFormulaInput ;ficamos com o valor em decimal no registo ax
- pop dx
- pop cx
- push bx
- call setCursorPOS
- pop bx
- cmp bx, -1
- jz invalid_formula_input
- jmp f_done
- invalid_formula_input:
- xor bx, bx ;para evitar parecer que estamos a clicar no menu
- f_done:
- ret
- formulaCellClicked endp
- ;*****************************************************************
- ; getFormula -
- ; descricao: accepts a formula inputed by the user
- ; input -
- ; output -
- ; destroi -
- ;*****************************************************************
- getFormula proc
- xor cx, cx ;contador
- ask_new_finput:
- xor ax, ax
- int 16h
- cmp al, 8 ;check if char is backspace
- jnz not_fbackspace
- cmp cx, 0
- jz ask_new_finput
- call writeSpace
- dec cx
- jmp ask_new_finput
- not_fbackspace:
- cmp al, 13
- jnz not_fenter
- jmp finput_done
- not_fenter:
- cmp cx, 5
- jz ask_new_finput
- ;check if it's time to get a letter
- cmp cx, 0
- jz f_letter
- cmp cx, 3
- jz f_letter
- cmp cx, 1
- jz f_number
- cmp cx, 4
- jz f_number
- ;now we obtain the operator
- cmp al, '+'
- jz accept_finput
- cmp al, '-'
- jz accept_finput
- cmp al, '*'
- jz accept_finput
- cmp al, '/'
- jz accept_finput
- jmp ask_new_finput
- f_letter:
- cmp al, 'd'
- ja ask_new_finput
- cmp al, 'a'
- jb newt
- sub al, 32 ;tranformar a letra em maiscula
- jmp accept_finput
- newt:
- cmp al, 'D'
- ja ask_new_finput
- cmp al, 'A'
- jb ask_new_finput
- jmp accept_finput
- f_number:
- cmp al, '4'
- ja ask_new_finput
- cmp al, '1'
- jb ask_new_finput
- accept_finput:
- mov bx, offset str_buffer2
- inc bx
- inc bx
- add bx, cx
- mov [bx], al ;store char in "string" position
- ;write char al = char in ascii
- push ax
- push bx
- push cx
- mov bh, 0
- mov bx, 0Fh
- mov cx, 1
- mov ah, 09h
- int 10h
- pop cx
- pop bx
- pop ax
- ;done
- ;update cursor position dl,dh must already have previous mouse position
- push ax
- push bx
- inc dl
- xor bx, bx
- mov ah, 02h
- int 10h
- pop bx
- pop ax
- ;done
- sub bl, cl
- mov al, [bx]
- inc cx
- jmp ask_new_finput
- finput_done:
- mov bx, offset str_buffer2
- inc bx
- mov [bx], cl
- ret
- getFormula endp
- ;*****************************************************************
- ; evaluateInput -
- ; descricao: checks if input is valid, updates result
- ; input -
- ; output - BX = -1 in case of error
- ; destroi -
- ;*****************************************************************
- evaluateFormulaInput proc
- xor bx, bx
- mov bl, str_buffer2[1] ;Antes estava 4
- cmp bl, 5 ;Verificar se o utilizador nao meteu 5 numeros
- jnz invalid_input2 ;Atencao porque se o utilizador meter mais do que 4 numero
- mov si, offset str_buffer2
- add si, 2
- call getCell
- mov ax, bx
- add si, 2
- call getOperand
- inc si
- call getCell
- mov di, offset formula_var
- mov [di], al
- inc di
- mov [di], cl
- inc di
- mov [di], bl
- call calculate
- cmp ax, -1
- jz invalid_input2
- mov ax, dx
- call writeNumber
- xor bx, bx
- jmp fdone
- invalid_input2:
- call invalidInput
- mov bx, -1
- fdone:
- ret
- evaluateFormulaInput endp
- ;*****************************************************************
- ; invalidInput -
- ; descricao: writes error on result box
- ; input - no input needed
- ; output - no output
- ; destroi - ax, bx, cx, dx, bp
- ;*****************************************************************
- invalidInput proc
- mov dx, 06h
- mov cx, 03h
- call setCursorPos
- call clearFormula
- mov ax, 1301h ;print "ERROR" on result box
- mov bx, 000Fh
- mov cx, 05h
- mov bp, offset string_error
- int 10h
- ret
- invalidInput endp
- ;*****************************************************************
- ; clearFormula -
- ; descricao: clears result box
- ; input - no input needed
- ; output - no output
- ; destroi -
- ;*****************************************************************
- clearFormula proc
- push cx
- push di
- pop di
- mov al, ' '
- xor bh, bh
- mov cx, 8
- mov ah, 0Ah
- int 10h
- pop cx
- ret
- clearFormula endp
- ;*****************************************************************
- ; getcell -
- ; descricao: find what's the cell position in the array
- ; input - SI = offset to cell (the memory array)
- ; output - BX = celula
- ; destroi -
- ;*****************************************************************
- getCell proc
- push ax
- xor ax, ax
- mov al, [si]
- sub al, 'A'
- mov bx, 4
- mul bl
- add al, [si+1]
- sub al, '1'
- xor ah, ah
- mov bx, ax
- pop ax
- ret
- getCell endp
- ;*****************************************************************
- ; getcell -
- ; descricao: checks if input is valid, startes checking from the last number
- ; input - SI = offset to the operator (in cell array)
- ; output - CX = operand
- ; destroi -
- ;*****************************************************************
- getOperand proc
- xor cx, cx
- mov cl, [si]
- ret
- getOperand endp
- ;*****************************************************************
- ; calculate -
- ; descricao: checks if input is valid, startes checking from the last number
- ; input - AX = cell1 , BX = cell2 , CX = operator
- ; output - DX = result
- ; destroi -
- ;*****************************************************************
- calculate proc
- mov di, ax
- mov al, cell[di] ;I'm sorry :c
- cmp al, -128
- jz invalid_calc
- mov di, bx
- mov bl, cell[di]
- cmp bl, -128
- jz invalid_calc
- mov dx, -128
- mov remainder, dx
- xor dx, dx
- xor ah, ah ;o numero esta em ax
- xor bh, bh ;o numero esta em bx
- or al, al
- jns al_not_neg
- neg al
- neg ax ;transforming a 8-bit negative number into a 16-bit negative number
- al_not_neg:
- or bl, bl
- jns bl_not_neg
- neg bl
- neg bx
- bl_not_neg:
- ;find operator
- cmp cx, '+'
- jz sum
- cmp cx, '-'
- jz subtract
- cmp cx, '*'
- jz multiply
- cmp cx, '/'
- jz divide
- jmp invalid_calc
- ;dx = 0 here
- sum:
- add ax, bx
- mov dx, ax
- xor ax, ax
- ;js num_neg
- ;jo num_over
- jmp calc_done
- subtract:
- sub ax, bx
- mov dx, ax
- xor ax, ax
- ;js num_neg
- ;jo num_over
- jmp calc_done
- multiply:
- or ax, ax
- jns num_not_neg
- not dx
- num_not_neg:
- imul bx
- cmp dx, 0
- jz cntinue
- cmp dx, 65535
- jnz invalid_calc
- cntinue:
- mov dx, ax
- xor ax, ax
- jmp calc_done
- divide:
- cmp bl, 0
- jz invalid_calc
- or ax, ax
- jns num_not_neg2
- not dx
- num_not_neg2:
- idiv bx
- mov remainder, dx
- mov dx, ax
- xor ax, ax
- jmp calc_done
- invalid_calc:
- mov ax, -1
- jmp calc_done
- calc_done:
- ret
- calculate endp
- ;*****************************************************************
- ; asciiToDecimal -
- ; descricao:
- ; input - ax = 1 if number is negative, ax = 0 if number is positive
- ; output - bx = numero para guardar
- ; destroi -
- ;*****************************************************************
- asciiToDecimal proc
- push ax
- xor di, di
- xor ax, ax
- xor bx, bx
- xor ch, ch ;estes 3 xor provavelmente na sao necessarios,
- mov cl, str_buffer[1] ;mas se eu retirar podem dar erros
- mov si, cx
- mov al, 1
- mov dl, 10
- next_number:
- dec si
- cmp si, 0
- jz last_char
- push ax ;isto deve dar erro porque eu acho que so queria al
- mov dh, str_buffer[si + 2]
- sub dh, '0'
- mul dh
- jo error_AtD
- add bx, ax ;o numero esta no bx
- pop ax
- mul dl
- jmp next_number
- last_char:
- pop cx
- cmp cx, 1 ;verificar se o numero e negativo ou nao
- jnz pos_num
- neg bl
- jmp ascii_dec_done:
- error_AtD:
- pop ax
- pop ax
- mov di, 1
- jmp ascii_dec_done
- pos_num:
- mov dh, str_buffer[2]
- sub dh, '0'
- mul dh
- add bx, ax
- ascii_dec_done:
- ret
- asciiToDecimal endp
- ;*****************************************************************
- ; writeNumber -
- ; descricao: prints number given in ax in the result box
- ; input - ax=number
- ; output - no output
- ; destroi - ad, bx, cx, dx, bp, di
- ;*****************************************************************
- writeNumber proc
- push ax
- mov dx, 06h ;clean-up result
- mov cx, 03h
- call setCursorPOS
- call clearFormula
- pop ax
- mov bp, offset str_buffer_result
- call decimalToASCII ;put result in string
- mov dx, 1012h ;location of where to print the quocient
- jmp quocient
- remainder_print: ;print ";R:" to seperate quocient
- push bp ;and remainder
- mov bp, offset string_remainder
- mov ax, 1301h
- mov bx, 0Fh
- add dx, cx
- mov cx, 03h
- int 10h
- add dx, 03h
- pop bp ;put remainder in string
- push dx
- mov ax, remainder
- call decimalToASCII
- mov remainder, -128 ;remainder is reset
- pop dx ;location of where to print the remainder
- quocient: ;print the quocient and (in case it exists) the remainder
- mov ax, 1301h
- mov bx, 000Fh
- xor ch, ch
- int 10h
- cmp remainder, -128
- jne remainder_print
- ret
- writeNumber endp
- ;*****************************************************************
- ; decimalToASCII -
- ; descricao: puts in string given in bp the ascii value of a number
- ; input - ax=number; bp= string
- ; output - bp=string; cl=number of characters in string
- ; destroi -
- ;*****************************************************************
- decimalToASCII proc
- mov di, bp
- xor bl, bl
- cmp ax, 00h
- jge notNegNumber
- mov [di], '-'
- inc di
- neg ax
- inc bl
- push 00h
- notNegNumber: ;divides number until result=0
- xor dx, dx ;stores result in stack
- mov cx, 0Ah
- div cx
- inc bl
- push dx
- cmp al, 0
- jne notNegNumber
- mov cl, bl
- copyRemainders: ;takes the remainders from the stack
- pop ax ;and puts them on the string pointed
- add al, '0' ;by bp
- mov [di], al
- inc di
- dec bl
- cmp bl, 00h
- jne copyRemainders
- mov [di], 00h
- ret
- decimalToASCII endp
- ;*****************************************************************
- ; importExportFilename -
- ; descricao: reads file name
- ; input - no input needed
- ; output - dx = offset nome do ficheiro
- ; destroi - ax, bx, cx
- ;*****************************************************************
- importExportFilename proc
- mov dx, 06h ;clears possible error and previous filename
- mov cx, 00h
- call setCursorPos
- mov ah, 09h
- mov al, ' '
- mov bx, 000Fh
- mov cx, 0021h
- int 10h
- mov dx, 07h
- mov cx, 00h
- call setCursorPos
- mov cx, 32h
- int 10h
- mov bp, offset string_filename ;prints "Filename:"
- mov ax, 1301h
- mov bx, 0Fh
- mov cx, 08h
- mov dx, 1003h
- int 10h
- mov dx, 07h ;puts cursor and writes "c:\"
- mov cx, 00h
- call setCursorPos
- mov ah, 09h
- mov al, 'c'
- mov bx, 000Fh
- mov cx, 01h
- int 10h
- inc dx ;updates
- mov ah, 02h ;cursor
- int 10h ;position after writing "c"
- mov ah, 09h
- mov al, ':'
- int 10h
- inc dx
- mov ah, 02h
- int 10h
- mov ah, 09h
- mov al, '\'
- int 10h
- inc dx ;updates cursor position
- mov ah, 02h ;after writing "c:\"
- int 10h
- call blinkingCursor
- xor cx, cx
- read_again: ;prints ' ' on previous character
- xor bh, bh
- sub dx, cx
- mov ah, 02h
- int 10h
- mov ah, 09h
- mov al, ' '
- mov bx, 000Fh
- int 10h
- mov bx, offset name_file
- add bx, 03h
- xor cx, cx
- keep_reading:
- push bx
- xor bh, bh
- mov ah, 02h
- int 10h
- pop bx ;reads a character from the user
- mov ah, 00h
- int 16h
- mov [bx], al
- inc bx
- inc cx
- push bx
- push cx
- mov ah, 09h ;writes character read
- mov bx, 0Fh
- mov cx, 01h
- int 10h
- pop cx
- pop bx
- inc dx
- cmp al, 0Dh
- je end_reading
- cmp al, 00h
- je clear_last_char
- cmp al, 08h
- jne keep_reading
- clear_last_char:
- dec cx
- dec dx
- dec bx
- cmp cx, 00h
- je keep_reading
- dec bx
- dec cx ;compensate increment in writeSpace
- call writeSpace
- jmp keep_reading
- end_reading: ;tests extension
- sub bx, 05h
- dec dx
- dec cx
- cmp [bx], '.'
- jne read_again
- inc bx
- cmp [bx], 't'
- jne read_again
- inc bx
- cmp [bx], 'x'
- jne read_again
- inc bx
- cmp [bx], 't'
- jne read_again
- mov [bx+1], 00h
- mov dx, offset name_file
- ret
- importExportFilename endp
- ;*****************************************************************
- ; blinkingCursor -
- ; descricao: cursor starts blinking
- ; input -
- ; output -
- ; destroi -
- ;*****************************************************************
- blinkingCursor proc
- mov ch, 06h
- mov cl, 0000_1111b
- mov ah, 01h
- int 10h
- ret
- blinkingCursor endp
- ;*****************************************************************
- ; keepCheckingMouse -
- ; descricao:
- ; input -
- ; output -
- ; destroi -
- ;*****************************************************************
- keepCheckingMouse proc
- keep_checking:
- mov ax, 03h
- int 33h
- shr cx, 1 ; x/2 - in this mode the value of CX is doubled.
- cmp bx, 1
- jnz keep_checking
- ret
- keepCheckingMouse endp
- ;*****************************************************************
- ; reiniciateVideo -
- ; descricao: mostra a spreadsheet em memoria
- ; input -
- ; output -
- ; destroi -
- ;*****************************************************************
- reiniciateVideo proc
- mov ah, 00h
- mov al, 13h
- int 10h
- ret
- reiniciateVideo endp
- ;*****************************************************************
- ; fopen -
- ; descricao: abre um ficheiro em modo read(al==0), write(al==1) ou append(al==2)
- ; input - dx=offset nome ficheiro
- ; output - ax=file_handle
- ; destroi -
- ;*****************************************************************
- fopen proc
- mov ah, 3Dh
- mov al, 02h
- mov cx, 00h
- int 21h
- ret
- fopen endp
- ;*****************************************************************
- ; fclose -
- ; descricao:
- ; input - bx= file handle
- ; output -
- ; destroi -
- ;*****************************************************************
- fclose proc
- mov ah, 3Eh
- int 21h
- ret
- fclose endp
- ;*****************************************************************
- ; fcreate -
- ; descricao: cria um ficheiro
- ; input - dx=offset nome ficheiro
- ; output - ax=file_handle
- ; destroi -
- ;*****************************************************************
- fcreate proc
- mov ah, 3Ch
- mov cx, 00h
- int 21h
- ret
- fcreate endp
- ;*****************************************************************
- ; save_contents -
- ; descricao: saves contents.bin or creates it
- ; input -
- ; output -
- ; destroi -
- ;*****************************************************************
- save_contents proc
- ;tries to open file
- mov dx, offset name_contents
- call fcreate
- mov bx, ax ;move handle
- mov cx, 19 ;number of bytes
- mov dx, offset cell ;offset to write to
- mov ah, 40h
- int 21h
- ;closes file
- call fclose
- ret
- save_contents endp
- ;*****************************************************************
- ; open_contents -
- ; descricao: opens contents.bin if it exists
- ; input -
- ; output -
- ; destroi - tudo
- ;*****************************************************************
- open_contents proc
- ;tries to open file
- mov dx, offset name_contents
- call fopen
- jc end_open_cont ;in case it doesn't exist yet
- mov bx, ax
- mov cx, 19 ;number of bytes
- mov dx, offset cell ;offset to write to
- mov ah, 3Fh
- int 21h
- call fclose
- end_open_cont:
- ret
- open_contents endp
- ends
- end start ; set entry point and stop the assembler.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement