Subversion Repositories Kolibri OS

Rev

Rev 2382 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
750 victor 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
2540 hidnplayr 3
;; Copyright (C) KolibriOS team 2004-2011. All rights reserved. ;;
750 victor 4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7
 
580 mario79 8
;**************************************************************************
9
;
10
;   [cache_ide[X]_pointer]
11
;   or [cache_ide[X]_data_pointer]  first entry in cache list
12
;
13
;            +0   - lba sector
14
;            +4   - state of cache sector
15
;                   0 = empty
16
;                   1 = used for read  ( same as in hd )
17
;                   2 = used for write ( differs from hd )
18
;
19
;  [cache_ide[X]_system_data]
20
;  or [cache_ide[x]_appl_data] - cache entries
21
;
22
;**************************************************************************
593 mikedld 23
 
2540 hidnplayr 24
$Revision $
593 mikedld 25
 
26
 
580 mario79 27
align 4
28
write_cache:
29
;-----------------------------------------------------------
30
; write all changed sectors to disk
31
;-----------------------------------------------------------
2382 hidnplayr 32
        push    eax ecx edx esi edi
580 mario79 33
 
34
    ; write difference ( 2 ) from cache to hd
2382 hidnplayr 35
        call    calculate_cache
36
        add     esi, 8
37
        mov     edi, 1
585 mario79 38
write_cache_more:
2382 hidnplayr 39
        cmp     dword [esi+4], 2; if cache slot is not different
40
        jne     .write_chain
41
        mov     dword [esi+4], 1; same as in hd
42
        mov     eax, [esi]      ; eax = sector to write
43
        cmp     eax, [PARTITION_START]
44
        jb      danger
45
        cmp     eax, [PARTITION_END]
46
        ja      danger
709 diamond 47
        cmp     [hdpos], 0x80
48
        jae     @f
580 mario79 49
; DMA write is permitted only if [allow_dma_access]=1
2382 hidnplayr 50
        cmp     [allow_dma_access], 2
51
        jae     .nodma
52
        cmp     [dma_hdd], 1
53
        jnz     .nodma
709 diamond 54
@@:
580 mario79 55
; Объединяем запись цепочки последовательных секторов в одно обращение к диску
2382 hidnplayr 56
        cmp     ecx, 1
57
        jz      .nonext
58
        cmp     dword [esi+8+4], 2
59
        jnz     .nonext
60
        push    eax
61
        inc     eax
62
        cmp     eax, [esi+8]
63
        pop     eax
64
        jnz     .nonext
65
        cmp     [cache_chain_started], 1
66
        jz      @f
67
        mov     [cache_chain_started], 1
68
        mov     [cache_chain_size], 0
69
        mov     [cache_chain_pos], edi
70
        mov     [cache_chain_ptr], esi
580 mario79 71
@@:
2382 hidnplayr 72
        inc     [cache_chain_size]
73
        cmp     [cache_chain_size], 16
74
        jnz     .continue
75
        jmp     .write_chain
580 mario79 76
.nonext:
2382 hidnplayr 77
        call    flush_cache_chain
78
        mov     [cache_chain_size], 1
79
        mov     [cache_chain_ptr], esi
80
        call    write_cache_sector
81
        jmp     .continue
580 mario79 82
.nodma:
2382 hidnplayr 83
        call    cache_write_pio
580 mario79 84
.write_chain:
2382 hidnplayr 85
        call    flush_cache_chain
580 mario79 86
.continue:
585 mario79 87
danger:
2382 hidnplayr 88
        add     esi, 8
89
        inc     edi
90
        dec     ecx
91
        jnz     write_cache_more
92
        call    flush_cache_chain
580 mario79 93
 return_02:
2382 hidnplayr 94
        pop     edi esi edx ecx eax
95
        ret
580 mario79 96
 
97
flush_cache_chain:
2382 hidnplayr 98
        cmp     [cache_chain_started], 0
99
        jz      @f
100
        call    write_cache_chain
101
        mov     [cache_chain_started], 0
580 mario79 102
@@:
2382 hidnplayr 103
        ret
585 mario79 104
;--------------------------------------------------------------------
580 mario79 105
align 4
106
find_empty_slot:
107
;-----------------------------------------------------------
108
; find empty or read slot, flush cache if next 10% is used by write
109
; output : edi = cache slot
110
;-----------------------------------------------------------
111
;    push  ecx esi
112
 
585 mario79 113
search_again:
2382 hidnplayr 114
        call    calculate_cache_3
115
        shr     ecx, 3
585 mario79 116
search_for_empty:
2382 hidnplayr 117
        inc     edi
118
        call    calculate_cache_4
119
        jbe     inside_cache
120
        mov     edi, 1
585 mario79 121
inside_cache:
2382 hidnplayr 122
        push    esi
123
        call    calculate_cache_1
124
        cmp     dword [edi*8+esi+4], 2
125
        pop     esi
126
        jb      found_slot              ; it's empty or read
127
        dec     ecx
128
        jnz     search_for_empty
129
        call    write_cache             ; no empty slots found, write all
