Subversion Repositories Kolibri OS

Rev

Rev 3187 | 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
3359 hidnplayr 137
;--------------------------------------------------------------------
138
align 4
139
clear_hd_cache:
140
        ret
141
;--------------------------------------------------------------------
142
align 4
580 mario79 143
calculate_cache:
144
;    mov   ecx,cache_max         ; entries in cache
145
;    mov   esi,HD_CACHE+8
146
 
147
; 1 - IDE0 ... 4 - IDE3
148
.ide0:
2382 hidnplayr 149
        cmp     [hdpos], 1
150
        jne     .ide1
151
        cmp     [hdd_appl_data], 0
152
        jne     .ide0_appl_data
153
        mov     ecx, [cache_ide0_system_sad_size]
154
        mov     esi, [cache_ide0_pointer]
155
        ret
580 mario79 156
.ide0_appl_data:
2382 hidnplayr 157
        mov     ecx, [cache_ide0_appl_sad_size]
158
        mov     esi, [cache_ide0_data_pointer]
159
        ret
580 mario79 160
.ide1:
2382 hidnplayr 161
        cmp     [hdpos], 2
162
        jne     .ide2
163
        cmp     [hdd_appl_data], 0
164
        jne     .ide1_appl_data
165
        mov     ecx, [cache_ide1_system_sad_size]
166
        mov     esi, [cache_ide1_pointer]
167
        ret
580 mario79 168
.ide1_appl_data:
2382 hidnplayr 169
        mov     ecx, [cache_ide1_appl_sad_size]
170
        mov     esi, [cache_ide1_data_pointer]
171
        ret
580 mario79 172
.ide2:
2382 hidnplayr 173
        cmp     [hdpos], 3
174
        jne     .ide3
175
        cmp     [hdd_appl_data], 0
176
        jne     .ide2_appl_data
177
        mov     ecx, [cache_ide2_system_sad_size]
178
        mov     esi, [cache_ide2_pointer]
179
        ret
580 mario79 180
.ide2_appl_data:
2382 hidnplayr 181
        mov     ecx, [cache_ide2_appl_sad_size]
182
        mov     esi, [cache_ide2_data_pointer]
183
        ret
580 mario79 184
.ide3:
2382 hidnplayr 185
        cmp     [hdpos], 4
186
        jne     .noide
187
        cmp     [hdd_appl_data], 0
188
        jne     .ide3_appl_data
189
        mov     ecx, [cache_ide3_system_sad_size]
190
        mov     esi, [cache_ide3_pointer]
191
        ret
580 mario79 192
.ide3_appl_data:
2382 hidnplayr 193
        mov     ecx, [cache_ide3_appl_sad_size]
194
        mov     esi, [cache_ide3_data_pointer]
195
        ret
709 diamond 196
.noide:
2382 hidnplayr 197
        push    eax
198
        mov     eax, [hdpos]
199
        sub     eax, 80h
200
        cmp     byte [BiosDisksData+eax*4+2], -1
201
        jz      @f
202
        movzx   eax, byte [BiosDisksData+eax*4+2]
203
        imul    eax, cache_ide1-cache_ide0
204
        add     eax, cache_ide0
205
        jmp     .get
709 diamond 206
@@:
2382 hidnplayr 207
        imul    eax, cache_ide1-cache_ide0
208
        add     eax, BiosDiskCaches
709 diamond 209
.get:
2382 hidnplayr 210
        cmp     [hdd_appl_data], 0
211
        jne     .bd_appl_data
212
        mov     ecx, [cache_ide0_system_sad_size-cache_ide0+eax]
213
        mov     esi, [cache_ide0_pointer-cache_ide0+eax]
214
        pop     eax
215
        ret
709 diamond 216
.bd_appl_data:
2382 hidnplayr 217
        mov     ecx, [cache_ide0_appl_sad_size-cache_ide0+eax]
218
        mov     esi, [cache_ide0_data_pointer-cache_ide0+eax]
219
        pop     eax
220
        ret
580 mario79 221
;--------------------------------------------------------------------
222
align 4
223
calculate_cache_1:
224
;    lea   esi,[edi*8+HD_CACHE]
225
; 1 - IDE0 ... 4 - IDE3
226
.ide0:
2382 hidnplayr 227
        cmp     [hdpos], 1
228
        jne     .ide1
229
        cmp     [hdd_appl_data], 0
230
        jne     .ide0_appl_data
