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

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