130
        cmp     [hd_error], 0
131
        jne     found_slot_access_denied
132
        jmp     search_again            ; and start again
585 mario79 133
found_slot:
2382 hidnplayr 134
        call    calculate_cache_5
585 mario79 135
found_slot_access_denied:
2382 hidnplayr 136
        ret
585 mario79 137
;--------------------------------------------------------------------
580 mario79 138
align 4
139
clear_hd_cache:
2382 hidnplayr 140
        mov     [fat_in_cache], -1
141
        mov     [fat_change], 0
142
        ret
580 mario79 143
;--------------------------------------------------------------------
144
align 4
145
calculate_cache:
146
;    mov   ecx,cache_max         ; entries in cache
147
;    mov   esi,HD_CACHE+8
148
 
149
; 1 - IDE0 ... 4 - IDE3
150
.ide0:
2382 hidnplayr 151
        cmp     [hdpos], 1
152
        jne     .ide1
153
        cmp     [hdd_appl_data], 0
154
        jne     .ide0_appl_data
155
        mov     ecx, [cache_ide0_system_sad_size]
156
        mov     esi, [cache_ide0_pointer]
157
        ret
580 mario79 158
.ide0_appl_data:
2382 hidnplayr 159
        mov     ecx, [cache_ide0_appl_sad_size]
160
        mov     esi, [cache_ide0_data_pointer]
161
        ret
580 mario79 162
.ide1:
2382 hidnplayr 163
        cmp     [hdpos], 2
164
        jne     .ide2
165
        cmp     [hdd_appl_data], 0
166
        jne     .ide1_appl_data
167
        mov     ecx, [cache_ide1_system_sad_size]
168
        mov     esi, [cache_ide1_pointer]
169
        ret
580 mario79 170
.ide1_appl_data:
2382 hidnplayr 171
        mov     ecx, [cache_ide1_appl_sad_size]
172
        mov     esi, [cache_ide1_data_pointer]
173
        ret
580 mario79 174
.ide2:
2382 hidnplayr 175
        cmp     [hdpos], 3
176
        jne     .ide3
177
        cmp     [hdd_appl_data], 0
178
        jne     .ide2_appl_data
179
        mov     ecx, [cache_ide2_system_sad_size]
180
        mov     esi, [cache_ide2_pointer]
181
        ret
580 mario79 182
.ide2_appl_data:
2382 hidnplayr 183
        mov     ecx, [cache_ide2_appl_sad_size]
184
        mov     esi, [cache_ide2_data_pointer]
185
        ret
580 mario79 186
.ide3:
2382 hidnplayr 187
        cmp     [hdpos], 4
188
        jne     .noide
189
        cmp     [hdd_appl_data], 0
190
        jne     .ide3_appl_data
191
        mov     ecx, [cache_ide3_system_sad_size]
192
        mov     esi, [cache_ide3_pointer]
193
        ret
580 mario79 194
.ide3_appl_data:
2382 hidnplayr 195
        mov     ecx, [cache_ide3_appl_sad_size]
196
        mov     esi, [cache_ide3_data_pointer]
197
        ret
709 diamond 198
.noide:
2382 hidnplayr 199
        push    eax
200
        mov     eax, [hdpos]
201
        sub     eax, 80h
202
        cmp     byte [BiosDisksData+eax*4+2], -1
203
        jz      @f
204
        movzx   eax, byte [BiosDisksData+eax*4+2]
205
        imul    eax, cache_ide1-cache_ide0
206
        add     eax, cache_ide0
207
        jmp     .get
709 diamond 208
@@:
2382 hidnplayr 209
        imul    eax, cache_ide1-cache_ide0
210
        add     eax, BiosDiskCaches
709 diamond 211
.get:
2382 hidnplayr 212
        cmp     [hdd_appl_data], 0
213
        jne     .bd_appl_data
214
        mov     ecx, [cache_ide0_system_sad_size-cache_ide0+eax]
215
        mov     esi, [cache_ide0_pointer-cache_ide0+eax]
216
        pop     eax
217
        ret
709 diamond 218
.bd_appl_data:
2382 hidnplayr 219
        mov     ecx, [cache_ide0_appl_sad_size-cache_ide0+eax]
220
        mov     esi, [cache_ide0_data_pointer-cache_ide0+eax]
221
        pop     eax
222
        ret
580 mario79 223
;--------------------------------------------------------------------
224
align 4
225
calculate_cache_1:
226
;    lea   esi,[edi*8+HD_CACHE]
227
; 1 - IDE0 ... 4 - IDE3
228
.ide0:
2382 hidnplayr 229
        cmp     [hdpos], 1
230
        jne     .ide1
231
        cmp     [hdd_appl_data], 0
232
        jne     .ide0_appl_data
233
        mov     esi, [cache_ide0_pointer]
234
        ret
580 mario79 235
.ide0_appl_data:
2382 hidnplayr 236
        mov     esi, [cache_ide0_data_pointer]
237
        ret
580 mario79 238
.ide1:
2382 hidnplayr 239
        cmp     [hdpos], 2
240
        jne     .ide2