231
        mov     esi, [cache_ide0_pointer]
232
        ret
580 mario79 233
.ide0_appl_data:
2382 hidnplayr 234
        mov     esi, [cache_ide0_data_pointer]
235
        ret
580 mario79 236
.ide1:
2382 hidnplayr 237
        cmp     [hdpos], 2
238
        jne     .ide2
239
        cmp     [hdd_appl_data], 0
240
        jne     .ide1_appl_data
241
        mov     esi, [cache_ide1_pointer]
242
        ret
580 mario79 243
.ide1_appl_data:
2382 hidnplayr 244
        mov     esi, [cache_ide1_data_pointer]
245
        ret
580 mario79 246
.ide2:
2382 hidnplayr 247
        cmp     [hdpos], 3
248
        jne     .ide3
249
        cmp     [hdd_appl_data], 0
250
        jne     .ide2_appl_data
251
        mov     esi, [cache_ide2_pointer]
252
        ret
580 mario79 253
.ide2_appl_data:
2382 hidnplayr 254
        mov     esi, [cache_ide2_data_pointer]
255
        ret
580 mario79 256
.ide3:
2382 hidnplayr 257
        cmp     [hdpos], 4
258
        jne     .noide
259
        cmp     [hdd_appl_data], 0
260
        jne     .ide3_appl_data
261
        mov     esi, [cache_ide3_pointer]
262
        ret
580 mario79 263
.ide3_appl_data:
2382 hidnplayr 264
        mov     esi, [cache_ide3_data_pointer]
265
        ret
709 diamond 266
.noide:
2382 hidnplayr 267
        push    eax
268
        mov     eax, [hdpos]
269
        sub     eax, 80h
270
        cmp     byte [BiosDisksData+eax*4+2], -1
271
        jz      @f
272
        movzx   eax, byte [BiosDisksData+eax*4+2]
273
        imul    eax, cache_ide1-cache_ide0
274
        add     eax, cache_ide0
275
        jmp     .get
709 diamond 276
@@:
2382 hidnplayr 277
        imul    eax, cache_ide1-cache_ide0
278
        add     eax, BiosDiskCaches
709 diamond 279
.get:
2382 hidnplayr 280
        cmp     [hdd_appl_data], 0
281
        jne     .bd_appl_data
282
        mov     esi, [cache_ide0_pointer-cache_ide0+eax]
283
        pop     eax
284
        ret
709 diamond 285
.bd_appl_data:
2382 hidnplayr 286
        mov     esi, [cache_ide0_data_pointer-cache_ide0+eax]
287
        pop     eax
288
        ret
709 diamond 289
 
580 mario79 290
;--------------------------------------------------------------------
291
align 4
292
calculate_cache_2:
293
;    add   esi,HD_CACHE+65536
294
; 1 - IDE0 ... 4 - IDE3
295
.ide0:
2382 hidnplayr 296
        cmp     [hdpos], 1
297
        jne     .ide1
298
        cmp     [hdd_appl_data], 0
299
        jne     .ide0_appl_data
300
        mov     eax, [cache_ide0_system_data]
301
        ret
580 mario79 302
.ide0_appl_data:
2382 hidnplayr 303
        mov     eax, [cache_ide0_appl_data]
304
        ret
580 mario79 305
.ide1:
2382 hidnplayr 306
        cmp     [hdpos], 2
307
        jne     .ide2
308
        cmp     [hdd_appl_data], 0
309
        jne     .ide1_appl_data
310
        mov     eax, [cache_ide1_system_data]
311
        ret
580 mario79 312
.ide1_appl_data:
2382 hidnplayr 313
        mov     eax, [cache_ide1_appl_data]
314
        ret
580 mario79 315
.ide2:
2382 hidnplayr 316
        cmp     [hdpos], 3
317
        jne     .ide3
318
        cmp     [hdd_appl_data], 0
319
        jne     .ide2_appl_data
320
        mov     eax, [cache_ide2_system_data]
321
        ret
580 mario79 322
.ide2_appl_data:
2382 hidnplayr 323
        mov     eax, [cache_ide2_appl_data]
324
        ret
580 mario79 325
.ide3:
2382 hidnplayr 326
        cmp     [hdpos], 4
327
        jne     .noide
328
        cmp     [hdd_appl_data], 0
329
        jne     .ide3_appl_data
330
        mov     eax, [cache_ide3_system_data]
331
        ret
