Fixed! Virtual .com files work perfectly now, command line arguments and all. DOS games probably work a lot better too.

This time no work-arounds, or wii-specific sections, just messy code.
If you can tell me how to properly declare a packed structure on the Wii (and other platforms), I can make the code less messy.
This commit is contained in:
Carl.Kenner 2009-05-06 19:40:27 +00:00
parent 0447edac43
commit 63c5a10292
4 changed files with 78 additions and 54 deletions

File diff suppressed because one or more lines are too long

View File

@ -286,19 +286,19 @@ public:
void SaveVectors (void);
void RestoreVectors (void);
void SetSize (Bit16u size) { sSave(sPSP,next_seg,size); };
Bit16u GetSize (void) { return (Bit16u)sGet(sPSP,next_seg); };
void SetEnvironment (Bit16u envseg) { sSave(sPSP,environment,envseg); };
Bit16u GetEnvironment (void) { return (Bit16u)sGet(sPSP,environment); };
void SetSize (Bit16u size) { SaveIt(2,0x02,size); /*sSave(sPSP,next_seg,size);*/ };
Bit16u GetSize (void) { return (Bit16u)GetIt(2,0x02); /*sGet(sPSP,next_seg);*/ };
void SetEnvironment (Bit16u envseg) { SaveIt(2,0x2c,envseg);/*sSave(sPSP,environment,envseg);*/ };
Bit16u GetEnvironment (void) { return (Bit16u)GetIt(2,0x2c);/*return (Bit16u)sGet(sPSP,environment);*/ };
Bit16u GetSegment (void) { return seg; };
void SetFileHandle (Bit16u index, Bit8u handle);
Bit8u GetFileHandle (Bit16u index);
void SetParent (Bit16u parent) { sSave(sPSP,psp_parent,parent); };
Bit16u GetParent (void) { return (Bit16u)sGet(sPSP,psp_parent); };
void SetStack (RealPt stackpt) { sSave(sPSP,stack,stackpt); };
RealPt GetStack (void) { return sGet(sPSP,stack); };
void SetInt22 (RealPt int22pt) { sSave(sPSP,int_22,int22pt); };
RealPt GetInt22 (void) { return sGet(sPSP,int_22); };
void SetParent (Bit16u parent) { SaveIt(2,0x16,parent); /*sSave(sPSP,psp_parent,parent);*/ };
Bit16u GetParent (void) { return (Bit16u)GetIt(2,0x16);/*sGet(sPSP,psp_parent);*/ };
void SetStack (RealPt stackpt) { SaveIt(4,0x2e,stackpt); /*sSave(sPSP,stack,stackpt);*/ };
RealPt GetStack (void) { return GetIt(4,0x2e);/*sGet(sPSP,stack);*/ };
void SetInt22 (RealPt int22pt) { SaveIt(4,0x0A,int22pt);/*sSave(sPSP,int_22,int22pt);*/ };
RealPt GetInt22 (void) { return GetIt(4,0x0A); /*sGet(sPSP,int_22);*/ };
void SetFCB1 (RealPt src);
void SetFCB2 (RealPt src);
void SetCommandTail (RealPt src);

View File