241
        cmp     [hdd_appl_data], 0
242
        jne     .ide1_appl_data
243
        mov     esi, [cache_ide1_pointer]
244
        ret
580 mario79 245
.ide1_appl_data:
2382 hidnplayr 246
        mov     esi, [cache_ide1_data_pointer]
247
        ret
580 mario79 248
.ide2:
2382 hidnplayr 249
        cmp     [hdpos], 3
250
        jne     .ide3
251
        cmp     [hdd_appl_data], 0
252
        jne     .ide2_appl_data
253
        mov     esi, [cache_ide2_pointer]
254
        ret
580 mario79 255
.ide2_appl_data:
2382 hidnplayr 256
        mov     esi, [cache_ide2_data_pointer]
257
        ret
580 mario79 258
.ide3:
2382 hidnplayr 259
        cmp     [hdpos], 4
260
        jne     .noide
261
        cmp     [hdd_appl_data], 0
262
        jne     .ide3_appl_data
263
        mov     esi, [cache_ide3_pointer]
264
        ret
580 mario79 265
.ide3_appl_data:
2382 hidnplayr 266
        mov     esi, [cache_ide3_data_pointer]
267
        ret
709 diamond 268
.noide:
2382 hidnplayr 269
        push    eax
270
        mov     eax, [hdpos]
271
        sub     eax, 80h
272
        cmp     byte [BiosDisksData+eax*4+2], -1
273
        jz      @f
274
        movzx   eax, byte [BiosDisksData+eax*4+2]
275
        imul    eax, cache_ide1-cache_ide0
276
        add     eax, cache_ide0
277
        jmp     .get
709 diamond 278
@@:
2382 hidnplayr 279
        imul    eax, cache_ide1-cache_ide0
280
        add     eax, BiosDiskCaches
709 diamond 281
.get:
2382 hidnplayr 282
        cmp     [hdd_appl_data], 0
283
        jne     .bd_appl_data
284
        mov     esi, [cache_ide0_pointer-cache_ide0+eax]
285
        pop     eax
286
        ret
709 diamond 287
.bd_appl_data:
2382 hidnplayr 288
        mov     esi, [cache_ide0_data_pointer-cache_ide0+eax]
289
        pop     eax
290
        ret
709 diamond 291
 
580 mario79 292
;--------------------------------------------------------------------
293
align 4
294
calculate_cache_2:
295
;    add   esi,HD_CACHE+65536
296
; 1 - IDE0 ... 4 - IDE3
297
.ide0:
2382 hidnplayr 298
        cmp     [hdpos], 1
299
        jne     .ide1
300
        cmp     [hdd_appl_data], 0
301
        jne     .ide0_appl_data
302
        mov     eax, [cache_ide0_system_data]
303
        ret
580 mario79 304
.ide0_appl_data:
2382 hidnplayr 305
        mov     eax, [cache_ide0_appl_data]
306
        ret
580 mario79 307
.ide1:
2382 hidnplayr 308
        cmp     [hdpos], 2
309
        jne     .ide2
310
        cmp     [hdd_appl_data], 0
311
        jne     .ide1_appl_data
312
        mov     eax, [cache_ide1_system_data]
313
        ret
580 mario79 314
.ide1_appl_data:
2382 hidnplayr 315
        mov     eax, [cache_ide1_appl_data]
316
        ret
580 mario79 317
.ide2:
2382 hidnplayr 318
        cmp     [hdpos], 3
319
        jne     .ide3
320
        cmp     [hdd_appl_data], 0
321
        jne     .ide2_appl_data
322
        mov     eax, [cache_ide2_system_data]
323
        ret
580 mario79 324
.ide2_appl_data:
2382 hidnplayr 325
        mov     eax, [cache_ide2_appl_data]
326
        ret
580 mario79 327
.ide3:
2382 hidnplayr 328
        cmp     [hdpos], 4
329
        jne     .noide
330
        cmp     [hdd_appl_data], 0
331
        jne     .ide3_appl_data
332
        mov     eax, [cache_ide3_system_data]
333
        ret
580 mario79 334
.ide3_appl_data:
2382 hidnplayr 335
        mov     eax, [cache_ide3_appl_data]
336
        ret
709 diamond 337
.noide:
2382 hidnplayr 338
        mov     eax, [hdpos]
339
        sub     eax, 80h
340
        cmp     byte [BiosDisksData+eax*4+2], -1
341
        jz      @f
342
        movzx   eax, byte [BiosDisksData+eax*4+2]
343
        imul    eax, cache_ide1-cache_ide0
344
        add     eax, cache_ide0
345
        jmp     .get
709 diamond 346
@@:
2382 hidnplayr 347
        imul    eax, cache_ide1-cache_ide0
348
        add     eax, BiosDiskCaches
709 diamond 349
.get:
2382 hidnplayr 350
        cmp     [hdd_appl_data], 0
351
        jne     .bd_appl_data
352
        mov     eax, [cache_ide0_system_data-cache_ide0+eax]
353
        ret
