home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d141 / smallc.lha / SmallC / SMCLIB.ASM < prev    next >
Assembly Source File  |  1988-05-15  |  4KB  |  290 lines

  1. ;
  2. ; some system equates
  3. ;
  4. AbsExecBase  equ  $4
  5. MODE_OLDFILE equ  1005
  6. MODE_NEWFILE equ  1006
  7. ;
  8. ;        Register equates
  9. ;
  10. bx    equr     d0
  11. dx    equr     d1
  12. ;
  13. ;        Macro definitions
  14. ;
  15. lref     MACRO
  16.          xref     _LVO\1
  17.          ENDM
  18. ;
  19. ;
  20. ;
  21. call     MACRO
  22.          jsr      _LVO\1(a6)
  23.          ENDM
  24. ;
  25. ;
  26. ;
  27.          lref     OpenLibrary
  28.          lref     CloseLibrary
  29.          lref     Open
  30.          lref     Close
  31.          lref     Read
  32.          lref     Write
  33.          lref     Input
  34.          lref     Output
  35. ;
  36. ;
  37. ;
  38.          section  ONE
  39. ;
  40. ;
  41. ;
  42.    nop
  43. ;
  44. ;        Define entry point
  45. ;
  46.    xdef     CCINIT
  47. CCINIT:
  48. ;
  49. ;        Save stack pointer for EXIT
  50. ;
  51.    move.l   sp,StkPtr
  52. ;
  53. ;        Initialize work areas
  54. ;
  55.    clr.l    HandFlgs
  56.    clr.l    HandFlgs+4
  57. ;
  58. ;        Open DOS library
  59. ;
  60.    move.l   #dosname,a1
  61.    clr      d0
  62.    move.l   AbsExecBase,a6
  63.    call     OpenLibrary
  64.    move.l   d0,a6
  65.    tst.l    d0
  66.    beq      CCWRAP
  67. ;
  68. ;        Find standard file handles
  69. ;
  70.    call     Input
  71.    move.l   d0,StdIn
  72.    beq      CCWRAP
  73.    call     Output
  74.    move.l   d0,StdOut
  75.    beq      CCWRAP
  76.    rts
  77. ;
  78. ;        Close opened libraries
  79. ;
  80.    xdef     CCWRAP
  81. CCWRAP:
  82.    move.l   a6,a1
  83.    move.l   AbsExecBase,a6
  84.    call     CloseLibrary
  85.    clr.l    d0
  86.    rts
  87. ;
  88. ;
  89. ;
  90.    xdef     CCDIV
  91. CCDIV:
  92.    divs     bx,dx
  93.    move.w   dx,bx
  94.    ext.l    bx
  95.    asr.l    #8,dx
  96.    asr.l    #8,dx
  97.    rts
  98. ;
  99. ;
  100. ;
  101.    xdef     QZPUTCHAR
  102. QZPUTCHAR:
  103.    move.l   4(sp),d0
  104.    move.l   d0,d7
  105.    move.b   d0,CharBuff
  106.    bsr      Wr1Byte
  107.    move.l   d7,d0
  108.    rts
  109. ;
  110. ;
  111. ;
  112. Wr1Byte:
  113.    move.l   StdOut,d1
  114.    move.l   #CharBuff,d2
  115.    move.l   #1,d3
  116.    call     Write
  117.    rts
  118. ;
  119. ;
  120. ;
  121.    xdef     QZBELL
  122. QZBELL:
  123.    move.l   #7,bx
  124.    move.l   bx,-(sp)
  125.    bsr      QZPUTCHAR
  126.    move.l   (sp)+,bx
  127.    rts
  128. ;
  129. ;
  130. ;
  131.    xdef     QZCLRSCREE
  132. QZCLRSCREE:
  133.    rts
  134. ;
  135. ;
  136. ;
  137.    xdef     QZGETS
  138. QZGETS:
  139.    move.l   4(sp),a4
  140.    move.l   StdIn,d1
  141.    move.l   a4,d2
  142.    move.l   #80,d3
  143.    call     Read
  144.    clr.b    -1(a4,d0.l)
  145.    move.l   d0,a4
  146.    move.b   #10,d0
  147.    move.b   d0,CharBuff
  148.    bsr      Wr1Byte
  149.    move.l   a4,d0
  150.    rts
  151. ;
  152. ;
  153. ;
  154.    xdef     QZFOPEN
  155. QZFOPEN:
  156.    move.l   #HandFlgs,a0
  157.    moveq    #7,d2
  158.    clr.l    d3
  159. 1$ tst.b    (a0)+
  160.    beq      2$
  161.    addq.l   #1,d3
  162.    dbra     d2,1$
  163.    bra      fail
  164. 2$ not.b    -(a0)
  165.    move.l   d3,Unit
  166.    asl.l    #2,d3
  167.    move.l   d3,HandOffs
  168.    move.l   #MODE_OLDFILE,d2
  169.    move.l   4(sp),a0
  170.    move.b   (a0),d0
  171.    cmp.b    #'r',d0
  172.    beq      4$
  173.    cmp.b    #'R',d0
  174.    beq      4$
  175.    cmp.b    #'w',d0
  176.    beq      3$
  177.    cmp.b    #'W',d0
  178.    bne      fail
  179. 3$ move.l   #MODE_NEWFILE,d2
  180. 4$ move.l   8(sp),d1
  181.    call     Open
  182.    tst.l    d0
  183.    beq      fail
  184.    move.l   #Handles,a0
  185.    move.l   HandOffs,d1
  186.    move.l   d0,0(a0,d1.l)
  187.    move.l   Unit,bx
  188.    addq.l   #1,bx
  189.    rts
  190. fail:
  191.    clr.l    bx
  192.    rts
  193. ;
  194. ;
  195. ;
  196.    xdef     QZGETC
  197. QZGETC:
  198.    bsr      GetHandl
  199.    move.l   #CharBuff,d2
  200.    move.l   #1,d3
  201.    call     Read
  202.    tst.l    d0
  203.    beq      eof
  204.    move.b   CharBuff,bx
  205.    ext.w    bx
  206.    ext.l    bx
  207.    rts
  208. eof:
  209.    move.l   #-1,bx
  210.    rts
  211. ;
  212. ;
  213. ;
  214.    xdef     QZPUTC
  215. QZPUTC:
  216.    move.l   8(sp),d0
  217.    move.l   d0,d7
  218.    move.b   d0,CharBuff
  219.    bsr      GetHandl
  220.    move.l   #CharBuff,d2
  221.    move.l   #1,d3
  222.    call     Write
  223.    move.l   d7,bx
  224.    rts
  225. ;
  226. ;
  227. ;
  228.    xdef     QZFCLOSE
  229. QZFCLOSE:
  230.    bsr      GetHandl
  231.    call     Close
  232.    move.l   4(sp),d0
  233.    subq.l   #1,d0
  234.    move.l   #HandFlgs,a0
  235.    clr.b    0(a0,d0.l)
  236.    clr.l    bx
  237.    rts
  238. ;
  239. ;
  240. ;
  241. GetHandl:
  242.    move.l   8(sp),d0
  243.    subq.l   #1,d0
  244.    asl.l    #2,d0
  245.    move.l   #Handles,a0
  246.    move.l   0(a0,d0.l),d1
  247.    rts
  248. ;
  249. ;
  250. ;
  251.    xdef     QZEXIT
  252. QZEXIT:
  253.    move.l   StkPtr,sp
  254.    addq     #4,sp
  255.    rts
  256. ;  
  257. ;
  258. ;
  259.          section  TWO,data
  260. ;
  261. ;        DOS Library name
  262. ;
  263. dosname  dc.b     'dos.library',0
  264. ;
  265. ;
  266. ;
  267.          section  THREE,bss
  268. ;
  269. ;
  270. ;
  271. CharBuff ds.b     1
  272.          ds.b     1
  273. ;
  274. ;
  275. ;
  276. StkPtr   ds.l     1
  277. ;
  278. ;
  279. ;
  280. StdIn    ds.l     1     ;input file handle
  281. StdOut   ds.l     1     ;output file handle
  282. HandOffs ds.l     1     ;offset to handle being opened
  283. Unit     ds.l     1     ;Value returned by open
  284. HandFlgs ds.b     8     ;Handle 'in-use' flags
  285. Handles  ds.l     8     ;Room for 8 handles
  286. ;
  287. ;
  288. ;
  289.    end
  290.