Subversion Repositories NedoOS

Rev

Rev 1828 | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
68 Alone 1
        DEVICE ZXSPECTRUM128
40 alone 2
        include "../_sdk/sys_h.asm"
192 demige 3
FR_EXIST=8 ;fatfs4os/ff.h
40 alone 4
 
59 Alone 5
       MACRO ziprdbyte
40 alone 6
        INC LY
7
        LD A,(IY)
8
        CALL Z,RDBYH
9
       ENDM
10
 
55 Alone 11
STACK=0x4000
344 alone 12
ziptrees=0x4000;0x8000;0x4000 ;⮡ 뫮 bit 6 ;size = 0xa60 + 2*288?
55 Alone 13
TCRC=0x6800 ;size 0x400, divisible by 0x400
14
DISKBUF=0x6c00
40 alone 15
DISKBUFsz=0x1000
1467 alone 16
READZIPDIR=1;0   ࠡ⠥
17
; 筮  䠩   䠩  㣮     㣮!
18
;READ   㤥 ᮤঠ 樮஢
19
;  ஢ ᫮ 䠩. 室  - 㣮 ᫮ -  , ஬ PK,3,4 ( ४ਨ PK,1,2. Archive decryption header, Archive extra data record 猪  㣨 , ਬ஢ )
40 alone 20
 
1471 alone 21
SEEK32BIT=1
1467 alone 22
 
55 Alone 23
depkbuf=0x7c00;0 for pages
24
buf64k=0;0 for nopages
40 alone 25
 
26
        org PROGSTART
27
cmd_begin
28
        ld sp,STACK
609 alone 29
        call initstdio
30
        ;ld e,6 ;textmode
31
        ;OS_SETGFX
40 alone 32
 
33
        ;OS_GETMAINPAGES
344 alone 34
;dehl= ࠭  0000,4000,8000,c000
55 Alone 35
        if depkbuf==0
40 alone 36
        ld hl,PTABL
55 Alone 37
        ld b,4;6
40 alone 38
getpgs0
39
        push bc
40
        push hl
41
        OS_NEWPAGE
42
        pop hl
43
        ld (hl),e
44
        inc hl
45
        pop bc
46
        djnz getpgs0
55 Alone 47
        endif
40 alone 48
 
49
        ld hl,COMMANDLINE
50
        call skipword
51
        call skipspaces
52
        ld a,(hl)
53
        or a
54
        jr nz,$+5
55
         ld hl,defaultfilename
56
        ex de,hl
57
 
58
        call openstream_file
59
        or a
60
        jr nz,openerror
61
 
62
        ld a,(filehandle)
63
        ld b,a
64
        OS_GETFILESIZE ;dehl=filesize
65
        ld (ML_FLEN),hl
1467 alone 66
       if SEEK32BIT
67
        ld (ST_FLENw),de
68
       else
40 alone 69
        ld a,e
70
        ld (ST_FLEN),a
1467 alone 71
       endif
68 Alone 72
 
344 alone 73
        CALL initdepk;Z6629 ; AKEPA
68 Alone 74
       LD IY,DISKBUF+DISKBUFsz-1
75
 
76
;0x1f,0x8b = *.gz
77
;"PK" = *.zip
78
        call RDBYTE
79
        cp 'P'
80
        jr nz,depack_gz
81
 
40 alone 82
        call depack
42 DimkaM 83
 
84
        if 1==0
85
        ld de,0
86
        ld hl,1
87
        ;dehl=shift
88
        ld a,(filehandle)
89
        ld b,a
90
        OS_SEEKHANDLE
40 alone 91
 
92
       LD IY,DISKBUF+DISKBUFsz-1
609 alone 93
 
40 alone 94
loop0
59 Alone 95
        ziprdbyte
40 alone 96
        push iy
609 alone 97
        PRCHAR_
40 alone 98
        pop iy
99
        jp loop0
100
        endif
609 alone 101
 
68 Alone 102
depack_gz_q
40 alone 103
        call closestream_file
104
openerror
192 demige 105
mkdirerror
40 alone 106
error
107
        QUIT
108
 
68 Alone 109
;readerror
40 alone 110
;TODO restore stack
68 Alone 111
        ;call closestream_file
112
        ;jr error
40 alone 113
 
68 Alone 114
depack_gz
115
        call RDBYTE ;rest of magic header 0x8b
116
        call RDBYTE ;method (TODO 0=store)
