home *** CD-ROM | disk | FTP | other *** search
/ 8bitfiles.net/archives / archives.tar / archives / genie-commodore-file-library / C64-128Toolkit / WEDGE.SRC.ARC / WEDGE.SRC
Encoding:
Text File  |  2019-04-13  |  14.8 KB  |  561 lines

  1. ;*                             *
  2. ;*  pet dos support            *
  3. ;*                             *
  4. ;*    04-27-79                 *
  5. ;*                             *
  6. ;* copyright (c) 1979,1982     *
  7. ;* commodore business machines *
  8. ;*          inc.               *
  9. ;*                             *
  10. ;*  bob fairbairn              *
  11. ;*                             *
  12. ;*******************************
  13. ;
  14. ;
  15. ;***************************************
  16. ;* this software is furnished for use  *
  17. ;* use in the commodore computer       *
  18. ;* series only.                        *
  19. ;*                                     *
  20. ;* copies thereof may not be provided  *
  21. ;* or made available for use on any    *
  22. ;* other system.                       *
  23. ;*                                     *
  24. ;* the information in this document is *
  25. ;* subject to change without notice.   *
  26. ;*                                     *
  27. ;* no responsibility is assumed for    *
  28. ;* reliability of this software.       *
  29. ;*                                     *
  30. ;* this disclaimer must always be      *
  31. ;* included with this source code      *
  32. ;*                                     *
  33. ;***************************************
  34. ;
  35. ;
  36. ;****************************************
  37. ;* version 5.0 12/16/81-02/10/82        *
  38. ;*    add new commands, allow to work in*
  39. ;*    running program. put volume names *
  40. ;*    in all commands using brackets    *
  41. ;*    only works with basic4.0          *
  42. ;*                                      *
  43. ;*                                      *
  44. ;* version 5.1/64   06/07/82-07/13/82   *
  45. ;*    make work with commodore 64       *
  46. ;*                                      *
  47. ;****************************************
  48. .page
  49. ;
  50. ;basic variables used
  51. ;
  52. bufpt  =$a6            ;cassette (two bytes)
  53. cntdn  =$a5            ;save area
  54. txttab =$2b            ;pointer to basic start
  55. txtptr =$7a            ;pointer to buf
  56. satus  =$90            ;status byte
  57. sa     =$b9            ;secondary address
  58. fa     =$ba            ;primary address
  59. fnlen  =$b7            ;file name length
  60. fnadr  =$bb            ;file name address
  61. eal    =$ae            ;end addr lo
  62. eah    =$af            ;hi
  63. vartab =$2d            ;end of basic pgm.
  64. tmp2   =$c3            ;temp variable
  65. buf    =$0200          ;input buffer
  66. ;
  67. ;program variables
  68. ;
  69. cr     =$0d            ;symbolic carriage return
  70. .page
  71. ;
  72. ;cbm 64  routines used (2.0 basic)
  73. ;
  74. main   =$a48c          ;where called from(main+12)
  75. linprt =$bdcd          ;print line #
  76. clsei  =$f642          ;close a file
  77. loadsp =$ffd5          ;load routine
  78. chrget =$73            ;inputs characters
  79. chrgot =$79            ;get last char
  80. gone   =$a7e6          ; statement exec(ngone+2)
  81. snerr  =$af08          ; syntax error print
  82. chdgot =$e3a8          ;rom copy of chrgot
  83. newstt =$a7ae          ;new statement exec
  84. prt    =$e716          ;print a character
  85. listn  =$ffb1          ;send listen
  86. setmsg =$ff90          ;set kernal messages
  87. secnd  =$ff93          ;send sa
  88. ciout  =$ffa8          ;send character
  89. unlsn  =$ffae          ;un listen
  90. acptr  =$ffa5          ;get a charcater
  91. talk   =$ffb4          ;send talk
  92. openi  =$f3d5          ;open file
  93. ready  =$e386          ;reenter basic
  94. runc   =$a659          ;clear variables and stack
  95. lnkprg =$a533          ;link basic lines
  96. untlk  =$ffab          ;un talk
  97. stxtpt =$a68e          ;set start text pointer
  98. stop   =$ffe1          ;check for stop key
  99. csave  =$e156+3        ;save with address set (basic)
  100. tksa   =$ff96          ;talk secondary address
  101. getin  =$ffe4          ;get a character
  102. .page  'wedge parser'
  103. ;
  104. ;wedge in routine with the
  105. ;command parser and executition
  106. ;
  107. *=$cc00
  108. jmp    gooo
  109. tabhi
  110. .byt   >zz1            ;%        load (non relo)
  111. .byt   >zz1            ;/        load
  112. .byt   >zz1            ;/ token    "
  113. .byt   >zz2            ;^        load/run
  114. .byt   >zz2            ;^ token   "    "
  115. .byt   >zz3            ;_        save
  116. .byt   >zz4            ;>        disk command
  117. .byt   >zz4            ;> token    "     "
  118. .byt   >zz4            ;@          "     "
  119. .byt   >zz5            ;#        change device
  120. .byt   >zz6            ;q        quit
  121. ;
  122. tablo
  123. .byt   <zz1            ;%
  124. .byt   <zz1            ;/
  125. .byt   <zz1            ;/ token
  126. .byt   <zz2            ;^
  127. .byt   <zz2            ;^ token
  128. .byt   <zz3            ;_
  129. .byt   <zz4            ;>
  130. .byt   <zz4            ;> token
  131. .byt   <zz4            ;@
  132. .byt   <zz5            ;#
  133. .byt   <zz6            ;q
  134. ;
  135. ncmd   =9              ;number of main commands
  136. cmd    .byt '%/',$ad,'^',$ae,'_','>',$b1,'@#q',$00
  137. ;commands  % / / ^ ^ _ > > @ # q
  138. ;commands  1 2 3 4 5 6 7 8 9 a b
  139. ;
  140. file   *=*+1           ;data for disk is stored here
  141. file1  *=*+79
  142. svfa   *=*+1           ;save fa
  143. vol    *=*+1           ;volume name
  144. lastch *=*+1           ;last char from chrget
  145. flag   *=*+1           ;save command
  146. msgs   .byt $d,$d,'      dos manager v5.1/071382',$d
  147. .byt   $d, '         by  bob fairbairn',$d
  148. .byt   $d, '(c) 1982 commodore business machines',$d,$0
  149. jump   jmp start       ;overlay for z-page 'chrgot'
  150. .page  'init code      ; vector'
  151. ;
  152. ; init the memory manager (startup comes here)
  153. ;
  154. gooo
  155.        ldx #$02        ;move three bytes
  156. wedge  lda jump,x
  157.        sta chrgot+3,x
  158.        dex
  159.        bpl wedge
  160. ;
  161.        lda fa          ;use current fa for device addr
  162.        sta svfa
  163. ;
  164. ; say hello and exit
  165. ;
  166.        jmp msg         ;print hello (jsr/rts)
  167. ;
  168. ; this is where we come to do the work
  169. ;
  170. start
  171.        sta bufpt       ;save .a, .x
  172.        stx bufpt+1
  173.        tsx             ;activated  call in 'gone'
  174.        lda $0101,x
  175.        cmp #<gone      ;from a running program??
  176.        beq trytwo
  177.        cmp #<main      ;from direct mode??
  178.        bne notcmd
  179. trytwo lda $0102,x
  180.        cmp #>gone      ;program?
  181.        beq findit
  182.        cmp #>main      ;direct?
  183.        bne notcmd
  184. findit lda bufpt       ;get the command back
  185.        ldx #ncmd-1
  186. findc  ;find the command
  187.        cmp cmd,x
  188.        beq call10
  189.        dex
  190.        bpl findc
  191. ;
  192. notcmd
  193.        lda bufpt       ;restore regs
  194.        ldx bufpt+1
  195.        cmp #':         ;complete chrgot
  196.        bcs strts
  197.        jmp chrgot+7
  198. strts  jmp chrgot+17   ;to the end of chrgot
  199. ;
  200. call10
  201.        stx cntdn       ;save index
  202.        sta flag        ;save the command for later
  203.        jsr rdfile      ;get the filename and length
  204.        ldx cntdn       ;restore index
  205.        lda #<file      ;set filename address
  206.        sta fnadr
  207.        lda #>file
  208.        sta fnadr+1
  209.        lda svfa        ;set primary address
  210.        sta fa
  211. ;
  212. callit
  213.        lda tabhi,x     ;found command...go there
  214.        pha
  215.        lda tablo,x
  216.        pha
  217.        rts
  218. .pag
  219. ;
  220. ;main action routine for wedge commands '>@'
  221. ;
  222. doit
  223.        tya             ;.y has fnlen
  224.        beq rderr       ;no data so read e. c.
  225. ;
  226.        ldx #ncmd       ;now check for sub-commands
  227. chksub
  228.        lda cmd,x
  229.        beq chklst      ;ran out...
  230.        cmp file        ;is this a command?
  231.        beq fndsub      ;yes...
  232.        inx
  233.        bpl chksub
  234. ;
  235. chklst ;not a sub-command
  236.        lda file        ;is this a dir command
  237.        cmp #'$
  238.        beq dodir       ;directory stuff
  239.        jmp notdir      ;disk commands
  240. ;
  241. ;
  242. fndsub ;found sub command
  243.        dec fnlen       ;setup and go there
  244.        lda #<file1
  245.        sta fnadr
  246.        lda #>file1
  247.        sta fnadr+1
  248.        jmp callit
  249. .page  'disk cmd & e. c.'
  250. ;
  251. ; send command to disk
  252. ;
  253. notdir
  254.        lda fa          ;device address
  255.        jsr listn
  256.        lda #$6f
  257.        sta sa
  258.        jsr secnd       ;send secondary addr
  259.        ldy #0
  260. bump   lda file,y
  261.        jsr ciout
  262.        iny
  263.        cpy fnlen
  264.        bcc bump        ;more
  265. ;
  266.        jsr unlsn       ;un listen
  267.        jmp wg998
  268. ;
  269. ; read the error channel
  270. ;
  271. rderr
  272.        lda f
  273.           ;device address
  274.        jsr talk
  275.        lda #$6f        ;command channel sa
  276.        sta sa
  277.        jsr tksa        ;send sa talk style
  278. wg140  jsr acptr       ;get byte from disk
  279.        cmp #cr
  280.        beq wg130
  281.        jsr prt         ;print byte to screen
  282.        jmp wg140       ;loop for more
  283. wg130  jsr prt         ;print cr
  284.        jsr untlk       ;un talk
  285. wg998  jmp chrgot      ;done with cmd
  286. .page  'directory read'
  287. ;
  288. ;print the directory '@$0:*'
  289. ;
  290. dodir
  291.        lda #$60        ;secondary addr
  292.        sta sa
  293.        jsr openi       ;open the file
  294.        lda fa          ;get primary address
  295.        jsr talk
  296.        lda sa          ;get secondary address
  297.        jsr tksa
  298. .ski
  299.        lda #0
  300.        sta satus       ;set status to 0
  301.        ldy #$03        ;loop three times
  302. wg220  sty fnlen       ;save new count
  303.        jsr acptr
  304.        sta tmp2
  305.        jsr acptr
  306.        sta tmp2+1
  307.        ldy satus       ;check status
  308.        bne wg230
  309.        ldy fnlen       ;more to do?
  310.        dey
  311.        bne wg220       ;not done yet
  312.        ldx tmp2
  313.        lda tmp2+1
  314.        jsr linprt      ;print line number
  315.        lda #$20        ;print a space
  316.        jsr prt
  317. wg250  jsr acptr
  318.        ldx satus
  319.        bne wg230       ;bad
  320.        cmp #0          ;eol
  321.        beq wg240
  322.        jsr prt
  323. ;check for stop key and pause
  324.        jsr stop        ;stop key
  325.        beq wg230       ;yes...
  326.        jsr getin       ;get a char from keyboard
  327.        beq wg250       ;nothing...
  328. r pause?
  329.        bne wg250       ;no...
  330. wg255  jsr getin       ;any key starts
  331.        beq wg255
  332.        bne wg250       ;(jmp)
  333. ;
  334. wg240  lda #cr
  335.        jsr prt
  336.        ldy #$02        ; do twice
  337.        jmp wg220
  338. ;
  339. ;close floppy and return
  340. ;
  341. wg230  jsr clsei       ;close file
  342.        lda #cr         ;print a return
  343.        jsr prt
  344.        jmp chrgot      ;return
  345. .page  'file load/run'
  346. ;
  347. ;    load or load and run a file
  348. ;  (fnlen is set and the name is in file)
  349. ;  %filename ...... load (non relocating)
  350. ;  /filename ...... load
  351. ;  ^filename ...... load/run
  352. ;
  353. runr
  354. load
  355.        ldx txttab      ;set pointer for auto locate
  356.        ldy txttab+1
  357.        lda flag        ;set type of load
  358.        cmp #'%
  359.        bne load0
  360.        lda #1
  361.        .byt $2c        ;skip2
  362. load0  lda #0
  363.        sta sa
  364.        lda #$0
  365.        jsr loadsp      ;load a program
  366.        bcs lderr       ;trouble in river city
  367.        lda flag        ;load type
  368.        cmp #'%         ;is it an absolute load
  369.        beq load1       ;yes
  370.        lda eah         ;set basic's pointers
  371.        sta vartab+1
  372.        lda eal
  373.        sta vartab
  374.        jsr runc        ;fix pointers
  375.        jsr lnkprg      ;fix links
  376.        lda flag        ;check for load or run
  377.        cmp #$ad        ;load command is / (token)
  378.        beq load1       ;yes...load only
  379.        cmp #'/         ;load command is /
  380.        bne wg300       ;no...load/run
  381. load1  jmp ready       ;load return to basic
  382. wg300  lda #$00        ;no kernal messages
  383.        jsr setmsg
  384.        jsr stxtpt      ;set txtptr for run
  385.        jmp newstt      ;run program
  386. lderr  ;load error
  387.        jmp ready
  388. .page  'quit, save, change'
  389. ;
  390. ; quit command '@q'
  391. ;
  392. quit
  393.        ldx #$02
  394. rest   ;restore 'chrget'
  395.        lda chdgot+3,x
  396.        sta chrgot+3,x
  397.        dex
  398.        bpl rest
  399.        jmp ready
  400. ;
  401. ;save command '_filename'
  402. ;
  403. save   ;save a file
  404.        jsr csave       ;call basic save routine just past parsing
  405.        jmp rderr       ;read thee ec after save
  406. ;
  407. ; change the default device number '@#9'
  408. ;
  409. chgdev
  410.        ldy fnlen
  411.        lda file,y
  412.        and #$0f        ;convert ascii to binary
  413.        sta svfa
  414.        dey
  415.        beq chg10       ;only one number
  416. ;
  417.        lda file,y
  418.        and #$0f
  419.        tay             ;use first digit as count
  420.        beq chg10
  421.        lda svfa
  422.        clc
  423. chg05  adc #10         ;add 10 for each count
  424.        dey
  425.        bne chg05
  426.  sta svfa ;save result
  427. chg10
  428.        jmp chrgot
  429. .page  'subroutines'
  430. ;
  431. ; read filename string from command
  432. ; and place it into file string
  433. ;
  434. rdfile
  435.        ldy #0
  436.        jsr chrget
  437.        tax
  438.        bne rd05        ;more to do...
  439.        jmp setlen      ;done...
  440. rd05   lda #$60        ;do not skip blanks or call me chrget
  441.        sta chrgot+3
  442.        lda txtptr      ;save pointer to data
  443.        pha
  444.        lda txtptr+1
  445.        pha
  446.        txa             ;put first char into .a
  447. rd10   cmp #'"         ;look for quote
  448.        beq rd20
  449.        jsr chrget      ;get next character
  450.        bne rd10
  451.        pla             ;did not find quote (read all of line)
  452.        sta txtptr+1    ;restore pointer
  453.        pla
  454.        sta txtptr
  455.        jsr chrgot      ;get first character on line
  456.        ldx #0          ;file name length count
  457.        cmp #'"         ;looking at quote?
  458.        beq fill        ;yes...(must be when running)
  459.        ldx #>buf       ;if in direct mode then ok
  460.        cpx txtptr+1
  461.        bne filer1      ;must have a quote
  462.        ldx #0
  463.        beq fill10      ;(branch)
  464. rd20   pla             ;found quote do our thing
  465.        pla
  466.        ldx #0
  467. ;
  468. fill
  469.        jsr chrget
  470.        beq setlen
  471. fill10
  472.        cmp #'"         ;end quote?
  473.        beq setlen
  474.        cmp #'=         ;filename start
  475.        beq fill20
  476.        cmp #':         ;filename start
  477.        bne storit
  478. fill20
  479.        ldx #$ff        ;do not count
  480. storit
  481.        cmp #'[         ;start vol stuff?
  482.        beq fill30      ;yes...
  483. stor10
  484.        sta file,y
  485.        sta lastch
  486.        inx
  487.        iny
  488.        bpl fill
  489. ;
  490. fill30
  491.        jsr chrget      ;get vol name
  492.        beq filer1      ;required
  493.        sta vol         ;save it
  494.        jsr chrget      ;get closing delimiter
  495.        beq filer1      ;must be there??...
  496.        cmp #']
  497.        bne filer1      ;wrong delimiter....
  498. ;
  499.        cpx #16         ;see if name is too long
  500.        bcs filer1
  501.        lda lastch      ;if last is * then fill ?
  502.        cmp #'*
  503.        bne filspc
  504.        dey             ;do not put in the *
  505.        dex
  506.        lda #'?
  507.        .byt $2c
  508. filspc lda #$20        ;else fill with space
  509. filpat
  510.        cpx #15         ;are we done yet ?
  511.        bcs filend      ;yes...
  512.        sta file,y
  513.        iny
  514.        inx
  515.        bpl filpat
  516. filend
  517.        lda vol         ;put in the volume name
  518.        bne stor10      ;branch
  519. ;
  520. filer1 ;blow off to syntax error
  521.        ldx #$4c        ;restore chrgot
  522.        stx chrgot+3
  523.        jmp snerr
  524. ;
  525. setlen
  526.        sty fnlen       ;save length
  527.        ldx #$4c        ;restore chrgot
  528.        stx chrgot+3
  529. ;
  530.        jsr chrgot      ;throw away the rest of the line
  531.        beq setrts
  532. setclr
  533.        jsr chrget
  534.        bne setclr
  535. ;
  536. setrts ;done
  537.        rts
  538. ;
  539. ;
  540. ; print the sign on msg
  541. ;
  542. msg
  543.        ldx #$00
  544. outlp  lda msgs,x
  545.        beq msgd
  546.        jsr prt
  547.        inx
  548.        bne outlp
  549. msgd   rts
  550. ;
  551. ;these must be after the definitions
  552. ;
  553. zz1    =load-1         ;load a program
  554. zz2    =runr-1         ;run a program
  555. zz3    =save-1         ;save a program
  556. zz4    =doit-1         ;> call
  557. zz5    =chgdev-1       ;change device number
  558. zz6    =quit-1         ;leave dos support
  559. .end
  560.