home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Database / CLIPR502.DOS / SOURCE / SAMPLE / EXAMPLEA.ASM < prev    next >
Encoding:
Assembly Source File  |  1993-02-15  |  6.6 KB  |  367 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. ;
  75. ;    CAUTION:  this routine works only on IBM-PC BIOS-compatibles!
  76. ;
  77. ;    Logical true if the printer is online and ready, otherwise false.
  78. ;
  79. ;    status = ISPRINTER()
  80. ;
  81. ;        status  -   logical.
  82. ;
  83. ;    Placed in the public domain by Tom Rettig Associates.
  84. ;
  85.     ; function declaration
  86.     ; return types include void, char, int, long, double, date, and log
  87.     CLfunc log ISPRINTER
  88.  
  89.     ; begin code
  90.     CLcode
  91.         MOV    AH, 02H            ; printer status function
  92.         MOV    DX, 0            ; which printer to check
  93.         INT    17H            ; read printer status
  94.  
  95.         MOV    BX, FALSE
  96.         CMP    AH, 90H            ; 90H means not busy
  97.         JNE    ISPRINTER_RET        ; return false if AH != 90H
  98.         MOV    BX, TRUE
  99.  
  100. ISPRINTER_RET:
  101.     ; return logical value to Clipper (declared "log" above)
  102.     CLret    BX
  103.  
  104.  
  105. ;******
  106. ;
  107. ;    declare dummy segment to access BIOS data area
  108. ;    no code is generated by this declaration
  109. ;
  110. BIOS_DATA    SEGMENT AT 40H
  111.  
  112.         ORG    6CH
  113. TIMER_LOW    LABEL    WORD            ; time of day is stored here
  114.  
  115. BIOS_DATA    ENDS
  116.  
  117.  
  118. ;***************
  119. ;
  120. ;    begin local assembler routines
  121. ;
  122.     WORKFUNCS
  123.  
  124.  
  125. ;******
  126. ;
  127. ;    delay processing a specified number of timer tics
  128. ;    the count is contained in the DX register
  129. ;    each tic is 1/18 second
  130. ;
  131. TIME_DELAY    PROC    NEAR
  132.  
  133.         PUSH    ES            ; preserve
  134.  
  135.  
  136.     ; ES = segment of BIOS data area
  137.         MOV    AX, BIOS_DATA        ; load segment value
  138.         MOV    ES, AX
  139.  
  140.         ASSUME    ES:BIOS_DATA        ; (tell MASM what's in ES)
  141.  
  142.  
  143.     ; delay at least one tick
  144.         MOV    BX, TIMER_LOW        ; fetch current time
  145. T1:
  146.         CMP    BX, TIMER_LOW        ; loop 'til TIMER_LOW changes
  147.         JE    T1
  148.  
  149.  
  150.     ; delay loop
  151. T2:
  152.         MOV    AX, TIMER_LOW        ; fetch current time
  153.         SUB    AX, BX            ; AX = number of ticks so far
  154.         CMP    AX, DX            ; compare with requested delay
  155.         JL    T2            ; keep looping if AX < DX
  156.  
  157.  
  158.         POP    ES            ; restore
  159.         ASSUME    ES:NOTHING        ; (tell MASM nothing in ES)
  160.  
  161.         RET                ; near return
  162.  
  163. TIME_DELAY    ENDP
  164.  
  165.  
  166. ;***************
  167. ;
  168. ;    end of local assembler routines
  169. ;
  170.     ENDWORK
  171.  
  172.  
  173. ;******
  174. ;
  175. ;    TONE()
  176. ;
  177. ;    Produce a tone of the specified frequency and duration.  If the
  178. ;    frequency is less than 20 Hz wait the specified duration without
  179. ;    producing a tone.
  180. ;
  181. ;    CAUTION:  this routine works only on IBM-PC compatible hardware!
  182. ;
  183. ;    TONE(frequency, duration)
  184. ;
  185. ;        frequency:    numeric -- cycles per second
  186. ;        duration:    numeric -- 18ths of a second
  187. ;
  188.     CLfunc void TONE <int frequency, int duration>
  189.  
  190.     CLcode
  191.         XOR    DX, DX            ; delay one timer tic
  192.         CALL    TIME_DELAY
  193.  
  194.     ; 1.19318 MHz / frequency
  195.         MOV    BX, frequency
  196.         CMP    BX, 20
  197.         JB    SILENCE
  198.  
  199.     ; select timer channel 2; read/write LSB, MSB; mode 3; binary
  200.         MOV    AL, TIMER_COMMAND
  201.         OUT    TIMER_COMMAND_REGISTER, AL
  202.  
  203.         MOV    DX, CLOCK_RATE_HIGH
  204.         MOV    AX, CLOCK_RATE_LOW
  205.  
  206.         DIV    BX            ; AX = correct Hz divisor
  207.  
  208.     ; output LSB, MSB (this sets the frequency)
  209.         OUT    TIMER_LATCH_REGISTER, AL
  210.         MOV    AL, AH
  211.         OUT    TIMER_LATCH_REGISTER, AL
  212.  
  213.     ; save current setting of port pb
  214.         IN    AL, PORT_PB
  215.         PUSH    AX
  216.  
  217.     ; turn on speaker data and timer gate bits
  218.         OR    AL, SPEAKER_ON
  219.         OUT    PORT_PB, AL
  220.  
  221.     ; speaker is on..wait the requested duration
  222.         MOV    DX, duration
  223.         CALL    TIME_DELAY
  224.  
  225.     ; shut that thing off!!
  226.         POP    AX
  227.         OUT    PORT_PB, AL
  228.  
  229.         JMP    SHORT TONE_RET
  230.  
  231. SILENCE:
  232.     ; just delay
  233.         MOV    DX, duration
  234.         CALL    TIME_DELAY
  235.  
  236. TONE_RET:
  237.  
  238.     ; no return value
  239.     CLret
  240.  
  241.  
  242. ;******
  243. ;
  244. ;    CURDIR()
  245. ;
  246. ;    Get and return the current directory path.
  247. ;    Note that a null string means that either an error
  248. ;    has occurred, or the root directory is current.
  249. ;
  250. ;    string = CURDIR(drive)
  251. ;
  252. ;        drive:   drive letter (A, B, ...)
  253. ;             :     current drive if omitted.
  254. ;
  255.     CLfunc char CURDIR <char drive>
  256.  
  257.     CLcode
  258.         PUSH    DS            ; preserve
  259.         LDS    SI, PATH        ; point to mem block
  260.         MOV    BYTE PTR [SI],0        ; null string if error
  261.         MOV    DL, 0            ; assume default drive
  262.  
  263.         TESTNUL    drive            ; test if parameter supplied
  264.         JZ    FILL_ASCIIZ
  265.  
  266.     ; parameter supplied..get specified drive letter
  267.         PUSH    ES            ; preserve
  268.         LES    BX, drive        ; load pointer
  269.         MOV    DL, ES:[BX]        ; get drive letter
  270.         AND    DL, 01011111B        ; ensure upper case
  271.         SUB    DL, ('A' - 1)        ; convert to number ('A' = 1)
  272.         POP    ES            ; restore
  273.  
  274. FILL_ASCIIZ:
  275.         DOSREQ    GET_CURDIR        ; fill with full path name
  276.  
  277.         POP    DS            ; restore
  278.  
  279.     ; return pointer to directory path
  280.     CLret    PATH
  281.  
  282.  
  283. ;*******
  284. ;    BIN2I()
  285. ;
  286.     CLfunc int BIN2I <char str>
  287.  
  288.     CLcode
  289.         LES    BX, str
  290.         MOV    AX, ES:[BX]
  291.  
  292.     CLret    AX
  293.  
  294.  
  295. ;*******
  296. ;    BIN2W()
  297. ;
  298.     CLfunc long BIN2W <char str>
  299.  
  300.     CLcode
  301.         LES    BX, str
  302.         MOV    AX, ES:[BX]
  303.         MOV    DX, 0
  304.  
  305.     CLret    DX AX
  306.  
  307.  
  308. ;*******
  309. ;    BIN2L()
  310. ;
  311.     CLfunc long BIN2L <char str>
  312.  
  313.     CLcode
  314.         LES    BX, str
  315.         MOV    AX, ES:[BX]
  316.         MOV    DX, ES:[BX+2]
  317.  
  318.     CLret    DX AX
  319.  
  320.  
  321. ;*******
  322. ;    I2BIN()
  323. ;
  324. ;    Note -    since the CL macros can't (currently) return strings
  325. ;        containing null bytes, the function is declared 'void'
  326. ;        and a separate call to _retclen is used...
  327. ;
  328.     CLfunc void I2BIN <int num>
  329.  
  330.     CLcode
  331.         MOV    AX, num
  332.         MOV    WORD PTR nbuff, AX
  333.  
  334.     ; note parameter order
  335.         Ccall    _retclen <OFFSET(nbuff), SEG(nbuff), 2>
  336.  
  337.     CLret
  338.  
  339.  
  340. ;*******
  341. ;    L2BIN()
  342. ;
  343. ;    Note -    since the CL macros can't (currently) return strings
  344. ;        containing null bytes, the function is declared 'void'
  345. ;        and a separate call to _retclen is used...
  346. ;
  347.     CLfunc void L2BIN <long num>
  348.  
  349.     CLcode
  350.         MOV    AX, LSW(num)
  351.         MOV    DX, MSW(num)
  352.  
  353.         MOV    WORD PTR nbuff[0], AX
  354.         MOV    WORD PTR nbuff[2], DX
  355.  
  356.     ; note parameter order
  357.         Ccall    _retclen <OFFSET(nbuff), SEG(nbuff), 4>
  358.  
  359.     CLret
  360.  
  361.  
  362.     ; end of assembly
  363.         END
  364.  
  365. ; eof examplea.asm
  366.  
  367.