117
        call RDBYTE ;flags (bit 3 set: original file name present)
118
        push af
119
 
120
        ld b,6 ;4time+1extraflags+1os
121
        call RDBYTE
122
        djnz $-3
123
 
124
        pop af
125
        bit 3,a
344 alone 126
        jr z,depack_gz_skipname ;TODO    娢
127
;ନ஢ filename:
68 Alone 128
        ld hl,filename
129
depack_gz_getfn0
130
        call RDBYTE
131
        ld (hl),a
132
        inc hl
133
        or a
134
        jr nz,depack_gz_getfn0
135
        ld hl,filename
136
        ld de,filename
137
        call copyname83
138
depack_gz_skipname
139
        call SAVECREATE
140
 
141
        ld hl,1
142
        ld (KOL_F),hl
143
        call depack_gz_pp
144
        jr depack_gz_q
145
depack_gz_pp
146
        LD (exit_sp),SP
147
        call INFLATING
148
        jp SKIP ;call SAVECLOSE
149
 
150
copyname83
151
;hl->de
152
copyname83_element
1898 alone 153
        ld b,64;8
68 Alone 154
copyname83_0
155
        ld a,(hl)
156
        inc hl
157
        or a
158
        jr z,copyname83_q
159
        cp '/'
160
        jr z,copyname83_endelement
161
        cp '.'
162
        jr z,copyname83_ext
163
        ld (de),a
164
        inc de
165
        djnz copyname83_0
166
;8 chars of name copied, wait for dot or slash or terminator
167
copyname83_skipname0
168
        ld a,(hl)
169
        inc hl
170
        or a
171
        jr z,copyname83_q
172
        cp '/'
173
        jr z,copyname83_endelement
174
        cp '.'
175
        jr nz,copyname83_skipname0
176
copyname83_ext
177
        ld (de),a ;'.'
178
        inc de
1898 alone 179
        ld b,64;3
68 Alone 180
copyname83_ext0
181
        ld a,(hl)
182
        inc hl
183
        or a
184
        jr z,copyname83_q
185
        cp '/'
186
        jr z,copyname83_endelement
187
        cp '.'
188
        jr z,copyname83_skipext0
189
        ld (de),a
190
        inc de
191
        djnz copyname83_ext0
192
copyname83_skipext0
193
        ld a,(hl)
194
        inc hl
195
        or a
196
        jr z,copyname83_q
197
        cp '/'
198
        jr nz,copyname83_skipext0
199
copyname83_endelement
200
        ld (de),a ;'/'
201
        inc de
202
        jr copyname83_element
203
copyname83_q
204
        ld (de),a ;0
205
        ret
206
 
40 alone 207
skipword
208
;hl=string
209
;out: hl=terminator/space addr
210
getword0
211
        ld a,(hl)
212
        or a
213
        ret z
214
        cp ' '
215
        ret z
216
        inc hl
217
        jr getword0
218
 
219
skipspaces
220
;hl=string
221
;out: hl=after last space
222
        ld a,(hl)
223
        cp ' '
224
        ret nz
225
        inc hl
226
        jr skipspaces
227
 
228
 
229
strcopy
230
;hl->de
231
strcopy0
232
        ld a,(hl)
233
        ldi
234
        or a
235
        jr nz,strcopy0
236
        ret
237
 
55 Alone 238
        if depkbuf==0
40 alone 239
PTABL
240
        ;DB #11,#13,#14,#17,#10,#16
55 Alone 241
        ds 4;6 ;patched
242
        endif
40 alone 243
 
55 Alone 244
;T61F7   DS 14 ;???
40 alone 245
T6221   DS 4 ;time(2), date(2) of depacked file
246
CRC_ISH DS 4
247
 
248
ML_LEN_ISH DB 0
249
T622A   DB 0
250
ST_LEN_ISH DB 0
251
T622C   DB 0
252
 
253
;T622D   DB 0
254
;T622E   DB 0
255
;T622F   DB 0
256
 
257
ML_CRC32 DW 0
258
ST_CRC32 DW 0
259
 
344 alone 260
;⥪騩 ࠧ 䠩  業⮬
40 alone 261
;B1      DB 0
262
;B2      DB 0
263
;B3      DB 0
264
 
55 Alone 265
        if depkbuf==0
40 alone 266
;a=4: for Z631F
267
;a=5: default
268
;a=0..3: for keep byte
344 alone 269
;   hl,de, a' (   bc?)
40 alone 270
ON_BANK
55 Alone 271
        ;CP 0
