home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / jsage / znode3 / uploads / make.arc / MAKEFILE.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-11-01  |  3.7 KB  |  155 lines

  1.         title    'CP/M Plus MAKE utility - reading from file'
  2.  
  3.         page    58
  4.  
  5.         public    PARSMF        ; parse make filename into FCB, <A> = error code
  6.         public    OPENMF        ; open make file, <A> = error code
  7.         public    UNGETC        ; store char in <A> back into file
  8.         public    GETC        ; get one char from file into <A>
  9.         public    CLOSMF        ; close make file, return EOF in <A>
  10.  
  11.         extrn    PARFCB        ; parse name at <HL> into FCB at <DE>
  12.         extrn    GUSER        ; return actual user number in <A>
  13.         extrn    NEXT        ; call BDOS via RSX chain
  14.         extrn    UBDOS        ; call BDOS with user number at (DE)-1
  15.  
  16.  
  17.     ; constant definitions
  18.  
  19. FALSE        equ    0        ; boolean constants
  20. TRUE        equ    not FALSE
  21. OPENF        equ    15        ; open file (FCB at .DE)
  22. CLOSEF        equ    16        ; close file (FCB at .DE)
  23. READSQ        equ    20        ; read sequential from file (FCB at .DE)
  24. SETDMA        equ    26        ; set DMA address := <DE>
  25. SETMUL        equ    44        ; set multi-sector-count := <E>
  26. GSSCB        equ    49        ; get/set System Control Block
  27. EOF        equ    26        ; end of file mark (CTRL-Z)
  28. COMLINE        equ    80h        ; CCP command tail
  29.  
  30.  
  31.     ; parse file name of make file
  32.  
  33.         cseg
  34. PARSMF:        lxi    h,COMLINE+1    ; address of ASCIIZ string
  35.         lxi    d,make$FCB    ; address of destination FCB
  36.         jmp    PARFCB
  37.  
  38.  
  39.     ; open make file
  40.  
  41.         cseg
  42. OPENMF:        lda    make$user    ; is user number of make file set?
  43.         ora    a
  44.         jnz    open$passw
  45.  
  46.         call    GUSER        ; get actual user number in <A>
  47.         inr    a        ; store user number(+1) into make FCB
  48.         sta    make$user
  49.  
  50. open$passw:    lxi    d,make$passw    ; set password for OPENF call
  51.         mvi    c,SETDMA
  52.         call    NEXT        ; we mean BDOS, in fact
  53.  
  54.         lxi    d,make$fcb    ; address of make file fcb
  55.         mvi    c,OPENF        ; open file
  56.         jmp    UBDOS        ; with user number support
  57.  
  58.  
  59.     ; one character from <A> back into make file
  60.  
  61.         cseg
  62. UNGETC:        sta    char$store    ; save char
  63.         mvi    a,TRUE        ; set flag
  64.         sta    char$flag
  65.         ret
  66.  
  67.  
  68.     ; read a character from make file into <A>
  69.  
  70.         cseg
  71. GETC$new:    xra    a        ; begin with new record
  72.         sta    make$index
  73.  
  74. GETC:        lda    char$flag    ; waiting char from ungetc ?
  75.         ora    a
  76.         jz    GETC$next    ; no : read one from record buffer
  77.  
  78.         mvi    a,FALSE        ; clear storage flag
  79.         sta    char$flag
  80.         lda    char$store    ; take char from storage
  81.         ret
  82.  
  83. GETC$next:    lda    make$index    ; index into record buffer
  84.         ora    a        ; exhausted ?
  85.         jm    GETC$more
  86.  
  87.         mov    e,a        ; -> DE
  88.         mvi    d,0
  89.         lxi    h,make$DMA    ; + start address of DMA buffer
  90.         dad    d        ; HL points into make DMA buffer
  91.  
  92.         inr    a        ; update index
  93.         sta    make$index
  94.  
  95.         mov    a,m        ; char into <A>
  96.         cpi    EOF        ; last char ?
  97.         jz    CLOSMF        ; yes : close make file
  98.         ret
  99.  
  100.  
  101.     ; read next sector from make file
  102.  
  103.         cseg
  104. GETC$more:    mvi    c,SETDMA    ; set DMA address to makefile buffer
  105.         lxi    d,make$DMA
  106.         call    NEXT
  107.         
  108.         mvi    c,GSSCB        ; get actual multi-sector-count
  109.         lxi    d,get$multio
  110.         call    NEXT
  111.         push    h        ; save count in <L>
  112.  
  113.         mvi    c,SETMUL    ; reset multi-sector count
  114.         mvi    e,1
  115.         call    NEXT
  116.  
  117.         mvi    c,READSQ    ; read next sector of make file
  118.         lxi    d,make$FCB
  119.         call    UBDOS        ; with user number support
  120.  
  121.         pop    d        ; <E> := old multi-sector-count
  122.         push    psw        ; save error code of READSQ
  123.         mvi    c,SETMUL    ; restore old multi-sector-count
  124.         call    NEXT
  125.  
  126.         pop    psw
  127.         ora    a        ; end of file or other error ?
  128.         jz    GETC$new    ; no: read first char of next record
  129.  
  130.  
  131.     ; close make file, returning EOF in <A>
  132.  
  133.         cseg
  134. CLOSMF:        mvi    c,CLOSEF    ; close make file
  135.         lxi    d,make$FCB
  136.         call    UBDOS        ; with user number support
  137.  
  138.         mvi    a,EOF        ; return EOF to caller
  139.         ret
  140.  
  141.  
  142.     ; data segment for file procedures
  143.  
  144.         dseg
  145. make$user:    ds    1        ; user number(+1) of make file
  146. make$FCB:    ds    36        ; FCB of make file
  147. make$passw:    ds    8        ; password of make file
  148. make$index:    db    128        ; index into make file record
  149. make$DMA:    ds    128        ; dma buffer for make file
  150. char$flag:    db    FALSE        ; set if character waiting in char$store
  151. char$store:    ds    1        ; waiting char for GETC
  152. get$multio:    db    4Ah        ; offset of multi-sector-count
  153.         db    0
  154.         end
  155.