home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / Assembly / VIDEO_16.ASM < prev    next >
Assembly Source File  |  1986-09-24  |  5KB  |  167 lines

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