Skip to content

Commit 538edbb

Browse files
committed
Fix some bitshift related bugs
1 parent b3773a6 commit 538edbb

39 files changed

+193
-193
lines changed

include/paging.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ class PageDirectory;
5454
#define PFLAG_HASCODE16 0x40 //Page contains 16-bit dynamic code
5555
#define PFLAG_HASCODE (PFLAG_HASCODE32|PFLAG_HASCODE16)
5656

57-
#define LINK_START ((1024+64)>>2) //Start right after the HMA
57+
#define LINK_START ((1024+64)/4) //Start right after the HMA
5858

5959
//Allow 128 mb of memory to be linked
60-
#define PAGING_LINKS (128*1024>>2)
60+
#define PAGING_LINKS (128*1024/4)
6161

6262
class PageHandler {
6363
public:

src/cpu/core_normal.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ static INLINE Bit32u Fetchd() {
141141
Bits CPU_Core_Normal_Run(void) {
142142
while (CPU_Cycles-->0) {
143143
LOADIP;
144-
core.opcode_index=cpu.code.big*0x200;
144+
core.opcode_index=cpu.code.big<<9;
145145
core.prefixes=cpu.code.big;
146-
core.ea_table=&EATable[cpu.code.big*256];
146+
core.ea_table=&EATable[cpu.code.big<<8];
147147
BaseDS=SegBase(ds);
148148
BaseSS=SegBase(ss);
149149
core.base_val_ds=ds;

src/cpu/core_prefetch.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,9 @@ Bits CPU_Core_Prefetch_Run(void) {
216216
invalidate_pq=false;
217217
}
218218
LOADIP;
219-
core.opcode_index=cpu.code.big*0x200;
219+
core.opcode_index=cpu.code.big<<9;
220220
core.prefixes=cpu.code.big;
221-
core.ea_table=&EATable[cpu.code.big*256];
221+
core.ea_table=&EATable[cpu.code.big<<8];
222222
BaseDS=SegBase(ds);
223223
BaseSS=SegBase(ss);
224224
core.base_val_ds=ds;

src/cpu/core_simple.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ static INLINE Bit32u Fetchd() {
137137
Bits CPU_Core_Simple_Run(void) {
138138
while (CPU_Cycles-->0) {
139139
LOADIP;
140-
core.opcode_index=cpu.code.big*0x200;
140+
core.opcode_index=cpu.code.big<<9;
141141
core.prefixes=cpu.code.big;
142-
core.ea_table=&EATable[cpu.code.big*256];
142+
core.ea_table=&EATable[cpu.code.big<<8];
143143
BaseDS=SegBase(ds);
144144
BaseSS=SegBase(ss);
145145
core.base_val_ds=ds;

src/cpu/paging.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ static INLINE void InitPageCheckPresence(PhysPt lin_addr,bool writing,X86PageEnt
181181
Bitu lin_page=lin_addr >> 12;
182182
Bitu d_index=lin_page >> 10;
183183
Bitu t_index=lin_page & 0x3ff;
184-
Bitu table_addr=(paging.base.page<<12)+(d_index<<2);
184+
Bitu table_addr=(paging.base.page<<12)+d_index*4;
185185
table.load=phys_readd(table_addr);
186186
if (!table.block.p) {
187187
LOG(LOG_PAGING,LOG_NORMAL)("NP Table");
@@ -191,7 +191,7 @@ static INLINE void InitPageCheckPresence(PhysPt lin_addr,bool writing,X86PageEnt
191191
if (GCC_UNLIKELY(!table.block.p))
192192
E_Exit("Pagefault didn't correct table");
193193
}
194-
Bitu entry_addr=(table.block.base<<12)+(t_index<<2);
194+
Bitu entry_addr=(table.block.base<<12)+t_index*4;
195195
entry.load=phys_readd(entry_addr);
196196
if (!entry.block.p) {
197197
// LOG(LOG_PAGING,LOG_NORMAL)("NP Page");
@@ -207,15 +207,15 @@ static INLINE bool InitPageCheckPresence_CheckOnly(PhysPt lin_addr,bool writing,
207207
Bitu lin_page=lin_addr >> 12;
208208
Bitu d_index=lin_page >> 10;
209209
Bitu t_index=lin_page & 0x3ff;
210-
Bitu table_addr=(paging.base.page<<12)+(d_index<<2);
210+
Bitu table_addr=(paging.base.page<<12)+d_index*4;
211211
table.load=phys_readd(table_addr);
212212
if (!table.block.p) {
213213
paging.cr2=lin_addr;
214214
cpu.exception.which=EXCEPTION_PF;
215215
cpu.exception.error=(writing?0x02:0x00) | (((cpu.cpl&cpu.mpl)==0)?0x00:0x04);
216216
return false;
217217
}
218-
Bitu entry_addr=(table.block.base<<12)+(t_index<<2);
218+
Bitu entry_addr=(table.block.base<<12)+t_index*4;
219219
entry.load=phys_readd(entry_addr);
220220
if (!entry.block.p) {
221221
paging.cr2=lin_addr;
@@ -370,13 +370,13 @@ class InitPageHandler : public PageHandler {
370370
if (priv_check==3) {
371371
LOG(LOG_PAGING,LOG_NORMAL)("Page access denied: cpl=%i, %x:%x:%x:%x",
372372
cpu.cpl,entry.block.us,table.block.us,entry.block.wr,table.block.wr);
373-
PAGING_PageFault(lin_addr,(table.block.base<<12)+(lin_page & 0x3ff)<<2,0x05 | (writing?0x02:0x00));
373+
PAGING_PageFault(lin_addr,(table.block.base<<12)+(lin_page & 0x3ff)*4,0x05 | (writing?0x02:0x00));
374374
priv_check=0;
375375
}
376376

377377
if (!table.block.a) {
378378
table.block.a=1; // set page table accessed
379-
phys_writed((paging.base.page<<12)+(lin_page >> 10)<<2,table.load);
379+
phys_writed((paging.base.page<<12)+(lin_page >> 10)*4,table.load);
380380
}
381381
if ((!entry.block.a) || (!entry.block.d)) {
382382
entry.block.a=1; // set page accessed
@@ -385,7 +385,7 @@ class InitPageHandler : public PageHandler {
385385
// page will be fully linked so we can't track later writes
386386
if (writing || (priv_check==0)) entry.block.d=1; // mark page as dirty
387387

388-
phys_writed((table.block.base<<12)+(lin_page & 0x3ff)<<2,entry.load);
388+
phys_writed((table.block.base<<12)+(lin_page & 0x3ff)*4,entry.load);
389389
}
390390

391391
phys_page=entry.block.base;
@@ -455,11 +455,11 @@ class InitPageHandler : public PageHandler {
455455

456456
if (!table.block.a) {
457457
table.block.a=1; //Set access
458-
phys_writed((paging.base.page<<12)+((lin_page >> 10)<<2),table.load);
458+
phys_writed((paging.base.page<<12)+(lin_page >> 10)*4,table.load);
459459
}
460460
if (!entry.block.a) {
461461
entry.block.a=1; //Set access
462-
phys_writed((table.block.base<<12)+((lin_page & 0x3ff)<<2),entry.load);
462+
phys_writed((table.block.base<<12)+(lin_page & 0x3ff)*4,entry.load);
463463
}
464464
phys_page=entry.block.base;
465465
// maybe use read-only page here if possible
@@ -533,16 +533,16 @@ class InitPageUserROHandler : public PageHandler {
533533

534534
LOG(LOG_PAGING,LOG_NORMAL)("Page access denied: cpl=%i, %x:%x:%x:%x",
535535
cpu.cpl,entry.block.us,table.block.us,entry.block.wr,table.block.wr);
536-
PAGING_PageFault(lin_addr,(table.block.base<<12)+((lin_page & 0x3ff)<<2),0x07);
536+
PAGING_PageFault(lin_addr,(table.block.base<<12)+(lin_page & 0x3ff)*4,0x07);
537537

538538
if (!table.block.a) {
539539
table.block.a=1; //Set access
540-
phys_writed((paging.base.page<<12)+((lin_page >> 10)<<2),table.load);
540+
phys_writed((paging.base.page<<12)+(lin_page >> 10)*4,table.load);
541541
}
542542
if ((!entry.block.a) || (!entry.block.d)) {
543543
entry.block.a=1; //Set access
544544
entry.block.d=1; //Set dirty
545-
phys_writed((table.block.base<<12)+((lin_page & 0x3ff)<<2),entry.load);
545+
phys_writed((table.block.base<<12)+(lin_page & 0x3ff)*4,entry.load);
546546
}
547547
phys_page=entry.block.base;
548548
PAGING_LinkPage(lin_page,phys_page);
@@ -588,11 +588,11 @@ class InitPageUserROHandler : public PageHandler {
588588

589589
if (!table.block.a) {
590590
table.block.a=1; //Set access
591-
phys_writed((paging.base.page<<12)+((lin_page >> 10)<<2),table.load);
591+
phys_writed((paging.base.page<<12)+(lin_page >> 10)*4,table.load);
592592
}
593593
if (!entry.block.a) {
594594
entry.block.a=1; //Set access
595-
phys_writed((table.block.base<<12)+((lin_page & 0x3ff)<<2),entry.load);
595+
phys_writed((table.block.base<<12)+(lin_page & 0x3ff)*4,entry.load);
596596
}
597597
phys_page=entry.block.base;
598598
} else {
@@ -609,10 +609,10 @@ bool PAGING_MakePhysPage(Bitu & page) {
609609
Bitu d_index=page >> 10;
610610
Bitu t_index=page & 0x3ff;
611611
X86PageEntry table;
612-
table.load=phys_readd((paging.base.page<<12)+(d_index<<2));
612+
table.load=phys_readd((paging.base.page<<12)+d_index*4);
613613
if (!table.block.p) return false;
614614
X86PageEntry entry;
615-
entry.load=phys_readd((table.block.base<<12)+(t_index<<2));
615+
entry.load=phys_readd((table.block.base<<12)+t_index*4);
616616
if (!entry.block.p) return false;
617617
page=entry.block.base;
618618
} else {

src/dos/cdrom_aspi_win32.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ bool CDROM_Interface_Aspi::GetUPC(unsigned char& attr, char* upcdata)
604604
attr = 0;
605605
// Convert to mscdex format
606606
for (int i=0; i<7; i++) upcdata[i] = upc.MediaCatalog[i];
607-
for (int i=0; i<7; i++) upcdata[i] = (upc.MediaCatalog[i<<1] << 4) | (upc.MediaCatalog[(i<<1)+1] & 0x0F);
607+
for (int i=0; i<7; i++) upcdata[i] = (upc.MediaCatalog[i*2] << 4) | (upc.MediaCatalog[i*2+1] & 0x0F);
608608

609609
return true;
610610
};

src/dos/cdrom_image.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ void CDROM_Interface_Image::CDAudioCallBack(Bitu len)
345345
if (player.ctrlUsed) {
346346
Bit16s sample0,sample1;
347347
Bit16s * samples=(Bit16s *)&player.buffer;
348-
for (Bitu pos=0;pos<len>>2;pos++) {
348+
for (Bitu pos=0;pos<len/4;pos++) {
349349
#if defined(WORDS_BIGENDIAN)
350350
sample0=(Bit16s)host_readw((HostPt)&samples[pos*2+player.ctrlData.out[0]]);
351351
sample1=(Bit16s)host_readw((HostPt)&samples[pos*2+player.ctrlData.out[1]]);
@@ -357,11 +357,11 @@ void CDROM_Interface_Image::CDAudioCallBack(Bitu len)
357357
samples[pos*2+1]=(Bit16s)(sample1*player.ctrlData.vol[1]/255.0);
358358
}
359359
#if defined(WORDS_BIGENDIAN)
360-
player.channel->AddSamples_s16(len>>2,(Bit16s *)player.buffer);
361-
} else player.channel->AddSamples_s16_nonnative(len>>2,(Bit16s *)player.buffer);
360+
player.channel->AddSamples_s16(len/4,(Bit16s *)player.buffer);
361+
} else player.channel->AddSamples_s16_nonnative(len/4,(Bit16s *)player.buffer);
362362
#else
363363
}
364-
player.channel->AddSamples_s16(len>>2,(Bit16s *)player.buffer);
364+
player.channel->AddSamples_s16(len/4,(Bit16s *)player.buffer);
365365
#endif
366366
memmove(player.buffer, &player.buffer[len], player.bufLen - len);
367367
player.bufLen -= len;

src/dos/cdrom_ioctl_win32.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,14 +560,14 @@ void CDROM_Interface_Ioctl::dx_CDAudioCallBack(Bitu len) {
560560
if (player.ctrlUsed) {
561561
Bit16s sample0,sample1;
562562
Bit16s * samples=(Bit16s *)&player.buffer;
563-
for (Bitu pos=0;pos<len>>2;pos++) {
563+
for (Bitu pos=0;pos<len/4;pos++) {
564564
sample0=samples[pos*2+player.ctrlData.out[0]];
565565
sample1=samples[pos*2+player.ctrlData.out[1]];
566566
samples[pos*2+0]=(Bit16s)(sample0*player.ctrlData.vol[0]/255.0);
567567
samples[pos*2+1]=(Bit16s)(sample1*player.ctrlData.vol[1]/255.0);
568568
}
569569
}
570-
player.channel->AddSamples_s16(len>>2,(Bit16s *)player.buffer);
570+
player.channel->AddSamples_s16(len/4,(Bit16s *)player.buffer);
571571
memmove(player.buffer, &player.buffer[len], player.bufLen - len);
572572
player.bufLen -= len;
573573
}

src/dos/dos.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ static Bitu DOS_21Handler(void) {
426426
int a = (14 - dos.date.month)/12;
427427
int y = dos.date.year - a;
428428
int m = dos.date.month + 12*a - 2;
429-
reg_al=(dos.date.day+y+(y>>2)-(y/100)+(y/400)+(31*m)/12) % 7;
429+
reg_al=(dos.date.day+y+(y/4)-(y/100)+(y/400)+(31*m)/12) % 7;
430430
reg_cx=dos.date.year;
431431
reg_dh=dos.date.month;
432432
reg_dl=dos.date.day;
@@ -544,8 +544,8 @@ static Bitu DOS_21Handler(void) {
544544
reg_bx=DOS_SDA_OFS + 0x01;
545545
break;
546546
case 0x35: /* Get interrupt vector */
547-
reg_bx=real_readw(0,((Bit16u)reg_al)<<2);
548-
SegSet16(es,real_readw(0,(((Bit16u)reg_al)<<2)+2));
547+
reg_bx=real_readw(0,((Bit16u)reg_al)*4);
548+
SegSet16(es,real_readw(0,((Bit16u)reg_al)*4+2));
549549
break;
550550
case 0x36: /* Get Free Disk Space */
551551
{
@@ -1179,7 +1179,7 @@ static Bitu DOS_20Handler(void) {
11791179

11801180
static Bitu DOS_27Handler(void) {
11811181
// Terminate & stay resident
1182-
Bit16u para = (reg_dx>>4)+((reg_dx % 16)>0);
1182+
Bit16u para = (reg_dx/16)+((reg_dx % 16)>0);
11831183
Bit16u psp = dos.psp(); //mem_readw(SegPhys(ss)+reg_sp+2);
11841184
if (DOS_ResizeMemory(psp,&para)) DOS_Terminate(psp,true,0);
11851185
return CBRET_NONE;

src/dos/dos_classes.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void DOS_InfoBlock::SetLocation(Bit16u segment) {
7676

7777
sSave(sDIB,bootDrive,(Bit8u)0);
7878
sSave(sDIB,useDwordMov,(Bit8u)1);
79-
sSave(sDIB,extendedSize,(Bit16u)((MEM_TotalPages()<<2)-1024));
79+
sSave(sDIB,extendedSize,(Bit16u)(MEM_TotalPages()*4-1024));
8080
sSave(sDIB,magicWord,(Bit16u)0x0001); // dos5+
8181

8282
sSave(sDIB,sharingCount,(Bit16u)0);
@@ -405,7 +405,7 @@ bool DOS_PSP::SetNumFiles(Bit16u fileNum) {
405405
if (fileNum > 20 && ((fileNum+2) > sGet(sPSP,max_files))) {
406406
// Allocate needed paragraphs
407407
fileNum+=2; // Add a few more files for safety
408-
Bit16u para = (fileNum>>4)+((fileNum%16)>0);
408+
Bit16u para = (fileNum/16)+((fileNum%16)>0);
409409
RealPt data = RealMake(DOS_GetMemory(para),0);
410410
for (Bit16u i=0; i<fileNum; i++) mem_writeb(Real2Phys(data)+i,(i<20)?GetFileHandle(i):0xFF);
411411
#if defined(__3DS__)

0 commit comments

Comments
 (0)