[3] | 1 | ; File name : prntbios.asm |
---|
| 2 | ; Project name : Print library |
---|
| 3 | ; Created date : 7.12.2009 |
---|
| 4 | ; Last update : 17.1.2010 |
---|
| 5 | ; Author : Tomi Tilli |
---|
| 6 | ; Description : ASM library to for character and string |
---|
| 7 | ; printing using BIOS. |
---|
| 8 | |
---|
| 9 | ;--------------- Equates ----------------------------- |
---|
| 10 | |
---|
| 11 | ; Int 10h (BIOS) functions |
---|
| 12 | FN_BIOS_WR_CHAR_TEL EQU 0Eh ; Teletype Output |
---|
| 13 | |
---|
| 14 | |
---|
| 15 | ;-------------- Public functions --------------------- |
---|
| 16 | ; Section containing code |
---|
| 17 | SECTION .text |
---|
| 18 | |
---|
| 19 | ;-------------------------------------------------------------------- |
---|
| 20 | ; Prints character. All character printing functions must |
---|
| 21 | ; use this macro to print characters (so printing implementation |
---|
| 22 | ; can be easily modified when needed). |
---|
| 23 | ; |
---|
| 24 | ; PRINT_CHAR |
---|
| 25 | ; Parameters: |
---|
| 26 | ; DL: Character to print |
---|
| 27 | ; Returns: |
---|
| 28 | ; Nothing |
---|
| 29 | ; Corrupts registers: |
---|
| 30 | ; AX |
---|
| 31 | ;-------------------------------------------------------------------- |
---|
| 32 | %macro PRINT_CHAR 0 |
---|
| 33 | call Print_BiosTeleChar |
---|
| 34 | %endmacro |
---|
| 35 | |
---|
| 36 | ALIGN JUMP_ALIGN |
---|
| 37 | Print_BiosTeleChar: |
---|
| 38 | push bp ; Save because of buggy BIOSes |
---|
| 39 | push bx |
---|
| 40 | mov ah, FN_BIOS_WR_CHAR_TEL |
---|
| 41 | mov al, dl ; Copy char to write |
---|
| 42 | xor bx, bx ; Page 0 |
---|
| 43 | int 10h |
---|
| 44 | pop bx |
---|
| 45 | pop bp |
---|
| 46 | ret |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | ;-------------------------------------------------------------------- |
---|
| 50 | ; Prints string. All string printing functions must |
---|
| 51 | ; use this macro to print strings (so printing implementation |
---|
| 52 | ; can be easily modified when needed). |
---|
| 53 | ; |
---|
| 54 | ; PRINT_STR |
---|
| 55 | ; Parameters: |
---|
| 56 | ; DS:DX: Ptr to STOP terminated string |
---|
| 57 | ; Returns: |
---|
| 58 | ; Nothing |
---|
| 59 | ; Corrupts registers: |
---|
| 60 | ; AX |
---|
| 61 | ;-------------------------------------------------------------------- |
---|
| 62 | %macro PRINT_STR 0 |
---|
| 63 | push dx |
---|
| 64 | call Print_BiosTeleStr |
---|
| 65 | pop dx |
---|
| 66 | %endmacro |
---|
| 67 | |
---|
| 68 | |
---|
| 69 | ;-------------------------------------------------------------------- |
---|
| 70 | ; Prints string and returns number of characters printed. |
---|
| 71 | ; All string printing functions must use this macro to print strings |
---|
| 72 | ; (so printing implementation can be easily modified when needed). |
---|
| 73 | ; |
---|
| 74 | ; PRINT_STR_LEN |
---|
| 75 | ; Parameters: |
---|
| 76 | ; DS:DX: Ptr to STOP terminated string |
---|
| 77 | ; Returns: |
---|
| 78 | ; DX: Number of characters printed |
---|
| 79 | ; Corrupts registers: |
---|
| 80 | ; AX |
---|
| 81 | ;-------------------------------------------------------------------- |
---|
| 82 | %macro PRINT_STR_LEN 0 |
---|
| 83 | call Print_BiosTeleStr |
---|
| 84 | %endmacro |
---|
| 85 | |
---|
| 86 | ALIGN JUMP_ALIGN |
---|
| 87 | Print_BiosTeleStr: |
---|
| 88 | push bp ; Save because of buggy BIOSes |
---|
| 89 | push si |
---|
| 90 | push bx |
---|
| 91 | mov si, dx ; Copy offset to string |
---|
| 92 | xor dx, dx ; Zero char counter |
---|
| 93 | xor bx, bx ; Page 0 |
---|
| 94 | cld ; LODSB to increment SI |
---|
| 95 | ALIGN JUMP_ALIGN |
---|
| 96 | .CharLoop: |
---|
| 97 | lodsb ; Load char from [DS:SI] to AL |
---|
| 98 | cmp al, STOP ; End of string? |
---|
| 99 | je .Return ; If so, return |
---|
| 100 | mov ah, FN_BIOS_WR_CHAR_TEL ; Some BIOSes corrupts AX when returning |
---|
| 101 | int 10h |
---|
| 102 | inc dx ; Increment chars printed |
---|
| 103 | jmp .CharLoop ; Loop while chars left |
---|
| 104 | ALIGN JUMP_ALIGN |
---|
| 105 | .Return: |
---|
| 106 | pop bx |
---|
| 107 | pop si |
---|
| 108 | pop bp |
---|
| 109 | ret |
---|