home *** CD-ROM | disk | FTP | other *** search
/ Transactor / Transactor_27_1988_Transactor_Publishing.d64 / shellram.sda / SHELLMAIN.A < prev    next >
Text File  |  2023-02-26  |  7KB  |  497 lines

  1. ;
  2. ; shellram
  3. ;
  4. ;  By: Adrian Pepper
  5. ;      Toronto, Ontario
  6. ;
  7. ;  based on, but heavily modified from
  8. ;  the Pro-Line/Spinnaker
  9. ;    C POWER/POWER C shell for the
  10. ;  Commodore 64 home computer.
  11. ;
  12. ;  The shell was modified to reduce
  13. ;  the size of the code, and arrange
  14. ;  things so memory page 22 (hex $16)
  15. ;  will be free for use as a "RAMdisk
  16. ;  Interface Page", for use with the
  17. ;  Commodore 1764 256K RAM expander
  18. ;  for the Commodore 64
  19. ;
  20. ;  This (basically) allows all programs
  21. ;  designed to run under the shell to
  22. ;  operate with the RAM disk
  23. ;
  24. ;
  25. ; shellmain.a - main loop, plus 
  26. ;   startup, initialization, nmi
  27. ;   handling
  28. ;
  29. ;
  30. ; shell data setup
  31. ;
  32.  .ref usrprog
  33.  .ref sysdev
  34.  .ref sysdrv
  35.  .ref wrkdev
  36.  .ref wrkdrv
  37.  .ref stdinfl
  38.  .ref stdoufl
  39.  .ref argstk
  40. ;
  41. ; kernal routines, etc
  42. ;
  43.  .ref cint
  44.  .ref ioint
  45.  .ref setlfs
  46.  .ref setnam
  47.  .ref open
  48.  .ref close
  49.  .ref chkin
  50.  .ref chkout
  51.  .ref clrchn
  52.  .ref chrin
  53.  .ref chrout
  54.  .ref stop
  55. ;
  56.  .ref nmivec
  57. ;
  58. charclr=$0286
  59. scrbase=$0288
  60. ;
  61. ; =$0801 - link at -s $0801
  62. ;
  63.  .byte $0c,$08 ;link to next basic statement
  64.  .byte $0a,$00 ;line number 10
  65.  .byte $9e,$20,'2,'0,'6,'2 ; sys 2062
  66.  .byte 0,0,0 ; end of basic program
  67. ;
  68.  .def c$start
  69.  .def savnmi
  70.  .def outchr
  71.  .def outln
  72.  .def clrstdo
  73.  .def kwrkfil
  74.  .def ksysfil
  75.  .def filcls
  76.  .def opnwrk
  77.  .def opnsys
  78. ;
  79. kwrkfil = 16
  80. ksysfil = 15
  81. ;
  82.  .ref dprintf
  83.  .ref dsprint
  84.  .ref dfprint
  85.  .ref c$getchar
  86.  .ref c$funct{CBM-@}init
  87.  .ref c$1102
  88.  .ref c$2102
  89.  .ref cmdlbuf
  90.  .ref curcmdn
  91.  .ref argv
  92. ;
  93.  .ref srchcmd
  94.  .ref strout
  95.  .ref strechn
  96.  .ref doload
  97.  .ref ostdin
  98.  .ref ostdout
  99.  .ref oprout
  100. ;
  101. ; vectors to C library routines
  102. ;
  103. ;  these are necessary for C programs
  104. ;    to work
  105. ;
  106. init jmp dinit
  107.  jmp c$1102
  108.  jmp c$funct{CBM-@}init
  109.  jmp dprintf
  110.  jmp dfprint
  111.  jmp dsprint
  112.  jmp c$getchar
  113.  jmp c$2102
  114. ;
  115. dinit lda nmivec
  116.  sta savnmi
  117.  lda nmivec+1
  118.  sta savnmi+1
  119.  tsx
  120.  stx savsp
  121.  lda #12
  122.  sta $d020
  123.  lda #15
  124.  sta $d021
  125.  lda #0
  126.  sta charclr
  127.  lda #8
  128.  sta sysdev
  129.  sta wrkdev
  130.  lda #1
  131.  sta sysdrv
  132.  lda #0
  133.  sta wrkdrv
  134.  sta cmdlbuf+81
  135.  sta vintcnt
  136.  sta curcmdn
  137. ;
  138. ;
  139. ; we come back here after interrupting
  140. ;  a C program because of STOP/RESTORE
  141. ;
  142. intrein lda #$0d
  143.  jsr chrout
  144.  lda  #<inthdl
  145.  sta  nmivec
  146.  lda  #>inthdl
  147.  sta  nmivec+1
  148.  lda $d018
  149.  ora #$02
  150.  sta $d018
  151.  lda #<kwrkfil
  152.  jsr close
  153.  jsr opnwrk
  154. mainlp = *
  155.  jsr filcls
  156.  ldx sysdev
  157.  jsr opnsys
  158.  jsr shprmpt
  159.  jsr shgetln
  160.  jsr shexeln
  161.  jmp mainlp
  162. ;
  163. filcls jsr clrchn
  164.  ldx #15
  165. t0080b txa
  166.  pha
  167.  jsr close
  168.  pla
  169.  tax
  170.  dex
  171.  bne t0080b
  172.  rts
  173. ;
  174. ;
  175. ; shprompt - prompt user for command line
  176. ;
  177. shprmpt lda  #'%
  178.  jsr chrout
  179.  lda #$20
  180.  jmp chrout
  181. ;
  182. ;
  183. ; shgetln - read command line from screen
  184. ;
  185. shgetln  ldy #0
  186. t0005b jsr chrin
  187.  cmp #$0d
  188.  beq t0020f
  189.  cmp #'a    ; ignore non-alphabetics at start of line
  190.  bcc t0005b
  191.  cmp #1+'z
  192.  bcs t0005b
  193. t0010b cmp #$0d   ; copy line up to a new line character
  194.  beq t0020f
  195.  sta cmdlbuf,y
  196.  jsr chrin
  197.  iny
  198.  bne t0010b
  199. t0020f = *
  200.  jsr chrout
  201.  lda #0
  202.  sta cmdlbuf,y
  203.  rts
  204. ;
  205. ;
  206. ; this is where we handle nmi interrupts
  207. ;   this allows STOP/Restore to break
  208. ;   a looping C program
  209. ;
  210. inthdl pha
  211.  lda vintcnt
  212.  beq t0050f
  213.  pla  ; ignore redundant interrupts
  214.  rti
  215. t0050f txa  ; save regs
  216.  pha
  217.  tya
  218.  pha
  219.  lda #$7f
  220.  sta $dd0d
  221.  ldy $dd0d
  222.  bpl t0060f
  223.  jmp $fe72
  224. t0060f jsr stop
  225.  beq t0070f
  226.  jmp $fe72
  227. t0070f inc vintcnt
  228.  lda  $1
  229.  ora #$07
  230.  sta  $1
  231.  lda #$04
  232.  sta scrbase
  233.  lda charclr
  234.  pha
  235.  lda $d020
  236.  pha
  237.  lda $d021
  238.  pha
  239.  jsr ioint  ; too bad this clears screen!
  240.  jsr cint
  241.  pla
  242.  sta $d021
  243.  pla
  244.  sta $d020
  245.  pla
  246.  sta charclr
  247.  ldx savsp
  248.  txs
  249.  cli
  250.  dec vintcnt
  251.  jmp intrein
  252. ;
  253. savnmi .bss 2
  254. savsp .bss 1
  255. vintcnt .bss 1
  256. ;
  257. ;
  258. ; shexeln - interpret/execute a line
  259. ;
  260. shexeln ldy #0
  261.  sty $29  ; arg count
  262.  sty stdinfl
  263.  sty stdoufl
  264.  ldx #$ff
  265. ;
  266. shexlp inx
  267.  lda cmdlbuf,x
  268.  bne t0690f
  269.  jmp shexend
  270. t0690f cmp #$20
  271.  beq t0700f
  272.  cmp #$a0
  273. t0700f beq shexlp
  274. ;
  275.  cmp #'<  ; check for input redirection
  276.  bne t0720f
  277.  jsr ostdin
  278.  bcc t0710f
  279.  ldx #<scnopni
  280.  ldy #>scnopni
  281.  jmp strout  ; and return
  282. t0710f jmp shexlp
  283. ;
  284. t0720f cmp #'>  ; check for output redirection
  285.  bne t0760f
  286.  inx
  287.  lda cmdlbuf,x
  288. ;
  289.  cmp #'>   ; >> means redirect out to printer
  290.  bne t0740f
  291.  jsr oprout
  292.  bcc t0730f
  293.  ldx #<sprtrnp
  294.  ldy #>sprtrnp
  295.  jmp strout  ; and return
  296. t0730f jmp shexlp
  297. ;
  298. t0740f dex
  299.  jsr ostdout
  300.  bcc t0750f
  301.  ldx #<scnopno
  302.  ldy #>scnopno
  303.  jmp strout  ; and return
  304. ;
  305. t0750f jmp shexlp
  306. ;
  307. t0760f inc $29   ; got an arg
  308.  cmp #'"
  309.  bne t0780f
  310.  inx    ; save an arg enclosed in '"'
  311.  jsr savargv
  312.  dex
  313. t0770b inx
  314.  lda cmdlbuf,x
  315.  beq shexend
  316.  cmp #'"
  317.  bne t0770b
  318.  lda #0
  319.  sta cmdlbuf,x
  320.  jmp shexlp
  321. ;
  322. t0780f jsr savargv
  323. t0790b inx    ; save a normal arg
  324.  lda cmdlbuf,x
  325.  beq shexend
  326.  cmp #$20
  327.  beq t0800f
  328.  cmp #$a0
  329. t0800f bne t0790b
  330.  lda #0
  331.  sta cmdlbuf,x
  332.  jmp shexlp
  333. ;
  334. shexend lda  $29
  335.  bne t0810f
  336.  rts
  337. ;
  338. t0810f = *
  339. t0850f jsr srchcmd  ; look for internal command
  340.  bcc t0860f  ;; found internal command
  341.  ldx #<cmdlbuf  ; otherwise, try and load a C program
  342.  ldy #>cmdlbuf
  343.  jsr doload
  344.  bcs t0860f
  345.  jsr execmd    ; execute C program if it was loaded okay
  346. t0860f rts
  347. ;
  348. ; strings for open failures
  349. ;
  350. scnopni .byte "can't open input file"
  351.  .byte $0d,0
  352. scnopno .byte "can't open output file"
  353.  .byte $0d,0
  354. sprtrnp .byte "printer not present"
  355.  .byte $0d,0
  356. ;
  357. ; execmd - call a c program
  358. ;   which has already been loaded at $2000
  359. ;
  360. execmd lda #<ksysfil
  361.  jsr close
  362.  lda $29
  363.  sta  argstk
  364.  lda  #0
  365.  sta  argstk+1
  366.  lda  #<argv
  367.  sta  argstk+2
  368.  lda  #>argv
  369.  sta  argstk+3
  370.  lda  charclr
  371.  sta  savcclr
  372.  lda  $d020
  373.  sta  savbclr
  374.  lda  $d021
  375.  sta  savsclr
  376. ;  
  377.  jsr  usrprog
  378. ;  
  379.  lda  savbclr
  380.  sta  $d020
  381.  lda  savsclr
  382.  sta  $d021
  383.  lda  savcclr
  384.  sta  charclr
  385.  ldx #$d8
  386.  ldy #0
  387.  sty $2a
  388. t0900b stx $2b
  389. t0910b sta ($2a),y
  390.  iny
  391.  bne t0910b
  392.  inx
  393.  cpx #$dc
  394.  bne t0900b
  395.  rts
  396. ;
  397. savcclr .bss 1
  398. savbclr .bss 1
  399. savsclr .bss 1
  400. ;  
  401. ; savargv - save address of current arg  
  402. ;   into argv vector for command  
  403. ;  
  404. savargv clc
  405.  txa
  406.  adc #<cmdlbuf ; add x to &cmdlbuf
  407.  sta argv,y
  408.  iny
  409.  lda #$00
  410.  adc #>cmdlbuf
  411.  sta argv,y
  412.  iny
  413.  rts
  414. ;
  415. ;
  416. ; opnsys - open a command channel for
  417. ;  the system (or another) device
  418. ; Should be closed before calling user
  419. ;  program, but not before "ls"
  420. ;
  421. opnsys cpx wrkdev
  422.  bne t1000f
  423.  clc  ; assume success
  424.  rts
  425. t1000f stx savdev
  426.  lda #<ksysfil
  427.  jsr close
  428.  ldx savdev
  429.  lda #<ksysfil
  430.  bne t1010f   ;; try the open
  431. ;
  432. ;
  433. ; opnwrk - open a command channel for
  434. ;  the work device
  435. ; Should be opened and closed once per
  436. ;  command line only
  437. ;
  438. opnwrk lda #<kwrkfil
  439.  ldx wrkdev
  440. t1010f stx savdev
  441.  ldy #15  ;
  442.  jsr setlfs
  443.  lda #m$rlen
  444.  ldx #<sm$r
  445.  ldy #>sm$r
  446.  jsr setnam
  447.  jsr open  ;; open tcmdfil,x,15,"m-r"
  448.  bcs t1020f  ;; no device
  449.  ldx savdev
  450.  jsr strechn ;; read, but ignore, error
  451.  clc
  452. t1020f rts  ;; and return -- sec on error
  453. sm$r .byte "m-r"
  454. m$rlen = *-sm$r
  455. savdev .bss 1
  456. ;
  457. ;
  458. ;  
  459. ; outchr - output char (in a)  
  460. ;   to stdout  
  461. ;  not for user commands, since  
  462. ;  argstk used as buffer  
  463. ;  
  464. stdoutx .bss 1
  465. ;
  466. outchr stx vdolc
  467.  ldx stdoutx
  468.  sta argstk,x
  469.  inc stdoutx
  470.  cmp #$0d
  471.  beq outln
  472.  ldx vdolc
  473.  rts
  474. outln lda stdoufl
  475.  beq t1130f
  476.  jsr clrchn
  477.  ldx #2
  478.  jsr chkout
  479. t1130f ldx #0
  480. t1140b cpx stdoutx
  481.  beq t1150f
  482.  lda argstk,x
  483.  jsr chrout
  484.  inx
  485.  bne t1140b
  486. t1150f lda stdoufl
  487.  beq t1160f
  488.  jsr clrchn
  489.  ldx #4
  490.  jsr chkin
  491. ;
  492.  .ref vdolc
  493. t1160f ldx vdolc
  494. clrstdo lda #0
  495.  sta stdoutx
  496.  rts
  497.