home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / enterprs / c128 / text / examples.arc / DIR.A < prev    next >
Encoding:
Text File  |  1989-12-01  |  11.8 KB  |  309 lines

  1. ;dir.asm
  2. ;===========================================
  3. ; User installable command: dir[/w] pattern
  4. ;===========================================
  5.                                   
  6. poker       = $0016               ;temp
  7. status      = $0090               ;I/O status byte
  8. stkey       = $0091               ;RUN/STOP flag
  9. la          = $00b8               
  10. sa          = $00b9               
  11. dv          = $00ba               
  12. pntr        = $00ec               ;Cursor column
  13. int02       = $1702               ;get default drive (.a) and unit (.x)
  14. int04       = $1704               ;get 1st char of parameter .x
  15. int08       = $1708               ;open file for read
  16. int0a       = $170a               ;find an unused la
  17. int0c       = $170c               ;check ds$ .. return ds in .a
  18. int0d       = $170d               ;print ds$ after int08
  19. int0e       = $170e               ;program terminate. Close all files then READY.
  20. sw1         = $1bfc               ;command line switch 1. (0=none present)
  21. linprt      = $8e32               ;print .x .a as decimal
  22. primm       = $ff7d               
  23. setnam      = $ffbd               
  24. open        = $ffc0               
  25. chkin       = $ffc6               
  26. chrin       = $ffcf               
  27. chrout      = $ffd2               
  28.                                   
  29. star        = $0b00               
  30.             .wor star             
  31.             * = star              
  32.  
  33.             jmp dir
  34.             dw Date
  35.                       
  36. dir         ldx #1                ;open %1 as a directory
  37.             jsr int04             ;check if parameter is there
  38.             bcc dir9              ;ok...use it
  39.             jsr int02             ;otherwise get default unit,drive
  40.             sta def+1             ;store drive
  41.             stx dv                ;store unit
  42.             jsr int0a             ;find a free la
  43.             sta la                
  44.             ldy #0                ;sa=0
  45.             sty sa                
  46.             lda #4                ;open "$d:*"
  47.             ldx #<def             
  48.             ldy #>def             
  49.             jsr setnam            
  50.             jsr open              
  51.             bcs dirx              
  52.             jsr int0c             
  53.             ldx la                
  54.             bne dir8              ;always
  55.                                   
  56. dir9        lda #"$"              ;open as type "$"
  57.             jsr int08             ;open it
  58. dir8        bcc dir0              ;open went ok. continue
  59.             pha                   
  60.             jsr int0d             ;bad open...print ds$
  61.             pla                   
  62. dirx        jmp int0e             ;and exit
  63.                                   
  64. dir0        jsr chkin             ;setup for input
  65.             bcs dirx              ;error..exit
  66.             lda sw1               ;get switch1
  67.             cmp #"w"              
  68.             bne zop               
  69.             jmp wdir              
  70.                                   
  71. zop         jsr crdo              ;next line
  72.             lda #0                
  73.             sta status            
  74.             ldy #3                ;3rd word in is drive number
  75.             .byt $2c              
  76. dir1        ldy #2                ;next time skip only 2
  77.             sty poker             
  78. dir2        jsr chrin             ;get word in .a high .x low
  79.             tax                   
  80.             ldy status            
  81.             bne dirxx             
  82.             jsr chrin             
  83.             ldy status            
  84.             bne dirxx             
  85.             dec poker             
  86.             bne dir2              
  87.             pha                   
  88.             jsr white             
  89.             pla                   
  90.             jsr linprt            ;print drive,#blocks or blocks free
  91.             lda #" "              
  92.             jsr chrout            
  93.             jsr lgreen            
  94.             lda #1                
  95.             sta flag              
  96. dir3        jsr chrin             ;print the rest of the line
  97.             cmp #34               
  98.             bne nq                
  99.             dec flag              
  100.             bpl nq                
  101. dir7        jsr chrout            
  102.             jsr chrin             
  103.             cmp #" "              
  104.             beq dir7              
  105.             cmp #">"              
  106.             beq dir7              
  107.             cmp #"*"              
  108.             beq dir7              
  109.             dec $f1               
  110.             cmp #"s"              
  111.             beq nq                
  112.             inc $f1               
  113.             inc $f1               
  114.             inc $f1               
  115.             cmp #"p"              
  116.             beq nq                
  117.             inc $f1               
  118.             inc $f1               
  119.             inc $f1               
  120.             inc $f1               
  121.             cmp #"r"              
  122.             beq nq                
  123.             inc $f1               
  124.             cmp #"u"              
  125.             beq nq                
  126.             inc $f1               
  127. nq          cmp #0                
  128.             beq dir4              ;next line
  129.             jsr chrout            
  130.             jmp dir3              
  131.                                   
  132. dir4        jsr crdo              
  133.             bit stkey             ;run/stop?
  134.             bpl dirxx             ;yes-exit
  135.             jmp dir1              ;otherwise next line
  136.                                   
  137. dirxx       jsr crdo              
  138.             jmp int0e             ;close all and quit
  139.                                   
  140. crdo        lda #13               
  141.             jmp chrout            
  142.                                   
  143. def         .asc "$0:*"           
  144.                                   
  145. ;-----------------------------
  146. ; do directory with /w option
  147. ;-----------------------------
  148.                                   
  149. wdir        lda #0                
  150.             sta blt               
  151.             sta blt+1             
  152.             sta blf               
  153.             jsr skp2              ;skip load address
  154.             jsr skp4              ;skip drive number
  155.             jsr skpq              ;skip to quote
  156.             jsr white             
  157.             jsr primm             
  158.             .asc 13,"disk:", 0
  159.             jsr lcyan             
  160.             ldy #0                
  161.             jsr prttq             ;print until quote
  162.             sty namlen            
  163.             ldy #0                
  164. prt9        lda name,y            
  165.             jsr chrout            
  166.             iny                   
  167.             cpy namlen            
  168.             bne prt9              
  169.             jsr crdo              
  170.             jsr skp0              ;skip to end of line
  171. wdlp        jsr skp2              ;skip pointer - start of loop for dir entry
  172.             jsr chrin             ;blocks lo
  173.             sta blo               
  174.             jsr chrin             ;blocks hi
  175.             sta blh               
  176.             jsr skpq              ;skip to quote
  177.             bcs wdx               ;no quote - must be blocks free
  178.             ldy #0                
  179.             jsr prttq             ;get file name
  180.             sty namlen            
  181.             bcs wdx               ;screwed up directory - better quit than crash
  182. spc         jsr chrin             ;get type
  183.             cmp #" "              
  184.             beq spc               
  185.             cmp #">"              
  186.             beq spc               
  187.             jsr setcol            
  188.             ldy #0                
  189. prtnam      lda name,y            
  190.             jsr chrout            
  191.             iny                   
  192.             cpy namlen            
  193.             bne prtnam            
  194. wd2         lda #" "              ;spc(20-len(filename))
  195.             jsr chrout            
  196.             lda pntr              ;get cursor column
  197.             beq wd1               
  198.             cmp #20               
  199.             beq wd1               
  200.             cmp #40               
  201.             beq wd1               
  202.             cmp #60               
  203.             beq wd1               
  204.             bne wd2               
  205.                                   
  206. wd1         jsr skp0              
  207.             clc                   
  208.             lda blo               
  209.             adc blt               
  210.             sta blt               
  211.             lda blh               
  212.             adc blt+1             
  213.             sta blt+1             
  214.             inc blf               
  215.             jmp wdlp              
  216.                                   
  217. wdx         jsr crdo              
  218.             jsr white             
  219.             lda blt+1             
  220.             ldx blt               
  221.             jsr linprt            
  222.             jsr lcyan             
  223.             jsr primm             
  224.             .asc " blocks in ", 0 
  225.             jsr white             
  226.             lda #0                
  227.             ldx blf               
  228.             jsr linprt            
  229.             jsr lcyan             
  230.             jsr primm             
  231.             .asc " files.",13,0
  232.             jsr white             
  233.             lda blh               
  234.             ldx blo               
  235.             jsr linprt            
  236.             jsr lcyan             
  237.             jsr primm             
  238.             .asc " blocks free.",13,0
  239.             jmp int0e             
  240.                                   
  241. skpq        jsr chrin             
  242.             cmp #0                
  243.             beq bdq               
  244.             cmp #34               
  245.             bne skpq              
  246. skpqrt      clc                   
  247.             rts                   
  248.                                   
  249. prttq       jsr chrin             
  250.             cmp #0                
  251.             beq bdq               
  252.             cmp #34               
  253.             beq skpqrt            
  254.             sta name,y            
  255.             iny                   
  256.             bne prttq             
  257.                                   
  258. bdq         sec                   
  259.             rts                   
  260.                                   
  261. blo         .byt 0                
  262. blh         .byt 0                
  263. blf         .byt 0                
  264. blt         .wor 0                
  265.                                   
  266. skp4        jsr skp2              
  267. skp2        jsr chrin             
  268.             jmp chrin             
  269.                                   
  270. skp0        jsr chrin             
  271.             cmp #0                
  272.             bne skp0              
  273.             rts                   
  274.                                   
  275. white       lda #$8f              
  276.             .byt $2c              
  277. lgreen      lda #$85              
  278.             .byt $2c              
  279. dgreen      lda #$84              
  280.             .byt $2c              
  281. yellow      lda #$8d              
  282.             .byt $2c              
  283. brown       lda #$8c              
  284.             .byt $2c              
  285. purple      lda #$8b              
  286.             .byt $2c              
  287. lcyan       lda #$87              
  288.             sta $f1               
  289.             rts                   
  290.                                   
  291. flag        .byt 0                
  292.                                   
  293. setcol      cmp #"*"              
  294.             beq white             
  295.             cmp #"s"              
  296.             beq dgreen            
  297.             cmp #"p"              
  298.             beq lcyan             
  299.             cmp #"r"              
  300.             beq purple            
  301.             cmp #"u"              
  302.             beq brown             
  303.             bne yellow            
  304.                                   
  305. namlen      *=*+1                 
  306. name        *=*+32                
  307.                                   
  308.             .end                  
  309.