home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / nor_asm / video_30.asm < prev    next >
Assembly Source File  |  1989-06-09  |  8KB  |  285 lines

  1. .MODEL    SMALL
  2.  
  3. .DATA
  4.     PUBLIC    SCREEN_PTR
  5.     PUBLIC    SCREEN_X, SCREEN_Y
  6. SCREEN_SEG    DW    0B800h        ;Segment of the screen buffer
  7. SCREEN_PTR    DW    0        ;Offset into screen memory of cursor
  8. SCREEN_X    DB    0        ;Position of the screen cursor
  9. SCREEN_Y    DB    0
  10.  
  11.  
  12. .CODE
  13.  
  14.     PUBLIC    WRITE_STRING
  15. ;-----------------------------------------------------------------------;
  16. ; This procedure writes a string of characters to the screen.  The    ;
  17. ; string must end with        DB    0                ;
  18. ;                                    ;
  19. ; On entry:    DS:DX    Address of the string                ;
  20. ;                                    ;
  21. ; Uses:        WRITE_CHAR                        ;
  22. ;-----------------------------------------------------------------------;
  23. WRITE_STRING    PROC
  24.     PUSH    AX
  25.     PUSH    DX
  26.     PUSH    SI
  27.     PUSHF                ;Save direction flag
  28.     CLD                ;Set direction for increment (forward)
  29.     MOV    SI,DX            ;Place address into SI for LODSB
  30. STRING_LOOP:
  31.     LODSB                ;Get a character into the AL register
  32.     OR    AL,AL            ;Have we found the 0 yet?
  33.     JZ    END_OF_STRING        ;Yes, we are done with the string
  34.     MOV    DL,AL            ;No, write character
  35.     CALL    WRITE_CHAR
  36.     JMP    STRING_LOOP
  37. END_OF_STRING:
  38.     POPF                ;Restore direction flag
  39.     POP    SI
  40.     POP    DX
  41.     POP    AX
  42.     RET
  43. WRITE_STRING    ENDP
  44.  
  45.     PUBLIC    WRITE_HEX
  46. ;-----------------------------------------------------------------------;
  47. ; This procedure converts the byte in the DL register to hex and writes    ;
  48. ; the two hex digits at the current cursor position.            ;
  49. ;                                    ;
  50. ; On entry:    DL    Byte to convert to hex.                ;
  51. ;                                    ;
  52. ; Uses:        WRITE_HEX_DIGIT                        ;
  53. ;-----------------------------------------------------------------------;
  54. WRITE_HEX    PROC            ;Entry point
  55.     PUSH    CX            ;Save registers used in this procedure
  56.     PUSH    DX
  57.     MOV    DH,DL            ;Make a copy of byte
  58.     MOV    CX,4            ;Get the upper nibble in DL
  59.     SHR    DL,CL
  60.     CALL    WRITE_HEX_DIGIT        ;Display first hex digit
  61.     MOV    DL,DH            ;Get lower nibble into DL
  62.     AND    DL,0Fh            ;Remove the upper nibble
  63.     CALL    WRITE_HEX_DIGIT        ;Display second hex digit
  64.     POP    DX
  65.     POP    CX
  66.     RET
  67. WRITE_HEX    ENDP
  68.  
  69.     PUBLIC    WRITE_HEX_DIGIT
  70. ;-----------------------------------------------------------------------;
  71. ; This procedure converts the lower 4 bits of DL to a hex digit and    ;
  72. ; writes it to the screen.                        ;
  73. ;                                    ;
  74. ; On entry:    DL    Lower 4 bits contain number to be printed    ;
  75. ;            in hex.                        ;
  76. ;                                    ;
  77. ; Uses:        WRITE_CHAR                        ;
  78. ;-----------------------------------------------------------------------;
  79. WRITE_HEX_DIGIT        PROC
  80.     PUSH    DX            ;Save registers used
  81.     CMP    DL,10            ;Is this nibble <10?
  82.     JAE    HEX_LETTER        ;No, convert to a letter
  83.     ADD    DL,"0"            ;Yes, convert to a digit
  84.     JMP    Short WRITE_DIGIT    ;Now write this character
  85. HEX_LETTER:
  86.     ADD    DL,"A"-10        ;Convert to hex letter
  87. WRITE_DIGIT:
  88.     CALL    WRITE_CHAR        ;Display the letter on the screen
  89.     POP    DX            ;Restore old value of DX
  90.     RET
  91. WRITE_HEX_DIGIT        ENDP
  92.  
  93.     PUBLIC    INIT_WRITE_CHAR
  94. ;-----------------------------------------------------------------------;
  95. ; You need to call this procedure before you call WRITE_CHAR since    ;
  96. ; WRITE_CHAR uses information set by this procedure.            ;
  97. ;                                    ;
  98. ; Writes:    SCREEN_SEG                        ;
  99. ;-----------------------------------------------------------------------;
  100. INIT_WRITE_CHAR        PROC
  101.     PUSH    AX
  102.     PUSH    BX
  103.     MOV    BX,0B800h        ;Set for color graphics display
  104.     INT    11h            ;Get equipment information
  105.     AND    AL,30h            ;Keep just the video display type
  106.     CMP    AL,30h            ;Is this a monochrome display adapter?
  107.     JNE    SET_BASE        ;No, it's color, so use B800
  108.     MOV    BX,0B800h        ;Yes, it's monochrome, so use B000
  109. SET_BASE:
  110.     MOV    SCREEN_SEG,BX        ;Save the screen segment
  111.     POP    BX
  112.     POP    AX
  113.     RET
  114. INIT_WRITE_CHAR        ENDP
  115.  
  116.     PUBLIC    WRITE_CHAR
  117.     EXTRN    CURSOR_RIGHT:PROC
  118. ;-----------------------------------------------------------------------;
  119. ; This procedure outputs a character to the screen by writing directly    ;
  120. ; into screen memory, so that characters such as the backspace are    ;
  121. ; treated as any other characters and are displayed.            ;
  122. ;                                    ;
  123. ; This procedure must do a bit of work to update the cursor position.    ;
  124. ;                                    ;
  125. ; On entry:    DL    Byte to print on screen.            ;
  126. ;                                    ;
  127. ; Uses:        CURSOR_RIGHT                        ;
  128. ; Reads:    SCREEN_SEG, SCREEN_PTR                    ;
  129. ;-----------------------------------------------------------------------;
  130. WRITE_CHAR    PROC
  131.     PUSH    AX
  132.     PUSH    BX
  133.     PUSH    DX
  134.     PUSH    ES
  135.  
  136.     MOV    AX,SCREEN_SEG        ;Get segment for screen memory
  137.     MOV    ES,AX            ;Point ES to screen memory
  138.     MOV    BX,SCREEN_PTR        ;Pointer to character in screen memory
  139.  
  140.     MOV    DH,7            ;Use the normal attribute
  141.     MOV    ES:[BX],DX        ;Write character/attribute to screen
  142.     CALL    CURSOR_RIGHT        ;Now move to next cursor position
  143.  
  144.     POP    ES
  145.     POP    DX
  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. ; On entry:    DX    N : 16-bit, unsigned number.            ;
  156. ;                                    ;
  157. ; Uses:        WRITE_HEX_DIGIT                        ;
  158. ;-----------------------------------------------------------------------;
  159. WRITE_DECIMAL    PROC
  160.     PUSH    AX            ;Save registers used here
  161.     PUSH    CX
  162.     PUSH    DX
  163.     PUSH    SI
  164.     MOV    AX,DX
  165.     MOV    SI,10            ;Will divide by 10 using SI
  166.     XOR    CX,CX            ;Count of digits placed on stack
  167. NON_ZERO:
  168.     XOR    DX,DX            ;Set upper word of N to 0
  169.     DIV    SI            ;Calculate N/10 and (N mod 10)
  170.     PUSH    DX            ;Push one digit onto the stack
  171.     INC    CX            ;One more digit added
  172.     OR    AX,AX            ;N = 0 yet?
  173.     JNE    NON_ZERO        ;Nope, continue
  174. WRITE_DIGIT_LOOP:
  175.     POP    DX            ;Get the digits in reverse order
  176.     CALL    WRITE_HEX_DIGIT
  177.     LOOP    WRITE_DIGIT_LOOP
  178. END_DECIMAL:
  179.     POP    SI
  180.     POP    DX
  181.     POP    CX
  182.     POP    AX
  183.     RET
  184. WRITE_DECIMAL    ENDP
  185.  
  186.     PUBLIC    WRITE_CHAR_N_TIMES
  187. ;-----------------------------------------------------------------------;
  188. ; This procedure writes more than one copy of a character        ;
  189. ;                                    ;
  190. ; On entry:    DL    Character code                    ;
  191. ;        CX    Number of times to write the character        ;
  192. ;                                    ;
  193. ; Uses:        WRITE_CHAR                        ;
  194. ;-----------------------------------------------------------------------;
  195. WRITE_CHAR_N_TIMES    PROC
  196.     PUSH    CX
  197. N_TIMES:
  198.     CALL    WRITE_CHAR
  199.     LOOP    N_TIMES
  200.     POP    CX
  201.     RET
  202. WRITE_CHAR_N_TIMES    ENDP
  203.  
  204.  
  205.     PUBLIC    WRITE_ATTRIBUTE_N_TIMES
  206.     EXTRN    CURSOR_RIGHT:PROC
  207. ;-----------------------------------------------------------------------;
  208. ; This procedure sets the attribute for N characters, starting at the    ;
  209. ; current cursor position.                        ;
  210. ;                                    ;
  211. ;    CX    Number of characters to set attribute for        ;
  212. ;    DL    New attribute for characters                ;
  213. ;                                    ;
  214. ; Uses:        CURSOR_RIGHT                        ;
  215. ; Reads:    SCREEN_SEG, SCREEN_PTR                    ;
  216. ;-----------------------------------------------------------------------;
  217. WRITE_ATTRIBUTE_N_TIMES        PROC
  218.     PUSH    AX
  219.     PUSH    CX
  220.     PUSH    DI
  221.     PUSH    ES
  222.  
  223.     MOV    AX,SCREEN_SEG        ;Set ES to point to screen segment
  224.     MOV    ES,AX
  225.     MOV    DI,SCREEN_PTR        ;Character under cursor
  226.     INC    DI            ;Point to the attribute under cursor
  227.     MOV    AL,DL            ;Put attribute into AL
  228. ATTR_LOOP:
  229.     STOSB                ;Save one attribute
  230.     INC    DI            ;Move to next attribute
  231.     INC    SCREEN_X        ;Move to next column
  232.     LOOP    ATTR_LOOP        ;Write N attributes
  233.  
  234.     DEC    DI            ;Point to start of next character
  235.     MOV    SCREEN_PTR,DI        ;Remember where we are
  236.  
  237.     POP    ES
  238.     POP    DI
  239.     POP    CX
  240.     POP    AX
  241.     RET
  242. WRITE_ATTRIBUTE_N_TIMES    ENDP
  243.  
  244.  
  245.     PUBLIC    WRITE_PATTERN
  246. ;-----------------------------------------------------------------------;
  247. ; This procedure writes a line to the screen, based on data in the    ;
  248. ; form                                    ;
  249. ;                                    ;
  250. ;    DB    {character, number of times to write character}, 0    ;
  251. ; Where {x} means that x can be repeated any number of times        ;
  252. ;                                    ;
  253. ; On entry:    DS:DX    Address of the pattern to draw            ;
  254. ;                                    ;
  255. ; Uses:        WRITE_CHAR_N_TIMES                    ;
  256. ;-----------------------------------------------------------------------;
  257. WRITE_PATTERN    PROC
  258.     PUSH    AX
  259.     PUSH    CX
  260.     PUSH    DX
  261.     PUSH    SI
  262.     PUSHF                ;Save the direction flag
  263.     CLD                ;Set direction flag for increment
  264.     MOV    SI,DX            ;Move offset into SI register for LODSB
  265. PATTERN_LOOP:
  266.     LODSB                ;Get character data into AL
  267.     OR    AL,AL            ;Is it the end of data (0h)?
  268.     JZ    END_PATTERN        ;Yes, return
  269.     MOV    DL,AL            ;No, set up to write character N times
  270.     LODSB                ;Get the repeat count into AL
  271.     MOV    CL,AL            ;And put in CX for WRITE_CHAR_N_TIMES
  272.     XOR    CH,CH            ;Zero upper byte of CX
  273.     CALL    WRITE_CHAR_N_TIMES
  274.     JMP    PATTERN_LOOP
  275. END_PATTERN:
  276.     POPF                ;Restore direction flag
  277.     POP    SI
  278.     POP    DX
  279.     POP    CX
  280.     POP    AX
  281.     RET
  282. WRITE_PATTERN    ENDP
  283.  
  284.     END
  285.