580 mario79 332
.ide3_appl_data:
2382 hidnplayr 333
        mov     eax, [cache_ide3_appl_data]
334
        ret
709 diamond 335
.noide:
2382 hidnplayr 336
        mov     eax, [hdpos]
337
        sub     eax, 80h
338
        cmp     byte [BiosDisksData+eax*4+2], -1
339
        jz      @f
340
        movzx   eax, byte [BiosDisksData+eax*4+2]
341
        imul    eax, cache_ide1-cache_ide0
342
        add     eax, cache_ide0
343
        jmp     .get
709 diamond 344
@@:
2382 hidnplayr 345
        imul    eax, cache_ide1-cache_ide0
346
        add     eax, BiosDiskCaches
709 diamond 347
.get:
2382 hidnplayr 348
        cmp     [hdd_appl_data], 0
349
        jne     .bd_appl_data
350
        mov     eax, [cache_ide0_system_data-cache_ide0+eax]
351
        ret
709 diamond 352
.bd_appl_data:
2382 hidnplayr 353
        mov     eax, [cache_ide0_appl_data-cache_ide0+eax]
354
        ret
580 mario79 355
;--------------------------------------------------------------------
356
align 4
357
calculate_cache_3:
358
;    mov   ecx,cache_max*10/100
359
;    mov   edi,[cache_search_start]
360
 
361
; 1 - IDE0 ... 4 - IDE3
362
.ide0:
2382 hidnplayr 363
        cmp     [hdpos], 1
364
        jne     .ide1
365
        cmp     [hdd_appl_data], 0
366
        jne     .ide0_appl_data
367
        mov     ecx, [cache_ide0_system_sad_size]
368
        mov     edi, [cache_ide0_search_start]
369
        ret
580 mario79 370
.ide0_appl_data:
2382 hidnplayr 371
        mov     ecx, [cache_ide0_appl_sad_size]
372
        mov     edi, [cache_ide0_appl_search_start]
373
        ret
580 mario79 374
.ide1:
2382 hidnplayr 375
        cmp     [hdpos], 2
376
        jne     .ide2
377
        cmp     [hdd_appl_data], 0
378
        jne     .ide1_appl_data
379
        mov     ecx, [cache_ide1_system_sad_size]
380
        mov     edi, [cache_ide1_search_start]
381
        ret
580 mario79 382
.ide1_appl_data:
2382 hidnplayr 383
        mov     ecx, [cache_ide1_appl_sad_size]
384
        mov     edi, [cache_ide1_appl_search_start]
385
        ret
580 mario79 386
.ide2:
2382 hidnplayr 387
        cmp     [hdpos], 3
388
        jne     .ide3
389
        cmp     [hdd_appl_data], 0
390
        jne     .ide2_appl_data
391
        mov     ecx, [cache_ide2_system_sad_size]
392
        mov     edi, [cache_ide2_search_start]
393
        ret
580 mario79 394
.ide2_appl_data:
2382 hidnplayr 395
        mov     ecx, [cache_ide2_appl_sad_size]
396
        mov     edi, [cache_ide2_appl_search_start]
397
        ret
580 mario79 398
.ide3:
2382 hidnplayr 399
        cmp     [hdpos], 4
400
        jne     .noide
401
        cmp     [hdd_appl_data], 0
402
        jne     .ide3_appl_data
403
        mov     ecx, [cache_ide3_system_sad_size]
404
        mov     edi, [cache_ide3_search_start]
405
        ret
580 mario79 406
.ide3_appl_data:
2382 hidnplayr 407
        mov     ecx, [cache_ide3_appl_sad_size]
408
        mov     edi, [cache_ide3_appl_search_start]
409
        ret
709 diamond 410
.noide:
2382 hidnplayr 411
        push    eax
412
        mov     eax, [hdpos]
413
        sub     eax, 80h
414
        cmp     byte [BiosDisksData+eax*4+2], -1
415
        jz      @f
416
        movzx   eax, byte [BiosDisksData+eax*4+2]
417
        imul    eax, cache_ide1-cache_ide0
418
        add     eax, cache_ide0
419
        jmp     .get
709 diamond 420
@@:
2382 hidnplayr 421
        imul    eax, cache_ide1-cache_ide0
422
        add     eax, BiosDiskCaches
709 diamond 423
.get:
2382 hidnplayr 424
        cmp     [hdd_appl_data], 0
425
        jne     .bd_appl_data
