home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / Assembly / VIDEO_21.ASM < prev    next >
Assembly Source File  |  1986-09-25  |  9KB  |  308 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_PROMPT_LINE
  43.     EXTRN    CLEAR_TO_END_OF_LINE:NEAR
  44.     EXTRN    GOTO_XY:NEAR
  45. DATA_SEG    SEGMENT PUBLIC
  46.     EXTRN    PROMPT_LINE_NO:BYTE
  47. DATA_SEG    ENDS
  48. ;-----------------------------------------------------------------------;
  49. ; This procedure writest he prompt line to the screen and clears the    ;
  50. ; end of the line.                            ;
  51. ;                                    ;
  52. ;    DS:DX    Address of the prompt-line message            ;
  53. ;                                    ;
  54. ; Uses:        WRITE_STRING, CLEAR_TO_END_OF_LINE, GOTO_XY        ;
  55. ; Reads:    PROMPT_LINE_NO                        ;
  56. ;-----------------------------------------------------------------------;
  57. WRITE_PROMPT_LINE    PROC    NEAR
  58.     PUSH    DX
  59.     XOR    DL,DL            ;Write the prompt line and
  60.     MOV    DH,PROMPT_LINE_NO    ; move the cursor there
  61.     CALL    GOTO_XY
  62.     POP    DX
  63.     CALL    WRITE_STRING
  64.     CALL    CLEAR_TO_END_OF_LINE
  65.     RET
  66. WRITE_PROMPT_LINE    ENDP
  67.  
  68.  
  69.     PUBLIC    WRITE_STRING
  70. ;-----------------------------------------------------------------------;
  71. ; This procedure writes a string of characters to the screen.  The    ;
  72. ; string must end with        DB    0                ;
  73. ;                                    ;
  74. ;    DS:DX    Address of the string                    ;
  75. ;                                    ;
  76. ; Uses:        WRITE_CHAR                        ;
  77. ;-----------------------------------------------------------------------;
  78. WRITE_STRING    PROC    NEAR
  79.     PUSH    AX
  80.     PUSH    DX
  81.     PUSH    SI
  82.     PUSHF                ;Save direction flag
  83.     CLD                ;Set direction for increment (forward)
  84.     MOV    SI,DX            ;Place address into SI for LODSB
  85. STRING_LOOP:
  86.     LODSB                ;Get a character into the AL register
  87.     OR    AL,AL            ;Have we found the 0 yet?
  88.     JZ    END_OF_STRING        ;Yes, we are done with the string
  89.     MOV    DL,AL            ;No, write character
  90.     CALL    WRITE_CHAR
  91.     JMP    STRING_LOOP
  92. END_OF_STRING:
  93.     POPF                ;Restore direction flag
  94.     POP    SI
  95.     POP    DX
  96.     POP    AX
  97.     RET
  98. WRITE_STRING    ENDP
  99.  
  100.     PUBLIC    WRITE_HEX
  101. ;-----------------------------------------------------------------------;
  102. ; This procedure converts the byte in the DL register to hex and writes    ;
  103. ; the two hex digits at the current cursor position.            ;
  104. ;                                    ;
  105. ;    DL    Byte to be converted to hex.                ;
  106. ;                                    ;
  107. ; Uses:        WRITE_HEX_DIGIT                        ;
  108. ;-----------------------------------------------------------------------;
  109. WRITE_HEX    PROC    NEAR        ;Entry point
  110.     PUSH    CX            ;Save registers used in this procedure
  111.     PUSH    DX
  112.     MOV    DH,DL            ;Make a copy of byte
  113.     MOV    CX,4            ;Get the upper nibble in DL
  114.     SHR    DL,CL
  115.     CALL    WRITE_HEX_DIGIT        ;Display first hex digit
  116.     MOV    DL,DH            ;Get lower nibble into DL
  117.     AND    DL,0Fh            ;Remove the upper nibble
  118.     CALL    WRITE_HEX_DIGIT        ;Display second hex digit
  119.     POP    DX
  120.     POP    CX
  121.     RET
  122. WRITE_HEX    ENDP
  123.  
  124.     PUBLIC    WRITE_HEX_DIGIT
  125. ;-----------------------------------------------------------------------;
  126. ; This procedure converts the lower 4 bits of DL to a hex digit and    ;
  127. ; writes it to the screen.                        ;
  128. ;                                    ;
  129. ;    DL    Lower 4 bits contain number to be printed in hex.    ;
  130. ;                                    ;
  131. ; Uses:        WRITE_CHAR                        ;
  132. ;-----------------------------------------------------------------------;
  133. WRITE_HEX_DIGIT        PROC    NEAR
  134.     PUSH    DX            ;Save registers used
  135.     CMP    DL,10            ;Is this nibble <10?
  136.     JAE    HEX_LETTER        ;No, convert to a letter
  137.     ADD    DL,"0"            ;Yes, convert to a digit
  138.     JMP    Short WRITE_DIGIT    ;Now write this character
  139. HEX_LETTER:
  140.     ADD    DL,"A"-10        ;Convert to hex letter
  141. WRITE_DIGIT:
  142.     CALL    WRITE_CHAR        ;Display the letter on the screen
  143.     POP    DX            ;Restore old value of AX
  144.     RET
  145. WRITE_HEX_DIGIT        ENDP
  146.  
  147.     PUBLIC    WRITE_CHAR
  148.     EXTRN    CURSOR_RIGHT:NEAR
  149. ;-----------------------------------------------------------------------;
  150. ; This procedure outputs a character to the screen using the ROM BIOS    ;
  151. ; routines, so that characters such as the backspace are treated as    ;
  152. ; any other character and are displayed.                ;
  153. ;   This procedure must do a bit of work to update the cursor position.    ;
  154. ;                                    ;
  155. ;    DL    Byte to print on screen                    ;
  156. ;                                    ;
  157. ; Uses:        CURSOR_RIGHT                        ;
  158. ;-----------------------------------------------------------------------;
  159. WRITE_CHAR    PROC    NEAR
  160.     PUSH    AX
  161.     PUSH    BX
  162.     PUSH    CX
  163.     PUSH    DX
  164.     MOV    AH,9            ;Call for output of character/attribute
  165.     MOV    BH,0            ;Set to display page 0
  166.     MOV    CX,1            ;Write only one character
  167.     MOV    AL,DL            ;Character to write
  168.     MOV    BL,7            ;Normal attribute
  169.     INT    10h            ;Write character and attribute
  170.     CALL    CURSOR_RIGHT        ;Now move to next cursor position
  171.     POP    DX
  172.     POP    CX
  173.     POP    BX
  174.     POP    AX
  175.     RET
  176. WRITE_CHAR    ENDP
  177.  
  178.     PUBLIC    WRITE_DECIMAL
  179. ;-----------------------------------------------------------------------;
  180. ; This procedure writes a 16-bit, unsigned number in decimal notation.    ;
  181. ;                                    ;
  182. ;    DX    N : 16-bit, unsigned number.                ;
  183. ;                                    ;
  184. ;-----------------------------------------------------------------------;
  185. WRITE_DECIMAL    PROC    NEAR
  186.     PUSH    AX            ;Save registers used here
  187.     PUSH    CX
  188.     PUSH    DX
  189.     PUSH    SI
  190.     MOV    AX,DX
  191.     MOV    SI,10            ;Will divide by 10 using SI
  192.     XOR    CX,CX            ;Count of digits placed on stack
  193. NON_ZERO:
  194.     XOR    DX,DX            ;Set upper word of N to 0
  195.     DIV    SI            ;Calculate N/10 and (N mod 10)
  196.     PUSH    DX            ;Push one digit onto the stack
  197.     INC    CX            ;One more digit added
  198.     OR    AX,AX            ;N = 0 yet?
  199.     JNE    NON_ZERO        ;Nope, continue
  200. WRITE_DIGIT_LOOP:
  201.     POP    DX            ;Get the digits in reverse order
  202.     CALL    WRITE_HEX_DIGIT
  203.     LOOP    WRITE_DIGIT_LOOP
  204. END_DECIMAL:
  205.     POP    SI
  206.     POP    DX
  207.     POP    CX
  208.     POP    AX
  209.     RET
  210. WRITE_DECIMAL    ENDP
  211.  
  212.     PUBLIC    WRITE_CHAR_N_TIMES
  213. ;-----------------------------------------------------------------------;
  214. ; This procedure writes more than one copy of a character        ;
  215. ;                                    ;
  216. ;    DL    Character code                        ;
  217. ;    CX    Number of times to write the character            ;
  218. ;                                    ;
  219. ; Uses:        WRITE_CHAR                        ;
  220. ;-----------------------------------------------------------------------;
  221. WRITE_CHAR_N_TIMES    PROC    NEAR
  222.     PUSH    CX
  223. N_TIMES:
  224.     CALL    WRITE_CHAR
  225.     LOOP    N_TIMES
  226.     POP    CX
  227.     RET
  228. WRITE_CHAR_N_TIMES    ENDP
  229.  
  230.  
  231.     PUBLIC    WRITE_ATTRIBUTE_N_TIMES
  232.     EXTRN    CURSOR_RIGHT:NEAR
  233. ;-----------------------------------------------------------------------;
  234. ; This procedure sets the attribute for N characters, starting at the    ;
  235. ; current cursor position.                        ;
  236. ;                                    ;
  237. ;    CX    Number of characters to set attribute for        ;
  238. ;    DL    New attribute for characters                ;
  239. ;                                    ;
  240. ; Uses:        CURSOR_RIGHT                        ;
  241. ;-----------------------------------------------------------------------;
  242. WRITE_ATTRIBUTE_N_TIMES        PROC    NEAR
  243.     PUSH    AX
  244.     PUSH    BX
  245.     PUSH    CX
  246.     PUSH    DX
  247.     MOV    BL,DL            ;Set attribute to new attribute
  248.     XOR    BH,BH            ;Set display page to 0
  249.     MOV    DX,CX            ;CX is used by the BIOS routines
  250.     MOV    CX,1            ;Set attribute for one character
  251. ATTR_LOOP:
  252.     MOV    AH,8            ;Read character under cursor
  253.     INT    10h
  254.     MOV    AH,9            ;Write attribute/character
  255.     INT    10h
  256.     CALL    CURSOR_RIGHT
  257.     DEC    DX            ;Set attribute for N characters?
  258.     JNZ    ATTR_LOOP        ;No, continue
  259.     POP    DX
  260.     POP    CX
  261.     POP    BX
  262.     POP    AX
  263.     RET
  264. WRITE_ATTRIBUTE_N_TIMES    ENDP
  265.  
  266.  
  267.     PUBLIC    WRITE_PATTERN
  268. ;-----------------------------------------------------------------------;
  269. ; This procedure writes a line to the screen, based on data in the    ;
  270. ; form                                    ;
  271. ;                                    ;
  272. ;    DB    {character, number of times to write character}, 0    ;
  273. ; Where {x} means that x can be repeated any number of times        ;
  274. ;    DS:DX    Address of above data statement                ;
  275. ;                                    ;
  276. ; Uses:        WRITE_CHAR_N_TIMES                    ;
  277. ;-----------------------------------------------------------------------;
  278. WRITE_PATTERN    PROC    NEAR
  279.     PUSH    AX
  280.     PUSH    CX
  281.     PUSH    DX
  282.     PUSH    SI
  283.     PUSHF                ;Save the direction flag
  284.     CLD                ;Set direction flag for increment
  285.     MOV    SI,DX            ;Move offset into SI register for LODSB
  286. PATTERN_LOOP:
  287.     LODSB                ;Get character data into AL
  288.     OR    AL,AL            ;Is it the end of data (0h)?
  289.     JZ    END_PATTERN        ;Yes, return
  290.     MOV    DL,AL            ;No, set up to write character N times
  291.     LODSB                ;Get repeat count into AL
  292.     MOV    CL,AL            ;And put in CX for WRITE_CHAR_N_TIMES
  293.     XOR    CH,CH            ;Zero upper byte of CX
  294.     CALL    WRITE_CHAR_N_TIMES
  295.     JMP    PATTERN_LOOP
  296. END_PATTERN:
  297.     POPF                ;Restore direction flag
  298.     POP    SI
  299.     POP    DX
  300.     POP    CX
  301.     POP    AX
  302.     RET
  303. WRITE_PATTERN    ENDP
  304.  
  305. CODE_SEG    ENDS
  306.  
  307.     END
  308.