First post, by Grunt
- Rank
- Newbie
Hello guys,
I've been trying to slow down I/O (especially disk reading) so I can emulate real I/O responses from old computer in DosBox. I've notice that such a thing is alredy implemented and used in DosBox.
dos/dos.cpp:
71: #define DATA_TRANSFERS_TAKE_CYCLES 1
72: #ifdef DATA_TRANSFERS_TAKE_CYCLES
73:
74: #ifndef DOSBOX_CPU_H
75: #include "cpu.h"
76: #endif
77: static inline void modify_cycles(Bits value) {
78: if((4*value+5) < CPU_Cycles) {
79: CPU_Cycles -= 4*value;
80: CPU_IODelayRemoved += 4*value;
81: } else {
82: CPU_IODelayRemoved += CPU_Cycles/*-5*/; //don't want to mess with negative
83: CPU_Cycles = 5;
84: }
85:}
procedure modify_cycles() is then called from reading and writing into file:
644: case 0x3f: /* READ Read from file or device */
645: {
646: Bit16u toread=reg_cx;
647: dos.echo=true;
648: if (DOS_ReadFile(reg_bx,dos_copybuf,&toread)) {
649: MEM_BlockWrite(SegPhys(ds)+reg_dx,dos_copybuf,toread);
650: reg_ax=toread;
651: CALLBACK_SCF(false);
652: } else {
653: reg_ax=dos.errorcode;
654: CALLBACK_SCF(true);
655: }
656: modify_cycles(reg_ax);
657: dos.echo=false;
658: break;
659: }
Unfortunately, I can't figure out how it works. I/O read and write is definitley slower with modify_cycles (respectively disk I/O with DATA_TRANSFERS_TAKE_CYCLES 0 is fast as a lightning on modern PC) but it is still not enough. Even if I just try to leave CPU_Cycles = 5; there hardcoded.
I did found a way, which is SDL_Delay:
77: static inline void modify_cycles(Bits value) {
78: SDL_Delay(10);
79: if((10*value+5) < CPU_Cycles) {
80: CPU_Cycles -= 10*value;
81: ....
This works how anticipated. But it is not correct way how to delay execution. Entire DosBox app is delayed (including drawing functions, recording, etc.), not just execution of virtual machine.
So question follows: Which is proper way how to slow down or delay execution of core (VM?) in DosBox? Lets say in order hundreds of milliseconds or even whole second, not just a few cycles. Just so I can emulate seek times of old HDD or floppy disks.