home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / PROGRAMS / WSTAR / WSLOAD.LBR / WSLOAD.AQM / WSLOAD.ASM
Assembly Source File  |  2000-06-30  |  13KB  |  625 lines

  1. ; WSLOAD ------------------------ A WordStar Utility
  2. ; This utility is described fully in WSLOAD.DOC within the library.  
  3. ; The source code here is included in the event that you need to reset 
  4. ; the OFFSET variable to a higher address.  The code below will 
  5. ; assemble correctly with either MicroSoft's M80 or with the fine 
  6. ; public domain assmebler Z80MR.  If you have problems or need special 
  7. ; assistance, I will be glad to do what I can.  Please send a SAS 
  8. ; envelope and/or disk.
  9. ; Lindsay Haisley
  10. ; 14206 Spreading Oaks
  11. ; Leander, TX  78641
  12. ;
  13. ;
  14. ; ****  THE OFFSET VARIABLE:
  15. ; --------------------------
  16. ;
  17. ; The offset variable below is the address of the end of your current 
  18. ; version of WordStar.  The is usually 4600 hex but if the area beyond 
  19. ; this address is already in use for an initialization routine, you must 
  20. ; find an area of free memory above this routine for WSLOAD to use. 
  21. ;
  22. ; WSLOAD will give you a "MORPAT OVERLAY" error if an init routine 
  23. ; already occupies the area above the current value of the offset.  You 
  24. ; must use DDT, Z8E, ZSID or some similar utility to find a string of 
  25. ; null or unused bytes above the offset address and reset "offset" to 
  26. ; the address of this string.  You may need to load WordStar and SAVE a 
  27. ; page or two more than the usual 70.  Make sure you have 200 bytes of 
  28. ; free space available for WSLOAD to occupy.
  29.  
  30. offset    equ    4600h
  31.     
  32.  
  33. ; -----------------------------------------------------------------------
  34.     
  35. aseg    
  36. .z80    ; IGNORE THIS ERROR WITH Z80MR
  37.  
  38. ; WordStar user patch area equates
  39.     
  40. inisub    equ    0287h
  41. morpat    equ    02CBh
  42. fnwscm    equ    0400h
  43.     
  44. loadpt    equ    1100h        ; Address of WordStar in memory for this prog.
  45.  
  46. loadref    equ    loadpt-100h
  47.     
  48.  
  49. ; CODE STARTS HERE
  50.     
  51.     org    100h
  52.     jp    ustart
  53.  
  54.     
  55. fcb1:    defb    0,20h,20h,20h,20h,20h,20h,20h,20h,20h,20h,20h,0,0,0,0
  56.     defb    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  57. fcb2:    defb    0,20h,20h,20h,20h,20h,20h,20h,20h,20h,20h,20h,0,0,0,0
  58.     defb    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  59. fcb3:    defb    0,20h,20h,20h,20h,20h,20h,20h,20h,20h,20h,20h,0,0,0,0
  60.     defb    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  61.     
  62. cflag:    defb    '+'
  63.     defb    0
  64.     
  65. fnbuf:    defb    0,0,0,0,0,0,0,0,0,0,0,0,0,0
  66. endbuf:    defb    0
  67.  
  68. getmsg:    defb    0dh,0ah,'Enter the filename of your version of WordStar => ',0
  69. outmsg:    defb    0dh,0ah,'Enter the name you want for WordStar with WSLOAD'
  70.     defb    ' installed => ',0
  71. csmsg1: defb    0dh,0ah,'Enter the character you want to preceed overlay '
  72.     defb    'filenames => ',0
  73. csmsg2:    defb    0dh,0ah,0ah,'All configuration overlays (except '
  74.     defb    'the default) must start with '''
  75.     defb    0
  76. csmsg3:    defb    '''',0dh,0ah,0
  77. e1msg:    defb    0dh,0ah,'File ',0
  78. e2msg:    defb    ' not found',0dh,0ah,0    
  79. dnmsg:    defb    0dh,0ah,'Modified WordStar written to disk as ',0
  80. mpemsg:    defb    0dh,0ah,'MORPAT ERROR - Reset patch location',0dh,0ah,0 
  81. cremsg:    defb    0dh,0ah,'Out of directory space.  Can''t create output file.'
  82.     defb    0dh,0ah,0
  83. wremsg:    defb    0dh,0ah,'Disk full. Operation aborted.',0dh,0ah,0
  84. defmsg:    defb    0dh,0ah,'Enter the default configuration filename => ',0
  85. bktxt:    defb    08h,20h,08h,0
  86. nline:    defb    0dh,0ah,0    
  87.  
  88. ; PROGRAM STARTS HERE
  89.  
  90. ustart:    ld    de,getmsg     ; Ask for filename
  91.     call    zprt
  92.     call    getname
  93.     cp    03h
  94.     jp    z,0000
  95.     ld    a,(fnbuf)
  96.     or    a
  97.     ret    z        ; Return to system if none given
  98.     ld    hl,fcb1
  99.     call    xfer    
  100.     ld    c,0fh        ; Now open the file, if possible
  101.     ld    de,fcb1
  102.     call    5
  103.     inc    a
  104.     jr    nz,ffound
  105.     ld    de,e1msg    ; If no find, report and quit
  106.     call    zprt
  107.     ld    de,fcb1
  108.     call    fnshow
  109.     ld    de,e2msg
  110.     call    zprt
  111.     ret            ; No Wordstar, no work !! (I quit!)
  112.     
  113. ffound:    ld    hl,fcb1        ; Save open fcb for output if necessary
  114.     ld    de,fcb3
  115.     ld    bc,24h
  116.     ldir
  117.     
  118.     ld    de,loadpt    ; Read the input file to memory
  119.     call    readfile
  120.     push    hl        ; Save size of file
  121.     
  122.     ld    de,outmsg    ; Get name of output file
  123.     call    zprt
  124.     call    getname
  125.     cp    03h
  126.     jp    z,0000
  127.     ld    hl,fcb2
  128.     call    xfer
  129.     
  130.     ld    de,fcb1        ; Is input same as output
  131.     ld    hl,fcb2
  132.     call    namecmp
  133.     jr    z,same
  134.     
  135.     ld    a,(fcb2+1)    ; Or is no filename specified
  136.     cp    20h
  137.     jr    nz,notsme
  138. same:    ld    hl,fcb3        ; Restore FCB opened for input to output FCB
  139.     ld    de,fcb2
  140.     ld    bc,24h
  141.     ldir
  142.     jr    creok
  143.     
  144.     
  145.     
  146. notsme:    ld    c,13h        ; Erase any file of similar name
  147.     ld    de,fcb2
  148.     call    5
  149.     ld    c,16h        ; Create the file
  150.     ld    de,fcb2
  151.     call    5
  152.     inc    a
  153.     jr    nz,creok    ; If directory full, say so and quit
  154.     pop    de
  155.     ld    de,cremsg
  156.     call    zprt
  157.     ret
  158.     
  159. creok:    ld    de,defmsg     ; Get the default config. filename
  160.     call    zprt
  161.     call    getname
  162.     cp    03h
  163.     jp    z,0000
  164.     ld    hl,dnme
  165.     call    xfer
  166.     
  167. getflg:    ld    de,csmsg1    ; Get the flag character
  168.     call    zprt
  169.     ld    c,01
  170.     call    5
  171.     call    upcase
  172.     cp    0dh
  173.     jr    z,ffdef        ; If none given, use default
  174.     cp    21h        ; Don't accept control characters
  175.     jr    nc,ffok
  176.     call    bell
  177.     jp    getflg
  178.  
  179. ffok:    ld    (cflag),a    ; Tell about the flag
  180. ffdef:    ld    de,csmsg2
  181.     call    zprt
  182.     ld    de,cflag
  183.     call    zprt
  184.     ld    de,csmsg3
  185.     call    zprt
  186.     
  187.     
  188. ; ACTUAL MODS TO WORDSTAR START HERE
  189.     
  190.     ld    a,(inisub+loadref)
  191.     cp    0c3h            ; See if JP instruction in INISUB
  192.     jr    nz,okini
  193.     ld    hl,(inisub+loadref+1)    ; If so, see where it JP's to
  194.     and    a
  195.     ld    de,offset
  196.     sbc    hl,de
  197.     jp    c,morpok
  198.     ld    de,mpemsg
  199.     call    zprt
  200.     pop    de
  201.     ret                ; If inisub too hi, quit
  202.     
  203. okini:    ld    a,0c3h            ; Put a JP in inisub
  204.     ld    (inisub+loadref),a
  205.     ld    a,0c9h        ; RETurn instruction instead of a JP to MORPAT
  206.     ld    (retins),a    ; 
  207.     
  208. morpok:    add    hl,de
  209.     ld    de,offset
  210.     ld    (inisub+loadref+1),de    ; Set up a patch and return situation
  211.     ld    (retad),hl
  212.     
  213.     ld    a,(cflag)    ; Enter the flag character into the overlay
  214.     ld    (f1+1),a
  215.     ld    (f2+1),a
  216.  
  217.     ld    hl,fcb2        ; Save the filename for later use by WordStar
  218.     ld    de,nme
  219.     ld    bc,12
  220.     ldir
  221.     
  222. ; Now move the working code into WordStar image
  223.     
  224.     ld    hl,patstrt
  225.     ld    de,loadref+offset
  226.     ld    bc,patend-patstrt
  227.     ldir
  228.  
  229. ; Now write the image back to a file
  230.     
  231.     ld    de,loadpt
  232.     pop    bc
  233.     call    writfile    ; Write the file
  234.     jr    z,alldn
  235.     ld    de,fcb2
  236.     ld    c,13h
  237.     call    5
  238.     ld    de,wremsg    ; If error, say so
  239.     call    zprt
  240.     ret
  241.     
  242. ; All done, so say so and quit
  243.     
  244. alldn:    ld    de,dnmsg
  245.     call    zprt
  246.     ld    de,fcb2
  247.     call    fnshow
  248.     ld    de,nline
  249.     call    zprt
  250.     ret
  251.         
  252.     
  253. ; ++++++++++++++++++++++++ SUBROUTINES ++++++++++++++++++++++++++
  254.  
  255. getname:    ; Get a valid CP/M filename to fnbuf
  256.     
  257.     xor    a        ; Zero fnbuf
  258.     ld    hl,fnbuf
  259.     ld    de,fnbuf+1
  260.     ld    (hl),a
  261.     ld    bc,11
  262.     ldir
  263.     ld    hl,fnbuf
  264.     
  265. fnloop:    ld    de,06        ; Use BIOS to fetch character
  266.     call    ubios    
  267.     cp    03h
  268.     ret    z
  269.     cp    0dh        ; Check for CR to mark end of string
  270.     jr    nz,morget
  271.     ld    (hl),0
  272.     ld    de,nline    ; If end, go on
  273.     call    zprt
  274.     ret
  275. morget:    call    upcase        ; Convert to Upper case, if approp.
  276.     jr    c,okchar    ; If conversion done, character must be OK
  277.     cp    7fh        ; Is it a DEL
  278.     jr    z,bsordl
  279.     cp    08h        ; Or is it a BS
  280.     jr    nz,notbs
  281. bsordl:    ld    de,fnbuf    ; Ignore if start of buffer
  282.     and    a
  283.     push    hl
  284.     sbc    hl,de
  285.     pop    hl
  286.     jr    z,fnloop    
  287.     dec    hl
  288.     ld    de,bktxt
  289.     push    hl
  290.     call    zprt
  291.     pop    hl
  292.     jr    fnloop
  293.     
  294. notbs:    cp    21h        ; Don't accept other control characters
  295.     jr    c,fnloop
  296.     
  297. okchar:    ld    de,endbuf    ; Check to see if end of buffer reached
  298.     and    a
  299.     push    hl
  300.     sbc    hl,de
  301.     pop    hl
  302.     jr    c,sizok
  303.     call    bell
  304.     jr    fnloop
  305. sizok:    ld    (hl),a        
  306.     inc    hl
  307.     ld    c,a
  308.     ld    de,09h
  309.     call    ubios
  310.     jr    fnloop
  311.     
  312. ; --------------------------------------------------------------
  313. xfer:        ; Transfer filename in FNBUF to (hl) in FCB format
  314.  
  315.     push    hl
  316.     xor    a        ; Clean and prep area to recieve transfer
  317.     ld    (dotflg),a
  318.     ld    (hl),a        ; 0 for disk
  319.     inc    hl
  320.     ld    (hl),20h
  321.     push    hl
  322.     pop    de
  323.     inc    de
  324.     ld    bc,10
  325.     ldir
  326.     
  327.     pop    hl
  328.     ld    de,fnbuf    ; Do disk desig, if there is one
  329.     ld    a,(fnbuf+1)
  330.     cp    ':'
  331.     jr    nz,nodisk
  332.     ld    a,(de)
  333.     sub    40h
  334.     ld    (hl),a
  335.     inc    de
  336.     inc    de
  337. nodisk:    inc    hl
  338.     ld    b,8
  339. xlup:    ld    a,(de)        ; Then copy characters
  340.     or    a
  341.     ret    z
  342.     cp    '.'        ; Check for a dot
  343.     jr    nz,nodot
  344.     ld    a,(dotflg)    ; Make sure only one dot
  345.     or    a
  346.     ret    nz
  347.     dec    a
  348.     ld    (dotflg),a
  349.     inc    de
  350.     ld    c,b        ; Set to copy extent, if any
  351.     ld    b,0
  352.     add    hl,bc
  353.     ld    b,3
  354.  
  355. nodot:    ld    a,b
  356.     or    a
  357.     jr    z,lulu
  358.     ld    a,(de)
  359.     ld    (hl),a
  360.     dec    b
  361.     inc    hl
  362. lulu:    inc    de
  363.     jr    xlup
  364.     
  365. dotflg:    defb    00        ; Flag to prevent multiple dots in name
  366.     
  367. ; ---------------------------------------------------------------
  368. readfile:    ; Load file spec in FCB1 to mem starting at (de)
  369.         ; Return number of sectors loaded in hl
  370.     
  371.     ld    bc,00
  372.  
  373. rloop:    push    de
  374.     push    bc        ; Save sector counter
  375.     ld    c,1ah
  376.     call    5        ; Set DMA as per reg de
  377.     ld    c,14h
  378.     ld    de,fcb1
  379.     call    5        ; Read a Sector
  380.     pop    bc
  381.     pop    de
  382.     or    a
  383.     jr    nz,lfdone
  384.     
  385.     ld    hl,80h        ; Bump the DMA pointer
  386.     add    hl,de        
  387.     ex    de,hl
  388.     
  389.     inc    bc        ; Bump the sector counter
  390.     jr    rloop        ; Go back for more
  391.     
  392. lfdone:    ld    h,b        
  393.     ld    l,c    
  394.     ret
  395.     
  396. ; --------------------------------------------------------------------
  397. writfile:    ; Writes (bc) sectors from memory, starting at (de) to
  398.         ; the file spec in FCB2.  Closes the file when done.
  399.     
  400.     ld    a,c
  401.     or    b
  402.     jr    z,wfdone    ; Check up on the sector count
  403.     push    de
  404.     push    bc        ; Set the DMA
  405.     ld    c,1ah
  406.     call    5
  407.     ld    c,15h        ; Write a record
  408.     ld    de,fcb2
  409.     call    5
  410.     pop    bc
  411.     pop    de
  412.     and    a
  413.     ret    nz
  414.     
  415.     ld    hl,80h        ; Bump the DMA pointer
  416.     add    hl,de        
  417.     ex    de,hl
  418.  
  419.     dec    bc
  420.     jr    writfile    
  421.     
  422. wfdone:    ld    c,10h        ; Close the file
  423.     ld    de,fcb2
  424.     call    5
  425.     xor    a
  426.     ret
  427.     
  428. ; --------------------------------------------------------------------
  429. namecmp:    ; Compares two names in FCB (12) bytes.  Returns zflg 
  430.         ; according to results of compare
  431.     
  432.     ld    b,12
  433. cmplup:    ld    a,(de)
  434.     cp    (hl)
  435.     ret    nz
  436.     inc    de
  437.     inc    hl
  438.     dec    b
  439.     jr    nz,cmplup
  440.     ret
  441.     
  442.     
  443. ; --------------------------------------------------------------------
  444. ubios:    push    hl        ; Use a BIOS direct call.  Save hl reg.
  445.     ld    hl,(001)    ; de contains offset from BIOS start
  446.     add    hl,de
  447.     ld    (bi1),hl
  448. bi1    equ    $+1
  449.     call    0000        ; Self mod code
  450.     pop    hl
  451.     ret
  452.     
  453. ; ---------------------------------------------------------------------
  454. zprt:    ld    a,(de)        ; print null term string
  455.     or    a
  456.     ret    z
  457.     push    de
  458.     ld    c,2
  459.     ld    e,a
  460.     call    5
  461.     pop    de
  462.     inc    de
  463.     jr    zprt
  464.  
  465. ; ---------------------------------------------------------------------
  466. fnshow:        ; Show a file name in *.* format from FCB format (in de)
  467.  
  468.     ex    de,hl
  469.     ld    a,(hl)
  470.     cp    0
  471.     jp    z,nfndsk
  472.     add    a,40h
  473.     push    hl
  474.     ld    e,a
  475.     ld    c,2
  476.     call    5
  477.     ld    e,':'
  478.     ld    c,2
  479.     call    5
  480.     pop    hl
  481. nfndsk:    inc    hl
  482.     ld    b,8
  483.     call    nfnlup
  484. doext:    ld    c,b
  485.     ld    b,0
  486.     add    hl,bc
  487.     ld    a,(hl)
  488.     cp    20h
  489.     ret    z
  490.     ld    e,'.'
  491.     ld    c,2
  492.     push    hl
  493.     call    5
  494.     pop    hl
  495.     ld    b,3
  496.     call    nfnlup
  497.     ret
  498.     
  499. nfnlup:    ld    e,(hl)
  500.     ld    a,20h
  501.     cp    e
  502.     ret    z
  503.     push    bc
  504.     push    hl
  505.     ld    c,2
  506.     call    5
  507.     pop    hl
  508.     pop    bc
  509.     inc    hl
  510.     dec    b
  511.     jr    nz,nfnlup
  512.     ret    
  513.     
  514. ; ---------------------------------------------------------------------
  515. upcase:    cp    61h        ; Convert to upper case
  516.     jr    c,notlo
  517.     cp    7bh
  518.     ret    nc
  519.     and    01011111b    ; If it is, uppercase it
  520.     and    a
  521. notlo:    ccf
  522.     ret
  523.  
  524. ; ---------------------------------------------------------------------
  525. bell:    push    hl        ; Ring the bell !!
  526.     ld    c,02
  527.     ld    e,07
  528.     call    5
  529.     pop    hl
  530.     ret
  531.     
  532. ; ----------------------------------------------------
  533. ; THE FOLLOWING IS THE PATCH TO THE END OF WORDSTAR
  534. ; ----------------------------------------------------    
  535.     
  536. patstrt    equ    $
  537.     ld    hl,05dh            ; find an argument, if any
  538.     ld    a,(hl)
  539. f1:    cp    0
  540.     jr    z,isarg-offset+patstrt
  541.     ld    hl,06dh
  542.     ld    a,(hl)
  543. f2:    cp    0
  544.     jr    z,isarg-offset+patstrt
  545.     jr    godef-offset+patstrt    ; if none, try for the default fnme
  546.     
  547. isarg    equ    $+offset-patstrt
  548.     dec    hl
  549.     push    hl
  550.     ld    de,fcb            ; move the filename to the fcb
  551.     ld    bc,12
  552.     ldir
  553.     pop    de
  554.     ld    a,e
  555.     cp    05ch            ; If first arg, substitute second arg
  556.     jr    nz,nomove-offset+patstrt
  557.     ld    hl,06ch
  558.     ld    bc,12
  559.     ldir
  560.     
  561. nomove    equ    $+offset-patstrt
  562.     call    open            ; open the file
  563.     jr    nz,pgodef-offset+patstrt
  564. godef    equ    $+offset-patstrt    ; If not found, try the default fnme
  565.     ld    hl,defnme
  566.     ld    de,fcb
  567.     ld    bc,12
  568.     ldir
  569.     call    open
  570.     jr    z,jrret-offset+patstrt    ; Can't find anything, so just do WS
  571.     
  572. pgodef    equ    $+offset-patstrt
  573.     ld    de,80h            ; Get set to loop
  574.     push    de
  575.  
  576. lloop     equ    $+offset-patstrt
  577.     pop    hl
  578.     ld    de,80h
  579.     add    hl,de        
  580.     ex    de,hl
  581.     push    de
  582.     ld    c,1ah
  583.     call    5        ; Advance DMA by 80h bytes
  584.     ld    c,14h
  585.     ld    de,fcb  
  586.     call    5        ; Read a Sector
  587.     or    a
  588.     jr    z,lloop-offset+patstrt    ; Until no more to read
  589.     pop    de
  590.     ld    de,80h        ; Restore DMA
  591.     ld    c,1ah
  592.     call    5
  593.     
  594.     ld    de,fnwscm    ; Move the filename into WordStar
  595.     ld    hl,wsname
  596.     ld    bc,12
  597.     ldir
  598.  
  599. retins    equ    $
  600. jrret    equ    $+offset-patstrt
  601.     jp    0000
  602. retad    equ    $-2
  603.  
  604. open    equ    $+offset-patstrt
  605.     ld    c,0fh
  606.     ld    de,fcb
  607.     call    5
  608.     inc    a
  609.     ret
  610.  
  611.     
  612. fcb    equ    $+offset-patstrt
  613.     defb    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  614.     defb    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  615. wsname    equ    $+offset-patstrt
  616. nme:    defb    0,0,0,0,0,0,0,0,0,0,0,0
  617.     defb    0
  618. defnme    equ    $+offset-patstrt
  619. dnme:    defb    0,'           '
  620.     defb    0
  621. patend    equ    $
  622.     end
  623.