709 diamond 354
.bd_appl_data:
2382 hidnplayr 355
        mov     eax, [cache_ide0_appl_data-cache_ide0+eax]
356
        ret
580 mario79 357
;--------------------------------------------------------------------
358
align 4
359
calculate_cache_3:
360
;    mov   ecx,cache_max*10/100
361
;    mov   edi,[cache_search_start]
362
 
363
; 1 - IDE0 ... 4 - IDE3
364
.ide0:
2382 hidnplayr 365
        cmp     [hdpos], 1
366
        jne     .ide1
367
        cmp     [hdd_appl_data], 0
368
        jne     .ide0_appl_data
369
        mov     ecx, [cache_ide0_system_sad_size]
370
        mov     edi, [cache_ide0_search_start]
371
        ret
580 mario79 372
.ide0_appl_data:
2382 hidnplayr 373
        mov     ecx, [cache_ide0_appl_sad_size]
374
        mov     edi, [cache_ide0_appl_search_start]
375
        ret
580 mario79 376
.ide1:
2382 hidnplayr 377
        cmp     [hdpos], 2
378
        jne     .ide2
379
        cmp     [hdd_appl_data], 0
380
        jne     .ide1_appl_data
381
        mov     ecx, [cache_ide1_system_sad_size]
382
        mov     edi, [cache_ide1_search_start]
383
        ret
580 mario79 384
.ide1_appl_data:
2382 hidnplayr 385
        mov     ecx, [cache_ide1_appl_sad_size]
386
        mov     edi, [cache_ide1_appl_search_start]
387
        ret
580 mario79 388
.ide2:
2382 hidnplayr 389
        cmp     [hdpos], 3
390
        jne     .ide3
391
        cmp     [hdd_appl_data], 0
392
        jne     .ide2_appl_data
393
        mov     ecx, [cache_ide2_system_sad_size]
394
        mov     edi, [cache_ide2_search_start]
395
        ret
580 mario79 396
.ide2_appl_data:
2382 hidnplayr 397
        mov     ecx, [cache_ide2_appl_sad_size]
398
        mov     edi, [cache_ide2_appl_search_start]
399
        ret
580 mario79 400
.ide3:
2382 hidnplayr 401
        cmp     [hdpos], 4
402
        jne     .noide
403
        cmp     [hdd_appl_data], 0
404
        jne     .ide3_appl_data
405
        mov     ecx, [cache_ide3_system_sad_size]
406
        mov     edi, [cache_ide3_search_start]
407
        ret
580 mario79 408
.ide3_appl_data:
2382 hidnplayr 409
        mov     ecx, [cache_ide3_appl_sad_size]
410
        mov     edi, [cache_ide3_appl_search_start]
411
        ret
709 diamond 412
.noide:
2382 hidnplayr 413
        push    eax
414
        mov     eax, [hdpos]
415
        sub     eax, 80h
416
        cmp     byte [BiosDisksData+eax*4+2], -1
417
        jz      @f
418
        movzx   eax, byte [BiosDisksData+eax*4+2]
419
        imul    eax, cache_ide1-cache_ide0
420
        add     eax, cache_ide0
421
        jmp     .get
709 diamond 422
@@:
2382 hidnplayr 423
        imul    eax, cache_ide1-cache_ide0
424
        add     eax, BiosDiskCaches
709 diamond 425
.get:
2382 hidnplayr 426
        cmp     [hdd_appl_data], 0
427
        jne     .bd_appl_data
428
        mov     ecx, [cache_ide0_system_sad_size-cache_ide0+eax]
429
        mov     edi, [cache_ide0_search_start-cache_ide0+eax]
430
        pop     eax
431
        ret
709 diamond 432
.bd_appl_data:
2382 hidnplayr 433
        mov     ecx, [cache_ide0_appl_sad_size-cache_ide0+eax]
434
        mov     edi, [cache_ide0_appl_search_start-cache_ide0+eax]
435
        pop     eax
436
        ret
580 mario79 437
;--------------------------------------------------------------------
438
align 4
439
calculate_cache_4:
440
;    cmp   edi,cache_max
441
; 1 - IDE0 ... 4 - IDE3
442
.ide0:
2382 hidnplayr 443
        cmp     [hdpos], 1
444
        jne     .ide1
445
        cmp     [hdd_appl_data], 0
446
        jne     .ide0_appl_data
447
        cmp     edi, [cache_ide0_system_sad_size]
448
        ret
580 mario79 449
.ide0_appl_data:
2382 hidnplayr 450
        cmp     edi, [cache_ide0_appl_sad_size]
451
        ret
580 mario79 452
.ide1:
2382 hidnplayr 453
        cmp     [hdpos], 2
454
        jne     .ide2
455
        cmp     [hdd_appl_data], 0
456
        jne     .ide1_appl_data
457
        cmp     edi, [cache_ide1_system_sad_size]
458
        ret
580 mario79 459
.ide1_appl_data:
2382 hidnplayr 460
        cmp     edi, [cache_ide1_appl_sad_size]
461
        ret
580 mario79 462
.ide2:
2382 hidnplayr 463
        cmp     [hdpos], 3