426
        mov     ecx, [cache_ide0_system_sad_size-cache_ide0+eax]
427
        mov     edi, [cache_ide0_search_start-cache_ide0+eax]
428
        pop     eax
429
        ret
709 diamond 430
.bd_appl_data:
2382 hidnplayr 431
        mov     ecx, [cache_ide0_appl_sad_size-cache_ide0+eax]
432
        mov     edi, [cache_ide0_appl_search_start-cache_ide0+eax]
433
        pop     eax
434
        ret
580 mario79 435
;--------------------------------------------------------------------
436
align 4
437
calculate_cache_4:
438
;    cmp   edi,cache_max
439
; 1 - IDE0 ... 4 - IDE3
440
.ide0:
2382 hidnplayr 441
        cmp     [hdpos], 1
442
        jne     .ide1
443
        cmp     [hdd_appl_data], 0
444
        jne     .ide0_appl_data
445
        cmp     edi, [cache_ide0_system_sad_size]
446
        ret
580 mario79 447
.ide0_appl_data:
2382 hidnplayr 448
        cmp     edi, [cache_ide0_appl_sad_size]
449
        ret
580 mario79 450
.ide1:
2382 hidnplayr 451
        cmp     [hdpos], 2
452
        jne     .ide2
453
        cmp     [hdd_appl_data], 0
454
        jne     .ide1_appl_data
455
        cmp     edi, [cache_ide1_system_sad_size]
456
        ret
580 mario79 457
.ide1_appl_data:
2382 hidnplayr 458
        cmp     edi, [cache_ide1_appl_sad_size]
459
        ret
580 mario79 460
.ide2:
2382 hidnplayr 461
        cmp     [hdpos], 3
462
        jne     .ide3
463
        cmp     [hdd_appl_data], 0
464
        jne     .ide2_appl_data
465
        cmp     edi, [cache_ide2_system_sad_size]
466
        ret
580 mario79 467
.ide2_appl_data:
2382 hidnplayr 468
        cmp     edi, [cache_ide2_appl_sad_size]
469
        ret
580 mario79 470
.ide3:
2382 hidnplayr 471
        cmp     [hdpos], 4
472
        jne     .noide
473
        cmp     [hdd_appl_data], 0
474
        jne     .ide3_appl_data
475
        cmp     edi, [cache_ide3_system_sad_size]
476
        ret
580 mario79 477
.ide3_appl_data:
2382 hidnplayr 478
        cmp     edi, [cache_ide3_appl_sad_size]
479
        ret
709 diamond 480
.noide:
2382 hidnplayr 481
        push    eax
482
        mov     eax, [hdpos]
483
        sub     eax, 80h
484
        cmp     byte [BiosDisksData+eax*4+2], -1
485
        jz      @f
486
        movzx   eax, byte [BiosDisksData+eax*4+2]
487
        imul    eax, cache_ide1-cache_ide0
488
        add     eax, cache_ide0
489
        jmp     .get
709 diamond 490
@@:
2382 hidnplayr 491
        imul    eax, cache_ide1-cache_ide0
492
        add     eax, BiosDiskCaches
709 diamond 493
.get:
2382 hidnplayr 494
        cmp     [hdd_appl_data], 0
495
        jne     .bd_appl_data
496
        cmp     edi, [cache_ide0_system_sad_size-cache_ide0+eax]
497
        pop     eax
498
        ret
709 diamond 499
.bd_appl_data:
2382 hidnplayr 500
        cmp     edi, [cache_ide0_appl_sad_size-cache_ide0+eax]
501
        pop     eax
502
        ret
709 diamond 503
 
580 mario79 504
;--------------------------------------------------------------------
505
align 4
506
calculate_cache_5:
507
;    mov   [cache_search_start],edi
508
; 1 - IDE0 ... 4 - IDE3
509
.ide0:
2382 hidnplayr 510
        cmp     [hdpos], 1
511
        jne     .ide1
512
        cmp     [hdd_appl_data], 0
513
        jne     .ide0_appl_data
514
        mov     [cache_ide0_search_start], edi
515
        ret
580 mario79 516
.ide0_appl_data:
2382 hidnplayr 517
        mov     [cache_ide0_appl_search_start], edi
518
        ret
580 mario79 519
.ide1:
2382 hidnplayr 520
        cmp     [hdpos], 2
521
        jne     .ide2
522
        cmp     [hdd_appl_data], 0
