home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / nor_asm / video_21.asm < prev    next >
Assembly Source File  |  1989-05-17  |  7KB  |  245 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.     EXTRN    CURSOR_RIGHT:PROC
  85. ;-----------------------------------------------------------------------;
  86. ; This procedure outputs a character to the screen using the ROM BIOS    ;
  87. ; routines, so that characters such as the backspace are treated as    ;
  88. ; any other character and are displayed.                ;
  89. ;                                    ;
  90. ; This procedure must do a bit of work to update the cursor position.    ;
  91. ;                                    ;
  92. ; On entry:    DL    Byte to print on screen.            ;
  93. ;                                    ;
  94. ; Uses:        CURSOR_RIGHT                        ;
  95. ;-----------------------------------------------------------------------;
  96. WRITE_CHAR    PROC
  97.     PUSH    AX
  98.     PUSH    BX
  99.     PUSH    CX
  100.     PUSH    DX
  101.     MOV    AH,9            ;Call for output of character/attribute
  102.     MOV    BH,0            ;Set to display page 0
  103.     MOV    CX,1            ;Write only one character
  104.     MOV    AL,DL            ;Character to write
  105.     MOV    BL,7            ;Normal attribute
  106.     INT    10h            ;Write character and attribute
  107.     CALL    CURSOR_RIGHT        ;Now move to next cursor position
  108.     POP    DX
  109.     POP    CX
  110.     POP    BX
  111.     POP    AX
  112.     RET
  113. WRITE_CHAR    ENDP
  114.  
  115.     PUBLIC    WRITE_DECIMAL
  116. ;-----------------------------------------------------------------------;
  117. ; This procedure writes a 16-bit, unsigned number in decimal notation.    ;
  118. ;                                    ;
  119. ; On entry:    DX    N : 16-bit, unsigned number.            ;
  120. ;                                    ;
  121. ; Uses:        WRITE_HEX_DIGIT                        ;
  122. ;-----------------------------------------------------------------------;
  123. WRITE_DECIMAL    PROC
  124.     PUSH    AX            ;Save registers used here
  125.     PUSH    CX
  126.     PUSH    DX
  127.     PUSH    SI
  128.     MOV    AX,DX
  129.     MOV    SI,10            ;Will divide by 10 using SI
  130.     XOR    CX,CX            ;Count of digits placed on stack
  131. NON_ZERO:
  132.     XOR    DX,DX            ;Set upper word of N to 0
  133.     DIV    SI            ;Calculate N/10 and (N mod 10)
  134.     PUSH    DX            ;Push one digit onto the stack
  135.     INC    CX            ;One more digit added
  136.     OR    AX,AX            ;N = 0 yet?
  137.     JNE    NON_ZERO        ;Nope, continue
  138. WRITE_DIGIT_LOOP:
  139.     POP    DX            ;Get the digits in reverse order
  140.     CALL    WRITE_HEX_DIGIT
  141.     LOOP    WRITE_DIGIT_LOOP
  142. END_DECIMAL:
  143.     POP    SI
  144.     POP    DX
  145.     POP    CX
  146.     POP    AX
  147.     RET
  148. WRITE_DECIMAL    ENDP
  149.  
  150.     PUBLIC    WRITE_CHAR_N_TIMES
  151. ;-----------------------------------------------------------------------;
  152. ; This procedure writes more than one copy of a character        ;
  153. ;                                    ;
  154. ; On entry:    DL    Character code                    ;
  155. ;        CX    Number of times to write the character        ;
  156. ;                                    ;
  157. ; Uses:        WRITE_CHAR                        ;
  158. ;-----------------------------------------------------------------------;
  159. WRITE_CHAR_N_TIMES    PROC
  160.     PUSH    CX
  161. N_TIMES:
  162.     CALL    WRITE_CHAR
  163.     LOOP    N_TIMES
  164.     POP    CX
  165.     RET
  166. WRITE_CHAR_N_TIMES    ENDP
  167.  
  168.  
  169.     PUBLIC    WRITE_ATTRIBUTE_N_TIMES
  170.     EXTRN    CURSOR_RIGHT:PROC
  171. ;-----------------------------------------------------------------------;
  172. ; This procedure sets the attribute for N characters, starting at the    ;
  173. ; current cursor position.                        ;
  174. ;                                    ;
  175. ;    CX    Number of characters to set attribute for        ;
  176. ;    DL    New attribute for characters                ;
  177. ;                                    ;
  178. ; Uses:        CURSOR_RIGHT                        ;
  179. ;-----------------------------------------------------------------------;
  180. WRITE_ATTRIBUTE_N_TIMES        PROC
  181.     PUSH    AX
  182.     PUSH    BX
  183.     PUSH    CX
  184.     PUSH    DX
  185.     MOV    BL,DL            ;Set attribute to new attribute
  186.     XOR    BH,BH            ;Set display page to 0
  187.     MOV    DX,CX            ;CX is used by the BIOS routines
  188.     MOV    CX,1            ;Set attribute for one character
  189. ATTR_LOOP:
  190.     MOV    AH,8            ;Read character under cursor
  191.     INT    10h
  192.     MOV    AH,9            ;Write attribute/character
  193.     INT    10h
  194.     CALL    CURSOR_RIGHT
  195.     DEC    DX            ;Set attribute for N characters?
  196.     JNZ    ATTR_LOOP        ;No, continue
  197.     POP    DX
  198.     POP    CX
  199.     POP    BX
  200.     POP    AX
  201.     RET
  202. WRITE_ATTRIBUTE_N_TIMES    ENDP
  203.  
  204.  
  205.     PUBLIC    WRITE_PATTERN
  206. ;-----------------------------------------------------------------------;
  207. ; This procedure writes a line to the screen, based on data in the    ;
  208. ; form                                    ;
  209. ;                                    ;
  210. ;    DB    {character, number of times to write character}, 0    ;
  211. ; Where {x} means that x can be repeated any number of times        ;
  212. ;                                    ;
  213. ; On entry:    DS:DX    Address of the pattern to draw            ;
  214. ;                                    ;
  215. ; Uses:        WRITE_CHAR_N_TIMES                    ;
  216. ;-----------------------------------------------------------------------;
  217. WRITE_PATTERN    PROC
  218.     PUSH    AX
  219.     PUSH    CX
  220.     PUSH    DX
  221.     PUSH    SI
  222.     PUSHF                ;Save the direction flag
  223.     CLD                ;Set direction flag for increment
  224.     MOV    SI,DX            ;Move offset into SI register for LODSB
  225. PATTERN_LOOP:
  226.     LODSB                ;Get character data into AL
  227.     OR    AL,AL            ;Is it the end of data (0h)?
  228.     JZ    END_PATTERN        ;Yes, return
  229.     MOV    DL,AL            ;No, set up to write character N times
  230.     LODSB                ;Get the repeat count into AL
  231.     MOV    CL,AL            ;And put in CX for WRITE_CHAR_N_TIMES
  232.     XOR    CH,CH            ;Zero upper byte of CX
  233.     CALL    WRITE_CHAR_N_TIMES
  234.     JMP    PATTERN_LOOP
  235. END_PATTERN:
  236.     POPF                ;Restore direction flag
  237.     POP    SI
  238.     POP    DX
  239.     POP    CX
  240.     POP    AX
  241.     RET
  242. WRITE_PATTERN    ENDP
  243.  
  244.     END
  245.