mirror of
https://github.com/dingusdev/dingusppc.git
synced 2024-12-22 15:29:58 +00:00
64fec88436
Use explicit cast when converting large integer types to smaller integer types when it is known that the most significant bytes are not required. For pcidevice, check the ROM file size before casting to int. We'll allow expansion ROM sizes up to 4MB but usually they are 64K, sometimes 128K, rarely 256K. for machinefactory, change the type to size_t so that it can correctly get the size of files that are larger than 4GB; it already checks the file size is 4MB before we need to cast to uint32_t. For floppyimg, check the image size before casting to int. For raw images, only allow files up to 2MB. For DiskCopy42 images, it already checks the file size, so do the cast after that.
50 lines
1.6 KiB
C
50 lines
1.6 KiB
C
/*
|
|
DingusPPC - The Experimental PowerPC Macintosh emulator
|
|
Copyright (C) 2018-22 divingkatae and maximum
|
|
(theweirdo) spatium
|
|
|
|
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef MATH_UTILS_H
|
|
#define MATH_UTILS_H
|
|
|
|
inline void _u32xu64(uint32_t a, uint64_t b, uint32_t &hi, uint64_t &lo)
|
|
{
|
|
uint64_t p0 = (b & 0xffffffff) * a;
|
|
uint64_t p1 = (b >> 32) * a;
|
|
lo = p0 + (p1 << 32);
|
|
hi = (p1 >> 32) + (lo < p0);
|
|
}
|
|
|
|
inline void _u32xu64(uint32_t a, uint64_t b, uint64_t &hi, uint32_t &lo)
|
|
{
|
|
uint64_t p0 = (b & 0xffffffff) * a;
|
|
uint64_t p1 = (b >> 32) * a;
|
|
lo = (uint32_t)p0;
|
|
hi = (p0 >> 32) + p1;
|
|
}
|
|
|
|
inline void _u64xu64(uint64_t a, uint64_t b, uint64_t &hi, uint64_t &lo)
|
|
{
|
|
uint32_t p0h; uint64_t p0l; _u32xu64((uint32_t)b, a, p0h, p0l);
|
|
uint64_t p1h; uint32_t p1l; _u32xu64(b >> 32, a, p1h, p1l);
|
|
lo = p0l + ((uint64_t)p1l << 32);
|
|
hi = p0h + p1h + (lo < p0l);
|
|
}
|
|
|
|
#endif // MATH_UTILS_H
|