523
        jne     .ide1_appl_data
524
        mov     [cache_ide1_search_start], edi
525
        ret
580 mario79 526
.ide1_appl_data:
2382 hidnplayr 527
        mov     [cache_ide1_appl_search_start], edi
528
        ret
580 mario79 529
.ide2:
2382 hidnplayr 530
        cmp     [hdpos], 3
531
        jne     .ide3
532
        cmp     [hdd_appl_data], 0
533
        jne     .ide2_appl_data
534
        mov     [cache_ide2_search_start], edi
535
        ret
580 mario79 536
.ide2_appl_data:
2382 hidnplayr 537
        mov     [cache_ide2_appl_search_start], edi
538
        ret
580 mario79 539
.ide3:
2382 hidnplayr 540
        cmp     [hdpos], 4
541
        jne     .noide
542
        cmp     [hdd_appl_data], 0
543
        jne     .ide3_appl_data
544
        mov     [cache_ide3_search_start], edi
545
        ret
580 mario79 546
.ide3_appl_data:
2382 hidnplayr 547
        mov     [cache_ide3_appl_search_start], edi
548
        ret
709 diamond 549
.noide:
2382 hidnplayr 550
        push    eax
551
        mov     eax, [hdpos]
552
        sub     eax, 80h
553
        cmp     byte [BiosDisksData+eax*4+2], -1
554
        jz      @f
555
        movzx   eax, byte [BiosDisksData+eax*4+2]
556
        imul    eax, cache_ide1-cache_ide0
557
        add     eax, cache_ide0
558
        jmp     .get
709 diamond 559
@@:
2382 hidnplayr 560
        imul    eax, cache_ide1-cache_ide0
561
        add     eax, BiosDiskCaches
709 diamond 562
.get:
2382 hidnplayr 563
        cmp     [hdd_appl_data], 0
564
        jne     .bd_appl_data
565
        mov     [cache_ide0_search_start-cache_ide0+eax], edi
566
        pop     eax
567
        ret
709 diamond 568
.bd_appl_data:
2382 hidnplayr 569
        mov     [cache_ide0_appl_search_start-cache_ide0+eax], edi
570
        pop     eax
571
        ret
585 mario79 572
 
580 mario79 573
;--------------------------------------------------------------------
574
align 4
585 mario79 575
find_empty_slot_CD_cache:
576
;-----------------------------------------------------------
577
; find empty or read slot, flush cache if next 10% is used by write
578
; output : edi = cache slot
579
;-----------------------------------------------------------
580
.search_again:
2382 hidnplayr 581
        call    cd_calculate_cache_3
585 mario79 582
.search_for_empty:
2382 hidnplayr 583
        inc     edi
584
        call    cd_calculate_cache_4
585
        jbe     .inside_cache
586
        mov     edi, 1
585 mario79 587
.inside_cache:
2382 hidnplayr 588
        call    cd_calculate_cache_5
589
        ret
585 mario79 590
;--------------------------------------------------------------------
591
clear_CD_cache:
2382 hidnplayr 592
        pusha
585 mario79 593
.ide0:
2382 hidnplayr 594
        xor     eax, eax
595
        cmp     [cdpos], 1
596
        jne     .ide1
597
        mov     [cache_ide0_search_start], eax
598
        mov     ecx, [cache_ide0_system_sad_size]
599
        mov     edi, [cache_ide0_pointer]
600
        call    .clear
601
        mov     [cache_ide0_appl_search_start], eax
602
        mov     ecx, [cache_ide0_appl_sad_size]
603
        mov     edi, [cache_ide0_data_pointer]
604
        jmp     .continue
585 mario79 605
.ide1:
2382 hidnplayr 606
        cmp     [cdpos], 2
607
        jne     .ide2
608
        mov     [cache_ide1_search_start], eax
609
        mov     ecx, [cache_ide1_system_sad_size]
610
        mov     edi, [cache_ide1_pointer]
611
        call    .clear
612
        mov     [cache_ide1_appl_search_start], eax
613
        mov     ecx, [cache_ide1_appl_sad_size]
614
        mov     edi, [cache_ide1_data_pointer]
615
        jmp     .continue
585 mario79 616
.ide2:
2382 hidnplayr 617
        cmp     [cdpos], 3
618
        jne     .ide3
619
        mov     [cache_ide2_search_start], eax
620
        mov     ecx, [cache_ide2_system_sad_size]
