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

  1. CGROUP    GROUP    CODE_SEG, DATA_SEG    ;Group two segments together
  2.     ASSUME    CS:CGROUP, DS:CGROUP
  3.  
  4. CODE_SEG    SEGMENT PUBLIC
  5.  
  6.     PUBLIC    WRITE_HEADER
  7. DATA_SEG    SEGMENT PUBLIC
  8.     EXTRN    HEADER_LINE_NO:BYTE
  9.     EXTRN    HEADER_PART_1:BYTE
  10.     EXTRN    HEADER_PART_2:BYTE
  11.     EXTRN    DISK_DRIVE_NO:BYTE
  12.     EXTRN    CURRENT_SECTOR_NO:WORD
  13. DATA_SEG    ENDS
  14.     EXTRN    GOTO_XY:NEAR, CLEAR_TO_END_OF_LINE:NEAR
  15. ;-----------------------------------------------------------------------;
  16. ; This procedure writes the header with disk-drive and sector number.    ;
  17. ;                                    ;
  18. ; Uses:        GOTO_XY, WRITE_STRING, WRITE_CHAR, WRITE_DECIMAL    ;
  19. ;        CLEAR_TO_END_OF_LINE                    ;
  20. ; Reads:    HEADER_LINE_NO, HEADER_PART_1, HEADER_PART_2        ;
  21. ;        DISK_DRIVE_NO, CURRENT_SECTOR_NO            ;
  22. ;-----------------------------------------------------------------------;
  23. WRITE_HEADER    PROC    NEAR
  24.     PUSH    DX
  25.     XOR    DL,DL            ;Move cursor to header line number
  26.     MOV    DH,HEADER_LINE_NO
  27.     CALL    GOTO_XY
  28.     LEA    DX,HEADER_PART_1
  29.     CALL    WRITE_STRING
  30.     MOV    DL,DISK_DRIVE_NO
  31.     ADD    DL,'A'            ;Print drives A, B, ...
  32.     CALL    WRITE_CHAR
  33.     LEA    DX,HEADER_PART_2
  34.     CALL    WRITE_STRING
  35.     MOV    DX,CURRENT_SECTOR_NO
  36.     CALL    WRITE_DECIMAL
  37.     CALL    CLEAR_TO_END_OF_LINE    ;Clear rest of sector number
  38.     POP    DX
  39.     RET
  40. WRITE_HEADER    ENDP
  41.  
  42.     PUBLIC    WRITE_STRING
  43. ;-----------------------------------------------------------------------;
  44. ; This procedure writes a string of characters to the screen.  The    ;
  45. ; string must end with        DB    0                ;
  46. ;                                    ;
  47. ;    DS:DX    Address of the string                    ;
  48. ;                                    ;
  49. ; Uses:        WRITE_CHAR                        ;
  50. ;-----------------------------------------------------------------------;
  51. WRITE_STRING    PROC    NEAR
  52.     PUSH    AX
  53.     PUSH    DX
  54.     PUSH    SI
  55.     PUSHF                ;Save direction flag
  56.     CLD                ;Set direction for increment (forward)
  57.     MOV    SI,DX            ;Place address into SI for LODSB
  58. STRING_LOOP:
  59.     LODSB                ;Get a character into the AL register
  60.     OR    AL,AL            ;Have we found the 0 yet?
  61.     JZ    END_OF_STRING        ;Yes, we are done with the string
  62.     MOV    DL,AL            ;No, write character
  63.     CALL    WRITE_CHAR
  64.     JMP    STRING_LOOP
  65. END_OF_STRING:
  66.     POPF                ;Restore direction flag
  67.     POP    SI
  68.     POP    DX
  69.     POP    AX
  70.     RET
  71. WRITE_STRING    ENDP
  72.  
  73.     PUBLIC    WRITE_HEX
  74. ;-----------------------------------------------------------------------;
  75. ; This procedure converts the byte in the DL register to hex and writes    ;
  76. ; the two hex digits at the current cursor position.            ;
  77. ;                                    ;
  78. ;    DL    Byte to be converted to hex.                ;
  79. ;                                    ;
  80. ; Uses:        WRITE_HEX_DIGIT                        ;
  81. ;-----------------------------------------------------------------------;
  82. WRITE_HEX    PROC    NEAR        ;Entry point
  83.     PUSH    CX            ;Save registers used in this procedure
  84.     PUSH    DX
  85.     MOV    DH,DL            ;Make a copy of byte
  86.     MOV    CX,4            ;Get the upper nibble in DL
  87.     SHR    DL,CL
  88.     CALL    WRITE_HEX_DIGIT        ;Display first hex digit
  89.     MOV    DL,DH            ;Get lower nibble into DL
  90.     AND    DL,0Fh            ;Remove the upper nibble
  91.     CALL    WRITE_HEX_DIGIT        ;Display second hex digit
  92.     POP    DX
  93.     POP    CX
  94.     RET
  95. WRITE_HEX    ENDP
  96.  
  97.     PUBLIC    WRITE_HEX_DIGIT
  98. ;-----------------------------------------------------------------------;
  99. ; This procedure converts the lower 4 bits of DL to a hex digit and    ;
  100. ; writes it to the screen.                        ;
  101. ;                                    ;
  102. ;    DL    Lower 4 bits contain number to be printed in hex.    ;
  103. ;                                    ;
  104. ; Uses:        WRITE_CHAR                        ;
  105. ;-----------------------------------------------------------------------;
  106. WRITE_HEX_DIGIT        PROC    NEAR
  107.     PUSH    DX            ;Save registers used
  108.     CMP    DL,10            ;Is this nibble <10?
  109.     JAE    HEX_LETTER        ;No, convert to a letter
  110.     ADD    DL,"0"            ;Yes, convert to a digit
  111.     JMP    Short WRITE_DIGIT    ;Now write this character
  112. HEX_LETTER:
  113.     ADD    DL,"A"-10        ;Convert to hex letter
  114. WRITE_DIGIT:
  115.     CALL    WRITE_CHAR        ;Display the letter on the screen
  116.     POP    DX            ;Restore old value of AX
  117.     RET
  118. WRITE_HEX_DIGIT        ENDP
  119.  
  120.     PUBLIC    WRITE_CHAR
  121.     EXTRN    CURSOR_RIGHT:NEAR
  122. ;-----------------------------------------------------------------------;
  123. ; This procedure outputs a character to the screen using the ROM BIOS    ;
  124. ; routines, so that characters such as the backspace are treated as    ;
  125. ; any other character and are displayed.                ;
  126. ;   This procedure must do a bit of work to update the cursor position.    ;
  127. ;                                    ;
  128. ;    DL    Byte to print on screen                    ;
  129. ;                                    ;
  130. ; Uses:        CURSOR_RIGHT                        ;
  131. ;-----------------------------------------------------------------------;
  132. WRITE_CHAR    PROC    NEAR
  133.     PUSH    AX
  134.     PUSH    BX
  135.     PUSH    CX
  136.     PUSH    DX
  137.     MOV    AH,9            ;Call for output of character/attribute
  138.     MOV    BH,0            ;Set to display page 0
  139.     MOV    CX,1            ;Write only one character
  140.     MOV    AL,DL            ;Character to write
  141.     MOV    BL,7            ;Normal attribute
  142.     INT    10h            ;Write character and attribute
  143.     CALL    CURSOR_RIGHT        ;Now move to next cursor position
  144.     POP    DX
  145.     POP    CX
  146.     POP    BX
  147.     POP    AX
  148.     RET
  149. WRITE_CHAR    ENDP
  150.  
  151.     PUBLIC    WRITE_DECIMAL
  152. ;-----------------------------------------------------------------------;
  153. ; This procedure writes a 16-bit, unsigned number in decimal notation.    ;
  154. ;                                    ;
  155. ;    DX    N : 16-bit, unsigned number.                ;
  156. ;                                    ;
  157. ;-----------------------------------------------------------------------;
  158. WRITE_DECIMAL    PROC    NEAR
  159.     PUSH    AX            ;Save registers used here
  160.     PUSH    CX
  161.     PUSH    DX
  162.     PUSH    SI
  163.     MOV    AX,DX
  164.     MOV    SI,10            ;Will divide by 10 using SI
  165.     XOR    CX,CX            ;Count of digits placed on stack
  166. NON_ZERO:
  167.     XOR    DX,DX            ;Set upper word of N to 0
  168.     DIV    SI            ;Calculate N/10 and (N mod 10)
  169.     PUSH    DX            ;Push one digit onto the stack
  170.     INC    CX            ;One more digit added
  171.     OR    AX,AX            ;N = 0 yet?
  172.     JNE    NON_ZERO        ;Nope, continue
  173. WRITE_DIGIT_LOOP:
  174.     POP    DX            ;Get the digits in reverse order
  175.     CALL    WRITE_HEX_DIGIT
  176.     LOOP    WRITE_DIGIT_LOOP
  177. END_DECIMAL:
  178.     POP    SI
  179.     POP    DX
  180.     POP    CX
  181.     POP    AX
  182.     RET
  183. WRITE_DECIMAL    ENDP
  184.  
  185.     PUBLIC    WRITE_CHAR_N_TIMES
  186. ;-----------------------------------------------------------------------;
  187. ; This procedure writes more than one copy of a character        ;
  188. ;                                    ;
  189. ;    DL    Character code                        ;
  190. ;    CX    Number of times to write the character            ;
  191. ;                                    ;
  192. ; Uses:        WRITE_CHAR                        ;
  193. ;-----------------------------------------------------------------------;
  194. WRITE_CHAR_N_TIMES    PROC    NEAR
  195.     PUSH    CX
  196. N_TIMES:
  197.     CALL    WRITE_CHAR
  198.     LOOP    N_TIMES
  199.     POP    CX
  200.     RET
  201. WRITE_CHAR_N_TIMES    ENDP
  202.  
  203.     PUBLIC    WRITE_PATTERN
  204. ;-----------------------------------------------------------------------;
  205. ; This procedure writes a line to the screen, based on data in the    ;
  206. ; form                                    ;
  207. ;                                    ;
  208. ;    DB    {character, number of times to write character}, 0    ;
  209. ; Where {x} means that x can be repeated any number of times        ;
  210. ;    DS:DX    Address of above data statement                ;
  211. ;                                    ;
  212. ; Uses:        WRITE_CHAR_N_TIMES                    ;
  213. ;-----------------------------------------------------------------------;
  214. WRITE_PATTERN    PROC    NEAR
  215.     PUSH    AX
  216.     PUSH    CX
  217.     PUSH    DX
  218.     PUSH    SI
  219.     PUSHF                ;Save the direction flag
  220.     CLD                ;Set direction flag for increment
  221.     MOV    SI,DX            ;Move offset into SI register for LODSB
  222. PATTERN_LOOP:
  223.     LODSB                ;Get character data into AL
  224.     OR    AL,AL            ;Is it the end of data (0h)?
  225.     JZ    END_PATTERN        ;Yes, return
  226.     MOV    DL,AL            ;No, set up to write character N times
  227.     LODSB                ;Get repeat count into AL
  228.     MOV    CL,AL            ;And put in CX for WRITE_CHAR_N_TIMES
  229.     XOR    CH,CH            ;Zero upper byte of CX
  230.     CALL    WRITE_CHAR_N_TIMES
  231.     JMP    PATTERN_LOOP
  232. END_PATTERN:
  233.     POPF                ;Restore direction flag
  234.     POP    SI
  235.     POP    DX
  236.     POP    CX
  237.     POP    AX
  238.     RET
  239. WRITE_PATTERN    ENDP
  240.  
  241. CODE_SEG    ENDS
  242.  
  243.     END
  244.