home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / nor_asm / video_17.asm < prev    next >
Assembly Source File  |  1989-05-16  |  6KB  |  198 lines

  1. .MODEL    SMALL
  2. .CODE
  3.  
  4.     PUBLIC    WRITE_STRING
  5. ;-----------------------------------------------------------------------;
  6. ; This procedure writes a string of characters to the screen.  The    ;
  7. ; string must end with        DB    0                ;
  8. ;                                    ;
  9. ; On entry:    DS:DX    Address of the string                ;
  10. ;                                    ;
  11. ; Uses:        WRITE_CHAR                        ;
  12. ;-----------------------------------------------------------------------;
  13. WRITE_STRING    PROC
  14.     PUSH    AX
  15.     PUSH    DX
  16.     PUSH    SI
  17.     PUSHF                ;Save direction flag
  18.     CLD                ;Set direction for increment (forward)
  19.     MOV    SI,DX            ;Place address into SI for LODSB
  20. STRING_LOOP:
  21.     LODSB                ;Get a character into the AL register
  22.     OR    AL,AL            ;Have we found the 0 yet?
  23.     JZ    END_OF_STRING        ;Yes, we are done with the string
  24.     MOV    DL,AL            ;No, write character
  25.     CALL    WRITE_CHAR
  26.     JMP    STRING_LOOP
  27. END_OF_STRING:
  28.     POPF                ;Restore direction flag
  29.     POP    SI
  30.     POP    DX
  31.     POP    AX
  32.     RET
  33. WRITE_STRING    ENDP
  34.  
  35.     PUBLIC    WRITE_HEX
  36. ;-----------------------------------------------------------------------;
  37. ; This procedure converts the byte in the DL register to hex and writes    ;
  38. ; the two hex digits at the current cursor position.            ;
  39. ;                                    ;
  40. ; On entry:    DL    Byte to convert to hex.                ;
  41. ;                                    ;
  42. ; Uses:        WRITE_HEX_DIGIT                        ;
  43. ;-----------------------------------------------------------------------;
  44. WRITE_HEX    PROC            ;Entry point
  45.     PUSH    CX            ;Save registers used in this procedure
  46.     PUSH    DX
  47.     MOV    DH,DL            ;Make a copy of byte
  48.     MOV    CX,4            ;Get the upper nibble in DL
  49.     SHR    DL,CL
  50.     CALL    WRITE_HEX_DIGIT        ;Display first hex digit
  51.     MOV    DL,DH            ;Get lower nibble into DL
  52.     AND    DL,0Fh            ;Remove the upper nibble
  53.     CALL    WRITE_HEX_DIGIT        ;Display second hex digit
  54.     POP    DX
  55.     POP    CX
  56.     RET
  57. WRITE_HEX    ENDP
  58.  
  59.     PUBLIC    WRITE_HEX_DIGIT
  60. ;-----------------------------------------------------------------------;
  61. ; This procedure converts the lower 4 bits of DL to a hex digit and    ;
  62. ; writes it to the screen.                        ;
  63. ;                                    ;
  64. ; On entry:    DL    Lower 4 bits contain number to be printed    ;
  65. ;            in hex.                        ;
  66. ;                                    ;
  67. ; Uses:        WRITE_CHAR                        ;
  68. ;-----------------------------------------------------------------------;
  69. WRITE_HEX_DIGIT        PROC
  70.     PUSH    DX            ;Save registers used
  71.     CMP    DL,10            ;Is this nibble <10?
  72.     JAE    HEX_LETTER        ;No, convert to a letter
  73.     ADD    DL,"0"            ;Yes, convert to a digit
  74.     JMP    Short WRITE_DIGIT    ;Now write this character
  75. HEX_LETTER:
  76.     ADD    DL,"A"-10        ;Convert to hex letter
  77. WRITE_DIGIT:
  78.     CALL    WRITE_CHAR        ;Display the letter on the screen
  79.     POP    DX            ;Restore old value of DX
  80.     RET
  81. WRITE_HEX_DIGIT        ENDP
  82.  
  83.     PUBLIC    WRITE_CHAR
  84. ;-----------------------------------------------------------------------;
  85. ; This procedure prints a character on the screen using the DOS        ;
  86. ; function call.  WRITE_CHAR replaces the characters 0 through 1Fh with    ;
  87. ; a period.                                ;
  88. ;                                    ;
  89. ; On entry:    DL    Byte to print on screen.            ;
  90. ;-----------------------------------------------------------------------;
  91. WRITE_CHAR    PROC
  92.     PUSH    AX    
  93.     PUSH    DX
  94.     CMP    DL,32            ;Is character before a space?
  95.     JAE    IS_PRINTABLE        ;No, then print as is
  96.     MOV    DL,'.'            ;Yes, replace with a period
  97. IS_PRINTABLE:
  98.     MOV    AH,2            ;Call for character output
  99.     INT    21h            ;Output character in DL register
  100.     POP    DX            ;Restore old value in AX and DX
  101.     POP    AX
  102.     RET
  103. WRITE_CHAR    ENDP
  104.  
  105.     PUBLIC    WRITE_DECIMAL
  106. ;-----------------------------------------------------------------------;
  107. ; This procedure writes a 16-bit, unsigned number in decimal notation.    ;
  108. ;                                    ;
  109. ; On entry:    DX    N : 16-bit, unsigned number.            ;
  110. ;                                    ;
  111. ; Uses:        WRITE_HEX_DIGIT                        ;
  112. ;-----------------------------------------------------------------------;
  113. WRITE_DECIMAL    PROC
  114.     PUSH    AX            ;Save registers used here
  115.     PUSH    CX
  116.     PUSH    DX
  117.     PUSH    SI
  118.     MOV    AX,DX
  119.     MOV    SI,10            ;Will divide by 10 using SI
  120.     XOR    CX,CX            ;Count of digits placed on stack
  121. NON_ZERO:
  122.     XOR    DX,DX            ;Set upper word of N to 0
  123.     DIV    SI            ;Calculate N/10 and (N mod 10)
  124.     PUSH    DX            ;Push one digit onto the stack
  125.     INC    CX            ;One more digit added
  126.     OR    AX,AX            ;N = 0 yet?
  127.     JNE    NON_ZERO        ;Nope, continue
  128. WRITE_DIGIT_LOOP:
  129.     POP    DX            ;Get the digits in reverse order
  130.     CALL    WRITE_HEX_DIGIT
  131.     LOOP    WRITE_DIGIT_LOOP
  132. END_DECIMAL:
  133.     POP    SI
  134.     POP    DX
  135.     POP    CX
  136.     POP    AX
  137.     RET
  138. WRITE_DECIMAL    ENDP
  139.  
  140.     PUBLIC    WRITE_CHAR_N_TIMES
  141. ;-----------------------------------------------------------------------;
  142. ; This procedure writes more than one copy of a character        ;
  143. ;                                    ;
  144. ; On entry:    DL    Character code                    ;
  145. ;        CX    Number of times to write the character        ;
  146. ;                                    ;
  147. ; Uses:        WRITE_CHAR                        ;
  148. ;-----------------------------------------------------------------------;
  149. WRITE_CHAR_N_TIMES    PROC
  150.     PUSH    CX
  151. N_TIMES:
  152.     CALL    WRITE_CHAR
  153.     LOOP    N_TIMES
  154.     POP    CX
  155.     RET
  156. WRITE_CHAR_N_TIMES    ENDP
  157.  
  158.     PUBLIC    WRITE_PATTERN
  159. ;-----------------------------------------------------------------------;
  160. ; This procedure writes a line to the screen, based on data in the    ;
  161. ; form                                    ;
  162. ;                                    ;
  163. ;    DB    {character, number of times to write character}, 0    ;
  164. ; Where {x} means that x can be repeated any number of times        ;
  165. ;                                    ;
  166. ; On entry:    DS:DX    Address of the pattern to draw            ;
  167. ;                                    ;
  168. ; Uses:        WRITE_CHAR_N_TIMES                    ;
  169. ;-----------------------------------------------------------------------;
  170. WRITE_PATTERN    PROC
  171.     PUSH    AX
  172.     PUSH    CX
  173.     PUSH    DX
  174.     PUSH    SI
  175.     PUSHF                ;Save the direction flag
  176.     CLD                ;Set direction flag for increment
  177.     MOV    SI,DX            ;Move offset into SI register for LODSB
  178. PATTERN_LOOP:
  179.     LODSB                ;Get character data into AL
  180.     OR    AL,AL            ;Is it the end of data (0h)?
  181.     JZ    END_PATTERN        ;Yes, return
  182.     MOV    DL,AL            ;No, set up to write character N times
  183.     LODSB                ;Get the repeat count into AL
  184.     MOV    CL,AL            ;And put in CX for WRITE_CHAR_N_TIMES
  185.     XOR    CH,CH            ;Zero upper byte of CX
  186.     CALL    WRITE_CHAR_N_TIMES
  187.     JMP    PATTERN_LOOP
  188. END_PATTERN:
  189.     POPF                ;Restore direction flag
  190.     POP    SI
  191.     POP    DX
  192.     POP    CX
  193.     POP    AX
  194.     RET
  195. WRITE_PATTERN    ENDP
  196.  
  197.     END
  198.