| 273 | } |
| 274 | |
| 275 | UINT YamlHelper::LoadMemory(MapYaml& mapYaml, const LPBYTE pMemBase, const size_t kAddrSpaceSize, const UINT offset) |
| 276 | { |
| 277 | UINT bytes = 0; |
| 278 | |
| 279 | for (MapYaml::iterator it = mapYaml.begin(); it != mapYaml.end(); ++it) |
| 280 | { |
| 281 | const char* pKey = it->first.c_str(); |
| 282 | UINT addr = strtoul(pKey, NULL, 16); |
| 283 | if (addr >= (kAddrSpaceSize + offset)) |
| 284 | throw std::runtime_error("Memory: line address too big: " + it->first); |
| 285 | |
| 286 | LPBYTE pDst = (LPBYTE) (pMemBase + addr); |
| 287 | const LPBYTE pDstEnd = (LPBYTE) (pMemBase + kAddrSpaceSize + offset); |
| 288 | |
| 289 | if (it->second.subMap) |
| 290 | throw std::runtime_error("Memory: unexpected sub-map"); |
| 291 | |
| 292 | const char* pValue = it->second.value.c_str(); |
| 293 | size_t len = strlen(pValue); |
| 294 | if (len & 1) |
| 295 | throw std::runtime_error("Memory: hex data must be an even number of nibbles on line address: " + it->first); |
| 296 | |
| 297 | for (UINT i = 0; i<len; i+=2) |
| 298 | { |
| 299 | if (pDst >= pDstEnd) |
| 300 | throw std::runtime_error("Memory: hex data overflowed address space on line address: " + it->first); |
| 301 | |
| 302 | BYTE ah = m_AsciiToHex[ (BYTE)(*pValue++) ]; |
| 303 | BYTE al = m_AsciiToHex[ (BYTE)(*pValue++) ]; |
| 304 | if ((ah | al) & 0x80) |
| 305 | throw std::runtime_error("Memory: hex data contains illegal character on line address: " + it->first); |
| 306 | |
| 307 | *pDst++ = (ah<<4) | al; |
| 308 | bytes++; |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | mapYaml.clear(); |
| 313 | |
| 314 | return bytes; |
| 315 | } |
| 316 | |
| 317 | //------------------------------------- |
| 318 |
no test coverage detected