; ; JR-IDE Project ; - (c) 2020 Alan Hightower ; ; This program is free software: you can redistribute it and/or modify ; it under the terms of the GNU General Public License as published by ; the Free Software Foundation, either version 3 of the License, or ; (at your option) any later version. ; ; This program is distributed in the hope that it will be useful, ; but WITHOUT ANY WARRANTY; without even the implied warranty of ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; GNU General Public License for more details. ; ; You should have received a copy of the GNU General Public License ; along with this program. If not, see . ; _TEXT segment public use16 'CODE' assume cs:_TEXT, ds:nothing, es:nothing ; Invoke BIOS teletype to print a character contained in al. ; The content of ax is preserved. print_char proc near public push ax push bx xor bx, bx mov ah, 0Eh int 10h pop bx pop ax ret print_char endp ; Print a local null terminated const string pointed to by si ; using the BIOS teletype service. print_char is unrolled/inlined ; here for speed. ; ; si is advanced to the termination null print_string proc near public pushf push ax push bx push ds push cs pop ds xor bx, bx cld print_string_loop: lodsb ; Get next character or al, al ; Check for null terminator jz print_string_exit mov ah, 0eh int 10h ; BIOS teletype jmp print_string_loop print_string_exit: pop ds pop bx pop ax popf ret print_string endp ; Prints (and preserves) a text representation of a value passed ; in through ax in decimal form via BIOS print calls. The value ; in ax is continually divided by 10 while pushing the remainders ; on the stack until there is no more quotient. Then the stack is ; unwound printing each decade value. print_dec proc near public push ax push bx push cx push dx xor cx, cx mov bx, 10 print_dec_loop1: xor dx, dx div bx ; divide ax by bx / remainder in dx push dx inc cx or ax, 0 jnz print_dec_loop1 print_dec_loop2: pop ax xor ah, ah add al, '0' ;48 call print_char dec cx jnz print_dec_loop2 pop dx pop cx pop bx pop ax ret print_dec endp hexTable: db '0123456789ABCDEF' ; Prints (and preserves) a text representation of a value passed ; in through al in hexadecimal form via BIOS print calls. print_hexb proc near public push ax push bx push ds push cs pop ds mov bx, hexTable mov ah, al ; Preserve original byte shr al, 1 ; Grab upper nibble shr al, 1 shr al, 1 shr al, 1 xlat ; al = ds:[bx + al] call print_char xchg al, ah ; Restore original byte and al, 0fh xlat ; al = ds:[bx + al] call print_char pop ds pop bx pop ax ret print_hexb endp ; Prints (and preserves) a text representation of a value passed ; in through ax in hexadecimal form via BIOS print calls. print_hexw proc near public xchg ah, al ; High byte first call print_hexb xchg ah, al ; Low byte second call print_hexb ret print_hexw endp to_upper proc near public pushf cmp al, 'a' jb to_upper_exit cmp al, 'z' ja to_upper_exit and al, 5fh ; 'A'= 0x4x, 'a' = 0x6x to_upper_exit: popf ret to_upper endp ; ******************************************************** ; Function - checksum ; ; Inputs: DS:SI = Pointer to buffer to be summed ; CX = Byte count - length ; ; Outputs: AL = Two's complement checksum ; ; Desc: Compute a two's complement checksum of the ; specified source buffer checksum proc near public push cx push di xor al, al checksum_loop: add al, ds:[di] inc di loop checksum_loop not al inc al pop di pop cx ret checksum endp _TEXT ends end