-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathopen
278 lines (278 loc) · 5.67 KB
/
open
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
.PAG 'OPEN FILE'
;***********************************
;* *
;* OPEN FUNCTION *
;* *
;* CREATES AN ENTRY IN THE LOGICAL *
;* FILES TABLES CONSISTING OF *
;* LOGICAL FILE NUMBER--LA, DEVICE *
;* NUMBER--FA, AND SECONDARY CMD-- *
;* SA. *
;* *
;* A FILE NAME DESCRIPTOR, FNADR & *
;* FNLEN ARE PASSED TO THIS ROUTINE*
;* *
;***********************************
;
NOPEN LDX LA ;CHECK FILE #
BNE OP98 ;IS NOT THE KEYBOARD
;
JMP ERROR6 ;NOT INPUT FILE...
;
OP98 JSR LOOKUP ;SEE IF IN TABLE
BNE OP100 ;NOT FOUND...O.K.
;
JMP ERROR2 ;FILE OPEN
;
OP100 LDX LDTND ;LOGICAL DEVICE TABLE END
CPX #10 ;MAXIMUM # OF OPEN FILES
BCC OP110 ;LESS THAN 10...O.K.
;
JMP ERROR1 ;TOO MANY FILES
;
OP110 INC LDTND ;NEW FILE
LDA LA
STA LAT,X ;STORE LOGICAL FILE #
LDA SA
ORA #$60 ;MAKE SA AN SERIAL COMMAND
STA SA
STA SAT,X ;STORE COMMAND #
LDA FA
STA FAT,X ;STORE DEVICE #
;
;PERFORM DEVICE SPECIFIC OPEN TASKS
;
BEQ OP175 ;IS KEYBOARD...DONE.
CMP #3
BEQ OP175 ;IS SCREEN...DONE.
BCC OP150 ;ARE CASSETTES 1 & 2
;
JSR OPENI ;IS ON SERIAL...OPEN IT
BCC OP175 ;BRANCH ALWAYS...DONE
;
;PERFORM TAPE OPEN STUFF
;
OP150 CMP #2
BNE OP152
;
JMP OPN232
;
OP152 JSR ZZZ ;SEE IF TAPE BUFFER
BCS OP155 ;YES
;
JMP ERROR9 ;NO...DEALLOCATED
;
OP155 LDA SA
AND #$F ;MASK OFF COMMAND
BNE OP200 ;NON ZERO IS TAPE WRITE
;
;OPEN CASSETE TAPE FILE TO READ
;
JSR CSTE1 ;TELL "PRESS PLAY"
BCS OP180 ;STOP KEY PRESSED
;
JSR LUKING ;TELL USER "SEARCHING"
;
LDA FNLEN
BEQ OP170 ;LOOKING FOR ANY FILE
;
JSR FAF ;LOOKING FOR NAMED FILE
BCC OP171 ;FOUND IT!!!
BEQ OP180 ;STOP KEY PRESSED
;
OP160 JMP ERROR4 ;FILE NOT FOUND
;
OP170 JSR FAH ;GET ANY OLD HEADER
BEQ OP180 ;STOP KEY PRESSED
BCC OP171 ;ALL O.K.
BCS OP160 ;FILE NOT FOUND...
;
;OPEN CASSETTE TAPE FOR WRITE
;
OP200 JSR CSTE2 ;TELL "PRESS PLAY AND RECORD"
BCS OP180 ;STOP KEY PRESSED
LDA #BDFH ;DATA FILE HEADER TYPE
JSR TAPEH ;WRITE IT
;
;FINISH OPEN FOR TAPE READ/WRITE
;
OP171 LDA #BUFSZ-1 ;ASSUME FORCE READ
;
LDY SA
CPY #$60 ;OPEN FOR READ?
BEQ OP172
;
;SET POINTERS FOR BUFFERING DATA
;
LDY #0
LDA #BDF ;TYPE FLAG FOR BLOCK
STA (TAPE1)Y ;TO BEGIN OF BUFFER
TYA
;
OP172 STA BUFPT ;POINT TO DATA
OP175 CLC ;FLAG GOOD OPEN
OP180 RTS ;EXIT IN PEACE
.SKI 5
OPENI LDA SA
BMI OP175 ;NO SA...DONE
;
LDY FNLEN
BEQ OP175 ;NO FILE NAME...DONE
;
LDA #0 ;CLEAR THE SERIAL STATUS
STA STATUS
;
LDA FA
JSR LISTN ;DEVICE LA TO LISTEN
;
LDA SA
ORA #$F0
JSR SECND
;
LDA STATUS ;ANYBODY HOME?
BPL OP35 ;YES...CONTINUE
;
;THIS ROUTINE IS CALLED BY OTHER
;KERNAL ROUTINES WHICH ARE CALLED
;DIRECTLY BY OS. KILL RETURN
;ADDRESS TO RETURN TO OS.
;
PLA
PLA
JMP ERROR5 ;DEVICE NOT PRESENT
;
OP35 LDA FNLEN
BEQ OP45 ;NO NAME...DONE SEQUENCE
;
;SEND FILE NAME OVER SERIAL
;
LDY #0
OP40 LDA (FNADR)Y
JSR CIOUT
INY
CPY FNLEN
BNE OP40
;
OP45 JMP CUNLSN ;JSR UNLSN: CLC: RTS
.PAGE 'OPEN RS232 FILE'
; OPN232 - OPEN AN RS-232 OR PARALLEL PORT FILE
;
; VARIABLES INITILIZED
; BITNUM - # OF BITS TO BE SENT CALC FROM M51CTR
; BAUDOF - BAUD RATE FULL
; RSSTAT - RS-232 STATUS REG
; M51CTR - 6551 CONTROL REG
; M51CDR - 6551 COMMAND REG
; M51AJB - USER BAUD RATE (CLOCK/BAUD/2-100)
; ENABL - 6526 NMI ENABLES (1-NMI BIT ON)
;
OPN232 JSR CLN232 ;SET UP RS232, .Y=0 ON RETURN
;
; PASS PRAMS TO M51REGS
;
STY RSSTAT ;CLEAR STATUS
;
OPN020 CPY FNLEN ;CHECK IF AT END OF FILENAME
BEQ OPN025 ;YES...
;
LDA (FNADR)Y ;MOVE DATA
STA M51CTR,Y ;TO M51REGS
INY
CPY #4 ;ONLY 4 POSSIBLE PRAMS
BNE OPN020
;
; CALC # OF BITS
;
OPN025 JSR BITCNT
STX BITNUM
;
; CALC BAUD RATE
;
LDA M51CTR
AND #$0F
BNE OPN010
;
; GET BAUD RATE FROM USER
;
LDA M51AJB
ASL A
TAY
LDA M51AJB+1
JMP OPN015
;
; USE INTERNAL TABLES
;
OPN010 ASL A ;GET INDEX INTO BAUDO
TAX
LDA BAUDO-2,X
ASL A ;BAUDO*2+200 IS RATE
TAY
LDA BAUDO-1,X
OPN015 ROL A
PHA
TYA
ADC #CBIT+CBIT ;TABLE HAS CB1 ADJST OFFSET
STA BAUDOF
PLA
ADC #0 ;GET CARRY IN
STA BAUDOF+1
;
; CHECK FOR 3/X LINE RESPONSE
;
OPN030 LDA M51CDR ;BIT 0 OF M51CDR
LSR A
BCC OPN050 ;...3 LINE
;
; CHECK FOR X LINE PROPER STATES
;
LDA D2PRB
ASL A
BCS OPN050
JMP CKDSRX ;NO DATA SET...DSR ERROR EXIT
;
; SET UP BUFFER POINTERS (DBE=DBS)
;
OPN050 LDA RIDBE
STA RIDBS
LDA RODBE
STA RODBS
;
; ALLOCATE BUFFERS
;
OPN055 JSR GETTOP ;GET MEMSIZ
LDA RIBUF+1 ;IN ALLOCATION...
BNE OPN060 ;ALREADY
DEY ;THERE GOES 256 BYTES
STY RIBUF+1
STX RIBUF
OPN060 LDA ROBUF+1 ;OUT ALLOCATION...
BNE MEMTCF ;ALREAY
DEY ;THERE GOES 256 BYTES
STY ROBUF+1
STX ROBUF
MEMTCF SEC ;SIGNAL TOP OF MEMORY CHANGE
LDA #$F0
JMP SETTOP ;TOP CHANGED
;
; CLN232 - CLEAN UP 232 SYSTEM FOR OPEN/CLOSE
; SET UP DDRB AND CB2 FOR RS-232
;
CLN232 LDA #$7F ;CLEAR NMI'S
STA D2ICR
LDA #%00000110 ;DDRB
STA D2DDRB
STA D2PRB ;DTR,RTS HIGH
LDA #$04 ;OUTPUT HIGH PA2
ORA D2PRA
STA D2PRA
LDY #00
STY ENABL ;CLEAR ENABLS
RTS
.END
; RSR 8/25/80 - ADD RS-232 CODE
; RSR 8/26/80 - TOP OF MEMORY HANDLER
; RSR 8/29/80 - ADD FILENAME TO M51REGS
; RSR 9/02/80 - FIX ORDERING OF RS-232 ROUTINES
; RSR 12/11/81 - MODIFY FOR VIC-40 I/O
; RSR 2/08/82 - CLEAR STATUS IN OPENI
; RSR 5/12/82 - COMPACT RS232 OPEN/CLOSE CODE