24 |
|
#include <devices/trackdisk.h> |
25 |
|
#include <devices/scsidisk.h> |
26 |
|
#include <resources/disk.h> |
27 |
+ |
#define __USE_SYSBASE |
28 |
|
#include <proto/dos.h> |
29 |
|
#include <proto/exec.h> |
30 |
|
#include <proto/disk.h> |
31 |
+ |
#include <inline/dos.h> |
32 |
+ |
#include <inline/exec.h> |
33 |
+ |
#include <inline/disk.h> |
34 |
|
|
35 |
|
#include "sysdeps.h" |
36 |
|
#include "main.h" |
82 |
|
the_port = CreateMsgPort(); |
83 |
|
tmp_buf = (UBYTE *)AllocMem(TMP_BUF_SIZE, MEMF_CHIP | MEMF_PUBLIC); |
84 |
|
if (the_port == NULL || tmp_buf == NULL) { |
85 |
< |
ErrorAlert(GetString(STR_NO_MEM_ERR)); |
85 |
> |
ErrorAlert(STR_NO_MEM_ERR); |
86 |
|
QuitEmulator(); |
87 |
|
} |
88 |
|
} |
216 |
|
return NULL; |
217 |
|
|
218 |
|
// Open device |
219 |
< |
if (OpenDevice((UBYTE *)dev_name, dev_unit, (struct IORequest *)io, dev_flags)) { |
219 |
> |
if (OpenDevice((UBYTE *) dev_name, dev_unit, (struct IORequest *)io, dev_flags)) { |
220 |
|
D(bug(" couldn't open device\n")); |
221 |
|
DeleteIORequest(io); |
222 |
|
return NULL; |
385 |
|
|
386 |
|
} else { |
387 |
|
|
388 |
< |
if (DoIO((struct IORequest *)fh->io) || fh->io->io_Actual != length) |
388 |
> |
// if (DoIO((struct IORequest *)fh->io) || fh->io->io_Actual != length) |
389 |
> |
if (DoIO((struct IORequest *)fh->io)) |
390 |
> |
{ |
391 |
> |
D(bug("send_io_request/%ld: Actual=%lu length=%lu Err=%ld\n", __LINE__, fh->io->io_Actual, length, fh->io->io_Error)); |
392 |
|
return 0; |
393 |
+ |
} |
394 |
|
return fh->io->io_Actual; |
395 |
|
} |
396 |
|
} |
405 |
|
{ |
406 |
|
file_handle *fh = (file_handle *)arg; |
407 |
|
if (!fh) |
408 |
+ |
{ |
409 |
+ |
D(bug("Sys_read/%ld return 0\n", __LINE__)); |
410 |
|
return 0; |
411 |
+ |
} |
412 |
+ |
|
413 |
+ |
D(bug("Sys_read/%ld length=%ld\n", __LINE__, length)); |
414 |
|
|
415 |
|
// File or device? |
416 |
|
if (fh->is_file) { |
417 |
|
|
418 |
|
// File, seek to position |
419 |
|
if (Seek(fh->f, offset + fh->start_byte, OFFSET_BEGINNING) == -1) |
420 |
+ |
{ |
421 |
+ |
D(bug("Sys_read/%ld return 0\n", __LINE__)); |
422 |
|
return 0; |
423 |
+ |
} |
424 |
|
|
425 |
|
// Read data |
426 |
|
LONG actual = Read(fh->f, buffer, length); |
427 |
|
if (actual == -1) |
428 |
+ |
{ |
429 |
+ |
D(bug("Sys_read/%ld return 0\n", __LINE__)); |
430 |
|
return 0; |
431 |
+ |
} |
432 |
|
else |
433 |
+ |
{ |
434 |
+ |
D(bug("Sys_read/%ld return %ld\n", __LINE__, actual)); |
435 |
|
return actual; |
436 |
+ |
} |
437 |
|
|
438 |
|
} else { |
439 |
|
|
445 |
|
|
446 |
|
// Yes, read one block |
447 |
|
if (send_io_request(fh, false, fh->block_size, pos - pre_offset, tmp_buf) == 0) |
448 |
+ |
{ |
449 |
+ |
D(bug("Sys_read/%ld return %ld\n", __LINE__, 0)); |
450 |
|
return 0; |
451 |
+ |
} |
452 |
|
|
453 |
|
// Copy data to destination buffer |
454 |
|
size_t pre_length = fh->block_size - pre_offset; |
469 |
|
// Yes, read blocks |
470 |
|
size_t main_length = length & ~(fh->block_size - 1); |
471 |
|
if (send_io_request(fh, false, main_length, pos, buffer) == 0) |
472 |
+ |
{ |
473 |
+ |
D(bug("Sys_read/%ld return %ld\n", __LINE__, 0)); |
474 |
|
return 0; |
475 |
+ |
} |
476 |
|
|
477 |
|
// Adjust data pointers |
478 |
|
buffer = (uint8 *)buffer + main_length; |
486 |
|
|
487 |
|
// Yes, read one block |
488 |
|
if (send_io_request(fh, false, fh->block_size, pos, tmp_buf) == 0) |
489 |
+ |
{ |
490 |
+ |
D(bug("Sys_read/%ld return %ld\n", __LINE__, 0)); |
491 |
|
return 0; |
492 |
+ |
} |
493 |
|
|
494 |
|
// Copy data to destination buffer |
495 |
|
memcpy(buffer, tmp_buf, length); |
496 |
|
actual += length; |
497 |
|
} |
498 |
|
|
499 |
+ |
D(bug("Sys_read/%ld return %ld\n", __LINE__, actual)); |
500 |
|
return actual; |
501 |
|
} |
502 |
|
} |
511 |
|
{ |
512 |
|
file_handle *fh = (file_handle *)arg; |
513 |
|
if (!fh) |
514 |
+ |
{ |
515 |
+ |
D(bug("Sys_write/%ld return %ld\n", __LINE__, 0)); |
516 |
|
return 0; |
517 |
+ |
} |
518 |
+ |
|
519 |
+ |
D(bug("Sys_write/%ld length=%ld\n", __LINE__, length)); |
520 |
|
|
521 |
|
// File or device? |
522 |
|
if (fh->is_file) { |
523 |
|
|
524 |
|
// File, seek to position if necessary |
525 |
|
if (Seek(fh->f, offset + fh->start_byte, OFFSET_BEGINNING) == -1) |
526 |
+ |
{ |
527 |
+ |
D(bug("Sys_write/%ld return %ld\n", __LINE__, 0)); |
528 |
|
return 0; |
529 |
+ |
} |
530 |
|
|
531 |
|
// Write data |
532 |
|
LONG actual = Write(fh->f, buffer, length); |
533 |
|
if (actual == -1) |
534 |
+ |
{ |
535 |
+ |
D(bug("Sys_write/%ld return %ld\n", __LINE__, 0)); |
536 |
|
return 0; |
537 |
+ |
} |
538 |
|
else |
539 |
+ |
{ |
540 |
+ |
D(bug("Sys_write/%ld return %ld\n", __LINE__, actual)); |
541 |
|
return actual; |
542 |
+ |
} |
543 |
|
|
544 |
|
} else { |
545 |
|
|
551 |
|
|
552 |
|
// Yes, read one block |
553 |
|
if (send_io_request(fh, false, fh->block_size, pos - pre_offset, tmp_buf) == 0) |
554 |
+ |
{ |
555 |
+ |
D(bug("Sys_write/%ld return %ld\n", __LINE__, 0)); |
556 |
|
return 0; |
557 |
+ |
} |
558 |
|
|
559 |
|
// Copy data from source buffer |
560 |
|
size_t pre_length = fh->block_size - pre_offset; |
564 |
|
|
565 |
|
// Write block back |
566 |
|
if (send_io_request(fh, true, fh->block_size, pos - pre_offset, tmp_buf) == 0) |
567 |
+ |
{ |
568 |
+ |
D(bug("Sys_write/%ld return %ld\n", __LINE__, 0)); |
569 |
|
return 0; |
570 |
+ |
} |
571 |
|
|
572 |
|
// Adjust data pointers |
573 |
|
buffer = (uint8 *)buffer + pre_length; |
582 |
|
// Yes, write blocks |
583 |
|
size_t main_length = length & ~(fh->block_size - 1); |
584 |
|
if (send_io_request(fh, true, main_length, pos, buffer) == 0) |
585 |
+ |
{ |
586 |
+ |
D(bug("Sys_write/%ld return %ld\n", __LINE__, 0)); |
587 |
|
return 0; |
588 |
+ |
} |
589 |
|
|
590 |
|
// Adjust data pointers |
591 |
|
buffer = (uint8 *)buffer + main_length; |
599 |
|
|
600 |
|
// Yes, read one block |
601 |
|
if (send_io_request(fh, false, fh->block_size, pos, tmp_buf) == 0) |
602 |
+ |
{ |
603 |
+ |
D(bug("Sys_write/%ld return %ld\n", __LINE__, 0)); |
604 |
|
return 0; |
605 |
+ |
} |
606 |
|
|
607 |
|
// Copy data from source buffer |
608 |
|
memcpy(buffer, tmp_buf, length); |
609 |
|
|
610 |
|
// Write block back |
611 |
|
if (send_io_request(fh, true, fh->block_size, pos, tmp_buf) == 0) |
612 |
+ |
{ |
613 |
+ |
D(bug("Sys_write/%ld return %ld\n", __LINE__, 0)); |
614 |
|
return 0; |
615 |
+ |
} |
616 |
|
actual += length; |
617 |
|
} |
618 |
|
|
619 |
+ |
D(bug("Sys_write/%ld return %ld\n", __LINE__, actual)); |
620 |
|
return actual; |
621 |
|
} |
622 |
|
} |