home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / mslang / as / c-prnt.asm < prev    next >
Assembly Source File  |  1984-12-13  |  13KB  |  475 lines

  1.       PAGE   60,132
  2. ;  prnt.ASM   06/25/84 update 10/16/84 sas
  3. ;  Subroutine called by a basic program to print a string .
  4. ;
  5. ; ************** THIS IS THE CBASIC VERSION OF PRNT ******************
  6. ;
  7.     TITLE    PRNT
  8.     NAME    PRNT
  9. CGROUP    GROUP    CODESEG
  10. ;
  11. CODESEG SEGMENT PARA PUBLIC 'CODE'
  12.     ASSUME    CS:CGROUP,DS:CGROUP
  13.     PUBLIC    PRNT
  14. ;
  15. COLOR    EQU    0B800H        ;seg address of color adaptor memory
  16. MONO    EQU    0B000H        ;seg address of color adaptor memory
  17. CRTCA    EQU    3D4h        ;port address of 6845 crt controller addr reg
  18. CRTCD    EQU    3D5h        ;port address of 6845 crt controller data reg
  19. CRTSTAT EQU    03DAh        ;crt status port address
  20. VSYNC    EQU    08h        ;crt vertical retrace status bit map
  21. PORTB    EQU    61h        ;I/O Port B
  22. MAG_NUM EQU    10110110b    ;special number for port B initialize
  23. TIME_2A EQU    43h        ;timer 2
  24. TIME_2B EQU    42h        ;timer 2
  25. TONE_CH EQU    1200d        ;frequency of tone to use
  26. ;
  27. FUNCT    DB    ?        ;function number
  28. FG_COLR DB    ?        ;forground color
  29. BG_COLR DB    ?        ;backround color
  30. T_FORG    DW    ?        ;forground color of field on entry
  31. T_BACK    DW    ?        ;backround color of field on entry
  32. ROW    DB    ?        ;upper left row
  33. COL    DB    ?        ;upper left column
  34. LENG    DW    ?        ;length of string
  35. STRG_AD DW    ?        ;address of string in DS
  36. STRING    DW    256 DUP(00)
  37. ATTRIB    DB    ?        ;attribute byte to use
  38. REPTC    DW    1        ;number of times to repeat each character
  39. REPTWD    DB    1        ;number of times to repeat each string
  40. ER_DUR    DW    500d
  41. ;
  42. PRNT    PROC    NEAR
  43.     PUSH    BP        ;BP unknown (don't care)
  44.     MOV    BP,SP        ;set base for parm list
  45.     PUSH    DS        ;DS -> basic work area
  46.     PUSH    ES        ;ES -> basic work area
  47. ;
  48. ; get the integer function number,string length,and string address from
  49. ; the call. the string address is in the extra segment.
  50. ;
  51.     PUSH    BP
  52.     MOV    AL,SS:[BP+4]    ;get addr of parameter
  53.     MOV    FUNCT,AL
  54.     MOV    SI,SS:[BP+6]    ;get addr of parameter
  55.     MOV    AH,ES:[SI]    ;get value of parm
  56.     MOV    AL,ES:[SI+1]    ;get value of parm
  57.     MOV    LENG,AX
  58.     ADD    SI,2        ;get value of parm
  59.     MOV    STRG_AD,SI
  60. ;
  61. ;   repeat function
  62. ;   check for character & string repitition -1 through -80 & -81 through -160
  63. ;
  64.     MOV    REPTC,1     ;set char repeat to 1
  65.     MOV    REPTWD,1    ;set string repeat to 1
  66.     CMP    FUNCT,0     ;are you requesting function repeat function
  67.     JGE    TYP3        ;if => 0 then check for function 1
  68.     NEG    FUNCT        ;convert the negitive function to positive
  69.     CMP    FUNCT,80d    ;are you requesting a repeat string function
  70.     JG    WD_REP        ;if yes the goto repeat string code
  71. ;
  72.     XOR    AX,AX
  73.     MOV    AL,FUNCT    ;move the number of repeat character to
  74.     MOV    REPTC,AX    ;  the repeat character indicator
  75.     JMP    WD_OUT        ;jump out of block
  76. ;
  77. WD_REP: SUB    FUNCT,80d    ;subtract 80 from value
  78.     MOV    AL,FUNCT    ;set number of times to repeat the string
  79.     MOV    REPTWD,AL    ;    in repeat string variable
  80. WD_OUT: MOV    FUNCT,3     ;force function to 3
  81. ;
  82. ;    function 3 send row,col and color/ full data print all prams specified.
  83. ;
  84. TYP3:
  85.     CMP    FUNCT,8
  86.     JE    TYP8
  87. R2A:    MOV    AL,SS:[BP+8]   ;get addr of parameter
  88.     CMP    AL,0
  89.     JE    R3
  90.     SUB    AL,1
  91.     MOV    ROW,AL
  92. R3:    MOV    AX,SS:[BP+10]    ;get addr of parameter
  93.     CMP    AL,0
  94.     JE    R4
  95.     CMP    FUNCT,6
  96.     JNE    R3A
  97.     MOV    ER_DUR,AX
  98.     JMP    R3B
  99. R3A:    SUB    AL,1
  100.     MOV    COL,AL
  101. R3B:    CMP    FUNCT,7
  102.     JE    TYP7
  103. R4:    MOV    AL,SS:[BP+12]    ;get addr of parameter
  104.     MOV    FG_COLR,AL
  105.     MOV    AL,SS:[BP+14]    ;get addr of parameter
  106.     MOV    BG_COLR,AL
  107.     CALL    GET_ATB
  108.     JMP    CAL_IT
  109. ;
  110. ;    for function 7 send address of colors
  111. ;
  112. TYP7:    MOV    SI,SS:[BP+12]    ;get addr of parameter
  113.     MOV    AX,[SI]
  114.     MOV    FG_COLR,AL
  115.     MOV    SI,SS:[BP+14]    ;get addr of parameter
  116.     MOV    AX,[SI]
  117.     MOV    BG_COLR,AL
  118.     CALL    GET_ATB
  119. ;
  120. ;   set border color through bios call 10 function 11
  121. ;
  122. TYP8:    MOV    AL,SS:[BP+14]    ;get value of color
  123.     MOV    BL,AL
  124.     MOV    BH,0        ;set palette to 0
  125.     MOV    AH,11        ;load function number
  126.     INT    10h        ;make bios call
  127.     JMP    FINISH
  128. ;
  129. ;   set up address of string form basica and my data area string
  130. ;
  131. CAL_IT:
  132.     MOV    SI,[STRG_AD]    ;set address of string in si
  133.     LEA    DI,STRING    ;load address of my data area string
  134.     MOV    CX,LENG     ;set loop counter to length of string
  135.     MOV    AH,ATTRIB    ;set color attribute
  136. ;
  137. ;   check for null string
  138. ;
  139.     MOV    AL,ES:[SI]    ;move character to al
  140.     CMP    AL,00        ;is the character a null
  141.     JE    FINISH        ;if yes then return
  142.     CMP    CX,0        ;is the length 0
  143.     JE    FINISH        ;if yes then return
  144. ;
  145. ;   move string from basic data area to my data area
  146. ;
  147. MOV_STR:MOV    AL,ES:[SI]    ;move character from basic to al
  148.     MOV    DS:[DI],AX    ;move character/attribute to my data area
  149.     INC    SI
  150.     INC    DI
  151.     INC    DI
  152.     LOOP    MOV_STR
  153. ;
  154. ;
  155. ;  determine if color or mono adaptor, and set ES to adaptor's address
  156.     CALL    VIDEO
  157. ;
  158. ;              --- calls for function 5 ---
  159. ;
  160.     CMP    FUNCT,5
  161.     JNE    F6
  162.     CALL    CENT        ;find center of line
  163.     CALL    GET_CR        ;find offset into video buffer
  164.     CALL    PT_STG        ;print the string
  165.     JMP    FINISH
  166. ;
  167. ;              --- calls for function 6 ---
  168. ;
  169. F6:    CMP    FUNCT,6
  170.     JNE    FOUT
  171.     CALL    CENT        ;find center of line
  172.     CALL    GET_CR        ;find offset into video buffer
  173.     CALL    PT_STG        ;print the string
  174.     CALL    ERR        ;make tone at speaker
  175.     MOV    CX,ER_DUR    ;set duration of display
  176. F6A:    PUSH    CX        ;loop the print cycle for the number
  177.     CALL    GET_CR        ;   of cycles in the duration
  178.     CALL    PT_STG
  179.     POP    CX
  180.     LOOP    F6A
  181. ;            blank the string
  182.     LEA    DI,STRING    ;get address of the string
  183.     MOV    CX,LENG     ;set length
  184. BLANK:    MOV    AX,DS:[DI]    ;mov char/attrib to ax
  185.     MOV    AL,32        ;mov blank to cahr part
  186.     MOV    DS:[DI],AX    ;store it
  187.     INC    DI
  188.     INC    DI
  189.     LOOP    BLANK
  190.     CALL    GET_CR        ;get offset into video buffer
  191.     CALL    PT_STG        ;clear the error message
  192.     JMP    FINISH
  193. ;
  194. ;        ---------- calls for all other functions ---------
  195. ;
  196. FOUT:    CALL    GET_CR
  197.     CMP    FUNCT,4
  198.     JNE    C1
  199.     CALL    RD_STG
  200.     JMP    FINISH
  201. ;
  202. C1:    CMP    FUNCT,7
  203.     JNE    C2
  204.     CALL    GET_CLR
  205. ;
  206. C2:    CALL    PT_STG
  207. ;
  208. ;      get correct return numbers
  209. ;
  210. FINISH: POP    BP
  211.     CMP    FUNCT,0
  212.     JE    RET12
  213. ;
  214. ;
  215.     CMP    FUNCT,1
  216.     JE    RET12
  217. ;
  218.     CMP    FUNCT,2
  219.     JE    RET12
  220. ;
  221.     CMP    FUNCT,3
  222.     JE    RET12
  223. ;
  224.     CMP    FUNCT,4
  225.     JE    RET8A
  226. ;
  227.     CMP    FUNCT,5
  228.     JE    RET12
  229. ;
  230.     CMP    FUNCT,6
  231.     JE    RET12
  232. ;
  233.     CMP    FUNCT,7
  234.     JE    RET12A
  235. ;
  236.     CMP    FUNCT,8
  237.     JE    RET12
  238. ;
  239. ;
  240. ;           function 5 passing the string back to basic.
  241. ;
  242. RET8A:    POP    ES        ;get back basic es
  243.     MOV    SI,[STRG_AD]    ;get address of basic string
  244.     LEA    DI,STRING    ;get address of my string
  245.     MOV    CX,LENG     ;get length of string
  246. RESET:    MOV    AX,DS:[DI]    ;move char of my string to ax
  247.     MOV    ES:[SI],AX    ;move ax to basic string
  248.     INC    SI
  249.     INC    DI
  250.     LOOP    RESET
  251.     POP    DS
  252.     POP    BP
  253.     RET    12        ;return to basic
  254. ;
  255. ;
  256. RET12:    POP    ES
  257.     POP    DS
  258.     POP    BP
  259.     RET    12        ;return to basic
  260.  
  261. RET12A:
  262.     POP    ES
  263.     MOV    AX,T_FORG    ;get addr of parameter
  264.     MOV    SI,SS:[BP+12]    ;get addr of parameter
  265.     MOV    ES:[SI],AX    ;get value of parm
  266.     MOV    AX,T_BACK    ;get addr of parameter
  267.     MOV    SI,SS:[BP+14]    ;get addr of parameter
  268.     MOV    ES:[SI],AX    ;get value of parm
  269.     POP    DS
  270.     POP    BP
  271.     RET    12        ;return to basic
  272. PRNT    ENDP
  273. ;
  274. ;--------------------------------------------------------------------
  275. ;    PRINT CHARACTER STRING AT ROW,COL WITH FG,BG COLORS
  276. ;
  277. PT_STG    PROC    NEAR
  278.     XOR    CX,CX
  279.     MOV    CL,REPTWD    ;set up loop counter for repeat word
  280. NXT_WD: PUSH    CX        ;save count
  281.     MOV    CX,LENG     ;set up count for number of characters in string
  282.     LEA    DI,STRING    ;load address of my string
  283. ;
  284. ;    wait until vertical retrace
  285. ;
  286.     MOV    DX,CRTSTAT
  287. CRETRC: IN    AL,DX
  288.     TEST    AL,VSYNC
  289.     JZ    CRETRC
  290. ;
  291. NXT_CHR:PUSH    CX        ;save character count
  292.     MOV    BX,DS:[DI]    ;move character from string to bx
  293.     MOV    CX,REPTC    ;set up count for repeat character
  294. REP_CHR:MOV    ES:[SI],BX    ;move character to video buffer
  295.     INC    SI
  296.     INC    SI
  297.     LOOP    REP_CHR     ;loop to repeat character
  298.     INC    DI
  299.     INC    DI
  300.     POP    CX        ;restore character count
  301.     LOOP    NXT_CHR     ;loop for next character
  302.     POP    CX        ;restore count for repeat string
  303.     LOOP    NXT_WD        ;loop to repeat the string
  304.     RET
  305. PT_STG    ENDP
  306. ;---------------------------------------------------------------------
  307. ;---------------------------------------------------------------------
  308. ;    READ IN CHARACTERS FROM SCREEN
  309. ;
  310. RD_STG    PROC    NEAR
  311.     LEA    DI,STRING    ;set address of string in si
  312.     MOV    CX,LENG     ;set loop counter to length of string
  313. ;
  314. RD_LIN:
  315.     MOV    AX,ES:[SI]    ;move character/attribute from video buffer to ax
  316.     MOV    DS:[DI],AL    ;move character to my data area
  317.     INC    DI
  318.     INC    SI
  319.     INC    SI
  320.     LOOP    RD_LIN        ;loop to next character
  321.     RET
  322. RD_STG    ENDP
  323. ;---------------------------------------------------------------------
  324. GET_ATB PROC    NEAR
  325.     MOV    AL,FG_COLR    ;move foreground color to bx
  326.     MOV    AH,BG_COLR    ;move backround color to bx
  327.     CMP    AL,15        ;check for color > 15 ie blinking
  328.     JG    BLNK        ;if > 15 then set blink bit
  329.     AND    AL,15        ;set normal fg color
  330.     JMP    N_BLNK        ;
  331. BLNK:    OR    AL,128        ;set blink bit 7
  332.     AND    AL,143        ;zero out bit 6,5,4 used for backround
  333. N_BLNK: AND    AH,7        ;zero out bit 7,6,5,4,3 used for forground
  334.     MOV    CL,4        ;4 bit shift count
  335.     SHL    AH,CL        ;shift right 3 bits to pos 6,5,4
  336.     OR    AL,AH        ;combine for & back to form attribute byte
  337.     MOV    ATTRIB,AL    ;move it to STORAGE
  338.     RET
  339. GET_ATB ENDP
  340. ;---------------------------------------------------------------------
  341. ;
  342. ;  compute starting offset into display buffer
  343. ;
  344. GET_CR    PROC    NEAR
  345.     XOR    AX,AX
  346.     MOV    AL,ROW        ;move starting row to al
  347.     MOV    BX,160        ;move number of character/row to bx
  348.     MUL    BX        ;multiply by 160
  349.     XOR    CX,CX
  350.     MOV    CL,COL        ;move starting column number to cl
  351.     ADD    AX,CX        ;add (scol * 2) to get relative offset
  352.     ADD    AX,CX
  353.     MOV    SI,AX        ;SI offsets VIDEO buffers
  354.     RET
  355. GET_CR    ENDP
  356. ;---------------------------------------------------------------------
  357. ;
  358. ;  determine if color or mono adaptor, and set ES to adaptor's address
  359. ;
  360. VIDEO    PROC    NEAR
  361.     PUSH    DS        ;save DS -> my data
  362.     MOV    AX,0        ;set up data seg register ..
  363.     MOV    DS,AX        ;..to gain access to DOS info
  364.     MOV    SI,410H     ;offset to color/mono byte
  365.     MOV    AL,[SI]     ;fetch byte
  366.     POP    DS        ;restore DS -> my data
  367.     AND    AL,48        ;mask
  368.     CMP    AL,48        ;48=mono, 32=color
  369.     JZ    SETMNO
  370.     MOV    AX,COLOR    ;add seg addr of page 0
  371.     JMP    SETES
  372. SETMNO: MOV    AX,MONO
  373. SETES:    MOV    ES,AX        ;now ES -> adaptor memory
  374.     RET
  375. VIDEO    ENDP
  376. ;---------------------------------------------------------------------
  377. ;   calculate column for centering a stripped string
  378. ;
  379. CENT    PROC    NEAR
  380. ;
  381. ;    find number of leading blanks
  382. ;
  383.     XOR    CX,CX        ;zero out CX
  384.     LEA    DI,STRING    ;load address of string
  385. C_R0:    CMP    CX,LENG     ;are you at end of string
  386.     JE    C_R2        ;if yes then out
  387.     MOV    AX,DS:[DI]    ;load character to ax
  388.     CMP    AL,20H        ;is it a blank
  389.     JNE    C_R2        ;if not a blank then out
  390.     INC    CX        ;index 1
  391.     INC    DI        ;index 2
  392.     INC    DI
  393.     JMP    C_R0        ;loop it
  394. ;
  395. ;    find number of trailing blanks
  396. ;
  397. C_R2:    PUSH    CX        ;save number of blanks on stack
  398.     LEA    DI,STRING    ;load address of string
  399.     ADD    DI,LENG     ;add length to address
  400.     ADD    DI,LENG     ;add length to address
  401.     SUB    DI,2        ;index back 2
  402.     XOR    CX,CX        ;zero CX
  403. C_R3:    MOV    AX,DS:[DI]    ;move character to AX
  404.     CMP    AL,20H        ;is it a blank
  405.     JNE    C_R4        ;if not then out
  406.     INC    CX        ;add 1 ti cx
  407.     DEC    DI        ;move back one character
  408.     DEC    DI
  409.     JMP    C_R3        ;loop it
  410. ;
  411. ;    calculate column position for centering
  412. ;    column = ((80-(length-trail-lead))/2)-lead
  413. ;
  414. C_R4:    MOV    AX,LENG     ;load length
  415.     SUB    AX,CX        ;subtract number of trailing blanks
  416.     POP    CX        ;get number of leading blanks
  417.     SUB    AX,CX        ;subtract number of leading blanks
  418.     MOV    BX,80        ;load screen width
  419.     SUB    BX,AX        ;subtract out adjusted length
  420.     SAR    BX,1        ;divide by 2
  421.     SUB    BX,CX        ;subtract number of leading blanks
  422.     MOV    COL,BL        ;set column
  423.     RET
  424. CENT    ENDP
  425. ;-----------------------------------------------------------------------
  426. ;        error tone for speaker
  427. ERR    PROC    NEAR
  428. ;     tone control of speaker
  429.     MOV    AL,MAG_NUM    ;put magic number
  430.     OUT    TIME_2A,AL    ;    into timer2
  431. ;
  432. ;     the constant put in ax changes the pitch
  433. ;
  434. TONE:    MOV    AX,TONE_CH    ;move 1/pitch into ax
  435.     OUT    TIME_2B,AL    ;LSB into timer2
  436.     MOV    AL,AH        ;MSB to AL then
  437.     OUT    TIME_2B,AL    ;  to timer2
  438. ;
  439.     IN    AL,PORTB    ;read port B into AL
  440.     MOV    AH,AL        ;save original in AH
  441.     OR    AL,3        ;turn on bits 0 and 1
  442.     OUT    PORTB,AL    ;turn on speaker
  443. ;
  444.     SUB    CX,CX        ;set up loop count
  445. WAIT:    LOOP    WAIT        ;delay
  446. ;
  447.     MOV    AL,AH
  448.     OUT    PORTB,AL    ;turn off speaker
  449.  ;
  450.     RET
  451.  
  452. ERR    ENDP
  453. ;---------------------------------------------------------------------
  454. ;---------------------------------------------------------------------
  455. GET_CLR PROC    NEAR
  456.     LEA    DI,STRING
  457.     MOV    AX,ES:[SI]    ;get attribute of fist character in field
  458.     XOR    BX,BX        ;blank BX registor
  459.     MOV    BL,AH        ;move attribute to the BL register
  460.     AND    BL,15        ;mask out the backround and blink bit
  461.     CMP    AH,128        ;is this a blink character
  462.     JGE    N_BLK        ;if no then go to no blink
  463.     ADD    BX,16        ;add 16 to forground color
  464. N_BLK:    MOV    T_FORG,BX    ;move completed forground color to temp data
  465.     MOV    BL,AH        ;move attribute to bl
  466.     AND    BL,112        ;mask out forground and blink bit
  467.     MOV    CL,4        ;4 bit shift count
  468.     SHR    BL,CL        ;shift right 3 bits to pos 2,1,0
  469.     MOV    T_BACK,BX    ;move backround to temp data
  470.     RET
  471. GET_CLR ENDP
  472. ;---------------------------------------------------------------------
  473. CODESEG ENDS
  474.     END
  475.