Best JavaScript code snippet using unexpected
emulator.js
Source:emulator.js
...1065 }1066 else if (op === 0xA7) {1067 // AND A 1068 this.PC++;1069 return this.executeAnd(this.A);1070 }1071 else if (op === 0xA0) {1072 // AND B 1073 this.PC++;1074 return this.executeAnd(this.B);1075 }1076 else if (op === 0xA1) {1077 // AND C1078 this.PC++;1079 return this.executeAnd(this.C);1080 }1081 else if (op === 0xA2) {1082 // AND D1083 this.PC++;1084 return this.executeAnd(this.D);1085 }1086 else if (op === 0xA3) {1087 // AND E1088 this.PC++;1089 return this.executeAnd(this.E);1090 }1091 else if (op === 0xA4) {1092 // AND H1093 this.PC++;1094 return this.executeAnd(this.H());1095 }1096 else if (op === 0xA5) {1097 // AND L1098 this.PC++;1099 return this.executeAnd(this.L());1100 }1101 else if (op === 0xA6) {1102 // AND (HL)1103 this.PC++;1104 return this.executeAnd(this.bus.readByte(this.HL));1105 }1106 else if (op === 0x28) {1107 // JR Z, r81108 const value = this.bus.readByte(this.PC + 1);1109 const offset = utils_1.makeSigned(value, 1);1110 this.PC += 2;1111 if (this.getFlag(exports.ZERO_FLAG)) {1112 // jumped1113 this.PC += offset;1114 return 12;1115 }1116 else {1117 // not jumped1118 return 8;1119 }1120 }1121 else if (op === 0xC0) {1122 // RET NZ1123 if (!this.getFlag(exports.ZERO_FLAG)) {1124 const lsb = this.stackPop();1125 const msb = this.stackPop();1126 const addr = (msb << 8) | lsb;1127 this.PC = addr;1128 return 20;1129 }1130 else {1131 this.PC++;1132 return 8;1133 }1134 }1135 else if (op === 0xC8) {1136 // 'RET Z'1137 if (this.getFlag(exports.ZERO_FLAG)) {1138 const lsb = this.stackPop();1139 const msb = this.stackPop();1140 const addr = (msb << 8) | lsb;1141 this.PC = addr;1142 return 20;1143 }1144 else {1145 this.PC++;1146 return 8;1147 }1148 }1149 else if (op === 0xD0) {1150 // 'RET NC'1151 if (!this.getFlag(exports.CARRY_FLAG)) {1152 const lsb = this.stackPop();1153 const msb = this.stackPop();1154 const addr = (msb << 8) | lsb;1155 this.PC = addr;1156 return 20;1157 }1158 else {1159 this.PC++;1160 return 8;1161 }1162 }1163 else if (op === 0xD8) {1164 // RET C1165 if (this.getFlag(exports.CARRY_FLAG)) {1166 const lsb = this.stackPop();1167 const msb = this.stackPop();1168 const addr = (msb << 8) | lsb;1169 this.PC = addr;1170 return 20;1171 }1172 else {1173 this.PC++;1174 return 8;1175 }1176 }1177 else if (op === 0xDE) {1178 // SBC A, d81179 const value = this.bus.readByte(this.PC + 1);1180 this.A = this.sbcInstruction(value);1181 this.PC += 2;1182 return 8;1183 }1184 else if (op === 0xFA) {1185 // 'LD A, (a16)';1186 const value = this.readTwoByteValue(this.PC + 1);1187 this.A = this.bus.readByte(value);1188 this.PC += 3;1189 return 16;1190 }1191 else if (op === 0x3D) {1192 // DEC A1193 const result = wrappingByteSub(this.A, 1);1194 this.updateSubHalfCarryFlag(this.A, 1);1195 this.A = result[0];1196 this.setFlag(exports.SUBTRACTION_FLAG);1197 this.updateZeroFlag(this.A);1198 this.PC++;1199 return 4;1200 }1201 else if (op === 0x2D) {1202 // DEC L1203 this.decrementL();1204 this.PC++;1205 return 4;1206 }1207 else if (op === 0x11) {1208 // LD DE, d161209 const lsb = this.bus.readByte(this.PC + 1);1210 const msb = this.bus.readByte(this.PC + 2);1211 this.D = msb;1212 this.E = lsb;1213 this.PC += 3;1214 return 12;1215 }1216 else if (op === 0x7E) {1217 // LD A, (HL)1218 this.A = this.bus.readByte(this.HL);1219 this.PC++;1220 return 8;1221 }1222 else if (op === 0x6E) {1223 // LD L, (HL)1224 const value = this.bus.readByte(this.HL);1225 this.HL = (this.H() << 8) | value;1226 this.PC++;1227 return 8;1228 }1229 else if (op === 0x5E) {1230 // LD E, (HL)1231 this.E = this.bus.readByte(this.HL);1232 this.PC++;1233 return 8;1234 }1235 else if (op === 0x4E) {1236 // LD C, (HL)1237 this.C = this.bus.readByte(this.HL);1238 this.PC++;1239 return 8;1240 }1241 else if (op === 0xB7) {1242 // OR A1243 this.A = this.A | this.A;1244 this.updateZeroFlagAndClearOthers();1245 this.PC++;1246 return 4;1247 }1248 else if (op === 0xC1) {1249 // POP BC1250 this.C = this.stackPop();1251 this.B = this.stackPop();1252 this.PC++;1253 return 12;1254 }1255 else if (op === 0xD1) {1256 // POP DE1257 this.E = this.stackPop();1258 this.D = this.stackPop();1259 this.PC++;1260 return 12;1261 }1262 else if (op === 0xE1) {1263 // POP HL1264 const l = this.stackPop();1265 const h = this.stackPop();1266 this.HL = (h << 8) | l;1267 this.PC++;1268 return 12;1269 }1270 else if (op === 0xF1) {1271 // POP AF1272 const popped = this.stackPop();1273 this.Flags = this.loadFlags(popped);1274 this.A = this.stackPop();1275 this.PC++;1276 return 12;1277 }1278 else if (op === 0x2F) {1279 // CPL [complement A]1280 this.A = utils_1.bitNegation(this.A);1281 this.setFlag(exports.SUBTRACTION_FLAG);1282 this.setFlag(exports.HALF_CARRY_FLAG);1283 this.PC++;1284 return 4;1285 }1286 else if (op === 0xE6) {1287 // AND A, d81288 // Z 0 1 01289 const value = this.bus.readByte(this.PC + 1);1290 this.A = this.A & value;1291 this.updateZeroFlag(this.A);1292 this.clearFlag(exports.SUBTRACTION_FLAG);1293 this.setFlag(exports.HALF_CARRY_FLAG);1294 this.clearFlag(exports.CARRY_FLAG);1295 this.PC += 2;1296 return 8;1297 }1298 else if (op === 0x47) {1299 // LD B, A1300 this.B = this.A;1301 this.PC++;1302 return 4;1303 }1304 else if (op === 0x46) {1305 // 'LD B, (HL)';1306 this.B = this.bus.readByte(this.HL);1307 this.PC++;1308 return 8;1309 }1310 else if (op === 0x45) {1311 // 'LD B, L';1312 this.B = this.L();1313 this.PC++;1314 return 4;1315 }1316 else if (op === 0x44) {1317 // 'LD B, H';1318 this.B = this.H();1319 this.PC++;1320 return 4;1321 }1322 else if (op === 0x43) {1323 // 'LD B, E';1324 this.B = this.E;1325 this.PC++;1326 return 4;1327 }1328 else if (op === 0x42) {1329 // 'LD B, D';1330 this.B = this.D;1331 this.PC++;1332 return 4;1333 }1334 else if (op === 0x41) {1335 // 'LD B, C';1336 this.B = this.C;1337 this.PC++;1338 return 4;1339 }1340 else if (op === 0x40) {1341 // 'LD B, B';1342 this.B = this.B;1343 this.PC++;1344 return 4;1345 }1346 else if (op === 0x4F) {1347 // 'LD C, A';1348 this.C = this.A;1349 this.PC++;1350 return 4;1351 }1352 else if (op === 0x4D) {1353 // 'LD C, L';1354 this.C = this.L();1355 this.PC++;1356 return 4;1357 }1358 else if (op === 0x4C) {1359 // 'LD C, H';1360 this.C = this.H();1361 this.PC++;1362 return 4;1363 }1364 else if (op === 0x4B) {1365 // 'LD C, E';1366 this.C = this.E;1367 this.PC++;1368 return 4;1369 }1370 else if (op === 0x4A) {1371 // 'LD C, D';1372 this.C = this.D;1373 this.PC++;1374 return 4;1375 }1376 else if (op === 0x49) {1377 // 'LD C, C';1378 this.C = this.C;1379 this.PC++;1380 return 4;1381 }1382 else if (op === 0x48) {1383 // 'LD C, B';1384 this.C = this.B;1385 this.PC++;1386 return 4;1387 }1388 else if (op === 0xEF) {1389 // 'RST 28h';1390 // Push present address onto stack.1391 // Jump to address 0x00281392 this.pushAddressOnStack(this.PC + 1);1393 this.PC = 0x28;1394 return 16;1395 }1396 else if (op === 0x5F) {1397 // LD E, A1398 this.E = this.A;1399 this.PC++;1400 return 4;1401 }1402 else if (op === 0x5D) {1403 // LD E, L1404 this.E = this.L();1405 this.PC++;1406 return 4;1407 }1408 else if (op === 0x5C) {1409 // LD E, H1410 this.E = this.H();1411 this.PC++;1412 return 4;1413 }1414 else if (op === 0x5B) {1415 // LD E, E1416 this.E = this.E;1417 this.PC++;1418 return 4;1419 }1420 else if (op === 0x5A) {1421 // LD E, D1422 this.E = this.D;1423 this.PC++;1424 return 4;1425 }1426 else if (op === 0x59) {1427 // LD E, C1428 this.E = this.C;1429 this.PC++;1430 return 4;1431 }1432 else if (op === 0x58) {1433 // LD E, B1434 this.E = this.B;1435 this.PC++;1436 return 4;1437 }1438 else if (op === 0x56) {1439 // LD D, (HL)1440 this.D = this.bus.readByte(this.HL);1441 this.PC++;1442 return 8;1443 }1444 else if (op === 0x57) {1445 // LD D, A1446 this.D = this.A;1447 this.PC++;1448 return 4;1449 }1450 else if (op === 0x55) {1451 // LD D, L1452 this.D = this.L();1453 this.PC++;1454 return 4;1455 }1456 else if (op === 0x54) {1457 // LD D, H1458 this.D = this.H();1459 this.PC++;1460 return 4;1461 }1462 else if (op === 0x53) {1463 // LD D, E1464 this.D = this.E;1465 this.PC++;1466 return 4;1467 }1468 else if (op === 0x52) {1469 // LD D, D1470 this.D = this.D;1471 this.PC++;1472 return 4;1473 }1474 else if (op === 0x51) {1475 // LD D, C1476 this.D = this.C;1477 this.PC++;1478 return 4;1479 }1480 else if (op === 0x50) {1481 // LD D, B1482 this.D = this.B;1483 this.PC++;1484 return 4;1485 }1486 else if (op === 0xE8) {1487 // ADD SP, r81488 const value = this.bus.readByte(this.PC + 1);1489 const offset = utils_1.makeSigned(value, 1);1490 const result = wrappingTwoByteAdd(this.SP, offset);1491 //this.updateHalfCarryFlag(this.SP, offset);1492 if (((result[0] ^ this.SP ^ offset) & 0x1000) == 0x1000) {1493 this.setFlag(exports.HALF_CARRY_FLAG);1494 }1495 else {1496 this.clearFlag(exports.HALF_CARRY_FLAG);1497 }1498 result[1] ? this.setFlag(exports.CARRY_FLAG) : this.clearFlag(exports.CARRY_FLAG);1499 this.clearFlag(exports.ZERO_FLAG);1500 this.clearFlag(exports.SUBTRACTION_FLAG);1501 this.SP = result[0];1502 this.PC += 2;1503 return 16;1504 }1505 else if (op === 0xE9) {1506 // 'JP (HL)';1507 this.PC = this.HL;1508 return 4;1509 }1510 else if (op === 0x1A) {1511 // LD A, (DE)1512 this.A = this.bus.readByte(this.DE());1513 this.PC++;1514 return 8;1515 }1516 else if (op === 0x22) {1517 // LD (HL+),A1518 this.bus.writeByte(this.HL, this.A);1519 this.incrementHL();1520 this.PC++;1521 return 8;1522 }1523 else if (op === 0xCA) {1524 // JP Z, a161525 const addr = this.readTwoByteValue(this.PC + 1);1526 if (this.getFlag(exports.ZERO_FLAG)) {1527 this.PC = addr;1528 return 16;1529 }1530 else {1531 this.PC += 3;1532 return 12;1533 }1534 }1535 else if (op === 0x35) {1536 // DEC (HL)1537 const value = this.bus.readByte(this.HL);1538 const [result,] = wrappingTwoByteSub(value, 1);1539 this.bus.writeByte(this.HL, result[0]);1540 this.updateSubHalfCarryFlag(value, 1);1541 this.updateZeroFlag(result[0]);1542 this.setFlag(exports.SUBTRACTION_FLAG);1543 this.PC++;1544 return 12;1545 }1546 else if (op === 0x09) {1547 // ADD HL, BC1548 this.addToHLInstr(this.BC());1549 this.PC++;1550 return 8;1551 }1552 else if (op === 0x69) {1553 // LD L, C1554 this.updateL(this.C);1555 this.PC++;1556 return 4;1557 }1558 else if (op === 0x60) {1559 // LD H, B1560 this.updateH(this.B);1561 this.PC++;1562 return 4;1563 }1564 else if (op === 0x0A) {1565 // LD A, (BC)';1566 this.A = this.bus.readByte(this.BC());1567 this.PC++;1568 return 8;1569 }1570 else if (op === 0x80) {1571 // ADD A, B';1572 this.A = this.addOneByte(this.A, this.B);1573 this.PC++;1574 return 4;1575 }1576 else if (op === 0x81) {1577 // ADD A, C';1578 this.A = this.addOneByte(this.A, this.C);1579 this.PC++;1580 return 4;1581 }1582 else if (op === 0x82) {1583 // ADD A, D';1584 this.A = this.addOneByte(this.A, this.D);1585 this.PC++;1586 return 4;1587 }1588 else if (op === 0x83) {1589 // ADD A, E';1590 this.A = this.addOneByte(this.A, this.E);1591 this.PC++;1592 return 4;1593 }1594 else if (op === 0x84) {1595 // ADD A, H';1596 this.A = this.addOneByte(this.A, this.H());1597 this.PC++;1598 return 4;1599 }1600 else if (op === 0x85) {1601 // ADD A, L';1602 this.A = this.addOneByte(this.A, this.L());1603 this.PC++;1604 return 4;1605 }1606 else if (op === 0x86) {1607 // ADD A, (HL)';1608 this.A = this.addOneByte(this.A, this.bus.readByte(this.HL));1609 this.PC++;1610 return 8;1611 }1612 else if (op === 0x87) {1613 // ADD A, A;1614 this.A = this.addOneByte(this.A, this.A);1615 this.PC++;1616 return 4;1617 }1618 else if (op === 0x88) {1619 // ADC A, B';1620 const carryValue = this.getFlag(exports.CARRY_FLAG) ? 1 : 0;1621 this.addOneByte(this.A, this.B, carryValue);1622 this.PC++;1623 return 4;1624 }1625 else if (op === 0x89) {1626 // ADC A, C';1627 const carryValue = this.getFlag(exports.CARRY_FLAG) ? 1 : 0;1628 this.addOneByte(this.A, this.C, carryValue);1629 this.PC++;1630 return 4;1631 }1632 else if (op === 0x8A) {1633 // ADC A, D';1634 const carryValue = this.getFlag(exports.CARRY_FLAG) ? 1 : 0;1635 this.addOneByte(this.A, this.D, carryValue);1636 this.PC++;1637 return 4;1638 }1639 else if (op === 0x8B) {1640 // ADC A, E';1641 const carryValue = this.getFlag(exports.CARRY_FLAG) ? 1 : 0;1642 this.addOneByte(this.A, this.E, carryValue);1643 this.PC++;1644 return 4;1645 }1646 else if (op === 0x8C) {1647 // ADC A, H';1648 const carryValue = this.getFlag(exports.CARRY_FLAG) ? 1 : 0;1649 this.addOneByte(this.A, this.H(), carryValue);1650 this.PC++;1651 return 4;1652 }1653 else if (op === 0x8D) {1654 // ADC A, L';1655 const carryValue = this.getFlag(exports.CARRY_FLAG) ? 1 : 0;1656 this.addOneByte(this.A, this.L(), carryValue);1657 this.PC++;1658 return 4;1659 }1660 else if (op === 0x8E) {1661 // ADC A, (HL)';1662 const carryValue = this.getFlag(exports.CARRY_FLAG) ? 1 : 0;1663 this.addOneByte(this.A, this.bus.readByte(this.HL), carryValue);1664 this.PC++;1665 return 8;1666 }1667 else if (op === 0x8F) {1668 // ADC A, A';1669 const carryValue = this.getFlag(exports.CARRY_FLAG) ? 1 : 0;1670 this.addOneByte(this.A, this.A, carryValue);1671 this.PC++;1672 return 4;1673 }1674 else if (op === 0x6F) {1675 // LD L, A1676 this.updateL(this.A);1677 this.PC++;1678 return 4;1679 }1680 else if (op === 0x6D) {1681 // 'LD L, L';1682 this.updateL(this.L());1683 this.PC++;1684 return 4;1685 }1686 else if (op === 0x6C) {1687 // 'LD L, H';1688 this.updateL(this.H());1689 this.PC++;1690 return 4;1691 }1692 else if (op === 0x6B) {1693 // 'LD L, E';1694 this.updateL(this.E);1695 this.PC++;1696 return 4;1697 }1698 else if (op === 0x6A) {1699 // 'LD L, D';1700 this.updateL(this.D);1701 this.PC++;1702 return 4;1703 }1704 else if (op === 0x68) {1705 // 'LD L, B';1706 this.updateL(this.B);1707 this.PC++;1708 return 4;1709 }1710 else if (op === 0x61) {1711 // 'LD H, C';1712 this.updateH(this.C);1713 this.PC++;1714 return 4;1715 }1716 else if (op === 0x62) {1717 // 'LD H, D';1718 this.updateH(this.D);1719 this.PC++;1720 return 4;1721 }1722 else if (op === 0x63) {1723 // 'LD H, E';1724 this.updateH(this.E);1725 this.PC++;1726 return 4;1727 }1728 else if (op === 0x64) {1729 // 'LD H, H';1730 this.updateH(this.H());1731 this.PC++;1732 return 4;1733 }1734 else if (op === 0x65) {1735 // 'LD H, L';1736 this.updateH(this.L());1737 this.PC++;1738 return 4;1739 }1740 else if (op === 0x66) {1741 // 'LD H, (HL)';1742 this.updateH(this.bus.readByte(this.HL));1743 this.PC++;1744 return 8;1745 }1746 else if (op === 0x67) {1747 // 'LD H, A';1748 this.updateH(this.A);1749 this.PC++;1750 return 4;1751 }1752 else if (op === 0xC2) {1753 // JP NZ, a161754 const addr = this.readTwoByteValue(this.PC + 1);1755 if (!this.getFlag(exports.ZERO_FLAG)) {1756 this.PC = addr;1757 return 16;1758 }1759 else {1760 this.PC += 3;1761 return 12;1762 }1763 }1764 else if (op === 0x7A) {1765 // 'LD A, D';1766 this.A = this.D;1767 this.PC++;1768 return 4;1769 }1770 else if (op === 0x7D) {1771 // 'LD A, L';1772 this.A = this.L();1773 this.PC++;1774 return 4;1775 }1776 else if (op === 0xC6) {1777 // ADD A, d81778 const value = this.bus.readByte(this.PC + 1);1779 this.A = this.addOneByte(this.A, value);1780 this.PC += 2;1781 return 8;1782 }1783 else if (op === 0xEE) {1784 // XOR d81785 const value = this.bus.readByte(this.PC + 1);1786 this.A = this.A ^ value;1787 this.updateZeroFlagAndClearOthers();1788 this.PC += 2;1789 return 8;1790 }1791 else if (op === 0xC4) {1792 // CALL NZ, a161793 const addr = this.readTwoByteValue(this.PC + 1);1794 if (!this.Flags.zeroFlag) {1795 this.pushAddressOnStack(this.PC + 3);1796 this.PC = addr;1797 return 24;1798 }1799 else {1800 this.PC += 3;1801 return 12;1802 }1803 }1804 else if (op === 0xD6) {1805 // SUB d81806 const value = this.bus.readByte(this.PC + 1);1807 this.A = this.subOneByte(this.A, value);1808 this.PC += 2;1809 return 8;1810 }1811 else if (op === 0x26) {1812 // `LD H, d8`;1813 const value = this.bus.readByte(this.PC + 1);1814 this.updateH(value);1815 this.PC += 2;1816 return 8;1817 }1818 else if (op === 0x38) {1819 // JR C,r81820 const value = this.bus.readByte(this.PC + 1);1821 const offset = utils_1.makeSigned(value, 1);1822 this.PC += 2; // move to next instruction then add offset1823 if (this.getFlag(exports.CARRY_FLAG)) {1824 this.PC += offset;1825 return 12;1826 }1827 return 8;1828 }1829 else if (op === 0x30) {1830 // JR NC, r81831 const value = this.bus.readByte(this.PC + 1);1832 const offset = utils_1.makeSigned(value, 1);1833 this.PC += 2;1834 if (!this.getFlag(exports.CARRY_FLAG)) {1835 this.PC += offset;1836 return 12;1837 }1838 return 8;1839 }1840 else if (op === 0x33) {1841 // INC SP1842 this.SP = (this.SP + 1) & 0xFFFF;1843 this.PC++;1844 return 8;1845 }1846 else if (op === 0x3B) {1847 // DEC SP1848 this.SP = (this.SP - 1) & 0xFFFF;1849 this.PC++;1850 return 8;1851 }1852 else if (op === 0x73) {1853 // LD (HL), E1854 this.bus.writeByte(this.HL, this.E);1855 this.PC++;1856 return 8;1857 }1858 else if (op === 0x72) {1859 // LD (HL), D1860 this.bus.writeByte(this.HL, this.D);1861 this.PC++;1862 return 8;1863 }1864 else if (op === 0x71) {1865 // LD (HL), C1866 this.bus.writeByte(this.HL, this.C);1867 this.PC++;1868 return 8;1869 }1870 else if (op === 0x70) {1871 // LD (HL), B1872 this.bus.writeByte(this.HL, this.B);1873 this.PC++;1874 return 8;1875 }1876 else if (op === 0x77) {1877 // LD (HL), A1878 this.bus.writeByte(this.HL, this.A);1879 this.PC++;1880 return 8;1881 }1882 else if (op === 0x74 || op === 0x75) {1883 // LD (HL), n1884 const valueMap = {1885 0x74: this.H(),1886 0x75: this.L()1887 };1888 this.bus.writeByte(this.HL, valueMap[op]);1889 this.PC += 1;1890 return 8;1891 }1892 else if (op === 0x76) {1893 // HALT1894 // TODO: Halt CPU until interrupt occurs1895 this.PC++;1896 return 4;1897 }1898 else if (op === 0xF9) {1899 // LD SP, HL1900 this.SP = this.HL;1901 this.PC++;1902 return 8;1903 }1904 else if (op === 0xCE) {1905 // ADC A, d81906 const value = this.bus.readByte(this.PC + 1);1907 const carryValue = this.getFlag(exports.CARRY_FLAG) ? 0x01 : 0x00;1908 this.A = this.addOneByte(this.A, value, carryValue);1909 this.PC += 2;1910 return 8;1911 }1912 else if (op >= 0xB0 && op <= 0xB7) {1913 // OR n1914 const valueMap = {1915 0x0: this.B,1916 0x1: this.C,1917 0x2: this.D,1918 0x3: this.E,1919 0x4: this.H(),1920 0x5: this.L(),1921 0x6: this.bus.readByte(this.HL),1922 0x7: this.A1923 };1924 this.A = this.A | valueMap[op & 0x0F];1925 this.updateZeroFlagAndClearOthers();1926 this.PC++;1927 return op === 0xB6 ? 8 : 4;1928 }1929 else if (op === 0x1E) {1930 // LD E, d81931 this.E = this.bus.readByte(this.PC + 1);1932 this.PC += 2;1933 return 8;1934 }1935 else if (op === 0xF6) {1936 // OR d81937 const value = this.bus.readByte(this.PC + 1);1938 this.executeOr(value);1939 this.PC += 2;1940 return 8;1941 }1942 else if (op === 0x03) {1943 // INC BC1944 this.incrementBC();1945 this.PC++;1946 return 8;1947 }1948 else if (op === 0x04) {1949 // INC B1950 this.B = this.incrementRegister(this.B);1951 this.PC++;1952 return 4;1953 }1954 else if (op === 0x0C) {1955 // INC C1956 this.C = this.incrementRegister(this.C);1957 this.PC++;1958 return 4;1959 }1960 else if (op === 0x14) {1961 // INC D1962 this.D = this.incrementRegister(this.D);1963 this.PC++;1964 return 4;1965 }1966 else if (op === 0x1C) {1967 // INC E1968 this.E = this.incrementRegister(this.E);1969 this.PC++;1970 return 4;1971 }1972 else if ([0x13, 0x23, 0x24, 0x2C, 0x34, 0x3C].includes(op)) {1973 const opMap = {1974 0x13: () => this.incrementDE(),1975 0x23: () => this.incrementHL(),1976 0x24: () => this.incrementH(),1977 0x2C: () => this.incrementL(),1978 0x34: () => {1979 const value = this.bus.readByte(this.HL);1980 const [result,] = wrappingByteAdd(value, 1);1981 //this.updateHalfCarryFlag(value, 1);1982 this.clearFlag(exports.HALF_CARRY_FLAG);1983 if (((result[0] ^ value ^ 1) & 0x10) == 0x10) {1984 this.setFlag(exports.HALF_CARRY_FLAG);1985 }1986 this.clearFlag(exports.SUBTRACTION_FLAG);1987 this.updateZeroFlag(result);1988 this.bus.writeByte(this.HL, result);1989 },1990 0x3C: () => {1991 const result = wrappingByteAdd(this.A, 1);1992 //this.updateHalfCarryFlag(this.A, 1);1993 this.clearFlag(exports.HALF_CARRY_FLAG);1994 if (((result[0] ^ this.A ^ 1) & 0x10) == 0x10) {1995 this.setFlag(exports.HALF_CARRY_FLAG);1996 }1997 this.clearFlag(exports.SUBTRACTION_FLAG);1998 this.updateZeroFlag(result[0]);1999 this.A = result[0];2000 }2001 };2002 if (opMap[op]) {2003 opMap[op]();2004 }2005 this.PC++;2006 if (op === 0x34) {2007 return 12;2008 }2009 return [0x13, 0x23].includes[op] ? 8 : 4;2010 }2011 else if (op >= 0x90 && op <= 0x97 || op === 0xD6) {2012 // SUB n2013 // Subtract n from A2014 if (op === 0xD6) {2015 const value = this.bus.readByte(this.PC + 1);2016 this.A = this.subOneByte(this.A, value);2017 this.PC += 2;2018 return 8;2019 }2020 if (op === 0x96) {2021 const value = this.bus.readByte(this.HL);2022 this.A = this.subOneByte(this.A, value);2023 this.PC++;2024 return 8;2025 }2026 const opMap = {2027 0x90: () => { return this.subOneByte(this.A, this.B); },2028 0x91: () => { return this.subOneByte(this.A, this.C); },2029 0x92: () => { return this.subOneByte(this.A, this.D); },2030 0x93: () => { return this.subOneByte(this.A, this.E); },2031 0x94: () => { return this.subOneByte(this.A, this.H()); },2032 0x95: () => { return this.subOneByte(this.A, this.L()); },2033 0x97: () => { return this.subOneByte(this.A, this.A); }2034 };2035 this.A = opMap[op]();2036 this.PC++;2037 return 4;2038 }2039 else if (op === 0xF8) {2040 // https://stackoverflow.com/questions/5159603/gbz80-how-does-ld-hl-spe-affect-h-and-c-flags/72611492041 // https://stackoverflow.com/questions/57958631/game-boy-half-carry-flag-and-16-bit-instructions-especially-opcode-0xe82042 // `LD HL, SP + ${value}`;2043 // TODO: half-carry AND carry flags might not be setting correctly2044 const value = this.bus.readByte(this.PC + 1);2045 const offset = utils_1.makeSigned(value, 1);2046 const result = wrappingTwoByteAdd(this.SP, offset);2047 //this.updateHalfCarryFlag(this.SP, offset);2048 if (((result[0] ^ this.SP ^ offset) & 0x1000) == 0x1000) {2049 this.setFlag(exports.HALF_CARRY_FLAG);2050 }2051 else {2052 this.clearFlag(exports.HALF_CARRY_FLAG);2053 }2054 this.clearFlag(exports.CARRY_FLAG);2055 if (result[1]) {2056 this.setFlag(exports.CARRY_FLAG);2057 }2058 this.HL = result[0];2059 this.clearFlag(exports.SUBTRACTION_FLAG);2060 this.clearFlag(exports.ZERO_FLAG);2061 this.PC += 2;2062 return 12;2063 }2064 else if (op >= 0xB8 && op <= 0xBF) {2065 // Compare A with n. This is basically an A - n subtraction instruction but the results are thrown away.2066 // CP d82067 const value = this.getRegisterValueInvolved(op);2068 let result = wrappingByteSub(this.A, value);2069 this.updateZeroFlag(result[0]);2070 this.setFlag(exports.SUBTRACTION_FLAG);2071 this.updateSubHalfCarryFlag(this.A, value);2072 result[1] ? this.setFlag(exports.CARRY_FLAG) : this.clearFlag(exports.CARRY_FLAG);2073 this.PC++;2074 return op === 0xBE ? 8 : 4;2075 }2076 else if (op === 0x27) {2077 // DAA2078 this.daaInstruction();2079 this.PC++;2080 return 4;2081 }2082 else if (op === 0x2E) {2083 // LD L,d82084 const value = this.bus.readByte(this.PC + 1);2085 this.updateL(value);2086 this.PC += 2;2087 return 8;2088 }2089 else if (op === 0x1B) {2090 // DEC DE2091 this.decrementDE();2092 this.PC++;2093 return 8;2094 }2095 else if (op === 0x2B) {2096 // DEC HL2097 this.decrementHL();2098 this.PC++;2099 return 8;2100 }2101 else if (op === 0x37) {2102 // SCF2103 // Set Carry flag2104 this.setFlag(exports.CARRY_FLAG);2105 this.clearFlag(exports.SUBTRACTION_FLAG);2106 this.clearFlag(exports.HALF_CARRY_FLAG);2107 this.PC++;2108 return 4;2109 }2110 else if (op === 0x3F) {2111 // CCF2112 // Complement carry flag2113 this.getFlag(exports.CARRY_FLAG) ? this.clearFlag(exports.CARRY_FLAG) : this.setFlag(exports.CARRY_FLAG);2114 this.clearFlag(exports.SUBTRACTION_FLAG);2115 this.clearFlag(exports.HALF_CARRY_FLAG);2116 this.PC++;2117 return 4;2118 }2119 else if (op === 0x98) {2120 // SBC B2121 this.A = this.sbcInstruction(this.B);2122 this.PC++;2123 return 4;2124 }2125 else if (op === 0x99) {2126 // SBC C2127 this.A = this.sbcInstruction(this.C);2128 this.PC++;2129 return 4;2130 }2131 else if (op === 0x9A) {2132 this.A = this.sbcInstruction(this.D);2133 this.PC++;2134 return 4;2135 }2136 else if (op === 0x9B) {2137 this.A = this.sbcInstruction(this.E);2138 this.PC++;2139 return 4;2140 }2141 else if (op === 0x9C) {2142 this.A = this.sbcInstruction(this.H());2143 this.PC++;2144 return 4;2145 }2146 else if (op === 0x9D) {2147 this.A = this.sbcInstruction(this.L());2148 this.PC++;2149 return 4;2150 }2151 else if (op === 0x9E) {2152 const value = this.bus.readByte(this.HL);2153 this.A = this.sbcInstruction(value);2154 this.PC++;2155 return 8;2156 }2157 else if (op === 0x9F) {2158 // SBC A2159 this.sbcInstruction(this.A);2160 this.PC++;2161 return 4;2162 }2163 else if (op === 0xA8) {2164 // XOR B2165 this.A = this.A ^ this.B;2166 this.updateZeroFlagAndClearOthers();2167 this.PC++;2168 return 4;2169 }2170 else if (op === 0xA9) {2171 // XOR C2172 this.A = this.A ^ this.C;2173 this.updateZeroFlagAndClearOthers();2174 this.PC++;2175 return 4;2176 }2177 else if (op === 0xAA) {2178 // XOR D2179 this.A = this.A ^ this.D;2180 this.updateZeroFlagAndClearOthers();2181 this.PC++;2182 return 4;2183 }2184 else if (op === 0xAB) {2185 // XOR E2186 this.A = this.A ^ this.E;2187 this.updateZeroFlagAndClearOthers();2188 this.PC++;2189 return 4;2190 }2191 else if (op === 0xAC) {2192 // XOR H2193 this.A = this.A ^ this.H();2194 this.updateZeroFlagAndClearOthers();2195 this.PC++;2196 return 4;2197 }2198 else if (op === 0xAD) {2199 // XOR L2200 this.A = this.A ^ this.L();2201 this.updateZeroFlagAndClearOthers();2202 this.PC++;2203 return 4;2204 }2205 else if (op === 0xAE) {2206 // XOR (HL)2207 const value = this.bus.readByte(this.HL);2208 this.A = this.A ^ value;2209 this.updateZeroFlagAndClearOthers();2210 this.PC++;2211 return 8;2212 }2213 else if (op === 0xAF) {2214 // XOR A2215 this.A = this.A ^ this.A;2216 this.updateZeroFlagAndClearOthers();2217 this.PC++;2218 return 4;2219 }2220 else if (op === 0x17) {2221 // RLA2222 this.A = this.rotateLeftThroughCarry(this.A);2223 this.clearFlag(exports.ZERO_FLAG);2224 this.PC++;2225 return 4;2226 }2227 else if (op === 0x0F) {2228 // RRCA2229 // Rotate A right. Old bit 0 to Carry flag.2230 this.A = this.rotateRight(this.A);2231 this.clearFlag(exports.ZERO_FLAG);2232 this.PC++;2233 return 4;2234 }2235 else if (op === 0x23) {2236 // INC HL2237 this.incrementHL();2238 this.PC++;2239 return 8;2240 }2241 else if (op === 0xC4) {2242 // CALL NZ, a162243 const addr = this.readTwoByteValue(this.PC + 1);2244 if (!this.getFlag(exports.ZERO_FLAG)) {2245 // push address after this instruction on to the stack2246 this.pushAddressOnStack(this.PC + 3); // 3 because this instruction is 3 bytes long 2247 this.PC = addr;2248 return 24;2249 }2250 this.PC += 3;2251 return 12;2252 }2253 else if (op === 0xD4) {2254 // CALL NC, a162255 const addr = this.readTwoByteValue(this.PC + 1);2256 if (!this.getFlag(exports.CARRY_FLAG)) {2257 // push address after this instruction on to the stack2258 this.pushAddressOnStack(this.PC + 3); // 3 because this instruction is 3 bytes long 2259 this.PC = addr;2260 return 24;2261 }2262 this.PC += 3;2263 return 12;2264 }2265 else if (op === 0xCC) {2266 // CALL Z, a162267 const addr = this.readTwoByteValue(this.PC + 1);2268 if (this.getFlag(exports.ZERO_FLAG)) {2269 // push address after this instruction on to the stack2270 this.pushAddressOnStack(this.PC + 3); // 3 because this instruction is 3 bytes long 2271 this.PC = addr;2272 return 24;2273 }2274 this.PC += 3;2275 return 12;2276 }2277 else if (op === 0xDC) {2278 // CALL C, a162279 const addr = this.readTwoByteValue(this.PC + 1);2280 if (this.getFlag(exports.CARRY_FLAG)) {2281 // push address after this instruction on to the stack2282 this.pushAddressOnStack(this.PC + 3); // 3 because this instruction is 3 bytes long 2283 this.PC = addr;2284 return 24;2285 }2286 this.PC += 3;2287 return 12;2288 }2289 else if (op === 0xCF) {2290 // RST 0x082291 this.rstInstruction(0x08); // fn changes PC address2292 return 16;2293 }2294 else if (op === 0xDF) {2295 // RST 0x182296 this.rstInstruction(0x18); // fn changes PC address2297 return 16;2298 }2299 else if (op === 0xEF) {2300 // RST 0x282301 this.rstInstruction(0x28); // fn changes PC address2302 return 16;2303 }2304 else if (op === 0xC7) {2305 // RST 0x002306 this.rstInstruction(0x00); // fn changes PC address2307 return 16;2308 }2309 else if (op === 0xD7) {2310 // RST 0x102311 this.rstInstruction(0x10); // fn changes PC address2312 return 16;2313 }2314 else if (op === 0xE7) {2315 // RST 0x202316 this.rstInstruction(0x20); // fn changes PC address2317 return 16;2318 }2319 else if (op === 0xF7) {2320 // RST 0x302321 this.rstInstruction(0x30); // fn changes PC address2322 return 16;2323 }2324 else if (op === 0xCB) {2325 let nextInstrByte = this.bus.readByte(this.PC + 1);2326 switch (nextInstrByte) {2327 case 0x00:2328 // RLC B2329 this.B = this.rotateLeft(this.B);2330 this.PC += 2;2331 return 8;2332 case 0x01:2333 // RLC C2334 this.C = this.rotateLeft(this.C);2335 this.PC += 2;2336 return 8;2337 case 0x02:2338 // RLC D2339 this.D = this.rotateLeft(this.D);2340 this.PC += 2;2341 return 8;2342 case 0x03:2343 // RLC E2344 this.E = this.rotateLeft(this.E);2345 this.PC += 2;2346 return 8;2347 case 0x04:2348 // RLC H2349 this.updateH(this.rotateLeft(this.H()));2350 this.PC += 2;2351 return 8;2352 case 0x05:2353 // RLC L2354 this.updateL(this.rotateLeft(this.L()));2355 this.PC += 2;2356 return 8;2357 case 0x06:2358 // RLC (HL)2359 let b = this.bus.readByte(this.HL);2360 b = this.rotateLeft(b);2361 this.bus.writeByte(this.HL, b);2362 this.PC += 2;2363 return 8;2364 case 0x07:2365 // RLC A2366 this.A = this.rotateLeft(this.A);2367 this.PC += 2;2368 return 8;2369 case 0x08:2370 // RRC B2371 this.B = this.rotateRight(this.B);2372 this.PC += 2;2373 return 8;2374 case 0x09:2375 // RRC C2376 this.C = this.rotateRight(this.C);2377 this.PC += 2;2378 return 8;2379 case 0x0A:2380 // RRC D2381 this.D = this.rotateRight(this.D);2382 this.PC += 2;2383 return 8;2384 case 0x0B:2385 // RRC E2386 this.E = this.rotateRight(this.E);2387 this.PC += 2;2388 return 8;2389 case 0x0C:2390 // RRC H2391 this.updateH(this.rotateRight(this.H()));2392 this.PC += 2;2393 return 8;2394 case 0x0D:2395 // RRC L2396 this.updateL(this.rotateRight(this.L()));2397 this.PC += 2;2398 return 8;2399 case 0x0E:2400 // RRC (HL)2401 let b2 = this.bus.readByte(this.HL);2402 b2 = this.rotateRight(b2);2403 this.bus.writeByte(this.HL, b2);2404 this.PC += 2;2405 return 8;2406 case 0x0F:2407 // RRC A2408 this.A = this.rotateRight(this.A);2409 this.PC += 2;2410 return 8;2411 case 0x10:2412 // RL B2413 this.B = this.rotateLeftThroughCarry(this.B);2414 this.PC += 2;2415 return 8;2416 case 0x11:2417 // RL C2418 this.C = this.rotateLeftThroughCarry(this.C);2419 this.PC += 2;2420 return 8;2421 case 0x12:2422 // RL D2423 this.D = this.rotateLeftThroughCarry(this.D);2424 this.PC += 2;2425 return 8;2426 case 0x13:2427 // RL E2428 this.E = this.rotateLeftThroughCarry(this.E);2429 this.PC += 2;2430 return 8;2431 case 0x14:2432 // RL H2433 this.updateH(this.rotateLeftThroughCarry(this.H()));2434 this.PC += 2;2435 return 8;2436 case 0x15:2437 // RL L2438 this.updateL(this.rotateLeftThroughCarry(this.L()));2439 this.PC += 2;2440 return 8;2441 case 0x16:2442 // RL (HL)2443 let b3 = this.bus.readByte(this.HL);2444 b3 = this.rotateLeftThroughCarry(b3);2445 this.bus.writeByte(this.HL, b3);2446 this.PC += 2;2447 return 8;2448 case 0x17:2449 // RL A2450 this.A = this.rotateLeftThroughCarry(this.A);2451 this.PC += 2;2452 return 8;2453 case 0x18:2454 // 'RR B'2455 this.B = this.rotateRightThroughCarry(this.B);2456 this.PC += 2;2457 return 8;2458 case 0x19:2459 // 'RR C'2460 // Rotate n right through Carry flag.2461 this.C = this.rotateRightThroughCarry(this.C);2462 this.PC += 2;2463 return 8;2464 case 0x1A:2465 // 'RR D';2466 this.D = this.rotateRightThroughCarry(this.D);2467 this.PC += 2;2468 return 8;2469 case 0x1B:2470 // 'RR E';2471 this.E = this.rotateRightThroughCarry(this.E);2472 this.PC += 2;2473 return 8;2474 case 0x1C:2475 // 'RR H';2476 this.updateH(this.rotateRightThroughCarry(this.H()));2477 this.PC += 2;2478 return 8;2479 case 0x1D:2480 // 'RR L';2481 this.updateL(this.rotateRightThroughCarry(this.L()));2482 this.PC += 2;2483 return 8;2484 case 0x1E:2485 // 'RR (HL)';2486 const b6 = this.bus.readByte(this.HL);2487 this.bus.writeByte(this.HL, this.rotateRightThroughCarry(b6));2488 this.PC += 2;2489 return 16;2490 case 0x1F:2491 // 'RR A';2492 this.A = this.rotateRightThroughCarry(this.A);2493 this.PC += 2;2494 return 8;2495 case 0x20:2496 // SLA B2497 this.B = this.shiftLeftIntoCarry(this.B);2498 this.PC += 2;2499 return 8;2500 case 0x21:2501 // SLA C2502 this.C = this.shiftLeftIntoCarry(this.C);2503 this.PC += 2;2504 return 8;2505 case 0x22:2506 // SLA D2507 this.D = this.shiftLeftIntoCarry(this.D);2508 this.PC += 2;2509 return 8;2510 case 0x23:2511 // SLA E2512 this.E = this.shiftLeftIntoCarry(this.E);2513 this.PC += 2;2514 return 8;2515 case 0x24:2516 // SLA H2517 this.updateH(this.shiftLeftIntoCarry(this.H()));2518 this.PC += 2;2519 return 8;2520 case 0x25:2521 // SLA L2522 this.updateL(this.shiftLeftIntoCarry(this.L()));2523 this.PC += 2;2524 return 8;2525 case 0x26:2526 // SLA (HL)2527 const b4 = this.bus.readByte(this.HL);2528 this.bus.writeByte(this.HL, this.shiftLeftIntoCarry(b4));2529 case 0x27:2530 // SLA A2531 // Shift n left into Carry. LSB of n set to 02532 this.A = this.shiftLeftIntoCarry(this.A);2533 this.PC += 2;2534 return 8;2535 case 0x28:2536 // SRA B2537 this.B = this.shiftRightIntoCarry(this.B);2538 this.PC += 2;2539 return 8;2540 case 0x29:2541 // SRA C2542 this.C = this.shiftRightIntoCarry(this.C);2543 this.PC += 2;2544 return 8;2545 case 0x2A:2546 // SRA D2547 this.D = this.shiftRightIntoCarry(this.D);2548 this.PC += 2;2549 return 8;2550 case 0x2B:2551 // SRA E2552 this.E = this.shiftRightIntoCarry(this.E);2553 this.PC += 2;2554 return 8;2555 case 0x2C:2556 // SRA H2557 this.updateH(this.shiftRightIntoCarry(this.H()));2558 this.PC += 2;2559 return 8;2560 case 0x2D:2561 // SRA L2562 this.updateL(this.shiftRightIntoCarry(this.L()));2563 this.PC += 2;2564 return 8;2565 case 0x2E:2566 // SRA (HL)2567 const b5 = this.bus.readByte(this.HL);2568 this.bus.writeByte(this.HL, this.shiftRightIntoCarry(b5));2569 this.PC += 2;2570 return 8;2571 case 0x2F:2572 // SRA A2573 this.A = this.shiftRightIntoCarry(this.A);2574 this.PC += 2;2575 return 8;2576 case 0x30:2577 // SWAP B2578 this.swapNibblesOf(this.B);2579 this.PC += 2;2580 return 8;2581 case 0x31:2582 // SWAP C2583 this.swapNibblesOf(this.C);2584 this.PC += 2;2585 return 8;2586 case 0x32:2587 // SWAP D2588 this.swapNibblesOf(this.D);2589 this.PC += 2;2590 return 8;2591 case 0x33:2592 // SWAP E2593 this.swapNibblesOf(this.E);2594 this.PC += 2;2595 return 8;2596 case 0x34:2597 // SWAP H2598 const swappedH = this.swapNibblesOf(this.H());2599 this.HL = (swappedH << 8) | this.L();2600 this.PC += 2;2601 return 8;2602 case 0x35:2603 // SWAP L2604 const swappedL = this.swapNibblesOf(this.L());2605 this.HL = (this.H() << 8) | swappedL;2606 this.PC += 2;2607 return 8;2608 case 0x36:2609 // SWAP (HL)2610 const swapValue = this.bus.readByte(this.HL);2611 const swapped = this.swapNibblesOf(swapValue);2612 this.bus.writeByte(this.HL, swapped);2613 this.PC += 2;2614 return 16;2615 case 0x37:2616 // SWAP A2617 this.swapNibblesOf(this.A);2618 this.PC += 2;2619 return 8;2620 case 0x38:2621 // SRL B2622 this.B = this.shiftRight(this.B);2623 this.PC += 2;2624 return 8;2625 case 0x39:2626 // SRL C2627 this.C = this.shiftRight(this.C);2628 this.PC += 2;2629 return 8;2630 case 0x3A:2631 // SRL D2632 this.D = this.shiftRight(this.D);2633 this.PC += 2;2634 return 8;2635 case 0x3B:2636 // SRL E2637 this.E = this.shiftRight(this.E);2638 this.PC += 2;2639 return 8;2640 case 0x3C:2641 // SRL H2642 this.updateH(this.shiftRight(this.H()));2643 this.PC += 2;2644 return 8;2645 case 0x3D:2646 // SRL L2647 this.updateL(this.shiftRight(this.L()));2648 this.PC += 2;2649 return 8;2650 case 0x3E:2651 // SRL (HL)2652 const v = this.bus.readByte(this.HL);2653 const updated = this.shiftRightIntoCarry(v);2654 this.bus.writeByte(this.HL, updated);2655 this.PC += 2;2656 return 16;2657 case 0x3F:2658 // SRL E2659 this.A = this.shiftRightIntoCarry(this.A);2660 this.PC += 2;2661 return 8;2662 case 0x40:2663 // BIT 0, B2664 return this.updateZeroFlagWithBit(this.B, 0);2665 case 0x41:2666 // BIT 0, C2667 return this.updateZeroFlagWithBit(this.C, 0);2668 case 0x42:2669 // BIT 0, D2670 return this.updateZeroFlagWithBit(this.D, 0);2671 case 0x43:2672 // BIT 0, E2673 return this.updateZeroFlagWithBit(this.E, 0);2674 case 0x44:2675 // BIT 0, H2676 return this.updateZeroFlagWithBit(this.H(), 0);2677 case 0x45:2678 // BIT 0, L2679 return this.updateZeroFlagWithBit(this.L(), 0);2680 case 0x46:2681 // BIT 0, (HL)2682 this.updateZeroFlagWithBit(this.bus.readByte(this.HL), 0);2683 return 16;2684 case 0x47:2685 // BIT 0, A2686 return this.updateZeroFlagWithBit(this.A, 0);2687 case 0x48:2688 // BIT 1, B2689 return this.updateZeroFlagWithBit(this.B, 1);2690 case 0x49:2691 // BIT 1, C2692 return this.updateZeroFlagWithBit(this.C, 1);2693 case 0x4A:2694 // BIT 1, D2695 return this.updateZeroFlagWithBit(this.D, 1);2696 case 0x4B:2697 // BIT 1, E2698 return this.updateZeroFlagWithBit(this.E, 1);2699 case 0x4C:2700 // BIT 1, H2701 return this.updateZeroFlagWithBit(this.H(), 1);2702 case 0x4D:2703 // BIT 1, L2704 return this.updateZeroFlagWithBit(this.L(), 1);2705 case 0x4E:2706 // BIT 1, (HL)2707 this.updateZeroFlagWithBit(this.bus.readByte(this.HL), 1);2708 return 16;2709 case 0x4F:2710 // BIT 1, A2711 return this.updateZeroFlagWithBit(this.A, 1);2712 case 0x50:2713 // BIT 2, B2714 return this.updateZeroFlagWithBit(this.B, 2);2715 case 0x51:2716 // 'BIT 2, C';2717 return this.updateZeroFlagWithBit(this.C, 2);2718 case 0x52:2719 // 'BIT 2, D';2720 return this.updateZeroFlagWithBit(this.D, 2);2721 case 0x53:2722 // 'BIT 2, E';2723 return this.updateZeroFlagWithBit(this.E, 2);2724 case 0x54:2725 // 'BIT 2, H';2726 return this.updateZeroFlagWithBit(this.H(), 2);2727 case 0x55:2728 // 'BIT 2, L';2729 return this.updateZeroFlagWithBit(this.L(), 2);2730 case 0x56:2731 // 'BIT 2, (HL)';2732 this.updateZeroFlagWithBit(this.bus.readByte(this.HL), 2);2733 return 16;2734 case 0x57:2735 // 'BIT 2, A';2736 return this.updateZeroFlagWithBit(this.A, 2);2737 case 0x58:2738 // BIT 3, B2739 return this.updateZeroFlagWithBit(this.B, 3);2740 case 0x59:2741 // BIT 3, C2742 return this.updateZeroFlagWithBit(this.C, 3);2743 case 0x5A:2744 // BIT 3, D2745 return this.updateZeroFlagWithBit(this.D, 3);2746 case 0x5B:2747 // BIT 3, E2748 return this.updateZeroFlagWithBit(this.E, 3);2749 case 0x5C:2750 // BIT 3, H2751 return this.updateZeroFlagWithBit(this.H(), 3);2752 case 0x5D:2753 // BIT 3, L2754 return this.updateZeroFlagWithBit(this.L(), 3);2755 case 0x5E:2756 // BIT 3, (HL)2757 this.updateZeroFlagWithBit(this.bus.readByte(this.HL), 3);2758 return 16;2759 case 0x5F:2760 // BIT 3, A2761 return this.updateZeroFlagWithBit(this.A, 3);2762 case 0x70:2763 // BIT 6, B2764 return this.updateZeroFlagWithBit(this.B, 6);2765 case 0x71:2766 // BIT 6, C2767 return this.updateZeroFlagWithBit(this.C, 6);2768 case 0x72:2769 // BIT 6, D2770 return this.updateZeroFlagWithBit(this.D, 6);2771 case 0x73:2772 // BIT 6, E2773 return this.updateZeroFlagWithBit(this.E, 6);2774 case 0x74:2775 // BIT 6, H2776 return this.updateZeroFlagWithBit(this.H(), 6);2777 case 0x75:2778 // BIT 6, L2779 return this.updateZeroFlagWithBit(this.L(), 6);2780 case 0x76:2781 // BIT 6, (HL)2782 this.updateZeroFlagWithBit(this.bus.readByte(this.HL), 6);2783 return 16;2784 case 0x77:2785 // BIT 6, A2786 return this.updateZeroFlagWithBit(this.A, 6);2787 case 0x78:2788 // BIT 7, B2789 return this.updateZeroFlagWithBit(this.B, 7);2790 case 0x79:2791 // BIT 7, C2792 return this.updateZeroFlagWithBit(this.C, 7);2793 case 0x7A:2794 // BIT 7, D2795 return this.updateZeroFlagWithBit(this.D, 7);2796 case 0x7B:2797 // BIT 7, E2798 return this.updateZeroFlagWithBit(this.E, 7);2799 case 0x7C:2800 // BIT 7, H2801 return this.updateZeroFlagWithBit(this.H(), 7);2802 case 0x7D:2803 // BIT 7, L2804 return this.updateZeroFlagWithBit(this.L(), 7);2805 case 0x7E:2806 // BIT 7, (HL)2807 this.updateZeroFlagWithBit(this.bus.readByte(this.HL), 7);2808 return 16;2809 case 0x7F:2810 // Updates Z, is zero flag2811 // BIT 7, A2812 return this.updateZeroFlagWithBit(this.A, 7);2813 case 0x87:2814 // 'RES 0, A'2815 // Reset bit u3 in register r8 to 0. Bit 0 is the rightmost one, bit 7 the leftmost one.2816 this.A = this.resetBitInstruction(this.A, 0);2817 return 8;2818 case 0x86:2819 // RES 0, (HL)2820 return this.resetHLBitInstruction(0);2821 case 0xA0:2822 // RES 4, B2823 this.B = this.resetBitInstruction(this.B, 4);2824 return 8;2825 case 0xA1:2826 // RES 4, C2827 this.C = this.resetBitInstruction(this.C, 4);2828 return 8;2829 case 0xA2:2830 // RES 4, D2831 this.D = this.resetBitInstruction(this.D, 4);2832 return 8;2833 case 0xA3:2834 // RES 4, E2835 this.E = this.resetBitInstruction(this.E, 4);2836 return 8;2837 case 0xA7:2838 // RES 4, A2839 this.A = this.resetBitInstruction(this.A, 4);2840 return 8;2841 case 0xA8:2842 // RES 5, B2843 this.B = this.resetBitInstruction(this.B, 5);2844 return 8;2845 case 0xA9:2846 // RES 5, C2847 this.C = this.resetBitInstruction(this.C, 5);2848 return 8;2849 case 0xAA:2850 // RES 5, D2851 this.D = this.resetBitInstruction(this.D, 5);2852 return 8;2853 case 0xAB:2854 // RES 5, E2855 this.E = this.resetBitInstruction(this.E, 5);2856 return 8;2857 case 0xAE:2858 // RES 5, (HL)2859 return this.resetHLBitInstruction(5);2860 case 0xAF:2861 // RES 5, A2862 this.A = this.resetBitInstruction(this.A, 5);2863 return 8;2864 case 0xE0:2865 // SET 4, B2866 this.B = this.setBitInstruction(this.B, 4);2867 return 8;2868 case 0xE1:2869 // SET 4, C2870 this.C = this.setBitInstruction(this.C, 4);2871 return 8;2872 case 0xE2:2873 // SET 4, D2874 this.D = this.setBitInstruction(this.D, 4);2875 return 8;2876 case 0xE3:2877 // SET 4, E2878 this.E = this.setBitInstruction(this.E, 4);2879 return 8;2880 case 0xE4:2881 // SET 4, H2882 return this.setHBitInstruction(4);2883 case 0xE5:2884 // SET 4, L2885 return this.setLBitInstruction(4);2886 case 0xE6:2887 // SET 4, (HL)2888 return this.setHLBitInstruction(4);2889 case 0xE7:2890 // SET 4, A2891 this.A = this.setBitInstruction(this.A, 4);2892 return 8;2893 case 0xE8:2894 // SET 5, B2895 this.B = this.setBitInstruction(this.B, 5);2896 return 8;2897 case 0xE9:2898 // SET 5, C2899 this.C = this.setBitInstruction(this.C, 5);2900 return 8;2901 case 0xEA:2902 // SET 5, D2903 this.D = this.setBitInstruction(this.D, 5);2904 return 8;2905 case 0xEB:2906 // SET 5, E2907 this.E = this.setBitInstruction(this.E, 5);2908 return 8;2909 case 0xEC:2910 // SET 5, H2911 return this.setHBitInstruction(5);2912 case 0xED:2913 // SET 5, L2914 return this.setLBitInstruction(5);2915 case 0xEE:2916 // SET 5, (HL)2917 return this.setHLBitInstruction(5);2918 case 0xEF:2919 // SET 5, A2920 this.A = this.setBitInstruction(this.A, 5);2921 return 8;2922 default:2923 console.log(`Error: encountered an unsupported opcode of ${utils_1.displayAsHex(op)} ${utils_1.displayAsHex(nextInstrByte)} at address ${utils_1.displayAsHex(this.PC)}`);2924 return 0;2925 }2926 }2927 console.log(`Error: encountered an unsupported opcode of ${utils_1.displayAsHex(op)} at address ${utils_1.displayAsHex(this.PC)}`);2928 return 0;2929 }2930 sbcInstruction(value) {2931 const carryFlag = this.getFlag(exports.CARRY_FLAG) ? 1 : 0;2932 return this.subOneByte(this.A, value, carryFlag);2933 }2934 rstInstruction(rstAddr) {2935 this.pushAddressOnStack(this.PC + 1);2936 this.PC = rstAddr;2937 }2938 // NO BUGS HERE. LITERALLY A PERFECT IMPLEMENTATION2939 daaInstruction() {2940 if (!this.getFlag(exports.SUBTRACTION_FLAG)) {2941 if (this.getFlag(exports.HALF_CARRY_FLAG) || (this.A & 0x0F) > 9) {2942 this.A += 0x06;2943 }2944 if (this.getFlag(exports.CARRY_FLAG) || this.A > 0x9F) {2945 this.A += 0x60;2946 }2947 }2948 else {2949 if (this.getFlag(exports.HALF_CARRY_FLAG)) {2950 this.A = (this.A - 6) & 0xFF;2951 }2952 if (this.getFlag(exports.CARRY_FLAG)) {2953 this.A -= 0x60;2954 }2955 }2956 this.clearFlag(exports.HALF_CARRY_FLAG);2957 if ((this.A & 0x100) === 0x100) {2958 this.setFlag(exports.CARRY_FLAG);2959 }2960 this.A &= 0xFF;2961 this.clearFlag(exports.ZERO_FLAG);2962 if (this.A === 0) {2963 this.setFlag(exports.ZERO_FLAG);2964 }2965 }2966 pushAddressOnStack(returnAddr) {2967 const [higherByte, lowerByte] = this.split16BitValueIntoTwoBytes(returnAddr);2968 this.stackPush(higherByte);2969 this.stackPush(lowerByte);2970 }2971 rotateLeftThroughCarry(value) {2972 const currCarry = this.Flags.carryFlag;2973 this.Flags.carryFlag = (value & 0x80) === 0x80;2974 let updated = value << 1;2975 if (currCarry) {2976 updated ^= 0x01;2977 }2978 this.Flags.zeroFlag = updated === 0x00;2979 this.clearFlag(exports.SUBTRACTION_FLAG);2980 this.clearFlag(exports.HALF_CARRY_FLAG);2981 return updated;2982 }2983 rotateLeft(value) {2984 const bit7 = (value & 0x80) === 0x80;2985 let updated = value << 1;2986 this.clearFlag(exports.CARRY_FLAG);2987 if (bit7) {2988 this.setFlag(exports.CARRY_FLAG);2989 updated ^= 0x01;2990 }2991 this.Flags.zeroFlag = updated === 0x00;2992 this.clearFlag(exports.SUBTRACTION_FLAG);2993 this.clearFlag(exports.HALF_CARRY_FLAG);2994 return updated;2995 }2996 rotateRightThroughCarry(value) {2997 // 1001 10102998 // 0011 010[0] | [1]2999 const currCarry = this.Flags.carryFlag ? 0x80 : 0x00;3000 this.Flags.carryFlag = (value & 0x01) === 0x01;3001 let updated = value >>> 1;3002 if (currCarry === 0x80) {3003 updated ^= currCarry;3004 }3005 this.Flags.zeroFlag = updated === 0x00;3006 this.clearFlag(exports.SUBTRACTION_FLAG);3007 this.clearFlag(exports.HALF_CARRY_FLAG);3008 return updated;3009 }3010 rotateRight(value) {3011 const bit0 = (value & 0x01) === 0x01;3012 let updated = value >>> 1;3013 this.clearFlag(exports.CARRY_FLAG);3014 if (bit0) {3015 this.setFlag(exports.CARRY_FLAG);3016 updated ^= 0x80;3017 }3018 this.Flags.zeroFlag = updated === 0x00;3019 this.clearFlag(exports.SUBTRACTION_FLAG);3020 this.clearFlag(exports.HALF_CARRY_FLAG);3021 return updated;3022 }3023 // 0x28 - 0x2F3024 shiftRightIntoCarry(value) {3025 this.clearFlag(exports.CARRY_FLAG);3026 if ((value & 0x01) === 0x01) {3027 this.setFlag(exports.CARRY_FLAG);3028 }3029 const updated = (value >>> 1) | (value & 0x80);3030 this.Flags.zeroFlag = updated === 0x00;3031 this.clearFlag(exports.SUBTRACTION_FLAG);3032 this.clearFlag(exports.HALF_CARRY_FLAG);3033 return updated;3034 }3035 shiftLeftIntoCarry(value) {3036 this.clearFlag(exports.CARRY_FLAG);3037 if ((value & 0x80) === 0x80) {3038 this.setFlag(exports.CARRY_FLAG);3039 }3040 const updated = value << 1;3041 this.Flags.zeroFlag = updated === 0x00;3042 this.clearFlag(exports.SUBTRACTION_FLAG);3043 this.clearFlag(exports.HALF_CARRY_FLAG);3044 return updated;3045 }3046 shiftRight(value) {3047 this.clearFlag(exports.CARRY_FLAG);3048 if ((value & 0x01) === 0x01) {3049 this.setFlag(exports.CARRY_FLAG);3050 }3051 const updated = value >>> 1;3052 this.Flags.zeroFlag = updated === 0x00;3053 this.clearFlag(exports.SUBTRACTION_FLAG);3054 this.clearFlag(exports.HALF_CARRY_FLAG);3055 return updated;3056 }3057 updateZeroFlagWithBit(value, bit) {3058 const val = this.getBit(value, bit);3059 val === 1 ? this.setFlag(exports.ZERO_FLAG) : this.clearFlag(exports.ZERO_FLAG);3060 this.clearFlag(exports.SUBTRACTION_FLAG);3061 this.setFlag(exports.HALF_CARRY_FLAG);3062 this.PC += 2;3063 return 8;3064 }3065 getBitInstruction(value, bit) {3066 const updated = this.getBit(value, bit);3067 this.PC += 2;3068 }3069 getBit(value, bit) {3070 return ((0x1 << bit) & value) >> bit;3071 }3072 // has side-effect of modifying this.PC3073 setBitInstruction(value, bit) {3074 const updated = this.setBit(value, bit);3075 this.PC += 2;3076 return updated;3077 }3078 setHBitInstruction(bit) {3079 this.updateH(this.setBit(this.H(), bit));3080 this.PC += 2;3081 return 8;3082 }3083 setLBitInstruction(bit) {3084 this.updateL(this.setBit(this.L(), bit));3085 this.PC += 2;3086 return 8;3087 }3088 setHLBitInstruction(bit) {3089 const value = this.bus.readByte(this.HL);3090 const updated = this.setBit(value, bit);3091 this.bus.writeByte(this.HL, updated);3092 this.PC += 2;3093 return 16;3094 }3095 setBit(value, bit) {3096 return value | (0x1 << bit);3097 }3098 resetBitInstruction(value, bit) {3099 const updated = this.clearBit(value, 0);3100 this.PC += 2;3101 return updated;3102 }3103 resetHLBitInstruction(bit) {3104 const value = this.bus.readByte(this.HL);3105 const updated = this.clearBit(value, bit);3106 this.bus.writeByte(this.HL, updated);3107 this.PC += 2;3108 return 16;3109 }3110 clearBit(value, bit) {3111 const mask = 0x1 << bit;3112 return value & ~mask;3113 }3114 executeAnd(operand) {3115 this.A = this.A & operand;3116 this.updateZeroFlag(this.A);3117 this.clearFlag(exports.SUBTRACTION_FLAG);3118 this.setFlag(exports.HALF_CARRY_FLAG);3119 this.clearFlag(exports.CARRY_FLAG);3120 return 4; // consumes 4 cycles3121 }3122 // TODO: Only used by 0xF6 opcode3123 executeOr(operand) {3124 this.A = this.A | operand;3125 this.updateZeroFlag(this.A);3126 this.clearFlag(exports.SUBTRACTION_FLAG);3127 this.clearFlag(exports.HALF_CARRY_FLAG);3128 this.clearFlag(exports.CARRY_FLAG);...
vm.js
Source:vm.js
1/* eslint-disable import/no-cycle */2import { message } from 'antd';3import moment from 'moment-timezone';4import { VMSelectors } from '../reducers';5export const ACTION_RESET = 'vm:ACTION_RESET';6export const ACTION_RESTART = 'vm:ACTION_RESTART';7export const ACTION_SAVE_INITIAL_CODE = 'vm:ACTION_SAVE_INITIAL_CODE';8export const ACTION_SAVE_PROGRAM_STACK = 'vm:ACTION_SAVE_PROGRAM_STACK';9export const ACTION_SAVE_INSTRUCTION_POINTER =10 'vm:ACTION_SAVE_INSTRUCTION_POINTER';11export const ACTION_SAVE_DATA_POINTER = 'vm:ACTION_SAVE_DATA_POINTER';12export const ACTION_INSERT_DATA_STACK = 'vm:ACTION_INSERT_DATA_STACK';13export const ACTION_SAVE_WAITING_INPUT = 'vm:ACTION_SAVE_WAITING_INPUT';14export const ACTION_SAVE_EXECUTING = 'vm:ACTION_SAVE_EXECUTING';15export const ACTION_SAVE_RUNNING_EXECUTION = 'vm:ACTION_SAVE_RUNNING_EXECUTION';16export const ACTION_INSERT_CONSOLE_STACK = 'vm:ACTION_INSERT_CONSOLE_STACK';17export const ACTION_SAVE_BREAKPOINTS = 'vm:ACTION_SAVE_BREAKPOINTS';18export const reset = () => ({ type: ACTION_RESET });19export const restart = () => ({ type: ACTION_RESTART });20export const saveInitialCode = (code) => ({21 type: ACTION_SAVE_INITIAL_CODE,22 payload: code,23});24export const saveProgramStack = (array) => ({25 type: ACTION_SAVE_PROGRAM_STACK,26 payload: array,27});28export const saveInstructionPointer = (value) => ({29 type: ACTION_SAVE_INSTRUCTION_POINTER,30 payload: value,31});32export const saveDataPointer = (value) => ({33 type: ACTION_SAVE_DATA_POINTER,34 payload: value,35});36export const saveExecuting = (value) => ({37 type: ACTION_SAVE_EXECUTING,38 payload: value,39});40export const saveRunningExecution = (value) => ({41 type: ACTION_SAVE_RUNNING_EXECUTION,42 payload: value,43});44export const saveBreakpoints = (array) => ({45 type: ACTION_SAVE_BREAKPOINTS,46 payload: array,47});48// Help Functions49export const incrementInstructionPointer = () => (dispatch, getState) => {50 const instructionPointer = VMSelectors.getInstructionPointer(getState());51 dispatch(saveInstructionPointer(instructionPointer + 1));52};53export const decrementInstructionPointer = () => (dispatch, getState) => {54 const instructionPointer = VMSelectors.getInstructionPointer(getState());55 dispatch(saveInstructionPointer(instructionPointer - 1));56};57export const incrementDataPointer = () => (dispatch, getState) => {58 const dataPointer = VMSelectors.getDataPointer(getState());59 dispatch(saveDataPointer(dataPointer + 1));60};61export const decrementDataPointer = () => (dispatch, getState) => {62 const dataPointer = VMSelectors.getDataPointer(getState());63 dispatch(saveDataPointer(dataPointer - 1));64};65export const insertDataStack = (value, increment = 0) => (66 dispatch,67 getState68) => {69 const dataPointer = VMSelectors.getDataPointer(getState());70 dispatch({71 type: ACTION_INSERT_DATA_STACK,72 payload: { value, index: dataPointer + increment },73 });74};75export const insertConsoleStack = (value) => (dispatch) => {76 dispatch({77 type: ACTION_INSERT_CONSOLE_STACK,78 payload: {79 time: moment().format('HH:mm'),80 message: value,81 },82 });83};84// Execution Functions85export const executeLDC = (k) => (dispatch, getState) => {86 dispatch(incrementDataPointer());87 const dataPointer = VMSelectors.getDataPointer(getState());88 dispatch(insertDataStack({ value: k, index: dataPointer }));89};90export const executeLDV = (n) => (dispatch, getState) => {91 dispatch(incrementDataPointer());92 const dataPointer = VMSelectors.getDataPointer(getState());93 dispatch(94 insertDataStack({95 value: VMSelectors.getDataStackByPosition(getState(), n).value,96 index: dataPointer,97 })98 );99};100export const executeADD = () => (dispatch, getState) => {101 const dataPointer = VMSelectors.getDataPointer(getState());102 const lastData = VMSelectors.getDataStackByPosition(103 getState(),104 dataPointer - 1105 );106 const actualData = VMSelectors.getDataStackByPosition(107 getState(),108 dataPointer109 );110 const newData = {111 value: lastData.value + actualData.value,112 index: dataPointer - 1,113 };114 dispatch(insertDataStack(newData, -1));115 dispatch(decrementDataPointer());116};117export const executeSUB = () => (dispatch, getState) => {118 const dataPointer = VMSelectors.getDataPointer(getState());119 const lastData = VMSelectors.getDataStackByPosition(120 getState(),121 dataPointer - 1122 );123 const actualData = VMSelectors.getDataStackByPosition(124 getState(),125 dataPointer126 );127 const newData = {128 value: lastData.value - actualData.value,129 index: dataPointer - 1,130 };131 dispatch(insertDataStack(newData, -1));132 dispatch(decrementDataPointer());133};134export const executeMULT = () => (dispatch, getState) => {135 const dataPointer = VMSelectors.getDataPointer(getState());136 const lastData = VMSelectors.getDataStackByPosition(137 getState(),138 dataPointer - 1139 );140 const actualData = VMSelectors.getDataStackByPosition(141 getState(),142 dataPointer143 );144 const newData = {145 value: lastData.value * actualData.value,146 index: dataPointer - 1,147 };148 dispatch(insertDataStack(newData, -1));149 dispatch(decrementDataPointer());150};151export const executeDIVI = () => (dispatch, getState) => {152 const dataPointer = VMSelectors.getDataPointer(getState());153 const lastData = VMSelectors.getDataStackByPosition(154 getState(),155 dataPointer - 1156 );157 const actualData = VMSelectors.getDataStackByPosition(158 getState(),159 dataPointer160 );161 const newData = {162 value: lastData.value / actualData.value,163 index: dataPointer - 1,164 };165 dispatch(insertDataStack(newData, -1));166 dispatch(decrementDataPointer());167};168export const executeINV = () => (dispatch, getState) => {169 const dataPointer = VMSelectors.getDataPointer(getState()); // s170 const actualData = VMSelectors.getDataStackByPosition(171 getState(),172 dataPointer173 ); // M[s]174 const newData = {175 value: -actualData.value,176 index: dataPointer,177 };178 dispatch(insertDataStack(newData));179};180export const executeAND = () => (dispatch, getState) => {181 const dataPointer = VMSelectors.getDataPointer(getState()); // s182 const lastData = VMSelectors.getDataStackByPosition(183 getState(),184 dataPointer - 1185 ); // M[s - 1]186 const actualData = VMSelectors.getDataStackByPosition(187 getState(),188 dataPointer189 ); // M[s]190 if (lastData.value === 1 && actualData.value === 1) {191 dispatch(insertDataStack({ value: 1, index: dataPointer - 1 }, -1));192 } else {193 dispatch(insertDataStack({ value: 0, index: dataPointer - 1 }, -1));194 }195 dispatch(decrementDataPointer());196};197export const executeOR = () => (dispatch, getState) => {198 const dataPointer = VMSelectors.getDataPointer(getState()); // s199 const lastData = VMSelectors.getDataStackByPosition(200 getState(),201 dataPointer - 1202 ); // M[s - 1]203 const actualData = VMSelectors.getDataStackByPosition(204 getState(),205 dataPointer206 ); // M[s]207 if (lastData.value === 1 || actualData.value === 1) {208 dispatch(insertDataStack({ value: 1, index: dataPointer - 1 }, -1));209 } else {210 dispatch(insertDataStack({ value: 0, index: dataPointer - 1 }, -1));211 }212 dispatch(decrementDataPointer());213};214export const executeNEG = () => (dispatch, getState) => {215 const dataPointer = VMSelectors.getDataPointer(getState()); // s216 const actualData = VMSelectors.getDataStackByPosition(217 getState(),218 dataPointer219 ); // M[s]220 const newData = {221 value: 1 - actualData.value,222 index: dataPointer,223 };224 dispatch(insertDataStack(newData));225};226export const executeCME = () => (dispatch, getState) => {227 const dataPointer = VMSelectors.getDataPointer(getState()); // s228 const actualData = VMSelectors.getDataStackByPosition(229 getState(),230 dataPointer231 ); // M[s]232 const lastData = VMSelectors.getDataStackByPosition(233 getState(),234 dataPointer - 1235 ); // M[s - 1]236 if (lastData.value < actualData.value) {237 dispatch(insertDataStack({ value: 1, index: dataPointer - 1 }, -1));238 } else {239 dispatch(insertDataStack({ value: 0, index: dataPointer - 1 }, -1));240 }241 dispatch(decrementDataPointer());242};243export const executeCMA = () => (dispatch, getState) => {244 const dataPointer = VMSelectors.getDataPointer(getState()); // s245 const actualData = VMSelectors.getDataStackByPosition(246 getState(),247 dataPointer248 ); // M[s]249 const lastData = VMSelectors.getDataStackByPosition(250 getState(),251 dataPointer - 1252 ); // M[s - 1]253 if (lastData.value > actualData.value) {254 dispatch(insertDataStack({ value: 1, index: dataPointer - 1 }, -1));255 } else {256 dispatch(insertDataStack({ value: 0, index: dataPointer - 1 }, -1));257 }258 dispatch(decrementDataPointer());259};260export const executeCEQ = () => (dispatch, getState) => {261 const dataPointer = VMSelectors.getDataPointer(getState()); // s262 const actualData = VMSelectors.getDataStackByPosition(263 getState(),264 dataPointer265 ); // M[s]266 const lastData = VMSelectors.getDataStackByPosition(267 getState(),268 dataPointer - 1269 ); // M[s - 1]270 if (lastData.value === actualData.value) {271 dispatch(insertDataStack({ value: 1, index: dataPointer - 1 }, -1));272 } else {273 dispatch(insertDataStack({ value: 0, index: dataPointer - 1 }, -1));274 }275 dispatch(decrementDataPointer());276};277export const executeCDIF = () => (dispatch, getState) => {278 const dataPointer = VMSelectors.getDataPointer(getState()); // s279 const actualData = VMSelectors.getDataStackByPosition(280 getState(),281 dataPointer282 ); // M[s]283 const lastData = VMSelectors.getDataStackByPosition(284 getState(),285 dataPointer - 1286 ); // M[s - 1]287 if (lastData.value !== actualData.value) {288 dispatch(insertDataStack({ value: 1, index: dataPointer - 1 }, -1));289 } else {290 dispatch(insertDataStack({ value: 0, index: dataPointer - 1 }, -1));291 }292 dispatch(decrementDataPointer());293};294export const executeCMEQ = () => (dispatch, getState) => {295 const dataPointer = VMSelectors.getDataPointer(getState()); // s296 const actualData = VMSelectors.getDataStackByPosition(297 getState(),298 dataPointer299 ); // M[s]300 const lastData = VMSelectors.getDataStackByPosition(301 getState(),302 dataPointer - 1303 ); // M[s - 1]304 if (lastData.value <= actualData.value) {305 dispatch(insertDataStack({ value: 1, index: dataPointer - 1 }, -1));306 } else {307 dispatch(insertDataStack({ value: 0, index: dataPointer - 1 }, -1));308 }309 dispatch(decrementDataPointer());310};311export const executeCMAQ = () => (dispatch, getState) => {312 const dataPointer = VMSelectors.getDataPointer(getState()); // s313 const actualData = VMSelectors.getDataStackByPosition(314 getState(),315 dataPointer316 ); // M[s]317 const lastData = VMSelectors.getDataStackByPosition(318 getState(),319 dataPointer - 1320 ); // M[s - 1]321 if (lastData.value >= actualData.value) {322 dispatch(insertDataStack({ value: 1, index: dataPointer - 1 }, -1));323 } else {324 dispatch(insertDataStack({ value: 0, index: dataPointer - 1 }, -1));325 }326 dispatch(decrementDataPointer());327};328export const executeSTR = (n) => (dispatch, getState) => {329 const dataPointer = VMSelectors.getDataPointer(getState());330 const actualData = VMSelectors.getDataStackByPosition(331 getState(),332 dataPointer333 );334 dispatch(335 insertDataStack({ value: actualData.value, index: n }, n - dataPointer)336 );337 dispatch(decrementDataPointer());338};339export const executeJMP = (p) => (dispatch) => {340 dispatch(saveInstructionPointer(p));341};342export const executeJMPF = (p) => (dispatch, getState) => {343 const dataPointer = VMSelectors.getDataPointer(getState());344 const actualData = VMSelectors.getDataStackByPosition(345 getState(),346 dataPointer347 );348 if (actualData.value === 0) {349 dispatch(saveInstructionPointer(p));350 } else {351 dispatch(incrementInstructionPointer());352 }353 dispatch(decrementDataPointer());354};355export const requestUserInput = () => (dispatch) => {356 dispatch({ type: ACTION_SAVE_WAITING_INPUT, payload: true });357 dispatch(insertConsoleStack('Insira um valor:'));358 message.info('Entre com um valor no terminal');359};360export const executePRN = () => (dispatch, getState) => {361 const dataPointer = VMSelectors.getDataPointer(getState());362 const actualData = VMSelectors.getDataStackByPosition(363 getState(),364 dataPointer365 );366 dispatch(insertConsoleStack(actualData.value));367 dispatch(decrementDataPointer());368};369export const executeSTART = () => (dispatch) => {370 dispatch(saveDataPointer(-1));371 dispatch(saveExecuting(true));372};373export const executeHLT = () => (dispatch) => {374 dispatch(saveExecuting(false));375 dispatch(saveRunningExecution(false));376};377export const executeALLOC = (m, n) => (dispatch, getState) => {378 for (let k = 0; k < n; k += 1) {379 dispatch(incrementDataPointer());380 const dataPointer = VMSelectors.getDataPointer(getState());381 const data = VMSelectors.getDataStackByPosition(getState(), m + k);382 dispatch(383 insertDataStack({ value: data ? data.value : 0, index: dataPointer })384 );385 }386};387export const executeDALLOC = (m, n) => (dispatch, getState) => {388 for (let k = n - 1; k >= 0; k -= 1) {389 const dataPointer = VMSelectors.getDataPointer(getState());390 const actualData = VMSelectors.getDataStackByPosition(391 getState(),392 dataPointer393 );394 dispatch(395 insertDataStack(396 { value: actualData.value, index: m + k },397 m + k - dataPointer398 )399 );400 dispatch(decrementDataPointer());401 }402};403export const executeCALL = (p) => (dispatch, getState) => {404 dispatch(incrementDataPointer());405 const instructionPointer = VMSelectors.getInstructionPointer(getState());406 const dataPointer = VMSelectors.getDataPointer(getState());407 dispatch(408 insertDataStack({ value: instructionPointer + 1, index: dataPointer })409 );410 dispatch(saveInstructionPointer(p));411};412export const executeRETURN = () => (dispatch, getState) => {413 const dataPointer = VMSelectors.getDataPointer(getState());414 const actualData = VMSelectors.getDataStackByPosition(415 getState(),416 dataPointer417 );418 dispatch(saveInstructionPointer(actualData.value));419 dispatch(decrementDataPointer());420};421export const executeInstruction = () => (dispatch, getState) => {422 const instructionPointer = VMSelectors.getInstructionPointer(getState());423 const instruction = VMSelectors.getProgramStack(getState())[424 instructionPointer425 ];426 switch (instruction.command) {427 case 'START':428 dispatch(executeSTART());429 dispatch(incrementInstructionPointer());430 break;431 case 'LDC':432 dispatch(executeLDC(instruction.var1));433 dispatch(incrementInstructionPointer());434 break;435 case 'LDV':436 dispatch(executeLDV(instruction.var1));437 dispatch(incrementInstructionPointer());438 break;439 case 'ADD':440 dispatch(executeADD());441 dispatch(incrementInstructionPointer());442 break;443 case 'SUB':444 dispatch(executeSUB());445 dispatch(incrementInstructionPointer());446 break;447 case 'MULT':448 dispatch(executeMULT());449 dispatch(incrementInstructionPointer());450 break;451 case 'DIVI':452 dispatch(executeDIVI());453 dispatch(incrementInstructionPointer());454 break;455 case 'INV':456 dispatch(executeINV());457 dispatch(incrementInstructionPointer());458 break;459 case 'AND':460 dispatch(executeAND());461 dispatch(incrementInstructionPointer());462 break;463 case 'OR':464 dispatch(executeOR());465 dispatch(incrementInstructionPointer());466 break;467 case 'NEG':468 dispatch(executeNEG());469 dispatch(incrementInstructionPointer());470 break;471 case 'CME':472 dispatch(executeCME());473 dispatch(incrementInstructionPointer());474 break;475 case 'CMA':476 dispatch(executeCMA());477 dispatch(incrementInstructionPointer());478 break;479 case 'CEQ':480 dispatch(executeCEQ());481 dispatch(incrementInstructionPointer());482 break;483 case 'CDIF':484 dispatch(executeCDIF());485 dispatch(incrementInstructionPointer());486 break;487 case 'CMEQ':488 dispatch(executeCMEQ());489 dispatch(incrementInstructionPointer());490 break;491 case 'CMAQ':492 dispatch(executeCMAQ());493 dispatch(incrementInstructionPointer());494 break;495 case 'STR':496 dispatch(executeSTR(instruction.var1));497 dispatch(incrementInstructionPointer());498 break;499 case 'JMP':500 dispatch(executeJMP(instruction.jumpIndex));501 break;502 case 'JMPF':503 dispatch(executeJMPF(instruction.jumpIndex));504 break;505 case 'RD':506 dispatch(requestUserInput());507 break;508 case 'PRN':509 dispatch(executePRN());510 dispatch(incrementInstructionPointer());511 break;512 case 'ALLOC':513 dispatch(executeALLOC(instruction.var1, instruction.var2));514 dispatch(incrementInstructionPointer());515 break;516 case 'DALLOC':517 dispatch(executeDALLOC(instruction.var1, instruction.var2));518 dispatch(incrementInstructionPointer());519 break;520 case 'CALL':521 dispatch(executeCALL(instruction.jumpIndex));522 break;523 case 'RETURN':524 dispatch(executeRETURN());525 break;526 case 'HLT':527 dispatch(executeHLT());528 break;529 default:530 dispatch(incrementInstructionPointer());531 break;532 }533};534export const execute = () => (dispatch, getState) => {535 dispatch(saveRunningExecution(true));536 const instructionPointer = VMSelectors.getInstructionPointer(getState());537 if (instructionPointer === 0) {538 dispatch(executeInstruction());539 }540 while (VMSelectors.getIsExecuting(getState())) {541 const breakpoints = VMSelectors.getBreakpoints(getState());542 const actualI = VMSelectors.getInstructionPointer(getState());543 if (breakpoints.findIndex((index) => index === actualI) !== -1) {544 dispatch(saveRunningExecution(false));545 break;546 }547 dispatch(executeInstruction());548 const isWaitingUserInput = VMSelectors.getIsWaitingInput(getState());549 if (isWaitingUserInput) break;550 }551};552export const executeRD = (input, isRunningExecution) => (553 dispatch,554 getState555) => {556 dispatch({ type: ACTION_SAVE_WAITING_INPUT, payload: false });557 dispatch(incrementDataPointer());558 const dataPointer = VMSelectors.getDataPointer(getState());559 dispatch(insertDataStack({ value: input, index: dataPointer }));560 dispatch(incrementInstructionPointer());561 dispatch(insertConsoleStack(`Valor inserido: ${input}`));562 if (isRunningExecution) dispatch(execute());...
addAdditionalPromiseMethods.js
Source:addAdditionalPromiseMethods.js
1function addAdditionalPromiseMethods(promise, expect, subject) {2 promise.and = function (...args) {3 function executeAnd() {4 if (expect.findTypeOf(args[0]).is('expect.it')) {5 return addAdditionalPromiseMethods(args[0](subject), expect, subject);6 } else {7 return expect(subject, ...args);8 }9 }10 if (this.isFulfilled()) {11 return executeAnd();12 } else {13 return addAdditionalPromiseMethods(14 this.then(executeAnd),15 expect,16 subject17 );18 }19 };20 return promise;21}...
Using AI Code Generation
1const unexpected = require('unexpected');2const unexpectedSinon = require('unexpected-sinon');3const sinon = require('sinon');4const expect = unexpected.clone().use(unexpectedSinon);5const obj = {6 method: function() {7 return 'result';8 }9};10expect(obj.method, 'was not called');11expect(obj.method, 'was called once');12expect(obj.method, 'was called twice');13expect(obj.method, 'was called thrice');14expect(obj.method, 'was called 4 times');15expect(obj.method, 'was called 5 times');16expect(obj.method, 'was called 6 times');17expect(obj.method, 'was called 7 times');18expect(obj.method, 'was called 8 times');19expect(obj.method, 'was called 9 times');20expect(obj.method, 'was called 10 times');21expect(obj.method, 'was called 11 times');22expect(obj.method, 'was called 12 times');23expect(obj.method, 'was called 13 times');24expect(obj.method, 'was called 14 times');25expect(obj.method, 'was called 15 times');26expect(obj.method, 'was called 16 times');27expect(obj.method, 'was called 17 times');28expect(obj.method, 'was called 18 times');29expect(obj.method, 'was called 19 times');30expect(obj.method, 'was called 20 times');31expect(obj.method, 'was called 21 times');32expect(obj.method, 'was called 22 times');33expect(obj.method, 'was called 23 times');34expect(obj.method, 'was called 24 times');35expect(obj.method, 'was called 25 times');36expect(obj.method, 'was called 26 times');37expect(obj.method, 'was called 27 times');38expect(obj.method, 'was called 28 times');39expect(obj.method, 'was called 29 times');40expect(obj.method, 'was called 30 times');41expect(obj.method, 'was called 31 times');42expect(obj.method, 'was called 32 times');43expect(obj.method, 'was called 33 times');44expect(obj.method, 'was called 34 times');45expect(obj.method, 'was called 35 times');46expect(obj.method, 'was called 36 times');47expect(obj.method, 'was called 37 times');48expect(obj.method, 'was called 38 times');49expect(obj.method, 'was called 39 times');50expect(obj.method, 'was called
Using AI Code Generation
1var unexpected = require('unexpected');2var unexpectedSinon = require('unexpected-sinon');3var sinon = require('sinon');4var expect = unexpected.clone().use(unexpectedSinon);5var myObject = {6 myMethod: function () {7 return 'Hello World';8 }9};10var mySpy = sinon.spy(myObject, 'myMethod');11expect(mySpy, 'was called');12expect(mySpy, 'was called once');13expect(mySpy, 'was called twice');14expect(mySpy, 'was called thrice');15expect(mySpy, 'was called 4 times');16expect(mySpy, 'was called 5 times');17expect(mySpy, 'was called 6 times');18expect(mySpy, 'was called 7 times');19expect(mySpy, 'was called 8 times');20expect(mySpy, 'was called 9 times');21expect(mySpy, 'was called 10 times');22expect(mySpy, 'was called 11 times');23expect(mySpy, 'was called 12 times');24expect(mySpy, 'was called 13 times');25expect(mySpy, 'was called 14 times');26expect(mySpy, 'was called 15 times');27expect(mySpy, 'was called 16 times');28expect(mySpy, 'was called 17 times');29expect(mySpy, 'was called 18 times');30expect(mySpy, 'was called 19 times');31expect(mySpy, 'was called 20 times');32expect(mySpy, 'was called 21 times');33expect(mySpy, 'was called 22 times');34expect(mySpy, 'was called 23 times');35expect(mySpy, 'was called 24 times');36expect(mySpy, 'was called 25 times');37expect(mySpy, 'was called 26 times');38expect(mySpy, 'was called 27 times');39expect(mySpy, 'was called 28 times');40expect(mySpy, 'was called 29 times');41expect(mySpy, 'was called 30 times');42expect(mySpy, 'was called 31 times');43expect(mySpy, 'was called 32 times');44expect(mySpy, 'was called 33 times');45expect(mySpy, 'was called 34 times');46expect(mySpy, 'was called 35 times');47expect(mySpy, 'was called 36 times');48expect(mySpy, 'was called 37 times');49expect(mySpy, 'was called 38 times');50expect(mySpy,
Using AI Code Generation
1var exec = require('child_process').exec;2var expect = require('unexpected');3expect.addAssertion('<string> [not] to execute and [exhaustively] satisfy <any>', function (expect, subject, value) {4 return expect.promise(function (run) {5 exec(subject, function (error, stdout, stderr) {6 if (error) {7 run(function () {8 expect.fail({9 diff: function (output, diff, inspect, equal) {10 return diff(stderr, '');11 }12 });13 });14 } else {15 run(function () {16 expect(stdout, 'to equal', value);17 });18 }19 });20 });21});22var expect = require('unexpected');23var exec = require('child_process').exec;24describe('test', function () {25 it('should execute and satisfy', function (done) {26 expect('node test.js', 'to execute and satisfy', 'hello');27 done();28 });29});30var expect = require('unexpected');31var exec = require('child_process').exec;32describe('test', function () {33 it('should execute and satisfy', function (done) {34 expect('node test.js', 'to execute and satisfy', 'hello');35 done();36 });37});38var expect = require('unexpected');39var exec = require('child_process').exec;40describe('test', function () {41 it('should execute and satisfy', function (done) {42 expect('node test.js', 'to execute and satisfy', 'hello');43 done();44 });45});46var expect = require('unexpected');47var exec = require('child_process').exec;48describe('test', function () {49 it('should execute and satisfy', function (done) {50 expect('node test.js', 'to execute and satisfy', 'hello');51 done();52 });53});54var expect = require('unexpected');55var exec = require('child_process').exec;56describe('test', function () {57 it('should execute and satisfy', function (done) {58 expect('node test.js', 'to execute and satisfy', 'hello');59 done();60 });61});62var expect = require('unexpected');63var exec = require('child_process').exec;64describe('test', function () {65 it('should execute and satisfy', function (done) {66 expect('node
Using AI Code Generation
1var expect = require('unexpected').clone().use(require('unexpected-express'));2var app = require('./app');3expect(app, 'to yield exchange', {4});5var express = require('express');6var app = express();7app.get('/', function (req, res) {8 res.send('Hello World!');9});10module.exports = app;11 Error: expected [Function] to yield exchange { request: 'GET /', response: 200 } but got error 'TypeError: Cannot read property 'statusCode' of undefined'12var expect = require('unexpected').clone().use(require('unexpected-express'));13var app = require('./app');14expect(app, 'to yield exchange', {15});16 Error: expected [Function] to yield exchange { request: 'GET /', response: 200 } but got error 'TypeError: Cannot read property 'statusCode' of undefined'17var expect = require('unexpected').clone().use(require('unexpected-express'));18var app = require('./app');19expect(app, 'to yield exchange', {20});21 Error: expected [Function] to yield exchange { request: 'GET /', response: 200 } but got error 'TypeError: Cannot read property 'statusCode' of undefined'22var expect = require('unexpected').clone().use(require('unexpected-express'));23var app = require('./app');24expect(app, 'to yield exchange', {25});26 Error: expected [Function] to yield exchange { request: 'GET /', response: 200 } but got error 'TypeError: Cannot read property 'statusCode' of undefined'
Using AI Code Generation
1var expect = require('unexpected').clone();2expect.output.preferredWidth = 80;3expect.addAssertion('<string> to execute and output <string>', function (expect, subject, value) {4 var result = expect.execute(subject, [], {env: process.env});5 return expect(result.stdout, 'to equal', value);6});7expect('node -e "console.log(\'hello world\')"', 'to execute and output', 'hello world');8var expect = require('unexpected').clone();9expect.output.preferredWidth = 80;10expect.addAssertion('<string> to execute and output <string>', function (expect, subject, value) {11 var result = expect.executeAnd(function (result) {12 return expect(result.stdout, 'to equal', value);13 }, subject, [], {env: process.env});14 return result;15});16expect('node -e "console.log(\'hello world\')"', 'to execute and output', 'hello world');
Using AI Code Generation
1var unexpected = require('unexpected');2var expect = unexpected.clone();3expect.addAssertion('<any> to be <any>', function (expect, subject, value) {4 expect(subject, 'to equal', value);5});6expect.addAssertion('<any> to be <any>', function (expect, subject, value) {7 expect(subject, 'to equal', value);8});9expect('foo', 'to be', 'bar');10expect('foo', 'to be', 'bar');11var unexpected = require('unexpected');12var expect = unexpected.clone();13expect.addAssertion('<any> to be <any>', function (expect, subject, value) {14 expect(subject, 'to equal', value);15});16expect.addAssertion('<any> to be <any>', function (expect, subject, value) {17 expect(subject, 'to equal', value);18});19expect('foo', 'to be', 'bar');20expect('foo', 'to be', 'bar');21var unexpected = require('unexpected');22var expect = unexpected.clone();23expect.addAssertion('<any> to be <any>', function (expect, subject, value) {24 expect(subject, 'to equal', value);25});26expect.addAssertion('<any> to be <any>', function (expect, subject, value) {27 expect(subject, 'to equal', value);28});29expect('foo', 'to be', 'bar');30expect('foo', 'to be', 'bar');31var unexpected = require('unexpected');32var expect = unexpected.clone();33expect.addAssertion('<any> to be <any>', function (expect, subject, value) {34 expect(subject, 'to equal', value);35});36expect.addAssertion('<any> to be <any>', function (expect, subject, value) {37 expect(subject, 'to equal', value);38});39expect('foo', 'to be', 'bar');40expect('foo', 'to be', 'bar');
Using AI Code Generation
1var exec = require('child_process').exec;2var expect = require('unexpected').clone();3expect.addAssertion('<function> to execute and', function (expect, subject) {4 return expect.promise(function (run) {5 exec('node ' + subject, function (err, stdout, stderr) {6 if (err) {7 run(err);8 } else {9 run(null, stdout);10 }11 });12 });13});14expect(function () {15 console.log('hello');16}, 'to execute and', 'to equal', 'hello');17var exec = require('child_process').exec;18var expect = require('unexpected').clone();19expect.addAssertion('<function> to execute and', function (expect, subject) {20 return expect.promise(function (run) {21 exec('node ' + subject, function (err, stdout, stderr) {22 if (err) {23 run(err);24 } else {25 run(null, stdout);26 }27 });28 });29});30expect(function () {31 console.log('hello');32}, 'to execute and', 'to equal', 'hello');33var exec = require('child_process').exec;34var expect = require('unexpected').clone();35expect.addAssertion('<function> to execute and', function (expect, subject) {36 return expect.promise(function (run) {37 exec('node ' + subject, function (err, stdout, stderr) {38 if (err) {39 run(err);40 } else {41 run(null, stdout);42 }43 });44 });45});46expect(function () {47 console.log('hello');48}, 'to execute and', 'to equal', 'hello');
Using AI Code Generation
1const expect = require('unexpected')2 .clone()3 .use(require('unexpected-mitm'));4const unexpectedMitm = require('unexpected-mitm');5expect.addAssertion('<any> to be an array of <number>', (expect, subject) => {6 expect(subject, 'to be an array');7 expect(subject, 'to have items satisfying', 'to be a number');8});9expect.addAssertion('<any> to be an array of <string>', (expect, subject) => {10 expect(subject, 'to be an array');11 expect(subject, 'to have items satisfying', 'to be a string');12});13expect.addAssertion('<any> to be an array of <function>', (expect, subject) => {14 expect(subject, 'to be an array');15 expect(subject, 'to have items satisfying', 'to be a function');16});17expect.addAssertion('<any> to be an array of <object>', (expect, subject) => {18 expect(subject, 'to be an array');19 expect(subject, 'to have items satisfying', 'to be an object');20});21expect.addAssertion('<any> to be an array of <array>', (expect, subject) => {22 expect(subject, 'to be an array');23 expect(subject, 'to have items satisfying', 'to be an array');24});25expect.addAssertion('<any> to be an array of <any>', (expect, subject) => {26 expect(subject, 'to be an array');27});28describe('test', () => {29 it('should pass', () => {30 return expect(31 unexpectedMitm.executeAnd(32 () => {33 return [1, 2, 3];34 },35 (it) => {36 return expect(it, 'to be an array of number');37 }38 );39 });40 it('should fail', () => {41 return expect(42 unexpectedMitm.executeAnd(43 () => {44 return [1, '2', 3];45 },46 (it) => {47 return expect(it, 'to be an array of number');48 }49 );50 });51});521 passing (24ms)
Using AI Code Generation
1var expect = require('unexpected').clone();2var result = expect.executeAnd(function () {3 return 1 + 1;4}, 'to equal', 2);5var expect = require('unexpected').clone();6var result = expect.executeAnd(function () {7 return 1 + 1;8}, 'to equal', 3);9var expect = require('unexpected').clone();10var result = expect.executeAnd(function () {11 return 1 + 1;12}, 'to equal', 3, 'with error', 'expected 2 to equal 3');13var expect = require('unexpected').clone();14var result = expect.executeAnd(function () {15 return 1 + 1;16}, 'to equal', 3, 'with error', 'expected 2 to equal 3');17var expect = require('unexpected').clone();18var result = expect.executeAnd(function () {19 return 1 + 1;20}, 'to equal', 2, 'with error', 'expected 2 to equal 3');21var expect = require('unexpected').clone();22var result = expect.executeAnd(function () {23 return 1 + 1;24}, 'to equal', 2, 'with error', 'expected 2 to equal 3');25var expect = require('unexpected').clone();26var result = expect.executeAnd(function () {27 return 1 + 1;28}, 'to equal', 3, 'with error', 'expected 2 to equal 3');29var expect = require('unexpected').clone();
Using AI Code Generation
1var unexpected = require('unexpected');2var expect = unexpected.clone();3var executeAnd = function (func) {4 var originalIt = it;5 it = function (description, test) {6 it = originalIt;7 test();8 };9 func();10};11describe('some test', function () {12 executeAnd(function () {13 it('should do something', function () {14 expect(1, 'to equal', 1);15 });16 });17});18var unexpected = require('unexpected');19var expect = unexpected.clone();20var executeAnd = function (func) {21 var originalIt = it;22 it = function (description, test) {23 it = originalIt;24 test();25 };26 func();27};28describe('some test', function () {29 executeAnd(function () {30 it('should do something', function () {31 expect(1, 'to equal', 1);32 });33 });34});
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!