464
        jne     .ide3
465
        cmp     [hdd_appl_data], 0
466
        jne     .ide2_appl_data
467
        cmp     edi, [cache_ide2_system_sad_size]
468
        ret
580 mario79 469
.ide2_appl_data:
2382 hidnplayr 470
        cmp     edi, [cache_ide2_appl_sad_size]
471
        ret
580 mario79 472
.ide3:
2382 hidnplayr 473
        cmp     [hdpos], 4
474
        jne     .noide
475
        cmp     [hdd_appl_data], 0
476
        jne     .ide3_appl_data
477
        cmp     edi, [cache_ide3_system_sad_size]
478
        ret
580 mario79 479
.ide3_appl_data:
2382 hidnplayr 480
        cmp     edi, [cache_ide3_appl_sad_size]
481
        ret
709 diamond 482
.noide:
2382 hidnplayr 483
        push    eax
484
        mov     eax, [hdpos]
485
        sub     eax, 80h
486
        cmp     byte [BiosDisksData+eax*4+2], -1
487
        jz      @f
488
        movzx   eax, byte [BiosDisksData+eax*4+2]
489
        imul    eax, cache_ide1-cache_ide0
490
        add     eax, cache_ide0
491
        jmp     .get
709 diamond 492
@@:
2382 hidnplayr 493
        imul    eax, cache_ide1-cache_ide0
494
        add     eax, BiosDiskCaches
709 diamond 495
.get:
2382 hidnplayr 496
        cmp     [hdd_appl_data], 0
497
        jne     .bd_appl_data
498
        cmp     edi, [cache_ide0_system_sad_size-cache_ide0+eax]
499
        pop     eax
500
        ret
709 diamond 501
.bd_appl_data:
2382 hidnplayr 502
        cmp     edi, [cache_ide0_appl_sad_size-cache_ide0+eax]
503
        pop     eax
504
        ret
709 diamond 505
 
580 mario79 506
;--------------------------------------------------------------------
507
align 4
508
calculate_cache_5:
509
;    mov   [cache_search_start],edi
510
; 1 - IDE0 ... 4 - IDE3
511
.ide0:
2382 hidnplayr 512
        cmp     [hdpos], 1
513
        jne     .ide1
514
        cmp     [hdd_appl_data], 0
515
        jne     .ide0_appl_data
516
        mov     [cache_ide0_search_start], edi
517
        ret
580 mario79 518
.ide0_appl_data:
2382 hidnplayr 519
        mov     [cache_ide0_appl_search_start], edi
520
        ret
580 mario79 521
.ide1:
2382 hidnplayr 522
        cmp     [hdpos], 2
523
        jne     .ide2
524
        cmp     [hdd_appl_data], 0
525
        jne     .ide1_appl_data
526
        mov     [cache_ide1_search_start], edi
527
        ret
580 mario79 528
.ide1_appl_data:
2382 hidnplayr 529
        mov     [cache_ide1_appl_search_start], edi
530
        ret
580 mario79 531
.ide2:
2382 hidnplayr 532
        cmp     [hdpos], 3
533
        jne     .ide3
534
        cmp     [hdd_appl_data], 0
535
        jne     .ide2_appl_data
536
        mov     [cache_ide2_search_start], edi
537
        ret
580 mario79 538
.ide2_appl_data:
2382 hidnplayr 539
        mov     [cache_ide2_appl_search_start], edi
540
        ret
580 mario79 541
.ide3:
2382 hidnplayr 542
        cmp     [hdpos], 4
543
        jne     .noide
544
        cmp     [hdd_appl_data], 0
545
        jne     .ide3_appl_data
546
        mov     [cache_ide3_search_start], edi
547
        ret
580 mario79 548
.ide3_appl_data:
2382 hidnplayr 549
        mov     [cache_ide3_appl_search_start], edi
550
        ret
709 diamond 551
.noide:
2382 hidnplayr 552
        push    eax
553
        mov     eax, [hdpos]
554
        sub     eax, 80h
555
        cmp     byte [BiosDisksData+eax*4+2], -1
556
        jz      @f
557
        movzx   eax, byte [BiosDisksData+eax*4+2]
558
        imul    eax, cache_ide1-cache_ide0
559
        add     eax, cache_ide0
560
        jmp     .get
709 diamond 561
@@:
2382 hidnplayr 562
        imul    eax, cache_ide1-cache_ide0
563
        add     eax, BiosDiskCaches
709 diamond 564
.get:
2382 hidnplayr 565
        cmp     [hdd_appl_data], 0
566
        jne     .bd_appl_data
567
        mov     [cache_ide0_search_start-cache_ide0+eax], edi
568
        pop     eax
569
        ret
709 diamond 570
.bd_appl_data:
2382 hidnplayr 571
        mov     [cache_ide0_appl_search_start-cache_ide0+eax], edi
572
        pop     eax
573
        ret
585 mario79 574
 
