Skip to content

Commit ef88577

Browse files
Add COPY command. Fixes #2
1 parent f5fc93e commit ef88577

5 files changed

Lines changed: 254 additions & 14 deletions

File tree

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ OUTDIR := out
66

77
TARGETS := $(OUTDIR)/path.BIN \
88
$(OUTDIR)/chtype.CMD $(OUTDIR)/chtime.CMD \
9+
$(OUTDIR)/copy.CMD \
910
$(OUTDIR)/bell.CMD $(OUTDIR)/hello.CMD $(OUTDIR)/echo.CMD $(OUTDIR)/online.CMD
1011

1112
XATTR := $(shell command -v xattr 2> /dev/null)

README.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ cmdname - load and execute named CMD, if in PATH
1919

2020
Once set, binary files of type `CMD` in the specified directories can be invoked by name.
2121
* CMD file is loaded at $4000 and invoked; should return (`rts`) on completion.
22+
* $4000-$5FFF is assumed reserved for the CMD file and any buffers it needs.
2223
* The command line will be present at $200 (`GETLN` input buffer).
2324
* Supports multi-segment, colon-separated paths, e.g. `/hd/cmds:/hd2/more.cmds`
2425
* Commands can use the BI parser for arguments. See `chtype.cmd.s` for an example.
@@ -46,13 +47,16 @@ Notes:
4647
* Commands with BASIC keywords as _prefixes_ are allowed as long as the command continues with an alphabetic character. For example, `ONLINE` is allowed despite conflicting with the valid BASIC statement `ONLINE GOTO10` which is short for `ON LINE GOTO 10`.
4748

4849
Sample commands included:
49-
* `BELL` - beeps the speaker
50-
* `HELLO` - shows a short message
51-
* `ONLINE` - lists online volumes (volume name, slot and drive)
52-
* `ECHO` - echoes back anything following the command
53-
* `CHTYPE` - change the type/auxtype of a file. e.g. `chtype file,T$F1,A$1234`
54-
* `T` (type) and `A` (auxtype) are optional. If neither is specified, current types are shown.
55-
* `S` and `D` arguments can be used to specify slot and drive.
56-
* `CHTIME` - change the modification date/time of a file. e.g. `chtime file,A$1234,B$5678`
57-
* `A` (date) and `B` (time) are optional. If neither is specified, current values are shown.
58-
* `S` and `D` arguments can be used to specify slot and drive.
50+
* Useful utilities:
51+
* `ONLINE` - lists online volumes (volume name, slot and drive)
52+
* `COPY` - copy a single file, e.g. `copy /path/to/file,dstfile`
53+
* `CHTYPE` - change the type/auxtype of a file. e.g. `chtype file,T$F1,A$1234`
54+
* `T` (type) and `A` (auxtype) are optional. If neither is specified, current types are shown.
55+
* `S` and `D` arguments can be used to specify slot and drive.
56+
* `CHTIME` - change the modification date/time of a file. e.g. `chtime file,A$1234,B$5678`
57+
* `A` (date) and `B` (time) are optional. If neither is specified, current values are shown.
58+
* `S` and `D` arguments can be used to specify slot and drive.
59+
* Other examples:
60+
* `BELL` - beeps the speaker
61+
* `HELLO` - shows a short message
62+
* `ECHO` - echoes back anything following the command

