-
Notifications
You must be signed in to change notification settings - Fork 84
/
save.src
154 lines (121 loc) · 3.38 KB
/
save.src
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
.page
.subttl save (10/17/84): c/128
; **********************************************
; * save memory to mass storage *
; * *
; * fa: 0= keyboard <invalid> *
; * 1= cassette *
; * 2= rs-232 <invalid> *
; * 3= screen <invalid> *
; * 4-31= serial device *
; * *
; * sa: (cassette save only) *
; * bit0- 0= basic (blf) *
; * 1= absolute (plf) *
; * bit1- 0= nop *
; * 1= write eot *
; * *
; * ba: bank source *
; * *
; * > .a points to start address *
; * > x & y point to end address *
; **********************************************
savesp ;////// jump table entry
stx eal
sty eah ;setup ending address (in x & y)
tax
lda $00,x ;setup starting address (.a points to indirect)
sta stal
lda $01,x
sta stah
save ;////// old monitor entry (not c/128 monitor)
jmp (isave)
nsave
lda fa ;dispatch per device number
cmp #1
beq svtape ;load from cassette tape
cmp #4
bcs svdisk ;load from serial device
err9s jmp error9 ;illegal device
err8s jmp error8 ;missing filename
err4s jmp error4 ;file not found
.page \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
; save memory to serial device
svdisk
ldy fnlen ;must have filename
beq err8s ;...branch if missing filename
lda #$61 ;pass 'save' command to disk in sa
sta sa
jsr openi ;open the file
jsr saving ;'saving...'
lda fa
jsr listn ;establish the channel
lda sa
jsr secnd ;send 'save' command
ldy #0
jsr rd300 ; (copy 'stal,h' to 'sal,h')
jsr ciout ;send starting address lo
lda sah
jsr ciout ;send starting address hi
1$ jsr cmpste ;compare start to end
bcs 3$ ;...branch if at end
jsr sally ;lda (sal),y
jsr ciout ;send a byte
jsr stop
beq break ;...branch if aborted by <stop> key
2$ jsr incsal ;increment address for next byte
bne 1$ ;always
3$ jsr unlsn ;close channel, fall into file close routine: save done
.page \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
clsei ;////// entry from other kernal routines
bit sa
bmi clsrts ;...branch if file not properly opened
lda fa
jsr listn ;get the channel
lda sa
and #$ef ;make sa a 'close' command
ora #$e0
jsr secnd ;send 'close' command
cunlsn ;////// entry from 'openi'
jsr unlsn ;close channel
clsrts clc ;signal good return
rts
break
jsr clsei ;close the file
lda #0 ;return =
sec ;signal error return
rts
; subroutine to output 'saving [<filename>]'
saving
lda msgflg
bpl svrts ;...branch if display disabled
ldy #ms11-ms1
jsr msg ;print 'saving '
jmp outfn ;print filename & rts
.page \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
; save memory to cassette tape
svtape
jsr tapadr ;setup pointers to cassette buffer
bcc err9s ;...branch if deallocated (error)
jsr cste2 ;prompt user 'press play & record...'
bcs svrts ;...branch if aborted by <stop> key
jsr saving ;'saving...'
ldx #plf
lda sa ;sa has type of tape file: 1=plf 0=blf
and #$01
bne 1$ ;...branch if 'plf' type
ldx #blf
1$ txa
jsr tapeh ;write tape header
bcs svrts ;...branch if aborted by <stop> key
jsr twrt ;write file to tape
bcs svrts ;...branch if aborted by <stop> key
lda sa
and #$02 ;sa has (optional) end_of_tape flag
beq 2$ ;...branch if not eot
lda #eot
jsr tapeh ;write eot mark to tape
.byte $24 ;preserve status in .c from tape handler
2$ clc ;signal good save
svrts rts ;done save
;.end