580 mario79 575
;--------------------------------------------------------------------
576
align 4
585 mario79 577
find_empty_slot_CD_cache:
578
;-----------------------------------------------------------
579
; find empty or read slot, flush cache if next 10% is used by write
580
; output : edi = cache slot
581
;-----------------------------------------------------------
582
.search_again:
2382 hidnplayr 583
        call    cd_calculate_cache_3
585 mario79 584
.search_for_empty:
2382 hidnplayr 585
        inc     edi
586
        call    cd_calculate_cache_4
587
        jbe     .inside_cache
588
        mov     edi, 1
585 mario79 589
.inside_cache:
2382 hidnplayr 590
        call    cd_calculate_cache_5
591
        ret
585 mario79 592
;--------------------------------------------------------------------
593
clear_CD_cache:
2382 hidnplayr 594
        pusha
585 mario79 595
.ide0:
2382 hidnplayr 596
        xor     eax, eax
597
        cmp     [cdpos], 1
598
        jne     .ide1
599
        mov     [cache_ide0_search_start], eax
600
        mov     ecx, [cache_ide0_system_sad_size]
601
        mov     edi, [cache_ide0_pointer]
602
        call    .clear
603
        mov     [cache_ide0_appl_search_start], eax
604
        mov     ecx, [cache_ide0_appl_sad_size]
605
        mov     edi, [cache_ide0_data_pointer]
606
        jmp     .continue
585 mario79 607
.ide1:
2382 hidnplayr 608
        cmp     [cdpos], 2
609
        jne     .ide2
610
        mov     [cache_ide1_search_start], eax
611
        mov     ecx, [cache_ide1_system_sad_size]
612
        mov     edi, [cache_ide1_pointer]
613
        call    .clear
614
        mov     [cache_ide1_appl_search_start], eax
615
        mov     ecx, [cache_ide1_appl_sad_size]
616
        mov     edi, [cache_ide1_data_pointer]
617
        jmp     .continue
585 mario79 618
.ide2:
2382 hidnplayr 619
        cmp     [cdpos], 3
620
        jne     .ide3
621
        mov     [cache_ide2_search_start], eax
622
        mov     ecx, [cache_ide2_system_sad_size]
623
        mov     edi, [cache_ide2_pointer]
624
        call    .clear
625
        mov     [cache_ide2_appl_search_start], eax
626
        mov     ecx, [cache_ide2_appl_sad_size]
627
        mov     edi, [cache_ide2_data_pointer]
628
        jmp     .continue
585 mario79 629
.ide3:
2382 hidnplayr 630
        mov     [cache_ide3_search_start], eax
631
        mov     ecx, [cache_ide3_system_sad_size]
632
        mov     edi, [cache_ide3_pointer]
633
        call    .clear
634
        mov     [cache_ide3_appl_search_start], eax
635
        mov     ecx, [cache_ide3_appl_sad_size]
636
        mov     edi, [cache_ide3_data_pointer]
585 mario79 637
.continue:
2382 hidnplayr 638
        call    .clear
639
        popa
640
        ret
585 mario79 641
.clear:
2382 hidnplayr 642
        shl     ecx, 1
643
        cld
644
        rep stosd
645
        ret
585 mario79 646
;--------------------------------------------------------------------
647
align 4
648
cd_calculate_cache:
649
;    mov   ecx,cache_max         ; entries in cache
650
;    mov   esi,HD_CACHE+8
651
 
652
; 1 - IDE0 ... 4 - IDE3
653
.ide0:
2382 hidnplayr 654
        cmp     [cdpos], 1
655
        jne     .ide1
656
        cmp     [cd_appl_data], 0
657
        jne     .ide0_appl_data
658
        mov     ecx, [cache_ide0_system_sad_size]
659
        mov     esi, [cache_ide0_pointer]
660
        ret
585 mario79 661
.ide0_appl_data:
2382 hidnplayr 662
        mov     ecx, [cache_ide0_appl_sad_size]
663
        mov     esi, [cache_ide0_data_pointer]
664
        ret
585 mario79 665
.ide1:
2382 hidnplayr 666
        cmp     [cdpos], 2
667
        jne     .ide2
668
        cmp     [cd_appl_data], 0
669
        jne     .ide1_appl_data
670
        mov     ecx, [cache_ide1_system_sad_size]
671
        mov     esi, [cache_ide1_pointer]
672
        ret
585 mario79 673
.ide1_appl_data:
2382 hidnplayr 674
        mov     ecx, [cache_ide1_appl_sad_size]
675
        mov     esi, [cache_ide1_data_pointer]
676
        ret
585 mario79 677
.ide2:
2382 hidnplayr 678
        cmp     [cdpos], 3
679
        jne     .ide3
680
        cmp     [cd_appl_data], 0
681
        jne     .ide2_appl_data
682
        mov     ecx, [cache_ide2_system_sad_size]
683
        mov     esi, [cache_ide2_pointer]
684
        ret
585 mario79 685
.ide2_appl_data:
2382 hidnplayr 686
        mov     ecx, [cache_ide2_appl_sad_size]
687
        mov     esi, [cache_ide2_data_pointer]
688
        ret
585 mario79 689
.ide3:
2382 hidnplayr 690
        cmp     [cd_appl_data], 0