@ -25,7 +25,6 @@
#include "dos_inc.h"
#include "support.h"
void DOS_ParamBlock::Clear(void) {
memset(&exec,0,sizeof(exec));
memset(&overlay,0,sizeof(overlay));
@ -176,32 +175,45 @@ void DOS_PSP::MakeNew(Bit16u mem_size) {
// DOS_PSP prevpsp(dos.psp());
/* Clear it first */
Bitu i;
for (i=0;i<sizeof(sPSP);i++) mem_writeb(pt+i,0);
for (i=0;i<0x100;i++) mem_writeb(pt+i,0);
// Set size
sSave(sPSP,next_seg,seg+mem_size);
SaveIt(2,0x02,seg+mem_size);
//sSave(sPSP,next_seg,seg+mem_size);
/* far call opcode */
sSave(sPSP,far_call,0xea);
SaveIt(1,0x05,0xea);
//sSave(sPSP,far_call,0xea);
// far call to interrupt 0x21 - faked for bill & ted
// lets hope nobody really uses this address
sSave(sPSP,cpm_entry,RealMake(0xDEAD,0xFFFF));
SaveIt(4,0x06,RealMake(0xDEAD,0xFFFF));
//sSave(sPSP,cpm_entry,RealMake(0xDEAD,0xFFFF));
/* Standard blocks,int 20 and int21 retf */
sSave(sPSP,exit[0],0xcd);
sSave(sPSP,exit[1],0x20);
sSave(sPSP,service[0],0xcd);
sSave(sPSP,service[1],0x21);
sSave(sPSP,service[2],0xcb);
SaveIt(1,0x00,0xcd); // INT...
//sSave(sPSP,exit[0],0xcd);
SaveIt(1,0x01,0x20); // ...20H
//sSave(sPSP,exit[1],0x20);
SaveIt(1,0x50,0xcd); // INT
SaveIt(1,0x51,0x21); // ...21H
SaveIt(1,0x52,0xcb); // RETF
//sSave(sPSP,service[0],0xcd);
//sSave(sPSP,service[1],0x21);
//sSave(sPSP,service[2],0xcb);
/* psp and psp-parent */
sSave(sPSP,psp_parent,dos.psp());
sSave(sPSP,prev_psp,0xffffffff);
sSave(sPSP,dos_version,0x0005);
SaveIt(2,0x16,dos.psp());
SaveIt(4,0x38,0xffffffff);
SaveIt(2,0x40,0x0005);
//sSave(sPSP,psp_parent,dos.psp());
//sSave(sPSP,prev_psp,0xffffffff);
//sSave(sPSP,dos_version,0x0005);
/* terminate 22,break 23,crititcal error 24 address stored */
SaveVectors();
/* FCBs are filled with 0 */
// ....
/* Init file pointer and max_files */
sSave(sPSP,file_table,RealMake(seg,offsetof(sPSP,files)));
sSave(sPSP,max_files,20);
SaveIt(4,0x34,RealMake(seg,offsetof(sPSP,files)));
//sSave(sPSP,file_table,RealMake(seg,offsetof(sPSP,files)));
SaveIt(2,0x32,20);
//sSave(sPSP,max_files,20);
for (i=0;i<20;i++) SetFileHandle(i,0xff);
/* User Stack pointer */
@ -211,29 +223,35 @@ void DOS_PSP::MakeNew(Bit16u mem_size) {
}
Bit8u DOS_PSP::GetFileHandle(Bit16u index) {
if (index>=sGet(sPSP,max_files)) return 0xff;
PhysPt files=Real2Phys(sGet(sPSP,file_table));
if (index>=GetIt(2,0x32)) return 0xff;
PhysPt files=Real2Phys(GetIt(4,0x34));
/*if (index>=sGet(sPSP,max_files)) return 0xff;
PhysPt files=Real2Phys(sGet(sPSP,file_table));*/
return mem_readb(files+index);
}
void DOS_PSP::SetFileHandle(Bit16u index, Bit8u handle) {
if (index<sGet(sPSP,max_files)) {
PhysPt files=Real2Phys(sGet(sPSP,file_table));
if (index<GetIt(2,0x32)) {
PhysPt files=Real2Phys(GetIt(4,0x34));
mem_writeb(files+index,handle);
}
/*if (index<sGet(sPSP,max_files)) {
PhysPt files=Real2Phys(sGet(sPSP,file_table));
mem_writeb(files+index,handle);
}*/
}
Bit16u DOS_PSP::FindFreeFileEntry(void) {
PhysPt files=Real2Phys(sGet(sPSP,file_table));
for (Bit16u i=0;i<sGet(sPSP,max_files);i++) {
PhysPt files=Real2Phys(GetIt(4,0x34));
for (Bit16u i=0;i<GetIt(2,0x32);i++) {
if (mem_readb(files+i)==0xff) return i;
}
return 0xff;
}
Bit16u DOS_PSP::FindEntryByHandle(Bit8u handle) {
PhysPt files=Real2Phys(sGet(sPSP,file_table));
for (Bit16u i=0;i<sGet(sPSP,max_files);i++) {
PhysPt files=Real2Phys(GetIt(4,0x34));
for (Bit16u i=0;i<GetIt(2,0x32);i++) {
if (mem_readb(files+i)==handle) return i;
}
return 0xFF;
@ -264,40 +282,47 @@ void DOS_PSP::CopyFileTable(DOS_PSP* srcpsp,bool createchildpsp) {
}
void DOS_PSP::CloseFiles(void) {
for (Bit16u i=0;i<sGet(sPSP,max_files);i++) {
for (Bit16u i=0;i<GetIt(2,0x32);i++) {
DOS_CloseFile(i);
}
}
void DOS_PSP::SaveVectors(void) {
/* Save interrupt 22,23,24 */
sSave(sPSP,int_22,RealGetVec(0x22));
sSave(sPSP,int_23,RealGetVec(0x23));
sSave(sPSP,int_24,RealGetVec(0x24));
SaveIt(4,0x0A,RealGetVec(0x22));
SaveIt(4,0x0E,RealGetVec(0x23));
SaveIt(4,0x12,RealGetVec(0x24));
//sSave(sPSP,int_22,RealGetVec(0x22));
//sSave(sPSP,int_23,RealGetVec(0x23));
//sSave(sPSP,int_24,RealGetVec(0x24));
}
void DOS_PSP::RestoreVectors(void) {
/* Restore interrupt 22,23,24 */
RealSetVec(0x22,sGet(sPSP,int_22));
RealSetVec(0x23,sGet(sPSP,int_23));
RealSetVec(0x24,sGet(sPSP,int_24));
RealSetVec(0x22,GetIt(4,0x0A));
RealSetVec(0x23,GetIt(4,0x0E));
RealSetVec(0x24,GetIt(4,0x12));
//RealSetVec(0x22,sGet(sPSP,int_22));
//RealSetVec(0x23,sGet(sPSP,int_23));
//RealSetVec(0x24,sGet(sPSP,int_24));
}
void DOS_PSP::SetCommandTail(RealPt src) {
if (src) { // valid source
MEM_BlockCopy(pt+offsetof(sPSP,cmdtail),Real2Phys(src),128);
MEM_BlockCopy(pt+128,Real2Phys(src),128);
} else { // empty
sSave(sPSP,cmdtail.count,0x00);
mem_writeb(pt+offsetof(sPSP,cmdtail.buffer),0x0d);
SaveIt(1,128,0);
mem_writeb(pt+129,0x0d);
};
}
void DOS_PSP::SetFCB1(RealPt src) {
if (src) MEM_BlockCopy(PhysMake(seg,offsetof(sPSP,fcb1)),Real2Phys(src),16);
if (src) MEM_BlockCopy(PhysMake(seg,0x5c),Real2Phys(src),16);
}
void DOS_PSP::SetFCB2(RealPt src) {
if (src) MEM_BlockCopy(PhysMake(seg,offsetof(sPSP,fcb2)),Real2Phys(src),16);
if (src) MEM_BlockCopy(PhysMake(seg,0x6c),Real2Phys(src),16);
}
bool DOS_PSP::SetNumFiles(Bit16u fileNum) {
@ -306,13 +331,16 @@ bool DOS_PSP::SetNumFiles(Bit16u fileNum) {
fileNum+=2; // Add a few more files for safety
Bit16u para = (fileNum/16)+((fileNum%16)>0);
RealPt data = RealMake(DOS_GetMemory(para),0);
sSave(sPSP,file_table,data);
sSave(sPSP,max_files,fileNum);
SaveIt(4,0x34,data);
//sSave(sPSP,file_table,data);
SaveIt(2,0x32,fileNum);
//sSave(sPSP,max_files,fileNum);
Bit16u i;
for (i=0; i<20; i++) SetFileHandle(i,sGet(sPSP,files[i]));
for (i=0; i<20; i++) SetFileHandle(i,GetIt(1,0x18+i*1)/*sGet(sPSP,files[i])*/);
for (i=20; i<fileNum; i++) SetFileHandle(i,0xFF);
} else {
sSave(sPSP,max_files,fileNum);
SaveIt(2,0x32,fileNum);
//sSave(sPSP,max_files,fileNum);
};
return true;
}

View File

@ -40,11 +40,7 @@ static Bit8u exe_block[]={
0xbc,0x00,0x04, //MOV SP,0x400 decrease stack size
0xbb,0x40,0x00, //MOV BX,0x040 for memory resize
0xb4,0x4a, //MOV AH,0x4A Resize memory block
#ifdef HW_RVL
0x90,0x90, // NOP, NOP... this prevents an invalid opcode crash in the core
#else
0xcd,0x21, //INT 0x21
#endif
//pos 12 is callback number
0xFE,0x38,0x00,0x00, //CALLBack number
0xb8,0x00,0x4c, //Mov ax,4c00