Skip to content

Commit

Permalink
Merge pull request #4330 from maron2000/dayweek_fix
Browse files Browse the repository at this point in the history
Fix day of week detection (INT 21h 0x2Ah)
  • Loading branch information
joncampbell123 authored Jul 17, 2023
2 parents b717bbb + 38ef514 commit ad58da4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Next
allocated block position. (maxpat78)
- Enhanced Dynamic and Differencing VHD support #4273 (maxpat78)
- Imported IBM Music Feature Card support from DOSBox Staging. (Allofich)
- Fix day of week detection (INT 21h 0x2Ah). (maron2000)
- Refine KEYB and CHCP command (maron2000)
2023.05.01
- IMGMAKE will choose LBA partition types for 2GB or larger disk
Expand Down
14 changes: 10 additions & 4 deletions src/dos/dos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1498,10 +1498,16 @@ static Bitu DOS_21Handler(void) {
reg_dl = dos.date.day;

// calculate day of week (we could of course read it from CMOS, but never mind)
unsigned int a = (14u - reg_dh) / 12u;
unsigned int y = reg_cl - a;
unsigned int m = reg_dh + 12u * a - 2u;
reg_al = (reg_dl + y + (y / 4u) - (y / 100u) + (y / 400u) + (31u * m) / 12u) % 7u;
/* Use Zeller's congruence */
uint16_t year = reg_cx, month = reg_dh, day = reg_dl;
int8_t weekday;
if(month <= 2) {
year--;
month += 12;
}
weekday = (year + year / 4u - year / 100u + year / 400u + (13u * month + 8u) / 5u + day) % 7;
reg_al = weekday < 0 ? weekday + 7 : weekday;
/* Sunday=0, Monday=1, ... */
}
break;
case 0x2b: /* Set System Date */
Expand Down

0 comments on commit ad58da4

Please sign in to comment.