/ src / multixfer.s
multixfer.s
  1  ; CCGMS Terminal
  2  ;
  3  ; Copyright (c) 2016,2020, Craig Smith, alwyz. All rights reserved.
  4  ; This project is licensed under the BSD 3-Clause License.
  5  ;
  6  ; Punter Multi-Transfer
  7  ;
  8  
  9  ;----------------------------------------------------------------------
 10  SET_PETSCII
 11  txt_multixfer:
 12  	.byte CR,WHITE,"Multi-transfer - Punter only.",CR,0
 13  SET_ASCII
 14  
 15  ;----------------------------------------------------------------------
 16  cf1_multi_send:
 17  	jsr text_color_save
 18  	lda protoc
 19  	beq mulsav	; PROTOCOL_PUNTER
 20  mulnop:
 21  	lda #<txt_multixfer
 22  	ldy #>txt_multixfer
 23  	jsr outstr
 24  	jmp ui_abort
 25  
 26  mulsav:
 27  	jsr supercpu_off
 28  	lda #CLR
 29  	jsr chrout
 30  
 31  ;	lda buffer_ptr+1; old references comparing buffer area and making sure theres enough
 32  ;	cmp #>mulfil	; room for punter files to be stored, but since we're now
 33  ;	bcc mulsok	; reserving #$ff space for punter, its not neccessary
 34  ;	lda buffer_ptr
 35  ;	cmp #<mulfil
 36  ;	bcc mulsok
 37  ;	lda #<mlswrn
 38  ;	ldy #>mlswrn
 39  ;	jsr outstr
 40  ;	jmp ui_abort
 41  ;mulsok
 42  
 43  	lda #<txt_multisend_select
 44  	ldy #>txt_multisend_select
 45  	jsr outstr
 46  	lda #<txt_yesnoquit
 47  	ldy #>txt_yesnoquit
 48  	jsr outstr
 49  	jsr select_files_from_disk
 50  	lda mulcnt	; some files to send?
 51  	bne mlss1	; yes
 52  mlss0	jmp mlssab	; nope, we are done
 53  mlss1
 54  	lda mulfln
 55  	sta mulcnt	; how many files to send. decrement until none left
 56  	beq mlss0
 57  	lda #0
 58  	sta mulfln
 59  	lda #<mulfil
 60  	sta tmpfd
 61  	lda #>mulfil
 62  	sta tmpfd+1
 63  mlslop
 64  	ldy #19
 65  	lda (tmpfd),y
 66  	bne mlssen
 67  mlsinc
 68  	lda tmpfd
 69  	clc
 70  	adc #20
 71  	sta tmpfd
 72  	lda tmpfd+1
 73  	adc #0
 74  	sta tmpfd+1
 75  	lda tmpfd+1
 76  	cmp #>endmulfil
 77  	bcc mlslop
 78  	jmp mulab2
 79  mlssen
 80  	ldy #17
 81  mlss2	lda (tmpfd),y
 82  	cmp #$a0
 83  	bne mlss3
 84  	dey
 85  	cpy #1
 86  	bne mlss2
 87  	jmp mulab2
 88  mlss3	dey
 89  	sty max
 90  	iny
 91  mlss4	lda (tmpfd),y
 92  	sta inpbuf-2,y
 93  	dey
 94  	cpy #1
 95  	bne mlss4
 96  	ldx max
 97  	lda #','
 98  	sta inpbuf,x
 99  	ldy #18