copy.cmd.s

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
;;; ============================================================
2+
;;;
3+
;;; COPY - Copy changing command for ProDOS-8
4+
;;;
5+
;;; Usage: COPY pathname1,pathname2
6+
;;;
7+
;;; Inspiration from COPY.ALL by Sandy Mossberg, Nibble 6/1987
8+
;;;
9+
;;; ============================================================
10+
11+
.include "apple2.inc"
12+
.include "more_apple2.inc"
13+
.include "prodos.inc"
14+
15+
;;; ============================================================
16+
17+
.org $4000
18+
19+
;; NOTE: Assumes XLEN is set by PATH
20+
21+
;; Point BI's parser at the command execution routine.
22+
lda #<execute
23+
sta XTRNADDR
24+
page_num2 := *+1 ; address needing updating
25+
lda #>execute
26+
sta XTRNADDR+1
27+
28+
;; Mark command as external (zero).
29+
lda #0
30+
sta XCNUM
31+
32+
;; Set accepted parameter flags (Name, Type, Address)
33+
34+
lda #PBitsFlags::FN1 | PBitsFlags::FN2 ; Filenames
35+
sta PBITS
36+
lda #0
37+
sta PBITS+1
38+
39+
clc ; Success (so far)
40+
rts ; Return to BASIC.SYSTEM
41+
42+
;;; ============================================================
43+
44+
FN1INFO := $2EE
45+
FN1BUF := $4200
46+
FN2BUF := $4600
47+
DATABUF := $4A00
48+
DATALEN = $6000 - DATABUF
49+
50+
execute:
51+
;; Get FN1 info
52+
lda #$A
53+
sta SSGINFO
54+
lda #GET_FILE_INFO
55+
jsr GOSYSTEM
56+
bcs rts1
57+
58+
;; Reject directory file
59+
lda FIFILID
60+
cmp #$F ; DIR
61+
bne :+
62+
lda #$D ; FILE TYPE MISMATCH
63+
sec
64+
rts1: rts
65+
:
66+
67+
;; Save FN1 info
68+
ldx #$11
69+
: lda SSGINFO,x
70+
sta FN1INFO,x
71+
dex
72+
bpl :-
73+
74+
;; Open FN1
75+
lda #<FN1BUF
76+
sta OSYSBUF
77+
lda #>FN1BUF
78+
sta OSYSBUF+1
79+
lda #OPEN
80+
jsr GOSYSTEM
81+
bcs rts1
82+
lda OREFNUM
83+
sta FN1REF
84+
85+
;; Copy FN2 to FN1
86+
ptr1 := $06
87+
ptr2 := $08
88+
lda VPATH1
89+
sta ptr1
90+
lda VPATH1+1
91+
sta ptr1+1
92+
lda VPATH2
93+
sta ptr2
94+
lda VPATH2+1
95+
sta ptr2+1
96+
ldy #0
97+
lda (ptr2),y
98+
tay
99+
: lda (ptr2),y
100+
sta (ptr1),y
101+
dey
102+
bpl :-
103+
104+
;; Get FN1 info
105+
lda #GET_FILE_INFO
106+
jsr GOSYSTEM
107+
bcs :+
108+
109+
lda #$13 ; DUPLICATE FILE NAME
110+
err: pha
111+
jsr close
112+
pla
113+
sec
114+
rts
115+
116+
: cmp #6 ; BI Errors 6 and 7 cover
117+
beq :+ ; vol dir, pathname, or filename
118+
cmp #7 ; not found.
119+
bne err ; Otherwise - fail.
120+
:
121+
122+
;; Create FN2
123+
lda #$C3 ; Free access
124+
sta CRACESS
125+
ldx #3
126+
: lda FN1INFO+4,x ; storage type, file type,
127+
sta CRFKIND-3,x ; aux type, create date/time
128+
lda FN1INFO+$E,x
129+
sta CRFKIND+1,x
130+
dex
131+
bpl :-
132+
lda #CREATE
133+
jsr GOSYSTEM
134+
bcs err
135+
136+
;; Open FN2
137+
lda #<FN2BUF
138+
sta OSYSBUF
139+
lda #>FN2BUF
140+
sta OSYSBUF+1
141+
lda #OPEN
142+
jsr GOSYSTEM
143+
bcs err
144+
lda OREFNUM
145+
sta FN2REF
146+
147+
;; Read
148+
read: lda FN1REF
149+
sta RWREFNUM
150+
lda #<DATABUF
151+
sta RWDATA
152+
lda #>DATABUF
153+
sta RWDATA+1
154+
lda #<DATALEN
155+
sta RWCOUNT
156+
lda #>DATALEN
157+
sta RWCOUNT+1
158+
lda #READ
159+
jsr GOSYSTEM
160+
bcc :+
161+
cmp #5 ; END OF DATA
162+
beq finish
163+
:
164+
165+
;; Write
166+
lda FN2REF
167+
sta RWREFNUM
168+
lda #<DATABUF
169+
sta RWDATA
170+
lda #>DATABUF
171+
sta RWDATA+1
172+
lda RWTRANS
173+
sta RWCOUNT
174+
lda RWTRANS+1
175+
sta RWCOUNT+1
176+
lda #WRITE
177+
jsr GOSYSTEM
178+
bcc read
179+
jmp err
180+
181+
182+
finish: jsr close
183+
clc
184+
rts
185+
186+
.proc close
187+
lda FN1REF
188+
sta CFREFNUM
189+
lda #CLOSE
190+
jsr GOSYSTEM
191+
lda FN2REF
192+
sta CFREFNUM
193+
lda #CLOSE
194+
jsr GOSYSTEM
195+
rts
196+
.endproc
197+
198+
FN1REF: .byte 0
199+
FN2REF: .byte 0
200+
201+
.assert * <= FN1BUF, error, "Too long"