621
        mov     edi, [cache_ide2_pointer]
622
        call    .clear
623
        mov     [cache_ide2_appl_search_start], eax
624
        mov     ecx, [cache_ide2_appl_sad_size]
625
        mov     edi, [cache_ide2_data_pointer]
626
        jmp     .continue
585 mario79 627
.ide3:
2382 hidnplayr 628
        mov     [cache_ide3_search_start], eax
629
        mov     ecx, [cache_ide3_system_sad_size]
630
        mov     edi, [cache_ide3_pointer]
631
        call    .clear
632
        mov     [cache_ide3_appl_search_start], eax
633
        mov     ecx, [cache_ide3_appl_sad_size]
634
        mov     edi, [cache_ide3_data_pointer]
585 mario79 635
.continue:
2382 hidnplayr 636
        call    .clear
637
        popa
638
        ret
585 mario79 639
.clear:
2382 hidnplayr 640
        shl     ecx, 1
641
        cld
642
        rep stosd
643
        ret
585 mario79 644
;--------------------------------------------------------------------
645
align 4
646
cd_calculate_cache:
647
;    mov   ecx,cache_max         ; entries in cache
648
;    mov   esi,HD_CACHE+8
649
 
650
; 1 - IDE0 ... 4 - IDE3
651
.ide0:
2382 hidnplayr 652
        cmp     [cdpos], 1
653
        jne     .ide1
654
        cmp     [cd_appl_data], 0
655
        jne     .ide0_appl_data
656
        mov     ecx, [cache_ide0_system_sad_size]
657
        mov     esi, [cache_ide0_pointer]
658
        ret
585 mario79 659
.ide0_appl_data:
2382 hidnplayr 660
        mov     ecx, [cache_ide0_appl_sad_size]
661
        mov     esi, [cache_ide0_data_pointer]
662
        ret
585 mario79 663
.ide1:
2382 hidnplayr 664
        cmp     [cdpos], 2
665
        jne     .ide2
666
        cmp     [cd_appl_data], 0
667
        jne     .ide1_appl_data
668
        mov     ecx, [cache_ide1_system_sad_size]
669
        mov     esi, [cache_ide1_pointer]
670
        ret
585 mario79 671
.ide1_appl_data:
2382 hidnplayr 672
        mov     ecx, [cache_ide1_appl_sad_size]
673
        mov     esi, [cache_ide1_data_pointer]
674
        ret
585 mario79 675
.ide2:
2382 hidnplayr 676
        cmp     [cdpos], 3
677
        jne     .ide3
678
        cmp     [cd_appl_data], 0
679
        jne     .ide2_appl_data
680
        mov     ecx, [cache_ide2_system_sad_size]
681
        mov     esi, [cache_ide2_pointer]
682
        ret
585 mario79 683
.ide2_appl_data:
2382 hidnplayr 684
        mov     ecx, [cache_ide2_appl_sad_size]
685
        mov     esi, [cache_ide2_data_pointer]
686
        ret
585 mario79 687
.ide3:
2382 hidnplayr 688
        cmp     [cd_appl_data], 0
689
        jne     .ide3_appl_data
690
        mov     ecx, [cache_ide3_system_sad_size]
691
        mov     esi, [cache_ide3_pointer]
692
        ret
585 mario79 693
.ide3_appl_data:
2382 hidnplayr 694
        mov     ecx, [cache_ide3_appl_sad_size]
695
        mov     esi, [cache_ide3_data_pointer]
696
        ret
585 mario79 697
;--------------------------------------------------------------------
698
align 4
699
cd_calculate_cache_1:
700
;    lea   esi,[edi*8+HD_CACHE]
701
; 1 - IDE0 ... 4 - IDE3
702
.ide0:
2382 hidnplayr 703
        cmp     [cdpos], 1
704
        jne     .ide1
705
        cmp     [cd_appl_data], 0
706
        jne     .ide0_appl_data
707
        mov     esi, [cache_ide0_pointer]
708
        ret
585 mario79 709
.ide0_appl_data:
2382 hidnplayr 710
        mov     esi, [cache_ide0_data_pointer]
711
        ret
585 mario79 712
.ide1:
2382 hidnplayr 713
        cmp     [cdpos], 2
714
        jne     .ide2
715
        cmp     [cd_appl_data], 0
716
        jne     .ide1_appl_data
717
        mov     esi, [cache_ide1_pointer]
718
        ret
