comparison clojure/com/aurellem/gb/assembly.clj @ 184:d585b91de06c

Added a worlds directory for worldbuilding practice, and added some assembly-reading utilities.
author Dylan Holmes <ocsenave@gmail.com>
date Thu, 22 Mar 2012 06:58:18 -0500
parents 5e34473ac774
children 19fd38fe376e
comparison
equal deleted inserted replaced
183:5e34473ac774 184:d585b91de06c
1436 (view-memory bytes-written) 1436 (view-memory bytes-written)
1437 1437
1438 (#(do (println "memory from 0xC00F to 0xC01F:" 1438 (#(do (println "memory from 0xC00F to 0xC01F:"
1439 (subvec (vec (memory %)) 0xC00F 0xC01F)) %))))) 1439 (subvec (vec (memory %)) 0xC00F 0xC01F)) %)))))
1440 1440
1441
1442
1443
1444
1445
1446 ;;; ASSEMBLY-READING UTILITIES
1447
1448 (def opcodes
1449 [
1450 "NOP"
1451 "LD BC,nn"
1452 "LD (BC),A"
1453 "INC BC"
1454 "INC B"
1455 "DEC B"
1456 "LD B,n"
1457 "RLC A"
1458 "LD (nn),SP"
1459 "ADD HL,BC"
1460 "LD A,(BC)"
1461 "DEC BC"
1462 "INC C"
1463 "DEC C"
1464 "LD C,n"
1465 "RRC A"
1466
1467 "STOP"
1468 "LD DE,nn"
1469 "LD (DE),A"
1470 "INC DE"
1471 "INC D"
1472 "DEC D"
1473 "LD D,n"
1474 "RL A"
1475 "JR n"
1476 "ADD HL,DE"
1477 "LD A,(DE)"
1478 "DEC DE"
1479 "INC E"
1480 "DEC E"
1481 "LD E,n"
1482 "RR A"
1483
1484 "JR NZ,n"
1485 "LD HL,nn"
1486 "LDI (HL),A"
1487 "INC HL"
1488 "INC H"
1489 "DEC H"
1490 "LD H,n"
1491 "DAA"
1492 "JR Z,n"
1493 "ADD HL,HL"
1494 "LDI A,(HL)"
1495 "DEC HL"
1496 "INC L"
1497 "DEC L"
1498 "LD L,n"
1499 "CPL"
1500
1501 "JR NC,n"
1502 "LD SP,nn"
1503 "LDD (HL),A"
1504 "INC SP"
1505 "INC (HL)"
1506 "DEC (HL)"
1507 "LD (HL),n"
1508 "SCF"
1509 "JR C,n"
1510 "ADD HL,SP"
1511 "LDD A,(HL)"
1512 "DEC SP"
1513 "INC A"
1514 "DEC A"
1515 "LD A,n"
1516 "CCF"
1517
1518 "LD B,B"
1519 "LD B,C"
1520 "LD B,D"
1521 "LD B,E"
1522 "LD B,H"
1523 "LD B,L"
1524 "LD B,(HL)"
1525 "LD B,A"
1526 "LD C,B"
1527 "LD C,C"
1528 "LD C,D"
1529 "LD C,E"
1530 "LD C,H"
1531 "LD C,L"
1532 "LD C,(HL)"
1533 "LD C,A"
1534
1535 "LD D,B"
1536 "LD D,C"
1537 "LD D,D"
1538 "LD D,E"
1539 "LD D,H"
1540 "LD D,L"
1541 "LD D,(HL)"
1542 "LD D,A"
1543 "LD E,B"
1544 "LD E,C"
1545 "LD E,D"
1546 "LD E,E"
1547 "LD E,H"
1548 "LD E,L"
1549 "LD E,(HL)"
1550 "LD E,A"
1551
1552 "LD H,B"
1553 "LD H,C"
1554 "LD H,D"
1555 "LD H,E"
1556 "LD H,H"
1557 "LD H,L"
1558 "LD H,(HL)"
1559 "LD H,A"
1560 "LD L,B"
1561 "LD L,C"
1562 "LD L,D"
1563 "LD L,E"
1564 "LD L,H"
1565 "LD L,L"
1566 "LD L,(HL)"
1567 "LD L,A"
1568
1569 "LD (HL),B"
1570 "LD (HL),C"
1571 "LD (HL),D"
1572 "LD (HL),E"
1573 "LD (HL),H"
1574 "LD (HL),L"
1575 "HALT"
1576 "LD (HL),A"
1577 "LD A,B"
1578 "LD A,C"
1579 "LD A,D"
1580 "LD A,E"
1581 "LD A,H"
1582 "LD A,L"
1583 "LD A,(HL)"
1584 "LD A,A"
1585
1586 "ADD A,B"
1587 "ADD A,C"
1588 "ADD A,D"
1589 "ADD A,E"
1590 "ADD A,H"
1591 "ADD A,L"
1592 "ADD A,(HL)"
1593 "ADD A,A"
1594 "ADC A,B"
1595 "ADC A,C"
1596 "ADC A,D"
1597 "ADC A,E"
1598 "ADC A,H"
1599 "ADC A,L"
1600 "ADC A,(HL)"
1601 "ADC A,A"
1602
1603 "SUB A,B"
1604 "SUB A,C"
1605 "SUB A,D"
1606 "SUB A,E"
1607 "SUB A,H"
1608 "SUB A,L"
1609 "SUB A,(HL)"
1610 "SUB A,A"
1611 "SBC A,B"
1612 "SBC A,C"
1613 "SBC A,D"
1614 "SBC A,E"
1615 "SBC A,H"
1616 "SBC A,L"
1617 "SBC A,(HL)"
1618 "SBC A,A"
1619
1620 "AND B"
1621 "AND C"
1622 "AND D"
1623 "AND E"
1624 "AND H"
1625 "AND L"
1626 "AND (HL)"
1627 "AND A"
1628 "XOR B"
1629 "XOR C"
1630 "XOR D"
1631 "XOR E"
1632 "XOR H"
1633 "XOR L"
1634 "XOR (HL)"
1635 "XOR A"
1636
1637 "OR B"
1638 "OR C"
1639 "OR D"
1640 "OR E"
1641 "OR H"
1642 "OR L"
1643 "OR (HL)"
1644 "OR A"
1645 "CP B"
1646 "CP C"
1647 "CP D"
1648 "CP E"
1649 "CP H"
1650 "CP L"
1651 "CP (HL)"
1652 "CP A"
1653
1654 "RET NZ"
1655 "POP BC"
1656 "JP NZ,nn"
1657 "JP nn"
1658 "CALL NZ,nn"
1659 "PUSH BC"
1660 "ADD A,n"
1661 "RST 0"
1662 "RET Z"
1663 "RET"
1664 "JP Z,nn"
1665 "Ext ops"
1666 "CALL Z,nn"
1667 "CALL nn"
1668 "ADC A,n"
1669 "RST 8"
1670
1671 "RET NC"
1672 "POP DE"
1673 "JP NC,nn"
1674 "XX"
1675 "CALL NC,nn"
1676 "PUSH DE"
1677 "SUB A,n"
1678 "RST 10"
1679 "RET C"
1680 "RETI"
1681 "JP C,nn"
1682 "XX"
1683 "CALL C,nn"
1684 "XX"
1685 "SBC A,n"
1686 "RST 18"
1687
1688 "LDH (n),A"
1689 "POP HL"
1690 "LDH (C),A"
1691 "XX"
1692 "XX"
1693 "PUSH HL"
1694 "AND n"
1695 "RST 20"
1696 "ADD SP,d"
1697 "JP (HL)"
1698 "LD (nn),A"
1699 "XX"
1700 "XX"
1701 "XX"
1702 "XOR n"
1703 "RST 28"
1704
1705 "LDH A,(n)"
1706 "POP AF"
1707 "XX"
1708 "DI"
1709 "XX"
1710 "PUSH AF"
1711 "OR n"
1712 "RST 30"
1713 "LDHL SP,d"
1714 "LD SP,HL"
1715 "LD A,(nn)"
1716 "EI"
1717 "XX"
1718 "XX"
1719 "CP n"
1720 "RST 38"])
1721
1722
1723 (defn hex
1724 "Converts the number into a hexadecimal-formatted symbol."
1725 [n]
1726 (symbol (str "0x" (.toUpperCase (Integer/toHexString n)))))
1727
1728
1729
1730 (defn arity
1731 "Returns the arity of the given opcode (hex numeral)."
1732 [op]
1733 (cond
1734 (#{0x06 0x0E 0x16 0x1E
1735 0x20 0x26 0x28 0x2E
1736 0x30 0x36 0x38 0x3E
1737 0xC6 0xD6 0xCE 0xDE
1738 0xE0 0xF0 0xE6 0xF6
1739 0xEE 0xFE} op)
1740 1
1741 (#{0x01 0x08 0x11 0x21
1742 0x31 0xC2 0xC3 0xC4
1743 0xCA 0xDA 0xCC 0xDC
1744 0xCD 0xEA 0xFA} op)
1745 2
1746 :else
1747 0))