package.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ add_file () {
1818
}
1919

2020
add_file "out/path.BIN" "path#062000"
21-
for file in bell echo hello online chtype chtime; do
21+
for file in bell echo hello online chtype chtime copy; do
2222
add_file "out/${file}.CMD" "${file}#F04000"
2323
done
2424

prodos.inc

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
MLI := $BF00
55
DATE := $BF90
66

7+
CREATE = $C0
78
SET_FILE_INFO = $C3
89
GET_FILE_INFO = $C4
910
ON_LINE = $C5
1011
OPEN = $C8
1112
READ = $CA
13+
WRITE = $CB
1214
CLOSE = $CC
1315

1416
.macro MLI_CALL cmd, params
@@ -61,28 +63,60 @@ VADDR := $BE58 ; Address parameter
6163
VBYTE := $BE5A ; Byte parameter
6264
VSLOT := $BE61 ; Slot parameter
6365
VTYPE := $BE6A ; Type parameter
64-
VPATH1 := $BE6C ; Pathname buffer
66+
VPATH1 := $BE6C ; Pathname 1 buffer
67+
VPATH2 := $BE6E ; Pathname 2 buffer (RENAME)
6568

6669
GOSYSTEM := $BE70 ; Use instead of MLI
6770

71+
6872
XRETURN := $BE9E ; Handy RTS
6973

74+
SCREATE := $BEA0 ; CREATE Parameter block
75+
CRACESS := $BEA3 ; $C1 if directory create
76+
CRFILID := $BEA4
77+
CRAUXID := $BEA5
78+
CRFKIND := $BEA7
79+
SSGPREFX := $BEAC
80+
SDSTROY := $BEAC
81+
SRECNAME := $BEAF
82+
7083
SSGINFO := $BEB4 ; GET_FILE_INFO Parameter block
71-
FIFILID := $BEB8 ; (set size $A)
72-
FIAUXID := $BEB9
84+
FIACESS := $BEB7 ; Access used by lock/unlock
85+
FIFILID := $BEB8 ; FILE ID is type specifier
86+
FIAUXID := $BEB9 ; Aux_id is used for load addr and record length
87+
FIFKIND := $BEBB ; Identifies trees vs. directories
88+
FIBLOKS := $BEBC ; Used by CAT commands for root
7389
FIMDATE := $BEBE
7490

91+
SONLINE := $BEC6
92+
SSETMKR := $BEC6
93+
SGETMRK := $BEC6
94+
SSETEOF := $BEC6
95+
SGETEOF := $BEC6
96+
SSETBUF := $BEC6
97+
SGETBUF := $BEC6
98+
SBUFREF := $BEC7
99+
SREFNUM := $BEC7
100+
SUNITNUM := $BEC7
101+
SDATPTR := $BEC8
102+
SMARK := $BEC8
103+
SEOF := $BEC8
104+
SBUFADR := $BEC8
75105
SOPEN := $BECB ; OPEN
76106
OSYSBUF := $BECE
77107
OREFNUM := $BED0
78108

79109
SREAD := $BED5 ; READ
110+
SWRITE := $BED5 ; WRITE
80111
RWREFNUM := $BED6
81112
RWDATA := $BED7
82113
RWCOUNT := $BED9
114+
RWTRANS := $BEDB
83115

84116
SCLOSE := $BEDD ; CLOSE
117+
SFLUSH := $BEDD ; FLUSH
85118
CFREFNUM := $BEDE
119+
CCCSPARE := $BEDF
86120

87121
GETBUFR := $BEF5
88122
FREEBUFR := $BEF8

0 commit comments

Comments
 (0)