home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / asmutil / 80x0393.zip / COLPRINT.ASM < prev    next >
Assembly Source File  |  1993-03-30  |  4KB  |  122 lines

  1. ; Routine by Rob Green.  
  2. ; Released to the Public Domain on Feb. 20th 1993.
  3. ;
  4.  
  5.                 .MODEL   small
  6.                 .code
  7. ;==============================================================
  8. ; This routine displays a string at the current cursor location
  9. ; DS:DX point to the string to display.  If a #0 is found, then
  10. ; the next byte is the attribute.  the string is '$' terminated
  11. ;
  12.  
  13. Attrib  Db  07
  14. X       Db  00
  15. Y       Db  00
  16.  
  17. Print  proc near
  18.         push ax            ; Save registers.. Dont want to
  19.         push bx            ; be like Microsoft
  20.         push cx
  21.         push si
  22.         push dx
  23.         push ds
  24.         mov ah,3           ; Gets the current cursor
  25.         mov bh,0           ; Location, so we know were
  26.         int 010h           ; to print
  27.         mov x,dl           ; and save
  28.         mov y,dh
  29.         pop ds
  30.         pop dx
  31.         push dx
  32.         cld                ; Not needed but habit ;)
  33.         mov si,dx          ; and setup our counter
  34.  
  35.  
  36. GetChr: mov al,ds:[si]     ; Get character,  LODSB wouldnt
  37.                            ; work for some reason
  38.         inc si             ; Inc pointer
  39.         cmp al,0           ; Is it an attribute?
  40.         jz Attr            ; Yes, change the Attrib.
  41.         cmp al,'$'         ; Is it end of String
  42.         jz endStr          ; Yes, do cleanup
  43.         cmp al,0dh         ; Is it Enter?
  44.         jne @@1            ; No, check for LF
  45.         mov x,0            ; Enter puts the cursor at begining of
  46.                            ; line
  47.         jmp short getchr   ; Dont print, 010h/09h prints literals only
  48.    @@1: cmp al,0ah         ; Is it a LF
  49.         jne @@2            ; No, go print
  50.         inc y              ; Linefeeds advances the cursor row
  51.         cmp y,26  ;decimal ; Check to see if time for a scroll
  52.         jne getchr         ; I omitted this code..
  53.         mov y,25           ; This takes into account of
  54.                            ; scrolling (decimal)
  55.                            ; Scrolling routine omitted
  56.         jmp short getchr   ; And dont print lf, literals only
  57.    @@2: push si            ; This was causing me trouble!!
  58.         push ax            ; I kept getting trash on the screen
  59.         push bx            ; and i couldnt figure out why
  60.         push dx            ; amazing what can happen by just saving
  61.         mov ah,02h         ; the registers..  like work ;)
  62.         mov bh,0h          ; This sets the cursor location before print
  63.         mov dh,y
  64.         mov dl,x
  65.         int 010h
  66.         pop dx             ;I wish Dos wouldnt trash the registers!!!
  67.         pop bx             ;
  68.         pop ax             ;
  69.         push dx            ;
  70.         push bx            ;
  71.         push ax            ;
  72.         mov ah,09h         ; And this prints a character to the
  73.         mov bh,0           ; screen
  74.         mov bl,attrib
  75.         mov cx,1
  76.         int 010h
  77.         pop ax
  78.         pop bx
  79.         pop dx
  80.         inc x              ; Increments the Column
  81.         pop si
  82.         jmp short getchr   ; And do it all over again
  83.  
  84. ; Changes the attribute
  85. attr:   mov al,ds:[si]
  86.         inc si
  87.         mov attrib,al
  88.         jmp short getchr
  89.  
  90. ; got a '$' and ready to RET
  91. endstr:
  92.         pop dx
  93.         pop si
  94.         pop cx
  95.         pop bx
  96.         pop ax
  97.         ret
  98. print endp
  99.  
  100. start proc far
  101.    push ds
  102.    xor ax,ax
  103.    push ax
  104.    mov ax,@data
  105.    mov ds,ax
  106.    mov es,ax
  107.    mov dx,offset testmsg
  108.    call print
  109.    mov ax,04c00h
  110.    int 021h
  111. start endp
  112.  
  113. .data
  114.  
  115. testMsg db 0,0eh,'Yellow ',0,1eh,'Yellow/Blue ',0,08eh,'Blinking Yellow'
  116.         db 0,04h,0dh,0ah,'This is in Red',0dh,0ah
  117.         db 0,0fh,'This is in White'
  118.         db '$'
  119.  
  120. .stack 0200h
  121.      end start
  122.