100  	lda (tmpfd),y
101  	and #7
102  	cmp #4
103  	bne mlsg
104  	jmp mulabt
105  mlsg
106  	tay
107  	lda drtype,y
108  	sta inpbuf+1,x
109  mlsgo
110  	jsr mlshdr
111  	ldy #0
112  mlsgo1	lda inpbuf,y
113  	jsr modput
114  	iny
115  	cpy max
116  	bne mlsgo1
117  	lda inpbuf,y
118  	jsr modput
119  	lda inpbuf+1,y
120  	jsr modput
121  	lda #CR
122  	jsr modput
123  	jsr clrchn
124  	jsr uplmen	; disk setup
125  	ldx SHFLAG
126  	cpx #SHFLAG_CBM
127  	beq mulab2
128  	lda inpbuf
129  	bne mulab2
130  	inc mulfln
131  	lda mulfln
132  	cmp mulcnt
133  	beq mlss5
134  	ldx #0
135  	stx JIFFIES
136  mlstim	lda JIFFIES
137  	cmp #110
138  	bcc mlstim
139  	jmp mlsinc
140  mlss5
141  	jsr mlshdr
142  	ldx #16
143  	lda #4		; ctrl-d
144  :	jsr modput
145  	dex
146  	bne :-
147  	lda #CR
148  	jsr modput
149  mlssab	jsr clrchn
150  	jsr text_color_restore
151  	jsr gong
152  	jmp term_entry
153  
154  ;----------------------------------------------------------------------
155  ; send 16 TABs
156  mlshdr:
157  	jsr clear232
158  	jsr enablexfer
159  	ldx #16
160  	lda #9		; ctrl-i
161  :	jsr modput
162  	dex
163  	bne :-
164  	rts
165  
166  ;----------------------------------------------------------------------
167  mulabt:
168  	jsr gong
169  mulab2
170  	jsr clrchn
171  	lda #CR
172  	jsr chrout
173  	lda #LFN_FILE
174  	jsr close
175  	lda modem_type
176  	cmp #MODEM_TYPE_SWIFTLINK_DE
177  	bmi mulab3
178  mulab3
179  	jsr enablexfer
180  	jmp term_entry
181  
182  ;----------------------------------------------------------------------
183  cf3_multi_receive:
184  	jsr disablexfer
185  	jsr text_color_save
186  	lda protoc
187  	beq mulrav	; PROTOCOL_PUNTER
188  	jmp mulnop
189  mulrav
190  	jsr supercpu_off
191  	lda #1
192  	sta mulcnt
193  	lda #CLR
194  	jsr chrout
195  	lda #<txt_multirecv
196  	ldy #>txt_multirecv
197  	jsr outstr
198  mrllgc
199  	ldx SHFLAG
200  	bne mrllgc
201  mlrnew
202  	jsr enablexfer
203  	ldy #0
204  	sty max
205  mlrwat
206  	ldx SHFLAG
207  	cpx #SHFLAG_CBM
208  	beq mulab2
209  	jsr modget
210  	cmp #9		; ctrl-i
211  	bne mlrwat
212  mlrwt2
213  	ldx SHFLAG
214  	cpx #SHFLAG_CBM
215  	beq mulab2
216  	jsr modget
217  	cmp #0
218  	beq mlrwt2
219  	cmp #9		; ctrl-i
220  	beq mlrwt2
221  	bne mlrfl1
222  mlrflp
223  	ldx SHFLAG
224  	cpx #SHFLAG_CBM
225  	beq mulab2
226  	jsr modget
227  	cmp #0
228  	beq mlrflp
229  mlrfl1
230  	cmp #CR
231  	beq mlrfl2
232  	ldy max
233  	sta inpbuf,y
234  	inc max
235  	lda max
236  	cmp #18
237  	bcc mlrflp
238  mlrfl2
239  	ldy max
240  	cpy #3
241  	bcc mlfext
242  	dey
243  	dey
244  	lda inpbuf,y
245  	cmp #','
246  	bne mlfext
247  	sty max
248  	lda inpbuf
249  	cmp #4		; ctrl-d
250  	bne mlffl2
251  mlfext	jmp mulabt
252  mlffl2
253  	jsr dowmen
254  	lda inpbuf
255  	beq mlrnew
256  	bne mlfext
257  
258  ;----------------------------------------------------------------------
259  ; count bad blocks
260  goobad:
261  	sta $0400+20*40+20
262  	cmp #'/'	; duplicate block?
263  	beq @1		; ignore in statistics
264  	cmp #'*'	; good?
265  	bne @2		; no
266  @1:	rts
267  @2:	cmp #'9'+1
268  	beq @3
269  	ldx #3
270  	bne @4
271  @3:	ldx #25
272  @4:	inc $0400+20*40+38-25,x
273  	lda $0400+20*40+38-25,x
274  	cmp #'9'+1
275  	bcc @1
276  	lda #'0'
277  	sta $0400+20*40+38-25,x
278  	dex
279  	bpl @4
280  	rts
281  
282  ;----------------------------------------------------------------------
283  SET_PETSCII
284  txt_multisend_select:
285  	.byte CR,LOCASE,WHITE,RVSON," Multi-Send ",RVSOFF," - "
286  	.byte "Select files:",CR,CR,0
287  
288  txt_yesnoquit:
289  	.byte LTBLUE," Yes/No/Quit/Skip8/Done/All",CR,0
290  
291  txt_multirecv:
292  	.byte CR,LOCASE,WHITE,RVSON," Multi-Receive ",CR,CR
293  	.byte CYAN,"Waiting for header...C= aborts.",CR,0
294  SET_ASCII
295  
296  ;----------------------------------------------------------------------
297  select_files_from_disk:
298  	jsr disablexfer
299  	lda device_disk
300  	jsr listen
301  	lda #$f0
302  	jsr second
303  	lda #'$'
304  	jsr ciout
305  	lda #'0'
306  	jsr ciout
307  	lda #':'
308  	jsr ciout
309  	lda #'*'
310  	jsr ciout
311  	jsr unlsn
312  	lda #<mulfil
313  	sta tmpfd
314  	lda #>mulfil
315  	sta tmpfd+1
316  	lda device_disk
317  	jsr talk
318  	lda #$60
319  	jsr tksa
320  	ldy #0
321  	sty mulcnt	; count entries
322  	sty mulfln
323  	sty mlsall
324  	sty mulskp
325  	ldy #31
326  mdrlp0
327  	jsr mgetch
328  	dey
329  	bpl mdrlp0
330  	ldy #1
331  mdrlp1	jsr mgetch
332  	dey
333  	bpl mdrlp1
334  	ldy #0
335  	jsr mgetch
336  	sta (tmpfd),y
337  	sta tmp07e8,y
338  	iny
339  	jsr mgetch
340  	sta (tmpfd),y
341  	sta tmp07e8,y
342  	lda #0
343  	sta tmp06
344  mdrlp2	jsr mgetch
345  	inc tmp06
346  	cmp #'"'
347  	bne mdrlp2
348  mdrlpf
349  	iny
350  	cpy #18
351  	beq drlpfn
352  	jsr mgetch
353  	cmp #'"'
354  	bne drlpnq
355  	lda #$a0
356  drlpnq
357  	sta (tmpfd),y
358  	sta tmp07e8,y
359  	jmp mdrlpf
360  drlpfn
361  	dey
362  	cpy #1
363  	beq drlptc
364  	lda tmp07e8,y
365  	cmp #' '
366  	bne drlptc
367  	lda #$a0
368  	sta (tmpfd),y
369  	sta tmp07e8,y
370  	bne drlpfn
371  drlptc
372  	jsr mgetch
373  	lda #0
374  	sta tmp05
375  	jsr mgetch
376  	cmp #'*'
377  	bne drlpsp
378  	lda #$80
379  	sta tmp05
380  drlpsp
381  	jsr mgetch
382  	ldx #4
383  drlptl
384  	cmp drtype,x
385  	beq drlptp
386  	dex
387  	bne drlptl
388  drlptp
389  	txa
390  	ora tmp05
391  	sta tmp05
392  	jsr mgetch
393  	jsr mgetch
394  	jsr mgetch
395  	cmp #'<'
396  	bne drlpte
397  	lda tmp05
398  	ora #$40
399  	sta tmp05
400  drlpte	lda tmp05
401  	ldy #18
402  	sta (tmpfd),y
403  	sta tmp07e8,y
404  	lda #0
405  	iny
406  	sta (tmpfd),y
407  dirgrb
408  	jsr mgetch
409  	bne dirgrb
410  	inc mulcnt
411  	lda mulskp
412  	bne mulpmt
413  	jsr mdrret
414  	bne mulnen
415  mulpmt	dec mulskp
416  	jsr drpol7
417  mulnen
418  	lda device_disk
419  	jsr talk
420  	lda #$60
421  	jsr tksa
422  	ldy #1
423  	jmp mdrlp1
424  mgetch	jsr acptr
425  	ldx status
426  	bne mdrlp3
427  	cmp #0
428  	rts
429  mdrlp3	pla
430  	pla
431  mdrext	lda device_disk
432  	jsr listen
433  	lda #$e0
434  	jsr second
435  	jsr untlk
436  	jsr unlsn
437  	jsr clrchn
438  	jsr ercopn ; possible fix for multi upload crash on up9600 - 2018 fix
439  	jmp enablexfer
440  
441  ;----------------------------------------------------------------------
442  mdrret:
443  	ldy #0
444  drpol0
445  	sty tmp02
446  	lda directory_format,y
447  	cmp #2		; ctrl-b
448  	bne @no1
449  
450  ; print blocks
451  	ldy #0
452  	lda tmp07e8,y
453  	tax
454  	iny
455  	lda tmp07e8,y
456  	jsr $bdcd	; print 16 bit decimal
457  	ldy tmp06
458  :	lda #' '
459  	jsr chrout
460  	dey
461  	bne :-
462  	beq drpol4
463  @no1:
464  
465  	cmp #$0e	; ctrl-n
466  	bne @no2
467  
468  ; print file name
469  	ldy #2
470  :	lda tmp07e8,y
471  	jsr chrout
472  	iny
473  	cpy #18		; print 16 chars
474  	bne :-
475  	beq drpol4
476  @no2:
477  
478  	cmp #$06	; ctrl-f
479  	bne @no3
480  
481  ; print file type
482  	ldy #18
483  	lda tmp07e8,y
484  	tay
485  	and #7
486  	tax
487  	tya
488  	and #$80
489  	bne @1
490  	lda #' '
491  	bne @2
492  @1:	lda #'*'	; splat
493  @2:	jsr chrout
494  	lda drtype,x	; file type
495  	jsr chrout
496  	lda drtyp2,x
497  	jsr chrout
498  	lda drtyp3,x
499  	jsr chrout
500  	tya
501  	and #$40
502  	bne @3
503  	lda #' '
504  	bne @4
505  @3:	lda #'<'	; write protect
506  @4:	jsr chrout
507  	bne drpol4
508  @no3:
509  
510  	jsr chrout
511  drpol4
512  	ldy tmp02
513  	iny
514  	cpy #directory_format_end-directory_format
515  	beq :+
516  	jmp drpol0	; [XXX drpol0 is reachable]
517  :
518  	lda mlsall
519  	beq mlsf0
520  	lda #'Y'
521  	jsr chrout
522  	bne mlsyes
523  
524  mlsf0
525  	lda #' '
526  	jsr chrout
527  	lda #CSR_LEFT
528  	jsr chrout
529  	jsr cursor_show
530  :	jsr getin
531  	beq :-
532  	and #$7f
533  	cmp #'A'
534  	bcc :-
535  	cmp #'['
536  	bcs :-
537  	pha
538  	jsr cursor_off
539  	pla
540  	pha
541  	jsr chrout
542  	lda #CSR_LEFT
543  	jsr chrout
544  	pla
545  
546  	cmp #'Y'	; YES
547  	bne mlsf1
548  
549  ; yes
550  mlsyes	ldy #19
551  	inc mulfln
552  	lda #$80
553  	sta (tmpfd),y
554  	bne mlsnpr2
555  mlsf1
556  
557  	cmp #'N'	; NO
558  	beq mlsnpr
559  
560  	cmp #'A'	; ALL
561  	bne mlsf2
562  
563  ; all
564  	lda #1
565  	sta mlsall
566  	bne mlsyes
567  mlsf2
568  
569  	cmp #'D'	; DONE
570  	bne mlsf3
571  
572  ; done
573  	lda #CR
574  	jsr chrout
575  	jmp mdrlp3
576  mlsf3
577  
578  	cmp #'Q'	; QUIT
579  	bne mlsf4
580  
581  ; quit
582  	jsr mdrext
583  	pla
584  	pla
585  	pla
586  	pla
587  	jsr clrchn
588  	jmp term_entry
589  mlsf4
590  
591  	cmp #'S'	; SKIP8
592  	bne mlsf0
593  
594  ; skip8
595  	lda #7
596  	sta mulskp
597  mlsnpr	lda #CR
598  	jsr chrout
599  drpol7
600  	lda tmpfd
601  	clc
602  	adc #0		; [XXX ???]
603  	sta tmpfd
604  	lda tmpfd+1
605  	adc #0
606  	sta tmpfd+1
607  	rts
608  mlsnpr2	lda #CR
609  	jsr chrout
610  drpol72
611  	lda tmpfd
612  	clc
613  	adc #20
614  	sta tmpfd
615  	lda tmpfd+1
616  	adc #0
617  	sta tmpfd+1
618  	rts