344 alone 272
        ;RET Z ; ⠪   ।  ᯠ  ࠧ⭮ ४祭, ⮡ ⮬ ࠡ⠫ 䠪᪮?
55 Alone 273
        ;LD (TPAGE),A
40 alone 274
        push bc
275
       LD b,PTABL/256
276
       ADD A,PTABL&0xff
277
        LD c,A
278
        LD A,(bc)
279
        SETPG32KHIGH
280
        pop bc
55 Alone 281
        RET
40 alone 282
        endif
283
 
55 Alone 284
;TPAGE=ON_BANK+1
40 alone 285
 
344 alone 286
;TEHE ACT A
40 alone 287
;de=len
288
;ix=buffer
1467 alone 289
;ahl=position in file
290
;SEEK32BIT: bchl=position in file
40 alone 291
READ    
292
        PUSH IX,DE,BC,HL,AF
293
 
294
        push de ;len
295
        push ix ;buf
296
 
1467 alone 297
       if SEEK32BIT
298
        ld d,b
299
        ld e,c
300
       else
40 alone 301
        ld d,0
302
        ld e,a
1467 alone 303
       endif
40 alone 304
        ;dehl=shift
305
        ld a,(filehandle)
306
        ld b,a
307
        OS_SEEKHANDLE
308
 
309
        pop de ;buf
310
        pop hl ;len
311
        call readstream_file
312
 
313
        ;CALL LOAD
314
        ;LD HL,0
315
        ;LD (OSTAT),HL
316
        ;LD (SMEV),HL
317
        POP AF,HL,BC,DE,IX
318
        RET
319
 
344 alone 320
;業⮬?
40 alone 321
COUNT
322
        LD A,0
323
NOPR=$-1
324
        INC A
325
        AND 3
326
        LD (NOPR),A
327
        RET NZ
328
        ;EXX 
329
        ;CALL P_IND
330
        ;EXX 
331
        RET
332
 
333
        if 1==0
334
P_IND   DI
335
        LD (P_IND1+1),SP
336
        LD SP,TABLICA
337
        LD B,48
338
        LD HL,(Z6546)
339
        LD DE,(B2)
340
        ADD HL,DE
341
        EX DE,HL
342
        LD A,(B1)
343
        ADC A,0
344
        LD C,A
345
PI2     POP HL,AF
346
        OR A
347
        SBC HL,DE
348
        SBC A,C
349
        JR C,PI1
350
        JR NZ,NE_0
351
        OR H
352
        OR L
353
        JR Z,PI1
354
NE_0    DJNZ PI2
355
PI1     DEC SP,SP
356
        POP HL
357
P_IND1  LD SP,0
358
        LD A,L
359
        CP -1
360
PNP=$-1
361
        RET Z
362
        LD (PNP),A
363
        LD HL,#0A08
364
        LD (COR),HL
365
        LD E,A
366
        LD D,0
367
        LD HL,SKAL
368
        OR A
369
        SBC HL,DE
370
        LD A,#4F
371
        LD (TEKATR+1),A
372
        JP PRINTS
373
;?
374
       DS 48,#0A0A
375
SKAL=$-1
376
        NOP
377
        endif
378
 
379
minhl_bc_tobc
380
        or a
381
        sbc hl,bc
382
        add hl,bc
383
        ret nc ;bc<=hl
384
        ld b,h
385
        ld c,l
386
        ret
387
 
344 alone 388
; HL =  
40 alone 389
;de=0
344 alone 390
; 䠩   filename
40 alone 391
;out: hl=0
392
SAVE
55 Alone 393
        ;LD A,4
394
        ;CALL ON_BANK
40 alone 395
 
55 Alone 396
        ;LD A,3
344 alone 397
        ;LD (NOPR),A ;஢ 業⮬?
398
        ;CALL COUNT ;業⮬?
40 alone 399
 
