home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a009 / 6.ddi / SAMPLE.LIF / EXAMPLEA.ASM < prev    next >
Encoding:
Assembly Source File  |  1991-04-14  |  6.8 KB  |  378 lines

  1.     PAGE    ,132
  2.     NAME    EXAMPLES
  3. ;************
  4. ;
  5. ;    examplea.asm
  6. ;
  7. ;    This file contains demonstration programs using the 
  8. ;    CLIPPER assembly interface.
  9. ;
  10. ;    Function source.....
  11. ;
  12. ;        ISPRINTER()
  13. ;        TONE()
  14. ;        CURDIR()
  15. ;        BIN2I()
  16. ;        BIN2W()
  17. ;        BIN2L()
  18. ;        I2BIN()
  19. ;        L2BIN()
  20. ;
  21.     INCLUDE    EXTENDA.INC
  22.  
  23.  
  24. ;***************
  25. ;
  26. ;    define segment names
  27. ;
  28.     CODESEG    EXAMPLEA
  29.     DATASEG
  30.  
  31.  
  32. ;***************
  33. ;
  34. ;    declaration of public functions
  35. ;
  36.     CLpublic <ISPRINTER, TONE, CURDIR>
  37.     CLpublic <BIN2I, BIN2W, BIN2L, I2BIN, L2BIN>
  38.  
  39.  
  40. ;***************
  41. ;
  42. ;    Static data
  43. ;
  44.     CLstatic <long nbuff 0>
  45.  
  46.     ; storage for full pathname and pointer to address it
  47.     CLstatic <byte ASCIIZ <<64 DUP(0)>>, cptr PATH ASCIIZ>
  48.  
  49.  
  50. ;***************
  51. ;
  52. ;    Equates
  53. ;
  54.  
  55. $define FALSE            0000H
  56. $define TRUE            0001H
  57.  
  58.     ; for TONE()
  59. $define TIMER_COMMAND        00B6H        ; value for timer setup
  60. $define TIMER_COMMAND_REGISTER    0043H        ; port address
  61. $define TIMER_LATCH_REGISTER    0042H        ; port address
  62. $define PORT_PB            0061H        ; port address
  63. $define SPEAKER_ON        00000011B     ; bit mask
  64. $define CLOCK_RATE_HIGH        0012H        ; 1.19318 MHz as 32 bit value
  65. $define CLOCK_RATE_LOW        34DCH
  66.  
  67.     ; for CURDIR()
  68. $define GET_CURDIR        0047H        ; DOS request number
  69.  
  70.  
  71. ;*******
  72. ;
  73. ;    ISPRINTER()
  74. ;    Tom Rettig, Brian Russell
  75. ;    11/01/85
  76. ;
  77. ;    CAUTION:  this routine works only on IBM-PC BIOS-compatibles!
  78. ;
  79. ;    Logical true if the printer is online and ready, otherwise false.
  80. ;
  81. ;    status = ISPRINTER()
  82. ;
  83. ;        status  -   logical.
  84. ;
  85. ;    Placed in the public domain by Tom Rettig Associates.
  86. ;
  87.     ; function declaration
  88.     ; return types include void, char, int, long, double, date, and log
  89.     CLfunc log ISPRINTER
  90.  
  91.     ; begin code
  92.     CLcode
  93.         MOV    AH, 02H            ; printer status function
  94.         MOV    DX, 0            ; which printer to check
  95.         INT    17H            ; read printer status
  96.  
  97.         MOV    BX, FALSE
  98.         CMP    AH, 90H            ; 90H means not busy
  99.         JNE    ISPRINTER_RET        ; return false if AH != 90H
  100.         MOV    BX, TRUE
  101.  
  102. ISPRINTER_RET:
  103.     ; return logical value to Clipper (declared "log" above)
  104.     CLret    BX
  105.  
  106.  
  107. ;******
  108. ;
  109. ;    declare dummy segment to access BIOS data area
  110. ;    no code is generated by this declaration
  111. ;
  112. BIOS_DATA    SEGMENT AT 40H
  113.  
  114.         ORG    6CH
  115. TIMER_LOW    LABEL    WORD            ; time of day is stored here
  116.  
  117. BIOS_DATA    ENDS
  118.  
  119.  
  120. ;***************
  121. ;
  122. ;    begin local assembler routines
  123. ;
  124.     WORKFUNCS
  125.  
  126.  
  127. ;******
  128. ;
  129. ;    delay processing a specified number of timer tics
  130. ;    the count is contained in the DX register
  131. ;    each tic is 1/18 second
  132. ;
  133. TIME_DELAY    PROC    NEAR
  134.  
  135.         PUSH    ES            ; preserve
  136.  
  137.  
  138.     ; ES = segment of BIOS data area
  139.         MOV    AX, BIOS_DATA        ; load segment value
  140.         MOV    ES, AX
  141.  
  142.         ASSUME    ES:BIOS_DATA        ; (tell MASM what's in ES)
  143.  
  144.  
  145.     ; delay at least one tick
  146.         MOV    BX, TIMER_LOW        ; fetch current time
  147. T1:
  148.         CMP    BX, TIMER_LOW        ; loop 'til TIMER_LOW changes
  149.         JE    T1
  150.  
  151.  
  152.     ; delay loop
  153. T2:
  154.         MOV    AX, TIMER_LOW        ; fetch current time
  155.         SUB    AX, BX            ; AX = number of ticks so far
  156.         CMP    AX, DX            ; compare with requested delay
  157.         JL    T2            ; keep looping if AX < DX
  158.  
  159.  
  160.         POP    ES            ; restore
  161.         ASSUME    ES:NOTHING        ; (tell MASM nothing in ES)
  162.  
  163.         RET                ; near return
  164.  
  165. TIME_DELAY    ENDP
  166.  
  167.  
  168. ;***************
  169. ;
  170. ;    end of local assembler routines
  171. ;
  172.     ENDWORK
  173.  
  174.  
  175. ;******
  176. ;
  177. ;    TONE()
  178. ;    Dennis L. Dias
  179. ;    12/09/87
  180. ;
  181. ;    Produce a tone of the specified frequency and duration.  If the
  182. ;    frequency is less than 20 Hz wait the specified duration without
  183. ;    producing a tone.
  184. ;
  185. ;    CAUTION:  this routine works only on IBM-PC compatible hardware!
  186. ;
  187. ;    TONE(frequency, duration)
  188. ;
  189. ;        frequency:    numeric -- cycles per second
  190. ;        duration:    numeric -- 18ths of a second
  191. ;
  192.     CLfunc void TONE <int frequency, int duration>
  193.  
  194.     CLcode
  195.         XOR    DX, DX            ; delay one timer tic
  196.         CALL    TIME_DELAY
  197.  
  198.     ; 1.19318 MHz / frequency
  199.         MOV    BX, frequency
  200.         CMP    BX, 20
  201.         JB    SILENCE
  202.  
  203.     ; select timer channel 2; read/write LSB, MSB; mode 3; binary
  204.         MOV    AL, TIMER_COMMAND
  205.         OUT    TIMER_COMMAND_REGISTER, AL
  206.  
  207.         MOV    DX, CLOCK_RATE_HIGH
  208.         MOV    AX, CLOCK_RATE_LOW
  209.  
  210.         DIV    BX            ; AX = correct Hz divisor
  211.  
  212.     ; output LSB, MSB (this sets the frequency)
  213.         OUT    TIMER_LATCH_REGISTER, AL
  214.         MOV    AL, AH
  215.         OUT    TIMER_LATCH_REGISTER, AL
  216.  
  217.     ; save current setting of port pb
  218.         IN    AL, PORT_PB
  219.         PUSH    AX
  220.  
  221.     ; turn on speaker data and timer gate bits
  222.         OR    AL, SPEAKER_ON
  223.         OUT    PORT_PB, AL
  224.  
  225.     ; speaker is on..wait the requested duration
  226.         MOV    DX, duration
  227.         CALL    TIME_DELAY
  228.  
  229.     ; shut that thing off!!
  230.         POP    AX
  231.         OUT    PORT_PB, AL
  232.  
  233.         JMP    SHORT TONE_RET
  234.  
  235. SILENCE:
  236.     ; just delay
  237.         MOV    DX, duration
  238.         CALL    TIME_DELAY
  239.  
  240. TONE_RET:
  241.  
  242.     ; no return value
  243.     CLret
  244.  
  245.  
  246. ;******
  247. ;
  248. ;    CURDIR()
  249. ;    Dennis L. Dias
  250. ;    12/17/87
  251. ;
  252. ;    Get and return the current directory path.
  253. ;    Note that a null string means that either an error
  254. ;    has occurred, or the root directory is current.
  255. ;
  256. ;    string = CURDIR(drive)
  257. ;
  258. ;        drive:   drive letter (A, B, ...)
  259. ;             :     current drive if omitted.
  260. ;
  261.     CLfunc char CURDIR <char drive>
  262.  
  263.     CLcode
  264.         PUSH    DS            ; preserve
  265.         LDS    SI, PATH        ; point to mem block
  266.         MOV    BYTE PTR [SI],0        ; null string if error
  267.         MOV    DL, 0            ; assume default drive
  268.  
  269.         TESTNUL    drive            ; test if parameter supplied
  270.         JZ    FILL_ASCIIZ
  271.  
  272.     ; parameter supplied..get specified drive letter
  273.         PUSH    ES            ; preserve
  274.         LES    BX, drive        ; load pointer
  275.         MOV    DL, ES:[BX]        ; get drive letter
  276.         AND    DL, 01011111B        ; ensure upper case
  277.         SUB    DL, ('A' - 1)        ; convert to number ('A' = 1)
  278.         POP    ES            ; restore
  279.  
  280. FILL_ASCIIZ:
  281.         DOSREQ    GET_CURDIR        ; fill with full path name
  282.  
  283.         POP    DS            ; restore
  284.  
  285.     ; return pointer to directory path
  286.     CLret    PATH
  287.  
  288.  
  289. ;*******
  290. ;    BIN2I()
  291. ;    Bri and Richie
  292. ;
  293.     CLfunc int BIN2I <char str>
  294.  
  295.     CLcode
  296.         LES    BX, str
  297.         MOV    AX, ES:[BX]
  298.  
  299.     CLret    AX
  300.  
  301.  
  302. ;*******
  303. ;    BIN2W()
  304. ;    Bri and Richie
  305. ;
  306.     CLfunc long BIN2W <char str>
  307.  
  308.     CLcode
  309.         LES    BX, str
  310.         MOV    AX, ES:[BX]
  311.         MOV    DX, 0
  312.  
  313.     CLret    DX AX
  314.  
  315.  
  316. ;*******
  317. ;    BIN2L()
  318. ;    Bri and Richie
  319. ;
  320.     CLfunc long BIN2L <char str>
  321.  
  322.     CLcode
  323.         LES    BX, str
  324.         MOV    AX, ES:[BX]
  325.         MOV    DX, ES:[BX+2]
  326.  
  327.     CLret    DX AX
  328.  
  329.  
  330. ;*******
  331. ;    I2BIN()
  332. ;    Bri and Richie
  333. ;
  334. ;    Note -    since the CL macros can't (currently) return strings
  335. ;        containing null bytes, the function is declared 'void'
  336. ;        and a separate call to _retclen is used...
  337. ;
  338.     CLfunc void I2BIN <int num>
  339.  
  340.     CLcode
  341.         MOV    AX, num
  342.         MOV    WORD PTR nbuff, AX
  343.  
  344.     ; note parameter order
  345.         Ccall    _retclen <OFFSET(nbuff), SEG(nbuff), 2>
  346.  
  347.     CLret
  348.  
  349.  
  350. ;*******
  351. ;    L2BIN()
  352. ;    Bri and Richie
  353. ;
  354. ;    Note -    since the CL macros can't (currently) return strings
  355. ;        containing null bytes, the function is declared 'void'
  356. ;        and a separate call to _retclen is used...
  357. ;
  358.     CLfunc void L2BIN <long num>
  359.  
  360.     CLcode
  361.         MOV    AX, LSW(num)
  362.         MOV    DX, MSW(num)
  363.  
  364.         MOV    WORD PTR nbuff[0], AX
  365.         MOV    WORD PTR nbuff[2], DX
  366.  
  367.     ; note parameter order
  368.         Ccall    _retclen <OFFSET(nbuff), SEG(nbuff), 4>
  369.  
  370.     CLret
  371.  
  372.  
  373.     ; end of assembly
  374.         END
  375.  
  376. ; eof examplea.asm
  377.  
  378.