585 mario79 719
.ide1_appl_data:
2382 hidnplayr 720
        mov     esi, [cache_ide1_data_pointer]
721
        ret
585 mario79 722
.ide2:
2382 hidnplayr 723
        cmp     [cdpos], 3
724
        jne     .ide3
725
        cmp     [cd_appl_data], 0
726
        jne     .ide2_appl_data
727
        mov     esi, [cache_ide2_pointer]
728
        ret
585 mario79 729
.ide2_appl_data:
2382 hidnplayr 730
        mov     esi, [cache_ide2_data_pointer]
731
        ret
585 mario79 732
.ide3:
2382 hidnplayr 733
        cmp     [cd_appl_data], 0
734
        jne     .ide3_appl_data
735
        mov     esi, [cache_ide3_pointer]
736
        ret
585 mario79 737
.ide3_appl_data:
2382 hidnplayr 738
        mov     esi, [cache_ide3_data_pointer]
739
        ret
585 mario79 740
;--------------------------------------------------------------------
741
align 4
742
cd_calculate_cache_2:
743
;    add   esi,HD_CACHE+65536
744
; 1 - IDE0 ... 4 - IDE3
745
.ide0:
2382 hidnplayr 746
        cmp     [cdpos], 1
747
        jne     .ide1
748
        cmp     [cd_appl_data], 0
749
        jne     .ide0_appl_data
750
        mov     eax, [cache_ide0_system_data]
751
        ret
585 mario79 752
.ide0_appl_data:
2382 hidnplayr 753
        mov     eax, [cache_ide0_appl_data]
754
        ret
585 mario79 755
.ide1:
2382 hidnplayr 756
        cmp     [cdpos], 2
757
        jne     .ide2
758
        cmp     [cd_appl_data], 0
759
        jne     .ide1_appl_data
760
        mov     eax, [cache_ide1_system_data]
761
        ret
585 mario79 762
.ide1_appl_data:
2382 hidnplayr 763
        mov     eax, [cache_ide1_appl_data]
764
        ret
585 mario79 765
.ide2:
2382 hidnplayr 766
        cmp     [cdpos], 3
767
        jne     .ide3
768
        cmp     [cd_appl_data], 0
769
        jne     .ide2_appl_data
770
        mov     eax, [cache_ide2_system_data]
771
        ret
585 mario79 772
.ide2_appl_data:
2382 hidnplayr 773
        mov     eax, [cache_ide2_appl_data]
774
        ret
585 mario79 775
.ide3:
2382 hidnplayr 776
        cmp     [cd_appl_data], 0
777
        jne     .ide3_appl_data
778
        mov     eax, [cache_ide3_system_data]
779
        ret
585 mario79 780
.ide3_appl_data:
2382 hidnplayr 781
        mov     eax, [cache_ide3_appl_data]
782
        ret
585 mario79 783
;--------------------------------------------------------------------
784
align 4
785
cd_calculate_cache_3:
786
;    mov   ecx,cache_max*10/100
787
;    mov   edi,[cache_search_start]
788
 
789
; 1 - IDE0 ... 4 - IDE3
790
.ide0:
2382 hidnplayr 791
        cmp     [cdpos], 1
792
        jne     .ide1
793
        cmp     [cd_appl_data], 0
794
        jne     .ide0_appl_data
795
        mov     edi, [cache_ide0_search_start]
796
        ret
585 mario79 797
.ide0_appl_data:
2382 hidnplayr 798
        mov     edi, [cache_ide0_appl_search_start]
799
        ret
585 mario79 800
.ide1:
2382 hidnplayr 801
        cmp     [cdpos], 2
802
        jne     .ide2
803
        cmp     [cd_appl_data], 0
804
        jne     .ide1_appl_data
805
        mov     edi, [cache_ide1_search_start]
806
        ret
585 mario79 807
.ide1_appl_data:
2382 hidnplayr 808
        mov     edi, [cache_ide1_appl_search_start]
809
        ret
585 mario79 810
.ide2:
2382 hidnplayr 811
        cmp     [cdpos], 3
812
        jne     .ide3
813
        cmp     [cd_appl_data], 0
814
        jne     .ide2_appl_data
815
        mov     edi, [cache_ide2_search_start]
816
        ret
585 mario79 817
.ide2_appl_data:
2382 hidnplayr 818
        mov     edi, [cache_ide2_appl_search_start]
819
        ret
