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

  1. ;install.asm
  2. ;===========================================
  3. ; CS-DOS Command: install[/bank] patternlist
  4. ;===========================================
  5. ;
  6. ; Revised: 21Mar90 - If bank is not specified, defaults are as follows:
  7. ;
  8. ;                    Load Address ->   $xx01 - Bank 0
  9. ;                                    < $1c00 - bank 15
  10. ;                                    >=$4000 - bank 1
  11. ;                                    Otherwise bank 0
  12.                                   
  13. ;Zero page image of REU registers. If RAMdisk is in the 128,
  14. ;then only 'zrda' is significant.
  15.                                   
  16. zrimg       = $0060               ; Command register
  17. z128        = $0061               ; C128 address
  18. zrda        = $0063               ; REU  address+bank
  19. zxfer       = $0066               ; transfer length
  20.                                   
  21. la          = $00b8               ; logical address of current input file
  22. poker       = $0016               ; two byte temp
  23. parm        = $0026               ; temp
  24. ccl         = $0027               ; temp
  25. status      = $0090               ; I/O status byte
  26. cl          = $1bf7               ; Drive letter for filename returned by int16
  27. rdadr       = $1bf5               ; RAM disk start address if in 128, or page if in 1750
  28. rdmax       = $1bf1               ; Highest RAM address+1 available to the RAM disk
  29. rflag       = $1bf0               ; bit 7 is true if RAM disk is in the 1750
  30. rdbnk       = $1bf3               ; Bank where RAM disk is if its in the 128
  31. sw1         = $1bfc               ; Command line switch 1
  32. tx          = $1bfe               ; Bit 6 is true if the RAMdisk is enabled
  33. int04       = $1704               ; Fetch first character of parameter .x
  34. int05       = $1705               ; Fetch next character after int04
  35. int0a       = $170a               ; Find an unused LA (.a) and SA (.y)
  36. int0e       = $170e               ; Program terminate
  37. int16       = $1716               ; Find 1st matching file for parameter .x
  38. int17       = $1717               ; Find subsequent matches after int16
  39. int21       = $1721               ; Function interrupt
  40. int3f       = $173f               ; Open %x for input using burst read if possible
  41.                                   
  42. chrout      = $ffd2               
  43. primm       = $ff7d               
  44. setnam      = $ffbd               
  45. getcfg      = $ff6b               
  46. setlfs      = $ffba               
  47. fnbank      = $00c7               
  48. open        = $ffc0               
  49. close       = $ffc3               
  50. chkin       = $ffc6               
  51. chrin       = $ffcf               
  52. clrchn      = $ffcc               
  53.                                   
  54. star        = $0b00               
  55.             .wor star             
  56.             * = star              
  57.                                   
  58.  
  59.             jmp start
  60.             dw  Date
  61.  
  62. start       bit tx                ; Abort if RAM disk isn't enabled
  63.             bvs inst              ; it is..continue
  64.             jsr primm             
  65.             .asc 13,"No RAM disk is installed",13, 0
  66. ex3         lda #3                
  67.             jmp int0e             
  68.                                   
  69. inst        lda #13               ; We're in bank 15, and shell did a clrchn
  70.             jsr chrout            
  71. instal      ldx #1                ; start with %1 and work up
  72.             stx parm              
  73.             jsr int04             ; test for parameter
  74.             bcs nprm              ; none there
  75.             jmp in0               ; got one. do it
  76.                                   
  77. nprm        jsr primm             
  78.             .asc 13,"Syntax:  install[/bank] programlist",13
  79.             .asc 13,"Purpose: makes external commands resident.",13, 0
  80. ex1         lda #1                
  81.             .byt $2c              
  82. ex0         lda #0                
  83.             jmp int0e             
  84.                                   
  85. in0         jsr int04             ; 1st test for parameter
  86.             bcs ex0               ; none there...quit
  87.             jsr int16             ; get 1st matching filename
  88.             bcc inok              ; got one
  89.             jmp nxtp              ; else try next parameter
  90.                                   
  91. inok        lda cl                ; get drive letter file is on
  92.             sta ccl               ; save it since int17 might erase it
  93. inagn       lda ccl               ; make a copy of the filename at $1b23
  94.             sta $1b23             ; and echo the filename to the screen
  95.             ldx $1bce             ; change colors
  96.             stx $f1               
  97.             jsr chrout            
  98.             lda #":"              
  99.             sta $1b24             
  100.             jsr chrout            
  101.             ldy #2                
  102. in1         lda $1b01,y           ; echo the name
  103.             cmp #$a0              
  104.             beq in2               
  105.             jsr chrout            
  106.             sta $1b23,y           
  107.             iny                   
  108.             cpy #18               
  109.             bcc in1               
  110. in2         lda #0                ; make name asciiz
  111.             sta $1b23,y           
  112.             sta $1b01,y           
  113. in3         lda #" "              ; tab(16)
  114.             jsr chrout            
  115.             iny                   
  116.             cpy #19               
  117.             bcc in3               
  118.             ldx $1bcb             ; change colors (assume prg for now)
  119.             lda $1b00             ; confirm type=prg
  120.             cmp #130              ; prg=$82
  121.             beq inag0             ; ok. continue
  122.             ldx $1bca             ; different color for SEQ
  123.             cmp #129              ; seq=$81
  124.             beq inag0             ; ok. continue
  125.             ldx $1bc9
  126.             stx $f1
  127.             jsr primm             
  128.             .asc "not PRG or SEQ. Can't install",13, 0
  129.             jmp nxtm              
  130.                                   
  131. inag0       stx $f1               ; change colors for screen
  132.             ldx #$81              ; check if it exists on RAM disk
  133.             ldy #6                
  134.             jsr int21             
  135.             bcs in4               ; it doesn't..add it
  136.             jsr primm             
  137.             .asc "Already installed!",13, 0
  138. nxtm        jsr int17             ; get next match
  139.             bcs nxtp              ; no more. try next parameter
  140.             jmp inagn             ; go again
  141.                                   
  142. nxtp        inc parm              
  143.             ldx parm              
  144.             jmp in0               
  145.                                   
  146.                                   
  147. in4         ldy #8                
  148.             jsr int21             ; goto end of the RAM disk
  149.             bcc inn4              ; ok
  150.             jsr primm             
  151.             .asc 13,"RAM disk corrupt. Can't install", 0
  152. ex4         lda #4                
  153.             jmp int0e             
  154.                                   
  155. inn4        ldy #0                ; make link zero for now in case install fails
  156.             sty $1b60             
  157.             sty $1b61             
  158. inn5        lda zrda,y            ; copy shell's REU register image
  159.             sta szrda,y           ; We'll need it later to adjust the pointer
  160.             iny                   ; if we succeed
  161.             cpy #3                
  162.             bne inn5              
  163.             dey                   ; .y=2
  164. in5         lda $1b01,y           ; move filename to RAMdisk
  165.             sta $1b60,y           
  166.             iny                   
  167.             cmp #0                
  168.             bne in5               
  169.             sty bufsiz            ; initialize stash subroutine
  170.             sty BankPtr           ; Save offset of config from $1b60
  171.             lda $1b00             ; recall type
  172.             and #%10111111        ; get rid of scratch protect flag
  173.             cmp #129              ; seq?
  174.             bne prog              ; no executable
  175.             ldx sw1               ; type or exec?
  176.             cpx #"t"              
  177.             bne exec              
  178.             ora #64               
  179. exec        jmp bank              
  180.                                   
  181. prog        lda sw1               ; get bank
  182.             cmp #$30              ; must be 0-9 or a-f
  183.             bcc use15             ; error. use bank 15
  184.             cmp #$3a              ; is it 0-9?
  185.             bcc usea              ; ok. use it
  186.             sbc #55               ; convert a-z to 10-15
  187.             cmp #16               
  188.             bcs use15             
  189. usea        and #$0f              
  190.             .byt $2c              
  191. use15       lda #15               
  192.             tax                   
  193.             sta $ff03             
  194.             jsr getcfg            
  195. bank        jsr stash             ; save Bank in RAM disk (or type flag for batch files)
  196.             lda #0                ; now open the file
  197.             sta $ff00             
  198.             ldx #$81              
  199.             jsr int3f             ; open for burst read
  200.             bcc GetLoadAddr
  201. derr        jsr primm             
  202.             .asc "disk error?",13, 0
  203. de          jsr clrchn            
  204.             lda la                
  205.             jsr close             
  206.             jmp nxtm              
  207.                                   
  208. toobig      jsr primm             
  209.             .asc "File too large",13, 0
  210.             jmp de
  211.  
  212. GetLoadAddr jsr $1779
  213.             bcs derr
  214.             sta LoadAddr
  215.             jsr stash
  216.             jsr $1779
  217.             bcs derr
  218.             sta LoadAddr+1
  219.             jsr stash
  220.             jsr AdjustBank
  221.  
  222. ina         jsr $1779             ; fetch char
  223.             bcs derr              
  224.             jsr stash             ; stash it
  225.             bcs toobig            ; past end of ramdisk
  226. in9         bit status            
  227.             bmi derr              
  228.             bvc ina               
  229.             jsr flush             
  230.             lda #0                ; eof. stash two zeros
  231.             jsr stash             
  232.             jsr stash             
  233.             sec                   ; and calculate the file size
  234.             lda zrda              
  235.             sbc szrda             
  236.             sta poker             
  237.             lda zrda+1            
  238.             sbc szrda+1           
  239.             sta poker+1           
  240.             lda zrda+2            
  241.             sbc szrda+2           
  242.             bne toobig            ; too big if length is a 3 byte quantity
  243.             jsr flush             
  244.             sec                   ; less the two zeros is the true size
  245.             lda poker             
  246.             sta $1b60             
  247.             lda poker+1           
  248.             sta $1b61             
  249. zip         ldy #2                
  250. zip1        lda szrda,y           ; recall start of entry and adjust the pointer
  251.             sta zrda,y            
  252.             dey                   
  253.             bpl zip1              
  254.             ldy #2                
  255.             sty bufsiz            
  256.             jsr flush             
  257.             jsr primm             
  258.             .asc "installed",13, 0
  259.             jmp de                
  260.                                   
  261.                                   
  262. ;-------------------------
  263. ; Stash byte to RAM drive
  264. ;-------------------------
  265.                                   
  266. stash       sty stsy+1            
  267.             ldy bufsiz            
  268.             sta $1b60,y           ; put in buffer for now
  269.             iny                   
  270.             inc bufsiz            
  271.             cpy #32               
  272.             bcs flush             ; until buffer overflows, then flush it to the REU
  273. stsy        ldy #0                
  274.             clc                   
  275.             rts                   
  276.                                   
  277. flush       pha                   
  278.             bit rflag             ; in 1750?
  279.             bpl inram             ; no. in the 128
  280.             lda bufsiz            ; 1st check for overflow before proceeding
  281.             clc                   
  282.             adc zrda              
  283.             bcc proc              ; no. proceed
  284.             ldy zrda+1            
  285.             cpy #$ff              
  286.             bne proc              
  287.             ldy zrda+2            
  288.             iny                   
  289.             cpy rdmax+1           
  290.             bcc proc              
  291.             rts                   ; overflow...can't flush
  292.                                   
  293. proc        lda bufsiz            
  294.             sta zxfer             
  295.             lda #0                
  296.             sta zxfer+1           
  297.             lda #%10010000        
  298.             sta zrimg             
  299.             lda $d030             
  300.             pha                   
  301.             and #%11111110        
  302.             sta $d030             
  303.             bit $df00             ; clear flags
  304.             ldy #9                
  305. flsh        lda zrimg,y           
  306.             sta $df01,y           
  307.             dey                   
  308.             bpl flsh              
  309. wfls        bit $df00             ; wait for Xfer to complete
  310.             bvc wfls              
  311.             pla                   
  312.             sta $d030             
  313. zb          clc                   ; bump REU pointer
  314.             lda zrda              
  315.             adc bufsiz            
  316.             sta zrda              
  317.             bcc flx               
  318.             inc zrda+1            
  319.             bne flx               
  320.             inc zrda+2            
  321. flx         lda #0                
  322.             sta bufsiz            
  323.             pla                   
  324.             jmp stsy              
  325.                                   
  326. inram       clc                   ; 1st check for overflow
  327.             lda bufsiz            
  328.             adc zrda              
  329.             ldy zrda+1            
  330.             bcc iinr              
  331.             iny                   
  332. iinr        cpy rdmax+1           ; check high byte of ram+buffer+1
  333.             bcc inra              ; ok
  334.             beq iiin              ; maybe
  335.             rts                   ; overflow, can't flush
  336.                                   
  337. iiin        cmp rdmax             ; now low byte
  338.             bcc inra              
  339.             beq inra              
  340.             rts                   
  341.                                   
  342. inra        lda rdbnk+1           ; flush buffer to 128 bank
  343.             sta $ff00             ; We're in common RAM, so any bank is ok
  344.             ldy #0                
  345. inr         lda $1b60,y           ; do it
  346.             sta (zrda),y          
  347.             iny                   
  348.             cpy bufsiz            
  349.             bcc inr               
  350.             lda #0                
  351.             sta $ff00             ; back to bank 15
  352.             beq zb                ; always
  353.  
  354. LoadAddr    dw 0
  355. BankPtr     db 0
  356.  
  357. AdjustBank  lda sw1                 ; Don't adjust if user specified the bank
  358.             bne AdjustDone
  359.             ldy BankPtr             ; Offset to config
  360.             lda $1b60,y
  361.             bmi AdjustDone          ; Its a seq file, no need to adjust
  362.             lda LoadAddr            ; Otherwise force bank 0 for $xx01
  363.             cmp #1
  364.             beq Bank0
  365.             lda LoadAddr+1
  366.             cmp #$1c                ; And bank 15 for < $1c00
  367.             bcc Bank15
  368.             cmp #$40
  369.             bcc Bank0               ; And bank 0 for $1c00 to $3fff
  370.             lda #$7f                ; But bank 1 for $4000 and higher
  371.             db $2c
  372. Bank0       lda #$3f
  373.             db $2c
  374. Bank15      lda #0
  375.             sta $1b60,y
  376. AdjustDone  rts
  377.  
  378.                                   
  379. bufsiz      .byt 0                
  380. szrda       .byt 0, 0, 0          
  381.                                   
  382.             .end                  
  383.