Skip to content

Commit

Permalink
core: Fix narrowing
Browse files Browse the repository at this point in the history
  • Loading branch information
carmiker committed Mar 5, 2025
1 parent 9e6bded commit 3da55ff
Show file tree
Hide file tree
Showing 67 changed files with 410 additions and 399 deletions.
142 changes: 71 additions & 71 deletions source/core/NstApu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,10 @@ namespace Nes

const byte data[4] =
{
ctrl,
clock & 0xFF,
clock >> 8,
cycles.frameDivider
static_cast<byte>(ctrl),
static_cast<byte>(clock & 0xFF),
static_cast<byte>(clock >> 8),
static_cast<byte>(cycles.frameDivider)
};

state.Begin( AsciiId<'F','R','M'>::V ).Write( data ).End();
Expand All @@ -494,9 +494,9 @@ namespace Nes

const byte data[3] =
{
clock & 0xFF,
clock >> 8,
cycles.frameIrqRepeat % 3
static_cast<byte>(clock & 0xFF),
static_cast<byte>(clock >> 8),
static_cast<byte>(cycles.frameIrqRepeat % 3)
};

state.Begin( AsciiId<'I','R','Q'>::V ).Write( data ).End();
Expand Down Expand Up @@ -532,10 +532,10 @@ namespace Nes
{
const byte data[4] =
{
cycles.rateCounter & 0xFFU,
cycles.rateCounter >> 8,
cycles.rateCounter >> 16,
cycles.rateCounter >> 24,
static_cast<byte>(cycles.rateCounter & 0xFFU),
static_cast<byte>(cycles.rateCounter >> 8),
static_cast<byte>(cycles.rateCounter >> 16),
static_cast<byte>(cycles.rateCounter >> 24),
};

state.Begin( AsciiId<'S','0','0'>::V ).Write( data ).End();
Expand Down Expand Up @@ -1065,7 +1065,7 @@ namespace Nes
const byte data[3] =
{
count,
regs[0] | (reset ? 0x80U : 0x00U),
static_cast<byte>(regs[0] | (reset ? 0x80U : 0x00U)),
regs[1]
};

Expand Down Expand Up @@ -1158,18 +1158,18 @@ namespace Nes
{
const byte data[12] =
{
acc & 0xFFU,
acc >> 8,
acc >> 16,
acc >> 24,
prev & 0xFFU,
prev >> 8,
prev >> 16,
prev >> 24,
next & 0xFFU,
next >> 8,
next >> 16,
next >> 24,
static_cast<byte>(acc & 0xFFU),
static_cast<byte>(acc >> 8),
static_cast<byte>(acc >> 16),
static_cast<byte>(acc >> 24),
static_cast<byte>(prev & 0xFFU),
static_cast<byte>(prev >> 8),
static_cast<byte>(prev >> 16),
static_cast<byte>(prev >> 24),
static_cast<byte>(next & 0xFFU),
static_cast<byte>(next >> 8),
static_cast<byte>(next >> 16),
static_cast<byte>(next >> 24),
};

state.Begin( AsciiId<'S','0','0'>::V ).Write( data ).End();
Expand Down Expand Up @@ -1380,19 +1380,19 @@ namespace Nes
{
const byte data[13] =
{
step,
timer & 0xFFU,
timer >> 8,
timer >> 16,
timer >> 24,
frequency & 0xFFU,
frequency >> 8,
frequency >> 16,
frequency >> 24,
amp & 0xFFU,
amp >> 8,
amp >> 16,
amp >> 24,
static_cast<byte>(step),
static_cast<byte>(timer & 0xFFU),
static_cast<byte>(timer >> 8),
static_cast<byte>(timer >> 16),
static_cast<byte>(timer >> 24),
static_cast<byte>(frequency & 0xFFU),
static_cast<byte>(frequency >> 8),
static_cast<byte>(frequency >> 16),
static_cast<byte>(frequency >> 24),
static_cast<byte>(amp & 0xFFU),
static_cast<byte>(amp >> 8),
static_cast<byte>(amp >> 16),
static_cast<byte>(amp >> 24),
};

state.Begin( AsciiId<'S','0','0'>::V ).Write( data ).End();
Expand Down Expand Up @@ -1682,10 +1682,10 @@ namespace Nes
{
const byte data[4] =
{
waveLength & 0xFFU,
waveLength >> 8,
linearCounter | (uint(status) << 7),
linearCtrl
static_cast<byte>(waveLength & 0xFFU),
static_cast<byte>(waveLength >> 8),
static_cast<byte>(linearCounter | (uint(status) << 7)),
static_cast<byte>(linearCtrl)
};

state.Begin( AsciiId<'R','E','G'>::V ).Write( data ).End();
Expand All @@ -1696,15 +1696,15 @@ namespace Nes
{
const byte data[9] =
{
step,
timer & 0xFFU,
timer >> 8,
timer >> 16,
timer >> 24,
amp & 0xFFU,
amp >> 8,
amp >> 16,
amp >> 24,
static_cast<byte>(step),
static_cast<byte>(timer & 0xFFU),
static_cast<byte>(timer >> 8),
static_cast<byte>(timer >> 16),
static_cast<byte>(timer >> 24),
static_cast<byte>(amp & 0xFFU),
static_cast<byte>(amp >> 8),
static_cast<byte>(amp >> 16),
static_cast<byte>(amp >> 24),
};

state.Begin( AsciiId<'S','0','0'>::V ).Write( data ).End();
Expand Down Expand Up @@ -1925,12 +1925,12 @@ namespace Nes
{
const byte data[6] =
{
bits & 0xFFU,
bits >> 8,
timer & 0xFFU,
timer >> 8,
timer >> 16,
timer >> 24
static_cast<byte>(bits & 0xFFU),
static_cast<byte>(bits >> 8),
static_cast<byte>(timer & 0xFFU),
static_cast<byte>(timer >> 8),
static_cast<byte>(timer >> 16),
static_cast<byte>(timer >> 24)
};

state.Begin( AsciiId<'S','0','0'>::V ).Write( data ).End();
Expand Down Expand Up @@ -2147,21 +2147,21 @@ namespace Nes
{
const byte data[12] =
{
dmcClock & 0xFF,
dmcClock >> 8,
(
static_cast<byte>(dmcClock & 0xFF),
static_cast<byte>(dmcClock >> 8),
static_cast<byte>((
( ( regs.ctrl & REG0_FREQUENCY ) ) |
( ( regs.ctrl & REG0_LOOP ) ? 0x10U : 0U ) |
( ( regs.ctrl & REG0_IRQ_ENABLE ) ? 0x20U : 0U ) |
( ( dma.lengthCounter ) ? 0x40U : 0U )
),
(regs.address - 0xC000U) >> 6,
(regs.lengthCounter - 1U) >> 4,
(dma.address >> 0 & 0xFFU),
(dma.address >> 8 & 0x7FU) | (dma.buffered ? 0x80 : 0x00),
dma.lengthCounter ? (dma.lengthCounter - 1U) >> 4 : 0,
dma.buffer,
7 - out.shifter,
)),
static_cast<byte>((regs.address - 0xC000U) >> 6),
static_cast<byte>((regs.lengthCounter - 1U) >> 4),
static_cast<byte>((dma.address >> 0 & 0xFFU)),
static_cast<byte>((dma.address >> 8 & 0x7FU) | (dma.buffered ? 0x80 : 0x00)),
static_cast<byte>(dma.lengthCounter ? (dma.lengthCounter - 1U) >> 4 : 0),
static_cast<byte>(dma.buffer),
static_cast<byte>(7 - out.shifter),
out.buffer,
out.dac,
};
Expand All @@ -2172,10 +2172,10 @@ namespace Nes
{
const byte data[4] =
{
linSample & 0xFFU,
linSample >> 8,
dma.lengthCounter & 0xFFU,
dma.lengthCounter >> 8,
static_cast<byte>(linSample & 0xFFU),
static_cast<byte>(linSample >> 8),
static_cast<byte>(dma.lengthCounter & 0xFFU),
static_cast<byte>(dma.lengthCounter >> 8),
};

state.Begin( AsciiId<'S','0','0'>::V ).Write( data ).End();
Expand Down
8 changes: 4 additions & 4 deletions source/core/NstCartridgeUnif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -738,10 +738,10 @@ namespace Nes
{
const byte bytes[] =
{
id >> 0 & 0xFF,
id >> 8 & 0xFF,
id >> 16 & 0xFF,
id >> 24 & 0xFF,
static_cast<byte>(id >> 0 & 0xFF),
static_cast<byte>(id >> 8 & 0xFF),
static_cast<byte>(id >> 16 & 0xFF),
static_cast<byte>(id >> 24 & 0xFF),
0
};

Expand Down
34 changes: 17 additions & 17 deletions source/core/NstCpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,13 +343,13 @@ namespace Nes
{
const byte data[7] =
{
pc & 0xFF,
pc >> 8,
sp,
a,
x,
y,
flags.Pack()
static_cast<byte>(pc & 0xFF),
static_cast<byte>(pc >> 8),
static_cast<byte>(sp),
static_cast<byte>(a),
static_cast<byte>(x),
static_cast<byte>(y),
static_cast<byte>(flags.Pack())
};

state.Begin( AsciiId<'R','E','G'>::V ).Write( data ).End();
Expand All @@ -360,16 +360,16 @@ namespace Nes
{
const byte data[5] =
{
((interrupt.nmiClock != CYCLE_MAX) ? 0x01U : 0x00U) |
((interrupt.low & IRQ_FRAME) ? 0x02U : 0x00U) |
((interrupt.low & IRQ_DMC) ? 0x04U : 0x00U) |
((interrupt.low & IRQ_EXT) ? 0x08U : 0x00U) |
(jammed ? 0x40U : 0x00U) |
(model == CPU_RP2A07 ? 0x80U : model == CPU_DENDY ? 0x20U : 0x00U),
cycles.count & 0xFF,
cycles.count >> 8,
(interrupt.nmiClock != CYCLE_MAX) ? interrupt.nmiClock+1 : 0,
(interrupt.irqClock != CYCLE_MAX) ? interrupt.irqClock+1 : 0
static_cast<byte>(((interrupt.nmiClock != CYCLE_MAX) ? 0x01U : 0x00U) |
((interrupt.low & IRQ_FRAME) ? 0x02U : 0x00U) |
((interrupt.low & IRQ_DMC) ? 0x04U : 0x00U) |
((interrupt.low & IRQ_EXT) ? 0x08U : 0x00U) |
(jammed ? 0x40U : 0x00U) |
(model == CPU_RP2A07 ? 0x80U : model == CPU_DENDY ? 0x20U : 0x00U)),
static_cast<byte>(cycles.count & 0xFF),
static_cast<byte>(cycles.count >> 8),
static_cast<byte>((interrupt.nmiClock != CYCLE_MAX) ? interrupt.nmiClock+1 : 0),
static_cast<byte>((interrupt.irqClock != CYCLE_MAX) ? interrupt.irqClock+1 : 0)
};

state.Begin( AsciiId<'F','R','M'>::V ).Write( data ).End();
Expand Down
60 changes: 30 additions & 30 deletions source/core/NstFds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,10 +487,10 @@ namespace Nes
{
const byte data[4] =
{
disks.sides.count,
(disks.current != Disks::EJECTED) | (disks.writeProtected ? 0x2U : 0x0U),
disks.current != Disks::EJECTED ? disks.current : 0xFF,
disks.current != Disks::EJECTED ? disks.mounting : 0
static_cast<byte>(disks.sides.count),
static_cast<byte>((disks.current != Disks::EJECTED) | (disks.writeProtected ? 0x2U : 0x0U)),
static_cast<byte>(disks.current != Disks::EJECTED ? disks.current : 0xFF),
static_cast<byte>(disks.current != Disks::EJECTED ? disks.mounting : 0)
};

state.Begin( AsciiId<'D','S','K'>::V ).Write( data ).End();
Expand Down Expand Up @@ -1255,12 +1255,12 @@ namespace Nes
{
const byte data[7] =
{
unit.timer.ctrl,
unit.status,
unit.timer.latch & 0xFFU,
unit.timer.latch >> 8,
unit.timer.count & 0xFFU,
unit.timer.count >> 8,
static_cast<byte>(unit.timer.ctrl),
static_cast<byte>(unit.status),
static_cast<byte>(unit.timer.latch & 0xFFU),
static_cast<byte>(unit.timer.latch >> 8),
static_cast<byte>(unit.timer.count & 0xFFU),
static_cast<byte>(unit.timer.count >> 8),
0
};

Expand All @@ -1274,20 +1274,20 @@ namespace Nes
{
unit.drive.ctrl,
unit.drive.status,
unit.drive.in & 0xFFU,
static_cast<byte>(unit.drive.in & 0xFFU),
unit.drive.out,
unit.drive.count ? headPos & 0xFF : 0,
unit.drive.count ? headPos >> 8 : 0,
unit.drive.count ? unit.drive.dataPos & 0xFFU : 0,
unit.drive.count ? unit.drive.dataPos >> 8 : 0,
unit.drive.count ? unit.drive.gap & 0xFFU : 0,
unit.drive.count ? unit.drive.gap >> 8 : 0,
unit.drive.count ? unit.drive.length & 0xFFU : 0,
unit.drive.count ? unit.drive.length >> 8 : 0,
unit.drive.count >> 0 & 0xFF,
unit.drive.count >> 8 & 0xFF,
unit.drive.count >> 16,
unit.drive.in >> 8
static_cast<byte>(unit.drive.count ? headPos & 0xFF : 0),
static_cast<byte>(unit.drive.count ? headPos >> 8 : 0),
static_cast<byte>(unit.drive.count ? unit.drive.dataPos & 0xFFU : 0),
static_cast<byte>(unit.drive.count ? unit.drive.dataPos >> 8 : 0),
static_cast<byte>(unit.drive.count ? unit.drive.gap & 0xFFU : 0),
static_cast<byte>(unit.drive.count ? unit.drive.gap >> 8 : 0),
static_cast<byte>(unit.drive.count ? unit.drive.length & 0xFFU : 0),
static_cast<byte>(unit.drive.count ? unit.drive.length >> 8 : 0),
static_cast<byte>(unit.drive.count >> 0 & 0xFF),
static_cast<byte>(unit.drive.count >> 8 & 0xFF),
static_cast<byte>(unit.drive.count >> 16),
static_cast<byte>(unit.drive.in >> 8)
};

state.Begin( AsciiId<'D','R','V'>::V ).Write( data ).End();
Expand Down Expand Up @@ -1695,11 +1695,11 @@ namespace Nes
{
byte data[6] =
{
((status & STATUS_OUTPUT_ENABLED) ? 0U : uint(REG3_OUTPUT_DISABLE)) |
((status & STATUS_ENVELOPES_ENABLED) ? 0U : uint(REG3_ENVELOPE_DISABLE)),
wave.writing ? REG9_WRITE_MODE : 0,
wave.length & 0xFFU,
wave.length >> 8,
static_cast<byte>(((status & STATUS_OUTPUT_ENABLED) ? 0U : uint(REG3_OUTPUT_DISABLE)) |
((status & STATUS_ENVELOPES_ENABLED) ? 0U : uint(REG3_ENVELOPE_DISABLE))),
static_cast<byte>(wave.writing ? REG9_WRITE_MODE : 0),
static_cast<byte>(wave.length & 0xFFU),
static_cast<byte>(wave.length >> 8),
envelopes.length,
envelopes.counter
};
Expand Down Expand Up @@ -1729,8 +1729,8 @@ namespace Nes
{
const byte data[4] =
{
modulator.length & 0xFF,
modulator.length >> 8 | (modulator.writing ? REG7_MOD_WRITE_MODE : 0),
static_cast<byte>(modulator.length & 0xFF),
static_cast<byte>(modulator.length >> 8 | (modulator.writing ? REG7_MOD_WRITE_MODE : 0)),
modulator.sweep,
modulator.pos
};
Expand Down
Loading

0 comments on commit 3da55ff

Please sign in to comment.