home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / utils / asmutl / asmlib.lbr / SETATT.AZM / SETATT.ASM
Encoding:
Assembly Source File  |  1991-06-25  |  3.9 KB  |  141 lines

  1. ;----------------------------------------------------------------
  2. ;         This is a module in the ASMLIB Library.
  3. ;
  4. ; This module takes the accumulator and uses it to index into an 
  5. ; internal table of screen attributes that are sent to the screen. 
  6. ; If an attribute is already set then it is cleared first before a 
  7. ; new attribute is set. This function is also used by the formin 
  8. ; routine for its video attribute setting.
  9. ; This module also is patchable by external routines so that screen
  10. ; attributes for different terminals are customizable.
  11. ;
  12. ; The tname routine returns the current terminal driver name
  13. ; which is exactly 6 ascii characters long
  14. ;
  15. ; Current attributes supported are
  16. ; 00    Default state, no attributes. Clear current attribute.
  17. ; 01    1/2 intensity characters.
  18. ; 02    Blinking characters.
  19. ; 03    Reverse characters.
  20. ; 04     Underline.
  21. ;
  22. ;            Written        R.C.H.    6/9/83
  23. ;            Last Update        R.C.H.    22/11/83
  24. ;----------------------------------------------------------------
  25. ;
  26.     name    'setatt'
  27. ;
  28.     public    setatt,tname
  29.     extrn    coe
  30.     maclib    z80
  31. ;
  32. numatt    equ    7        ; Number of attributes supported
  33. ;
  34. tname    lxi    h,termnam
  35.     ret
  36. ;
  37. setatt:
  38.     cpi    numatt        ; In range ??
  39.     rnc            ; Return wit tail B/N legs if too big
  40.     push    d
  41.     push    b
  42.     push    h
  43.     push    psw        ; Save the users attribute
  44.     lda    curatt        ; Get the current attribute
  45.     ora    a
  46.     jrz    doatt        ; If 00, no need to clear old one
  47. ; Here we must clear the old attribute before proceeding.
  48.     dcr    a        ; Make the attribute in range
  49.     lxi    h,attclr    ; Point to the tbale of clear atts.
  50.     call    index
  51.     call    att$send    ; Send the attributes -> by HL
  52. doatt:
  53.     pop    psw        ; Get users attribute
  54.     sta    curatt        ; Save in ram.
  55.     ora    a        ; Is it attribute 00 ?
  56.     jrz    set$end        ; Ignore if so
  57.     dcr    a        ; Make in the correct range then
  58. ; Now index into the table of attribute setting bytes to get the req'd code.
  59.     lxi    h,attset    ; Point to start
  60.     call    index        ; Get hl -> start
  61.     call    att$send    ; Send attributes -> by HL
  62. ; Re-load registers and return.
  63. set$end:
  64.     pop    h
  65.     pop    b
  66.     pop    d
  67.     ret
  68. ;
  69. ; This routine must use HL -> a counter byte to send the proceeeding bytes
  70. ; to the console.
  71. ;
  72. att$send:    
  73.     mov    a,m
  74.     ora    a        ; See if a null length ?
  75.     rz            ; Return if a null string
  76.     mov    b,a        ; Else load the length
  77. sloop:
  78.     inx    h        ; Point to next character
  79.     mov    a,m
  80.     call    coe        ; Send
  81.     djnz    sloop
  82.     ret
  83. ;
  84. ; This routine that follows simply indexes into the table 
  85. ; of bytes. Each table entry is assumed to be 5 bytes long.
  86. ;
  87. ; On entry hl -> start of table, on exit hl -> first element in line (a)
  88. ;
  89. index:    
  90.     ora    a
  91.     rz            ; Return if no loops needed
  92.     mvi    d,0        ; Clear upper register
  93.     mov    e,a        ; Load counter
  94. ; Multiply A by 5 then add to HL
  95.     add    a        ; * 2 (double original)
  96.     add    a        ; * 4
  97.     add    e        ; * 5 (add original)
  98.     mov    e,a        ; load into indexing register
  99.     dad    d        ; now HL -> start of this entry
  100.     ret            ; hl -> start of a line
  101.  
  102. ; ~~~~ The following table of bytes is used to SET a video attribute. ~~~~
  103. ;
  104. setid:
  105.     db    0ffh,01ah,0ffh,01ah,00        ; this flags the set att. table
  106. termnam:
  107.     db    'ABM 85'        ; 6 bytes allowed for terminal name
  108. attset:
  109.     db    2,01bh,029h,00,00    ; Start half intensity
  110.     db    2,01bh,05eh,00,00    ; Start blinking
  111.     db    2,01bh,06ah,00,00    ; Start reverse video
  112.     db    2,01bh,06ch,00,00    ; Start underline
  113.     db    00,00,00,00,00        ; extra for later
  114.     db    00,00,00,00,00        ; extra for later
  115.     db    0ffh            ; end table flag
  116. ;
  117. ; ~~~~ The following table of bytes is used to CLEAR video attributes ~~~~
  118. ;
  119. clrid:
  120.     db    0ffh,01ah,0ffh,1ah,01    ; This flags the clear att. table
  121. attclr:
  122.     db    02,01bh,028h,00,00    ; End half intensity
  123.     db    02,01bh,071h,00,00    ; End blinking
  124.     db    02,01bh,06bh,00,00    ; End reverse video
  125.     db    02,01bh,06dh,00,00    ; End underline
  126.     db    00,00,00,00,00        ; extra for later
  127.     db    00,00,00,00,00        ; extra for later
  128.     db    0ffh            ; end table flag
  129. ;
  130. ; Data variables / flag storage next
  131. ;
  132.     dseg                
  133. ;
  134. curatt    db    00            ; Current attribute in use
  135. ;
  136. ;
  137.     end
  138.  
  139.  
  140.  
  141.