691
        jne     .ide3_appl_data
692
        mov     ecx, [cache_ide3_system_sad_size]
693
        mov     esi, [cache_ide3_pointer]
694
        ret
585 mario79 695
.ide3_appl_data:
2382 hidnplayr 696
        mov     ecx, [cache_ide3_appl_sad_size]
697
        mov     esi, [cache_ide3_data_pointer]
698
        ret
585 mario79 699
;--------------------------------------------------------------------
700
align 4
701
cd_calculate_cache_1:
702
;    lea   esi,[edi*8+HD_CACHE]
703
; 1 - IDE0 ... 4 - IDE3
704
.ide0:
2382 hidnplayr 705
        cmp     [cdpos], 1
706
        jne     .ide1
707
        cmp     [cd_appl_data], 0
708
        jne     .ide0_appl_data
709
        mov     esi, [cache_ide0_pointer]
710
        ret
585 mario79 711
.ide0_appl_data:
2382 hidnplayr 712
        mov     esi, [cache_ide0_data_pointer]
713
        ret
585 mario79 714
.ide1:
2382 hidnplayr 715
        cmp     [cdpos], 2
716
        jne     .ide2
717
        cmp     [cd_appl_data], 0
718
        jne     .ide1_appl_data
719
        mov     esi, [cache_ide1_pointer]
720
        ret
585 mario79 721
.ide1_appl_data:
2382 hidnplayr 722
        mov     esi, [cache_ide1_data_pointer]
723
        ret
585 mario79 724
.ide2:
2382 hidnplayr 725
        cmp     [cdpos], 3
726
        jne     .ide3
727
        cmp     [cd_appl_data], 0
728
        jne     .ide2_appl_data
729
        mov     esi, [cache_ide2_pointer]
730
        ret
585 mario79 731
.ide2_appl_data:
2382 hidnplayr 732
        mov     esi, [cache_ide2_data_pointer]
733
        ret
585 mario79 734
.ide3:
2382 hidnplayr 735
        cmp     [cd_appl_data], 0
736
        jne     .ide3_appl_data
737
        mov     esi, [cache_ide3_pointer]
738
        ret
585 mario79 739
.ide3_appl_data:
2382 hidnplayr 740
        mov     esi, [cache_ide3_data_pointer]
741
        ret
585 mario79 742
;--------------------------------------------------------------------
743
align 4
744
cd_calculate_cache_2:
745
;    add   esi,HD_CACHE+65536
746
; 1 - IDE0 ... 4 - IDE3
747
.ide0:
2382 hidnplayr 748
        cmp     [cdpos], 1
749
        jne     .ide1
750
        cmp     [cd_appl_data], 0
751
        jne     .ide0_appl_data
752
        mov     eax, [cache_ide0_system_data]
753
        ret
585 mario79 754
.ide0_appl_data:
2382 hidnplayr 755
        mov     eax, [cache_ide0_appl_data]
756
        ret
585 mario79 757
.ide1:
2382 hidnplayr 758
        cmp     [cdpos], 2
759
        jne     .ide2
760
        cmp     [cd_appl_data], 0
761
        jne     .ide1_appl_data
762
        mov     eax, [cache_ide1_system_data]
763
        ret
585 mario79 764
.ide1_appl_data:
2382 hidnplayr 765
        mov     eax, [cache_ide1_appl_data]
766
        ret
585 mario79 767
.ide2:
2382 hidnplayr 768
        cmp     [cdpos], 3
769
        jne     .ide3
770
        cmp     [cd_appl_data], 0
771
        jne     .ide2_appl_data
772
        mov     eax, [cache_ide2_system_data]
773
        ret
585 mario79 774
.ide2_appl_data:
2382 hidnplayr 775
        mov     eax, [cache_ide2_appl_data]
776
        ret
585 mario79 777
.ide3:
2382 hidnplayr 778
        cmp     [cd_appl_data], 0
779
        jne     .ide3_appl_data
780
        mov     eax, [cache_ide3_system_data]
781
        ret
585 mario79 782
.ide3_appl_data:
2382 hidnplayr 783
        mov     eax, [cache_ide3_appl_data]
784
        ret
585 mario79 785
;--------------------------------------------------------------------
786
align 4
787
cd_calculate_cache_3:
788
;    mov   ecx,cache_max*10/100
789
;    mov   edi,[cache_search_start]
790
 
791
; 1 - IDE0 ... 4 - IDE3
792
.ide0:
2382 hidnplayr 793
        cmp     [cdpos], 1
794
        jne     .ide1
795
        cmp     [cd_appl_data], 0
796
        jne     .ide0_appl_data
797
        mov     edi, [cache_ide0_search_start]
798
        ret
585 mario79 799
.ide0_appl_data:
2382 hidnplayr 800
        mov     edi, [cache_ide0_appl_search_start]
801
        ret
585 mario79 802
.ide1:
2382 hidnplayr 803
        cmp     [cdpos], 2
804
        jne     .ide2
805
        cmp     [cd_appl_data], 0
806
        jne     .ide1_appl_data