400
        ;LD (#5CE8),HL ;length
401
        ld de,0
402
        LD (IST),DE
403
 
404
        ld a,h
405
        or l
406
        ret z
55 Alone 407
 
408
        if depkbuf
409
        ex de,hl
410
IST=$+1
411
        LD HL,0;(IST)
412
        ld bc,depkbuf
413
        add hl,bc
414
        ex de,hl
415
        ld a,(savefilehandle)
416
        ld b,a
417
        push iy
1828 alone 418
       inc a
419
       jr z,skipbadsave
55 Alone 420
        OS_WRITEHANDLE
1828 alone 421
skipbadsave
55 Alone 422
        pop iy
423
 
424
        else
40 alone 425
;RE_READ
426
        ;push hl
427
        ;call SAVECREATE
428
        ;pop hl ;size
429
SAVE_pg
430
        push hl
431
IST=$+1
432
        LD HL,0;(IST)
433
        LD A,H
434
        RLCA
435
        RLCA
436
        AND 3
437
        CALL ON_BANK
438
        pop hl
439
 
440
        ld bc,0x4000
441
        call minhl_bc_tobc ;bc=block size
442
        or a
443
        sbc hl,bc
444
        push hl ;remaining size
445
        ld h,b
446
        ld l,c
447
        ld de,0xc000
448
        ld a,(savefilehandle)
449
        ld b,a
450
        push iy
1828 alone 451
       inc a
452
       jr z,skipbadsave
40 alone 453
        OS_WRITEHANDLE
1828 alone 454
skipbadsave
40 alone 455
        pop iy
456
 
457
        LD DE,#4000
458
        LD HL,(IST)
459
        ADD HL,DE
460
        LD (IST),HL
461
        pop hl ;remaining size
462
        ld a,h
463
        or l
464
        jr nz,SAVE_pg
465
        ;call SAVECLOSE
466
 
55 Alone 467
        endif
468
 
469
        ;LD A,5
470
        ;call ON_BANK 
40 alone 471
        ld hl,0 ;OK
472
        ret
473
 
192 demige 474
findslash_or_zero
475
;hl=filename
476
;out: hl=at slash or zero, a=code
477
findslash_or_zero0
478
        ld a,(hl)
479
        or a
480
        ret z
481
        cp '/'
482
        ret z
483
        inc hl
484
        jr findslash_or_zero0
485
 
40 alone 486
SAVECREATE
192 demige 487
        ;jr $
40 alone 488
        push iy
1828 alone 489
;SAVECREATE_retry
40 alone 490
        ld de,filename
491
        OS_CREATEHANDLE
192 demige 492
         or a
493
         jr z,SAVECREATE_nomkdir
494
;5=FR_NO_PATH
344 alone 495
; ᮧ    ⮬: md 1, md 1/2, md 1/2/3...
192 demige 496
        ld hl,filename
497
SAVECREATE_mkdir0
498
        call findslash_or_zero ;hl=at slash or zero, a=code
499
        or a
1828 alone 500
        jr z,SAVECREATE_aftermd;SAVECREATE_retry ;path created
192 demige 501
        push hl ;hl=at slash or zero
502
        ld (hl),0 ;end path at this slash
503
        ld de,filename
344 alone 504
        OS_MKDIR ;, ⠪ ४ 㦥 !
192 demige 505
        pop hl ;hl=at slash or zero
506
        ld (hl),'/' ;restore slash
507
         cp FR_EXIST
508
         jr z,SAVECREATE_mkdir_exist
509
         or a
510
         jp nz,mkdirerror
511
SAVECREATE_mkdir_exist
512
        inc hl ;after slash
513
        jr SAVECREATE_mkdir0
1828 alone 514
SAVECREATE_aftermd
515
        ld de,filename
516
        OS_CREATEHANDLE
517
         or a
518
         jr z,SAVECREATE_nomkdir
519
         ld b,0xff ;badsavehandle
192 demige 520
SAVECREATE_nomkdir
40 alone 521
;b=new file handle
522
        ld a,b
523
        ld (savefilehandle),a
524
        pop iy
525
        ret
526
 
527
SAVECLOSE
528
        push iy
529
savefilehandle=$+1
530
        ld b,0
531
        OS_CLOSEHANDLE
532
        pop iy
533
        ret
534
 
535
 
536
RDBYTE
537
        INC LY
538
        LD A,(IY)
539
        RET NZ
540
RDBYH
541
        INC HY
542
        LD A,HY
543
;RDBYHend=$+1
544
        CP DISKBUF/256+(DISKBUFsz/256)
545
        ;JR Z,rDDSK
546
        LD A,(IY)
547
         ccf ;CY=0: OK
548
        RET nz
549
;rDDSK
550
       PUSH HL
551
       PUSH DE
552
        PUSH BC
553
        push IX
554
       ;CALL rdCS
1467 alone 555
       ex af,af' ;'
40 alone 556
       PUSH AF
557
        exx
558
        push bc
559
        push de
560
        push hl
561
        ld de,DISKBUF
562
        ld hl,DISKBUFsz
59 Alone 563
         push de
40 alone 564
        call readstream_file
59 Alone 565
         pop de
566
         push de ;addr
40 alone 567
;hl=actual size
568
         ld a,h
569
         or l
570
         jp z,readerror
571
;move block to end of buf:
572
        ld b,h
573
        ld c,l
59 Alone 574
        dec de ;ld de,DISKBUF-1
40 alone 575
        add hl,de ;end of data
576
        ld de,DISKBUF+DISKBUFsz-1
59 Alone 577
        sbc hl,de
578
        add hl,de
579
        jr z,ZIPRDBYHq
580
         pop af
40 alone 581
        lddr
582
        inc de ;begin of data
59 Alone 583
         push de
584
ZIPRDBYHq
585
         pop iy ;addr = DISKBUF+
40 alone 586
 
587
        pop hl
588
        pop de
589
        pop bc
590
        exx
591
       POP AF
1467 alone 592
       ex af,af' ;'
40 alone 593
        POP IX
594
        pop BC
595
       POP DE
596
         pop hl
597
       ;ld iy,DISKBUF
598
       LD A,(IY)
599
       or a ;CY=0: OK
600
        RET
601
 
82 Alone 602
;Z61B7   LD A,#2E
603
;        LD (DE),A
604
;        INC DE
605
;Z61BB   LDI 
606
;        RET PO
607
;        JR Z61BB
40 alone 608
 
1467 alone 609
ML_FLEN DW 0
610
       if SEEK32BIT
611
ST_FLENw DW 0
612
       else
40 alone 613
ST_FLEN DB 0
1467 alone 614
       endif
40 alone 615
 
55 Alone 616
prcrlf
617
        ld hl,tcrlf
618
prtext
619
        ld a,(hl)
620
        or a
621
        ret z
622
        push hl
623
        push iy
609 alone 624
        PRCHAR_
55 Alone 625
        pop iy
626
        pop hl
627
        inc hl
628
        jr prtext
629
 
630
tcrcerror
631
        db "CRC error"
632
tcrlf
633
        db 13,10,0
634
 
59 Alone 635
        include "../_sdk/file.asm"
609 alone 636
        include "../_sdk/stdio.asm"
55 Alone 637
        include "zipfile.asm"
40 alone 638
        include "depk.asm"
639
 
640
defaultfilename
55 Alone 641
        db "0:/12345/DOWNLOAD.ZIP",0
40 alone 642
filename
643
        db "depkfile.fil"
344 alone 644
        ds filename+256-$ ;  
40 alone 645
 
646
CAT
344 alone 647
; 䠩  16 :
648
;11  , 3  , 2  ய᪠
649
        ds 0x900 ;TODO 
40 alone 650
 
651
cmd_end
652
 
344 alone 653
;BUFER ᯮ  ᨭ 娢    ,  ᯮ  ᯠ
40 alone 654
BUFER=0x8000;$
655
;B_LEN=0x3f00-BUFER
656
B_LEN=0xbfff-BUFER
657
T6624=BUFER+8 ;flags
344 alone 658
T6626=BUFER+#0A ;T6626=METO CAT: 0:STORED, 8:DEFLATE, others unknown
40 alone 659
T6628=BUFER+#0C ;file last modification time
660
Z6630=BUFER+#14
661
Z6632=BUFER+#16
662
Z6634=BUFER+#18
663
Z6636=BUFER+#1A
664
Z6638=BUFER+#1C ;file name length
665
Z663A=BUFER+#1E ;extra field length
666
Z663C=BUFER+#20 ;file comment length
667
Z6646=BUFER+#2A ;(4)Relative offset of local file header. This is the number of bytes between the start of the first disk on which the file occurs, and the start of the local file header. This allows software reading the central directory to locate the position of the file inside the ZIP file.
668
Z6648=BUFER+#2C
344 alone 669
Z664A=BUFER+#2E ;   䠩
40 alone 670
 
671
        display "Size ",/d,cmd_end-cmd_begin," bytes"
672
 
673
        savebin "pkunzip.com",cmd_begin,cmd_end-cmd_begin
674
 
1467 alone 675
        LABELSLIST "../../us/user.l",1