585 mario79 820
.ide3:
2382 hidnplayr 821
        cmp     [cd_appl_data], 0
822
        jne     .ide3_appl_data
823
        mov     edi, [cache_ide3_search_start]
824
        ret
585 mario79 825
.ide3_appl_data:
2382 hidnplayr 826
        mov     edi, [cache_ide3_appl_search_start]
827
        ret
585 mario79 828
;--------------------------------------------------------------------
829
align 4
830
cd_calculate_cache_4:
831
;    cmp   edi,cache_max
832
; 1 - IDE0 ... 4 - IDE3
833
.ide0:
2382 hidnplayr 834
        cmp     [cdpos], 1
835
        jne     .ide1
836
        cmp     [cd_appl_data], 0
837
        jne     .ide0_appl_data
838
        cmp     edi, [cache_ide0_system_sad_size]
839
        ret
585 mario79 840
.ide0_appl_data:
2382 hidnplayr 841
        cmp     edi, [cache_ide0_appl_sad_size]
842
        ret
585 mario79 843
.ide1:
2382 hidnplayr 844
        cmp     [cdpos], 2
845
        jne     .ide2
846
        cmp     [cd_appl_data], 0
847
        jne     .ide1_appl_data
848
        cmp     edi, [cache_ide1_system_sad_size]
849
        ret
585 mario79 850
.ide1_appl_data:
2382 hidnplayr 851
        cmp     edi, [cache_ide1_appl_sad_size]
852
        ret
585 mario79 853
.ide2:
2382 hidnplayr 854
        cmp     [cdpos], 3
855
        jne     .ide3
856
        cmp     [cd_appl_data], 0
857
        jne     .ide2_appl_data
858
        cmp     edi, [cache_ide2_system_sad_size]
859
        ret
585 mario79 860
.ide2_appl_data:
2382 hidnplayr 861
        cmp     edi, [cache_ide2_appl_sad_size]
862
        ret
585 mario79 863
.ide3:
2382 hidnplayr 864
        cmp     [cd_appl_data], 0
865
        jne     .ide3_appl_data
866
        cmp     edi, [cache_ide3_system_sad_size]
867
        ret
585 mario79 868
.ide3_appl_data:
2382 hidnplayr 869
        cmp     edi, [cache_ide3_appl_sad_size]
870
        ret
585 mario79 871
;--------------------------------------------------------------------
872
align 4
873
cd_calculate_cache_5:
874
;    mov   [cache_search_start],edi
875
; 1 - IDE0 ... 4 - IDE3
876
.ide0:
2382 hidnplayr 877
        cmp     [cdpos], 1
878
        jne     .ide1
879
        cmp     [cd_appl_data], 0
880
        jne     .ide0_appl_data
881
        mov     [cache_ide0_search_start], edi
882
        ret
585 mario79 883
.ide0_appl_data:
2382 hidnplayr 884
        mov     [cache_ide0_appl_search_start], edi
885
        ret
585 mario79 886
.ide1:
2382 hidnplayr 887
        cmp     [cdpos], 2
888
        jne     .ide2
889
        cmp     [cd_appl_data], 0
890
        jne     .ide1_appl_data
891
        mov     [cache_ide1_search_start], edi
892
        ret
585 mario79 893
.ide1_appl_data:
2382 hidnplayr 894
        mov     [cache_ide1_appl_search_start], edi
895
        ret
585 mario79 896
.ide2:
2382 hidnplayr 897
        cmp     [cdpos], 3
898
        jne     .ide3
899
        cmp     [cd_appl_data], 0
900
        jne     .ide2_appl_data
901
        mov     [cache_ide2_search_start], edi
902
        ret
585 mario79 903
.ide2_appl_data:
2382 hidnplayr 904
        mov     [cache_ide2_appl_search_start], edi
905
        ret
585 mario79 906
.ide3:
2382 hidnplayr 907
        cmp     [cd_appl_data], 0
908
        jne     .ide3_appl_data
909
        mov     [cache_ide3_search_start], edi
910
        ret
585 mario79 911
.ide3_appl_data:
2382 hidnplayr 912
        mov     [cache_ide3_appl_search_start], edi
913
        ret
585 mario79 914
;--------------------------------------------------------------------
915
;align 4
916
;calculate_linear_to_real:
917
;    shr eax, 12
918
;    mov eax, [page_tabs+eax*4]
919
;    and eax, 0xFFFFF000
920
;    ret