807
        mov     edi, [cache_ide1_search_start]
808
        ret
585 mario79 809
.ide1_appl_data:
2382 hidnplayr 810
        mov     edi, [cache_ide1_appl_search_start]
811
        ret
585 mario79 812
.ide2:
2382 hidnplayr 813
        cmp     [cdpos], 3
814
        jne     .ide3
815
        cmp     [cd_appl_data], 0
816
        jne     .ide2_appl_data
817
        mov     edi, [cache_ide2_search_start]
818
        ret
585 mario79 819
.ide2_appl_data:
2382 hidnplayr 820
        mov     edi, [cache_ide2_appl_search_start]
821
        ret
585 mario79 822
.ide3:
2382 hidnplayr 823
        cmp     [cd_appl_data], 0
824
        jne     .ide3_appl_data
825
        mov     edi, [cache_ide3_search_start]
826
        ret
585 mario79 827
.ide3_appl_data:
2382 hidnplayr 828
        mov     edi, [cache_ide3_appl_search_start]
829
        ret
585 mario79 830
;--------------------------------------------------------------------
831
align 4
832
cd_calculate_cache_4:
833
;    cmp   edi,cache_max
834
; 1 - IDE0 ... 4 - IDE3
835
.ide0:
2382 hidnplayr 836
        cmp     [cdpos], 1
837
        jne     .ide1
838
        cmp     [cd_appl_data], 0
839
        jne     .ide0_appl_data
840
        cmp     edi, [cache_ide0_system_sad_size]
841
        ret
585 mario79 842
.ide0_appl_data:
2382 hidnplayr 843
        cmp     edi, [cache_ide0_appl_sad_size]
844
        ret
585 mario79 845
.ide1:
2382 hidnplayr 846
        cmp     [cdpos], 2
847
        jne     .ide2
848
        cmp     [cd_appl_data], 0
849
        jne     .ide1_appl_data
850
        cmp     edi, [cache_ide1_system_sad_size]
851
        ret
585 mario79 852
.ide1_appl_data:
2382 hidnplayr 853
        cmp     edi, [cache_ide1_appl_sad_size]
854
        ret
585 mario79 855
.ide2:
2382 hidnplayr 856
        cmp     [cdpos], 3
857
        jne     .ide3
858
        cmp     [cd_appl_data], 0
859
        jne     .ide2_appl_data
860
        cmp     edi, [cache_ide2_system_sad_size]
861
        ret
585 mario79 862
.ide2_appl_data:
2382 hidnplayr 863
        cmp     edi, [cache_ide2_appl_sad_size]
864
        ret
585 mario79 865
.ide3:
2382 hidnplayr 866
        cmp     [cd_appl_data], 0
867
        jne     .ide3_appl_data
868
        cmp     edi, [cache_ide3_system_sad_size]
869
        ret
585 mario79 870
.ide3_appl_data:
2382 hidnplayr 871
        cmp     edi, [cache_ide3_appl_sad_size]
872
        ret
585 mario79 873
;--------------------------------------------------------------------
874
align 4
875
cd_calculate_cache_5:
876
;    mov   [cache_search_start],edi
877
; 1 - IDE0 ... 4 - IDE3
878
.ide0:
2382 hidnplayr 879
        cmp     [cdpos], 1
880
        jne     .ide1
881
        cmp     [cd_appl_data], 0
882
        jne     .ide0_appl_data
883
        mov     [cache_ide0_search_start], edi
884
        ret
585 mario79 885
.ide0_appl_data:
2382 hidnplayr 886
        mov     [cache_ide0_appl_search_start], edi
887
        ret
585 mario79 888
.ide1:
2382 hidnplayr 889
        cmp     [cdpos], 2
890
        jne     .ide2
891
        cmp     [cd_appl_data], 0
892
        jne     .ide1_appl_data
893
        mov     [cache_ide1_search_start], edi
894
        ret
585 mario79 895
.ide1_appl_data:
2382 hidnplayr 896
        mov     [cache_ide1_appl_search_start], edi
897
        ret
585 mario79 898
.ide2:
2382 hidnplayr 899
        cmp     [cdpos], 3
900
        jne     .ide3
901
        cmp     [cd_appl_data], 0
902
        jne     .ide2_appl_data
903
        mov     [cache_ide2_search_start], edi
904
        ret
585 mario79 905
.ide2_appl_data:
2382 hidnplayr 906
        mov     [cache_ide2_appl_search_start], edi
907
        ret
585 mario79 908
.ide3:
2382 hidnplayr 909
        cmp     [cd_appl_data], 0
910
        jne     .ide3_appl_data
911
        mov     [cache_ide3_search_start], edi
912
        ret
585 mario79 913
.ide3_appl_data:
2382 hidnplayr 914
        mov     [cache_ide3_appl_search_start], edi
915
        ret
585 mario79 916
;--------------------------------------------------------------------
917
;align 4
918
;calculate_linear_to_real:
919
;    shr eax, 12
920
;    mov eax, [page_tabs+eax*4]
921
;    and eax, 0xFFFFF000
922
;    ret