home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Database / CLIPR503.W96 / EXAMPLEA.AS_ / EXAMPLEA.AS
Text File  |  1995-06-20  |  7KB  |  371 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.                 CLI
  145.         MOV    BX, TIMER_LOW        ; fetch current time
  146.                 STI
  147. T1:
  148.                 CLI
  149.         CMP    BX, TIMER_LOW        ; loop 'til TIMER_LOW changes
  150.                 STI
  151.         JE    T1
  152.  
  153.  
  154.     ; delay loop
  155. T2:
  156.         MOV    AX, TIMER_LOW        ; fetch current time
  157.         SUB    AX, BX            ; AX = number of ticks so far
  158.         CMP    AX, DX            ; compare with requested delay
  159.         JL    T2            ; keep looping if AX < DX
  160.  
  161.  
  162.         POP    ES            ; restore
  163.         ASSUME    ES:NOTHING        ; (tell MASM nothing in ES)
  164.  
  165.         RET                ; near return
  166.  
  167. TIME_DELAY    ENDP
  168.  
  169.  
  170. ;***************
  171. ;
  172. ;    end of local assembler routines
  173. ;
  174.     ENDWORK
  175.  
  176.  
  177. ;******
  178. ;
  179. ;    TONE()
  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. ;
  250. ;    Get and return the current directory path.
  251. ;    Note that a null string means that either an error
  252. ;    has occurred, or the root directory is current.
  253. ;
  254. ;    string = CURDIR(drive)
  255. ;
  256. ;        drive:   drive letter (A, B, ...)
  257. ;             :     current drive if omitted.
  258. ;
  259.     CLfunc char CURDIR <char drive>
  260.  
  261.     CLcode
  262.         PUSH    DS            ; preserve
  263.         LDS    SI, PATH        ; point to mem block
  264.         MOV    BYTE PTR [SI],0        ; null string if error
  265.         MOV    DL, 0            ; assume default drive
  266.  
  267.         TESTNUL    drive            ; test if parameter supplied
  268.         JZ    FILL_ASCIIZ
  269.  
  270.     ; parameter supplied..get specified drive letter
  271.         PUSH    ES            ; preserve
  272.         LES    BX, drive        ; load pointer
  273.         MOV    DL, ES:[BX]        ; get drive letter
  274.         AND    DL, 01011111B        ; ensure upper case
  275.         SUB    DL, ('A' - 1)        ; convert to number ('A' = 1)
  276.         POP    ES            ; restore
  277.  
  278. FILL_ASCIIZ:
  279.         DOSREQ    GET_CURDIR        ; fill with full path name
  280.  
  281.         POP    DS            ; restore
  282.  
  283.     ; return pointer to directory path
  284.     CLret    PATH
  285.  
  286.  
  287. ;*******
  288. ;    BIN2I()
  289. ;
  290.     CLfunc int BIN2I <char str>
  291.  
  292.     CLcode
  293.         LES    BX, str
  294.         MOV    AX, ES:[BX]
  295.  
  296.     CLret    AX
  297.  
  298.  
  299. ;*******
  300. ;    BIN2W()
  301. ;
  302.     CLfunc long BIN2W <char str>
  303.  
  304.     CLcode
  305.         LES    BX, str
  306.         MOV    AX, ES:[BX]
  307.         MOV    DX, 0
  308.  
  309.     CLret    DX AX
  310.  
  311.  
  312. ;*******
  313. ;    BIN2L()
  314. ;
  315.     CLfunc long BIN2L <char str>
  316.  
  317.     CLcode
  318.         LES    BX, str
  319.         MOV    AX, ES:[BX]
  320.         MOV    DX, ES:[BX+2]
  321.  
  322.     CLret    DX AX
  323.  
  324.  
  325. ;*******
  326. ;    I2BIN()
  327. ;
  328. ;    Note -    since the CL macros can't (currently) return strings
  329. ;        containing null bytes, the function is declared 'void'
  330. ;        and a separate call to _retclen is used...
  331. ;
  332.     CLfunc void I2BIN <int num>
  333.  
  334.     CLcode
  335.         MOV    AX, num
  336.         MOV    WORD PTR nbuff, AX
  337.  
  338.     ; note parameter order
  339.         Ccall    _retclen <OFFSET(nbuff), SEG(nbuff), 2>
  340.  
  341.     CLret
  342.  
  343.  
  344. ;*******
  345. ;    L2BIN()
  346. ;
  347. ;    Note -    since the CL macros can't (currently) return strings
  348. ;        containing null bytes, the function is declared 'void'
  349. ;        and a separate call to _retclen is used...
  350. ;
  351.     CLfunc void L2BIN <long num>
  352.  
  353.     CLcode
  354.         MOV    AX, LSW(num)
  355.         MOV    DX, MSW(num)
  356.  
  357.         MOV    WORD PTR nbuff[0], AX
  358.         MOV    WORD PTR nbuff[2], DX
  359.  
  360.     ; note parameter order
  361.         Ccall    _retclen <OFFSET(nbuff), SEG(nbuff), 4>
  362.  
  363.     CLret
  364.  
  365.  
  366.     ; end of assembly
  367.         END
  368.  
  369. ; eof examplea.asm
  370.  
  371.