[
  {
    "path": ".gitignore",
    "content": "## Ignored project files and folders\r\nTools\r\n\r\n## Core latex/pdflatex auxiliary files:\r\n*.ptc\r\n*.aux\r\n*.lof\r\n*.log\r\n*.lot\r\n*.fls\r\n*.out\r\n*.toc\r\n*.fmt\r\n*.fot\r\n*.cb\r\n*.cb2\r\n.*.lb\r\n\r\n## Intermediate documents:\r\n*.dvi\r\n*.xdv\r\n*-converted-to.*\r\n# these rules might exclude image files for figures etc.\r\n*.ps\r\n*.eps\r\n*.pdf\r\n\r\n## Generated if empty string is given at \"Please type another file name for output:\"\r\n.pdf\r\n\r\n## Bibliography auxiliary files (bibtex/biblatex/biber):\r\n*.bbl\r\n*.bcf\r\n*.blg\r\n*-blx.aux\r\n*-blx.bib\r\n*.run.xml\r\n\r\n## Build tool auxiliary files:\r\n*.fdb_latexmk\r\n*.synctex\r\n*.synctex(busy)\r\n*.synctex.gz\r\n*.synctex.gz(busy)\r\n*.pdfsync\r\n\r\n## Build tool directories for auxiliary files\r\n# latexrun\r\nlatex.out/\r\n\r\n## Auxiliary and intermediate files from other packages:\r\n# algorithms\r\n*.alg\r\n*.loa\r\n\r\n# achemso\r\nacs-*.bib\r\n\r\n# amsthm\r\n*.thm\r\n\r\n# beamer\r\n*.nav\r\n*.pre\r\n*.snm\r\n*.vrb\r\n\r\n# changes\r\n*.soc\r\n\r\n# comment\r\n*.cut\r\n\r\n# cprotect\r\n*.cpt\r\n\r\n# elsarticle (documentclass of Elsevier journals)\r\n*.spl\r\n\r\n# endnotes\r\n*.ent\r\n\r\n# fixme\r\n*.lox\r\n\r\n# feynmf/feynmp\r\n*.mf\r\n*.mp\r\n*.t[1-9]\r\n*.t[1-9][0-9]\r\n*.tfm\r\n\r\n#(r)(e)ledmac/(r)(e)ledpar\r\n*.end\r\n*.?end\r\n*.[1-9]\r\n*.[1-9][0-9]\r\n*.[1-9][0-9][0-9]\r\n*.[1-9]R\r\n*.[1-9][0-9]R\r\n*.[1-9][0-9][0-9]R\r\n*.eledsec[1-9]\r\n*.eledsec[1-9]R\r\n*.eledsec[1-9][0-9]\r\n*.eledsec[1-9][0-9]R\r\n*.eledsec[1-9][0-9][0-9]\r\n*.eledsec[1-9][0-9][0-9]R\r\n\r\n# glossaries\r\n*.acn\r\n*.acr\r\n*.glg\r\n*.glo\r\n*.gls\r\n*.glsdefs\r\n*.lzo\r\n*.lzs\r\n\r\n# uncomment this for glossaries-extra (will ignore makeindex's style files!)\r\n# *.ist\r\n\r\n# gnuplottex\r\n*-gnuplottex-*\r\n\r\n# gregoriotex\r\n*.gaux\r\n*.gtex\r\n\r\n# htlatex\r\n*.4ct\r\n*.4tc\r\n*.idv\r\n*.lg\r\n*.trc\r\n*.xref\r\n\r\n# hyperref\r\n*.brf\r\n\r\n# knitr\r\n*-concordance.tex\r\n# TODO Uncomment the next line if you use knitr and want to ignore its generated tikz files\r\n# *.tikz\r\n*-tikzDictionary\r\n\r\n# listings\r\n*.lol\r\n\r\n# luatexja-ruby\r\n*.ltjruby\r\n\r\n# makeidx\r\n*.idx\r\n*.ilg\r\n*.ind\r\n\r\n# minitoc\r\n*.maf\r\n*.mlf\r\n*.mlt\r\n*.mtc\r\n*.mtc[0-9]*\r\n*.slf[0-9]*\r\n*.slt[0-9]*\r\n*.stc[0-9]*\r\n\r\n# minted\r\n_minted*\r\n*.pyg\r\n\r\n# morewrites\r\n*.mw\r\n\r\n# nomencl\r\n*.nlg\r\n*.nlo\r\n*.nls\r\n\r\n# pax\r\n*.pax\r\n\r\n# pdfpcnotes\r\n*.pdfpc\r\n\r\n# sagetex\r\n*.sagetex.sage\r\n*.sagetex.py\r\n*.sagetex.scmd\r\n\r\n# scrwfile\r\n*.wrt\r\n\r\n# sympy\r\n*.sout\r\n*.sympy\r\nsympy-plots-for-*.tex/\r\n\r\n# pdfcomment\r\n*.upa\r\n*.upb\r\n\r\n# pythontex\r\n*.pytxcode\r\npythontex-files-*/\r\n\r\n# tcolorbox\r\n*.listing\r\n\r\n# thmtools\r\n*.loe\r\n\r\n# TikZ & PGF\r\n*.dpth\r\n*.md5\r\n*.auxlock\r\n\r\n# todonotes\r\n*.tdo\r\n\r\n# vhistory\r\n*.hst\r\n*.ver\r\n\r\n# easy-todo\r\n*.lod\r\n\r\n# xcolor\r\n*.xcp\r\n\r\n# xmpincl\r\n*.xmpi\r\n\r\n# xindy\r\n*.xdy\r\n\r\n# xypic precompiled matrices and outlines\r\n*.xyc\r\n*.xyd\r\n\r\n# endfloat\r\n*.ttt\r\n*.fff\r\n\r\n# Latexian\r\nTSWLatexianTemp*\r\n\r\n## Editors:\r\n# WinEdt\r\n*.bak\r\n*.sav\r\n\r\n# Texpad\r\n.texpadtmp\r\n\r\n# LyX\r\n*.lyx~\r\n\r\n# Kile\r\n*.backup\r\n\r\n# gummi\r\n.*.swp\r\n\r\n# KBibTeX\r\n*~[0-9]*\r\n\r\n# TeXnicCenter\r\n*.tps\r\n\r\n# auto folder when using emacs and auctex\r\n./auto/*\r\n*.el\r\n\r\n# expex forward references with \\gathertags\r\n*-tags.tex\r\n\r\n# standalone packages\r\n*.sta\r\n\r\n# Makeindex log files\r\n*.lpz\r\n\r\n# xwatermark package\r\n*.xwm\r\n\r\n# REVTeX puts footnotes in the bibliography by default, unless the nofootinbib\r\n# option is specified. Footnotes are the stored in a file with suffix Notes.bib.\r\n# Uncomment the next line to have this generated file ignored.\r\n#*Notes.bib\r\n\r\n## Auto generated files for companion code\r\n.tmp"
  },
  {
    "path": "chapter-acknowledge.tex",
    "content": "\\begingroup\r\n\r\n\t\\WorkInProgressFullScreen\r\n\r\n\r\n\t\\textbf{Acknowlegements}\r\n\r\n\tA lot of work has gone into this book. But I also learned a lot. Not just about Z80 and Next, also \\LaTeX~which basics I learned in secondary school and then all but forgotten. In this regard, I'd like to thank Jan Wilmans and Sean Young for creating the original Z80 Undocumented that I took as a basis for this book. I also need to thank countless kind folks on \\url{https://tex.stackexchange.com/}, those who asked questions and those who answered them; I found solutions to most issues I encountered there (and I was one very frequent visitor at times :) I'm very grateful to all members of {\\tt z80-hardcore} Spectrum Next Discord channel who pointed out errors and shortcomings of the book but especially Peter Ped Helcmanovsky and Alvin Albrecht (aka Allen Albright) for help in fact-checking and pull request contributions. And last but not least, my family for being patient with my frequent long after-hours. Oh, also special shoutout to Bibi, our small JRT companion with the biggest heart :)\r\n\r\n\t\\vspace*{\\fill}\r\n\r\n\t\\WorkInProgressFullScreen\r\n\r\n\\endgroup\r\n"
  },
  {
    "path": "chapter-bibliography.tex",
    "content": "\r\n% ████████████████████████████████████████████████████████████████████████████\r\n% █░░░░░░░░░░░░░░███░░░░░░░░░░█░░░░░░░░░░░░░░███░░░░░░█████████░░░░░░░░░░░░░░█\r\n% █░░▄▀▄▀▄▀▄▀▄▀░░███░░▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░███░░▄▀░░█████████░░▄▀▄▀▄▀▄▀▄▀░░█\r\n% █░░▄▀░░░░░░▄▀░░███░░░░▄▀░░░░█░░▄▀░░░░░░▄▀░░███░░▄▀░░█████████░░▄▀░░░░░░▄▀░░█\r\n% █░░▄▀░░██░░▄▀░░█████░░▄▀░░███░░▄▀░░██░░▄▀░░███░░▄▀░░█████████░░▄▀░░██░░▄▀░░█\r\n% █░░▄▀░░░░░░▄▀░░░░███░░▄▀░░███░░▄▀░░░░░░▄▀░░░░█░░▄▀░░█████████░░▄▀░░██░░▄▀░░█\r\n% █░░▄▀▄▀▄▀▄▀▄▀▄▀░░███░░▄▀░░███░░▄▀▄▀▄▀▄▀▄▀▄▀░░█░░▄▀░░█████████░░▄▀░░██░░▄▀░░█\r\n% █░░▄▀░░░░░░░░▄▀░░███░░▄▀░░███░░▄▀░░░░░░░░▄▀░░█░░▄▀░░█████████░░▄▀░░██░░▄▀░░█\r\n% █░░▄▀░░████░░▄▀░░███░░▄▀░░███░░▄▀░░████░░▄▀░░█░░▄▀░░█████████░░▄▀░░██░░▄▀░░█\r\n% █░░▄▀░░░░░░░░▄▀░░█░░░░▄▀░░░░█░░▄▀░░░░░░░░▄▀░░█░░▄▀░░░░░░░░░░█░░▄▀░░░░░░▄▀░░█\r\n% █░░▄▀▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█\r\n% █░░░░░░░░░░░░░░░░█░░░░░░░░░░█░░░░░░░░░░░░░░░░█░░░░░░░░░░░░░░█░░░░░░░░░░░░░░█\r\n% ████████████████████████████████████████████████████████████████████████████\r\n\r\n\\begin{thebibliography}{}\r\n\r\n\t\\bibitem{mrison}  Mark Rison Z80 page for !CPC. \\\\\r\n\t{\\tt \\small http://www.acorn.co.uk/$\\sim$mrison/en/cpc/tech.html}\r\n\r\n\t\\bibitem{yaze} YAZE (Yet Another Z80 Emulator). This is a CPM emulator by Frank Cringle. It emulates almost every undocumented flag, very good emulator. Also includes a very good instruction exerciser and is released under the GPL. \\\\\r\n\t{\\tt \\small ftp://ftp.ping.de/pub/misc/emulators/yaze-1.10.tar.gz} \\\\\r\n\tNote: the instruction exerciser zexdoc/zexall does not test I/O instructions and not all normal instructions (for instance LD A,(IX+n) is tested, but not with different values of n, just n=1, values above 128 (LD A,(IX-n) are not tested) but it still gives a pretty good idea of how well a simulated Z80 works.\r\n\r\n\t\\bibitem{thomas} Z80 Family Official Support Page by Thomas Scherrer. Very good -- your one-stop Z80 page. \\\\\r\n\t{\\tt \\small http://www.geocities.com/SiliconValley/Peaks/3938/z80\\_home.htm}\r\n\r\n\t\\bibitem{speccy_faq} Spectrum FAQ technical information. \\\\\r\n\t{\\tt \\small http://www.worldofspectrum.org/faq/}\r\n\r\n\t\\bibitem{gerton} Gerton Lunter's Spectrum emulator (Z80). In the package there is a file TECHINFO.DOC, which contains a lot of interesting information. Note that the current version can only be unpacked in Windows. \\\\\r\n\t{\\tt \\small ftp://ftp.void.jump.org/pub/sinclair/emulators/pc/dos/z80-400.zip}\r\n\r\n\t\\bibitem{mostek} Mostek Z80 Programming Manual -- a very good reference to the Z80.\r\n\r\n\t\\bibitem{datasheet} Z80 Product Specification, from MSX2 Hardware Information. \\\\\r\n\t{\\tt \\small http://www.hardwareinfo.msx2.com/pdf/Zilog/z80.pdf}\r\n\r\n\t\\bibitem{zx_next} ZX Spectrum Next information. \\\\\r\n\t{\\tt \\small \\url{https://wiki.specnext.dev/}}\r\n\r\n\\end{thebibliography}\r\n\r\n\\pagebreak\r\n\\IntentionallyEmpty\r\n\\pagebreak"
  },
  {
    "path": "chapter-copyright.tex",
    "content": "\\begingroup\r\n\t{\\WorkInProgressFullScreen}\r\n\r\n\t\\vspace*{\\fill} % render at the bottom of the page\r\n\r\n\t{\\Large\\textbf{\\BookTitle}}\r\n\r\n\t\\vspace*{0.1cm}\r\n\r\n\t{\\large\\AuthorNameSurname}\r\n\r\n\t\\LatestRevisionName{}\r\n\r\n\tREVISIONS\\\\\r\n\t\\LatestRevisionDate{}\\\\\r\n\t\\RevisionTwoDate{}\\\\\r\n\t\\RevisionOneDate{}\r\n\r\n\t\\vspace*{0.2cm}\r\n\r\n\tCopyright {\\copyright} \\LatestYear{} \\AuthorNameSurname{}\\\\\t% note this should become 2021-\\LatestYear (aka 2021-2022) for releases after 2021...\r\n\tCopyright {\\copyright} 2005 Jan Wilmans\\\\\r\n\tCopyright {\\copyright} 1997, 1998, 2001, 2003, 2005 Sean Young\r\n\r\n\tPermission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled ``GNU Free Documentation License''.\r\n\\endgroup\r\n"
  },
  {
    "path": "chapter-instr-close.tex",
    "content": "\\chapter{Instructions up Close}\r\n\\label{instruction_details}\r\n\r\n% ████████████████████████████████████████████████████████████████████████████\r\n% █░░░░░░░░░░░░░░█░░░░░░█████████░░░░░░░░░░░░░░█░░░░░░░░░░░░░░█░░░░░░░░░░░░░░█\r\n% █░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀░░█████████░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█\r\n% █░░▄▀░░░░░░░░░░█░░▄▀░░█████████░░▄▀░░░░░░▄▀░░█░░▄▀░░░░░░░░░░█░░▄▀░░░░░░░░░░█\r\n% █░░▄▀░░█████████░░▄▀░░█████████░░▄▀░░██░░▄▀░░█░░▄▀░░█████████░░▄▀░░█████████\r\n% █░░▄▀░░█████████░░▄▀░░█████████░░▄▀░░██░░▄▀░░█░░▄▀░░░░░░░░░░█░░▄▀░░░░░░░░░░█\r\n% █░░▄▀░░█████████░░▄▀░░█████████░░▄▀░░██░░▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█\r\n% █░░▄▀░░█████████░░▄▀░░█████████░░▄▀░░██░░▄▀░░█░░░░░░░░░░▄▀░░█░░▄▀░░░░░░░░░░█\r\n% █░░▄▀░░█████████░░▄▀░░█████████░░▄▀░░██░░▄▀░░█████████░░▄▀░░█░░▄▀░░█████████\r\n% █░░▄▀░░░░░░░░░░█░░▄▀░░░░░░░░░░█░░▄▀░░░░░░▄▀░░█░░░░░░░░░░▄▀░░█░░▄▀░░░░░░░░░░█\r\n% █░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█\r\n% █░░░░░░░░░░░░░░█░░░░░░░░░░░░░░█░░░░░░░░░░░░░░█░░░░░░░░░░░░░░█░░░░░░░░░░░░░░█\r\n% ████████████████████████████████████████████████████████████████████████████\r\n\r\n\\input{defines-instr-close.tex}\r\n\r\nThe following pages describe all instructions in detail. Alphabetical order is used as much as possible, but some deviations were made to better fit to pages. Each instruction includes:\r\n\r\n\\begin{itemize}\r\n\t\\setlength\\itemsep{1pt}\r\n\t\\item Mnemonic\r\n\t\\item Symbolic operation for quick info on what instruction does\r\n\t\\item All variants (where applicable)\r\n\t\\item Description with further details\r\n\t\\item Effects on flags\r\n\t\\item Timing table with machine cycles, T states and time required for execution on different CPU speeds\r\n\\end{itemize}\r\n\r\nWhere possible, multiple variants of same instruction are grouped together and where multiple timings are possible, timing table is sorted from quickest to slowest.\r\n\r\n\\pagebreak\r\n\\thispagestyle{plain} % use toc style without headers for this explanation page, it better matches chapter start page\r\n\r\n\r\n\\subsubsection{Flags}\r\n\r\n\\newcommand{\\DetailsFlagTableList}[1]{\r\n\t\\vspace*{-2ex}\r\n\t\\setlist{leftmargin=1em,after=\\vspace{-2ex}}\r\n\t\\begin{itemize}\r\n\t\t\\setlength\\itemsep{-4pt}\r\n\t\t#1\r\n\t\\end{itemize}\r\n}\r\n\r\n\\newcommand{\\DetailsFlagTableParagraph}{\\vspace{1ex}}\r\n\r\n{\t\r\n\t\\renewcommand{\\arraystretch}{1.5}\r\n\r\n\t\\begin{tabularx}{\\linewidth}{cX}\r\n\t\t\\FlagSF{} &\r\n\t\t\t\\textbf{Sign Flag} is set to twos-complement of the most-significant bit (bit 7) of the result of an instruction. If the result is positive (bit 7 is {\\tt 0}), \\FlagSF{} is set, and if the result is negative (bit 7 is {\\tt 1}), \\FlagSF{} is reset. This leaves bits 0-6 to represent the value. Positive numbers range from {\\tt 0} to {\\tt 127} and negative from {\\tt -1} to {\\tt -128}.\r\n\t\t\t\\\\\r\n\r\n\t\t\\FlagZF{} &\r\n\t\t\t\\textbf{Zero Flag} depends on whether the result of an instruction is {\\tt 0}. \\FlagZF{} is set if the result if {\\tt 0} and reset otherwise.\r\n\t\t\t\\\\\r\n\r\n\t\t\\FlagHF{} &\r\n\t\t\t\\textbf{Half Carry Flag} represents a carry or borrow status between bits 3 and 4 of an 8-bit arithmetic operation (bits 11 and 12 for 16-bit operations). Set if:\r\n\t\t\r\n\t\t\t\\DetailsFlagTableList{\r\n\t\t\t\t\\item A carry from bit 3 to bit 4 occurs during addition (bit 11 to 12 for 16-bit operations)\r\n\t\t\t\t\\item A borrow from bit 4 occurs during subtraction (from bit 12 for 16-bit operations)\r\n\t\t\t}\r\n\t\t\t\\\\\r\n\r\n\t\t\\FlagPV{} &\r\n\t\t\t\\textbf{Parity/Overflow Flag} value depends on the type of the operation.\r\n\t\t\t\r\n\t\t\t\\DetailsFlagTableParagraph\r\n\t\t\tFor arithmetic operations, \\FlagPV{} indicates an overflow. The flag is set when the sign of the result is different from the sign of the operands:\r\n\t\t\t\r\n\t\t\t\\DetailsFlagTableList{\r\n\t\t\t\t\\item all operands are positive but the result is negative or\r\n\t\t\t\t\\item all operands are negative but the result is positive\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t\\DetailsFlagTableParagraph\r\n\t\t\tFor logical and rotate operations, \\FlagPV{} indicates the parity of the result. The number of set bits in the result are counted. If the total is an even value, \\FlagPV{} is set. If the total is odd, \\FlagPV{} is reset.\r\n\t\t\t\\\\\r\n\r\n\t\t\\FlagNF{} &\r\n\t\t\t\\textbf{Add/Subtract Flag} is used primarily for {\\tt DAA} instruction to distinguish between add and subtract operations. But other instructions may also affect it as described in the following pages.\r\n\t\t\t\\\\\r\n\r\n\t\t\\textbf{CF} &\r\n\t\t\t\\textbf{Carry Flag} represents a carry or borrow status for arithmetic operations. \\textbf{CF} is set if add instruction generates a carry, or subtract generates a borrow.\r\n\t\t\t\r\n\t\t\t\\DetailsFlagTableParagraph\r\n\t\t\tFor rotate and shift instructions, \\textbf{CF} is used:\r\n\t\t\t\r\n\t\t\t\\DetailsFlagTableList{\r\n\t\t\t\t\\item as a link between least-significat and most significant bit for {\\tt RLA}, {\\tt RL}, {\\tt RRA} and {\\tt RR}\r\n\t\t\t\t\\item contains the value shifted out of bit 7 for {\\tt RLC}, {\\tt RLCA} and {\\tt SLA}\r\n\t\t\t\t\\item contains the value shifted out of bit 0 for {\\tt RRC}, {\\tt RRCA}, {\\tt SRA} and {\\tt SRL}\r\n\t\t\t}\r\n\r\n\t\t\t\\DetailsFlagTableParagraph\r\n\t\t\tFinally, some instructions directly affect the value of \\textbf{CF}:\r\n\r\n\t\t\t\\DetailsFlagTableList{\r\n\t\t\t\t\\item reset with {\\tt AND}, {\\tt OR} and {\\tt XOR}\r\n\t\t\t\t\\item set with {\\tt SCF}\r\n\t\t\t\t\\item completed with {\\tt CCF}\r\n\t\t\t}\r\n\t\t\t\\\\\r\n\t\\end{tabularx}\r\n}\r\n\r\n\r\n\\subsubsection{Effects}\r\n\r\n\\begin{tabular}{cl}\r\n\t{\\tt 0} & Flag is set to {\\tt 0} \\\\\r\n\t{\\tt 1} & Flag is set to {\\tt 1} \\\\\r\n\t{\\tt \\FS} & Flag is modified according to operation \\\\\r\n\t{\\tt \\FN} & Flag is not affected \\\\\r\n\t{\\tt \\FU} & Effect on flag is unpredictable \\\\\r\n\t{\\tt \\FX} & Special case, see notes below effects table \\\\\r\n\t\\DetailParityOverflow{v} & P/V flag is used as overflow \\\\\r\n\t\\DetailParityOverflow{p} & P/V flag is used as parity \\\\\r\n\t\\DetailParityOverflow{} & P/V is undefined or indicates other result \\\\\r\n\\end{tabular}\r\n\r\n\r\n\\subsubsection{Abbreviations}\r\n\r\n\\begin{tabularx}{\\textwidth}{lX}\r\n\t{\\tt r} & \r\n\t\t8-bit register {\\tt A}-{\\tt L} \\\\\r\n\t{\\tt n} &\r\n\t\t8-bit immediate value \\\\\r\n\t{\\tt rr} & \r\n\t\t16-bit register pair {\\tt AF}, {\\tt BC}, {\\tt DE}, {\\tt HL}, {\\tt IX}, {\\tt IY}, {\\tt SP} (note in some cases particular register pairs may use different timing from the rest; if so, those will be explicitly indicated in their own line; {\\tt rr} may still be used, though in those cases it will cover the remaining registers only) \\\\\r\n\t{\\tt nn} & \r\n\t\t16-bit immediate value \\\\\r\n\t{\\tt s} &\r\n\t\tPlaceholder for argument when multiple variants are possible \\\\\r\n\t{\\tt d} &\r\n\t\tIf instruction takes 2 operands, {\\tt d} indicates destination and {\\tt s} source \\\\\r\n\t\\UNDOC & Indicates undocumented instruction \\\\\r\n\t\\ZXN & Indicates ZX Spectrum Next extended instruction \\\\\t\t\r\n\\end{tabularx}\r\n\r\n\r\n\\pagebreak\r\n\\IntentionallyEmpty\r\n\\pagebreak\r\n\r\n\r\n\r\n\\begin{basedescript}{\r\n\t% setup basedescript styling for labels\r\n\t\\desclabelstyle{\\multilinelabel}\r\n\t\\desclabelwidth{3cm}}\r\n\r\n\t% setup spacing between items\r\n\t\\setlength\\itemsep{1.5em}\r\n\r\n\t\\pagebreak\r\n\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{ADC}{d,s}\r\n\t\t{\\IH{AD}d with \\IH{C}arry}\r\n\t\t{\\SymADC{d}{s}}\r\n\r\n\t\t\\begin{DetailVariants}[p{1.9cm}p{1.9cm}Xp{2.8cm}p{2.4cm}]\r\n\t\t\t\\textnormal{8 bit} & \\textnormal{8 bit} & \\textnormal{8 bit} & \\textnormal{8 bit} & \\textnormal{16 bit} \\\\\r\n\t\t\tADC A,A\t& ADC A,E\t& ADC A,(HL)\t& ADC A,IXH\\UNDOC\t& ADC HL,BC \\\\\r\n\t\t\tADC A,B\t& ADC A,H\t& ADC A,(IX+d)\t& ADC A,IXL\\UNDOC\t& ADC HL,DE \\\\\r\n\t\t\tADC A,C\t& ADC A,L\t& ADC A,(IY+d)\t& ADC A,IYH\\UNDOC\t& ADC HL,HL \\\\\r\n\t\t\tADC A,D\t& ADC A,n\t& \t\t\t\t& ADC A,IYL\\UNDOC\t& ADC HL,SP \\\\\r\n\t\t\\end{DetailVariants}\r\n\t\t\r\n\t\tAdds source operand {\\tt s} or contents of the memory location addressed by {\\tt s} and value of carry flag to destination {\\tt d}. Result is then stored to destination {\\tt d}.\r\n\r\n\t\t\\begin{DetailEffects}[v]\r\n\t\t\t\\FlagsADCr[8-bit]\r\n\t\t\t\\FlagsADCrr[16-bit]\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagSF{\\DetailFlagResultSign}\r\n\t\t\t\\DetailFlagZF{\\DetailFlagResultZero}\r\n\t\t\t\\DetailFlagHF{\\DetailFlagResultHalfCarry}*\r\n\t\t\t\\DetailFlagPV{\\DetailFlagResultOverflow}*\r\n\t\t\t\\DetailFlagCF{\\DetailFlagResultCarry}\r\n\t\t\\end{DetailEffectsFlags}\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime[A,r]{1}{4}\r\n\t\t\t\\DetailTime[A,n]{2}{7}\r\n\t\t\t\\DetailTime[A,(HL)]{2}{7}\r\n\t\t\t\\DetailTime[HL,rr]{4}{15}\r\n\t\t\t\\DetailTime[A,(IX+d)]{5}{19}\r\n\t\t\t\\DetailTime[A,(IY+d)]{5}{19}\r\n\t\t\\end{DetailTiming}\r\n\t\t\r\n\t\\end{DetailItem}\r\n\t\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{ADD}{d,s}\r\n\t\t{\\IH{ADD}}\r\n\t\t{\\SymADD{d}{s}}\r\n\r\n\t\t\\begin{DetailVariants}[p{1.9cm}Xp{2.3cm}p{2.3cm}p{2.4cm}]\r\n\t\t\t\\textnormal{8-bit} & \\textnormal{8-bit} & \\textnormal{16-bit} & \\textnormal{16-bit} & \\textnormal{ZX Next} \\\\\r\n\t\t\tADD A,A & ADD A,(HL) \t\t& ADD IX,BC & ADD HL,BC\t& ADD BC,A\\ZXN \\\\\r\n\t\t\tADD A,B & ADD A,(IX+d)\t\t& ADD IX,DE & ADD HL,DE & ADD DE,A\\ZXN \\\\\r\n\t\t\tADD A,C & ADD A,(IY+d)\t\t& ADD IX,IX & ADD HL,HL & ADD HL,A\\ZXN \\\\\r\n\t\t\tADD A,D & ADD A,IXH\\UNDOC\t& ADD IX,SP & ADD HL,SP & ADD BE,nn\\ZXN \\\\ \r\n\t\t\tADD A,E & ADD A,IXL\\UNDOC\t& ADD IY,BC & \t\t\t& ADD DE,nn\\ZXN \\\\\r\n\t\t\tADD A,H & ADD A,IYH\\UNDOC\t& ADD IY,DE & \t\t\t& ADD HL,nn\\ZXN \\\\\r\n\t\t\tADD A,L & ADD A,IYL\\UNDOC\t& ADD IY,IY \\\\\r\n\t\t\tADD A,n & \t\t\t\t\t& ADD IY,SP \\\\\r\n\t\t\\end{DetailVariants}\r\n\t\t\r\n\t\tSimilar to {\\tt ADC} except carry flag is not used in calculation: adds operand {\\tt s} or contents of the memory location addressed by {\\tt s} to destination {\\tt d}. Result is then stored to destination {\\tt d}.\r\n\r\n\t\tZX Next Extended instructions for adding {\\tt A} to 16-bit register pair, zero extend {\\tt A} to 16-bits.\r\n\r\n\t\t\\begin{DetailEffects}[v]\r\n\t\t\t\\FlagsADDr[8-bit]\r\n\t\t\t\\FlagsADDrr[16-bit]\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagSF[8-bit only, set if:]{\\DetailFlagResultSign}\r\n\t\t\t\\DetailFlagZF[8-bit only, set if:]{\\DetailFlagResultZero}\r\n\t\t\t\\DetailFlagHF{\\DetailFlagResultHalfCarry*}*\r\n\t\t\t\\DetailFlagPV[8-bit only, set if:]{\\DetailFlagResultOverflow}*\r\n\t\t\t\\DetailFlagCF{\\DetailFlagResultCarry*}\r\n\t\t\\end{DetailEffectsFlags}\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsADDrra[\\tt ADD rr,A\\ZXN]\r\n\t\t\t\\FlagsADDrrnn[\\tt ADD rr,nn\\ZXN]\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime[A,r]{1}{4}\r\n\t\t\t\\DetailTime[A,n]{2}{7}\r\n\t\t\t\\DetailTime[A,(HL)]{2}{7}\r\n\t\t\t\\DetailTime[rr,A\\ZXN]{2}{8}\r\n\t\t\t\\DetailTime[HL,rr]{3}{11}\r\n\t\t\t\\DetailTime[IX,rr]{4}{15}\r\n\t\t\t\\DetailTime[IY,rr]{4}{15}\r\n\t\t\t\\DetailTime[rr,nn\\ZXN]{4}{16}\r\n\t\t\t\\DetailTime[A,(IX+d)]{5}{19}\r\n\t\t\t\\DetailTime[A,(IY+d)]{5}{19}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{AND}{s}\r\n\t\t{bitwise \\IH{AND}}\r\n\t\t{\\SymAND{s}}\r\n\r\n\t\t\\begin{DetailVariants}[4]\r\n\t\t\tAND A\\\\\r\n\t\t\tAND B\\\\\r\n\t\t\tAND C\\\\\r\n\t\t\tAND D\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\tAND E\\\\\r\n\t\t\tAND H\\\\\r\n\t\t\tAND L\\\\\r\n\t\t\tAND n\r\n\t\t\t\r\n\t\t\t\\columnbreak\r\n\t\t\tAND (HL)\\\\\r\n\t\t\tAND (IX+d)\\\\\r\n\t\t\tAND (IY+d)\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\tAND IXH\\UNDOC\\\\\r\n\t\t\tAND IXL\\UNDOC\\\\\r\n\t\t\tAND IYH\\UNDOC\\\\\r\n\t\t\tAND IYL\\UNDOC\r\n\t\t\\end{DetailVariants}\r\n\r\n\t\t\\begin{tabularx}{\\linewidth}{@{}Xl}\r\n\t\t\tPerforms bitwise AND between accumulator {\\tt A} and the given operand. The result is then stored back to the accumulator. Individual bits are AND'ed as shown on the right:\r\n\r\n\t\t\t&\r\n\r\n\t\t\t\\begin{tabular}[t]{cc|c}\r\n\t\t\t\t{\\tt A} & {\\tt s} & Result \\\\\r\n\t\t\t\t\\hline\r\n\t\t\t\t{\\tt 0} & {\\tt 0} & {\\tt 0} \\\\\r\n\t\t\t\t{\\tt 0} & {\\tt 1} & {\\tt 0} \\\\\r\n\t\t\t\t{\\tt 1} & {\\tt 0} & {\\tt 0} \\\\\r\n\t\t\t\t{\\tt 1} & {\\tt 1} & {\\tt 1} \\\\\r\n\t\t\t\\end{tabular}\r\n\r\n\t\t\t\\\\\r\n\t\t\\end{tabularx}\r\n\r\n\t\t\\begin{DetailEffects}[p]\r\n\t\t\t\\FlagsANDr\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagSF{\\DetailFlagResultSign}\r\n\t\t\t\\DetailFlagZF{\\DetailFlagResultZero}\r\n\t\t\t\\DetailFlagPV{\\DetailFlagResultParity}\r\n\t\t\\end{DetailEffectsFlags}\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime[r]{1}{4}\r\n\t\t\t\\DetailTime[n]{2}{7}\r\n\t\t\t\\DetailTime[(HL)]{2}{7}\r\n\t\t\t\\DetailTime[(IX+d)]{5}{19}\r\n\t\t\t\\DetailTime[(IY+d)]{5}{19}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{BIT}{b,s}\r\n\t\t{test \\IH{BIT}}\r\n\t\t{\\SymBIT{s}}\r\n\r\n\t\t\\begin{DetailVariants}\r\n\t\t\tBIT b,A\\\\\r\n\t\t\tBIT b,B\\\\\r\n\t\t\tBIT b,C\\\\\r\n\t\t\tBIT b,D\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\tBIT b,E\\\\\r\n\t\t\tBIT b,H\\\\\r\n\t\t\tBIT b,L\r\n\t\t\t\r\n\t\t\t\\columnbreak\r\n\t\t\tBIT b,(HL)\\\\\r\n\t\t\tBIT b,(IX+d)\\\\\r\n\t\t\tBIT b,(IY+d)\r\n\t\t\\end{DetailVariants}\r\n\r\n\t\tTests specified bit {\\tt b} ({\\tt 0-7}) of the given register {\\tt s} or contents of memory addressed by {\\tt s} and sets zero flag according to result; if bit was 1, \\FlagZF{} is 0 and vice versa.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsBITr\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagZF{bit {\\tt b} of the given source argument is {\\tt 0}}\r\n\t\t\\end{DetailEffectsFlags}\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime[b,r]{2}{8}\r\n\t\t\t\\DetailTime[b,(HL)]{3}{12}\r\n\t\t\t\\DetailTime[b,(IX+d)]{5}{20}\r\n\t\t\t\\DetailTime[b,(IY+d)]{5}{20}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t% these instructions should be here in alphabetical order, but I want them to be placed on the same page spread so reader can check the differences easily\r\n\t\\DetailItemsSeePageReference{BRLC, BSLA, BSRA, BSRF, BSRL}{See pages \\DetailItemPageRef{BRLC} and \\DetailItemPageRef{BSRL}}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{CALL}{nn}\r\n\t\t{\\IH{CALL} subroutine}\r\n\t\t{\\SymCALL{nn}}\r\n\r\n\t\tPushes program counter {\\tt PC} to stack and calls subroutine at the given location {\\tt nn} by changing {\\tt PC} to point to address {\\tt nn}.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsCALLnn\r\n\t\t\\end{DetailEffects}\r\n\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{5}{17}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{CALL c,nn}{}\r\n\t\t{\\IH{CALL} subroutine conditionally}\r\n\t\t{\\SymCALLc{nn}}\r\n\r\n\t\t\\vspace{1ex} % we need some vertical space to achieve same separation as multicols\r\n\t\t\\begin{tabular}{@{}llcll}\t\t\t\r\n\t\t\t{\\tt CALL C,nn} & calls if \\FlagCF{} is set & &\r\n\t\t\t\t{\\tt CALL M,nn} & calls if \\FlagSF{} is set\\\\\r\n\t\t\t{\\tt CALL NC,nn} & calls if \\FlagCF{} is reset & &\r\n\t\t\t\t{\\tt CALL P,nn} & calls if \\FlagSF{} is reset\\\\\r\n\t\t\t{\\tt CALL Z,nn} & calls if \\FlagZF{} is set & &\r\n\t\t\t\t{\\tt CALL PE,nn} & calls if \\FlagPV{} is set\\\\\r\n\t\t\t{\\tt CALL NZ,nn} & calls if \\FlagZF{} is reset & &\r\n\t\t\t\t{\\tt CALL PO,nn} & calls if \\FlagPV{} is reset\\\\\r\n\t\t\\end{tabular}\r\n\r\n\t\tIf the given condition is met, {\\tt CALL nn} is performed, as described above.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsCALLccnn\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime[c\\normalfont{=false}]{3}{10}\r\n\t\t\t\\DetailTime[c\\normalfont{=true}]{5}{17}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{BRLC}{DE,B\\ZXN}\r\n\t\t{\\IH{B}arrel \\IH{R}otate \\IH{L}eft \\IH{C}ircular}\r\n\t\t{\\SymBRLC}\r\n\r\n\t\tRotates value in register pair {\\tt DE} left for the amount given in bits 3-0 (low nibble) of register {\\tt B}. To rotate right, use formula: {\\tt B=16-places}. The result is stored in {\\tt DE}.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsBRLC\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{2}{8}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{BSLA}{DE,B\\ZXN}\r\n\t\t{\\IH{B}arrel \\IH{S}hift \\IH{L}eft \\IH{A}rithmetic}\r\n\t\t{\\SymBSLA}\r\n\r\n\t\tPerforms shift left of the value in register pair {\\tt DE} for the amount given in lower 5 bits of register {\\tt B}. The result is stored in {\\tt DE}.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsBSLA\r\n\t\t\\end{DetailEffects}\r\n\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{2}{8}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{BSRA}{DE,B\\ZXN}\r\n\t\t{\\IH{B}arrel \\IH{S}hift \\IH{R}ight \\IH{A}rithmetic}\r\n\t\t{\\SymBSRA}\r\n\r\n\t\tPerforms arithmetical shift right of the value in register pair {\\tt DE} for the amount given in lower 5 bits of register {\\tt B}. The result is stored in {\\tt DE}.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsBSRA\r\n\t\t\\end{DetailEffects}\r\n\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{2}{8}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{BSRF}{DE,B\\ZXN}\r\n\t\t{\\IH{B}arrel \\IH{S}hift \\IH{R}ight \\IH{F}ill-one}\r\n\t\t{\\SymBSRF}\r\n\r\n\t\tPerforms fill-one-way shift right of the value in register pair {\\tt DE} for the amount given in lower 5 bits of register {\\tt B}. The result is stored in {\\tt DE}.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsBSRF\r\n\t\t\\end{DetailEffects}\r\n\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{2}{8}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{BSRL}{DE,B\\ZXN}\r\n\t\t{\\IH{B}arrel \\IH{S}hift \\IH{R}ight \\IH{L}ogical}\r\n\t\t{\\SymBSRL}\r\n\r\n\t\tPerforms logical shift right of the value in register pair {\\tt DE} for the amount given in lower 5 bits of register {\\tt B}. The result is stored in {\\tt DE}.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsBSRL\r\n\t\t\\end{DetailEffects}\r\n\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{2}{8}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t% CALL instructions should be here in alphabetical order, but I placed them before B*** above so they can be in the same page spread\r\n\t\\DetailItemSeePageReference{CALL}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{CCF}{}\r\n\t\t{\\IH{C}omplement \\IH{C}arry \\IH{F}lag}\r\n\t\t{\\SymCCF}\r\n\r\n\t\tComplements (inverts) carry flag \\FlagCF{}; if \\FlagCF{} was {\\tt 0} it's now {\\tt 1} and vice versa. Previous value of \\FlagCF{} is copied to \\FlagHF{}.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsCCF\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagHF[]{Documentation says original value of \\FlagCF{} is copied to \\FlagHF{}, however under my tests \\FlagHF{} remained unchanged}\r\n\t\t\t\\DetailFlagCF[]{if \\FlagCF{} was {\\tt 0} it's now {\\tt 1} and vice versa}\r\n\t\t\\end{DetailEffectsFlags}\r\n\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{1}{4}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{CP}{s}\r\n\t\t{\\IH{C}om\\IH{P}are}\r\n\t\t{\\SymCP{s}}\r\n\r\n\t\t\\begin{DetailVariants}[4]\r\n\t\t\tCP A\\\\\r\n\t\t\tCP B\\\\\r\n\t\t\tCP C\\\\\r\n\t\t\tCP D\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\tCP E\\\\\r\n\t\t\tCP H\\\\\r\n\t\t\tCP L\\\\\r\n\t\t\tCP n\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\tCP (HL)\\\\\r\n\t\t\tCP (IX+d)\\\\\r\n\t\t\tCP (IY+d)\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\tCP IXH\\UNDOC\\\\\r\n\t\t\tCP IXL\\UNDOC\\\\\r\n\t\t\tCP IYH\\UNDOC\\\\\r\n\t\t\tCP IYL\\UNDOC\r\n\t\t\\end{DetailVariants}\r\n\r\n\t\tOperand {\\tt s} or content of the memory location addressed by {\\tt s} is subtracted from accumulator {\\tt A}. Status flags are updated according to the result, but the result is then discarded (value of {\\tt A} is not changed).\r\n\r\n\t\t\\begin{DetailEffects}[v]\r\n\t\t\t\\FlagsCPr\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagHF{\\DetailFlagResultHalfBorrow}*\r\n\t\t\t\\DetailFlagPV{\r\n\t\t\t\t\\DetailFlagsList{\r\n\t\t\t\t\t\\item {\\tt A} and {\\tt s} positive and {\\tt A-s} result negative\r\n\t\t\t\t\t\\item {\\tt A} and {\\tt s} negative and {\\tt A-s} result positve\r\n\t\t\t\t}\r\n\t\t\t\t\\DetailFlagResultOverflowListBottomSpacing % we don't want additional space below the table, otherwise next item would have larger gap\r\n\t\t\t}\r\n\t\t\\end{DetailEffectsFlags}\r\n\r\n\t\tOther flags are set like this when {\\tt A} is greater than, equal or less than {\\tt s}:\r\n\r\n\t\t\\begin{DetailEffects}[v][]\r\n\t\t\t\\Flags[A$>$s]{0}{0}{\\FS}{\\FS}{1}{0}\r\n\t\t\t\\Flags[A$=$s]{0}{1}{\\FS}{\\FS}{1}{0}\r\n\t\t\t\\Flags[A$<$s]{1}{0}{\\FS}{\\FS}{1}{1}\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\tWith this in mind, we can derive the programs for common comparisons:\r\n\r\n\t\t\\newcommand{\\CPExampleTitle}[1]{{\\tt #1}\\vspace{-1.5ex}}\r\n\r\n\t\t%-----------------------------------------------------------------------------------------------------\r\n\t\t\\begin{multicols}{2}\r\n\t\t\t\\CPExampleTitle{A=s}\r\n\t\t\t\\begin{tcblisting}{right skip=1em}\r\n\tCP s\r\n\tJP Z, true ; A=s?\r\nfalse: ; A!=s\r\ntrue:   ; A=s\r\n\t\t\t\\end{tcblisting}\r\n\r\n\t\t\t\\CPExampleTitle{A$\\neq$s}\r\n\t\t\t\\begin{tcblisting}{}\r\n\tCP s\r\n\tJP NZ, true ; A!=s?\r\nfalse: ; A=s\r\ntrue:   ; A!=s\r\n\t\t\t\\end{tcblisting}\r\n\t\t\\end{multicols}\r\n\r\n\t\t%-----------------------------------------------------------------------------------------------------\r\n\t\t\\begin{multicols}{2}\r\n\t\t\t\\CPExampleTitle{A$\\leqslant$s}\r\n\t\t\t\\begin{tcblisting}{right skip=1em}\r\n\tCP s\r\n\tJP M, true  ; A<s?\r\n\tJP Z, true  ; A=s?\r\nfalse: ; A>s\r\ntrue:   ; A<=s\r\n\t\t\t\\end{tcblisting}\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\t\\CPExampleTitle{A<s}\r\n\t\t\t\\begin{tcblisting}{}\r\n\tCP s\r\n\tJP M, true ; A<s?\r\nfalse: ; A>=s\r\ntrue:   ; A<s\r\n\t\t\t\\end{tcblisting}\r\n\t\t\\end{multicols}\r\n\r\n\t\t%-----------------------------------------------------------------------------------------------------\r\n\t\t\\begin{multicols}{2}\r\n\t\t\t\\CPExampleTitle{A$\\geqslant$s}\r\n\t\t\t\\begin{tcblisting}{right skip=1em}\r\n\tCP s\r\n\tJP M, false ; A<s?\r\ntrue:   ; A>=s\r\nfalse: ; A<s\r\n\t\t\t\\end{tcblisting}\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\t\\CPExampleTitle{A>s}\r\n\t\t\t\\begin{tcblisting}{}\r\n\tCP s\r\n\tJP M, false ; A<s?\r\n\tJP Z, false ; A=s?\r\ntrue:   ; A>s\r\nfalse: ; A<=s\r\n\t\t\t\\end{tcblisting}\r\n\t\t\\end{multicols}\r\n\r\n\t\t\\DetailNote[-1ex]{\r\n\t\t\tNote: the examples use two labels to emphasize both results. But only one is needed. Furthermore, depending on the actual needs, the programs can also use no label at all. For example, we can use {\\tt RET} instead of {\\tt JP} when used within a subroutine, and the desired outcome is to return if the condition is not met:\r\n\t\t}\r\n\r\n\t\t%-----------------------------------------------------------------------------------------------------\r\n\t\t\\begin{multicols}{2}\r\n\t\t\t\\CPExampleTitle{A=s}\r\n\t\t\t\\begin{tcblisting}{right skip=1em}\r\n\tCP s\r\n\tRET NZ ; A!=s?\r\n\t; A=s\r\n\t\t\t\\end{tcblisting}\r\n\r\n\t\t\t\\CPExampleTitle{A$\\neq$s}\r\n\t\t\t\\begin{tcblisting}{}\r\n\tCP s\r\n\tRET Z ; A=s?\r\n\t; A!=s\r\n\t\t\t\\end{tcblisting}\r\n\t\t\\end{multicols}\r\n\r\n\t\t%-----------------------------------------------------------------------------------------------------\r\n\t\t\\begin{multicols}{2}\r\n\t\t\t\\CPExampleTitle{A$\\leqslant$s}\r\n\t\t\t\\begin{tcblisting}{right skip=1em}\r\n\tCP s\r\n\tJP M, true  ; A<s?\r\n\tJP Z, true  ; A=s?\r\n\tRET         ; A>s\r\ntrue:   ; A<=s\r\n\t\t\t\\end{tcblisting}\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\t\\CPExampleTitle{A<s}\r\n\t\t\t\\begin{tcblisting}{}\r\n\tCP s\r\n\tRET P ; A>=s?\r\n\t; A<s\r\n\t\t\t\\end{tcblisting}\r\n\t\t\\end{multicols}\r\n\r\n\t\t%-----------------------------------------------------------------------------------------------------\r\n\t\t\\begin{multicols}{2}\r\n\t\t\t\\CPExampleTitle{A$\\geqslant$s}\r\n\t\t\t\\begin{tcblisting}{right skip=1em}\r\n\tCP s\r\n\tRET M ; A<s?\r\n\t; A>=s\r\n\t\t\t\\end{tcblisting}\r\n\r\n\t\t\t\\CPExampleTitle{A>s}\r\n\t\t\t\\begin{tcblisting}{}\r\n\tCP s\r\n\tRET M ; A<s?\r\n\tRET Z ; A=s?\r\n\t; A>s\r\n\t\t\t\\end{tcblisting}\r\n\t\t\\end{multicols}\r\n\r\n\t\t\\DetailNote[-1ex]{\r\n\t\t\tNote: some of the comparisons are reversed. And {\\tt A$\\leqslant$s} still requires a label because the condition is true if either \\FlagSF{} or \\FlagZF{} is set.\r\n\t\t}\r\n\r\n\t\t\\DetailNote{\r\n\t\t\tNote: I opted to use \\FlagSF{} for some of the comparisons. It makes more sense to me this way. But you can just as well use \\FlagCF{} instead. As evident from the table on the previous page, both flags are updated the same way, so you could use {\\tt JP C} or {\\tt RET C} instead of {\\tt M} and {\\tt JP NZ} or {\\tt RET NZ} instead of {\\tt P}. This is due to {\\tt CP} performing a subtraction {\\tt A-s} internally. So when {\\tt s} is greater than {\\tt A}, the result of the subtraction is negative, meaning the sign flag is set. At the same time a borrow is needed, so the carry is set too. I thought it's worth mentioning since you may find examples using the carry flag elsewhere and wonder why.\r\n\t\t}\r\n\r\n\t\t\\vspace{2ex} % some vertical gap between notes and timings\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime[r]{1}{4}\r\n\t\t\t\\DetailTime[n]{2}{7}\r\n\t\t\t\\DetailTime[(HL)]{2}{7}\r\n\t\t\t\\DetailTime[(IX+d)]{5}{19}\r\n\t\t\t\\DetailTime[(IY+d)]{5}{19}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{CPD}{}\r\n\t\t{\\IH{C}om\\IH{P}are and \\IH{D}ecrement}\r\n\t\t{\\SymCPD}\r\n\r\n\t\tSubtracts contents of memory location addressed by {\\tt HL} register pair from accumulator {\\tt A}. Result is then discarded. Afterwards both {\\tt HL} and {\\tt BC} are decremented.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsCPD\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagSF{{\\tt A<(HL)} before {\\tt HL} is decremented}\r\n\t\t\t\\DetailFlagZF{{\\tt A=(HL)} before {\\tt HL} is decremented}\r\n\t\t\t\\DetailFlagPV{{\\tt BC$\\neq$0} after execution}\r\n\t\t\\end{DetailEffectsFlags}\r\n\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{4}{16}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{CPDR}{}\r\n\t\t{\\IH{C}om\\IH{P}are and \\IH{D}ecrement \\IH{R}epeated}\r\n\t\t{\\SymCPDR}\r\n\r\n\t\tRepeats {\\tt CPD} until either {\\tt A=(HL)} or {\\tt BC=0}. If {\\tt BC} is set to {\\tt 0} before instruction execution, it loops through 64KB if no match is found. See {\\tt CPIR} for example.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsCPDR\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagSF{{\\tt A<(HL)} before {\\tt HL} is decremented}\r\n\t\t\t\\DetailFlagZF{{\\tt A=(HL)} before {\\tt HL} is decremented}\r\n\t\t\t\\DetailFlagPV{{\\tt BC$\\neq$0} after execution}\r\n\t\t\\end{DetailEffectsFlags}\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTimeRegular[{\\tt BC}=0 or {\\tt A}={\\tt (HL)}]{4}{16}\r\n\t\t\t\\DetailTimeRegular[{\\tt BC}$\\neq$0 and {\\tt A}$\\neq${\\tt (HL)}]{5}{21}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{CPI}{}\r\n\t\t{\\IH{C}om\\IH{P}are and \\IH{I}ncrement}\r\n\t\t{\\SymCPI}\r\n\r\n\t\tSubtracts contents of memory location addressed by {\\tt HL} register pair from accumulator {\\tt A}. Result is then discarded. Afterwards {\\tt HL} is incremented and {\\tt BC} decremented.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsCPI\r\n\t\t\\end{DetailEffects}\r\n\t\t\t\t\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagSF{{\\tt A<(HL)} before {\\tt HL} is decremented}\r\n\t\t\t\\DetailFlagZF{{\\tt A=(HL)} before {\\tt HL} is decremented}\r\n\t\t\t\\DetailFlagPV{{\\tt BC$\\neq$0} after execution}\r\n\t\t\\end{DetailEffectsFlags}\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{4}{16}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{CPIR}{}\r\n\t\t{\\IH{C}om\\IH{P}are and \\IH{D}ecrement \\IH{R}epeated}\r\n\t\t{\\SymCPIR}\r\n\r\n\t\tRepeats {\\tt CPI} until either {\\tt A=(HL)} or {\\tt BC=0}. If {\\tt BC} is set to {\\tt 0} before instruction execution, it loops through 64KB if no match is found.\r\n\r\n\t\tExample, searching for {\\tt \\$AB} in memory from \\MemAddr{0000}-\\MemAddr{999}:\r\n\r\n\t\t\\begin{multicols}{2}\r\n\t\t\t{\\tt CPIR} = finding first occurrence:\r\n\t\t\t\\begin{tcblisting}{right skip=1em}\r\nLD HL, &0000\r\nLD BC, &0999\r\nLD A, &AB\r\nCPIR\r\n\t\t\t\\end{tcblisting}\r\n\r\n\t\t\t{\\tt CPDR} = finding last occurrence:\r\n\t\t\t\\begin{tcblisting}{}\r\nLD HL, &0999\r\nLD BC, &0999\r\nLD A, &AB\r\nCPDR\r\n\t\t\t\\end{tcblisting}\r\n\t\t\\end{multicols}\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsCPIR\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagSF{{\\tt A<(HL)} before {\\tt HL} is decremented}\r\n\t\t\t\\DetailFlagZF{{\\tt A=(HL)} before {\\tt HL} is decremented}\r\n\t\t\t\\DetailFlagPV{{\\tt BC$\\neq$0} after execution}\r\n\t\t\\end{DetailEffectsFlags}\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTimeRegular[{\\tt BC}=0 or {\\tt A}={\\tt (HL)}]{4}{16}\r\n\t\t\t\\DetailTimeRegular[{\\tt BC}$\\neq$0 and {\\tt A}$\\neq${\\tt (HL)}]{5}{21}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t% by moving CPL to next page, we can have DAA fit the whole of the page. Otherwise last part (timing) doesn't fit the same page (it's still in the same spread, but this way it's nicer)\r\n\t\\DetailItemsSeePageReference{CPL}{See next page}\r\n\r\n\t\\begin{DetailItem}{DAA}{}\r\n\t\t{\\IH{D}ecimal \\IH{A}djust \\IH{A}ccumulator}\r\n\t\t{}\r\n\r\n\t\tUpdates accumulator {\\tt A} for BCD correction after arithmetic operations using the following algorithm:\r\n\r\n\t\t\\begin{enumerate}\r\n\t\t\t\\item The least significant 4 bits of accumulator {\\tt A} (low nibble) are checked first. If they contain invalid BCD number (greater than 9), or \\FlagHF{} is set, the value of {\\tt A} is adjusted based on the value of \\FlagNF{}: if it's reset, {\\tt \\$06} is added to {\\tt A}, if set, {\\tt \\$06} is removed from {\\tt A}.\r\n\t\t\t\\item Then 4 most significant bits of accumulator {\\tt A} (high nibble) are checked in a similar fashion. If they contain invalid BCD number, or \\textbf{CF} is set, the value of {\\tt A} is adjusted: if \\FlagNF{} is not set, {\\tt \\$60} is added to {\\tt A}, if \\FlagNF{} is set, {\\tt \\$60} is removed from {\\tt A}.\r\n\t\t\t\\item Finally flags are changed accordingly, as described below.\r\n\t\t\\end{enumerate}\r\n\r\n\t\t% Symbolically, the algorithm could be expressed as:\r\n\r\n\t\t% {\r\n\t\t% \t\\tt \\small\r\n\t\t% \tif (A$\\wedge$\\$0F>\\$09)$\\vee$(HF=1):\\\\\r\n\t\t% \t\\hspace*{1em}if NF=0:~A$\\leftarrow$A+\\$06~else:~A$\\leftarrow$A-\\$06\\\\\r\n\t\t% \tif (A$\\wedge$\\$F0>\\$90)$\\vee$(CF=1):\\\\\r\n\t\t% \t\\hspace*{1em}if NF=0:~A$\\leftarrow$A+\\$60~else:~A$\\leftarrow$A-\\$60\\\\\r\n\t\t% }\r\n\t\t\r\n\t\t\\begin{DetailEffects}[p]\r\n\t\t\t\\FlagsDAA\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\newcommand{\\DAAIn}[1]{#1}\r\n\t\t\\newcommand{\\DAAOut}[1]{\\RArrow{6pt}#1}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagSF{\\DetailFlagResultSign[A] after operation}\r\n\t\t\t\\DetailFlagZF{\\DetailFlagResultZero[A] after operation}*\r\n\t\t\t\\DetailFlagHF[depends on:]{\r\n\t\t\t\tinput values of \\FlagNF{}, \\FlagHF{} and bits 0-3 of {\\tt A}:\r\n\t\t\t\t{\r\n\t\t\t\t\t\\tt\r\n\t\t\t\t\t\\begin{tabular}{ccc|c}\r\n\t\t\t\t\t\t\\DAAIn{NF} & \\DAAIn{HF} & \\DAAIn{A\\textsubscript{{[}3-0{]}}} & \\DAAOut{HF} \\notet\\noteb \\\\\r\n\t\t\t\t\t\t\\hline\r\n\t\t\t\t\t\t0 & * & 0-9 & 0 \\notet \\\\\r\n\t\t\t\t\t\t0 & * & A-F & 1 \\notet \\\\\r\n\t\t\t\t\t\t1 & 0 & * & 0 \\notet \\\\\r\n\t\t\t\t\t\t1 & 1 & 0-5 & 1 \\notet \\\\\r\n\t\t\t\t\t\t1 & 1 & 6-F & 0 \\notet\\noteb \\\\\r\n\t\t\t\t\t\\end{tabular}\r\n\t\t\t\t}\r\n\t\t\t}*\r\n\t\t\t\\DetailFlagPV{\\DetailFlagResultParity[A] after operation}\r\n\t\t\\end{DetailEffectsFlags}\r\n\r\n\t\t\\vspace*{-1ex} % using separate DetailEffectsFlags allows us to control vertical spacing between CF and PV\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagCF[depends on:]{\r\n\t\t\t\tinput values of \\textbf{CF} and both nibbles of {\\tt A}:\r\n\t\t\t\t{\r\n\t\t\t\t\t\\tt\r\n\t\t\t\t\t\\begin{tabular}{ccc|c}\r\n\t\t\t\t\t\t\\DAAIn{CF} & \\DAAIn{A\\textsubscript{{[}7-4{]}}} & \\DAAIn{A\\textsubscript{{[}3-0{]}}} & \\DAAOut{CF} \\notet\\noteb \\\\\r\n\t\t\t\t\t\t\\hline\r\n\t\t\t\t\t\t0 & 0-9 & 0-9 & 0 \\notet \\\\\r\n\t\t\t\t\t\t0 & 0-8 & A-F & 0 \\notet \\\\\r\n\t\t\t\t\t\t0 & 9-F & A-F & 1 \\notet \\\\\r\n\t\t\t\t\t\t0 & A-F & 0-9 & 1 \\notet \\\\\r\n\t\t\t\t\t\t1 & * & * & 1 \\notet\\noteb \\\\\r\n\t\t\t\t\t\\end{tabular}\r\n\t\t\t\t}\r\n\t\t\t}*\r\n\t\t\\end{DetailEffectsFlags}\r\n\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{1}{4}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{CPL}{}\r\n\t\t{\\IH{C}om\\IH{PL}ement accumulator}\r\n\t\t{\\SymCPL}\r\n\r\n\t\tComplements (inverts) all bits of the accumulator {\\tt A} and stores the result back to {\\tt A}.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsCPL\r\n\t\t\\end{DetailEffects}\r\n\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{1}{4}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{DEC}{s}\r\n\t\t{\\IH{DEC}rement}\r\n\t\t{\\SymDEC{s}}\r\n\r\n\t\t\\begin{DetailVariants}\r\n\t\t\t\\textnormal{8-bit}\\\\\r\n\t\t\tDEC A\\\\\r\n\t\t\tDEC B\\\\\r\n\t\t\tDEC C\\\\\r\n\t\t\tDEC D\\\\\r\n\t\t\tDEC E\\\\\r\n\t\t\tDEC H\\\\\r\n\t\t\tDEC L\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\t\\textnormal{8-bit}\\\\\r\n\t\t\tDEC (HL)\\\\\r\n\t\t\tDEC (IX+d)\\\\\r\n\t\t\tDEC (IY+d)\\\\\r\n\t\t\tDEC IXH\\UNDOC\\\\\r\n\t\t\tDEC IXL\\UNDOC\\\\\r\n\t\t\tDEC IYH\\UNDOC\\\\\r\n\t\t\tDEC IYL\\UNDOC\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\t\\textnormal{16-bit}\\\\\r\n\t\t\tDEC BC\\\\\r\n\t\t\tDEC DE\\\\\r\n\t\t\tDEC HL\\\\\r\n\t\t\tDEC IX\\\\\r\n\t\t\tDEC IY\\\\\r\n\t\t\tDEC SP\r\n\t\t\\end{DetailVariants}\r\n\r\n\t\tDecrements the operand {\\tt s} or memory addressed by {\\tt s} by 1.\r\n\r\n\t\t\\begin{DetailEffects}[v]\r\n\t\t\t\\FlagsDECr[8-bit]\r\n\t\t\t\\FlagsDECrr[16-bit (no effect)]\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagSF[8-bit only, set if:]{\\DetailFlagResultSign}\r\n\t\t\t\\DetailFlagZF[8-bit only, set if:]{\\DetailFlagResultZero}\r\n\t\t\t\\DetailFlagHF[8-bit only, set if:]{\\DetailFlagResultHalfBorrow}\r\n\t\t\t\\DetailFlagPV[8-bit only, set if:]{value was {\\tt \\$80} before decrementing}\r\n\t\t\\end{DetailEffectsFlags}\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime[r]{1}{4}\r\n\t\t\t\\DetailTime[rr]{1}{6}\r\n\t\t\t\\DetailTime[IX]{2}{10}\r\n\t\t\t\\DetailTime[IY]{2}{10}\r\n\t\t\t\\DetailTime[(HL)]{3}{11}\r\n\t\t\t\\DetailTime[(IX+d)]{6}{23}\r\n\t\t\t\\DetailTime[(IY+d)]{6}{23}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{DI}{}\r\n\t\t{\\IH{D}isable \\IH{I}nterrupts}\r\n\t\t{\\SymDI}\r\n\r\n\t\tDisables all maskable interrupts (mode 1 and 2). Interrupts are disabled after execution of the instruction following {\\tt DI}. See sections \\XRef{z80_interrupts} and \\XRef{zx_next_interrupts} for more details on interrupts.\r\n\t\t\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsDI\r\n\t\t\\end{DetailEffects}\r\n\t\t\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{1}{4}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{DJNZ}{e}\r\n\t\t{\\IH{D}ecrement {\\tt B} and \\IH{J}ump if \\IH{N}ot \\IH{Z}ero}\r\n\t\t{\\SymDJNZ{e}}\r\n\r\n\t\tDecrements {\\tt B} register and jumps to the given relative address if {\\tt B$\\neq$0}. Given offset is added to the value of {\\tt PC} after parsing {\\tt DJNZ} instruction, so effective offset it {\\tt -126} to {\\tt +129}. Assembler automatically subtracts {\\tt 2} from offset value {\\tt e} to generate opcode.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsDJNZ\r\n\t\t\\end{DetailEffects}\r\n\t\t\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTimeRegular[{\\tt B}=0]{2}{8}\r\n\t\t\t\\DetailTimeRegular[{\\tt B}$\\neq$0]{3}{13}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{EI}{}\r\n\t\t{\\IH{E}nable \\IH{I}nterrupts}\r\n\t\t{\\SymEI}\r\n\r\n\t\tEnables maskable interrupts (mode 1 and 2). Interrupts are enabled after execution of the instruction following {\\tt EI}; typically {\\tt RETI} or {\\tt RETN}. See sections \\XRef{z80_interrupts} and \\XRef{zx_next_interrupts} for more details on interrupts.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsEI\r\n\t\t\\end{DetailEffects}\r\n\t\t\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{1}{4}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{EX}{d,s}\r\n\t\t{\\IH{EX}change register pair}\r\n\t\t{\\SymEX{d}{s}}\r\n\r\n\t\t\\begin{DetailVariants}\r\n\t\t\tEX AF,AF'\\\\\r\n\t\t\tEX DE,HL\\\\\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\tEX (SP),HL\\\\\r\n\t\t\tEX (SP),IX\\\\\r\n\t\t\tEX (SP),IY\r\n\t\t\\end{DetailVariants}\r\n\r\n\t\tExchanges contents of two register pairs or register pair and last value pushed to stack. For example:\r\n\r\n\t\t\\begin{tabular}{llcl}\r\n\t\t\t\\multicolumn{2}{c}{BEFORE} & & AFTER \\\\[5pt]\r\n\t\t\tReg & \\multicolumn{3}{l}{Value} \\\\[5pt]\r\n\t\t\t{\\tt HL} & \r\n\t\t\t\t\\MemAddr{ABCD} & \r\n\t\t\t\t\\multirow{5}{*}{$\\rightarrow$ {\\tt EX (SP),HL} $\\rightarrow$} & \r\n\t\t\t\t\\MemAddr{3412}\\\\\r\n\t\t\t{\\tt SP} & \\MemAddr{0B00} & & \\MemAddr{0B00}\\\\[5pt]\r\n\t\t\tMem & Value \\\\[5pt]\r\n\t\t\t\\MemAddr{0B00} & {\\tt \\$12} & & {\\tt \\$CD}\\\\\r\n\t\t\t\\MemAddr{0B01} & {\\tt \\$34} & & {\\tt \\$AB}\\\\\r\n\t\t\\end{tabular}\\\\[5pt] % some spacing between table and effects\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsEXaf[{\\tt EX AF,AF'}]\r\n\t\t\t\\FlagsEXrr[Other variants no effect]\r\n\t\t\t\\DetailFlagsComments{\r\n\t\t\t\t\\item {\\tt EX AF,AF'} sets flags directly from the value of {\\tt F'}\r\n\t\t\t}\r\n\t\t\\end{DetailEffects}\r\n\t\t\t\t\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime[rr,rr]{1}{4}\r\n\t\t\t\\DetailTime[(SP),HL]{5}{19}\r\n\t\t\t\\DetailTime[(SP),IX]{6}{23}\r\n\t\t\t\\DetailTime[(SP),IY]{6}{23}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{EXX}{}\r\n\t\t{\\IH{EX}change alternate registers}\r\n\t\t{\\SymEXX}\r\n\r\n\t\tExchanges contents of registers {\\tt BC}, {\\tt DE} and {\\tt HL} with shadow registers {\\tt BC'}, {\\tt DE'} and {\\tt HL'}. The most frequent use is in interrupt handlers as an alternative to using the stack for saving and restoring register values. If using outside interrupt handlers, interrupts must be disabled before using this instruction.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsEXX\r\n\t\t\\end{DetailEffects}\r\n\t\t\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{1}{4}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{HALT}{}\r\n\t\t{\\IH{HALT}}\r\n\t\t{}\r\n\r\n\t\tSuspends CPU and executes {\\tt NOP}s (to continue memory refresh cycles) until the next interrupt or reset. This effectively creates a delay. You can chain {\\tt HALT}s. But make sure that there will be an interrupt, otherwise {\\tt HALT} will run forever.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsHALT\r\n\t\t\\end{DetailEffects}\r\n\t\t\t\t\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{1}{4}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{IM}{n}\r\n\t\t{\\IH{I}nterrupt \\IH{M}ode}\r\n\t\t{}\r\n\r\n\t\t\\begin{DetailVariants}[2]\r\n\t\t\tIM 0\\\\\r\n\t\t\tIM 1\\\\\r\n\t\t\tIM 2\r\n\t\t\t\r\n\t\t\t\\columnbreak\r\n\t\t\t~\r\n\t\t\\end{DetailVariants}\r\n\r\n\t\tSets the interrupt mode. All 3 interrupts are maskable, meaning they can be disabled using {\\tt DI} instruction. See sections \\XRef{z80_interrupts} and \\XRef{zx_next_interrupts} for details and example.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsIM\t\t\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{2}{8}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{IN}{r,(s)}\r\n\t\t{\\IH{IN}put from port}\r\n\t\t{\\SymIN{r}{s}}\r\n\r\n\t\t\\begin{DetailVariants}\r\n\t\t\tIN A,(n)\\\\\r\n\t\t\tIN A,(C)\\\\\r\n\t\t\tIN B,(C)\\\\\r\n\t\t\tIN C,(C)\\\\\r\n\t\t\tIN D,(C)\\\\\r\n\t\t\tIN E,(C)\\\\\r\n\t\t\tIN H,(C)\\\\\r\n\t\t\tIN L,(C)\\\\\r\n\t\t\tIN (C)\\UNDOC\\\\\r\n\t\t\tIN F,(C)\\UNDOC\r\n\t\t\\end{DetailVariants}\r\n\r\n\t\tReads peripheral device addressed by {\\tt BC} or combination of {\\tt A} and immediate value and stores result in given register. The address is provided as follows:\r\n\r\n\t\t\\begin{tabular}{ccc}\r\n\t\t\t& \\multicolumn{2}{c}{Address Bits} \\\\\r\n\t\t\tVariant & {\\tt 15-8} & {\\tt 7-0} \\\\\r\n\t\t\t\\hline\r\n\t\t\t{\\tt IN A,(n)} & {\\tt A} & {\\tt n} \\\\\r\n\t\t\t{\\tt IN r,(C)} & {\\tt B} & {\\tt C} \\\\\r\n\t\t\\end{tabular}\r\n\t\t\\vspace{1ex} % some spacing before next text for less cluttered layout\r\n\r\n\t\tSo these two have the same result (though, as mentioned in section \\XRef{zx_next_keyboard}, variant on the right is slightly faster, 18 vs 22 T states):\r\n\r\n\t\t\\begin{multicols}{2}\r\n\t\t\t\\begin{tcblisting}{right skip=1em}\r\nLD BC, &DFFE\r\nIN A, (C)\r\n\t\t\t\\end{tcblisting}\r\n\t\t\t\\columnbreak\r\n\t\t\t\\begin{tcblisting}{}\r\nLD A, &DF\r\nIN A, (&FE)\r\n\t\t\t\\end{tcblisting}\r\n\t\t\\end{multicols}\r\n\r\n\t\t\\begin{DetailEffects}[p]\r\n\t\t\t\\FlagsINrc[\\tt IN r,(C)]\r\n\t\t\t\\FlagsINan[{\\tt IN A,(n)} no effect]\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagSF[{\\tt \\small IN r,(C)}, set if:]{input data is negative (bit 7 is set)}\r\n\t\t\t\\DetailFlagZF[{\\tt \\small IN r,(C)}, set if:]{input data is {\\tt 0}}\r\n\t\t\t\\DetailFlagPV[{\\tt \\small IN r,(C)}, set if:]{input data has even number of bits set}\r\n\t\t\\end{DetailEffectsFlags}\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime[r,(n)]{3}{11}\r\n\t\t\t\\DetailTime[r,(C)]{3}{12}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\t\\DetailNote{Note: {\\tt IN (C)} (or its alternative form {\\tt IN F,(C)}) performs an input, but does not store the result, only sets the flags.}\r\n\r\n\t\t\\DetailNote[]{Note: some assemblers also allow {\\tt (BC)} to be used instead of {\\tt (C)}.}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{INC}{s}\r\n\t\t{\\IH{INC}rement}\r\n\t\t{\\SymINC{s}}\r\n\r\n\t\t\\begin{DetailVariants}\r\n\t\t\t\\textnormal{8-bit}\\\\\r\n\t\t\tINC A\\\\\r\n\t\t\tINC B\\\\\r\n\t\t\tINC C\\\\\r\n\t\t\tINC D\\\\\r\n\t\t\tINC E\\\\\r\n\t\t\tINC H\\\\\r\n\t\t\tINC L\r\n\r\n\t\t\t\\textnormal{8-bit}\\\\\r\n\t\t\tINC (HL)\\\\\r\n\t\t\tINC (IX+d)\\\\\r\n\t\t\tINC (IY+d)\\\\\r\n\t\t\tINC IXH\\UNDOC\\\\\r\n\t\t\tINC IXL\\UNDOC\\\\\r\n\t\t\tINC IYH\\UNDOC\\\\\r\n\t\t\tINC IYL\\UNDOC\r\n\r\n\t\t\t\\textnormal{16-bit}\\\\\r\n\t\t\tINC BC\\\\\r\n\t\t\tINC DE\\\\\r\n\t\t\tINC HL\\\\\r\n\t\t\tINC IX\\\\\r\n\t\t\tINC IY\\\\\r\n\t\t\tINC SP\r\n\t\t\\end{DetailVariants}\r\n\r\n\t\tIncrements the operand {\\tt s} or memory addressed by {\\tt s} by 1.\r\n\r\n\t\t\\begin{DetailEffects}[v]\r\n\t\t\t\\FlagsINCr[8-bit]\r\n\t\t\t\\FlagsINCrr[16-bit (no effect)]\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagSF[8-bit only, set if:]{\\DetailFlagResultSign}\r\n\t\t\t\\DetailFlagZF[8-bit only, set if:]{\\DetailFlagResultZero}\r\n\t\t\t\\DetailFlagHF[8-bit only, set if:]{\\DetailFlagResultHalfCarry}\r\n\t\t\t\\DetailFlagPV[8-bit only, set if:]{value was {\\tt \\$7F} before incrementing}\r\n\t\t\\end{DetailEffectsFlags}\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime[r]{1}{6}\r\n\t\t\t\\DetailTime[rr]{1}{6}\r\n\t\t\t\\DetailTime[IX]{2}{10}\r\n\t\t\t\\DetailTime[IY]{2}{10}\r\n\t\t\t\\DetailTime[(HL)]{3}{11}\r\n\t\t\t\\DetailTime[(IX+d)]{6}{23}\r\n\t\t\t\\DetailTime[(IY+d)]{6}{23}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t% with an empty page, we can achieve nice spreads for upcoming related instructions...\r\n\t\\pagebreak\r\n\t\\IntentionallyEmpty\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{IND}{}\r\n\t\t{\\IH{IN}put and \\IH{D}ecrement}\r\n\t\t{\\SymIND}\r\n\r\n\t\tReads peripheral device addressed by {\\tt BC} and stores the result in memory addressed by {\\tt HL} register pair. Then decrements {\\tt HL} and {\\tt B}.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsIND\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagSF[]{destroyed on Next, Z80 see \\XRef{z80_undocumented_instructions_io_block}}\r\n\t\t\t\\DetailFlagZF{{\\tt B} becomes zero after decrementing}\r\n\t\t\t\\DetailFlagHF[]{destroyed on Next, Z80 see \\XRef{z80_undocumented_instructions_io_block}}\r\n\t\t\t\\DetailFlagPV[]{destroyed on Next, Z80 see \\XRef{z80_undocumented_instructions_io_block}}\r\n\t\t\\end{DetailEffectsFlags}\r\n\t\t\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{4}{16}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{INDR}{}\r\n\t\t{\\IH{IN}put and \\IH{D}ecrement \\IH{R}epeated}\r\n\t\t{\\SymINDR}\r\n\r\n\t\tRepeats {\\tt IND} until {\\tt B=0}.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsINDR\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagSF[]{destroyed on Next, Z80 see \\XRef{z80_undocumented_instructions_io_block}}\r\n\t\t\t\\DetailFlagHF[]{destroyed on Next, Z80 see \\XRef{z80_undocumented_instructions_io_block}}\r\n\t\t\t\\DetailFlagPV[]{destroyed on Next, Z80 see \\XRef{z80_undocumented_instructions_io_block}}\r\n\t\t\\end{DetailEffectsFlags}\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTimeRegular[{\\tt B}=0]{4}{16}\r\n\t\t\t\\DetailTimeRegular[{\\tt B}$\\neq$0]{5}{21}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{INI}{}\r\n\t\t{\\IH{IN}put and \\IH{I}ncrement}\r\n\t\t{\\SymINI}\r\n\r\n\t\tReads peripheral device addressed by {\\tt BC} and stores the result in memory addressed by {\\tt HL} register pair. Then increments {\\tt HL} and decrements {\\tt B}.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsINI\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagSF[]{destroyed on Next, Z80 see \\XRef{z80_undocumented_instructions_io_block}}\r\n\t\t\t\\DetailFlagZF{{\\tt B} becomes zero after decrementing}\r\n\t\t\t\\DetailFlagHF[]{destroyed on Next, Z80 see \\XRef{z80_undocumented_instructions_io_block}}\r\n\t\t\t\\DetailFlagPV[]{destroyed on Next, Z80 see \\XRef{z80_undocumented_instructions_io_block}}\r\n\t\t\\end{DetailEffectsFlags}\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{4}{16}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{INIR}{}\r\n\t\t{\\IH{IN}put and \\IH{I}ncrement \\IH{R}epeated}\r\n\t\t{\\SymINIR}\r\n\r\n\t\tRepeats {\\tt INI} until {\\tt B=0}.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsINIR\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagSF[]{destroyed on Next, Z80 see \\XRef{z80_undocumented_instructions_io_block}}\r\n\t\t\t\\DetailFlagHF[]{destroyed on Next, Z80 see \\XRef{z80_undocumented_instructions_io_block}}\r\n\t\t\t\\DetailFlagPV[]{destroyed on Next, Z80 see \\XRef{z80_undocumented_instructions_io_block}}\r\n\t\t\\end{DetailEffectsFlags}\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTimeRegular[{\\tt B}=0]{4}{16}\r\n\t\t\t\\DetailTimeRegular[{\\tt B}$\\neq$0]{5}{21}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{JP}{nn}\r\n\t\t{\\IH{J}um\\IH{P}}\r\n\t\t{\\SymJP{nn}}\r\n\r\n\t\t\\begin{DetailVariants}\r\n\t\t\tJP nn\\\\\r\n\t\t\tJP (HL)\r\n\t\t\t\r\n\t\t\t\\columnbreak\r\n\t\t\tJP (IX)\\\\\r\n\t\t\tJP (IY)\r\n\t\t\\end{DetailVariants}\r\n\r\n\t\tUnconditionally jumps (changes program counter {\\tt PC} to point) to the given absolute address or the memory location addressed by register pair. Unconditional jumps are the fastest way of changing program counter, even faster than {\\tt JR}, but they take more bytes.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsJPnn\r\n\t\t\\end{DetailEffects}\r\n\t\t\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime[(HL)]{1}{4}\r\n\t\t\t\\DetailTime[(IX)]{2}{8}\r\n\t\t\t\\DetailTime[(IY)]{2}{8}\r\n\t\t\t\\DetailTime[nn]{3}{10}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{JP c,nn}{}\r\n\t\t{\\IH{J}um\\IH{P} conditionally}\r\n\t\t{\\SymJPc{nn}}\r\n\r\n\t\t\\vspace{1ex} % we need some vertical space to achieve same separation as with multicols\r\n\t\t\\begin{tabular}{@{}llcll}\t\t\t\r\n\t\t\t{\\tt JP C,nn} & jumps if \\FlagCF{} is set & &\r\n\t\t\t\t{\\tt JP M,nn} & jumps if \\FlagSF{} is set\\\\\r\n\r\n\t\t\t{\\tt JP NC,nn} & jumps if \\FlagCF{} is reset & &\r\n\t\t\t\t{\\tt JP P,nn} & jumps if \\FlagSF{} is reset\\\\\r\n\r\n\t\t\t{\\tt JP Z,nn} & jumps if \\FlagZF{} is set & &\r\n\t\t\t\t{\\tt JP PE,nn} & jumps if \\FlagPV{} is set\\\\\r\n\r\n\t\t\t{\\tt JP NZ,nn} & jumps if \\FlagZF{} is reset & &\r\n\t\t\t\t{\\tt JP PO,nn} & jumps if \\FlagPV{} is reset\\\\\r\n\t\t\\end{tabular}\r\n\r\n\t\tConditionally jumps to the given absolute address. See {\\tt CP} on page \\DetailItemPageRef{CP} for more details on comparisons.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsJPccnn\r\n\t\t\\end{DetailEffects}\r\n\t\t\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{3}{10}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{JP (C)}{\\DetailItemZXN}\r\n\t\t{\\IH{J}um\\IH{P}}\r\n\t\t{\\SymJPC}\r\n\r\n\t\tSets bottom 14 bits of current program counter {\\tt PC}\\See{*} to value read from I/O port: {\\tt PC[13-0] = (IN (C) << 6)}. Can be used to execute code block read from a disk stream.\r\n\t\t\r\n\t\t\\DetailNote[]{\\See{*}``Current {\\tt PC}'' is the address of the next instruction after {\\tt JP (C)}; {\\tt PC} was already advanced after fetching {\\tt JP (C)} instruction from memory. If {\\tt JP (C)} instruction is located at the very end of 16K memory block (\\MemAddr{..FE} or \\MemAddr{..FF} address), then the new {\\tt PC} value will land into the following 16K block.}\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsJPc\r\n\t\t\\end{DetailEffects}\r\n\t\t\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{3}{13}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{JR}{e}\r\n\t\t{\\IH{J}ump \\IH{R}elative}\r\n\t\t{\\SymJR{e}}\r\n\t\t\r\n\t\tUnconditionally performs relative jump. Offset {\\tt e} is added to the value of program counter {\\tt PC} as signed value to allow jumps forward and backward. Offset is added to {\\tt PC} after {\\tt JR} instruction is read (aka {\\tt PC+2}), so offset is in the range of {\\tt -126} to {\\tt 129}. Assembler automatically subtracts {\\tt 2} from offset value {\\tt e} to generate opcode.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsJRn\r\n\t\t\\end{DetailEffects}\r\n\t\t\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{3}{12}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{JR c,n}{}\r\n\t\t{\\IH{J}ump \\IH{R}elative conditionally}\r\n\t\t{\\SymJRc{c}{n}}\r\n\r\n\t\t\\vspace{1ex} % we need some vertical space to achieve same separation as with multicols\r\n\t\t\\begin{tabular}{@{}llcll}\r\n\t\t\t{\\tt JR C,e} & jumps if \\FlagCF{} is set & &\r\n\t\t\t\t{\\tt JR Z,e} & jumps if \\FlagZF{} is set\\\\\r\n\t\t\t{\\tt JR NC,e} & jumps if \\FlagCF{} is reset & &\r\n\t\t\t\t{\\tt JR NZ,e} & jumps if \\FlagZF{} is reset\\\\\r\n\t\t\\end{tabular}\r\n\t\t\r\n\t\tConditionally performs relative jump. Note: in contrast to {\\tt JP}, {\\tt JR} only supports above 4 conditions. See {\\tt CP} on page \\DetailItemPageRef{CP} for more details on conditions.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsJRccn\r\n\t\t\\end{DetailEffects}\r\n\t\t\t\t\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTimeRegular[{\\tt c}=false]{2}{7}\r\n\t\t\t\\DetailTimeRegular[{\\tt c}=true]{3}{12}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{LD}{d,s}\r\n\t\t{\\IH{L}oa\\IH{D}}\r\n\t\t{\\SymLD{d}{s}}\r\n\r\n\t\tLoads source {\\tt s} into destination {\\tt d}. The following combinations are allowed (source {\\tt s} is represented horizontally, destination {\\tt d} vertically):\r\n\r\n\t\t{\r\n\t\t\t\\fontsize{10pt}{10pt}\t% 9pt results in slightly wider table than the rest of the text, but the larger the font, more readable it is, so I prefer it this way (originally \\scripsize was used which makes the table slightly slimer than the rest of the text)\r\n\t\t\t\\setlength{\\tabcolsep}{1pt}\r\n\r\n\t\t\t% note: OO and ii were chosen simply because the difference is noticable in the table below...\r\n\t\t\t% note: OQ and ik are the same, but darker backgrounds\r\n\t\t\t\\newcommand{\\OO}{$\\bullet$}\r\n\t\t\t\\newcommand{\\OQ}{\\cellcolor{PrintableLightMidGray}$\\bullet$}\r\n\t\t\t\\newcommand{\\ii}{\\cellcolor{PrintableLightGray}}\r\n\t\t\t\\newcommand{\\ik}{\\cellcolor{PrintableMidGray}}\r\n\t\t\t\\newcommand{\\Small}[1]{\\FontSize{8.5pt}{#1}}\r\n\t\t\t\\newcommand{\\Mini}[1]{\\FontSize{7.5pt}{#1}}\r\n\r\n\t\t\t\\newcolumntype{A}{>{\\centering\\arraybackslash}p{2.6ex}}\t% A...\r\n\t\t\t\\newcolumntype{B}{>{\\centering\\arraybackslash}p{2.8ex}}\t% BC...\r\n\t\t\t\\newcolumntype{D}{>{\\centering\\arraybackslash}p{3.7ex}}\t% (BC)...\r\n\t\t\t\\newcolumntype{E}{>{\\centering\\arraybackslash}p{5.0ex}}\t% (IX+d)...\r\n\t\t\t\\newcolumntype{?}{!{\\vrule width 0.6pt}} % wider vertical line\r\n\r\n\t\t\t\\begin{changemargin}{-3.2cm}{0cm}\t% let the table extend below the title to allow more width, for more comfortable reading\r\n\t\t\t\t\\begin{tabular}{@{}|c?A|A|A|A|A|A|A?A|A?c|c|c|c?B|B|B|B|B|B?D|D|D?E|E?A|B|D|}\r\n\t\t\t\t\t\\arrayrulecolor{gray}\r\n\t\t\t\t\t\\hline\r\n\t\t\t\t\t& {\\tt A} & {\\tt B} & {\\tt C} & {\\tt D} & {\\tt E} & {\\tt H} & {\\tt L} & {\\tt I} & {\\tt R}\r\n\t\t\t\t\t& {\\tt IXH} & {\\tt IXL} & {\\tt IYH} & {\\tt IYL}\r\n\t\t\t\t\t& {\\tt BC} & {\\tt DE} & {\\tt HL} & {\\tt SP} & {\\tt IX} & {\\tt IY}\r\n\t\t\t\t\t& {\\tt \\Small{(BC)}} & {\\tt \\Small{(DE)}} & {\\tt \\Small{(HL)}}\r\n\t\t\t\t\t& {\\tt \\Mini{(IX+d)}} & {\\tt \\Mini{(IY+d)}}\r\n\t\t\t\t\t& {\\tt n} & {\\tt nn} & {\\tt \\Small{(nn)}} \\\\\r\n\t\t\t\t\t\\hline\r\n\r\n\t\t\t\t\t{\\tt A}      &\\OO&\\OO&\\OO&\\OO&\\OO&\\OO&\\OO&\\OO&\\OO&\\OO&\\OO&\\OO&\\OO&\\ii&\\ii&\\ii&\\ii&\\ii&\\ii&\\OO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OO&\\OO&\\OO&\\ii&\\ii&\\ii&\\ii&\\ii&\\ii&\\ii&\\ii \\\\ \\hline\r\n\t\t\t\t\\end{tabular}\r\n\t\t\t\\end{changemargin}\r\n\t\t}\r\n\r\n\t\t% while moving effects and timing tables to next page presents a gap below variants, it's nonetheless more readable to keep it all together\r\n\t\t\\pagebreak\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsLDair[{\\tt LD A,I} and {\\tt LD A,R}]\r\n\t\t\t\\FlagsLDr[Other variants]\r\n\t\t\\end{DetailEffects}\r\n\t\t\t\t\t\t\r\n\t\t\\begin{DetailTiming}[Timing 8-bit]\r\n\t\t\t\\DetailTime[r,r]{1}{4}\r\n\t\t\t\\DetailTime[r,n]{2}{7}\r\n\t\t\t\\DetailTime[(rr),A]{2}{7}\r\n\t\t\t\\DetailTime[A,(rr)]{2}{7}\r\n\t\t\t\\DetailTime[r,(HL)]{2}{7}\r\n\t\t\t\\DetailTime[(HL),r]{2}{7}\r\n\t\t\t\\DetailTime[A,I]{2}{9}\r\n\t\t\t\\DetailTime[A,R]{2}{9}\r\n\t\t\t\\DetailTime[I,A]{2}{9}\r\n\t\t\t\\DetailTime[R,A]{2}{9}\r\n\t\t\t\\DetailTime[(HL),n]{3}{10}\r\n\t\t\t\\DetailTime[A,(nn)]{4}{13}\r\n\t\t\t\\DetailTime[(nn),A]{4}{13}\r\n\t\t\t\\DetailTime[r,(IX+d)]{5}{19}\r\n\t\t\t\\DetailTime[r,(IY+d)]{5}{19}\r\n\t\t\t\\DetailTime[(IX+d),r]{5}{19}\r\n\t\t\t\\DetailTime[(IX+d),n]{5}{19}\r\n\t\t\t\\DetailTime[(IY+d),r]{5}{19}\r\n\t\t\t\\DetailTime[(IY+d),n]{5}{19}\r\n\t\t\\end{DetailTiming}\r\n\t\t\t\t\t\t\r\n\t\t\\begin{DetailTiming}[Timing 16-bit]\r\n\t\t\t\\DetailTime[SP,HL]{1}{6}\r\n\t\t\t\\DetailTime[SP,IX]{2}{10}\r\n\t\t\t\\DetailTime[SP,IY]{2}{10}\r\n\t\t\t\\DetailTime[rr,nn]{3}{10}\r\n\t\t\t\\DetailTime[IX,nn]{4}{14}\r\n\t\t\t\\DetailTime[IY,nn]{4}{14}\r\n\t\t\t\\DetailTime[(HL),nn]{5}{16}\r\n\t\t\t\\DetailTime[(nn),HL]{5}{16}\r\n\t\t\t\\DetailTime[(IX),nn]{6}{20}\r\n\t\t\t\\DetailTime[(IY),nn]{6}{20}\r\n\t\t\t\\DetailTime[rr,(nn)]{6}{20}\r\n\t\t\t\\DetailTime[(nn),rr]{6}{20}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t% note: LDx instructions are not listed alphabetically, instead all \"single\" operation instructions are listed together on one page spread, while their \"repeat\" variants on the following page spread. I thought this would result in nicer direct comparison of the variants. Plus it fits better on the pages without excess empty space\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{LDD}{}\r\n\t\t{\\IH{L}oa\\IH{D} and \\IH{D}ecrement}\t\t\r\n\t\t{\\SymLDD}\r\n\r\n\t\tLoads contents of memory location addressed by {\\tt HL} to memory location addressed by {\\tt DE}. Then decrements {\\tt DE}, {\\tt HL} and {\\tt BC} register pairs.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsLDD\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagPV{{\\tt BC$\\neq$0} after execution}\r\n\t\t\\end{DetailEffectsFlags}\r\n\t\t\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{4}{16}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{LDDX}{\\DetailItemZXN}\r\n\t\t{\\IH{L}oa\\IH{D} and \\IH{D}ecrement e\\IH{X}tended}\t\t\r\n\t\t{\\SymLDDX}\r\n\r\n\t\tWorks similar to {\\tt LDD} except:\r\n\t\t\\begin{DetailCompactList}\r\n\t\t\t\\item Byte is only copied if it's different from the accumulator {\\tt A}\r\n\t\t\t\\item {\\tt DE} is incremented instead of decremented\r\n\t\t\t\\item Doesn't change flags\r\n\t\t\\end{DetailCompactList}\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsLDDX\r\n\t\t\\end{DetailEffects}\r\n\t\t\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{4}{16}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{LDI}{}\r\n\t\t{\\IH{L}oa\\IH{D} and \\IH{I}ncrement}\t\t\r\n\t\t{\\SymLDI}\r\n\r\n\t\tSame as {\\tt LDD}, except it increments {\\tt DE} and {\\tt HL}.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsLDI\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagPV{{\\tt BC$\\neq$0} after execution}\r\n\t\t\\end{DetailEffectsFlags}\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{4}{16}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{LDIX}{\\DetailItemZXN}\r\n\t\t{\\IH{L}oa\\IH{D} and \\IH{I}ncrement e\\IH{X}tended}\t\t\r\n\t\t{\\SymLDIX}\r\n\r\n\t\tWorks similar to {\\tt LDI} except:\r\n\t\t\\begin{DetailCompactList}\r\n\t\t\t\\item Byte is only copied if it's different from the accumulator {\\tt A}\r\n\t\t\t\\item Doesn't change flags\r\n\t\t\\end{DetailCompactList}\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsLDIX\r\n\t\t\\end{DetailEffects}\r\n\t\t\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{4}{16}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t% this item is not in alphabetical order, should be after LDPIRX, but we have empty space here and following set of instructions belong together so want to keep them on the same page\r\n\t\\begin{DetailItem}{LDWS}{\\DetailItemZXN}\r\n\t\t{\\IH{L}oa\\IH{D} \\IH{W}asp \\IH{S}pecial}\r\n\t\t{\\SymLDWS}\r\n\r\n\t\tCopies the byte pointed to by {\\tt HL} to the address pointed to by {\\tt DE}. Then increments {\\tt L} and {\\tt D}. Used for vertically copying bytes to Layer 2 display. Flags are identical to what the {\\tt INC D} instrution would produce.\r\n\t\t\t\r\n\t\t\\begin{DetailEffects}[v]\r\n\t\t\t\\FlagsLDWS\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagSF{\\DetailFlagResultSign[D]}\r\n\t\t\t\\DetailFlagZF{\\DetailFlagResultZero}\r\n\t\t\t\\DetailFlagHF{\\DetailFlagResultHalfCarry}\r\n\t\t\t\\DetailFlagPV{{\\tt D} was {\\tt \\$7F} before incrementing}\r\n\t\t\\end{DetailEffectsFlags}\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{4}{14}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\t\\DetailNote{Note: the source data are read from a single 256B (aligned) block of memory, because only {\\tt L} is incremented, not the whole {\\tt HL} pair.}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t% note: LDxR instructions are not listed alphabetically, instead all \"single\" operation instructions are listed together on one page spread, while their \"repeat\" variants on the following page spread. I thought this would result in nicer direct comparison of the variants. Plus it fits better on the pages without excess empty space\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{LDDR}{}\r\n\t\t{\\IH{L}oa\\IH{D} and \\IH{D}ecrement \\IH{R}epeated}\t\t\r\n\t\t{\\SymLDDR}\r\n\r\n\t\tRepeats {\\tt LDD} until {\\tt BC=0}. {\\tt LDDR} can be used for block transfer. See {\\tt LDIR} on page \\DetailItemPageRef{LDIR} for an example and comparison of both instructions.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsLDDR\r\n\t\t\\end{DetailEffects}\r\n\t\t\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTimeRegular[{\\tt BC}=0]{4}{16}\r\n\t\t\t\\DetailTimeRegular[{\\tt BC}$\\neq$0]{5}{21}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{LDDRX}{\\DetailItemZXN}\r\n\t\t{\\IH{L}oa\\IH{D} and \\IH{D}ecrement \\IH{R}epeated e\\IH{X}tended}\t\t\r\n\t\t{\\SymLDDRX}\r\n\r\n\t\tWorks similar to {\\tt LDDR} except the differences noted at {\\tt LDDX} above.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsLDDRX\r\n\t\t\\end{DetailEffects}\r\n\t\t\t\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTimeRegular[{\\tt BC}=0]{4}{16}\r\n\t\t\t\\DetailTimeRegular[{\\tt BC}$\\neq$0]{5}{21}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{LDIR}{}\r\n\t\t{\\IH{L}oa\\IH{D} and \\IH{I}ncrement \\IH{R}epeated}\t\t\r\n\t\t{\\SymLDIR}\r\n\r\n\t\tRepeats {\\tt LDI} until {\\tt BC=0}. Example of copying 100 bytes from {\\tt source} to {\\tt destination} with {\\tt LDIR} and {\\tt LDDR}:\r\n\r\n\t\t\\begin{multicols}{2}\r\n\t\t\t{\\tt LDIR} = copy forward\r\n\t\t\t\\begin{tcblisting}{right skip=1em}\r\nLD HL, source\r\nLD DE, destination\r\nLD BC, 100\r\nLDIR\r\n\t\t\t\\end{tcblisting}\r\n\t\t\t\r\n\t\t\t\\columnbreak\r\n\t\t\t{\\tt LDDR} = copy backwards\r\n\t\t\t\\begin{tcblisting}{}\r\nLD HL, source+99\r\nLD DE, destination+99\r\nLD BC, 100\r\nLDDR\r\n\t\t\t\\end{tcblisting}\r\n\t\t\\end{multicols}\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsLDIR\r\n\t\t\\end{DetailEffects}\r\n\t\t\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTimeRegular[{\\tt BC}=0]{4}{16}\r\n\t\t\t\\DetailTimeRegular[{\\tt BC}$\\neq$0]{5}{21}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{LDIRX}{\\DetailItemZXN}\r\n\t\t{\\IH{L}oa\\IH{D} and \\IH{I}ncrement \\IH{R}epeated e\\IH{X}tended}\t\t\r\n\t\t{\\SymLDIRX}\r\n\r\n\t\tWorks similar to {\\tt LDIR} except the differences noted at {\\tt LDIX} on previous page.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsLDIRX\r\n\t\t\\end{DetailEffects}\r\n\t\t\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTimeRegular[{\\tt BC}=0]{4}{16}\r\n\t\t\t\\DetailTimeRegular[{\\tt BC}$\\neq$0]{5}{21}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{LDPIRX}{\\DetailItemZXN}\r\n\t\t{\\IH{L}oa\\IH{D} \\IH{P}attern fill and \\IH{I}ncrement \\IH{R}epeated e\\IH{X}tended}\r\n\t\t{\\SymLDPIRX}\r\n\r\n\t\tSimilar to {\\tt LDIRX} except the source byte address is not just {\\tt HL}, but is obtained by using the top 13 bits of {\\tt HL} and lower 3 bits of {\\tt DE}. Furthermore {\\tt HL} is not incremented during the loop; it serves as the base address of the aligned 8-byte lookup table. {\\tt DE} works as destination and also wrapping index 0..7 into the table. This instruction is intended for ``pattern fill'' functionality.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsLDPIRX\r\n\t\t\\end{DetailEffects}\t\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTimeRegular[{\\tt BC}=0]{4}{16}\r\n\t\t\t\\DetailTimeRegular[{\\tt BC}$\\neq$0]{5}{21}\r\n\t\t\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{MUL}{D,E\\ZXN}\r\n\t\t{\\IH{MUL}tiply}\r\n\t\t{\\SymMUL}\r\n\r\n\t\tMultiplies {\\tt D} by {\\tt E}, storing 16-bit result into {\\tt DE}.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsMULde\r\n\t\t\\end{DetailEffects}\r\n\t\t\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{2}{8}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{NEG}{}\r\n\t\t{\\IH{NEG}ate}\r\n\t\t{\\SymNEG}\r\n\r\n\t\tNegates contents of the accumulator {\\tt A} and stores result back to {\\tt A}. You can also think of the operation as subtracting the value of {\\tt A} from {\\tt 0} ({\\tt A$\\leftarrow$0-A}). This way it might be easier to understand effects on flags.\r\n\r\n\t\t\\begin{DetailEffects}[p]\r\n\t\t\t\\FlagsNEG\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagSF{\\DetailFlagResultSign}\r\n\t\t\t\\DetailFlagZF{\\DetailFlagResultZero}\r\n\t\t\t\\DetailFlagHF{\\DetailFlagResultHalfBorrow}\r\n\t\t\t\\DetailFlagPV{{\\tt A} was {\\tt \\$80} before operation}\r\n\t\t\t\\DetailFlagCF{{\\tt A} was not {\\tt \\$00} before operation}\r\n\t\t\\end{DetailEffectsFlags}\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{2}{8}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{NEXTREG}{n,s\\ZXN}\r\n\t\t{set \\IH{NEXT} \\IH{REG}ister value}\r\n\t\t{\\SymNEXTREG{s}}\r\n\r\n\t\t\\begin{DetailVariants}\r\n\t\t\tNEXTREG n,A\\\\\r\n\t\t\tNEXTREG n,n'\r\n\t\t\\end{DetailVariants}\r\n\r\n\t\t% note: we only show page number on second port xref since both are declared on the same page, but if this changes in the future, we should update this text accordingly\r\n\t\tDirectly sets the Next Feature Control Registers without going through ports \\PortTextXRef[]{243B} and \\PortTextXRef[]{253B} (page \\PortPage{243B}). See section \\XRef{zx_next_tbblue_registers} for registers list.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsNEXTREGna\r\n\t\t\\end{DetailEffects}\t\t\r\n\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime[r,A]{4}{17}\r\n\t\t\t\\DetailTime[r,n]{5}{20}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{NOP}{}\r\n\t\t{\\IH{N}o \\IH{OP}eration}\r\n\t\t{}\r\n\r\n\t\tDoes nothing for 4 cycles.\r\n\t\t\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsNOP\r\n\t\t\\end{DetailEffects}\r\n\t\t\t\t\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{1}{4}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{OR}{s}\r\n\t\t{bitwise \\IH{OR}}\r\n\t\t{\\SymOR{s}}\r\n\r\n\t\t\\begin{DetailVariants}[4]\r\n\t\t\tOR A\\\\\r\n\t\t\tOR B\\\\\r\n\t\t\tOR C\\\\\r\n\t\t\tOR D\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\tOR E\\\\\r\n\t\t\tOR H\\\\\r\n\t\t\tOR L\\\\\r\n\t\t\tOR n\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\tOR (HL)\\\\\r\n\t\t\tOR (IX+d)\\\\\r\n\t\t\tOR (IY+d)\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\tOR IXH\\UNDOC\\\\\r\n\t\t\tOR IXL\\UNDOC\\\\\r\n\t\t\tOR IYH\\UNDOC\\\\\r\n\t\t\tOR IYL\\UNDOC\r\n\t\t\\end{DetailVariants}\r\n\r\n\t\t\\begin{tabularx}{\\linewidth}{@{}Xl}\r\n\t\t\tPerforms bitwise or between the accumulator {\\tt A} and operand {\\tt s} or contents of memory addressed by {\\tt s}. Then stores the result back to {\\tt A}. Individual bits are OR'ed as shown on the right:\r\n\t\r\n\t\t\t&\r\n\r\n\t\t\t\\begin{tabular}[t]{cc|c}\r\n\t\t\t\t{\\tt A} & {\\tt s} & Result \\\\\r\n\t\t\t\t\\hline\r\n\t\t\t\t{\\tt 0} & {\\tt 0} & {\\tt 0} \\\\\r\n\t\t\t\t{\\tt 0} & {\\tt 1} & {\\tt 1} \\\\\r\n\t\t\t\t{\\tt 1} & {\\tt 0} & {\\tt 1} \\\\\r\n\t\t\t\t{\\tt 1} & {\\tt 1} & {\\tt 1} \\\\\r\n\t\t\t\\end{tabular}\r\n\r\n\t\t\t\\\\\r\n\t\t\\end{tabularx}\r\n\r\n\t\t\\begin{DetailEffects}[p]\r\n\t\t\t\\FlagsORr\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagSF{\\DetailFlagResultSign}\r\n\t\t\t\\DetailFlagZF{\\DetailFlagResultZero}\r\n\t\t\t\\DetailFlagPV{\\DetailFlagResultParity}\r\n\t\t\\end{DetailEffectsFlags}\r\n\t\t\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime[r]{1}{4}\r\n\t\t\t\\DetailTime[n]{2}{7}\r\n\t\t\t\\DetailTime[(HL)]{2}{7}\r\n\t\t\t\\DetailTime[(IX+d)]{5}{19}\r\n\t\t\t\\DetailTime[(IY+d)]{5}{19}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{OTDR}{}\r\n\t\t{\\IH{O}u\\IH{T}put and \\IH{D}ec\\IH{R}ement}\r\n\t\t{\\SymOTDR}\r\n\r\n\t\tRepeats {\\tt OUTD} (see page \\DetailItemPageRef{OUTD}) until {\\tt B=0}. Similar to {\\tt OTIR} except {\\tt HL} is decremented instead of incremented.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsOTDR\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagSF[]{destroyed on Next, Z80 see \\XRef{z80_undocumented_instructions_io_block}}\r\n\t\t\t\\DetailFlagHF[]{destroyed on Next, Z80 see \\XRef{z80_undocumented_instructions_io_block}}\r\n\t\t\t\\DetailFlagPV[]{destroyed on Next, Z80 see \\XRef{z80_undocumented_instructions_io_block}}\r\n\t\t\\end{DetailEffectsFlags}\r\n\t\t\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTimeRegular[{\\tt B}=0]{4}{16}\r\n\t\t\t\\DetailTimeRegular[{\\tt B}$\\neq$0]{5}{21}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{OTIR}{}\r\n\t\t{\\IH{O}u\\IH{T}put and \\IH{I}nc\\IH{R}ement}\r\n\t\t{\\SymOTIR}\r\n\r\n\t\tRepeats {\\tt OUTI} (see page \\DetailItemPageRef{OUTI}) until {\\tt B=0}. Similar to {\\tt OTDR} except {\\tt HL} is incremented instead of decremented.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsOTIR\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagSF[]{destroyed on Next, Z80 see \\XRef{z80_undocumented_instructions_io_block}}\r\n\t\t\t\\DetailFlagHF[]{destroyed on Next, Z80 see \\XRef{z80_undocumented_instructions_io_block}}\r\n\t\t\t\\DetailFlagPV[]{destroyed on Next, Z80 see \\XRef{z80_undocumented_instructions_io_block}}\r\n\t\t\\end{DetailEffectsFlags}\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTimeRegular[{\\tt B}=0]{4}{16}\r\n\t\t\t\\DetailTimeRegular[{\\tt B}$\\neq$0]{5}{21}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t% we want to keep OUTI and OUTD on the same page spread as their block repeat variants above\r\n\t\\DetailItemSeePageReference{OUT}\r\n\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{OUTD}{}\r\n\t\t{\\IH{OUT}put and \\IH{D}ecrement}\r\n\t\t{\\SymOUTD}\r\n\r\n\t\tOutputs the value from contents of memory addressed by {\\tt HL} to port on address {\\tt BC}. Then decrements both, {\\tt HL} and {\\tt B}.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsOUTD\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagSF[]{destroyed on Next, Z80 see \\XRef{z80_undocumented_instructions_io_block}}\r\n\t\t\t\\DetailFlagZF{{\\tt B=0} after decrement}\r\n\t\t\t\\DetailFlagHF[]{destroyed on Next, Z80 see \\XRef{z80_undocumented_instructions_io_block}}\r\n\t\t\t\\DetailFlagPV[]{destroyed on Next, Z80 see \\XRef{z80_undocumented_instructions_io_block}}\r\n\t\t\\end{DetailEffectsFlags}\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{4}{16}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{OUTI}{}\r\n\t\t{\\IH{OUT}put and \\IH{I}ncrement}\r\n\t\t{\\SymOUTI}\r\n\r\n\t\tSimilar to {\\tt OUTD} except {\\tt HL} is incremented.\r\n\t\t\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsOUTI\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagSF[]{destroyed on Next, Z80 see \\XRef{z80_undocumented_instructions_io_block}}\r\n\t\t\t\\DetailFlagZF{{\\tt B=0} after decrement}\r\n\t\t\t\\DetailFlagHF[]{destroyed on Next, Z80 see \\XRef{z80_undocumented_instructions_io_block}}\r\n\t\t\t\\DetailFlagPV[]{destroyed on Next, Z80 see \\XRef{z80_undocumented_instructions_io_block}}\r\n\t\t\\end{DetailEffectsFlags}\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{4}{16}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{OUT}{(d),s}\r\n\t\t{\\IH{OUT}put to port}\r\n\t\t{\\SymOUT{d}{s}}\r\n\r\n\t\t\\begin{DetailVariants}\r\n\t\t\tOUT (n),A\r\n\t\t\t\r\n\t\t\t\\columnbreak\r\n\t\t\tOUT (C),A\\\\\r\n\t\t\tOUT (C),B\\\\\r\n\t\t\tOUT (C),C\\\\\r\n\t\t\tOUT (C),D\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\tOUT (C),E\\\\\r\n\t\t\tOUT (C),H\\\\\r\n\t\t\tOUT (C),L\\\\\r\n\t\t\tOUT (C),0\\UNDOC\r\n\t\t\\end{DetailVariants}\r\n\r\n\t\tWrites the value of operand {\\tt s} to the port at address {\\tt d}. Port addresses are always 16-bit values defined like this:\r\n\r\n\t\t\\begin{tabular}{ccc}\r\n\t\t\t& \\multicolumn{2}{c}{Address Bits} \\\\\r\n\t\t\tVariant & {\\tt 15-8} & {\\tt 7-0} \\\\\r\n\t\t\t\\hline\r\n\t\t\t{\\tt OUT (n),A} & {\\tt A} & {\\tt n} \\\\\r\n\t\t\t{\\tt OUT (C),r} & {\\tt B} & {\\tt C} \\\\\r\n\t\t\\end{tabular}\r\n\t\t\\vspace{1ex} % some spacing before next text for less cluttered layout\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsOUTcr\r\n\t\t\\end{DetailEffects}\r\n\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime[(n),A]{3}{11}\r\n\t\t\t\\DetailTime[(C),r]{3}{12}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\t\\DetailNote{Note: on the Next FPGA {\\tt OUT (C),0} variant outputs {\\tt 0} to the port at address {\\tt BC}, but some Z80 chips may output different value like {\\tt \\$FF}, so it is not recommended to use {\\tt OUT (C),0} if you want to reuse your code on original ZX Spectrum also.}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{OUTINB}{\\DetailItemZXN}\r\n\t\t{\\IH{OUT}put and \\IH{I}ncrement with \\IH{N}o \\IH{B}}\r\n\t\t{\\SymOUTINB}\r\n\r\n\t\tSimilar to {\\tt OUTI} except it doesn't decrement {\\tt B}.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsOUTINB\r\n\t\t\\end{DetailEffects}\r\n\t\t\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{4}{16}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{PIXELAD}{\\DetailItemZXN}\r\n\t\t{\\IH{PIXEL} \\IH{AD}dress}\r\n\t\t{\\SymPIXELAD}\r\n\r\n\t\tTakes {\\tt E} and {\\tt D} as the (x,y) coordinates of a point and calculates the address of the byte containing this pixel in the pixel area of standard ULA screen 0. Result is stored in {\\tt HL}.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsPIXELAD\r\n\t\t\\end{DetailEffects}\r\n\t\t\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{2}{8}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{PIXELDN}{\\DetailItemZXN}\r\n\t\t{\\IH{PIXEL} \\IH{D}ow\\IH{N}}\r\n\t\t{\\SymPIXELDN}\r\n\r\n\t\tUpdates the address in {\\tt HL} (likely from prior {\\tt PIXELAD} or {\\tt PIXELDN}) to move down by one line of pixels of standard ULA screen 0.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsPIXELDN\r\n\t\t\\end{DetailEffects}\r\n\t\t\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{2}{8}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{POP}{rr}\r\n\t\t{\\IH{POP} from stack}\r\n\t\t{\\SymPOP{rr}}\r\n\r\n\t\t\\begin{DetailVariants}\r\n\t\t\tPOP AF\\\\\r\n\t\t\tPOP BC\\\\\r\n\t\t\tPOP DE\\\\\r\n\t\t\tPOP HL\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\tPOP IX\\\\\r\n\t\t\tPOP IY\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\t~\r\n\t\t\\end{DetailVariants}\r\n\r\n\t\tCopies 2 bytes from stack pointer {\\tt SP} into contents of the given register pair {\\tt ss} and increments {\\tt SP} by {\\tt 2}.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsPOPaf[{\\tt POP AF}]\r\n\t\t\t\\FlagsPOPrr[Other variants no effect]\r\n\t\t\t\\DetailFlagsComments{\r\n\t\t\t\t\\item {\\tt POP AF} flags set directly to low 8-bits of the value from {\\tt SP}\r\n\t\t\t}\r\n\t\t\\end{DetailEffects}\r\n\t\t\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime[rr]{3}{10}\r\n\t\t\t\\DetailTime[IX]{4}{14}\r\n\t\t\t\\DetailTime[IY]{4}{14}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{PUSH}{ss}\r\n\t\t{\\IH{PUSH} on stack}\r\n\t\t{\\SymPUSH{ss}}\r\n\r\n\t\t\\begin{DetailVariants}\r\n\t\t\tPUSH AF\\\\\r\n\t\t\tPUSH BC\\\\\r\n\t\t\tPUSH DE\\\\\r\n\t\t\tPUSH HL\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\tPUSH IX\\\\\r\n\t\t\tPUSH IY\\\\\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\tPUSH nn\\ZXN\r\n\t\t\\end{DetailVariants}\r\n\r\n\t\tCopies contents of a register pair to the top of the stack pointer {\\tt SP}, then decrements {\\tt SP} by {\\tt 2}. Next extended {\\tt PUSH nn} also allows pushing immediate 16-bit value.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsPUSHrr\r\n\t\t\\end{DetailEffects}\r\n\t\t\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime[rr]{3}{11}\r\n\t\t\t\\DetailTime[IX]{4}{15}\r\n\t\t\t\\DetailTime[IY]{4}{15}\r\n\t\t\t\\DetailTime[nn]{6}{23}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{RES}{b,s}\r\n\t\t{\\IH{RES}et bit}\r\n\t\t{\\SymRES{s}}\r\n\r\n\t\t% we use tabularx instead of multicols because some columns need to be wider to accomodate instructions. And then tabularx instead of tabular to fit whole width\r\n\t\t\\begin{DetailVariants}\r\n\t\t\tRES b,A\\\\\r\n\t\t\tRES b,B\\\\\r\n\t\t\tRES b,C\\\\\r\n\t\t\tRES b,D\\\\\r\n\t\t\tRES b,E\\\\\r\n\t\t\tRES b,H\\\\\r\n\t\t\tRES b,L\\\\\r\n\t\t\tRES b,(HL)\\\\\r\n\t\t\tRES b,(IX+d)\\\\\r\n\t\t\tRES b,(IY+d)\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\tRES b,(IX+d),A\\UNDOC\\\\\r\n\t\t\tRES b,(IX+d),B\\UNDOC\\\\\r\n\t\t\tRES b,(IX+d),C\\UNDOC\\\\\r\n\t\t\tRES b,(IX+d),D\\UNDOC\\\\\r\n\t\t\tRES b,(IX+d),E\\UNDOC\\\\\r\n\t\t\tRES b,(IX+d),H\\UNDOC\\\\\r\n\t\t\tRES b,(IX+d),L\\UNDOC\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\tRES b,(IY+d),A\\UNDOC\\\\\r\n\t\t\tRES b,(IY+d),B\\UNDOC\\\\\r\n\t\t\tRES b,(IY+d),C\\UNDOC\\\\\r\n\t\t\tRES b,(IY+d),D\\UNDOC\\\\\r\n\t\t\tRES b,(IY+d),E\\UNDOC\\\\\r\n\t\t\tRES b,(IY+d),H\\UNDOC\\\\\r\n\t\t\tRES b,(IY+d),L\\UNDOC\r\n\t\t\\end{DetailVariants}\r\n\r\n\t\tResets bit {\\tt b} ({\\tt 0-7}) of the given register {\\tt s} or memory location addressed by operand {\\tt s}.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsRESr\r\n\t\t\\end{DetailEffects}\r\n\t\t\t\t\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime[r]{2}{8}\r\n\t\t\t\\DetailTime[(HL)]{4}{15}\r\n\t\t\t\\DetailTime[(IX+d)]{6}{23}\r\n\t\t\t\\DetailTime[(IY+d)]{6}{23}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{RET}{}\r\n\t\t{\\IH{RET}urn from subroutine}\r\n\t\t{\\SymRET}\r\n\r\n\t\tReturns from subroutine. The contents of program counter {\\tt PC} is {\\tt POP}-ed from stack so next instruction will be loaded from there.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsRET\r\n\t\t\\end{DetailEffects}\r\n\t\t\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{3}{10}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{RET c}{}\r\n\t\t{\\IH{RET}urn from subroutine conditionally}\r\n\t\t{\\SymRETc{c}}\r\n\r\n\t\t\\vspace{1ex} % we need some vertical space to achieve same separation as multicols\r\n\t\t\\begin{tabular}{@{}llcll}\r\n\t\t\t{\\tt RET C,nn} & returns if \\FlagCF{} is set & & \r\n\t\t\t\t{\\tt RET M,nn} & returns if \\FlagSF{} is set\\\\\r\n\t\t\t{\\tt RET NC,nn} & returns if \\FlagCF{} is reset & & \r\n\t\t\t\t{\\tt RET P,nn} & returns if \\FlagSF{} is reset\\\\\r\n\t\t\t{\\tt RET Z,nn} & returns if \\FlagZF{} is set & & \r\n\t\t\t\t{\\tt RET PE,nn} & returns if \\FlagPV{} is set\\\\\r\n\t\t\t{\\tt RET NZ,nn} & returns if \\FlagZF{} is reset & & \r\n\t\t\t\t{\\tt RET PO,nn} & returns if \\FlagPV{} is reset\\\\\r\n\t\t\\end{tabular}\r\n\r\n\t\tIf given condition is met, {\\tt RET} is performed, as described above.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsRETcc\r\n\t\t\\end{DetailEffects}\r\n\t\t\t\t\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTimeRegular[{\\tt c}=false]{1}{5}\r\n\t\t\t\\DetailTimeRegular[{\\tt c}=true]{3}{11}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{RETI}{}\r\n\t\t{\\IH{RET}urn from \\IH{I}nterrupt}\r\n\t\t{\\SymRETI}\r\n\r\n\t\tReturns from maskable interrupt; restores stack pointer {\\tt SP} and signals to I/O device that interrupt routine is completed.\r\n\t\t\r\n\t\tNote that {\\tt RETI} doesn't re-enable interrupts that were disabled when interrupt routine started - {\\tt EI} should be called before {\\tt RETI} to do that.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsRETI\r\n\t\t\\end{DetailEffects}\r\n\t\t\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{4}{14}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{RETN}{}\r\n\t\t{\\IH{RET}urn from \\IH{N}on-maskable interrupt}\r\n\t\t{\\SymRETN}\r\n\r\n\t\tReturns from non-maskable interrupt; restores stack pointer {\\tt SP} and copies state of {\\tt IFF2} back to {\\tt IFF1} so that maskable interrupts are re-enabled.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsRETN\r\n\t\t\\end{DetailEffects}\r\n\t\t\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{4}{14}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{RL}{s}\r\n\t\t{\\IH{R}otate \\IH{L}eft}\r\n\t\t{\\SymRL{s}}\r\n\r\n\t\t\\begin{DetailVariants}\r\n\t\t\tRL A\\\\\r\n\t\t\tRL B\\\\\r\n\t\t\tRL C\\\\\r\n\t\t\tRL D\\\\\r\n\t\t\tRL E\\\\\r\n\t\t\tRL H\\\\\r\n\t\t\tRL L\\\\\r\n\t\t\tRL (HL)\\\\\r\n\t\t\tRL (IX+d)\\\\\r\n\t\t\tRL (IY+d)\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\tRL (IX+d),A\\UNDOC\\\\\r\n\t\t\tRL (IX+d),B\\UNDOC\\\\\r\n\t\t\tRL (IX+d),C\\UNDOC\\\\\r\n\t\t\tRL (IX+d),D\\UNDOC\\\\\r\n\t\t\tRL (IX+d),E\\UNDOC\\\\\r\n\t\t\tRL (IX+d),H\\UNDOC\\\\\r\n\t\t\tRL (IX+d),L\\UNDOC\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\tRL (IY+d),A\\UNDOC\\\\\r\n\t\t\tRL (IY+d),B\\UNDOC\\\\\r\n\t\t\tRL (IY+d),C\\UNDOC\\\\\r\n\t\t\tRL (IY+d),D\\UNDOC\\\\\r\n\t\t\tRL (IY+d),E\\UNDOC\\\\\r\n\t\t\tRL (IY+d),H\\UNDOC\\\\\r\n\t\t\tRL (IY+d),L\\UNDOC\r\n\t\t\\end{DetailVariants}\r\n\r\n\t\tPerforms 9-bit left rotation of the value of the operand {\\tt s} or memory addressed by {\\tt s} through the carry flag \\FlagCF{} so that contents of \\FlagCF{} are moved to bit {\\tt 0} and bit {\\tt 7} to \\FlagCF{}. Result is then stored back to {\\tt s}.\r\n\r\n\t\t\\begin{DetailEffects}[p]\r\n\t\t\t\\FlagsRLr\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagSF{\\DetailFlagResultSign}\r\n\t\t\t\\DetailFlagZF{\\DetailFlagResultZero}\r\n\t\t\t\\DetailFlagPV{\\DetailFlagResultParity}\r\n\t\t\t\\DetailFlagCF[set to:]{bit {\\tt 7} of the original value}\r\n\t\t\\end{DetailEffectsFlags}\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime[r]{2}{8}\r\n\t\t\t\\DetailTime[(HL)]{4}{15}\r\n\t\t\t\\DetailTime[(IX+d)]{6}{23}\r\n\t\t\t\\DetailTime[(IY+d)]{6}{23}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{RLA}{}\r\n\t\t{\\IH{R}otate \\IH{L}eft \\IH{A}ccumulator}\r\n\t\t{\\SymRL{A}}\r\n\r\n\t\tPerforms {\\tt RL A}, but twice faster and preserves \\FlagSF{}, \\FlagZF{} and \\FlagPV{}.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsRLA\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagCF[set to:]{bit {\\tt 7} of the original value}\r\n\t\t\\end{DetailEffectsFlags}\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{1}{4}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{RLC}{s}\r\n\t\t{\\IH{R}otate \\IH{L}eft \\IH{C}ircular}\r\n\t\t{\\SymRLC{s}}\r\n\r\n\t\t\\begin{DetailVariants}\r\n\t\t\tRLC A\\\\\r\n\t\t\tRLC B\\\\\r\n\t\t\tRLC C\\\\\r\n\t\t\tRLC D\\\\\r\n\t\t\tRLC E\\\\\r\n\t\t\tRLC H\\\\\r\n\t\t\tRLC L\\\\\r\n\t\t\tRLC (HL)\\\\\r\n\t\t\tRLC (IX+d)\\\\\r\n\t\t\tRLC (IY+d)\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\tRLC (IX+d),A\\UNDOC\\\\\r\n\t\t\tRLC (IX+d),B\\UNDOC\\\\\r\n\t\t\tRLC (IX+d),C\\UNDOC\\\\\r\n\t\t\tRLC (IX+d),D\\UNDOC\\\\\r\n\t\t\tRLC (IX+d),E\\UNDOC\\\\\r\n\t\t\tRLC (IX+d),H\\UNDOC\\\\\r\n\t\t\tRLC (IX+d),L\\UNDOC\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\tRLC (IY+d),A\\UNDOC\\\\\r\n\t\t\tRLC (IY+d),B\\UNDOC\\\\\r\n\t\t\tRLC (IY+d),C\\UNDOC\\\\\r\n\t\t\tRLC (IY+d),D\\UNDOC\\\\\r\n\t\t\tRLC (IY+d),E\\UNDOC\\\\\r\n\t\t\tRLC (IY+d),H\\UNDOC\\\\\r\n\t\t\tRLC (IY+d),L\\UNDOC\r\n\t\t\\end{DetailVariants}\r\n\r\n\t\tPerforms 8-bit rotation to the left. Bit {\\tt 7} is moved to carry flag \\FlagCF{} as well as to bit {\\tt 0}. Result is then stored back to {\\tt s}.\r\n\r\n\t\tNote: undocumented variants work slightly differently:\r\n\r\n\t\t\\begin{multicols}{2}\r\n\t\t\t\\DetailSymbolVariants{RLC r,(IX+d)}{\\SymRLCu{r}{IX}}\r\n\r\n\t\t\t\\DetailSymbolVariants{RLC r,(IY+d)}{\\SymRLCu{r}{IY}}\r\n\t\t\\end{multicols}\r\n\r\n\t\t\\begin{DetailEffects}[p]\r\n\t\t\t\\FlagsRLCr\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagSF{\\DetailFlagResultSign}\r\n\t\t\t\\DetailFlagZF{\\DetailFlagResultZero}\r\n\t\t\t\\DetailFlagPV{\\DetailFlagResultParity}\r\n\t\t\t\\DetailFlagCF[set to:]{bit {\\tt 7} of the original value}\r\n\t\t\\end{DetailEffectsFlags}\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime[r]{2}{8}\r\n\t\t\t\\DetailTime[(HL)]{4}{15}\r\n\t\t\t\\DetailTime[(IX+d)]{6}{23}\r\n\t\t\t\\DetailTime[(IY+d)]{6}{23}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{RLCA}{}\r\n\t\t{\\IH{R}otate \\IH{L}eft \\IH{C}ircular \\IH{A}ccumulator}\r\n\t\t{\\SymRLC{A}}\r\n\t\t\r\n\t\tPerforms {\\tt RLC A}, but twice faster and preserves \\FlagSF{}, \\FlagZF{} and \\FlagPV{}.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsRLCA\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagCF[set to:]{bit {\\tt 7} of the original value}\r\n\t\t\\end{DetailEffectsFlags}\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{1}{4}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t% RLD and RRD are similar instructions, so while RLD would alphabetically fit here, moving it on the same page spread with RRD allows direct comparison between the two\r\n\t\\DetailItemSeePageReference{RLD}\r\n\r\n\t% % these instructions were moved before backwards so they can be all together on the same page spread for better direct comparison\r\n\t% \\DetailItemsSeePageReference{RR, RRA, RRC, RRCA}{See pages \\DetailItemPageRef{RR} and \\DetailItemPageRef{RRCA}}\r\n\r\n\t% \\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{RR}{s}\r\n\t\t{\\IH{R}otate \\IH{R}ight}\r\n\t\t{\\SymRR{s}}\r\n\r\n\t\t\\begin{DetailVariants}\r\n\t\t\tRR A\\\\\r\n\t\t\tRR B\\\\\r\n\t\t\tRR C\\\\\r\n\t\t\tRR D\\\\\r\n\t\t\tRR E\\\\\r\n\t\t\tRR H\\\\\r\n\t\t\tRR L\\\\\r\n\t\t\tRR (HL)\\\\\r\n\t\t\tRR (IX+d)\\\\\r\n\t\t\tRR (IY+d)\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\tRR (IX+d),A\\UNDOC\\\\\r\n\t\t\tRR (IX+d),B\\UNDOC\\\\\r\n\t\t\tRR (IX+d),C\\UNDOC\\\\\r\n\t\t\tRR (IX+d),D\\UNDOC\\\\\r\n\t\t\tRR (IX+d),E\\UNDOC\\\\\r\n\t\t\tRR (IX+d),H\\UNDOC\\\\\r\n\t\t\tRR (IX+d),L\\UNDOC\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\tRR (IY+d),A\\UNDOC\\\\\r\n\t\t\tRR (IY+d),B\\UNDOC\\\\\r\n\t\t\tRR (IY+d),C\\UNDOC\\\\\r\n\t\t\tRR (IY+d),D\\UNDOC\\\\\r\n\t\t\tRR (IY+d),E\\UNDOC\\\\\r\n\t\t\tRR (IY+d),H\\UNDOC\\\\\r\n\t\t\tRR (IY+d),L\\UNDOC\r\n\t\t\\end{DetailVariants}\r\n\r\n\t\tPerforms 9-bit right rotation of the contents of the operand {\\tt s} or memory addressed by {\\tt s} through carry flag \\FlagCF{} so that contents of \\FlagCF{} are moved to bit {\\tt 7} and bit {\\tt 0} to \\FlagCF{}. Result is then stored back to {\\tt s}.\r\n\r\n\t\t\\begin{DetailEffects}[p]\r\n\t\t\t\\FlagsRRr\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagSF{\\DetailFlagResultSign}\r\n\t\t\t\\DetailFlagZF{\\DetailFlagResultZero}\r\n\t\t\t\\DetailFlagPV{\\DetailFlagResultParity}\r\n\t\t\t\\DetailFlagCF[set to:]{bit {\\tt 0} of the original value}\r\n\t\t\\end{DetailEffectsFlags}\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime[r]{2}{8}\r\n\t\t\t\\DetailTime[(HL)]{4}{15}\r\n\t\t\t\\DetailTime[(IX+d)]{6}{23}\r\n\t\t\t\\DetailTime[(IY+d)]{6}{23}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{RRA}{}\r\n\t\t{\\IH{R}otate \\IH{R}ight \\IH{A}ccumulator}\r\n\t\t{\\SymRR{A}}\r\n\r\n\t\tPerforms {\\tt RR A}, but twice faster and preserves \\FlagSF{}, \\FlagZF{} and \\FlagPV{}.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsRRA\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagCF[set to:]{bit {\\tt 0} of the original value}\r\n\t\t\\end{DetailEffectsFlags}\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{1}{4}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{RRC}{s}\r\n\t\t{\\IH{R}otate \\IH{R}ight \\IH{C}ircular}\r\n\t\t{\\SymRRC{s}}\r\n\r\n\t\t\\begin{DetailVariants}\r\n\t\t\tRRC A\\\\\r\n\t\t\tRRC B\\\\\r\n\t\t\tRRC C\\\\\r\n\t\t\tRRC D\\\\\r\n\t\t\tRRC E\\\\\r\n\t\t\tRRC H\\\\\r\n\t\t\tRRC L\\\\\r\n\t\t\tRRC (HL)\\\\\r\n\t\t\tRRC (IX+d)\\\\\r\n\t\t\tRRC (IY+d)\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\tRRC (IX+d),A\\UNDOC\\\\\r\n\t\t\tRRC (IX+d),B\\UNDOC\\\\\r\n\t\t\tRRC (IX+d),C\\UNDOC\\\\\r\n\t\t\tRRC (IX+d),D\\UNDOC\\\\\r\n\t\t\tRRC (IX+d),E\\UNDOC\\\\\r\n\t\t\tRRC (IX+d),H\\UNDOC\\\\\r\n\t\t\tRRC (IX+d),L\\UNDOC\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\tRRC (IY+d),A\\UNDOC\\\\\r\n\t\t\tRRC (IY+d),B\\UNDOC\\\\\r\n\t\t\tRRC (IY+d),C\\UNDOC\\\\\r\n\t\t\tRRC (IY+d),D\\UNDOC\\\\\r\n\t\t\tRRC (IY+d),E\\UNDOC\\\\\r\n\t\t\tRRC (IY+d),H\\UNDOC\\\\\r\n\t\t\tRRC (IY+d),L\\UNDOC\r\n\t\t\\end{DetailVariants}\r\n\r\n\t\tPerforms 8-bit rotation of the source {\\tt s} to the right. Bit {\\tt 0} is moved to \\FlagCF{} as well as to bit {\\tt 7}. Result is then stored back to {\\tt s}.\r\n\r\n\t\t\\begin{DetailEffects}[p]\r\n\t\t\t\\FlagsRRCr\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagSF{\\DetailFlagResultSign}\r\n\t\t\t\\DetailFlagZF{\\DetailFlagResultZero}\r\n\t\t\t\\DetailFlagPV{\\DetailFlagResultParity}\r\n\t\t\t\\DetailFlagCF[set to:]{bit {\\tt 0} of the original value}\r\n\t\t\\end{DetailEffectsFlags}\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime[r]{2}{8}\r\n\t\t\t\\DetailTime[(HL)]{4}{15}\r\n\t\t\t\\DetailTime[(IX+d)]{6}{23}\r\n\t\t\t\\DetailTime[(IY+d)]{6}{23}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t% while RRCA should alphabetically be before RLD, I opted for this changed order so that both RLD and RRD are rendered at the top of their pages - easier to compare both this way\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{RLD}{}\r\n\t\t{\\IH{R}otate \\IH{L}eft bcd \\IH{D}igit}\r\n\t\t{\\SymRLD}\r\n\r\n\t\tPerforms leftward 12-bit rotation of 4-bit nibbles where 2 least significant nibbles are stored in memory location addressed by {\\tt HL} and most significant digit as lower 4 bits of the accumulator {\\tt A}.\r\n\r\n\t\tIf used with BCD numbers: as the shift happens by 1 digit to the left, this effectively results in multiplication with {\\tt 10}. {\\tt A} acts as a sort of decimal carry in the operation. Example of multiplying multi-digit BCD number by 10:\r\n\r\n\t\t\\begin{tabular}{m{8cm}p{0.1cm}m{4.3cm}}\r\n\r\n\t\t\t{ % tcblisting must be enclosed within {} inside tabular otherwise latex compiler gets confused\r\n\t\t\t\\begin{tcblisting}{}\r\nMultiplyBy10:\t\t; number=0123\r\n\tLD HL, number+digits-1\r\n\tLD B, digits\t; number of repeats\r\n\tXOR A\t\t\t; reset \"carry\"\r\nlp:\tRLD\t\t\t\t; multiply by 10 \r\n\tDEC HL\t\t\t; prev 2 digits\r\n\tDJNZ lp\t\t\t; number=1230, A=0\r\n\r\nnumber:\r\n\tDB &01, &23\r\ndigits = &-number   ;(2)\r\n\t\t\t\\end{tcblisting}\r\n\t\t\t}\r\n\t\r\n\t\t\t& &\r\n   \t\r\n\t\t\t\\newcommand{\\HLindicator}[2]{\r\n\t\t\t\t\\path (progress-#1-2.south west) --\r\n\t\t\t\t\tnode[xshift=#2, yshift=1.4ex, rotate=90]{$\\lbrace$}\r\n\t\t\t\t\tnode[xshift=#2 + 0.1ex, yshift=0.2ex, indicator]{(HL)} (progress-#1-2.south)\r\n\t\t\t}\r\n\t\t\r\n\t\t\t\\newcommand{\\ByteIndicator}[1]{\r\n\t\t\t\t\\draw \r\n\t\t\t\t\t(progress-#1-2.south west) ++(8pt,13pt) \r\n\t\t\t\t\t|- ++(5pt,-3pt) -| ++(5pt,3pt) \r\n\t\t\t\t\t++(1pt,0) \r\n\t\t\t\t\t|- ++(5pt,-3pt) -| ++(5pt,3pt);\r\n\t\t\t}\r\n\t\t\r\n\t\t\t\\begin{tikzpicture}[\r\n\t\t\t\tvalue/.style={font=\\ttfamily},\r\n\t\t\t\tleading/.style={value, inner xsep=8pt, xshift=2pt},\r\n\t\t\t\tindicator/.style={inner sep=0, font=\\ttfamily\\scriptsize},\r\n\t\t\t\tline/.style={inner sep=6pt, font=\\ttfamily\\tiny}]\r\n\t\t\r\n\t\t\t\t\\node (title) {Progression};\r\n\t\t\r\n\t\t\t\t\\matrix (progress)  [\r\n\t\t\t\t\tbelow=0em of title,\r\n\t\t\t\t\tmatrix of nodes, \r\n\t\t\t\t\tcolumn 1/.style={line},\r\n\t\t\t\t\tcolumn 2/.style={value},\r\n\t\t\t\t\tcolumn 3/.style={value},\r\n\t\t\t\t\tcolumn 4/.style={leading}] {\r\n\t\t\r\n\t\t\t\t\tline & number & A & B \\\\\r\n\t\t\t\t\t\\hline\r\n\t\t\r\n\t\t\t\t\t2-4 & 0123 & 0 & 2 \\\\[-1.3ex]\r\n\t\t\t\t\t$\\downarrow$ & ~~~~~ & & \\\\[0.8em]\r\n\t\t\r\n\t\t\t\t\t5-7 & 0130 & 2 & 1 \\\\[-1.3ex]\r\n\t\t\t\t\t$\\circlearrowright$ & ~~~~~ & & \\\\[0.8em]\r\n\t\t\r\n\t\t\t\t\t5-7 & 1230 & 0 & 0 \\\\[-1.3ex]\r\n\t\t\t\t\t$\\circlearrowright$ & ~~~~~ & & \\\\\r\n\t\t\t\t};\r\n\t\t\r\n\t\t\t\t\\ByteIndicator{3};\r\n\t\t\t\t\\ByteIndicator{5};\r\n\t\t\t\t\\ByteIndicator{7};\r\n\t\t\r\n\t\t\t\t\\HLindicator{3}{3.15ex};\r\n\t\t\t\t\\HLindicator{5}{0.8ex};\r\n\t\t\t\t\\HLindicator{7}{-1.45ex};\r\n\t\t\r\n\t\t\t\\end{tikzpicture}\r\n\t\r\n\t\t\\end{tabular}\r\n\r\n\t\t\\begin{DetailEffects}[p]\r\n\t\t\t\\FlagsRLD\r\n\t\t\\end{DetailEffects}\r\n\t\t\t\t\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{5}{18}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\t\\DetailNote{Note: instruction doesn't assume any format of the data; it simply rotates nibbles. So while it's most frequently associated with BCD numbers, it can be used for shifting hexadecimal values or any other content.}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{RRCA}{}\r\n\t\t{\\IH{R}otate \\IH{R}ight \\IH{C}ircular \\IH{A}ccumulator}\r\n\t\t{\\SymRRC{A}}\r\n\r\n\t\tPerforms {\\tt RRC A}, but twice faster and preserves \\FlagSF{}, \\FlagZF{} and \\FlagPV{}.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsRRCA\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagCF[set to:]{bit {\\tt 0} of the original value}\r\n\t\t\\end{DetailEffectsFlags}\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{1}{4}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{RRD}{}\r\n\t\t{\\IH{R}otate \\IH{R}ight bcd \\IH{D}igit}\r\n\t\t{\\SymRRD}\r\n\t\t\r\n\t\tSimilar to {\\tt RLD} except rotation is to the right. If used with BCD values, this operation effectively divides 3-digit BCD number by {\\tt 10} and stores remainder in {\\tt A}. Taking the example from {\\tt RLD}, we can easily convert it to division by 10 simply by using {\\tt RRD}. Note however we also need to change the order - we start from MSB now (which is exactly how division would be performed by hand):\r\n\r\n\t\t\\begin{tabular}{m{8cm}p{0.1cm}m{4.3cm}}\r\n\r\n\t\t\t{ % tcblisting must be enclosed within {} inside tabular otherwise latex compiler gets confused\r\n\t\t\t\\begin{tcblisting}{}\r\nDivideBy10:\r\n\tLD HL, number\t; number=0123\r\n\tLD B, digits\t; number of repeats\r\n\tXOR A\t\t\t; reset \"carry\"\r\nlp:\tRRD\t\t\t\t; divide by 10 \r\n\tINC HL\t\t\t; next 2 digits\r\n\tDJNZ lp\t\t\t; number=0012, A=3\r\n\r\nnumber:\r\n\tDB &01, &23\r\ndigits = &-number   ;(2)\r\n\t\t\t\\end{tcblisting}\r\n\t\t\t}\r\n\t\r\n\t\t\t& &\r\n   \t\r\n\t\t\t\\newcommand{\\HLindicator}[2]{\r\n\t\t\t\t\\path (progress-#1-2.south west) --\r\n\t\t\t\t\tnode[xshift=#2, yshift=1.4ex, rotate=90]{$\\lbrace$}\r\n\t\t\t\t\tnode[xshift=#2 + 0.1ex, yshift=0.2ex, indicator]{(HL)} (progress-#1-2.south)\r\n\t\t\t}\r\n\r\n\t\t\t\\newcommand{\\ByteIndicator}[1]{\r\n\t\t\t\t\\draw \r\n\t\t\t\t\t(progress-#1-2.south west) ++(8pt,13pt) \r\n\t\t\t\t\t|- ++(5pt,-3pt) -| ++(5pt,3pt) \r\n\t\t\t\t\t++(1pt,0) \r\n\t\t\t\t\t|- ++(5pt,-3pt) -| ++(5pt,3pt);\r\n\t\t\t}\r\n\t\r\n\t\t\t\\begin{tikzpicture}[\r\n\t\t\t\tvalue/.style={font=\\ttfamily},\r\n\t\t\t\tleading/.style={value, inner xsep=8pt, xshift=2pt},\r\n\t\t\t\tindicator/.style={inner sep=0, font=\\ttfamily\\scriptsize},\r\n\t\t\t\tline/.style={inner sep=6pt, font=\\ttfamily\\tiny}]\r\n\t\r\n\t\t\t\t\\node (title) {Progression};\r\n\t\r\n\t\t\t\t\\matrix (progress)  [\r\n\t\t\t\t\tbelow=0em of title,\r\n\t\t\t\t\tmatrix of nodes, \r\n\t\t\t\t\tcolumn 1/.style={line},\r\n\t\t\t\t\tcolumn 2/.style={value},\r\n\t\t\t\t\tcolumn 3/.style={value},\r\n\t\t\t\t\tcolumn 4/.style={leading}] {\r\n\r\n\t\t\t\t\tline & number & A & B \\\\\r\n\t\t\t\t\t\\hline\r\n\r\n\t\t\t\t\t2-4 & 0123 & 0 & 2 \\\\[-1.3ex]\r\n\t\t\t\t\t$\\downarrow$ & ~~~~~ & & \\\\[1em]\r\n\r\n\t\t\t\t\t5-7 & 0023 & 1 & 1 \\\\[-1.3ex]\r\n\t\t\t\t\t$\\circlearrowright$ & ~~~~~ & & \\\\[1em]\r\n\r\n\t\t\t\t\t5-7 & 0012 & 3 & 0 \\\\[-1.3ex]\r\n\t\t\t\t\t$\\circlearrowright$ & ~~~~~  & \\\\[1em]\r\n\t\t\t\t};\r\n\t\r\n\t\t\t\t\\ByteIndicator{3};\r\n\t\t\t\t\\ByteIndicator{5};\r\n\t\t\t\t\\ByteIndicator{7};\r\n\t\t\r\n\t\t\t\t\\HLindicator{3}{0.8ex};\r\n\t\t\t\t\\HLindicator{5}{3.15ex};\r\n\t\t\t\t\\HLindicator{7}{5.6ex};\r\n\t\r\n\t\t\t\\end{tikzpicture}\t\r\n\r\n\t\t\\end{tabular}\r\n\t\t\r\n\t\t\\begin{DetailEffects}[p]\r\n\t\t\t\\FlagsRRD\r\n\t\t\\end{DetailEffects}\r\n\t\t\t\t\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{5}{18}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\t\\DetailNote{Note: similar to {\\tt RLD}, this instruction also doesn't assume any format of the data; it simply rotates nibbles. So while it's most frequently associated with BCD numbers, it can be used for shifting hexadecimal values or any other content.}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{RST}{n}\r\n\t\t{\\IH{R}e\\IH{ST}art}\r\n\t\t{\\SymRST{n}}\r\n\r\n\t\t\\begin{DetailVariants}\r\n\t\t\tRST \\$00\\\\\r\n\t\t\tRST \\$08\\\\\r\n\t\t\tRST \\$10\\\\\r\n\t\t\tRST \\$18\r\n\t\t\t\r\n\t\t\t\\columnbreak\r\n\t\t\tRST \\$20\\\\\r\n\t\t\tRST \\$28\\\\\r\n\t\t\tRST \\$30\\\\\r\n\t\t\tRST \\$38\r\n\t\t\\end{DetailVariants}\r\n\r\n\t\tRestarts at the zero page address {\\tt s}. Only above addresses are possible, all in page {\\tt 0} of the memory, therefore the most significant byte of the program counter {\\tt PC} is loaded with {\\tt \\$00}. The instruction may be used as a fast response to an interrupt.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsRSTn\t\t\t\t\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{3}{11}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t% SBC should be listed here alphabetically, but we move it backwards so we can have both SBC and SUB on the same page spread for easier comparison\r\n\t\\DetailItemSeePageReference{SBC}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{SCF}{}\r\n\t\t{\\IH{S}et \\IH{C}arry \\IH{F}lag}\r\n\t\t{\\SymSCF}\r\n\r\n\t\tSets carry flag \\FlagCF{}.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsSCF\r\n\t\t\\end{DetailEffects}\r\n\t\t\t\t\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{1}{4}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{SET}{b,s}\r\n\t\t{\\IH{SET} bit}\r\n\t\t{\\SymSET{s}}\r\n\r\n\t\t\\begin{DetailVariants}\r\n\t\t\tSET b,A\\\\\r\n\t\t\tSET b,B\\\\\r\n\t\t\tSET b,C\\\\\r\n\t\t\tSET b,D\\\\\r\n\t\t\tSET b,E\\\\\r\n\t\t\tSET b,H\\\\\r\n\t\t\tSET b,L\\\\\r\n\t\t\tSET b,(HL)\\\\\r\n\t\t\tSET b,(IX+d)\\\\\r\n\t\t\tSET b,(IY+d)\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\tSET b,(IX+d),A\\UNDOC\\\\\r\n\t\t\tSET b,(IX+d),B\\UNDOC\\\\\r\n\t\t\tSET b,(IX+d),C\\UNDOC\\\\\r\n\t\t\tSET b,(IX+d),D\\UNDOC\\\\\r\n\t\t\tSET b,(IX+d),E\\UNDOC\\\\\r\n\t\t\tSET b,(IX+d),H\\UNDOC\\\\\r\n\t\t\tSET b,(IX+d),L\\UNDOC\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\tSET b,(IY+d),A\\UNDOC\\\\\r\n\t\t\tSET b,(IY+d),B\\UNDOC\\\\\r\n\t\t\tSET b,(IY+d),C\\UNDOC\\\\\r\n\t\t\tSET b,(IY+d),D\\UNDOC\\\\\r\n\t\t\tSET b,(IY+d),E\\UNDOC\\\\\r\n\t\t\tSET b,(IY+d),H\\UNDOC\\\\\r\n\t\t\tSET b,(IY+d),L\\UNDOC\r\n\t\t\\end{DetailVariants}\r\n\r\n\t\tSets bit {\\tt b} ({\\tt 0-7}) of operand {\\tt s} or memory location addressed by {\\tt s}.\r\n\r\n\t\tNote: undocumented variants work slightly differently:\r\n\r\n\t\t\\begin{multicols}{2}\r\n\t\t\t\\DetailSymbolVariants{SET b,(IX+d),r}{\\SymSETu{r}{IX}}\r\n\r\n\t\t\t\\DetailSymbolVariants{SET b,(IY+d),r}{\\SymSETu{r}{IY}}\r\n\t\t\\end{multicols}\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsSETr\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime[r]{2}{8}\r\n\t\t\t\\DetailTime[(HL)]{4}{15}\r\n\t\t\t\\DetailTime[(IX+d)]{6}{23}\r\n\t\t\t\\DetailTime[(IY+d)]{6}{23}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{SETAE}{\\DetailItemZXN}\r\n\t\t{\\IH{SET} \\IH{A}ccumulator from \\IH{E}}\r\n\t\t{\\SymSETAE}\r\n\r\n\t\tTakes the bit number to set from {\\tt E} (only the low 3 bits) and sets the value of the accumulator {\\tt A} to the value of that bit, but counted from top to bottom ({\\tt E=0} will produce {\\tt A$\\leftarrow$\\$80}, {\\tt E=7} will produce {\\tt A$\\leftarrow$\\$01} and so on). This works as pixel mask for ULA bitmap modes, when {\\tt E} represents x-coordinate {\\tt 0-255}.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsSETAE\r\n\t\t\\end{DetailEffects}\r\n\t\t\t\t\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{2}{8}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{SLA}{s}\r\n\t\t{\\IH{S}hift \\IH{L}eft \\IH{A}rithmetic}\r\n\t\t{\\SymSLA{s}}\r\n\t\t\r\n\t\t\\begin{DetailVariants}\r\n\t\t\tSLA A\\\\\r\n\t\t\tSLA B\\\\\r\n\t\t\tSLA C\\\\\r\n\t\t\tSLA D\\\\\r\n\t\t\tSLA E\\\\\r\n\t\t\tSLA H\\\\\r\n\t\t\tSLA L\\\\\r\n\t\t\tSLA (HL)\\\\\r\n\t\t\tSLA (IX+d)\\\\\r\n\t\t\tSLA (IY+d)\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\tSLA (IX+d),A\\UNDOC\\\\\r\n\t\t\tSLA (IX+d),B\\UNDOC\\\\\r\n\t\t\tSLA (IX+d),C\\UNDOC\\\\\r\n\t\t\tSLA (IX+d),D\\UNDOC\\\\\r\n\t\t\tSLA (IX+d),E\\UNDOC\\\\\r\n\t\t\tSLA (IX+d),H\\UNDOC\\\\\r\n\t\t\tSLA (IX+d),L\\UNDOC\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\tSLA (IY+d),A\\UNDOC\\\\\r\n\t\t\tSLA (IY+d),B\\UNDOC\\\\\r\n\t\t\tSLA (IY+d),C\\UNDOC\\\\\r\n\t\t\tSLA (IY+d),D\\UNDOC\\\\\r\n\t\t\tSLA (IY+d),E\\UNDOC\\\\\r\n\t\t\tSLA (IY+d),H\\UNDOC\\\\\r\n\t\t\tSLA (IY+d),L\\UNDOC\r\n\t\t\\end{DetailVariants}\r\n\r\n\t\tPerforms arithmetic shift left of the operand {\\tt s} or memory location addressed by {\\tt s}. Bit {\\tt 0} is forced to {\\tt 0} and bit {\\tt 7} is moved to \\FlagCF{}.\r\n\r\n\t\t\\begin{DetailEffects}[p]\r\n\t\t\t\\FlagsSLAr\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagSF{\\DetailFlagResultSign}\r\n\t\t\t\\DetailFlagZF{\\DetailFlagResultZero}\r\n\t\t\t\\DetailFlagPV{\\DetailFlagResultParity}\r\n\t\t\t\\DetailFlagCF[set to:]{bit 7 of the original value}\r\n\t\t\\end{DetailEffectsFlags}\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime[r]{2}{8}\r\n\t\t\t\\DetailTime[(HL)]{4}{15}\r\n\t\t\t\\DetailTime[(IX+d)]{6}{23}\r\n\t\t\t\\DetailTime[(IY+d)]{6}{23}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{SLL}{}\r\n\t\t{\\IH{S}hift \\IH{L}eft \\IH{L}ogical}\r\n\t\t{}\r\n\r\n\t\tThis mnemonic has no associated opcode on Next. There is no difference between logical and arithmetic shift left, use {\\tt SLA} for both. Some assemblers will allow {\\tt SLL} as equivalent, but unfortunately, some will assemble it as {\\tt SLI}, so it's best avoiding.\r\n\t\t\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItemMultiline}\r\n\t\t{SLI}{s\\UNDOC}{\\IH{S}hift \\IH{L}eft and \\IH{I}ncrement}\r\n\t\t{SL1}{s\\UNDOC}{\\IH{S}hift \\IH{L}eft and add \\IH{1}}\r\n\t\t{\\SymSLI{s}}\r\n\t\t\r\n\t\t\\begin{DetailVariants}\r\n\t\t\tSLI A\\\\\r\n\t\t\tSLI B\\\\\r\n\t\t\tSLI C\\\\\r\n\t\t\tSLI D\\\\\r\n\t\t\tSLI E\\\\\r\n\t\t\tSLI H\\\\\r\n\t\t\tSLI L\\\\\r\n\t\t\tSLA (HL)\\\\\r\n\t\t\tSLA (IX+d)\\\\\r\n\t\t\tSLA (IY+d)\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\tSLI (IX+d),A\\UNDOC\\\\\r\n\t\t\tSLI (IX+d),B\\UNDOC\\\\\r\n\t\t\tSLI (IX+d),C\\UNDOC\\\\\r\n\t\t\tSLI (IX+d),D\\UNDOC\\\\\r\n\t\t\tSLI (IX+d),E\\UNDOC\\\\\r\n\t\t\tSLI (IX+d),H\\UNDOC\\\\\r\n\t\t\tSLI (IX+d),L\\UNDOC\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\tSLI (IY+d),A\\UNDOC\\\\\r\n\t\t\tSLI (IY+d),B\\UNDOC\\\\\r\n\t\t\tSLI (IY+d),C\\UNDOC\\\\\r\n\t\t\tSLI (IY+d),D\\UNDOC\\\\\r\n\t\t\tSLI (IY+d),E\\UNDOC\\\\\r\n\t\t\tSLI (IY+d),H\\UNDOC\\\\\r\n\t\t\tSLI (IY+d),L\\UNDOC\r\n\t\t\\end{DetailVariants}\r\n\r\n\t\tUndocumented instruction. Similar to {\\tt SLA} except {\\tt 1} is moved to bit {\\tt 0}.\r\n\r\n\t\t\\begin{DetailEffects}[p]\r\n\t\t\t\\FlagsSLIr\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagSF{\\DetailFlagResultSign}\r\n\t\t\t\\DetailFlagZF{\\DetailFlagResultZero}\r\n\t\t\t\\DetailFlagPV{\\DetailFlagResultParity}\r\n\t\t\t\\DetailFlagCF[set to:]{bit 7 of the original value}\r\n\t\t\\end{DetailEffectsFlags}\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime[r]{2}{8}\r\n\t\t\t\\DetailTime[(HL)]{4}{15}\r\n\t\t\t\\DetailTime[(IX+d)]{6}{23}\r\n\t\t\t\\DetailTime[(IY+d)]{6}{23}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\t\\DetailNote{Note: most assemblers will accept both variants: {\\tt SLI} or {\\tt SL1}, but some may only accept one or the other, while some may expect {\\tt SLL} instead.}\r\n\r\n\t\\end{DetailItemMultiline}\r\n\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{SRA}{s}\r\n\t\t{\\IH{S}hift \\IH{R}ight \\IH{A}rithmetic}\r\n\t\t{\\SymSRA{s}}\r\n\t\t\t\t\r\n\t\t% we're using non-standard layout here so that we can fit SRA and SRL to the same page\r\n\t\t\\begin{DetailVariants}[p{1.3cm}p{3.5cm}XX]\r\n\t\t\tSRA A\t& SRA (HL)\t\t& SRA (IX+d),A\\UNDOC\t& SRA (IY+d),A\\UNDOC \\\\\r\n\t\t\tSRA B\t& SRA (IX+d)\t& SRA (IX+d),B\\UNDOC\t& SRA (IY+d),B\\UNDOC \\\\\r\n\t\t\tSRA C\t& SRA (IY+d)\t& SRA (IX+d),C\\UNDOC\t& SRA (IY+d),C\\UNDOC \\\\\r\n\t\t\tSRA D\t&\t\t\t\t& SRA (IX+d),D\\UNDOC\t& SRA (IY+d),D\\UNDOC \\\\\r\n\t\t\tSRA E\t&\t\t\t\t& SRA (IX+d),E\\UNDOC\t& SRA (IY+d),E\\UNDOC \\\\\r\n\t\t\tSRA H\t&\t\t\t\t& SRA (IX+d),H\\UNDOC\t& SRA (IY+d),H\\UNDOC \\\\\r\n\t\t\tSRA L\t&\t\t\t\t& SRA (IX+d),L\\UNDOC\t& SRA (IY+d),L\\UNDOC \\\\\r\n\t\t\\end{DetailVariants}\r\n\r\n\t\tPerforms arithmetic shift right of the operand {\\tt s} or memory location addressed by {\\tt s}. Bit {\\tt 0} is moved to \\FlagCF{} while bit {\\tt 7} remains unchanged (on the assumption that it's the sign bit).\r\n\r\n\t\t\\begin{DetailEffects}[p]\r\n\t\t\t\\FlagsSRAr\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagSF{\\DetailFlagResultSign}\r\n\t\t\t\\DetailFlagZF{\\DetailFlagResultZero}\r\n\t\t\t\\DetailFlagPV{\\DetailFlagResultParity}\r\n\t\t\t\\DetailFlagCF[set to:]{bit 0 of the original value}\r\n\t\t\\end{DetailEffectsFlags}\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime[r]{2}{8}\r\n\t\t\t\\DetailTime[(HL)]{4}{15}\r\n\t\t\t\\DetailTime[(IX+d)]{6}{23}\r\n\t\t\t\\DetailTime[(IY+d)]{6}{23}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{SRL}{s}\r\n\t\t{\\IH{S}hift \\IH{R}ight \\IH{L}ogical}\r\n\t\t{\\SymSRL{s}}\r\n\t\t\t\t\r\n\t\t% we're using non-standard layout here so that we can fit SRA and SRL to the same page\r\n\t\t\\begin{DetailVariants}[p{1.3cm}p{3.5cm}XX]\r\n\t\t\tSRL A\t& SRL (HL)\t\t& SRL (IX+d),A\\UNDOC\t& SRL (IY+d),A\\UNDOC \\\\\r\n\t\t\tSRL B\t& SRL (IX+d)\t& SRL (IX+d),B\\UNDOC\t& SRL (IY+d),B\\UNDOC \\\\\r\n\t\t\tSRL C\t& SRL (IY+d)\t& SRL (IX+d),C\\UNDOC\t& SRL (IY+d),C\\UNDOC \\\\\r\n\t\t\tSRL D\t&\t\t\t\t& SRL (IX+d),D\\UNDOC\t& SRL (IY+d),D\\UNDOC \\\\\r\n\t\t\tSRL E\t&\t\t\t\t& SRL (IX+d),E\\UNDOC\t& SRL (IY+d),E\\UNDOC \\\\\r\n\t\t\tSRL H\t&\t\t\t\t& SRL (IX+d),H\\UNDOC\t& SRL (IY+d),H\\UNDOC \\\\\r\n\t\t\tSRL L\t&\t\t\t\t& SRL (IX+d),L\\UNDOC\t& SRL (IY+d),L\\UNDOC \\\\\r\n\t\t\\end{DetailVariants}\r\n\r\n\t\tPerforms logical shift right of the operand {\\tt s} or memory location addressed by {\\tt s}. Bit {\\tt 0} is moved to \\FlagCF{} while {\\tt 0} is moved to bit {\\tt 7}.\r\n\r\n\t\t\\begin{DetailEffects}[p]\r\n\t\t\t\\FlagsSRLr\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagSF{\\DetailFlagResultSign}\r\n\t\t\t\\DetailFlagZF{\\DetailFlagResultZero}\r\n\t\t\t\\DetailFlagPV{\\DetailFlagResultParity}\r\n\t\t\t\\DetailFlagCF[set to:]{bit 0 of the original value}\r\n\t\t\\end{DetailEffectsFlags}\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime[r]{2}{8}\r\n\t\t\t\\DetailTime[(HL)]{4}{15}\r\n\t\t\t\\DetailTime[(IX+d)]{6}{23}\r\n\t\t\t\\DetailTime[(IY+d)]{6}{23}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{SBC}{d,s}\r\n\t\t{\\IH{S}u\\IH{B}tract with \\IH{C}arry}\r\n\t\t{\\SymSBC{d}{s}}\r\n\t\r\n\t\t\\begin{DetailVariants}\r\n\t\t\t\\textnormal{8 bit}\\\\\r\n\t\t\tSBC A,A\\\\\r\n\t\t\tSBC A,B\\\\\r\n\t\t\tSBC A,C\\\\\r\n\t\t\tSBC A,D\\\\\r\n\t\t\tSBC A,E\\\\\r\n\t\t\tSBC A,H\\\\\r\n\t\t\tSBC A,L\\\\\r\n\t\t\tSBC A,n\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\t\\textnormal{8 bit}\\\\\r\n\t\t\tSBC A,IXH\\UNDOC\\\\\r\n\t\t\tSBC A,IXL\\UNDOC\\\\\r\n\t\t\tSBC A,IYH\\UNDOC\\\\\r\n\t\t\tSBC A,IYL\\UNDOC\\\\\r\n\t\t\tSBC A,(HL)\\\\\r\n\t\t\tSBC A,(IX+d)\\\\\r\n\t\t\tSBC A,(IY+d)\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\t\\textnormal{16 bit}\\\\\r\n\t\t\tSBC HL,BC\\\\\r\n\t\t\tSBC HL,DE\\\\\r\n\t\t\tSBC HL,HL\\\\\r\n\t\t\tSBC HL,SP\r\n\t\t\\end{DetailVariants}\r\n\t\t\r\n\t\tSubtracts source operand {\\tt s} or contents of the memory location addressed by {\\tt s} and carry flag \\FlagCF{} from destination {\\tt d}. Result is then stored to destination {\\tt d}.\r\n\r\n\t\t\\begin{DetailEffects}[v]\r\n\t\t\t\\FlagsSBCr[8-bit]\r\n\t\t\t\\FlagsSBCrr[16-bit]\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagSF{\\DetailFlagResultSign}\r\n\t\t\t\\DetailFlagZF{\\DetailFlagResultZero}\r\n\t\t\t\\DetailFlagHF{\\DetailFlagResultHalfBorrow*}*\r\n\t\t\t\\DetailFlagPV{\\DetailFlagResultOverflow}*\r\n\t\t\t\\DetailFlagCF{\\DetailFlagResultBorrow*}\r\n\t\t\\end{DetailEffectsFlags}\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime[r]{1}{4}\r\n\t\t\t\\DetailTime[n]{2}{7}\r\n\t\t\t\\DetailTime[(HL)]{2}{7}\r\n\t\t\t\\DetailTime[HL,rr]{4}{15}\r\n\t\t\t\\DetailTime[(IX+d)]{5}{19}\r\n\t\t\t\\DetailTime[(IY+d)]{5}{19}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{SUB}{s}\r\n\t\t{\\IH{SUB}tract}\r\n\t\t{\\SymSUB{s}}\r\n\r\n\t\t\\begin{DetailVariants}\r\n\t\t\tSUB A\\\\\r\n\t\t\tSUB B\\\\\r\n\t\t\tSUB C\\\\\r\n\t\t\tSUB D\\\\\r\n\t\t\tSUB E\\\\\r\n\t\t\tSUB H\\\\\r\n\t\t\tSUB L\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\tSUB n\\\\\r\n\t\t\tSUB (HL)\\\\\r\n\t\t\tSUB (IX+d)\\\\\r\n\t\t\tSUB (IY+d)\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\tSUB IXH\\UNDOC\\\\\r\n\t\t\tSUB IXL\\UNDOC\\\\\r\n\t\t\tSUB IYH\\UNDOC\\\\\r\n\t\t\tSUB IYL\\UNDOC\r\n\t\t\\end{DetailVariants}\r\n\r\n\t\tSubtracts 8-bit immediate value, operand {\\tt s} or memory location addressed by {\\tt s} from accumulator {\\tt A}. Then stores result back to {\\tt A}.\r\n\r\n\t\t\\begin{DetailEffects}[v]\r\n\t\t\t\\FlagsSUBr\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagSF{\\DetailFlagResultSign}\r\n\t\t\t\\DetailFlagZF{\\DetailFlagResultZero}\r\n\t\t\t\\DetailFlagHF{\\DetailFlagResultHalfBorrow*}*\r\n\t\t\t\\DetailFlagPV{\\DetailFlagResultOverflow}*\r\n\t\t\t\\DetailFlagCF{\\DetailFlagResultBorrow*}\r\n\t\t\\end{DetailEffectsFlags}\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime[r]{1}{4}\r\n\t\t\t\\DetailTime[n]{2}{7}\r\n\t\t\t\\DetailTime[(HL)]{2}{7}\r\n\t\t\t\\DetailTime[(IX+d)]{5}{19}\r\n\t\t\t\\DetailTime[(IY+d)]{5}{19}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t\\pagebreak\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{SWAPNIB}{\\DetailItemZXN}\r\n\t\t{\\IH{SWAP} \\IH{NIB}bles}\r\n\t\t{\\SymSWAPNIB}\r\n\r\n\t\tSwaps the high and low nibbles of the accumulator {\\tt A}.\r\n\r\n\t\t\\begin{DetailEffects}\r\n\t\t\t\\FlagsSWAPNIB\r\n\t\t\\end{DetailEffects}\r\n\t\t\t\t\t\t\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{2}{8}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\begin{DetailItem}{TEST}{n\\ZXN}\r\n\t\t{\\IH{TEST}}\r\n\t\t{\\SymTEST}\r\n\r\n\t\tSimilar to {\\tt CP} (page \\DetailItemPageRef{CP}), but performs an {\\tt AND} instead of a subtraction. Again, {\\tt AND} is performed between the accumulator {\\tt A} and value {\\tt n}. Status flags are updated according to the result, but the result is then discarded (value of {\\tt A} is not changed).\r\n\r\n\t\t\\begin{DetailEffects}[p]\r\n\t\t\t\\FlagsTESTn\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagSF{\\DetailFlagResultSign}\r\n\t\t\t\\DetailFlagZF{\\DetailFlagResultZero ~(no bits matched)}\r\n\t\t\t\\DetailFlagPV{\\DetailFlagResultParity}\r\n\t\t\\end{DetailEffectsFlags}\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime{3}{11}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\t% ███████████████████████████████████████████████████████████████████\r\n\t% █▄─▄█▄─▀█▄─▄█─▄▄▄▄█─▄─▄─█▄─▄▄▀█▄─██─▄█─▄▄▄─█─▄─▄─█▄─▄█─▄▄─█▄─▀█▄─▄█\r\n\t% ██─███─█▄▀─██▄▄▄▄─███─████─▄─▄██─██─██─███▀███─████─██─██─██─█▄▀─██\r\n\t% ▀▄▄▄▀▄▄▄▀▀▄▄▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▄▀▄▄▄▄▀▄▄▄▀▀▄▄▀\r\n\t%----------------------------------------------------------------------------------------------------------------------\r\n\r\n\t\\pagebreak\r\n\t\\begin{DetailItem}{XOR}{s}\r\n\t\t{bitwise e\\IH{X}clusive \\IH{OR}}\r\n\t\t{\\SymXOR{s}}\r\n\r\n\t\t\\begin{DetailVariants}\r\n\t\t\tXOR A\\\\\r\n\t\t\tXOR B\\\\\r\n\t\t\tXOR C\\\\\r\n\t\t\tXOR D\\\\\r\n\t\t\tXOR E\\\\\r\n\t\t\tXOR H\\\\\r\n\t\t\tXOR L\\\\\r\n\t\t\tXOR n\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\tXOR (HL)\\\\\r\n\t\t\tXOR (IX+d)\\\\\r\n\t\t\tXOR (IY+d)\r\n\r\n\t\t\t\\columnbreak\r\n\t\t\tXOR IXH\\UNDOC\\\\\r\n\t\t\tXOR IXL\\UNDOC\\\\\r\n\t\t\tXOR IYH\\UNDOC\\\\\r\n\t\t\tXOR IYL\\UNDOC\r\n\t\t\\end{DetailVariants}\r\n\t\t\r\n\t\t\\begin{tabularx}{\\linewidth}{@{}Xl}\r\n\t\t\tPerforms exclusive or between accumulator {\\tt A} and operand {\\tt s} or memory location addressed by {\\tt s}. Result is then stored back to {\\tt A}. Individual bits are XOR'ed as shown on the right:\r\n\t\r\n\t\t\t&\r\n\r\n\t\t\t\\begin{tabular}[t]{cc|c}\r\n\t\t\t\t{\\tt A} & {\\tt s} & Result \\\\\r\n\t\t\t\t\\hline\r\n\t\t\t\t{\\tt 0} & {\\tt 0} & {\\tt 0} \\\\\r\n\t\t\t\t{\\tt 0} & {\\tt 1} & {\\tt 1} \\\\\r\n\t\t\t\t{\\tt 1} & {\\tt 0} & {\\tt 1} \\\\\r\n\t\t\t\t{\\tt 1} & {\\tt 1} & {\\tt 0} \\\\\r\n\t\t\t\\end{tabular}\r\n\r\n\t\t\t\\\\\r\n\t\t\\end{tabularx}\r\n\r\n\t\t\\begin{DetailEffects}[p]\r\n\t\t\t\\FlagsXORr\r\n\t\t\\end{DetailEffects}\r\n\r\n\t\t\\begin{DetailEffectsFlags}\r\n\t\t\t\\DetailFlagSF{\\DetailFlagResultSign}\r\n\t\t\t\\DetailFlagZF{\\DetailFlagResultZero}\r\n\t\t\t\\DetailFlagPV{\\DetailFlagResultParity}\r\n\t\t\\end{DetailEffectsFlags}\r\n\r\n\t\t\\begin{DetailTiming}\r\n\t\t\t\\DetailTime[r]{1}{4}\r\n\t\t\t\\DetailTime[n]{2}{7}\r\n\t\t\t\\DetailTime[(HL)]{2}{7}\r\n\t\t\t\\DetailTime[(IX+d)]{5}{19}\r\n\t\t\t\\DetailTime[(IY+d)]{5}{19}\r\n\t\t\\end{DetailTiming}\r\n\r\n\t\\end{DetailItem}\r\n\r\n\\end{basedescript}\r\n"
  },
  {
    "path": "chapter-instr-glance-16bit-arithmetic.tex",
    "content": "\\section{16-Bit Arithmetic}\r\n\r\n\\vspace*{0.7ex} % ensure this table starts at the same height as the one on the odd page\r\n\\begin{minipage}{\\textwidth}\r\n\r\n\\begin{instrtable}\r\n\r\n\t\\begin{instruction}{ADC HL,rr} \r\n\t\t\\Symbol{\\SymADC{HL}{rr}}\r\n\t\t\t\\FlagsADCrr\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{15}\r\n\t\t\t\\Comment{\r\n\t\t\t\t\\tt\r\n\t\t\t\t\\multirow{4}{*}{\r\n\t\t\t\t\t\\begin{tabular}{ll}\r\n\t\t\t\t\t\trr & \\OCT{rr} \\\\\r\n\t\t\t\t\t\t\\hline\r\n\t\t\t\t\t\tBC & 00 \\\\\r\n\t\t\t\t\t\tDE & 01 \\\\\r\n\t\t\t\t\t\tHL & 10 \\\\\r\n\t\t\t\t\t\tSP & 11 \\\\\r\n\t\t\t\t\t\\end{tabular}\r\n\t\t\t\t}\r\n\r\n\t\t\t}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{01}{\\OCT{rr}1}{010}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{SBC HL,rr} \r\n\t\t\\Symbol{\\SymSBC{HL}{rr}}\r\n\t\t\t\\FlagsSBCrr\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{15}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{01}{\\OCT{rr}0}{010}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{ADD HL,rr} \r\n\t\t\\Symbol{\\SymADD{HL}{rr}}\r\n\t\t\t\\FlagsADDrr\r\n\t\t\t\\OpCode{00}{\\OCT{rr}1}{001}\r\n\t\t\t\\Hex{..}{1}\r\n\t\t\t\\Cycles{3}{11}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{ADD IX,pp} \r\n\t\t\\Symbol{\\SymADD{IX}{pp}}\r\n\t\t\t\\FlagsADDrr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{2}\r\n\t\t\t\\Cycles{4}{15}\r\n\t\t\t\\Comment{\r\n\t\t\t\t\\multirow{4}{*}{\r\n\t\t\t\t\t\\tt\r\n\t\t\t\t\t\\begin{tabular}{ll}\r\n\t\t\t\t\t\tpp & \\OCT{pp} \\\\\r\n\t\t\t\t\t\t\\hline\r\n\t\t\t\t\t\tBC & 00 \\\\\r\n\t\t\t\t\t\tDE & 01 \\\\\r\n\t\t\t\t\t\tIX & 10 \\\\\r\n\t\t\t\t\t\tSP & 11 \\\\\r\n\t\t\t\t\t\\end{tabular}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{00}{\\OCT{pp}1}{001}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{ADD IY,qq} \r\n\t\t\\Symbol{\\SymADD{IY}{qq}}\r\n\t\t\t\\FlagsADDrr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{2}\r\n\t\t\t\\Cycles{4}{15}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{00}{\\OCT{qq}1}{001}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{INC rr} \r\n\t\t\\Symbol{\\SymINC{rr}}\r\n\t\t\t\\FlagsINCrr\r\n\t\t\t\\OpCode{00}{\\OCT{rr}0}{011}\r\n\t\t\t\\Hex{..}{1}\r\n\t\t\t\\Cycles{1}{6}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{INC IX} \r\n\t\t\\Symbol{\\SymINC{IX}}\r\n\t\t\t\\FlagsINCrr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{2}\r\n\t\t\t\\Cycles{2}{10}\r\n\t\t\t\\Comment{\r\n\t\t\t\t\\multirow{4}{*}{\r\n\t\t\t\t\t\\tt\r\n\t\t\t\t\t\\begin{tabular}{ll}\r\n\t\t\t\t\t\tqq & \\OCT{qq} \\\\\r\n\t\t\t\t\t\t\\hline\r\n\t\t\t\t\t\tBC & 00 \\\\\r\n\t\t\t\t\t\tDE & 01 \\\\\r\n\t\t\t\t\t\tIY & 10 \\\\\r\n\t\t\t\t\t\tSP & 11 \\\\\r\n\t\t\t\t\t\\end{tabular}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{00}{100}{011}\r\n\t\t\t\\Hex{23}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{INC IY} \r\n\t\t\\Symbol{\\SymINC{IY}}\r\n\t\t\t\\FlagsINCrr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{2}\r\n\t\t\t\\Cycles{2}{10}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{00}{100}{011}\r\n\t\t\t\\Hex{23}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{DEC rr} \r\n\t\t\\Symbol{\\SymDEC{rr}}\r\n\t\t\t\\FlagsDECrr\r\n\t\t\t\\OpCode{00}{\\OCT{rr}1}{011}\r\n\t\t\t\\Hex{..}{1}\r\n\t\t\t\\Cycles{1}{6}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{DEC IX} \r\n\t\t\\Symbol{\\SymDEC{IX}}\r\n\t\t\t\\FlagsDECrr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{2}\r\n\t\t\t\\Cycles{2}{10}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{00}{101}{011}\r\n\t\t\t\\Hex{2B}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{lastinstruction}{DEC IY} \r\n\t\t\\Symbol{\\SymDEC{IY}}\r\n\t\t\t\\FlagsDECrr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{2}\r\n\t\t\t\\Cycles{2}{10}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{00}{101}{011}\r\n\t\t\t\\Hex{2B}{}\r\n\t\\end{lastinstruction}\r\n\r\n\\end{instrtable}\r\n\r\n\\begin{notestable}\r\n\t\\NoteItem{\\See{1}Flag is set by carry from bit 15}\r\n\t\\NoteItem{\\See{2}Flag is set by carry from bit 11 (half carry in high byte)}\r\n\\end{notestable}\r\n\r\n\\end{minipage}\r\n"
  },
  {
    "path": "chapter-instr-glance-16bit-load.tex",
    "content": "\\section{16-Bit Load}\r\n\r\n\\begin{instrtable}\r\n\r\n\t\\begin{instruction}{LD rr,nm} \r\n\t\t\\Symbol{\\SymLD{rr}{nm}}\r\n\t\t\t\\FlagsLDrr\r\n\t\t\t\\OpCode{00}{\\OCT{rr}0}{001} \r\n\t\t\t\\Hex{..}{3} \r\n\t\t\t\\Cycles{3}{10}\r\n\t\t\t\\Comment{\r\n\t\t\t\t\\tt\r\n\t\t\t\t\\multirow{4}{*}{\r\n\t\t\t\t\t\\begin{tabular}{ll}\r\n\t\t\t\t\t\trr & \\OCT{rr} \\\\\r\n\t\t\t\t\t\t\\hline\r\n\t\t\t\t\t\tBC & 00 \\\\\r\n\t\t\t\t\t\tDE & 01 \\\\\r\n\t\t\t\t\t\tHL & 10 \\\\\r\n\t\t\t\t\t\tSP & 11 \\\\\r\n\t\t\t\t\t\\end{tabular}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{m} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{n} \r\n\t\t\t\\Hex{..}{} \r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LD IX,nm} \r\n\t\t\\Symbol{\\SymLD{IX}{nm}}\r\n\t\t\t\\FlagsLDrr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{4}\r\n\t\t\t\\Cycles{4}{14}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{100}{001}\r\n\t\t\t\\Hex{21}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{m} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{n} \r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LD IY,nm} \r\n\t\t\\Symbol{\\SymLD{IX}{nm}}\r\n\t\t\t\\FlagsLDrr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{4}\r\n\t\t\t\\Cycles{4}{14}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{100}{001}\r\n\t\t\t\\Hex{21}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{m} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{n} \r\n\t\t\t\\Hex{..}{} \r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LD HL,(nm)} \r\n\t\t\\Symbol{\\SymLD{H}{(nm+1)}}\r\n\t\t\t\\FlagsLDrr\r\n\t\t\t\\OpCode{00}{101}{010}\r\n\t\t\t\\Hex{2A}{3}\r\n\t\t\t\\Cycles{5}{16}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLD{L}{(nm)}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpRange{m}\r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{n} \r\n\t\t\t\\Hex{..}{} \r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LD rr,(nm)} \r\n\t\t\\Symbol{\\SymLD{rr\\High}{(nm+1)}}\r\n\t\t\t\\FlagsLDrr\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{4}\r\n\t\t\t\\Cycles{6}{20}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLD{rr\\Low}{(nm)}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{01}{\\OCT{rr}1}{011}\r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{m} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{n} \r\n\t\t\t\\Hex{..}{} \r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LD IX,(nm)}\r\n\t\t\\Symbol{\\SymLD{IX\\High}{(nm+1)}}\r\n\t\t\t\\FlagsLDrr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{4}\r\n\t\t\t\\Cycles{6}{20}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLD{IX\\Low}{(nm)}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{00}{101}{010}\r\n\t\t\t\\Hex{2A}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{m}\r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{n}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LD IY,(nm)}\r\n\t\t\\Symbol{\\SymLD{IY\\High}{(nm+1)}}\r\n\t\t\t\\FlagsLDrr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{4}\r\n\t\t\t\\Cycles{6}{20}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLD{IY\\Low}{(nn)}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{00}{101}{010}\r\n\t\t\t\\Hex{2A}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{n} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{n} \r\n\t\t\t\\Hex{..}{} \r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LD (nm),HL}\r\n\t\t\\Symbol{\\SymLD{(nn+1)}{H}}\r\n\t\t\t\\FlagsLDrr\r\n\t\t\t\\OpCode{00}{100}{010}\r\n\t\t\t\\Hex{22}{3} \r\n\t\t\t\\Cycles{5}{16}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLD{(nm)}{L}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpRange{m} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{n} \r\n\t\t\t\\Hex{..}{} \r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{LD (nm),rr} \r\n\t\t\\Symbol{\\SymLD{(nm+1)}{rr\\High}}\r\n\t\t\t\\FlagsLDrr\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{4}\r\n\t\t\t\\Cycles{6}{20}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLD{(nm)}{rr\\Low}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{01}{\\OCT{rr}0}{011}\r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{m} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{n} \r\n\t\t\t\\Hex{..}{} \r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{LD (nm),IX} \r\n\t\t\\Symbol{\\SymLD{(nm+1)}{IX\\High}}\r\n\t\t\t\\FlagsLDrr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{4}\r\n\t\t\t\\Cycles{6}{20}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLD{(nm)}{IX\\Low}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{00}{100}{010}\r\n\t\t\t\\Hex{22}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{m}\r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{n}\r\n\t\t\t\\Hex{..}{} \r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{LD (nm),IY} \r\n\t\t\\Symbol{\\SymLD{(nm+1)}{IY\\High}}\r\n\t\t\t\\FlagsLDrr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{4}\r\n\t\t\t\\Cycles{6}{20}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLD{(nm)}{IY\\Low}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{00}{100}{010}\r\n\t\t\t\\Hex{22}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{m} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{n} \r\n\t\t\t\\Hex{..}{} \r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LD SP,HL} \r\n\t\t\\Symbol{\\SymLD{SP}{HL}}\r\n\t\t\t\\FlagsLDrr\r\n\t\t\t\\OpCode{11}{111}{001}\r\n\t\t\t\\Hex{F9}{1}\r\n\t\t\t\\Cycles{1}{6}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{LD SP,IX} \r\n\t\t\\Symbol{\\SymLD{SP}{IX}}\r\n\t\t\t\\FlagsLDrr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{2}\r\n\t\t\t\\Cycles{2}{10}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{11}{111}{001}\r\n\t\t\t\\Hex{F9}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{lastinstruction}{LD SP,IY} \r\n\t\t\\Symbol{\\SymLD{SP}{IY}}\r\n\t\t\t\\FlagsLDrr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{2}\r\n\t\t\t\\Cycles{2}{10}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{11}{111}{001}\r\n\t\t\t\\Hex{F9}{}\r\n\t\\end{lastinstruction}\r\n\t\t\r\n\\end{instrtable}"
  },
  {
    "path": "chapter-instr-glance-8bit-arithmetic.tex",
    "content": "\\section{8-Bit Arithmetic and Logical}\r\n\r\n\\begin{minipage}{\\textwidth}\r\n\r\n\\begin{instrtable}\r\n\r\n\t\\begin{instruction}{ADD A,r}\r\n\t\t\\Symbol{\\SymADD{A}{r}}\r\n\t\t\t\\FlagsADDr\r\n\t\t\t\\OpCode{10}{\\fbox{000}}{\\OCT{r}}\r\n\t\t\t\\Hex{..}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\t\t\\Comment{\r\n\t\t\t\t\\tt\r\n\t\t\t\t\\multirow{6}{*}{\r\n\t\t\t\t\t\\begin{tabular}{ll}\r\n\t\t\t\t\t\tr & \\OCT{r} \\\\\r\n\t\t\t\t\t\t\\hline\r\n\t\t\t\t\t\tB & 000 \\\\\r\n\t\t\t\t\t\tC & 001 \\\\\r\n\t\t\t\t\t\tD & 010 \\\\\r\n\t\t\t\t\t\tE & 011 \\\\\r\n\t\t\t\t\t\tH & 100 \\\\\r\n\t\t\t\t\t\tL & 101 \\\\\r\n\t\t\t\t\t\tA & 111 \\\\\r\n\t\t\t\t\t\\end{tabular}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{ADD A,p}\r\n\t\t\\Symbol{\\SymADD{A}{p}}\r\n\t\t\t\\FlagsADDr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{2} \r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{10}{\\fbox{000}}{\\OCT{p}}\r\n\t\t\t\\Hex{..}{}\r\n\t\t\t\\Cycles{}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{ADD A,q} \r\n\t\t\\Symbol{\\SymADD{A}{q}}\r\n\t\t\t\\FlagsADDr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{10}{\\fbox{000}}{\\OCT{q}}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{ADD A,n}\r\n\t\t\\Symbol{\\SymADD{A}{n}}\r\n\t\t\t\\FlagsADDr\r\n\t\t\t\\OpCode{11}{\\fbox{000}}{110}\r\n\t\t\t\\Hex{C6}{2}\r\n\t\t\t\\Cycles{2}{7}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{n}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{ADD A,(HL)}\r\n\t\t\\Symbol{\\SymADD{A}{(HL)}}\r\n\t\t\t\\FlagsADDr\r\n\t\t\t\\OpCode{10}{\\fbox{000}}{110}\r\n\t\t\t\\Hex{86}{1} \r\n\t\t\t\\Cycles{2}{7}\r\n\t\t\t\\Comment{\r\n\t\t\t\t\\multirow{8}{*}{\r\n\t\t\t\t\t\\tt\r\n\t\t\t\t\t\\begin{tabular}{ll}\r\n\t\t\t\t\t\tp & \\OCT{p} \\\\\r\n\t\t\t\t\t\t\\hline\r\n\t\t\t\t\t\tB & 000 \\\\\r\n\t\t\t\t\t\tC & 001 \\\\\r\n\t\t\t\t\t\tD & 010 \\\\\r\n\t\t\t\t\t\tE & 011 \\\\\r\n\t\t\t\t\t\tIX\\High & 100 \\\\\r\n\t\t\t\t\t\tIX\\Low & 101 \\\\\r\n\t\t\t\t\t\tA & 111 \\\\\r\n\t\t\t\t\t\\end{tabular}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{ADD A,(IX+d)}\r\n\t\t\\Symbol{\\SymADD{A}{(IX+d)}}\r\n\t\t\t\\FlagsADDr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{3}\r\n\t\t\t\\Cycles{5}{19}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{10}{\\fbox{000}}{110}\r\n\t\t\t\\Hex{86}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{d}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{ADD A,(IY+d)}\r\n\t\t\\Symbol{\\SymADD{A}{(IY+d)}}\r\n\t\t\t\\FlagsADDr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{3}\r\n\t\t\t\\Cycles{5}{19}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{10}{\\fbox{000}}{110}\r\n\t\t\t\\Hex{86}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{d}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\StartWithOpCode\\OpCode{}{$\\uparrow$}{}\\\\\r\n\r\n\t\\begin{instruction}{ADC A,s\\See{2}}\r\n\t\t\\Symbol{\\SymADC{A}{s}}\r\n\t\t\\FlagsADCr\r\n\t\t\\OpCode{..}{\\fbox{001}}{...} \r\n\t\t\\Hex{}{}\r\n\t\t\\Cycles{}{}\r\n\t\t\\Comment{\r\n\t\t\t\\multirow{8}{*}{\r\n\t\t\t\t\\tt\r\n\t\t\t\t\\begin{tabular}{ll}\r\n\t\t\t\t\tq & \\OCT{q} \\\\\r\n\t\t\t\t\t\\hline\r\n\t\t\t\t\tB & 000 \\\\\r\n\t\t\t\t\tC & 001 \\\\\r\n\t\t\t\t\tD & 010 \\\\\r\n\t\t\t\t\tE & 011 \\\\\r\n\t\t\t\t\tIY\\High & 100 \\\\\r\n\t\t\t\t\tIY\\Low & 101 \\\\\r\n\t\t\t\t\tA & 111 \\\\\r\n\t\t\t\t\\end{tabular}\r\n\t\t\t}\r\n\t\t}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{SUB s\\See{2}}\r\n\t\t\\Symbol{\\SymSUB{s}}\r\n\t\t\t\\FlagsSUBr\r\n\t\t\t\\OpCode{..}{\\fbox{010}}{...}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{SBC A,s\\See{2}}\r\n\t\t\\Symbol{\\SymSBC{A}{s}}\r\n\t\t\t\\FlagsSBCr\r\n\t\t\t\\OpCode{..}{\\fbox{011}}{...}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{AND s\\See{2}}\r\n\t\t\\Symbol{\\SymAND{s}}\r\n\t\t\t\\FlagsANDr\r\n\t\t\t\\OpCode{..}{\\fbox{100}}{...}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{XOR s\\See{2}}\r\n\t\t\\Symbol{\\SymXOR{s}}\r\n\t\t\t\\FlagsXORr\r\n\t\t\t\\OpCode{..}{\\fbox{101}}{...}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{OR s\\See{2}}\r\n\t\t\\Symbol{\\SymOR{s}}\r\n\t\t\t\\FlagsORr\r\n\t\t\t\\OpCode{..}{\\fbox{110}}{...}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{CP s\\See{1,2}}\r\n\t\t\\Symbol{\\SymCP{s}}\r\n\t\t\t\\FlagsCPr\r\n\t\t\t\\OpCode{..}{\\fbox{111}}{...}\r\n\t\\end{instruction}\r\n\r\n\t\\Empty{}\r\n\r\n\t\\begin{instruction}{INC r} \r\n\t\t\\Symbol{\\SymINC{r}}\r\n\t\t\t\\FlagsINCr\r\n\t\t\t\\OpCode{00}{\\OCT{r}}{\\fbox{100}}\r\n\t\t\t\\Hex{..}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{INC p}\r\n\t\t\\Symbol{\\SymINC{p}}\r\n\t\t\t\\FlagsINCr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{00}{\\OCT{p}}{\\fbox{100}}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{INC q}\r\n\t\t\\Symbol{\\SymINC{q}}\r\n\t\t\t\\FlagsINCr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{2}\r\n\t\t\t\\Hex{2}{8}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{00}{\\OCT{q}}{\\fbox{100}}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{INC (HL)}\r\n\t\t\\Symbol{\\SymINC{(HL)}}\r\n\t\t\t\\FlagsINCr\r\n\t\t\t\\OpCode{00}{110}{\\fbox{100}}\r\n\t\t\t\\Hex{34}{1}\r\n\t\t\t\\Cycles{3}{11}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{INC (IX+d)}\r\n\t\t\\Symbol{\\SymINC{(IX+d)}}\r\n\t\t\t\\FlagsINCr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{3}\r\n\t\t\t\\Cycles{6}{23}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{00}{110}{\\fbox{100}}\r\n\t\t\t\\Hex{34}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{d}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{INC (IY+d)}\r\n\t\t\\Symbol{\\SymINC{(IY+d)}}\r\n\t\t\t\\FlagsINCr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{3}\r\n\t\t\t\\Cycles{6}{23}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{00}{110}{\\fbox{100}}\r\n\t\t\t\\Hex{34}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{d}\r\n\t\\end{instruction}\r\n\r\n\t\\StartWithOpCode\\OpCode{}{}{$\\uparrow$} \\\\\r\n\r\n\t\\begin{lastinstruction}{DEC m\\See{3}}\r\n\t\t\\Symbol{\\SymDEC{m}}\r\n\t\t\t\\FlagsDECr\r\n\t\t\t\\OpCode{..}{...}{\\fbox{101}}\r\n\t\\end{lastinstruction}\r\n\r\n\\end{instrtable}\r\n\r\n\\begin{notestable}\r\n\t\\NoteItem{\\See{1}YF and XF flags are copied from the operand {\\tt s}, not the result {\\tt A-s}}\r\n\r\n\t\\NoteItem{\\See{2}{\\tt s} is any of {\\tt r}, {\\tt p}, {\\tt q}, {\\tt n}, {\\tt (HL)}, {\\tt (IX+d)}, {\\tt (IY+d)} as shown for {\\tt ADD}. Replace \\fbox{{\\tt 000}} in the {\\tt ADD} set above. Ts also the same}\r\n\r\n\t\\NoteItem{\\See{3}{\\tt m} is any of {\\tt r}, {\\tt p}, {\\tt q}, {\\tt n}, {\\tt (HL)}, {\\tt (IX+d)}, {\\tt (IY+d)} as shown for {\\tt INC}. Replace \\fbox{{\\tt 100}} with \\fbox{{\\tt 101}} in opcode. Ts also the same}\r\n\r\n\t\\NoteItem{\\See{4}PV set if value was {\\tt \\$7F} before incrementing}\r\n\r\n\t\\NoteItem{\\See{5}PV set if value was {\\tt \\$80} before decrementing}\r\n\\end{notestable}\r\n\r\n\\end{minipage}\r\n"
  },
  {
    "path": "chapter-instr-glance-8bit-load.tex",
    "content": "\\section{8-Bit Load}\r\n\r\n\\begin{instrtable}\t\r\n\r\n\t\\begin{instruction}{LD r,r'}\r\n\t\t\\Symbol{\\SymLD{r}{r'}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{01}{\\OCT{r}}{\\OCTS{r}}\r\n\t\t\t\\Hex{..}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\t\t\\Comment{\r\n\t\t\t\t\\tt\r\n\t\t\t\t\\multirow{6}{*}{\r\n\t\t\t\t\t\\begin{tabular}{ll}\r\n\t\t\t\t\t\tr & \\OCT{r} \\\\\r\n\t\t\t\t\t\tr' & \\OCTS{r} \\\\\r\n\t\t\t\t\t\t\\hline\r\n\t\t\t\t\t\tB & 000 \\\\\r\n\t\t\t\t\t\tC & 001 \\\\\r\n\t\t\t\t\t\tD & 010 \\\\\r\n\t\t\t\t\t\tE & 011 \\\\\r\n\t\t\t\t\t\tH & 100 \\\\\r\n\t\t\t\t\t\tL & 101 \\\\\r\n\t\t\t\t\t\tA & 111 \\\\\r\n\t\t\t\t\t\\end{tabular}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\\end{instruction}\r\n\t\t\r\n\t\\begin{instruction}{LD p,p'}\r\n\t\t\\Symbol{\\SymLD{p}{p'}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{11}{011}{101} \r\n\t\t\t\\Hex{DD}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{01}{\\OCT{p}}{\\OCTS{p}}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LD q,q'}\r\n\t\t\\Symbol{\\SymLD{q}{q'}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{2} \r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{01}{\\OCT{q}}{\\OCTS{q}}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LD r,n}\r\n\t\t\\Symbol{\\SymLD{r}{n}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{00}{\\OCT{r}}{110}\r\n\t\t\t\\Hex{..}{2} \r\n\t\t\t\\Cycles{2}{7}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{n}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LD p,n}\r\n\t\t\\Symbol{\\SymLD{p}{n}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{3} \r\n\t\t\t\\Cycles{3}{11}\r\n\t\t\t\\Comment{\r\n\t\t\t\t\\multirow{6}{*}{\r\n\t\t\t\t\t\\tt\r\n\t\t\t\t\t\\begin{tabular}{ll}\r\n\t\t\t\t\t\tp & \\OCT{p} \\\\\r\n\t\t\t\t\t\tp' & \\OCTS{p} \\\\\r\n\t\t\t\t\t\t\\hline\r\n\t\t\t\t\t\tB & 000 \\\\\r\n\t\t\t\t\t\tC & 001 \\\\\r\n\t\t\t\t\t\tD & 010 \\\\\r\n\t\t\t\t\t\tE & 011 \\\\\r\n\t\t\t\t\t\tIX\\High & 100 \\\\\r\n\t\t\t\t\t\tIX\\Low & 101 \\\\\r\n\t\t\t\t\t\tA & 111 \\\\\r\n\t\t\t\t\t\\end{tabular}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{00}{\\OCT{p}}{110}\r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{n}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{LD q,n}\r\n\t\t\\Symbol{\\SymLD{q}{n}} \r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{3}\r\n\t\t\t\\Cycles{3}{11}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{00}{\\OCT{q}}{110}\r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{n}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LD r,(HL)}\r\n\t\t\\Symbol{\\SymLD{r}{(HL)}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{01}{\\OCT{r}}{110}\r\n\t\t\t\\Hex{..}{1}\r\n\t\t\t\\Cycles{2}{7}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LD r,(IX+d)}\r\n\t\t\\Symbol{\\SymLD{r}{(IX+d)}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{3}\r\n\t\t\t\\Cycles{5}{19}\r\n\t\t\t\\Comment{\r\n\t\t\t\t\\multirow{6}{*}{\r\n\t\t\t\t\t\\tt\r\n\t\t\t\t\t\\begin{tabular}{ll}\r\n\t\t\t\t\t\tq & \\OCT{q} \\\\\r\n\t\t\t\t\t\tq' & \\OCTS{q} \\\\\r\n\t\t\t\t\t\t\\hline\r\n\t\t\t\t\t\tB & 000 \\\\\r\n\t\t\t\t\t\tC & 001 \\\\\r\n\t\t\t\t\t\tD & 010 \\\\\r\n\t\t\t\t\t\tE & 011 \\\\\r\n\t\t\t\t\t\tIY\\High & 100 \\\\\r\n\t\t\t\t\t\tIY\\Low & 101\\\\\r\n\t\t\t\t\t\tA & 111 \\\\\r\n\t\t\t\t\t\\end{tabular}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{01}{\\OCT{r}}{110}\r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{d}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LD r,(IY+d)}\r\n\t\t\\Symbol{\\SymLD{r}{(IY+d)}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{3}\r\n\t\t\t\\Cycles{5}{19}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{01}{\\OCT{r}}{110}\r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{d}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LD (HL),r}\r\n\t\t\\Symbol{\\SymLD{(HL)}{r}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{01}{110}{\\OCT{r}}\r\n\t\t\t\\Hex{..}{1} \r\n\t\t\t\\Cycles{2}{7}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LD (IX+d),r}\r\n\t\t\\Symbol{\\SymLD{(IX+d)}{r}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{3}\r\n\t\t\t\\Cycles{5}{19}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{01}{110}{\\OCT{r}}\r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{d}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LD (IY+d),r}\r\n\t\t\\Symbol{\\SymLD{(IY+d)}{r}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{11}{111}{101} \r\n\t\t\t\\Hex{FD}{3} \r\n\t\t\t\\Cycles{5}{19}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{01}{110}{\\OCT{r}}\r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{d}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LD (HL),n}\r\n\t\t\\Symbol{\\SymLD{(HL)}{n}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{00}{110}{110}\r\n\t\t\t\\Hex{36}{2}\r\n\t\t\t\\Cycles{3}{10}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{n}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LD (IX+d),n} \r\n\t\t\\Symbol{\\SymLD{(IX+d)}{n}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{4}\r\n\t\t\t\\Cycles{5}{19}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{00}{110}{110}\r\n\t\t\t\\Hex{36}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{d}\r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{n}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{LD (IY+d),n} \r\n\t\t\\Symbol{\\SymLD{(IY+d)}{n}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{4}\r\n\t\t\t\\Cycles{5}{19}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{00}{110}{110}\r\n\t\t\t\\Hex{36}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{d}\r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{n}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\t\r\n\t\\begin{instruction}{LD A,(BC)} \r\n\t\t\\Symbol{\\SymLD{A}{(BC)}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{00}{001}{010}\r\n\t\t\t\\Hex{0A}{1}\r\n\t\t\t\\Cycles{2}{7}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{LD A,(DE)} \r\n\t\t\\Symbol{\\SymLD{A}{(DE)}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{00}{011}{01}\r\n\t\t\t\\Hex{1A}{1}\r\n\t\t\t\\Cycles{2}{7}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{lastinstruction}{LD A,(nm)} \r\n\t\t\\Symbol{\\SymLD{A}{(nm)}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{00}{111}{010}\r\n\t\t\t\\Hex{3A}{3}\r\n\t\t\t\\Cycles{4}{13}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{m}\r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{n}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{lastinstruction}\r\n\t\t\t\r\n\\end{instrtable}\r\n\r\n\\InstrTableContinue\r\n\\pagebreak\r\n\r\n\\vspace*{0.38cm} % ensure this table starts at the same height as the one on the odd page\r\n\\begin{instrtable}\r\n\r\n\t\\begin{instruction}{LD (BC),A} \r\n\t\t\\Symbol{\\SymLD{(BC)}{A}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{00}{000}{010}\r\n\t\t\t\\Hex{02}{1}\r\n\t\t\t\\Cycles{2}{7}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LD (DE),A} \r\n\t\t\\Symbol{\\SymLD{(DE)}{A}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{00}{010}{010}\r\n\t\t\t\\Hex{12}{1}\r\n\t\t\t\\Cycles{2}{7}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LD (nm),A} \r\n\t\t\\Symbol{\\SymLD{(nm)}{A}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{00}{110}{010}\r\n\t\t\t\\Hex{32}{3}\r\n\t\t\t\\Cycles{4}{13}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{m}\r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{n}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LD A,I} \r\n\t\t\\Symbol{\\SymLD{A}{I}}\r\n\t\t\t\\FlagsLDair\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{2}{9}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{01}{010}{111}\r\n\t\t\t\\Hex{57}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LD A,R} \r\n\t\t\\Symbol{\\SymLD{A}{R}}\r\n\t\t\t\\FlagsLDair\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{2}{9}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{01}{011}{111}\r\n\t\t\t\\Hex{5F}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LD I,A} \r\n\t\t\\Symbol{\\SymLD{I}{A}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{2}{9}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{01}{000}{111}\r\n\t\t\t\\Hex{47}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{lastinstruction}{LD R,A} \r\n\t\t\\Symbol{\\SymLD{R}{A}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{2}{9}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{01}{001}{111}\r\n\t\t\t\\Hex{4F}{}\r\n\t\\end{lastinstruction}\r\n\r\n\\end{instrtable}\r\n"
  },
  {
    "path": "chapter-instr-glance-alphabetical.tex",
    "content": "% Alphabetical section only really makes sense for printed book; online PDF can be searched to get to specific instructions. TBH, the whole \"in a glance\" chapter only truly comes to life on paper, for online version, details chapter is more suitable, combined with sorted by mnemonic if actual machine codes are needed. But for now I'm only stripping alphabetical section out...\r\n\\ifdefined\\isPDF\r\n\\else\r\n\r\n\\section{Alphabetical}\r\n\r\n\\renewcommand{\\FlagsSee}[1]{}\t% we don't want to display any footnotes in alphabetical list; it would result in too many notes as instructions are not grouped by their resemblance\r\n\r\n% note we don't need `lastinstruction` here because we don't use bottom hline; however it's still useful in cases where last instruction in the table would otherwise cause vertical gap before next table\r\n\r\n\\begin{instrtablesimple}\r\n\r\n\t\\begin{instruction}{ADC A,r}\r\n\t\t\\Symbol{\\SymADC{A}{r}}\r\n\t\t\t\\FlagsADCr\r\n\t\t\t\\OpCode{10}{001}{\\OCT{r}}\r\n\t\t\t\\Hex{..}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{ADC A,n}\r\n\t\t\\Symbol{\\SymADC{A}{n}}\r\n\t\t\t\\FlagsADCr\r\n\t\t\t\\OpCode{11}{001}{110}\r\n\t\t\t\\Hex{CE}{2}\r\n\t\t\t\\Cycles{2}{7}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{n}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{ADC A,(HL)}\r\n\t\t\\Symbol{\\SymADC{A}{(HL)}}\r\n\t\t\t\\FlagsADCr\r\n\t\t\t\\OpCode{10}{001}{110}\r\n\t\t\t\\Hex{8E}{1} \r\n\t\t\t\\Cycles{2}{7}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{ADC A,(IX+d)}\r\n\t\t\\Symbol{\\SymADC{A}{(IX+d)}}\r\n\t\t\t\\FlagsADCr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{3}\r\n\t\t\t\\Cycles{5}{19}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{10}{001}{110}\r\n\t\t\t\\Hex{8E}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{d}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\t\r\n\t\\begin{instruction}{ADC A,(IY+d)}\r\n\t\t\\Symbol{\\SymADC{A}{(IY+d)}}\r\n\t\t\t\\FlagsADCr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{3}\r\n\t\t\t\\Cycles{5}{19}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{10}{001}{110}\r\n\t\t\t\\Hex{8E}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{d}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{ADC HL,rr} \r\n\t\t\\Symbol{\\SymADC{HL}{rr}}\r\n\t\t\t\\FlagsADCrr\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{15}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{01}{\\OCT{rr}1}{010}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\EmptySeparator\r\n\r\n\t%-------------------------------------------\r\n\r\n\t\\begin{instruction}{ADD A,r}\r\n\t\t\\Symbol{\\SymADD{A}{r}}\r\n\t\t\t\\FlagsADDr\r\n\t\t\t\\OpCode{10}{000}{\\OCT{r}}\r\n\t\t\t\\Hex{..}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{ADD A,n}\r\n\t\t\\Symbol{\\SymADD{A}{n}}\r\n\t\t\t\\FlagsADDr\r\n\t\t\t\\OpCode{11}{000}{110}\r\n\t\t\t\\Hex{C6}{2}\r\n\t\t\t\\Cycles{2}{7}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{n}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\t\r\n\t\\begin{instruction}{ADD A,(HL)}\r\n\t\t\\Symbol{\\SymADD{A}{(HL)}}\r\n\t\t\t\\FlagsADDr\r\n\t\t\t\\OpCode{10}{000}{110}\r\n\t\t\t\\Hex{86}{1} \r\n\t\t\t\\Cycles{2}{7}\r\n\t\\end{instruction}\r\n\t\t\r\n\t\\begin{instruction}{ADD A,(IX+d)}\r\n\t\t\\Symbol{\\SymADD{A}{(IX+d)}}\r\n\t\t\t\\FlagsADDr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{3}\r\n\t\t\t\\Cycles{5}{19}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{10}{000}{110}\r\n\t\t\t\\Hex{86}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{d}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\t\t\r\n\t\\begin{instruction}{ADD A,(IY+d)}\r\n\t\t\\Symbol{\\SymADD{A}{(IY+d)}}\r\n\t\t\t\\FlagsADDr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{3}\r\n\t\t\t\\Cycles{5}{19}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{10}{000}{110}\r\n\t\t\t\\Hex{86}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{d}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{ADD HL,rr} \r\n\t\t\\Symbol{\\SymADD{HL}{rr}}\r\n\t\t\t\\FlagsADDrr\r\n\t\t\t\\OpCode{00}{\\OCT{rr}1}{001}\r\n\t\t\t\\Hex{..}{1}\r\n\t\t\t\\Cycles{3}{11}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{ADD IX,rr} \r\n\t\t\\Symbol{\\SymADD{IX}{rr}}\r\n\t\t\t\\FlagsADDrr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{2}\r\n\t\t\t\\Cycles{4}{15}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{00}{\\OCT{rr}1}{001}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{ADD IY,rr} \r\n\t\t\\Symbol{\\SymADD{IY}{rr}}\r\n\t\t\t\\FlagsADDrr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{2}\r\n\t\t\t\\Cycles{4}{15}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{00}{\\OCT{rr}1}{001}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{ADD rr,A\\ZXNS} \r\n\t\t\\Symbol{\\SymADD{rr}{A}}\r\n\t\t\t\\FlagsADDrra\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{110}{0\\OCT{rr}}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{ADD rr,nm\\ZXNS} \r\n\t\t\\Symbol{\\SymADD{rr}{nm}}\r\n\t\t\t\\FlagsADDrrnn\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{110}{1\\OCT{rr}}\r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{m} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{n} \r\n\t\t\t\\Hex{..}{} \r\n\t\\end{instruction}\r\n\r\n\t\\EmptySeparator\r\n\r\n\t%-------------------------------------------\r\n\r\n\t\\begin{instruction}{AND A,r}\r\n\t\t\\Symbol{\\SymAND{r}}\r\n\t\t\t\\FlagsANDr\r\n\t\t\t\\OpCode{10}{100}{\\OCT{r}}\r\n\t\t\t\\Hex{..}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{AND A,n}\r\n\t\t\\Symbol{\\SymAND{n}}\r\n\t\t\t\\FlagsANDr\r\n\t\t\t\\OpCode{11}{100}{110}\r\n\t\t\t\\Hex{E6}{2}\r\n\t\t\t\\Cycles{2}{7}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{n}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\t\r\n\t\\begin{instruction}{AND A,(HL)}\r\n\t\t\\Symbol{\\SymAND{(HL)}}\r\n\t\t\t\\FlagsANDr\r\n\t\t\t\\OpCode{10}{100}{110}\r\n\t\t\t\\Hex{A6}{}\r\n\t\t\t\\Cycles{2}{7}\r\n\t\\end{instruction}\r\n\t\t\r\n\t\\begin{instruction}{AND A,(IX+d)}\r\n\t\t\\Symbol{\\SymAND{(IX+d)}}\r\n\t\t\t\\FlagsANDr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{3}\r\n\t\t\t\\Cycles{5}{19}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{10}{100}{110}\r\n\t\t\t\\Hex{A6}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{d}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\t\t\r\n\t\\begin{instruction}{AND A,(IY+d)}\r\n\t\t\\Symbol{\\SymAND{(IY+d)}}\r\n\t\t\t\\FlagsANDr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{3}\r\n\t\t\t\\Cycles{5}{19}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{10}{100}{110}\r\n\t\t\t\\Hex{A6}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{d}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\t\t\r\n\\end{instrtablesimple}\r\n\r\n\\vspace*{3ex} % ensure this table starts at the same height as the one on the odd page\r\n\\begin{instrtablesimple}\r\n\t\r\n\t\\begin{instruction}{BIT b,r} \r\n\t\t\\Symbol{\\SymBIT{r}}\r\n\t\t\t\\FlagsBITr\r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{01}{\\OCT{b}}{\\OCT{r}}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{BIT b,(HL)} \r\n\t\t\\Symbol{\\SymBIT{(HL)}}\r\n\t\t\t\\FlagsBITr\r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{2}\r\n\t\t\t\\Cycles{3}{12}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{01}{\\OCT{b}}{110}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{BIT b,(IX+d)} \r\n\t\t\\Symbol{\\SymBIT{(IX+d)}}\r\n\t\t\t\\FlagsBITr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{4}\r\n\t\t\t\\Cycles{5}{20}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{d}\r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{01}{\\OCT{b}}{110}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{BIT b,(IY+d)} \r\n\t\t\\Symbol{\\SymBIT{(IY+d)}}\r\n\t\t\t\\FlagsBITr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{4}\r\n\t\t\t\\Cycles{5}{20}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{d} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{01}{\\OCT{b}}{110}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\EmptySeparator\r\n\r\n\t%-------------------------------------------\r\n\t\t\r\n\t\\begin{instruction}{BRLC DE,B\\ZXNS} \r\n\t\t\\Symbol{\\SymBRLC[0]}\r\n\t\t\t\\FlagsBRLC\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymBRLC[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{00}{101}{100}\r\n\t\t\t\\Hex{2C}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{BSLA DE,B\\ZXNS} \r\n\t\t\\Symbol{\\SymBSLA[0]}\r\n\t\t\t\\FlagsBSLA\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{101}{000}\r\n\t\t\t\\Hex{28}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{BSRA DE,B\\ZXNS} \r\n\t\t\\SymbolS{\\SymBSRA[0]}\r\n\t\t\t\\FlagsBSRA\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\SymbolP{\\SymBSRA[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{00}{101}{001}\r\n\t\t\t\\Hex{29}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{BSRL DE,B\\ZXNS} \r\n\t\t\\SymbolS{\\SymBSRL[0]}\r\n\t\t\t\\FlagsBSRL\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\SymbolP{\\SymBSRL[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{00}{101}{010}\r\n\t\t\t\\Hex{2A}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{BSRF DE,B\\ZXNS} \r\n\t\t\\SymbolS{\\SymBSRF[0]}\r\n\t\t\t\\FlagsBSRF\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\SymbolP{\\SymBSRF[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{00}{101}{011}\r\n\t\t\t\\Hex{2B}{}\r\n\t\t\t\\Cycles{}{}\r\n\t\\end{instruction}\r\n\r\n\t\\EmptySeparator\r\n\r\n\t%-------------------------------------------\r\n\t\r\n\t\\begin{instruction}{CALL nm} \r\n\t\t\\Symbol{\\SymCALL[0]{nm}}\r\n\t\t\t\\FlagsCALLnn\r\n\t\t\t\\OpCode{11}{001}{101}\r\n\t\t\t\\Hex{CD}{3}\r\n\t\t\t\\Cycles{5}{17}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymCALL[1]{nm}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpRange{m} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymCALL[2]{nm}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpRange{n} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymCALL[3]{nm}}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{CALL c,nm} \r\n\t\t\\Symbol{\\SymCALLc{nm}}\r\n\t\t\t\\FlagsCALLccnn\r\n\t\t\t\\OpCode{11}{\\OCT{c}}{100}\r\n\t\t\t\\Hex{..}{3}\r\n\t\t\t\\Cycles{3}{10}\r\n\t\t\t\\Comment{if {\\tt c}=false}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{m} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\t\\Cycles{5}{17}\r\n\t\t\t\\Comment{if {\\tt c}=true}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{n} \r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\EmptySeparator\r\n\r\n\t%-------------------------------------------\r\n\t\r\n\t\\begin{instruction}{CCF} \r\n\t\t\\Symbol{\\SymCCF}\r\n\t\t\t\\FlagsCCF\r\n\t\t\t\\OpCode{00}{111}{111}\r\n\t\t\t\\Hex{3F}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\\end{instruction}\r\n\r\n\t\\EmptySeparator\r\n\r\n\t%-------------------------------------------\r\n\r\n\t\\begin{instruction}{CP r}\r\n\t\t\\Symbol{\\SymCP{r}}\r\n\t\t\t\\FlagsCPr\r\n\t\t\t\\OpCode{10}{111}{\\OCT{r}}\r\n\t\t\t\\Hex{..}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{CP n}\r\n\t\t\\Symbol{\\SymCP{n}}\r\n\t\t\t\\FlagsCPr\r\n\t\t\t\\OpCode{11}{111}{110}\r\n\t\t\t\\Hex{FE}{2}\r\n\t\t\t\\Cycles{2}{7}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{n}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\t\r\n\t\\begin{instruction}{CP (HL)}\r\n\t\t\\Symbol{\\SymCP{(HL)}}\r\n\t\t\t\\FlagsCPr\r\n\t\t\t\\OpCode{10}{111}{110}\r\n\t\t\t\\Hex{BE}{1} \r\n\t\t\t\\Cycles{2}{7}\r\n\t\\end{instruction}\r\n\t\t\r\n\t\\begin{instruction}{CP (IX+d)}\r\n\t\t\\Symbol{\\SymCP{(IX+d)}}\r\n\t\t\t\\FlagsCPr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{3}\r\n\t\t\t\\Cycles{5}{19}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{10}{111}{110}\r\n\t\t\t\\Hex{BE}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{d}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\t\t\r\n\t\\begin{instruction}{CP (IY+d)}\r\n\t\t\\Symbol{\\SymCP{(IY+d)}}\r\n\t\t\t\\FlagsCPr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{3}\r\n\t\t\t\\Cycles{5}{19}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{10}{111}{110}\r\n\t\t\t\\Hex{BE}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{d}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\\end{instrtablesimple}\r\n\r\n\\begin{instrtablesimple}\r\n\t\r\n\t\\begin{instruction}{CPD} \r\n\t\t\\Symbol{\\SymCPD[0]}\r\n\t\t\t\\FlagsCPD\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymCPD[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{101}{001}\r\n\t\t\t\\Hex{A9}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymCPD[2]}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{CPDR} \r\n\t\t\\Symbol{\\SymCPDR[0]}\r\n\t\t\t\\FlagsCPDR\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\t\\Comment{if {\\tt A=(HL)}}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymCPDR[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{111}{001}\r\n\t\t\t\\Hex{B9}{}\r\n\t\t\t\\Cycles{}{}\r\n\t\t\t\\Comment{or {\\tt BC}=0}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{}{}{}\r\n\t\t\t\\Hex{}{}\r\n\t\t\t\\Cycles{5}{21}\r\n\t\t\t\\Comment{if {\\tt A}$\\neq${\\tt (HL)}}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{}{}{}\r\n\t\t\t\\Hex{}{}\r\n\t\t\t\\Cycles{}{}\r\n\t\t\t\\Comment{and {\\tt BC}$\\neq${\\tt 0}}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{CPI} \r\n\t\t\\Symbol{\\SymCPI[0]}\r\n\t\t\t\\FlagsCPI\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymCPI[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{100}{001}\r\n\t\t\t\\Hex{A1}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymCPI[2]}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{CPIR} \r\n\t\t\\Symbol{\\SymCPIR[0]}\r\n\t\t\t\\FlagsCPIR\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\t\\Comment{if {\\tt A=(HL)}}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymCPIR[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{110}{001}\r\n\t\t\t\\Hex{B1}{}\r\n\t\t\t\\Cycles{}{}\r\n\t\t\t\\Comment{or {\\tt BC}=0}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{}{}{}\r\n\t\t\t\\Hex{}{}\r\n\t\t\t\\Cycles{5}{21}\r\n\t\t\t\\Comment{if {\\tt A}$\\neq${\\tt (HL)}}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{}{}{}\r\n\t\t\t\\Hex{}{}\r\n\t\t\t\\Cycles{}{}\r\n\t\t\t\\Comment{and {\\tt BC}$\\neq$0}\r\n\t\\end{instruction}\r\n\r\n\t%-------------------------------------------\r\n\t\r\n\t\\begin{instruction}{CPL} \r\n\t\t\\Symbol{\\SymCPL}\r\n\t\t\t\\FlagsCPL\r\n\t\t\t\\OpCode{00}{101}{111}\r\n\t\t\t\\Hex{2F}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\\end{instruction}\r\n\r\n\t%-------------------------------------------\r\n\r\n\t\\begin{instruction}{DAA}\r\n\t\t\\Symbol{}\r\n\t\t\t\\FlagsDAA\r\n\t\t\t\\OpCode{00}{100}{111}\r\n\t\t\t\\Hex{27}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\\end{instruction}\r\n\r\n\t\\EmptySeparator\r\n\r\n\t%-------------------------------------------\r\n\r\n\t\\begin{instruction}{DEC r}\r\n\t\t\\Symbol{\\SymDEC{r}}\r\n\t\t\t\\FlagsDECr\r\n\t\t\t\\OpCode{00}{\\OCT{r}}{101}\r\n\t\t\t\\Hex{..}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\\end{instruction}\r\n\t\t\r\n\t\\begin{instruction}{DEC (HL)}\r\n\t\t\\Symbol{\\SymDEC{(HL)}}\r\n\t\t\t\\FlagsDECr\r\n\t\t\t\\OpCode{00}{110}{101}\r\n\t\t\t\\Hex{35}{1} \r\n\t\t\t\\Cycles{3}{11}\r\n\t\\end{instruction}\r\n\t\t\r\n\t\\begin{instruction}{DEC (IX+d)}\r\n\t\t\\Symbol{\\SymDEC{(IX+d)}}\r\n\t\t\t\\FlagsDECr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{3}\r\n\t\t\t\\Cycles{5}{19}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{00}{110}{101}\r\n\t\t\t\\Hex{35}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{d}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\t\t\r\n\t\\begin{instruction}{DEC (IY+d)}\r\n\t\t\\Symbol{\\SymDEC{(IY+d)}}\r\n\t\t\t\\FlagsDECr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{3}\r\n\t\t\t\\Cycles{5}{19}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{00}{110}{101}\r\n\t\t\t\\Hex{35}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{d}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{DEC rr} \r\n\t\t\\Symbol{\\SymDEC{rr}}\r\n\t\t\t\\FlagsDECrr\r\n\t\t\t\\OpCode{00}{\\OCT{rr}1}{011}\r\n\t\t\t\\Hex{..}{1}\r\n\t\t\t\\Cycles{1}{6}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{DEC IX} \r\n\t\t\\Symbol{\\SymDEC{IX}}\r\n\t\t\t\\FlagsDECrr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{2}\r\n\t\t\t\\Cycles{2}{10}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{00}{101}{011}\r\n\t\t\t\\Hex{2B}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{DEC IY} \r\n\t\t\\Symbol{\\SymDEC{IY}}\r\n\t\t\t\\FlagsDECrr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{2}\r\n\t\t\t\\Cycles{2}{10}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{00}{101}{011}\r\n\t\t\t\\Hex{2B}{}\r\n\t\\end{instruction}\r\n\r\n\t\\EmptySeparator\t\r\n\t\r\n\t%-------------------------------------------\r\n\r\n\t\\begin{instruction}{DI} \r\n\t\t\\Symbol{\\SymDI[0]}\r\n\t\t\t\\FlagsDI\r\n\t\t\t\\OpCode{11}{110}{011}\r\n\t\t\t\\Hex{F3}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymDI[1]}\r\n\t\\end{instruction}\r\n\r\n\t%-------------------------------------------\r\n\r\n\t\\begin{instruction}{DJNZ e} \r\n\t\t\\Symbol{\\SymDJNZ[0]{e}}\r\n\t\t\t\\FlagsDJNZ\r\n\t\t\t\\OpCode{00}{010}{000}\r\n\t\t\t\\Hex{10}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\t\\Comment{if {\\tt B}=0}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymDJNZ[1]{e}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpRangeSmall{e-2}\r\n\t\t\t\\Hex{..}{}\r\n\t\t\t\\Cycles{3}{13}\r\n\t\t\t\\Comment{if {\\tt B}$\\neq$0}\r\n\t\\end{instruction}\r\n\r\n\t%-------------------------------------------\r\n\r\n\t\\begin{instruction}{EI} \r\n\t\t\\Symbol{\\SymEI[0]}\r\n\t\t\t\\FlagsEI\r\n\t\t\t\\OpCode{11}{111}{011}\r\n\t\t\t\\Hex{FB}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymEI[1]}\r\n\t\\end{instruction}\r\n\r\n\t%-------------------------------------------\r\n\r\n\t\\begin{instruction}{EX AF,AF'} \r\n\t\t\\Symbol{\\SymEX{AF}{AF'}}\r\n\t\t\t\\FlagsEXaf\r\n\t\t\t\\OpCode{00}{001}{000}\r\n\t\t\t\\Hex{08}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{EX DE,HL} \r\n\t\t\\Symbol{\\SymEX{DE}{HL}}\r\n\t\t\t\\FlagsEXrr\r\n\t\t\t\\OpCode{11}{101}{011}\r\n\t\t\t\\Hex{EB}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{EX (SP),HL} \r\n\t\t\\Symbol{\\SymEX{H}{(SP+1)}}\r\n\t\t\t\\FlagsEXrr\r\n\t\t\t\\OpCode{11}{100}{011}\r\n\t\t\t\\Hex{E3}{1}\r\n\t\t\t\\Cycles{5}{19}\r\n\t\t\\SkipToSymbol \r\n\t\t\t\\Symbol{\\SymEX{L}{(SP)}}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{EX (SP),IX} \r\n\t\t\\Symbol{\\SymEX{IX\\High}{(SP+1)}}\r\n\t\t\t\\FlagsEXrr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{2}\r\n\t\t\t\\Cycles{6}{2}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymEX{IX\\Low}{(SP)}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{11}{100}{011}\r\n\t\t\t\\Hex{E3}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{EX (SP),IY} \r\n\t\t\\Symbol{\\SymEX{IY\\High}{(SP+1)}}\r\n\t\t\t\\FlagsEXrr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{2}\r\n\t\t\t\\Cycles{6}{23}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymEX{IY\\Low}{(SP)}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{11}{100}{011}\r\n\t\t\t\\Hex{E3}{}\r\n\t\\end{instruction}\r\n\t\r\n\\end{instrtablesimple}\r\n\r\n\\begin{instrtablesimple}\r\n\t\r\n\t\\begin{instruction}{EXX} \r\n\t\t\\Symbol{\\SymEXX[0]}\r\n\t\t\t\\FlagsEXX\r\n\t\t\t\\OpCode{11}{011}{001}\r\n\t\t\t\\Hex{D9}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymEXX[1]}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymEXX[2]}\r\n\t\\end{instruction}\r\n\r\n\t%-------------------------------------------\r\n\r\n\t\\begin{instruction}{HALT}\r\n\t\t\\Symbol{}\r\n\t\t\t\\FlagsHALT\r\n\t\t\t\\OpCode{01}{110}{110}\r\n\t\t\t\\Hex{76}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\\end{instruction}\r\n\r\n\t\\EmptySeparator\r\n\r\n\t%-------------------------------------------\r\n\r\n\t\\begin{instruction}{IM 0\\See{4}}\r\n\t\t\\Symbol{}\r\n\t\t\t\\FlagsIM\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{01}{000}{110}\r\n\t\t\t\\Hex{46}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{IM 1\\See{4}}\r\n\t\t\\Symbol{}\r\n\t\t\t\\FlagsIM\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{01}{010}{110}\r\n\t\t\t\\Hex{56}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{IM 2\\See{4}}\r\n\t\t\\Symbol{}\r\n\t\t\t\\FlagsIM\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{01}{011}{110}\r\n\t\t\t\\Hex{5E}{}\r\n\t\\end{instruction}\r\n\r\n\t\\EmptySeparator\r\n\t\r\n\t%-------------------------------------------\r\n\r\n\t\\begin{instruction}{IN A,(n)}\r\n\t\t\\Symbol{\\SymIN{A}{n}}\r\n\t\t\t\\FlagsINan\r\n\t\t\t\\OpCode{11}{011}{011}\r\n\t\t\t\\Hex{DB}{2}\r\n\t\t\t\\Cycles{3}{11}\r\n\t\t\\SkipToOpCode\t\r\n\t\t\t\\OpRange{n} \r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{IN r,(C)}\r\n\t\t\\Symbol{\\SymIN{r}{BC}}\r\n\t\t\t\\FlagsINrc\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{3}{12}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{01}{\\OCT{r}}{000}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{IN (C)}\r\n\t\t\\Symbol{(BC)}\r\n\t\t\t\\FlagsINc\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{3}{12}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{01}{110}{000}\r\n\t\t\t\\Hex{70}{}\r\n\t\\end{instruction}\r\n\r\n\t\\EmptySeparator\r\n\t\r\n\t%-------------------------------------------\r\n\r\n\t\\begin{instruction}{INC r}\r\n\t\t\\Symbol{\\SymINC{r}}\r\n\t\t\t\\FlagsINCr\r\n\t\t\t\\OpCode{00}{\\OCT{r}}{100}\r\n\t\t\t\\Hex{..}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\\end{instruction}\r\n\t\t\t\r\n\t\\begin{instruction}{INC (HL)}\r\n\t\t\\Symbol{\\SymINC{(HL)}}\r\n\t\t\t\\FlagsINCr\r\n\t\t\t\\OpCode{00}{110}{100}\r\n\t\t\t\\Hex{34}{1} \r\n\t\t\t\\Cycles{3}{11}\r\n\t\\end{instruction}\r\n\t\t\t\r\n\t\\begin{instruction}{INC (IX+d)}\r\n\t\t\\Symbol{\\SymINC{(IX+d)}}\r\n\t\t\t\\FlagsINCr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{3}\r\n\t\t\t\\Cycles{5}{19}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{00}{110}{100}\r\n\t\t\t\\Hex{34}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{d}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\t\t\t\r\n\t\\begin{instruction}{INC (IY+d)}\r\n\t\t\\Symbol{\\SymINC{(IY+d)}}\r\n\t\t\t\\FlagsINCr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{3}\r\n\t\t\t\\Cycles{5}{19}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{00}{110}{100}\r\n\t\t\t\\Hex{34}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{d}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{INC rr} \r\n\t\t\\Symbol{\\SymINC{rr}}\r\n\t\t\t\\FlagsINCrr\r\n\t\t\t\\OpCode{00}{\\OCT{rr}0}{011}\r\n\t\t\t\\Hex{..}{1}\r\n\t\t\t\\Cycles{1}{6}\r\n\t\\end{instruction}\r\n\t\t\r\n\t\\begin{instruction}{INC IX} \r\n\t\t\\Symbol{\\SymINC{IX}}\r\n\t\t\t\\FlagsINCrr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{2}\r\n\t\t\t\\Cycles{2}{10}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{00}{100}{011}\r\n\t\t\t\\Hex{23}{}\r\n\t\\end{instruction}\r\n\t\t\r\n\t\\begin{instruction}{INC IY} \r\n\t\t\\Symbol{\\SymINC{IY}}\r\n\t\t\t\\FlagsINCrr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{2}\r\n\t\t\t\\Cycles{2}{10}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{00}{100}{011}\r\n\t\t\t\\Hex{23}{}\r\n\t\\end{instruction}\r\n\r\n\t\\EmptySeparator\t\r\n\t\t\r\n\t%-------------------------------------------\r\n\r\n\t\\begin{instruction}{IND} \r\n\t\t\\Symbol{\\SymIND[0]}\r\n\t\t\t\\FlagsIND\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymIND[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{101}{010}\r\n\t\t\t\\Hex{AA}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymIND[2]}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{INDR} \r\n\t\t\\Symbol{\\SymINDR[0]}\r\n\t\t\t\\FlagsINDR\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\t\\Comment{if {\\tt B}=0}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymINDR[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{111}{010}\r\n\t\t\t\\Hex{BA}{}\r\n\t\t\t\\Cycles{5}{21}\r\n\t\t\t\\Comment{if {\\tt B}$\\neq$0}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{INI} \r\n\t\t\\Symbol{\\SymINI[0]}\r\n\t\t\t\\FlagsINI\r\n\t\t\t\\OpCode{11}{101}{101} \r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymINI[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{100}{010}\r\n\t\t\t\\Hex{A2}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymINI[2]}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{INIR} \r\n\t\t\\Symbol{\\SymINIR[0]}\r\n\t\t\t\\FlagsINIR\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\t\\Comment{if {\\tt B}=0}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymINIR[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{110}{010}\r\n\t\t\t\\Hex{B2}{}\r\n\t\t\t\\Cycles{5}{21}\r\n\t\t\t\\Comment{if {\\tt B}$\\neq$0}\r\n\t\\end{instruction}\r\n\r\n\t\\EmptySeparator\r\n\t\r\n\t%-------------------------------------------\r\n\r\n\t\\begin{instruction}{JP nm} \r\n\t\t\\Symbol{\\SymJP{nm}}\r\n\t\t\t\\FlagsJPnn\r\n\t\t\t\\OpCode{11}{000}{011}\r\n\t\t\t\\Hex{C3}{3}\r\n\t\t\t\\Cycles{3}{10}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{m} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{n} \r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\r\n\\end{instrtablesimple}\r\n\r\n\\begin{instrtablesimple}\r\n\r\n\t\\begin{instruction}{JP (HL)}\r\n\t\t\\Symbol{\\SymJP{HL}}\r\n\t\t\t\\FlagsJPrr\r\n\t\t\t\\OpCode{11}{101}{001}\r\n\t\t\t\\Hex{E9}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{JP (IX)} \r\n\t\t\\Symbol{\\SymJP{IX}}\r\n\t\t\t\\FlagsJPrr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{11}{101}{001}\r\n\t\t\t\\Hex{E9}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{JP (IY)} \r\n\t\t\\Symbol{\\SymJP{IY}}\r\n\t\t\t\\FlagsJPrr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{11}{101}{001}\r\n\t\t\t\\Hex{E9}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{JP (C)\\ZXNS} \r\n\t\t\\Symbol{\\SymJPC}\r\n\t\t\t\\FlagsJPc\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{3}{13}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{10}{011}{000}\r\n\t\t\t\\Hex{98}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{JP c,nm} \r\n\t\t\\Symbol{\\SymJPc{nm}}\r\n\t\t\t\\FlagsJPccnn\r\n\t\t\t\\OpCode{11}{\\OCT{c}}{010}\r\n\t\t\t\\Hex{..}{3}\r\n\t\t\t\\Cycles{3}{10}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{m}\r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{n} \r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{JR e} \r\n\t\t\\Symbol{\\SymJR{e}}\r\n\t\t\t\\FlagsJRn\r\n\t\t\t\\OpCode{00}{011}{000}\r\n\t\t\t\\Hex{18}{2}\r\n\t\t\t\\Cycles{3}{12}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRangeSmall{e-2}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{JR c,e} \r\n\t\t\\Symbol{\\SymJRc{c}{e}}\r\n\t\t\t\\FlagsJRccn\r\n\t\t\t\\OpCode{00}{1\\OCT{cc}}{000}\r\n\t\t\t\\Hex{..}{2}\r\n\t\t\t\\Cycles{2}{7}\r\n\t\t\t\\Comment{if {\\tt p}=false}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRangeSmall{e-2}\r\n\t\t\t\\Hex{..}{}\r\n\t\t\t\\Cycles{3}{12}\r\n\t\t\t\\Comment{if {\\tt p}=true}\r\n\t\\end{instruction}\r\n\r\n\t\\EmptySeparator\r\n\t\r\n\t%-------------------------------------------\r\n\r\n\t\\begin{instruction}{LD r,r'}\r\n\t\t\\Symbol{\\SymLD{r}{r'}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{01}{\\OCT{r}}{\\OCTS{r}}\r\n\t\t\t\\Hex{..}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LD r,n}\r\n\t\t\\Symbol{\\SymLD{r}{n}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{00}{\\OCT{r}}{110}\r\n\t\t\t\\Hex{..}{2} \r\n\t\t\t\\Cycles{2}{7}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{n}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LD r,(HL)}\r\n\t\t\\Symbol{\\SymLD{r}{(HL)}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{01}{\\OCT{r}}{110}\r\n\t\t\t\\Hex{..}{1}\r\n\t\t\t\\Cycles{2}{7}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{LD r,(IX+d)}\r\n\t\t\\Symbol{\\SymLD{r}{(IX+d)}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{3}\r\n\t\t\t\\Cycles{5}{19}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{01}{\\OCT{r}}{110}\r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{d}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{LD r,(IY+d)}\r\n\t\t\\Symbol{\\SymLD{r}{(IY+d)}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{3}\r\n\t\t\t\\Cycles{5}{19}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{01}{\\OCT{r}}{110}\r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{d}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{LD (HL),r}\r\n\t\t\\Symbol{\\SymLD{(HL)}{r}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{01}{110}{\\OCT{r}}\r\n\t\t\t\\Hex{..}{1} \r\n\t\t\t\\Cycles{2}{7}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{LD (IX+d),r}\r\n\t\t\\Symbol{\\SymLD{(IX+d)}{r}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{3}\r\n\t\t\t\\Cycles{5}{19}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{01}{110}{\\OCT{r}}\r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{d}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{LD (IY+d),r}\r\n\t\t\\Symbol{\\SymLD{(IY+d)}{r}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{11}{111}{101} \r\n\t\t\t\\Hex{FD}{3} \r\n\t\t\t\\Cycles{5}{19}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{01}{110}{\\OCT{r}}\r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{d}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{LD (HL),n}\r\n\t\t\\Symbol{\\SymLD{(HL)}{n}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{00}{110}{110}\r\n\t\t\t\\Hex{36}{2}\r\n\t\t\t\\Cycles{3}{10}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{n}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{LD (IX+d),n} \r\n\t\t\\Symbol{\\SymLD{(IX+d)}{n}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{4}\r\n\t\t\t\\Cycles{5}{19}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{00}{110}{110}\r\n\t\t\t\\Hex{36}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{d}\r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{n}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\t\r\n\t\\begin{instruction}{LD (IY+d),n} \r\n\t\t\\Symbol{\\SymLD{(IY+d)}{n}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{4}\r\n\t\t\t\\Cycles{5}{19}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{00}{110}{110}\r\n\t\t\t\\Hex{36}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{d}\r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{n}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LD (BC),A} \r\n\t\t\\Symbol{\\SymLD{(BC)}{A}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{00}{000}{010}\r\n\t\t\t\\Hex{02}{1}\r\n\t\t\t\\Cycles{2}{7}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{LD (DE),A} \r\n\t\t\\Symbol{\\SymLD{(DE)}{A}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{00}{010}{010}\r\n\t\t\t\\Hex{12}{1}\r\n\t\t\t\\Cycles{2}{7}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{lastinstruction}{LD (nm),A} \r\n\t\t\\Symbol{\\SymLD{(nm)}{A}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{00}{110}{010}\r\n\t\t\t\\Hex{32}{3}\r\n\t\t\t\\Cycles{4}{13}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{m}\r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{n}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{lastinstruction}\r\n\t\r\n\\end{instrtablesimple}\r\n\r\n\\begin{instrtablesimple}\r\n\t\t\t\r\n\t\\begin{instruction}{LD A,(BC)} \r\n\t\t\\Symbol{\\SymLD{A}{(BC)}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{00}{001}{010}\r\n\t\t\t\\Hex{0A}{1}\r\n\t\t\t\\Cycles{2}{7}\r\n\t\\end{instruction}\r\n\t\t\r\n\t\\begin{instruction}{LD A,(DE)} \r\n\t\t\\Symbol{\\SymLD{A}{(DE)}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{00}{011}{01}\r\n\t\t\t\\Hex{1A}{1}\r\n\t\t\t\\Cycles{2}{7}\r\n\t\\end{instruction}\r\n\t\t\r\n\t\\begin{instruction}{LD A,(nm)} \r\n\t\t\\Symbol{\\SymLD{A}{(nm)}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{00}{111}{010}\r\n\t\t\t\\Hex{3A}{3}\r\n\t\t\t\\Cycles{4}{13}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{m}\r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{n}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LD A,I} \r\n\t\t\\Symbol{\\SymLD{A}{I}}\r\n\t\t\t\\FlagsLDair\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{2}{9}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{01}{010}{111}\r\n\t\t\t\\Hex{57}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{LD A,R} \r\n\t\t\\Symbol{\\SymLD{A}{R}}\r\n\t\t\t\\FlagsLDair\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{2}{9}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{01}{011}{111}\r\n\t\t\t\\Hex{5F}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{LD I,A} \r\n\t\t\\Symbol{\\SymLD{I}{A}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{2}{9}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{01}{000}{111}\r\n\t\t\t\\Hex{47}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{LD R,A} \r\n\t\t\\Symbol{\\SymLD{R}{A}}\r\n\t\t\t\\FlagsLDr\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{2}{9}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{01}{001}{111}\r\n\t\t\t\\Hex{4F}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LD rr,nm} \r\n\t\t\\Symbol{\\SymLD{rr}{nm}}\r\n\t\t\t\\FlagsLDrr\r\n\t\t\t\\OpCode{00}{\\OCT{rr}0}{001} \r\n\t\t\t\\Hex{..}{3} \r\n\t\t\t\\Cycles{3}{10}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{m} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{n} \r\n\t\t\t\\Hex{..}{} \r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{LD IX,nm} \r\n\t\t\\Symbol{\\SymLD{IX}{nm}}\r\n\t\t\t\\FlagsLDrr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{4}\r\n\t\t\t\\Cycles{4}{14}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{100}{001}\r\n\t\t\t\\Hex{21}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{m} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{n} \r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{LD IY,nm} \r\n\t\t\\Symbol{\\SymLD{IX}{nm}}\r\n\t\t\t\\FlagsLDrr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{4}\r\n\t\t\t\\Cycles{4}{14}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{100}{001}\r\n\t\t\t\\Hex{21}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{m} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{n} \r\n\t\t\t\\Hex{..}{} \r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{LD SP,HL} \r\n\t\t\\Symbol{\\SymLD{SP}{HL}}\r\n\t\t\t\\FlagsLDrr\r\n\t\t\t\\OpCode{11}{111}{001}\r\n\t\t\t\\Hex{F9}{1}\r\n\t\t\t\\Cycles{1}{6}\r\n\t\\end{instruction}\r\n\t\t\r\n\t\\begin{instruction}{LD SP,IX} \r\n\t\t\\Symbol{\\SymLD{SP}{IX}}\r\n\t\t\t\\FlagsLDrr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{2}\r\n\t\t\t\\Cycles{2}{10}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{11}{111}{001}\r\n\t\t\t\\Hex{F9}{}\r\n\t\\end{instruction}\r\n\t\t\r\n\t\\begin{instruction}{LD SP,IY} \r\n\t\t\\Symbol{\\SymLD{SP}{IY}}\r\n\t\t\t\\FlagsLDrr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{2}\r\n\t\t\t\\Cycles{2}{10}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{11}{111}{001}\r\n\t\t\t\\Hex{F9}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{LD HL,(nm)} \r\n\t\t\\Symbol{\\SymLD{H}{(nm+1)}}\r\n\t\t\t\\FlagsLDrr\r\n\t\t\t\\OpCode{00}{101}{010}\r\n\t\t\t\\Hex{2A}{3}\r\n\t\t\t\\Cycles{5}{16}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLD{L}{(nm)}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpRange{m}\r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{n} \r\n\t\t\t\\Hex{..}{} \r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{LD rr,(nm)} \r\n\t\t\\Symbol{\\SymLD{rr\\High}{(nm+1)}}\r\n\t\t\t\\FlagsLDrr\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{4}\r\n\t\t\t\\Cycles{6}{20}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLD{rr\\Low}{(nm)}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{01}{\\OCT{rr}1}{011}\r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{m} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{n} \r\n\t\t\t\\Hex{..}{} \r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{LD IX,(nm)}\r\n\t\t\\Symbol{\\SymLD{IX\\High}{(nm+1)}}\r\n\t\t\t\\FlagsLDrr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{4}\r\n\t\t\t\\Cycles{6}{20}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLD{IX\\Low}{(nm)}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{00}{101}{010}\r\n\t\t\t\\Hex{2A}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{m}\r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{n}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{LD IY,(nm)}\r\n\t\t\\Symbol{\\SymLD{IY\\High}{(nm+1)}}\r\n\t\t\t\\FlagsLDrr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{4}\r\n\t\t\t\\Cycles{6}{20}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLD{IY\\Low}{(nn)}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{00}{101}{010}\r\n\t\t\t\\Hex{2A}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{n} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{n} \r\n\t\t\t\\Hex{..}{} \r\n\t\\end{instruction}\r\n\t\r\n\\end{instrtablesimple}\r\n\r\n\\begin{instrtablesimple}\r\n\t\r\n\t\\begin{instruction}{LD (nm),HL}\r\n\t\t\\Symbol{\\SymLD{(nn+1)}{H}}\r\n\t\t\t\\FlagsLDrr\r\n\t\t\t\\OpCode{00}{100}{010}\r\n\t\t\t\\Hex{22}{3} \r\n\t\t\t\\Cycles{5}{16}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLD{(nm)}{L}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpRange{m} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{n} \r\n\t\t\t\\Hex{..}{} \r\n\t\\end{instruction}\r\n\t\t\r\n\t\\begin{instruction}{LD (nm),rr} \r\n\t\t\\Symbol{\\SymLD{(nm+1)}{rr\\High}}\r\n\t\t\t\\FlagsLDrr\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{4}\r\n\t\t\t\\Cycles{6}{20}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLD{(nm)}{rr\\Low}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{01}{\\OCT{rr}0}{011}\r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{m} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{n} \r\n\t\t\t\\Hex{..}{} \r\n\t\\end{instruction}\r\n\t\t\r\n\t\\begin{instruction}{LD (nm),IX} \r\n\t\t\\Symbol{\\SymLD{(nm+1)}{IX\\High}}\r\n\t\t\t\\FlagsLDrr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{4}\r\n\t\t\t\\Cycles{6}{20}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLD{(nm)}{IX\\Low}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{00}{100}{010}\r\n\t\t\t\\Hex{22}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{m}\r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{n}\r\n\t\t\t\\Hex{..}{} \r\n\t\\end{instruction}\r\n\t\t\r\n\t\\begin{instruction}{LD (nm),IY} \r\n\t\t\\Symbol{\\SymLD{(nm+1)}{IY\\High}}\r\n\t\t\t\\FlagsLDrr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{4}\r\n\t\t\t\\Cycles{6}{20}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLD{(nm)}{IY\\Low}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{00}{100}{010}\r\n\t\t\t\\Hex{22}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{m} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{n} \r\n\t\t\t\\Hex{..}{} \r\n\t\\end{instruction}\r\n\r\n\t\\EmptySeparator\r\n\r\n\t%-------------------------------------------\r\n\r\n\t\\begin{instruction}{LDD} \r\n\t\t\\Symbol{\\SymLDD[0]}\r\n\t\t\t\\FlagsLDD\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDD[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{101}{000}\r\n\t\t\t\\Hex{A8}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDD[2]}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDD[3]}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{LDDR} \r\n\t\t\\Symbol{\\SymLDDR[0]}\r\n\t\t\t\\FlagsLDDR\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\t\\Comment{if {\\tt BC=0}}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDDR[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{111}{000}\r\n\t\t\t\\Hex{B8}{}\r\n\t\t\t\\Cycles{5}{21}\r\n\t\t\t\\Comment{if {\\tt BC$\\neq$0}}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LDDX\\ZXNS} \r\n\t\t\\Symbol{\\SymLDDX[0]}\r\n\t\t\t\\FlagsLDDX\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDDX[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{101}{100}\r\n\t\t\t\\Hex{AC}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDDX[2]}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDDX[3]}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LDDRX\\ZXNS} \r\n\t\t\\Symbol{\\SymLDDRX[0]}\r\n\t\t\t\\FlagsLDDRX\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\t\\Comment{if {\\tt BC}=0}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDDRX[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{111}{100}\r\n\t\t\t\\Hex{BC}{}\r\n\t\t\t\\Cycles{5}{21}\r\n\t\t\t\\Comment{if {\\tt BC}$\\neq$0}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LDI}\r\n\t\t\\Symbol{\\SymLDI[0]}\r\n\t\t\t\\FlagsLDI\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDI[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{100}{000}\r\n\t\t\t\\Hex{A0}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDI[2]}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDI[3]}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{LDIR} \r\n\t\t\\Symbol{\\SymLDIR[0]}\r\n\t\t\t\\FlagsLDIR\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\t\\Comment{if {\\tt BC=0}}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDIR[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{110}{000}\r\n\t\t\t\\Hex{B0}{}\r\n\t\t\t\\Cycles{5}{21}\r\n\t\t\t\\Comment{if {\\tt BC$\\neq$0}}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LDIX\\ZXNS} \r\n\t\t\\Symbol{\\SymLDIX[0]}\r\n\t\t\t\\FlagsLDIX\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDIX[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{100}{100}\r\n\t\t\t\\Hex{A4}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDIX[2]}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDIX[3]}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{LDIRX\\ZXNS} \r\n\t\t\\Symbol{\\SymLDIRX[0]}\r\n\t\t\t\\FlagsLDIRX\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\t\\Comment{if {\\tt BC}=0}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDIRX[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{110}{100}\r\n\t\t\t\\Hex{B4}{}\r\n\t\t\t\\Cycles{5}{21}\r\n\t\t\t\\Comment{if {\\tt BC}$\\neq$0}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LDPIRX\\ZXNS} \r\n\t\t\\Symbol{\\SymLDPIRX[0]}\r\n\t\t\t\\FlagsLDPIRX\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\t\\Comment{if {\\tt BC}=0}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDPIRX[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{110}{111}\r\n\t\t\t\\Hex{B7}{}\r\n\t\t\t\\Cycles{5}{21}\r\n\t\t\t\\Comment{if {\\tt BC}$\\neq$0}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDPIRX[2]}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDPIRX[3]}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDPIRX[4]}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDPIRX[5]}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{lastinstruction}{LDWS\\ZXNS} \r\n\t\t\\Symbol{\\SymLDWS[0]}\r\n\t\t\t\\FlagsLDWS\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDWS[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{100}{101}\r\n\t\t\t\\Hex{A5}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDWS[2]}\r\n\t\\end{lastinstruction}\r\n\t\t\t\t\t\r\n\\end{instrtablesimple}\r\n\r\n\\begin{instrtablesimple}\r\n\t\r\n\t% we need some extra spacing to accomodate the image; it's negative because \\\\ adds a line, but we don't need full line of space...\r\n\t\\\\[-10pt]\r\n\r\n\t\\begin{instruction}{MIRROR A}\r\n\t\t\\Symbol{\\multirow{2}{*}{\\SymMIRROR{A}}}\r\n\t\t\t\\FlagsMIRRORa\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{100}{100}\r\n\t\t\t\\Hex{24}{}\r\n\t\\end{instruction}\r\n\r\n\t% we need some extra spacing to accomodate the image from MIRROR\r\n\t\\\\[0ex]\r\n\r\n\t%-------------------------------------------\r\n\r\n\t\\begin{instruction}{MUL D,E} \r\n\t\t\\Symbol{\\SymMUL}\r\n\t\t\t\\FlagsMULde\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{110}{000}\r\n\t\t\t\\Hex{30}{}\r\n\t\\end{instruction}\r\n\r\n\t%-------------------------------------------\r\n\r\n\t\\begin{instruction}{NEG} \r\n\t\t\\Symbol{\\SymNEG}\r\n\t\t\t\\FlagsNEG\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{01}{000}{100}\r\n\t\t\t\\Hex{44}{}\r\n\t\\end{instruction}\r\n\r\n\t\\EmptySeparator\r\n\r\n\t%-------------------------------------------\r\n\r\n\t\\begin{instruction}{NEXTREG n,A} \r\n\t\t\\Symbol{\\SymNEXTREG{A}}\r\n\t\t\t\\FlagsNEXTREGna\r\n\t\t\t\\OpCode{11}{101}{101} \r\n\t\t\t\\Hex{ED}{3}\r\n\t\t\t\\Cycles{4}{17}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{10}{010}{010}\r\n\t\t\t\\Hex{92}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{n} \r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{NEXTREG n,m}\r\n\t\t\\Symbol{\\SymNEXTREG{m}}\r\n\t\t\t\\FlagsNEXTREGnn\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{3}\r\n\t\t\t\\Cycles{5}{20}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{10}{010}{001}\r\n\t\t\t\\Hex{91}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{n} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{m} \r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\EmptySeparator\r\n\r\n\t%-------------------------------------------\r\n\r\n\t\\begin{instruction}{NOP}\r\n\t\t\\Symbol{}\r\n\t\t\t\\FlagsNOP\r\n\t\t\t\\OpCode{00}{000}{000}\r\n\t\t\t\\Hex{00}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\\end{instruction}\r\n\r\n\t\\EmptySeparator\r\n\r\n\t%-------------------------------------------\r\n\r\n\t\\begin{instruction}{OR r}\r\n\t\t\\Symbol{\\SymOR{r}}\r\n\t\t\t\\FlagsORr\r\n\t\t\t\\OpCode{10}{110}{\\OCT{r}}\r\n\t\t\t\\Hex{..}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\\end{instruction}\r\n\t\t\r\n\t\\begin{instruction}{OR n}\r\n\t\t\\Symbol{\\SymOR{n}}\r\n\t\t\t\\FlagsORr\r\n\t\t\t\\OpCode{11}{110}{110}\r\n\t\t\t\\Hex{F6}{2}\r\n\t\t\t\\Cycles{2}{7}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{n}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\t\t\r\n\t\\begin{instruction}{OR (HL)}\r\n\t\t\\Symbol{\\SymOR{(HL)}}\r\n\t\t\t\\FlagsORr\r\n\t\t\t\\OpCode{10}{110}{110}\r\n\t\t\t\\Hex{B6}{1} \r\n\t\t\t\\Cycles{2}{7}\r\n\t\\end{instruction}\r\n\t\t\t\r\n\t\\begin{instruction}{OR (IX+d)}\r\n\t\t\\Symbol{\\SymOR{(IX+d)}}\r\n\t\t\t\\FlagsORr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{3}\r\n\t\t\t\\Cycles{5}{19}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{10}{110}{110}\r\n\t\t\t\\Hex{B6}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{d}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\t\t\t\r\n\t\\begin{instruction}{OR (IY+d)}\r\n\t\t\\Symbol{\\SymOR{(IY+d)}}\r\n\t\t\t\\FlagsORr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{3}\r\n\t\t\t\\Cycles{5}{19}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{10}{110}{110}\r\n\t\t\t\\Hex{B6}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{d}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\EmptySeparator\r\n\r\n\t%-------------------------------------------\r\n\r\n\t\\begin{instruction}{OTDR} \r\n\t\t\\Symbol{\\SymOTDR[0]}\r\n\t\t\t\\FlagsOTDR\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\t\\Comment{if {\\tt B}=0}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymOTDR[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{111}{011}\r\n\t\t\t\\Hex{BB}{}\r\n\t\t\t\\Cycles{5}{21}\r\n\t\t\t\\Comment{if {\\tt B}$\\neq$0}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{OTIR} \r\n\t\t\\Symbol{\\SymOTIR[0]}\r\n\t\t\t\\FlagsOTIR\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\t\\Comment{if {\\tt B}=0}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymOTIR[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{110}{011}\r\n\t\t\t\\Hex{B3}{}\r\n\t\t\t\\Cycles{5}{21}\r\n\t\t\t\\Comment{if {\\tt B}$\\neq$0}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{OUT (n),A} \r\n\t\t\\Symbol{\\SymOUT{n}{A}}\r\n\t\t\t\\FlagsOUTna\r\n\t\t\t\\OpCode{11}{010}{011}\r\n\t\t\t\\Hex{D3}{2}\r\n\t\t\t\\Cycles{3}{11}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{n} \r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{OUT (C),r} \r\n\t\t\\Symbol{\\SymOUT{BC}{r}}\r\n\t\t\t\\FlagsOUTcr\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{3}{12}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{01}{\\OCT{r}}{001}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{OUT (C),0} \r\n\t\t\\Symbol{\\SymOUT{BC}{0}}\r\n\t\t\t\\FlagsOUTc\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{3}{12}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{01}{110}{001}\r\n\t\t\t\\Hex{71}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{OUTD} \r\n\t\t\\Symbol{\\SymOUTD[0]}\r\n\t\t\t\\FlagsOUTI\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymOUTD[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{101}{011}\r\n\t\t\t\\Hex{AB}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymOUTD[2]}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{OUTI} \r\n\t\t\\Symbol{\\SymOUTI[0]}\r\n\t\t\t\\FlagsOUTI\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymOUTI[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{100}{011}\r\n\t\t\t\\Hex{A3}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymOUTI[2]}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{OUTINB\\ZXNS} \r\n\t\t\\Symbol{\\SymOUTINB[0]}\r\n\t\t\t\\FlagsOUTINB\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymOUTINB[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{010}{000}\r\n\t\t\t\\Hex{90}{}\r\n\t\\end{instruction}\r\n\t\r\n\\end{instrtablesimple}\r\n\t\r\n\\begin{instrtablesimple}\r\n\t\r\n\t\\begin{instruction}{PIXELAD\\ZXNS} \r\n\t\t\\SymbolS{\\SymPIXELAD[0]}\r\n\t\t\t\\FlagsPIXELAD\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{3}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\SymbolP{\\SymPIXELAD[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{010}{100}\r\n\t\t\t\\Hex{94}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\SymbolP{\\SymPIXELAD[2]}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\SymbolP{\\SymPIXELAD[3]}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\SymbolP{\\SymPIXELAD[4]}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{PIXELDN\\ZXNS} \r\n\t\t\\Symbol{\\SymPIXELDN[0]}\r\n\t\t\t\\FlagsPIXELDN\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{3}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPIXELDN[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{010}{011}\r\n\t\t\t\\Hex{93}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPIXELDN[2]}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPIXELDN[3]}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPIXELDN[4]}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPIXELDN[5]}\r\n\t\\end{instruction}\r\n\r\n\t\\EmptySeparator\r\n\r\n\t%-------------------------------------------\r\n\r\n\t\\begin{instruction}{POP rr} \r\n\t\t\\Symbol{\\SymPOP[0]{rr}}\r\n\t\t\t\\FlagsPOPrr\r\n\t\t\t\\OpCode{11}{\\OCT{rr}0}{001}\r\n\t\t\t\\Hex{..}{1}\r\n\t\t\t\\Cycles{3}{10}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPOP[1]{rr}}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPOP[2]{rr}}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{POP AF} \r\n\t\t\\Symbol{\\SymPOP[10]{A}}\r\n\t\t\t\\FlagsPOPaf\r\n\t\t\t\\OpCode{11}{110}{001}\r\n\t\t\t\\Hex{F1}{1}\r\n\t\t\t\\Cycles{3}{10}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPOP[11]{F}}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPOP[12]{}}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{POP IX} \r\n\t\t\\Symbol{\\SymPOP[0]{IX}}\r\n\t\t\t\\FlagsPOPrr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{2}\r\n\t\t\t\\Cycles{4}{14}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPOP[1]{IX}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{11}{100}{001}\r\n\t\t\t\\Hex{E1}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPOP[2]{IX}}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{POP IY}\r\n\t\t\\Symbol{\\SymPOP[0]{IY}}\r\n\t\t\t\\FlagsPOPrr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{2}\r\n\t\t\t\\Cycles{4}{14}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPOP[1]{IY}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{11}{100}{001}\r\n\t\t\t\\Hex{E1}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPOP[2]{IY}}\r\n\t\\end{instruction}\r\n\r\n\t\\EmptySeparator\r\n\r\n\t%-------------------------------------------\r\n\r\n\t\\begin{instruction}{PUSH rr} \r\n\t\t\\Symbol{\\SymPUSH[0]{rr}}\r\n\t\t\t\\FlagsPUSHrr\r\n\t\t\t\\OpCode{11}{\\OCT{rr}0}{101}\r\n\t\t\t\\Hex{..}{1}\r\n\t\t\t\\Cycles{3}{11}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPUSH[1]{rr}}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPUSH[2]{rr}}\r\n\t\\end{instruction}\r\n\t\t\r\n\t\\begin{instruction}{PUSH IX} \r\n\t\t\\Symbol{\\SymPUSH[0]{IX}}\r\n\t\t\t\\FlagsPUSHrr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{2}\r\n\t\t\t\\Cycles{4}{15}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPUSH[1]{IX}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{11}{100}{101}\r\n\t\t\t\\Hex{E5}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPUSH[2]{IX}}\r\n\t\\end{instruction}\r\n\t\t\r\n\t\\begin{instruction}{PUSH IY} \r\n\t\t\\Symbol{\\SymPUSH[0]{IY}}\r\n\t\t\t\\FlagsPUSHrr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{2}\r\n\t\t\t\\Cycles{4}{15}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPUSH[1]{IY}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{11}{100}{101}\r\n\t\t\t\\Hex{E5}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPUSH[2]{IY}}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{PUSH nm\\ZXNS}\r\n\t\t\\Symbol{\\SymPUSHnn[0]{n}{m}}\r\n\t\t\t\\FlagsPUSHnn\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{3}\r\n\t\t\t\\Cycles{6}{23}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPUSHnn[1]{n}{m}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{001}{010}\r\n\t\t\t\\Hex{8A}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPUSHnn[2]{n}{m}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpRange{n} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{m} \r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\EmptySeparator\r\n\t\r\n\t%-------------------------------------------\r\n\r\n\t\\begin{instruction}{RES b,r} \r\n\t\t\\Symbol{\\SymRES{r}}\r\n\t\t\t\\FlagsRESr\r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{10}{\\OCT{b}}{\\OCT{r}}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{RES b,(HL)} \r\n\t\t\\Symbol{\\SymRES{(HL)}}\r\n\t\t\t\\FlagsRESr\r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{2}\r\n\t\t\t\\Cycles{4}{15}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{10}{\\OCT{b}}{110}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{RES b,(IX+d)} \r\n\t\t\\Symbol{\\SymRES{(IX+d)}}\r\n\t\t\t\\FlagsRESr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{4}\r\n\t\t\t\\Cycles{6}{23}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{d} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{10}{\\OCT{b}}{110}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{lastinstruction}{RES b,(IY+d)} \r\n\t\t\\Symbol{\\SymRES{(IY+d)}}\r\n\t\t\t\\FlagsRESr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{4}\r\n\t\t\t\\Cycles{6}{23}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{d} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{10}{\\OCT{b}}{110}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{lastinstruction}\r\n\t\r\n\\end{instrtablesimple}\r\n\r\n\\vspace*{-4.4ex} % previous table pushes this one too far down, so we manually move it up\r\n\\begin{instrtablesimple}\r\n\t\r\n\t\\begin{instruction}{RET} \r\n\t\t\\Symbol{\\SymRET[0]}\r\n\t\t\t\\FlagsRET\r\n\t\t\t\\OpCode{11}{001}{001}\r\n\t\t\t\\Hex{C9}{1}\r\n\t\t\t\\Cycles{3}{10}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymRET[1]}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymRET[2]}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{RET c} \r\n\t\t\\Symbol{\\SymRETc{c}}\r\n\t\t\t\\FlagsRETcc\r\n\t\t\t\\OpCode{11}{\\OCT{c}}{000}\r\n\t\t\t\\Hex{..}{1}\r\n\t\t\t\\Cycles{1}{5}\r\n\t\t\t\\Comment{if {\\tt c}=false}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{}{}{}\r\n\t\t\t\\Hex{}{}\r\n\t\t\t\\Cycles{3}{11}\r\n\t\t\t\\Comment{if {\\tt c}=true}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{RETI} \r\n\t\t\\Symbol{\\SymRETI[0]}\r\n\t\t\t\\FlagsRETI\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{14}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymRETI[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{01}{001}{101}\r\n\t\t\t\\Hex{4D}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymRETI[2]}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{RETN} \r\n\t\t\\Symbol{\\SymRETN[0]}\r\n\t\t\t\\FlagsRETN\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{14}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymRETN[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{01}{000}{101}\r\n\t\t\t\\Hex{45}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymRETN[2]}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymRETN[3]}\r\n\t\\end{instruction}\r\n\r\n\t\\EmptySeparator\r\n\r\n\t%-------------------------------------------\r\n\r\n\t\\begin{instruction}{RL r}\r\n\t\t\\Symbol{\\SymRL[0]{r}}\r\n\t\t\t\\FlagsRLr\r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{010}{\\OCT{r}}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{RL (HL)}\r\n\t\t\\Symbol{\\SymRL[0]{(HL)}}\r\n\t\t\t\\FlagsRLr\r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{2}\r\n\t\t\t\\Cycles{4}{15}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{010}{110}\r\n\t\t\t\\Hex{16}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{RL (IX+d)}\r\n\t\t\\Symbol{\\SymRL[0]{(IX+d)}}\r\n\t\t\t\\FlagsRLr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{4}\r\n\t\t\t\\Cycles{6}{23}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{d} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{010}{110}\r\n\t\t\t\\Hex{16}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{RL (IY+d)}\r\n\t\t\\Symbol{\\SymRL[0]{(IY+d)}}\r\n\t\t\t\\FlagsRLr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{4}\r\n\t\t\t\\Cycles{6}{23}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{d} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{010}{110}\r\n\t\t\t\\Hex{16}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{RLA}\r\n\t\t\\Symbol{\\SymRL[0]{A}}\r\n\t\t\t\\FlagsRLA\r\n\t\t\t\\OpCode{00}{010}{111}\r\n\t\t\t\\Hex{17}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\\end{instruction}\r\n\r\n\t\\EmptySeparator\r\n\t\r\n\t%-------------------------------------------\r\n\r\n\t\\begin{instruction}{RLC r}\r\n\t\t\\Symbol{\\SymRLC[0]{r}}\r\n\t\t\t\\FlagsRLCr\r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{000}{\\OCT{r}}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{RLC (HL)}\r\n\t\t\\Symbol{\\SymRLC[0]{(HL)}}\r\n\t\t\t\\FlagsRLCr\r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{2}\r\n\t\t\t\\Cycles{4}{15}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{000}{110}\r\n\t\t\t\\Hex{06}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{RLC (IX+d)}\r\n\t\t\\Symbol{\\SymRLC[0]{(IX+d)}}\r\n\t\t\t\\FlagsRLCr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{4}\r\n\t\t\t\\Cycles{6}{23}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{d} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{000}{110}\r\n\t\t\t\\Hex{06}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{RLC (IY+d)}\r\n\t\t\\Symbol{\\SymRLC[0]{(IY+d)}}\r\n\t\t\t\\FlagsRLCr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{4}\r\n\t\t\t\\Cycles{6}{23}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{d} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{000}{110}\r\n\t\t\t\\Hex{06}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{RLCA}\r\n\t\t\\Symbol{\\SymRLC[0]{A}}\r\n\t\t\t\\FlagsRLCA\r\n\t\t\t\\OpCode{00}{000}{111}\r\n\t\t\t\\Hex{07}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\\end{instruction}\r\n\r\n\t\\EmptySeparator\r\n\r\n\t%-------------------------------------------\r\n\r\n\t\\begin{instruction}{RLD}\r\n\t\t\\Symbol{\\vspace*{-12pt}\\hspace*{-0.8cm}\\SymRLD}\r\n\t\t\t\\FlagsRLD \r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{5}{18}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{01}{101}{111}\r\n\t\t\t\\Hex{6F}{}\r\n\t\t\t\\Cycles{}{}\r\n\t\\end{instruction}\r\n\t\t\t\r\n\t\\begin{lastinstruction}{RRD}\r\n\t\t\\Symbol{\\vspace*{-12pt}\\hspace*{-0.8cm}\\SymRRD}\r\n\t\t\t\\FlagsRRD\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{5}{18}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{01}{100}{111}\r\n\t\t\t\\Hex{67}{}\r\n\t\\end{lastinstruction}\r\n\r\n\t\\EmptySeparator\r\n\r\n\\end{instrtablesimple}\r\n\r\n\\begin{instrtablesimple}\r\n\r\n\t% we need slightly more vertical space to accomodate symbolic operation drawing for RR; it's negative because we only need a fraction of what new line produces\r\n\t\\\\[-10pt]\r\n\r\n\t\\begin{instruction}{RR r}\r\n\t\t\\Symbol{\\SymRR[0]{r}}\r\n\t\t\t\\FlagsRRr\r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{011}{\\OCT{r}}\r\n\t\t\t\\Hex{..}{}\r\n\t\t\t\\Cycles{}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{RR (HL)}\r\n\t\t\\Symbol{\\SymRR[0]{(HL)}}\r\n\t\t\t\\FlagsRRr\r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{2}\r\n\t\t\t\\Cycles{4}{15}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{011}{110}\r\n\t\t\t\\Hex{1E}{}\r\n\t\t\t\\Cycles{}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{RR (IX+d)}\r\n\t\t\\Symbol{\\SymRR[0]{(IX+d)}}\r\n\t\t\t\\FlagsRRr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{4}\r\n\t\t\t\\Cycles{6}{23}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{d} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{011}{110}\r\n\t\t\t\\Hex{1E}{}\r\n\t\t\t\\Cycles{}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{RR (IY+d)}\r\n\t\t\\Symbol{\\SymRR[0]{(IY+d)}}\r\n\t\t\t\\FlagsRRr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{4}\r\n\t\t\t\\Cycles{6}{23}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{d} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{011}{110}\r\n\t\t\t\\Hex{1E}{}\r\n\t\t\t\\Cycles{}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{RRA}\r\n\t\t\\Symbol{\\SymRR[0]{A}}\r\n\t\t\t\\FlagsRRA\r\n\t\t\t\\OpCode{00}{011}{111}\r\n\t\t\t\\Hex{1F}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\\end{instruction}\r\n\r\n\t\\EmptySeparator\r\n\r\n\t%-------------------------------------------\r\n\t\r\n\t\\begin{instruction}{RRC r}\r\n\t\t\\Symbol{\\SymRRC[0]{r}}\r\n\t\t\t\\FlagsRRCr\r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{001}{\\OCT{r}}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{RRC (HL)}\r\n\t\t\\Symbol{\\SymRRC[0]{(HL)}}\r\n\t\t\t\\FlagsRRCr\r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{2}\r\n\t\t\t\\Cycles{4}{15}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{001}{110}\r\n\t\t\t\\Hex{0E}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{RRC (IX+d)}\r\n\t\t\\Symbol{\\SymRRC[0]{(IX+d)}}\r\n\t\t\t\\FlagsRRCr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{4}\r\n\t\t\t\\Cycles{6}{23}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{d} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{001}{110}\r\n\t\t\t\\Hex{0E}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{RRC (IY+d)}\r\n\t\t\\Symbol{\\SymRRC[0]{(IY+d)}}\r\n\t\t\t\\FlagsRRCr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{4}\r\n\t\t\t\\Cycles{6}{23}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{d} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{001}{110}\r\n\t\t\t\\Hex{0E}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{RRCA}\r\n\t\t\\Symbol{\\SymRRC[0]{A}}\r\n\t\t\t\\FlagsRRCA\r\n\t\t\t\\OpCode{00}{001}{111}\r\n\t\t\t\\Hex{0F}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\\end{instruction}\r\n\r\n\t\\EmptySeparator\r\n\t\r\n\t%-------------------------------------------\r\n\r\n\t\\begin{instruction}{RST n} \r\n\t\t\\Symbol{\\SymRST[0]{n}}\r\n\t\t\t\\FlagsRSTn\r\n\t\t\t\\OpCode{11}{\\OCT{n}}{111}\r\n\t\t\t\\Hex{..}{1}\r\n\t\t\t\\Cycles{3}{11}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymRST[1]{n}}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymRST[2]{n}}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymRST[3]{n}}\r\n\t\\end{instruction}\r\n\r\n\t\\EmptySeparator\r\n\r\n\t%-------------------------------------------\r\n\r\n\t\\begin{instruction}{SBC A,r}\r\n\t\t\\Symbol{\\SymSBC{A}{r}}\r\n\t\t\t\\FlagsSBCr\r\n\t\t\t\\OpCode{10}{011}{\\OCT{r}}\r\n\t\t\t\\Hex{..}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{SBC A,n}\r\n\t\t\\Symbol{\\SymSBC{A}{n}}\r\n\t\t\t\\FlagsSBCr\r\n\t\t\t\\OpCode{11}{011}{110}\r\n\t\t\t\\Hex{DE}{2}\r\n\t\t\t\\Cycles{2}{7}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{n}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\t\r\n\t\\begin{instruction}{SBC A,(HL)}\r\n\t\t\\Symbol{\\SymSBC{A}{(HL)}}\r\n\t\t\t\\FlagsSBCr\r\n\t\t\t\\OpCode{10}{011}{110}\r\n\t\t\t\\Hex{9E}{1} \r\n\t\t\t\\Cycles{2}{7}\r\n\t\\end{instruction}\r\n\t\t\r\n\t\\begin{instruction}{SBC A,(IX+d)}\r\n\t\t\\Symbol{\\SymSBC{A}{(IX+d)}}\r\n\t\t\t\\FlagsSBCr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{3}\r\n\t\t\t\\Cycles{5}{19}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{10}{011}{110}\r\n\t\t\t\\Hex{9E}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{d}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\t\t\r\n\t\\begin{instruction}{SBC A,(IY+d)}\r\n\t\t\\Symbol{\\SymSBC{A}{(IY+d)}}\r\n\t\t\t\\FlagsSBCr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{3}\r\n\t\t\t\\Cycles{5}{19}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{10}{011}{110}\r\n\t\t\t\\Hex{9E}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{d}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{SBC HL,rr} \r\n\t\t\\Symbol{\\SymSBC{HL}{rr}}\r\n\t\t\t\\FlagsSBCrr\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{15}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{01}{\\OCT{rr}0}{010}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\EmptySeparator\r\n\t\r\n\t%-------------------------------------------\r\n\r\n\t\\begin{instruction}{SCF} \r\n\t\t\\Symbol{\\SymSCF}\r\n\t\t\t\\FlagsSCF\r\n\t\t\t\\OpCode{00}{110}{111}\r\n\t\t\t\\Hex{37}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\\end{instruction}\r\n\r\n\t%-------------------------------------------\r\n\r\n\\end{instrtablesimple}\r\n\r\n\\begin{instrtablesimple}\r\n\r\n\t\\begin{instruction}{SET b,r} \r\n\t\t\\Symbol{\\SymSET{r}}\r\n\t\t\t\\FlagsSETr\r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{11}{\\OCT{b}}{\\OCT{r}}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{SET b,(HL)} \r\n\t\t\\Symbol{\\SymSET{(HL)}}\r\n\t\t\t\\FlagsSETr\r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{2}\r\n\t\t\t\\Cycles{4}{15}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{11}{\\OCT{b}}{110}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{SET b,(IX+d)} \r\n\t\t\\Symbol{\\SymSET{(IX+d)}}\r\n\t\t\t\\FlagsSETr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{4}\r\n\t\t\t\\Cycles{6}{23}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{d} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{11}{\\OCT{b}}{110}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{SET b,(IY+d)} \r\n\t\t\\Symbol{\\SymSET{(IY+d)}}\r\n\t\t\t\\FlagsSETr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{4}\r\n\t\t\t\\Cycles{6}{23}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{d} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{11}{\\OCT{b}}{110}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\EmptySeparator\t\r\n\r\n\t%-------------------------------------------\r\n\r\n\t\\begin{instruction}{SETAE} \r\n\t\t\\Symbol{\\SymSETAE}\r\n\t\t\t\\FlagsSETAE\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{3}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{10}{010}{101}\r\n\t\t\t\\Hex{95}{}\r\n\t\\end{instruction}\r\n\r\n\t\\EmptySeparator\r\n\t\r\n\t%-------------------------------------------\r\n\t\r\n\t\\begin{instruction}{SLA r}\r\n\t\t\\Symbol{\\SymSLA[0]{r}}\r\n\t\t\t\\FlagsSLAr\r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{100}{\\OCT{r}}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\t\r\n\t\\begin{instruction}{SLA (HL)}\r\n\t\t\\Symbol{\\SymSLA[0]{(HL)}}\r\n\t\t\t\\FlagsSLAr\r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{2}\r\n\t\t\t\\Cycles{4}{15}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{100}{110}\r\n\t\t\t\\Hex{26}{}\r\n\t\\end{instruction}\r\n\t\t\r\n\t\\begin{instruction}{SLA (IX+d)}\r\n\t\t\\Symbol{\\SymSLA[0]{(IX+d)}}\r\n\t\t\t\\FlagsSLAr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{4}\r\n\t\t\t\\Cycles{6}{23}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{d} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{100}{110}\r\n\t\t\t\\Hex{26}{}\r\n\t\\end{instruction}\r\n\t\t\r\n\t\\begin{instruction}{SLA (IY+d)}\r\n\t\t\\Symbol{\\SymSLA[0]{(IY+d)}}\r\n\t\t\t\\FlagsSLAr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{4}\r\n\t\t\t\\Cycles{6}{23}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{d} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{100}{110}\r\n\t\t\t\\Hex{26}{}\t\r\n\t\\end{instruction}\r\n\r\n\t\\EmptySeparator\r\n\t\t\r\n\t%-------------------------------------------\r\n\t\r\n\t\\begin{instruction}{SLI r}\r\n\t\t\\Symbol{\\SymSLI[0]{r}}\r\n\t\t\t\\FlagsSLIr\r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{110}{\\OCT{r}}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\t\t\r\n\t\\begin{instruction}{SLI (HL)\\UNDOC}\r\n\t\t\\Symbol{\\SymSLI[0]{(HL)}}\r\n\t\t\t\\FlagsSLIr\r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{2}\r\n\t\t\t\\Cycles{4}{15}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{110}{110}\r\n\t\t\t\\Hex{36}{}\r\n\t\\end{instruction}\r\n\t\t\t\r\n\t\\begin{instruction}{SLI (IX+d)\\UNDOC}\r\n\t\t\\Symbol{\\SymSLI[0]{(IX+d)}}\r\n\t\t\t\\FlagsSLIr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{4}\r\n\t\t\t\\Cycles{6}{23}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{d} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{110}{110}\r\n\t\t\t\\Hex{36}{}\r\n\t\\end{instruction}\r\n\t\t\t\r\n\t\\begin{instruction}{SLI (IY+d)\\UNDOC}\r\n\t\t\\Symbol{\\SymSLI[0]{(IY+d)}}\r\n\t\t\t\\FlagsSLIr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{4}\r\n\t\t\t\\Cycles{6}{23}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{d} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{110}{110}\r\n\t\t\t\\Hex{36}{}\r\n\t\\end{instruction}\r\n\r\n\t\\EmptySeparator\r\n\t\r\n\\end{instrtablesimple}\r\n\r\n\\begin{instrtablesimple}\r\n\r\n\t% we need slightly more vertical space to accomodate symbolic operation drawing for SRA; it's negative because we only need a fraction of what new line produces\r\n\t\\\\[-10pt]\r\n\t\r\n\t\\begin{instruction}{SRA r}\r\n\t\t\\Symbol{\\SymSRA[0]{r}}\r\n\t\t\t\\FlagsSRAr\r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{101}{\\OCT{r}}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\t\t\r\n\t\\begin{instruction}{SRA (HL)}\r\n\t\t\\Symbol{\\SymSRA[0]{(HL)}}\r\n\t\t\t\\FlagsSRAr\r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{2}\r\n\t\t\t\\Cycles{4}{15}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{00}{101}{110}\r\n\t\t\t\\Hex{2E}{}\r\n\t\\end{instruction}\r\n\t\t\t\r\n\t\\begin{instruction}{SRA (IX+d)}\r\n\t\t\\Symbol{\\SymSRA[0]{(IX+d)}}\r\n\t\t\t\\FlagsSRAr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{4}\r\n\t\t\t\\Cycles{6}{23}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{d} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{00}{101}{110}\r\n\t\t\t\\Hex{2E}{}\r\n\t\\end{instruction}\r\n\t\t\t\r\n\t\\begin{instruction}{SRA (IY+d)}\r\n\t\t\\Symbol{\\SymSRA[0]{(IY+d)}}\r\n\t\t\t\\FlagsSRAr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{4}\r\n\t\t\t\\Cycles{6}{23}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{d} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{00}{101}{110}\r\n\t\t\t\\Hex{2E}{}\r\n\t\\end{instruction}\r\n\r\n\t\\EmptySeparator\r\n\t\t\t\r\n\t%-------------------------------------------\r\n\t\r\n\t\\begin{instruction}{SRL r}\r\n\t\t\\Symbol{\\SymSRL[0]{r}}\r\n\t\t\t\\FlagsSRLr\r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{111}{\\OCT{r}}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\t\t\t\r\n\t\\begin{instruction}{SRL (HL)}\r\n\t\t\\Symbol{\\SymSRL[0]{(HL)}}\r\n\t\t\t\\FlagsSRLr\r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{2}\r\n\t\t\t\\Cycles{4}{15}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{00}{111}{110}\r\n\t\t\t\\Hex{3E}{}\r\n\t\\end{instruction}\r\n\t\t\t\t\r\n\t\\begin{instruction}{SRL (IX+d)}\r\n\t\t\\Symbol{\\SymSRL[0]{(IX+d)}}\r\n\t\t\t\\FlagsSRLr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{4}\r\n\t\t\t\\Cycles{6}{23}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{d} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{00}{111}{110}\r\n\t\t\t\\Hex{3E}{}\r\n\t\\end{instruction}\r\n\t\t\t\t\r\n\t\\begin{instruction}{SRL (IY+d)}\r\n\t\t\\Symbol{\\SymSRL[0]{(IY+d)}}\r\n\t\t\t\\FlagsSRLr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{4}\r\n\t\t\t\\Cycles{6}{23}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{d} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{00}{111}{110}\r\n\t\t\t\\Hex{3E}{}\r\n\t\\end{instruction}\r\n\r\n\t\\EmptySeparator\r\n\t\t\t\t\r\n\t%-------------------------------------------\r\n\r\n\t\\begin{instruction}{SUB r}\r\n\t\t\\Symbol{\\SymSUB{r}}\r\n\t\t\t\\FlagsSUBr\r\n\t\t\t\\OpCode{10}{010}{\\OCT{r}}\r\n\t\t\t\\Hex{..}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\\end{instruction}\r\n\t\t\r\n\t\\begin{instruction}{SUB n}\r\n\t\t\\Symbol{\\SymSUB{n}}\r\n\t\t\t\\FlagsSUBr\r\n\t\t\t\\OpCode{11}{010}{110}\r\n\t\t\t\\Hex{D6}{2}\r\n\t\t\t\\Cycles{2}{7}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{n}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\t\t\r\n\t\\begin{instruction}{SUB (HL)}\r\n\t\t\\Symbol{\\SymSUB{(HL)}}\r\n\t\t\t\\FlagsSUBr\r\n\t\t\t\\OpCode{10}{010}{110}\r\n\t\t\t\\Hex{96}{1}\r\n\t\t\t\\Cycles{2}{7}\r\n\t\\end{instruction}\r\n\t\t\t\r\n\t\\begin{instruction}{SUB (IX+d)}\r\n\t\t\\Symbol{\\SymSUB{(IX+d)}}\r\n\t\t\t\\FlagsSUBr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{3}\r\n\t\t\t\\Cycles{5}{19}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{10}{010}{110}\r\n\t\t\t\\Hex{96}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{d}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\t\t\t\r\n\t\\begin{instruction}{SUB (IY+d)}\r\n\t\t\\Symbol{\\SymSUB{(IY+d)}}\r\n\t\t\t\\FlagsSUBr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{3}\r\n\t\t\t\\Cycles{5}{19}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{10}{010}{110}\r\n\t\t\t\\Hex{96}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{d}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\EmptySeparator\r\n\t\t\r\n\t%-------------------------------------------\r\n\r\n\t\\begin{instruction}{SWAPNIB}\r\n\t\t\\Symbol{\\multirow[b]{1}{*}{\\SymSWAPNIB[0]}}\r\n\t\t\t\\FlagsSWAPNIB\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{100}{011}\r\n\t\t\t\\Hex{23}{}\r\n\t\t\t\\Cycles{}{}\r\n\t\\end{instruction}\r\n\r\n\t\\EmptySeparator\r\n\t\r\n\t%-------------------------------------------\r\n\r\n\t\\begin{instruction}{TEST n} \r\n\t\t\\Symbol{\\SymTEST}\r\n\t\t\t\\FlagsTESTn\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{3}\r\n\t\t\t\\Cycles{3}{11}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{100}{111}\r\n\t\t\t\\Hex{27}{}\r\n\t\t\t\\Cycles{}{}\r\n\t\\end{instruction}\r\n\r\n\t\\EmptySeparator\r\n\t\r\n\\end{instrtablesimple}\r\n\r\n\\begin{instrtablesimple}\r\n\r\n\t\\begin{instruction}{XOR r}\r\n\t\t\\Symbol{\\SymXOR{r}}\r\n\t\t\t\\FlagsXORr\r\n\t\t\t\\OpCode{10}{101}{\\OCT{r}}\r\n\t\t\t\\Hex{..}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\\end{instruction}\r\n\t\t\t\r\n\t\\begin{instruction}{XOR n}\r\n\t\t\\Symbol{\\SymXOR{n}}\r\n\t\t\t\\FlagsXORr\r\n\t\t\t\\OpCode{11}{101}{110}\r\n\t\t\t\\Hex{EE}{2}\r\n\t\t\t\\Cycles{2}{7}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{n}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\t\t\t\r\n\t\\begin{instruction}{XOR (HL)}\r\n\t\t\\Symbol{\\SymXOR{(HL)}}\r\n\t\t\t\\FlagsXORr\r\n\t\t\t\\OpCode{10}{101}{110}\r\n\t\t\t\\Hex{AE}{1}\r\n\t\t\t\\Cycles{2}{7}\r\n\t\\end{instruction}\r\n\t\t\t\t\r\n\t\\begin{instruction}{XOR (IX+d)}\r\n\t\t\\Symbol{\\SymXOR{(IX+d)}}\r\n\t\t\t\\FlagsXORr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{3}\r\n\t\t\t\\Cycles{5}{19}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{10}{101}{110}\r\n\t\t\t\\Hex{AE}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{d}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\t\t\t\t\r\n\t\\begin{instruction}{XOR (IY+d)}\r\n\t\t\\Symbol{\\SymXOR{(IY+d)}}\r\n\t\t\t\\FlagsXORr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{3}\r\n\t\t\t\\Cycles{5}{19}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{10}{101}{110}\r\n\t\t\t\\Hex{AE}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{d}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\EmptySeparator\r\n\t\r\n\\end{instrtablesimple}\r\n\r\n\\fi\r\n"
  },
  {
    "path": "chapter-instr-glance-bit.tex",
    "content": "\\section{Bit Set, Reset and Test}\r\n\r\n\\begin{minipage}{\\textwidth}\r\n\r\n\\begin{instrtable}\r\n\r\n\t\\begin{instruction}{BIT b,r} \r\n\t\t\\Symbol{\\SymBIT{r}}\r\n\t\t\t\\FlagsBITr\r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\t\\Comment{\r\n\t\t\t\t\\multirow{6}{*}{\r\n\t\t\t\t\t\\tt\r\n\t\t\t\t\t\\begin{tabular}{ll}\r\n\t\t\t\t\t\tr & \\OCT{r} \\\\\r\n\t\t\t\t\t\t\\hline\r\n\t\t\t\t\t\tB & 000 \\\\\r\n\t\t\t\t\t\tC & 001 \\\\\r\n\t\t\t\t\t\tD & 010 \\\\\r\n\t\t\t\t\t\tE & 011 \\\\\r\n\t\t\t\t\t\tH & 100 \\\\\r\n\t\t\t\t\t\tL & 101 \\\\\r\n\t\t\t\t\t\tA & 111 \\\\\r\n\t\t\t\t\t\\end{tabular}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{01}{\\OCT{b}}{\\OCT{r}}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{BIT b,(HL)} \r\n\t\t\\Symbol{\\SymBIT{(HL)}}\r\n\t\t\t\\FlagsBITr\r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{2}\r\n\t\t\t\\Cycles{3}{12}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{01}{\\OCT{b}}{110}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{BIT b,(IX+d)\\See{2}} \r\n\t\t\\Symbol{\\SymBIT{(IX+d)}}\r\n\t\t\t\\FlagsBITr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{4}\r\n\t\t\t\\Cycles{5}{20}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{d}\r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{01}{\\OCT{b}}{110}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{BIT b,(IY+d)\\See{2}} \r\n\t\t\\Symbol{\\SymBIT{(IY+d)}}\r\n\t\t\t\\FlagsBITr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{4}\r\n\t\t\t\\Cycles{5}{20}\r\n\t\t\t\\Comment{\r\n\t\t\t\t\\multirow{7}{*}{\r\n\t\t\t\t\t\\tt\r\n\t\t\t\t\t\\begin{tabular}{ll}\r\n\t\t\t\t\t\tb & \\OCT{b} \\\\\r\n\t\t\t\t\t\t\\hline\r\n\t\t\t\t\t\t0 & 000 \\\\\r\n\t\t\t\t\t\t1 & 001 \\\\\r\n\t\t\t\t\t\t2 & 010 \\\\\r\n\t\t\t\t\t\t3 & 011 \\\\\r\n\t\t\t\t\t\t4 & 100 \\\\\r\n\t\t\t\t\t\t5 & 101 \\\\\r\n\t\t\t\t\t\t6 & 110 \\\\\r\n\t\t\t\t\t\t7 & 111 \\\\\r\n\t\t\t\t\t\\end{tabular}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{d} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{01}{\\OCT{b}}{110}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{SET b,r} \r\n\t\t\\Symbol{\\SymSET{r}}\r\n\t\t\t\\FlagsSETr\r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{\\fbox{11}}{\\OCT{b}}{\\OCT{r}}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{SET b,(HL)} \r\n\t\t\\Symbol{\\SymSET{(HL)}}\r\n\t\t\t\\FlagsSETr\r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{2}\r\n\t\t\t\\Cycles{4}{15}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{\\fbox{11}}{\\OCT{b}}{110}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{SET b,(IX+d)} \r\n\t\t\\Symbol{\\SymSET{(IX+d)}}\r\n\t\t\t\\FlagsSETr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{4}\r\n\t\t\t\\Cycles{6}{23}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{d} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{\\fbox{11}}{\\OCT{b}}{110}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{SET b,(IY+d)} \r\n\t\t\\Symbol{\\SymSET{(IY+d)}}\r\n\t\t\t\\FlagsSETr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{4}\r\n\t\t\t\\Cycles{6}{23}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{d} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{\\fbox{11}}{\\OCT{b}}{110}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{SET b,(IX+d),r} \r\n\t\t\\Symbol{\\SymSETu[0]{r}{IX}}\r\n\t\t\t\\FlagsSETr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{4}\r\n\t\t\t\\Cycles{6}{23}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymSETu[1]{r}{IX}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymSETu[2]{r}{IX}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpRange{d} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{\\fbox{11}}{\\OCT{b}}{\\OCT{r}}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{SET b,(IY+d),r} \r\n\t\t\\Symbol{\\SymSETu[0]{r}{IY}}\r\n\t\t\t\\FlagsSETr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{4}\r\n\t\t\t\\Cycles{6}{23}\r\n\t\t\\SkipToSymbol \r\n\t\t\t\\Symbol{\\SymSETu[1]{r}{IY}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymSETu[2]{r}{IY}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpRange{d} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{\\fbox{11}}{\\OCT{b}}{\\OCT{r}}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\StartWithOpCode\\OpCode{$\\uparrow$}{}{} \\\\\r\n\r\n\t\\begin{lastinstruction}{RES b,m\\See{3}} \r\n\t\t\\Symbol{\\SymRES{m}}\r\n\t\t\t\\FlagsRESr\r\n\t\t\t\\OpCode{\\fbox{10}}{...}{...}\r\n\t\\end{lastinstruction} \r\n\t\t\t\t\t\t\r\n\\end{instrtable}\r\n\r\n\\begin{notestable}\r\n\t\\NoteItem{\\See{1}See section \\XRef{z80_undocumented_flags_bit} for complete description\\noteb}\r\n\t\\NoteItem{\\See{2}Instruction has other undocumented opcodes\\noteb}\r\n\t\\NoteItem{\\See{3}{\\tt m} is one of {\\tt r}, {\\tt (HL)}, {\\tt (IX+d)}, {\\tt (IY+d)}. To form RES instruction, replace \\fbox{{\\tt 11}} with \\fbox{{\\tt 10}}. Ts also the same}\r\n\\end{notestable}\r\n\r\n\\end{minipage}"
  },
  {
    "path": "chapter-instr-glance-block.tex",
    "content": "\\section{Block Transfer, Search}\r\n\r\n\\begin{minipage}{\\textwidth}\r\n\t\r\n\\begin{instrtable}\r\n\r\n\t\\begin{instruction}{CPD} \r\n\t\t\\Symbol{\\SymCPD[0]}\r\n\t\t\t\\FlagsCPD\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymCPD[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{101}{001}\r\n\t\t\t\\Hex{A9}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymCPD[2]}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{CPDR} \r\n\t\t\\Symbol{\\SymCPDR[0]}\r\n\t\t\t\\FlagsCPDR\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\t\\Comment{if {\\tt A=(HL)}}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymCPDR[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{111}{001}\r\n\t\t\t\\Hex{B9}{}\r\n\t\t\t\\Cycles{}{}\r\n\t\t\t\\Comment{or {\\tt BC}=0}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{}{}{}\r\n\t\t\t\\Hex{}{}\r\n\t\t\t\\Cycles{5}{21}\r\n\t\t\t\\Comment{if {\\tt A}$\\neq${\\tt (HL)}}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{}{}{}\r\n\t\t\t\\Hex{}{}\r\n\t\t\t\\Cycles{}{}\r\n\t\t\t\\Comment{and {\\tt BC}$\\neq${\\tt 0}}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{CPI} \r\n\t\t\\Symbol{\\SymCPI[0]}\r\n\t\t\t\\FlagsCPI\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymCPI[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{100}{001}\r\n\t\t\t\\Hex{A1}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymCPI[2]}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{CPIR} \r\n\t\t\\Symbol{\\SymCPIR[0]}\r\n\t\t\t\\FlagsCPIR\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\t\\Comment{if {\\tt A=(HL)}}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymCPIR[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{110}{001}\r\n\t\t\t\\Hex{B1}{}\r\n\t\t\t\\Cycles{}{}\r\n\t\t\t\\Comment{or {\\tt BC}=0}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{}{}{}\r\n\t\t\t\\Hex{}{}\r\n\t\t\t\\Cycles{5}{21}\r\n\t\t\t\\Comment{if {\\tt A}$\\neq${\\tt (HL)}}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{}{}{}\r\n\t\t\t\\Hex{}{}\r\n\t\t\t\\Cycles{}{}\r\n\t\t\t\\Comment{and {\\tt BC}$\\neq$0}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LDD} \r\n\t\t\\Symbol{\\SymLDD[0]}\r\n\t\t\t\\FlagsLDD\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDD[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{101}{000}\r\n\t\t\t\\Hex{A8}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDD[2]}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDD[3]}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LDDR} \r\n\t\t\\Symbol{\\SymLDDR[0]}\r\n\t\t\t\\FlagsLDDR\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\t\\Comment{if {\\tt BC=0}}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDDR[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{111}{000}\r\n\t\t\t\\Hex{B8}{}\r\n\t\t\t\\Cycles{5}{21}\r\n\t\t\t\\Comment{if {\\tt BC$\\neq$0}}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LDI}\r\n\t\t\\Symbol{\\SymLDI[0]}\r\n\t\t\t\\FlagsLDI\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDI[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{100}{000}\r\n\t\t\t\\Hex{A0}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDI[2]}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDI[3]}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{lastinstruction}{LDIR} \r\n\t\t\\Symbol{\\SymLDIR[0]}\r\n\t\t\t\\FlagsLDIR\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\t\\Comment{if {\\tt BC=0}}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDIR[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{110}{000}\r\n\t\t\t\\Hex{B0}{}\r\n\t\t\t\\Cycles{5}{21}\r\n\t\t\t\\Comment{if {\\tt BC$\\neq$0}}\r\n\t\\end{lastinstruction}\r\n\r\n\\end{instrtable}\r\n\r\n\\begin{notestable}\r\n\t\\NoteItem{\\See{1}See section \\XRef{z80_undocumented_instructions_memory_block} for a description}\r\n\t\\NoteItem{\\See{2}ZF is {\\tt 1} if {\\tt A=(HL)}, otherwise {\\tt 0}}\r\n\t\\NoteItem{\\See{3}PV is {\\tt 1} if {\\tt BC$\\neq$0} after execution, otherwise {\\tt 0}}\r\n\t\\NoteItem{\\See{4}PV is {\\tt 0} only at the completion of the instruction}\r\n\\end{notestable}\r\n\r\n\\end{minipage}\r\n"
  },
  {
    "path": "chapter-instr-glance-call-return.tex",
    "content": "\\section{Call and Return}\r\n\r\n\\vspace*{0.7ex} % ensure this table starts at the same height as the one on the odd page\r\n\\begin{minipage}{\\textwidth}\r\n\t\r\n\\begin{instrtable}\r\n\r\n\t\\begin{instruction}{CALL nm} \r\n\t\t\\Symbol{\\SymCALL[0]{nm}}\r\n\t\t\t\\FlagsCALLnn\r\n\t\t\t\\OpCode{11}{001}{101}\r\n\t\t\t\\Hex{CD}{3}\r\n\t\t\t\\Cycles{5}{17}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymCALL[1]{nm}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpRange{m} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymCALL[2]{nm}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpRange{n} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymCALL[3]{nm}}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{CALL c,nm} \r\n\t\t\\Symbol{\\SymCALLc{nm}}\r\n\t\t\t\\FlagsCALLccnn\r\n\t\t\t\\OpCode{11}{\\OCT{c}}{100}\r\n\t\t\t\\Hex{..}{3}\r\n\t\t\t\\Cycles{3}{10}\r\n\t\t\t\\Comment{if {\\tt c}=false}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{m} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\t\\Cycles{5}{17}\r\n\t\t\t\\Comment{if {\\tt c}=true}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{n} \r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{RET} \r\n\t\t\\Symbol{\\SymRET[0]}\r\n\t\t\t\\FlagsRET\r\n\t\t\t\\OpCode{11}{001}{001}\r\n\t\t\t\\Hex{C9}{1}\r\n\t\t\t\\Cycles{3}{10}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymRET[1]}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymRET[2]}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{RET c} \r\n\t\t\\Symbol{\\SymRETc{c}}\r\n\t\t\t\\FlagsRETcc\r\n\t\t\t\\OpCode{11}{\\OCT{c}}{000}\r\n\t\t\t\\Hex{..}{1}\r\n\t\t\t\\Cycles{1}{5}\r\n\t\t\t\\Comment{if {\\tt c}=false}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{}{}{}\r\n\t\t\t\\Hex{}{}\r\n\t\t\t\\Cycles{3}{11}\r\n\t\t\t\\Comment{if {\\tt c}=true}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{RETI\\See{1}} \r\n\t\t\\Symbol{\\SymRETI[0]}\r\n\t\t\t\\FlagsRETI\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{14}\r\n\t\t\t\\Comment{\r\n\t\t\t\t\\multirow{7}{*}{\r\n\t\t\t\t\t\\tt\r\n\t\t\t\t\t\\begin{tabular}{ll}\r\n\t\t\t\t\t\tc & \\OCT{c} \\\\\r\n\t\t\t\t\t\t\\hline\r\n\t\t\t\t\t\tNZ & 000 \\\\\r\n\t\t\t\t\t\tZ & 001 \\\\\r\n\t\t\t\t\t\tNC & 010 \\\\\r\n\t\t\t\t\t\tC & 011 \\\\\r\n\t\t\t\t\t\tPO & 100 \\\\\r\n\t\t\t\t\t\tPE & 101 \\\\\r\n\t\t\t\t\t\tP & 110 \\\\\r\n\t\t\t\t\t\tM & 111 \\\\\r\n\t\t\t\t\t\\end{tabular}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymRETI[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{01}{001}{101}\r\n\t\t\t\\Hex{4D}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymRETI[2]}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{RETN\\See{2}} \r\n\t\t\\Symbol{\\SymRETN[0]}\r\n\t\t\t\\FlagsRETN\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{14}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymRETN[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{01}{000}{101}\r\n\t\t\t\\Hex{45}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymRETN[2]}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymRETN[3]}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{lastinstruction}{RST p} \r\n\t\t\\Symbol{\\SymRST[0]{p}}\r\n\t\t\t\\FlagsRSTn\r\n\t\t\t\\OpCode{11}{\\OCT{p}}{111}\r\n\t\t\t\\Hex{..}{1}\r\n\t\t\t\\Cycles{3}{11}\r\n\t\t\t\\Comment{\r\n\t\t\t\t\\multirow{7}{*}{\r\n\t\t\t\t\t\\tt\r\n\t\t\t\t\t\\begin{tabular}{ll}\r\n\t\t\t\t\t\tp & \\OCT{p} \\\\\r\n\t\t\t\t\t\t\\hline\r\n\t\t\t\t\t\t\\$0 & 000 \\\\\r\n\t\t\t\t\t\t\\$8 & 001 \\\\\r\n\t\t\t\t\t\t\\$10 & 010 \\\\\r\n\t\t\t\t\t\t\\$18 & 011 \\\\\r\n\t\t\t\t\t\t\\$20 & 100 \\\\\r\n\t\t\t\t\t\t\\$28 & 101 \\\\\r\n\t\t\t\t\t\t\\$30 & 110 \\\\\r\n\t\t\t\t\t\t\\$38 & 111 \\\\\r\n\t\t\t\t\t\\end{tabular}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymRST[1]{p}}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymRST[2]{p}}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymRST[3]{p}}\r\n\t\\end{lastinstruction}\r\n\r\n\t\\\\[7ex] % note we need to add some manual spacing after this instruction so that tt/p comment table is visible in full (we don't have enough rows for multirow command)\r\n\r\n\\end{instrtable}\r\n\r\n\\begin{notestable}\r\n\t\\NoteItem{\\See{1}{\\tt RETI} also copies {\\tt IFF2} into {\\tt IFF1}, like {\\tt RETN}}\r\n\t\\NoteItem{\\See{2}This instruction has other undocumented opcodes}\r\n\\end{notestable}\r\n\r\n\\end{minipage}"
  },
  {
    "path": "chapter-instr-glance-exchange.tex",
    "content": "\\section{Exchange}\r\n\r\n\\begin{minipage}{\\textwidth}\r\n\t\r\n\\begin{instrtable}\t\r\n\r\n\t\\begin{instruction}{EX AF,AF'} \r\n\t\t\\Symbol{\\SymEX{AF}{AF'}}\r\n\t\t\t\\FlagsEXaf\r\n\t\t\t\\OpCode{00}{001}{000}\r\n\t\t\t\\Hex{08}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{EX DE,HL} \r\n\t\t\\Symbol{\\SymEX{DE}{HL}}\r\n\t\t\t\\FlagsEXrr\r\n\t\t\t\\OpCode{11}{101}{011}\r\n\t\t\t\\Hex{EB}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{EX (SP),HL} \r\n\t\t\\Symbol{\\SymEX{H}{(SP+1)}}\r\n\t\t\t\\FlagsEXrr\r\n\t\t\t\\OpCode{11}{100}{011}\r\n\t\t\t\\Hex{E3}{1}\r\n\t\t\t\\Cycles{5}{19}\r\n\t\t\\SkipToSymbol \r\n\t\t\t\\Symbol{\\SymEX{L}{(SP)}}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{EX (SP),IX} \r\n\t\t\\Symbol{\\SymEX{IX\\High}{(SP+1)}}\r\n\t\t\t\\FlagsEXrr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{2}\r\n\t\t\t\\Cycles{6}{2}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymEX{IX\\Low}{(SP)}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{11}{100}{011}\r\n\t\t\t\\Hex{E3}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{EX (SP),IY} \r\n\t\t\\Symbol{\\SymEX{IY\\High}{(SP+1)}}\r\n\t\t\t\\FlagsEXrr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{2}\r\n\t\t\t\\Cycles{6}{23}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymEX{IY\\Low}{(SP)}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{11}{100}{011}\r\n\t\t\t\\Hex{E3}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{lastinstruction}{EXX} \r\n\t\t\\Symbol{\\SymEXX[0]}\r\n\t\t\t\\FlagsEXX\r\n\t\t\t\\OpCode{11}{011}{001}\r\n\t\t\t\\Hex{D9}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymEXX[1]}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymEXX[2]}\r\n\t\\end{lastinstruction}\r\n\t\r\n\\end{instrtable}\r\n\r\n\\NoteTableSingleItemSpaceCorrection\r\n\r\n\\begin{notestable}\r\n\t\\NoteItem{\\See{1}Flags set directly from the value of {\\tt F'}}\r\n\\end{notestable}\r\n\r\n\\end{minipage}"
  },
  {
    "path": "chapter-instr-glance-general.tex",
    "content": "\\section{General-Purpose Arithmetic and CPU Control}\r\n\r\n\\begin{minipage}{\\textwidth}\r\n\r\n\\begin{instrtable}\r\n\r\n\t\\begin{instruction}{DAA}\r\n\t\t\\Symbol{}\r\n\t\t\t\\FlagsDAA\r\n\t\t\t\\OpCode{00}{100}{111}\r\n\t\t\t\\Hex{27}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{CPL} \r\n\t\t\\Symbol{\\SymCPL}\r\n\t\t\t\\FlagsCPL\r\n\t\t\t\\OpCode{00}{101}{111}\r\n\t\t\t\\Hex{2F}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{NEG} \r\n\t\t\\Symbol{\\SymNEG}\r\n\t\t\t\\FlagsNEG\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{01}{000}{100}\r\n\t\t\t\\Hex{44}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{CCF\\See{1}} \r\n\t\t\\Symbol{\\SymCCF}\r\n\t\t\t\\FlagsCCF\r\n\t\t\t\\OpCode{00}{111}{111}\r\n\t\t\t\\Hex{3F}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{SCF\\See{1}} \r\n\t\t\\Symbol{\\SymSCF}\r\n\t\t\t\\FlagsSCF\r\n\t\t\t\\OpCode{00}{110}{111}\r\n\t\t\t\\Hex{37}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{NOP}\r\n\t\t\\Symbol{}\r\n\t\t\t\\FlagsNOP\r\n\t\t\t\\OpCode{00}{000}{000}\r\n\t\t\t\\Hex{00}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{HALT}\r\n\t\t\\Symbol{}\r\n\t\t\t\\FlagsHALT\r\n\t\t\t\\OpCode{01}{110}{110}\r\n\t\t\t\\Hex{76}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{DI\\See{3}} \r\n\t\t\\Symbol{\\SymDI[0]}\r\n\t\t\t\\FlagsDI\r\n\t\t\t\\OpCode{11}{110}{011}\r\n\t\t\t\\Hex{F3}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymDI[1]}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{EI\\See{3}} \r\n\t\t\\Symbol{\\SymEI[0]}\r\n\t\t\t\\FlagsEI\r\n\t\t\t\\OpCode{11}{111}{011}\r\n\t\t\t\\Hex{FB}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymEI[1]}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{IM 0\\See{4}}\r\n\t\t\\Symbol{}\r\n\t\t\t\\FlagsIM\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{01}{000}{110}\r\n\t\t\t\\Hex{46}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{IM 1\\See{4}}\r\n\t\t\\Symbol{}\r\n\t\t\t\\FlagsIM\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{01}{010}{110}\r\n\t\t\t\\Hex{56}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{lastinstruction}{IM 2\\See{4}}\r\n\t\t\\Symbol{}\r\n\t\t\t\\FlagsIM\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{01}{011}{110}\r\n\t\t\t\\Hex{5E}{}\r\n\t\\end{lastinstruction}\r\n\t\r\n\\end{instrtable}\r\n\r\n\\begin{notestable}\r\n\t\\NoteItem{\\See{1}YF and XF are copied from register {\\tt A}}\r\n\t\\NoteItem{\\See{2}Documentation says original value of CF is copied to HF, but my tests show that \\FlagHF{} remains unchanged}\r\n\t\\NoteItem{\\See{3}No interrupts are accepted directly after {\\tt EI} or {\\tt DI}}\r\n\t\\NoteItem{\\See{4}This instruction has other undocumented opcodes}\r\n\\end{notestable}\r\n\t\r\n\\end{minipage}\r\n"
  },
  {
    "path": "chapter-instr-glance-input.tex",
    "content": "\\section{Input}\r\n\r\n\\begin{minipage}{\\textwidth}\r\n\r\n\\begin{instrtable}\r\n\r\n\t\\begin{instruction}{IN A,(n)\\See{1}} \r\n\t\t\\Symbol{\\SymIN{A}{n}}\r\n\t\t\t\\FlagsINan\r\n\t\t\t\\OpCode{11}{011}{011}\r\n\t\t\t\\Hex{DB}{2}\r\n\t\t\t\\Cycles{3}{11}\r\n\t\t\t\\Comment{\r\n\t\t\t\t\\multirow{7}{*}{\r\n\t\t\t\t\t\\tt\r\n\t\t\t\t\t\\begin{tabular}{ll}\r\n\t\t\t\t\t\tr & \\OCT{r} \\\\\r\n\t\t\t\t\t\t\\hline\r\n\t\t\t\t\t\tB & 000 \\\\\r\n\t\t\t\t\t\tC & 001 \\\\\r\n\t\t\t\t\t\tD & 010 \\\\\r\n\t\t\t\t\t\tE & 011 \\\\\r\n\t\t\t\t\t\tH & 100 \\\\\r\n\t\t\t\t\t\tL & 101 \\\\\r\n\t\t\t\t\t\tA & 111 \\\\\r\n\t\t\t\t\t\\end{tabular}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\\SkipToOpCode\t\r\n\t\t\t\\OpRange{n} \r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{IN r,(C)\\See{2}} \r\n\t\t\\Symbol{\\SymIN{r}{BC}}\r\n\t\t\t\\FlagsINrc\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{3}{12}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{01}{\\OCT{r}}{000}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{IN (C)\\See{2,3}} \r\n\t\t\\Symbol{(BC)}\r\n\t\t\t\\FlagsINc\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{3}{12}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{01}{110}{000}\r\n\t\t\t\\Hex{70}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{IND} \r\n\t\t\\Symbol{\\SymIND[0]}\r\n\t\t\t\\FlagsIND\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymIND[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{101}{010}\r\n\t\t\t\\Hex{AA}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymIND[2]}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{INDR} \r\n\t\t\\Symbol{\\SymINDR[0]}\r\n\t\t\t\\FlagsINDR\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\t\\Comment{if {\\tt B}=0}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymINDR[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{111}{010}\r\n\t\t\t\\Hex{BA}{}\r\n\t\t\t\\Cycles{5}{21}\r\n\t\t\t\\Comment{if {\\tt B}$\\neq$0}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{INI} \r\n\t\t\\Symbol{\\SymINI[0]}\r\n\t\t\t\\FlagsINI\r\n\t\t\t\\OpCode{11}{101}{101} \r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymINI[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{100}{010}\r\n\t\t\t\\Hex{A2}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymINI[2]}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{lastinstruction}{INIR} \r\n\t\t\\Symbol{\\SymINIR[0]}\r\n\t\t\t\\FlagsINIR\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\t\\Comment{if {\\tt B}=0}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymINIR[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{110}{010}\r\n\t\t\t\\Hex{B2}{}\r\n\t\t\t\\Cycles{5}{21}\r\n\t\t\t\\Comment{if {\\tt B}$\\neq$0}\r\n\t\\end{lastinstruction}\t\r\n\t\t\r\n\\end{instrtable}\r\n\r\n\\begin{notestable}\r\n\t\\NoteItem{\\See{1}Some assemblers allow {\\tt IN (n)} to be used instead of {\\tt IN A,(n)}}\r\n\t\\NoteItem{\\See{2}Some assemblers allow instruction to be written with  {\\tt (BC)} instead of {\\tt (C)}}\r\n\t\\NoteItem{\\See{3}Performs the input without storing the result. Some assemblers allow {\\tt IN F,(C)} to be used instead of {\\tt IN (C)}}\r\n\t\\NoteItem{\\See{4}Flag is {\\tt 1} if {\\tt B=0} after execution, otherwise {\\tt 0}; similar to {\\tt DEC B}}\r\n\t\\NoteItem{\\See{5}On Next this flag is destroyed, for other Z80 computers see section \\XRef{z80_undocumented_instructions_io_block}}\r\n\\end{notestable}\r\n\t\r\n\\end{minipage}\r\n"
  },
  {
    "path": "chapter-instr-glance-jump.tex",
    "content": "\\section{Jump}\r\n\r\n\\begin{minipage}{\\textwidth}\r\n\t\r\n\\begin{instrtable}\r\n\r\n\t\\begin{instruction}{JP nm} \r\n\t\t\\Symbol{\\SymJP{nm}}\r\n\t\t\t\\FlagsJPnn\r\n\t\t\t\\OpCode{11}{000}{011}\r\n\t\t\t\\Hex{C3}{3}\r\n\t\t\t\\Cycles{3}{10}\r\n\t\t\t\\Comment{\r\n\t\t\t\t\\multirow{8}{*}{\r\n\t\t\t\t\t\\tt\r\n\t\t\t\t\t\\begin{tabular}{ll}\r\n\t\t\t\t\t\tc & \\OCT{c} \\\\\r\n\t\t\t\t\t\t\\hline\r\n\t\t\t\t\t\tNZ & 000 \\\\\r\n\t\t\t\t\t\tZ & 001 \\\\\r\n\t\t\t\t\t\tNC & C10 \\\\\r\n\t\t\t\t\t\tC & 011 \\\\\r\n\t\t\t\t\t\tPO & 100 \\\\\r\n\t\t\t\t\t\tPE & 101 \\\\\r\n\t\t\t\t\t\tP & 110 \\\\\r\n\t\t\t\t\t\tM & 111 \\\\\r\n\t\t\t\t\t\\end{tabular}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{m} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{n} \r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{JP (HL)}\r\n\t\t\\Symbol{\\SymJP{HL}}\r\n\t\t\t\\FlagsJPrr\r\n\t\t\t\\OpCode{11}{101}{001}\r\n\t\t\t\\Hex{E9}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{JP (IX)} \r\n\t\t\\Symbol{\\SymJP{IX}}\r\n\t\t\t\\FlagsJPrr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{11}{101}{001}\r\n\t\t\t\\Hex{E9}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{JP (IY)} \r\n\t\t\\Symbol{\\SymJP{IY}}\r\n\t\t\t\\FlagsJPrr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\t\\Comment{\r\n\t\t\t\t\\multirow{8}{*}{\r\n\t\t\t\t\t\\tt\r\n\t\t\t\t\t\\begin{tabular}{ll}\r\n\t\t\t\t\t\tp & \\OCT{pp} \\\\\r\n\t\t\t\t\t\t\\hline\r\n\t\t\t\t\t\tNZ & 00 \\\\\r\n\t\t\t\t\t\tZ & 01 \\\\\r\n\t\t\t\t\t\tNC & 10 \\\\\r\n\t\t\t\t\t\tC & 11 \\\\\r\n\t\t\t\t\t\\end{tabular}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{11}{101}{001}\r\n\t\t\t\\Hex{E9}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{JP c,nm} \r\n\t\t\\Symbol{\\SymJPc{nm}}\r\n\t\t\t\\FlagsJPccnn\r\n\t\t\t\\OpCode{11}{\\OCT{c}}{010}\r\n\t\t\t\\Hex{..}{3}\r\n\t\t\t\\Cycles{3}{10}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRange{m}\r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{n} \r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{JR e} \r\n\t\t\\Symbol{\\SymJR{e}}\r\n\t\t\t\\FlagsJRn\r\n\t\t\t\\OpCode{00}{011}{000}\r\n\t\t\t\\Hex{18}{2}\r\n\t\t\t\\Cycles{3}{12}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRangeSmall{e-2}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{JR p,e} \r\n\t\t\\Symbol{\\SymJRc{p}{e}}\r\n\t\t\t\\FlagsJRccn\r\n\t\t\t\\OpCode{00}{1\\OCT{pp}}{000}\r\n\t\t\t\\Hex{..}{2}\r\n\t\t\t\\Cycles{2}{7}\r\n\t\t\t\\Comment{if {\\tt p}=false}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpRangeSmall{e-2}\r\n\t\t\t\\Hex{..}{}\r\n\t\t\t\\Cycles{3}{12}\r\n\t\t\t\\Comment{if {\\tt p}=true}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{DJNZ e} \r\n\t\t\\Symbol{\\SymDJNZ[0]{e}}\r\n\t\t\t\\FlagsDJNZ\r\n\t\t\t\\OpCode{00}{010}{000}\r\n\t\t\t\\Hex{10}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\t\\Comment{if {\\tt B}=0}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymDJNZ[1]{e}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpRangeSmall{e-2}\r\n\t\t\t\\Hex{..}{}\r\n\t\t\t\\Cycles{3}{13}\r\n\t\t\t\\Comment{if {\\tt B}$\\neq$0}\r\n\t\\end{instruction}\r\n\t\t\r\n\\end{instrtable}\r\n\r\n\\begin{notestable}\r\n\t\\NoteItem{{\\tt e} is a signed two-complement in the range -127, 129.}\r\n\t\\NoteItem{{\\tt e-2} in the opcode provides an effective number of {\\tt PC+e} as {\\tt PC} is incremented by two prior to the addition of {\\tt e}.}\r\n\\end{notestable}\r\n\r\n\\end{minipage}\r\n"
  },
  {
    "path": "chapter-instr-glance-next.tex",
    "content": "\\section{ZX Spectrum Next Extended}\r\n\\label{zx_next_instructions_table}\r\n\r\n\\begin{minipage}{\\textwidth}\r\n\r\n\\begin{instrtable}\r\n\r\n\t\\begin{instruction}{ADD rr,A} \r\n\t\t\\Symbol{\\SymADD{rr}{A}}\r\n\t\t\t\\FlagsADDrra\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\t\\Comment{\r\n\t\t\t\t\\multirow{3}{*}{\r\n\t\t\t\t\t\\tt\r\n\t\t\t\t\t\\begin{tabular}{ll}\r\n\t\t\t\t\t\trr & \\OCT{rr} \\\\\r\n\t\t\t\t\t\t\\hline\r\n\t\t\t\t\t\tHL & 01 \\\\\r\n\t\t\t\t\t\tDE & 10 \\\\\r\n\t\t\t\t\t\tBC & 11 \\\\\r\n\t\t\t\t\t\\end{tabular}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{110}{0\\OCT{rr}}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{ADD pp,nm} \r\n\t\t\\Symbol{\\SymADD{pp}{nm}}\r\n\t\t\t\\FlagsADDrrnn\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\t\\Comment{\r\n\t\t\t\t\\multirow{6}{*}{\r\n\t\t\t\t\t\\tt\r\n\t\t\t\t\t\\begin{tabular}{ll}\r\n\t\t\t\t\t\tpp & \\OCT{pp} \\\\\r\n\t\t\t\t\t\t\\hline\r\n\t\t\t\t\t\tHL & 00 \\\\\r\n\t\t\t\t\t\tDE & 01 \\\\\r\n\t\t\t\t\t\tBC & 10 \\\\\r\n\t\t\t\t\t\\end{tabular}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{110}{1\\OCT{pp}}\r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{m} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{n} \r\n\t\t\t\\Hex{..}{} \r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{BSLA DE,B\\See{2}} \r\n\t\t\\Symbol{\\SymBSLA[0]}\r\n\t\t\t\\FlagsBSLA\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{101}{000}\r\n\t\t\t\\Hex{28}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{BSRA DE,B\\See{2}} \r\n\t\t\\SymbolS{\\SymBSRA[0]}\r\n\t\t\t\\FlagsBSRA\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\SymbolP{\\SymBSRA[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{00}{101}{001}\r\n\t\t\t\\Hex{29}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{BSRL DE,B\\See{2}} \r\n\t\t\\SymbolS{\\SymBSRL[0]}\r\n\t\t\t\\FlagsBSRL\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\SymbolP{\\SymBSRL[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{00}{101}{010}\r\n\t\t\t\\Hex{2A}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{BSRF DE,B\\See{2}} \r\n\t\t\\SymbolS{\\SymBSRF[0]}\r\n\t\t\t\\FlagsBSRF\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\SymbolP{\\SymBSRF[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{00}{101}{011}\r\n\t\t\t\\Hex{2B}{}\r\n\t\\end{instruction}\r\n\t\t\r\n\t\\begin{instruction}{BRLC DE,B\\See{2}} \r\n\t\t\\Symbol{\\SymBRLC[0]}\r\n\t\t\t\\FlagsBRLC\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymBRLC[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{00}{101}{100}\r\n\t\t\t\\Hex{2C}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{JP (C)} \r\n\t\t\\Symbol{\\SymJPC}\r\n\t\t\t\\FlagsJPc\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{3}{13}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{10}{011}{000}\r\n\t\t\t\\Hex{98}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LDDX} \r\n\t\t\\Symbol{\\SymLDDX[0]}\r\n\t\t\t\\FlagsLDDX\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDDX[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{101}{100}\r\n\t\t\t\\Hex{AC}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDDX[2]}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDDX[3]}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LDDRX} \r\n\t\t\\Symbol{\\SymLDDRX[0]}\r\n\t\t\t\\FlagsLDDRX\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\t\\Comment{if {\\tt BC}=0}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDDRX[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{111}{100}\r\n\t\t\t\\Hex{BC}{}\r\n\t\t\t\\Cycles{5}{21}\r\n\t\t\t\\Comment{if {\\tt BC}$\\neq$0}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LDIX} \r\n\t\t\\Symbol{\\SymLDIX[0]}\r\n\t\t\t\\FlagsLDIX\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDIX[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{100}{100}\r\n\t\t\t\\Hex{A4}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDIX[2]}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDIX[3]}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LDIRX} \r\n\t\t\\Symbol{\\SymLDIRX[0]}\r\n\t\t\t\\FlagsLDIRX\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\t\\Comment{if {\\tt BC}=0}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDIRX[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{110}{100}\r\n\t\t\t\\Hex{B4}{}\r\n\t\t\t\\Cycles{5}{21}\r\n\t\t\t\\Comment{if {\\tt BC}$\\neq$0}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{LDPIRX} \r\n\t\t\\Symbol{\\SymLDPIRX[0]}\r\n\t\t\t\\FlagsLDPIRX\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\t\\Comment{if {\\tt BC}=0}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDPIRX[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{110}{111}\r\n\t\t\t\\Hex{B7}{}\r\n\t\t\t\\Cycles{5}{21}\r\n\t\t\t\\Comment{if {\\tt BC}$\\neq$0}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDPIRX[2]}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDPIRX[3]}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDPIRX[4]}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDPIRX[5]}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{lastinstruction}{LDWS} \r\n\t\t\\Symbol{\\SymLDWS[0]}\r\n\t\t\t\\FlagsLDWS\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDWS[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{100}{101}\r\n\t\t\t\\Hex{A5}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymLDWS[2]}\r\n\t\\end{lastinstruction}\r\n\r\n\\end{instrtable}\r\n\r\n\\begin{notestable}\r\n\t\\NoteItemCont{\\See{1}CF is undefined, recently discovered, thanks to Peter Ped Helcmanovsky}\r\n\t\\NoteItemEnd{\\url{https://discord.com/channels/556228195767156758/695180116040351795/888099852725133412}}\r\n\t\\NoteItem{\\See{2}Core v2+ only}\r\n\t\\NoteItem{\\See{3}PV set to {\\tt 1} if {\\tt D} was {\\tt \\$7F} before increment, otherwise {\\tt 0}}\r\n\\end{notestable}\r\n\r\n% we need to have \"continue\" within minipage, and pagebreak outside...\r\n\\InstrTableContinue[-1.5ex]\r\n\t\r\n\\end{minipage}\r\n\r\n\\pagebreak\r\n\r\n\\vspace*{3ex} % ensure this table starts at the same height as the one on the odd page\r\n\\begin{minipage}{\\textwidth}\r\n\r\n\\begin{instrtable}\t\r\n\r\n\t% we need some extra spacing to accomodate the image; it's negative because \\\\ adds a line, but we don't need full line of space...\r\n\t\\\\[-9pt]\r\n\r\n\t\\begin{instruction}{MIRROR A}\r\n\t\t\\Symbol{\\multirow{2}{*}{\\SymMIRROR{A}}}\r\n\t\t\t\\FlagsMIRRORa\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{100}{100}\r\n\t\t\t\\Hex{24}{}\r\n\t\\end{instruction}\r\n\t\r\n\t% we need some extra spacing to accomodate the image\r\n\t\\\\[0.5ex]\r\n\r\n\t\\begin{instruction}{MUL D,E} \r\n\t\t\\Symbol{\\SymMUL}\r\n\t\t\t\\FlagsMULde\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{110}{000}\r\n\t\t\t\\Hex{30}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{NEXTREG n,A} \r\n\t\t\\Symbol{\\SymNEXTREG{A}}\r\n\t\t\t\\FlagsNEXTREGna\r\n\t\t\t\\OpCode{11}{101}{101} \r\n\t\t\t\\Hex{ED}{3}\r\n\t\t\t\\Cycles{4}{17}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{10}{010}{010}\r\n\t\t\t\\Hex{92}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{n} \r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{NEXTREG n,m}\r\n\t\t\\Symbol{\\SymNEXTREG{m}}\r\n\t\t\t\\FlagsNEXTREGnn\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{3}\r\n\t\t\t\\Cycles{5}{20}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{10}{010}{001}\r\n\t\t\t\\Hex{91}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{n} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{m} \r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{OUTINB} \r\n\t\t\\Symbol{\\SymOUTINB[0]}\r\n\t\t\t\\FlagsOUTINB\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymOUTINB[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{010}{000}\r\n\t\t\t\\Hex{90}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{PIXELAD} \r\n\t\t\\SymbolS{\\SymPIXELAD[0]}\r\n\t\t\t\\FlagsPIXELAD\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{3}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\SymbolP{\\SymPIXELAD[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{010}{100}\r\n\t\t\t\\Hex{94}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\SymbolP{\\SymPIXELAD[2]}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\SymbolP{\\SymPIXELAD[3]}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\SymbolP{\\SymPIXELAD[4]}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{PIXELDN} \r\n\t\t\\Symbol{\\SymPIXELDN[0]}\r\n\t\t\t\\FlagsPIXELDN\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{3}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPIXELDN[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{010}{011}\r\n\t\t\t\\Hex{93}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPIXELDN[2]}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPIXELDN[3]}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPIXELDN[4]}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPIXELDN[5]}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{PUSH nm}\r\n\t\t\\Symbol{\\SymPUSHnn[0]{n}{m}}\r\n\t\t\t\\FlagsPUSHnn\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{3}\r\n\t\t\t\\Cycles{6}{23}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPUSHnn[1]{n}{m}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{001}{010}\r\n\t\t\t\\Hex{8A}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPUSHnn[2]{n}{m}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpRange{\\hspace*{-0.5ex}n\\See{1}\\hspace*{-0.5ex}} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{\\hspace*{-0.5ex}m\\See{1}\\hspace*{-0.5ex}} \r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{SETAE} \r\n\t\t\\Symbol{\\SymSETAE}\r\n\t\t\t\\FlagsSETAE\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{3}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{10}{010}{101}\r\n\t\t\t\\Hex{95}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{SWAPNIB}\r\n\t\t\\Symbol{\\multirow[b]{1}{*}{\\SymSWAPNIB[0]}}\r\n\t\t\t\\FlagsSWAPNIB\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{100}{011}\r\n\t\t\t\\Hex{23}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{lastinstruction}{TEST n} \r\n\t\t\\Symbol{\\SymTEST}\r\n\t\t\t\\FlagsTESTn\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{3}\r\n\t\t\t\\Cycles{3}{11}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{100}{111}\r\n\t\t\t\\Hex{27}{}\r\n\t\\end{lastinstruction}\r\n\r\n\\end{instrtable}\r\n\r\n\\NoteTableSingleItemSpaceCorrection\r\n\r\n\\begin{notestable}\r\n\t\\NoteItem{\\See{1} This is not mistake, {\\tt nm} operand is in fact encoded in big-endian}\r\n\\end{notestable}\r\n\r\n\\end{minipage}\r\n\r\n"
  },
  {
    "path": "chapter-instr-glance-output.tex",
    "content": "\\section{Output}\r\n\r\n\\begin{minipage}{\\textwidth}\r\n\r\n\\begin{instrtable}\r\n\r\n\t\\begin{instruction}{OUT (n),A} \r\n\t\t\\Symbol{\\SymOUT{n}{A}}\r\n\t\t\t\\FlagsOUTna\r\n\t\t\t\\OpCode{11}{010}{011}\r\n\t\t\t\\Hex{D3}{2}\r\n\t\t\t\\Cycles{3}{11}\r\n\t\t\t\\Comment{\r\n\t\t\t\t\\multirow{7}{*}{\r\n\t\t\t\t\t\\tt\r\n\t\t\t\t\t\\begin{tabular}{ll}\r\n\t\t\t\t\t\tr & \\OCT{r} \\\\\r\n\t\t\t\t\t\t\\hline\r\n\t\t\t\t\t\tB & 000 \\\\\r\n\t\t\t\t\t\tC & 001 \\\\\r\n\t\t\t\t\t\tD & 010 \\\\\r\n\t\t\t\t\t\tE & 011 \\\\\r\n\t\t\t\t\t\tH & 100 \\\\\r\n\t\t\t\t\t\tL & 101 \\\\\r\n\t\t\t\t\t\tA & 111 \\\\\r\n\t\t\t\t\t\\end{tabular}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{n} \r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{OUT (C),r} \r\n\t\t\\Symbol{\\SymOUT{BC}{r}}\r\n\t\t\t\\FlagsOUTcr\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{3}{12}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{01}{\\OCT{r}}{001}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{OUT (C),0} \r\n\t\t\\Symbol{\\SymOUT{BC}{0}}\r\n\t\t\t\\FlagsOUTc\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{3}{12}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{01}{110}{001}\r\n\t\t\t\\Hex{71}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{OUTI} \r\n\t\t\\Symbol{\\SymOUTI[0]}\r\n\t\t\t\\FlagsOUTI\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymOUTI[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{100}{011}\r\n\t\t\t\\Hex{A3}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymOUTI[2]}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{OTIR} \r\n\t\t\\Symbol{\\SymOTIR[0]}\r\n\t\t\t\\FlagsOTIR\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\t\\Comment{if {\\tt B}=0}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymOTIR[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{110}{011}\r\n\t\t\t\\Hex{B3}{}\r\n\t\t\t\\Cycles{5}{21}\r\n\t\t\t\\Comment{if {\\tt B}$\\neq$0}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{OUTD} \r\n\t\t\\Symbol{\\SymOUTD[0]}\r\n\t\t\t\\FlagsOUTI\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymOUTD[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{101}{011}\r\n\t\t\t\\Hex{AB}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymOUTD[2]}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{lastinstruction}{OTDR} \r\n\t\t\\Symbol{\\SymOTDR[0]}\r\n\t\t\t\\FlagsOTDR\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{4}{16}\r\n\t\t\t\\Comment{if {\\tt B}=0}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymOTDR[1]}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{10}{111}{011}\r\n\t\t\t\\Hex{BB}{}\r\n\t\t\t\\Cycles{5}{21}\r\n\t\t\t\\Comment{if {\\tt B}$\\neq$0}\r\n\t\\end{lastinstruction}\r\n\r\n\\end{instrtable}\r\n\r\n\\begin{notestable}\r\n\t\\NoteItem{\\See{1}Flag is {\\tt 1} if {\\tt B=0} after execution, otherwise {\\tt 0}}\r\n\t\\NoteItem{\\See{2}On Next this flag is destroyed, for other Z80 computers see section \\XRef{z80_undocumented_instructions_io_block}.}\r\n\\end{notestable}\r\n\t\r\n\\end{minipage}\r\n\r\n\r\n\r\n\\pagebreak"
  },
  {
    "path": "chapter-instr-glance-rotate-shift.tex",
    "content": "\\section{Rotate and Shift}\r\n\r\n\\vspace*{0.7ex} % ensure this table starts at the same height as the one on the odd page\r\n\\begin{minipage}{\\textwidth}\r\n\t\r\n\\begin{instrtable}\r\n\t% we need slightly more vertical space to accomodate symbolic operation drawing for RLC; it's negative because we only need a fraction of what new line produces\r\n\t\\\\[-10pt]\r\n\r\n\t\\begin{instruction}{RLC r}\r\n\t\t\\Symbol{\\SymRLC[0]{r}}\r\n\t\t\t\\FlagsRLCr\r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{2}\r\n\t\t\t\\Cycles{2}{8}\r\n\t\t\t\\Comment{\r\n\t\t\t\t\\multirow{6}{*}{\r\n\t\t\t\t\t\\tt\r\n\t\t\t\t\t\\begin{tabular}{ll}\r\n\t\t\t\t\t\tr & \\OCT{r} \\\\\r\n\t\t\t\t\t\t\\hline\r\n\t\t\t\t\t\tB & 000 \\\\\r\n\t\t\t\t\t\tC & 001 \\\\\r\n\t\t\t\t\t\tD & 010 \\\\\r\n\t\t\t\t\t\tE & 011 \\\\\r\n\t\t\t\t\t\tH & 100 \\\\\r\n\t\t\t\t\t\tL & 101 \\\\\r\n\t\t\t\t\t\tA & 111 \\\\\r\n\t\t\t\t\t\\end{tabular}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{\\fbox{000}}{\\OCT{r}}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{RLC (HL)}\r\n\t\t\\Symbol{\\SymRLC[0]{(HL)}}\r\n\t\t\t\\FlagsRLCr\r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{2}\r\n\t\t\t\\Cycles{4}{15}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{\\fbox{000}}{110}\r\n\t\t\t\\Hex{06}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{RLC (IX+d)}\r\n\t\t\\Symbol{\\SymRLC[0]{(IX+d)}}\r\n\t\t\t\\FlagsRLCr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{4}\r\n\t\t\t\\Cycles{6}{23}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{d} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{\\fbox{000}}{110}\r\n\t\t\t\\Hex{06}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{RLC (IY+d)}\r\n\t\t\\Symbol{\\SymRLC[0]{(IY+d)}}\r\n\t\t\t\\FlagsRLCr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{4}\r\n\t\t\t\\Cycles{6}{23}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpRange{d} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{\\fbox{000}}{110}\r\n\t\t\t\\Hex{06}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{RLC r,(IX+d)}\r\n\t\t\\Symbol{\\SymRLCu[0]{r}{IX}}\r\n\t\t\t\\FlagsRLCr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{4}\r\n\t\t\t\\Cycles{6}{23}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymRLCu[1]{r}{IX}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymRLCu[2]{r}{IX}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpRange{d} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{00}{\\fbox{000}}{\\OCT{r}}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{RLC r,(IY+d)}\r\n\t\t\\Symbol{\\SymRLCu[0]{r}{IY}}\r\n\t\t\t\\FlagsRLCr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{4}\r\n\t\t\t\\Cycles{6}{23}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymRLCu[1]{r}{IY}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{11}{001}{011}\r\n\t\t\t\\Hex{CB}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymRLCu[2]{r}{IY}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpRange{d} \r\n\t\t\t\\Hex{..}{}\r\n\t\t\\SkipToOpCode\r\n\t\t\t\\OpCode{00}{\\fbox{000}}{\\OCT{r}}\r\n\t\t\t\\Hex{..}{}\r\n\t\\end{instruction}\r\n\r\n\t\\StartWithOpCode\\OpCode{}{$\\uparrow$}{} \\\\\r\n\r\n\t\\begin{instruction}{RRC m\\See{1}}\r\n\t\t\\Symbol{\\SymRRC[0]{m}}\r\n\t\t\t\\FlagsRRCr\r\n\t\t\t\\OpCode{..}{\\fbox{001}}{...}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{RL m\\See{1}}\r\n\t\t\\Symbol{\\SymRL[0]{m}}\r\n\t\t\t\\FlagsRLr\r\n\t\t\t\\OpCode{..}{\\fbox{010}}{...}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{RR m\\See{1}}\r\n\t\t\\Symbol{\\SymRR[0]{m}}\r\n\t\t\t\\FlagsRRr\r\n\t\t\t\\OpCode{..}{\\fbox{011}}{...}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{SLA m\\See{1}}\r\n\t\t\\Symbol{\\vspace*{2pt}\\SymSLA[0]{m}}\r\n\t\t\t\\FlagsSLAr\r\n\t\t\t\\OpCode{..}{\\fbox{100}}{...}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{SRA m\\See{1}}\r\n\t\t\\Symbol{\\vspace*{3pt}\\SymSRA[0]{m}}\r\n\t\t\t\\FlagsSRAr\r\n\t\t\t\\OpCode{..}{\\fbox{101}}{...}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{SLI m\\See{1,2}}\r\n\t\t\\Symbol{\\vspace*{2pt}\\SymSLI[0]{m}}\r\n\t\t\t\\FlagsSLIr\r\n\t\t\t\\OpCode{..}{\\fbox{110}}{...}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{SRL m\\See{1}}\r\n\t\t\\Symbol{\\vspace*{2pt}\\SymSRL[0]{m}}\r\n\t\t\t\\FlagsSRLr\r\n\t\t\t\\OpCode{..}{\\fbox{111}}{...}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{SLL m\\See{3}}\r\n\t\\end{instruction}\r\n\r\n\t\\Empty{}\r\n\t\r\n\t\\begin{instruction}{RLA}\r\n\t\t\\Symbol{\\SymRL[0]{A}}\r\n\t\t\t\\FlagsRLA\r\n\t\t\t\\OpCode{00}{010}{111}\r\n\t\t\t\\Hex{17}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{RLCA}\r\n\t\t\\Symbol{\\SymRLC[0]{A}}\r\n\t\t\t\\FlagsRLCA\r\n\t\t\t\\OpCode{00}{000}{111}\r\n\t\t\t\\Hex{07}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{RRA}\r\n\t\t\\Symbol{\\SymRR[0]{A}}\r\n\t\t\t\\FlagsRRA\r\n\t\t\t\\OpCode{00}{011}{111}\r\n\t\t\t\\Hex{1F}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{RRCA}\r\n\t\t\\Symbol{\\SymRRC[0]{A}}\r\n\t\t\t\\FlagsRRCA\r\n\t\t\t\\OpCode{00}{001}{111}\r\n\t\t\t\\Hex{0F}{1}\r\n\t\t\t\\Cycles{1}{4}\r\n\t\\end{instruction}\r\n\r\n\t\\Empty{}\r\n\r\n\t\\begin{instruction}{RLD}\r\n\t\t\\Symbol{\\vspace*{-12pt}\\hspace*{-0.8cm}\\SymRLD}\r\n\t\t\t\\FlagsRLD \r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{5}{18}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{01}{101}{111}\r\n\t\t\t\\Hex{6F}{}\r\n\t\\end{instruction}\r\n\t\t\t\r\n\t\\begin{lastinstruction}{RRD}\r\n\t\t\\Symbol{\\vspace*{-12pt}\\hspace*{-0.8cm}\\SymRRD}\r\n\t\t\t\\FlagsRRD\r\n\t\t\t\\OpCode{11}{101}{101}\r\n\t\t\t\\Hex{ED}{2}\r\n\t\t\t\\Cycles{5}{18}\r\n\t\t\\SkipToOpCode \r\n\t\t\t\\OpCode{01}{100}{111}\r\n\t\t\t\\Hex{67}{}\r\n\t\\end{lastinstruction}\r\n\t\t\t\r\n\\end{instrtable}\r\n\r\n\\NoteTableSingleItemSpaceCorrection\r\n\r\n\\begin{notestable}\r\n\t\\NoteItem{\\See{1}{\\tt m} is one of {\\tt r}, {\\tt (HL)}, {\\tt (IX+d)}, {\\tt (IY+d)}. To form new opcode replace \\fbox{000} of {\\tt RLC}s with shown code. Ts also the same\\rule{0pt}{3.5ex}}\r\n\r\n\t\\NoteItem{\\See{2}Some assemblers may also allow {\\tt SL1} to be used instead of {\\tt SLI}}\r\n\r\n\t\\NoteItem{\\See{3}Shift Left Logical; no associated opcode, there is no difference between logical and arithmetic shift left, use {\\tt SLA} for both. Some assemblers will allow {\\tt SLL} as equivalent, but unfortunately some will assemble it as {\\tt SLI}, so it's best avoiding}\r\n\\end{notestable}\r\n\r\n\\end{minipage}\r\n"
  },
  {
    "path": "chapter-instr-glance-stack.tex",
    "content": "\\section{Stack}\r\n\r\n\\begin{minipage}{\\textwidth}\r\n\t\r\n\\begin{instrtable}\r\n\r\n\t\\begin{instruction}{POP pp} \r\n\t\t\\Symbol{\\SymPOP[0]{pp}}\r\n\t\t\t\\FlagsPOPrr\r\n\t\t\t\\OpCode{11}{\\OCT{pp}0}{001}\r\n\t\t\t\\Hex{..}{1}\r\n\t\t\t\\Cycles{3}{10}\r\n\t\t\t\\Comment{\r\n\t\t\t\t\\multirow{3}{*}{\r\n\t\t\t\t\t\\tt\r\n\t\t\t\t\t\\begin{tabular}{ll}\r\n\t\t\t\t\t\tpp & \\OCT{pp} \\\\\r\n\t\t\t\t\t\t\\hline\r\n\t\t\t\t\t\tBC & 00 \\\\\r\n\t\t\t\t\t\tDE & 01 \\\\\r\n\t\t\t\t\t\tHL & 10 \\\\\r\n\t\t\t\t\t\\end{tabular}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPOP[1]{pp}}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPOP[2]{pp}}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{POP AF} \r\n\t\t\\Symbol{\\SymPOP[10]{A}}\r\n\t\t\t\\FlagsPOPaf\r\n\t\t\t\\OpCode{11}{110}{001}\r\n\t\t\t\\Hex{F1}{1}\r\n\t\t\t\\Cycles{3}{10}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPOP[11]{F}}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPOP[12]{}}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{POP IX} \r\n\t\t\\Symbol{\\SymPOP[0]{IX}}\r\n\t\t\t\\FlagsPOPrr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{2}\r\n\t\t\t\\Cycles{4}{14}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPOP[1]{IX}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{11}{100}{001}\r\n\t\t\t\\Hex{E1}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPOP[2]{IX}}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{POP IY}\r\n\t\t\\Symbol{\\SymPOP[0]{IY}}\r\n\t\t\t\\FlagsPOPrr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{2}\r\n\t\t\t\\Cycles{4}{14}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPOP[1]{IY}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{11}{100}{001}\r\n\t\t\t\\Hex{E1}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPOP[2]{IY}}\r\n\t\\end{instruction}\r\n\r\n\t\\begin{instruction}{PUSH rr} \r\n\t\t\\Symbol{\\SymPUSH[0]{rr}}\r\n\t\t\t\\FlagsPUSHrr\r\n\t\t\t\\OpCode{11}{\\OCT{rr}0}{101}\r\n\t\t\t\\Hex{..}{1}\r\n\t\t\t\\Cycles{3}{11}\r\n\t\t\t\\Comment{\r\n\t\t\t\t\\multirow{4}{*}{\r\n\t\t\t\t\t\\tt\r\n\t\t\t\t\t\\begin{tabular}{ll}\r\n\t\t\t\t\t\trr & \\OCT{rr} \\\\\r\n\t\t\t\t\t\t\\hline\r\n\t\t\t\t\t\tBC & 00 \\\\\r\n\t\t\t\t\t\tDE & 01 \\\\\r\n\t\t\t\t\t\tHL & 10 \\\\\r\n\t\t\t\t\t\tAF & 11 \\\\\r\n\t\t\t\t\t\\end{tabular}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPUSH[1]{rr}}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPUSH[2]{rr}}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{instruction}{PUSH IX} \r\n\t\t\\Symbol{\\SymPUSH[0]{IX}}\r\n\t\t\t\\FlagsPUSHrr\r\n\t\t\t\\OpCode{11}{011}{101}\r\n\t\t\t\\Hex{DD}{2}\r\n\t\t\t\\Cycles{4}{15}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPUSH[1]{IX}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{11}{100}{101}\r\n\t\t\t\\Hex{E5}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPUSH[2]{IX}}\r\n\t\\end{instruction}\r\n\t\r\n\t\\begin{lastinstruction}{PUSH IY} \r\n\t\t\\Symbol{\\SymPUSH[0]{IY}}\r\n\t\t\t\\FlagsPUSHrr\r\n\t\t\t\\OpCode{11}{111}{101}\r\n\t\t\t\\Hex{FD}{2}\r\n\t\t\t\\Cycles{4}{15}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPUSH[1]{IY}}\r\n\t\t\t\\FromSymbolToOpCode\r\n\t\t\t\\OpCode{11}{100}{101}\r\n\t\t\t\\Hex{E5}{}\r\n\t\t\\SkipToSymbol\r\n\t\t\t\\Symbol{\\SymPUSH[2]{IY}}\r\n\t\\end{lastinstruction}\r\n\t\r\n\\end{instrtable}\r\n\r\n\\NoteTableSingleItemSpaceCorrection\r\n\r\n\\begin{notestable}\r\n\t\\NoteItem{\\See{1}Flags set directly to low 8-bits of the value from stack SP}\r\n\\end{notestable}\r\n\r\n\\end{minipage}"
  },
  {
    "path": "chapter-instr-glance.tex",
    "content": "\\chapter{Instructions at a Glance}\r\n\r\n% ███████████████████████████████████████████████████████████████████████████████████████████████████\r\n% █░░░░░░░░░░░░░░█░░░░░░█████████░░░░░░░░░░░░░░█░░░░░░██████████░░░░░░█░░░░░░░░░░░░░░█░░░░░░░░░░░░░░█\r\n% █░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀░░█████████░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀░░░░░░░░░░██░░▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█\r\n% █░░▄▀░░░░░░░░░░█░░▄▀░░█████████░░▄▀░░░░░░▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░██░░▄▀░░█░░▄▀░░░░░░░░░░█░░▄▀░░░░░░░░░░█\r\n% █░░▄▀░░█████████░░▄▀░░█████████░░▄▀░░██░░▄▀░░█░░▄▀░░░░░░▄▀░░██░░▄▀░░█░░▄▀░░█████████░░▄▀░░█████████\r\n% █░░▄▀░░█████████░░▄▀░░█████████░░▄▀░░░░░░▄▀░░█░░▄▀░░██░░▄▀░░██░░▄▀░░█░░▄▀░░█████████░░▄▀░░░░░░░░░░█\r\n% █░░▄▀░░██░░░░░░█░░▄▀░░█████████░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀░░██░░▄▀░░██░░▄▀░░█░░▄▀░░█████████░░▄▀▄▀▄▀▄▀▄▀░░█\r\n% █░░▄▀░░██░░▄▀░░█░░▄▀░░█████████░░▄▀░░░░░░▄▀░░█░░▄▀░░██░░▄▀░░██░░▄▀░░█░░▄▀░░█████████░░▄▀░░░░░░░░░░█\r\n% █░░▄▀░░██░░▄▀░░█░░▄▀░░█████████░░▄▀░░██░░▄▀░░█░░▄▀░░██░░▄▀░░░░░░▄▀░░█░░▄▀░░█████████░░▄▀░░█████████\r\n% █░░▄▀░░░░░░▄▀░░█░░▄▀░░░░░░░░░░█░░▄▀░░██░░▄▀░░█░░▄▀░░██░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀░░░░░░░░░░█░░▄▀░░░░░░░░░░█\r\n% █░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀░░██░░▄▀░░█░░▄▀░░██░░░░░░░░░░▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█\r\n% █░░░░░░░░░░░░░░█░░░░░░░░░░░░░░█░░░░░░██░░░░░░█░░░░░░██████████░░░░░░█░░░░░░░░░░░░░░█░░░░░░░░░░░░░░█\r\n% ███████████████████████████████████████████████████████████████████████████████████████████████████\r\n\r\n\r\n\\ChapterTOC[]\r\n\r\n\\pagebreak\r\n\\thispagestyle{plain} % use toc style without headers for this explanation page, it better matches chapter start page\r\n\r\nThis chapter presents all instructions at a glance for quick info and to easily compare them when choosing the most optimal combination for the task at hand. Instructions are grouped into logical sections based on the area they operate on.\r\n\\ifdefined\\isPDF \\else The chapter ends with alphabetical list of all instructions to make them easier to find when searching by mnemonic. \\fi\r\n\r\n\\subsubsection{Instruction Execution}\r\n\r\n\\begin{tabular}{ll}\r\n\tB & Number of bytes instruction uses in RAM\\\\\r\n\tMc\\notet & Number of machine cycles instruction takes to complete\\\\\r\n\tTs\\notet & Number of clock periods instruction requires to complete\\\\\r\n\\end{tabular}\r\n\r\n\\subsubsection{Flags \\textnormal{(copied from section \\XRef{z80_flags} as convenience)}}\r\n\r\n\\begin{tabularx}{\\linewidth}{lX}\r\n\tSF & \r\n\t\t\\textbf{Sign} Set if 2-complement value is negative.\\\\\r\n\tZF\\notet & \r\n\t\t\\textbf{Zero} Set if the result is zero. \\\\\r\n\tHY\\notet & \r\n\t\t\\textbf{Half-Carry} The half-carry of an addition/subtraction (from bit 3 to 4)\\See{*}. \\\\\r\n\tPV\\notet & \r\n\t\t\\textbf{Parity/Overflow} This flag can either be the parity of the result ({\\tt \\FPP}), or 2-complement signed overflow ({\\tt \\FPV}). \\\\\r\n\tNF\\notet & \r\n\t\t\\textbf{Add/Subtract} Indicates the last operation was an addition ({\\tt 0}) or a subtraction ({\\tt 1})\\See{*}. \\\\\r\n\tCF\\notet & \r\n\t\t\\textbf{Carry} Set if there was a carry from the most significant bit. \\\\\r\n\\end{tabularx}\r\n\r\n\\See{*} \\small{Primarily used for BCD operations.}\r\n\r\n\r\n\\subsubsection{Effects}\r\n\r\n\\begin{tabular}{cl}\r\n\t{\\tt 0}/{\\tt 1} & Flag is set to {\\tt 0} or {\\tt 1} \\\\\r\n\t{\\tt \\FS} & Flag is modified according to operation \\\\\r\n\t{\\tt \\FN} & Flag is not affected \\\\\r\n\t{\\tt \\FU} & Effect on flag is unpredictable \\\\\r\n\t{\\tt VF} & P/V flag is used as overflow \\\\\r\n\t{\\tt PF} & P/V flag is used as parity \\\\\r\n\t{\\tt \\FX} & Special case, see description under the table or in chapter \\XRef{instruction_details}\r\n\\end{tabular}\r\n\r\n\\subsubsection{Notes}\r\n\r\n{\\tt YF} and {\\tt XF} flags are not represented; they're irrelevant from the programmer point of view.\r\n\t\r\nI used 4 sources for comparing effects: Z80 undocumented\\footnote{\\url{http://www.myquest.nl/z80undocumented/}}, Programming the Z80 third edition\\footnote{\\url{http://www.z80.info/zaks.html}}, Zilog Z80 manual\\footnote{\\url{https://www.zilog.com/docs/z80/um0080.pdf}} and Next Dev Wiki\\footnote{\\url{https://wiki.specnext.dev/Extended_Z80_instruction_set}}. Where different and I couldn't verify, I opted for variant that matches most sources with slightly greater precedence for Next Dev Wiki side.\r\n\r\n\r\n\\pagebreak\r\n"
  },
  {
    "path": "chapter-instr-sorted-mnemonic.tex",
    "content": "\\chapter{Instructions Sorted by Mnemonic}\r\n\r\n% █████████████████████████████████████████████████████████████████████████████████████\r\n% █░░░░░░██████████░░░░░░█░░░░░░██████████░░░░░░█░░░░░░░░░░░░░░█░░░░░░██████████░░░░░░█\r\n% █░░▄▀░░░░░░░░░░░░░░▄▀░░█░░▄▀░░░░░░░░░░██░░▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀░░░░░░░░░░░░░░▄▀░░█\r\n% █░░▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░██░░▄▀░░█░░▄▀░░░░░░░░░░█░░▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀░░█\r\n% █░░▄▀░░░░░░▄▀░░░░░░▄▀░░█░░▄▀░░░░░░▄▀░░██░░▄▀░░█░░▄▀░░█████████░░▄▀░░░░░░▄▀░░░░░░▄▀░░█\r\n% █░░▄▀░░██░░▄▀░░██░░▄▀░░█░░▄▀░░██░░▄▀░░██░░▄▀░░█░░▄▀░░░░░░░░░░█░░▄▀░░██░░▄▀░░██░░▄▀░░█\r\n% █░░▄▀░░██░░▄▀░░██░░▄▀░░█░░▄▀░░██░░▄▀░░██░░▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀░░██░░▄▀░░██░░▄▀░░█\r\n% █░░▄▀░░██░░░░░░██░░▄▀░░█░░▄▀░░██░░▄▀░░██░░▄▀░░█░░▄▀░░░░░░░░░░█░░▄▀░░██░░░░░░██░░▄▀░░█\r\n% █░░▄▀░░██████████░░▄▀░░█░░▄▀░░██░░▄▀░░░░░░▄▀░░█░░▄▀░░█████████░░▄▀░░██████████░░▄▀░░█\r\n% █░░▄▀░░██████████░░▄▀░░█░░▄▀░░██░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀░░░░░░░░░░█░░▄▀░░██████████░░▄▀░░█\r\n% █░░▄▀░░██████████░░▄▀░░█░░▄▀░░██░░░░░░░░░░▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀░░██████████░░▄▀░░█\r\n% █░░░░░░██████████░░░░░░█░░░░░░██████████░░░░░░█░░░░░░░░░░░░░░█░░░░░░██████████░░░░░░█\r\n% █████████████████████████████████████████████████████████████████████████████████████\r\n\r\nInstructions marked with \\UNDOC ~are undocumented.\\\\\r\nInstructions marked with \\ZXN ~are ZX Spectrum Next extended.\r\n% TODO: and any instruction not listed has no effect? (same behaviour as an equal amount of NOP instructions)\r\n\\setlength\\columnsep{4em}\r\n\\begin{multicols}{3}\r\n{\r\n\t\\tt \r\n\t\\footnotesize\r\n\t\\begin{tabbing}\r\n\t\tADC A,A~~~~{\\qquad}{\\quad}\\=8F\\\\\r\n\t\tADC A,B\\>88\\\\\r\n\t\tADC A,C\\>89\\\\\r\n\t\tADC A,D\\>8A\\\\\r\n\t\tADC A,E\\>8B\\\\\r\n\t\tADC A,H\\>8C\\\\\r\n\t\tADC A,L\\>8D\\\\\r\n\t\tADC A,n\\>CE n\\\\\r\n\t\tADC A,(HL)\\>8E\\\\\r\n\t\tADC A,(IX+d)\\>DD8E d\\\\\r\n\t\tADC A,(IY+d)\\>FD8E d\\\\\r\n\t\tADC A,IXH\\UNDOC\\>DD8C\\\\\r\n\t\tADC A,IXL\\UNDOC\\>DD8D\\\\\r\n\t\tADC A,IYH\\UNDOC\\>FD8C\\\\\r\n\t\tADC A,IYL\\UNDOC\\>FD8D\\\\\r\n\t\tADC HL,BC\\>ED4A\\\\\r\n\t\tADC HL,DE\\>ED5A\\\\\r\n\t\tADC HL,HL\\>ED6A\\\\\r\n\t\tADC HL,SP\\>ED7A\\\\\r\n\t\tADD A,A\\>87\\\\\r\n\t\tADD A,B\\>80\\\\\r\n\t\tADD A,C\\>81\\\\\r\n\t\tADD A,D\\>82\\\\\r\n\t\tADD A,E\\>83\\\\\r\n\t\tADD A,H\\>84\\\\\r\n\t\tADD A,L\\>85\\\\\r\n\t\tADD A,n\\>C6 n\\\\\r\n\t\tADD A,(HL)\\>86\\\\\r\n\t\tADD A,(IX+d)\\>DD86 d\\\\\r\n\t\tADD A,(IY+d)\\>FD86 d\\\\\r\n\t\tADD A,IXH\\UNDOC\\>DD84\\\\\r\n\t\tADD A,IXL\\UNDOC\\>DD85\\\\\r\n\t\tADD A,IYH\\UNDOC\\>FD84\\\\\r\n\t\tADD A,IYL\\UNDOC\\>FD85\\\\\r\n\t\tADD BC,A\\ZXN\\>ED33\\\\\r\n\t\tADD BC,nm\\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\\\\\r\n\t\tSUB IXH\\UNDOC\\>DD94\\\\\r\n\t\tSUB IXL\\UNDOC\\>DD95\\\\\r\n\t\tSUB IYH\\UNDOC\\>FD94\\\\\r\n\t\tSUB IYL\\UNDOC\\>FD95\\\\\r\n\t\tSWAPNIB\\ZXN\\>ED23\\\\\r\n\t\tTEST n\\ZXN\\>ED27 n\\\\\r\n\t\tXOR A\\>AF\\\\\r\n\t\tXOR B\\>A8\\\\\r\n\t\tXOR C\\>A9\\\\\r\n\t\tXOR D\\>AA\\\\\r\n\t\tXOR E\\>AB\\\\\r\n\t\tXOR H\\>AC\\\\\r\n\t\tXOR L\\>AD\\\\\r\n\t\tXOR n\\>EE n\\\\\r\n\t\tXOR (HL)\\>AE\\\\\r\n\t\tXOR (IX+d)\\>DDAE d\\\\\r\n\t\tXOR (IY+d)\\>FDAE d\\\\\r\n\t\tXOR IXH\\UNDOC\\>DDAC\\\\\r\n\t\tXOR IXL\\UNDOC\\>DDAD\\\\\r\n\t\tXOR IYH\\UNDOC\\>FDAC\\\\\r\n\t\tXOR IYL\\UNDOC\\>FDAD\r\n\r\n\t\\end{tabbing}\r\n}\r\n\\end{multicols}\r\n\\normalsize\r\n\r\n\r\n\\pagebreak\r\n\\IntentionallyEmpty\r\n\\pagebreak\r\n"
  },
  {
    "path": "chapter-instr-sorted-opcode.tex",
    "content": "\\chapter{Instructions Sorted by Opcode}\r\n\r\n% ███████████████████████████████████████████████████████████████████████████████████████████\r\n% █░░░░░░░░░░░░░░█░░░░░░░░░░░░░░█░░░░░░░░░░░░░░█░░░░░░░░░░░░░░█░░░░░░░░░░░░███░░░░░░░░░░░░░░█\r\n% █░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀░░░░█░░▄▀▄▀▄▀▄▀▄▀░░█\r\n% █░░▄▀░░░░░░▄▀░░█░░▄▀░░░░░░▄▀░░█░░▄▀░░░░░░░░░░█░░▄▀░░░░░░▄▀░░█░░▄▀░░░░▄▀▄▀░░█░░▄▀░░░░░░░░░░█\r\n% █░░▄▀░░██░░▄▀░░█░░▄▀░░██░░▄▀░░█░░▄▀░░█████████░░▄▀░░██░░▄▀░░█░░▄▀░░██░░▄▀░░█░░▄▀░░█████████\r\n% █░░▄▀░░██░░▄▀░░█░░▄▀░░░░░░▄▀░░█░░▄▀░░█████████░░▄▀░░██░░▄▀░░█░░▄▀░░██░░▄▀░░█░░▄▀░░░░░░░░░░█\r\n% █░░▄▀░░██░░▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀░░█████████░░▄▀░░██░░▄▀░░█░░▄▀░░██░░▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█\r\n% █░░▄▀░░██░░▄▀░░█░░▄▀░░░░░░░░░░█░░▄▀░░█████████░░▄▀░░██░░▄▀░░█░░▄▀░░██░░▄▀░░█░░▄▀░░░░░░░░░░█\r\n% █░░▄▀░░██░░▄▀░░█░░▄▀░░█████████░░▄▀░░█████████░░▄▀░░██░░▄▀░░█░░▄▀░░██░░▄▀░░█░░▄▀░░█████████\r\n% █░░▄▀░░░░░░▄▀░░█░░▄▀░░█████████░░▄▀░░░░░░░░░░█░░▄▀░░░░░░▄▀░░█░░▄▀░░░░▄▀▄▀░░█░░▄▀░░░░░░░░░░█\r\n% █░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀░░█████████░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀░░░░█░░▄▀▄▀▄▀▄▀▄▀░░█\r\n% █░░░░░░░░░░░░░░█░░░░░░█████████░░░░░░░░░░░░░░█░░░░░░░░░░░░░░█░░░░░░░░░░░░███░░░░░░░░░░░░░░█\r\n% ███████████████████████████████████████████████████████████████████████████████████████████\r\n\r\nInstructions marked with \\UNDOC ~are undocumented.\\\\\r\nInstructions marked with \\ZXN ~are ZX Spectrum Next extended.\r\n\r\n% TODO: and any instruction not listed has no effect? (same behaviour as an equal amount of NOP instructions)\r\n\\setlength\\columnsep{4em}\r\n\\begin{multicols}{3}\r\n{\r\n\t\\tt \r\n\t\\footnotesize\r\n\t\\begin{tabbing}\r\n\t00{\\qquad}{\\qquad}{\\quad}\\=NOP\\\\\r\n\t01 m n\\>LD BC,nm\\\\\r\n\t02\\>LD (BC),A\\\\\r\n\t03\\>INC BC\\\\\r\n\t04\\>INC B\\\\\r\n\t05\\>DEC B\\\\\r\n\t06 n\\>LD B,n\\\\\r\n\t07\\>RLCA\\\\\r\n\t08\\>EX AF,AF'\\\\\r\n\t09\\>ADD HL,BC\\\\\r\n\t0A\\>LD A,(BC)\\\\\r\n\t0B\\>DEC BC\\\\\r\n\t0C\\>INC C\\\\\r\n\t0D\\>DEC C\\\\\r\n\t0E n\\>LD C,n\\\\\r\n\t0F\\>RRCA\\\\\r\n\t10 e\\>DJNZ (PC+e)\\\\\r\n\t11 m n\\>LD DE,nm\\\\\r\n\t12\\>LD (DE),A\\\\\r\n\t13\\>INC DE\\\\\r\n\t14\\>INC D\\\\\r\n\t15\\>DEC D\\\\\r\n\t16 n\\>LD D,n\\\\\r\n\t17\\>RLA\\\\\r\n\t18 e\\>JR e\\\\\r\n\t19\\>ADD HL,DE\\\\\r\n\t1A\\>LD A,(DE)\\\\\r\n\t1B\\>DEC DE\\\\\r\n\t1C\\>INC E\\\\\r\n\t1D\\>DEC E\\\\\r\n\t1E n\\>LD E,n\\\\\r\n\t1F\\>RRA\\\\\r\n\t20 e\\>JR NZ,e\\\\\r\n\t21 m n\\>LD HL,nm\\\\\r\n\t22 m n\\>LD (nm),HL\\\\\r\n\t23\\>INC HL\\\\\r\n\t24\\>INC H\\\\\r\n\t25\\>DEC H\\\\\r\n\t26 n\\>LD H,n\\\\\r\n\t27\\>DAA\\\\\r\n\t28 e\\>JR Z,e\\\\\r\n\t29\\>ADD HL,HL\\\\\r\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ES 5,(IX+d),C\\UNDOC\\\\\r\n\tDDCB d AA\\>RES 5,(IX+d),D\\UNDOC\\\\\r\n\tDDCB d AB\\>RES 5,(IX+d),E\\UNDOC\\\\\r\n\tDDCB d AC\\>RES 5,(IX+d),H\\UNDOC\\\\\r\n\tDDCB d AD\\>RES 5,(IX+d),L\\UNDOC\\\\\r\n\tDDCB d AE\\>RES 5,(IX+d)\\\\\r\n\tDDCB d AF\\>RES 5,(IX+d),A\\UNDOC\\\\\r\n\tDDCB d B0\\>RES 6,(IX+d),B\\UNDOC\\\\\r\n\tDDCB d B1\\>RES 6,(IX+d),C\\UNDOC\\\\\r\n\tDDCB d B2\\>RES 6,(IX+d),D\\UNDOC\\\\\r\n\tDDCB d B3\\>RES 6,(IX+d),E\\UNDOC\\\\\r\n\tDDCB d B4\\>RES 6,(IX+d),H\\UNDOC\\\\\r\n\tDDCB d B5\\>RES 6,(IX+d),L\\UNDOC\\\\\r\n\tDDCB d B6\\>RES 6,(IX+d)\\\\\r\n\tDDCB d B7\\>RES 6,(IX+d),A\\UNDOC\\\\\r\n\tDDCB d B8\\>RES 7,(IX+d),B\\UNDOC\\\\\r\n\tDDCB d B9\\>RES 7,(IX+d),C\\UNDOC\\\\\r\n\tDDCB d BA\\>RES 7,(IX+d),D\\UNDOC\\\\\r\n\tDDCB d BB\\>RES 7,(IX+d),E\\UNDOC\\\\\r\n\tDDCB d BC\\>RES 7,(IX+d),H\\UNDOC\\\\\r\n\tDDCB d BD\\>RES 7,(IX+d),L\\UNDOC\\\\\r\n\tDDCB d BE\\>RES 7,(IX+d)\\\\\r\n\tDDCB d BF\\>RES 7,(IX+d),A\\UNDOC\\\\\r\n\tDDCB d C0\\>SET 0,(IX+d),B\\UNDOC\\\\\r\n\tDDCB d C1\\>SET 0,(IX+d),C\\UNDOC\\\\\r\n\tDDCB d C2\\>SET 0,(IX+d),D\\UNDOC\\\\\r\n\tDDCB d C3\\>SET 0,(IX+d),E\\UNDOC\\\\\r\n\tDDCB d C4\\>SET 0,(IX+d),H\\UNDOC\\\\\r\n\tDDCB d C5\\>SET 0,(IX+d),L\\UNDOC\\\\\r\n\tDDCB d C6\\>SET 0,(IX+d)\\\\\r\n\tDDCB d C7\\>SET 0,(IX+d),A\\UNDOC\\\\\r\n\tDDCB d C8\\>SET 1,(IX+d),B\\UNDOC\\\\\r\n\tDDCB d C9\\>SET 1,(IX+d),C\\UNDOC\\\\\r\n\tDDCB d CA\\>SET 1,(IX+d),D\\UNDOC\\\\\r\n\tDDCB d CB\\>SET 1,(IX+d),E\\UNDOC\\\\\r\n\tDDCB d CC\\>SET 1,(IX+d),H\\UNDOC\\\\\r\n\tDDCB d CD\\>SET 1,(IX+d),L\\UNDOC\\\\\r\n\tDDCB d CE\\>SET 1,(IX+d)\\\\\r\n\tDDCB d CF\\>SET 1,(IX+d),A\\UNDOC\\\\\r\n\tDDCB d D0\\>SET 2,(IX+d),B\\UNDOC\\\\\r\n\tDDCB d D1\\>SET 2,(IX+d),C\\UNDOC\\\\\r\n\tDDCB d D2\\>SET 2,(IX+d),D\\UNDOC\\\\\r\n\tDDCB d D3\\>SET 2,(IX+d),E\\UNDOC\\\\\r\n\tDDCB d D4\\>SET 2,(IX+d),H\\UNDOC\\\\\r\n\tDDCB d D5\\>SET 2,(IX+d),L\\UNDOC\\\\\r\n\tDDCB d D6\\>SET 2,(IX+d)\\\\\r\n\tDDCB d D7\\>SET 2,(IX+d),A\\UNDOC\\\\\r\n\tDDCB d D8\\>SET 3,(IX+d),B\\UNDOC\\\\\r\n\tDDCB d D9\\>SET 3,(IX+d),C\\UNDOC\\\\\r\n\tDDCB d DA\\>SET 3,(IX+d),D\\UNDOC\\\\\r\n\tDDCB d DB\\>SET 3,(IX+d),E\\UNDOC\\\\\r\n\tDDCB d DC\\>SET 3,(IX+d),H\\UNDOC\\\\\r\n\tDDCB d DD\\>SET 3,(IX+d),L\\UNDOC\\\\\r\n\tDDCB d DE\\>SET 3,(IX+d)\\\\\r\n\tDDCB d DF\\>SET 3,(IX+d),A\\UNDOC\\\\\r\n\tDDCB d E0\\>SET 4,(IX+d),B\\UNDOC\\\\\r\n\tDDCB d E1\\>SET 4,(IX+d),C\\UNDOC\\\\\r\n\tDDCB d E2\\>SET 4,(IX+d),D\\UNDOC\\\\\r\n\tDDCB d E3\\>SET 4,(IX+d),E\\UNDOC\\\\\r\n\tDDCB d E4\\>SET 4,(IX+d),H\\UNDOC\\\\\r\n\tDDCB d E5\\>SET 4,(IX+d),L\\UNDOC\\\\\r\n\tDDCB d E6\\>SET 4,(IX+d)\\\\\r\n\tDDCB d E7\\>SET 4,(IX+d),A\\UNDOC\\\\\r\n\tDDCB d E8\\>SET 5,(IX+d),B\\UNDOC\\\\\r\n\tDDCB d E9\\>SET 5,(IX+d),C\\UNDOC\\\\\r\n\tDDCB d EA\\>SET 5,(IX+d),D\\UNDOC\\\\\r\n\tDDCB d EB\\>SET 5,(IX+d),E\\UNDOC\\\\\r\n\tDDCB d EC\\>SET 5,(IX+d),H\\UNDOC\\\\\r\n\tDDCB d ED\\>SET 5,(IX+d),L\\UNDOC\\\\\r\n\tDDCB d EE\\>SET 5,(IX+d)\\\\\r\n\tDDCB d EF\\>SET 5,(IX+d),A\\UNDOC\\\\\r\n\tDDCB d F0\\>SET 6,(IX+d),B\\UNDOC\\\\\r\n\tDDCB d F1\\>SET 6,(IX+d),C\\UNDOC\\\\\r\n\tDDCB d F2\\>SET 6,(IX+d),D\\UNDOC\\\\\r\n\tDDCB d F3\\>SET 6,(IX+d),E\\UNDOC\\\\\r\n\tDDCB d F4\\>SET 6,(IX+d),H\\UNDOC\\\\\r\n\tDDCB d F5\\>SET 6,(IX+d),L\\UNDOC\\\\\r\n\tDDCB d F6\\>SET 6,(IX+d)\\\\\r\n\tDDCB d F7\\>SET 6,(IX+d),A\\UNDOC\\\\\r\n\tDDCB d F8\\>SET 7,(IX+d),B\\UNDOC\\\\\r\n\tDDCB d F9\\>SET 7,(IX+d),C\\UNDOC\\\\\r\n\tDDCB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\\\\\r\n\tED34 m n\\>ADD HL,nm\\ZXN\\\\\r\n\tED35 m n\\>ADD DE,nm\\ZXN\\\\\r\n\tED36 m n\\>ADD BC,nm\\ZXN\\\\\r\n\tED40\\>IN B,(C)\\\\\r\n\tED41\\>OUT (C),B\\\\\r\n\tED42\\>SBC HL,BC\\\\\r\n\tED43 m n\\>LD (nm),BC\\\\\r\n\tED44\\>NEG\\\\\r\n\tED45\\>RETN\\\\\r\n\tED46\\>IM 0\\\\\r\n\tED47\\>LD I,A\\\\\r\n\tED48\\>IN C,(C)\\\\\r\n\tED49\\>OUT (C),C\\\\\r\n\tED4A\\>ADC HL,BC\\\\\r\n\tED4B m n\\>LD BC,(nm)\\\\\r\n\tED4C\\>NEG\\UNDOC\\\\\r\n\tED4D\\>RETI\\\\\r\n\tED4E\\>IM 0\\UNDOC\\\\\r\n\tED4F\\>LD R,A\\\\\r\n\tED50\\>IN D,(C)\\\\\r\n\tED51\\>OUT (C),D\\\\\r\n\tED52\\>SBC HL,DE\\\\\r\n\tED53 m n\\>LD (nm),DE\\\\\r\n\tED54\\>NEG\\UNDOC\\\\\r\n\tED55\\>RETN\\UNDOC\\\\\r\n\tED56\\>IM 1\\\\\r\n\tED57\\>LD A,I\\\\\r\n\tED58\\>IN E,(C)\\\\\r\n\tED59\\>OUT (C),E\\\\\r\n\tED5A\\>ADC HL,DE\\\\\r\n\tED5B m n\\>LD DE,(nm)\\\\\r\n\tED5C\\>NEG\\UNDOC\\\\\r\n\tED5D\\>RETN\\UNDOC\\\\\r\n\tED5E\\>IM 2\\\\\r\n\tED5F\\>LD A,R\\\\\r\n\tED60\\>IN H,(C)\\\\\r\n\tED61\\>OUT (C),H\\\\\r\n\tED62\\>SBC HL,HL\\\\\r\n\tED63 m n\\>LD (nm),HL\\\\\r\n\tED64\\>NEG\\UNDOC\\\\\r\n\tED65\\>RETN\\UNDOC\\\\\r\n\tED66\\>IM 0\\UNDOC\\\\\r\n\tED67\\>RRD\\\\\r\n\tED68\\>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),B\\UNDOC\\\\\r\n\tFDCB d A9\\>RES 5,(IY+d),C\\UNDOC\\\\\r\n\tFDCB d AA\\>RES 5,(IY+d),D\\UNDOC\\\\\r\n\tFDCB d AB\\>RES 5,(IY+d),E\\UNDOC\\\\\r\n\tFDCB d AC\\>RES 5,(IY+d),H\\UNDOC\\\\\r\n\tFDCB d AD\\>RES 5,(IY+d),L\\UNDOC\\\\\r\n\tFDCB d AE\\>RES 5,(IY+d)\\\\\r\n\tFDCB d AF\\>RES 5,(IY+d),A\\UNDOC\\\\\r\n\tFDCB d B0\\>RES 6,(IY+d),B\\UNDOC\\\\\r\n\tFDCB d B1\\>RES 6,(IY+d),C\\UNDOC\\\\\r\n\tFDCB d B2\\>RES 6,(IY+d),D\\UNDOC\\\\\r\n\tFDCB d B3\\>RES 6,(IY+d),E\\UNDOC\\\\\r\n\tFDCB d B4\\>RES 6,(IY+d),H\\UNDOC\\\\\r\n\tFDCB d B5\\>RES 6,(IY+d),L\\UNDOC\\\\\r\n\tFDCB d B6\\>RES 6,(IY+d)\\\\\r\n\tFDCB d B7\\>RES 6,(IY+d),A\\UNDOC\\\\\r\n\tFDCB d B8\\>RES 7,(IY+d),B\\UNDOC\\\\\r\n\tFDCB d B9\\>RES 7,(IY+d),C\\UNDOC\\\\\r\n\tFDCB d BA\\>RES 7,(IY+d),D\\UNDOC\\\\\r\n\tFDCB d BB\\>RES 7,(IY+d),E\\UNDOC\\\\\r\n\tFDCB d BC\\>RES 7,(IY+d),H\\UNDOC\\\\\r\n\tFDCB d BD\\>RES 7,(IY+d),L\\UNDOC\\\\\r\n\tFDCB d BE\\>RES 7,(IY+d)\\\\\r\n\tFDCB d BF\\>RES 7,(IY+d),A\\UNDOC\\\\\r\n\tFDCB d C0\\>SET 0,(IY+d),B\\UNDOC\\\\\r\n\tFDCB d C1\\>SET 0,(IY+d),C\\UNDOC\\\\\r\n\tFDCB d C2\\>SET 0,(IY+d),D\\UNDOC\\\\\r\n\tFDCB d C3\\>SET 0,(IY+d),E\\UNDOC\\\\\r\n\tFDCB d C4\\>SET 0,(IY+d),H\\UNDOC\\\\\r\n\tFDCB d C5\\>SET 0,(IY+d),L\\UNDOC\\\\\r\n\tFDCB d C6\\>SET 0,(IY+d)\\\\\r\n\tFDCB d C7\\>SET 0,(IY+d),A\\UNDOC\\\\\r\n\tFDCB d C8\\>SET 1,(IY+d),B\\UNDOC\\\\\r\n\tFDCB d C9\\>SET 1,(IY+d),C\\UNDOC\\\\\r\n\tFDCB d CA\\>SET 1,(IY+d),D\\UNDOC\\\\\r\n\tFDCB d CB\\>SET 1,(IY+d),E\\UNDOC\\\\\r\n\tFDCB d CC\\>SET 1,(IY+d),H\\UNDOC\\\\\r\n\tFDCB d CD\\>SET 1,(IY+d),L\\UNDOC\\\\\r\n\tFDCB d CE\\>SET 1,(IY+d)\\\\\r\n\tFDCB d CF\\>SET 1,(IY+d),A\\UNDOC\\\\\r\n\tFDCB d D0\\>SET 2,(IY+d),B\\UNDOC\\\\\r\n\tFDCB d D1\\>SET 2,(IY+d),C\\UNDOC\\\\\r\n\tFDCB d D2\\>SET 2,(IY+d),D\\UNDOC\\\\\r\n\tFDCB d D3\\>SET 2,(IY+d),E\\UNDOC\\\\\r\n\tFDCB d D4\\>SET 2,(IY+d),H\\UNDOC\\\\\r\n\tFDCB d D5\\>SET 2,(IY+d),L\\UNDOC\\\\\r\n\tFDCB d D6\\>SET 2,(IY+d)\\\\\r\n\tFDCB d D7\\>SET 2,(IY+d),A\\UNDOC\\\\\r\n\tFDCB d D8\\>SET 3,(IY+d),B\\UNDOC\\\\\r\n\tFDCB d D9\\>SET 3,(IY+d),C\\UNDOC\\\\\r\n\tFDCB d DA\\>SET 3,(IY+d),D\\UNDOC\\\\\r\n\tFDCB d DB\\>SET 3,(IY+d),E\\UNDOC\\\\\r\n\tFDCB d DC\\>SET 3,(IY+d),H\\UNDOC\\\\\r\n\tFDCB d DD\\>SET 3,(IY+d),L\\UNDOC\\\\\r\n\tFDCB d DE\\>SET 3,(IY+d)\\\\\r\n\tFDCB d DF\\>SET 3,(IY+d),A\\UNDOC\\\\\r\n\tFDCB d E0\\>SET 4,(IY+d),B\\UNDOC\\\\\r\n\tFDCB d E1\\>SET 4,(IY+d),C\\UNDOC\\\\\r\n\tFDCB d E2\\>SET 4,(IY+d),D\\UNDOC\\\\\r\n\tFDCB d E3\\>SET 4,(IY+d),E\\UNDOC\\\\\r\n\tFDCB d E4\\>SET 4,(IY+d),H\\UNDOC\\\\\r\n\tFDCB d E5\\>SET 4,(IY+d),L\\UNDOC\\\\\r\n\tFDCB d E6\\>SET 4,(IY+d)\\\\\r\n\tFDCB d E7\\>SET 4,(IY+d),A\\UNDOC\\\\\r\n\tFDCB d E8\\>SET 5,(IY+d),B\\UNDOC\\\\\r\n\tFDCB d E9\\>SET 5,(IY+d),C\\UNDOC\\\\\r\n\tFDCB d EA\\>SET 5,(IY+d),D\\UNDOC\\\\\r\n\tFDCB d EB\\>SET 5,(IY+d),E\\UNDOC\\\\\r\n\tFDCB d EC\\>SET 5,(IY+d),H\\UNDOC\\\\\r\n\tFDCB d ED\\>SET 5,(IY+d),L\\UNDOC\\\\\r\n\tFDCB d EE\\>SET 5,(IY+d)\\\\\r\n\tFDCB d EF\\>SET 5,(IY+d),A\\UNDOC\\\\\r\n\tFDCB d F0\\>SET 6,(IY+d),B\\UNDOC\\\\\r\n\tFDCB d F1\\>SET 6,(IY+d),C\\UNDOC\\\\\r\n\tFDCB d F2\\>SET 6,(IY+d),D\\UNDOC\\\\\r\n\tFDCB d F3\\>SET 6,(IY+d),E\\UNDOC\\\\\r\n\tFDCB d F4\\>SET 6,(IY+d),H\\UNDOC\\\\\r\n\tFDCB d F5\\>SET 6,(IY+d),L\\UNDOC\\\\\r\n\tFDCB d F6\\>SET 6,(IY+d)\\\\\r\n\tFDCB d F7\\>SET 6,(IY+d),A\\UNDOC\\\\\r\n\tFDCB d F8\\>SET 7,(IY+d),B\\UNDOC\\\\\r\n\tFDCB d F9\\>SET 7,(IY+d),C\\UNDOC\\\\\r\n\tFDCB d FA\\>SET 7,(IY+d),D\\UNDOC\\\\\r\n\tFDCB d FB\\>SET 7,(IY+d),E\\UNDOC\\\\\r\n\tFDCB d FC\\>SET 7,(IY+d),H\\UNDOC\\\\\r\n\tFDCB d FD\\>SET 7,(IY+d),L\\UNDOC\\\\\r\n\tFDCB d FE\\>SET 7,(IY+d)\\\\\r\n\tFDCB d FF\\>SET 7,(IY+d),A\\UNDOC\\\\\r\n\tFDE1\\>POP IY\\\\\r\n\tFDE3\\>EX (SP),IY\\\\\r\n\tFDE5\\>PUSH IY\\\\\r\n\tFDE9\\>JP (IY)\\\\\r\n\tFDF9\\>LD SP,IY\\\\\r\n\tFE n\\>CP n\\\\\r\n\tFF\\>RST 38H\r\n\\end{tabbing}\r\n}\r\n\\end{multicols}\r\n\\normalsize\r\n\r\n\\pagebreak\r\n\\IntentionallyEmpty\r\n\\pagebreak\r\n"
  },
  {
    "path": "chapter-introduction.tex",
    "content": "\\chapter{Introduction}\r\n\r\n% ████████████████████████████████████████████████████████████████████████████████████\r\n% █░░░░░░░░░░█░░░░░░██████████░░░░░░█░░░░░░░░░░░░░░█░░░░░░░░░░░░░░░░███░░░░░░░░░░░░░░█\r\n% █░░▄▀▄▀▄▀░░█░░▄▀░░░░░░░░░░██░░▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀▄▀░░███░░▄▀▄▀▄▀▄▀▄▀░░█\r\n% █░░░░▄▀░░░░█░░▄▀▄▀▄▀▄▀▄▀░░██░░▄▀░░█░░░░░░▄▀░░░░░░█░░▄▀░░░░░░░░▄▀░░███░░▄▀░░░░░░▄▀░░█\r\n% ███░░▄▀░░███░░▄▀░░░░░░▄▀░░██░░▄▀░░█████░░▄▀░░█████░░▄▀░░████░░▄▀░░███░░▄▀░░██░░▄▀░░█\r\n% ███░░▄▀░░███░░▄▀░░██░░▄▀░░██░░▄▀░░█████░░▄▀░░█████░░▄▀░░░░░░░░▄▀░░███░░▄▀░░██░░▄▀░░█\r\n% ███░░▄▀░░███░░▄▀░░██░░▄▀░░██░░▄▀░░█████░░▄▀░░█████░░▄▀▄▀▄▀▄▀▄▀▄▀░░███░░▄▀░░██░░▄▀░░█\r\n% ███░░▄▀░░███░░▄▀░░██░░▄▀░░██░░▄▀░░█████░░▄▀░░█████░░▄▀░░░░░░▄▀░░░░███░░▄▀░░██░░▄▀░░█\r\n% ███░░▄▀░░███░░▄▀░░██░░▄▀░░░░░░▄▀░░█████░░▄▀░░█████░░▄▀░░██░░▄▀░░█████░░▄▀░░██░░▄▀░░█\r\n% █░░░░▄▀░░░░█░░▄▀░░██░░▄▀▄▀▄▀▄▀▄▀░░█████░░▄▀░░█████░░▄▀░░██░░▄▀░░░░░░█░░▄▀░░░░░░▄▀░░█\r\n% █░░▄▀▄▀▄▀░░█░░▄▀░░██░░░░░░░░░░▄▀░░█████░░▄▀░░█████░░▄▀░░██░░▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█\r\n% █░░░░░░░░░░█░░░░░░██████████░░░░░░█████░░░░░░█████░░░░░░██░░░░░░░░░░█░░░░░░░░░░░░░░█\r\n% ████████████████████████████████████████████████████████████████████████████████████\r\n\r\n\\ChapterTOC[]\t% don't apply default style for introduction (we want to keep using the simple style without headers)\r\n\r\n\r\n\\section{Where to get this document}\r\n\r\n\\BookTitle ~is available as coil bound printed book on\r\n\r\n\\url{https://bit.ly/zx-next-assembly-dev-guide}\r\n\r\nYou can also download it as PDF document from GitHub where you can also find its source \\LaTeX ~form so you can edit it to your preference\r\n\r\n\\url{https://github.com/tomaz/zx-next-dev-guide}\r\n\r\n\r\n\\section{Companion Source Code}\r\n\r\nGitHub repository also includes companion source code. Sample projects were created in a cross-platform environment on Windows so instructions on the following page are written with these in mind. All programs mentioned are available on Linux and macOS; you should be able to run everything on those platforms too, but likely with some deviations. Regardless, these are merely suggestions, you should be able to use your preferred editor or tools.\r\n\r\n\r\n\\pagebreak % we want list of all tools and software to be on the same page\r\n\\begin{description}[style=unboxed,leftmargin=0cm]\r\n\t\\item[Visual Studio Code (\\url{https://code.visualstudio.com/})]\\hfill\r\n\t\r\n\tMy code editor of choice! I use it with the following plugins:\r\n\r\n\t\\begin{description}[topsep=1pt,labelindent=2em,leftmargin=2em]\r\n\t\t\\item[DeZog plugin (\\url{https://github.com/maziac/DeZog})]\\hfill\r\n\t\r\n\t\tEssential plugin; features list is too large to even attempt to enumerate here but essentially turns VS Code into a fully-fledged debugging environment.\r\n\r\n\t\t\\item[Z80 Macro-Assembler (\\url{https://github.com/mborik/z80-macroasm-vscode})]\\hfill\r\n\t\t\r\n\t\tAnother must-have plugin for the Z80 assembly developer; syntax highlighting, code formatting and code completion, renaming etc.\r\n\r\n\t\t\\item[Z80 Instruction Set (\\url{https://github.com/maziac/z80-instruction-set})]\\hfill\r\n\t\t\r\n\t\tAdds mouse hover action above any Z80N instruction for quick info.\r\n\r\n\t\t\\item[Z80 Assembly meter (\\url{https://github.com/theNestruo/z80-asm-meter-vscode})]\\hfill\r\n\t\t\r\n\t\tShows the sum of clock cycles and machine code bytes for all instructions in the current selection.\r\n\t\\end{description}\r\n\t\r\n\t\\item[sjasmplus 1.18.2 (\\url{https://github.com/z00m128/sjasmplus})]\\hfill\r\n\r\n\tSource code includes sjasmplus specific directives for creating {\\tt nex} files at the top and bottom of {\\tt main.asm} files; if you use a different compiler, you may need to tweak or comment them out.\r\n\r\n\tVS Code projects are set up to expect binaries in a specific folder. You will need to download and copy so that {\\tt sjasmplus.exe} is located in {\\tt Tools/sjasmplus}.\r\n\r\n\t\\item[CSpect 2.13.0 (\\url{http://cspect.org})]\\hfill\r\n\r\n\tSimilar to sjasmplus, CSpect binaries are expected in a specific folder. To install, download and copy so that {\\tt CSpect.exe} is located in {\\tt Tools/CSpect} folder.\r\n\r\n\t\\item[CSpect Next Image (\\url{http://www.zxspectrumnext.online/\\#sd})]\\hfill\r\n\r\n\tYou will also need to download the ZX Spectrum Next image file and copy it to the folder where {\\tt CSpect.exe} is located. I use a 2GB image, hence VS Code project file is configured for that. If you use a different image, make sure to update {\\tt .vscode/tasks.json} file.\r\n\t\r\n\t\\item[DeZog CSpect plugin (\\url{https://github.com/maziac/DeZogPlugin})]\\hfill\r\n\r\n\tDeZog requires this plugin to be installed to work with CSpect. To install, download and copy to the same folder where {\\tt CSpect.exe} is located. Make sure the plugin version matches the DeZog version!\r\n\r\n\\end{description}\r\n\r\n{\r\n\t\\footnotesize\r\n\r\n\t\\begin{description}[topsep=1pt,itemsep=1pt,labelindent=0pt,leftmargin=0pt]\t\t\r\n\t\t\\item[Note:] you need to have CSpect launched before you can run the samples. I created couple tasks\\footnotemark~for it: open VS Code command palette ({\\tt Ctrl+Shift+P} shortcut on my installation) and select \\textit{Tasks: Run Task} option, then select \\textit{Launch CSpect} from list. This is only needed once. Afterwards, use \\textit{Run \\textgreater ~Start Debugging} from the main menu to compile and launch the program.\r\n\r\n\t\t\\item[Note:] default DeZog port of 11000 doesn't work on my computer, so I changed it to 13000. This needs to be managed in 2 places: {\\tt .vscode/launch.json} and on the plugin side. Companion code repository already includes the setup needed, including {\\tt DeZogPlugin.dll.config} file, so it should work out of the box.\r\n\t\r\n\t\t\\item[Note:] sample projects are ready for ZEsarUX as well, select the option from debugging panel in VS Code.\r\n\t\\end{description}\r\n}\r\n\r\n\\footnotetext{\r\n\tWorkspace tasks seem to not be supported in some later VS Code versions. If this is the case for you, copy them to user tasks (shared between projects): open {\\tt .vscode/tasks.json} file from any of the sample projects, scroll down a little and copy {\\tt Launch CSpect} and {\\tt Launch ZEsarUX} tasks to user tasks. You can do this all from within VS Code. To open the user tasks file, open the command palette and start typing {\\tt open user tasks}, then select the option from the drop-down menu.\r\n}\r\n\r\n\r\n\\pagebreak % we want next section to be on its own page, fully visible when listing physical book\r\n\\section{Background, Contact \\& Feedback}\r\n\r\nMy first computer was ZX Spectrum 48K. Initially, it was only used to play games, but my creative mind soon set me on the path of building simple games of my own in BASIC. While too young to master assembler at that point, the idea stayed with me. ZX Spectrum Next revived my wish to learn Z80 and return to writing games for the platform.\r\n    \r\nMy original intent was to have coil bound list of all ZX Next instructions so I can quickly compare. However, after finding Z80 Undocumented online, it felt like a perfect starting point. And with additional information included, it also encouraged me to extend the mere instructions list with the Next specific chapters. In a way, this book represents my notes as I was learning those topics. That being said, I did my best to present information as a reference to keep the book relevant.\r\n\r\nDuring the process, I wanted to tweak or unify the look of various elements. For example instruction tables. Original \\LaTeX ~code required applying changes to each and every instance. As \\LaTeX ~is all but a programming language, I extracted individual elements into reusable commands which allowed me to tweak appearance in a single place and apply it to the whole document. I also converted almost all drawings from {\\tt picture} to {\\tt tikz} as it's far more adaptable. With this, I almost completely restructured the original \\LaTeX ~code. While this took a lot of time and effort, it allowed me to quickly iterate later on. I really love this aspect of \\LaTeX!\r\n\r\nEnglish is not my native tongue. And our mind is not the best tool to correct our own work either. Since I can't afford a professional proofreader, mistakes are a matter of fact I'm afraid. If you spot something or want to contribute, feel free to open an issue on GitHub. Pull requests are also welcome! If you want to contribute, but are unsure of what, check the accompanying readme file on GitHub for ideas. If you want to discuss in advance, or for anything else, you can find me on email \\email{tkragelj}{gmail}{com} or Twitter {\\tt @tomsbarks}.\r\n\r\nThat being said, I hope you'll enjoy reading this document as much as I did writing it!\r\n\r\nSincerely, \\AuthorName\r\n\r\n\r\n\\pagebreak\r\n\\section{Z80 Undocumented}\r\n\r\nAs the saying ``standing on the shoulders of giants'' goes, this book is also based on pre-existing work from Jan and Sean. While my work is ZX Spectrum Next developer-oriented, their original project was more focused on hardware perspective, for Z80 emulator developers.\r\n\r\nIf interested, you can find it at \\url{http://www.myquest.nl/z80undocumented/}.\r\n\r\n\\begin{description}[style=unboxed,leftmargin=0cm]\r\n\t\\item[Jan]\\hfill\r\n\t\r\n\t\\url{http://www.myquest.nl/z80undocumented/}\\\\\r\n\tEmail \\email{jw}{dds}{nl}\\\\\r\n\tTwitter \\twitter{janwilmans}\r\n\r\n\tInterested in emulation for a long time, but a few years after Sean started writing this document, I have also started writing my own MSX emulator in 2003 and I've used this document quite a lot. Now (2005) the Z80 emulation is nearing perfection, I decided to add what extra I have learned and comments various people have sent to Sean, to this document.\r\n\r\n\tI have restyled the document (although very little) to fit my personal needs and I have checked a lot of things that were already in here.\r\n \r\n\t\\item[Sean]\\hfill\r\n\r\n\t\\url{http://www.msxnet.org/}\r\n\t\r\n\tEver since I first started working on an MSX emulator, I've been very interested in getting the emulation absolutely correct - including the undocumented features. Not just to make sure that all games work, but also to make sure that if a program crashes, it crashes exactly the same way if running on an emulator as on the real thing. Only then is perfection achieved.\r\n\r\n\tI set about collecting information. I found pieces of information on the Internet, but not everything there is to know. So I tried to fill in the gaps, the results of which I put on my website. Various people have helped since then; this is the result of all those efforts and to my knowledge, this document is the most complete.\r\n\\end{description}\r\n\r\n\r\n\\pagebreak\r\n\\section{ChangeLog}\r\n\r\n\\begin{description}\r\n\r\n\t% when adding versions:\r\n\t% 1. replace `\\LatestRevisionName` with value from macro definition in `defines.tex`\r\n\t% 2. update `\\LatestRevisionName` with new value in `defines.tex`\r\n\t% 3. create new entry here using now updated values (copy item definition from previous version)\r\n\r\n\t\\item[\\LatestRevisionName]\r\n\tCorrections, updates and improvements. Main focus on making instruction up close chapter more useful. Each instruction now includes description of effects on flags and where makes sense, includes additional description or code examples.\r\n\r\n\t\\item[\\RevisionTwoName]\r\n\tCorrections and updates based on community comments - with special thanks to Peter Ped Helcmanovsky and Alvin Albrecht. Restructured and updated many ZX Next chapters: added sample code to ports, completely restructured memory map and paging, added new palette chapter including 9-bit palette handling, updated ULA with shadow screen info and added Next extended keyboard, DMA, Copper and Hardware IM2 sections. Other than some cosmetic changes: redesigned title, copyright pages etc. Also, many behind the scenes improvements like splitting previous huge single \\LaTeX~ file into multiple per-chapter/section. This is not only more manageable but can also compile much faster.\r\n\r\n\t\\item[\\RevisionOneName]\r\n\tAdded ZX Spectrum Next information and instructions and restructured text for better maintainability and readability.\r\n\r\n\t\\item[18 September 2005]\r\n\tCorrected a textual typo in the R register and memory refresh section, thanks to David Aubespin. Corrected the contradiction in the {\\tt DAA} section saying the \\FlagNF{} flag was both affected and unchanged :) thanks to Dan Meir. Added an error in official documentation about the way Interrupt Mode 2 works, thanks to Aaldert Dekker.\r\n\t\r\n\t\\item[15 June 2005]\r\n\tCorrected improper notation of {\\tt JP x,nn} mnemonics in opcode list, thanks to Laurens Holst. Corrected a mistake in the {\\tt INI}, {\\tt INIR}, {\\tt IND}, {\\tt INDR} section and documented a mistake in official Z80 documentation concerning Interrupt Mode 2, thanks to Boris Donko. Thanks to Aaldert Dekker for his ideas, for verifying many assumptions and for writing instruction exercisers for various instruction groups.\r\n\r\n\t\\item[18 May 2005]\r\n\tAdded an alphabetical list of instructions for easy reference and corrected an error in the 16-bit arithmetic section, {\\tt SBC HL,nn} sets the NF flag just like other subtraction instructions, thanks to Fredrik Olssen for pointing that out.\r\n\r\n\t\\item[4 April 2005]\r\n\tI (Jan \\email{jw}{dds}{nl}) will be maintaining this document from this version on. I restyled the document to fix the page numbering issues, corrected an error in the I/O Block Instructions section, added graphics for the {\\tt RLD} and {\\tt RRD} instructions and corrected the spelling in several places.\r\n\r\n\t\\item[20 November 2003]\r\n\tAgain, thanks to Ramsoft, added PV flag to {\\tt OUTI}, {\\tt INI} and friends. Minor fix to {\\tt DAA} tables, other minor fixes.\r\n\r\n\t\\item[13 November 2003]\r\n\tThanks to Ramsoft, add the correct tables for the {\\tt DAA} instruction (section \\XRef{z80_undocumented_instruction_daa}). Minor corrections \\& typos, thanks to Jim Battle, David Sutherland and most of all Fred Limouzin.\r\n\r\n\t\\item[September 2001]\r\n\tPrevious documents I had written were in plain text and Microsoft Word, which I now find very embarrassing, so I decided to combine them all and use {\\LaTeX}. Apart from a full re-write, the only changed information is ``Power on defaults'' (section \\XRef{z80_power_on_defaults}) and the algorithm for the CF and HF flags for {\\tt OTIR} and friends (section \\XRef{z80_undocumented_instructions_io_block}).\r\n\r\n\\end{description}\r\n\r\n\r\n\\pagebreak\r\n\\IntentionallyEmpty\r\n\\pagebreak\r\n"
  },
  {
    "path": "chapter-license.tex",
    "content": "\\chapter{GNU Free Documentation License}\r\n\\label{gfdl}\r\n\r\n\r\n% ██████████████████████████████████████████\r\n% █░░░░░░█████████░░░░░░░░░░█░░░░░░░░░░░░░░█\r\n% █░░▄▀░░█████████░░▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█\r\n% █░░▄▀░░█████████░░░░▄▀░░░░█░░▄▀░░░░░░░░░░█\r\n% █░░▄▀░░███████████░░▄▀░░███░░▄▀░░█████████\r\n% █░░▄▀░░███████████░░▄▀░░███░░▄▀░░█████████\r\n% █░░▄▀░░███████████░░▄▀░░███░░▄▀░░█████████\r\n% █░░▄▀░░███████████░░▄▀░░███░░▄▀░░█████████\r\n% █░░▄▀░░███████████░░▄▀░░███░░▄▀░░█████████\r\n% █░░▄▀░░░░░░░░░░█░░░░▄▀░░░░█░░▄▀░░░░░░░░░░█\r\n% █░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█\r\n% █░░░░░░░░░░░░░░█░░░░░░░░░░█░░░░░░░░░░░░░░█\r\n% ██████████████████████████████████████████\r\n\r\n\\begingroup\r\n\t\\small\r\n\r\n\tVersion 1.1, March 2000\\\\\r\n\r\n\tCopyright \\copyright\\ 2000  Free Software Foundation, Inc.\\\\\r\n\t\t59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\\\\\r\n\tEveryone is permitted to copy and distribute verbatim copies\r\n\tof this license document, but changing it is not allowed.\r\n\r\n\t\\section*{Preamble}\r\n\r\n\tThe purpose of this License is to make a manual, textbook, or other\r\n\twritten document ``free'' in the sense of freedom: to assure everyone\r\n\tthe effective freedom to copy and redistribute it, with or without\r\n\tmodifying it, either commercially or non-commercially.  Secondarily,\r\n\tthis License preserves for the author and publisher a way to get\r\n\tcredit for their work, while not being considered responsible for\r\n\tmodifications made by others.\r\n\r\n\tThis License is a kind of ``copyleft'', which means that derivative\r\n\tworks of the document must themselves be free in the same sense.  It\r\n\tcomplements the GNU General Public License, which is a copyleft\r\n\tlicense designed for free software.\r\n\r\n\tWe have designed this License in order to use it for manuals for free\r\n\tsoftware, because free software needs free documentation: a free\r\n\tprogram should come with manuals providing the same freedoms that the\r\n\tsoftware does.  But this License is not limited to software manuals;\r\n\tit can be used for any textual work, regardless of subject matter or\r\n\twhether it is published as a printed book.  We recommend this License\r\n\tprincipally for works whose purpose is instruction or reference.\r\n\r\n\t\\section{Applicability and Definitions}\r\n\r\n\tThis License applies to any manual or other work that contains a\r\n\tnotice placed by the copyright holder saying it can be distributed\r\n\tunder the terms of this License.  The ``Document'', below, refers to any\r\n\tsuch manual or work.  Any member of the public is a licensee, and is\r\n\taddressed as ``you''.\r\n\r\n\tA ``Modified Version'' of the Document means any work containing the\r\n\tDocument or a portion of it, either copied verbatim, or with\r\n\tmodifications and/or translated into another language.\r\n\r\n\tA ``Secondary Section'' is a named appendix or a front-matter section of\r\n\tthe Document that deals exclusively with the relationship of the\r\n\tpublishers or authors of the Document to the Document's overall subject\r\n\t(or to related matters) and contains nothing that could fall directly\r\n\twithin that overall subject.  (For example, if the Document is in part a\r\n\ttextbook of mathematics, a Secondary Section may not explain any\r\n\tmathematics.)  The relationship could be a matter of historical\r\n\tconnection with the subject or with related matters, or of legal,\r\n\tcommercial, philosophical, ethical or political position regarding\r\n\tthem.\r\n\r\n\tThe ``Invariant Sections'' are certain Secondary Sections whose titles\r\n\tare designated, as being those of Invariant Sections, in the notice\r\n\tthat says that the Document is released under this License.\r\n\r\n\tThe ``Cover Texts'' are certain short passages of text that are listed,\r\n\tas Front-Cover Texts or Back-Cover Texts, in the notice that says that\r\n\tthe Document is released under this License.\r\n\r\n\tA ``Transparent'' copy of the Document means a machine-readable copy,\r\n\trepresented in a format whose specification is available to the\r\n\tgeneral public, whose contents can be viewed and edited directly and\r\n\tstraightforwardly with generic text editors or (for images composed of\r\n\tpixels) generic paint programs or (for drawings) some widely available\r\n\tdrawing editor, and that is suitable for input to text formatters or\r\n\tfor automatic translation to a variety of formats suitable for input\r\n\tto text formatters.  A copy made in an otherwise Transparent file\r\n\tformat whose mark-up has been designed to thwart or discourage\r\n\tsubsequent modification by readers is not Transparent.  A copy that is\r\n\tnot ``Transparent'' is called ``Opaque''.\r\n\r\n\tExamples of suitable formats for Transparent copies include plain\r\n\tASCII without mark-up, Texinfo input format, \\LaTeX~input format, SGML\r\n\tor XML using a publicly available DTD, and standard-conforming simple\r\n\tHTML designed for human modification.  Opaque formats include\r\n\tPostScript, PDF, proprietary formats that can be read and edited only\r\n\tby proprietary word processors, SGML or XML for which the DTD and/or\r\n\tprocessing tools are not generally available, and the\r\n\tmachine-generated HTML produced by some word processors for output\r\n\tpurposes only.\r\n\r\n\tThe ``Title Page'' means, for a printed book, the title page itself,\r\n\tplus such following pages as are needed to hold, legibly, the material\r\n\tthis License requires to appear in the title page.  For works in\r\n\tformats which do not have any title page as such, ``Title Page'' means\r\n\tthe text near the most prominent appearance of the work's title,\r\n\tpreceding the beginning of the body of the text.\r\n\r\n\r\n\t\\section{Verbatim Copying}\r\n\r\n\tYou may copy and distribute the Document in any medium, either\r\n\tcommercially or non-commercially, provided that this License, the\r\n\tcopyright notices, and the license notice saying this License applies\r\n\tto the Document are reproduced in all copies, and that you add no other\r\n\tconditions whatsoever to those of this License.  You may not use\r\n\ttechnical measures to obstruct or control the reading or further\r\n\tcopying of the copies you make or distribute.  However, you may accept\r\n\tcompensation in exchange for copies.  If you distribute a large enough\r\n\tnumber of copies you must also follow the conditions in section 3.\r\n\r\n\tYou may also lend copies, under the same conditions stated above, and\r\n\tyou may publicly display copies.\r\n\r\n\r\n\t\\section{Copying in Quantity}\r\n\r\n\tIf you publish printed copies of the Document numbering more than 100,\r\n\tand the Document's license notice requires Cover Texts, you must enclose\r\n\tthe copies in covers that carry, clearly and legibly, all these Cover\r\n\tTexts: Front-Cover Texts on the front cover, and Back-Cover Texts on\r\n\tthe back cover.  Both covers must also clearly and legibly identify\r\n\tyou as the publisher of these copies.  The front cover must present\r\n\tthe full title with all words of the title equally prominent and\r\n\tvisible.  You may add other material on the covers in addition.\r\n\tCopying with changes limited to the covers, as long as they preserve\r\n\tthe title of the Document and satisfy these conditions, can be treated\r\n\tas verbatim copying in other respects.\r\n\r\n\tIf the required texts for either cover are too voluminous to fit\r\n\tlegibly, you should put the first ones listed (as many as fit\r\n\treasonably) on the actual cover, and continue the rest onto adjacent\r\n\tpages.\r\n\r\n\tIf you publish or distribute Opaque copies of the Document numbering\r\n\tmore than 100, you must either include a machine-readable Transparent\r\n\tcopy along with each Opaque copy, or state in or with each Opaque copy\r\n\ta publicly-accessible computer-network location containing a complete\r\n\tTransparent copy of the Document, free of added material, which the\r\n\tgeneral network-using public has access to download anonymously at no\r\n\tcharge using public-standard network protocols.  If you use the latter\r\n\toption, you must take reasonably prudent steps, when you begin\r\n\tdistribution of Opaque copies in quantity, to ensure that this\r\n\tTransparent copy will remain thus accessible at the stated location\r\n\tuntil at least one year after the last time you distribute an Opaque\r\n\tcopy (directly or through your agents or retailers) of that edition to\r\n\tthe public.\r\n\r\n\tIt is requested, but not required, that you contact the authors of the\r\n\tDocument well before redistributing any large number of copies, to give\r\n\tthem a chance to provide you with an updated version of the Document.\r\n\r\n\r\n\t\\section{Modifications}\r\n\r\n\tYou may copy and distribute a Modified Version of the Document under\r\n\tthe conditions of sections 2 and 3 above, provided that you release\r\n\tthe Modified Version under precisely this License, with the Modified\r\n\tVersion filling the role of the Document, thus licensing distribution\r\n\tand modification of the Modified Version to whoever possesses a copy\r\n\tof it.  In addition, you must do these things in the Modified Version:\r\n\r\n\t\\begin{itemize}\r\n\r\n\t\\item Use in the Title Page (and on the covers, if any) a title distinct\r\n\tfrom that of the Document, and from those of previous versions\r\n\t(which should, if there were any, be listed in the History section\r\n\tof the Document).  You may use the same title as a previous version\r\n\tif the original publisher of that version gives permission.\r\n\t\\item List on the Title Page, as authors, one or more persons or entities\r\n\tresponsible for authorship of the modifications in the Modified\r\n\tVersion, together with at least five of the principal authors of the\r\n\tDocument (all of its principal authors, if it has less than five).\r\n\t\\item State on the Title page the name of the publisher of the\r\n\tModified Version, as the publisher.\r\n\t\\item Preserve all the copyright notices of the Document.\r\n\t\\item Add an appropriate copyright notice for your modifications\r\n\tadjacent to the other copyright notices.\r\n\t\\item Include, immediately after the copyright notices, a license notice\r\n\tgiving the public permission to use the Modified Version under the\r\n\tterms of this License, in the form shown in the Addendum below.\r\n\t\\item Preserve in that license notice the full lists of Invariant Sections\r\n\tand required Cover Texts given in the Document's license notice.\r\n\t\\item Include an unaltered copy of this License.\r\n\t\\item Preserve the section entitled ``History'', and its title, and add to\r\n\tit an item stating at least the title, year, new authors, and\r\n\tpublisher of the Modified Version as given on the Title Page.  If\r\n\tthere is no section entitled ``History'' in the Document, create one\r\n\tstating the title, year, authors, and publisher of the Document as\r\n\tgiven on its Title Page, then add an item describing the Modified\r\n\tVersion as stated in the previous sentence.\r\n\t\\item Preserve the network location, if any, given in the Document for\r\n\tpublic access to a Transparent copy of the Document, and likewise\r\n\tthe network locations given in the Document for previous versions\r\n\tit was based on.  These may be placed in the ``History'' section.\r\n\tYou may omit a network location for a work that was published at\r\n\tleast four years before the Document itself, or if the original\r\n\tpublisher of the version it refers to gives permission.\r\n\t\\item In any section entitled ``Acknowledgements'' or ``Dedications'',\r\n\tpreserve the section's title, and preserve in the section all the\r\n\tsubstance and tone of each of the contributor acknowledgements\r\n\tand/or dedications given therein.\r\n\t\\item Preserve all the Invariant Sections of the Document,\r\n\tunaltered in their text and in their titles.  Section numbers\r\n\tor the equivalent are not considered part of the section titles.\r\n\t\\item Delete any section entitled ``Endorsements''.  Such a section\r\n\tmay not be included in the Modified Version.\r\n\t\\item Do not retitle any existing section as ``Endorsements''\r\n\tor to conflict in title with any Invariant Section.\r\n\r\n\t\\end{itemize}\r\n\r\n\tIf the Modified Version includes new front-matter sections or\r\n\tappendices that qualify as Secondary Sections and contain no material\r\n\tcopied from the Document, you may at your option designate some or all\r\n\tof these sections as invariant.  To do this, add their titles to the\r\n\tlist of Invariant Sections in the Modified Version's license notice.\r\n\tThese titles must be distinct from any other section titles.\r\n\r\n\tYou may add a section entitled ``Endorsements'', provided it contains\r\n\tnothing but endorsements of your Modified Version by various\r\n\tparties -- for example, statements of peer review or that the text has\r\n\tbeen approved by an organization as the authoritative definition of a\r\n\tstandard.\r\n\r\n\tYou may add a passage of up to five words as a Front-Cover Text, and a\r\n\tpassage of up to 25 words as a Back-Cover Text, to the end of the list\r\n\tof Cover Texts in the Modified Version.  Only one passage of\r\n\tFront-Cover Text and one of Back-Cover Text may be added by (or\r\n\tthrough arrangements made by) any one entity.  If the Document already\r\n\tincludes a cover text for the same cover, previously added by you or\r\n\tby arrangement made by the same entity you are acting on behalf of,\r\n\tyou may not add another; but you may replace the old one, on explicit\r\n\tpermission from the previous publisher that added the old one.\r\n\r\n\tThe author(s) and publisher(s) of the Document do not by this License\r\n\tgive permission to use their names for publicity for or to assert or\r\n\timply endorsement of any Modified Version.\r\n\r\n\r\n\t\\section{Combining Documents}\r\n\r\n\tYou may combine the Document with other documents released under this\r\n\tLicense, under the terms defined in section 4 above for modified\r\n\tversions, provided that you include in the combination all of the\r\n\tInvariant Sections of all of the original documents, unmodified, and\r\n\tlist them all as Invariant Sections of your combined work in its\r\n\tlicense notice.\r\n\r\n\tThe combined work need only contain one copy of this License, and\r\n\tmultiple identical Invariant Sections may be replaced with a single\r\n\tcopy.  If there are multiple Invariant Sections with the same name but\r\n\tdifferent contents, make the title of each such section unique by\r\n\tadding at the end of it, in parentheses, the name of the original\r\n\tauthor or publisher of that section if known, or else a unique number.\r\n\tMake the same adjustment to the section titles in the list of\r\n\tInvariant Sections in the license notice of the combined work.\r\n\r\n\tIn the combination, you must combine any sections entitled ``History''\r\n\tin the various original documents, forming one section entitled\r\n\t``History''; likewise combine any sections entitled ``Acknowledgements'',\r\n\tand any sections entitled ``Dedications''.  You must delete all sections\r\n\tentitled ``Endorsements.''\r\n\r\n\r\n\t\\section{Collections of Documents}\r\n\r\n\tYou may make a collection consisting of the Document and other documents\r\n\treleased under this License, and replace the individual copies of this\r\n\tLicense in the various documents with a single copy that is included in\r\n\tthe collection, provided that you follow the rules of this License for\r\n\tverbatim copying of each of the documents in all other respects.\r\n\r\n\tYou may extract a single document from such a collection, and distribute\r\n\tit individually under this License, provided you insert a copy of this\r\n\tLicense into the extracted document, and follow this License in all\r\n\tother respects regarding verbatim copying of that document.\r\n\r\n\r\n\r\n\t\\section{Aggregation With Independent Works}\r\n\r\n\tA compilation of the Document or its derivatives with other separate\r\n\tand independent documents or works, in or on a volume of a storage or\r\n\tdistribution medium, does not as a whole count as a Modified Version\r\n\tof the Document, provided no compilation copyright is claimed for the\r\n\tcompilation.  Such a compilation is called an ``aggregate'', and this\r\n\tLicense does not apply to the other self-contained works thus compiled\r\n\twith the Document, on account of their being thus compiled, if they\r\n\tare not themselves derivative works of the Document.\r\n\r\n\tIf the Cover Text requirement of section 3 is applicable to these\r\n\tcopies of the Document, then if the Document is less than one quarter\r\n\tof the entire aggregate, the Document's Cover Texts may be placed on\r\n\tcovers that surround only the Document within the aggregate.\r\n\tOtherwise they must appear on covers around the whole aggregate.\r\n\r\n\r\n\t\\section{Translation}\r\n\r\n\tTranslation is considered a kind of modification, so you may\r\n\tdistribute translations of the Document under the terms of section 4.\r\n\tReplacing Invariant Sections with translations requires special\r\n\tpermission from their copyright holders, but you may include\r\n\ttranslations of some or all Invariant Sections in addition to the\r\n\toriginal versions of these Invariant Sections.  You may include a\r\n\ttranslation of this License provided that you also include the\r\n\toriginal English version of this License.  In case of a disagreement\r\n\tbetween the translation and the original English version of this\r\n\tLicense, the original English version will prevail.\r\n\r\n\r\n\t\\section{Termination}\r\n\r\n\tYou may not copy, modify, sublicense, or distribute the Document except\r\n\tas expressly provided for under this License.  Any other attempt to\r\n\tcopy, modify, sublicense or distribute the Document is void, and will\r\n\tautomatically terminate your rights under this License.  However,\r\n\tparties who have received copies, or rights, from you under this\r\n\tLicense will not have their licenses terminated so long as such\r\n\tparties remain in full compliance.\r\n\r\n\r\n\t\\section{Future Revisions of This License}\r\n\r\n\tThe Free Software Foundation may publish new, revised versions\r\n\tof the GNU Free Documentation License from time to time.  Such new\r\n\tversions will be similar in spirit to the present version, but may\r\n\tdiffer in detail to address new problems or concerns. See\r\n\thttp://www.gnu.org/copyleft/.\r\n\r\n\tEach version of the License is given a distinguishing version number.\r\n\tIf the Document specifies that a particular numbered version of this\r\n\tLicense \"or any later version\" applies to it, you have the option of\r\n\tfollowing the terms and conditions either of that specified version or\r\n\tof any later version that has been published (not as a draft) by the\r\n\tFree Software Foundation.  If the Document does not specify a version\r\n\tnumber of this License, you may choose any version ever published (not\r\n\tas a draft) by the Free Software Foundation.\r\n\r\n\\endgroup\r\n"
  },
  {
    "path": "chapter-next-copper.tex",
    "content": "\\section{Copper}\r\n\\label{zx_next_copper}\r\n\r\n% ───────────────────────────────────────────────────────────────────────────────────────────────\r\n% ─██████████████─██████████████─██████████████─██████████████─██████████████─████████████████───\r\n% ─██░░░░░░░░░░██─██░░░░░░░░░░██─██░░░░░░░░░░██─██░░░░░░░░░░██─██░░░░░░░░░░██─██░░░░░░░░░░░░██───\r\n% ─██░░██████████─██░░██████░░██─██░░██████░░██─██░░██████░░██─██░░██████████─██░░████████░░██───\r\n% ─██░░██─────────██░░██──██░░██─██░░██──██░░██─██░░██──██░░██─██░░██─────────██░░██────██░░██───\r\n% ─██░░██─────────██░░██──██░░██─██░░██████░░██─██░░██████░░██─██░░██████████─██░░████████░░██───\r\n% ─██░░██─────────██░░██──██░░██─██░░░░░░░░░░██─██░░░░░░░░░░██─██░░░░░░░░░░██─██░░░░░░░░░░░░██───\r\n% ─██░░██─────────██░░██──██░░██─██░░██████████─██░░██████████─██░░██████████─██░░██████░░████───\r\n% ─██░░██─────────██░░██──██░░██─██░░██─────────██░░██─────────██░░██─────────██░░██──██░░██─────\r\n% ─██░░██████████─██░░██████░░██─██░░██─────────██░░██─────────██░░██████████─██░░██──██░░██████─\r\n% ─██░░░░░░░░░░██─██░░░░░░░░░░██─██░░██─────────██░░██─────────██░░░░░░░░░░██─██░░██──██░░░░░░██─\r\n% ─██████████████─██████████████─██████─────────██████─────────██████████████─██████──██████████─\r\n% ───────────────────────────────────────────────────────────────────────────────────────────────\r\n\r\nCopper stands for ``co-processor''. If the name sounds familiar, there's a reason - it functions similarly to the Copper from the Commodore Amiga Agnus chip. It allows changing a subset of Next registers at certain scanline positions, which frees the Z80 processor for other tasks.\r\n\r\nCopper uses 2K of dedicated write-only memory for its programs. A program consists of a series of instructions. Instructions are 16-bits in size, meaning we can store up to 1024 instructions. Internally, Copper uses a 10-bit program counter ({\\tt CPC}) that by default auto-increments and wraps around from the last to the first instruction. But we can change this behaviour if needed.\r\n\r\nTiming for Copper is 14MHz on core 2.0 and 28MHz on core 3.0. If interested, this document describes the timing and many other details for core 2.0 in great detail\\footnote{\\url{https://gitlab.com/thesmog358/tbblue/blob/master/docs/extra-hw/copper/COPPER-v0.1c.TXT}}.\r\n\r\n\r\n\\subsection{Instructions}\r\n\r\nThere are only two types of instructions ZX Next Copper understands, but each type has a special case, so in total, we can say there are four operations:\r\n\r\n\\begin{ElegantTableX}{|l|l|X|l|}[\r\n\t\\newcommand{\\CopperInstr}[4]{{\\tt #1} & {\\tt #2} & \\raggedright{#3} & #4 \\\\}\r\n]\r\n\t\\ElegantHeader{\r\n\t\t\\EH{Op.} &\r\n\t\t\\EH{Bit Pattern} &\r\n\t\t\\EH{Effect} &\r\n\t\t\\EH{Dur.}\r\n\t}\r\n\r\n\t\\CopperInstr{WAIT}\r\n\t\t{1HHHHHHV VVVVVVVV}\r\n\t\t{Wait for raster line \\textbf{V} ({\\tt 0}-{\\tt 311}) and horizontal position \\textbf{H} ({\\tt 0}-{\\tt 55})}\r\n\t\t{1 cycle}\r\n\r\n\t\\hline\r\n\r\n\t\\CopperInstr{HALT}\r\n\t\t{11111111 11111111}\r\n\t\t{Special case of {\\tt WAIT}; works as ``halt''}\r\n\t\t{1 cycle}\r\n\r\n\t\\hline\r\n\t\t\r\n\t\\CopperInstr{MOVE}\r\n\t\t{0RRRRRRR VVVVVVVV}\r\n\t\t{Write value \\textbf{V} to Next register \\textbf{R}}\r\n\t\t{2 cycles}\r\n\r\n\t\\hline\r\n\r\n\t\\CopperInstr{NOOP}\r\n\t\t{00000000 00000000}\r\n\t\t{Special case of {\\tt MOVE}; works as ``no operation''}\r\n\t\t{1 cycle}\r\n\r\n\\end{ElegantTableX}\r\n\r\n\r\n\\subsubsection{WAIT}\r\n\r\n\\begin{BitTableWord}\r\n\t\\BitMono{1} &\r\n\t\\BitMulti{6}{Horizontal ({\\tt 0}-{\\tt 55})} &\r\n\t\\BitMulti{9}{Vertical ({\\tt 0}-{\\tt 311})} \\\\\t\r\n\\end{BitTableWord}\r\n\r\n{\\tt WAIT} blocks Copper program until the current raster line reaches the 9-bit vertical position from bits 8-0. When the line matches, it further waits until the given 6-bit horizontal position is reached.\r\n\r\n\\begin{tabularx}{\\linewidth}{@{}lX}\r\n\t\r\n\t\\begin{tikzpicture}[\r\n\t\tbaseline=(raster.north),\r\n\t\tframed/.style={draw},\r\n\t\tfilled/.style={framed, fill=PrintableLightGray}\r\n\t]\r\n\t\t\\node[framed, minimum width=6cm, minimum height=4cm, anchor=north west, label={[yshift=1.5em]below:Raster Area}] at(0,0) (raster) {};\r\n\t\t\\node[filled, minimum width=4cm, minimum height=3cm, anchor=north west] at(0,0) (screen) {Screen};\r\n\t\r\n\t\t\\begin{scope}[\r\n\t\t\tevery path/.style={>=stealth', <->, line width=0.5pt},\r\n\t\t\tevery node/.style={font=\\footnotesize\\ttfamily, midway, above}]\r\n\t\t\t\t\t\r\n\t\t\t\\draw ([yshift=1.5ex]raster.north west) -- ([yshift=1.5ex]raster.north east) node {448};\r\n\t\t\t\\draw ([xshift=-1.5ex]raster.north west) -- ([xshift=-1.5ex]raster.south west) node[rotate=90] {312};\r\n\t\t\t\t\t\r\n\t\t\t\\draw ([yshift=-3ex]screen.north west) -- ([yshift=-3ex]screen.north east) node {256};\r\n\t\t\t\\draw ([xshift=3ex]screen.north west) -- ([xshift=3ex]screen.south west) node[rotate=90] {192};\r\n\t\t\t\t\r\n\t\t\\end{scope}\r\n\t\r\n\t\\end{tikzpicture}\r\n\r\n\t&\r\n\r\n\tThe raster area addressable by Copper is 448$\\times$312 pixels. So for the standard 256$\\times$192 resolution, one horizontal position translates into 8 pixels. The visible portion of the screen is positioned top-left within the raster area like shown in this drawing. This means Copper line 0 corresponds with the top line of the screen, just below the border.\r\n\r\n\t\\\\\r\n\\end{tabularx}\r\n\r\n\r\n\\subsubsection{HALT}\r\n\r\n\\begin{BitTableWord}\r\n\t\\BitMono{1} &\r\n\t\t\\BitMono{1} &\r\n\t\t\\BitMono{1} &\r\n\t\t\\BitMono{1} &\r\n\t\t\\BitMono{1} &\r\n\t\t\\BitMono{1} &\r\n\t\t\\BitMono{1} &\r\n\t\t\\BitMono{1} &\r\n\t\\BitMono{1} &\r\n\t\t\\BitMono{1} &\r\n\t\t\\BitMono{1} &\r\n\t\t\\BitMono{1} &\r\n\t\t\\BitMono{1} &\r\n\t\t\\BitMono{1} &\r\n\t\t\\BitMono{1} &\r\n\t\t\\BitMono{1} \\\\\r\n\\end{BitTableWord}\r\n\r\n{\\tt HALT} is a special case of {\\tt WAIT} instruction that tells Copper to wait for the vertical position 511 and horizontal 63. As these are unreachable positions, it will effectively stop all further Copper processing until Next is reset.\r\n\r\n% note: we use comma for referencing port declaration page to avoid double closing parenthesis, more readable this way\r\nHowever, when mode {\\tt 11} is used (bits 7-6 of \\PortTextXRef[,]{62}), Copper will auto-wrap to the first instruction on every vertical blank. This allows us to use {\\tt HALT} to mark the end of the Copper program without having to fill in the remaining bytes with {\\tt 0}. Quite convenient! In fact, I'd imagine this would be the most commonly used mode. If you're used to Copper on Amiga, this is also how it behaved there.\r\n\r\n\r\n\\subsubsection{MOVE}\r\n\r\n\\begin{BitTableWord}\r\n\t\\BitMono{0} &\r\n\t\\BitMulti{7}{Next Register ({\\tt 0}-{\\tt 127})} &\r\n\t\\BitMulti{8}{Value ({\\tt 0}-{\\tt 255})} \\\\\r\n\\end{BitTableWord}\r\n\r\n{\\tt MOVE} writes the given 8-bit value to the given Next register. Any register between {\\tt 1} and {\\tt 127} (\\MemAddr{7F}) can be written to. Register {\\tt 0} is a special case, see {\\tt NOOP} below.\r\n\r\n{\\tt MOVE} can be used for all sorts of neat effects. For example: change Layer 2 offsets to achieve parallax scrolling effect, change palette at specific screen coordinates to achieve sky gradient or simulate above and under-water colours etc.\r\n\r\n\r\n\\subsubsection{NOOP}\r\n\r\n\\begin{BitTableWord}\r\n\t\\BitMono{0} &\r\n\t\t\\BitMono{0} &\r\n\t\t\\BitMono{0} &\r\n\t\t\\BitMono{0} &\r\n\t\t\\BitMono{0} &\r\n\t\t\\BitMono{0} &\r\n\t\t\\BitMono{0} &\r\n\t\t\\BitMono{0} &\r\n\t\\BitMono{0} &\r\n\t\t\\BitMono{0} &\r\n\t\t\\BitMono{0} &\r\n\t\t\\BitMono{0} &\r\n\t\t\\BitMono{0} &\r\n\t\t\\BitMono{0} &\r\n\t\t\\BitMono{0} &\r\n\t\t\\BitMono{0} \\\\\r\n\\end{BitTableWord}\r\n\r\n{\\tt NOOP} is a special case of {\\tt MOVE} that effectively does nothing for a period of one horizontal position. It can be used to fine-tune timing, align colour and display changes etc.\r\n\r\n\r\n\\pagebreak\r\n\\subsection{Configuration}\r\n\\label{zx_next_copper_configuration}\r\n\r\n% note: we only show page number on second port xref since both are declared on the same page, but if this changes in the future, we should update this text accordingly\r\nTo load a program, we need to send it, byte by byte, through \\PortTextXRef[]{60} or \\PortTextXRef[]{63} registers (page \\PortPage{60}). As instructions are 16-bits in size, two writes are required. The difference between the two registers is that \\MemAddr{60} sends bytes immediately while \\MemAddr{63} only after both bytes of an instruction are provided, thus preventing half-written instructions from executing.\r\n\r\n% note: we only show page number on second port xref since both are declared on the same page, but if this changes in the future, we should update this text accordingly\r\nCopper is controlled through 16-bit control word accessible through \\PortTextXRef[]{62} and \\PortTextXRef[]{61} registers (page \\PortPage{62}):\r\n\r\n\\begin{BitTableWord}[c][\\PortTextXRef{62}][\\PortTextXRef{61}]\r\n\t\\BitStartMulti{2}{Mode} &\r\n\t\t\\BitMono{0} & \r\n\t\t\\BitMono{0} & \r\n\t\t\\BitMono{0} &\r\n\t\t\\BitMulti{11}{Index for program upload} \\\\\r\n\\end{BitTableWord}\r\n\r\nMode can be one of the following:\r\n\r\n\\begin{PortBitConfig}\r\n\t\\PortBitLine{00}{Stops the Copper, {\\tt CPC} keeps its current value. This is useful during program upload, to prevent Copper from executing incomplete instructions and programs.}\r\n\t\\PortBitLine{01}{Resets {\\tt CPC} to {\\tt 0}, then starts Copper. From here on, Copper will start executing the first instruction in the program and continue until {\\tt CPC} reaches 1023, then wrap around back to first. However it will stop if {\\tt HALT} instruction is encountered.}\r\n\t\\PortBitLine{10}{Starts or resumes Copper from current {\\tt CPC}. Similar to {\\tt 01}, except that {\\tt CPC} is not changed. Instead, Copper resumes execution from current instruction.}\r\n\t\\PortBitLine{11}{Same as {\\tt 01}, but also auto-resets {\\tt CPC} to 0 on vertical blank. In this mode we can use {\\tt HALT} to mark the end of the program and still repeat it without having to fill-in {\\tt NOOP}s from the last instruction of our program to the end of Copper 2K memory.}\r\n\\end{PortBitConfig}\r\n\r\n% note: we only show page number on second port xref since both are declared on the same page, but if this changes in the future, we should update this text accordingly\r\nThe other value we set is the index for program upload. This is 11-bit value ({\\tt 0}-{\\tt 2047}) specifying the byte offset for write commands with \\PortTextXRef[]{60} or \\PortTextXRef[]{63} registers (page \\PortPage{60}). In other words: this is the index for the location into which data will be uploaded, not the value of the {\\tt CPC}. We can't change {\\tt CPC} programmatically, apart from resetting it to {\\tt 0}.\r\n\r\n\r\n\\subsection{Example}\r\n\r\nEnough theory, let's see how it works in practice, Copper program first. It changes palette colour to green at the top of the screen and then to red in the middle:\r\n\r\n\\begin{tcblisting}{}\r\nCopperList:\r\n\tDB &80, 0           ; Wait line 0\r\n\tDB &41, %00011100 ; Set palette entry to green\r\n\tDB &80, 96          ; Wait line 96\r\n\tDB &41, %11100000 ; Set palette entry to red\r\n\tDB &FF, &FF         ; HALT\r\nCopperListSize = &-CopperList\r\n\\end{tcblisting}\r\n\r\nIn case you may be wondering: we should also ensure we update the correct colour with \\PortTextXRef{43} and \\PortTextXRef{40}. But I wanted to keep the program simple for demonstration purposes.\r\n\r\nWith Copper program in place, we can upload it to Copper memory. We can use DMA or directly upload values through Next registers. The code here demonstrates later, but companion code implements both so you can compare:\r\n\r\n\\begin{tcblisting}{}\r\n\t; Stop Copper and set data upload index to 0\r\n\tNEXTREG &61, %00000000\r\n\tNEXTREG &62, %00000000\r\n\r\n\t; Copy list into Copper memory\r\n\tLD HL, CopperList           ; HL points to start of copper list\r\n\tLD B, CopperListSize        ; B = size of our Copper list in bytes\r\n.nextByte:\r\n\tLD A, (HL)                  ; Load current byte to A\r\n\tNEXTREG &63, A              ; Copy it to Copper memory\r\n\tINC HL                      ; Increment HL to next byte\r\n\tDJNZ .nextByte              ; Repeat or continue\r\n\r\n\t; Start Copper in mode %11 - reset on every vertical blank\r\n\tNEXTREG &61, %00000000\r\n\tNEXTREG &62, %11000000\r\n\\end{tcblisting}\r\n\r\nAgain, this is an overly simplified example. It only works for lists that are less than 256 bytes long.\r\n\r\nThe next step is... Well, there is no next step - if we enabled Layer 2 and filled it with the colour we're changing in our Copper list, we should see the screen divided into two halves with top in green and bottom red colour.\r\n\r\nNot the most impressive display of Copper capabilities, I give you that. You can find a more complex example in companion code on GitHub, folder {\\tt copper} with couple additional points of interest:\r\n\r\n\\begin{itemize}[topsep=1pt,itemsep=1pt]\r\n\t\\item Upload routine that supports programs of arbitrary size (within 1024 instructions limit)\r\n\t\\item Example of upload routine using DMA\r\n\t\\item Using DMA to fill in Layer 2 banks\r\n\t\\item Macros that hopefully make Copper programs easier to read and write\r\n\t\\item Usage of \\PortTextXRef{60} to dynamically update individual bytes of the program in memory to achieve couple effects\r\n\\end{itemize}\r\n\r\n\r\n\\pagebreak\r\n\\subsection{Copper Registers}\r\n\\label{zx_next_copper_registers}\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{60}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-0}\r\n\t\t\\PortDesc{Data to upload to Copper memory}\r\n\\end{NextPort}\r\n\r\n% note: port page is not used here since the declaration is on the same page\r\nThe data is written to the index specified with \\PortTextXRef[]{61} and \\PortTextXRef[]{62} registers. After the write, the index is auto-incremented to the next memory position. The index wraps to {\\tt 0} when the last byte of the program memory is written to position {\\tt 2047}. Since Copper instructions are 16-bits in size, two writes are required to complete each one.\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{61}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-0}\r\n\t\t\\PortDesc{Least significant 8 bits of Copper list index}\r\n\\end{NextPort}\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{62}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-6}\r\n\t\t\\PortDesc{Control mode}\r\n\t\t\\PortDescOnly{\r\n\t\t\t\\begin{PortBitConfig}\r\n\t\t\t\t\\PortBitLine{00}{Stops the Copper, {\\tt CPC} keeps its current value}\r\n\t\t\t\t\\PortBitLine{01}{Resets {\\tt CPC} to {\\tt 0}, then starts Copper}\r\n\t\t\t\t\\PortBitLine{10}{Starts or resumes Copper from current {\\tt CPC}}\r\n\t\t\t\t\\PortBitLine{11}{Same as {\\tt 01}, but also auto-resets {\\tt CPC} to 0 on vertical blank}\r\n\t\t\t\\end{PortBitConfig}\r\n\t\t}\r\n\t\\PortBits{5-3}\r\n\t\t\\PortDesc{Reserved, must be {\\tt 0}}\r\n\t\\PortBits{2-0}\r\n\t\t\\PortDesc{Most significant 3 bits of Copper list index}\r\n\\end{NextPort}\r\n\r\nWhen control mode is identical to current one, it's ignored. This allows change of the upload index without restarting the program.\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{63}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-0}\r\n\t\t\\PortDesc{Data to upload to Copper memory}\r\n\\end{NextPort}\r\n\r\n% note: port page is not used here since the declaration is on the same page\r\nSimilar to \\PortTextXRef[]{60} except that writes are only committed to Copper memory after two bytes are written. This prevents half-written instructions to be executed.\r\n\r\nThe first write to this register is for MSB of the Copper instruction or even instruction address and second write for LSB or odd instruction address.\r\n\r\n\r\n\\pagebreak\r\n\\IntentionallyEmpty\r\n\\pagebreak\r\n"
  },
  {
    "path": "chapter-next-dma.tex",
    "content": "\\section{DMA}\r\n\\label{zx_next_dma}\r\n\r\n% ──────────────────────────────────────────────────────\r\n% ─████████████───██████──────────██████─██████████████─\r\n% ─██░░░░░░░░████─██░░██████████████░░██─██░░░░░░░░░░██─\r\n% ─██░░████░░░░██─██░░░░░░░░░░░░░░░░░░██─██░░██████░░██─\r\n% ─██░░██──██░░██─██░░██████░░██████░░██─██░░██──██░░██─\r\n% ─██░░██──██░░██─██░░██──██░░██──██░░██─██░░██████░░██─\r\n% ─██░░██──██░░██─██░░██──██░░██──██░░██─██░░░░░░░░░░██─\r\n% ─██░░██──██░░██─██░░██──██████──██░░██─██░░██████░░██─\r\n% ─██░░██──██░░██─██░░██──────────██░░██─██░░██──██░░██─\r\n% ─██░░████░░░░██─██░░██──────────██░░██─██░░██──██░░██─\r\n% ─██░░░░░░░░████─██░░██──────────██░░██─██░░██──██░░██─\r\n% ─████████████───██████──────────██████─██████──██████─\r\n% ──────────────────────────────────────────────────────\r\n\r\n\\input{defines-dma.tex}\r\n\r\nThe ZX Spectrum Next DMA (zxnDMA) is a single channel direct memory access device that implements a subset of the Z80 DMA functionality. The subset is large enough to be compatible with common uses of the similar Datagear interface available for standard ZX Spectrums but without the idiosyncracies and requirements on the order of commands.\r\n\r\nzxnDMA defines two ``ports'', called ``A'' and ``B'' (port is just a word used for referring to both, source and destination). Either one can be used as a source, the other as the destination. They can be memory location or I/O port, auto-increment, auto-decrement or stay fixed. zxnDMA can operate in continuous or burst mode and implements a special feature that can force each byte transfer to take a fixed amount of time, which can be used to deliver sampled audio.\r\n\r\n\r\n\\subsection{Programming}\r\n\r\n% note: since both ports are declared on the same page, we only link to the page once\r\nSince core 3.1.2, zxnDMA is mapped to \\PortTextXRef[]{xx6B} and legacy Zilog DMA to \\PortTextXRef[]{xx0B} (see page \\PortPage{xx0B} for details).\r\n\r\nSimilar to Z80 DMA, zxnDMA also has 7 write registers named \\DMARegName{WR0}-\\DMARegName{WR6}. Some of the bits are used to identify a register, while the rest represent the payload ({\\tt x} in the table below):\r\n\r\n% Registers are defined with specific bit configuration ({\\tt 0} or {\\tt 1} in the table below) while the rest of the bits define the payload ({\\tt x}):\r\n\r\n\\begin{ElegantTableX}{|l|l|X|}[\r\n\t\\newcommand{\\DMAReg}[3]{{\\tt #1} & {\\tt #2} & #3 \\\\}\r\n]\r\n\r\n\t\\ElegantHeader{\r\n\t\t\\EH{Reg.} & \\EH{Bitmask} & \\EH{Description}\r\n\t}\r\n\r\n\t\\DMAReg{WR0}{0xxxxx01}{Direction, operation and port A configuration}\r\n\t\\hline\r\n\r\n\t\\DMAReg{WR1}{0xxxx100}{Port A configuration}\r\n\t\\hline\r\n\r\n\t\\DMAReg{WR2}{0xxxx000}{Port B configuration}\r\n\t\\hline\r\n\r\n\t\\DMAReg{WR3}{1xxxxx00}{Activation}\r\n\t\\hline\r\n\r\n\t\\DMAReg{WR4}{1xxxxx01}{Port B, timing and interrupt configuration}\r\n\t\\hline\r\n\r\n\t\\DMAReg{WR5}{10xxx010}{Ready and stop configuration}\r\n\t\\hline\r\n\r\n\t\\DMAReg{WR6}{1xxxxx11}{Command register}\r\n\r\n\\end{ElegantTableX}\r\n\r\nEach register can include zero or more parameters. Most often specific bits in the payload define whether and which parameters are used. Each parameter is one byte long. Parameters are written immediately after the base register byte. If multiple parameters are used, the order is specified by the bit position within the base payload. The order is from right to left, the parameter associated with bit {\\tt 0} is written first, the one from bit {\\tt 7} last.\r\n\r\nSometimes it's also possible that a specific configuration of parameter byte requires additional bytes to be inserted. If so, these bytes are inserted immediately after their ``parent'' parameter byte following the same rules as indicated above. Only after all child parameters are written, we continue with other parents' parameters, if there are more. This forms a sort of recursive pattern.\r\n\r\nAfter all parameters are written, we can start with a new register byte again. This is then repeated until zxnDMA program is started using \\DMARegName{WR3} or (preferably) \\DMARegName{WR6}. The same registers can be repeated multiple times within the same DMA program.\r\n\r\nDMA programs can be up to 256 bytes long (but the data being transferred can be up to 64K).\r\n\r\n\r\n\\pagebreak\r\n\\subsection{Registers at a Glance}\r\n\r\n\\begin{multicols}{2}\r\n\t\r\n\t\\DMAScaledReg{WR0}{\r\n\t\t\\begin{tikzpicture}\r\n\r\n\t\t\t% Instruction Byte\r\n\t\t\t\\DMABitHeader\r\n\t\t\t\\DMABitValue{7}{0}\r\n\t\t\t\\DMABitValue{6}{}\r\n\t\t\t\\DMABitValue{5}{}\r\n\t\t\t\\DMABitValue{4}{}\r\n\t\t\t\\DMABitValue{3}{}\r\n\t\t\t\\DMABitValue{2}{}\r\n\t\t\t\\DMABitValue{1}{0}\r\n\t\t\t\\DMABitValue{0}{1}\r\n\t\t\r\n\t\t\t% Bit 2 description\r\n\t\t\t\\DMABitDescTitle{2}{Transfer Direction}\r\n\t\t\t\\DMABitDescItem{2}{0}{Port B$\\rightarrow$A}\r\n\t\t\t\\DMABitDescItem{2}{1}{Port A$\\rightarrow$B}\r\n\t\t\r\n\t\t\t% Parameters\r\n\t\t\t\\DMABitPar{3}{Port A address (LSB)}[1ex][pos=0.35][]\r\n\t\t\t\\DMABitPar{4}{Port A address (MSB)}[][pos=0.35][]\r\n\t\t\t\\DMABitPar{5}{Block length (LSB)}[][pos=0.35][]\r\n\t\t\t\\DMABitPar{6}{Block length (MSB)}[][pos=0.35][]\r\n\t\t\r\n\t\t\\end{tikzpicture}\r\n\t}\r\n\r\n\t\\DMAScaledReg{WR1}{\r\n\t\t\\begin{tikzpicture}\r\n\t\r\n\t\t\t% Instruction Byte\r\n\t\t\t\\DMABitHeader\r\n\t\t\t\\DMABitValue{7}{0}\r\n\t\t\t\\DMABitValue{6}{}\r\n\t\t\t\\DMABitValue[2]{5}{}\r\n\t\t\t\\DMABitValue{3}{}\r\n\t\t\t\\DMABitValue{2}{1}\r\n\t\t\t\\DMABitValue{1}{0}\r\n\t\t\t\\DMABitValue{0}{0}\r\n\t\r\n\t\t\t% Bit 3 description\r\n\t\t\t\\DMABitDescTitle{3}{Port A Source}\r\n\t\t\t\\DMABitDescItem{3}{0}{Port A is Memory}\r\n\t\t\t\\DMABitDescItem{3}{1}{Port A is I/O}\r\n\t\r\n\t\t\t% Bit 5-4 description\r\n\t\t\t\\DMABitDescTitle[-3ex]{5}{Port A Address Handling}\r\n\t\t\t\\DMABitDescItem{5}{\\DMATwoBits{0}{0}}{Port A Address Decrements}\r\n\t\t\t\\DMABitDescItem{5}{\\DMATwoBits{0}{1}}{Port A Address Increments}\r\n\t\t\t\\DMABitDescItem{5}{\\DMATwoBits{1}{0}}{Port A Address is Fixed}\r\n\t\t\t\\DMABitDescItem{5}{\\DMATwoBits{1}{1}}{Port A Address is Fixed}\r\n\t\t\r\n\t\t\t% Parameters\r\n\t\t\t\\DMABitParHeader{6}{Port A Timing}[]\r\n\t\t\t\\DMABitValue{7}{0}\r\n\t\t\t\\DMABitValue{6}{0}\r\n\t\t\t\\DMABitValue{5}{0}\r\n\t\t\t\\DMABitValue{4}{0}\r\n\t\t\t\\DMABitValue{3}{0}\r\n\t\t\t\\DMABitValue{2}{0}\r\n\t\t\t\\DMABitValue[2]{1}{}\r\n\t\t\r\n\t\t\t% Par bit 1-0 description\r\n\t\t\t\\DMABitDescTitle[-3ex]{1}{Port A Variable Timing}\r\n\t\t\t\\DMABitDescItem{1}{\\DMATwoBits{0}{0}}{Cycle length = 4}\r\n\t\t\t\\DMABitDescItem{1}{\\DMATwoBits{0}{1}}{Cycle length = 3}\r\n\t\t\t\\DMABitDescItem{1}{\\DMATwoBits{1}{0}}{Cycle length = 2}\r\n\t\t\t\\DMABitDescItem{1}{\\DMATwoBits{1}{1}}{Do not use!}\r\n\t\r\n\t\t\\end{tikzpicture}\r\n\t}\r\n\r\n\t\\DMAScaledReg{WR2}{\r\n\t\t\\begin{tikzpicture}\r\n\t\r\n\t\t\t% Instruction Byte\r\n\t\t\t\\DMABitHeader\r\n\t\t\t\\DMABitValue{7}{0}\r\n\t\t\t\\DMABitValue{6}{}\r\n\t\t\t\\DMABitValue[2]{5}{}\r\n\t\t\t\\DMABitValue{3}{}\r\n\t\t\t\\DMABitValue{2}{0}\r\n\t\t\t\\DMABitValue{1}{0}\r\n\t\t\t\\DMABitValue{0}{0}\r\n\r\n\t\t\t% Bit 3 description\r\n\t\t\t\\DMABitDescTitle{3}{Port B source}\r\n\t\t\t\\DMABitDescItem{3}{0}{Port B is Memory}\r\n\t\t\t\\DMABitDescItem{3}{1}{Port B is I/O}\r\n\r\n\t\t\t% Bit 5-4 description\r\n\t\t\t\\DMABitDescTitle[-3ex]{5}{Port B Address Handling}\r\n\t\t\t\\DMABitDescItem{5}{\\DMATwoBits{0}{0}}{Port B Address Decrements}\r\n\t\t\t\\DMABitDescItem{5}{\\DMATwoBits{0}{1}}{Port B Address Increments}\r\n\t\t\t\\DMABitDescItem{5}{\\DMATwoBits{1}{0}}{Port B Address is Fixed}\r\n\t\t\t\\DMABitDescItem{5}{\\DMATwoBits{1}{1}}{Port B Address is Fixed}\r\n\t\r\n\t\t\t% Parameter 1\r\n\t\t\t\\DMABitParHeader{6}{Port B Timing}[]\r\n\t\t\t\\DMABitValue{7}{0}\r\n\t\t\t\\DMABitValue{6}{0}\r\n\t\t\t\\DMABitValue{5}{}\r\n\t\t\t\\DMABitValue{4}{0}\r\n\t\t\t\\DMABitValue{3}{0}\r\n\t\t\t\\DMABitValue{2}{0}\r\n\t\t\t\\DMABitValue[2]{1}{}\r\n\t\r\n\t\t\t% Parameter 1 bit 1-0 description\r\n\t\t\t\\DMABitDescTitle[-3ex]{1}{Port B Variable Timing}\r\n\t\t\t\\DMABitDescItem{1}{\\DMATwoBits{0}{0}}{Cycle Length = 4}\r\n\t\t\t\\DMABitDescItem{1}{\\DMATwoBits{0}{1}}{Cycle Length = 3}\r\n\t\t\t\\DMABitDescItem{1}{\\DMATwoBits{1}{0}}{Cycle Length = 2}\r\n\t\t\t\\DMABitDescItem{1}{\\DMATwoBits{1}{1}}{Do not use!}\r\n\t\r\n\t\t\t% Parameter 2\r\n\t\t\t\\DMABitPar{5}{Prescalar (Fixed Time Transfer)}[1ex][near start][]\r\n\r\n\t\t\\end{tikzpicture}\r\n\t}\r\n\r\n\t\\columnbreak\r\n\r\n\t\\DMAScaledReg{WR3}{\r\n\t\t\\begin{tikzpicture}\r\n\t\r\n\t\t\t% Instruction Byte\r\n\t\t\t\\DMABitHeader\r\n\t\t\t\\DMABitValue{7}{1}\r\n\t\t\t\\DMABitValue{6}{}\r\n\t\t\t\\DMABitValue{5}{0}\r\n\t\t\t\\DMABitValue{4}{0}\r\n\t\t\t\\DMABitValue{3}{0}\r\n\t\t\t\\DMABitValue{2}{0}\r\n\t\t\t\\DMABitValue{1}{0}\r\n\t\t\t\\DMABitValue{0}{0}\r\n\r\n\t\t\t% Bit 3 description\r\n\t\t\t\\DMABitDescTitle{6}{Activation}\r\n\t\t\t\\DMABitDescItem{6}{0}{DMA Disabled}\r\n\t\t\t\\DMABitDescItem{6}{1}{DMA Enabled}\r\n\t\r\n\t\t\\end{tikzpicture}\r\n\t}\r\n\r\n\t\\DMAScaledReg{WR4}{\r\n\t\t\\begin{tikzpicture}\r\n\r\n\t\t\t\\pgfdeclarelayer{above}\r\n\t\t\t\\pgfsetlayers{main,above}\r\n\t\r\n\t\t\t% Instruction Byte\r\n\t\t\t\\DMABitHeader\r\n\t\t\t\\DMABitValue{7}{1}\r\n\t\t\t\\DMABitValue[2]{6}{}\r\n\t\t\t\\DMABitValue{4}{0}\r\n\t\t\t\\DMABitValue{3}{}\r\n\t\t\t\\DMABitValue{2}{}\r\n\t\t\t\\DMABitValue{1}{0}\r\n\t\t\t\\DMABitValue{0}{1}\r\n\r\n\t\t\t% Bit 6 description\r\n\t\t\t\\begin{pgfonlayer}{above}\r\n\t\t\t\t% we only need fill on top of text to avoid lines drawn on top. Coordinates were set via trial & error, so any change in data will also require re-positioning...\r\n\t\t\t\t\\node[fill=white, opacity=0.95, minimum width=3em, minimum height=5.7em] at(2.5,-2.4) {};\r\n\r\n\t\t\t\t\\DMABitDescTitle{6}{DMA Mode}\r\n\t\t\t\t\\DMABitDescItem{6}{\\DMATwoBits{0}{0}}{Do not use!}\r\n\t\t\t\t\\DMABitDescItem{6}{\\DMATwoBits{0}{1}}{Continuous Mode}\r\n\t\t\t\t\\DMABitDescItem{6}{\\DMATwoBits{1}{0}}{Burst Mode}\r\n\t\t\t\t\\DMABitDescItem{6}{\\DMATwoBits{1}{1}}{Do not use!}\r\n\t\t\t\\end{pgfonlayer}\r\n\t\r\n\t\t\t% Parameters\r\n\t\t\t\\DMABitPar{2}{Port B Address (LSB)}[1ex][pos=0.2][]\r\n\t\t\t\\DMABitPar{3}{Port B Address (MSB)}[][pos=0.2][]\r\n\r\n\t\t\\end{tikzpicture}\r\n\t}\r\n\r\n\t\\DMAScaledReg{WR5}{\r\n\t\t\\begin{tikzpicture}\r\n\t\r\n\t\t\t% Instruction Byte\r\n\t\t\t\\DMABitHeader\r\n\t\t\t\\DMABitValue{7}{1}\r\n\t\t\t\\DMABitValue{6}{0}\r\n\t\t\t\\DMABitValue{5}{}\r\n\t\t\t\\DMABitValue{4}{}\r\n\t\t\t\\DMABitValue{3}{0}\r\n\t\t\t\\DMABitValue{2}{0}\r\n\t\t\t\\DMABitValue{1}{1}\r\n\t\t\t\\DMABitValue{0}{0}\r\n\r\n\t\t\t% Bit 4 description\r\n\t\t\t\\DMABitDescTitle{4}{Ready Configuration}\r\n\t\t\t\\DMABitDescItem{4}{0}{\\DMAPinLabel{CE} only}\r\n\t\t\t\\DMABitDescItem{4}{1}{\\DMAPinLabel{CE} and \\DMAPinLabel{}{WAIT} multiplexed}\r\n\t\r\n\t\t\t% Bit 5 description\r\n\t\t\t\\DMABitDescTitle{5}{Stop Configuration}\r\n\t\t\t\\DMABitDescItem{5}{0}{Stop on End of Block}\r\n\t\t\t\\DMABitDescItem{5}{1}{Auto Restart on End of Block}\r\n\t\r\n\t\t\\end{tikzpicture}\r\n\t}\r\n\r\n\t\\DMAScaledReg{WR6}{\r\n\t\t\\begin{tikzpicture}\r\n\t\r\n\t\t\t\\newcommand{\\DMAWRBits}[5]{#1\\hspace*{1.8ex}#2\\hspace*{1.8ex}#3\\hspace*{1.8ex}#4\\hspace*{1.8ex}#5}\r\n\t\t\t\\newcommand{\\DMAWRHex}[2]{\\MemAddr{#1}\\hspace*{1.8ex}#2}\r\n\t\t\r\n\t\t\t% Instruction Byte\r\n\t\t\t\\DMABitHeader\r\n\t\t\t\\DMABitValue{7}{1}\r\n\t\t\t\\DMABitValue[5]{6}{}\r\n\t\t\t\\DMABitValue{1}{1}\r\n\t\t\t\\DMABitValue{0}{1}\r\n\t\r\n\t\t\t% Bit 6-2 description\r\n\t\t\t\\DMABitDescTitle[-7.5ex]{6}{Command}\r\n\t\t\t\\DMABitDescItem{6}{\\DMAWRBits{0}{0}{0}{0}{1}}{\\DMAWRHex{87}{Enable DMA}}\r\n\t\t\t\\DMABitDescItem{6}{\\DMAWRBits{0}{0}{0}{0}{0}}{\\DMAWRHex{83}{Disable DMA}}\r\n\t\t\t\\DMABitDescItem{6}{\\DMAWRBits{0}{0}{0}{1}{0}}{\\DMAWRHex{8B}{Reinitialize Status Byte}}\r\n\t\t\t\\DMABitDescItem{6}{\\DMAWRBits{0}{1}{0}{0}{1}}{\\DMAWRHex{A7}{Initialize Read Sequence}}\r\n\t\t\t\\DMABitDescItem{6}{\\DMAWRBits{0}{1}{1}{0}{0}}{\\DMAWRHex{B3}{Force Ready}}\r\n\t\t\t\\DMABitDescItem{6}{\\DMAWRBits{0}{1}{1}{1}{0}}{\\DMAWRHex{BB}{Read Mask Follows (see below)}}\r\n\t\t\t\\DMABitDescItem{6}{\\DMAWRBits{0}{1}{1}{1}{1}}{\\DMAWRHex{BF}{Read Status Byte}}\r\n\t\t\t\\DMABitDescItem{6}{\\DMAWRBits{1}{0}{0}{0}{0}}{\\DMAWRHex{C3}{Reset}}\r\n\t\t\t\\DMABitDescItem{6}{\\DMAWRBits{1}{0}{0}{0}{1}}{\\DMAWRHex{C7}{Reset Port A Timing}}\r\n\t\t\t\\DMABitDescItem{6}{\\DMAWRBits{1}{0}{0}{1}{0}}{\\DMAWRHex{CB}{Reset Port B Timing}}\r\n\t\t\t\\DMABitDescItem{6}{\\DMAWRBits{1}{0}{0}{1}{1}}{\\DMAWRHex{CF}{Load}}\r\n\t\t\t\\DMABitDescItem{6}{\\DMAWRBits{1}{0}{1}{0}{0}}{\\DMAWRHex{D3}{Continue}}\r\n\t\t\r\n\t\t\t% Parameter\r\n\t\t\t\\DMABitParHeader{}{Read Mask}[]\r\n\t\t\t\\DMABitValue{7}{1}\r\n\t\t\t\\DMABitValue{6}{}\r\n\t\t\t\\DMABitValue{5}{}\r\n\t\t\t\\DMABitValue{4}{}\r\n\t\t\t\\DMABitValue{3}{}\r\n\t\t\t\\DMABitValue{2}{}\r\n\t\t\t\\DMABitValue{1}{}\r\n\t\t\t\\DMABitValue{0}{}\r\n\t\t\r\n\t\t\t% Read bytes\r\n\t\t\t\\DMABitPar{0}{Status}[1em][pos=0.5][]\r\n\t\t\t\\DMABitPar{1}{Byte Counter LSB}[][pos=0.37][]\r\n\t\t\t\\DMABitPar{2}{Byte Counter MSB}[][pos=0.30][]\r\n\t\t\t\\DMABitPar{3}{Port A Address LSB}[][pos=0.26][]\r\n\t\t\t\\DMABitPar{4}{Port A Address MSB}[][pos=0.23][]\r\n\t\t\t\\DMABitPar{5}{Port B Address LSB}[][pos=0.21][]\r\n\t\t\t\\DMABitPar{6}{Port B Address MSB}[][pos=0.2][]\r\n\t\t\r\n\t\t\\end{tikzpicture}\r\n\t}\r\n\t\r\n\\end{multicols}\r\n\r\n\r\n\\pagebreak\r\n\\subsection{WR0 - Direction, Operation, Port A Configuration}\r\n\r\n% ▒█░░▒█ ▒█▀▀█ █▀▀█ \r\n% ▒█▒█▒█ ▒█▄▄▀ █▄▀█ \r\n% ▒█▄▀▄█ ▒█░▒█ █▄▄█\r\n\r\n\\DMARegName{WR0} specifies the direction of the transfer, the length of the data that will be transferred and port A address. Base register byte can be followed by up to four parameter bytes:\r\n\r\n\\begin{tikzpicture}\r\n\r\n\t% Instruction Byte\r\n\t\\DMABitHeader\r\n\t\\DMABitValue{7}{0}\r\n\t\\DMABitValue{6}{}\r\n\t\\DMABitValue{5}{}\r\n\t\\DMABitValue{4}{}\r\n\t\\DMABitValue{3}{}\r\n\t\\DMABitValue{2}{}\r\n\t\\DMABitValue[2]{1}{}\r\n\r\n\t% Bits 1-0 description\r\n\t\\DMABitDescTitle[-3ex]{1}{Operation}\r\n\t\\DMABitDescItem{1}{\\DMATwoBits{0}{0}}{Do not use! {\\small (Reserved for {\\tt WR1} and {\\tt WR2})}}\r\n\t\\DMABitDescItem{1}{\\DMATwoBits{0}{1}}{Transfer}\r\n\t\\DMABitDescItem{1}{\\DMATwoBits{1}{0}}{Do not use! {\\small (Behaves like transfer)}}\r\n\t\\DMABitDescItem{1}{\\DMATwoBits{1}{1}}{Do not use! {\\small (Behaves like transfer)}}\r\n\r\n\t% Bit 2 description\r\n\t\\DMABitDescTitle{2}{Transfer Direction}\r\n\t\\DMABitDescItem{2}{0}{Port B$\\rightarrow$A}\r\n\t\\DMABitDescItem{2}{1}{Port A$\\rightarrow$B}\r\n\r\n\t% Parameters\r\n\t\\DMABitPar{3}{Port A starting address (LSB)}[1ex][pos=0.35]\r\n\t\\DMABitPar{4}{Port A starting address (MSB)}[][pos=0.35]\r\n\t\\DMABitPar{5}{Block length (LSB)}[][pos=0.35]\r\n\t\\DMABitPar{6}{Block length (MSB)}[][pos=0.35]\r\n\r\n\t% Legend\r\n\t\\DMALegend{\\DMABitParID{3}}\r\n\r\n\\end{tikzpicture}\r\n\r\n\r\n\\subsubsection{Base Register Byte}\r\n\r\n\\begin{DMADescription}\r\n\r\n\t\\DMADescriptionItem{1-0}{Operation}{\r\n\t\tThe combination of these two bits defines the type of operation the DMA program will use. While all four combinations are listed, zxnDMA only supports one at the moment - {\\tt 01}:\r\n\r\n\t\t\\begin{DMAList}\r\n\t\t\t\\item[{\\tt 00}] Don't use, it conflicts with \\DMARegName{WR1} and \\DMARegName{WR2}.\r\n\t\t\t\r\n\t\t\t\\item[{\\tt 01}] Transfer; this is the only supported operation on zxnDMA.\r\n\t\t\t\r\n\t\t\t\\item[{\\tt 10}] Not recommended for compatibility reasons: at the moment {\\tt 10} behaves exactly like {\\tt 01} (transfer) on zxnDMA, but on Z80 it's ``search'' instead. So there is a possibility this will change in future cores.\r\n\t\t\t\r\n\t\t\t\\item[{\\tt 11}] Similar to {\\tt 10}; at the moment it behaves like {\\tt 01} (transfer) on zxnDMA, but on Z80 it's ``search/transfer''. Again, this may change in future cores.\r\n\t\t\\end{DMAList}\r\n\t}\r\n\r\n\t\\DMADescriptionItem{2}{Transfer Direction}{\r\n\t\tProvides the destination of the data transfer:\r\n\r\n\t\t\\begin{DMAList}\r\n\t\t\t\\item[{\\tt 0}] Port B is source, port A destination.\r\n\t\t\t\\item[{\\tt 1}] Port A is source, port B destination.\r\n\t\t\\end{DMAList}\r\n\r\n\t\tEither port can act as source, while the other becomes the destination.\r\n\t}\r\n\r\n\t\\DMADescriptionItem{4-3}{Port A Starting Address}{\r\n\t\tRegardless of whether port A acts as a source or destination, we have to define its source address. To do so, set both bits to {\\tt 1}. The address is then entered immediately after this byte. The address is interpreted either as memory or I/O port, based on the configuration from \\DMARegName{WR1}.\r\n\t}\r\n\r\n\t\\DMADescriptionItem{6-5}{Transfer Length}{\r\n\t\tAll DMA operations must have a length defined. Therefore this parameter is also required - set both bits to {\\tt 1}. The length is a 16-bit value and needs to be entered at the end of the data for \\DMARegName{WR0} register.\r\n\t}\r\n\r\n\\end{DMADescription}\r\n\r\n\r\n\\subsubsection{Port A Starting Address}\r\n\r\nIf bit 3 of the base register byte is set, then LSB of port A starting address is expected as the first parameter after the base. If bit 4 is set, then MSB byte is expected. If both bits are set, then LSB needs to be written first, followed by MSB. This is in fact the most common setup because port A starting address is required for each DMA operation. And since little-endian format is used, the value forming the 16-bit starting address of port A can be written directly. For example:\r\n\r\n\\begin{tcblisting}{}\r\n\tDW &253B          ; Port A starts at &253B\r\n\\end{tcblisting}\r\n\\vspace*{-1ex}\r\n\r\nOr, if we have a label that points to the start of the memory:\r\n\r\n\\begin{tcblisting}{}\r\n\tDW StartLabel     ; Port A starts on memory at this label\r\n\\end{tcblisting}\r\n\\vspace*{-1ex}\r\n\r\nWhether the address represents a memory location or I/O port is defined with \\DMARegName{WR1}.\r\n\r\n\r\n\\subsubsection{Transfer Length}{\r\n\r\nSetting bit 5 of the base register byte is associated with LSB of transfer length and bit 6 with MSB. If both bits are set, which is the usual case, then LSB is written first, followed by MSB. Again, 16-bit length can be written directly in this case, as shown above with port A starting address.\r\n\r\n\r\n\\subsubsection{Notes}\r\n\r\nSince all parameters in \\DMARegName{WR0} are important for DMA transfer, they are typically always included. The configuration would most often look something like this:\r\n\r\n\\begin{tcblisting}{}\r\n\tDB %01111101      ; WR0 - append length and port A address, A->B\r\n\tDW &253B          ; Port A starts at &253B\r\n\tDW 1500           ; We will transfer 1500 bytes\r\n\\end{tcblisting}\r\n\r\nUsually, the address and length are provided dynamically, and frequently ``self-modifying code'' approach is used to fill this data on the fly. We'll discuss this in the example section later on.\r\n\r\n\r\n\r\n\\pagebreak\r\n\\subsection{WR1 - Port A Configuration}\r\n\r\n% ▒█░░▒█ ▒█▀▀█ ▄█░ \r\n% ▒█▒█▒█ ▒█▄▄▀ ░█░ \r\n% ▒█▄▀▄█ ▒█░▒█ ▄█▄\"\r\n\r\nThis is where we provide details about port A. Base register byte may be followed by one parameter, if bit 6 of the base byte is set:\r\n\r\n\\begin{tikzpicture}\r\n\t\r\n\t% Instruction Byte\r\n\t\\DMABitHeader\r\n\t\\DMABitValue{7}{0}\r\n\t\\DMABitValue{6}{}\r\n\t\\DMABitValue[2]{5}{}\r\n\t\\DMABitValue{3}{}\r\n\t\\DMABitValue{2}{1}\r\n\t\\DMABitValue{1}{0}\r\n\t\\DMABitValue{0}{0}\r\n\r\n\t% Bit 3 description\r\n\t\\DMABitDescTitle{3}{Port A Source}\r\n\t\\DMABitDescItem{3}{0}{Port A is Memory}\r\n\t\\DMABitDescItem{3}{1}{Port A is I/O}\r\n\r\n\t% Bit 5-4 description\r\n\t\\DMABitDescTitle[-3ex]{5}{Port A Address Handling}\r\n\t\\DMABitDescItem{5}{\\DMATwoBits{0}{0}}{Port A Address Decrements}\r\n\t\\DMABitDescItem{5}{\\DMATwoBits{0}{1}}{Port A Address Increments}\r\n\t\\DMABitDescItem{5}{\\DMATwoBits{1}{0}}{Port A Address is Fixed}\r\n\t\\DMABitDescItem{5}{\\DMATwoBits{1}{1}}{Port A Address is Fixed}\r\n\t\r\n\t% Parameters\r\n\t\\DMABitParHeader{6}{Port A Timing}\r\n\t\\DMABitValue{7}{0}\r\n\t\\DMABitValue{6}{0}\r\n\t\\DMABitValue{5}{0}\r\n\t\\DMABitValue{4}{0}\r\n\t\\DMABitValue{3}{0}\r\n\t\\DMABitValue{2}{0}\r\n\t\\DMABitValue[2]{1}{}\r\n\t\r\n\t% Par bit 1-0 description\r\n\t\\DMABitDescTitle[-3ex]{1}{Port A Variable Timing}\r\n\t\\DMABitDescItem{1}{\\DMATwoBits{0}{0}}{Cycle length = 4}\r\n\t\\DMABitDescItem{1}{\\DMATwoBits{0}{1}}{Cycle length = 3}\r\n\t\\DMABitDescItem{1}{\\DMATwoBits{1}{0}}{Cycle length = 2}\r\n\t\\DMABitDescItem{1}{\\DMATwoBits{1}{1}}{Do not use!}\r\n\r\n\t% Legend\r\n\t\\DMALegend{\\DMABitDefID{7}}[PARAMETER]\r\n\r\n\\end{tikzpicture}\r\n\r\n\\subsubsection{Base Register Byte}\r\n\r\n\\begin{DMADescription}\r\n\t\r\n\t\\DMADescriptionItem{3}{Port A Source}{\r\n\t\tSpecifies the type of the address for port A (the address is written with \\DMARegName{WR0}):\r\n\r\n\t\t\\begin{DMAList}\r\n\t\t\t\\item[{\\tt 0}] Port A address is memory location.\r\n\t\t\t\\item[{\\tt 1}] Port A address is I/O port.\r\n\t\t\\end{DMAList}\r\n\t}\r\n\r\n\t\\DMADescriptionItem{5-4}{Port A Address Handling}{\r\n\t\tThe combination of these two bits determines how port A address will be handled after each byte is transferred:\r\n\r\n\t\t\\begin{DMAList}\r\n\t\t\t\\item[{\\tt 00}] Address is decremented after byte is transferred.\r\n\t\t\t\r\n\t\t\t\\item[{\\tt 01}] Address is incremented after byte is transferred.\r\n\t\t\t\t\r\n\t\t\t\\item[{\\tt 10}] The address remains fixed at its starting value. This is typically used when port A is an I/O port; all bytes are sent to the same port in this case.\r\n\t\t\t\t\r\n\t\t\t\\item[{\\tt 11}] The same as {\\tt 10}, address is fixed.\r\n\t\t\\end{DMAList}\r\n\r\n\t\tIn case of decrementing or incrementing, the first byte is read from or written to the starting address for port A from \\DMARegName{WR0}, then decrementing or incrementing begins for the second and subsequent bytes.\r\n\t}\r\n\r\n\t\\DMADescriptionItem{6}{Port A Timing}{\r\n\t\tIf bit 6 is set, the next byte written to the DMA after \\DMARegName{WR1} base register byte is used to define port A variable timing. If bit 6 is {\\tt 0}, standard Z80 timing for read and write cycles is used.\r\n\t}\r\n\r\n\\end{DMADescription}\r\n\r\n\r\n\\pagebreak\r\n\\subsubsection{Port A Timing}\r\n\r\nThis byte is expected if bit 6 of the base register byte is set. Only bits 1 and 0 are used, the rest must be set to {\\tt 0}.\r\n\r\n\\begin{DMADescription}\r\n\t\r\n\t\\DMADescriptionItem{1-0}{Port A Timing}{\r\n\t\tSpecifies variable timing configuration for port A that allows shortening the length of port A read or write cycles:\r\n\r\n\t\t\\begin{DMAList}\r\n\t\t\t\\item[{\\tt 00}] Cycle length is 4.\r\n\t\t\t\\item[{\\tt 01}] Cycle length is 3.\r\n\t\t\t\\item[{\\tt 10}] Cycle length is 2.\r\n\t\t\t\\item[{\\tt 11}] Do not use!\r\n\t\t\\end{DMAList}\r\n\r\n\t\tThe cycle lengths are intended to selectively slow down read or write cycles for hardware that can't operate at the DMA full speed.\r\n\t}\r\n\r\n\\end{DMADescription}\r\n\r\nIn contrast with Z80 DMA, zxnDMA doesn't support half-cycle timing for control signals.\r\n\r\n\r\n\\pagebreak\r\n\\subsection{WR2 - Port B Configuration}\r\n\r\n% ▒█░░▒█ ▒█▀▀█ █▀█ \r\n% ▒█▒█▒█ ▒█▄▄▀ ░▄▀ \r\n% ▒█▄▀▄█ ▒█░▒█ █▄▄\r\n\r\nThis register is similar to \\DMARegName{WR1} except it sets the configuration for port B. If bit 6 is set, base register byte needs to be followed by one parameter. And the configuration of this parameter may in turn require one more parameter byte to be appended.\r\n\r\n\\begin{tikzpicture}\r\n\t\r\n\t% Instruction Byte\r\n\t\\DMABitHeader\r\n\t\\DMABitValue{7}{0}\r\n\t\\DMABitValue{6}{}\r\n\t\\DMABitValue[2]{5}{}\r\n\t\\DMABitValue{3}{}\r\n\t\\DMABitValue{2}{0}\r\n\t\\DMABitValue{1}{0}\r\n\t\\DMABitValue{0}{0}\r\n\r\n\t% Bit 3 description\r\n\t\\DMABitDescTitle{3}{Port B source}\r\n\t\\DMABitDescItem{3}{0}{Port B is Memory}\r\n\t\\DMABitDescItem{3}{1}{Port B is I/O}\r\n\r\n\t% Bit 5-4 description\r\n\t\\DMABitDescTitle[-3ex]{5}{Port B Address Handling}\r\n\t\\DMABitDescItem{5}{\\DMATwoBits{0}{0}}{Port B Address Decrements}\r\n\t\\DMABitDescItem{5}{\\DMATwoBits{0}{1}}{Port B Address Increments}\r\n\t\\DMABitDescItem{5}{\\DMATwoBits{1}{0}}{Port B Address is Fixed}\r\n\t\\DMABitDescItem{5}{\\DMATwoBits{1}{1}}{Port B Address is Fixed}\r\n\t\r\n\t% Parameter 1\r\n\t\\DMABitParHeader{6}{Port B Timing}\r\n\t\\DMABitValue{7}{0}\r\n\t\\DMABitValue{6}{0}\r\n\t\\DMABitValue{5}{}\r\n\t\\DMABitValue{4}{0}\r\n\t\\DMABitValue{3}{0}\r\n\t\\DMABitValue{2}{0}\r\n\t\\DMABitValue[2]{1}{}\r\n\t\r\n\t% Parameter 1 bit 1-0 description\r\n\t\\DMABitDescTitle[-3ex]{1}{Port B Variable Timing}\r\n\t\\DMABitDescItem{1}{\\DMATwoBits{0}{0}}{Cycle Length = 4}\r\n\t\\DMABitDescItem{1}{\\DMATwoBits{0}{1}}{Cycle Length = 3}\r\n\t\\DMABitDescItem{1}{\\DMATwoBits{1}{0}}{Cycle Length = 2}\r\n\t\\DMABitDescItem{1}{\\DMATwoBits{1}{1}}{Do not use!}\r\n\t\r\n\t% Parameter 2\r\n\t\\DMABitPar{5}{Prescalar (Fixed Time Transfer)}\r\n\r\n\t% Legend\r\n\t\\DMALegend{\\DMABitDefAnyID{1}{7}}\r\n\r\n\\end{tikzpicture}\r\n\r\n\\subsubsection{Base Register Byte}\r\n\r\n\\begin{DMADescription}\r\n\r\n\t\\DMADescriptionItem{3}{Port B\\\\Source}{\r\n\t\tSpecifies the type of the address for port B (the address is written with \\DMARegName{WR4}):\r\n\r\n\t\t\\begin{DMAList}\r\n\t\t\t\\item[{\\tt 0}] Port B address is memory location.\r\n\t\t\t\\item[{\\tt 1}] Port B address is I/O port.\r\n\t\t\\end{DMAList}\r\n\t}\r\n\r\n\t\\DMADescriptionItem{5-4}{Port B Address Handling}{\r\n\t\tThe combination of the two bits determines how port B address will be handled after each byte is transferred:\r\n\t\r\n\t\t\\begin{DMAList}\r\n\t\t\t\\item[{\\tt 00}] Address is decremented after byte is transferred.\r\n\t\t\t\t\r\n\t\t\t\\item[{\\tt 01}] Address is incremented after byte is transferred.\r\n\t\t\t\t\t\r\n\t\t\t\\item[{\\tt 10}] The address remains fixed at its starting value. This is typically used when port B is an I/O port; all bytes are sent to the same port in this case.\r\n\t\t\t\t\t\r\n\t\t\t\\item[{\\tt 11}] The same as {\\tt 10}, address is fixed.\r\n\t\t\\end{DMAList}\r\n\t\r\n\t\tIn case of decrementing or incrementing, the first byte is read from or written to the starting address for port B from \\DMARegName{WR4}, then decrementing or incrementing begins for the second and subsequent bytes.\r\n\t}\r\n\t\r\n\t\\DMADescriptionItem{6}{Port B Timing}{\r\n\t\tIf bit 6 is set, the next byte written to the DMA after \\DMARegName{WR2} base register byte is used to define port B variable timing. If bit 6 is {\\tt 0}, standard Z80 timing for read and write cycles is used.\r\n\t}\r\n\r\n\\end{DMADescription}\r\n\r\n\r\n\\subsubsection{Port B Timing}\r\n\r\nThis byte is expected if bit 6 of the base register byte is set. Only bits 5, 1 and 0 are used, the rest must be set to {\\tt 0}.\r\n\r\n\\begin{DMADescription}\r\n\t\r\n\t\\DMADescriptionItem{1-0}{Port A Timing}{\r\n\t\tSpecifies variable timing configuration for port A that allows shortening the length of port A read or write cycles:\r\n\r\n\t\t\\begin{DMAList}\r\n\t\t\t\\item[{\\tt 00}] Cycle length is 4.\r\n\t\t\t\\item[{\\tt 01}] Cycle length is 3.\r\n\t\t\t\\item[{\\tt 10}] Cycle length is 2.\r\n\t\t\t\\item[{\\tt 11}] Do not use!\r\n\t\t\\end{DMAList}\r\n\r\n\t\tThe cycle lengths are intended to selectively slow down read or write cycles for hardware that can't operate at the DMA full speed.\r\n\t}\r\n\r\n\t\\DMADescriptionItem{5}{Enable Prescalar}{\r\n\t\tIf set, then additional byte is expected with prescalar value used for fixed time transfers. See below for details.\r\n\t}\r\n\r\n\\end{DMADescription}\r\n\r\nIn contrast with Z80 DMA, zxnDMA doesn't support half-cycle timing for control signals.\r\n\r\n\r\n\\subsubsection{Prescalar - Fixed Time Transfer}\r\n\r\nThis byte is expected if bit 5 of ``Port B Timing'' is set. This is a feature of zxnDMA not present in Z80. If non-zero value is written, a delay will be inserted after each byte is transferred. The delay is calculated so that the total amount of time for each byte, including time required for actual transfer, is determined by the prescalar value.\r\n\r\nTo calculate prescalar value, use formula: $prescalar = 875kHz / rate$ where rate is desired frequency. For example to have a constant rate of 16kHz, prescalar needs to be set to 55 (calculation gives 54.6875 which needs to be rounded). The constant 875kHz is assumed for 28MHz system clock. But exact system clock depends on video timing selected by user (HDMI, VGA). The actual value should therefore be adjusted according to exact frequency as described with \\PortTextXRef{11}.\r\n\r\nFixed time transfer works in continuous and burst mode (see \\DMARegName{WR4}). In burst mode, DMA will give up any waiting time to the CPU so it can run while DMA is idle.\r\n\r\n\r\n\\pagebreak\r\n\\subsection{WR3 - Activation}\r\n\r\n% ▒█░░▒█ ▒█▀▀█ █▀▀█ \r\n% ▒█▒█▒█ ▒█▄▄▀ ░░▀▄ \r\n% ▒█▄▀▄█ ▒█░▒█ █▄▄█\r\n\r\nCompared to Z80 DMA, Next only uses one bit:\r\n\r\n\\begin{tikzpicture}\r\n\t\r\n\t% Instruction Byte\r\n\t\\DMABitHeader\r\n\t\\DMABitValue{7}{1}\r\n\t\\DMABitValue{6}{}\r\n\t\\DMABitValue{5}{0}\r\n\t\\DMABitValue{4}{0}\r\n\t\\DMABitValue{3}{0}\r\n\t\\DMABitValue{2}{0}\r\n\t\\DMABitValue{1}{0}\r\n\t\\DMABitValue{0}{0}\r\n\r\n\t% Bit 3 description\r\n\t\\DMABitDescTitle{6}{Activation}\r\n\t\\DMABitDescItem{6}{0}{DMA Disabled}\r\n\t\\DMABitDescItem{6}{1}{DMA Enabled}\r\n\t\r\n\\end{tikzpicture}\r\n\r\n\r\n\\subsubsection{Base Register Byte}\r\n\r\n\\begin{DMADescription}\r\n\t\r\n\t\\DMADescriptionItem{6}{Enable\\\\DMA}{\r\n\t\tIf set, DMA will be enabled, otherwise disabled. DMA should be enabled only after all other bytes are written.\r\n\r\n\t\tNote: while enabling/disabling through \\DMARegName{WR3} works on Next, it's recommended to use \\DMARegName{WR6} instead.\r\n\t}\r\n\r\n\\end{DMADescription}\r\n\r\n\\subsection{WR4 - Port B, Timing, Interrupt Control}\r\n\r\n% ▒█░░▒█ ▒█▀▀█ ░█▀█░ \r\n% ▒█▒█▒█ ▒█▄▄▀ █▄▄█▄ \r\n% ▒█▄▀▄█ ▒█░▒█ ░░░█░\r\n\r\nAnother register where zxnDMA uses only a small portion of functionality from Z80 DMA:\r\n\r\n\\begin{tikzpicture}\r\n\r\n\t\\pgfdeclarelayer{above}\r\n\t\\pgfsetlayers{main,above}\r\n\t\r\n\t% Instruction Byte\r\n\t\\DMABitHeader\r\n\t\\DMABitValue{7}{1}\r\n\t\\DMABitValue[2]{6}{}\r\n\t\\DMABitValue{4}{0}\r\n\t\\DMABitValue{3}{}\r\n\t\\DMABitValue{2}{}\r\n\t\\DMABitValue{1}{0}\r\n\t\\DMABitValue{0}{1}\r\n\r\n\t% Bit 6 description\r\n\t\\begin{pgfonlayer}{above}\r\n\t\t% we only need fill on top of text to avoid lines drawn on top. Coordinates were set via trial & error, so any change in data will also require re-positioning...\r\n\t\t\\node[fill=white, opacity=0.95, minimum width=3em, minimum height=5.2em] at(2.5,-3.1) {};\r\n\r\n\t\t\\DMABitDescTitle[-3ex]{6}{DMA Mode}[2.5em]\r\n\t\t\\DMABitDescItem{6}{\\DMATwoBits{0}{0}}{Do not use! {\\small (Behaves like continuous mode)}}\r\n\t\t\\DMABitDescItem{6}{\\DMATwoBits{0}{1}}{Continuous Mode}\r\n\t\t\\DMABitDescItem{6}{\\DMATwoBits{1}{0}}{Burst Mode}\r\n\t\t\\DMABitDescItem{6}{\\DMATwoBits{1}{1}}{Do not use!}\r\n\t\\end{pgfonlayer}\r\n\t\r\n\t% Parameters\r\n\t\\DMABitPar{2}{Port B Starting Address (LSB)}[1ex][pos=0.2]\r\n\t\\DMABitPar{3}{Port B Starting Address (MSB)}[][pos=0.2]\r\n\r\n\t% Legend\r\n\t\\DMALegend{\\DMABitParID{2}}[PARAMS]\r\n\r\n\\end{tikzpicture}\r\n\r\n\r\n\\subsubsection{Base Register Byte}\r\n\r\n\\begin{DMADescription}\r\n\r\n\t\\DMADescriptionItem{3-2}{Port B Starting Address}{\r\n\t\tSimilar to bits 4-3 of \\DMARegName{WR0}, these two bits indicate that port B address will follow. Bit 3 enables LSB and bit 2 MSB of the address. Each byte can be enabled separately, though most commonly, both are used. The address is interpreted either as memory or I/O port, based on the configuration from \\DMARegName{WR2}.\r\n\t}\r\n\t\r\n\t\\DMADescriptionItem{6-5}{DMA Mode}{\r\n\t\tSpecifes operating mode for DMA:\r\n\t\r\n\t\t\\begin{DMAList}\r\n\t\t\t\\item[{\\tt 00}] Not recommended for compatibility reasons: at the moment {\\tt 00} behaves exactly like {\\tt 01} (continuous mode) on zxnDMA, but on Z80 it's ``byte'' mode. So there is a possibility this will change in future cores.\r\n\t\t\t\t\r\n\t\t\t\\item[{\\tt 01}] Continuous mode. When the CPU starts DMA, it will run to completion without allowing the CPU to run. The CPU will only execute the next instruction after DMA completes.\r\n\t\t\t\t\r\n\t\t\t\\item[{\\tt 10}] Burst mode. In this mode, DMA will let the CPU run if either port is not ready. With zxnDMA, this condition can only occur when operating in fixed time transfer mode, as described with \\DMARegName{WR2}.\r\n\t\t\t\t\r\n\t\t\t\\item[{\\tt 11}] Do not use!\r\n\t\t\\end{DMAList}\r\n\t}\r\n\t\r\n\\end{DMADescription}\r\n\r\n\r\n\\subsubsection{Port B Starting Address}\r\n\r\nThis works exactly the same as port A starting address in bits 4-3 of \\DMARegName{WR0}, but for port B. Bit 3 of base register enables LSB and bit 4 MSB of the port B address. If both are set, then LSB is written before MSB. As port B address is also required for each DMA operation, both bytes are usually provided. And because the 16-bit value uses little-endian notation, it can be written directly. For example:\r\n\r\n\\begin{tcblisting}{}\r\n\tDW &253B          ; Port B starts at &253B\r\n\\end{tcblisting}\r\n\\vspace*{-1ex}\r\n\r\nWhether the address represents memory or I/O port is defined with \\DMARegName{WR2}.\r\n\r\n\r\n\\subsection{WR5 - Ready, Stop Configuration}\r\n\r\n% ▒█░░▒█ ▒█▀▀█ █▀▀ \r\n% ▒█▒█▒█ ▒█▄▄▀ ▀▀▄ \r\n% ▒█▄▀▄█ ▒█░▒█ ▄▄▀\r\n\r\n\\begin{tikzpicture}\r\n\t\r\n\t% Instruction Byte\r\n\t\\DMABitHeader\r\n\t\\DMABitValue{7}{1}\r\n\t\\DMABitValue{6}{0}\r\n\t\\DMABitValue{5}{}\r\n\t\\DMABitValue{4}{}\r\n\t\\DMABitValue{3}{0}\r\n\t\\DMABitValue{2}{0}\r\n\t\\DMABitValue{1}{1}\r\n\t\\DMABitValue{0}{0}\r\n\r\n\t% Bit 4 description\r\n\t\\DMABitDescTitle{4}{Ready Configuration}\r\n\t\\DMABitDescItem{4}{0}{\\DMAPinLabel{CE} only}\r\n\t\\DMABitDescItem{4}{1}{\\DMAPinLabel{CE} and \\DMAPinLabel{WAIT} multiplexed}\r\n\t\r\n\t% Bit 5 description\r\n\t\\DMABitDescTitle{5}{Stop Configuration}\r\n\t\\DMABitDescItem{5}{0}{Stop on End of Block}\r\n\t\\DMABitDescItem{5}{1}{Auto Restart on End of Block}\r\n\t\r\n\\end{tikzpicture}\r\n\r\n\r\n\\subsubsection{Base Register Byte}\r\n\r\n\\begin{DMADescription}\r\n\r\n\t\\DMADescriptionItem{4}{Ready Configuration}{\r\n\t\t\\begin{DMAList}\r\n\t\t\t\\item[{\\tt 0}] \\DMAPinLabel{CE}/\\DMAPinLabel{WAIT} line functions only as chip enable line, allowing CPU to read and write control and status bytes when DMA is not owning the bus.\r\n\r\n\t\t\t\\item[{\\tt 1}] This mode is implemented but currently not used in zxnDMA. This mode has an external device using the DMA's \\DMAPinLabel{CE} pin to insert wait states during the DMA's transfer.\r\n\t\t\\end{DMAList}\r\n\t}\r\n\r\n\t\\DMADescriptionItem{5}{Stop Configuration}{\r\n\t\tSpecifies what happens when DMA reaches the end of the block:\r\n\r\n\t\t\\begin{DMAList}\r\n\t\t\t\\item[{\\tt 0}] DMA stops once the end of the block is reached.\r\n\t\t\t\\item[{\\tt 1}] DMA will auto repeat at the end of the block.\r\n\t\t\\end{DMAList}\r\n\t}\r\n\r\n\\end{DMADescription}\r\n\r\n\r\n\\subsection{WR6 - Command Register}\r\n\r\n% ▒█░░▒█ ▒█▀▀█ ▄▀▀▄ \r\n% ▒█▒█▒█ ▒█▄▄▀ █▄▄░ \r\n% ▒█▄▀▄█ ▒█░▒█ ▀▄▄▀\r\n\r\nThis register is the most complex, but usually only a small subset of functionality is needed:\r\n\r\n\\begin{tikzpicture}\r\n\r\n\t\\newcommand{\\DMAWRBits}[5]{#1\\hspace*{1.8ex}#2\\hspace*{1.8ex}#3\\hspace*{1.8ex}#4\\hspace*{1.8ex}#5}\r\n\t\\newcommand{\\DMAWRHex}[2]{\\MemAddr{#1}\\hspace*{1.8ex}#2}\r\n\t\r\n\t% Instruction Byte\r\n\t\\DMABitHeader\r\n\t\\DMABitValue{7}{1}\r\n\t\\DMABitValue[5]{6}{}\r\n\t\\DMABitValue{1}{1}\r\n\t\\DMABitValue{0}{1}\r\n\r\n\t% Bit 6-2 description\r\n\t\\DMABitDescTitle[-7.5ex]{6}{Command}\r\n\t\\DMABitDescItem{6}{\\DMAWRBits{0}{0}{0}{0}{1}}{\\DMAWRHex{87}{Enable DMA}}\r\n\t\\DMABitDescItem{6}{\\DMAWRBits{0}{0}{0}{0}{0}}{\\DMAWRHex{83}{Disable DMA}}\r\n\t\\DMABitDescItem{6}{\\DMAWRBits{0}{0}{0}{1}{0}}{\\DMAWRHex{8B}{Reinitialize Status Byte}}\r\n\t\\DMABitDescItem{6}{\\DMAWRBits{0}{1}{0}{0}{1}}{\\DMAWRHex{A7}{Initialize Read Sequence}}\r\n\t\\DMABitDescItem{6}{\\DMAWRBits{0}{1}{1}{0}{0}}{\\DMAWRHex{B3}{Force Ready (irrelevant for zxnDMA)}}\r\n\t\\DMABitDescItem{6}{\\DMAWRBits{0}{1}{1}{1}{0}}{\\DMAWRHex{BB}{Read Mask Follows (see below)}}\r\n\t\\DMABitDescItem{6}{\\DMAWRBits{0}{1}{1}{1}{1}}{\\DMAWRHex{BF}{Read Status Byte}}\r\n\t\\DMABitDescItem{6}{\\DMAWRBits{1}{0}{0}{0}{0}}{\\DMAWRHex{C3}{Reset}}\r\n\t\\DMABitDescItem{6}{\\DMAWRBits{1}{0}{0}{0}{1}}{\\DMAWRHex{C7}{Reset Port A Timing}}\r\n\t\\DMABitDescItem{6}{\\DMAWRBits{1}{0}{0}{1}{0}}{\\DMAWRHex{CB}{Reset Port B Timing}}\r\n\t\\DMABitDescItem{6}{\\DMAWRBits{1}{0}{0}{1}{1}}{\\DMAWRHex{CF}{Load}}\r\n\t\\DMABitDescItem{6}{\\DMAWRBits{1}{0}{1}{0}{0}}{\\DMAWRHex{D3}{Continue}}\r\n    \r\n\t% Parameter\r\n\t\\DMABitParHeader{}{Read Mask}\r\n\t\\DMABitValue{7}{1}\r\n\t\\DMABitValue{6}{}\r\n\t\\DMABitValue{5}{}\r\n\t\\DMABitValue{4}{}\r\n\t\\DMABitValue{3}{}\r\n\t\\DMABitValue{2}{}\r\n\t\\DMABitValue{1}{}\r\n\t\\DMABitValue{0}{}\r\n\t\r\n\t% Read bytes\r\n\t\\DMABitPar{0}{Status}[2em][pos=0.5][]\r\n\t\\DMABitPar{1}{Byte Counter LSB {\\small (MSB in core 3.0.5 - bug)}}[][pos=0.39][]\r\n\t\\DMABitPar{2}{Byte Counter MSB {\\small (LSB in core 3.0.5 - bug)}}[][pos=0.33][]\r\n\t\\DMABitPar{3}{Port A Address LSB}[][pos=0.29][]\r\n\t\\DMABitPar{4}{Port A Address MSB}[][pos=0.27][]\r\n\t\\DMABitPar{5}{Port B Address LSB}[][pos=0.26][]\r\n\t\\DMABitPar{6}{Port B Address MSB}[][pos=0.25][]\r\n\t\r\n\t% Legend\r\n\t\\DMALegend{\\DMABitDefAnyID{1}{7}}[PARAM]\r\n\r\n\t% Render horizontal line and explanation text below last command parameter.\r\n\t\\begin{scope}\r\n\t\t\\draw[PrintableLightGray, line width=0.6pt]\r\n\t\t\t([xshift=15.5em,yshift=0ex]\\DMABitValID{0}.east |- \\DMALegendParID.west) -- \r\n\t\t\t([xshift=-1.5em,yshift=0ex]\\DMABitValID{7}.west |- \\DMALegendParID.west)\r\n\t\t\tnode (ReadDelimiterLine) {};\r\n\r\n\t\t% Read data text below delimiter\r\n\t\t\\node[dmalegend, anchor=north east, rotate=90, yshift=-1pt]\r\n\t\t\tat(ReadDelimiterLine.west)\r\n\t\t\t{READ FROM DMA I/O PORT};\r\n\t\\end{scope}\r\n\t\r\n\\end{tikzpicture}\r\n\r\n\r\n\\subsubsection{Base Register Byte}\r\n\r\n\\DMARegName{WR6} uses a slightly different configuration than other registers. Bits 7, 1 and 0 are always set while bits 6-2 are used together to specify the command to execute. Only a subset of possbible bit combinations are implemented. Some of the most relevant ones:\r\n\r\n\\begin{DMADescription}\r\n\t\r\n\t\\DMADescriptionByte{Enable DMA}{\r\n\t\tThis should be written as the last command of the DMA program to start executing.\r\n\t}\r\n\r\n\t\\DMADescriptionByte{Disable DMA}{\r\n\t\tIt's recommended to use this command at the start to ensure the whole program will be written before executing.\r\n\t}\r\n\r\n\t\\DMADescriptionByte{Load}{\r\n\t\tThis is required for DMA to copy port A and B addresses into its internal pointers. Usually, this is used just before \\textbf{Enable DMA}.\r\n\t}\r\n\r\n\t\\DMADescriptionByte{Read Mask}{\r\n\t\tThis is not one of the frequently used commands, but it's mentioned because it works differently: instead of indicating parameter bytes that will follow the register as part of the DMA program, it specifies which bytes will be read from the DMA port in the ``future''. See below for more details.\r\n\t}\r\n\r\n\\end{DMADescription}\r\n\r\n\r\n\\subsubsection{Read Mask}\r\n\r\nThis parameter provides a bit mask that defines which bytes will be read from DMA. While read mask parameter byte has to be written immediately after base register byte, as any other parameter, reading happens separately as I/O read from the DMA port.\r\n\r\n\\begin{DMADescription}\r\n\t\r\n\t\\DMADescriptionItem{0}{Status}{\r\n\t\tIndicates that the status byte will be read from the DMA I/O port. Status byte has the following format: {\\tt 00E1101T} where:\r\n\r\n\t\t\\begin{DMAList}\r\n\t\t\t\\item[{\\tt E}] is {\\tt 0} if the total block length was transferred at least once, {\\tt 1} otherwise.\r\n\t\t\t\\item[{\\tt T}] is {\\tt 0} if no byte transferred yet, {\\tt 1} if at least one byte was transferred.\r\n\t\t\\end{DMAList}\r\n\t}\r\n\r\n\t\\DMADescriptionItem{1-2}{Byte Counter}{\r\n\t\tIndicates that the 16-bit number of bytes transferred so far will be read from the DMA I/O port. Bit 1 indicates read for LSB and bit 2 for MSB of the value (note: core 3.0.5 has a bug that reverses the bytes, so bit 1 indicates read for MSB and bit 2 for LSB).\r\n\t}\r\n\r\n\t\\DMADescriptionItem{3-4}{Port A Address}{\r\n\t\tIndicates that the current internal 16-bit port A address will be read from the I/O port. Bit 3 indicates LSB and bit 4 MSB of the value will be read. Usually the address it read as the whole 16-bit value, so both bits are set.\r\n\t}\r\n\r\n\t\\DMADescriptionItem{5-6}{Port B Address}{\r\n\t\tSimilar to bits 3-4 above; indicates that the current internal 16-bit port B address will be read from the I/O port. Bit 3 indicates LSB and bit 4 MSB of the value will be read.\r\n\t}\r\n\t\r\n\\end{DMADescription}\r\n\r\n\r\n\\subsubsection{Reading From DMA I/O Port}\r\n\r\nRegisters can be read via an I/O read from the DMA port \\MemAddr{6B} after setting the read mask. Register values are the current internal DMA values. Or in other words: the values that will be used for the next transfer operation. Once the end of the read mask is reached, further reads loop around to the first one.\r\n\r\n\r\n\\subsection{Examples}\r\n\r\nDMA is another subject that may sound quite complicated when attempting to explain, but is really quite straighforward in practice. As you'll see in the following pages, most programs can use the same pattern with only slight changes. You can also find use of DMA to transfer data in various projects in companion code, for example {\\tt sprites} and {\\tt copper}.\r\n\r\n\r\n\\pagebreak\r\n\\subsubsection{Copy Data From Memory to Memory}\r\n\r\nSource is at memory address \\MemAddr{C000}, destination \\MemAddr{D000}, size 2048 bytes. We'll use port A as source, B as destination.\r\n\r\n\\begin{tcblisting}{}\r\nCopyMemory:\r\n\tLD HL, .dmaProgram     ; HL = pointer to DMA program\r\n\tLD B, .dmaProgramSize; B = size of the code\r\n\tLD C, &6B              ; C = &6B (zxnDMA port)\r\n\tOTIR                   ; upload DMA program\r\n\tRET\r\n\r\n.dmaProgram:\r\n\tDB %1'00000'11         ; WR6 - disable DMA\r\n\r\n\tDB %0'11'11'1'01       ; WR0 - append length + port A address, A->B\r\n\tDW &C000               ; WR0 par 1Band2 - port A start address\r\n\tDW 2048                ; WR0 par 3Band4 - transfer length\r\n\r\n\tDB %0'0'01'0'100       ; WR1 - A incr., A=memory\r\n\r\n\tDB %0'0'01'0'000       ; WR2 - B incr., B=memory\r\n\r\n\tDB %1'01'0'11'01       ; WR4 - continuous, append port B addres\r\n\tDW &D000               ; WR4 par 1Band2 - port B address\r\n\r\n\tDB %10'0'0'0010        ; WR5 - stop on end of block, CE only\r\n\r\n\tDB %1'10011'11         ; WR6 - load addresses into DMA counters\r\n\tDB %1'00001'11         ; WR6 - enable DMA\r\n.dmaProgramSize = &-.dmaProgram\r\n\\end{tcblisting}\r\n\r\nThe code includes both, the routine that copies the program into DMA memory and the program itself.\r\n\r\nCopy routine relies on {\\tt OTIR} to upload the program to DMA memory through port \\MemAddr{xx6B}. {\\tt OTIR} does all the heavy lifting for us - continuously copies bytes until {\\tt B} becomes 0. Perhaps worth noting: {\\tt .dmaProgramSize} is used to establish the length of the program that will be sent. This way we can safely add or remove instructions and it will continue to work (as long as the size stays within 256 bytes).\r\n\r\nThe program itself, lines 9-25, should be self-explanatory. But we'll go through it anyway since this is how most DMA programs look like:\r\n\r\n\\begin{itemize}[topsep=1pt,itemsep=1pt]\r\n\r\n\t\\item Line 9 uses \\DMARegName{WR6} with bits 6-2 set to {\\tt \\%00000} which corresponds to command ``Disable DMA''. It's good practice to disable DMA before uploading the rest of the program.\r\n\t\r\n\t\\item Next comes \\DMARegName{WR0} register in line 11; from least to most significant:\r\n\t\r\n\t\t\\begin{DMAList}\r\n\t\t\t\\item Bits 1-0 have the value {\\tt \\%01}, so ``transfer'' operation will be used. On zxnDMA this is the only allowed combination anyway.\r\n\t\t\t\\item Bit 2 establishes the direction of transfer A$\\rightarrow$B with value {\\tt 1}.\r\n\t\t\t\\item Next two bits, 4-3, are both set, which tells DMA we want to append both bytes of the port A starting address.\r\n\t\t\t\\item Similarly bits 6-5 tell DMA to expect both bytes of transfer length.\r\n\t\t\\end{DMAList}\r\n\r\n\t\\item Since we enabled all 4 parameters with \\DMARegName{WR0} register, we have to append all 4 bytes immediately afterwards. In this case, it's a 16-bit port A starting address first, followed by the 16-bit transfer length. Since little-endian format is expected (LSB first, then MSB), we can simply use a {\\tt DW} and write the exact address in a natural and readable way. Lines 12-13 is where the parameters are written.\r\n    \r\n\tNote: we could also use {\\tt DB} to write each byte separately. It emphasizes the fact two bytes are written, but obfuscates the address. Regardless, the program would then look like this:\r\n\r\n\t\t\\begin{tcblisting}{listing options={style=CodeStyle,firstnumber=12}}\r\n\tDB &00\r\n\tDB &C0    ; &C000\r\n\tDB &00\r\n\tDB &08    ; &0800 (=2048)\r\n\t\t\\end{tcblisting}\r\n\r\n\t\\item Line 15 specifies the configuration for port A with \\DMARegName{WR1} and line 17 for port B with \\DMARegName{WR2}. Both use the same:\r\n\t\r\n\t\t\\begin{DMAList}\r\n\t\t\t\\item Bit 3 is {\\tt 0} meaning port is memory.\r\n\t\t\t\\item Bits 5-4 are {\\tt \\%01} so address will increment after each byte.\r\n\t\t\t\\item Bit 6 is {\\tt 0} so we use default cycle length.\r\n\t\t\\end{DMAList}\r\n\r\n\t\\item Next comes \\DMARegName{WR4} in line 19 with which we specify additional configuration for port B:\r\n\t\r\n\t\t\\begin{DMAList}\r\n\t\t\t\\item Bits 3-2 are set, therefore both bytes of port B address are expected after the register.\r\n\t\t\t\\item Bits 6-5 are {\\tt \\%01} therefore DMA will run the program in continuous mode.\r\n\t\t\\end{DMAList}\r\n\r\n\t\\item 16-bit port B starting address follows in line 20.\r\n\t\r\n\t\\item Line 22 has \\DMARegName{WR5} register with bit 4 and 5 reset. Bit 4 tells DMA to use \\DMAPinLabel{CE} only and bit 5 to stop at the end of the block, after all bytes are transferred.\r\n\t\r\n\t\\item Line 24 uses \\DMARegName{WR6} with bits 6-2 set to {\\tt \\%10011} which tells DMA to load source and destination addresses into its own internal pointers. This command must always be included before the end of the program, otherwise DMA internal pointers may point to old values.\r\n\t\r\n\t\\item And finally, once everything is configured, line 25 includes another \\DMARegName{WR6} with bits 6-2 set to {\\tt \\%00001}. This corresponds to ``Enable DMA''. After encountering this command, DMA will start running the program.\r\n\\end{itemize}\r\n\r\nNote the use of apostrophes to delimit bits. This is special syntax for binary values, {\\tt sjasmplus} will strip them out, so {\\tt \\%1'00000'11} will become {\\tt \\%10000011} for example. I used it to emphasize individual bits and bit groups. You can use whichever you prefer though.\r\n\r\nPerhaps one more thing: the dot in front of {\\tt .dmaProgram} and {\\tt .dmaProgramSize} labels makes them private within last ``normal'' label ({\\tt CopyMemory} in our case). This is nice if your editor supports code completion; it will not offer these labels outside this scope.\r\n\r\n\r\n\r\n\\pagebreak\r\n\\subsubsection{Copy Data From Memory to I/O Port}\r\n\r\nSource is at memory address \\MemAddr{9000}, destination is port \\MemAddr{5B}, size 16384 bytes. We'll use port A as source, B as destination.\r\n\r\n\\begin{tcblisting}{}\r\nCopyMemory:\r\n\tLD HL, .dmaProgram     ; HL = pointer to DMA program\r\n\tLD B, .dmaProgramSize; B = size of the code\r\n\tLD C, &6B              ; C = &6B (zxnDMA port)\r\n\tOTIR                   ; upload DMA program\r\n\tRET\r\n\r\n.dmaProgram:\r\n\tDB %1'00000'11         ; WR6 - disable DMA\r\n\r\n\tDB %0'11'11'1'01       ; WR0 - append length + port A address, A->B\r\n\tDW &9000               ; WR0 par 1Band2 - port A start address\r\n\tDW 16384               ; WR0 par 3Band4 - transfer length\r\n\r\n\tDB %0'0'01'0'100       ; WR1 - A incr., A=memory\r\n\r\n\tDB %0'0'10'1'000       ; WR2 - B fixed, B=I/O\r\n\r\n\tDB %1'01'0'11'01       ; WR4 - continuous, append port B addres\r\n\tDW &005B               ; WR4 par 1Band2 - port B address\r\n\r\n\tDB %10'0'0'0010        ; WR5 - stop on end of block, CE only\r\n\r\n\tDB %1'10011'11         ; WR6 - load addresses into DMA counters\r\n\tDB %1'00001'11         ; WR6 - enable DMA\r\n.dmaProgramSize = &-.dmaProgram\r\n\\end{tcblisting}\r\n\r\nApart from the obvious differences - source and destination addresses and size in lines 12, 13 and 20, the program is almost the same as before.\r\n\r\nThe only other difference is port B setup in line 17. Because we're sending the bytes to an I/O port, which exists on a specific address and doesn't change, we need to tweak \\DMARegName{WR2} register data:\r\n\r\n\\begin{DMAList}\r\n\t\\item Bit 3 is now set to indicate port B is an I/O port.\r\n\t\\item Bits 5-4 are {\\tt \\%10} to indicate port B address is fixed.\r\n\\end{DMAList}\r\n\r\nWith this change, port B address will remain fixed at the given value of \\MemAddr{5B} throughout the whole transfer, while port A address will be incremented after each byte.\r\n\r\nWhile the result is quite different, the two programs share a lot of similarities. Even more so if we want to use this program multiple times, for transferring data to the same port but from another memory address or of a different size. As it stands now, we'd have to repeat the above program, only replace port A source and transfer length in lines 12-13.\r\n\r\nWell, we can use a neat trick to have a reusable DMA program and pass in the address and length as parameters! And it's right on the next page for easy comparison.\r\n\r\n\r\n\\subsubsection{Using Generic Routine for DMA Transfer}\r\n\r\nThe routine gets the address of the source memory through {\\tt HL} and length in {\\tt BC} register pair:\r\n\r\n\\begin{tcblisting}{}\r\nCopyMemory:\r\n\tLD (.dmaPortAAddress), HL      ; modify program with actual address\r\n\tLD (.dmaTransferLength), BC  ; modify program with actual length\r\n\r\n\tLD HL, .dmaProgram     ; HL = pointer to DMA program\r\n\tLD B, .dmaProgramSize; B = size of the code\r\n\tLD C, &6B              ; C = &6B (zxnDMA port)\r\n\tOTIR                   ; upload DMA program\r\n\tRET\r\n\r\n.dmaProgram:\r\n\tDB %1'00000'11         ; WR6 - disable DMA\r\n\r\n\tDB %0'11'11'1'01       ; WR0 - append length + port A address, A->B\r\n.dmaPortAAddress:\r\n\tDW 0                   ; WR0 par 1Band2 - port A start address\r\n.dmaTransferLength:\r\n\tDW 0                   ; WR0 par 3Band4 - transfer length\r\n\r\n\tDB %0'0'01'0'100       ; WR1 - A incr., A=memory\r\n\r\n\tDB %0'0'10'1'000       ; WR2 - B fixed, B=I/O\r\n\r\n\tDB %1'01'0'11'01       ; WR4 - continuous, append port B address\r\n\tDW &005B               ; WR4 par 1Band2 - port B address\r\n\r\n\tDB %10'0'0'0010        ; WR5 - stop on end of block, CE only\r\n\r\n\tDB %1'10011'11         ; WR6 - load addresses into DMA counters\r\n\tDB %1'00001'11         ; WR6 - enable DMA\r\n.dmaProgramSize = &-.dmaProgram\r\n\\end{tcblisting}\r\n\r\nDMA program is exactly the same, except for the two \\DMARegName{WR0} parameters.\r\n\r\nThe labels in lines 15 and 17 are the first part of the puzzle. They are used to get the exact memory address of the first byte of the 16-bit value declared with {\\tt DW 0}. Lines 2 and 3 are where the magic happens. We take the address from the labels and load the value from the corresponding register pair over it.\r\n\r\nThat's all there is to it. This is one of the most frequent implementations of DMA routines, you likely saw it in various code listings.\r\n\r\nThe technique is called ``self-modifying code'', for obvious reasons: we are modifying the program loaded into memory. It's a useful trick to keep in our bag, and this is just one of the simplest implementations. However, we should take care - it's very easy to modify wrong parts which can lead to all sorts of issues. So use with care!\r\n\r\n\r\n\\subsection{Miscellaneous}\r\n\r\n\r\n\\subsubsection{Operating Speed}\r\n\r\nThe zxnDMA operates at the same speed as the CPU.\r\n\r\nNote: at the moment of this writing, Next Dev Wiki\\footnote{\\url{https://wiki.specnext.dev/DMA\\#Operating_speed}} states that DMA automatically slows down if the speed exceeds 7MHz and Layer 2 display is being generated and then automatically resumes in high speed operation once Layer 2 display finishes generating. However this is no longer true on latest cores. Thanks to Alvin Albrecht for clarifying this!\r\n\r\n\r\n\\subsubsection{DMA and Interrupts}\r\n\r\nWhen zxnDMA controls the bus (when transfer is in progress), Z80 can't respond to interrupts. Here's detailed explanation from Next Dev Wiki\\footnote{\\url{https://wiki.specnext.dev/DMA\\#The_DMA_and_Interrupts}}:\r\n\r\n\\vspace*{-1ex}\r\n\\begin{quote}\r\n\tOn the Z80, the NMI interrupt is edge triggered so if an NMI occurs the fact that it occurred is stored internally in the Z80 so that it will respond when it is woken up. On the other hand, maskable interrupts are level triggered. That is, the Z80 must be active to regularly sample the \\ZilogPinLabel{INT} line to determine if a maskable interrupt is occurring. On the Spectrum and the ZX Next, the ULA (and line interrupt) are only asserted for a fixed amount of time, $\\sim$30 cycles at 3.5MHz. If the DMA is executing a transfer while the interrupt is asserted, the CPU will not be able to see this and it will most likely miss the interrupt.\r\n\\end{quote}\r\n\r\nHowever, when operating in burst mode, with large enough prescalar, the CPU will be able to respond to interrupts.\r\n\r\nIt's also possible to allow or prevent specific interrupters from interrupting DMA using Next specific Hardware IM2 mode. This is configured with Next registers \\PortTextXRef[]{CC}, \\PortTextXRef[]{CD} and \\PortTextXRef[]{CE} (pages \\PortPage{CC}-\\PortPage{CE}). See section \\XRef{zx_next_interrupts} for more details on interrupts.\r\n\r\n\r\n\\pagebreak\r\n\\subsection{DMA Ports and Registers}\r\n\\label{zx_next_dma_registers}\r\n\r\n% note: page number is excluded from XRef for all ports that are declared on the same page\r\n\r\n\\subsubsection{\\PortDeclaration{xx0B}}\r\n\r\nCore 3.1.2+: Always in Zilog DMA mode for uploading legacy DMA programs. For zxnDMA, use \\PortTextXRef[]{xx6B}.\r\n\r\nOlder cores: this port is not supported, set bit 6 of \\PortTextXRef{06} and use \\PortTextXRef[]{xx6B}.\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{xx6B}}\r\n\r\nCore 3.1.2+: Always in zxnDMA mode. For legacy Zilog DMA, use \\PortTextXRef[]{xx0B}.\r\n\r\nOlder cores: this port behaves either in zxnDMA or legacy Zilog DMA mode based on bit 6 of \\PortTextXRef{06}: if bit 6 is {\\tt 0}, zxnDMA mode is enabled, otherwise Zilog DMA.\r\n\r\n\r\n\\subsubsection{\\PortTextXRef[]{06}}\r\n\r\n\\PortDeclarationXRef{Sound}{06}\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{11}}\r\n\r\n\\newcommand{\\DMATimingItem}[4]{{\\tt #1} & clk28=#2#3 & #4 \\\\}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-3}\r\n\t\t\\PortDesc{Reserved, must be {\\tt 0}}\r\n\t\\PortBits{2-0}\r\n\t\t\\PortDesc{Video signal timing variant}\r\n\t\t\\PortDescOnly{\r\n\t\t\t\\begin{tabularx}{\\linewidth}{llX}\r\n\t\t\t\t\\DMATimingItem{000}{28}{000000}{Base VGA timing}\r\n\t\t\t\t\\DMATimingItem{001}{28}{571429}{VGA setting 1}\r\n\t\t\t\t\\DMATimingItem{010}{29}{464286}{VGA setting 2}\r\n\t\t\t\t\\DMATimingItem{011}{30}{000000}{VGA setting 3}\r\n\t\t\t\t\\DMATimingItem{100}{31}{000000}{VGA setting 4}\r\n\t\t\t\t\\DMATimingItem{101}{32}{000000}{VGA setting 5}\r\n\t\t\t\t\\DMATimingItem{110}{33}{000000}{VGA setting 6}\r\n\t\t\t\t\\DMATimingItem{111}{27}{000000}{HDMI}\r\n\t\t\t\\end{tabularx}\r\n\t\t}\r\n\\end{NextPort}\r\n\r\n\r\n\\subsubsection{\\PortTextXRef[]{CC}}\r\n\\vspace*{-2ex}\r\n\\subsubsection{\\PortTextXRef[]{CD}}\r\n\\vspace*{-2ex}\r\n\\subsubsection{\\PortTextXRef[]{CE}}\r\n\\PortDeclarationXRefMultiple{Interrupts}{CC}{CE}\r\n"
  },
  {
    "path": "chapter-next-interrupts.tex",
    "content": "\\section{Interrupts on Next}\r\n\\label{zx_next_interrupts}\r\n\r\n% ─────────────────────────────────────────────────────────────────────\r\n% ─██████████─██████──────────██████─██████████████─████████████████───\r\n% ─██░░░░░░██─██░░██████████──██░░██─██░░░░░░░░░░██─██░░░░░░░░░░░░██───\r\n% ─████░░████─██░░░░░░░░░░██──██░░██─██████░░██████─██░░████████░░██───\r\n% ───██░░██───██░░██████░░██──██░░██─────██░░██─────██░░██────██░░██───\r\n% ───██░░██───██░░██──██░░██──██░░██─────██░░██─────██░░████████░░██───\r\n% ───██░░██───██░░██──██░░██──██░░██─────██░░██─────██░░░░░░░░░░░░██───\r\n% ───██░░██───██░░██──██░░██──██░░██─────██░░██─────██░░██████░░████───\r\n% ───██░░██───██░░██──██░░██████░░██─────██░░██─────██░░██──██░░██─────\r\n% ─████░░████─██░░██──██░░░░░░░░░░██─────██░░██─────██░░██──██░░██████─\r\n% ─██░░░░░░██─██░░██──██████████░░██─────██░░██─────██░░██──██░░░░░░██─\r\n% ─██████████─██████──────────██████─────██████─────██████──██████████─\r\n% ─────────────────────────────────────────────────────────────────────\r\n\r\nLike many other functionalities, Next also inherits interrupts handling from ZX Spectrum. As described in the Z80 chapter, section \\XRef{z80_interrupts}, Interrupt Mode 0 is used for a short period of time after booting up, before ROM activates Mode 1. IM1 remains active unless we explicitly change it. To replace the default IM1 interrupt handler, we can page out ROM or change to Interrupt Mode 2.\r\n\r\n% note: we reference page number manually since both registers are declared on the same page, but if this changes in the future, we should update this text accordingly\r\nBoth IM1 and IM2 are triggered by standard Spectrum ULA on every video frame. However timing can be adjusted using \\PortTextXRef[]{22} and \\PortTextXRef[]{23} registers (page \\PortPage{22}). This allows disabling standard ULA interrupt, or add an extra interrupt that occurs on a particular video line.\r\n\r\nInterrupts are most frequently used for driving music playback. Though they can also be used for other purposes such as synchronizing game state etc.\r\n\r\n\r\n\\subsection{Interrupt Mode 1}\r\n\r\nIn Interrupt Mode 1, an interrupt handler is expected on address \\MemAddr{0038} in ROM. Default handler updates frame counter system variable, scans the keyboard and updates keyboard state system variables. We can replace it with our routine by paging out ROM.\r\n\r\nLet's see how to do this with an example. We will use the interrupt routine to update an 8-bit counter. The example uses {\\tt sjasmplus} directives to establish paging. If you are using a different assembler, you may need to change! First, let's prepare the groundwork - declare the variable and main part of the program:\r\n\r\n\\begin{tcblisting}{}\r\n\tDEVICE ZXSPECTRUMNEXT ; this is Next program - important for paging setup!\r\n\r\n\tORG &8000              ; set PC to &8000\r\nStart:\r\n\tDI                     ; disable interrupts while we page out ROM\r\n\tNEXTREG &50, 28        ; page out ROM in slot 0 (&000-&1FFF) with page 28\r\n\tIM 1                   ; enable Interrupt Mode 1\r\n\tEI                     ; enable interrupts\r\n\r\n.loop:\r\n\tJP .loop               ; infinite loop\r\n\tRET                    ; this is never reached...\r\n\r\ncounter: DB 0              ; counter variable\r\n\\end{tcblisting}\r\n\r\nThe first directive tells {\\tt sjasmplus} to generate the code for Next. This will become important later on. Then we set the program counter to \\MemAddr{8000}; all subsequent instructions and data will be assembled starting at this address.\r\n\r\nNext, we are paging out ROM in 8K slot 0 with bank 28. We'll write our interrupt handler subroutine into this bank later on. Afterwards, we enable Interrupt Mode 1. This is optional; by default, Next will run in this mode already, but being explicit is more future proof. Maybe another program would change to IM2. Note how we disable interrupts during this setup to prevent undesired side effects.\r\n\r\nThe remaining part is simply an infinite loop to prevent the program from exiting. And finally, we declare our counter variable.\r\n\r\nThe interrupt subroutine is expected at \\MemAddr{0038}. There are several ways to achieve this with {\\tt sjasmplus}. I opted for explicit slot/bank technique so we're in control of the paging:\r\n\r\n\\begin{tcblisting}{}\r\n\tSLOT 6             ; activate slot 6\r\n\tPAGE 28            ; load page 28K to active slot\r\n\tORG &C038          ; set PC to &C038\r\n\r\nInterruptHandler:\r\n\tLD HL, counter     ; load address of counter var\r\n\tINC (HL)           ; increment it\r\n\tEI                 ; enable interrupts\r\n\tRETI               ; return from interrupt\r\n\\end{tcblisting}\r\n\r\nThis is where the previously mentioned {\\tt DEVICE} directive comes to play - {\\tt sjasmplus} decides slot and bank configuration based on it. {\\tt ZXSPECTRUMNEXT} assumes 8K slot and bank size. Lines 1-3 are the key to ensure our interrupt handler will be present on \\MemAddr{0038}:\r\n\r\n\\begin{itemize}\r\n\t\\item {\\tt SLOT} directive tells {\\tt sjasmplus} we want the following section to be loaded into 8K slot 6, addresses \\MemAddr{C000}-\\MemAddr{DFFF}.\r\n\t\r\n\t\\item Next, we specify 8K bank number to load into the selected slot with {\\tt PAGE} directive. Subsequent code will be assembled into this bank. This step is optional; default bank would be used otherwise, 0 in this case (see section \\XRef{zx_next_memorypaging}). Being explicit is more future proof though. I chose bank 28 but feel free to use others. What's important is to use the same bank with {\\tt NEXTREG} instruction when paging out ROM!\r\n\t\r\n\t\\item Since we selected slot 6, we also need to set the program counter to the corresponding address - we want the code to be assembled into the selected bank that we will page into ROM slot 0 at runtime. Because interrupt handler is expected on \\MemAddr{0038}, we need to start at \\MemAddr{C038} (slot 6 starts at \\MemAddr{C000}, but this will be loaded into slot 0 at \\MemAddr{0000}).\r\n\\end{itemize}\r\n\r\nNot that hard, right!? It may take a while to wrap the head around those {\\tt SLOT}, {\\tt PAGE} and {\\tt ORG} directives and addresses, but it's quite straightforward otherwise. While at it: this same technique can be used to load assets into specific banks and then page them in during runtime!\r\n\r\nYou can find the full source code for this example in companion code, folder {\\tt im1}. Feel free to run it, set breakpoints and see how the counter is being changed.\r\n\r\nNote there's one potentially deal-breaking issue with this approach: since we are paging out ROM, we can't use any of its functionality. For example, ROM routines like print text at \\MemAddr{203C}. But we can do this with IM2 - read on!\r\n\r\n\r\n\\subsection{Interrupt Mode 2}\r\n\r\nOnce Interrupt Mode 2 is activated, mode 1 handler at \\MemAddr{0038} isn't called anymore. Instead, when an interrupt occurs, Z80 performs the following steps:\r\n\r\n\\begin{itemize}[topsep=1pt,itemsep=1pt]\r\n\t\\item First, a 16-bit address is formed where the value for the most significant byte is taken from the {\\tt I} register and the value for the least significant byte from the current value of the data bus.\r\n\t\r\n\t\\item Two bytes are read from this address (little endian format is assumed - low byte first, then high byte); these 2 bytes form another 16-bit address.\r\n\t\r\n\t\\item It's this second address that the CPU treats as an interrupt routine and starts executing from.\r\n\\end{itemize}\r\n\r\n\\vspace*{1ex}\r\n\\begin{tabularx}{\\linewidth}{p{6cm}X}\r\n\t\\begin{tikzpicture}[\r\n\t\tbaseline=(bus.base),\r\n\t\tframed/.style={draw, font=\\ttfamily, minimum width=2cm, minimum height=0.6cm},\r\n\t\tfilled/.style={framed, fill=PrintableLightGray}\r\n\t]\r\n\t\t\r\n\t\t\\node[filled, minimum height=1.5cm] (contentstart) {};\r\n\t\t\\node[framed, below=0pt of contentstart] (contentxx00) {yy\\Low};\r\n\t\t\\node[framed, below=0pt of contentxx00] (contentxx01) {yy\\High};\r\n\t\t\\node[framed, below=0pt of contentxx01] (contentxx02) {yy\\Low};\r\n\t\t\\node[framed, below=0pt of contentxx02] (contentxx03) {yy\\High};\r\n\t\t\\node[framed, minimum height=1cm, below=0pt of contentxx03] (contentxx04) {\\vdots};\r\n\t\t\\node[framed, below=0pt of contentxx04] (contentxxfe) {yy\\Low};\r\n\t\t\\node[framed, below=0pt of contentxxfe] (contentxxff) {yy\\High};\r\n\t\t\\node[filled, minimum height=1cm, below=0pt of contentxxff] (contentmiddle) {};\r\n\t\t\\node[framed, minimum height=1.5cm, text width=1.5cm, below=0pt of contentmiddle] (contentyyyy) {\\rmfamily interrupt handler};\r\n\t\t\t\r\n\t\t\\node[left=0pt of contentstart.north west, anchor=north east] (bus) {data bus};\r\n\t\t\\node[left=8pt of contentstart.north west, anchor=north east, yshift=-15pt] (I) {\\tt I(xx)};\r\n\t\t\t\r\n\t\t\\node[left=0pt of contentxx00] (memxx00) {\\MemAddr{xx00}};\r\n\t\t\\node[left=0pt of contentxx01] (memxx01) {\\MemAddr{xx01}};\r\n\t\t\\node[left=0pt of contentxx02] (memxx02) {\\MemAddr{xx02}};\r\n\t\t\\node[left=0pt of contentxx03] (memxx03) {\\MemAddr{xx03}};\r\n\t\t\\node[left=0pt of contentxxfe] (memxxfe) {\\MemAddr{xxFE}};\r\n\t\t\\node[left=0pt of contentxxff] (memxxff) {\\MemAddr{xxFF}};\r\n\t\t\\node[left=0pt of contentyyyy.north west, anchor=north east] (memyyyy) {\\MemAddr{yyyy}};\r\n\t\t\t\r\n\t\t\\draw[decorate,decoration={brace,amplitude=5pt,raise=3pt},yshift=0pt]\r\n\t\t\t(contentxx00.north east) -- (contentxx01.south east)\r\n\t\t\tnode[midway,xshift=1.5ex] (yyyyaddress) {};\r\n\t\t\r\n\t\t\\path[->, bend left, out=100, in=90] (yyyyaddress.east) edge (contentyyyy.north east);\r\n\t\t\t\r\n\t\t\\path[->, draw] (I.295) -- (memxx00.105);\r\n\t\t\\path[->, draw] (bus.335) -- (memxx00.45);\r\n\t\t\r\n\t\\end{tikzpicture}\r\n\r\n\t&\r\n\r\n\t\\vspace*{-1em}\r\n\r\n\t% paragraphs don't work within tabular, so we use left aligned description instead...\r\n\t\\begin{description}[topsep=0pt,itemsep=1pt,labelindent=-1.25ex,leftmargin=0cm]\r\n\t\t\\item In other words:\r\n\t\t\r\n\t\t\\item Because the LSB for the vector table address is effectively a random number, we need to allocate 256 bytes in the memory, on 256-byte boundary (meaning any address with low byte \\MemAddr{00} - \\MemAddr{xx00}). This gives us a chunk of memory where low byte starts at \\MemAddr{00} up to \\MemAddr{FF}, thus covering all possible 8-bit values the data bus can ``throw'' at us. This chunk, called ``vector table'', is 256 bytes long and consists of 128 16-bit addresses (vectors), all pointing to the IM2 interrupt handler routine.\r\n\t\t\r\n\t\t\\item We are responsible for assigning the high byte of the vector table address to {\\tt I} register though. Together 16-bit address for vector table lookup looks like this:\r\n\t\\end{description}\r\n\t\r\n\t\\vspace*{1ex}\r\n\r\n\t{ % tabularx requires inner table to be embedded within curlies...\r\n\t\\begin{ElegantTable}{|C{3cm}|C{3cm}|}\r\n\t\t\\ElegantHeader{\\EH{15-8} & \\EH{7-0}}\r\n\r\n\t\t\\rowcolor{white} % not sure why header colour is spilled over the whole table in this instance!?\r\n\t\t{\\tt I} register & Data Bus \\\\\r\n\t\\end{ElegantTable}\r\n\t}\r\n\r\n\t\\\\\r\n\\end{tabularx}\r\n\r\nPhew, a lot of words and concepts to grasp. But it's simpler than it sounds - let's rewrite the IM1 example, but this time with IM2. The main program first:\r\n\r\n\\begin{tcblisting}{}\r\n\tORG &8000              ; set PC to &8000\r\nStart:\r\n\tDI                     ; disable interrupts while we setup interrupts\r\n\tCALL SetupInterruptVectors\r\n\tIM 2                   ; enable Interrupt Mode 2\r\n\tEI                     ; enable interrupts\r\n\t|(the rest is the same as in IM1 example)|\r\n\\end{tcblisting}\r\n\r\nAlmost the same except for the {\\tt NEXTREG} replaced with {\\tt SetupInterruptVectors} subroutine call that initializes vector table:\r\n\r\n\\begin{tcblisting}{}\r\nSetupInterruptVectors:\r\n\tLD DE, InterruptHandler        ; prepare pointer to IM2 routine\r\n\tLD HL, InterruptVectorTable   ; prepare pointer to vector table\r\n\tLD B, 128                      ; we need to fill 128 addresses\r\n.loop:\r\n\tLD (HL), E                     ; copy low byte\r\n\tINC HL                         ; increment vector table pointer\r\n\tLD (HL), D\t                   ; copy high byte\r\n\tINC HL                         ; increment vector table pointer\r\n\tDJNZ .loop                     ; repeat until the end of the vector table\r\n\tLD A, InterruptVectorTable >> 8\r\n\tLD I, A                        ; I now holds high byte of vector table\r\n\tRET\r\n\\end{tcblisting}\r\n\r\nThe subroutine fills in all 128 entries of the vector table with the address of our actual interrupt routine. The only remaining piece is the declaration of the vector table itself; I chose {\\tt .ALIGN 256} directive that fills in bytes until 256-byte boundary is reached:\r\n\r\n\\begin{tcblisting}{}\r\n\t.ALIGN 256                     ; section must start on 256-byte boundary &xx00\r\nInterruptVectorTable:              ; I register should therefore have value &xx\r\n\tDEFS 128*2                     ; 128 16-bit vectors\t\r\n\\end{tcblisting}\r\n\r\nThe interrupt handler itself can reside anywhere in the memory. Code-wise it's the same as for IM1 mode previously.\r\n\r\nSo there's some more work when using IM2 mode, but it leaves ROM untouched so we can rely on its routines and other functionality. I only demonstrated relevant bits here. You can find a fully working example in companion code, folder {\\tt im2} (make sure to \\textbf{read the next section}!).\r\n\r\n\r\n\\subsubsection{What About Odd Data Bus Values?}\r\n\r\nSharp-eyed readers may be wondering what would happen if the value from the data bus is odd? Given our IM2 example from above, our interrupt handler happens to be on address \\MemAddr{802A}. Therefore the vector table would have the following contents:\r\n\r\n\\begin{ElegantTable}{|c|c|c|c|C{3cm}|c|c|}\r\n\t\\ElegantHeader{\\MemAddr{xx00} & \\MemAddr{xx01} & \\MemAddr{xx02} & \\MemAddr{xx03} & ... & \\MemAddr{xxFE} & \\MemAddr{xxFF}}\r\n\r\n\t\\MemAddr{2A} & \\MemAddr{80} & \\MemAddr{2A} & \\MemAddr{80} & ... & \\MemAddr{2A} & \\MemAddr{80} \\\\\r\n\\end{ElegantTable}\r\n\r\nIf the bus value is even, for example {\\tt 0}, {\\tt 2}, {\\tt 4} etc, then the address of the interrupt handler would be correctly read as \\MemAddr{802A} (remember, Z80 is little-endian). But what if the value is odd, {\\tt 1}, {\\tt 3}, {\\tt 5} etc? In this case, 16-bit interrupt handler address would be wrong - \\MemAddr{2A80}! During my tests, this didn't happen - whether by luck, the data bus always had an even number, or, maybe Z80 reset bit 0 before constructing vector lookup address. But we can't rely on luck!\r\n\r\nIn fact, Next Dev Wiki\\footnote{\\url{https://wiki.specnext.dev/Interrupts}} recommends that the interrupt handler routine is always placed on an address where high and low bytes are equal. It's best to follow this advice to avoid potential issues. The changes to the code are minimal, so I won't show it here - it could be a nice exercise though! Just a tip - to be extra safe, make vector table 257 bytes long in case the data bus has \\MemAddr{FF}. You can find a working example in companion code, folder {\\tt im2safe}.\r\n\r\n\r\n\\subsection{Hardware Interrupt Mode 2}\r\n\r\nIn addition to regular IM2, Next also supports a ``Hardware IM2'' mode. This mode works similar to legacy IM2 in that we still need to provide vector tables. But it properly implements the Z80 IM2 scheme with daisy chain priority. So when particular interrupt subroutine is called, we know exactly which device caused it without having to figure it out as needed in legacy IM2. Let's go over the details with an example. First, the initialization:\r\n\r\n% note: Band will be converted to & and Bor to | when rendering...\r\n\\begin{tcblisting}{}\r\n\tDI                             ; disable interrupts\r\n\tNEXTREG &C0, (InterruptVectorTable Band %11100000) Bor %00000001\r\n\tNEXTREG &C4, %10000001         ; enable expansion bus INT and ULA interrupts\r\n\tNEXTREG &C5, %00000000         ; disable all CTC channel interrupts\r\n\tNEXTREG &C6, %00000000         ; disable UART interrupts\r\n\t\r\n\tLD A, InterruptVectorTable >> 8\r\n\tLD I, A                        ; I now holds high byte of vector table\r\n\r\n\tIM 2                           ; enable HW Interrupt Mode 2\r\n\tEI                             ; enable interrupts\r\n\\end{tcblisting}\r\n\r\nLine 3 is where hardware IM2 mode is established. The crucial part is \\PortTextXRef{C0} register: firstly, we are supplying the top 3 bits of LSB of the vector table to bits 7-5, and secondly, we enable IM2 mode by setting bit 0.\r\n\r\nLines 4-6 enable or disable specific interrupters with \\PortTextXRef{C4}, \\PortTextXRef{C5} and \\PortTextXRef{C6}.\r\n\r\nLines 8-12 are the same as with legacy IM2 mode - we assign the LSB of the vector table address to {\\tt I} register. Then we enable IM2 mode and interrupts.\r\n\r\nInterrupt vectors table is quite a bit different (in a good way though):\r\n\r\n\\begin{tcblisting}{}\r\n\t.ALIGN 32\r\nInterruptVectorTable:\r\n\tDW InterruptHandler        ; 0 = line interrupt (highest priority)\r\n\tDW InterruptHandler        ; 1 = UART0 Rx\r\n\tDW InterruptHandler        ; 2 = UART1 Rx\r\n\tDW InterruptHandler        ; 3 = CTC channel 0\r\n\tDW InterruptHandler        ; 4 = CTC channel 1\r\n\tDW InterruptHandler        ; 5 = CTC channel 2\r\n\tDW InterruptHandler        ; 6 = CTC channel 3\r\n\tDW InterruptHandler        ; 7 = CTC channel 4\r\n\tDW InterruptHandler        ; 8 = CTC channel 5\r\n\tDW InterruptHandler        ; 9 = CTC channel 6\r\n\tDW InterruptHandler        ; 10 = CTC channel 7\r\n\tDW InterruptHandlerULA     ; 11 = ULA\r\n\tDW InterruptHandler        ; 12 = UART0 Tx\r\n\tDW InterruptHandler        ; 13 = UART1 Tx (lowest priority)\r\n\tDW InterruptHandler\r\n\tDW InterruptHandler\r\n\\end{tcblisting}\r\n\r\nAs you can see, each interrupter gets its own vector. In the above example, all except ULA are pointing to the same interrupt routine. Since there are only a handful, we can use a much clearer declaration with {\\tt DW <routine address>}. This way we don't need any initialization code that would fill in the routine address as we used with legacy IM2 mode.\r\n\r\nThe thing to note: {\\tt .ALIGN 32} is used to ensure the interrupt table is placed on a 32-byte boundary; the least significant 5 bits of the address must be {\\tt 0} ($2^5=32=$ {\\tt \\%100000}). This is important due to how hardware IM2 vector table lookup address is formed during interrupt:\r\n\r\n\\begin{BitTableWord}\r\n\t\\BitStartMulti{8}{{\\tt I} register: MSB} & \\BitMulti{3}{\\MemAddr{C0}: LSB 7-5} & \\BitMulti{5}{Interrupt specific} \\\\\r\n\\end{BitTableWord}\r\n\r\nAs with legacy IM2 mode, the most significant byte of the vector table address is assigned to {\\tt I} register. But the least significant byte is not random. We provide the top 3 bits through \\PortTextXRef{C0} Next register, the rest are filled in based on interrupt type:\r\n\r\n\\begin{tabular}{cl}\r\n\t{\\tt 0} & Line interrupt (highest priority) \\\\\r\n\t{\\tt 1} & UART0 Rx \\\\\r\n\t{\\tt 2} & UART1 Rx \\\\\r\n\t{\\tt 3-10} & CTC Channels 0-7 \\\\\r\n\t{\\tt 11} & ULA \\\\\r\n\t{\\tt 12} & UART0 Tx \\\\\r\n\t{\\tt 13} & UART1 Tx (lowest priority) \\\\\r\n\\end{tabular}\r\n\r\nInterrupt routines can reside anywhere in the memory.\r\n\r\nYou can find fully working example in companion code, folder {\\tt im2hw}.\r\n\r\nWith hardware IM2 mode it's possible to interrupt DMA operations. The choice of interrupters that can interrupt DMA is made with \\PortTextXRef{CC}, \\PortTextXRef{CD} and \\PortTextXRef{CE} registers. Here's what Alvin Albrecht wrote about this possibility on Next Discord server:\r\n\r\n\\vspace*{-1ex}\r\n\\begin{quote}\r\n\tIn this mode, it is also possible to program interrupters to interrupt DMA operations. Interrupting a DMA operation comes with a new caveat since the Z80 cannot see an interrupt until the end of an instruction. So if the DMA gives up the bus temporarily for an interrupt, then the Z80 will execute one instruction in the main program until the interrupt is seen. The interrups subroutine will execute and {\\tt RETI} will return control to the DMA. Anyway there is another rabbit hole here.\r\n\\end{quote}\r\n\r\nFor details and more, see this discussion on Discord\\footnote{\\url{https://discord.com/channels/556228195767156758/692885312296190102/894284968614854749}}, highly recommended!\r\n\r\nVery special thanks to the folks from Next Discord server: Alvin Albrecht for mentioning\\footnote{\\url{https://discord.com/channels/556228195767156758/692885312296190102/865955247552462848}} hardware IM2 mode and \\discord{varmfskii} whos discussion\\footnote{\\url{https://discord.com/channels/556228195767156758/692885353161293895/817807486744526886}} and sample code was the basis for my exploration into this mode!\r\n\r\n\r\n\r\n\\pagebreak\r\n\\subsection{Interrupt Registers}\r\n\\label{zx_next_interrupts_registers}\r\n\r\n\\subsubsection{\\PortDeclaration{22}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7}\r\n\t\t\\PortDesc{Read: \\ZilogPinLabel{INT} signal (even when Z80N has interrupts disabled) ({\\tt 1} = interrupt is requested)}\r\n\t\t\\PortDescOnly{Write: Reserved, must be {\\tt 0}}\r\n\t\\PortBits{6-3}\r\n\t\t\\PortDesc{Reserved, must be {\\tt 0}}\r\n\t\\PortBits{2}\r\n\t\t\\PortDesc{{\\tt 1} disables original ULA interrupt ({\\tt 0} after reset)}\r\n\t\\PortBits{1}\r\n\t\t\\PortDesc{{\\tt 1} enables Line Interrupt ({\\tt 0} after reset)}\r\n\t\\PortBits{0}\r\n\t\t\\PortDesc{MSB of interrupt line value ({\\tt 0} after reset)}\r\n\\end{NextPort}\r\n\r\nLine value starts with 0 for the first line of pixels. But the line-interrupt happens already when the previous line's pixel area is finished (i.e. the raster-line counter still reads \"previous line\" and not the one programmed for interrupt). The \\ZilogPinLabel{INT} signal is raised while display beam horizontal position is between 256-319 standard pixels, precise timing of interrupt handler execution then depends on how-quickly/if the Z80 will process the \\ZilogPinLabel{INT} signal.\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{23}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-0}\r\n\t\t\\PortDesc{LSB of interrupt line value ({\\tt 0} after reset)}\r\n\\end{NextPort}\r\n\r\n% note: port page is not used here since the declaration is on the same page\r\nOn core 3.1.5+ line numbering can be offset by \\PortTextXRef[]{64}.\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{64}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-0}\r\n\t\t\\PortDesc{Vertical line offset value {\\tt 0}-{\\tt 255} added to Copper, Video Line Interrupt and Active Video Line readings.}\r\n\\end{NextPort}\r\n\r\nCore 3.1.5+ only.\r\n\r\nNormally the ULA's pixel row 0 aligns with vertical line count 0. With a non-zero offset, the ULA's pixel row 0 will align with the vertical line offset. For example, if the offset is 32 then video line 32 will correspond to the first pixel row in the ULA and video line 0 will align with the first pixel row of the Tilemap and Sprites (in the top border area).\r\n\r\nSince a change in offset takes effect when the ULA reaches row 0, the change can take up to one frame to occur.\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{C0}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-5}\r\n\t\t\\PortDesc{Programmable portion of IM2 vector}\r\n\t\\PortBits{4}\r\n\t\t\\PortDesc{Reserved, must be {\\tt 0}}\r\n\t\\PortBits{3}\r\n\t\t\\PortDesc{{\\tt 1} enables, {\\tt 0} disabled stackless NMI response}\r\n\t\\PortBits{2-1}\r\n\t\t\\PortDesc{Reserved, must be {\\tt 0}}\r\n\t\\PortBits{0}\r\n\t\t\\PortDesc{Maskable interrupt mode: {\\tt 1} IM2, {\\tt 0} pulse}\r\n\\end{NextPort}\r\n\r\n% note port xrefs don't use pages here since both ports are declared on the same page, immediately below\r\nIf bit 3 is set, the return address pushed during an NMI acknowledge cycle will be written to \\PortTextXRef[]{C2} and \\PortTextXRef[]{C3} instead of the memory (the stack pointer will be decremented). The first {\\tt RETN} after the NMI acknowledge will then take its return address from the registers instead of memory (the stack pointer will be incremented). If bit 3 is {\\tt 0}, and in other circumstances (if there is no NMI first), {\\tt RETN} functions normally.\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{C2}}\r\n\\vspace*{-2ex}\r\n\\subsubsection{\\PortDeclaration{C3}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-0}\r\n\t\t\\PortDesc{LSB or MSB of the return address written during an NMI acknowledge cycle}\r\n\\end{NextPort}\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{C4}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7}\r\n\t\t\\PortDesc{Expansion bus \\ZilogPinLabel{INT} ({\\tt 1} after reset)}\r\n\t\\PortBits{6-2}\r\n\t\t\\PortDesc{Reserved, must be 0}\r\n\t\\PortBits{1}\r\n\t\t\\PortDesc{{\\tt 1} enables, {\\tt 0} disables line interrupt ({\\tt 0} after reset)}\r\n\t\\PortBits{0}\r\n\t\t\\PortDesc{{\\tt 1} enables, {\\tt 0} disabled ULA interrupt ({\\tt 1} after reset)}\r\n\\end{NextPort}\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{C5}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7}\r\n\t\t\\PortDesc{{\\tt 1} enables, {\\tt 0} disables CTC channel 7 interrupt}\r\n\t\\PortBits{6}\r\n\t\t\\PortDesc{{\\tt 1} enables, {\\tt 0} disables CTC channel 6 interrupt}\r\n\t\\PortBits{5}\r\n\t\t\\PortDesc{{\\tt 1} enables, {\\tt 0} disables CTC channel 5 interrupt}\r\n\t\\PortBits{4}\r\n\t\t\\PortDesc{{\\tt 1} enables, {\\tt 0} disables CTC channel 4 interrupt}\r\n\t\\PortBits{3}\r\n\t\t\\PortDesc{{\\tt 1} enables, {\\tt 0} disables CTC channel 3 interrupt}\r\n\t\\PortBits{2}\r\n\t\t\\PortDesc{{\\tt 1} enables, {\\tt 0} disables CTC channel 2 interrupt}\r\n\t\\PortBits{1}\r\n\t\t\\PortDesc{{\\tt 1} enables, {\\tt 0} disables CTC channel 1 interrupt}\r\n\t\\PortBits{0}\r\n\t\t\\PortDesc{{\\tt 1} enables, {\\tt 0} disables CTC channel 0 interrupt}  \r\n\\end{NextPort}\r\n\r\nAll bits {\\tt 0} after reset.\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{C6}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7}\r\n\t\t\\PortDesc{Reserved, must be {\\tt 0}}\r\n\t\\PortBits{6}\r\n\t\t\\PortDesc{UART1 Tx empty}\r\n\t\\PortBits{5}\r\n\t\t\\PortDesc{UART1 Rx half full}\r\n\t\\PortBits{4}\r\n\t\t\\PortDesc{UART1 Rx available}\r\n\t\\PortBits{3}\r\n\t\t\\PortDesc{Reserved, must be {\\tt 0}}\r\n\t\\PortBits{2}\r\n\t\t\\PortDesc{UART0 Tx empty}\r\n\t\\PortBits{1}\r\n\t\t\\PortDesc{UART0 Rx half full}\r\n\t\\PortBits{0}\r\n\t\t\\PortDesc{UART0 Rx available}\r\n\\end{NextPort}\r\n\r\nAll bits {\\tt 0} after reset. Rx half full overrides Rx available.\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{C8}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-2}\r\n\t\t\\PortDesc{Reserved, must be {\\tt 0}}\r\n\t\\PortBits{1}\r\n\t\t\\PortDesc{Line interrupt}\r\n\t\\PortBits{0}\r\n\t\t\\PortDesc{ULA interrupt}\r\n\\end{NextPort}\r\n\r\nRead indicates whether the given interrupt was generated in the past. Write with {\\tt 1} clears given bit unless in IM2 mode (bit 0 set on \\PortTextXRef{C0}) with interrupts enabled.\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{C9}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7}\r\n\t\t\\PortDesc{CTC channel 7 interrupt}\r\n\t\\PortBits{6}\r\n\t\t\\PortDesc{CTC channel 6 interrupt}\r\n\t\\PortBits{5}\r\n\t\t\\PortDesc{CTC channel 5 interrupt}\r\n\t\\PortBits{4}\r\n\t\t\\PortDesc{CTC channel 4 interrupt}\r\n\t\\PortBits{3}\r\n\t\t\\PortDesc{CTC channel 3 interrupt}\r\n\t\\PortBits{2}\r\n\t\t\\PortDesc{CTC channel 2 interrupt}\r\n\t\\PortBits{1}\r\n\t\t\\PortDesc{CTC channel 1 interrupt}\r\n\t\\PortBits{0}\r\n\t\t\\PortDesc{CTC channel 0 interrupt}\r\n\\end{NextPort}\r\n\r\n% note: we use comma for referencing port declaration page to avoid double closing parenthesis, more readable this way\r\nRead indicates whether the given interrupt was generated in the past. Write with {\\tt 1} clears given bit unless in IM2 mode (bit 0 set on \\PortTextXRef[,]{C0}) with interrupts enabled.\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{CA}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7}\r\n\t\t\\PortDesc{Reserved, must be {\\tt 0}}\r\n\t\\PortBits{6}\r\n\t\t\\PortDesc{UART1 Tx empty interrupt}\r\n\t\\PortBits{5}\r\n\t\t\\PortDesc{UART1 Rx half full interrupt}\r\n\t\\PortBits{4}\r\n\t\t\\PortDesc{UART1 Rx available interrupt}\r\n\t\\PortBits{3}\r\n\t\t\\PortDesc{Reserved, must be {\\tt 0}}\r\n\t\\PortBits{2}\r\n\t\t\\PortDesc{UART0 Tx empty interrupt}\r\n\t\\PortBits{1}\r\n\t\t\\PortDesc{UART0 Rx half full interrupt}\r\n\t\\PortBits{0}\r\n\t\t\\PortDesc{UART0 Rx available interrupt}\r\n\\end{NextPort}\r\n\r\n% note: we use comma for referencing port declaration page to avoid double closing parenthesis, more readable this way\r\nRead indicates whether the given interrupt was generated in the past. Write with {\\tt 1} clears given bit unless in IM2 mode (bit 0 set on \\PortTextXRef[,]{C0}) with interrupts enabled.\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{CC}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-2}\r\n\t\t\\PortDesc{Reserved, must be 0}\r\n\t\\PortBits{1}\r\n\t\t\\PortDesc{{\\tt 1} allows, {\\tt 0} prevents line interrupt from interrupting DMA}\r\n\t\\PortBits{0}\r\n\t\t\\PortDesc{{\\tt 1} allows, {\\tt 0} prevents ULA interrupt from interrupting DMA}\r\n\\end{NextPort}\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{CD}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7}\r\n\t\t\\PortDesc{{\\tt 1} allows, {\\tt 0} prevents CTC channel 7 interrupt from interrupting DMA}\r\n\t\\PortBits{6}\r\n\t\t\\PortDesc{{\\tt 1} allows, {\\tt 0} prevents CTC channel 6 interrupt from interrupting DMA}\r\n\t\\PortBits{5}\r\n\t\t\\PortDesc{{\\tt 1} allows, {\\tt 0} prevents CTC channel 5 interrupt from interrupting DMA}\r\n\t\\PortBits{4}\r\n\t\t\\PortDesc{{\\tt 1} allows, {\\tt 0} prevents CTC channel 4 interrupt from interrupting DMA}\r\n\t\\PortBits{3}\r\n\t\t\\PortDesc{{\\tt 1} allows, {\\tt 0} prevents CTC channel 3 interrupt from interrupting DMA}\r\n\t\\PortBits{2}\r\n\t\t\\PortDesc{{\\tt 1} allows, {\\tt 0} prevents CTC channel 2 interrupt from interrupting DMA}\r\n\t\\PortBits{1}\r\n\t\t\\PortDesc{{\\tt 1} allows, {\\tt 0} prevents CTC channel 1 interrupt from interrupting DMA}\r\n\t\\PortBits{0}\r\n\t\t\\PortDesc{{\\tt 1} allows, {\\tt 0} prevents CTC channel 0 interrupt from interrupting DMA}\r\n\\end{NextPort}\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{CE}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7}\r\n\t\t\\PortDesc{Reserved, must be {\\tt 0}}\r\n\t\\PortBits{6}\r\n\t\t\\PortDesc{{\\tt 1} allows, {\\tt 0} prevents UART1 Tx empty from interrupting DMA}\r\n\t\\PortBits{5}\r\n\t\t\\PortDesc{{\\tt 1} allows, {\\tt 0} prevents UART1 Rx half full from interrupting DMA}\r\n\t\\PortBits{4}\r\n\t\t\\PortDesc{{\\tt 1} allows, {\\tt 0} prevents UART1 Rx available from interrupting DMA}\r\n\t\\PortBits{3}\r\n\t\t\\PortDesc{Reserved, must be {\\tt 0}}\r\n\t\\PortBits{2}\r\n\t\t\\PortDesc{{\\tt 1} allows, {\\tt 0} prevents UART0 Tx empty from interrupting DMA}\r\n\t\\PortBits{1}\r\n\t\t\\PortDesc{{\\tt 1} allows, {\\tt 0} prevents UART0 Rx half full from interrupting DMA}\r\n\t\\PortBits{0}\r\n\t\t\\PortDesc{{\\tt 1} allows, {\\tt 0} prevents UART0 Rx available from interrupting DMA}\r\n\\end{NextPort}\r\n\r\n\r\n\\pagebreak\r\n\\IntentionallyEmpty\r\n\\pagebreak"
  },
  {
    "path": "chapter-next-keyboard.tex",
    "content": "\\section{Keyboard}\r\n\\label{zx_next_keyboard}\r\n\r\n% ───────────────────────────────────────────────────────────────────\r\n% ─██████──████████─██████████████─████████──████████─██████████████─\r\n% ─██░░██──██░░░░██─██░░░░░░░░░░██─██░░░░██──██░░░░██─██░░░░░░░░░░██─\r\n% ─██░░██──██░░████─██░░██████████─████░░██──██░░████─██░░██████████─\r\n% ─██░░██──██░░██───██░░██───────────██░░░░██░░░░██───██░░██─────────\r\n% ─██░░██████░░██───██░░██████████───████░░░░░░████───██░░██████████─\r\n% ─██░░░░░░░░░░██───██░░░░░░░░░░██─────████░░████─────██░░░░░░░░░░██─\r\n% ─██░░██████░░██───██░░██████████───────██░░██───────██████████░░██─\r\n% ─██░░██──██░░██───██░░██───────────────██░░██───────────────██░░██─\r\n% ─██░░██──██░░████─██░░██████████───────██░░██───────██████████░░██─\r\n% ─██░░██──██░░░░██─██░░░░░░░░░░██───────██░░██───────██░░░░░░░░░░██─\r\n% ─██████──████████─██████████████───────██████───────██████████████─\r\n% ───────────────────────────────────────────────────────────────────\r\n\r\nNext inherits ZX Spectrum keyboard handling, so all legacy programs will work out of the box. Additionally, it allows reading the status of extended keys.\r\n\r\n\r\n\\subsection{Legacy Keyboard Status}\r\n\r\nZX Spectrum uses 8$\\times$5 matrix for reading keyboard status. This means 40 distinct keys can be represented. The keyboard is read from \\PortTextXRef{xxFE} with particular high bytes. There are 8 possible bytes, each will return the status of 5 associated keys. If a key is pressed, the corresponding bit is set to {\\tt 0} and vice versa.\r\n\r\nExample for checking if {\\tt P} or {\\tt I} is pressed:\r\n\t\r\n\\begin{tcblisting}{}\r\n\tLD BC, &DFFE     ; We want to read keys..... YUIOP\r\n\tIN A, (C)        ; A holds values in bits... 43210\r\ncheckP:\r\n\tBIT 0, A         ; test bit 0 of A (P key)\r\n\tJR NZ checkI     ; if bit0=1, P not pressed\r\n\t...              ; P is pressed\r\ncheckI:\r\n\tBIT 2, A         ; test bit 2 of A (I key)\r\n\tJR NZ continue   ; if bit2=1, I not pressed\r\n\t...              ; I is pressed\r\ncontinue:\r\n\\end{tcblisting}\r\n\r\nAs mentioned in Ports chapter, section \\XRef{zx_next_ports_examples}, we can slightly improve performance if we replace first two lines with:\r\n\r\n\\begin{tcblisting}{}\r\n\tLD A, &DF\r\n\tIN (&FE)\r\n\\end{tcblisting}\r\n\r\nReading the port in first example requires 22 t-states (10+12) vs. 18 (7+11). The difference is small, but it can add up as typically keyboard is read multiple times per frame.\r\n\r\nThe first program is more understandable at a glance - the port address is given as a whole 16-bit value, as usually provided in the documentation. The second program splits it into 2 8-bit values, so intent may not be immediately apparent. Of course, one learns the patterns with experience, but it nonetheless demonstrates the compromise between readability and speed.\r\n\r\n\r\n\\subsection{Next Extended Keys}\r\n\r\n% note: we only show page number after last port xref since both are declared on the same page, but if this changes in the future, we should update this text accordingly\r\nNext uses larger 8$\\times$7 matrix for keyboard, with 10 additional keys. By default, hardware is translating keys from extra two columns into the existing 8$\\times$5 set. But you can turn this off with bit {\\tt 4} of \\PortTextXRef{68}. Extra keys can be read separately via \\PortTextXRef[]{B0} and \\PortTextXRef[]{B1}, details on page \\PortPage{B0}.\r\n\r\n\r\n\\subsection{Keyboard Ports and Registers}\r\n\\label{zx_next_keyboard_registers}\r\n\r\n\\subsubsection{\\PortDeclaration{xxFE}}\r\n\r\n\\vspace*{-1em} % for some reason LaTeX adds some unwanted vertical space between title and text!?\r\nReturns keyboard status when read with certain high byte values:\r\n\r\n{\r\n\t\\tt\r\n\t\\setlength{\\extrarowheight}{0pt}\r\n\t\\def\\arraystretch{0.1}\r\n\t\r\n\t\\begin{tabular}{p{0.7cm}|cp{1cm}p{1cm}p{1cm}p{1.3cm}p{1.5cm}}\r\n\r\n\t\t~xx & & 4 & 3 & 2 & 1 & 0 \\instrb \\\\\r\n\t\t\\hline\r\n\t\t\\MemAddr{7F}\\instrt & & B & N & M & Symb & Space \\\\\r\n\t\t\\MemAddr{BF}\\instrt & & H & J & K & L & Enter \\\\\r\n\t\t\\MemAddr{DF}\\instrt & & Y & U & I & O & P \\\\\r\n\t\t\\MemAddr{EF}\\instrt & & 6 & 7 & 8 & 9 & 0 \\\\\r\n\t\t\\MemAddr{F7}\\instrt & & 5 & 4 & 3 & 2 & 1 \\\\\r\n\t\t\\MemAddr{FB}\\instrt & & T & R & E & W & Q \\\\\r\n\t\t\\MemAddr{FD}\\instrt & & G & F & D & S & A \\\\\r\n\t\t\\MemAddr{FE}\\instrt\\instrb & & V & C & X & Z & Caps \\\\\r\n\r\n\t\\end{tabular}\r\n}\r\n\r\nBits are reversed: if a key is pressed, the corresponding bit is {\\tt 0}, if a key is not pressed, bit is {\\tt 1}.\r\n\r\n% note: we don't show page next to port since we use more verbose link to the section+page afterwards\r\nNote: when written to, \\PortTextXRef[]{xxFEWrite} is used to set border colour and audio devices. See ULA Layer, section \\PortXRef{xxFEWrite} for details.\r\n\r\n\r\n\\subsubsection{\\PortTextXRef[]{68}}\r\n\r\n\\PortDeclarationXRef{Tilemap}{68}\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{B0}}\r\n\\vspace*{-2ex}\r\n\\subsubsection{\\PortDeclaration{B1}}\r\n\r\n\\newcommand{\\PortNextExtKey}[2]{{\\tt 0} if key pressed, {\\tt 1} otherwise & {\\tt #1} & {\\tt #2} \\\\ }\r\n\\begin{NextPort}[cp{5.5cm}p{1.5cm}X][Bit & Effect & \\MemAddr{B0} & \\MemAddr{B1}]\r\n\t\\PortBits{7}\r\n\t\t\\PortNextExtKey{;}{Delete}\r\n\t\\PortBits{6}\r\n\t\t\\PortNextExtKey{\"}{Edit}\r\n\t\\PortBits{5}\r\n\t\t\\PortNextExtKey{,}{Break}\r\n\t\\PortBits{4}\r\n\t\t\\PortNextExtKey{.}{Inv Video}\r\n\t\\PortBits{3}\r\n\t\t\\PortNextExtKey{Up}{True Video}\r\n\t\\PortBits{2}\r\n\t\t\\PortNextExtKey{Down}{Graph}\r\n\t\\PortBits{1}\r\n\t\t\\PortNextExtKey{Left}{Caps Lock}\r\n\t\\PortBits{0}\r\n\t\t\\PortNextExtKey{Right}{Extend}\r\n\\end{NextPort}\r\n\r\nAvailable since core 3.1.5\r\n\r\n\\pagebreak"
  },
  {
    "path": "chapter-next-layer2.tex",
    "content": "\\section{Layer 2}\r\n\\label{zx_next_layer2}\r\n\r\n% ───────────────────────────────\r\n% ─██████─────────██████████████─\r\n% ─██░░██─────────██░░░░░░░░░░██─\r\n% ─██░░██─────────██████████░░██─\r\n% ─██░░██─────────────────██░░██─\r\n% ─██░░██─────────██████████░░██─\r\n% ─██░░██─────────██░░░░░░░░░░██─\r\n% ─██░░██─────────██░░██████████─\r\n% ─██░░██─────────██░░██─────────\r\n% ─██░░██████████─██░░██████████─\r\n% ─██░░░░░░░░░░██─██░░░░░░░░░░██─\r\n% ─██████████████─██████████████─\r\n% ───────────────────────────────\r\n\r\nAs we saw in the previous section, drawing with ULA graphics is much simplified on Next. But it can't eliminate the colour clash. Well, not with ULA mode at least. However, Next brings a couple of brand new graphic modes to the table, hidden behind a somewhat casual name ``Layer 2''. But don't let its name deceive you; Layer 2 raises Next graphics capabilities to a whole new level!\r\n\r\nLayer 2 may appear behind or above the ULA layer. It supports different resolutions with every pixel coloured independently and memory organized sequentially, line by line, pixel by pixel. Consequently, Layer 2 requires more memory compared to ULA; each mode needs multiple 16K banks. But of course, Next has far more memory than the original Speccy ever did!\r\n\r\n\\begin{tabularx}{\\textwidth}{cccX}\r\n\t\\BitHead{Resolution} & \\BitHead{Colours} & \\BitHead{BPP} & \\BitHead{Memory Organization} \\\\\r\n\t256$\\times$192 & 256 & 8 & 48K, 3 horizontal banks of 64 lines \\\\\r\n\t320$\\times$256 & 256 & 8 & 80K, 5 vertical banks of 64 columns\\footnote{Core 3.0.6+ only} \\\\\r\n\t640$\\times$256 & 16 & 4 & 80K, 5 vertical banks of 128 columns\\footnotemark[\\value{footnote}] \\\\\r\n\\end{tabularx}\r\n\r\n\r\n\\subsection{Initialization}\r\n\r\nDrawing on Layer 2 is much simpler than ULA. But in contrast with ULA, which is always ``on'', Layer 2 needs to be explicitly enabled. This is done by setting bit {\\tt 1} of \\PortTextXRef{123B}.\r\n\r\nBy default, Layer 2 will use 256$\\times$192 with 256 colours, supported across all Next core versions. You can select another resolution with \\PortTextXRef{70}. In this case you will also have to set up clip window correctly with \\PortTextXRef{18}.\r\n\r\n\r\n\\subsection{Paging}\r\n\r\nAfter Layer 2 is enabled, we can start writing into memory banks. As mentioned, Layer 2 requires 3-5 contiguous 16K banks. Upon boot, Next assigns it 16K banks 8-10. However, that gets modified by NextZXOS to 9-11 soon afterwards. You can use this configuration, but it's a good idea to set it up manually to future proof our programs.\r\n\r\nThere are two pieces to the ``puzzle'' of Layer 2 paging: first, we need to tell the hardware which banks are used. Since banks are always contiguous we only need to write the starting 16K bank number into \\PortTextXRef{12}. Then we need to swap the banks into one or more slots to write or read the data. Any supported mode can be used for paging, as described in section \\XRef{zx_next_memorypaging}. But the recommended and simplest is MMU mode. It's recommended to only use 16K banks 9 or greater for Layer 2.\r\n\r\n16K slot 3 (\\MemAddr{C000}-\\MemAddr{FFFF}, MMU7 and 8) is typically used for Layer 2 banks. But any other slot will work. You can use MMU registers to swap banks. Alternatively \\PortTextXRef{123B} also allows setting up paging for Layer 2. Either way, make sure paging is reset before passing control back from Layer 2 handling code.\r\n\r\nSimilar to ULA, Layer 2 can also be set up to use a double-buffering scheme. \\PortTextXRef{13} defines starting 16K bank number for ``shadow screen'' (back buffer) in this case. This is mainly used when paging is set up through \\PortTextXRef{123B}; bit 3 is used to switch configuration between normal and shadow banks. Or we can use MMU registers instead. If we track shadow banks manually, we don't have to use register \\MemAddr{13} at all. We still need to assign starting shadow screen bank to register \\PortTextXRef{12} in order to make it visible on screen.\r\n\r\n\r\n\\subsection{Drawing}\r\n\r\nIn general, drawing pixels requires the programmer to:\r\n\r\n\\begin{itemize}[topsep=1pt,itemsep=1pt]\r\n\t\\item Determine and select bank to write to\r\n\t\\item Calculate address of the pixel within the bank\r\n\t\\item Write byte with colour data\r\n\\end{itemize}\r\n\r\nAll Layer 2 modes use the same approach when drawing pixels. Each pixel uses one byte (except 640$\\times$320 where each byte contains data for 2 pixels). The value is simply an index into the palette entries list. Similar to other layers, Layer 2 also has two palettes, of which only one can be active at any given time. \\PortTextXRef{43} is used to select active palette. See Palette chapter \\XRef{zx_next_palette} for details on how to program palettes.\r\n\r\nSee specific modes in the following pages for examples of writing pixel data.\r\n\r\n\r\n\\subsection{Effects}\r\n\r\n\\PortTextXRef{15} can be used to change Layer 2 priority, effectively moving Layer 2 above or below other layers - see Tilemap chapter, section \\XRef{zx_next_tilemap_registers} for details.\r\n\r\nWe can even be more specific and only prioritize specific colours, so only pixels using those colours will appear on top while other pixels below other layers. This way we can achieve a simple depth effect. Per-pixel priority is available when writing a custom palette with \\PortTextXRef{44} (9-bit colours). See description under Palette chapter, section \\XRef{zx_next_palette} for details on how to program palette.\r\n\r\nWe can also use both Layer 2 palettes to achieve simple effects. For example, certain colours can be marked with the priority flag on one palette but not on the other. When swapping palettes, pixels drawn with these colours would appear on top or below other layers. Another simple effect using both palettes could be colour animation, though it can't be very smooth with only two states.\r\n\r\n\\PortTextXRef{14} register can be used to alter the transparent colour of Layer 2. This same register also affects ULA, LoRes and 1-bit (``text mode'') tilemap. \r\n\r\nScrolling effects can be achieved by writing pixel offsets to registers \\PortTextXRef{71}, \\PortTextXRef{16} and \\PortTextXRef{17}.\r\n\r\n\r\n\r\n\r\n\r\n\\pagebreak\r\n\\subsection{256$\\times$192 256 Colour Mode}\r\n\r\n\\begin{multicols}{2}\r\n\t3 horizontal banks:\r\n\r\n\t\\begin{tabularx}{0.95\\linewidth}{c|YY|YY|}\r\n\t\t\\multicolumn{1}{l}{} & \r\n\t\t\t\\multicolumn{1}{l}{0} &\r\n\t\t\t\\multicolumn{2}{c}{\\dots} &\r\n\t\t\t\\multicolumn{1}{r}{255} \\\\\r\n\t\t\\cline{2-5}\r\n\t\t\t0 & \r\n\t\t\t\\multicolumn{2}{l|}{16K BANK 0} & \r\n\t\t\t\\multicolumn{2}{l|}{8K BANK 0} \\\\\r\n\t\t\\multirow{2}{*}{\\vdots} & & & \r\n\t\t\t\\multicolumn{2}{l|}{0\\dots 31} \\\\\r\n\t\t\\cline{4-5}\r\n\t\t\t& & & \\multicolumn{2}{l|}{8K BANK 1} \\\\\r\n\t\t\t63 & & & \\multicolumn{2}{l|}{32 \\dots 63} \\\\\r\n\t\t\\cline{2-5}\r\n\t\t\t64 & \r\n\t\t\t\\multicolumn{2}{l|}{16K BANK 1} & \r\n\t\t\t\\multicolumn{2}{l|}{8K BANK 2} \\\\\r\n\t\t\\multirow{2}{*}{\\vdots} & & & \r\n\t\t\t\\multicolumn{2}{l|}{64 \\dots 95} \\\\\r\n\t\t\\cline{4-5}\r\n\t\t\t& & & \\multicolumn{2}{l|}{8K BANK 3} \\\\\r\n\t\t\t127 & & & \\multicolumn{2}{l|}{96 \\dots 127} \\\\\r\n\t\t\\cline{2-5}\r\n\t\t\t128 & \r\n\t\t\t\\multicolumn{2}{l|}{16K BANK 2} & \r\n\t\t\t\\multicolumn{2}{l|}{8K BANK 4} \\\\\r\n\t\t\\multirow{2}{*}{\\vdots} & & & \r\n\t\t\t\\multicolumn{2}{l|}{128 \\dots 159} \\\\\r\n\t\t\\cline{4-5}\r\n\t\t\t& & & \\multicolumn{2}{l|}{8K BANK 5} \\\\\r\n\t\t\t191 & & & \\multicolumn{2}{l|}{160 \\dots 191} \\\\\r\n\t\t\\cline{2-5}\r\n\t\\end{tabularx}\r\n\r\n\t\\columnbreak\r\n\t8BPP:\\\\\r\n\r\n\t\\begin{BitTableByte}\r\n\t\t\\BitSmall{$I_7$} & \r\n\t\t\t\\BitSmall{$I_6$} & \r\n\t\t\t\\BitSmall{$I_5$} &\r\n\t\t\t\\BitSmall{$I_4$} &\r\n\t\t\t\\BitSmall{$I_3$} & \r\n\t\t\t\\BitSmall{$I_2$} &\r\n\t\t\t\\BitSmall{$I_1$} &\r\n\t\t\t\\BitSmall{$I_0$} \\\\\r\n\t\t\\hline\r\n\t\t\\BitStartMulti{8}{Colour index} \\\\\r\n\t\\end{BitTableByte}\r\n\r\n\tBanking Setup:\r\n\r\n\t\\begin{ElegantTableX}{|c|c|c|c|Y|}\r\n\t\t\\ElegantHeader{\r\n\t\t\t\\BitHead{15} & \r\n\t\t\t\\BitHead{14} & \r\n\t\t\t\\BitHead{13} &\r\n\t\t\t\\BitHead{12-8} &\r\n\t\t\t\\BitHead{7-0}\r\n\t\t}\r\n\t\t\\BitStartMulti{4}{$Y$} & \r\n\t\t\t\\BitMulti{1}{$X$} \\\\\r\n\t\t\\hline\r\n\t\t\\BitStartMulti{2}{16K} &\r\n\t\t\t\\BitMulti{2}{$Y_{5-0}$} &\r\n\t\t\t\\BitMulti{1}{$X$} \\\\\r\n\t\t\\hline\r\n\t\t\\BitStartMulti{3}{8K} &\r\n\t\t\t\\BitMulti{1}{$Y_{4-0}$} &\r\n\t\t\t\\BitMulti{1}{$X$} \\\\\r\n\t\\end{ElegantTableX}\r\n\r\n\\end{multicols}\r\n\r\nThis mode is the closest to ULA, resolution wise, so is perhaps the simplest to grasp. It's also supported across all Next core versions. Pixels are laid out from left to right and top to bottom. Each pixel uses one byte that represents an 8-bit index into the palette. 3 16K banks are needed to cover the whole screen, each holding data for 64 lines. Or, if using 8K, 6 banks, 32 lines each. Combined, colour data requires 48K of memory.\r\n\r\nEach (x,y) coordinate pair requires 16-bits. If the upper byte is used for Y and lower for the X coordinate, together they will form exact memory location offset from the top of the first bank. But to account for bank swapping; for 16K banks, the most significant 2 bits of Y correspond to bank number and for 8K banks, top 3 bits. The rest of Y + X is memory location within the bank.\r\n\r\nExample of filling the screen with a vertical rainbow:\r\n\r\n\\begin{tcblisting}{}\r\nSTART_16K_BANK  = 9\r\nSTART_8K_BANK   = START_16K_BANK*2\r\n\r\n\t; Enable Layer 2\r\n\tLD BC, &123B\r\n\tLD A, 2\r\n\tOUT (C), A\r\n\t\r\n\t; Setup starting Layer2 16K bank\r\n\tNEXTREG &12, START_16K_BANK\r\n\t\r\n\tLD D, 0                   ; D=Y, start at top of the screen\r\n\t\r\nnextY:\r\n\t; Calculate bank number and swap it in\r\n\tLD A, D                   ; Copy current Y to A\r\n\tAND %11100000             ; 32100000 (3 MSBs = bank number)\r\n\tRLCA                      ; 21000003\r\n\tRLCA                      ; 10000032\r\n\tRLCA                      ; 00000321\r\n\tADD A, START_8K_BANK      ; A=bank number to swap in\r\n\tNEXTREG &56, A            ; Swap bank to slot 6 (&C000-&DFFF)\r\n\t\r\n\t; Convert DE (yx) to screen memory location starting at &C000\r\n\tPUSH DE                   ; (DE) will be changed to bank offset\r\n\tLD A, D                   ; Copy current Y to A\r\n\tAND %00011111             ; Discard bank number\r\n\tOR &C0                    ; Screen starts at &C000\r\n\tLD D, A                   ; D=high byte for &C000 screen memory\r\n\r\n\t; Loop X through 0..255; we don't have to deal with bank swapping\r\n\t; here because it only occurs when changing Y\r\n\tLD E, 0\r\nnextX:\r\n\tLD A, E                   ; A=current X\r\n\tLD (DE), A                ; Use X as colour index\r\n\tINC E                     ; Increment to next X\r\n\tJR NZ, nextX              ; Repeat until E rolls over\r\n\t\r\n\t; Continue with next line or exit\r\n\tPOP DE                    ; Restore DE to coordinates\r\n\tINC D                     ; Increment to next Y\r\n\tLD A, D                   ; A=current Y\r\n\tCP 192                    ; Did we just complete last line?\r\n\tJP C, nextY               ; No, continue with next linee\r\n\\end{tcblisting}\r\n\r\nWorth noting: MMU page 6 (next register \\MemAddr{56}) covers memory \\MemAddr{C000} - \\MemAddr{DFFF}. As we swap different 8K banks there, we're effectively changing 8K banks that are readable and writable at those memory addresses. That's why we {\\tt OR \\$C0} in line 24; we need to convert zero based address to \\MemAddr{C000} based.\r\n\r\nWe don't have to handle bank swapping on every iteration; once per 32 rows would do for this example. But the code is more versatile this way and could be easily converted into a reusable pixel setting routine.\r\n\r\nYou can find fully working example in companion code on GitHub in folder {\\tt layer2-256x192}.\r\n\r\n\r\n\\pagebreak\r\n\\subsection{320$\\times$256 256 Colour Mode}\r\n\r\n\\begin{multicols}{2}\r\n\t5 vertical banks:\r\n\r\n\t\\begin{tabularx}{0.95\\linewidth}{l|X|X|X|X|X|X|X|X|X|X|}\r\n\t\t\\multicolumn{1}{l}{} &\r\n\t\t\t\\multicolumn{1}{l}{0} &\r\n\t\t\t\\multicolumn{7}{X}{} &\r\n\t\t\t\\multicolumn{2}{r}{319} \\\\\r\n\t\t\\cline{2-11}\r\n\t\t\\rotatebox[origin=c]{90}{~~~~~~~~~~~~~~0} &\r\n\t\t\t\\multicolumn{2}{X|}{\\rotatebox[origin=c]{90}{~16K BANK 0~}} &\r\n\t\t\t\\multicolumn{2}{X|}{\\rotatebox[origin=c]{90}{16K BANK 1}} &\r\n\t\t\t\\multicolumn{2}{X|}{\\rotatebox[origin=c]{90}{16K BANK 2}} &\r\n\t\t\t\\multicolumn{2}{X|}{\\rotatebox[origin=c]{90}{16K BANK 3}} &\r\n\t\t\t\\multicolumn{2}{X|}{\\rotatebox[origin=c]{90}{16K BANK 4}} \\\\\r\n\t\t\\cline{2-11}\r\n\t\t\\rotatebox[origin=c]{90}{255~~~~~~~~~~~} &\r\n\t\t\t\\rotatebox[origin=c]{90}{~8K BANK 0~} &\r\n\t\t\t\\rotatebox[origin=c]{90}{8K BANK 1} &\r\n\t\t\t\\rotatebox[origin=c]{90}{8K BANK 2} &\r\n\t\t\t\\rotatebox[origin=c]{90}{8K BANK 3} &\r\n\t\t\t\\rotatebox[origin=c]{90}{8K BANK 4} &\r\n\t\t\t\\rotatebox[origin=c]{90}{8K BANK 5} &\r\n\t\t\t\\rotatebox[origin=c]{90}{8K BANK 6} &\r\n\t\t\t\\rotatebox[origin=c]{90}{8K BANK 7} &\r\n\t\t\t\\rotatebox[origin=c]{90}{8K BANK 8} &\r\n\t\t\t\\rotatebox[origin=c]{90}{8K BANK 9} \\\\\r\n\t\t\\cline{2-11}\r\n\t\t\\multicolumn{1}{c}{} & \\multicolumn{10}{c}{} \\\\[-5pt]\r\n\t\t\\multicolumn{1}{c}{} & \r\n\t\t\t\\multicolumn{10}{l}{16K bank contains 64 columns} \\\\\r\n\t\t\\multicolumn{1}{c}{} & \r\n\t\t\t\\multicolumn{10}{l}{8K bank contains 32 columns} \\\\\r\n\t\\end{tabularx}\r\n\r\n\t\\columnbreak\r\n\t8BPP:\\\\\r\n\r\n\t\\begin{BitTableByte}\r\n\t\t\\BitSmall{$I_7$} & \r\n\t\t\t\\BitSmall{$I_6$} & \r\n\t\t\t\\BitSmall{$I_5$} &\r\n\t\t\t\\BitSmall{$I_4$} &\r\n\t\t\t\\BitSmall{$I_3$} & \r\n\t\t\t\\BitSmall{$I_2$} &\r\n\t\t\t\\BitSmall{$I_1$} &\r\n\t\t\t\\BitSmall{$I_0$} \\\\\r\n\t\t\\hline\r\n\t\t\\BitStartMulti{8}{Colour index} \\\\\r\n\t\\end{BitTableByte}\r\n\r\n\tBanking Setup:\r\n\r\n\t\\begin{ElegantTableX}{|c|C{1em}|C{1em}|C{1em}|C{2.5em}|Y|}\r\n\t\t\\ElegantHeader{\r\n\t\t\t\\BitHead{16} &\r\n\t\t\t\\BitMulti{4}{\\BitHead{15-8}} &\r\n\t\t\t\\BitHead{7-0}\r\n\t\t}\r\n\t\t\\ElegantHeader{\r\n\t\t\t\\BitHead{16} &\r\n\t\t\t\\BitHead{15} &\r\n\t\t\t\\BitHead{14} &\r\n\t\t\t\\BitHead{13} &\r\n\t\t\t\\BitHead{12-8} &\r\n\t\t\t\\BitHead{7-0}\r\n\t\t}\r\n\t\t\\BitStartMulti{1}{$X_{8}$} & \r\n\t\t\t\\BitMulti{4}{$X_{7-0}$} &\r\n\t\t\t\\BitMulti{1}{$Y$} \\\\\r\n\t\t\\hline\r\n\t\t\\BitStartMulti{3}{16K} &\r\n\t\t\t\\BitMulti{2}{$X_{5-0}$} &\r\n\t\t\t\\BitMulti{1}{$Y$} \\\\\r\n\t\t\\hline\r\n\t\t\\BitStartMulti{4}{8K} &\r\n\t\t\t\\BitMulti{1}{$X_{4-0}$} &\r\n\t\t\t\\BitMulti{1}{$Y$} \\\\\r\n\t\\end{ElegantTableX}\r\n\r\n\\end{multicols}\r\n\r\n320$\\times$256 mode is only available on Next core 3.0.6 or later. Pixels are laid out from top to bottom and left to right. Each pixel uses one byte that represents an 8-bit index into the palette. To cover the whole screen, 5 16K banks of 64 columns or 10 8K banks of 32 columns are needed. Together colour data requires 80K of memory.\r\n\r\nIn contrast with 256$\\times$192, this mode allows drawing to the whole screen, including border. In fact, you can think of it as the regular 256$\\times$192 mode with additional 32 pixel border around (32 + 256 + 32 = 320 and 32 + 192 + 32 = 256).\r\n\r\nAddressing is more complicated though. As we need 9 bits for X and 8 for Y, we can't address all screen pixels with single 16-bit register pair. But we can use 16-bit register pair to address all pixels within each bank. From this perspective, the setup is similar to 256$\\times$192 mode, except that X and Y are reversed: if the upper byte is used for X and lower for Y, then most significant 2 bits of 16-bit register pair represent lower 2 bits of 16K bank number. And for 8K banks, the most significant 3 bits correspond to the lower 3 bits of 8K bank number. In either case, the most significant bit of the bank number arrives from the 9th bit of the X coordinate ($X_8$ in the table above). The rest of the X + Y is memory location within the bank.\r\n\r\nTo use this mode, we must explicitly select it with \\PortTextXRef{70}. We must also not forget to set clip window correctly with \\PortTextXRef{18} and \\PortTextXRef{1C}, as demonstrated in example below:\r\n\r\n\\begin{tcblisting}{}\r\nSTART_16K_BANK  = 9\r\nSTART_8K_BANK   = START_16K_BANK*2\r\n\r\nRESOLUTION_X    = 320\r\nRESOLUTION_Y    = 256\r\n\r\nBANK_8K_SIZE    = 8192\r\nNUM_BANKS       = RESOLUTION_X * RESOLUTION_Y / BANK_8K_SIZE\r\nBANK_X          = BANK_8K_SIZE / RESOLUTION_Y\r\n\r\n\t; Enable Layer 2\r\n\tLD BC, &123B\r\n\tLD A, 2\r\n\tOUT (C), A\r\n\r\n\t; Setup starting Layer2 16K bank\r\n\tNEXTREG &12, START_16K_BANK\r\n\tNEXTREG &70, %00010000    ; 320x256 256 colour mode\r\n\r\n\t; Setup window clip for 320x256 resolution\r\n\tNEXTREG &1C, 1            ; Reset Layer 2 clip window reg index\r\n\tNEXTREG &18, 0            ; X1; X2 next line\r\n\tNEXTREG &18, RESOLUTION_X / 2 - 1\r\n\tNEXTREG &18, 0            ; Y1; Y2 next line\r\n\tNEXTREG &18, RESOLUTION_Y - 1\r\n\r\n\tLD B, START_8K_BANK       ; Bank number\r\n\tLD H, 0                   ; Colour index\r\nnextBank:\r\n\t; Swap to next bank, exit once all 5 are done\r\n\tLD A, B                   ; Copy current bank number to A\r\n\tNEXTREG &56, A            ; Swap bank to slot 6 (&C000-&DFFF)\r\n\r\n\t; Fill in current bank\r\n\tLD DE, &C000              ; Prepare starting address\r\nnextY:\r\n\t; Fill in 256 pixels of current line\r\n\tLD A, H                   ; Copy colour index to A\r\n\tLD (DE), A                ; Write colour index into memory\r\n\tINC E                     ; Increment Y\r\n\tJR NZ, nextY              ; Continue with next Y until we wrap to next X\r\n\r\n\t; Prepare for next line until bank is full\r\n\tINC H                     ; Increment colour\r\n\tINC D                     ; Increment X\r\n\tLD A, D                   ; Copy X to A\r\n\tAND %00111111             ; Clear &C0 to get pure X coordinate\r\n\tCP BANK_X                 ; Did we reach next bank?\r\n\tJP NZ, nextY              ; No, continue with next Y\r\n\r\n\t; Prepare for next bank\r\n\tINC B                     ; Increment to next bank\r\n\tLD A, B                   ; Copy bank to A\r\n\tCP START_8K_BANK+NUM_BANKS; Did we fill last bank?\r\n\tJP NZ, nextBank           ; No, proceed with next bank\r\n\\end{tcblisting}\r\n\r\nYou can find fully working example in companion code on GitHub in folder {\\tt layer2-320x256}.\r\n\r\n\r\n\\pagebreak\r\n\\subsection{640$\\times$256 16 Colour Mode}\r\n\r\n\\begin{multicols}{2}\r\n\t5 vertical banks:\r\n\r\n\t\\begin{tabularx}{0.95\\linewidth}{l|X|X|X|X|X|X|X|X|X|X|}\r\n\t\t\\multicolumn{1}{l}{} &\r\n\t\t\t\\multicolumn{1}{l}{0} &\r\n\t\t\t\\multicolumn{7}{X}{} &\r\n\t\t\t\\multicolumn{2}{r}{639} \\\\\r\n\t\t\\cline{2-11}\r\n\t\t\\rotatebox[origin=c]{90}{~~~~~~~~~~~~~~0} &\r\n\t\t\t\\multicolumn{2}{X|}{\\rotatebox[origin=c]{90}{~16K BANK 0~}} &\r\n\t\t\t\\multicolumn{2}{X|}{\\rotatebox[origin=c]{90}{16K BANK 1}} &\r\n\t\t\t\\multicolumn{2}{X|}{\\rotatebox[origin=c]{90}{16K BANK 2}} &\r\n\t\t\t\\multicolumn{2}{X|}{\\rotatebox[origin=c]{90}{16K BANK 3}} &\r\n\t\t\t\\multicolumn{2}{X|}{\\rotatebox[origin=c]{90}{16K BANK 4}} \\\\\r\n\t\t\\cline{2-11}\r\n\t\t\\rotatebox[origin=c]{90}{255~~~~~~~~~~~} &\r\n\t\t\t\\rotatebox[origin=c]{90}{~8K BANK 0~} &\r\n\t\t\t\\rotatebox[origin=c]{90}{8K BANK 1} &\r\n\t\t\t\\rotatebox[origin=c]{90}{8K BANK 2} &\r\n\t\t\t\\rotatebox[origin=c]{90}{8K BANK 3} &\r\n\t\t\t\\rotatebox[origin=c]{90}{8K BANK 4} &\r\n\t\t\t\\rotatebox[origin=c]{90}{8K BANK 5} &\r\n\t\t\t\\rotatebox[origin=c]{90}{8K BANK 6} &\r\n\t\t\t\\rotatebox[origin=c]{90}{8K BANK 7} &\r\n\t\t\t\\rotatebox[origin=c]{90}{8K BANK 8} &\r\n\t\t\t\\rotatebox[origin=c]{90}{8K BANK 9} \\\\\r\n\t\t\\cline{2-11}\r\n\t\t\\multicolumn{1}{c}{} & \\multicolumn{10}{c}{} \\\\[-5pt]\r\n\t\t\\multicolumn{1}{c}{} & \r\n\t\t\t\\multicolumn{10}{l}{16K bank contains 128 columns} \\\\\r\n\t\t\\multicolumn{1}{c}{} & \r\n\t\t\t\\multicolumn{10}{l}{8K bank contains 64 columns} \\\\\r\n\t\\end{tabularx}\r\n\r\n\t\\columnbreak\r\n\t4BPP:\\\\\r\n\r\n\t\\begin{BitTableByte}\r\n\t\t\\BitSmall{$I_3$} & \r\n\t\t\t\\BitSmall{$I_2$} & \r\n\t\t\t\\BitSmall{$I_1$} &\r\n\t\t\t\\BitSmall{$I_0$} &\r\n\t\t\t\\BitSmall{$I_3$} & \r\n\t\t\t\\BitSmall{$I_2$} &\r\n\t\t\t\\BitSmall{$I_1$} &\r\n\t\t\t\\BitSmall{$I_0$} \\\\\r\n\t\t\\hline\r\n\t\t\\BitStartMulti{4}{Colour 1} &\r\n\t\t\t\\BitMulti{4}{Colour 2} \\\\\r\n\t\\end{BitTableByte}\r\n\r\n\tBanking Setup:\r\n\r\n\t\\begin{ElegantTableX}{|c|C{1em}|C{1em}|C{1em}|c|Y|}\r\n\t\t\\ElegantHeader{\r\n\t\t\t\\BitHead{16} &\r\n\t\t\t\\BitMulti{4}{\\BitHead{15-8}} &\r\n\t\t\t\\BitHead{7-0}\r\n\t\t}\r\n\t\t\\ElegantHeader{\r\n\t\t\t\\BitHead{16} &\r\n\t\t\t\\BitHead{15} &\r\n\t\t\t\\BitHead{14} &\r\n\t\t\t\\BitHead{13} &\r\n\t\t\t\\BitHead{12-8} &\r\n\t\t\t\\BitHead{7-0}\r\n\t\t}\r\n\t\t\\BitStartMulti{1}{$X_{8}$} & \r\n\t\t\t\\BitMulti{4}{$X_{7-0}$} &\r\n\t\t\t\\BitMulti{1}{$Y$} \\\\\r\n\t\t\\hline\r\n\t\t\\BitStartMulti{3}{16K} &\r\n\t\t\t\\BitMulti{2}{$X_{5-0}$} &\r\n\t\t\t\\BitMulti{1}{$Y$} \\\\\r\n\t\t\\hline\r\n\t\t\\BitStartMulti{4}{8K} &\r\n\t\t\t\\BitMulti{1}{$X_{4-0}$} &\r\n\t\t\t\\BitMulti{1}{$Y$} \\\\\r\n\t\\end{ElegantTableX}\r\n\r\n\\end{multicols}\r\n\r\n640$\\times$256 mode is very similar to 320$\\times$256, except that each byte represents 2 colours instead of 1. It's also available on Next core 3.0.6 or later only. Pixels are laid out from top to bottom and left to right. Each pixel takes 4 bits, so each byte contains data for 2 pixels. Therefore division by 2 should be used to convert screen coordinate to $X$ for address, multiplication by 2 for the other way around.\r\n\r\nTo cover the whole screen, 5 16K banks of 128 columns or 10 8K banks of 64 columns are needed. Together colour data requires 80K of memory. Similar to 320$\\times$256, this mode also covers the whole screen, including the border.\r\n\r\nAddressing wise, this mode is the same as 320$\\times$256. Using 16-bit register pair we can't address all pixels on the screen, but we can address all pixels within each bank. Again, assuming upper byte of 16-bit register pair is used for X and lower for Y and using 9th bit of X coordinate (bit $X_8$ in the table above) as the most significant bit of bank number, then most significant 2 bits of 16-bit register pair represent lower 2 bits of 16K bank number. And for 8K banks, the most significant 3 bits correspond to the lower 3 bits of 8K bank number. The rest of the X + Y is memory location within the bank. Don't forget: each colour byte represents 2 screen pixels, so the memory X coordinate (as described above) needs to be multiplied by 2 to convert to screen X coordinate.\r\n\r\nTo use this mode, we must explicitly select it with \\PortTextXRef{70}. We must also not forget to set clip window correctly with \\PortTextXRef{18} and \\PortTextXRef{1C}, as demonstrated in example below:\r\n\r\n\\begin{tcblisting}{}\r\nSTART_16K_BANK  = 9\r\nSTART_8K_BANK   = START_16K_BANK*2\r\n\r\nRESOLUTION_X    = 640\r\nRESOLUTION_Y    = 256\r\n\r\nBANK_8K_SIZE    = 8192\r\nNUM_BANKS       = RESOLUTION_X * RESOLUTION_Y / BANK_8K_SIZE / 2\r\nBANK_X          = BANK_8K_SIZE / RESOLUTION_Y\r\n\r\n\t; Enable Layer 2\r\n\tLD BC, &123B\r\n\tLD A, 2\r\n\tOUT (C), A\r\n\r\n\t; Setup starting Layer2 16K bank\r\n\tNEXTREG &12, START_16K_BANK\r\n\tNEXTREG &70, %00100000    ; 640x256 16 colour mode\r\n\r\n\tNEXTREG &1C, 1            ; Reset Layer 2 clip window reg index\r\n\tNEXTREG &18, 0\r\n\tNEXTREG &18, RESOLUTION_X / 4 - 1\r\n\tNEXTREG &18, 0\r\n\tNEXTREG &18, RESOLUTION_Y - 1\r\n\r\n\tLD B, START_8K_BANK       ; Bank number\r\n\tLD H, 0                   ; Colour index for 2 pixels\r\nnextBank:\r\n\t; Swap to next bank, exit once all 5 are done\r\n\tLD A, B                   ; Copy current bank number to A\r\n\tNEXTREG &56, A            ; Swap bank to slot 6 (&C000-&DFFF)\r\n\r\n\t; Fill in current bank\r\n\tLD DE, &C000              ; Prepare starting address\r\nnextY:\r\n\t; Fill in 256 pixels of current line\r\n\tLD A, H                   ; Copy colour indexes for 2 pixels to A\r\n\tLD (DE), A                ; Write colour indexes into memory\r\n\tINC E                     ; Increment Y\r\n\tJR NZ, nextY              ; Continue with next Y until we wrap to next X\r\n\r\n\t; Prepare for next line until bank is full\r\n\tINC H                     ; Increment colour index for both colours\r\n\tINC D                     ; Increment X\r\n\tLD A, D                   ; Copy X to A\r\n\tAND %00111111             ; Clear &C0 to get pure X coordinate\r\n\tCP BANK_X                 ; Did we reach next bank?\r\n\tJP NZ, nextY              ; No, continue with next Y\r\n\r\n\t; Prepare for next bank\r\n\tINC B                     ; Increment to next bank\r\n\tLD A, B                   ; Copy bank to A\r\n\tCP START_8K_BANK+NUM_BANKS; Did we fill last bank?\r\n\tJP NZ, nextBank           ; No, proceed with next bank\r\n\\end{tcblisting}\r\n\r\nYou can find fully working example in companion code on GitHub in folder {\\tt layer2-640x256}.\r\n\r\n\\subsection{Layer 2 Registers}\r\n\\label{zx_next_layer2_registers}\r\n\r\n\\subsubsection{\\PortDeclaration{123B}}\r\n\r\n% note: most port xrefs exclude page numbers since those ports/registers are declared on the same page spread\r\n\\begin{NextPort}\r\n\t\\PortBits{7-6}\r\n\t\t\\PortDesc{Video RAM bank select}\r\n\t\t\\PortDescOnly{\r\n\t\t\t\\begin{PortBitConfig}\r\n\t\t\t\t\\PortBitLine{00}{First 16K of layer 2 in the bottom 16K slot}\r\n\t\t\t\t\\PortBitLine{01}{Second 16K of layer 2 in the bottom 16K slot}\r\n\t\t\t\t\\PortBitLine{10}{Third 16K of layer 2 in the bottom 16K slot}\r\n\t\t\t\t\\PortBitLine{11}{First 48K of layer 2 in the bottom 48K - 16K slots 0-2 (core 3.0+)}\r\n\t\t\t\\end{PortBitConfig}\r\n\t\t}\r\n\t\\PortBits{5}\r\n\t\t\\PortDesc{Reserved, use {\\tt 0}}\r\n\t\\PortBits{4}\r\n\t\t\\PortDesc{{\\tt 0} (see below)}\r\n\t\\PortBits{3}\r\n\t\t\\PortDesc{Use Shadow Layer 2 for paging}\r\n\t\t\\PortDescOnly{\r\n\t\t\t\\begin{PortBitConfig}\r\n\t\t\t\t\\PortBitLine{0}{Map \\PortTextXRef[]{12}}\r\n\t\t\t\t\\PortBitLine{1}{Map \\PortTextXRef[]{13}}\r\n\t\t\t\\end{PortBitConfig}\r\n\t\t}\r\n\t\\PortBits{2}\r\n\t\t\\PortDesc{Enable Layer 2 read-only paging on 16K slot 0 (core 3.0+)}\r\n\t\\PortBits{1}\r\n\t\t\\PortDesc{Layer 2 visible, see \\PortTextXRef[]{12}}\r\n\t\t\\PortDescOnly{Since core 3.0 this bit has mirror in \\PortTextXRef{69}}\r\n\t\\PortBits{0}\r\n\t\t\\PortDesc{Enable Layer 2 write-only paging on 16K slot 0}\r\n\\end{NextPort}\r\n\r\nNote: bits 0 and 2 can be combined to get both read and write access to selected bank(s). If bit 3 is set, then paging uses shadow screen banks instead.\r\n\r\nSince core 3.0.7, write with bit {\\tt 4} set was also added:\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-5}\r\n\t\t\\PortDesc{Reserved, use {\\tt 0}}\r\n\t\\PortBits{4}\r\n\t\t\\PortDesc{{\\tt 1}}\r\n\t\\PortBits{3}\r\n\t\t\\PortDesc{Reserved, use {\\tt 0}}\r\n\t\\PortBits{2-0}\r\n\t\t\\PortDesc{16K bank relative offset (+0..+7) applied to Layer 2 memory mapping}\r\n\\end{NextPort}\r\n\r\nWith this, all 5 banks needed for 320$\\times$256 and 640$\\times$256 modes can be selected for reading or writing to 16K slot 0 (or first three slots). To use this mode, port \\MemAddr{123B} is typically written to twice, first without bit 4 to switch on read/write access, then with bit 4 set to select bank offset.\r\n\r\nNote: read and write access to Layer 2 banks (or any other bank for that matter) can also be achieved using Next MMU registers which is arguably simpler to use. Regardless, don't forget to reset banks back to the original after you're done handling Layer 2!\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{12}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7}\r\n\t\t\\PortDesc{Reserved, must be {\\tt 0}}\r\n\t\\PortBits{6-0}\r\n\t\t\\PortDesc{Starting 16K bank of Layer 2}\r\n\\end{NextPort}\r\n\r\nDefault 256$\\times$192 mode requires 3 16K banks while new, 320$\\times$256 and 640$\\times$256 modes require 5 16K banks. Banks need to be contiguous in memory, so here we only specify the first one. Valid bank numbers are therefore {\\tt 0} - {\\tt 45} ({\\tt 109} for 2MB RAM models) for standard mode and {\\tt 0} - {\\tt 43} ({\\tt 107} for 2MB RAM models) for new modes.\r\n\r\nChanges to this registers are immediately visible on screen.\r\n\r\nNote: this register uses 16K bank numbers. If you're using 8K banks, you have to multiply this value by 2. For example, 16K bank 9 corresponds to 8K banks 18 and 19.\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{13}}\r\n\r\n% note: most port xrefs exclude page numbers since those ports/registers are declared on the same page spread\r\n\\begin{NextPort}\r\n\t\\PortBits{7}\r\n\t\t\\PortDesc{Reserved, must be {\\tt 0}}\r\n\t\\PortBits{6-0}\r\n\t\t\\PortDesc{Starting 16K bank of Layer 2 shadow screen}\r\n\\end{NextPort}\r\n\r\nSimilar to \\PortTextXRef[]{12} except this register sets up starting 16K bank for Layer 2 shadow screen. The other difference is that changes to this registers are not immediately visible on screen.\r\n\r\nNote: this register doesn't affect the shadow screen in any way besides when bit 3 is set in \\PortTextXRef[]{123B}. We can circumvent it completely if a manual paging scheme is used to swap banks for reading and writing.\r\n\r\n\\subsubsection{\\PortDeclaration{14}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-0}\\PortDesc{Sets index of transparent colour for Layer 2, ULA and LoRes pixel data (\\MemAddr{E3} after reset).}\r\n\\end{NextPort}\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{16}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-0}\r\n\t\t\\PortDesc{Writes or reads X pixel offset used for drawing Layer 2 graphics on the screen.}\r\n\\end{NextPort}\r\n\r\nThis can be used for creating scrolling effects. For 320$\\times$256 and 640$\\times$256 modes, 9 bits are required; use \\PortTextXRef{71} to set it up.\r\n\r\n\r\n\\pagebreak\r\n\\subsubsection{\\PortDeclaration{17}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-0}\r\n\t\t\\PortDesc{Writes or reads Y pixel offset used for drawing Layer 2 graphics on the screen.}\r\n\\end{NextPort}\r\n\r\nValid range is:\r\n\r\n\\begin{itemize}[topsep=1pt,itemsep=1pt]\r\n\t\\item 256$\\times$192: {\\tt 191}\r\n\t\\item 320$\\times$256: {\\tt 255}\r\n\t\\item 640$\\times$256: {\\tt 255}\r\n\\end{itemize}\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{18}}\r\n\r\n% note: most port xrefs exclude page numbers since those ports/registers are declared on the same page spread\r\n\\begin{NextPort}\r\n\t\\PortBits{7-0}\r\n\t\t\\PortDesc{Reads and writes clip-window coordinates for Layer 2}\r\n\\end{NextPort}\r\n\r\n4 coordinates need to be set: X1, X2, Y1 and Y2. Which coordinate gets set, is determined by index. As each write to this register will also increment index, the usual flow is to reset the index to {\\tt 0} in \\PortTextXRef[]{1C}, then write all 4 coordinates in succession. Positions are inclusive. Furthermore, X positions are doubled for 320$\\times$256 mode, quadrupled for 640$\\times$256. Therefore, to view the whole of Layer 2, the values are:\r\n\r\n\\begin{tabular}{cllll}\r\n\t& & \r\n\t\t\\BitHead{256$\\times$192} & \r\n\t\t\\BitHead{320$\\times$256} & \r\n\t\t\\BitHead{640$\\times$256} \\\\\r\n\t0 & X1 position & \\BitMono{0}   & \\BitMono{0}   & \\BitMono{0} \\\\\r\n\t1 & X2 position & \\BitMono{255} & \\BitMono{159} & \\BitMono{159} \\\\\r\n\t2 & Y1 position & \\BitMono{0}   & \\BitMono{0}   & \\BitMono{0} \\\\\r\n\t3 & Y2 position & \\BitMono{191} & \\BitMono{255} & \\BitMono{255} \\\\\r\n\\end{tabular}\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{1C}}\r\n\r\nWrite:\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-4}\r\n\t\t\\PortDesc{Reserved, must be {\\tt 0}}\r\n\t\\PortBits{3}\r\n\t\t\\PortDesc{{\\tt 1} to reset Tilemap clip-window register index}\r\n\t\\PortBits{2}\r\n\t\t\\PortDesc{{\\tt 1} to reset ULA/LoRes clip-window register index}\r\n\t\\PortBits{1}\r\n\t\t\\PortDesc{{\\tt 1} to reset Sprite clip-window register index}\r\n\t\\PortBits{0}\r\n\t\t\\PortDesc{{\\tt 1} to reset Layer 2 clip-window register index}\r\n\\end{NextPort}\r\n\r\nRead:\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-6}\r\n\t\t\\PortDesc{Current Tilemap clip-window register index}\r\n\t\\PortBits{5-4}\r\n\t\t\\PortDesc{Current ULA/LoRes clip-window register index}\r\n\t\\PortBits{3-2}\r\n\t\t\\PortDesc{Current Sprite clip-window register index}\r\n\t\\PortBits{1-0}\r\n\t\t\\PortDesc{Current Layer 2 clip-window register index}\r\n\\end{NextPort}\r\n\r\n\r\n\\subsubsection{\\PortTextXRef[]{40}}\r\n\\vspace*{-2ex}\r\n\\subsubsection{\\PortTextXRef[]{41}}\r\n\\vspace*{-2ex}\r\n\\subsubsection{\\PortTextXRef[]{43}}\r\n\\vspace*{-2ex}\r\n\\subsubsection{\\PortTextXRef[]{44}}\r\n\\PortDeclarationXRefMultiple{Palette}{40}{44}\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{69}}\r\n\r\n% note: we use comma for referencing port declaration page to avoid double closing parenthesis, more readable this way\r\n\\begin{NextPort}\r\n\t\\PortBits{7}\r\n\t\t\\PortDesc{{\\tt 1} to enable Layer 2 (alias for bit 1 in \\PortTextXRef[,]{123B})}\r\n\t\\PortBits{6}\r\n\t\t\\PortDesc{{\\tt 1} to enable ULA shadow display (alias for bit 3 in \\PortTextXRef[,]{7FFD})}\r\n\t\\PortBits{5-0}\r\n\t\t\\PortDesc{Alias for bits 5-0 in Timex Sinclair Video Mode Control \\MemAddr{xxFF}}\r\n\\end{NextPort}\r\n\r\nULA shadow screen from Bank 7 has higher priority than Timex modes.\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{70}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-6}\r\n\t\t\\PortDesc{Reserved, must be {\\tt 0}}\r\n\t\\PortBits{5-4}\r\n\t\t\\PortDesc{Layer 2 resolution ({\\tt 0} after soft reset)}\r\n\t\t\\PortDescOnly{\r\n\t\t\t\\begin{PortBitConfig}\r\n\t\t\t\t\\PortBitLine{00}{256$\\times$192, 8BPP}\r\n\t\t\t\t\\PortBitLine{01}{320$\\times$256, 8BPP}\r\n\t\t\t\t\\PortBitLine{10}{640$\\times$256, 4BPP}\r\n\t\t\t\\end{PortBitConfig}\r\n\t\t}\r\n\t\\PortBits{3-0}\r\n\t\t\\PortDesc{Palette offset ({\\tt 0} after soft reset)}\r\n\\end{NextPort}\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{71}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-1}\r\n\t\t\\PortDesc{Reserved, must be {\\tt 0}}\r\n\t\\PortBits{0}\r\n\t\t\\PortDesc{MSB for X pixel offset}\r\n\\end{NextPort}\r\n\r\nThis is only used for 320$\\times$256 and 640$\\times$256 modes. Together with \\PortTextXRef{16} full 319 pixels offsets are available. For 640$\\times$256 only 2 pixel offsets are possible.\r\n\r\n\r\n\\pagebreak\r\n"
  },
  {
    "path": "chapter-next-memory.tex",
    "content": "\\section{Memory Map and Paging}\r\n\\label{zx_next_memorypaging}\r\n\r\n% ──────────────────────────────────────────────────────────────\r\n% ─██████──────────██████─██████████████─██████──────────██████─\r\n% ─██░░██████████████░░██─██░░░░░░░░░░██─██░░██████████████░░██─\r\n% ─██░░░░░░░░░░░░░░░░░░██─██░░██████████─██░░░░░░░░░░░░░░░░░░██─\r\n% ─██░░██████░░██████░░██─██░░██─────────██░░██████░░██████░░██─\r\n% ─██░░██──██░░██──██░░██─██░░██████████─██░░██──██░░██──██░░██─\r\n% ─██░░██──██░░██──██░░██─██░░░░░░░░░░██─██░░██──██░░██──██░░██─\r\n% ─██░░██──██████──██░░██─██░░██████████─██░░██──██████──██░░██─\r\n% ─██░░██──────────██░░██─██░░██─────────██░░██──────────██░░██─\r\n% ─██░░██──────────██░░██─██░░██████████─██░░██──────────██░░██─\r\n% ─██░░██──────────██░░██─██░░░░░░░░░░██─██░░██──────────██░░██─\r\n% ─██████──────────██████─██████████████─██████──────────██████─\r\n% ──────────────────────────────────────────────────────────────\r\n\r\n\\newcommand{\\MemEmpty}{\\multicolumn{1}{c}{}}\r\n\\newcommand{\\MemArrow}[1]{\\multicolumn{1}{c}{\\IfEq{#1}{<}{\\LArrowLine{1em}}{\\RArrowLine{1em}}}}\r\n\r\nZX Spectrum Next comes with 1024K (expanded version with 2048K) of memory. But it can't see it all at once.\r\n\r\n\r\n\\subsection{Banks and Slots}\r\n\r\nDue to its 16-bit address bus, Next can only address 2\\textsuperscript{16} = 65.536 bytes or 64K of memory at a time. To get access to all available memory, it's divided into smaller chunks called ``banks''\\footnote{You may also see the term ``page'' used instead of ``bank'' (in fact, that's why the process of swapping banks into slots is usually called ``paging''). I also noticed sometimes 64K addressable memory is referred to as ``bank''. In this book, I will keep naming consistent to avoid confusion.}.\r\n\r\nNext supports two interchangeable memory management models. One is inherited from the original Spectrums and clones and uses 16K banks. The other is unique to Next and uses 8K banks. Hence, addressable 64K is also divided into 16K or 8K ``slots'' into which banks are swapped in and out. In a way, slots are like windows into available memory.\r\n\r\nBanks are selected by their number - the first bank is {\\tt 0}, second {\\tt 1} and so on. If you ever worked with arrays, banks and their numbers work the same as array data and indexes. Both 16K and 8K banks start with number {\\tt 0} at the same address. So if 16K bank $n$ is selected, then the two corresponding 8K bank numbers would be $n \\times 2$ and $n \\times 2 + 1$.\r\n\r\nAfter startup, addressable 64K space is mapped like this:\r\n\r\n\\begin{ElegantTableX}{|l|l|l|l|l|X|}[\r\n\t\\newcommand{\\StartRow}[7]{\\MemAddr{#1}-\\MemAddr{#2} & \\multirow[t]{2}{*}{{\\tt #3}} & {\\tt #4} & \\multirow[t]{2}{*}{#5} & #6 & #7 \\\\}\r\n\t\\newcommand{\\EndRow}[5]{\\MemAddr{#1}-\\MemAddr{#2} & & {\\tt #3} & & #4 & #5 \\\\}\r\n]\r\n\r\n\t\\ElegantHeader[]{\r\n\t\t& \r\n\t\t\\multicolumn{2}{c|}{\\EH{Slots}} & \r\n\t\t\\multicolumn{2}{c|}{\\EH{Banks}} &\r\n\t}\r\n\r\n\t\\ElegantHeader{\r\n\t\t\\multirow{-2}{*}{\\EH{Address}} & % in second line and negative value to draw over row colour\r\n\t\t\\multicolumn{1}{c}{\\EH{16K}} & \r\n\t\t\\multicolumn{1}{c|}{\\EH{8K}} & \r\n\t\t\\multicolumn{1}{c}{\\EH{16K}} & \r\n\t\t\\multicolumn{1}{c|}{\\EH{8K}} & \r\n\t\t\\multirow{-2}{*}{\\EH{Description}}\r\n\t}\r\n\r\n\t\\StartRow{0000}{1FFF}{0}{0}{ROM}{ROM}{ROM, R/W redirect by L2, IRQ, NMI}\r\n\t\\EndRow{2000}{3FFF}     {1}     {ROM}{ROM, R/W redirect by Layer 2}\r\n\t\r\n\t\\hline\r\n\t\r\n\t\\StartRow{4000}{5FFF}{1}{2}{5}{10}{Normal/shadow ULA screen, Tilemap}\r\n\t\\EndRow{6000}{7FFF}     {3}   {11}{ULA extended attribute/graphics, Tilemap}\r\n\t\r\n\t\\hline\r\n\t\r\n\t\\StartRow{8000}{9FFF}{2}{4}{2}{4}{Free RAM}\r\n\t\\EndRow{A000}{BFFF}     {5}   {5}{Free RAM}\r\n\t\t\r\n\t\\hline\r\n\t\r\n\t\\StartRow{C000}{DFFF}{3}{6}{0}{0}{Free RAM}\r\n\t\\EndRow{E000}{FFFF}     {7}   {1}{Free RAM}\r\n\r\n\\end{ElegantTableX}\r\n\r\n\r\n\\subsection{Default Bank Traits}\r\n\r\nFirst few addressable banks have certain uses and traits:\r\n\r\n\\NewDocumentEnvironment{BankTraitTable}{ +!b }{\r\n\t\\begin{ElegantTableX}{|l|l|X|}\r\n\r\n\t\t\\ElegantHeader[]{ \\multicolumn{2}{|c|}{\\EH{Banks}} & }\r\n\t\t\\ElegantHeader{\r\n\t\t\t\\multicolumn{1}{|c}{\\EH{16K}} & \r\n\t\t\t\\multicolumn{1}{c|}{\\EH{8K}} &\r\n\t\t\t\\multirow{-2}{*}{\\EH{Description}}\r\n\t\t}\r\n\r\n\t\t#1\r\n\r\n\t\\end{ElegantTableX}\r\n}{}\r\n\r\n\\newcommand{\\BankTraitRow}[5][\\hline]{{\\tt #2} & {\\tt #3}-{\\tt #4} & #5 \\\\ #1}\r\n\\newcommand{\\BankTraitRowMulti}[6][\\hline]{{\\tt #2}-{\\tt #3} & {\\tt #4}-{\\tt #5} & #6 \\\\ #1}\r\n\r\n\\begin{BankTraitTable}\r\n\r\n\t\\BankTraitRow{0}{0}{1}{Standard RAM, maybe used by EsxDOS. Initially mapped to \\MemAddr{C000}-\\MemAddr{FFFF}}\r\n\t\\BankTraitRow[]{1}{2}{3}{Standard RAM, contended on 128, may be used by EsxDOS, RAM disk on NextZXOS}\r\n\r\n\\end{BankTraitTable}\r\n\r\n\\begin{BankTraitTable}\r\n\r\n\t\\BankTraitRow{2}{4}{5}{Standard RAM. Initially mapped to \\MemAddr{8000}-\\MemAddr{BFFF}}\r\n\t\\BankTraitRow{3}{6}{7}{Standard RAM, contended on 128, may be used by EsxDOS, RAM disk on NextZXOS}\r\n\t\\BankTraitRow{4}{8}{9}{Standard RAM, contended on +2/+3, RAM disk on NextZXOS}\r\n\t\\BankTraitRow{5}{10}{11}{ULA Screen, contended except on Pentagon, cannot be used by NextBASIC commands. Initially mapped to \\MemAddr{4000}-\\MemAddr{7FFF}}\r\n\t\\BankTraitRow{6}{12}{13}{Standard RAM, contended on +2/+3, RAM disk on NextZXOS}\r\n\t\\BankTraitRow{7}{14}{15}{ULA Shadow Screen, contended except on Pentagon, NextZXOS Workspace, cannot be used by NextBASIC commands}\r\n\t\\BankTraitRow{8}{16}{17}{Next RAM, Default Layer 2, NextZXOS screen and extra data, cannot be used by NextBASIC commands}\r\n\t\\BankTraitRowMulti{9}{10}{18}{21}{Next RAM, Rest of default Layer 2}\r\n\t\\BankTraitRowMulti[]{11}{13}{22}{27}{Next RAM, Default Layer 2 Shadow Screen}\r\n\t\r\n\\end{BankTraitTable}\r\n\r\n\r\n\\subsection{Memory Map}\r\n\r\nAs hinted before, not all available memory is addressable by programs. The first 256K is always reserved for ROMs and firmware. Hence bank {\\tt 0} starts at absolute address \\MemAddr{40000}:\r\n\r\n\\begin{ElegantTableX}{|l|l|l|l|l|l|X|}[\r\n\t\\newcommand{\\MapROMRowNoPrefix}[4]{- & - & #1 & \\MemAddr{#2}-\\MemAddr{#3} & #4 \\\\}\r\n\t\\newcommand{\\MapROMRow}[4]{& & \\MapROMRowNoPrefix{#1}{#2}{#3}{#4}}\r\n\t\\newcommand{\\MapRow}[8]{& & {\\tt #1}-{\\tt #2} & {\\tt #3}-{\\tt #4} & #5 & \\MemAddr{#6}-\\MemAddr{#7} & #8 \\\\}\r\n\t\\newcommand{\\MapDelim}{\\cline{3-7}}\r\n]\r\n\r\n\t\\ElegantHeader{\\multicolumn{2}{|c|}{} & \\EH{16K bank} & \\EH{8K bank} & \\EH{Size} & \\EH{Absolute Address} & \\EH{Description}}\r\n\t\r\n\t\\multirow{11}{*}{\\rotatebox[origin=c]{90}{\\LArrowLine{1.75cm} Expanded Next \\RArrowLine{1.75cm}}} &\r\n\t\\multirow{9}{*}{\\rotatebox[origin=c]{90}{\\LArrowLine{0.92cm} Unexpanded Next \\RArrowLine{0.92cm}}} &\r\n\t\\MapROMRowNoPrefix{64K}{000000}{00FFFF}{ZX Spectrum ROM}\r\n\t\\MapDelim\r\n\t\t\t\r\n\t\\MapROMRow{16K}{010000}{013FFF}{EsxDOS ROM}\r\n\t\\MapDelim\r\n\t\t\t\r\n\t\\MapROMRow{16K}{014000}{017FFF}{Multiface ROM}\r\n\t\\MapDelim\r\n\t\t\t\r\n\t\\MapROMRow{16K}{018000}{01BFFF}{Multiface Extra ROM}\r\n\t\\MapDelim\r\n\t\t\t\r\n\t\\MapROMRow{16K}{01C000}{01FFFF}{Multiface RAM}\r\n\t\\MapDelim\r\n\t\t\t\r\n\t\\MapROMRow{128K}{020000}{03FFFF}{DivMMC RAM}\r\n\t\\MapDelim\r\n\t\t\t\r\n\t\\MapRow{0}{7}{0}{15}{128K}{040000}{05FFFF}{Standard 128K RAM}\r\n\t\\MapDelim\r\n\t\t\t\r\n\t\\MapRow{8}{15}{16}{31}{128K}{060000}{07FFFF}{Extra RAM}\r\n\t\\MapDelim\r\n\t\t\t\r\n\t\\MapRow{16}{47}{32}{95}{512K}{080000}{0FFFFF}{1st Extra IC RAM}\r\n\t\\cline{2-7}\r\n\t\t\t\r\n\t\\MapRow{48}{79}{96}{159}{512K}{080000}{0FFFFF}{1st Extra IC RAM}\r\n\t\\MapDelim\r\n\t\t\t\r\n\t\\MapRow{80}{111}{160}{223}{512K}{080000}{0FFFFF}{2st Extra IC RAM}\r\n\t\r\n\\end{ElegantTableX}\r\n\r\nSo when swapping in, for example:\r\n\r\n\\begin{itemize}[topsep=0pt,itemsep=0pt]\r\n\t\\item 16K bank 20 to slot 3 and writing 10 bytes to memory \\MemAddr{C000} (start of 16K slot 3), we're effectively writing to absolute memory \\MemAddr{90000}-\\MemAddr{90009} ({\\tt \\MemAddr{40000} + 20 $\\times$ 16384})\r\n\t\r\n\t\\item 8K bank 30 to slot 5 and writing 10 bytes to memory \\MemAddr{A000} (start of 8K slot 5), we're effectively writing to absolute memory \\MemAddr{7C000}-\\MemAddr{7C009} ({\\tt \\MemAddr{40000} + 30 $\\times$ 8192})\r\n\\end{itemize}.\r\n\r\n\r\n\\subsection{Legacy Paging Modes}\r\n\r\nAs mentioned, Next inherits the memory management models from the Spectrum 128K/+2/+3 models and Pentagon clones. It's unlikely you will use these modes for Next programs, as Next own model is much simpler to use. They are still briefly described here though in case you will encounter them in older programs. All legacy models use 16K slots and banks.\r\n\r\n\r\n\\NewDocumentEnvironment{PagingTableLegacy}{ +!b }{\r\n\t% note: we need to use constant column widths so that all tables exactly match their cells...\r\n\r\n\t% this table uses elegant background and spacing\r\n\t\\begin{ElegantTable}{|p{1cm}|C{1.55cm}|C{1.55cm}|C{1.55cm}|C{1.55cm}|}[][]\r\n\t\t\\ElegantHeader{\\EH{Slot}\t& {\\tt 0}\t\t& {\\tt 1}\t\t\t& {\\tt 2}\t\t\t& {\\tt 3}}\r\n\t\\end{ElegantTable}\r\n\r\n\t\\vspace*{-0.75em}\r\n\r\n\t% second table touches top one, repeats borders, but without extra spacing that elegant table uses\r\n\t\\begin{tabular}{|p{1cm}|C{1.55cm}|C{1.55cm}|C{1.55cm}|C{1.55cm}|}\r\n\t\tStart\t& \\MemAddr{0000}\t& \\MemAddr{4000}\t& \\MemAddr{8000}\t& \\MemAddr{C000} \\\\\r\n\t\tEnd\t\t& \\MemAddr{3FFF}\t& \\MemAddr{7FFF}\t& \\MemAddr{BFFF}\t& \\MemAddr{FFFF} \\\\\r\n\t\t\\hline\r\n\t\\end{tabular}\r\n\r\n\t\\vspace*{-0.7em}\r\n\r\n\t% third table touches second one but without borders and with extra column at the end.\r\n\t\\begin{tabular}{p{1cm}C{1.55cm}C{1.55cm}C{1.55cm}C{1.55cm}l}\r\n\t\t#1\r\n\t\\end{tabular}\r\n}{}\r\n\r\n\\newcommand{\\PagingTableLegacyItem}[5]{ #1 & #2 & #3 & #4 & #5 \\\\ }\r\n\r\n\\subsubsection{128K Mode}\r\n\r\n\\begin{PagingTableLegacy}\r\n\t\\PagingTableLegacyItem{}{$\\uparrow$}{}{}{$\\uparrow$}\r\n\t\\PagingTableLegacyItem{}{\\tt ROM 0-1}{}{}{\\multicolumn{2}{l}{{\\tt BANK 0-7} on 128K}}\r\n\t\\PagingTableLegacyItem{}{}{}{}{\\multicolumn{2}{l}{{\\tt BANK 0-127} on Next}}\r\n\\end{PagingTableLegacy}\r\n\r\nAllows selecting:\r\n\r\n\\begin{itemize}[topsep=0pt,itemsep=0pt]\r\n\t\\item 16K ROM to be visible in the bottom 16K slot (0) from 2 possible banks\r\n\t\\item 16K RAM to be visible in the top 16K slot (3) from 8 possible banks (128 banks on Next)\r\n\\end{itemize}\r\n\r\nPorts involved:\r\n\r\n% note: since all ports are declared on the same page, we group the page in more info section below the table\r\n\\begin{itemize}[topsep=0pt,itemsep=0pt]\r\n\t\\item \\PortTextXRef[]{7FFD} bit 4 selects ROM bank for slot 0\r\n\t\\item \\PortTextXRef[]{7FFD} bits 2-0 select one of 8 RAM banks for slot 3\r\n\t\\item \\PortTextXRef[]{DFFD} bits 3-0 are added as MSB to 2-0 from \\MemAddr{7FFD} to form 128 banks for slot 3 (Next specific)\r\n\\end{itemize}\r\n\r\nSee page \\PortPage{7FFD} for details on ports \\MemAddr{7FFD} and \\MemAddr{DFFD}. If you are using the standard interrupt handler or OS routines, then any time you write to \\PortTextXRef[]{7FFD} you should also store the value at \\MemAddr{5B5C}.\r\n\r\n\r\n\\subsubsection{+3 Normal Mode}\r\n\r\n\\begin{PagingTableLegacy}\r\n\t\\PagingTableLegacyItem{}{$\\uparrow$}{}{}{$\\uparrow$}\r\n\t\\PagingTableLegacyItem{}{\\tt ROM 0-3}{}{}{\\multicolumn{2}{l}{{\\tt BANK 0-7} on 128K}}\r\n\t\\PagingTableLegacyItem{}{}{}{}{\\multicolumn{2}{l}{{\\tt BANK 0-127} on Next}}\r\n\\end{PagingTableLegacy}\r\n\r\nAllows selecting:\r\n\r\n\\begin{itemize}[topsep=0pt,itemsep=0pt]\r\n\t\\item 16K ROM to be visible in the bottom 16K slot (0) from 4 possible banks\r\n\t\\item 16K RAM to be visible in the top 16K slot (3) from 8 possible banks (128 banks on Next)\r\n\\end{itemize}\r\n\r\n\\pagebreak\r\nPorts involved:\r\n\r\n% note: since all ports are declared on the same page, we group the page in more info section below the table\r\n\\begin{itemize}[topsep=0pt,itemsep=0pt]\r\n\t\\item \\PortTextXRef[]{1FFD} bit 2 as LSB selects ROM bank for slot 0\r\n\t\\item \\PortTextXRef[]{7FFD} bit 4 forms MSB selects ROM bank for slot 0\r\n\t\\item \\PortTextXRef[]{7FFD} bits 2-0 select one of 8 RAM banks for slot 3\r\n\t\\item \\PortTextXRef[]{DFFD} bits 3-0 are added as MSB to 2-0 from \\MemAddr{7FFD} to form 128 banks for slot 3 (Next specific)\r\n\\end{itemize}\r\n\r\nSee page \\PortPage{7FFD} for details on ports \\MemAddr{1FFD}, \\MemAddr{7FFD} and \\MemAddr{DFFD}. If you are using the standard interrupt handler or OS routines, then any time you write to \\PortTextXRef[]{1FFD} you should also store the same value at \\MemAddr{5B67} and any time your write to \\PortTextXRef[]{7FFD} you should also store the value at \\MemAddr{5B5C}.\r\n\r\n\r\n\\subsubsection{+3 All-RAM Mode}\r\n\r\n\\begin{PagingTableLegacy}\r\n\t\\PagingTableLegacyItem{}{$\\uparrow$}{$\\uparrow$}{$\\uparrow$}{$\\uparrow$}\r\n\t\\PagingTableLegacyItem{\\tt 00 =}{\\tt BANK 0}{\\tt BANK 1}{\\tt BANK 2}{\\tt BANK 3}\r\n\t\\PagingTableLegacyItem{\\tt 01 =}{\\tt BANK 4}{\\tt BANK 5}{\\tt BANK 6}{\\tt BANK 7}\r\n\t\\PagingTableLegacyItem{\\tt 10 =}{\\tt BANK 4}{\\tt BANK 5}{\\tt BANK 6}{\\tt BANK 3}\r\n\t\\PagingTableLegacyItem{\\tt 11 =}{\\tt BANK 4}{\\tt BANK 7}{\\tt BANK 6}{\\tt BANK 3}\r\n\t\\multirow{2}{*}{$\\Big\\downarrow$}$\\downarrow$ & \\\\\r\n\t\\multicolumn{5}{l}{~~Lo bit = bit 1 from \\MemAddr{1DDF}} \\\\\r\n\t\\multicolumn{5}{l}{Hi bit = bit 2 from \\MemAddr{1DDF}} \\\\\r\n\\end{PagingTableLegacy}\r\n\r\nAlso called ``Special Mode'' or ``CP/M Mode''. Allows selecting all 4 slots from limited selection of banks as shown in the table above.\r\n\r\nPorts involved:\r\n\r\n% note: since all ports are declared on the same page, we group the page in more info section below the table\r\n\\begin{itemize}[topsep=0pt,itemsep=0pt]\r\n\t\\item \\PortTextXRef[]{1FFD} bit 0 enables All-RAM (if {\\tt 1}) or normal mode ({\\tt 0})\r\n\t\\item \\PortTextXRef[]{1FFD} bits 2-1 select memory configuration\r\n\\end{itemize}\r\n\r\nSee page \\PortPage{1FFD} for details on port \\MemAddr{1FFD}. If you are using the standard interrupt handler or OS routines, then any time you write to \\PortTextXRef[]{1FFD} you should also store the same value at \\MemAddr{5B67}.\r\n\r\n\r\n\\subsubsection{Pentagon 512K/1024K Mode}\r\n\r\nNext also supports paging implementation from Pentagon spectrums. It's unlikely you will ever use it on Next, so just mentioning for completness sake. You can find more information on Next Dev Wiki\\footnote{\\url{https://wiki.specnext.dev/Next_Memory_Bank_Select}} or internet if interested.\r\n\r\n\r\n\\pagebreak\r\n\\subsection{Next MMU Paging Mode}\r\n\r\nNext MMU based paging mode is much more flexible in that it allows mapping 8K banks into any 8K slot of memory available to the CPU. This is the only mode that allows paging in all 2048K on extended Next. It's also the simplest to use - a single {\\tt NEXTREG} instruction assigning bank number to desired MMU slot register.\r\n\r\nIn this mode, 64K memory accessible to the CPU is divided into 8 slots called MMU0 through MMU7, as shown in the diagram below. Physical memory is thus divided into 96 (or 224 on expanded Next) 8K banks.\r\n\r\n% similar to legacy tables, but less width per column\r\n\\begin{ElegantTable}{|p{1.8cm}|C{1.1cm}|C{1.1cm}|C{1.1cm}|C{1.1cm}|C{1.1cm}|C{1.1cm}|C{1.1cm}|C{1.1cm}|}[][]\r\n\t\\ElegantHeader{\r\n\t\t\\EH{16K Slot} &\r\n\t\t\\multicolumn{2}{c|}{\\tt 0} &\r\n\t\t\\multicolumn{2}{c|}{\\tt 1} &\r\n\t\t\\multicolumn{2}{c|}{\\tt 2} &\r\n\t\t\\multicolumn{2}{c|}{\\tt 3}\r\n\t}\r\n\t\\ElegantHeader{\r\n\t\t\\EH{8K Slot} &\r\n\t\t{\\tt 0} &\r\n\t\t{\\tt 1} &\r\n\t\t{\\tt 2} &\r\n\t\t{\\tt 3} &\r\n\t\t{\\tt 4} &\r\n\t\t{\\tt 5} &\r\n\t\t{\\tt 6} &\r\n\t\t{\\tt 7}\r\n\t}\r\n\\end{ElegantTable}\r\n\r\n\\vspace*{-0.75em}\r\n\r\n\\begin{tabular}{|p{1.8cm}|C{1.1cm}|C{1.1cm}|C{1.1cm}|C{1.1cm}|C{1.1cm}|C{1.1cm}|C{1.1cm}|C{1.1cm}|}\r\n\t\\hline\r\n\tStart\t& \\MemAddr{0000}\t& \\MemAddr{2000}\t& \\MemAddr{4000}\t& \\MemAddr{6000}\t& \\MemAddr{8000}\t& \\MemAddr{A000}\t& \\MemAddr{C000}\t& \\MemAddr{E000} \\\\\r\n\tEnd\t\t& \\MemAddr{1FFF}\t& \\MemAddr{3FFF}\t& \\MemAddr{5FFF}\t& \\MemAddr{7FFF}\t& \\MemAddr{9FFF}\t& \\MemAddr{BFFF}\t& \\MemAddr{DFFF}\t& \\MemAddr{FFFF} \\\\\r\n\t\\hline\r\n\\end{tabular}\r\n\r\n\\vspace*{-0.7em}\r\n\r\n\\begin{tabular}{p{1.8cm}C{1.1cm}C{1.1cm}C{1.1cm}C{1.1cm}C{1.1cm}C{1.1cm}C{1.1cm}C{1.1cm}}\r\n\t\t\t& $\\uparrow$\t\t& $\\uparrow$\t\t& $\\uparrow$\t\t& $\\uparrow$\t\t& $\\uparrow$\t\t& $\\uparrow$\t\t& $\\uparrow$\t\t& $\\uparrow$ \\\\\r\n\t\t\t& {\\tt BANK}\t\t& {\\tt BANK}\t\t& {\\tt BANK}\t\t& {\\tt BANK}\t\t& {\\tt BANK}\t\t& {\\tt BANK}\t\t& {\\tt BANK}\t\t& {\\tt BANK} \\\\\r\n\t\t\t& {\\tt 0-255}\t\t& {\\tt 0-255}\t\t& {\\tt 0-255}\t\t& {\\tt 0-255}\t\t& {\\tt 0-255}\t\t& {\\tt 0-255}\t\t& {\\tt 0-255}\t\t& {\\tt 0-255} \\\\\r\n\\end{tabular}\r\n\r\nBank selection is set via Next registers (see page \\PortPage{50} for details):\r\n\r\n% note: since all ports are declared on the same page, we group the page in more info section below the table\r\n\\begin{itemize}[topsep=0pt,itemsep=0pt]\r\n\t\\item \\PortTextXRef[]{50}\r\n\t\\item \\PortTextXRef[]{51}\r\n\t\\item \\PortTextXRef[]{52}\r\n\t\\item \\PortTextXRef[]{53}\r\n\t\\item \\PortTextXRef[]{54}\r\n\t\\item \\PortTextXRef[]{55}\r\n\t\\item \\PortTextXRef[]{56}\r\n\t\\item \\PortTextXRef[]{57}\r\n\\end{itemize}\r\n\r\nWhile not absolutely required, it's good practice to store original slot values and then restore before exiting program or returning from subroutines.\r\n\r\nExample of writing 10 bytes ({\\tt 00 01 02 03 04 05 06 07 08 09}) to 8K bank 30 swapped in to slot 5. As mentioned before, this will effectively write to absolute memory \\MemAddr{7C000}-\\MemAddr{7C009}:\r\n\r\n\\begin{tcblisting}{}\r\n\tNEXTREG &55, 30     ; swap bank 30 to slot 5\r\n\r\n\tLD DE, &A000        ; slot 5 starts at &A000\r\n\tLD A, 0             ; starting data to write\r\n\tLD B, 10            ; number of bytes to write\r\nnext:\r\n\tLD (DE), A          ; write next byte\r\n\tINC A               ; increment source byte\r\n\tINC DE              ; increment destination location\r\n\tDJNZ next\r\n\\end{tcblisting}\r\n\r\n% note: since both ports are declared on the same page, we group the page\r\nNote: registers \\PortTextXRef[]{50} and \\PortTextXRef[]{51} (page \\PortPage{50}) have extra ``functionality'': ROM can be automatically paged in if otherwise nonexistent 8K page \\MemAddr{FF} is set. Low or high 8K ROM bank is automatically determined based on which 8K slot is used. This may be useful if temporarily paging RAM into the bottom 16K region and then wanting to restore back to ROM.\r\n\r\n\r\n\\subsection{Interaction Between Paging Modes}\r\n\r\nAs mentioned, legacy and Next paging modes are interchangeable. Changing banks in one will be reflected in the other. The most recent change always has priority. Again, keep in mind that legacy modes use 16K banks, therefore single bank change will affect 2 8K banks.\r\n\r\n\r\n\\subsubsection{Paging Out ROM}\r\n\r\nROM is usually mapped to the bottom 16K slot, addresses \\MemAddr{0000}-\\MemAddr{3FFF}. This area can only be remapped using +3 All-RAM or Next MMU-based mode. Beware though that some programs may expect to find ROM routines at fixed addresses between \\MemAddr{0000} and \\MemAddr{3FFF}. And if default interrupt mode (IM 1) is set, Z80 will expect to find interrupt handler at the address \\MemAddr{0038}.\r\n\r\n\r\n\\subsubsection{ULA}\r\n\r\nULA always reads content from 16K bank 5. This is mapped to 16K slot 1 by default, addresses \\MemAddr{4000}-\\MemAddr{7FFF}. ULA will always use bank 5, regardless of which bank is mapped to slot 1, or which slot bank 5 is mapped to (or if it is mapped into any slot at all).\r\n\r\nYou can redirect ULA to read from 16K bank 7 instead (the ``shadow screen'', used for double-buffering), using bit 3 of \\PortTextXRef{7FFD}. However, you still need to map bank 7 into one of the slots if you want to read or write to it (that's 8K banks 14 and 15 if using MMU for paging). Read more in ULA chapter, section \\XRef{zx_next_ula}.\r\n\r\n\r\n\\subsubsection{Layer 2 Paging}\r\n\r\nLayer 2 uses specific ports and registers that are can be used to change memory mapping. For example, the bottom 16K slot can be set for write and read access. Layer 2 also supports a double-buffering scheme of its own. Though any other mapping mode discussed here can be used as well. See Layer 2 chapter, section \\XRef{zx_next_layer2} for more details.\r\n\r\n\r\n\r\n\\pagebreak\r\n\r\n\\subsection{Paging Mode Ports and Registers}\r\n\\label{zx_next_memorypaging_registers}\r\n\r\n% note: almost all references to ports are described on this same page spread, hence no page numbers in XRefs\r\n\r\n\\subsubsection{\\PortDeclaration{1FFD}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-3}\r\n\t\t\\PortDesc{Unused, use 0}\r\n\t\\PortBits{2}\r\n\t\t\\PortDesc{In normal mode high bit of ROM selection. With low bit from bit 4 of \\MemAddr{7FFD}:}\r\n\t\t\\PortDescOnly{\r\n\t\t\t\\begin{PortBitConfig}\r\n\t\t\t\t\\PortBitLine{00}{ROM0 = 128K editor and menu system}\r\n\t\t\t\t\\PortBitLine{01}{ROM1 = 128K syntax checker}\r\n\t\t\t\t\\PortBitLine{10}{ROM2 = +3DOS}\r\n\t\t\t\t\\PortBitLine{11}{ROM3 = 48K BASIC}\r\n\t\t\t\\end{PortBitConfig}\r\n\t\t}\r\n\t\t\\PortDescOnly{In special mode: high bit of memory configuration number}\r\n\t\\PortBits{1}\r\n\t\t\\PortDesc{In special mode: low bit of memory configuration number}\r\n\t\\PortBits{0}\r\n\t\t\\PortDesc{Paging mode: 0 = normal, 1 = special}\r\n\\end{NextPort}\r\n\r\n\\subsubsection{\\PortDeclaration{7FFD}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-6}\r\n\t\t\\PortDesc{Extra two bits for 16K RAM bank if in Pentagon 512K/1024K mode (see \\PortTextXRef[]{DFFD} below)}\r\n\t\\PortBits{5}\r\n\t\t\\PortDesc{{\\tt 1} locks pages; cannot be unlocked until next reset on regular ZX128)}\r\n\t\\PortBits{4}\r\n\t\t\\PortDesc{128K: ROM select ({\\tt 0} = 128K editor, {\\tt 1} = 48K BASIC)}\r\n\t\t\\PortDescOnly{+2/+3: low bit of ROM select (see \\PortTextXRef[]{1FFD} above)}\r\n\t\\PortBits{3}\r\n\t\t\\PortDesc{ULA layer shadow screen toggle (0 = bank 5, 1 = bank 7)}\r\n\t\\PortBits{2-0}\r\n\t\t\\PortDesc{Bank number for slot 4 (\\MemAddr{C000})}\r\n\\end{NextPort}\r\n\r\n\\subsubsection{\\PortDeclaration{DFFD}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7}\r\n\t\t\\PortDesc{1 to set Pentagon 512K/1024K mode}\r\n\t\\PortBits{3-0}\r\n\t\t\\PortDesc{Most significant bits of the 16K RAM bank selected in \\PortTextXRef[]{7FFD}}\r\n\\end{NextPort}\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{50}}\r\n\\vspace*{-2ex}\r\n\\subsubsection{\\PortDeclaration{51}}\r\n\\vspace*{-2ex}\r\n\\subsubsection{\\PortDeclaration{52}}\r\n\\vspace*{-2ex}\r\n\\subsubsection{\\PortDeclaration{53}}\r\n\\vspace*{-2ex}\r\n\\subsubsection{\\PortDeclaration{54}}\r\n\\vspace*{-2ex}\r\n\\subsubsection{\\PortDeclaration{55}}\r\n\\vspace*{-2ex}\r\n\\subsubsection{\\PortDeclaration{56}}\r\n\\vspace*{-2ex}\r\n\\subsubsection{\\PortDeclaration{57}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-0}\r\n\t\t\\PortDesc{Selects 8K bank stored in corresponding 8K slot}\r\n\\end{NextPort}\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{8E}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7}\r\n\t\t\\PortDesc{Access to bit 0 of \\PortTextXRef[]{DFFD}}\r\n\t\\PortBits{6-4}\r\n\t\t\\PortDesc{Access to bits 2-0 of \\PortTextXRef[]{7FFD}}\r\n\t\\PortBits{3}\r\n\t\t\\PortDesc{Read will always return {\\tt 1}}\r\n\t\t\\PortDescOnly{Write {\\tt 1} to change RAM bank, {\\tt 0} for no change to MMU6,7, \\MemAddr{7FFD} and \\MemAddr{DFFD}}\r\n\t\\PortBits{2}\r\n\t\t\\PortDesc{{\\tt 0} for normal paging mode, {\\tt 1} for special all-RAM mode}\r\n\t\\PortBits{1}\r\n\t\t\\PortDesc{Access to bit 2 of \\PortTextXRef[]{1FFD}}\r\n\t\\PortBits{0}\r\n\t\t\\PortDesc{If bit 2 = {\\tt 0} (normal mode): bit 4 of \\PortTextXRef[]{7FFD}}\r\n\t\t\\PortDescOnly{If bit 2 = {\\tt 1} (special mode): bit 1 of \\PortTextXRef[]{1FFD}}\r\n\\end{NextPort}\r\n\r\nActs as a shortcut for reading and writing \\PortTextXRef[]{1FFD}, \\PortTextXRef[]{7FFD} and \\PortTextXRef[]{DFFD} all at once. Mainly to simplify classic Spectrum memory mapping. Though, as mentioned, Next specific programs should prefer MMU based memory mapping.\r\n\r\n\\pagebreak"
  },
  {
    "path": "chapter-next-palette.tex",
    "content": "\\section{Palette}\r\n\\label{zx_next_palette}\r\n\r\nNext greatly enhances ZX Spectrum video capabilities by offering several new ways to draw graphics on a screen. We'll see how to program each in later chapters, but let's check common behaviour first - colour management.\r\n\r\nTo draw a pixel on a screen, we need to set its colour as data in memory. Next shares implementation to other contemporary 8-bit computers - all possible colours are stored together in a palette, as an array of RGB values, and each pixel is simply an index into this array. This approach requires less memory and allows creating efficient effects such as fade to/from black, transitions from day to night, water animations etc.\r\n\r\n\r\n\\subsection{Palette Selection}\r\n\r\nEach graphics mode or layer has not one but two palettes, each of which can be changed independently. Of course, only one of two can be active at any given time for each mode. The other can be initialized with alternate colours and can be quickly activated to achieve colour animation effects.\r\n\r\nActive palette is set with \\PortTextXRef{43} for ULA, Layer 2 and Sprites and \\PortTextXRef{6B} for Tilemap.\r\n\r\n\r\n\\subsection{Palette Editing}\r\n\r\nNext palettes have 256 colours. All are initialized with default values, so they are usable out of the box. But it's also possible to change every colour. Regardless of the palette, the procedure to read or write colours is:\r\n\r\n\\begin{enumerate}[topsep=1pt,itemsep=1pt]\r\n\t\\item \\PortTextXRef{43} selects palette which colours you want to edit\r\n\t\\item \\PortTextXRef{40} selects colour index that will be read or written\r\n\t\\item \\PortTextXRef{41} or \\PortTextXRef{44} reads or writes data for selected colour\r\n\\end{enumerate}\r\n\r\n% note: since all mentioned registers already include page numbers in enumerate above, they are omitted in the description below, makes it more readable\r\nWhen writing colours, we can chose to automatically increment colour indexes after each write. Bit 7 of \\PortTextXRef[]{43} is used for that purpose. This works the same for both write registers (\\MemAddr{41} and \\MemAddr{44}). Colour RGB values can either be 8-bit {\\tt RRRGGGBB}, or 9-bit {\\tt RRRGGGBBB} values. Use \\PortTextXRef[]{41} for 8-bit and \\PortTextXRef[]{44} for 9-bit.\r\n\r\nNote: \\PortTextXRef[]{43} has two roles when working with palettes - it selects the active palette for display (out of two available - only for ULA, Layer 2 and Sprites) and selects palette for editing (for all layers, including Tilemap). Therefore care needs to be taken when updating colour entries to avoid accidentally changing the active palette for display at the same time. Depending on our program, we may first need to read the value and then only change bits affecting the palette for editing to ensure the rest of the data remains unaffected.\r\n\r\n\r\n\\subsection{8 Bit Colours}\r\n\r\n8-bit colours are stored as {\\tt RRRGGGBB} values with 3 bits per red and green and 2 bits per blue component. Each colour is therefore stored as a single byte. \\PortTextXRef{41} is used to read or write the value.\r\n\r\nHere's a reusable subroutine for copying {\\tt B} number of colours stored as a contiguous block in memory addressed by {\\tt HL} register, starting at the currently selected colour index:\r\n\r\n\\begin{tcblisting}{}\r\nCopy8BitPalette:\r\n\tLD A, (HL)                ; Load RRRGGGBB into A\r\n\tINC HL                    ; Increment to next colour entry\r\n\tNEXTREG &41, A            ; Send colour data to Next HW\r\n\tDJNZ Copy8BitPalette      ; Repeat until B=0\r\n\\end{tcblisting}\r\n\r\nAnd we'd call the subroutine with something like:\r\n\r\n\\begin{tcblisting}{}\r\n\tNEXTREG &43, %00010000    ; Auto increment, Layer 2 first palette for read/write\r\n\tNEXTREG &40, 0            ; Start copying into index 0\r\n\tLD HL, palette            ; Address to copy RRRGGGBB values from\r\n\tLD B, 255                 ; Copy 255 colours\r\n\tCALL Copy8BitPalette\r\n\\end{tcblisting}\r\n\r\nNote: we could also use DMA to transfer all the bytes. I won't show it here, but feel free to implement it as an excercise - see section \\ref{zx_next_dma} for details on programming the DMA.\r\n\r\n\r\n\\subsection{9 Bit Colours}\r\n\r\nWith 9 bits per colour, each RGB component uses full 3 bits, thus greatly increasing the available colour gamut. However, each colour needs 2 bytes in memory instead of 1. To read or write we use \\PortTextXRef{44} register instead of \\PortAddr{41}. It works similarly to \\PortAddr{41}~except that each colour requires two writes: first one stores {\\tt RRRGGGBB} part and second least significant bit of blue component. Subroutine for copying 9-bit colours:\r\n\r\n\\begin{tcblisting}{}\r\nCopy9BitPalette:\r\n\tLD A, (HL)                ; Load RRRGGGBB into A\r\n\tINC HL                    ; Increment to next byte\r\n\tNEXTREG &44, A            ; Send colour data to Next HW\r\n\tLD A, (HL)                ; Load remaining byte with LSB of B component into A\r\n\tINC HL                    ; Increment to next colour entry\r\n\tNEXTREG &44, A            ; Send colour data to Next HW and increment index\r\n\tDJNZ Copy9BitPalette      ; Repeat until B=0\r\n\\end{tcblisting}\r\n\r\nNote: subroutine requires that colours are stored in 2 bytes with first containing {\\tt RRRGGGBB} part and second least significant bit of blue. Which is how typically drawing programs store a 9-bit palette anyways. The code for calling this subroutine is exactly the same as for the 8-bit colours above.\r\n\r\n\r\n\\subsection{Palette Registers}\r\n\\label{zx_next_palette_registers}\r\n\r\n\\subsubsection{\\PortDeclaration{40}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-0}\r\n\t\t\\PortDesc{Reads or writes palette colour index to be manipulated}\r\n\\end{NextPort}\r\n\r\n% note: register $41 is declared on next page (same spread), so we omit page number, but others are declared on the following spreads, so we leave them\r\nWriting an index {\\tt 0-255} associates it with colour set through \\PortTextXRef[]{41} or \\PortTextXRef{44} of currently selected pallette in \\PortTextXRef{43}. Write also resets value of \\PortTextXRef{44} so next write will occur for first colour of the palette\r\n\r\nWhile Tilemap, Layer 2 and Sprites palettes use all 256 distinct colours (with some caveats, as described in specific chapters), ULA modes work like this:\r\n\r\n\\begin{quote}\r\n\t\\small\r\n\r\n\t\\NewDocumentEnvironment{PalIndexTable}{ +b }{\r\n\t\t\\begin{tabularx}{\\linewidth}{@{}p{1.5cm}X}\r\n\t\t\tIndex & Colours \\\\\r\n\t\t\t#1\r\n\t\t\\end{tabularx}\r\n\t\t\\vspace*{-1ex}\r\n\t}{}\r\n\r\n\t\\NewDocumentCommand{\\PalIndexEntry}{ m m }{{\\tt #1} & #2 \\\\}\r\n\r\n\t\\textbf{Classic ULA}\r\n\r\n\t\\begin{PalIndexTable}\r\n\t\t\\PalIndexEntry{~0-7}{Ink}\r\n\t\t\\PalIndexEntry{~8-15}{Bright ink}\r\n\t\t\\PalIndexEntry{16-23}{Paper}\r\n\t\t\\PalIndexEntry{24-31}{Bright paper}\r\n\t\\end{PalIndexTable}\r\n\r\n\tBorder is taken from paper colours.\r\n\r\n\t\r\n\t\\vspace*{1em}\r\n\t\\textbf{ULA+}\r\n\r\n\t\\begin{PalIndexTable}\r\n\t\t\\PalIndexEntry{0-64}{Ink}\r\n\t\\end{PalIndexTable}\r\n\r\n\tPaper and border are taken from \\PortTextXRef{4A}.\r\n\r\n\r\n\t\\vspace*{1em}\r\n\t\\textbf{ULANext normal mode}\r\n\r\n\t\\begin{PalIndexTable}\r\n\t\t\\PalIndexEntry{~~0-127}{Ink (only a subset)}\r\n\t\t\\PalIndexEntry{128-255}{Paper (only a subset)}\r\n\t\\end{PalIndexTable}\r\n\r\n\t% note: register $42 is declared on next page (same spread), so we omit page number to keep text more readable\r\n\tBorder is taken from paper colours. The number of active indices depends on the number of attribute bits assigned to ink and paper out of the attribute byte by \\PortTextXRef[]{42}.\r\n\r\n\r\n\t\\vspace*{1em}\r\n\t\\textbf{ULANext full-ink mode}\r\n\r\n\t\\begin{PalIndexTable}\r\n\t\t\\PalIndexEntry{0-255}{Ink}\r\n\t\\end{PalIndexTable}\r\n\r\n\tPaper and border are taken from \\PortTextXRef{4A}.\r\n\r\n\\end{quote}\r\n\r\n\r\n\\pagebreak\r\n\\subsubsection{\\PortDeclaration{41}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-0}\r\n\t\t\\PortDesc{Reads or writes 8-bit colour data}\r\n\\end{NextPort}\r\n\r\nFormat is:\r\n\r\n\\begin{BitTableByte}\r\n\t\\BitSmall{$R_2$} &\r\n\t\t\\BitSmall{$R_1$} &\r\n\t\t\\BitSmall{$R_0$} &\r\n\t\t\\BitSmall{$G_2$} &\r\n\t\t\\BitSmall{$G_1$} &\r\n\t\t\\BitSmall{$G_0$} &\r\n\t\t\\BitSmall{$B_2$} &\r\n\t\t\\BitSmall{$B_1$} \\\\\r\n\t\\hline\r\n\t\\BitStartMulti{3}{Red} &\r\n\t\t\\BitMulti{3}{Green} &\r\n\t\t\\BitMulti{2}{Blue} \\\\\r\n\\end{BitTableByte}\r\n\r\nLeast significant bit of blue is set to {\\tt OR} between $B_2$ and $B_1$.\r\n\r\n% note: register $40 is declared on previous page (same spread), so we omit page number to keep text more readable\r\nWriting the value will automatically increment index in \\PortTextXRef[]{40}, if auto-increment is enabled in \\PortTextXRef{43}. Read doesn't auto-increment index.\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{42}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-0}\r\n\t\t\\PortDesc{The number for last ink colour entry in the palette. Only used when ULANext mode is enabled (see \\PortTextXRef{43}). Only the following values are allowed, harware behavior is unpredictable for other values:}\r\n\t\t\\PortDescOnly{\r\n\t\t\t\\begin{PortBitConfig}\r\n\t\t\t\t\\PortBitLine{1}{Ink and paper only use 1 colour each on indices {\\tt 0} and {\\tt 128} respectively}\r\n\t\t\t\t\\PortBitLine{3}{Ink and paper use 4 colours each, on indices {\\tt 0}-{\\tt 3} and {\\tt 128}-{\\tt 131}}\r\n\t\t\t\t\\PortBitLine{7}{Ink and paper use 8 colours each, on indices {\\tt 0}-{\\tt 7} and {\\tt 128}-{\\tt 135}}\r\n\t\t\t\t\\PortBitLine{15}{Ink and paper use 16 colours each, on indices {\\tt 0}-{\\tt 15} and {\\tt 128}-{\\tt 143}}\r\n\t\t\t\t\\PortBitLine{31}{Ink and paper use 32 colours each, on indices {\\tt 0}-{\\tt 31} and {\\tt 128}-{\\tt 159}}\r\n\t\t\t\t\\PortBitLine{63}{Ink and paper use 64 colours each, on indices {\\tt 0}-{\\tt 63} and {\\tt 128}-{\\tt 191}}\r\n\t\t\t\t\\PortBitLine{127}{Ink and paper use 128 colours each, on indices {\\tt 0}-{\\tt 127} and {\\tt 128}-{\\tt 255}}\r\n\t\t\t\t\\PortBitLine{255}{Enables full-ink colour mode where all indices are ink. In this mode paper and border are taken from \\PortTextXRef{4A}}\r\n\t\t\t\\end{PortBitConfig}\r\n\t\t}\r\n\t\t\\PortDescOnly{Default value is {\\tt 7} for core 3.0 and later, {\\tt 15} for older cores.}\r\n\\end{NextPort}\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{43}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7}\r\n\t\t\\PortDesc{{\\tt 1} to disable palette index auto-increment, {\\tt 0} to enable}\r\n\t\\PortBits{6-4}\r\n\t\t\\PortDesc{Selects palette for read or write}\r\n\t\t\\PortDescOnly{\r\n\t\t\t\\begin{PortBitConfig}\r\n\t\t\t\t\\PortBitLine{000}{ULA first palette}\r\n\t\t\t\t\\PortBitLine{100}{ULA second palette}\r\n\t\t\t\t\\PortBitLine{001}{Layer 2 first palette}\r\n\t\t\t\t\\PortBitLine{101}{Layer 2 second palette}\r\n\t\t\t\t\\PortBitLine{010}{Sprites first palette}\r\n\t\t\t\t\\PortBitLine{110}{Sprites second palette}\r\n\t\t\t\t\\PortBitLine{011}{Tilemap first palette}\r\n\t\t\t\t\\PortBitLine{111}{Tilemap second palette}\r\n\t\t\t\\end{PortBitConfig}\r\n\t\t}\r\n\t\\PortBits{3}\r\n\t\t\\PortDesc{Selects active Sprites palette ({\\tt 0} = first palette, {\\tt 1} = second palette)}\r\n\t\\PortBits{2}\r\n\t\t\\PortDesc{Selects active Layer 2 palette ({\\tt 0} = first palette, {\\tt 1} = second palette)}\r\n\t\\PortBits{1}\r\n\t\t\\PortDesc{Selects active ULA palette ({\\tt 0} = first palette, {\\tt 1} = second palette)}\r\n\t\\PortBits{0}\r\n\t\t\\PortDesc{Enables ULANext mode if {\\tt 1} ({\\tt 0} after reset)}\r\n\\end{NextPort}\r\n\r\n% note: register $44 is declared on the same page, so we omit page number to keep text more readable\r\nWrite will also reset the index of \\PortTextXRef[]{44} so next write there will be considered as first byte of first colour.\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{44}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-0}\r\n\t\t\\PortDesc{Reads or writes 9-bit colour definition}\r\n\\end{NextPort}\r\n\r\nTwo consequtive writes are needed:\r\n\r\n\\begin{multicols}{2}\r\n\tFirst write:\r\n\t\r\n\t\\begin{BitTableByte}[C{1em}]\r\n\t\t\\BitSmall{$R_2$} &\r\n\t\t\t\\BitSmall{$R_1$} &\r\n\t\t\t\\BitSmall{$R_0$} &\r\n\t\t\t\\BitSmall{$G_2$} &\r\n\t\t\t\\BitSmall{$G_1$} &\r\n\t\t\t\\BitSmall{$G_0$} &\r\n\t\t\t\\BitSmall{$B_2$} &\r\n\t\t\t\\BitSmall{$B_1$} \\\\\r\n\t\t\\hline\r\n\t\t\\BitStartMulti{3}{Red} &\r\n\t\t\t\\BitMulti{3}{Green} &\r\n\t\t\t\\BitMulti{2}{Blue} \\\\\r\n\t\\end{BitTableByte}\r\n\r\n\t\\columnbreak\r\n\r\n\tSecond write:\r\n\r\n\t\\begin{BitTableByte}[C{1em}]\r\n\t\t\\BitSmall{$P_r$} &\r\n\t\t\t\\BitMulti{6}{-} &\r\n\t\t\t\\BitSmall{$B_0$} \\\\\r\n\t\t\\hline\r\n\t\t\\BitSmall{$L2$} &\r\n\t\t\t\\BitMulti{6}{Reserved, set to {\\tt 0}} &\r\n\t\t\t\\BitSmall{B} \\\\\r\n\t\\end{BitTableByte}\r\n\r\n\\end{multicols}\r\n\r\nBit 7 of the second write must be {\\tt 0} except for Layer 2 palettes where it specifies colour priority. If set to {\\tt 1}, then the colour will always be on top, above all other layers, regardless of priority set with \\PortTextXRef{15}. So if you need exactly the same colour with priority and non-priority, you will need to set the same data twice, to different indexes, once with priority bit {\\tt 1} and then with {\\tt 0}.\r\n\r\n% note: register $43 is declared on the same page, therefore we omit page number to keep text more readable\r\nAfter the second write palette colour index in \\PortTextXRef{40} is automatically increment, if auto-increment is enabled in \\PortTextXRef[]{43}.\r\n\r\nNote: reading will always return the second byte of the colour (least significant bit of blue) and will not auto-increment index. You can read {\\tt RRRGGGBB} part with \\PortTextXRef{41}.\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{4A}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-0}\r\n\t\t\\PortDesc{8-bit colour to be used when all layers contain transparent pixel. Format is {\\tt RRRGGGBB}}\r\n\\end{NextPort}\r\n\r\nThis colour is also used for paper and border when ULANext full-ink mode is enabled - see \\PortTextXRef{42}.\r\n\r\n\r\n\\pagebreak\r\n"
  },
  {
    "path": "chapter-next-ports.tex",
    "content": "\\section{Ports and Registers}\r\n\\label{zx_next_ports}\r\n\r\n% ────────────────────────────────────────────────────────────────────────────────\r\n% ─██████████████─██████████████─████████████████───██████████████─██████████████─\r\n% ─██░░░░░░░░░░██─██░░░░░░░░░░██─██░░░░░░░░░░░░██───██░░░░░░░░░░██─██░░░░░░░░░░██─\r\n% ─██░░██████░░██─██░░██████░░██─██░░████████░░██───██████░░██████─██░░██████████─\r\n% ─██░░██──██░░██─██░░██──██░░██─██░░██────██░░██───────██░░██─────██░░██─────────\r\n% ─██░░██████░░██─██░░██──██░░██─██░░████████░░██───────██░░██─────██░░██████████─\r\n% ─██░░░░░░░░░░██─██░░██──██░░██─██░░░░░░░░░░░░██───────██░░██─────██░░░░░░░░░░██─\r\n% ─██░░██████████─██░░██──██░░██─██░░██████░░████───────██░░██─────██████████░░██─\r\n% ─██░░██─────────██░░██──██░░██─██░░██──██░░██─────────██░░██─────────────██░░██─\r\n% ─██░░██─────────██░░██████░░██─██░░██──██░░██████─────██░░██─────██████████░░██─\r\n% ─██░░██─────────██░░░░░░░░░░██─██░░██──██░░░░░░██─────██░░██─────██░░░░░░░░░░██─\r\n% ─██████─────────██████████████─██████──██████████─────██████─────██████████████─\r\n% ────────────────────────────────────────────────────────────────────────────────\r\n\r\n\\newcommand{\\ZXSee}[1]{(see section \\PortXRef{#1})}\r\n\r\n\\subsection{Mapped Spectrum Ports}\r\n\r\n\\begingroup\r\n\t\\newcommand{\\zxport}[4]{\r\n\t\t\\tt {#1} & \r\n\t\t{\\tt \\$#2} & \r\n\t\t\\IfEq{#3}{}{}{\\tt \\%#3} &\r\n\t\t#4\\\\\r\n\t}\r\n\r\n\t\\setlength{\\extrarowheight}{5pt}\t% a bit more spacing between items for clearer visuals\r\n\r\n\t\\begin{tabularx}{\\textwidth}{lllX}\r\n\t\t{\\tt RW} & Addr & Mask & Description \\\\\r\n\t\t\r\n\t\t\\hline\r\n\t\t\r\n\t\t\\zxport{RW}{103B}{0001 0000 0011 1011}{Sets and reads the I2C SCL line}\r\n\t\t\\zxport{RW}{113B}{0001 0001 0011 1011}{Sets and reads the I2C SDA line}\r\n\t\t\\zxport{RW}{123B}{0001 0010 0011 1011}{Enables layer 2 and controls paging of layer 2 screen into lower memory \\ZXSee{123B}}\r\n\t\t\\zxport{RW}{133B}{0001 0011 0011 1011}{Sends byte to serial port. Read tells if data is available in RX buffer}\r\n\t\t\\zxport{RW}{143B}{0001 0100 0011 1011}{Reads data from serial port, write sets the baud rate}\r\n\t\t\\zxport{RW}{153B}{0001 0101 0011 1011}{Configuration of UART interfaces}\r\n\t\t\\zxport{-W}{1FFD}{0001 ---- ---- --0-}{Controls ROM paging and special paging options from the +2a/+3 \\ZXSee{1FFD}}\r\n\t\t\\zxport{RW}{243B}{0010 0100 0011 1011}{Selects active port for TBBlue/Next feature configuration \\ZXSee{243B}}\r\n\t\t\\zxport{RW}{253B}{0010 0101 0011 1011}{Reads and/or writes the selected TBBlue control register \\ZXSee{253B}}\r\n\t\t\\zxport{RW}{303B}{0011 0000 0011 1011}{Sets active sprite-attribute index and pattern-slot index, reads sprite status \\ZXSee{303B}}\r\n\t\t\\zxport{-W}{7FFD}{01-- ---- ---- --0-}{Selects active RAM, ROM, and displayed screen \\ZXSee{7FFD}}\r\n\t\t\\zxport{-W}{BFFD}{10-- ---- ---- --0-}{Writes to the selected register of the selected sound chip \\ZXSee{BFFD}}\r\n\t\t\\zxport{-W}{DFFD}{1101 1111 1111 1101}{Provides additional bank select bits for extended memory \\ZXSee{DFFD}}\r\n\t\t\\zxport{R-}{FADF}{---- ---0 --0- ----}{Reads buttons on Kempston Mouse}\r\n\t\t\\zxport{R-}{FBDF}{---- -0-1 --0- ----}{X coordinate of Kempston Mouse, 0-255}\r\n\t\t\\zxport{R-}{FFDF}{---- -1-1 --0- ----}{Y coordinate of Kempston Mouse, 0-192}\r\n\t\t\\zxport{-W}{FFFD}{11-- ---- ---- --0-}{Controls stereo channels and selects active sound chip and sound chip channel \\ZXSee{FFFD}}\r\n\r\n\t\\end{tabularx}\r\n\r\n\t\\pagebreak\r\n\t\\vspace*{9ex}\r\n\t\\begin{tabularx}{\\textwidth}{lllX}\r\n\t\t{\\tt RW} & Addr & Mask & Description \\\\\r\n\t\t\r\n\t\t\\hline\r\n\r\n\t\t\\zxport{RW}{xx0B}{---- ---- 0000 1011}{Controls Z8410 DMA chip via MB02 standard \\ZXSee{xx0B}}\r\n\t\t\\zxport{R-}{xx1F}{---- ---- 0001 1111}{Reads movement of joysticks using Kempston interface}\r\n\t\t\\zxport{RW}{xx37}{---- ---- ---- ----}{Kempston interface second joystick variant and controls joystick I/O}\r\n\t\t\\zxport{-W}{xx57}{---- ---- 0101 0111}{Uploads sprite positions, visibility, colour type and effect flags \\ZXSee{xx5B}}\r\n\t\t\\zxport{-W}{xx5B}{---- ---- 0101 1011}{Used to upload the pattern of the selected sprite \\ZXSee{xx5B}}\r\n\t\t\\zxport{RW}{xx6B}{---- ---- 0110 1011}{Controls zxnDMA chip \\ZXSee{xx6B}}\r\n\t\t\\zxport{-W}{xxDF}{---- ---- --01 1111}{Output to SpecDrum DAC}\r\n\t\t\\zxport{RW}{xxFE}{xxxx xxxx ---- ---0}{Reading with particular high bytes returns keyboard status \\ZXSee{xxFE}, write changes border colour and base Spectrum audio settings \\ZXSee{xxFEWrite}}\r\n\t\t\\zxport{RW}{xxFF}{---- ---- ---- ----}{Controls Timex Sinclair video modes and colours in hi-res mode. Readable when bit 2 of \\PortTextXRef{08} is set}\r\n\r\n\t\\end{tabularx}\r\n\\endgroup\r\n\r\n\r\n\\pagebreak\r\n\r\n\\subsection{Next/TBBlue Feature Control Registers}\r\n\\label{zx_next_tbblue_registers}\r\n\r\nSpecific features of the Next are controlled via these register numbers, accessed through ports \\PortTextXRef[]{243B} and \\PortTextXRef[]{253B} (see page \\PortPage{243B} for details). All registers can also be written to directly with the {\\tt NEXTREG} instruction.\r\n\r\n\\begingroup\r\n\t\\NewDocumentEnvironment{tbbluereg}{ +b }{\r\n\t\t\\begin{tabularx}{\\textwidth}{llX}\r\n\t\t\t{\\tt RW} & Port & Description \\\\\r\n\t\t\t\\hline\r\n\t\t\t#1\r\n\t\t\\end{tabularx}\r\n\t}{}\r\n\r\n\t\\newcommand{\\nextport}[3]{\r\n\t\t{\\tt #1} & \r\n\t\t{\\tt \\$#2} & \r\n\t\t#3 \\\\\r\n\t}\r\n\r\n\t\\setlength{\\extrarowheight}{2pt}\r\n\r\n\t\\begin{tbbluereg}\r\n\t\t\\nextport{R-}{0}{Identifies TBBlue board type. Should always be {\\tt 10} on Next}\r\n\t\t\\nextport{R-}{1}{Identifies core (FPGA image) version}\r\n\t\t\\nextport{RW}{2}{Identifies type of last reset. Can be written to force reset}\r\n\t\t\\nextport{RW}{3}{Identifies timing and machine type}\r\n\t\t\\nextport{-W}{4}{In config mode, allows RAM to be mapped to ROM area}\r\n\t\t\\nextport{RW}{5}{Sets joystick mode, video frequency and Scandoubler}\r\n\t\t\\nextport{RW}{6}{Enables CPU Speed key, DivMMC, Multiface, Mouse and AY audio \\ZXSee{06}}\r\n\t\t\\nextport{RW}{7}{Sets CPU Speed, reads actual speed}\r\n\t\t\\nextport{RW}{8}{ABC/ACB Stereo, Internal Speaker, SpecDrum, Timex Video Modes, Turbo Sound Next, RAM contention and (un)lock 128k paging \\ZXSee{08}}\r\n\t\t\\nextport{RW}{9}{Sets scanlines, AY mono output, sprite-id lockstep, resets DivMMC mapram and disables HDMI audio \\ZXSee{09}}\r\n\t\t\\nextport{RW}{0A}{Mouse buttons and DPI config}\r\n\t\t\\nextport{R-}{0E}{Identifies core (FPGA image) version (sub minor number)}\r\n\t\t\\nextport{RW}{10}{Used within the Anti-brick system}\r\n\t\t\\nextport{RW}{11}{Sets video output timing variant \\ZXSee{11}}\r\n\t\t\\nextport{RW}{12}{Sets the bank number where Layer 2 video memory begins \\ZXSee{12}}\r\n\t\t\\nextport{RW}{13}{Sets the bank number where the Layer 2 shadow screen begins}\r\n\t\t\\nextport{RW}{14}{Sets the transparent colour for Layer 2, ULA and LoRes pixel data}\r\n\t\t\\nextport{RW}{15}{Enables/disables sprites and Lores Layer, and chooses priority of sprites and Layer 2 \\ZXSee{15}}\r\n\t\t\\nextport{RW}{16}{Sets X pixel offset used for drawing Layer 2 graphics on the screen \\ZXSee{16}}\r\n\t\t\\nextport{RW}{17}{Sets Y offset used when drawing Layer 2 graphics on the screen \\ZXSee{17}}\r\n\t\t\\nextport{RW}{18}{Sets and reads clip-window for Layer 2 \\ZXSee{18}}\r\n\t\t\\nextport{RW}{19}{Sets and reads clip-window for Sprites \\ZXSee{19}}\r\n\t\t\\nextport{RW}{1A}{Sets and reads clip-window for ULA/LoRes layer}\r\n\t\t\\nextport{RW}{1B}{Sets and reads clip-window for Tilemap \\ZXSee{1B}}\r\n\t\t\\nextport{RW}{1C}{Controls (resets) the clip-window registers indices \\ZXSee{1C}}\r\n\t\t\\nextport{R-}{1E}{Holds the MSB of the raster line currently being drawn}\r\n\t\t\\nextport{R-}{1F}{Holds the eight LSBs of the raster line currently being drawn}\r\n\t\\end{tbbluereg}\r\n\r\n\t\\pagebreak\r\n\r\n\t\\vspace*{11.8ex}\t% this aligns content with previous page vertically\r\n\t\\begin{tbbluereg}\r\n\t\t\\nextport{RW}{22}{Controls the timing of raster interrupts and the ULA frame interrupt \\ZXSee{22}}\r\n\t\t\\nextport{RW}{23}{Holds the eight LSBs of the line on which a raster interrupt should occur \\ZXSee{23}}\r\n\t\t\\nextport{RW}{26}{Pixel X offset ({\\tt 0-255}) to use when drawing ULA Layer}\r\n\t\t\\nextport{RW}{27}{Pixel Y offset ({\\tt 0-191}) to use when drawing ULA Layer}\r\n\t\t\\nextport{RW}{28}{PS/2 Keymap address MSB, read (pending) first byte of palette colour}\r\n\t\t\\nextport{-W}{29}{PS/2 Keymap address LSB}\r\n\t\t\\nextport{-W}{2A}{High data to PS/2 Keymap (MSB of data in bit 0)}\r\n\t\t\\nextport{-W}{2B}{Low eight LSBs of PS/2 Keymap data}\r\n\t\t\\nextport{RW}{2C}{DAC B mirror, read current I2S left MSB}\r\n\t\t\\nextport{RW}{2D}{SpecDrum port 0xDF / DAC A+D mirror, read current I2S LSB}\r\n\t\t\\nextport{RW}{2E}{DAC C mirror, read current I2S right MSB}\r\n\t\t\\nextport{RW}{2F}{Sets the pixel offset (two high bits) used for drawing Tilemap graphics on the screen \\ZXSee{2F}}\r\n\t\t\\nextport{RW}{30}{Sets the pixel offset (eight low bits) used for drawing Tilemap graphics on the screen \\ZXSee{30}}\r\n\t\t\\nextport{RW}{31}{Sets the pixel offset used for drawing Tilemap graphics on the screen \\ZXSee{31}}\r\n\t\t\\nextport{RW}{32}{Pixel X offset ({\\tt 0-255}) to use when drawing LoRes Layer}\r\n\t\t\\nextport{RW}{33}{Pixel Y offset ({\\tt 0-191}) to use when drawing LoRes Layer}\r\n\t\t\\nextport{RW}{34}{Selects sprite index {\\tt 0-127} to be affected by writes to other Sprite ports (and mirrors) \\ZXSee{34}}\r\n\t\t\\nextport{-W}{35}{Writes directly into byte 1 of port \\PortAddr{xx57}~\\ZXSee{35}}\r\n\t\t\\nextport{-W}{36}{Writes directly into byte 2 of port \\PortAddr{xx57}~\\ZXSee{36}}\r\n\t\t\\nextport{-W}{37}{Writes directly into byte 3 of port \\PortAddr{xx57}~\\ZXSee{37}}\r\n\t\t\\nextport{-W}{38}{Writes directly into byte 4 of port \\PortAddr{xx57}~\\ZXSee{38}}\r\n\t\t\\nextport{-W}{39}{Writes directly into byte 5 of port \\PortAddr{xx57}~\\ZXSee{39}}\r\n\t\t\\nextport{RW}{40}{Chooses a palette element (index) to manipulate with \\ZXSee{40}}\r\n\t\t\\nextport{RW}{41}{Use to set/read 8-bit colours of the ULANext palette \\ZXSee{41}}\r\n\t\t\\nextport{RW}{42}{Specifies mask to extract ink colour from attribute cell value in ULANext mode}\r\n\t\t\\nextport{RW}{43}{Enables or disables Enhanced ULA interpretation of attribute values and toggles active palette \\ZXSee{43}}\r\n\t\t\\nextport{RW}{44}{Sets 9-bit (2-byte) colours of the Enhanced ULA palette, or to read second byte of colour \\ZXSee{44}}\r\n\t\\end{tbbluereg}\r\n\r\n\t\\pagebreak\r\n\r\n\t\\begin{tbbluereg}\r\n\t\t\\nextport{RW}{4A}{8-bit colour to be used when all layers contain transparent pixel \\ZXSee{4A}}\r\n\t\t\\nextport{RW}{4B}{Index of transparent colour in sprite palette \\ZXSee{4B}}\r\n\t\t\\nextport{RW}{4C}{Index of transparent colour in Tilemap palette \\ZXSee{4C}}\r\n\t\t\\nextport{RW}{50}{Selects the 8k-bank stored in 8k-slot 0 \\ZXSee{50}}\r\n\t\t\\nextport{RW}{51}{Selects the 8k-bank stored in 8k-slot 1 \\ZXSee{51}}\r\n\t\t\\nextport{RW}{52}{Selects the 8k-bank stored in 8k-slot 2 \\ZXSee{52}}\r\n\t\t\\nextport{RW}{53}{Selects the 8k-bank stored in 8k-slot 3 \\ZXSee{53}}\r\n\t\t\\nextport{RW}{54}{Selects the 8k-bank stored in 8k-slot 4 \\ZXSee{54}}\r\n\t\t\\nextport{RW}{55}{Selects the 8k-bank stored in 8k-slot 5 \\ZXSee{55}}\r\n\t\t\\nextport{RW}{56}{Selects the 8k-bank stored in 8k-slot 6 \\ZXSee{56}}\r\n\t\t\\nextport{RW}{57}{Selects the 8k-bank stored in 8k-slot 7 \\ZXSee{57}}\r\n\t\t\\nextport{-W}{60}{Used to upload code to the Copper \\ZXSee{60}}\r\n\t\t\\nextport{RW}{61}{Holds low byte of Copper control bits \\ZXSee{61}}\r\n\t\t\\nextport{RW}{62}{Holds high byte of Copper control flags \\ZXSee{62}}\r\n\t\t\\nextport{-W}{63}{Used to upload code to the Copper in 16-bit chunks \\ZXSee{63}}\r\n\t\t\\nextport{RW}{64}{Offset numbering of raster lines in copper/interrupt/active register \\ZXSee{64}}\r\n\t\t\\nextport{RW}{68}{Disable ULA, controls ULA mixing/blending, enable ULA+ \\ZXSee{68}}\r\n\t\t\\nextport{RW}{69}{Layer2, ULA shadow, Timex \\MemAddr{FF} port \\ZXSee{69}}\r\n\t\t\\nextport{RW}{6A}{LoRes Radastan mode}\r\n\t\t\\nextport{RW}{6B}{Controls Tilemap mode \\ZXSee{6B}}\r\n\t\t\\nextport{RW}{6C}{Default tile attribute for 8-bit only maps \\ZXSee{6C}}\r\n\t\t\\nextport{RW}{6E}{Base address of the 40x32 or 80x32 tile map \\ZXSee{6E}}\r\n\t\t\\nextport{RW}{6F}{Base address of the tiles' graphics \\ZXSee{6F}}\r\n\t\t\\nextport{RW}{70}{Layer 2 resolution, palette offset \\ZXSee{70}}\r\n\t\t\\nextport{RW}{71}{Sets pixel offset for drawing Layer 2 graphics on the screen \\ZXSee{61}}\r\n\t\t\\nextport{-W}{75}{Same as register \\PortAddr{35}~plus increments \\PortAddr{34}~\\ZXSee{75}}\r\n\t\t\\nextport{-W}{76}{Same as register \\PortAddr{36}~plus increments \\PortAddr{34}~\\ZXSee{76}}\r\n\t\t\\nextport{-W}{77}{Same as register \\PortAddr{37}~plus increments \\PortAddr{34}~\\ZXSee{77}}\r\n\t\t\\nextport{-W}{78}{Same as register \\PortAddr{38}~plus increments \\PortAddr{34}~\\ZXSee{78}}\r\n\t\t\\nextport{-W}{79}{Same as register \\PortAddr{39}~plus increments \\PortAddr{34}~\\ZXSee{79}}\r\n\t\t\\nextport{RW}{7F}{8-bit storage for user}\r\n\t\t\\nextport{RW}{80}{Expansion bus enable/config}\r\n\t\t\\nextport{RW}{81}{Expansion bus controls}\r\n\t\t\\end{tbbluereg}\r\n\r\n\t\\pagebreak\r\n\r\n\t\\begin{tbbluereg}\r\n\t\t\\nextport{RW}{82}{Enabling internal ports decoding bits 0-7 register}\r\n\t\t\\nextport{RW}{83}{Enabling internal ports decoding bits 8-15 register}\r\n\t\t\\nextport{RW}{84}{Enabling internal ports decoding bits 16-23 register}\r\n\t\t\\nextport{RW}{85}{Enabling internal ports decoding bits 24-31 register}\r\n\t\t\\nextport{RW}{86}{When expansion bus is enabled: internal ports decoding mask bits 0-7}\r\n\t\t\\nextport{RW}{87}{When expansion bus is enabled: internal ports decoding mask bits 8-15}\r\n\t\t\\nextport{RW}{88}{When expansion bus is enabled: internal ports decoding mask bits 16-23}\r\n\t\t\\nextport{RW}{89}{When expansion bus is enabled: internal ports decoding mask bits 24-31}\r\n\t\t\\nextport{RW}{8A}{Monitoring internal I/O or adding external keyboard}\r\n\t\t\\nextport{RW}{8C}{Enable alternate ROM or lock 48k ROM}\r\n\t\t\\nextport{RW}{8E}{Control classic Spectrum memory mapping}\r\n\t\t\\nextport{RW}{90-93}{Enables GPIO pins output}\r\n\t\t\\nextport{RW}{98-9B}{GPIO pins mapped to Next Register}\r\n\t\t\\nextport{RW}{A0}{Enable Pi peripherals: UART, Pi hats, I2C, SPI}\r\n\t\t\\nextport{RW}{A2}{Pi I2S controls}\r\n\t\t\\nextport{RW}{A3}{Pi I2S clock divide in master mode}\r\n\t\t\\nextport{RW}{A8}{ESP WiFi GPIO output}\r\n\t\t\\nextport{RW}{A9}{ESP WiFi GPIO read/write}\r\n\t\t\\nextport{R-}{B0}{Read Next keyboard compound keys separately \\ZXSee{B0}}\r\n\t\t\\nextport{R-}{B1}{Read Next keyboard compound keys separately \\ZXSee{B1}}\r\n\t\t\\nextport{RW}{B2}{DivMMC trap configuration}\r\n\t\t\\nextport{RW}{B4}{DivMMC trap configuration}\r\n\t\t\\nextport{RW}{C0}{Interrupt Control \\ZXSee{C0}}\r\n\t\t\\nextport{RW}{C2}{NMI Return Address LSB \\ZXSee{C2}}\r\n\t\t\\nextport{RW}{C3}{NMI Return Address MSB \\ZXSee{C3}}\r\n\t\t\\nextport{RW}{C4}{Interrupt Enable 0 \\ZXSee{C4}}\r\n\t\t\\nextport{RW}{C5}{Interrupt Enable 1 \\ZXSee{C5}}\r\n\t\t\\nextport{RW}{C6}{Interrupt Enable 2 \\ZXSee{C6}}\r\n\t\t\\nextport{RW}{C8}{Interrupt Status 0 \\ZXSee{C8}}\r\n\t\t\\nextport{RW}{C9}{Interrupt Status 1 \\ZXSee{C9}}\r\n\t\t\\nextport{RW}{CA}{Interrupt Status 2 \\ZXSee{CA}}\r\n\t\t\\nextport{RW}{CC}{DMA Interrupt Enable 0 \\ZXSee{CC}}\r\n\t\t\\nextport{RW}{CD}{DMA Interrupt Enable 1 \\ZXSee{CD}}\r\n\t\t\\nextport{RW}{CE}{DMA Interrupt Enable 2 \\ZXSee{CE}}\r\n\t\t\\nextport{-W}{FF}{Turns debug LEDs on and off on TBBlue implementations that have them}\r\n\t\\end{tbbluereg}\r\n\\endgroup\r\n\r\n\r\n\\pagebreak\r\n\r\n\\subsection{Accessing Registers}\r\n\\label{zx_next_ports_examples}\r\n\r\n% note: this section results in full 2 pages (there's 1 paragraph available in first 2 sub sections); if adding substantial text make sure it still fits 2 pages! If not possible otherwise, space can be found by combining more Next registers in tables above - so that they fill full pages, and then continuing directly with this subsection, without pagebreak... Current layout is nice though - left page describes read/write to Spectrum ports, right one for Next registers...\r\n\r\n\\subsubsection{Writing to Spectrum Ports}\r\n\r\nWhen writing to one of the lower 256 ports, {\\tt OUT (n),A} instruction is used. For example to write the value of {\\tt 43} to peripheral device mapped to port \\MemAddr{15}:\r\n\r\n\\begin{tcblisting}{}\r\n\tLD A, 43            ; we want to write 43\r\n\tOUT (&15), A        ; writes value of A to port &15\r\n\\end{tcblisting}\r\n\r\nTo write using full 16-bit address, {\\tt OUT (C),r} instruction is used instead. Example of writing a byte to serial port using \\PortText{133B}:\r\n\r\n\\begin{tcblisting}{}\r\n\tLD A, 42            ; we want to write 42\r\n\tLD BC, &133B        ; we want to write to port &133B\r\n\tOUT (C), A\r\n\\end{tcblisting}\r\n\r\nThe difference between the two speed-wise is tangible: first example requires only 18 t-states (7+11) while second 29 (7+10+12).\r\n\r\n\r\n\\subsubsection{Reading from Spectrum Ports}\r\n\r\nReading also uses the same approach as on original Spectrums - for the lower 256 ports {\\tt IN A,(n)} is used. For example reading a byte from port \\MemAddr{15}:\r\n\r\n\\begin{tcblisting}{}\r\n\tLD A, 0       ; perhaps not strictly required, but good idea\r\n\tIN A, (&15)   ; read byte from port &15 to A\r\n\\end{tcblisting}\r\n\r\nNote how the accumulator {\\tt A} is cleared before accessing the port. With {\\tt IN A,(n)}, the 16-bit address is composed from {\\tt A} forming high byte and {\\tt n} low byte.\r\n\r\nLet's see how we can use this for reading from 16-bit ports - we have two options: we can either use {\\tt IN A,(n)} or {\\tt IN r,(C)}. Example of both, reading a byte from serial port:\r\n\r\n\\begin{multicols}{2}\r\n\t\\begin{tcblisting}{right skip=1em}\r\nLD BC, &143B   ; read &143B port\r\nIN A, (C)      ; read byte to A\r\n\t\\end{tcblisting}\r\n\r\n\t\\columnbreak\r\n\r\n\t\\begin{tcblisting}{}\r\nLD A, &14      ; high byte\r\nIN A, (&3B)    ; read byte to A\r\n\t\\end{tcblisting}\r\n\\end{multicols}\r\n\r\n\\vspace*{-0.7em} % multicols creates additional space below, we want next text to be closer up...\r\nBoth have the same result. The difference speed-wise is 22 t-states (10+12) vs 18 (7+11). Not by a lot, but it may add up if used frequently. However, the intent of the first code is clearer as the port address is provided in full instead of being split between two instructions.\r\n\r\nThis example nicely demonstrates a common dilemma when programming: frequently we can have readable but not as optimal code, or vice versa. But I also thought this was worth pointing out to avoid possible confusion in case you will encounter different ways in someone else's code.\r\n\r\n\r\n\\subsubsection{Writing to Next registers}\r\n% note: at the moment we don't have ports 243B and 253B declared elsewhere, so we label them here; this was cross references will lead to this place. Since this **IS** the declaration, we don't use XRefs when mentioning both ports below.\r\n\\label{\\PortReference{243B}}\r\n\\label{\\PortReference{253B}}\r\n\r\nWriting values to Next/TBBlue registers occurs through \\PortText{243B}~and \\PortText{253B}~ports. It's composed from 2 steps: first we select the register via write to port \\MemAddr{243B}, then write the value through port \\MemAddr{253B}. For example writing value of {\\tt 5} to Next register \\MemAddr{16}:\r\n\r\n\\begin{multicols}{2}\r\n\t\\begin{tcblisting}{right skip=1em}\r\nLD A, &16      ; register &16\r\nLD BC, &243B   ; port &243B\r\nOUT (C), A\r\n\r\nLD A, 5        ; write 5\r\nLD BC, &253B   ; to port &254B\r\nOUT (C), A\r\n\t\\end{tcblisting}\r\n\r\n\t\\columnbreak\r\n\r\n\t\\begin{tcblisting}{}\r\nLD A, &16      ; register &16\r\nLD BC, &243B   ; port &243B\r\nOUT (C), A\r\n\r\nLD A, 5        ; write 5\r\nINC B          ; to port &253B\r\nOUT (C), A\t\r\n\t\\end{tcblisting}\r\n\r\n\\end{multicols}\r\n\r\n\\vspace*{-0.7em} % multicols creates additional space below, we want next text to be closer up...\r\nQuite involving, isn't it? Speed-wise, first example requires 58 t-states ((7+10+12)$\\times$2) and second 6 t-states less: 52 ((7+10+12)+(7+4+12)).\r\n\r\nThe second code relies on the fact that the only difference between two port addresses is the high byte (\\MemAddr{24} vs \\MemAddr{25}). So given we already assigned \\MemAddr{243B} to {\\tt BC}, we can simply increment {\\tt B} to get \\MemAddr{253B}. Again, the intent of the first example is clearer. And again, I thought it was worth pointing out in case you will encounter both approaches and wonder...\r\n\r\nHowever, we can do better. Much better, in fact, using Next {\\tt NEXTREG} instruction, which allows direct writes to given Next registers. So above examples could simply be changed to either:\r\n\r\n\\begin{multicols}{2}\r\n\t\\begin{tcblisting}{{right skip=1em}}\r\nLD A, 5          ; write 5\r\nNEXTREG &16, A  ; to reg &16\r\n\t\\end{tcblisting}\r\n\r\n\t\\columnbreak\r\n\r\n\t\\begin{tcblisting}{}\r\nNEXTREG &16, 5 ; write 5 to reg &16\r\n\t\\end{tcblisting}\r\n\\end{multicols}\r\n\r\n\\vspace*{-0.7em} % multicols creates additional space below, we want next text to be closer up...\r\nThe first example requires 24 t-states (7+17) while the second 20. So less than half compared to using ports. In fact, using {\\tt NEXTREG} is the preferred method of writing to Next registers!\r\n\r\n\r\n\\subsubsection{Reading from Next Registers}\r\n\r\nReading values from Next/TBBlue registers also occurs through \\MemAddr{243B} and \\MemAddr{253B} ports. Similar to write, read is also composed from 2 steps: first select the register with port \\MemAddr{243B}, then read the value from port \\MemAddr{253B}. For example reading a byte from Next register \\MemAddr{B0}:\r\n\r\n\\begin{multicols}{2}\r\n\r\n\t\\begin{tcblisting}{right skip=1em}\r\nLD A, &16      ; register &16\r\nLD BC, &243B   ; port &243B\r\nOUT (C), A     ; set port\r\n\r\nLD BC, &253B   ; port &253B\r\nIN A, (C)      ; read to A\r\n\t\\end{tcblisting}\r\n\r\n\t\\columnbreak\r\n\t\r\n\t\\begin{tcblisting}{}\r\nLD A, &16      ; register &16\r\nLD BC, &243B   ; port &243B\r\nOUT (C), A     ; set port\r\n\r\nINC B          ; port &253B\r\nIN A, (C)      ; read to A\r\n\t\\end{tcblisting}\r\n\t\t\r\n\\end{multicols}\r\n\r\n\\vspace*{-0.7em} % multicols creates additional space below, we want next text to be closer up...\r\nThe difference is small: 51 t-states ((7+10+12)+(10+12)) vs 45 ((7+10+12)+(4+12)). \r\n\r\nUnfortunately, we don't have faster means of reading Next registers directly as we do for writing; there is no {\\tt NEXTREG} alternative for reads.\r\n\r\n\r\n\\pagebreak"
  },
  {
    "path": "chapter-next-sound.tex",
    "content": "\\section{Sound}\r\n\\label{zx_next_sound}\r\n\r\n% ────────────────────────────────────────────────────────────────────────────────────\r\n% ─██████████████─██████████████─██████──██████─██████──────────██████─████████████───\r\n% ─██░░░░░░░░░░██─██░░░░░░░░░░██─██░░██──██░░██─██░░██████████──██░░██─██░░░░░░░░████─\r\n% ─██░░██████████─██░░██████░░██─██░░██──██░░██─██░░░░░░░░░░██──██░░██─██░░████░░░░██─\r\n% ─██░░██─────────██░░██──██░░██─██░░██──██░░██─██░░██████░░██──██░░██─██░░██──██░░██─\r\n% ─██░░██████████─██░░██──██░░██─██░░██──██░░██─██░░██──██░░██──██░░██─██░░██──██░░██─\r\n% ─██░░░░░░░░░░██─██░░██──██░░██─██░░██──██░░██─██░░██──██░░██──██░░██─██░░██──██░░██─\r\n% ─██████████░░██─██░░██──██░░██─██░░██──██░░██─██░░██──██░░██──██░░██─██░░██──██░░██─\r\n% ─────────██░░██─██░░██──██░░██─██░░██──██░░██─██░░██──██░░██████░░██─██░░██──██░░██─\r\n% ─██████████░░██─██░░██████░░██─██░░██████░░██─██░░██──██░░░░░░░░░░██─██░░████░░░░██─\r\n% ─██░░░░░░░░░░██─██░░░░░░░░░░██─██░░░░░░░░░░██─██░░██──██████████░░██─██░░░░░░░░████─\r\n% ─██████████████─██████████████─██████████████─██████──────────██████─████████████───\r\n% ────────────────────────────────────────────────────────────────────────────────────\r\n\r\nNext inherits the same 3 AY-3-8912 chips setup as used in 128K Spectrums. This allows us to reuse many of the pre-existing applications and routines to play sound effects and music.\r\n\r\n\\subsection{AY Chip Registers}\r\n\r\nAY chip has 3 sound channels, called A, B and C. Combined with 3 chips, this allows us to produce 9 channel music. Programming wise, each of the 3 chips needs to be selected first via \\PortTextXRef{FFFD} register. Afterwards, we can set various parameters through \\PortTextXRef{08} and \\PortTextXRef{09} registers.\r\n\r\nAY chip is controlled by 14 internal registers. To program them, we first need to select the register with \\PortTextXRef{FFFD} and then write the value with \\PortTextXRef{BFFD}.\r\n\r\n\r\n\\subsection{Editing and Players}\r\n\r\nSeveral applications can produce sounds or music compatible with the AY chip. For sounds, Shiru's AYFX Player\\footnote{\\url{https://shiru.untergrund.net/software.shtml\\#old}} can be used. This program also includes a Z80 native player that can directly load and play sound effects. Alternatively, Remy's AY audio generator website\\footnote{\\url{https://zx.remysharp.com/audio/}} can produce exactly the same results and is fully compatible with AYFX Player.\r\n\r\nA different way of playing sounds is to convert the WAV file into 1, 2 or 4-bit per sample sound with the ChibiWave application. Sounds take a bit more memory this way but are much easier to create. You can find the application, as well as tutorial and playback source code on Chibi Akumas website\\footnote{\\url{https://www.chibiakumas.com/z80/platform4.php\\#LessonP35}}. While there, definitely check other tutorials too - they're all high quality and available as both, written posts and YouTube videos.\r\n\r\nFor creating music there are also several options. NextDAW\\footnote{\\url{https://nextdaw.biasillo.com/}} is native composer that runs on ZX Spectrum Next itself. Or if you prefer cross-platform, Arkos Tracker\\footnote{\\url{https://www.julien-nevo.com/arkostracker/}} or Vortex Tracker\\footnote{\\url{https://bulba.untergrund.net/vortex_e.htm}} should do the job. All include ``drivers''; Z80 code you can include in your program that can load and play created music.\r\n\r\n\r\n\\pagebreak\r\n\\subsection{Examples}\r\n\r\nBefore we can start playing sounds, we need to enable the sound hardware. While this is usually enabled by default, it's nonetheless a good idea to ensure our program will always run under the same conditions.\r\n\r\n\\begin{tcblisting}{}\r\n\t; Setup Turbo Sound chip\r\n\tLD BC, &FFFD            ; Turbo Sound Next Control Register\r\n\tLD A, %11111101         ; Enable left+right audio, select AY2\r\n\tOUT (C), A\r\n\t\r\n\t; Setup mapping of chip channels to stereo channels\r\n\tNEXTREG &08, %00010010  ; Use ABC, enable internal speaker & turbosound\r\n\tNEXTREG &09, %11100000  ; Enable mono for AY0-2\r\n\\end{tcblisting}\r\n\r\nProgramming AY consists of writing various values to its registers. As mentioned, this is a two-step process: first select register number, then write the value. Multiple writes are required for each tone to set period, volume etc. To make it simpler, I created a subroutine. It takes 2 parameters: {\\tt A} for register number ({\\tt 0-13}) and {\\tt D} with value to write.\r\n\r\n\\begin{tcblisting}{}\r\nWriteDToAYReg:\r\n\t; Select desired register\r\n\tLD BC, &FFFD\r\n\tOUT (C), A\r\n\t\r\n\t; Write given value\r\n\tLD A, D\r\n\tLD BC, &BFFD\r\n\tOUT (C), A\r\n\t\r\n\tRET\r\n\\end{tcblisting}\r\n\r\nCompanion code on GitHub, folder {\\tt sound} includes expanded code as well as a simple player that plays multiple tones in sequence. For the purposes of this book, I used Remy's AY audio generator website to load one of the example effects, then manually copied raw values into the source code. Laborious process to say the least - this is not how effects should be handled in real life. But I wanted to learn and demonstrate how to program AY chip, not how to use ready-made drivers to play effects or music. Furthermore, my ``player'' blocks the main loop; ideally, sound effects and music would play on the interrupt handler. This could be a nice homework for the reader - example in section \\XRef{zx_next_interrupts} should give you an idea of how to achieve this - happy coding!\r\n\r\n\r\n\\pagebreak\r\n\\subsection{Sound Ports and Registers}\r\n\\label{zx_next_sound_registers}\r\n\r\n\\subsubsection{\\PortDeclaration{FFFD}}\r\n\r\nWhen bit {\\tt 7} is {\\tt 1}:\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7}\r\n\t\t\\PortDesc{{\\tt 1}}\r\n\t\\PortBits{6}\r\n\t\t\\PortDesc{{\\tt 1} to enable left audio}\r\n\t\\PortBits{5}\r\n\t\t\\PortDesc{{\\tt 1} to enable right audio}\r\n\t\\PortBits{4-2}\r\n\t\t\\PortDesc{Must be {\\tt 1}}\r\n\t\\PortBits{1-0}\r\n\t\t\\PortDesc{Selects active chip:}\r\n\t\t\\PortDescOnly{\r\n\t\t\t\\begin{PortBitConfig}\r\n\t\t\t\t\\PortBitLine{00}{Unused}\r\n\t\t\t\t\\PortBitLine{01}{AY2}\r\n\t\t\t\t\\PortBitLine{10}{AY1}\r\n\t\t\t\t\\PortBitLine{11}{AY0}\r\n\t\t\t\\end{PortBitConfig}\r\n\t\t}\r\n\\end{NextPort}\r\n\r\nWhen bit {\\tt 7} is {\\tt 0}:\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7}\r\n\t\t\\PortDesc{{\\tt 0}}\r\n\t\\PortBits{6-0}\r\n\t\t\\PortDesc{Selects given AY register number for read or write from active sound chip} \r\n\\end{NextPort}\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{BFFD}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-0}\r\n\t\t\\PortDesc{Writes given value to currently selected register:}\r\n\\end{NextPort}\r\n\r\n\\begingroup\r\n\t\\small\r\n\t\\vspace*{8pt}\t\t\t\t\t% some vertical spacing between port table and this sectino\r\n\t\\setlength{\\leftskip}{1.25cm}\t% Setup left margin as if this whole section was within port table (tried adding it there but got syntax errors)\r\n\r\n\t\\newcommand{\\AYRegTitle}[1]{\r\n\t\t\\subsubsection{#1}\r\n\t\t\\vspace*{-1ex}\r\n\t}\r\n\r\n\t\\begin{multicols}{2}\r\n\t\t\\AYRegTitle{0 - Channel A tone, low byte}\r\n\t\t\\begin{BitTableByte}\r\n\t\t\t\\BitStartMulti{8}{A tone} \\\\\r\n\t\t\\end{BitTableByte}\r\n\t\t\r\n\t\t\\AYRegTitle{1 - Channel A tone, high 4-bits}\r\n\t\t\\begin{BitTableByte}\r\n\t\t\t\\BitMono{0} & \\BitMono{0} & \\BitMono{0} & \\BitMono{0} & \\BitMulti{4}{A tone high} \\\\\r\n\t\t\\end{BitTableByte}\t\t\r\n\t\\end{multicols}\r\n\r\n\t\\begin{multicols}{2}\r\n\t\t\\AYRegTitle{2 - Channel B tone, low byte}\r\n\t\t\\begin{BitTableByte}\r\n\t\t\t\\BitStartMulti{8}{B tone} \\\\\r\n\t\t\\end{BitTableByte}\r\n\r\n\t\t\\AYRegTitle{3 - Channel B tone, high 4-bits}\r\n\t\t\\begin{BitTableByte}\r\n\t\t\t\\BitMono{0} & \\BitMono{0} & \\BitMono{0} & \\BitMono{0} & \\BitMulti{4}{B tone high} \\\\\r\n\t\t\\end{BitTableByte}\r\n\t\\end{multicols}\r\n\r\n\t\\begin{multicols}{2}\r\n\t\t\\AYRegTitle{4 - Channel C tone, low byte}\r\n\t\t\\begin{BitTableByte}\r\n\t\t\t\\BitStartMulti{8}{C tone} \\\\\r\n\t\t\\end{BitTableByte}\r\n\r\n\t\t\\AYRegTitle{5 - Channel C tone, high 4-bits}\r\n\t\t\\begin{BitTableByte}\r\n\t\t\t\\BitMono{0} & \\BitMono{0} & \\BitMono{0} & \\BitMono{0} & \\BitMulti{4}{C tone high} \\\\\r\n\t\t\\end{BitTableByte}\r\n\t\\end{multicols}\r\n\r\n\t\\pagebreak\r\n\t\\begin{multicols}{2}\r\n\t\t\\AYRegTitle{6 - Noise period}\r\n\t\t\\begin{BitTableByte}\r\n\t\t\t\\BitMono{0} & \\BitMono{0} & \\BitMono{0} & \\BitMulti{5}{Noise Period} \\\\\r\n\t\t\\end{BitTableByte}\r\n\t\t\\leavevmode\t% for some reason new line \\\\ doesn't work here with BitTableByte/ElegantTable\r\n\r\n\t\t\\columnbreak\r\n\r\n\t\t\\AYRegTitle{7 - Flags}\r\n\t\t\\begin{BitTableByte}\r\n\t\t\t\\BitMono{0} & \\BitMono{0} & \\BitMono{C} & \\BitMono{B} & \\BitMono{A} & \\BitMono{C} & \\BitMono{B} & \\BitMono{A} \\\\\r\n\t\t\t\\hline\r\n\t\t\t\\BitMono{0} & \\BitMono{0} & \\BitMulti{3}{Noise} & \\BitMulti{3}{Tone} \\\\\r\n\t\t\\end{BitTableByte}\r\n\t\\end{multicols}\r\n\r\n\t\\begin{multicols}{2}\r\n\t\t\\AYRegTitle{8 - Channel A volume/envelope}\r\n\t\t\\begin{BitTableByte}\r\n\t\t\t\\BitMono{0} & \\BitMono{0} & \\BitMono{0} & \\BitMono{0} & \\BitMulti{4}{A Volume} \\\\\r\n\t\t\\end{BitTableByte}\r\n\r\n\t\t\\AYRegTitle{9 - Channel B volume/envelope}\r\n\t\t\\begin{BitTableByte}\r\n\t\t\t\\BitMono{0} & \\BitMono{0} & \\BitMono{0} & \\BitMono{0} & \\BitMulti{4}{B Volume} \\\\\r\n\t\t\\end{BitTableByte}\r\n\t\\end{multicols}\r\n\r\n\t\\begin{multicols}{2}\r\n\t\t\\AYRegTitle{10 - Channel C volume/envelope}\r\n\t\t\\begin{BitTableByte}\r\n\t\t\t\\BitMono{0} & \\BitMono{0} & \\BitMono{0} & \\BitMono{0} & \\BitMulti{4}{C Volume} \\\\\r\n\t\t\\end{BitTableByte}\r\n\r\n\t\t\\columnbreak\r\n\r\n\t\t\\textbf{Note:} Registers {\\tt 8-10} work as volume control if bit {\\tt 4} is {\\tt 0}, otherwise envelop generator is\r\n\t\tused (see registers {\\tt 11-13}). In this case bits {\\tt 3-0} are ignored.\r\n\t\\end{multicols}\r\n\r\n\t\\begin{multicols}{2}\r\n\t\t\\AYRegTitle{11 - Envelope period fine}\r\n\t\t\\begin{BitTableByte}\r\n\t\t\t\\BitStartMulti{8}{Envelope bits 7-0} \\\\\r\n\t\t\\end{BitTableByte}\r\n\r\n\t\t\\AYRegTitle{12 - Envelope period coarse}\r\n\t\t\\begin{BitTableByte}\r\n\t\t\t\\BitStartMulti{8}{Envelope bits 15-8} \\\\\r\n\t\t\\end{BitTableByte}\r\n\t\\end{multicols}\r\n\r\n\t\\begin{multicols}{2}\r\n\t\t\\AYRegTitle{13 - Envelope shape}\r\n\t\t\\begin{BitTableByte}\r\n\t\t\t\\BitMono{0} & \\BitMono{0} & \\BitMono{0} & \\BitMono{0} & \\BitMono{$C$} & \\BitMono{$A_t$} & \\BitMono{$A_l$} & \\BitMono{$H$} \\\\\r\n\t\t\\end{BitTableByte}\r\n\t\\end{multicols}\r\n\r\n\t\\hspace*{1.3cm}\r\n\t\\begin{tabular}{lllp{18cm}}\r\n\t\t$H$ & \\multicolumn{3}{l}{``Hold''} \\\\\r\n\t\t\t& {\\tt 1} & \\multicolumn{2}{p{10cm}}{envelope generator performs 1 cycle then holds the end value} \\\\\r\n\t\t\t& {\\tt 0} & \\multicolumn{2}{p{10cm}}{cycles continuously} \\\\\r\n\r\n\t\t$A_l$ & \\multicolumn{3}{l}{``Alternate''} \\\\\r\n\t\t\t& \\multicolumn{3}{l}{If ``hold'' set} \\\\\r\n\t\t\t& & {\\tt 1} & the value held is initial value \\\\\r\n\t\t\t& & {\\tt 0} & the value held is the final value \\\\\r\n\t\t\t& \\multicolumn{3}{l}{If ``hold'' not set} \\\\\r\n\t\t\t& & {\\tt 1} & envelope generator alters direction after each cycle \\\\\r\n\t\t\t& & {\\tt 0} & resets after each cycle \\\\\r\n\r\n\t\t$A_t$ & \\multicolumn{3}{l}{``Attack''} \\\\\r\n\t\t\t& {\\tt 1} & \\multicolumn{2}{l}{the generator counts up} \\\\\r\n\t\t\t& {\\tt 0} & \\multicolumn{2}{l}{the generator counts down} \\\\\r\n\r\n\t\t$C$ & \\multicolumn{3}{l}{``Continue''} \\\\\r\n\t\t\t& {\\tt 1} & \\multicolumn{2}{l}{``hold'' is followed} \\\\\r\n\t\t\t& {\\tt 0} & \\multicolumn{2}{p{12cm}}{the envelope generator performs one cycle then drops volume to 0 and stays there, overriding ``hold''} \\\\\r\n\t\\end{tabular}\r\n\\endgroup\r\n\r\n\\subsubsection{\\PortDeclaration{06}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7}\r\n\t\t\\PortDesc{{\\tt 1} to enable CPU speed mode key \"F8\", {\\tt 0} to disable ({\\tt 1} after soft reset)}\r\n\t\\PortBits{6}\r\n\t\t\\PortDesc{Core 3.1.2+: Divert BEEP-only to internal speaker ({\\tt 0} after hard reset)}\r\n\t\t\\PortDescOnly{Pre core 3.1.2: DMA mode, {\\tt 0} zxnDMA, {\\tt 1} Z80 DMA ({\\tt 0} after hard reset)}\r\n\t\\PortBits{5}\r\n\t\t\\PortDesc{Core 2.0+: {\\tt 1} to enable \"F3\" key (50/60 Hz switch) ({\\tt 1} after soft reset)}\r\n\t\t\\PortDescOnly{Pre core 2.0: \"Enable Lightpen\"}\r\n\t\\PortBits{4}\r\n\t\t\\PortDesc{{\\tt 1} to enable DivMMC automap and DivMMC NMI by DRIVE button ({\\tt 0} after hard reset)}\r\n\t\\PortBits{3}\r\n\t\t\\PortDesc{{\\tt 1} to enable multiface NMI by M1 button ({\\tt 0} after hard reset)}\r\n\t\\PortBits{2}\r\n\t\t\\PortDesc{{\\tt 1} to set primary device to mouse in PS/2 mode, {\\tt 0} to set to keyboard}\r\n\t\\PortBits{1-0}\r\n\t\t\\PortDesc{Audio chip mode:}\r\n\t\t\\PortDescOnly{\r\n\t\t\t\\begin{PortBitConfig}\r\n\t\t\t\t\\PortBitLine{00}{YM}\t\t\t\t\r\n\t\t\t\t\\PortBitLine{01}{AY}\r\n\t\t\t\t\\PortBitLine{10}{Disabled}\r\n\t\t\t\t\\PortBitLine{11}{Core 3.0+: Hold all AY in reset}\r\n\t\t\t\\end{PortBitConfig}\r\n\t\t}\r\n\\end{NextPort}\r\n\r\n\\subsubsection{\\PortDeclaration{08}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7}\r\n\t\t\\PortDesc{{\\tt 1} unlock / {\\tt 0} lock port \\PortTextXRef{7FFD} paging}\r\n\t\\PortBits{6}\r\n\t\t\\PortDesc{{\\tt 1} to disable RAM and I/O port contention ({\\tt 0} after soft reset)}\r\n\t\\PortBits{5}\r\n\t\t\\PortDesc{AY stereo mode ({\\tt 0} = ABC, {\\tt 1} = ACB) ({\\tt 0} after hard reset)}\r\n\t\\PortBits{4}\r\n\t\t\\PortDesc{Enable internal speaker ({\\tt 1} after hard reset)}\r\n\t\\PortBits{3}\r\n\t\t\\PortDesc{Enable 8-bit DACs (A,B,C,D) ({\\tt 0} after hard reset)}\r\n\t\\PortBits{2}\r\n\t\t\\PortDesc{Enable port \\MemAddr{FF} Timex video mode read ({\\tt 0} after hard reset)}\r\n\t\\PortBits{1}\r\n\t\t\\PortDesc{Enable Turbosound (currently selected AY is frozen when disabled) ({\\tt 0} after hard reset)}\r\n\t\\PortBits{0}\r\n\t\t\\PortDesc{Implement Issue 2 keyboard (port \\MemAddr{FE} reads as early ZX boards) ({\\tt 0} after hard reset)}\r\n\\end{NextPort}\r\n\r\n\\subsubsection{\\PortTextXRef[]{09}}\r\n\r\n\\PortDeclarationXRef{Sprites}{09}\r\n\r\n\r\n\\pagebreak\r\n\\IntentionallyEmpty\r\n\\pagebreak\r\n"
  },
  {
    "path": "chapter-next-sprites.tex",
    "content": "\\section{Sprites}\r\n\\label{zx_next_sprites}\r\n\r\n% ───────────────────────────────────────────────────────────────────────────────────────────\r\n% ─██████████████─██████████████─████████████████───██████████─██████████████─██████████████─\r\n% ─██░░░░░░░░░░██─██░░░░░░░░░░██─██░░░░░░░░░░░░██───██░░░░░░██─██░░░░░░░░░░██─██░░░░░░░░░░██─\r\n% ─██░░██████████─██░░██████░░██─██░░████████░░██───████░░████─██████░░██████─██░░██████████─\r\n% ─██░░██─────────██░░██──██░░██─██░░██────██░░██─────██░░██───────██░░██─────██░░██─────────\r\n% ─██░░██████████─██░░██████░░██─██░░████████░░██─────██░░██───────██░░██─────██░░██████████─\r\n% ─██░░░░░░░░░░██─██░░░░░░░░░░██─██░░░░░░░░░░░░██─────██░░██───────██░░██─────██░░░░░░░░░░██─\r\n% ─██████████░░██─██░░██████████─██░░██████░░████─────██░░██───────██░░██─────██░░██████████─\r\n% ─────────██░░██─██░░██─────────██░░██──██░░██───────██░░██───────██░░██─────██░░██─────────\r\n% ─██████████░░██─██░░██─────────██░░██──██░░██████─████░░████─────██░░██─────██░░██████████─\r\n% ─██░░░░░░░░░░██─██░░██─────────██░░██──██░░░░░░██─██░░░░░░██─────██░░██─────██░░░░░░░░░░██─\r\n% ─██████████████─██████─────────██████──██████████─██████████─────██████─────██████████████─\r\n% ───────────────────────────────────────────────────────────────────────────────────────────\r\n\r\nOne of the frequently used ``my computer is better'' arguments from owners and developers of contemporary systems such as Commodore 64 was hardware supported sprites. To be fair, they had a point - poor old Speccy had none. But Next finally rectifies this with a sprite system that far supersedes even later 16-bit era machines such as Amiga. And as we'll see, it's really simple to program too!\r\n\r\nSome of the capabilities of Next sprites:\r\n\r\n\\begin{itemize}[topsep=1pt,itemsep=1pt]\r\n\t\\item 128 simultaneous sprites\r\n\t\\item 16x16 pixels per sprite\r\n\t\\item Magnification of 2x, 4x or 8x horizontally and vertically\r\n\t\\item Mirroring and rotation\r\n\t\\item Sprite grouping to form larger objects\r\n\t\\item 512 colours from 2 256 colour palettes\r\n\t\\item Per sprite palette\r\n\t\\item Built-in sprite editor\r\n\\end{itemize}\r\n\r\nSo lots of reasons to get excited! Let's dig in!\r\n\r\n\\subsection{Editing}\r\n\r\nBefore describing how sprites hardware works, it would be beneficial to know how to draw them. As mentioned, Next comes with a built-in sprite editor. To use it, change to desired folder, then enter {\\tt .spredit <filename>} in BASIC or command line. The editor is quite capable and can even be used with a mouse if you have one attached to your Next (or in the emulator).\r\n\r\nAlternatively, if you're developing cross-platform, the most feature-complete application for converting images to sprite data in my experience is Next Graphics\\footnote{\\url{https://github.com/infromthecold/Next-Graphics}}. It takes images from your preferred editor and converts them into a format that can be easily consumed by Next hardware. Other options I found are UDGeed-Next\\footnote{\\url{http://zxbasic.uk/files/UDGeedNext-current.rar}} or Remy's Sprite, Tile and Palette editor\\footnote{\\url{https://zx.remysharp.com/sprites/}}. In contrast to Next Graphics, the latter two are not just exporters but also editors and share very similar feature sets. So try them out and decide for yourself.\r\n\r\n\r\n\\subsection{Patterns}\r\n\r\nNext sprites have a fixed size of 16x16 pixels. Their display surface is 320x256, overlapping the ULA by 32 pixels on each side. Or in other words, to draw the sprite fully on-screen, we need to position it to (32,32) coordinate. And the last coordinate where the sprite is fully visible at the bottom-right edge is (271,207). This allows sprites to be animated in and out of the visible area. Sprites can be made visible or invisible when over the border as well as rendered on top or below Layer 2 and ULA, all specified by \\PortTextXRef{15}. It's also possible to further restrict sprite visibility within provided clip window using \\PortTextXRef{19}.\r\n\r\nSprite patterns (or pixel data) are stored in Next FPGA internal 16K memory. As mentioned, sprites are always 16x16 pixels but can be 8-bit or 4-bit.\r\n\r\n\\begin{itemize}[topsep=1pt,itemsep=1pt]\r\n\t\\item 8-bit sprites use full 8-bits to specify colour, so each pixel can be of any of 256 colours from the sprite palette of which one acts as transparent. Hence each sprite occupies 256 bytes of memory and 64 sprites can be stored.\r\n\r\n\t\\item 4-bit sprites use only 4-bits for colour, so each pixel can only choose from 16 colours, one of which is reserved for transparency. However this allows us to store 2 colours per byte, so these sprites take half the memory of 8-bit ones: 128 bytes each, meaning 128 sprites can be stored in available memory.\r\n\\end{itemize}\r\n\r\n\r\n\\subsection{Palette}\r\n\r\nEach sprite can specify its own palette offset. This allows sprites to share image data but use different colours. 4 bits are used for palette offset, therefore the final colour index within the current sprite palette (as defined by \\PortTextXRef{43}) is determined using the following formula:\r\n\r\n\\begin{multicols}{2}\r\n\t8-bit sprites\r\n\r\n\t\\begin{tabular}{ccccccccc}\r\n\t\t& \\BitHead{7} & \\BitHead{6} & \\BitHead{5} & \\BitHead{4} & \\BitHead{3} & \\BitHead{2} & \\BitHead{1} & \\BitHead{0} \\\\\r\n\t\t\\hline\r\n\t\t  & $P_3$ & $P_2$ & $P_1$ & $P_0$ & 0 & 0 & 0 & 0 \\\\\r\n\t\t+ & $S_7$ & $S_6$ & $S_5$ & $S_4$ & $S_3$ & $S_2$ & $S_1$ & $S_0$ \\\\\r\n\t\t\\hline\r\n\t\t= & $C_7$ & $C_6$ & $C_5$ & $C_4$ & $C_3$ & $C_2$ & $C_1$ & $C_0$ \\\\\r\n\t\\end{tabular}\r\n\r\n\tIf default palette offset and default palette are used, sprite colour index can be interpretted as RGB332 colour.\r\n\r\n\t\\columnbreak\r\n\r\n\t4-bit sprites\r\n\r\n\t\\begin{tabular}{ccccccccc}\r\n\t\t& \\BitHead{7} & \\BitHead{6} & \\BitHead{5} & \\BitHead{4} & \\BitHead{3} & \\BitHead{2} & \\BitHead{1} & \\BitHead{0} \\\\\r\n\t\t\\hline\r\n\t\t  & $P_3$ & $P_2$ & $P_1$ & $P_0$ & 0 & 0 & 0 & 0 \\\\\r\n\t\t+ & 0 & 0 & 0 & 0 & $S_3$ & $S_2$ & $S_1$ & $S_0$ \\\\\r\n\t\t\\hline\r\n\t\t= & $C_7$ & $C_6$ & $C_5$ & $C_4$ & $C_3$ & $C_2$ & $C_1$ & $C_0$ \\\\\r\n\t\\end{tabular}\r\n\r\n\tPalette offset can be thought of as if selecting one of 16 different 16-colour palettes.\r\n\\end{multicols}\r\n\r\n$P_n$ is palette offset bit, $S_n$ sprite colour index bit and $C_n$ final colour index.\r\n\r\nTransparent colour is defined with \\PortTextXRef{4B}.\r\n\r\n\r\n\\pagebreak\r\n\\subsection{Combined Sprites}\r\n\r\n\\subsubsection{Anchor Sprites}\r\n\r\nThese are ``normal'' 16x16 pixel sprites, as described in previous sections. They act as standalone sprites.\r\n\r\nThe reason they are called ``anchors'' is because multiple sprites can be grouped together to form larger sprites. In such case ``anchor'' acts as a parent and all its ``relative'' sprites are tied to it. In order to combine sprites, anchor needs to be defined first, immediately followed by all its relative sprites. The group ends with the next anchor sprite which can either be another standalone sprite, or an anchor for another sprite group. For example, if sprite 5 is setup as an anchor, its relative sprites must be followed at 6, 7, 8... until another sprite that's setup as ``anchor''.\r\n\r\nThere are 2 types of relative sprites: composite and unified sprites.\r\n\r\n\\subsubsection{Composite Relative Sprites}\r\n\r\nComposite sprites inherit certain attributes from their anchor.\r\n\r\n\\begin{multicols}{2}\r\n\t Inherited attributes:\r\n\r\n\t\\begin{itemize}[topsep=1pt,itemsep=1pt]\r\n\t\t\\item Visibility\r\n\t\t\\item X\r\n\t\t\\item Y\r\n\t\t\\item Palette offset\r\n\t\t\\item Pattern number\r\n\t\t\\item 4 or 8-bit pattern \r\n\t\\end{itemize}\r\n\r\n\t\\columnbreak\r\n\r\n\t\\textbf{NOT} inherited:\r\n\r\n\t\\begin{itemize}[topsep=1pt,itemsep=1pt]\r\n\t\t\\item Rotation\r\n\t\t\\item X \\& Y mirroring\r\n\t\t\\item X \\& Y scaling\r\n\t\\end{itemize}\r\n\r\n\\end{multicols}\r\n\r\nRelative sprites only have 8-bits for X and Y coordinates (ninth bits are used for other purposes). But as the name suggests, these coordinates are relative to their parent anchor sprite so they are usually positioned close by. When the anchor sprite is moved to a different position on the screen, all its relatives are also moved by the same amount.\r\n\r\nVisibility of relative sprites is determined as {\\tt AND} between anchor visibility and relative sprite visibility. This way individual relative sprites can be made invisible independently from their anchor, but if the anchor is invisible, then all its relative sprites will also be invisible.\r\n\r\nRelative sprites inherit 4 or 8-bit setup from their anchor. They can't use a different type but can use a different palette offset than its anchor.\r\n\r\nIt's also possible to tie relative sprite's pattern number to act as an offset on top of its anchor's pattern number and thus easily animate the whole sprite group simply by changing the anchor's pattern number.\r\n\r\n\\subsubsection{Unified Relative Sprites}\r\n\r\nUnified relative sprites are an extension of the composite type. Everything described above applies here as well.\r\n\r\nThe main difference is the hardware will automatically adjust relative sprites X, Y, rotation, mirroring and scaling attributes according to changes in anchor. So relatives will rotate, mirror and scale around the anchor as if it was a single larger sprite.\r\n\r\n\\subsection{Attributes}\r\n\r\n% note: we only show page number on second port xref since both are declared on the same page, but if this changes in the future, we should update this text accordingly\r\nAttributes are 4 or 5 bytes that define where and how the sprite is drawn. The data can be set either by selecting sprite index with \\PortTextXRef[]{303B} and then continuously sending bytes to \\PortTextXRef[]{xx57} (details on page \\PortPage{303B}) which automatically increments sprite index after all data for single sprite is transferred or by calling individual direct access Next registers \\PortAddr{35}-\\PortAddr{39}~or their auto-increment variants \\PortAddr{75}-\\PortAddr{79}. See ports and registers section \\XRef{zx_next_sprites_registers} for a description of individual bytes:\r\n\r\n\\begin{itemize}[topsep=1pt,itemsep=1pt]\r\n\t\\item Byte 0: \\PortTextXRef{35}\r\n\t\\item Byte 1: \\PortTextXRef{36}\r\n\t\\item Byte 2: \\PortTextXRef{37}\r\n\t\\item Byte 3: \\PortTextXRef{38}\r\n\t\\item Byte 4: \\PortTextXRef{39}\r\n\\end{itemize}\r\n\r\n\r\n\\subsection{Examples}\r\n\r\nReading about sprites may seem complicated, but in practice, it's quite simple. The following pages include sample code for working with sprites.\r\n\r\nTo preserve space, only partial code demonstrating relevant parts is included. You can find fully working example in companion code on GitHub in folder {\\tt sprites}. Besides demonstrating anchor and relative sprites, it also includes some very crude animations as a bonus.\r\n\r\n\r\n\\pagebreak\r\n\\subsubsection{Loading Patterns into FPGA Memory}\r\n\r\nBefore we can use sprites, we need to load their data into FPGA memory. This example introduces a generic routine that uses DMA\\footnote{\\url{https://wiki.specnext.dev/DMA}} to copy from given memory to FPGA. Don't worry if it seems like magic - it's implemented as a reusable routine, just copy it to your project. Routine requires 3 parameters:\r\n\r\n\\begin{itemize}[topsep=1pt,itemsep=1pt]\r\n\t\\item {\\tt HL} Source address of sprites to copy from\r\n\t\\item {\\tt BC} Number of bytes to copy\r\n\t\\item {\\tt A} Starting sprite number to copy to\r\n\\end{itemize}\r\n\r\n\\begin{tcblisting}{}\r\nLoadSprites:\r\n\tLD (.dmaSource), HL     ; Copy sprite sheet address from HL\r\n\tLD (.dmaLength), BC     ; Copy length in bytes from BC\r\n\tLD BC, &303B            ; Prepare port for sprite index\r\n\tOUT (C), A              ; Load index of first sprite\r\n\tLD HL, .dmaProgram      ; Setup source for OTIR\r\n\tLD B, .dmaProgramLength ; Setup length for OTIR\r\n\tLD C, &6B               ; Setup DMA port\r\n\tOTIR                    ; Invoke DMA code\r\n\tRET\r\n.dmaProgram:\r\n\tDB %10000011            ; WR6 - Disable DMA\r\n\tDB %01111101            ; WR0 - append length + port A address, A->B\r\n.dmaSource:\r\n\tDW 0                    ; WR0 par 1Band2 - port A start address\r\n.dmaLength:\r\n\tDW 0                    ; WR0 par 3Band4 - transfer length\r\n\tDB %00010100            ; WR1 - A incr., A=memory\r\n\tDB %00101000            ; WR2 - B fixed, B=I/O\r\n\tDB %10101101            ; WR4 - continuous, append port B address\r\n\tDW &005B                ; WR4 par 1Band2 - port B address\r\n\tDB %10000010            ; WR5 - stop on end of block, CE only\r\n\tDB %11001111            ; WR6 - load addresses into DMA counters\r\n\tDB %10000111            ; WR6 - enable DMA\r\n.dmaProgramLength = &-.dmaProgram\r\n\\end{tcblisting}\r\n\r\nSee section \\XRef{zx_next_dma} for details on how to program the zxnDMA.\r\n\r\n\r\n\\pagebreak\r\n\\subsubsection{Loading Sprites}\r\n\r\nUsing {\\tt loadSprites} routine is very simple. This example assumes you've edited sprites with one of the editors and saved them as {\\tt sprites.spr} file in the same folder as the assembler code:\r\n\r\n\\begin{tcblisting}{}\r\n\tLD HL, sprites          ; Sprites data source\r\n\tLD BC, 16*16*5          ; Copy 5 sprites, each 16x16 pixels\r\n\tLD A, 0                 ; Start with first sprite\r\n\tCALL LoadSprites        ; Load sprites to FPGA\r\n\r\nsprites:\r\n\tINCBIN \"sprites.spr\"    ; Sprite sheets file\r\n\\end{tcblisting}\r\n\r\n\r\n\\subsubsection{Enabling Sprites}\r\n\r\nAfter sprites are loaded into FPGA memory, we need to enable them:\r\n\r\n\\begin{tcblisting}{}\r\n\tNEXTREG &15, %01000001\t\t; Sprite 0 on top, SLU, sprites visible\r\n\\end{tcblisting}\r\n\r\n\r\n\\subsubsection{Displaying a Sprite}\r\n\r\nSprites are now loaded into FPGA memory, they are enabled, so we can start displaying them. This example displays the same sprite pattern twice, as two separate sprites:\r\n\r\n\\begin{tcblisting}{}\r\n\tNEXTREG &34, 0              ; First sprite\r\n\tNEXTREG &35, 100            ; X=100\r\n\tNEXTREG &36, 80             ; Y=80\r\n\tNEXTREG &37, %00000000      ; Palette offset, no mirror, no rotation\r\n\tNEXTREG &38, %10000000      ; Visible, no byte 4, pattern 0\r\n\r\n\tNEXTREG &34, 1              ; Second sprite\r\n\tNEXTREG &35, 86             ; X=86\r\n\tNEXTREG &36, 80             ; Y=80\r\n\tNEXTREG &37, %00000000      ; Palette offset, no mirror, no rotation\r\n\tNEXTREG &38, %10000000      ; Visible, no byte 4, pattern 0\r\n\\end{tcblisting}\r\n\r\n\r\n\\pagebreak\r\n\\subsubsection{Displaying Combined Sprites}\r\n\r\nEven handling combined sprites is much simpler in practice than in theory! This example combines 4 sprites into a single one using unified relative sprites. Note use of ``inc'' register \\MemAddr{79} which auto-increments sprite index for next sprite:\r\n\r\n\\begin{tcblisting}{}\r\n\tNEXTREG &34, 2              ; Select third sprite\r\n\tNEXTREG &35, 150            ; X=150\r\n\tNEXTREG &36, 80             ; Y=80\r\n\tNEXTREG &37, %00000000      ; Palette offset, no mirror, no rotation\r\n\tNEXTREG &38, %11000001      ; Visible, use byte 4, pattern 1\r\n\tNEXTREG &79, %00100000      ; Anchor with unified relatives, no scaling\r\n\r\n\tNEXTREG &35, 16             ; X=AnchorX+16\r\n\tNEXTREG &36, 0              ; Y=AnchorY+0\r\n\tNEXTREG &37, %00000000      ; Palette offset, no mirror, no rotation\r\n\tNEXTREG &38, %11000010      ; Visible, use byte 4, pattern 2\r\n\tNEXTREG &79, %01000000      ; Relative sprite\r\n\r\n\tNEXTREG &35, 0              ; X=AnchorX+0\r\n\tNEXTREG &36, 16             ; Y=AnchorY+16\r\n\tNEXTREG &37, %00000000      ; Palette offset, no mirror, no rotation\r\n\tNEXTREG &38, %11000011      ; Visible, use byte 4, pattern 3\r\n\tNEXTREG &79, %01000000      ; Relative sprite\r\n\r\n\tNEXTREG &35, 16             ; X=AnchorX+16\r\n\tNEXTREG &36, 16             ; Y=AnchorY+16\r\n\tNEXTREG &37, %00000000      ; Palette offset, no mirror, no rotation\r\n\tNEXTREG &38, %11000100      ; Visible, use byte 4, pattern 4\r\n\tNEXTREG &79, %01000000      ; Relative sprite\r\n\\end{tcblisting}\r\n\r\nBecause we use combined sprite, we only need to update the anchor to change all its relatives. And because we set it up as unified relative sprites, even rotation, mirroring and scaling is inherited as if it was a single sprite!\r\n\r\n\\begin{tcblisting}{}\r\n\tNEXTREG &34, 1              ; Select second sprite\r\n\tNEXTREG &35, 200            ; X=200\r\n\tNEXTREG &36, 100            ; Y=100\r\n\tNEXTREG &37, %00001010      ; Palette offset, mirror X, rotate\r\n\tNEXTREG &38, %11000001      ; Visible, use byte 4, pattern 1\r\n\tNEXTREG &39, %00101010      ; Anchor with unified relatives, scale X&Y \r\n\\end{tcblisting}\r\n\r\n\r\n\\pagebreak\r\n\\subsection{Sprite Ports and Registers}\r\n\\label{zx_next_sprites_registers}\r\n\r\n\\subsubsection{\\PortDeclaration{303B}}\r\n\r\nWrite: sets active sprite attribute and pattern slot index used by \\PortTextXRef[]{xx57} and \\PortTextXRef[]{xx5B} (see below).\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7}\r\n\t\t\\PortDesc{Set to {\\tt 1} to offset reads and writes by 128 bytes}\r\n\t\\PortBits{6-0}\r\n\t\t\\PortDesc{{\\tt 0-63} for pattern slots and {\\tt 0-127} for attribute slots}\r\n\\end{NextPort}\r\n\r\nRead: returns sprite status information\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-2}\r\n\t\t\\PortDesc{Reserved}\r\n\t\\PortBits{1}\t\r\n\t\t\\PortDesc{{\\tt 1} if sprite renderer was not able to render all sprites; read will reset to {\\tt 0}}\r\n\t\\PortBits{0}\r\n\t\t\\PortDesc{{\\tt 1} when collision between any 2 sprites occurred; read will reset to {\\tt 0}}\r\n\\end{NextPort}\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{xx57}}\r\n\r\nUploads the attributes for the currently selected sprite slot. Attributes require 4 or 5 bytes. After all bytes are sent, the sprite index slot automatically increments. See the following Next registers that directly set the value for specific bytes:\r\n\r\n\\begin{itemize}[topsep=1pt,itemsep=1pt]\r\n\t\\item Byte 0: \\PortTextXRef{35}\r\n\t\\item Byte 1: \\PortTextXRef{36}\r\n\t\\item Byte 2: \\PortTextXRef{37}\r\n\t\\item Byte 3: \\PortTextXRef{38}\r\n\t\\item Byte 4: \\PortTextXRef{39}\r\n\\end{itemize}\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{xx5B}}\r\n\r\nUploads sprite pattern data. 256 bytes are needed for each sprite. For 8-bit sprites, each pattern slot contains a single sprite. For 4-bit sprites, it contains 2 128 byte sprites. After 256 bytes are sent, the target pattern slot is auto-incremented.\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-0}\r\n\t\t\\PortDesc{Next byte of pattern data for current sprite}\r\n\\end{NextPort}\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{09}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7}\r\n\t\t\\PortDesc{{\\tt 1} to enable AY2 ``mono'' output (A+B+C is sent to both R and L channels, makes it a bit louder than stereo mode)}\r\n\t\\PortBits{6}\r\n\t\t\\PortDesc{{\\tt 1} to enable AY1 ``mono'' output, {\\tt 0} default}\r\n\t\\PortBits{5}\r\n\t\t\\PortDesc{{\\tt 1} to enable AY0 ``mono'' output ({\\tt 0} after hard reset)}\r\n\t\\PortBits{4}\r\n\t\t\\PortDesc{{\\tt 1} to lockstep \\PortTextXRef{34} and \\PortTextXRef{303B}}\r\n\t\\PortBits{3}\r\n\t\t\\PortDesc{{\\tt 1} to reset mapram bit in DivMMC}\r\n\t\\PortBits{2}\r\n\t\t\\PortDesc{{\\tt 1} to silence HDMI audio (0 after hard reset) (since core 3.0.5)}\r\n\t\\PortBits{1-0}\r\n\t\t\\PortDesc{Scanlines weight ({\\tt 0} after hard reset)}\r\n\t\t\\PortDescOnly{\r\n\t\t\t\\begin{tabular}{lll}\r\n\t\t\t\t& \\BitHead{Core 3.1.1+} & \\BitHead{Older cores} \\\\\r\n\t\t\t\t\\BitMono{00} & Scanlines off & Scalines off \\\\\r\n\t\t\t\t\\BitMono{01} & Scanlines 50\\% & Scanlines 75\\% \\\\\r\n\t\t\t\t\\BitMono{10} & Scanlines 50\\% & Scanlines 25\\% \\\\\r\n\t\t\t\t\\BitMono{11} & Scanlines 25\\% & Scanlines 12.5\\% \\\\\r\n\t\t\t\\end{tabular}\r\n\t\t}\r\n\\end{NextPort}\r\n\r\n\r\n\\subsubsection{\\PortTextXRef[]{15}}\r\n\r\n\\PortDeclarationXRef{Tilemap}{15}\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{19}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-0}\r\n\t\t\\PortDesc{Reads or writes clip-window coordinates for Sprites}\r\n\\end{NextPort}\r\n\r\n4 coordinates need to be set: X1, X2, Y1 and Y2. Sprites will only be visible within these coordinates. Positions are inclusive. Default values are {\\tt 0}, {\\tt 255}, {\\tt 0}, {\\tt 191}. Origin (0,0) is located 32 pixels to the top-left of ULA top-left coordinate.\r\n\r\nWhich coordinate gets set, is determined by index. As each write to this register will also increment index, the usual flow is to reset the index to 0 with \\PortTextXRef{1C}, then write all 4 coordinates in succession.\r\n\r\n% note: we use comma for referencing port declaration page to avoid double closing parenthesis, more readable this way\r\nWhen ``over border'' mode is enabled (bit 1 of \\PortTextXRef[,]{15}), X coordinates are doubled internally.\r\n\r\n\r\n\\subsubsection{\\PortTextXRef[]{1C}}\r\n\r\n\\PortDeclarationXRef{Layer 2}{1C}\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{34}}\r\n\r\nIf sprite id lockstep in \\PortTextXRef{09} is enabled, write to this registers has same effect as writing to \\PortTextXRef{303B}.\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7}\r\n\t\t\\PortDesc{Set to {\\tt 1} to offset reads and writes by 128 bytes}\r\n\t\\PortBits{6-0}\r\n\t\t\\PortDesc{{\\tt 0-63} for pattern slots and {\\tt 0-127} for attribute slots}\r\n\\end{NextPort}\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{35}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-0}\r\n\t\t\\PortDesc{Low 8 bits of X position}\r\n\\end{NextPort}\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{36}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-0}\r\n\t\t\\PortDesc{Low 8 bits of Y position}\r\n\\end{NextPort}\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{37}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-4}\r\n\t\t\\PortDesc{Palette offset}\r\n\t\\PortBits{3}\r\n\t\t\\PortDesc{{\\tt 1} to enable X mirroring, {\\tt 0} to disable}\r\n\t\\PortBits{2}\r\n\t\t\\PortDesc{{\\tt 1} to enable Y mirroring, {\\tt 0} to disable}\r\n\t\\PortBits{1}\r\n\t\t\\PortDesc{{\\tt 1} to rotate sprite 90\\Deg clockwise, {\\tt 0} to disable}\r\n\t\\PortBits{0}\r\n\t\t\\PortDesc{Anchor sprite: most significant bit of X coordinate}\r\n\t\t\\PortDescOnly{Relative sprite: {\\tt 1} to add anchor palette offset, {\\tt 0} to use independent palette offset}\r\n\\end{NextPort}\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{38}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7}\r\n\t\t\\PortDesc{{\\tt 1} to make sprite visible, {\\tt 0} to hide it}\r\n\t\\PortBits{6}\r\n\t\t\\PortDesc{{\\tt 1} to enable optional byte 4, {\\tt 0} to disable it}\r\n\t\\PortBits{5-0}\r\n\t\t\\PortDesc{Pattern index {\\tt 0-63} (7th, MSB for 4-bit sprites is configured with byte 4)}\r\n\\end{NextPort}\r\n\r\n\r\n\\pagebreak\r\n\\subsubsection{\\PortDeclaration{39}}\r\n\r\nFor anchor sprites:\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-6}\r\n\t\t\\PortDesc{{\\tt H+N6} where {\\tt H} is 4/8-bit data selector and {\\tt N6} is sub-pattern selector for 4-bit sprites}\r\n\t\t\\PortDescOnly{\r\n\t\t\t\\begin{PortBitConfig}\r\n\t\t\t\t\\PortBitLine{00}{Anchor sprite, 8-bit}\r\n\t\t\t\t\\PortBitLine{10}{Anchor sprite, 4-bit using bytes 0-127 of pattern slot}\r\n\t\t\t\t\\PortBitLine{11}{Anchor sprite, 4-bit using bytes 128-255 of pattern slot}\r\n\t\t\t\\end{PortBitConfig}\r\n\t\t}\r\n\t\\PortBits{5}\r\n\t\t\\PortDesc{{\\tt 0} if this anchor's relative sprites are composite, {\\tt 1} for unified sprite}\r\n\t\\PortBits{4-3}\r\n\t\t\\PortDesc{X axis scale factor}\r\n\t\t\\PortDescOnly{\r\n\t\t\t\\begin{PortBitConfig}\r\n\t\t\t\t\\PortBitLine{00}{1x}\r\n\t\t\t\t\\PortBitLine{01}{2x}\r\n\t\t\t\t\\PortBitLine{10}{4x}\r\n\t\t\t\t\\PortBitLine{11}{8x}\r\n\t\t\t\\end{PortBitConfig}\r\n\t\t}\r\n\t\\PortBits{2-1}\r\n\t\t\\PortDesc{Y axis scale factor, see above}\r\n\t\\PortBits{0}\r\n\t\t\\PortDesc{Most significant bit of Y coordinate}\r\n\\end{NextPort}\r\n\r\nFor composite relative sprites:\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-6}\r\n\t\t\\PortDesc{{\\tt 01} needs to be used for relative sprites}\r\n\t\\PortBits{5}\r\n\t\t\\PortDesc{4-bit mode: {\\tt N6}, {\\tt 1} to use bytes 0-127, {\\tt 0} to use bytes 128-255 of pattern slot}\r\n\t\t\\PortDescOnly{8-bit mode: not used, set to {\\tt 0}}\r\n\t\\PortBits{4-3}\r\n\t\t\\PortDesc{X axis scale factor, see below}\r\n\t\\PortBits{2-1}\r\n\t\t\\PortDesc{Y axis scale factor, see below}\r\n\t\\PortBits{0}\r\n\t\t\\PortDesc{{\\tt 1} to enable relative pattern offset, {\\tt 0} to use independent pattern index}\r\n\\end{NextPort}\r\n\r\nFor unified relative sprites\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-6}\r\n\t\t\\PortDesc{{\\tt 01} needs to be used for relative sprites}\r\n\t\\PortBits{5}\r\n\t\t\\PortDesc{4-bit mode: {\\tt N6}, {\\tt 1} to use bytes 0-127, {\\tt 0} to use bytes 128-255 of pattern slot}\r\n\t\t\\PortDescOnly{8-bit mode: not used, set to {\\tt 0}}\r\n\t\\PortBits{4-1}\r\n\t\t\\PortDesc{Set to {\\tt 0}; scaling is defined by anchor sprite}\r\n\t\\PortBits{0}\r\n\t\t\\PortDesc{{\\tt 1} to enable relative pattern offset, {\\tt 0} to use independent pattern index}\r\n\\end{NextPort}\r\n\r\n\r\n\\pagebreak\r\n\\subsubsection{\\PortTextXRef[]{40}}\r\n\\vspace*{-2ex}\r\n\\subsubsection{\\PortTextXRef[]{41}}\r\n\\vspace*{-2ex}\r\n\\subsubsection{\\PortTextXRef[]{43}}\r\n\\vspace*{-2ex}\r\n\\subsubsection{\\PortTextXRef[]{44}}\r\n\\PortDeclarationXRefCustom{Palette}{section \\ref{\\PortReference{40}}, pages \\PortPage{40}-\\PortPage{44}}\r\n\r\n\\subsubsection{\\PortDeclaration{4B}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-0}\\PortDesc{Sets index of transparent colour inside sprites palette.}\r\n\\end{NextPort}\r\n\r\nFor 4-bit sprites, low 4 bits of this register are used.\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{75}}\r\n\\vspace*{-2ex}\r\n\\subsubsection{\\PortDeclaration{76}}\r\n\\vspace*{-2ex}\r\n\\subsubsection{\\PortDeclaration{77}}\r\n\\vspace*{-2ex}\r\n\\subsubsection{\\PortDeclaration{78}}\r\n\\vspace*{-2ex}\r\n\\subsubsection{\\PortDeclaration{79}}\r\n\r\nThis set of registers work the same as their non-inc counterpart in \\MemAddr{35}-\\MemAddr{39}; writes byte 0-4 of Sprite attributes for currently selected sprite, except \\MemAddr{7X} variants also increment \\PortTextXRef{34} after write. When batch updating multiple sprites, typically the first sprite is selected explicitly, then \\MemAddr{3X} registers are used until the last write, which occurs through \\MemAddr{7X} register. This way we'll also increment the sprite index for the next iteration.\r\n\r\n\r\n\\pagebreak"
  },
  {
    "path": "chapter-next-tilemap.tex",
    "content": "\\section{Tilemap}\r\n\\label{zx_next_tilemap}\r\n\r\n% ────────────────────────────────────────────────────────────────────────\r\n% ─██████████████─██████████─██████─────────██████████████─██████████████─\r\n% ─██░░░░░░░░░░██─██░░░░░░██─██░░██─────────██░░░░░░░░░░██─██░░░░░░░░░░██─\r\n% ─██████░░██████─████░░████─██░░██─────────██░░██████████─██░░██████████─\r\n% ─────██░░██───────██░░██───██░░██─────────██░░██─────────██░░██─────────\r\n% ─────██░░██───────██░░██───██░░██─────────██░░██████████─██░░██████████─\r\n% ─────██░░██───────██░░██───██░░██─────────██░░░░░░░░░░██─██░░░░░░░░░░██─\r\n% ─────██░░██───────██░░██───██░░██─────────██░░██████████─██████████░░██─\r\n% ─────██░░██───────██░░██───██░░██─────────██░░██─────────────────██░░██─\r\n% ─────██░░██─────████░░████─██░░██████████─██░░██████████─██████████░░██─\r\n% ─────██░░██─────██░░░░░░██─██░░░░░░░░░░██─██░░░░░░░░░░██─██░░░░░░░░░░██─\r\n% ─────██████─────██████████─██████████████─██████████████─██████████████─\r\n% ────────────────────────────────────────────────────────────────────────\r\n\r\nTilemap is fast and effective way of displaying 8x8 pixel blocks on the screen. There are two possible resolutions available: 40x32 or 80x32 tiles. Tilemap layer overlaps ULA by 32 pixels on each side. Or in other words, similar to 320x256 and 640x256 modes of Layer 2, tilemap also covers the whole of the screen, including the border.\r\n\r\nTilemap is defined by 2 data structures: tile definitions and tilemap data itself.\r\n\r\n\r\n\\subsection{Tile Definitions}\r\n\r\nTiles are 8x8 pixels with each pixel representing an index of the colour from the currently selected tilemap palette.\r\n\r\nEach pixel occupies 4-bits, meaning tiles can use 16 colours. However, as we'll see in the next section, it's possible to specify a 4-bit palette offset for each tile which allows us to reach all 256 colours from the palette.\r\n\r\nA maximum of 256 tile definitions are possible, but this can be extended to 512 if needed using \\PortTextXRef{6B}.\r\n\r\nAll tiles definitions are specified in a contiguous memory block. The offset of tile definitions memory address relative to the start of bank 5 needs to be specified with \\PortTextXRef{6F}.\r\n\r\n\r\n\\subsection{Tilemap Data}\r\n\r\nTilemap data requires 2 bytes per tile:\r\n\r\n\\begin{BitTableWord}\r\n\t\\BitStartMulti{4}{\\rotatebox[origin=c]{90}{Palette Offset}} &\r\n\t\\rotatebox[origin=c]{90}{X Mirror} &\r\n\t\\rotatebox[origin=c]{90}{Y Mirror} &\r\n\t\\rotatebox[origin=c]{90}{Rotate} &\r\n\t\\rotatebox[origin=c]{90}{ULA Mode} &\r\n\t\\BitMulti{8}{\\rotatebox[origin=c]{90}{Tile Index}} \\\\\r\n\\end{BitTableWord}\r\n\r\n\\begin{basedescript}{\r\n\t\\desclabelstyle{\\multilinelabel}\r\n\t\\desclabelwidth{3cm}}\r\n\t\\setlength\\itemsep{0pt}\r\n\r\n\t\\newcommand{\\RightItem}[1]{\\item[#1]}\r\n\r\n\t\\RightItem{Palette Offset} 4-bit palette offset for this tile. This allows shifting colours to other 16-colour ``banks'' thus allowing us to reach the whole 256 colours from the palette.\r\n\t\r\n\t\\RightItem{X Mirror} If {\\tt 1}, this tile will be mirrored in X direction.\r\n\r\n\t\\RightItem{Y Mirror} If {\\tt 1}, this tile will be mirrored in Y direction.\r\n\t\r\n\t\\RightItem{Rotate} If {\\tt 1}, this tile will be rotated 90\\Deg clockwise.\r\n\t\r\n\t\\RightItem{ULA Mode} If {\\tt 1}, this tile will be rendered on top, if {\\tt 0} below ULA display. However in 512 tile mode, this is the 8th bit of tile index.\r\n\t\r\n\t\\RightItem{Tile Index} 8-bit tile index within the tile definitions.\r\n\\end{basedescript}\r\n\r\nHowever, it's possible to eliminate attributes byte by setting bit 5 in \\PortTextXRef{6B}. This only leaves an 8-bit tile index. Tileset then only occupies half the memory. But we lose the option to specify attributes for each tile separately. Instead attributes for all tiles are taken from \\PortTextXRef{6C}.\r\n\r\nThe offset of the tilemap data memory address relative to the start of bank 5 needs to be specified with \\PortTextXRef{6E}.\r\n\r\n\r\n\\subsection{Memory Organization}\r\n\r\nThe Tilemap layer is closely tied with ULA. Memory wise, it always exists in 16K slot 5. By default, this page is loaded into 16K slot 1 \\MemAddr{4000}-\\MemAddr{7FFF} (examples here will assume this configuration, if you load into a different slot, you will have to adjust addresses accordingly).\r\n\r\nIf both ULA and tilemap are used, memory should be arranged to avoid overlap. Given ULA pixel and attributes memory occupied memory addresses \\MemAddr{4000}-\\MemAddr{5AFF}, this leaves \\MemAddr{5B00}-\\MemAddr{7FFF} for tilemap. If we also take into account various system variables that reside on top of ULA attributes, \\MemAddr{6000} should be used for starting address. This leaves us:\r\n\r\n\\begin{ElegantTable}{|l|l|l|l|l|}\r\n\t\\ElegantHeader{& \\multicolumn{2}{c|}{\\EH{40x32}} & \\multicolumn{2}{c|}{\\EH{80x32}}}\r\n\r\n\tBytes per tile & 1 & 2 & 1 & 2 \\\\\r\n\t\\hline\r\n\tBytes per tileset & 1280 & 2560 & 2560 & 5120 \\\\\r\n\t\\hline\r\n\tMax Tile Definitions & 215 & 175 & 175 & 95 \\\\\r\n\\end{ElegantTable}\r\n\r\n% note: we only show page number on second port xref since both are declared on the same page, but if this changes in the future, we should update this text accordingly\r\nWe as programmers need to tell hardware where in the memory tilemap and tile definitions are stored. \\PortTextXRef[]{6E} and \\PortTextXRef[]{6F} registers (page \\PortPage{6E}) are used for that.\r\n\r\nBoth addresses are provided as most significant byte of the offset into memory slot 5 (which starts at \\MemAddr{4000}). This means we can only store data at multiples of 256 bytes. For example, if data is stored at \\MemAddr{6000}, the MSB offset value would be {\\tt \\$20} ({\\tt \\$6000 - \\$4000 = \\$\\underline{20}00}).\r\n\r\nGeneric formula to calculate MSB of the offset is: {\\tt (Address - \\$4000) >> 8}.\r\n\r\n\r\n\\subsection{Combining ULA and Tilemap}\r\n\r\nULA and Tilemap can be combined in two ways:\r\n\r\n\\begin{itemize}[topsep=1pt,itemsep=1pt]\r\n\t\\item Standard mode: uses bit {\\tt 0} from tile's attribute byte to determine if a tile is above or below ULA. If tilemap uses 2 bytes per tile, we can specify the priority for each tile separately, otherwise we specify it for all tiles. Transparent pixels are taken into account - if the top layer is transparent, the bottom one is visible through.\r\n\t\r\n\t\\item Stencil mode: only used if both, ULA and tileset are enabled. The final pixel is transparent if both, ULA and tilemap pixels are transparent. Otherwise final pixel is {\\tt AND} of both colour bits. This mode allows one layer to act as a cut-out for the other.\r\n\\end{itemize}\r\n\r\n\r\n\\subsection{Examples}\r\n\r\nUsing tilemaps is very simple. The most challenging part of my experience was finding a drawing program that would export to required formats in full. In my experience, Next Graphics\\footnote{\\url{https://github.com/infromthecold/Next-Graphics}} is the most feature-complete application for generating data for the Next. It takes images from your preferred editor and converts them into a format that can be easily consumed by Next hardware. It supports many different configurations too.\r\n\r\nAlternatively, Remy's Sprite, Tile and Palette editor website\\footnote{\\url{https://zx.remysharp.com/sprites/}} is the readily available editor and exporter. However, at the time of this writing, export is limited.\r\n\r\nRegardless of the editor, we need 3 pieces of data: palette, tile definitions and tileset itself. In this example, they are included as binary files:\r\n\r\n\\begin{tcblisting}{}\r\ntilemap:\r\n\tINCBIN \"tiles.map\"\r\ntilemapLength = &-tilemap\r\n\r\ntiles:\r\n\tINCBIN \"tiles.spr\"\r\ntilesLength = &-tiles\r\n\r\npalette:\r\n\tINCBIN \"tiles.pal\"\r\npaletteLength = &-palette\r\n\\end{tcblisting}\r\n\r\nWith all data in place, we can start setting up tilemap:\r\n\r\n\\begin{tcblisting}{}\r\nSTART_OF_BANK_5     = &4000\r\nSTART_OF_TILEMAP    = &6000     ; Just after ULA attributes and system vars\r\nSTART_OF_TILES      = &6600     ; Just after 40x32 tilemap\r\n\r\nOFFSET_OF_MAP       = (START_OF_TILEMAP - START_OF_BANK_5) >> 8\r\nOFFSET_OF_TILES     = (START_OF_TILES - START_OF_BANK_5) >> 8\r\n\r\n\t; Enable tilemap mode\r\n\tNEXTREG &6B, %10100001       ; 40x32, 8-bit entries\r\n\tNEXTREG &6C, %00000000       ; palette offset, visuals\r\n\r\n\t; Tell hardware where to find tiles\r\n\tNEXTREG &6E, OFFSET_OF_MAP   ; MSB of tilemap in bank 5\r\n\tNEXTREG &6F, OFFSET_OF_TILES ; MSB of tilemap definitions\r\n\\end{tcblisting}\r\n\r\nAbove code uses couple neat preprocessing tricks to automatically calculate MSB for tilemap and tile definitions offsets. The rest is simply setting up desired behaviour using Next registers.\r\n\r\n\\pagebreak\r\nThe only remaining piece is to actually copy all the data to expected memory locations:\r\n\r\n\\begin{tcblisting}{}\r\n\t; Setup tilemap palette\r\n\tNEXTREG &43, %00110000       ; Auto increment, select first tilemap palette\r\n\r\n\t; Copy palette\r\n\tLD HL, palette               ; Address of palette data in memory\r\n\tLD B, 16                     ; Copy 16 colours\r\n\tCALL Copy8BitPalette         ; Call routine for copying\r\n\r\n\t; Copy tile definitions to expected memory\r\n\tLD HL, tiles                 ; Address of tiles in memory\r\n\tLD BC, tilesLength           ; Number of bytes to copy\r\n\tCALL CopyTileDefinitions     ; Copy all tiles data\r\n\r\n\t; Copy tilemap to expected memory\r\n\tLD HL, tilemap               ; Addreess of tilemap in memory\r\n\tCALL CopyTileMap40x32        ; Copy 40x32 tilemaps\r\n\\end{tcblisting}\r\n\r\nWe already know {\\tt Copy8BitPalette} routine from Layer 2 chapter, the other two are straightforward {\\tt LDIR} loops:\r\n\r\n\\begin{tcblisting}{}\r\nCopyTileDefinitions:\r\n\tLD DE, START_OF_TILES\r\n\tLDIR\r\n\tRET\r\n\r\nCopyTileMap40x32:\r\n\tLD BC, 40*32\t\t; This variant always loads 40x32\r\n\tJR copyTileMap\r\n\r\nCopyTileMap80x32:\r\n\tLD BC, 80*32\t\t; This variant always loads 80x32\r\n\r\nCopyTileMap:\r\n\tLD DE, START_OF_TILEMAP\r\n\tLDIR\r\n\tRET\r\n\\end{tcblisting}\r\n\r\nYou can find fully working example in companion code on GitHub in folder {\\tt tilemap}.\r\n\r\n\r\n\\pagebreak\r\n\\subsection{Tilemap Registers}\r\n\\label{zx_next_tilemap_registers}\r\n\r\n\\subsubsection{\\PortDeclaration{15}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7}\r\n\t\t\\PortDesc{{\\tt 1} to enable lo-res layer, {\\tt 0} disable it}\r\n\t\\PortBits{6}\r\n\t\t\\PortDesc{{\\tt 1} to flip sprite rendering priority, i.e. sprite 0 is on top ({\\tt 0} after reset)}\r\n\t\\PortBits{5}\r\n\t\t\\PortDesc{{\\tt 1} to change clipping to ``over border'' mode (doubling X-axis coordinates of clip window, {\\tt 0} after reset)}\r\n\t\\PortBits{4-2}\r\n\t\t\\PortDesc{Layers priority and mixing}\r\n\t\t\\PortDescOnly{\r\n\t\t\t\\begin{PortBitConfig}\r\n\t\t\t\t\\PortBitLine{000}{{\\tt S L U} (Sprites are at top, Layer 2 under, Enhanced ULA at bottom)}\r\n\t\t\t\t\\PortBitLine{001}{{\\tt L S U}}\r\n\t\t\t\t\\PortBitLine{010}{{\\tt S U L}}\r\n\t\t\t\t\\PortBitLine{011}{{\\tt L U S}}\r\n\t\t\t\t\\PortBitLine{100}{{\\tt U S L}}\r\n\t\t\t\t\\PortBitLine{101}{{\\tt U L S}}\r\n\t\t\t\t\\PortBitLine{110}{Core 3.1.1+: {\\tt (U|T)S(T|U)(B+L)} blending layer and Layer 2 combined}\r\n\t\t\t\t\\PortBitLine{   }{Older cores: {\\tt S(U+L)} colours from ULA and L2 added per R/G/B channel}\r\n\t\t\t\t\\PortBitLine{111}{Core 3.1.1+: {\\tt (U|T)S(T|U)(B+L-5)} blending layer and Layer 2 combined}\r\n\t\t\t\t\\PortBitLine{   }{Older cores: {\\tt S(U+L-5)} similar as {\\tt 110}, but per R/G/B channel {\\tt (U+L-5)}}\r\n\t\t\t\t\\PortBitLine{   }{{\\tt 110} and {\\tt 111} modes: colours are clamped to {\\tt [0,7]}}\r\n\t\t\t\\end{PortBitConfig}\r\n\t\t}\r\n\t\\PortBits{1}\r\n\t\t\\PortDesc{{\\tt 1} to enable sprites over border ({\\tt 0} after reset)}\r\n\t\\PortBits{0}\r\n\t\t\\PortDesc{{\\tt 1} to enable sprite visibility ({\\tt 0} after reset)}\r\n\\end{NextPort}\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{1B}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-0}\r\n\t\t\\PortDesc{Reads and writes clip-window coordinates for Tilemap}\r\n\\end{NextPort}\r\n\r\n4 coordinates need to be set: X1, X2, Y1 and Y2. Tilemap will only be visible within these coordinates. X coordinates are internally doubled for 40x32 or quadrupled for 80x32 mode. Positions are inclusive. Default values are {\\tt 0}, {\\tt 159}, {\\tt 0}, {\\tt 255}. Origin (0,0) is located 32 pixels to the top-left of ULA top-left coordinate.\r\n\r\nWhich coordinate gets set, is determined by index. As each write to this register will also increment index, the usual flow is to reset the index to 0 in \\PortTextXRef{1C}, then write all 4 coordinates in succession.\r\n\r\n\r\n\\subsubsection{\\PortTextXRef[]{1C}}\r\n\r\n\\PortDeclarationXRef{Layer 2}{1C}\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{2F}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-2}\r\n\t\t\\PortDesc{Reserved, use {\\tt 0}}\r\n\t\\PortBits{1-0}\r\n\t\t\\PortDesc{Most significant bit(s) of X offset}\r\n\\end{NextPort}\r\n\r\n% note: port page is not used here since the declaration is on the same page\r\nIn 40x32 mode, meaningful range is {\\tt 0-319}, for 80x32 {\\tt 0-639}. Low 8-bits are stored in \\PortTextXRef[]{30}.\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{30}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-0}\r\n\t\t\\PortDesc{X offset for drawing tilemap in pixels}\r\n\\end{NextPort}\r\n\r\n% note: port page is not used here since the declaration is on the same page\r\nTilemap X offset in pixels. Meaningful range is {\\tt 0-319} for 40x32 and {\\tt 0-639} for 80x32 mode. To write values larger than 255, \\PortTextXRef[]{2F} is used to store MSB.\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{31}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-0}\r\n\t\t\\PortDesc{Y offset for drawing tilemap in pixels}\r\n\\end{NextPort}\r\n\r\nY offset is {\\tt 0-255}.\r\n\r\n\r\n\\subsubsection{\\PortTextXRef[]{40}}\r\n\\vspace*{-2ex}\r\n\\subsubsection{\\PortTextXRef[]{41}}\r\n\\vspace*{-2ex}\r\n\\subsubsection{\\PortTextXRef[]{43}}\r\n\\vspace*{-2ex}\r\n\\subsubsection{\\PortTextXRef[]{44}}\r\n\\PortDeclarationXRefCustom{Palette}{section \\ref{\\PortReference{40}}, pages \\PortPage{40}-\\PortPage{44}}\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{4C}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-5}\r\n\t\t\\PortDesc{Reserved, must be {\\tt 0}}\r\n\t\\PortBits{4-0}\r\n\t\t\\PortDesc{Index of transparent colour into tilemap palette}\r\n\\end{NextPort}\r\n\r\nThe pixel index from tile definitions is compared before palette offset is applied to the upper 4 bits, so there's always one index between {\\tt 0} and {\\tt 15} that works as transparent colour.\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{68}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7}\r\n\t\t\\PortDesc{{\\tt 1} to disable ULA output ({\\tt 0} after soft reset)}\r\n\t\\PortBits{6-5}\r\n\t\t\\PortDesc{(Core 3.1.1+) Blending in SLU modes 6 \\& 7}\r\n\t\t\\PortDescOnly{\r\n\t\t\t\\begin{PortBitConfig}\r\n\t\t\t\t\\PortBitLine{00}{ULA as blend colour}\r\n\t\t\t\t\\PortBitLine{01}{No blending}\r\n\t\t\t\t\\PortBitLine{10}{ULA/tilemap as blend colour}\r\n\t\t\t\t\\PortBitLine{11}{Tilemap as blend colour}\r\n\t\t\t\\end{PortBitConfig}\r\n\t\t}\r\n\t\\PortBits{4}\r\n\t\t\\PortDesc{(Core 3.1.4+) Cancel entries in 8x5 matrix for extended keys}\r\n\t\\PortBits{3}\r\n\t\t\\PortDesc{{\\tt 1} to enable ULA+ ({\\tt 0} after soft reset)}\r\n\t\\PortBits{2}\r\n\t\t\\PortDesc{{\\tt 1} to enable ULA half pixel scroll ({\\tt 0} after soft reset)}\r\n\t\\PortBits{1}\r\n\t\t\\PortDesc{Reserved, set to {\\tt 0}}\r\n\t\\PortBits{0}\r\n\t\t\\PortDesc{{\\tt 1} to enable stencil mode when both the ULA and tilemap are enabled.}\r\n\\end{NextPort}\r\n\r\nSee \\PortTextXRef{15} for different priorities and mixing of ULA, Layer 2 and Sprites.\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{6B}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7}\r\n\t\t\\PortDesc{{\\tt 1} to enable tilemap, {\\tt 0} disable tilemap}\r\n\t\\PortBits{6}\r\n\t\t\\PortDesc{{\\tt 1} for 80x32, {\\tt 0} 40x32 mode}\r\n\t\\PortBits{5}\r\n\t\t\\PortDesc{{\\tt 1} to eliminate attribute byte in tilemap}\r\n\t\\PortBits{4}\r\n\t\t\\PortDesc{{\\tt 1} for second, {\\tt 0} for first tilemap palette}\r\n\t\\PortBits{3}\r\n\t\t\\PortDesc{{\\tt 1} to activate ``text mode''\\See{1}}\r\n\t\\PortBits{2}\r\n\t\t\\PortDesc{Reserved, set to {\\tt 0}}\r\n\t\\PortBits{1}\r\n\t\t\\PortDesc{{\\tt 1} to activate 512, {\\tt 0} for 256 tile mode}\r\n\t\\PortBits{0}\r\n\t\t\\PortDesc{{\\tt 1} to force tilemap on top of ULA}\r\n\\end{NextPort}\r\n\r\n\\See{1}In the text mode, tiles are defined as 1-bit B\\&W bitmaps, same as original Spectrum UDGs. Each tile only requires 8 bytes. In this mode, the tilemap attribute byte is also interpreted differently: bit 0 is still ULA over Tilemap (or 9th bit of tile data index) but the top 7 bits are extended palette offset (the least significant bit is the value of the pixel itself). In this mode, transparency is checked against \\PortTextXRef{14} colour, not against the four-bit tilemap colour index.\r\n\r\n\r\n\\pagebreak\r\n\\subsubsection{\\PortDeclaration{6C}}\r\n\r\n% note: we don't use page number for port xref since the declaration is on previous page, same spread\r\nIf single byte tilemap mode is selected (bit 5 of \\PortTextXRef[]{6B}), this register defines attributes for all tiles.\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-4}\r\n\t\t\\PortDesc{Palette offset}\r\n\t\\PortBits{3}\r\n\t\t\\PortDesc{{\\tt 1} to mirror tiles in X direction}\r\n\t\\PortBits{2}\r\n\t\t\\PortDesc{{\\tt 1} to mirror tiles in Y direction}\r\n\t\\PortBits{1}\r\n\t\t\\PortDesc{{\\tt 1} rotate tiles 90\\Deg clockwise}\r\n\t\\PortBits{0}\r\n\t\t\\PortDesc{In 512 tile mode, bit 8 of tile index}\r\n\t\t\\PortDescOnly{{\\tt 1} for ULA over tilemap, {\\tt 0} for tilemap over ULA}\r\n\\end{NextPort}\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{6E}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-6}\r\n\t\t\\PortDesc{Ignored, set to {\\tt 0}}\r\n\t\\PortBits{5-0}\r\n\t\t\\PortDesc{Most significant byte of tilemap data offset in bank 5}\r\n\\end{NextPort}\r\n\r\n\r\n\\subsubsection{\\PortDeclaration{6F}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-6}\r\n\t\t\\PortDesc{Ignored, set to {\\tt 0}}\r\n\t\\PortBits{5-0}\r\n\t\t\\PortDesc{Most significant byte of tile definitions offset in bank 5}\r\n\\end{NextPort}\r\n\r\n\r\n\\pagebreak"
  },
  {
    "path": "chapter-next-ula.tex",
    "content": "\\section{ULA Layer}\r\n\\label{zx_next_ula}\r\n\r\n% ──────────────────────────────────────────────\r\n% ─██████──██████─██████─────────██████████████─\r\n% ─██░░██──██░░██─██░░██─────────██░░░░░░░░░░██─\r\n% ─██░░██──██░░██─██░░██─────────██░░██████░░██─\r\n% ─██░░██──██░░██─██░░██─────────██░░██──██░░██─\r\n% ─██░░██──██░░██─██░░██─────────██░░██████░░██─\r\n% ─██░░██──██░░██─██░░██─────────██░░░░░░░░░░██─\r\n% ─██░░██──██░░██─██░░██─────────██░░██████░░██─\r\n% ─██░░██──██░░██─██░░██─────────██░░██──██░░██─\r\n% ─██░░██████░░██─██░░██████████─██░░██──██░░██─\r\n% ─██░░░░░░░░░░██─██░░░░░░░░░░██─██░░██──██░░██─\r\n% ─██████████████─██████████████─██████──██████─\r\n% ──────────────────────────────────────────────\r\n\r\nOriginal ZX Spectrum didn't have a dedicated graphics chip. To keep the price as low as possible, screen rendering was performed by ULA (``Uncommitted Logic Array'') chip.\r\n\r\nZX Spectrum Next inherits ULA mode. The resolution of the screen in this mode is 256$\\times$192 pixels. If we translate this to 8$\\times$8 pixels characters, it gives us 32 character columns in 24 character rows.\r\n\r\nULA always reads from 16K bank 5 which is assigned to the second 16K slot at addresses \\MemAddr{4000}-\\MemAddr{7FFF} by default. Similar to the memory configuration of other contemporary computers, pixel memory is separate from attributes/colour memory. If using default memory configuration:\r\n\r\n\\begin{ElegantTable}{|c|c|c|c|}[\r\n\t\\setlength{\\tabcolsep}{5pt}\r\n]\r\n\t\\ElegantHeader{ROM & \\multicolumn{3}{c|}{RAM}}\r\n\r\n\t16K & 16K & 16K & 16K \\\\\r\n\t&\r\n\t\t\\begin{tabular}{c|c|c}\r\n\t\t\t\\arrayrulecolor{gray}\r\n\t\t\t\\hline\r\n\t\t\tPixels & Attributes & (free) \\\\\r\n\t\t\t\\MemAddr{4000}-\\MemAddr{57FF} & \r\n\t\t\t\t\\MemAddr{5800}-\\MemAddr{5AFF} &\r\n\t\t\t\t\\MemAddr{5B00}-\\MemAddr{7FFF} \\\\\r\n\t\t\\end{tabular}\r\n\t& & \\\\\r\n\\end{ElegantTable}\r\n\r\n\\subsection{Pixel Memory}\r\n\r\nEach screen pixel is represented by a single bit, meaning 1 byte holds 8 screen pixels. So, for each line of 256 pixels, 32 bytes are needed. However, for sake of efficiency, the original Spectrum optimized screen memory layout for speed but made it inconvenient for programming.\r\n\r\nPixel memory is not linear but is instead divided to fill character rows line by line. The first 32 bytes of memory represent the first line of the first character row, followed by 32 bytes representing the first line of the second character row and so on until the first line of 8 character rows is filled. Then next 32 bytes of screen memory represent the second line of the first character row, again followed by the second line of the second character row, until all 8 character rows are covered:\r\n\r\n{\r\n\t\\newcommand{\\PixelTitle}{Addr. & Ln. & Ch.}\r\n\t\\newcommand{\\PixelData}[4]{{\\tt \\$#1} & {\\tt #2} & {\\tt #3}/{\\tt #4}}\r\n\r\n\t\\begin{tabularx}{0.9\\linewidth}{lccXlccXlcccX}\r\n\t\t\\addtolength{\\tabcolsep}{-2pt}\r\n\t\t\\PixelTitle & & \\PixelTitle & & \\PixelTitle & & \\\\\r\n\t\t\\PixelData{4000}{0}{0}{0} & & \\PixelData{4100}{1}{0}{1} & & \\PixelData{4200}{2}{0}{2} & & \\multirow{8}{*}{\\ddd} \\\\\r\n\t\t\\PixelData{4020}{8}{1}{0} & & \\PixelData{4120}{9}{1}{1} & & \\PixelData{4220}{10}{1}{2} & & \\\\\r\n\t\t\\PixelData{4040}{16}{2}{0} & & \\PixelData{4140}{17}{2}{1} & & \\PixelData{4240}{18}{2}{2} & & \\\\\r\n\t\t\\PixelData{4060}{24}{3}{0} & & \\PixelData{4160}{25}{3}{1} & & \\PixelData{4260}{26}{3}{2} & & \\\\\r\n\t\t\\PixelData{4080}{32}{4}{0} & & \\PixelData{4180}{32}{4}{1} & & \\PixelData{4280}{33}{4}{2} & & \\\\\r\n\t\t\\PixelData{40A0}{40}{5}{0} & & \\PixelData{41A0}{41}{5}{1} & & \\PixelData{42A0}{42}{5}{2} & & \\\\\r\n\t\t\\PixelData{40C0}{48}{6}{0} & & \\PixelData{41C0}{49}{6}{1} & & \\PixelData{42C0}{50}{6}{2} & & \\\\\r\n\t\t\\PixelData{40E0}{56}{7}{0} & & \\PixelData{41E0}{57}{7}{1} & & \\PixelData{42E0}{58}{7}{2} & & \\\\[1ex]\r\n\t\t\\multicolumn{4}{l}{\\textbf{Ln.} Screen line (0-191)} & \\multicolumn{9}{l}{\\textbf{Ch.} Character {\\tt <row>}/{\\tt <line>} (0-23/0-7)} \\\\\r\n\t\\end{tabularx}\r\n}\r\n\r\nBut this is not the end of the peculiarities of Spectrum ULA mode. If you attempt to fill the screen memory byte by byte, you'll realize the top third of the screen fills in first, then middle third and lastly bottom third. The reason is, ULA mode divides the screen into 3 banks. Each bank covers 8 character rows, so 8$\\times$8$\\times$32 or 2048 bytes:\r\n\r\n\\begin{tabular}{ccc}\r\n\tMemory Range & Screen Lines & Char. Rows \\\\\r\n\t\\MemAddr{4000} - \\MemAddr{47FF} & \r\n\t\t{\\tt ~~0} - {\\tt 63~} & \r\n\t\t{\\tt ~0} - {\\tt 8~} \\\\\r\n\t\\MemAddr{4800} - \\MemAddr{4FFF} & \r\n\t\t{\\tt ~64} - {\\tt 127} & \r\n\t\t{\\tt ~9} - {\\tt 16} \\\\\r\n\t\\MemAddr{5000} - \\MemAddr{57FF} & \r\n\t\t{\\tt 128} - {\\tt 191} & \r\n\t\t{\\tt 17} - {\\tt 23} \\\\\r\n\\end{tabular}\r\n\r\nIn fact, to calculate the address of memory for any given (x,y) coordinate, we'd need to prepare a 16-bit value like this:\r\n\r\n\\begin{BitTableWord}\r\n\t\\BitMono{0} &\r\n\t\t\\BitMono{1} &\r\n\t\t\\BitMono{0} &\r\n\t\t\\BitSmall{$Y_7$} &\r\n\t\t\\BitSmall{$Y_6$} &\r\n\t\t\\BitSmall{$Y_2$} &\r\n\t\t\\BitSmall{$Y_1$} &\r\n\t\t\\BitSmall{$Y_0$} &\r\n\t\\BitSmall{$Y_5$} &\r\n\t\t\\BitSmall{$Y_4$} &\r\n\t\t\\BitSmall{$Y_3$} &\r\n\t\t\\BitSmall{$X_7$} &\r\n\t\t\\BitSmall{$X_6$} &\r\n\t\t\\BitSmall{$X_5$} &\r\n\t\t\\BitSmall{$X_4$} &\r\n\t\t\\BitSmall{$X_3$} \\\\\r\n\r\n\t\\hline\r\n\r\n\t\\BitMono{0} &\r\n\t\t\\BitMono{1} &\r\n\t\t\\BitMono{0} &\r\n\t\t\\BitMulti{8}{$Y$} &\r\n\t\t\\BitMulti{5}{$X$} \\\\\r\n\r\n\\end{BitTableWord}\r\n\r\nAs you can see, X is straightforward; we simply need to take the upper 5 bits and fill them into the lower 5 bits of a 16-bit register pair. Y coordinate requires all 8 bits written into bits 12-5 of 16-bit register pair. However, notice how individual bits are scrambled. It makes incrementing address for next character row simple operation of {\\tt INC H} (assuming {\\tt HL} stores the address of the previous row), which is likely one of the reasons for such implementation. But imagine for a second how complex a Z80 program would need to be to handle all of this. Sure, nothing couple shifts and masking operations couldn't handle but still, lots of wasted CPU cycles. However, on ZX Spectrum Next we have 3 new instructions that take care of all of the complexity for us:\r\n\r\n\\begin{itemize}[topsep=1pt,itemsep=1pt]\r\n\t\\item {\\tt PIXELAD} calculates the address of a pixel with coordinates from {\\tt DE} register pair where {\\tt D} is Y and {\\tt E} is X coordinate and stores the memory location address into {\\tt HL} register pair for ready consumption\r\n\t\r\n\t\\item {\\tt PIXELDN} takes the address of a pixel in {\\tt HL} and updates it to point to the same X coordinate but one screen line down\r\n\t\r\n\t\\item {\\tt SETAE} takes X coordinate from {\\tt E} register and prepares mask in register {\\tt A} for reading or writing to ULA screen\r\n\\end{itemize}\r\n\r\nFurthermore; each instruction only uses 8 t-states, which is far less than the corresponding Z80 assembly program would require. Somewhat naive program for drawing vertical line write from the pixel at coordinate (16,32) to (16,50):\r\n\r\n\\begin{tcblisting}{}\r\n\tLD DE, &1020      ; Y=16, X=32\r\n\tPIXELAD           ; HL=address of pixel (E,D)\r\nloop:\r\n\tSETAE             ; A=pixel mask\r\n\tOR (HL)           ; we'll write the pixel\r\n\tLD (HL), A        ; actually write the pixel\r\n\t\r\n\tINC D             ; Y=Y+1\r\n\tLD A, D           ; copy new Y coordinate to A\r\n\tCP 51             ; are we at 51 already?\r\n\tRET NC            ; yes, return\r\n\r\n\tPIXELDN           ; no, update HL to next line\r\n\tJR loop           ; continue with next pixel\r\n\\end{tcblisting}\r\n\r\nNote: because we're updating our Y coordinate in {\\tt D} register within the loop, we could also use {\\tt PIXELAD} instead of {\\tt PIXELDN} in line 13. Both instructions require 8 T states for execution, so there's no difference performance-wise.\r\n\r\nIf we instead wanted to check if the pixel at the given coordinate is set or not, we would use {\\tt AND (HL)} instead of {\\tt OR (HL)}. For example:\r\n\r\n\\begin{tcblisting}{}\r\n\tLD DE, &1020      ; Y=16, X=32\r\n\tPIXELAD           ; HL=address of pixel (E,D)\r\n\tSETAE             ; A=pixel mask\r\n\tAND (HL)          ; we'll read the pixel\r\n\tRET Z             ; exit if pixel is not set\r\n\\end{tcblisting}\r\n\r\n\r\n\\subsection{Attributes Memory}\r\n\r\nNow that we know how to draw individual pixels, it's time to handle colour. Memory wise, it's stored immediately after pixel RAM, at memory locations \\MemAddr{5800} - \\MemAddr{5AFF}. Each byte represents colour and attributes for 8$\\times$8 pixel block on the screen. Byte contents are as follows:\r\n\r\n\\begin{BitTableByte}\r\n\t\\BitSmall{$F$} &\r\n\t\t\\BitSmall{$B$} &\r\n\t\t\\BitSmall{$P_2$} &\r\n\t\t\\BitSmall{$P_1$} &\r\n\t\t\\BitSmall{$P_0$} &\r\n\t\t\\BitSmall{$I_2$} &\r\n\t\t\\BitSmall{$I_1$} &\r\n\t\t\\BitSmall{$I_0$} \\\\\r\n\t\\hline\r\n\t\\BitSmall{$F$} &\r\n\t\t\\BitSmall{$B$} &\r\n\t\t\\BitMulti{3}{Paper} &\r\n\t\t\\BitMulti{3}{Ink} \\\\\r\n\\end{BitTableByte}\r\n\r\n\\begin{itemize}[topsep=1pt,itemsep=1pt]\r\n\t\\item Bit 7: {\\tt 1} to enable flashing, {\\tt 0} to disables it\r\n\t\\item Bit 6: {\\tt 1} to enable bright colours, {\\tt 0} for normal colours\r\n\t\\item Bits 5-3: paper colour {\\tt 0-7}\r\n\t\\item Bits 2-0: ink colour {\\tt 0-7}\r\n\\end{itemize}\r\n\r\nColour value {\\tt 0-7} corresponds to:\r\n\r\n\\begin{tabular}{ccll}\r\n\t\\BitHead{Value} & \\BitHead{Binary} & \\BitHead{Colour} & \\BitHead{Bright} \\\\\r\n\t\\BitMono{0}\t& \\BitMono{000}\t& Black & Black \\\\\r\n\t\\BitMono{1}\t& \\BitMono{001}\t& Blue & Bright blue \\\\\r\n\t\\BitMono{2}\t& \\BitMono{010}\t& Red & Bright red \\\\\r\n\t\\BitMono{3}\t& \\BitMono{011}\t& Magenta & Bright magenta \\\\\r\n\t\\BitMono{4}\t& \\BitMono{100}\t& Green & Bright green \\\\\r\n\t\\BitMono{5}\t& \\BitMono{101}\t& Cyan & Bright cyan \\\\\r\n\t\\BitMono{6}\t& \\BitMono{110}\t& Yellow & Bright yellow \\\\\r\n\t\\BitMono{7}\t& \\BitMono{111}\t& Gray & White \\\\\r\n\\end{tabular}\r\n\r\nSpectrum only requires 768 bytes to configure colour and attributes for the whole screen. And memory is contiguous so it's simple to manage. However, it comes at expense of restricting to only 2 colours per character block - the reason for the (in)famous colour clash.\r\n\r\nNote: on Next, default ULA colours can be changed, see Palette chapter \\XRef{zx_next_palette} for details.\r\n\r\n\r\n\\subsection{Border}\r\n\r\n% note: use of \"previous page\" in parenthesis below - this works as long as colours table will be physically on previous page in printed book, but make sure it's adjusted if additional content it added, or layout changes otherwise in the future (\"in previous section\" or \"above\" for example, or, if several pages are inserted in between, use \\XRef)\r\nNext inherits Spectrum border colour handling through \\PortTextXRef{xxFEWrite}. The bottom 3 bits are used to specify one of 8 possible colours (see table on the previous page for full list). Example:\r\n\r\n\\begin{tcblisting}{}\r\n\tLD A, 1\t\t\t; Select blue colour\r\n\tOUT (&FE), A\t; Set border colour from A\r\n\\end{tcblisting}\r\n\r\nNote: border colour is set the same way regardless of graphics mode used. However, some Layer 2 modes and Tileset may partially or fully cover the border, effectively making it invisible to the user.\r\n\r\n\r\n\\subsection{Shadow Screen}\r\n\r\nAs mentioned, ULA uses 16K bank 5 by default to determine what to show on the screen. However, it's possible to change this to bank 7 instead by using bit 3 of \\PortTextXRef{7FFD}. Bank 7 mode is called the ``shadow'' screen. It gives us two separate memory spaces for rendering ULA data and means for quickly swapping between them. It allows always drawing into inactive bank and only swapping it in when ready thus help eliminating flicker.\r\n\r\nNote: \\PortTextXRef{7FFD} only controls which of the two possible banks is being used by ULA, but it doesn't map the bank into any of the memory slots. This needs to be done by one of the paging modes as described in the Memory Map and Paging chapter, section \\XRef{zx_next_memorypaging}. Using MMU, we could do something like:\r\n\r\n\\begin{tcblisting}{}\r\n\tLD HL, &5800        ; we'll be swapping colours\r\n\r\n\tNEXTREG &52, 10     ; swap first half of 16K bank 5 to 8K slot 2\r\n\tLD A, %00000000     ; paper=black, ink=black\r\n\tLD (HL), A          ; write data to screen (immediately visible)\r\n\t\r\n\tNEXTREG &52, 14     ; swap first half of 16K bank 7 to 8K slot 2\r\n\tLD A, %00000101     ; paper=black, ink=cyan\r\n\tLD (HL), A          ; write to 16K bank 7 (not visible)\r\n\t\r\n\tLD BC, &7FFD        ; prepare port for changing layers\r\n\tLD A, %00001000     ; activate shadow layer\r\n\tOUT (C), A          ; top left char now has black background\r\n\t\r\n\tLD A, %00000000     ; deactivate shadow layer\r\n\tOUT (C), A          ; top left char now has cyan background\r\n\\end{tcblisting}\r\n\r\nRemember: 16K bank 7 corresponds to 8K banks 14 and 15. And because pixel and attributes combined fit within single 8K, only single bank needs to be swapped in.\r\n\r\n\\subsection{Enhanced ULA Modes}\r\n\r\nZX Spectrum Next also supports several enhanced ULA modes like Timex Sinclair Double Buffering, Timex Sinclair Hi-Res and Hi-Colour, etc. However, with the presence of Layer 2 and Tilemap modes, it's unlikely these will be used when programming new software on Next. Therefore they are not described here. If interested, read more on:\r\n\r\n\\url{https://wiki.specnext.dev/Video_Modes}\r\n\r\n\r\n\\subsection{ULA Registers}\r\n\\label{zx_next_ula_registers}\r\n\r\n\\subsubsection{\\PortDeclaration{xxFEWrite}}\r\n\r\n\\begin{NextPort}\r\n\t\\PortBits{7-5}\r\n\t\t\\PortDesc{Reserved, use {\\tt 0}}\r\n\t\\PortBits{4}\r\n\t\t\\PortDesc{EAR output (connected to internal speaker)}\r\n\t\\PortBits{3}\r\n\t\t\\PortDesc{MIC output (saving to tape via audio jack)}\r\n\t\\PortBits{2-0}\r\n\t\t\\PortDesc{Border colour}\r\n\\end{NextPort}\r\n\r\n% note: we don't show page next to port since we use more verbose link to the section+page afterwards\r\nNote: when read with certain high byte values, \\PortTextXRef[]{xxFE} will read keyboard status. See Keyboard, section \\PortXRef{xxFE} for details.\r\n\r\n\r\n\\subsubsection{\\PortTextXRef[]{7FFD}}\r\n\\PortDeclarationXRef{Memory Map and Paging}{7FFD}\r\n\r\n\r\n\\subsubsection{\\PortTextXRef[]{40}}\r\n\\vspace*{-2ex}\r\n\\subsubsection{\\PortTextXRef[]{41}}\r\n\\vspace*{-2ex}\r\n\\subsubsection{\\PortTextXRef[]{42}}\r\n\\vspace*{-2ex}\r\n\\subsubsection{\\PortTextXRef[]{43}}\r\n\\vspace*{-2ex}\r\n\\subsubsection{\\PortTextXRef[]{44}}\r\n\\vspace*{-2ex}\r\n\\subsubsection{\\PortTextXRef[]{4A}}\r\n\\PortDeclarationXRefMultiple{Palette}{40}{4A}\r\n\r\n\r\n\r\n\\pagebreak\r\n\\IntentionallyEmpty\r\n\\pagebreak\r\n"
  },
  {
    "path": "chapter-next.tex",
    "content": "\\chapter{ZX Spectrum Next}\r\n\r\n% █████████████████████████████████████████████████████████████████████████\r\n% █░░░░░░██████████░░░░░░█░░░░░░░░░░░░░░█░░░░░░░░██░░░░░░░░█░░░░░░░░░░░░░░█\r\n% █░░▄▀░░░░░░░░░░██░░▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀░░██░░▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█\r\n% █░░▄▀▄▀▄▀▄▀▄▀░░██░░▄▀░░█░░▄▀░░░░░░░░░░█░░░░▄▀░░██░░▄▀░░░░█░░░░░░▄▀░░░░░░█\r\n% █░░▄▀░░░░░░▄▀░░██░░▄▀░░█░░▄▀░░███████████░░▄▀▄▀░░▄▀▄▀░░███████░░▄▀░░█████\r\n% █░░▄▀░░██░░▄▀░░██░░▄▀░░█░░▄▀░░░░░░░░░░███░░░░▄▀▄▀▄▀░░░░███████░░▄▀░░█████\r\n% █░░▄▀░░██░░▄▀░░██░░▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█████░░▄▀▄▀▄▀░░█████████░░▄▀░░█████\r\n% █░░▄▀░░██░░▄▀░░██░░▄▀░░█░░▄▀░░░░░░░░░░███░░░░▄▀▄▀▄▀░░░░███████░░▄▀░░█████\r\n% █░░▄▀░░██░░▄▀░░░░░░▄▀░░█░░▄▀░░███████████░░▄▀▄▀░░▄▀▄▀░░███████░░▄▀░░█████\r\n% █░░▄▀░░██░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀░░░░░░░░░░█░░░░▄▀░░██░░▄▀░░░░█████░░▄▀░░█████\r\n% █░░▄▀░░██░░░░░░░░░░▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀░░██░░▄▀▄▀░░█████░░▄▀░░█████\r\n% █░░░░░░██████████░░░░░░█░░░░░░░░░░░░░░█░░░░░░░░██░░░░░░░░█████░░░░░░█████\r\n% █████████████████████████████████████████████████████████████████████████\r\n\r\n\r\n\\ChapterTOC[]\r\n\r\n\\pagebreak\r\n\\thispagestyle{plain} % use toc style without headers for this explanation page, it better matches chapter start page\r\n\r\nWith increased CPU speeds, more memory, better graphics, hardware sprites and tiles, to mention just some of the most obvious, ZX Spectrum Next is an exciting platform for the retro programmer.\r\n\r\nThis chapter represents the bulk of the book. Each topic is discussed in its own section. While the sections are laid out in order - later sections sometimes rely on, or refer to the topics discussed earlier, there's no need to go through them in an orderly fashion. Each section should be quite usable by itself as well. All topics discussed elsewhere are referenced, so you can quickly jump there if needed. If using PDF you can click on the section number to go straight to it. With a printed book though, turning the pages gives you a chance to land on something unrelated, but equally interesting, thus learning something new almost by accident.\r\n\r\nOne more thing worth mentioning, before leaving you on to explore, are ports and Next registers. You will find the full list in the next section. But that's just a list with a couple of examples on how to read and write them. Still, many ports and registers are described in detail at the end of the sections in which they are first mentioned. Those registers that are relevant for multiple topics are described in the first section they are mentioned in, and then referenced from other sections. Additionally, each port and register that's described in detail, has the reference to that section in the list on the following pages as a convenience. I thought for a while about how to approach this. One way would be to describe the ports and references in a single section, together with their list, and then only reference them elsewhere. But ultimately decided on the format described above for two reasons: descriptions are not comprehensive, only relevant ports and registers have this ``honour''. And secondly, I wanted to keep all relevant material as close together as possible.\r\n\r\n\\pagebreak\r\n\\pagestyle{clean} % all subsequent pages should use clean style with full header\r\n"
  },
  {
    "path": "chapter-title.tex",
    "content": "% ████████████████████████████████████████████████████████████████████████\r\n% █░░░░░░░░░░░░░░█░░░░░░░░░░█░░░░░░░░░░░░░░█░░░░░░█████████░░░░░░░░░░░░░░█\r\n% █░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀░░█████████░░▄▀▄▀▄▀▄▀▄▀░░█\r\n% █░░░░░░▄▀░░░░░░█░░░░▄▀░░░░█░░░░░░▄▀░░░░░░█░░▄▀░░█████████░░▄▀░░░░░░░░░░█\r\n% █████░░▄▀░░███████░░▄▀░░███████░░▄▀░░█████░░▄▀░░█████████░░▄▀░░█████████\r\n% █████░░▄▀░░███████░░▄▀░░███████░░▄▀░░█████░░▄▀░░█████████░░▄▀░░░░░░░░░░█\r\n% █████░░▄▀░░███████░░▄▀░░███████░░▄▀░░█████░░▄▀░░█████████░░▄▀▄▀▄▀▄▀▄▀░░█\r\n% █████░░▄▀░░███████░░▄▀░░███████░░▄▀░░█████░░▄▀░░█████████░░▄▀░░░░░░░░░░█\r\n% █████░░▄▀░░███████░░▄▀░░███████░░▄▀░░█████░░▄▀░░█████████░░▄▀░░█████████\r\n% █████░░▄▀░░█████░░░░▄▀░░░░█████░░▄▀░░█████░░▄▀░░░░░░░░░░█░░▄▀░░░░░░░░░░█\r\n% █████░░▄▀░░█████░░▄▀▄▀▄▀░░█████░░▄▀░░█████░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█\r\n% █████░░░░░░█████░░░░░░░░░░█████░░░░░░█████░░░░░░░░░░░░░░█░░░░░░░░░░░░░░█\r\n% ████████████████████████████████████████████████████████████████████████\r\n\r\n\\title{\\BookTitle}\r\n\\author{\\AuthorNameSurname}\r\n\\date{\\LatestRevisionName}\r\n\r\n\r\n\\begin{titlepage}\r\n\t\\newcommand{\\BigFont}[1]{\\fontsize{30}{30}\\selectfont #1}\r\n\t\\newcommand{\\MidFont}[1]{\\fontsize{21.4}{21}\\selectfont #1}\r\n\t\\newcommand{\\SmallFont}[1]{\\fontsize{14}{14}\\selectfont #1}\r\n\t\\newcommand{\\MiniFont}[1]{\\fontsize{8}{8}\\selectfont #1}\r\n\t\r\n\t\\WorkInProgressFullScreen\r\n\r\n\t\\vspace*{\\fill}\r\n\r\n\t\\begin{flushright}\r\n\t\t\\sffamily\r\n\r\n\t\t\\textbf{\r\n\t\t\t\\BigFont{\\BookTitleMain}\r\n\t\t\t\\\\[0.5cm]\r\n\t\t\t\\MidFont{\\BookTitleSub\\hspace*{-0.8ex}}\r\n\t\t\t% ^^^ for some reason there's some horizontal space at the right side of subtitle instead of being nicely aligned with the rest of the text... \\hspace takes care of that\r\n\t\t}\r\n\r\n\t\t\\vspace*{2cm}\r\n\r\n\t\t\\MidFont{\\AuthorNameSurname}\r\n\r\n\t\t\\vspace*{5cm}\r\n\r\n\t\t\\SmallFont{Z80 Undocumented by}\\\\\r\n\t\t\\SmallFont{Jan Wilmans}\\\\\r\n\t\t\\SmallFont{Sean Young}\r\n\r\n\t\\end{flushright}\r\n\r\n\t\\vspace*{\\fill}\r\n\r\n\t\\WorkInProgressFullScreen\r\n\t\r\n\\end{titlepage}\r\n"
  },
  {
    "path": "chapter-toc.tex",
    "content": "% ██████████████████████████████████████████████\r\n% █░░░░░░░░░░░░░░█░░░░░░░░░░░░░░█░░░░░░░░░░░░░░█\r\n% █░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█\r\n% █░░░░░░▄▀░░░░░░█░░▄▀░░░░░░▄▀░░█░░▄▀░░░░░░░░░░█\r\n% █████░░▄▀░░█████░░▄▀░░██░░▄▀░░█░░▄▀░░█████████\r\n% █████░░▄▀░░█████░░▄▀░░██░░▄▀░░█░░▄▀░░█████████\r\n% █████░░▄▀░░█████░░▄▀░░██░░▄▀░░█░░▄▀░░█████████\r\n% █████░░▄▀░░█████░░▄▀░░██░░▄▀░░█░░▄▀░░█████████\r\n% █████░░▄▀░░█████░░▄▀░░██░░▄▀░░█░░▄▀░░█████████\r\n% █████░░▄▀░░█████░░▄▀░░░░░░▄▀░░█░░▄▀░░░░░░░░░░█\r\n% █████░░▄▀░░█████░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█\r\n% █████░░░░░░█████░░░░░░░░░░░░░░█░░░░░░░░░░░░░░█\r\n% ██████████████████████████████████████████████\r\n\r\n\r\n\\tableofcontents\r\n\r\n% Manually break the page before introduction in non-print version. Non-print PDF TOC includes sub-sub-sections as well therefore spreads much more pages and, more crutially, ends on odd page so introduction chapter that follows would begin on even one.\r\n% Note: when new sub/sections are added in the future that cause TOC to spread onto even page, this whole \\ifdefined can be deleted (or commented out to leave it for the future). There's probably automated way to ensure chapters always start on odd page, but nothing I tried worked (I think part of the problem lies in the fact that odd/even is reversed in this document due to how lulu expects PDF to be formatted)\r\n\r\n\\ifdefined\\isPDF\r\n\t% e-book doesn't require empty line\r\n\\else\r\n\t% printed book requires an empty line\r\n\t\\pagebreak\r\n\t\\IntentionallyEmpty\r\n\t\\pagebreak\r\n\\fi"
  },
  {
    "path": "chapter-z80.tex",
    "content": "\\chapter{Zilog Z80}\r\n\r\n% ██████████████████████████████████████████████████\r\n% █░░░░░░░░░░░░░░░░░░█░░░░░░░░░░░░░░█░░░░░░░░░░░░░░█\r\n% █░░▄▀▄▀▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█\r\n% █░░░░░░░░░░░░▄▀▄▀░░█░░▄▀░░░░░░▄▀░░█░░▄▀░░░░░░▄▀░░█\r\n% █████████░░░░▄▀░░░░█░░▄▀░░██░░▄▀░░█░░▄▀░░██░░▄▀░░█\r\n% ███████░░░░▄▀░░░░███░░▄▀░░░░░░▄▀░░█░░▄▀░░██░░▄▀░░█\r\n% █████░░░░▄▀░░░░█████░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀░░██░░▄▀░░█\r\n% ███░░░░▄▀░░░░███████░░▄▀░░░░░░▄▀░░█░░▄▀░░██░░▄▀░░█\r\n% █░░░░▄▀░░░░█████████░░▄▀░░██░░▄▀░░█░░▄▀░░██░░▄▀░░█\r\n% █░░▄▀▄▀░░░░░░░░░░░░█░░▄▀░░░░░░▄▀░░█░░▄▀░░░░░░▄▀░░█\r\n% █░░▄▀▄▀▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█\r\n% █░░░░░░░░░░░░░░░░░░█░░░░░░░░░░░░░░█░░░░░░░░░░░░░░█\r\n% ██████████████████████████████████████████████████\r\n\r\n% TODO\r\n% - Describe BIT A,(HL) undocumented flags from internal MEMPRT/WZ register\r\n% - Add testing code to appendices\r\n\r\n\\ChapterTOC\r\n\r\n% renders two column instruction table; parameters:\r\n% (optional) first column type; defaults to \"l\"\r\n% (optional) width ratio of the first column; defaults to 0.3\r\n% (required) first column\r\n% (required) second column\r\n% use \\TwoColumnInstr to render individual instruction\r\n\\NewDocumentCommand{\\TwoColumnInstructions}{ O{l} O{0.3} m m }{\r\n\t{\r\n\t\t\\tt \r\n\t\t\\vspace*{1em} % we need some spacing above tables\r\n\r\n\t\t\\begin{parcolumns}[colwidths={1=#2\\linewidth}]{2}\r\n\t\t\t\\colchunk{\r\n\t\t\t\t\\hspace*{0.25cm} % we want to inset left table inwards\r\n\t\t\t\t\\begin{tabularx}{\\linewidth}{#1X}\r\n\t\t\t\t\t#3\r\n\t\t\t\t\\end{tabularx}\r\n\t\t\t}\r\n\t\t\t\\colchunk{\r\n\t\t\t\t\\begin{tabularx}{\\linewidth}{#1X}\r\n\t\t\t\t\t#4\r\n\t\t\t\t\\end{tabularx}\r\n\t\t\t}\r\n\t\t\\end{parcolumns}\r\n\t}\r\n}\r\n\r\n% renders a title inside two column instruction; parameters:\r\n% (required) the title\r\n\\newcommand{\\TwoColumnTitle}[1]{\r\n\t\\multicolumn{2}{l}{\\rm #1} \\\\\r\n}\r\n\r\n% renders single instruction spanning accross whole width; parameters:\r\n% (required) the instruction to render\r\n\\newcommand{\\TwoColumnSingleInstr}[1]{\r\n\t\\multicolumn{2}{l}{#1} \\\\\r\n}\r\n\r\n% renders individual two column instruction; parameters:\r\n% (required) address\r\n% (required) instruction\r\n\\newcommand{\\TwoColumnInstr}[2]{\r\n\t#1 & #2 \\\\\r\n}\r\n\r\n\\pagebreak\r\n\\section{Overview}\r\n\\subsection{History of the Z80}\r\n\r\nIn 1969 Intel was approached by a Japanese company called Busicom to produce chips for Busicom's electronic desktop calculator. Intel suggested that the calculator should be built around a single-chip generalized computing engine and thus was born the first microprocessor - the 4004. Although it was based on ideas from a much larger mainframe and mini-computers the 4004 was cut down to fit onto a 16-pin chip, the largest that was available at the time, so that its data bus and address bus were each only 4-bits wide. \r\n\r\nIntel went on to improve the design and produced the 4040 (an improved 4-bit design) the 8008 (the first 8-bit microprocessor) and then in 1974 the 8080. This last one turned out to be a very useful and popular design and was used in the first home computer, the Altair 8800, and CP/M. \r\n\r\nIn 1975 Federico Faggin who had worked at Intel on the 4004 and its successors left the company and joined forces with Masatoshi Shima to form Zilog. At their new company, Faggin and Shima designed a microprocessor that was compatible with Intel's 8080 (it ran all 78 instructions of the 8080 in almost the same way that Intel's chip did)\\footnote{Thanks to Jim Battle (\\email{frustum}{pacbell}{net}): the 8080 always puts the parity in the PF flag; VF does not exist and the timing is different. Possibly there are other differences.} but had many more abilities (an extra 120 instructions, many more registers, simplified connection to hardware). Thus was born the mighty Z80, and thus was the empire forged!\r\n\r\nThe original Z80 was first released in July 1976, coincidentally Jan was born in the very same month. Since then newer versions have appeared with much of the same architecture but running at higher speeds. The original Z80 ran with a clock rate of 2.5MHz, the Z80A runs at 4MHz, the Z80B at 6MHz and the Z80H at 8Mhz. \r\n\r\nMany companies produced machines based around Zilog's improved chip during the 1970s and 80's and because the chip could run 8080 code without needing any changes to the code the perfect choice of the operating system was CP/M. \r\n\r\nAlso, Zilog has created a Z280, an enhanced version of the Zilog Z80 with a 16-bit architecture, introduced in July 1987. It added an MMU to expand addressing to 16Mb, features for multitasking, a 256-byte cache, and a huge number of new opcodes (giving a total of over 2000!). Its internal clock runs at 2 or 4 times the external clock (e.g. a 16MHz CPU with a 4MHz bus.\r\n\r\nThe Z380 CPU incorporates advanced architectural while maintaining Z80/Z180 object code compatibility. The Z380 CPU is an enhanced version of the Z80 CPU. The Z80 instruction set has been retained, adding a full complement of 16-bit arithmetic and logical operations, multiply and divide, a complete set of register-to-register loads and exchanges, plus 32-bit load and exchange, and 32-bit arithmetic operations for address calculations.\r\n\r\nThe addressing modes of the Z80 have been enhanced with Stack pointer relative loads and stores, 16-bit and 24-bit indexed offsets and more flexible indirect register addressing. All of the addressing modes allow access to the entire 32-bit addressing space.\r\n\r\n\r\n\\subsection{Pin Descriptions \\cite{datasheet}}\r\n\\label{z80_pin_descriptions}\r\n\r\nThis section might be relevant even if you don't do anything with hardware; it might give you insight into how the Z80 operates. Besides, it took me hours to draw this.\r\n\r\n{\\tt \r\n\t\\setlength{\\unitlength}{1mm}\r\n\t\\begin{picture}(50,80)\r\n\t\t\\multiput(11.8,2)(0,3.9){20}{\\framebox(2,2){}}\r\n\t\t\\multiput(36.2,2)(0,3.9){20}{\\framebox(2,2){}}\r\n\t\t\\thicklines \\footnotesize\r\n\t\t\\put(14,0){\\framebox(22,80){Z80 CPU}}\r\n\t\t\\put(25,80){\\oval(3,3)[b]}\r\n\t\t\\thinlines \r\n\t\t\\newcounter{pinno}\r\n\t\t\\multiput(15,76)(0,-3.9){20}{\\stepcounter{pinno}\\makebox(2,2){\\arabic{pinno}}}\r\n\t\t\\multiput(33,2)(0,3.9){20}{\\stepcounter{pinno}\\makebox(2,2)[r]{\\arabic{pinno}}}\r\n\r\n\t\t\\put(9,2){\\makebox(2,2)[r]{\\NoLinkChipPinLabel{IORQ}}}\r\n\t\t\\put(9,5.9){\\makebox(2,2)[r]{\\NoLinkChipPinLabel{MREQ}}}\r\n\t\t\\put(9,9.8){\\makebox(2,2)[r]{\\NoLinkChipPinLabel{HALT}}}\r\n\t\t\\put(9,13.7){\\makebox(2,2)[r]{\\NoLinkChipPinLabel{NMI}}}\r\n\t\t\\put(9,17.6){\\makebox(2,2)[r]{\\NoLinkChipPinLabel{INT}}}\r\n\t\t\\put(9,21.5){\\makebox(2,2)[r]{$\\mathtt{D_1}$}}\r\n\t\t\\put(9,25.4){\\makebox(2,2)[r]{$\\mathtt{D_0}$}}\r\n\t\t\\put(9,29.3){\\makebox(2,2)[r]{$\\mathtt{D_7}$}}\r\n\t\t\\put(9,33.2){\\makebox(2,2)[r]{$\\mathtt{D_2}$}}\r\n\t\t\\put(9,37.1){\\makebox(2,2)[r]{$\\mathtt{+ 5V}$}}\r\n\t\t\\put(9,41){\\makebox(2,2)[r]{$\\mathtt{D_6}$}}\r\n\t\t\\put(9,44.9){\\makebox(2,2)[r]{$\\mathtt{D_5}$}}\r\n\t\t\\put(9,48.8){\\makebox(2,2)[r]{$\\mathtt{D_3}$}}\r\n\t\t\\put(9,52.7){\\makebox(2,2)[r]{$\\mathtt{D_4}$}}\r\n\t\t\\put(9,56.6){\\makebox(2,2)[r]{$\\mathtt{CLK}$}}\r\n\t\t\\put(9,60.5){\\makebox(2,2)[r]{$\\mathtt{A_{15}}$}}\r\n\t\t\\put(9,64.4){\\makebox(2,2)[r]{$\\mathtt{A_{14}}$}}\r\n\t\t\\put(9,68.3){\\makebox(2,2)[r]{$\\mathtt{A_{13}}$}}\r\n\t\t\\put(9,72.2){\\makebox(2,2)[r]{$\\mathtt{A_{12}}$}}\r\n\t\t\\put(9,76.1){\\makebox(2,2)[r]{$\\mathtt{A_{11}}$}}\r\n\r\n\t\t\\put(39,2){\\makebox(2,2)[l]{\\NoLinkChipPinLabel{RD}}}\r\n\t\t\\put(39,5.9){\\makebox(2,2)[l]{\\NoLinkChipPinLabel{WR}}}\r\n\t\t\\put(39,9.8){\\makebox(2,2)[l]{\\NoLinkChipPinLabel{BUSACK}}}\r\n\t\t\\put(39,13.7){\\makebox(2,2)[l]{\\NoLinkChipPinLabel{WAIT}}}\r\n\t\t\\put(39,17.6){\\makebox(2,2)[l]{\\NoLinkChipPinLabel{BUSREQ}}}\r\n\t\t\\put(39,21.5){\\makebox(2,2)[l]{\\NoLinkChipPinLabel{RESET}}}\r\n\t\t\\put(39,25.4){\\makebox(2,2)[l]{\\NoLinkChipPinLabel{M1}}}\r\n\t\t\\put(39,29.3){\\makebox(2,2)[l]{\\NoLinkChipPinLabel{RFSH}}}\r\n\t\t\\put(39,33.2){\\makebox(2,2)[l]{$\\mathtt{GND}$}}\r\n\t\t\\put(39,37.1){\\makebox(2,2)[l]{$\\mathtt{A_0}$}}\r\n\t\t\\put(39,41.0){\\makebox(2,2)[l]{$\\mathtt{A_1}$}}\r\n\t\t\\put(39,44.9){\\makebox(2,2)[l]{$\\mathtt{A_2}$}}\r\n\t\t\\put(39,48.8){\\makebox(2,2)[l]{$\\mathtt{A_3}$}}\r\n\t\t\\put(39,52.7){\\makebox(2,2)[l]{$\\mathtt{A_4}$}}\r\n\t\t\\put(39,56.6){\\makebox(2,2)[l]{$\\mathtt{A_5}$}}\r\n\t\t\\put(39,60.5){\\makebox(2,2)[l]{$\\mathtt{A_{6}}$}}\r\n\t\t\\put(39,64.4){\\makebox(2,2)[l]{$\\mathtt{A_{7}}$}}\r\n\t\t\\put(39,68.3){\\makebox(2,2)[l]{$\\mathtt{A_{8}}$}}\r\n\t\t\\put(39,72.2){\\makebox(2,2)[l]{$\\mathtt{A_{9}}$}}\r\n\t\t\\put(39,76.1){\\makebox(2,2)[l]{$\\mathtt{A_{10}}$}}\r\n\r\n\t\\end{picture}\r\n}\r\n\r\n\\begin{description}[leftmargin=1.5em]\r\n\r\n\t\\item[$A_{15}$-${A_0}$] \r\n\t{\\em Address bus} (output, active high, 3-state). This bus is used for accessing the memory and for I/O ports. During the refresh cycle the IR register is put on this bus.\r\n\r\n\t\\item[\\NoLinkChipPinLabel{BUSACK}]\r\n\t{\\em Bus Acknowledge} (output, active low). Bus Acknowledge indicates to the requesting device that the CPU address bus, data bus, and control signals \\NoLinkChipPinLabel{MREQ}, \\NoLinkChipPinLabel{IORQ}, \\NoLinkChipPinLabel{RD} and \\NoLinkChipPinLabel{WR} have been entered into their high-impedance states. The external device now control these lines.\r\n\r\n\t\\item[\\NoLinkChipPinLabel{BUSREQ}]\r\n\t{\\em Bus Request} (input, active low). Bus Request has a higher priority than \\NoLinkChipPinLabel{NMI} and is always recognised at the end of the current machine cycle. \\NoLinkChipPinLabel{BUSREQ} forces the CPU address bus, data bus and control signals \\NoLinkChipPinLabel{MREQ}, \\NoLinkChipPinLabel{IORQ}, \\NoLinkChipPinLabel{RD} and \\NoLinkChipPinLabel{WR} to go to a high-impedance state so that other devices can control these lines. \\NoLinkChipPinLabel{BUSREQ} is normally wired-OR and requires an external pullup for these applications. Extended \\NoLinkChipPinLabel{BUSREQ} periods due to extensive DMA operations can prevent the CPU from refreshing dynamic RAMs.\r\n\r\n\t\\item[${D_7}$-${D_0}$]\r\n\t{\\em Data Bus} (input/output, active low, 3-state). Used for data exchanges with memory, I/O and interrupts.\r\n\r\n\t\\item[\\NoLinkChipPinLabel{HALT}]\r\n\t{\\em Halt State} (output, active low). Indicates that the CPU has executed a {\\tt HALT} instruction and is waiting for either a maskable or nonmaskable interrupt (with the mask enabled) before operation can resume. While halted, the CPU stops increasing the PC so the instruction is re-executed, to maintain memory refresh.\r\n\r\n\t\\item[\\NoLinkChipPinLabel{INT}]\r\n\t{\\em Interrupt Request} (input, active low). Interrupt Request is generated by I/O devices. The CPU honours a request at the end of the current instruction if {\\tt IFF1} is set. \\NoLinkChipPinLabel{INT} is normally wired-OR and requires an external pullup for these applications.\r\n\r\n\t\\item[\\NoLinkChipPinLabel{IORQ}]\r\n\t{\\em Input/Output Request} (output, active low, 3-state). Indicates that the address bus holds a valid I/O address for an I/O read or write operation. \\NoLinkChipPinLabel{IORQ} is also generated concurrently with \\NoLinkChipPinLabel{M1} during an interrupt acknowledge cycle to indicate that an interrupt response vector can be placed on the databus.\r\n\r\n\t\\item[\\NoLinkChipPinLabel{M1}]\r\n\t{\\em Machine Cycle One} (output, active low). \\NoLinkChipPinLabel{M1}, together with \\NoLinkChipPinLabel{MREQ}, indicates that the current machine cycle is the opcode fetch cycle of an instruction execution. \\NoLinkChipPinLabel{M1}, together with \\NoLinkChipPinLabel{IORQ}, indicates an interrupt acknowledge cycle.\r\n\r\n\t\\item[\\NoLinkChipPinLabel{MREQ}]\r\n\t{\\em Memory Request} (output, active low, 3-state). Indicates that the address holds a valid address for a memory read or write cycle operations.\r\n\r\n\t\\item[\\NoLinkChipPinLabel{NMI}]\r\n\t{\\em Non-Maskable Interrupt} (input, negative edge-triggered). \\NoLinkChipPinLabel{NMI} has a higher priority than \\NoLinkChipPinLabel{INT}. \\NoLinkChipPinLabel{NMI} is always recognised at the end of an instruction, independent of the status of the interrupt flip-flops and automatically forces the CPU to restart at location \\$0066.\r\n\r\n\t\\item[\\NoLinkChipPinLabel{RD}]\r\n\t{\\em Read} (output, active low, 3-state). Indicates that the CPU wants to read data from memory or an I/O device. The addressed I/O device or memory should use this signal to place data onto the data bus.\r\n\r\n\t\\item[\\NoLinkChipPinLabel{RESET}]\r\n\t{\\em Reset} (input, active low). Initializes the CPU as follows: it resets the interrupt flip-flops, clears the PC and IR registers, and set the interrupt mode to 0. During reset time, the address bus and data bus go to a high-impedance state, and all control output signals go to the inactive state. Note that \\NoLinkChipPinLabel{RESET} must be active for a minimum of three full clock cycles before the reset operation is complete. Note that Matt found that SP and AF are set to \\$FFFF.\r\n\r\n\t\\item[\\NoLinkChipPinLabel{RFSH}]\r\n\t{\\em Refresh} (output, active low). \\NoLinkChipPinLabel{RFSH}, together with \\NoLinkChipPinLabel{MREQ}, indicates that the IR registers are on the address bus (note that only the lower 7 bits are useful) and can be used for the refresh of dynamic memories.\r\n\r\n\t\\item[\\NoLinkChipPinLabel{WAIT}]\r\n\t{\\em Wait} (input, active low). Indicates to the CPU that the addressed memory or I/O device are not ready for data transfer. The CPU continues to enter a wait state as long as this signal is active. Note that during this period memory is not refreshed.\r\n\r\n\t\\item[\\NoLinkChipPinLabel{WR}]\r\n\t{\\em Write} (output, active low, 3-state). Indicates that the CPU wants to write data to memory or an I/O device. The addressed I/O device or memory should use this signal to store the data on the data bus.\r\n\r\n\\end{description}\r\n\r\n\r\n\\subsection{Power on Defaults}\r\n\\label{z80_power_on_defaults}\r\n\r\nMatt\\footnote{\\email{redflame}{xmission}{com}} has done some excellent research on this. He found that AF and SP are always set to \\MemAddr{FFFF} after a reset, and all other registers are undefined (different depending on how long the CPU has been powered off, different for different Z80 chips). Of course, the PC should be set to 0 after a reset, and so should the {\\tt IFF1} and {\\tt IFF2} flags (otherwise strange things could happen). Also since the Z80 is 8080 compatible, the interrupt mode is probably 0.\r\n\r\nProbably the best way to simulate this in an emulator is to set {\\tt PC}, {\\tt IFF1}, {\\tt IFF2}, {\\tt IM} to 0 and set all other registers to \\MemAddr{FFFF}.\r\n\r\n\r\n\\subsection{Registers}\r\n\r\n\\begin{tikzpicture}[\r\n\tframed/.style={draw, font=\\ttfamily, minimum width=1.1cm, minimum height=0.5cm},\r\n\tfilled/.style={framed, fill=PrintableLightGray},\r\n\tframeddouble/.style={framed, minimum width=2.2cm},\r\n\tfilleddouble/.style={filled, minimum width=2.2cm},\r\n\tdesc/.style={midway,xshift=1.5ex,anchor=west},\r\n\tcurly/.style={\r\n\t\tdecorate,\r\n\t\tdecoration={brace,amplitude=5pt,raise=3pt},\r\n\t\tline width=1pt,\r\n\t\tyshift=0pt,\r\n\t\tshorten >=1pt,\r\n\t\tshorten <=1pt\r\n\t}\r\n]\r\n\r\n\t\\node[framed] (a) {A};\r\n\t\\node[framed, right=0pt of a] (f) {F};\r\n\t\\draw[curly] (f.north east) -- (f.south east) node[desc] {Accumulator and Flags};\r\n\r\n\t\\node[filleddouble, below=0pt of a.south east] (bc) {BC};\r\n\t\\node[filleddouble, below=0pt of bc] (de) {DE};\r\n\t\\node[filleddouble, below=0pt of de] (hl) {HL};\r\n\t\\draw[curly] (bc.north east) -- (hl.south east) node[desc] {General purpose registers};\r\n\r\n\t\\node[frameddouble, below=0pt of hl] (ix) {IX};\r\n\t\\node[frameddouble, below=0pt of ix] (iy) {IY};\r\n\t\\draw[curly] (ix.north east) -- (iy.south east) node[desc] {Index registers};\r\n\r\n\t\\node[filleddouble, below=0pt of iy] (pc) {PC};\r\n\t\\node[filleddouble, below=0pt of pc] (sp) {SP};\r\n\t\\node[filled, below=0pt of sp.south west, anchor=north west] (i) {I};\r\n\t\\node[filled, right=0pt of i] (r) {R};\r\n\t\\draw[curly] (pc.north east) -- (r.south east) node[desc] {Special purpose registers};\r\n\r\n\t\\node[frameddouble, below=0pt of i.south east] (afe) {AF'};\r\n\t\\node[frameddouble, below=0pt of afe] (bce) {BC'};\r\n\t\\node[frameddouble, below=0pt of bce] (dee) {DE'};\r\n\t\\node[frameddouble, below=0pt of dee] (hle) {HL'};\r\n\t\\draw[curly] (afe.north east) -- (hle.south east) node[desc] {Alternate general purpose registers};\r\n\r\n\\end{tikzpicture}\r\n\r\n\r\n\\subsection{Flags}\r\n\\label{z80_flags}\r\n\r\nThe conventional way of denoting the flags is with one letter, ``C'' for the carry flag for example. It could be confused with the C register, so I've chosen to use the ``CF'' notation for flags (except ``P'' which uses ``PV'' notation due to having dual-purpose, either as parity or overflow). And for YF and XF the same notation is used in MAME\\footnote{\\url{http://www.mame.net/}}.\r\n\r\n\\begin{tabular}{|l|c|c|c|c|c|c|c|c|} \r\n\t\\hline\r\n\tbit & 7 & 6 & 5 & 4 & 3 & 2 & 1 & 0 \\instrt\\instrb \\\\\r\n\t\\hline\r\n\tflag & SF & ZF & YF & HF & XF & PF & NF & CF \\instrt\\instrb \\\\ \r\n\t\\hline\r\n\\end{tabular}\r\n\r\n\\begin{description}\r\n\r\n\t\\item[SF]\r\n\tSet if the 2-complement value is negative; simply a copy of the most significant bit.\r\n\r\n\t\\item[ZF]\r\n\tSet if the result is zero.\r\n\r\n\t\\item[YF]\r\n\tA copy of bit 5 of the result.\r\n\r\n\t\\item[HF]\r\n\tThe half-carry of an addition/subtraction (from bit 3 to 4). Needed for BCD correction with {\\tt DAA}.\r\n\r\n\t\\item[XF]\r\n\tA copy of bit 3 of the result.\r\n\r\n\t\\item[PV]\r\n\tThis flag can either be the parity of the result (PF), or the 2-complement signed overflow (VF): set if 2-complement value doesn't fit in the register.\r\n\r\n\t\\item[NF]\r\n\tShows whether the last operation was an addition (0) or a subtraction (1). This information is needed for {\\tt DAA}.\\footnote{Wouldn't it be better to have separate instructions for {\\tt DAA} after addition and subtraction, like the 80x86 has instead of sacrificing a bit in the flag register?}\r\n\r\n\t\\item[CF]\r\n\tThe carry flag, set if there was a carry after the most significant bit.\r\n\r\n\\end{description}\r\n\r\n\r\n\\section{Undocumented Opcodes}\r\n\r\nThere are quite a few undocumented opcodes/instructions. This section should describe every possible opcode so you know what will be executed, whatever the value of the opcode is.\r\n\r\nThe following prefixes exist: {\\tt CB}, {\\tt ED}, {\\tt DD}, {\\tt FD}, {\\tt DDCB} and {\\tt FDCB}. Prefixes change the way the following opcodes are interpreted. All instructions without a prefix (not a value of one the above) are single-byte opcodes (without the operand, that is), which are documented in the official documentation.\r\n\r\n\r\n\\subsection{CB Prefix \\cite{gerton}}\r\n\\label{z80_undocumented_prefix_cb}\r\n\r\nAn opcode with a {\\tt CB} prefix is a rotate, shift or bit test/set/reset instruction. A few instructions are missing from the official list, for example {\\tt SLL} (Shift Logical Left). It works like {\\tt SLA}, for one exception: it sets bit 0 ({\\tt SLA} resets it).\r\n\r\n\\TwoColumnInstructions{\r\n\t\\TwoColumnInstr{CB30}{SLL B}\r\n\t\\TwoColumnInstr{CB31}{SLL C}\r\n\t\\TwoColumnInstr{CB32}{SLL D}\r\n\t\\TwoColumnInstr{CB33}{SLL E}\r\n}{\r\n\t\\TwoColumnInstr{CB34}{SLL H}\r\n\t\\TwoColumnInstr{CB35}{SLL L}\r\n\t\\TwoColumnInstr{CB36}{SLL (HL)}\r\n\t\\TwoColumnInstr{CB37}{SLL A}\r\n}\r\n\r\n\\subsection{DD Prefix \\cite{gerton}}\r\n\r\nIn general, the instruction following the {\\tt DD} prefix is executed as is, but if the {\\tt HL} register is supposed to be used the {\\tt IX} register is used instead. Here are the rules:\r\n\r\n\\begin{itemize}[topsep=1pt,itemsep=1pt]\r\n\t\\item Any usage of {\\tt HL} is treated as an access to {\\tt IX} (except {\\tt EX DE,HL} and {\\tt EXX} and the {\\tt ED} prefixed instructions that use {\\tt HL}).\r\n\t\r\n\t\\item Any access to {\\tt (HL)} is changed to {\\tt (IX+d)}, where ``d'' is a signed displacement byte placed after the main opcode - except {\\tt JP (HL)}, which isn't indirect anyway. The mnemonic should be {\\tt JP HL}.\r\n\t\r\n\t\\item Any access to {\\tt H} is treated as an access to {\\tt IX\\High} (the high byte of {\\tt IX}) except if {\\tt (IX+d)} is used as well.\r\n\t\r\n\t\\item Any access to {\\tt L} is treated as an access to {\\tt IX\\Low} (the low byte of {\\tt IX}) except if {\\tt (IX+d)} is used as well.\r\n\t\r\n\t\\item A {\\tt DD} prefix before a {\\tt CB} selects a completely different instruction set, see section {\\XRef{z80_undocumented_prefix_cbdd}}.\r\n\\end{itemize}\r\n\r\nSome examples:\r\n\r\n\\TwoColumnInstructions[p{2.3cm}][0.4]{\r\n\t\\TwoColumnInstr{\\rm Without}{\\rm With {\\tt DD} prefix}\r\n\t\\TwoColumnInstr{LD H, (HL)}{LD H, (IX+d)}\r\n\t\\TwoColumnInstr{LD H, A}{LD IXH, A}\r\n\t\\TwoColumnInstr{LD L, H}{LD IXL, IXH}\r\n}{\r\n\t\\TwoColumnInstr{\\rm Without}{\\rm With {\\tt DD} prefix}\r\n\t\\TwoColumnInstr{JP (HL)}{JP (IX)}\r\n\t\\TwoColumnInstr{LD DE, 0}{LD DE, 0}\r\n\t\\TwoColumnInstr{LD HL, 0}{LD IX, 0}\r\n}\r\n\r\n\r\n\\subsection{ED Prefix \\cite{gerton}}\r\n\r\nThere are a number of undocumented {\\tt EDxx} instructions, of which most are duplicates of documented instructions. Any instruction not listed here has no effect (same as 2 {\\tt NOP}s). \\See{**} indicates undocumented instruction:\r\n\r\n\\TwoColumnInstructions{\r\n\t\\TwoColumnInstr{ED40}{IN B, (C)}\r\n\t\\TwoColumnInstr{ED41}{OUT (C), B}\r\n\t\\TwoColumnInstr{ED42}{SBC HL, BC}\r\n\t\\TwoColumnInstr{ED43}{LD (nn), BC}\r\n\t\\TwoColumnInstr{ED44}{NEG}\r\n\t\\TwoColumnInstr{ED45}{RETN}\r\n\t\\TwoColumnInstr{ED46}{IM 0}\r\n\t\\TwoColumnInstr{ED47}{LD I, A}\r\n\t\\TwoColumnInstr{ED48}{IN C, (C)}\r\n\t\\TwoColumnInstr{ED49}{OUT (C), C}\r\n\t\\TwoColumnInstr{ED4A}{ADC HL, BC}\r\n\t\\TwoColumnInstr{ED4B}{LD BC, (nn)}\r\n\t\\TwoColumnInstr{ED4C}{NEG\\See{**}}\r\n\t\\TwoColumnInstr{ED4D}{RETI}\r\n\t\\TwoColumnInstr{ED4E}{IM 0\\See{**}}\r\n\t\\TwoColumnInstr{ED4F}{LD R, A}\r\n}{\r\n\t\\TwoColumnInstr{ED50}{IN D, (C)}\r\n\t\\TwoColumnInstr{ED51}{OUT (C), D}\r\n\t\\TwoColumnInstr{ED52}{SBC HL, DE}\r\n\t\\TwoColumnInstr{ED53}{LD (nn), DE}\r\n\t\\TwoColumnInstr{ED54}{NEG\\See{**}}\r\n\t\\TwoColumnInstr{ED55}{RETN\\See{**}}\r\n\t\\TwoColumnInstr{ED56}{IM 1}\r\n\t\\TwoColumnInstr{ED57}{LD A, I}\r\n\t\\TwoColumnInstr{ED58}{IN E, (C)}\r\n\t\\TwoColumnInstr{ED59}{OUT (C), E}\r\n\t\\TwoColumnInstr{ED5A}{ADC HL, DE}\r\n\t\\TwoColumnInstr{ED5B}{LD DE, (nn)}\r\n\t\\TwoColumnInstr{ED5C}{NEG\\See{**}}\r\n\t\\TwoColumnInstr{ED5D}{RETN\\See{**}}\r\n\t\\TwoColumnInstr{ED5E}{IM 2}\r\n\t\\TwoColumnInstr{ED5F}{LD A, R}\r\n}\r\n\r\n\\TwoColumnInstructions{\r\n\t\\TwoColumnInstr{ED60}{IN H, (C)}\r\n\t\\TwoColumnInstr{ED61}{OUT (C), H}\r\n\t\\TwoColumnInstr{ED62}{SBC HL, HL}\r\n\t\\TwoColumnInstr{ED63}{LD (nn), HL}\r\n\t\\TwoColumnInstr{ED64}{NEG\\See{**}}\r\n\t\\TwoColumnInstr{ED65}{RETN\\See{**}}\r\n\t\\TwoColumnInstr{ED66}{IM 0\\See{**}}\r\n\t\\TwoColumnInstr{ED67}{RRD}\r\n\t\\TwoColumnInstr{ED68}{IN L, (C)}\r\n\t\\TwoColumnInstr{ED69}{OUT (C), L}\r\n\t\\TwoColumnInstr{ED6A}{ADC HL, HL}\r\n\t\\TwoColumnInstr{ED6B}{LD HL, (nn)}\r\n\t\\TwoColumnInstr{ED6C}{NEG\\See{**}}\r\n\t\\TwoColumnInstr{ED6D}{RETN\\See{**}}\r\n\t\\TwoColumnInstr{ED6E}{IM 0\\See{**}}\r\n\t\\TwoColumnInstr{ED6F}{RLD}\r\n}{\r\n\t\\TwoColumnInstr{ED70}{IN (C) / IN F, (C)\\See{**}}\r\n\t\\TwoColumnInstr{ED71}{OUT (C), 0\\See{**}}\r\n\t\\TwoColumnInstr{ED72}{SBC HL, SP}\r\n\t\\TwoColumnInstr{ED73}{LD (nn), SP}\r\n\t\\TwoColumnInstr{ED74}{NEG\\See{**}}\r\n\t\\TwoColumnInstr{ED75}{RETN\\See{**}}\r\n\t\\TwoColumnInstr{ED76}{IM 1\\See{**}}\r\n\t\\TwoColumnInstr{ED77}{NOP\\See{**}}\r\n\t\\TwoColumnInstr{ED78}{IN A, (C)}\r\n\t\\TwoColumnInstr{ED79}{OUT (C), A}\r\n\t\\TwoColumnInstr{ED7A}{ADC HL, SP}\r\n\t\\TwoColumnInstr{ED7B}{LD SP, (nn)}\r\n\t\\TwoColumnInstr{ED7C}{NEG\\See{**}}\r\n\t\\TwoColumnInstr{ED7D}{RETN\\See{**}}\r\n\t\\TwoColumnInstr{ED7E}{IM 2\\See{**}}\r\n\t\\TwoColumnInstr{ED7F}{NOP\\See{**}}\r\n}\r\n\r\nThe {\\tt ED70} instruction reads from I/O port {\\tt C}, but does not store the result. It just affects the flags like the other {\\tt IN x,(C)} instructions. {\\tt ED71} simply outs the value 0 to I/O port {\\tt C}.\r\n\r\nThe {\\tt ED63} is a duplicate of the 22 opcode ({\\tt LD (nn),HL}) and similarly {\\tt ED6B} is a duplicate of the {\\tt 2A} opcode ({\\tt LD HL,(nn)}). Of course the timings are different. These instructions are listed in the official documentation.\r\n\r\n\\pagebreak\r\nAccording to Gerton Lunter\\footnote{\\email{gerton}{math.rug}{nl}}:\r\n\r\n\\begin{quote}\r\n\tThe instructions {\\tt ED 4E} and {\\tt ED 6E} are {\\tt IM 0} equivalents: when {\\tt FF} was put on the bus (physically) at interrupt time, the Spectrum continued to execute normally, whereas when an {\\tt EF} ({\\tt RST \\$28}) was put on the bus it crashed, just as it does in that case when the Z80 is in the official interrupt mode 0. In {\\tt IM 1} the Z80 just executes a {\\tt RST \\$38} (opcode {\\tt FF}) no matter what is on the bus.\r\n\\end{quote}\r\n\r\nAll the {\\tt RETI/RETN} instructions are the same, all like the {\\tt RETN} instruction. So they all, including {\\tt RETI}, copy {\\tt IFF2} to {\\tt IFF1}. See section \\XRef{z80_interrupts_flipflop} for more information on {\\tt RETI} and {\\tt RETN} and {\\tt IM x}.\r\n\r\n\r\n\\subsection{FD Prefix \\cite{gerton}}\r\n\r\nThis prefix has the same effect as the {\\tt DD} prefix, though {\\tt IY} is used instead of {\\tt IX}.  Note {\\tt LD IXL}, {\\tt IYH} is not possible: only {\\tt IX} or {\\tt IY} is accessed in one instruction, never both.\r\n\r\n\r\n\\subsection{DDCB Prefix}\r\n\\label{z80_undocumented_prefix_cbdd}\r\n\r\nThe undocumented {\\tt DDCB} instructions store the result (if any) of the operation in one of the seven all-purpose registers. Which one depends on the lower 3 bits of the last byte of the opcode (not operand, so not the offset).\r\n\r\n\\TwoColumnInstructions{\r\n\t\\TwoColumnInstr{000}{B}\r\n\t\\TwoColumnInstr{001}{C}\r\n\t\\TwoColumnInstr{010}{D}\r\n\t\\TwoColumnInstr{011}{E}\r\n}{\r\n\t\\TwoColumnInstr{100}{H}\r\n\t\\TwoColumnInstr{101}{L}\r\n\t\\TwoColumnInstr{110}{\\normalfont{(none: documented opcode)}}\r\n\t\\TwoColumnInstr{111}{A}\r\n}\r\n\r\nThe documented {\\tt DDCB0106} is {\\tt RLC (IX+\\$01)}. So, clear the lower three bits ({\\tt DDCB0100}) and something is done to register {\\tt B}. The result of the {\\tt RLC} (which is stored in {\\tt (IX+\\$01)}) is now also stored in register {\\tt B}. Effectively, it does the following:\r\n\r\n\\begin{tcblisting}{}\r\n\tLD B, (IX+&01)\r\n\tRLC B\r\n\tLD (IX+&01), B\r\n\\end{tcblisting}\r\n\r\nSo you get double value for money. The result is stored in {\\tt B} and {\\tt (IX+\\$01)}. The most common notation is: {\\tt RLC (IX+\\$01), B}\r\n\r\nI've once seen this notation:\r\n\r\n\\begin{tcblisting}{}\r\n\tRLC (IX+&01)\r\n\tLD B, (IX+&01)\r\n\\end{tcblisting}\r\n\r\nThat's not correct: {\\tt B} contains the rotated value, even if {\\tt (IX+\\$01)} points to ROM.\r\n\r\nThe {\\tt DDCB} {\\tt SET} and {\\tt RES} instructions do the same thing as the shift/rotate instructions:\r\n\r\n\\TwoColumnInstructions[p{2.2cm}][0.9]{\r\n\t\\TwoColumnInstr{DDCB10C0}{SET 0, (IX+\\$10), B}\r\n\t\\TwoColumnInstr{DDCB10C1}{SET 0, (IX+\\$10), C}\r\n\t\\TwoColumnInstr{DDCB10C2}{SET 0, (IX+\\$10), D}\r\n\t\\TwoColumnInstr{DDCB10C3}{SET 0, (IX+\\$10), E}\r\n\t\\TwoColumnInstr{DDCB10C4}{SET 0, (IX+\\$10), H}\r\n\t\\TwoColumnInstr{DDCB10C5}{SET 0, (IX+\\$10), L}\r\n\t\\TwoColumnInstr{DDCB10C6}{SET 0, (IX+\\$10) {\\rm - documented instruction}}\r\n\t\\TwoColumnInstr{DDCB10C7}{SET 0, (IX+\\$10), A}\r\n}{}\r\n\r\nSo for example with the last instruction, the value of {\\tt (IX+\\$10)} with bit 0 set is also stored in register {\\tt A}.\r\n\r\nThe {\\tt DDCB} {\\tt BIT} instructions do not store any value; they merely test a bit. That's why the undocumented {\\tt DDCB} {\\tt BIT} instructions are no different from the official ones:\r\n\r\n\\TwoColumnInstructions[p{2.2cm}][0.9]{\r\n\t\\TwoColumnInstr{DDCB d 78}{BIT 7, (IX+d)}\r\n\t\\TwoColumnInstr{DDCB d 79}{BIT 7, (IX+d)}\r\n\t\\TwoColumnInstr{DDCB d 7A}{BIT 7, (IX+d)}\r\n\t\\TwoColumnInstr{DDCB d 7B}{BIT 7, (IX+d)}\r\n\t\\TwoColumnInstr{DDCB d 7C}{BIT 7, (IX+d)}\r\n\t\\TwoColumnInstr{DDCB d 7D}{BIT 7, (IX+d)}\r\n\t\\TwoColumnInstr{DDCB d 7E}{BIT 7, (IX+d) {\\rm - documented instruction}}\r\n\t\\TwoColumnInstr{DDCB d 7F}{BIT 7, (IX+d)}\r\n}{}\r\n\r\n\r\n\\subsection{FDCB Prefixes}\r\n\r\nSame as for the {\\tt DDCB} prefix, though {\\tt IY} is used instead of {\\tt IX}.\r\n\r\n\r\n\\subsection{Combinations of Prefixes}\r\n\r\nThis part may be of some interest to emulator coders. Here we define what happens if strange sequences of prefixes appear in the instruction cycle of the Z80.\r\n\r\nIf {\\tt CB} or {\\tt ED} is encountered, that byte plus the next make up an instruction. {\\tt FD} or {\\tt DD} should be seen as prefix setting a flag which says ``use {\\tt IX} or {\\tt IY} instead of {\\tt HL}'', and not an instruction. In a large sequence of {\\tt DD} and {\\tt FD} bytes, it is the last one that counts. Also any other byte (or instruction) resets this flag.\r\n\r\n{\\tt {\\qquad}FD DD 00 21 00 10{\\qquad}NOP NOP NOP LD HL, \\$1000}\r\n\r\n\r\n\r\n\r\n\\section{Undocumented Effects}\r\n\r\n\\subsection{BIT Instructions}\r\n\\label{z80_undocumented_flags_bit}\r\n\r\n{\\tt BIT n,r} behaves much like {\\tt AND r,2{\\raisebox{1ex}{n}}} with the result thrown away, and CF flag unaffected. Compare {\\tt BIT 7,A} with {\\tt AND \\$80}: flag YF and XF are reset, SF is set if bit 7 was actually set; ZF is set if the result was 0 (bit was reset), and PV is effectively set if ZF is set (the result of the AND leaves either no bits set (PV set - parity even) or one bit set (PV reset - parity odd). So the rules for the flags are:\r\n\r\n\\begin{description}\r\n\t\\item[SF flag]\r\n\tSet if n = 7 and tested bit is set.\r\n\r\n\t\\item[ZF flag]\r\n\tSet if the tested bit is reset.\r\n\r\n\t\\item[YF flag]\r\n\tSet if n = 5 and tested bit is set.\r\n\r\n\t\\item[HF flag]\r\n\tAlways set.\r\n\r\n\t\\item[XF flag]\r\n\tSet if n = 3 and tested bit is set.\r\n\r\n\t\\item[PV flag]\r\n\tSet just like ZF flag.\r\n\r\n\t\\item[NF flag]\r\n\tAlways reset. \r\n\r\n\t\\item[CF flag]\r\n\tUnchanged.\r\n\r\n\\end{description}\r\n\r\nThis is where things start to get strange. With the {\\tt BIT n,(IX+d)} instructions, the flags behave just like the {\\tt BIT n,r} instruction, except for YF and XF. These are not copied from the result but from something completely different, namely bit 5 and 3 of the high byte of {\\tt IX+d} (so {\\tt IX} plus the displacement).\r\n\r\nThings get more bizarre with the {\\tt BIT n,(HL)} instruction. Again, except for YF and XF, the flags are the same. YF and XF are copied from some sort of internal register. This register is related to 16-bit additions. Most instructions do not change this register. Unfortunately, I haven't tested all instructions yet, but here is the list so far:\r\n\r\n\\begin{tabularx}{\\linewidth}{@{}lX}\r\n\t{\\tt ADD HL, xx}\r\n\t\t& Use high byte of {\\tt HL}, ie. {\\tt H} before the addition. \\\\\r\n\r\n\t{\\tt LD r, (IX+d)}\r\n\t\t& Use high byte of the resulting address {\\tt IX+d}. \\\\\r\n\r\n\t{\\tt JR d}\r\n\t\t& Use high byte target address of the jump. \\\\\r\n\r\n\t{\\tt LD r, r'}\r\n\t\t& Doesn't change this register. \\\\\r\n\\end{tabularx}\r\n\r\nAny help here would be most appreciated!\r\n\r\n\r\n\\pagebreak\r\n\\subsection{Memory Block Instructions \\cite{mrison}}\r\n\\label{z80_undocumented_instructions_memory_block}\r\n\r\nThe {\\tt LDI}/{\\tt LDIR}/{\\tt LDD}/{\\tt LDDR} instructions affect the flags in a strange way. At every iteration, a byte is copied. Take that byte and add the value of register {\\tt A} to it. Call that value {\\tt n}. Now, the flags are:\r\n\r\n\\begin{description}\r\n \r\n\t\\item[YF flag]\r\n\tA copy of bit 1 of n.\r\n\r\n\t\\item[HF flag]\r\n\tAlways reset.\r\n\r\n\t\\item[XF flag]\r\n\tA copy of bit 3 of n.\r\n\r\n\t\\item[PV flag]\r\n\tSet if BC not 0.\r\n\r\n\t\\item[SF, ZF, CF flags]\r\n\tThese flags are unchanged.\r\n\r\n\\end{description}\r\n\r\nAnd now for {\\tt CPI}/{\\tt CPIR}/{\\tt CPD}/{\\tt CPDR}. These instructions compare a series of bytes in memory to register {\\tt A}. Effectively, it can be said they perform {\\tt CP (HL)} at every iteration. The result of that comparison sets the HF flag, which is important for the next step. Take the value of register {\\tt A}, subtract the value of the memory address, and finally subtract the value of HF flag, which is set or reset by the hypothetical {\\tt CP (HL)}. So, {\\tt n=A-(HL)-HF}.\r\n\r\n\\begin{description}\r\n\r\n\t\\item[SF, ZF, HF flags]\r\n\tSet by the hypothetical {\\tt CP (HL)}.\r\n\r\n\t\\item[YF flag]\r\n\tA copy of bit 1 of {\\tt n}.\r\n\r\n\t\\item[XF flag]\r\n\tA copy of bit 3 of {\\tt n}.\r\n\r\n\t\\item[PV flag]\r\n\tSet if BC is not 0.\r\n\r\n\t\\item[NF flag]\r\n\tAlways set.\r\n\r\n\t\\item[CF flag]\r\n\tUnchanged.\r\n\r\n\\end{description}\r\n\r\n\r\n\\subsection{I/O Block Instructions}\r\n\\label{z80_undocumented_instructions_io_block}\r\n\r\nThese are the most bizarre instructions, as far as the flags are concerned. Ramsoft found all of the flags. The ``out'' instructions behave differently than the ``in'' instructions, which doesn't make the CPU very symmetrical. \r\n\r\nFirst of all, all instructions affect the following flags:\r\n\r\n\\begin{description}\r\n\r\n\t\\item[SF, ZF, YF, XF flags]\r\n\tAffected by decreasing register B, as in {\\tt DEC B}.\r\n\r\n\t\\item[NF flag]\r\n\tA copy of bit 7 of the value read from or written to an I/O port.\r\n\r\n\\end{description}\r\n\r\n\\pagebreak % we want to keep this paragraph with description below to avoid page flipping\r\nAnd now the for {\\tt OUTI}/{\\tt OTIR}/{\\tt OUTD}/{\\tt OTDR} instructions. Take the state of the {\\tt L} after the increment or decrement of HL; add the value written to the I/O port; call that {\\tt k} for now. If {\\tt k} $>$ 255, then the CF and HF flags are set. The PV flag is set like the parity of {\\tt k} bitwise and'ed with 7, bitwise xor'ed with {\\tt B}.\r\n\r\n\\begin{description}\r\n\r\n\t\\item[HF and CF]\r\n\tBoth set if {\\tt ((HL) + L  $>$ 255)}\r\n\r\n\t\\item[PV]\r\n\tThe parity of {\\tt ((((HL) + L) $\\wedge$ 7) $\\veebar$ B)}\r\n\r\n\\end{description}\r\n\r\n{\\tt INI}/{\\tt INIR}/{\\tt IND}/{\\tt INDR} use the {\\tt C} register instead of the {\\tt L} register. There is a catch though, because not the value of {\\tt C} is used, but {\\tt C + 1} if it's {\\tt INI}/{\\tt INIR} or {\\tt C - 1} if it's {\\tt IND}/{\\tt INDR}. So, first of all {\\tt INI}/{\\tt INIR}:\r\n\r\n\\begin{description}\r\n\r\n\t\\item[HF and CF]\r\n\tBoth set if {\\tt ((HL) + ((C + 1) $\\wedge$ 255)  $\\veebar$ 255)}\r\n\r\n\t\\item[PF]\r\n\tThe parity of {\\tt (((HL) + ((C + 1) $\\wedge$ 255)) $\\wedge$ 7) $\\veebar$ B)}\r\n\r\n\\end{description}\r\n\r\nAnd last {\\tt IND}/{\\tt INDR}:\r\n\r\n\\begin{description}\r\n\r\n\t\\item[HF and CF]\r\n\tBoth set if {\\tt ((HL) + ((C - 1) $\\wedge$ 255) $>$ 255)}\r\n\r\n\t\\item[PF]\r\n\tThe parity of {\\tt (((HL) + ((C - 1) $\\wedge$ 255)) $\\wedge$ 7) $\\veebar$ B)}\r\n\r\n\\end{description}\r\n\r\n\r\n\\subsection{16 Bit I/O ports}\r\n\r\nOfficially the Z80 has an 8-bit I/O port address space. When using the I/O ports, the 16 address lines are used. And in fact, the high 8 bits do have some value, so you can use 65536 ports after all. {\\tt IN r, (C)}, {\\tt OUT (C), r}, and the block I/O instructions actually place the entire {\\tt BC} register on the address bus. Similarly {\\tt IN A, (n)} and {\\tt OUT (n), A} put {\\tt A $\\times$256 + n} on the address bus.\r\n\r\nThe {\\tt INI}, {\\tt INIR}, {\\tt IND} and {\\tt INDR} instructions use {\\tt BC} before decrementing {\\tt B}, and the {\\tt OUTI}, {\\tt OTIR}, {\\tt OUTD} and {\\tt OTDR} instructions use {\\tt BC} after decrementing.\r\n\r\n\r\n\\subsection{Block Instructions}\r\n\r\nThe repeated block instructions simply decrement the {\\tt PC} by two so the instruction is simply re-executed. So interrupts can occur during block instructions. So, {\\tt LDIR} is simply {\\tt LDI} + if {\\tt BC} is not {\\tt 0}, decrement {\\tt PC} by {\\tt 2}.\r\n\r\n\r\n\\subsection{16 Bit Additions}\r\n\r\nThe 16-bit additions are a bit more complicated than the 8-bit ones. Since the Z80 is an 8-bit CPU, 16-bit additions are done in two stages: first, the lower bytes are added, then the two higher bytes. The SF, YF, HF, XF flags are affected by the second (high) 8-bit addition. ZF is set if the whole 16-bit result is 0.\r\n\r\n\r\n\\subsection{DAA Instruction}\r\n\\label{z80_undocumented_instruction_daa}\r\n\r\nThis instruction is useful when you're using BCD values. After addition or subtraction, {\\tt DAA} corrects the value back to BCD again.  Note that it uses the CF flag, so it cannot be used after {\\tt INC} and {\\tt DEC}.\r\n\r\nStefano Donati from Ramsoft\\footnote{http://www.ramsoft.bbk.org/} has found the tables which describe the {\\tt DAA} operation. The input is the A register and the CF, NF, HF flags. The result is as follows:\r\n\r\n{\r\n\t\\footnotesize\r\n\r\n\t\\begin{tabular}{b{5.8cm}b{4.8cm}b{4.8cm}}\r\n\t\tDepending on the NF flag, the ``diff'' from this table must be added (NF is reset) or subtracted (NF is set) to {\\tt A}:\r\n\t\t&\r\n\t\tCF flag is affected:\r\n\t\t&\r\n\t\tHF flag is affected: \\\\\r\n\t\\end{tabular}\r\n\r\n\t\\begin{tabular}{p{5.8cm}p{4.8cm}p{4.8cm}}\r\n\r\n\t\t% ----------------------------------\r\n\t\t% | NF | CF |  hi | HF |  lo | add |\r\n\t\t% |----|----|-----|----|-----|-----|\r\n\t\t% |  0 |  0 | 0-9 |  0 | 0-9 |  00 |\r\n\t\t% |  0 |  0 | 0-9 |  1 | 0-9 |  06 |\r\n\t\t% |  0 |  0 | 0-8 |  * | a-f |  06 |\r\n\t\t% |  0 |  0 | a-f |  0 | 0-9 |  60 |\r\n\t\t% |  0 |  1 |  *  |  0 | 0-9 |  60 |\r\n\t\t% |  0 |  1 |  *  |  1 | 0-9 |  66 |\r\n\t\t% |  0 |  1 |  *  |  * | a-f |  66 |\r\n\t\t% |  0 |  0 | 9-f |  * | a-f |  66 |\r\n\t\t% |  0 |  0 | a-f |  1 | 0-9 |  66 |\r\n\t\t% ----------------------------------\r\n\t\t% |  1 |  0 | 0-9 |  0 | 0-9 |  00 |\r\n\t\t% |  1 |  0 | 0-9 |  1 | 0-9 |  fa |\r\n\t\t% |  1 |  0 | 0-8 |  * | a-f |  fa |\r\n\t\t% |  1 |  0 | a-f |  0 | 0-9 |  a0 |\r\n\t\t% |  1 |  1 |  *  |  0 | 0-9 |  a0 |\r\n\t\t% |  1 |  1 |  *  |  1 | 0-9 |  9a |\r\n\t\t% |  1 |  1 |  *  |  * | a-f |  9a |\r\n\t\t% |  1 |  0 | 9-f |  * | a-f |  9a |\r\n\t\t% |  1 |  0 | a-f |  1 | 0-9 |  9a |\r\n\t\t% ----------------------------------\r\n\t\t{\\tt\r\n\t\t\t\\begin{tabular}[t]{c|c|c|c|c}\r\n\t\t\t\t   &  high   &    & low    &  \\\\\r\n\t\t\t\tCF &  nibble & HF & nibble & diff \\\\\r\n\t\t\t\t\\hline\r\n\t\t\t\t0 & 0-9     &  0 & 0-9    &  00  \\\\\r\n\t\t\t\t0 & 0-9     &  1 & 0-9    &  06  \\\\\r\n\t\t\t\t0 & 0-8     &  * & A-F    &  06  \\\\\r\n\t\t\t\t0 & A-F     &  0 & 0-9    &  60  \\\\\r\n\t\t\t\t1 &  *      &  0 & 0-9    &  60  \\\\\r\n\t\t\t\t1 &  *      &  1 & 0-9    &  66  \\\\\r\n\t\t\t\t1 &  *      &  * & A-F    &  66  \\\\\r\n\t\t\t\t0 & 9-F     &  * & A-F    &  66  \\\\\r\n\t\t\t\t0 & A-F     &  1 & 0-9    &  66  \\\\\r\n\t\t\t\t\\hline\r\n\t\t\t\\end{tabular}\r\n\t\t}\r\n\r\n\t\t&\r\n\r\n\t\t% ------------------------\r\n\t\t% | CF |  hi |  lo | CF' |\r\n\t\t% |----|-----|-----|-----|\r\n\t\t% |  0 | 0-9 | 0-9 |  0  |\r\n\t\t% |  0 | 0-8 | a-f |  0  |\r\n\t\t% |  0 | 9-f | a-f |  1  |\r\n\t\t% |  0 | a-f | 0-9 |  1  |\r\n\t\t% |  1 |  *  |  *  |  1  |\r\n\t\t% ------------------------\r\n\t\t{\\tt\r\n\t\t\t\\begin{tabular}[t]{c|c|c|c}\r\n\t\t\t\t   & high   & low    & \\\\\r\n\t\t\t\tCF & nibble & nibble & CF' \\\\ \t\r\n\t\t\t\t\\hline\r\n\t\t\t\t0 & 0-9    & 0-9    &  0  \\\\\r\n\t\t\t\t0 & 0-8    & A-F    &  0  \\\\\r\n\t\t\t\t0 & 9-F    & A-F    &  1  \\\\\r\n\t\t\t\t0 & A-F    & 0-9    &  1  \\\\\r\n\t\t\t\t1 &  *     &  *     &  1  \\\\ \r\n\t\t\t\t\\hline\r\n\t\t\t\\end{tabular}\r\n\t\t}\r\n\r\n\t\t&\r\n\t\t\r\n\t\t% -----------------------\r\n\t\t% | NF | HF |  lo | HF' |\r\n\t\t% |----|----|-----|-----|\r\n\t\t% |  0 |  * | 0-9 |  0  |\r\n\t\t% |  0 |  * | a-f |  1  |\r\n\t\t% -----------------------\r\n\t\t% |  1 |  0 |  *  |  0  |\r\n\t\t% |  1 |  1 | 6-f |  0  |\r\n\t\t% |  1 |  1 | 0-5 |  1  |\r\n\t\t% -----------------------\r\n\t\t{\\tt\r\n\t\t\t\\begin{tabular}[t]{c|c|c|c}\r\n\t\t\t\t   &    & low    & \\\\\r\n\t\t\t\tNF & HF & nibble & HF' \\\\ \r\n\t\t\t\t\\hline\r\n\t\t\t\t0 &  * & 0-9    &  0  \\\\\r\n\t\t\t\t0 &  * & A-F    &  1  \\\\\r\n\t\t\t\t1 &  0 &  *     &  0  \\\\\r\n\t\t\t\t1 &  1 & 6-F    &  0  \\\\\r\n\t\t\t\t1 &  1 & 0-5    &  1  \\\\ \r\n\t\t\t\t\\hline\r\n\t\t\t\\end{tabular}\r\n\t\t}\r\n\t\t\r\n\t\t\\\\\r\n\r\n\t\\end{tabular}\r\n}\r\n\r\nSF, YF, XF are copies of bit 7, 5, 3 of the result respectively; ZF is set according to the result and NF is always unchanged.\r\n\r\n\r\n\\section{Interrupts}\r\n\\label{z80_interrupts}\r\n\r\nThere are two types of interrupts, maskable and non-maskable. The maskable type is ignored if {\\tt IFF1} is reset. Non-maskable interrupts (NMI) will are always accepted, and they have a higher priority, so if both are requested at the same time, the NMI will be accepted first.\r\n\r\nFor the interrupts, the following things are important: interrupt Mode (set with the {\\tt IM 0, IM 1, IM 2} instructions), the interrupt flip-flops ({\\tt IFF1} and {\\tt IFF2}), and the {\\tt I} register. When a maskable interrupt is accepted, the external device can put a value on the data bus.\r\n\r\nBoth types of interrupts increase the {\\tt R} register by one when accepted.\r\n\r\n\r\n\\subsection{Non-Maskable Interrupts (NMI)}\r\n\r\nWhen an NMI is accepted, {\\tt IFF1} is reset. At the end of the routine, {\\tt IFF1} must be restored (so the running program is not affected). That's why {\\tt IFF2} is there; to keep a copy of {\\tt IFF1}.\r\n\r\nAn NMI is accepted when the \\NoLinkChipPinLabel{NMI} pin on the Z80 is made low (edge-triggered). The Z80 responds to the change of the line from +5 to 0 - so the interrupt line doesn't have a state, it's just a pulse. When this happens, a call is done to address \\MemAddr{0066} and {\\tt IFF1} is reset so the routine isn't bothered by maskable interrupts. The routine should end with an {\\tt RETN} (RETurn from Nmi) which is just a usual {\\tt RET} but also copies {\\tt IFF2} to {\\tt IFF1}, so the IFFs are the same as before the interrupt.\r\n\r\nYou can check whether interrupts were disabled or not during an NMI by using the {\\tt LD A,I} or {\\tt LD A,R} instruction. These instructions copy {\\tt IFF2} to the PV flag.\r\n\r\nAccepting an NMI costs 11 t-states.\r\n\r\n\r\n\\subsection{Maskable Interrupts (INT)}\r\n\r\nIf the \\NoLinkChipPinLabel{INT} line is low and {\\tt IFF1} is set, a maskable interrupt is accepted - whether or not the last interrupt routine has finished. That's why you should not enable interrupts during such a routine, and make sure that the device that generated it has put the \\NoLinkChipPinLabel{INT} line up again before ending the routine. So unlike NMI interrupts, the interrupt line has a state; it's not a pulse.\r\n\r\nWhen an interrupt is accepted, both {\\tt IFF1} and {\\tt IFF2} are cleared, preventing another interrupt from occurring which would end up as an infinite loop (and overflowing the stack). What happens next depends on the Interrupt Mode.\r\n\r\nA device can place a value on the data bus when the interrupt is accepted. Some computer systems do not utilize this feature, and this value ends up being {\\tt \\$FF}.\r\n\r\n\\begin{description}\r\n\r\n\t\\item[Interrupt Mode 0]\r\n\tThis is the 8080 compatibility mode. The instruction on the bus is executed (usually an {\\tt RST} instruction, but it can be anything). {\\tt I} register is not used. Assuming it's a {\\tt RST} instruction, accepting this takes 13 t-states.\r\n\r\n\t\\item[Interrupt Mode 1]\r\n\tThis is the 8080 compatibility mode. The instruction on the bus is executed (usually an {\\tt RST} instruction, but it can be anything). {\\tt I} register is not used. Assuming it's a {\\tt RST} instruction, accepting this takes 13 t-states.\r\n\r\n\t\\item[Interrupt Mode 2]\r\n\tA call is made to the address read from memory. What address is read from is calculated as follows: $(I\\ register) \\times 256 + (value\\ on\\ bus)$. Zilog's user manual states (very convincingly) that the least significant bit of the address is always 0, so they calculate the address that is read from as: $(I\\ register) \\times 256 + (value\\ on\\ bus \\wedge \\mathtt{\\$FE})$. I have tested this and it's not correct. Of course, a word (two bytes) is read, making the address where the call is made to. In this way, you can have a vector table for interrupts. Accepting this interrupt type costs 19 t-states.\r\n\r\n\\end{description}\r\n\r\nAt the end of a maskable interrupt, the interrupts should be enabled again. You can assume that was the state of the IFFs because otherwise the interrupt wasn't accepted. So, an interrupt routine always ends with an {\\tt EI} and a {\\tt RET} ({\\tt RETI} according to the official documentation, more about that later):\r\n\r\n\\begin{tcblisting}{}\r\nInterruptRoutine:\r\n\t...\r\n\tEI\r\n\tRETI or RET\r\n\\end{tcblisting}\r\n\r\nNote a fact about {\\tt EI}: a maskable interrupt isn't accepted directly after it, so the next opportunity for an interrupt is after the {\\tt RETI}. This is very useful; if the \\NoLinkChipPinLabel{INT} line is still low, an interrupt is accepted again.  If this happens a lot and the interrupt is generated before the {\\tt RETI}, the stack could overflow (since the routine would be called again and again). But this property of {\\tt EI} prevents this.\r\n\r\n{\\tt DI} is not necessary at the start of the interrupt routine: the interrupt flip-flops are cleared when accepting the interrupt.\r\n\r\nYou can use {\\tt RET} instead of {\\tt RETI}, depending on the hardware setup. {\\tt RETI} is only useful if you have something like a Z80 PIO to support daisy-chaining: queuing interrupts. The PIO can detect that the routine has ended by the opcode of {\\tt RETI}, and let another device generate an interrupt. That is why I called all the undocumented {\\tt EDxx} {\\tt RET} instructions {\\tt RETN}: All of them operate alike, the only difference of {\\tt RETI} is its specific opcode which the Z80 PIO recognises.\r\n\r\n\r\n\\subsection{Things Affecting the Interrupt Flip-Flops}\r\n\\label{z80_interrupts_flipflop}\r\n\r\nAll the IFF related things are:\r\n\r\n\\begin{tabular}{llll}\r\n\tAccept NMI\t& {\\tt IFF1}\t& {\\tt IFF2} \\\\\r\n\tCPU reset\t& {\\tt 0}\t\t& {\\tt 0}\\\\\r\n\t{\\tt DI}\t& {\\tt 0}\t\t& {\\tt 0}\\\\\r\n\t{\\tt EI}\t& {\\tt 1}\t\t& {\\tt 1}\\\\\r\n\tAccept INT\t& {\\tt 0}\t\t& {\\tt 0}\\\\\r\n\tAccept NMI\t& {\\tt 0}\t\t& -\\\\\r\n\t{\\tt RETI/N}& {\\tt IFF2}\t& - & All the {\\tt EDxx} {\\tt RETI/N} instructions\\\\\r\n\t{\\tt LD A,I / LD A,R} & - & - & Copies {\\tt IFF2} into {\\tt PV} flag\r\n\\end{tabular}\r\n\r\nIf you're working with a Z80 system without NMIs (like the MSX), you can forget all about the two separate IFFs; since an NMI isn't ever generated, the two will always be the same. \r\n\r\nSome documentation says that when an NMI is accepted, {\\tt IFF1} is first copied into {\\tt IFF2} before {\\tt IFF1} is cleared. If this is true, the state of {\\tt IFF2} is lost after a nested NMI, which is undesirable. Have tested this in the following way: make sure the Z80 is in {\\tt EI} mode, generate an NMI. In the NMI routine, wait for another NMI before executing {\\tt RETN}. In the second NMI {\\tt IFF2} was still set, so {\\tt IFF1} is {\\em not} copied to {\\tt IFF2} when accepting an NMI.\r\n\r\nAnother interesting fact: I was trying to figure out whether the undocumented {\\tt ED} {\\tt RET} instructions were {\\tt RETN} or {\\tt RETI}. I tested this by putting the machine in {\\tt EI} mode, wait for an NMI and end with one of the {\\tt ED} {\\tt RET} instructions. Then execute a {\\tt HALT} instruction. If {\\tt IFF1} was not restored, the machine would hang but this did not happen with any of the instructions, including the documented {\\tt RETI}!\r\n\r\nSince every interrupt routine must end with {\\tt EI} followed by {\\tt RETI} officially, It does not matter that {\\tt RETI} copies {\\tt IFF2} into IFF1; both are set anyway.\r\n\r\n\r\n\\subsection{HALT Instruction}\r\n\r\nThe HALT instruction halts the Z80; it does not increase the PC so that the instruction is re-executed until a maskable or non-maskable interrupt is accepted. Only then does the Z80 increase the PC again and continues with the next instruction. During the HALT state, the HALT line is set. The PC is increased before the interrupt routine is called.\r\n\r\n\r\n\\subsection{Where interrupts are accepted}\r\n\r\nDuring the execution of instructions, interrupts won't be accepted. Only {\\em between} instructions. This is also true for prefixed instructions.\r\n\r\nDirectly after an {\\tt EI} or {\\tt DI} instruction, interrupts aren't accepted. They're accepted again after the instruction after the {\\tt EI} ({\\tt RET} in the following example). So for example, look at this MSX2 routine that reads a scanline from the keyboard:\r\n\r\n\\begin{tcblisting}{}\r\n\tLD C, A\r\n\tDI\r\n\tIN A, (&AA)\r\n\tAND &F0\r\n\tADD A, C\r\n\tOUT (&AA), A\r\n\tEI\r\n\tIN A, (&A9)\r\n\tRET\r\n\\end{tcblisting}\r\n\r\nYou can assume that there never is an interrupt after the {\\tt EI}, before the {\\tt IN A,(\\$A9)} - which would be a problem because the MSX interrupt routine reads the keyboard too.\r\n\r\nUsing this feature of {\\tt EI}, it is possible to check whether it is true that interrupts are never accepted during instructions:\r\n\r\n\\begin{tcblisting}{}\r\n\tDI\r\n\t|make sure interrupt is active|\r\n\tEI\r\n\t|insert instruction to test|\r\nInterruptRoutine:\r\n\t|store PC where interrupt was accepted|\r\n\tRET\r\n\\end{tcblisting}\r\n\r\nAnd yes, for all instructions, including the prefixed ones, interrupts are never accepted during an instruction. Only after the tested instruction. Remember that block instructions simply re-execute themselves (by decreasing the PC with 2) so an interrupt is accepted after each iteration.\r\n\r\nAnother predictable test: at the ``insert instruction to test'' insert a large sequence of {\\tt EI} instructions. Of course, during the execution of the {\\tt EI} instructions, no interrupts are accepted. \r\n\r\n\\pagebreak % we want to keep this paragraph together on the next page\r\nBut now for the interesting stuff. {\\tt ED} or {\\tt CB} make up instructions, so interrupts are accepted after them. But {\\tt DD} and {\\tt FD} are prefixes, which only slightly affects the next opcode. If you test a large sequence of {\\tt DD}s or {\\tt FD}s, the same happens as with the {\\tt EI} instruction: no interrupts are accepted during the execution of these sequences.\r\n\r\nThis makes sense if you think of {\\tt DD} and {\\tt FD} as a prefix that sets the ``use {\\tt IX} instead of {\\tt HL}'' or ``use {\\tt IY} instead of {\\tt HL}'' flag. If an interrupt was accepted after {\\tt DD} or {\\tt FD}, this flag information would be lost, and:\r\n\r\n{\\tt \r\n\t{\\qquad}DD 21 00 00{\\qquad}LD IX, 0\r\n}\r\n\r\ncould be interpreted as a simple {\\tt LD HL,0} if the interrupt was after the last {\\tt DD}. Which never happens, so the implementation is correct. Although I haven't tested this, as I imagine the same holds for NMI interrupts.\r\n\r\nAlso see section \\XRef{zx_next_interrupts} for details on handling interrupts on ZX Spectrum Next.\r\n\r\n\r\n\\section{Timing and R register}\r\n\r\n\\subsection{R register and memory refresh}\r\n\r\nDuring every first machine cycle (beginning of instruction or part of it - prefixes have their own M1 two), the memory refresh cycle is issued. The whole IR register is put on the address bus, and the \\NoLinkChipPinLabel{RFSH} pin is lowered.  It's unclear whether the Z80 increases the {\\tt R} register before or after putting IR on the bus. \r\n\r\nThe {\\tt R} register is increased at every first machine cycle (M1). Bit 7 of the register is never changed by this; only the lower 7 bits are included in the addition. So bit 7 stays the same, but it can be changed using the\r\n{\\tt LD R,A} instruction.\r\n\r\nInstructions without a prefix increase {\\tt R} by one. Instructions with an {\\tt ED}, {\\tt CB}, {\\tt DD}, {\\tt FD} prefix, increase {\\tt R} by two, and so do the {\\tt DDCBxxxx} and {\\tt FDCBxxxx} instructions (weird enough). Just a stray {\\tt DD} or {\\tt FD} increases the {\\tt R} by one. {\\tt LD A,R} and {\\tt LD R,A} access the {\\tt R} register after it is increased by the instruction itself. \r\n\r\nRemember that block instructions simply decrement the {\\tt PC} with two, so the instructions are re-executed. So {\\tt LDIR} increases {\\tt R} by {\\tt BC} $\\times$ 2 (note that in the case of {\\tt BC} = 0, {\\tt R} is increased by \\MemAddr{10000} $\\times$ 2, effectively 0).\r\n\r\nAccepting a maskable or non-maskable interrupt increases the {\\tt R} by one.\r\n\r\nAfter a hardware reset, or after power on, the {\\tt R} register is reset to 0.\r\n\r\nThat should cover all there is to say about the {\\tt R} register. It is often used in programs for a random value, which is good but of course not truly random.\r\n\r\n\r\n\\pagebreak\r\n\\section{Errors in Official Documentation}\r\n\r\nSome official Zilog documentation contains errors. Not every documentation has all of these mistakes, so your milage may vary, but these are just things to look out for.\r\n\r\n\\begin{itemize}\r\n\r\n\t\\item\r\n\tThe flag affection summary table shows that {\\tt LDI}/{\\tt LDIR}/{\\tt LDD}/{\\tt LDDR} instructions leave the SF and ZF in an undefined state. This is not correct; the SF and ZF flags are unaffected.\r\n\r\n\t\\item\r\n\tSimilarly, the same table shows that {\\tt CPI}/{\\tt CPIR}/{\\tt CPD}/{\\tt CPDR} leave the SF and HF flags in an undefined state. Not true, they are affected as defined elsewhere in the documentation.\r\n\r\n\t\\item\r\n\tAlso, the table says about {\\tt INI}/{\\tt OUTD}/etc ``Z=0 if B $<>$ 0 otherwise Z=0''; of course the latter should be Z=1.\r\n\r\n\t\\item\r\n\tThe {\\tt INI}/{\\tt INIR}/{\\tt IND}/{\\tt INDR}/{\\tt OUTI}/{\\tt OUTD}/{\\tt OTIR}/{\\tt OTDR} instructions do affect the CF flag (some official documentation says they leave it unaffected, important!) and the NF flag isn't always set but may also be reset (see \\XRef{z80_undocumented_instructions_io_block} for exact operation).\r\n\r\n\t\\item\r\n\tWhen an NMI is accepted, the {\\tt IFF1} isn't copied to {\\tt IFF2}. Only {\\tt IFF1} is reset.\r\n\r\n\t\\item\r\n\tIn the 8-bit Load Group, the last two bits of the second byte of the {\\tt LD r,(IX + d)} opcode should be 10 and not 01.\r\n\r\n\t\\item\r\n\tIn the 16-bit Arithmetic Group, bit 6 of the second byte of the {\\tt ADD IX,pp} opcode should be 0, not 1.\r\n\r\n\t\\item\r\n\t{\\tt IN x,(C)} resets the HF flag, it never sets it. Some documentation states it is set according to the result of the operation; this is impossible since no arithmetic is done in this instruction.\r\n\r\n\\end{itemize}\r\n\r\nNote: In zilog's own z80cpu\\_um.pdf document, there are a lot of errors, some are very confusing, so I'll mention the ones I have found here:\r\n\r\n\\begin{itemize}\r\n\r\n\t\\item\r\n\tPage 21, figure 2 says ``the Alternative Register Set contains 2 {\\tt B'} registers''; this should of course be {\\tt B'} and {\\tt C'}.\r\n\r\n\t\\item\r\n\tPage 26, figure 16 shows very convincingly that ``the least significant bit of the address to read for Interrupt Mode 2 is always 0''. I have tested this and it is not correct, it can also be 1, in my test case the bus contained {\\tt \\$FF} and the address that was read did not end in {\\tt \\$FE} but was {\\tt \\$FF}.\r\n  \r\n\\end{itemize}\r\n"
  },
  {
    "path": "defines-dma.tex",
    "content": "% ▒█▀▀█ ▒█▀▀▀ ▒█▄░▒█ ▒█▀▀▀ ▒█▀▀█ ░█▀▀█ ▒█░░░ \r\n% ▒█░▄▄ ▒█▀▀▀ ▒█▒█▒█ ▒█▀▀▀ ▒█▄▄▀ ▒█▄▄█ ▒█░░░ \r\n% ▒█▄▄█ ▒█▄▄▄ ▒█░░▀█ ▒█▄▄▄ ▒█░▒█ ▒█░▒█ ▒█▄▄█\r\n\r\n% Writes register name (WR0...) in the proper style.\r\n\\newcommand{\\DMARegName}[1]{{\\tt #1}}\r\n\r\n\r\n% ▒█▀▀█ ▒█░░▒█ ▀▀█▀▀ ▒█▀▀▀ 　 ▒█▀▀▄ ▒█▀▀▀ ▒█▀▀▀█ ▒█▀▀█ ▒█▀▀█ ▀█▀ ▒█▀▀█ ▀▀█▀▀ ▀█▀ ▒█▀▀▀█ ▒█▄░▒█ \r\n% ▒█▀▀▄ ▒█▄▄▄█ ░▒█░░ ▒█▀▀▀ 　 ▒█░▒█ ▒█▀▀▀ ░▀▀▀▄▄ ▒█░░░ ▒█▄▄▀ ▒█░ ▒█▄▄█ ░▒█░░ ▒█░ ▒█░░▒█ ▒█▒█▒█ \r\n% ▒█▄▄█ ░░▒█░░ ░▒█░░ ▒█▄▄▄ 　 ▒█▄▄▀ ▒█▄▄▄ ▒█▄▄▄█ ▒█▄▄█ ▒█░▒█ ▄█▄ ▒█░░░ ░▒█░░ ▄█▄ ▒█▄▄▄█ ▒█░░▀█\r\n\r\n% Writes an environment for describing individual components of a DMA byte\r\n\\newenvironment{DMADescription}{\r\n\t\\begin{basedescript}{\r\n\t\t% setup basedescript styling for labels\r\n\t\t\\desclabelstyle{\\multilinelabel}\r\n\t\t\\desclabelwidth{2.5cm}\r\n\t}\r\n\r\n\t% setup spacing between items\r\n\t\\setlength\\itemsep{1ex}\r\n}{\r\n\t\\end{basedescript}\r\n}\r\n\r\n% Writes an itemize within the DMADescription environment; it uses some less vertical spacing\r\n\\newenvironment{DMAList}{\r\n\t\\begin{itemize}[topsep=-3pt,itemsep=-1pt]\r\n}{\r\n\t\\end{itemize}\r\n}\r\n\r\n% Use for individual items within DMADescription environment. Parameters:\r\n% - #1 Single bit (0) or range (2-0)\r\n% - #2 Title\r\n% - #3 Description\r\n\\newcommand{\\DMADescriptionItem}[3]{\r\n\t\\item[\\footnotesize \\IfInteger{#1}{Bit}{Bits} {\\tt #1}:\\\\#2]\r\n\r\n\t#3\r\n}\r\n\r\n% Use for description items that are not bits - typically what remains are bytes. Parameters:\r\n% - #1 Title\r\n% - #2 Description\r\n\\newcommand{\\DMADescriptionByte}[2]{\r\n\t\\item[\\footnotesize #1]\r\n\t\r\n\t#2\r\n}\r\n\r\n\r\n% ▒█▀▀▄ ▒█▀▀█ ░█▀▀█ ▒█░░▒█ ▀█▀ ▒█▄░▒█ ▒█▀▀█ ▒█▀▀▀█ 　 ░░ 　 ▒█▀▀█ ░█▀▀█ ▒█▀▀▀█ ▒█▀▀▀ \r\n% ▒█░▒█ ▒█▄▄▀ ▒█▄▄█ ▒█▒█▒█ ▒█░ ▒█▒█▒█ ▒█░▄▄ ░▀▀▀▄▄ 　 ▀▀ 　 ▒█▀▀▄ ▒█▄▄█ ░▀▀▀▄▄ ▒█▀▀▀ \r\n% ▒█▄▄▀ ▒█░▒█ ▒█░▒█ ▒█▄▀▄█ ▄█▄ ▒█░░▀█ ▒█▄▄█ ▒█▄▄▄█ 　 ░░ 　 ▒█▄▄█ ▒█░▒█ ▒█▄▄▄█ ▒█▄▄▄\r\n\r\n\\newcommand{\\DMAScaledReg}[2]{\r\n\t\\textbf{#1}\r\n\t\r\n\t\\scalebox{0.75}{#2}\r\n}\r\n\r\n% Note: counters and macros below depends on specific order; but this makes drawings much more straighforward. Just be very careful if changing anything as it may have unexpected effects on other nodes!\r\n\r\n\\newcounter{DMAHeaderIndex}         % Current bit header index; used with \\DMABitParHeader\r\n\\newcounter{DMABitParameterIndex}\t\t% Current parameter index\r\n\\newcounter{DMABitDescIndex}\t\t% Current bit description index\r\n\\newcounter{DMABitDescItemIndex}\t% Current bit description item index\r\n\r\n% This declares all styles used within tikz drawings for DMA commands so we don't have to repeat\r\n\\tikzset{\r\n\tdmatitle/.style={font=\\small\\bf},\r\n\tdmacode/.style={font=\\ttfamily},\r\n\tdmalegend/.style={font=\\scriptsize\\bf, text=PrintableLightGray},\r\n\tdmabit/.style={minimum width=1.3em, minimum height=1.3em},\r\n\tdmabyte/.style={\r\n\t\tdmabit, \r\n\t\tdraw=PrintableLightGray, \r\n\t\trectangle split,\r\n\t\trectangle split parts=8,\r\n\t\trectangle split horizontal,\r\n\t\trectangle split empty part width=0.2em},\r\n\tdmabyteouter/.style={dmabit, draw, minimum width=10.68em},\r\n\tdmamono/.style={dmabit, dmacode, draw, inner sep=0pt, outer sep=0pt},\r\n\tdmaheader/.style={dmabit, dmatitle, draw, fill=PrintableLightGray},\r\n\tdmaconnector/.style={Circle-stealth', line width=0.6pt},\r\n\tdmavalue/.style={dmacode},\r\n\tdmabyteexpl/.style={font=\\small\\it, text=PrintableDarkGray},\r\n\tdmaexpl/.style={},\r\n}\r\n\r\n% Returns various IDs for the given bit, taking into account current DMAHeaderIndex\r\n\\newcommand{\\DMALegendID}{LegendHor\\arabic{DMAHeaderIndex}}\t\t\t\t\t% LegendHor0...\r\n\\newcommand{\\DMALegendRegID}{LegendReg\\arabic{DMAHeaderIndex}}\t\t\t\t% LegendReg0...\r\n\\newcommand{\\DMALegendParID}{LegendPar\\arabic{DMAHeaderIndex}}\t\t\t\t% LegendPar0...\r\n\\newcommand{\\DMABitDefAnyID}[2]{BitDef#1_#2}\t\t\t\t\t\t\t\t% BitDef0_0, BitDef0_1...\r\n\\newcommand{\\DMABitDefID}[1]{\\DMABitDefAnyID{\\arabic{DMAHeaderIndex}}{#1}}\t% BitDef0_0, BitDef0_1...\r\n\\newcommand{\\DMABitValID}[1]{BitVal\\arabic{DMAHeaderIndex}_#1}\t\t\t\t% BitVal0_0, BitVal0_1...\r\n\\newcommand{\\DMABitDescTitleID}[1]{Bit\\arabic{DMAHeaderIndex}_#1Title}\t\t% Bit0_0Title, Bit0_1Title...\r\n\\newcommand{\\DMABitDescItemAnyID}[2]{Bit\\arabic{DMAHeaderIndex}_#1Item#2}\t% Bit0_0Item0...\r\n\\newcommand{\\DMABitDescItemID}[1]{\\DMABitDescItemAnyID{#1}{\\arabic{DMABitDescItemIndex}}}\t\t\t% Bit0_0Item0...\r\n\\newcommand{\\DMABitDescExplID}[1]{Bit\\arabic{DMAHeaderIndex}_#1Expl\\arabic{DMABitDescItemIndex}}\t% Bit0_0Expl0...\r\n\\newcommand{\\DMABitParID}[1]{Bit\\arabic{DMAHeaderIndex}_#1ParByte}\t\t\t\t\t\t\t\t\t% Bit0_0ParByte\r\n\\newcommand{\\DMABitParExplID}[1]{Bit\\arabic{DMAHeaderIndex}_\\arabic{DMABitDescIndex}_#1ParExpl}\t\t% Bit0_0_0ParExpl\r\n\r\n\r\n% ▒█▀▀▄ ▒█▀▀█ ░█▀▀█ ▒█░░▒█ ▀█▀ ▒█▄░▒█ ▒█▀▀█ ▒█▀▀▀█ 　 ░░ 　 ▒█▀▀█ ▒█▀▀▀█ ▒█▀▄▀█ ▒█▀▀█ ▒█▀▀▀█ ▒█▄░▒█ ▒█▀▀▀ ▒█▄░▒█ ▀▀█▀▀ ▒█▀▀▀█ \r\n% ▒█░▒█ ▒█▄▄▀ ▒█▄▄█ ▒█▒█▒█ ▒█░ ▒█▒█▒█ ▒█░▄▄ ░▀▀▀▄▄ 　 ▀▀ 　 ▒█░░░ ▒█░░▒█ ▒█▒█▒█ ▒█▄▄█ ▒█░░▒█ ▒█▒█▒█ ▒█▀▀▀ ▒█▒█▒█ ░▒█░░ ░▀▀▀▄▄ \r\n% ▒█▄▄▀ ▒█░▒█ ▒█░▒█ ▒█▄▀▄█ ▄█▄ ▒█░░▀█ ▒█▄▄█ ▒█▄▄▄█ 　 ░░ 　 ▒█▄▄█ ▒█▄▄▄█ ▒█░░▒█ ▒█░░░ ▒█▄▄▄█ ▒█░░▀█ ▒█▄▄▄ ▒█░░▀█ ░▒█░░ ▒█▄▄▄█\r\n\r\n% Inserts enough spacing to properly render double bit configuration (0 0, 0 1, 1 0, 1 1). Parameters:\r\n% - #1 First bit value\r\n% - #2 Second bit value\r\n\\newcommand{\\DMATwoBits}[2]{#1\\hspace*{1.8ex}#2}\r\n\r\n% Renders header with all 8 bits. Parameters:\r\n% - (optional) #1 empty (default) for main header, otherwise it will be treated as parameter positioning wise\r\n\\newcommand{\\DMABitHeader}{\r\n\t\\begin{scope}\r\n\t\t\\node[dmaheader] (\\DMABitDefID{7}) {7};\r\n\t\t\\node[dmaheader, right=0pt of \\DMABitDefID{7}] (\\DMABitDefID{6}) {6};\r\n\t\t\\node[dmaheader, right=0pt of \\DMABitDefID{6}] (\\DMABitDefID{5}) {5};\r\n\t\t\\node[dmaheader, right=0pt of \\DMABitDefID{5}] (\\DMABitDefID{4}) {4};\r\n\t\t\\node[dmaheader, right=0pt of \\DMABitDefID{4}] (\\DMABitDefID{3}) {3};\r\n\t\t\\node[dmaheader, right=0pt of \\DMABitDefID{3}] (\\DMABitDefID{2}) {2};\r\n\t\t\\node[dmaheader, right=0pt of \\DMABitDefID{2}] (\\DMABitDefID{1}) {1};\r\n\t\t\\node[dmaheader, right=0pt of \\DMABitDefID{1}] (\\DMABitDefID{0}) {0};\r\n\t\t\r\n\t\t% description at the right side\r\n\t\t\\node[dmabyteexpl, anchor=west]\r\n\t\t\tat(\\DMABitDefID{0}.south east)\r\n\t\t\t{Base Register Byte};\r\n\r\n\t\t% Reset all command related counters\r\n\t\t\\setcounter{DMAHeaderIndex}{0}\r\n\t\t\\setcounter{DMABitDescIndex}{-1}\r\n\t\t\\setcounter{DMABitParameterIndex}{-1}\r\n\t\\end{scope}\r\n}\r\n\r\n% Renders individual bit below header. Parameters:\r\n% - (optional) #1 number of bits to span (default = 1)\r\n% - #2 bit number (0-7) - used to generate node ID\r\n% - #3 bit value (empty for no value)\r\n\\newcommand{\\DMABitValue}[3][1]{\r\n\t\\begin{scope}\r\n\t\t\\IfEq{#1}{1}{\r\n\t\t\t% single bit\r\n\t\t\t\\node[dmamono, \r\n\t\t\t\tfit=(\\DMABitDefID{#2}.west)(\\DMABitDefID{#2}.east),\r\n\t\t\t\tanchor=north west,\r\n\t\t\t\ttext height=1.35ex] \r\n\t\t\t\tat(\\DMABitDefID{#2}.south west)\r\n\t\t\t\t(\\DMABitValID{#2}) \r\n\t\t\t\t{#3};\r\n\t\t}{\r\n\t\t\t% span multiple bits\r\n\t\t\t\\pgfmathtruncatemacro{\\DMATo}{#2 - #1 + 1}\r\n\t\t\t\\node[dmamono, \r\n\t\t\t\tfit=(\\DMABitDefID{#2}.west)(\\DMABitDefID{\\DMATo}.east),\r\n\t\t\t\tanchor=north west,\r\n\t\t\t\ttext height=1.35ex]\r\n\t\t\t\tat(\\DMABitDefID{#2}.south west)\r\n\t\t\t\t(\\DMABitValID{#2})\r\n\t\t\t\t{#3};\r\n\t\t}\r\n\t\\end{scope}\r\n}\r\n\r\n% Renders legend on the left side. Parameters:\r\n% - #1 bit number for the top parameter (0-7)\r\n% - (optional) #2 title for paramters part (default = PARAMETERS)\r\n% - (optional) #3 title for command part (default = REGISTER)\r\n\\NewDocumentCommand{\\DMALegend}{ m O{PARAMETERS} O{REGISTER} }{\r\n\t\\begin{scope}[\r\n\t\tevery path/.style={PrintableLightGray, line width=0.6pt},\r\n\t\tevery node/.style={rotate=90}]\r\n\r\n\t\t% Horizontal delimiter\r\n\t\t\\draw\r\n\t\t\t([xshift=1ex,yshift=1ex]#1.north west) -- \r\n\t\t\t([xshift=-1.5em,yshift=1ex]#1.north west) \r\n\t\t\tnode (\\DMALegendID) {};\r\n\r\n\t\t% Command text above delimiter\r\n\t\t\\node[dmalegend, above=0pt of \\DMALegendID, anchor=north west, yshift=-1.5pt]\r\n\t\t\t(\\DMALegendRegID)\r\n\t\t\t{#3};\r\n\t\t\r\n\t\t% Parameters text below delimiter\r\n\t\t\\node[dmalegend, below=0pt of \\DMALegendID, anchor=east]\r\n\t\t\t(\\DMALegendParID)\r\n\t\t\t{#2};\r\n\t\\end{scope}\r\n}\r\n\r\n% Renders title for bit description group. Parameters:\r\n% - (optional) #1 left offset (default = -1.6ex)\r\n% - #2 Bit number (0-7)\r\n% - #3 Description text\r\n% - (optional) #4 top offset when first parameter (default = 2ex)\r\n\\NewDocumentCommand{\\DMABitDescTitle}{ O{-1.6ex} m m O{2ex} }{\r\n\t\\begin{scope}\r\n\t\t\\IfEq{\\arabic{DMABitDescIndex}}{-1}{\r\n\t\t\t% If this is first description group, position it below bit \"table\"\r\n\t\t\t\\node[\r\n\t\t\t\tdmatitle, \r\n\t\t\t\txshift=#1, \r\n\t\t\t\tbelow=#4 of \\DMABitValID{#2}, \r\n\t\t\t\tanchor=north west]\r\n\t\t\t\t(\\DMABitDescTitleID{#2})\r\n\t\t\t\t{#3};\r\n\t\t}{\r\n\t\t\t% Subsequent description groups should be positioned below last item of the previous group\r\n\t\t\t\\node[\r\n\t\t\t\tdmatitle, \r\n\t\t\t\tanchor=north west, \r\n\t\t\t\txshift=#1, \r\n\t\t\t\tyshift=-1em]\r\n\t\t\t\tat(\\DMABitValID{#2} |- \\DMABitDescItemID{\\arabic{DMABitDescIndex}})\r\n\t\t\t\t(\\DMABitDescTitleID{#2})\r\n\t\t\t\t{#3};\r\n\t\t}\r\n\t\t\r\n\t\t% Draw vertical connecting line from bit to title\r\n\t\t\\draw[dmaconnector] \r\n\t\t\t([yshift=2pt]\\DMABitValID{#2}.center) -- \r\n\t\t\t([yshift=-1pt]\\DMABitValID{#2}.center |- \\DMABitDescTitleID{#2}.north);\r\n\t\t\r\n\t\t% Change bit description counter to given bit number and reset item counter\r\n\t\t\\setcounter{DMABitDescIndex}{#2}\r\n\t\t\\setcounter{DMABitDescItemIndex}{-1}\r\n\t\\end{scope}\r\n}\r\n\r\n% Renders individual bit description item. Parameters:\r\n% - #1 Bit number (0-7)\r\n% - #2 Bit value (0/1)\r\n% - #3 Explanation text\r\n\\newcommand{\\DMABitDescItem}[3]{\r\n\t\\begin{scope}\r\n\t\t% Update item counter for next item\r\n\t\t\\stepcounter{DMABitDescItemIndex}\r\n\r\n\t\t\\IfEq{\\arabic{DMABitDescItemIndex}}{0}{\r\n\t\t\t% if this is first item for this group, position it below previously generated title\r\n\t\t\t\\node[dmavalue, below=1ex of \\DMABitDescTitleID{#1}.west, anchor=north west]\r\n\t\t\t\t(\\DMABitDescItemID{#1})\r\n\t\t\t\t{#2};\r\n\t\t}{\r\n\t\t\t% Otherwise position it below previous item\r\n\t\t\t\\pgfmathtruncatemacro{\\prev}{\\arabic{DMABitDescItemIndex}-1}\r\n\t\t\t\\node[dmavalue]\r\n\t\t\t\tat([yshift=-5pt]\\DMABitDescItemAnyID{#1}{\\prev}.south) \r\n\t\t\t\t(\\DMABitDescItemID{#1}) \r\n\t\t\t\t{#2};\r\n\t\t}\r\n\r\n\t\t% render explanation text\r\n\t\t\\node[dmaexpl, anchor=west] \r\n\t\t\tat(\\DMABitDescItemID{#1}.east) \r\n\t\t\t(\\DMABitDescExplID{#1}) \r\n\t\t\t{#3};\r\n\t\\end{scope}\r\n}\r\n\r\n% Renders parameter for given bit. Parameters:\r\n% - #1 Bit number (0-7)\r\n% - #2 Parameter description text\r\n% - (optional) #3 vertical spacing from parent when this is first parameter (default = 1ex)\r\n% - (optional) #4 positioning for \"bit=1\" text on connector line (default = near start)\r\n% - (optional) #5 text to use in front of parameter description (default = +1 byte) (note: if empty, then connector node also doesn't display text on it)\r\n\\NewDocumentCommand{\\DMABitPar}{ m m O{1ex} O{near start} O{+1 byte} }{\r\n\t\\begin{scope}\r\n\t\t% increment parameter counter\r\n\t\t\\stepcounter{DMABitParameterIndex}\r\n\r\n\t\t\\IfEq{\\arabic{DMABitParameterIndex}}{0}{\r\n\t\t\t% if this is first parameter, position it below bit table\r\n\t\t\t\\node[dmabyte, \r\n\t\t\t\tbelow=#3 of \\DMABitValID{7}.west |- \\DMABitDescExplID{\\arabic{DMABitDescIndex}}.south, \r\n\t\t\t\tanchor=north west]\r\n\t\t\t\t(\\DMABitParID{#1})\r\n\t\t\t\t{};\r\n\t\t}{\r\n\t\t\t\\IfEq{\\arabic{DMABitDescIndex}}{-1}{\r\n\t\t\t\t\\IfEq{#1}{0}{\r\n\t\t\t\t\t% if this is the first parameter for current header and it's for bit 0, position it below previous parameter or header. But we can't use -1 as it will end up in negative index...\r\n\t\t\t\t\t\t\\node[dmabyte, \r\n\t\t\t\t\t\t\tbelow=#3 of \\DMABitValID{7}.south west,\r\n\t\t\t\t\t\t\tanchor=north west]\r\n\t\t\t\t\t\t\t(\\DMABitParID{#1})\r\n\t\t\t\t\t\t\t{};\r\n\t\t\t\t\t}{\r\n\t\t\t\t\t% if this is the first parameter for current header, position it below previous parameter or header\r\n\t\t\t\t\t\\pgfmathtruncatemacro{\\prev}{#1-1}\r\n\t\t\t\t\t\\node[dmabyte, \r\n\t\t\t\t\t\tbelow=2pt of \\DMABitParID{\\prev}]\r\n\t\t\t\t\t\t(\\DMABitParID{#1})\r\n\t\t\t\t\t\t{};\r\n\t\t\t\t}\r\n\t\t\t}{\r\n\t\t\t\t% if this is the first parameter for current header, position it below last item of the previous group\r\n\t\t\t\t\\pgfmathtruncatemacro{\\prev}{\\arabic{DMABitParameterIndex}-1}\r\n\t\t\t\t\\node[dmabyte, \r\n\t\t\t\t\tbelow=2.7ex of \\DMABitValID{7}.west |- \\DMABitDescItemID{\\arabic{DMABitDescIndex}},\r\n\t\t\t\t\tanchor=north west]\r\n\t\t\t\t\t(\\DMABitParID{#1})\r\n\t\t\t\t\t{};\r\n\t\t\t\t\t\r\n\t\t\t\t% afterwards reset desc index; once parameters are listed, this no longer applies\r\n\t\t\t\t\\setcounter{DMABitDescIndex}{-1}\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\t% above node renders all 8 bits with lighter color, this one renders black frame around all bits\r\n\t\t\\node[dmabyteouter, left=0pt of \\DMABitParID{#1}, anchor=west] {};\r\n\t\t\r\n\t\t% render description and explanation text\r\n\t\t\\IfStrEq{#5}{}{\r\n\t\t\t% if empty string, render only explanation text\r\n\t\t\t\\node[dmaexpl, anchor=west]\r\n\t\t\t\tat(\\DMABitParID{#1}.east)\r\n\t\t\t\t(\\DMABitParExplID{#1})\r\n\t\t\t\t{#2};\r\n\t\t}{\r\n\t\t\t% otherwise render both\r\n\t\t\t\\node[dmabyteexpl, anchor=west]\r\n\t\t\t\tat(\\DMABitParID{#1}.east)\r\n\t\t\t\t(\\DMABitParExplID{#1}ByteText)\r\n\t\t\t\t{#5};\r\n\t\t\t\\node[dmaexpl, anchor=base west, xshift=-3pt]\r\n\t\t\t\tat(\\DMABitParExplID{#1}ByteText.base east)\r\n\t\t\t\t(\\DMABitParExplID{#1})\r\n\t\t\t\t{#2};\r\n\t\t}\r\n\t\t\r\n\t\t% render connection arrow from bit to parameter\r\n\t\t\\draw[dmaconnector]\r\n\t\t\t([yshift=2pt]\\DMABitValID{#1}.center) -- \r\n\t\t\tnode[dmabyteexpl, above, #4, xshift=3pt, font=\\tiny, rotate=90] {\\IfStrEq{#5}{}{}{\\fbox{#1}={\\tt 1}}}\r\n\t\t\t([yshift=-3pt]\\DMABitValID{#1}.center |- \\DMABitParID{#1}.north);\r\n\r\n\t\t% Reset all parameter related counters\r\n\t\t\\setcounter{DMABitDescIndex}{-1}\r\n\t\\end{scope}\r\n}\r\n\r\n% Same as \\DMABitHeader but when used as parameter for given bit. Parameters:\r\n% - #1 Bit number (0-7), leave empty for no bit\r\n% - #2 parameter description\r\n% - (optional) #3 text to use in front of parameter description (default = +1 byte) (note: if this is empty, then connector line also doesn't display text on it)\r\n\\NewDocumentCommand{\\DMABitParHeader}{ m m O{+1 byte} }{\r\n\t\\begin{scope}\r\n\t\t% increment parameter counter\r\n\t\t\\stepcounter{DMABitParameterIndex}\r\n\r\n\t\t\\pgfmathtruncatemacro{\\DMAHeadNextID}{\\arabic{DMAHeaderIndex}+1}\r\n\r\n\t\t\\IfEq{\\arabic{DMABitParameterIndex}}{0}{\r\n\t\t\t% if this is first parameter, position it below bit table\r\n\t\t\t\\node[dmaheader, \r\n\t\t\t\tbelow=1ex of \\DMABitValID{7}.west |- \\DMABitDescExplID{\\arabic{DMABitDescIndex}}.south, \r\n\t\t\t\tanchor=north west]\r\n\t\t\t\t(\\DMABitDefAnyID{\\DMAHeadNextID}{7})\r\n\t\t\t\t{7};\r\n\t\t}{\r\n\t\t\t\\IfEq{\\arabic{DMABitDescIndex}}{-1}{\r\n\t\t\t\t% if this is the first parameter for current header, position it below previous parameter\r\n\t\t\t\t\\pgfmathtruncatemacro{\\prev}{\\arabic{DMABitParameterIndex}-1}\r\n\t\t\t\t\\node[dmaheader, \r\n\t\t\t\t\tbelow=2pt of \\DMABitParID{\\prev}]\r\n\t\t\t\t\t(\\DMABitDefAnyID{\\DMAHeadNextID}{7})\r\n\t\t\t\t\t{7};\r\n\t\t\t}{\r\n\t\t\t\t% if this is the first parameter for current header, position it below last item of the previous group\r\n\t\t\t\t\\node[dmaheader, \r\n\t\t\t\t\tbelow=2.7ex of \\DMABitValID{7}.west |- \\DMABitDescItemID{\\arabic{DMABitDescIndex}},\r\n\t\t\t\t\tanchor=north west] \r\n\t\t\t\t\t(\\DMABitDefAnyID{\\DMAHeadNextID}{7})\r\n\t\t\t\t\t{7};\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\t\\node[dmaheader, right=0pt of \\DMABitDefAnyID{\\DMAHeadNextID}{7}] (\\DMABitDefAnyID{\\DMAHeadNextID}{6}) {6};\r\n\t\t\\node[dmaheader, right=0pt of \\DMABitDefAnyID{\\DMAHeadNextID}{6}] (\\DMABitDefAnyID{\\DMAHeadNextID}{5}) {5};\r\n\t\t\\node[dmaheader, right=0pt of \\DMABitDefAnyID{\\DMAHeadNextID}{5}] (\\DMABitDefAnyID{\\DMAHeadNextID}{4}) {4};\r\n\t\t\\node[dmaheader, right=0pt of \\DMABitDefAnyID{\\DMAHeadNextID}{4}] (\\DMABitDefAnyID{\\DMAHeadNextID}{3}) {3};\r\n\t\t\\node[dmaheader, right=0pt of \\DMABitDefAnyID{\\DMAHeadNextID}{3}] (\\DMABitDefAnyID{\\DMAHeadNextID}{2}) {2};\r\n\t\t\\node[dmaheader, right=0pt of \\DMABitDefAnyID{\\DMAHeadNextID}{2}] (\\DMABitDefAnyID{\\DMAHeadNextID}{1}) {1};\r\n\t\t\\node[dmaheader, right=0pt of \\DMABitDefAnyID{\\DMAHeadNextID}{1}] (\\DMABitDefAnyID{\\DMAHeadNextID}{0}) {0};\r\n\t\t\r\n\t\t% if bit is provided, render connector and explanation\r\n\t\t\\IfEq{#1}{}{}{\r\n\t\t\t% render connection arrow from bit to parameter\r\n\t\t\t\\draw[dmaconnector]\r\n\t\t\t\t([yshift=2pt]\\DMABitValID{#1}.center) -- \r\n\t\t\t\tnode[dmabyteexpl, above, near start, xshift=3pt, font=\\tiny, rotate=90] {\\IfStrEq{#3}{}{}{\\fbox{#1}={\\tt 1}}}\r\n\t\t\t\t([yshift=-2pt]\\DMABitValID{#1}.center |- \\DMABitDefAnyID{\\DMAHeadNextID}{#1}.north);\r\n\t\t}\r\n\t\t\r\n\t\t% increment header index\r\n\t\t\\stepcounter{DMAHeaderIndex}\r\n   \r\n\t\t% Reset all parameter related counters\r\n\t\t\\setcounter{DMABitDescIndex}{-1}\r\n\r\n\t\t% render description and explanation text\r\n\t\t\\IfStrEq{#3}{}{\r\n\t\t\t% if empty string, render only explanation text\r\n\t\t\t\\node[dmaexpl, anchor=west]\r\n\t\t\t\tat(\\DMABitDefAnyID{\\DMAHeadNextID}{0}.south east)\r\n\t\t\t\t(\\DMABitParExplID{#1})\r\n\t\t\t\t{#2};\r\n\t\t}{\r\n\t\t\t% otherwise render both\r\n\t\t\t\\node[dmabyteexpl, anchor=west]\r\n\t\t\t\tat(\\DMABitDefAnyID{\\DMAHeadNextID}{0}.south east)\r\n\t\t\t\t(\\DMABitParExplID{#1}ByteText)\r\n\t\t\t\t{#3};\r\n\t\t\t\\node[dmaexpl, anchor=base west, xshift=-3pt]\r\n\t\t\t\tat(\\DMABitParExplID{#1}ByteText.base east)\r\n\t\t\t\t(\\DMABitParExplID{#1})\r\n\t\t\t\t{#2};\r\n\t\t}\r\n\r\n\t\\end{scope}\r\n}\r\n"
  },
  {
    "path": "defines-instr-close.tex",
    "content": "% ───────────────────────────────────────────────────────────────────────────────────────\r\n% ─████████████───██████████████─██████████████─██████████████─██████████─██████─────────\r\n% ─██░░░░░░░░████─██░░░░░░░░░░██─██░░░░░░░░░░██─██░░░░░░░░░░██─██░░░░░░██─██░░██─────────\r\n% ─██░░████░░░░██─██░░██████████─██████░░██████─██░░██████░░██─████░░████─██░░██─────────\r\n% ─██░░██──██░░██─██░░██─────────────██░░██─────██░░██──██░░██───██░░██───██░░██─────────\r\n% ─██░░██──██░░██─██░░██████████─────██░░██─────██░░██████░░██───██░░██───██░░██─────────\r\n% ─██░░██──██░░██─██░░░░░░░░░░██─────██░░██─────██░░░░░░░░░░██───██░░██───██░░██─────────\r\n% ─██░░██──██░░██─██░░██████████─────██░░██─────██░░██████░░██───██░░██───██░░██─────────\r\n% ─██░░██──██░░██─██░░██─────────────██░░██─────██░░██──██░░██───██░░██───██░░██─────────\r\n% ─██░░████░░░░██─██░░██████████─────██░░██─────██░░██──██░░██─████░░████─██░░██████████─\r\n% ─██░░░░░░░░████─██░░░░░░░░░░██─────██░░██─────██░░██──██░░██─██░░░░░░██─██░░░░░░░░░░██─\r\n% ─████████████───██████████████─────██████─────██████──██████─██████████─██████████████─\r\n% ───────────────────────────────────────────────────────────────────────────────────────\r\n\r\n\r\n% ▒█▀▀█ ▒█▀▀▀ ▒█▀▀▄ ▒█▀▀▀ ▒█▀▀█ ▒█░░░ ░█▀▀█ ▒█▀▀█ ░█▀▀█ ▀▀█▀▀ ▀█▀ ▒█▀▀▀█ ▒█▄░▒█ ▒█▀▀▀█ \r\n% ▒█▄▄▀ ▒█▀▀▀ ▒█░▒█ ▒█▀▀▀ ▒█░░░ ▒█░░░ ▒█▄▄█ ▒█▄▄▀ ▒█▄▄█ ░▒█░░ ▒█░ ▒█░░▒█ ▒█▒█▒█ ░▀▀▀▄▄ \r\n% ▒█░▒█ ▒█▄▄▄ ▒█▄▄▀ ▒█▄▄▄ ▒█▄▄█ ▒█▄▄█ ▒█░▒█ ▒█░▒█ ▒█░▒█ ░▒█░░ ▄█▄ ▒█▄▄▄█ ▒█░░▀█ ▒█▄▄▄█\r\n\r\n% ~ doesn't work here, so we need to use invisible characters instead\r\n\\renewcommand{\\SymTab}{\\phantom{>>}}\r\n% similar to \\SymTab, ~ doesn't work, so we use manual space instead; however the macros already space it way too much, so we basically need to reduce it to get approximate 1 space\r\n\\renewcommand{\\SymSpc}{\\hspace*{-2ex}}\r\n\r\n% all drawings should be scaled up and drawn slightly to the left to be aligned perfectly with the rest of the text. Note that instruction tables use optional parameter for vertical spacing, we take it over for horizontal spacing - vertical spacing is fine in details, but we do need horizontal to align drawing with rest of the text\r\n\\renewcommand{\\SymDrawing}[2][-1.7em]{\r\n\t\\hspace*{#1}\r\n\t\\scalebox{1.5}{\r\n\t\t\\scriptsize\r\n\t\t#2\r\n\t}\r\n}\r\n\r\n% these redeclaration allows us to reuse all previously declared flags so changes can only be made in single place\r\n\\renewcommand{\\FlagsFPP}{\\FS}\t\t% we indicate PF status in header, so use standard in table\r\n\\renewcommand{\\FlagsFPV}{\\FS}\t\t% we indicate VF status in header, so use standard in table\r\n\\renewcommand{\\FlagsSmall}[1]{\\footnotesize #1}\t% larger font than in tables above\r\n\\renewcommand{\\FlagsSee}[1]{}\t\t% we don't want to display any footnotes in details section, we describe unusual cases below table\r\n\\renewcommand{\\FlagsNoEffect}{No effect on flags}   % we do want to show this text in details\r\n\r\n% and the main flags redeclaration as well - we need additional columns and different formatting in details tables\r\n% see \"EFFECTS TABLE\" section below for table declaration\r\n\\renewcommand{\\Flags}[7][]{\r\n\t& \r\n\t#1 & \r\n\t\\multicolumn{1}{|c|}{\\tt #2} & \r\n\t{\\tt #3} & \r\n\t& \r\n\t{\\tt #4} & \r\n\t& \r\n\t{\\tt #5} & \r\n\t{\\tt #6} & \r\n\t{\\tt #7} \\notet\\noteb \\\\\\cline{3-10}\r\n}\r\n\r\n\r\n% ▒█▀▀█ ▒█▀▀▀█ ▒█▀▄▀█ ▒█▀▄▀█ ▒█▀▀▀█ ▒█▄░▒█ 　 ▒█▀▀▄ ▒█▀▀▀ ▒█▀▀█ ▒█░░░ ░█▀▀█ ▒█▀▀█ ░█▀▀█ ▀▀█▀▀ ▀█▀ ▒█▀▀▀█ ▒█▄░▒█ ▒█▀▀▀█ \r\n% ▒█░░░ ▒█░░▒█ ▒█▒█▒█ ▒█▒█▒█ ▒█░░▒█ ▒█▒█▒█ 　 ▒█░▒█ ▒█▀▀▀ ▒█░░░ ▒█░░░ ▒█▄▄█ ▒█▄▄▀ ▒█▄▄█ ░▒█░░ ▒█░ ▒█░░▒█ ▒█▒█▒█ ░▀▀▀▄▄ \r\n% ▒█▄▄█ ▒█▄▄▄█ ▒█░░▒█ ▒█░░▒█ ▒█▄▄▄█ ▒█░░▀█ 　 ▒█▄▄▀ ▒█▄▄▄ ▒█▄▄█ ▒█▄▄█ ▒█░▒█ ▒█░▒█ ▒█░▒█ ░▒█░░ ▄█▄ ▒█▄▄▄█ ▒█░░▀█ ▒█▄▄▄█\r\n\r\n\r\n% mnemonic - also serves as the title for instruction\r\n\\newcommand{\\DetailMnemonic}[1]{\\item[{\\tt \\large \\textbf{#1}}]}\r\n\r\n% symbolic operation\r\n\\newcommand{\\DetailSymbol}[1]{{\\tt #1}}\r\n% symbolic operation for alternative variants\r\n\\newcommand{\\DetailSymbolVariants}[2]{\r\n\t\\small\r\n\t\\underline{\\tt #1}:\\\\[1ex]\r\n\t\\DetailSymbol{#2}\r\n}\r\n\r\n% name - explains the letters used for mnemonic\r\n\\newcommand{\\DetailName}[1]{\\textbf{#1}}\r\n\r\n% (I)nstruction (H)ighlight (for highlighting letters forming mnemonic in `DetailName`)\r\n\\newcommand{\\IH}[1]{\\underline{#1}}\r\n\r\n% forms label name for the given item\r\n% #1 mnemonic\r\n\\newcommand{\\DetailItemRef}[1]{InstrDetailRef#1}\r\n% this is used to avoid warning about repeated label in macros below (in reality there is no repetition in the generated document, just suppresses compiler warning)\r\n\\newcommand{\\DetailItemLabel}[1]{\\label{\\DetailItemRef{#1}}}\r\n% convenience for less verbose page reference for given item\r\n% #1 mnemonic\r\n\\newcommand{\\DetailItemPageRef}[1]{\\pageref{\\DetailItemRef{#1}}}\r\n\r\n\r\n% ▒█▀▄▀█ ░█▀▀█ ▀█▀ ▒█▄░▒█ 　 ▒█▀▀▄ ▒█▀▀▀ ▒█▀▀█ ▒█░░░ ░█▀▀█ ▒█▀▀█ ░█▀▀█ ▀▀█▀▀ ▀█▀ ▒█▀▀▀█ ▒█▄░▒█ ▒█▀▀▀█ \r\n% ▒█▒█▒█ ▒█▄▄█ ▒█░ ▒█▒█▒█ 　 ▒█░▒█ ▒█▀▀▀ ▒█░░░ ▒█░░░ ▒█▄▄█ ▒█▄▄▀ ▒█▄▄█ ░▒█░░ ▒█░ ▒█░░▒█ ▒█▒█▒█ ░▀▀▀▄▄ \r\n% ▒█░░▒█ ▒█░▒█ ▄█▄ ▒█░░▀█ 　 ▒█▄▄▀ ▒█▄▄▄ ▒█▄▄█ ▒█▄▄█ ▒█░▒█ ▒█░▒█ ▒█░▒█ ░▒█░░ ▄█▄ ▒█▄▄▄█ ▒█░░▀█ ▒█▄▄▄█\r\n\r\n% main instruction enviroment, takes 3 parameters:\r\n% #1 mnemonic only (mainly for section names and references)\r\n% #2 parameters (uses `DetailMnemonic` under the hood)\r\n% #3 name (uses `DetailName` under the hood)\r\n% #4 symbolic operation (uses `DetailSymbol` under the hood)\r\n\\newenvironment{DetailItem}[4]{\r\n\t% insert invisible section marker for TOC\r\n\t\\refstepcounter{section}\r\n\t\\addcontentsline{toc}{section}{\\protect\\numberline{\\thesection}#1}\r\n\t\\sectionmark{#1}\r\n\r\n\t\\DetailItemLabel{#1}\r\n\t\\DetailMnemonic{#1 #2}\r\n\t\\DetailName{#3}\r\n\t% if symbolic operation is not given we should not use any spacing, otherwise, we should\r\n\t\\if\\relax\\detokenize{#4}\\relax\r\n\t\t% we don't have symbolic operation\r\n\t\\else\r\n\t\t\\\\[1.2ex]\r\n\t\t\\DetailSymbol{#4}\r\n\t\\fi\r\n\t% reduce spacing before and after multicols\r\n\t\\setlength{\\multicolsep}{1ex}\r\n\r\n}{\r\n\t% we want some spacing below each item\r\n\t\\vspace{1em}\r\n}\r\n\r\n% same as DetailItem but allows 2 lines for title:\r\n% #1 mnemonic line 1 (uses `DetailMnemonic` under the hood)\r\n% #2 parameters line 1\r\n% #3 name for line 1 (uses `DetailName` under the hood)\r\n% #4 mnemonic line 2 (for second line)\r\n% #5 parameters line 2\r\n% #6 name for line 2\r\n% #7 symbolic operation (uses `DetailSymbol` under the hood)\r\n\\newenvironment{DetailItemMultiline}[7]{\r\n\t% insert invisible section marker for TOC (only for e-book)\r\n\t\\ifdefined\\isPDF\r\n\t\t\\refstepcounter{section}\r\n\t\t\\addcontentsline{toc}{section}{\\protect\\numberline{\\thesection}#1 / #4}\r\n\t\t\\sectionmark{#1 / #4}\r\n\t\\fi\r\n\r\n\t\\DetailItemLabel{#1}\r\n\t\\DetailItemLabel{#4}\r\n\t\\DetailMnemonic{#1 #2\\\\#4 #5}\r\n\t\\DetailName{#3\\\\#6}\r\n\t% if symbolic operation is not given we should not use any spacing, otherwise, we should\r\n\t\\if\\relax\\detokenize{#7}\\relax\r\n\t\t% we don't have symbolic operation\r\n\t\\else\r\n\t\t\\\\[1.2ex]\r\n\t\t\\DetailSymbol{#7}\r\n\t\\fi\r\n\t% reduce spacing before and after multicols\r\n\t\\setlength{\\multicolsep}{1ex}\r\n\r\n}{\r\n\t% we want some spacing below each item\r\n\t\\vspace{1em}\r\n}\r\n\r\n% use this as parameters in above 2 macros when ZX Next Extended instruction doesn't have any parameters. It will eliminate space between mnemonic and ZX indicator\r\n\\newcommand{\\DetailItemZXN}{\\hspace*{-1ex}\\ZXN}\r\n\r\n\r\n% ▒█▀▀▄ ▒█▀▀▀ ▒█▀▀▀█ ▒█▀▀█ ▒█▀▀█ ▀█▀ ▒█▀▀█ ▀▀█▀▀ ▀█▀ ▒█▀▀▀█ ▒█▄░▒█ 　 ▒█▀▀▀█ ▒█▀▀▀ ▒█▀▀█ ▀▀█▀▀ ▀█▀ ▒█▀▀▀█ ▒█▄░▒█ \r\n% ▒█░▒█ ▒█▀▀▀ ░▀▀▀▄▄ ▒█░░░ ▒█▄▄▀ ▒█░ ▒█▄▄█ ░▒█░░ ▒█░ ▒█░░▒█ ▒█▒█▒█ 　 ░▀▀▀▄▄ ▒█▀▀▀ ▒█░░░ ░▒█░░ ▒█░ ▒█░░▒█ ▒█▒█▒█ \r\n% ▒█▄▄▀ ▒█▄▄▄ ▒█▄▄▄█ ▒█▄▄█ ▒█░▒█ ▄█▄ ▒█░░░ ░▒█░░ ▄█▄ ▒█▄▄▄█ ▒█░░▀█ 　 ▒█▄▄▄█ ▒█▄▄▄ ▒█▄▄█ ░▒█░░ ▄█▄ ▒█▄▄▄█ ▒█░░▀█\r\n\r\n% describes all variants of the instruction - only used where applicable. Note this can generate 2 variants based on optional parameter:\r\n% - if parameter is number (defaults to 3), then `multicols` environment is used and parameter is taken to be number of columns\r\n% - otherwise `tabularx` is used and parameter is taken to be columns definitions\r\n\\NewDocumentEnvironment{DetailVariants}{ O{3} +b }{\r\n\t{\r\n\t\t\\tt\r\n\t\t\\StrLeft{#1}{1}[\\FirstLetter]\r\n\t\t\\IfInteger{\\FirstLetter}{\r\n\t\t\t\\begin{multicols}{#1}\r\n\t\t\t\t#2\r\n\t\t\t\\end{multicols}\r\n\t\t}{\r\n\t\t\t\\vspace*{0.8ex}\r\n\t\t\t\\begin{tabularx}{\\linewidth}{@{}#1}\r\n\t\t\t\t#2\r\n\t\t\t\\end{tabularx}\r\n\t\t}\r\n\t}\r\n}{}\r\n\r\n% `itemize` environment with less spacing, suitable for instruction description section\r\n\\NewDocumentEnvironment{DetailCompactList}{ O{} +b }{\r\n\t#1\r\n\t\\vspace{-6pt}\r\n\t\\setlist{leftmargin=1em}\r\n\t\\begin{itemize}\r\n\t\t\\setlength\\itemsep{-1pt}\r\n\t\t#2\r\n\t\\end{itemize}\r\n}{}\r\n\r\n\r\n% ▒█▀▀▀ ▒█▀▀▀ ▒█▀▀▀ ▒█▀▀▀ ▒█▀▀█ ▀▀█▀▀ ▒█▀▀▀█ 　 ▀▀█▀▀ ░█▀▀█ ▒█▀▀█ ▒█░░░ ▒█▀▀▀ \r\n% ▒█▀▀▀ ▒█▀▀▀ ▒█▀▀▀ ▒█▀▀▀ ▒█░░░ ░▒█░░ ░▀▀▀▄▄ 　 ░▒█░░ ▒█▄▄█ ▒█▀▀▄ ▒█░░░ ▒█▀▀▀ \r\n% ▒█▄▄▄ ▒█░░░ ▒█░░░ ▒█▄▄▄ ▒█▄▄█ ░▒█░░ ▒█▄▄▄█ 　 ░▒█░░ ▒█░▒█ ▒█▄▄█ ▒█▄▄█ ▒█▄▄▄\r\n\r\n% renders PV title that also indicates whether the PV indicates parity or overflow; parameters:\r\n% (required) #1 parity type:\r\n% - p = indicate Parity\r\n% - v = indicate oVerflow\r\n% - default = just PV\r\n\\NewDocumentCommand{\\DetailParityOverflow}{ m }{\r\n\t\\IfEqCase{#1}\r\n\t{\r\n\t\t{p}{\r\n\t\t\t\\hspace*{-0.9ex}\t% this achieves better visually pleasing centering in the tables\r\n\t\t\t\\small\r\n\t\t\t\\begin{tikzpicture}[baseline=(p.base), plain/.style={}]\r\n\t\t\t\t\\node (p) [plain] {P};\r\n\t\t\t\t\\node (v) [plain, right=1.9ex of p.west] {V};\r\n\t\t\t\t\\draw (p.center) ++(0,0.2pt) circle(1.3ex);\r\n\t\t\t\\end{tikzpicture}\r\n\t\t}\r\n\t\t{v}{\r\n\t\t\t\\hspace*{-1.4ex}\t% this achieves better visually pleasing centering in the tables\r\n\t\t\t\\small\r\n\t\t\t\\begin{tikzpicture}[baseline=(p.base), plain/.style={}]\r\n\t\t\t\t\\node (p) [plain] {P};\r\n\t\t\t\t\\node (v) [plain, right=1.95ex of p.west] {V};\r\n\t\t\t\t\\draw (v.center) ++(0.2pt,0.5pt) circle(1.3ex);\r\n\t\t\t\\end{tikzpicture}\r\n\t\t}\r\n\t\t{}{PV}\r\n\t}\r\n}\r\n\r\n% renders header cell for effects table\r\n\\NewDocumentCommand{\\DetailEffectHead}{ m }{\\cellcolor{PrintableLightGray}#1}\r\n\r\n% effects table for instruction; optional parameter:\r\n% - p = indicate Parity\r\n% - v = indicate oVerflow\r\n% - default = just PV\r\n\\NewDocumentEnvironment{DetailEffects}{ O{} O{Effects} +b }{   \r\n\t%                               /spacer\r\n\t%                               |/note\r\n\t\\vspace{3pt}                   %||/SF     /ZF      /(YF)    /HF      /(XF)    /PV      /NF      /CF      |\r\n\t\\begin{tabularx}{\\linewidth}{@{}lXC{3.8ex}|C{3.8ex}|C{3.6ex}|C{3.8ex}|C{3.6ex}|C{3.8ex}|C{3.8ex}|C{3.8ex}|@{}}\r\n\t\t% we need to use hhline because \\cellcolor renders on top of cline/hline, and we can't use \\rowcolor because we only want some cells to use background...\r\n\t\t\\hhline{~~|*{8}{-|}}\r\n\r\n\t\t\\multicolumn{2}{@{}X}{\\textbf{#2}} &\r\n\t\t\\multicolumn{1}{|c|}{\\DetailEffectHead{SF}} &\r\n\t\t\\DetailEffectHead{ZF} &\r\n\t\t\\DetailEffectHead{} &\r\n\t\t\\DetailEffectHead{HF} &\r\n\t\t\\DetailEffectHead{} &\r\n\t\t\\DetailEffectHead{\\DetailParityOverflow{#1}} &\r\n\t\t\\DetailEffectHead{NF} &\r\n\t\t\\DetailEffectHead{CF}\\notet\\noteb\\\\[1pt]\\cline{3-10}\r\n\r\n\t\t#3\r\n\r\n\t\\end{tabularx}\r\n\t\\vspace{2pt}\r\n}{}\r\n\r\n% effects details\r\n\\NewDocumentEnvironment{DetailEffectsFlags}{ +b }{\r\n\t{\r\n\t\\vspace{0pt}\r\n\t\\renewcommand{\\arraystretch}{0.5}\t% setting default row spacing low will allow us to manipulate individual rows to be taller (see \\DetailFlag)\r\n\t\\begin{tabularx}{\\linewidth}{@{}llR{3.35cm}X}\r\n\r\n\t\t#1\r\n\r\n\t\\end{tabularx}\r\n\t\\vspace{2pt}\r\n\t}\r\n}{}\r\n\r\n% common flag result descriptions\r\n\\NewDocumentCommand{\\DetailFlagResultHalfBorrow}{ s }{borrow from bit 4\\IfBooleanTF{#1}{ (bit 12 for 16-bit)}{}}\r\n\\NewDocumentCommand{\\DetailFlagResultBorrow}{ s }{borrow from bit 8\\IfBooleanTF{#1}{ (bit 16 for 16-bit)}{}}\r\n\\NewDocumentCommand{\\DetailFlagResultHalfCarry}{ s }{carry from bit 3\\IfBooleanTF{#1}{ (bit 11 for 16-bit)}{}}\r\n\\NewDocumentCommand{\\DetailFlagResultCarry}{ s }{carry from bit 7\\IfBooleanTF{#1}{ (bit 15 for 16-bit)}{}}\r\n\\newcommand{\\DetailFlagResultOverflowListBottomSpacing}{\\vspace*{-4ex}}\r\n\\newcommand{\\DetailFlagResultSign}[1][]{\\IfEq{#1}{}{result}{{\\tt #1}} is negative (bit {\\tt 7} is set)}\r\n\\newcommand{\\DetailFlagResultZero}[1][]{\\IfEq{#1}{}{result}{{\\tt #1}} is {\\tt 0}}\r\n\\newcommand{\\DetailFlagResultParity}[1][]{\\IfEq{#1}{}{result}{{\\tt #1}} has even number of bits set}\r\n\\newcommand{\\DetailFlagResultOverflow}{\r\n\t\\DetailFlagsList{\r\n\t\t\\item both operands positive and result negative\r\n\t\t\\item both operands negative and result positve\r\n\t}\r\n\t\\DetailFlagResultOverflowListBottomSpacing % we don't want additional space below the table, otherwise next item would have larger gap\r\n}\r\n\r\n% describes the given flag in details\r\n% #1 mandatory flag name, empty will leave less space before this row\r\n% #2 mandatory prefix before description\r\n% #3 mandatory description\r\n% #4 optional, if \"p\" some vertical \"prefix\" space is inserted above\r\n% note use of \\rule when #1 (flag name) is empty - we want to have less spacing before next row in such case to keep all rows of the same flag closer together (don't use both, #4=p and empty #1 since they both set rules, results may be unpredictable)\r\n\\NewDocumentCommand{\\DetailFlag}{ m m m O{} }{\r\n\t& \\textbf{#1} & #2 & #3 \r\n\t\\IfEq{#4}{p}{\r\n\t\t\\rule{0pt}{1ex}\r\n\t\t\\rule[-2ex]{0pt}{0pt}\r\n\t}{}\r\n\t\\IfEq{#1}{}{}{\r\n\t\t\\rule[2.5ex]{0pt}{0pt}\r\n\t} \\\\[2pt]\r\n}\r\n% concrete flags (so we don't have to type in the names as strings)\r\n% #1 optional prefix before description (default = \"set if:\")\r\n% #2 optional name of the flag, empty will leave less space before this row\r\n% #3 mandatory description\r\n% #4 * to add some vertical spacing before the item, empty to leave default\r\n\\NewDocumentCommand{\\DetailFlagSF}{ O{set if:} O{SF} m s }{\\DetailFlag{#2}{#1}{#3}[\\IfBooleanTF{#4}{p}{}]}\r\n\\NewDocumentCommand{\\DetailFlagZF}{ O{set if:} O{ZF} m s }{\\DetailFlag{#2}{#1}{#3}[\\IfBooleanTF{#4}{p}{}]}\r\n\\NewDocumentCommand{\\DetailFlagHF}{ O{set if:} O{HF} m s }{\\DetailFlag{#2}{#1}{#3}[\\IfBooleanTF{#4}{p}{}]}\r\n\\NewDocumentCommand{\\DetailFlagPV}{ O{set if:} O{PV} m s }{\\DetailFlag{#2}{#1}{#3}[\\IfBooleanTF{#4}{p}{}]}\r\n\\NewDocumentCommand{\\DetailFlagNF}{ O{set if:} O{NF} m s }{\\DetailFlag{#2}{#1}{#3}[\\IfBooleanTF{#4}{p}{}]}\r\n\\NewDocumentCommand{\\DetailFlagCF}{ O{set if:} O{CF} m s }{\\DetailFlag{#2}{#1}{#3}[\\IfBooleanTF{#4}{p}{}]}\r\n\r\n% creates a list with specific margins and spacing to be used within detail flags descriptions\r\n\\newcommand{\\DetailFlagsList}[1]{\r\n\t\\vspace{-3ex}\r\n\t\\setlist{leftmargin=1em,after=\\vspace{-2ex}}\r\n\t\\begin{itemize}\r\n\t\t\\setlength\\itemsep{-1pt}\r\n\t\t#1\r\n\t\\end{itemize}\r\n}\r\n\r\n% this is used where additional comments are needed below flags table (actually, technically, from LaTeX point of view, from within the table itself); each item should be provided with `\\item` command\r\n\\newcommand{\\DetailFlagsComments}[1]{ \r\n\t& & \\multicolumn{8}{p{7.8cm}}{\r\n\t\t\\vspace{1ex}\t% compensate for -3ex from \\DetailFlagsList, we want -2ex\r\n\t\t\\DetailFlagsList{#1}\r\n\t\t\\vspace{2ex}\t% compenase for -2ex from \\DetailFlagsList, we want default\r\n\t} \\\\[-3ex]\r\n}\r\n\r\n\r\n% ▀▀█▀▀ ▀█▀ ▒█▀▄▀█ ▀█▀ ▒█▄░▒█ ▒█▀▀█ 　 ▒█▀▀▀█ ▒█▀▀▀ ▒█▀▀█ ▀▀█▀▀ ▀█▀ ▒█▀▀▀█ ▒█▄░▒█ \r\n% ░▒█░░ ▒█░ ▒█▒█▒█ ▒█░ ▒█▒█▒█ ▒█░▄▄ 　 ░▀▀▀▄▄ ▒█▀▀▀ ▒█░░░ ░▒█░░ ▒█░ ▒█░░▒█ ▒█▒█▒█ \r\n% ░▒█░░ ▄█▄ ▒█░░▒█ ▄█▄ ▒█░░▀█ ▒█▄▄█ 　 ▒█▄▄▄█ ▒█▄▄▄ ▒█▄▄█ ░▒█░░ ▄█▄ ▒█▄▄▄█ ▒█░░▀█\r\n\r\n% the main timing environment; optional parameter allows specifying the title, defaults to \"Timing\"\r\n\\NewDocumentEnvironment{DetailTiming}{ O{Timing} +b }{\r\n\t\\vspace{1pt}\r\n\t\\begin{tabularx}{0.8\\textwidth}{@{}lXccrrrr@{}}\r\n\t\t\\multicolumn{2}{@{}X}{\\textbf{#1}} & Mc & Ts & 3.5MHz & 7MHz & 14MHz & 28MHz \\\\[1pt]\r\n\t\t#2\r\n\t\\end{tabularx}\r\n}{}\r\n\r\n% formats individual timing item; parameters\r\n% - optional: number of digits to round to (defaults to 2)\r\n% - T states\r\n% - CPU frequency to adjust to\r\n% note: this is meant to be used internally by other detail time commands, the only reason for implementing it as its own command is to unify formatting\r\n% note: command must be single line to avoid spaces being added on either side...\r\n\\newcommand{\\DetailTimeItem}[3][2]{\\nprounddigits{#1}{\\small {\\tt \\numprint{\\fpeval{#2/#3}}}$\\mu$s}}\r\n\r\n% individual time; parameters:\r\n% - optional description, omit if none (which is the default)\r\n% - number of machine cycles\r\n% - number to T states\r\n% note: the times in microsec are automatically calculated from Ts\r\n\\newcommand{\\DetailTimeRegular}[3][]{\r\n\t& #1 & #2 & #3 & \r\n\t\t\\DetailTimeItem[1]{#3}{3.5} & \r\n\t\t\\DetailTimeItem{#3}{7} &\r\n\t\t\\DetailTimeItem{#3}{14} &\r\n\t\t\\DetailTimeItem{#3}{28} \\\\\r\n}\r\n% same as `DetailTimeRegular` but uses mono font for first (optional) parameter\r\n\\newcommand{\\DetailTime}[3][]{\\DetailTimeRegular[{\\tt #1}]{#2}{#3}}\r\n\r\n\r\n% ▒█▀▄▀█ ▀█▀ ▒█▀▀▀█ ▒█▀▀█ \r\n% ▒█▒█▒█ ▒█░ ░▀▀▀▄▄ ▒█░░░ \r\n% ▒█░░▒█ ▄█▄ ▒█▄▄▄█ ▒█▄▄█\r\n\r\n% notes with additional information about instruction; optional parameter: if not empty, it is interpretted as size, empty will yield no space (this is used for multiple successive notes so that they are more compact vertically)\r\n\\newcommand{\\DetailNote}[2][1.5ex]{\r\n\t\\IfEq{#1}{}{\r\n\t\t% if empty, no spacing should be applied\r\n\t}{\r\n\t\t% otherwise interpret #1 as size and use for vertical spacing\r\n\t\t\\vspace*{#1}\r\n\t}\r\n\t% either way, print note in smaller font\r\n\t{\\small \\normalfont{#2}}\r\n}\r\n\r\n% references to multiple items from other pages; parameters:\r\n% #1 items description\r\n% #2 page references (from `label` command)\r\n\\newcommand{\\DetailItemsSeePageReference}[2]{\r\n\t\\vspace*{-1.5em}\r\n\t\\desclabelstyle{\\pushlabel}\r\n\t\\DetailMnemonic{#1}\r\n\t\\desclabelstyle{\\multilinelabel}\r\n\t\\DetailNote{#2}\r\n}\r\n% reference to single item from another page\r\n% #1 mnemonic (also serves to form the page reference itself)\r\n\\newcommand{\\DetailItemSeePageReference}[1]{\r\n\t\\DetailItemsSeePageReference{#1}{See page \\DetailItemPageRef{#1}}\r\n}\r\n"
  },
  {
    "path": "defines.tex",
    "content": "\\newcommand*{\\isPDF}{1}\r\n\\newcommand*{\\isWIP}{1}\r\n\r\n\r\n% ░█▀▀█ ▒█▀▀█ ▒█▀▀▀█ ▒█░▒█ ▀▀█▀▀ \r\n% ▒█▄▄█ ▒█▀▀▄ ▒█░░▒█ ▒█░▒█ ░▒█░░ \r\n% ▒█░▒█ ▒█▄▄█ ▒█▄▄▄█ ░▀▄▄▀ ░▒█░░\r\n\r\n% general document info for simpler reuse\r\n\\newcommand{\\AuthorName}{Toma\\v{z}}\r\n\\newcommand{\\AuthorNameSurname}{\\AuthorName ~Kragelj}\r\n\\newcommand{\\BookTitleMain}{ZX Spectrum Next}\r\n\\newcommand{\\BookTitleSub}{Assembly Developer Guide}\r\n\\newcommand{\\BookTitle}{\\BookTitleMain~\\BookTitleSub}\r\n\\newcommand{\\BookKeywords}{zx,next,spectrum,retro,documentation,manual,guide,assembly,language,programming}\r\n\r\n\r\n% ▒█▀▀█ ▒█▀▀▀ ▒█░░▒█ ▀█▀ ▒█▀▀▀█ ▀█▀ ▒█▀▀▀█ ▒█▄░▒█ ▒█▀▀▀█ \r\n% ▒█▄▄▀ ▒█▀▀▀ ░▒█▒█░ ▒█░ ░▀▀▀▄▄ ▒█░ ▒█░░▒█ ▒█▒█▒█ ░▀▀▀▄▄ \r\n% ▒█░▒█ ▒█▄▄▄ ░░▀▄▀░ ▄█▄ ▒█▄▄▄█ ▄█▄ ▒█▄▄▄█ ▒█░░▀█ ▒█▄▄▄█\r\n\r\n\\newcommand{\\LatestYear}{2022}\r\n\\newcommand{\\LatestMonthName}{July}\r\n\\newcommand{\\LatestMonth}{07}\r\n\\newcommand{\\LatestDay}{15}\r\n\r\n% revision name is nicely structured variant with named month\r\n\\newcommand{\\LatestRevisionName}{\\LatestDay~\\LatestMonthName~\\LatestYear}\r\n\r\n% revision date is \"reverse domain\" type that can be easily sorted in various computer lists; also suitable for git tags\r\n\\newcommand{\\LatestRevisionDate}{\\LatestYear-\\LatestMonth-\\LatestDay}\r\n\r\n% older revisions\r\n\\newcommand{\\RevisionTwoDate}{2021-11-11}\r\n\\newcommand{\\RevisionTwoName}{11 November 2021}\r\n\r\n\\newcommand{\\RevisionOneDate}{2021-07-16}\r\n\\newcommand{\\RevisionOneName}{16 July 2021}\r\n\r\n\r\n% ▒█▀▀▀ ▒█░░░ ▒█▀▀▀ ▒█▀▄▀█ ▒█▀▀▀ ▒█▄░▒█ ▀▀█▀▀ ▒█▀▀▀█ \r\n% ▒█▀▀▀ ▒█░░░ ▒█▀▀▀ ▒█▒█▒█ ▒█▀▀▀ ▒█▒█▒█ ░▒█░░ ░▀▀▀▄▄ \r\n% ▒█▄▄▄ ▒█▄▄█ ▒█▄▄▄ ▒█░░▒█ ▒█▄▄▄ ▒█░░▀█ ░▒█░░ ▒█▄▄▄█\r\n\r\n% creates an email (obfuscated for PDF variant), Discord or Twitter user text\r\n\\newcommand{\\email}[3]{\\ifdefined\\isPDF{\\tt #1 AT #2 DOT #3}\\else{\\tt #1@#2.#3}\\fi}\r\n\\newcommand{\\discord}[1]{{\\tt @#1}}\r\n\\newcommand{\\twitter}[1]{{\\tt @#1}}\r\n\r\n% sets given font size for just \"selected\" text\r\n\\newcommand{\\FontSize}[2]{\\fontsize{#1}{#1}\\selectfont #2}\r\n\r\n% creates minitoc without any headers; parameters:\r\n% - (optional) #1 boolean; if star present, no styling will be applied after TOC, otherwise default styling will be applied (which is the default)\r\n% - (optional) #1 boolean; if present, chapter TOC is generated, otherwise not (default will create TOC)\r\n\\NewDocumentCommand{\\ChapterTOC}{ o o }{\r\n\t\\pagestyle{nosectionmarker}\r\n\r\n\t% if #2 is present (aka not \"[]\"), render TOC.\r\n\t\\IfValueF{#2}{\r\n\t\t\\etocsettocstyle{}{}\t% no title\r\n\t\t\\localtableofcontents\r\n\t}\r\n\t\\thispagestyle{plain}\t% simple TOC pages without headers\r\n\t\r\n\t% if #1 is present (aka not \"[]\"), set page style to clean\r\n\t\\IfValueF{#1}{\\pagestyle{clean}}\r\n}\r\n\r\n% we can use this for pages that are intentionally left blank\r\n\\newcommand{\\IntentionallyEmpty}{\r\n\t\\mbox{}\r\n\t\\vfill\r\n\t\\begin{center}\r\n\tThis page intentionally left empty\r\n\t\\end{center}\r\n\t\\vfill\r\n\t\\mbox{}\r\n}\r\n\r\n% renders \"work in progress\" text using current font and size.\r\n\\newcommand{\\WorkInProgress}{\\ifdefined\\isWIP\\color{red}\\textbf{WORK IN PROGRESS}\\fi}\r\n\r\n% renders \"work in progress\" sign for use on \"full screen\" pages; uses \\Huge font by default, but that can be changed with optional parameter\r\n\\newcommand{\\WorkInProgressFullScreen}[1][\\normalsize]{\r\n\t\\ifdefined\\isWIP\r\n\t\t#1\r\n\t\t\\begin{center}\r\n\t\t\t\\WorkInProgress\r\n\t\t\\end{center}\r\n\t\\fi\r\n}\r\n\r\n\\newenvironment{changemargin}[2]{%\r\n\t\\begin{list}{}{%\r\n\t\t\\setlength{\\topsep}{0pt}%\r\n\t\t\\setlength{\\leftmargin}{#1}%\r\n\t\t\\setlength{\\rightmargin}{#2}%\r\n\t\t\\setlength{\\listparindent}{\\parindent}%\r\n\t\t\\setlength{\\itemindent}{\\parindent}%\r\n\t\t\\setlength{\\parsep}{\\parskip}%\r\n\t}%\r\n\\item[]}{\\end{list}}\r\n\r\n\r\n% ▒█▀▀█ ▒█▀▀▀█ ▒█░░░ ▒█▀▀▀█ ▒█░▒█ ▒█▀▀█ ▒█▀▀▀█ \r\n% ▒█░░░ ▒█░░▒█ ▒█░░░ ▒█░░▒█ ▒█░▒█ ▒█▄▄▀ ░▀▀▀▄▄ \r\n% ▒█▄▄█ ▒█▄▄▄█ ▒█▄▄█ ▒█▄▄▄█ ░▀▄▄▀ ▒█░▒█ ▒█▄▄▄█\r\n\r\n\\definecolor{PrintableLightGray}{rgb}{0.85, 0.85, 0.85}\r\n\\definecolor{PrintableLightMidGray}{rgb}{0.7675, 0.7675, 0.7675}\r\n\\definecolor{PrintableMidGray}{rgb}{0.675, 0.675, 0.675}\r\n\\definecolor{PrintableDarkGray}{rgb}{0.5, 0.5, 0.5}\r\n\r\n\r\n% ▒█▀▀▀█ ▒█░▒█ ▒█▀▀▀█ ▒█▀▀█ ▀▀█▀▀ ▒█░▒█ ░█▀▀█ ▒█▄░▒█ ▒█▀▀▄ ▒█▀▀▀█ \r\n% ░▀▀▀▄▄ ▒█▀▀█ ▒█░░▒█ ▒█▄▄▀ ░▒█░░ ▒█▀▀█ ▒█▄▄█ ▒█▒█▒█ ▒█░▒█ ░▀▀▀▄▄ \r\n% ▒█▄▄▄█ ▒█░▒█ ▒█▄▄▄█ ▒█░▒█ ░▒█░░ ▒█░▒█ ▒█░▒█ ▒█░░▀█ ▒█▄▄▀ ▒█▄▄▄█\r\n\r\n% less tall slash\r\n\\newcommand\\scslash{\\stretchrel*{$/$}{\\textsc{e}}}\r\n\r\n% couple shorthands that can be used throughout the document\r\n\\newcommand{\\Deg}{\\textsuperscript{o}}\r\n\\newcommand{\\ddd}{\\makebox[1em][c]{.\\hfil.\\hfil.}}\r\n\\newcommand{\\See}[1]{\\textsuperscript{#1}}\r\n\\newcommand{\\UNDOC}{\\textnormal{\\textsuperscript{**}}}\r\n\\newcommand{\\ZXN}{\\textnormal{\\textsuperscript{ZX}}}\r\n\\newcommand{\\ZXNS}{\\tiny\\textnormal{\\textsuperscript{ZX}}}\r\n\\newcommand{\\High}{\\textsubscript{h}}\r\n\\newcommand{\\Low}{\\textsubscript{l}}\r\n\r\n% instruction flags definitions - for unified formatting\r\n\\newcommand{\\FS}{$\\updownarrow$} % standard effect\r\n\\newcommand{\\FN}{-}\t\t\t\t% no effect\r\n\\newcommand{\\FU}{?}\t\t\t\t% unknown effect\r\n\\newcommand{\\FX}{$\\bullet$}\t\t% special case\r\n\\newcommand{\\FPV}{VF}\t\t\t% PV=Overflow\r\n\\newcommand{\\FPP}{PF}\t\t\t% PV=Parity\r\n\r\n% flags with expected formatting\r\n\\newcommand{\\FlagSF}{\\textbf{SF}}\r\n\\newcommand{\\FlagZF}{\\textbf{ZF}}\r\n\\newcommand{\\FlagHF}{\\textbf{HF}}\r\n\\newcommand{\\FlagPV}{\\textbf{PV}}\r\n\\newcommand{\\FlagNF}{\\textbf{NF}}\r\n\\newcommand{\\FlagCF}{\\textbf{CF}}\r\n\r\n% cross reference with section and page number\r\n\\newcommand{\\XRef}[1]{\\ref{#1}, page \\pageref{#1}}\r\n\r\n% generic renderer for any chip pin label (uses line above); this is used for all concrete chip labels internally.\r\n\\newcommand{\\NoLinkChipPinLabel}[1]{$\\mathtt{\\overline{#1}}$}\r\n% renders the given Z80 chip pin label with link to Z80 chip diagram. Needless to say - only use for links to Z80 chip pins!\r\n\\newcommand{\\ZilogPinLabel}[1]{\\hyperref[z80_pin_descriptions]{\\NoLinkChipPinLabel{#1}}}\r\n% renders the given DMA chip pin label with link to DMA chip diagram (once we actually have it)\r\n\\newcommand{\\DMAPinLabel}[1]{\\NoLinkChipPinLabel{#1}}\r\n\r\n% other commonly used definitions\r\n\\newcommand{\\MemAddr}[1]{{\\tt \\$#1}}\r\n\r\n\r\n% ▒█▀▀█ ▒█▀▀▀█ ▒█▀▄▀█ ▒█▀▄▀█ ▒█▀▀▀█ ▒█▄░▒█ 　 ▒█▀▀▄ ▒█▀▀█ ░█▀▀█ ▒█░░▒█ ░█▀▀█ ▒█▀▀█ ▒█░░░ ▒█▀▀▀ ▒█▀▀▀█ \r\n% ▒█░░░ ▒█░░▒█ ▒█▒█▒█ ▒█▒█▒█ ▒█░░▒█ ▒█▒█▒█ 　 ▒█░▒█ ▒█▄▄▀ ▒█▄▄█ ▒█▒█▒█ ▒█▄▄█ ▒█▀▀▄ ▒█░░░ ▒█▀▀▀ ░▀▀▀▄▄ \r\n% ▒█▄▄█ ▒█▄▄▄█ ▒█░░▒█ ▒█░░▒█ ▒█▄▄▄█ ▒█░░▀█ 　 ▒█▄▄▀ ▒█░▒█ ▒█░▒█ ▒█▄▀▄█ ▒█░▒█ ▒█▄▄█ ▒█▄▄█ ▒█▄▄▄ ▒█▄▄▄█\r\n\r\n% horizontal arrows of arbitrary size (lehgth specified through parameter)\r\n\\newcommand{\\RArrow}[1]{\\parbox{#1}{\\tikz{\r\n\t\\draw[->,line width=0.5pt](0,0)--(#1,0);\r\n}}}\r\n\\newcommand{\\LArrow}[1]{\\parbox{#1}{\\tikz{\r\n\t\\draw[<-,line width=0.5pt](0,0)--(#1,0);\r\n}}}\r\n\r\n% horizontal arrows with vertical line on the arrow side; parameters:\r\n% - mandatory horizontal line width\r\n% - optional any additional horizontal line styles (dotted, dashed etc)\r\n% - optional vertical line height (divided by 2), default 0.1\r\n% - optional arrow scale, default 1\r\n% - optional line width, default 0.5pt\r\n\\NewDocumentCommand{\\RArrowLine}{ m O{} O{0.1} O{1.6} O{0.5pt} }{\\parbox{#1}{\\tikz{\r\n\t\\draw[-{>[scale=#4,length=#4,width=#4]},line width=#5,#2](0,0)--(#1,0);\r\n\t\\draw[line width=#5](#1,-#3)--(#1,#3);\r\n}}}\r\n\\NewDocumentCommand{\\LArrowLine}{ m O{} O{0.1} O{1.6} O{0.5pt} }{\\parbox{#1}{\\tikz{\r\n\t\\draw[line width=#5](0,-#3)--(0,#3);\r\n\t\\draw[-{>[scale=#4,length=#4,width=#4]},line width=#5,#2](#1,0)--(0,0);\r\n}}}\r\n\r\n\r\n% ▒█▀▀█ ▒█░▒█ ▒█▀▀▀█ ▀▀█▀▀ ▒█▀▀▀█ ▒█▀▄▀█ ▀█▀ ▒█▀▀▀█ ░█▀▀█ ▀▀█▀▀ ▀█▀ ▒█▀▀▀█ ▒█▄░▒█ ▒█▀▀▀█ \r\n% ▒█░░░ ▒█░▒█ ░▀▀▀▄▄ ░▒█░░ ▒█░░▒█ ▒█▒█▒█ ▒█░ ░▄▄▄▀▀ ▒█▄▄█ ░▒█░░ ▒█░ ▒█░░▒█ ▒█▒█▒█ ░▀▀▀▄▄ \r\n% ▒█▄▄█ ░▀▄▄▀ ▒█▄▄▄█ ░▒█░░ ▒█▄▄▄█ ▒█░░▒█ ▄█▄ ▒█▄▄▄█ ▒█░▒█ ░▒█░░ ▄█▄ ▒█▄▄▄█ ▒█░░▀█ ▒█▄▄▄█\r\n\r\n% define the style for lstlisting\r\n\\lstdefinestyle{CodeStyle}{\r\n\tbasicstyle=\\ttfamily\\small,\r\n\tcommentstyle=\\color{PrintableDarkGray},\r\n\tcolumns=flexible,\r\n\ttabsize=4,\r\n\tnumbers=left,\r\n\tnumberstyle=\\ttfamily\\tiny,\r\n\tnumbersep=1.8em,\r\n\tmorecomment=[l]{;},\r\n\tmoredelim=[is][\\rmfamily\\itshape]{|}{|},\t% any text within |...| will be roman/italic\r\n\tliterate={&}{\\$}1\t\t\t\t\t\t\t% replace `&` with `$` (to avoid syntax higlight issues)\r\n\t\t\t{Band}{\\&~}1\t\t\t\t\t\t% replace `Band` with `&` (to allow bitwise and output without & being consumed for $ from previous rule)\r\n\t\t\t{Bor}{|~}1\t\t\t\t\t\t\t% replace `Bor' with `|` (to allow bitwise or output without | being consumed for roman/italic from moredelim rule above)\r\n}\r\n\r\n% define default settings for all tcolorbox instances\r\n\\tcbset{\r\n\tarc=4pt,\t\t\t% radius for rounded corners\r\n\tboxrule=0pt,\t\t% no frame around the box\r\n\tboxsep=1.3ex,\t\t% add some spacing between frame and content\r\n\tleft=0ex,\t\t\t% left side should be flush with content\r\n\tright=0ex,\t\t\t% right side should be flush with content\r\n\ttop=-1.5ex,\t\t\t% less spacing between frame and start of content\r\n\tbottom=-1.5ex,\t\t% less spacing between end of content and frame\r\n\tpad at break=1pt,\t% leave some small spacing between content and frame when page break occurs\r\n\tbefore skip=2ex,\r\n\tafter skip=3ex,\r\n\tcolback=PrintableLightGray,\r\n\tcolframe=PrintableLightGray,\r\n\tenhanced,\t\t\t% only use rounded corners on top and bottom part, not between page breaks\r\n\tbreakable,\t\t\t% allow breaking tcolorbox to multiple pages\r\n\tlisting only,\t\t% only show listing\r\n\tlisting options={style=CodeStyle},\r\n}\r\n"
  },
  {
    "path": "instructions.tex",
    "content": "% ──────────────────────────────────────────────────────────\r\n% ─██████████████─████████──████████─██████──────────██████─\r\n% ─██░░░░░░░░░░██─██░░░░██──██░░░░██─██░░██████████████░░██─\r\n% ─██░░██████████─████░░██──██░░████─██░░░░░░░░░░░░░░░░░░██─\r\n% ─██░░██───────────██░░░░██░░░░██───██░░██████░░██████░░██─\r\n% ─██░░██████████───████░░░░░░████───██░░██──██░░██──██░░██─\r\n% ─██░░░░░░░░░░██─────████░░████─────██░░██──██░░██──██░░██─\r\n% ─██████████░░██───────██░░██───────██░░██──██████──██░░██─\r\n% ─────────██░░██───────██░░██───────██░░██──────────██░░██─\r\n% ─██████████░░██───────██░░██───────██░░██──────────██░░██─\r\n% ─██░░░░░░░░░░██───────██░░██───────██░░██──────────██░░██─\r\n% ─██████████████───────██████───────██████──────────██████─\r\n% ──────────────────────────────────────────────────────────\r\n\r\n\r\n% ▒█▀▀▄ ▒█▀▀▀ ▒█▀▀▀ ▀█▀ ▒█▄░▒█ ▀█▀ ▀▀█▀▀ ▀█▀ ▒█▀▀▀█ ▒█▄░▒█ ▒█▀▀▀█ \r\n% ▒█░▒█ ▒█▀▀▀ ▒█▀▀▀ ▒█░ ▒█▒█▒█ ▒█░ ░▒█░░ ▒█░ ▒█░░▒█ ▒█▒█▒█ ░▀▀▀▄▄ \r\n% ▒█▄▄▀ ▒█▄▄▄ ▒█░░░ ▄█▄ ▒█░░▀█ ▄█▄ ░▒█░░ ▄█▄ ▒█▄▄▄█ ▒█░░▀█ ▒█▄▄▄█\r\n\r\n% common declarations used within symbol definitions below; allow reuse of symbols but with different aesthetic later on\r\n\r\n% tab declaration that's used for all symbolic operation macros\r\n\\newcommand{\\SymTab}{~~}\r\n\\newcommand{\\SymSpc}{~}\r\n\r\n% drawing declaration that's used for all symbolic operation macros; allows redeclaring so that all drawings may be repositioned or resized for example; allows one optional argument that is used for vertical spacing by default (but can be reused for something else in redeclaration)\r\n\\newcommand{\\SymDrawing}[2][-10pt]{\r\n\t\\scriptsize\r\n\t\\vspace*{#1}\t% this will center drawings better\r\n\t#2\r\n}\r\n\r\n% ▒█▀▀▀█ ▒█▀▀█ ▒█▀▀▀ ▒█▀▀█ ░█▀▀█ ▀▀█▀▀ ▀█▀ ▒█▀▀▀█ ▒█▄░▒█ ▒█▀▀▀█ \r\n% ▒█░░▒█ ▒█▄▄█ ▒█▀▀▀ ▒█▄▄▀ ▒█▄▄█ ░▒█░░ ▒█░ ▒█░░▒█ ▒█▒█▒█ ░▀▀▀▄▄ \r\n% ▒█▄▄▄█ ▒█░░░ ▒█▄▄▄ ▒█░▒█ ▒█░▒█ ░▒█░░ ▄█▄ ▒█▄▄▄█ ▒█░░▀█ ▒█▄▄▄█\r\n\r\n\\newcommand{\\SymADD}[2]{#1$\\leftarrow$#1+#2}\r\n\r\n\\newcommand{\\SymADC}[2]{#1$\\leftarrow$#1+#2+CF}\r\n\r\n\\newcommand{\\SymAND}[1]{A$\\leftarrow$A$\\wedge$#1}\r\n\r\n\\newcommand{\\SymBIT}[1]{ZF$\\leftarrow\\mathtt{\\overline{#1_b}}$}\r\n\r\n\\newcommand{\\SymBRLC}[1][]{\\ignorespaces\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{DE$\\leftarrow$DE<<(B$\\wedge$\\$0F {\\normalfont or}}\r\n\t\t{1}{DE$\\leftarrow$DE>>(16-B$\\wedge$\\$0F)}\r\n\t\t{}{\\SymBRLC[0]\\\\\\SymBRLC[1]}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymBSLA}[1][]{ % we don't need parameters here, but keep it so it's similar to other BSxx instructions\r\n\tDE$\\leftarrow$DE<<(B$\\wedge$\\$1F)\r\n}\r\n\r\n\\newcommand{\\SymBSRA}[1][]{\\ignorespaces\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{DE$\\leftarrow$signed(DE)}\r\n\t\t{1}{>>(B$\\wedge$\\$1F)}\r\n\t\t{}{\\SymBSRA[0]\\SymBSRA[1]}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymBSRF}[1][]{\\ignorespaces\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{DE$\\leftarrow\\sim$(unsigned($\\sim$DE)}\r\n\t\t{1}{>>(B$\\wedge$\\$1F))}\r\n\t\t{}{\\SymBSRF[0]\\SymBSRF[1]}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymBSRL}[1][]{\\ignorespaces\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{DE$\\leftarrow$unsigned(DE)}\r\n\t\t{1}{>>(B$\\wedge$\\$1F)}\r\n\t\t{}{\\SymBSRL[0]\\SymBSRL[1]}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymCALL}[2][]{\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{(SP-1)$\\leftarrow$PC\\High}\r\n\t\t{1}{(SP-2)$\\leftarrow$PC\\Low}\r\n\t\t{2}{SP$\\leftarrow$SP-2}\r\n\t\t{3}{PC$\\leftarrow$#2}\r\n\t\t{}{\\SymCALL[0]{#2}\\\\\\SymCALL[1]{#2}\\\\\\SymCALL[2]{#2}\\\\\\SymCALL[3]{#2}}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymCALLc}[1]{\r\n\tif c=true:~CALL #1\r\n}\r\n\r\n\\newcommand{\\SymCCF}{CF$\\leftarrow\\mathtt{\\overline{CF}}$}\r\n\r\n\\newcommand{\\SymCP}[1]{A-#1}\r\n\r\n\\newcommand{\\SymCPD}[1][]{\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{A-(HL)}\r\n\t\t{1}{HL$\\leftarrow$HL-1}\r\n\t\t{2}{BC$\\leftarrow$BC-1}\r\n\t\t{}{\\SymCPD[0]\\\\\\SymCPD[1]\\\\\\SymCPD[2]}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymCPDR}[1][]{\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{do CPD}\r\n\t\t{1}{while A$\\neq$(HL)$\\wedge$BC>0}\r\n\t\t{}{\\SymCPDR[0]\\\\\\SymCPDR[1]}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymCPI}[1][]{\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{A-(HL)}\r\n\t\t{1}{HL$\\leftarrow$HL+1}\r\n\t\t{2}{BC$\\leftarrow$BC-1}\r\n\t\t{}{\\SymCPI[0]\\\\\\SymCPI[1]\\\\\\SymCPI[2]}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymCPIR}[1][]{\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{do CPI}\r\n\t\t{1}{while A$\\neq$(HL)$\\wedge$BC>0}\r\n\t\t{}{\\SymCPIR[0]\\\\\\SymCPIR[1]}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymCPL}{A$\\leftarrow\\mathtt{\\overline{A}}$}\r\n\r\n\\newcommand{\\SymDEC}[1]{#1$\\leftarrow$#1-1}\r\n\r\n\\newcommand{\\SymDI}[1][]{\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{IFF1$\\leftarrow$0}\r\n\t\t{1}{IFF2$\\leftarrow$0}\r\n\t\t{}{\\SymDI[0]\\\\\\SymDI[1]}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymDJNZ}[2][]{\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{B$\\leftarrow$B-1}\r\n\t\t{1}{if B$\\neq$0:~JR #2}\r\n\t\t{}{\\SymDJNZ[0]{#2}\\\\\\SymDJNZ[1]{#2}}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymEI}[1][]{\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{IFF1$\\leftarrow$1}\r\n\t\t{1}{IFF2$\\leftarrow$1}\r\n\t\t{}{\\SymEI[0]\\\\\\SymEI[1]}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymEX}[2]{#1$\\leftrightarrow$#2}\r\n\r\n\\newcommand{\\SymEXX}[1][]{\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{\\SymEX{BC}{BC'}}\r\n\t\t{1}{\\SymEX{DE}{DE'}}\r\n\t\t{2}{\\SymEX{HL}{HL'}}\r\n\t\t{}{\\SymEXX[0]\\\\\\SymEXX[1]\\\\\\SymEXX[2]}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymIN}[2]{#1$\\leftarrow$(#2)}\r\n\r\n\\newcommand{\\SymINC}[1]{#1$\\leftarrow$#1+1}\r\n\r\n\\newcommand{\\SymIND}[1][]{\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{(HL)$\\leftarrow$(BC)}\r\n\t\t{1}{HL$\\leftarrow$HL-1}\r\n\t\t{2}{B$\\leftarrow$B-1}\r\n\t\t{}{\\SymIND[0]\\\\\\SymIND[1]\\\\\\SymIND[2]}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymINDR}[1][]{\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{do IND}\r\n\t\t{1}{while B>0}\r\n\t\t{}{\\SymINDR[0]\\\\\\SymINDR[1]}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymINI}[1][]{\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{(HL)$\\leftarrow$(BC)}\r\n\t\t{1}{HL$\\leftarrow$HL+1}\r\n\t\t{2}{B$\\leftarrow$B-1}\r\n\t\t{}{\\SymINI[0]\\\\\\SymINI[1]\\\\\\SymINI[2]}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymINIR}[1][]{\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{do INI}\r\n\t\t{1}{while B>0}\r\n\t\t{}{\\SymINIR[0]\\\\\\SymINIR[1]}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymJP}[1]{PC$\\leftarrow$#1}\r\n\r\n\\newcommand{\\SymJPc}[1]{if c=true:~JP #1}\r\n\r\n\\newcommand{\\SymJPC}{PC$\\leftarrow$PC$\\wedge$\\$C000+IN(C)<<6}\r\n\r\n\\newcommand{\\SymJR}[1]{PC$\\leftarrow$PC+#1}\r\n\r\n\\newcommand{\\SymJRc}[2]{if #1=true:~JR #2}\r\n\r\n\\newcommand{\\SymLD}[2]{#1$\\leftarrow$#2}\r\n\r\n\\newcommand{\\SymLDD}[1][]{\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{(DE)$\\leftarrow$(HL)}\r\n\t\t{1}{DE$\\leftarrow$DE-1}\r\n\t\t{2}{HL$\\leftarrow$HL-1}\r\n\t\t{3}{BC$\\leftarrow$BC-1}\r\n\t\t{}{\\SymLDD[0]\\\\\\SymLDD[1]\\\\\\SymLDD[2]\\\\\\SymLDD[3]}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymLDDR}[1][]{\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{do LDD}\r\n\t\t{1}{while BC>0}\r\n\t\t{}{\\SymLDDR[0]:\\\\\\SymTab{}\\SymLDD[0]\\\\\\SymTab{}\\SymLDD[1]:\\SymSpc{}\\SymTab{}\\SymLDD[2]:\\SymSpc{}\\SymTab{}\\SymLDD[3]\\\\\\SymLDDR[1]}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymLDDRX}[1][]{\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{do LDDX}\r\n\t\t{1}{while BC>0}\r\n\t\t{}{\\SymLDDRX[0]:\\\\\\SymTab{}\\SymLDDX[0]\\\\\\SymTab{}\\SymLDDX[1]:\\SymSpc{}\\SymTab{}\\SymLDDX[2]:\\SymSpc{}\\SymTab{}\\SymLDDX[3]\\\\\\SymLDDRX[1]}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymLDDX}[1][]{\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{if (HL)$\\neq$A:~(DE)$\\leftarrow$(HL)}\r\n\t\t{1}{DE$\\leftarrow$DE+1}\r\n\t\t{2}{HL$\\leftarrow$HL-1}\r\n\t\t{3}{BC$\\leftarrow$BC-1}\r\n\t\t{}{\\SymLDDX[0]\\\\\\SymLDDX[1]\\\\\\SymLDDX[2]\\\\\\SymLDDX[3]}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymLDI}[1][]{\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{(DE)$\\leftarrow$(HL)}\r\n\t\t{1}{DE$\\leftarrow$DE+1}\r\n\t\t{2}{HL$\\leftarrow$HL+1}\r\n\t\t{3}{BC$\\leftarrow$BC-1}\r\n\t\t{}{\\SymLDI[0]\\\\\\SymLDI[1]\\\\\\SymLDI[2]\\\\\\SymLDI[3]}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymLDIR}[1][]{\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{do LDI}\r\n\t\t{1}{while BC>0}\r\n\t\t{}{\\SymLDIR[0]:\\\\\\SymTab{}\\SymLDI[0]\\\\\\SymTab{}\\SymLDI[1]:\\SymSpc{}\\SymTab{}\\SymLDI[2]:\\SymSpc{}\\SymTab{}\\SymLDI[3]\\\\\\SymLDIR[1]}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymLDIX}[1][]{\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{if (HL)$\\neq$A: (DE)$\\leftarrow$(HL)}\r\n\t\t{1}{DE$\\leftarrow$DE+1}\r\n\t\t{2}{HL$\\leftarrow$HL+1}\r\n\t\t{3}{BC$\\leftarrow$BC-1}\r\n\t\t{}{\\SymLDIX[0]\\\\\\SymLDIX[1]\\\\\\SymLDIX[2]\\\\\\SymLDIX[3]}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymLDIRX}[1][]{\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{do LDIX}\r\n\t\t{1}{while BC>0}\r\n\t\t{}{\\SymLDIRX[0]:\\\\\\SymTab{}\\SymLDIX[0]\\\\\\SymTab{}\\SymLDIX[1]:\\SymSpc{}\\SymTab{}\\SymLDIX[2]:\\SymSpc{}\\SymTab{}\\SymLDIX[3]\\\\\\SymLDIRX[1]}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymLDPIRX}[1][]{\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{do}\r\n\t\t{1}{\\SymTab{}t$\\leftarrow$(HL$\\wedge$\\$FFF8+E$\\wedge$7)}\r\n\t\t{2}{\\SymTab{}if t$\\neq$A: (DE)$\\leftarrow$t}\r\n\t\t{3}{\\SymTab{}DE$\\leftarrow$DE+1}\r\n\t\t{4}{\\SymTab{}BC$\\leftarrow$BC-1}\r\n\t\t{5}{while BC>0}\r\n\t\t{}{\\SymLDPIRX[0]\\\\\\SymLDPIRX[1]\\\\\\SymLDPIRX[2]\\\\\\SymLDPIRX[3]:\\SymSpc{}\\SymLDPIRX[4]\\\\\\SymLDPIRX[5]}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymLDWS}[1][]{\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{(DE)$\\leftarrow$(HL)}\r\n\t\t{1}{INC L}\r\n\t\t{2}{INC D}\r\n\t\t{}{\\SymLDWS[0]\\\\\\SymLDWS[1]\\\\\\SymLDWS[2]}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymMIRROR}[1]{\r\n\t\\SymDrawing{\r\n\t\t\\begin{tikzpicture}[\r\n\t\t\tframed/.style={rectangle, draw=black, inner sep=1},\r\n\t\t\tplain/.style={inner sep=0},\r\n\t\t\tarrow/.style={thin,->,-latex}]\r\n\t\t\t\t\r\n\t\t\t\\node[plain] (reg) {\\tt #1};\r\n\t\t\t\\node[framed, right=0.2em of reg] (hi) {7654};\r\n\t\t\t\\node[framed, right=0em of hi] (lo) {3210};\r\n\t\t\t\t\r\n\t\t\t\\draw[arrow] (hi.148) |- +(0.1,0.5) -| (lo.32);\r\n\t\t\t\\draw[arrow] (hi.118) |- +(0.1,0.4) -| (lo.65);\r\n\t\t\t\\draw[arrow] (hi.64) |- +(0.1,0.3) -| (lo.118);\r\n\t\t\t\\draw[arrow] (hi.34) |- +(0.1,0.2) -| (lo.148);\r\n\t\t\t\t\r\n\t\t\t\\draw[arrow] (lo.-148) |- +(-0.1,-0.2) -| (hi.-32);\r\n\t\t\t\\draw[arrow] (lo.-118) |- +(-0.1,-0.3) -| (hi.-65);\r\n\t\t\t\\draw[arrow] (lo.-34) |- +(-0.1,-0.5) -| (hi.-148);\r\n\t\t\t\\draw[arrow] (lo.-64) |- +(-0.1,-0.4) -| (hi.-118);\r\n\t\t\\end{tikzpicture}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymMUL}{DE$\\leftarrow$D$\\times$E}\r\n\r\n\\newcommand{\\SymNEG}{A$\\leftarrow$-A}\r\n\r\n\\newcommand{\\SymNEXTREG}[1]{HwNextReg[n]$\\leftarrow$#1}\r\n\r\n\\newcommand{\\SymOR}[1]{A$\\leftarrow$A$\\vee$#1}\r\n\r\n\\newcommand{\\SymOUT}[2]{(#1)$\\leftarrow$#2}\r\n\r\n\\newcommand{\\SymOUTINB}[1][]{\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{(BC)$\\leftarrow$(HL)}\r\n\t\t{1}{HL$\\leftarrow$HL+1}\r\n\t\t{}{\\SymOUTINB[0]\\\\\\SymOUTINB[1]}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymOUTD}[1][]{\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{B$\\leftarrow$B-1}\r\n\t\t{1}{(BC)$\\leftarrow$(HL)}\r\n\t\t{2}{HL$\\leftarrow$HL-1}\r\n\t\t{}{\\SymOUTD[0]\\\\\\SymOUTD[1]\\\\\\SymOUTD[2]}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymOUTI}[1][]{\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{B$\\leftarrow$B-1}\r\n\t\t{1}{(BC)$\\leftarrow$(HL)}\r\n\t\t{2}{HL$\\leftarrow$HL+1}\r\n\t\t{}{\\SymOUTI[0]\\\\\\SymOUTI[1]\\\\\\SymOUTI[2]}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymOTDR}[1][]{\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{do OUTD}\r\n\t\t{1}{while B>0}\r\n\t\t{}{\\SymOTDR[0]\\\\\\SymOTDR[1]}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymOTIR}[1][]{\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{do OUTI}\r\n\t\t{1}{while B>0}\r\n\t\t{}{\\SymOTIR[0]\\\\\\SymOTIR[1]}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymPIXELAD}[1][]{\\ignorespaces\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{HL$\\leftarrow$\\$4000}\r\n\t\t{1}{+((D$\\wedge$\\$C0)<<5)}\r\n\t\t{2}{+((D$\\wedge$\\$07)<<8)}\r\n\t\t{3}{+((D$\\wedge$\\$38)<<2)}\r\n\t\t{4}{+(E>>3)}\r\n\t\t{}{\\SymPIXELAD[0]\\SymPIXELAD[1]\\SymPIXELAD[2]\\SymPIXELAD[3]\\SymPIXELAD[4]}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymPIXELDN}[1][]{\\ignorespaces\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{if~(HL$\\wedge$\\$700)$\\neq$\\$700}\r\n\t\t{1}{\\SymTab{}HL$\\leftarrow$HL+256}\r\n\t\t{2}{else~if~(HL$\\wedge$\\$E0)$\\neq$\\$E0}\r\n\t\t{3}{\\SymTab{}HL$\\leftarrow$HL$\\wedge$\\$F8FF+\\$20}\r\n\t\t{4}{else}\r\n\t\t{5}{\\SymTab{}HL$\\leftarrow$HL$\\wedge$\\$F81F+\\$800}\r\n\t\t{}{\\SymPIXELDN[0]\\\\\\SymPIXELDN[1]\\\\\\SymPIXELDN[2]\\\\\\SymPIXELDN[3]\\\\\\SymPIXELDN[4]\\\\\\SymPIXELDN[5]}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymPOP}[2][]{\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{#2\\High$\\leftarrow$(SP+1)}\r\n\t\t{1}{#2\\Low$\\leftarrow$(SP)}\r\n\t\t{2}{SP$\\leftarrow$SP+2}\r\n\t\t{10}{#2$\\leftarrow$(SP+1)}\r\n\t\t{11}{#2$\\leftarrow$(SP)}\r\n\t\t{12}{SP$\\leftarrow$SP+2}\r\n\t\t{}{\\SymPOP[0]{#2}\\\\\\SymPOP[1]{#2}\\\\\\SymPOP[2]{#2}}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymPUSHnn}[3][]{\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{(SP-2)$\\leftarrow$#3}\r\n\t\t{1}{(SP-1)$\\leftarrow$#2}\r\n\t\t{2}{SP$\\leftarrow$SP-2}\r\n\t\t{}{\\SymPUSHnn[0]{#2}{#3}\\\\\\SymPUSHnn[1]{#2}{#3}\\\\\\SymPUSHnn[2]{#2}{#3}}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymPUSH}[2][]{\r\n\t\\SymPUSHnn[#1]{#2\\High}{#2\\Low}\r\n}\r\n\r\n\\newcommand{\\SymRES}[1]{$\\mathtt{#1_b}\\leftarrow$0}\r\n\r\n\\newcommand{\\SymRET}[1][]{\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{PC\\Low$\\leftarrow$(SP)}\r\n\t\t{1}{PC\\High$\\leftarrow$(SP+1)}\r\n\t\t{2}{SP$\\leftarrow$SP+2}\r\n\t\t{}{\\SymRET[0]\\\\\\SymRET[1]\\\\\\SymRET[2]}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymRETc}[1]{\r\n\tif #1=true:~RET\r\n}\r\n\r\n\\newcommand{\\SymRETI}[1][]{\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{PC\\Low$\\leftarrow$(SP)}\r\n\t\t{1}{PC\\High$\\leftarrow$(SP+1)}\r\n\t\t{2}{SP$\\leftarrow$SP+2}\r\n\t\t{}{\\SymRETI[0]\\\\\\SymRETI[1]\\\\\\SymRETI[2]}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymRETN}[1][]{\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{PC\\Low$\\leftarrow$(SP)}\r\n\t\t{1}{PC\\High$\\leftarrow$(SP+1)}\r\n\t\t{2}{SP$\\leftarrow$SP+2}\r\n\t\t{3}{IFF1$\\leftarrow$IFF2}\r\n\t\t{}{\\SymRETN[0]\\\\\\SymRETN[1]\\\\\\SymRETN[2]\\\\\\SymRETN[3]}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymRL}[2][]{\r\n\t\\SymDrawing{\r\n\t\t\\begin{tikzpicture}[\r\n\t\t\tframed/.style={ rectangle, draw=black, inner sep=1 },\r\n\t\t\tarrow/.style={thin,->,-latex}]\r\n\r\n\t\t\t\\node[framed] (cf) {\\tt CF};\r\n\t\t\t\\node[framed] (bits) at([xshift=3em]cf) {7$\\leftarrow$0};\r\n\t\t\t\\IfEqCase{#1} {\r\n\t\t\t\t{0}{}\r\n\t\t\t\t{}{\\node(reg) at([yshift=-1em]bits) {\\tt #2};}\r\n\t\t\t}\r\n\r\n\t\t\t\\draw[arrow] (bits) -- (cf);\r\n\t\t\t\\draw[arrow] (cf.west) |- +(-0.12,0) |- +(1.67,0.25) |- (bits.east);\r\n\t\t\\end{tikzpicture}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymRLC}[2][]{\r\n\t\\SymDrawing{\r\n\t\t\\begin{tikzpicture}[\r\n\t\t\tframed/.style={rectangle, draw=black, inner sep=1},\r\n\t\t\tarrow/.style={thin,->,-latex}]\r\n\t\t\t\t\r\n\t\t\t\\node[framed] (cf) {\\tt CF};\r\n\t\t\t\\node[framed, right=1.1em of cf] (bits) {7$\\leftarrow$0};\r\n\t\t\t\\IfEqCase{#1} {\r\n\t\t\t\t{0}{}\r\n\t\t\t\t{}{\\node[below=-1pt of bits](reg) {\\tt #2};}\r\n\t\t\t}\r\n\t\t\t\t\r\n\t\t\t\\draw[arrow] (bits) -- (cf);\r\n\t\t\t\\draw[arrow] (bits.west) |- +(-0.1,0) |- +(0.9,0.25) |- (bits.east);\r\n\t\t\\end{tikzpicture}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymRLCu}[3][]{\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{#2$\\leftarrow$(#3+d)}\r\n\t\t{1}{RLC #2}\r\n\t\t{2}{(#3+d)$\\leftarrow$#2}\r\n\t\t{}{\\SymRLCu[0]{#2}{#3}\\\\\\SymRLCu[1]{#2}{#3}\\\\\\SymRLCu[2]{#2}{#3}}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymRLD}{\r\n\t\\SymDrawing{\r\n\t\t\\begin{tikzpicture}[\r\n\t\t\tframed/.style={rectangle, draw=black, inner sep=1, outer sep=0},\r\n\t\t\tplain/.style={inner sep=0},\r\n\t\t\tarrow/.style={thin,->,-latex}]\r\n\t\t\t\r\n\t\t\t\\node[plain] (a) {\\tt A};\r\n\t\t\t\r\n\t\t\t\\node[framed, right=0.5ex of a] (bitsAhi) {7-4};\r\n\t\t\t\\node[framed, right=0ex of bitsAhi] (bitsAlo) {3-0};\r\n\r\n\t\t\t\\node[framed, right=1ex of bitsAlo] (bitsHLhi) {7-4};\r\n\t\t\t\\node[framed, right=0ex of bitsHLhi] (bitsHLlo) {3-0};\r\n \t\t\t\r\n\t\t\t\\node[plain, right=0.5ex of bitsHLlo] (hl) {\\tt (HL)};\r\n\t\t\t\r\n\t\t\t\\draw[arrow] (bitsHLlo.south) |- +(-0.2,-0.2) -| (bitsHLhi.310);\r\n\t\t\t\\draw[arrow] (bitsHLhi.240) |- +(-0.2,-0.2) -| (bitsAlo.south);\r\n\t\t\t\\draw[arrow] (bitsAlo.north) |- +(0.2,0.2) -| (bitsHLlo.north);\r\n\t\t\\end{tikzpicture}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymRR}[2][]{\r\n\t\\SymDrawing{\r\n\t\t\\begin{tikzpicture}[\r\n\t\t\tframed/.style={ rectangle, draw=black, inner sep=1 },\r\n\t\t\tarrow/.style={thin,->,-latex}]\r\n\r\n\t\t\t\\node[framed] (bits) {7$\\rightarrow$0};\r\n\t\t\t\\node[framed, right=1em of bits] (cf) {\\tt CF};\r\n\t\t\t\\IfEqCase{#1} {\r\n\t\t\t\t{0}{}\r\n\t\t\t\t{}{\\node[below=-1pt of bits](reg) {\\tt #2};}\r\n\t\t\t}\r\n\r\n\t\t\t\\draw[arrow] (bits) -- (cf);\r\n\t\t\t\\draw[arrow] (cf.east) |- +(0.12,0) |- +(-1.6,0.25) |- (bits.west);\r\n\t\t\\end{tikzpicture}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymRRC}[2][]{\r\n\t\\SymDrawing{\r\n\t\t\\begin{tikzpicture}[\r\n\t\t\tframed/.style={rectangle, draw=black, inner sep=1},\r\n\t\t\tarrow/.style={thin,->,-latex}]\r\n\t\t\t\r\n\t\t\t\\node[framed] (bits) {7$\\rightarrow$0};\r\n\t\t\t\\node[framed, right=1.1em of bits] (cf) {\\tt CF};\r\n\t\t\t\\IfEqCase{#1} {\r\n\t\t\t\t{0}{}\r\n\t\t\t\t{}{\\node[below=-1pt of bits](reg) {\\tt #2};}\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t\\draw[arrow] (bits) -- (cf);\r\n\t\t\t\\draw[arrow] (bits.east) |- +(0.1,0) |- +(-0.9,0.25) |- (bits.west);\r\n\t\t\\end{tikzpicture}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymRRD}{\r\n\t\\SymDrawing{\r\n\t\t\\begin{tikzpicture}[\r\n\t\t\tframed/.style={rectangle, draw=black, inner sep=1, outer sep=0},\r\n\t\t\tplain/.style={inner sep=0},\r\n\t\t\tarrow/.style={thin,->,-latex}]\r\n\t\t\t\r\n\t\t\t\\node[plain] (a) {\\tt A};\r\n\t\t\t\r\n\t\t\t\\node[framed, right=0.5ex of a] (bitsAhi) {7-4};\r\n\t\t\t\\node[framed, right=0ex of bitsAhi] (bitsAlo) {3-0};\r\n\r\n\t\t\t\\node[framed, right=1ex of bitsAlo] (bitsHLhi) {7-4};\r\n\t\t\t\\node[framed, right=0ex of bitsHLhi] (bitsHLlo) {3-0};\r\n \t\t\t\r\n\t\t\t\\node[plain, right=0.5ex of bitsHLlo] (hl) {\\tt (HL)};\r\n\t\t\t\r\n\t\t\t\\draw[arrow] (bitsHLlo.south) |- +(-0.2,-0.2) -| (bitsAlo.south);\r\n\t\t\t\\draw[arrow] (bitsAlo.north) |- +(0.2,0.2) -| (bitsHLhi.120);\r\n\t\t\t\\draw[arrow] (bitsHLhi.60) |- +(0.2,0.2) -| (bitsHLlo.north);\r\n\t\t\\end{tikzpicture}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymRST}[2][]{\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{(SP-1)$\\leftarrow$PC\\High}\r\n\t\t{1}{(SP-2)$\\leftarrow$PC\\Low}\r\n\t\t{2}{SP$\\leftarrow$SP-2}\r\n\t\t{3}{PC$\\leftarrow$#2}\r\n\t\t{}{\\SymRST[0]{#2}\\\\\\SymRST[1]{#2}\\\\\\SymRST[2]{#2}\\\\\\SymRST[3]{#2}}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymSET}[1]{$\\mathtt{#1_b}\\leftarrow$1}\r\n\r\n\\newcommand{\\SymSETu}[3][]{\r\n\t\\IfEqCase{#1}{\r\n\t\t{0}{#2$\\leftarrow$(#3+d)}\r\n\t\t{1}{$\\mathtt{#2_b}\\leftarrow$1}\r\n\t\t{2}{(#3+d)$\\leftarrow$#2}\r\n\t\t{}{\\SymSETu[0]{#2}{#3}\\\\\\SymSETu[1]{#2}{#3}\\\\\\SymSETu[2]{#2}{#3}}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymSBC}[2]{#1$\\leftarrow$#1-#2-CF}\r\n\r\n\\newcommand{\\SymSCF}{CF$\\leftarrow$1}\r\n\r\n\\newcommand{\\SymSETAE}{A$\\leftarrow$unsigned(\\$80)>>(E$\\wedge$7)}\r\n\r\n\\newcommand{\\SymSLA}[2][]{\r\n\t\\SymDrawing{\r\n\t\t\\begin{tikzpicture}[\r\n\t\t\tframed/.style={rectangle, draw=black, inner sep=1},\r\n\t\t\tplain/.style={inner sep=0},\r\n\t\t\tarrow/.style={thin,->,-latex}]\r\n\r\n\t\t\t\\node[framed] (cf) {\\tt CF};\r\n\t\t\t\\node[framed, right=1em of cf] (bits) {7$\\leftarrow$0};\r\n\t\t\t\\node[plain, right=1em of bits] (zero) {\\tt 0};\r\n\t\t\t\\IfEqCase{#1} {\r\n\t\t\t\t{0}{}\r\n\t\t\t\t{}{\\node[below=-1pt of bits](reg) {\\tt #2};}\r\n\t\t\t}\r\n\r\n\t\t\t\\draw[arrow] (zero) -- (bits);\r\n\t\t\t\\draw[arrow] (bits) -- (cf);\r\n\t\t\\end{tikzpicture}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymSLI}[2][]{\r\n\t\\SymDrawing{\r\n\t\t\\begin{tikzpicture}[\r\n\t\t\tframed/.style={rectangle, draw=black, inner sep=1},\r\n\t\t\tplain/.style={inner sep=0},\r\n\t\t\tarrow/.style={thin,->,-latex}]\r\n\r\n\t\t\t\\node[framed] (cf) {\\tt CF};\r\n\t\t\t\\node[framed, right=1em of cf] (bits) {7$\\leftarrow$0};\r\n\t\t\t\\node[plain, right=1em of bits] (one) {\\tt 1};\r\n\t\t\t\\IfEqCase{#1} {\r\n\t\t\t\t{0}{}\r\n\t\t\t\t{}{\\node[below=-1pt of bits](reg) {\\tt #2};}\r\n\t\t\t}\r\n\r\n\t\t\t\\draw[arrow] (one) -- (bits);\r\n\t\t\t\\draw[arrow] (bits) -- (cf);\r\n\t\t\\end{tikzpicture}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymSRA}[2][]{\r\n\t\\SymDrawing{\r\n\t\t\\begin{tikzpicture}[\r\n\t\t\tframed/.style={rectangle, draw=black, inner sep=1},\r\n\t\t\tarrow/.style={thin,->,-latex}]\r\n\t\t\t\t\r\n\t\t\t\\node[framed] (bits) {7$\\rightarrow$0};\r\n\t\t\t\\node[framed, right=1em of bits] (cf) {\\tt CF};\r\n\t\t\t\\IfEqCase{#1} {\r\n\t\t\t\t{0}{}\r\n\t\t\t\t{}{\\node[below=-1pt of bits](reg) {\\tt #2};}\r\n\t\t\t}\r\n\t\t\t\t\r\n\t\t\t\\draw[arrow] (bits) -- (cf);\r\n\t\t\t\\draw[arrow] (bits.211) |- +(-0.35,-0.1) |- (bits.west);\r\n\t\t\\end{tikzpicture}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymSRL}[2][]{\r\n\t\\SymDrawing{\r\n\t\t\\begin{tikzpicture}[\r\n\t\t\tframed/.style={rectangle, draw=black, inner sep=1},\r\n\t\t\tplain/.style={inner sep=0},\r\n\t\t\tarrow/.style={thin,->,-latex}]\r\n\t\t\t\r\n\t\t\t\\node[plain] (zero) {\\tt 0};\r\n\t\t\t\\node[framed, right=1em of zero] (bits) {7$\\rightarrow$0};\r\n\t\t\t\\node[framed, right=1em of bits] (cf) {\\tt CF};\r\n\t\t\t\\IfEqCase{#1} {\r\n\t\t\t\t{0}{}\r\n\t\t\t\t{}{\\node[below=-1pt of bits](reg) {\\tt #2};}\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t\\draw[arrow] (zero) -- (bits);\r\n\t\t\t\\draw[arrow] (bits) -- (cf);\r\n\t\t\\end{tikzpicture}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymSUB}[1]{A$\\leftarrow$A-#1}\r\n\r\n\\newcommand{\\SymSWAPNIB}[1][]{\r\n\t\\IfEq{#1}{}{}{\\hspace*{-1.6em}}\r\n\t\\SymDrawing{\r\n\t\t\\begin{tikzpicture}[\r\n\t\t\tframed/.style={rectangle, draw=black, inner sep=1},\r\n\t\t\tplain/.style={inner sep=0},\r\n\t\t\tarrow/.style={thin,->,-latex}]\r\n\t\t\t\r\n\t\t\t\\node[plain] (a) {\\tt A};\r\n\t\t\t\\node[framed, right=0.2em of a] (hi) {7654};\r\n\t\t\t\\node[framed, right=0em of hi] (lo) {3210};\r\n\t\t\t\r\n\t\t\t\\draw[arrow] (hi.north) |- +(0.1,0.2) -| (lo.north);\r\n\t\t\t\\draw[arrow] (lo.south) |- +(-0.1,-0.2) -| (hi.south);\r\n\t\t\\end{tikzpicture}\r\n\t}\r\n}\r\n\r\n\\newcommand{\\SymTEST}{A$\\wedge$n}\r\n\r\n\\newcommand{\\SymXOR}[1]{A$\\leftarrow$A$\\veebar$#1}\r\n\r\n% ────────────────────────────────────────────────────────────────────────────\r\n% ─██████████████─██████─────────██████████████─██████████████─██████████████─\r\n% ─██░░░░░░░░░░██─██░░██─────────██░░░░░░░░░░██─██░░░░░░░░░░██─██░░░░░░░░░░██─\r\n% ─██░░██████████─██░░██─────────██░░██████░░██─██░░██████████─██░░██████████─\r\n% ─██░░██─────────██░░██─────────██░░██──██░░██─██░░██─────────██░░██─────────\r\n% ─██░░██████████─██░░██─────────██░░██████░░██─██░░██─────────██░░██████████─\r\n% ─██░░░░░░░░░░██─██░░██─────────██░░░░░░░░░░██─██░░██──██████─██░░░░░░░░░░██─\r\n% ─██░░██████████─██░░██─────────██░░██████░░██─██░░██──██░░██─██████████░░██─\r\n% ─██░░██─────────██░░██─────────██░░██──██░░██─██░░██──██░░██─────────██░░██─\r\n% ─██░░██─────────██░░██████████─██░░██──██░░██─██░░██████░░██─██████████░░██─\r\n% ─██░░██─────────██░░░░░░░░░░██─██░░██──██░░██─██░░░░░░░░░░██─██░░░░░░░░░░██─\r\n% ─██████─────────██████████████─██████──██████─██████████████─██████████████─\r\n% ────────────────────────────────────────────────────────────────────────────\r\n\r\n% some common declarations to unify formatting of individual parts; we can then later redefine these macros to change appearance without having to tweak main macros\r\n\\newcommand{\\FlagsSee}[1]{\\See{#1}}\t\t% footnote declarations\r\n\\newcommand{\\FlagsFPP}{\\FPP}\t\t\t% PF=parity indicator\r\n\\newcommand{\\FlagsFPV}{\\FPV}\t\t\t% PF=overflow indicator\r\n\\newcommand{\\FlagsSmall}[1]{\\tiny #1}\t% small font size\r\n\\newcommand{\\FlagsNoEffect}{}\t\t\t% text for \"no effect\"; we don't display anything in tables, but may redeclare to display something in details section\r\n\r\n% note: because LaTeX doesn't allow numbers in commands, we use the following notation:\r\n% r = 8 bit register or number\r\n% n = 8 bit number (only if we already use r)\r\n% rr = 16 bit register pair or number\r\n% nn = 16 bit number (only if we already use rr)\r\n% note: we need to pass 1 optional parameter to Flags; we need it in details section\r\n\r\n% order of the parameters: SF, ZF, HF, PV, NF, CF\r\n\\newcommand{\\FlagsADDr}[1][]{\\Flags[#1]{\\FS}{\\FS}{\\FS}{\\FlagsFPV}{0}{\\FS}}\r\n\\newcommand{\\FlagsADDrr}[1][]{\\Flags[#1]{\\FN}{\\FN}{\\FS\\FlagsSee{2}}{\\FN}{0}{\\FS\\FlagsSee{1}}}\r\n\\newcommand{\\FlagsADDrra}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FU\\FlagsSee{1}}}\r\n\\newcommand{\\FlagsADDrrnn}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsADCr}[1][]{\\Flags[#1]{\\FS}{\\FS}{\\FS}{\\FlagsFPV}{0}{\\FS}}\r\n\\newcommand{\\FlagsADCrr}[1][]{\\Flags[#1]{\\FS\\FlagsSee{1}}{\\FS\\FlagsSee{1}}{\\FS\\FlagsSee{2}}{\\FlagsFPV\\FlagsSee{1}}{0}{\\FS\\FlagsSee{1}}}\r\n\\newcommand{\\FlagsANDr}[1][]{\\Flags[#1]{\\FS}{\\FS}{1}{\\FlagsFPP}{0}{0}}\r\n\\newcommand{\\FlagsBITr}[1][]{\\Flags[#1]{\\FU\\FlagsSee{1}}{\\FS}{1}{\\FU\\FlagsSee{1}}{0}{\\FN}}\r\n\\newcommand{\\FlagsBSLA}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsBSRA}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsBSRL}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsBSRF}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsBRLC}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsCALLnn}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsCALLccnn}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsCCF}[1][]{\\Flags[#1]{\\FN}{\\FN}{\\FX\\FlagsSee{2}}{\\FN}{0}{\\FS}}\r\n\\newcommand{\\FlagsCPr}[1][]{\\Flags[#1]{\\FS}{\\FS}{\\FS}{\\FlagsFPV}{1}{\\FS}}\r\n\\newcommand{\\FlagsCPI}[1][]{\\Flags[#1]{\\FS\\FlagsSee{1}}{\\FS\\FlagsSee{2}}{\\FS\\FlagsSee{1}}{\\FX\\FlagsSee{3}}{1}{\\FN}}\r\n\\newcommand{\\FlagsCPIR}[1][]{\\Flags[#1]{\\FS\\FlagsSee{1}}{\\FS\\FlagsSee{2}}{\\FS\\FlagsSee{1}}{\\FX\\FlagsSee{3}}{1}{\\FN}}\r\n\\newcommand{\\FlagsCPD}[1][]{\\Flags[#1]{\\FS\\FlagsSee{1}}{\\FS\\FlagsSee{2}}{\\FS\\FlagsSee{1}}{\\FX\\FlagsSee{3}}{1}{\\FN}}\r\n\\newcommand{\\FlagsCPDR}[1][]{\\Flags[#1]{\\FS\\FlagsSee{1}}{\\FS\\FlagsSee{2}}{\\FS\\FlagsSee{1}}{\\FX\\FlagsSee{3}}{1}{\\FN}}\r\n\\newcommand{\\FlagsCPL}[1][]{\\Flags[#1]{\\FN}{\\FN}{1}{\\FN}{1}{\\FN}}\r\n\\newcommand{\\FlagsDAA}[1][]{\\Flags[#1]{\\FS}{\\FS}{\\FS}{\\FlagsFPP}{\\FN}{\\FS}}\r\n\\newcommand{\\FlagsDECr}[1][]{\\Flags[#1]{\\FS}{\\FS}{\\FS}{\\FlagsFPV\\FlagsSee{5}}{1}{\\FN}}\r\n\\newcommand{\\FlagsDECrr}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsDI}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsDJNZ}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsEI}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsEXrr}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsEXaf}[1][]{\\Flags[#1]{\\FX\\FlagsSee{1}}{\\FX\\FlagsSee{1}}{\\FX\\FlagsSee{1}}{\\FX\\FlagsSee{1}}{\\FX\\FlagsSee{1}}{\\FX\\FlagsSee{1}}}\r\n\\newcommand{\\FlagsEXX}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsHALT}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsIM}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsINan}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsINrc}[1][]{\\Flags[#1]{\\FS}{\\FS}{0}{\\FlagsFPP}{0}{\\FN}}\r\n\\newcommand{\\FlagsINc}[1][]{\\Flags[#1]{\\FS}{\\FS}{0}{\\FlagsFPP}{0}{\\FN}}\r\n\\newcommand{\\FlagsINCr}[1][]{\\Flags[#1]{\\FS}{\\FS}{\\FS}{\\FlagsFPV\\FlagsSee{4}}{0}{\\FN}}\r\n\\newcommand{\\FlagsINCrr}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsINI}[1][]{\\Flags[#1]{\\FX\\FlagsSee{5}}{\\FX\\FlagsSee{4}}{\\FX\\FlagsSee{5}}{\\FX\\FlagsSee{5}}{1}{\\FN}}\r\n\\newcommand{\\FlagsINIR}[1][]{\\Flags[#1]{\\FX\\FlagsSee{5}}{1}{\\FX\\FlagsSee{5}}{\\FX\\FlagsSee{5}}{1}{\\FN}}\r\n\\newcommand{\\FlagsIND}[1][]{\\Flags[#1]{\\FX\\FlagsSee{5}}{\\FX\\FlagsSee{4}}{\\FX\\FlagsSee{5}}{\\FX\\FlagsSee{5}}{1}{\\FN}}\r\n\\newcommand{\\FlagsINDR}[1][]{\\Flags[#1]{\\FX\\FlagsSee{5}}{1}{\\FX\\FlagsSee{5}}{\\FX\\FlagsSee{5}}{1}{\\FN}}\r\n\\newcommand{\\FlagsJPc}[1][]{\\Flags[#1]{\\FU}{\\FU}{\\FU}{\\FU}{\\FU}{\\FU}}\r\n\\newcommand{\\FlagsJPnn}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsJPccnn}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsJPrr}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsJRn}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsJRccn}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsLDr}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsLDrr}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsLDair}[1][]{\\Flags[#1]{\\FS}{\\FS}{0}{{\\FlagsSmall IFF2}}{0}{\\FN}}\r\n\\newcommand{\\FlagsLDI}[1][]{\\Flags[#1]{\\FN}{\\FN}{0}{\\FX\\FlagsSee{3}}{0}{\\FN}}\r\n\\newcommand{\\FlagsLDIR}[1][]{\\Flags[#1]{\\FN}{\\FN}{0}{0\\FlagsSee{4}}{0}{\\FN}}\r\n\\newcommand{\\FlagsLDD}[1][]{\\Flags[#1]{\\FN}{\\FN}{0}{\\FX\\FlagsSee{3}}{0}{\\FN}}\r\n\\newcommand{\\FlagsLDDR}[1][]{\\Flags[#1]{\\FN}{\\FN}{0}{0\\FlagsSee{4}}{0}{\\FN}}\r\n\\newcommand{\\FlagsLDDX}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsLDDRX}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsLDIX}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsLDIRX}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsLDPIRX}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsLDWS}[1][]{\\Flags[#1]{\\FS}{\\FS}{\\FS}{\\FlagsFPV\\FlagsSee{3}}{0}{\\FN}}\r\n\\newcommand{\\FlagsMIRRORa}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsMULde}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsNEG}[1][]{\\Flags[#1]{\\FS}{\\FS}{\\FS}{\\FlagsFPP}{1}{\\FS}}\r\n\\newcommand{\\FlagsNEXTREGna}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsNEXTREGnn}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsNOP}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsORr}[1][]{\\Flags[#1]{\\FS}{\\FS}{0}{\\FlagsFPP}{0}{0}}\r\n\\newcommand{\\FlagsOUTna}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsOUTcr}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsOUTc}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsOUTI}[1][]{\\Flags[#1]{\\FX\\FlagsSee{2}}{\\FX\\FlagsSee{1}}{\\FX\\FlagsSee{2}}{\\FX\\FlagsSee{2}}{1}{\\FN}}\r\n\\newcommand{\\FlagsOTIR}[1][]{\\Flags[#1]{\\FX\\FlagsSee{2}}{1}{\\FX\\FlagsSee{2}}{\\FX\\FlagsSee{2}}{1}{\\FN}}\r\n\\newcommand{\\FlagsOUTD}[1][]{\\Flags[#1]{\\FX\\FlagsSee{2}}{\\FX\\FlagsSee{1}}{\\FX\\FlagsSee{2}}{\\FX\\FlagsSee{2}}{1}{\\FN}}\r\n\\newcommand{\\FlagsOTDR}[1][]{\\Flags[#1]{\\FX\\FlagsSee{2}}{1}{\\FX\\FlagsSee{2}}{\\FX\\FlagsSee{2}}{1}{\\FN}}\r\n\\newcommand{\\FlagsOUTINB}[1][]{\\Flags[#1]{\\FU}{\\FU}{\\FU}{\\FU}{\\FU}{\\FU}}\r\n\\newcommand{\\FlagsPIXELAD}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsPIXELDN}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsPOPrr}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsPOPaf}[1][]{\\Flags[#1]{\\FS\\FlagsSee{1}}{\\FS\\FlagsSee{1}}{\\FS\\FlagsSee{1}}{\\FS\\FlagsSee{1}}{\\FS\\FlagsSee{1}}{\\FS\\FlagsSee{1}}}\r\n\\newcommand{\\FlagsPUSHrr}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsPUSHnn}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsRESr}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsRET}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsRETcc}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsRETI}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsRETN}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsRLr}[1][]{\\Flags[#1]{\\FS}{\\FS}{0}{\\FlagsFPP}{0}{\\FS}}\r\n\\newcommand{\\FlagsRLA}[1][]{\\Flags[#1]{\\FN}{\\FN}{0}{\\FN}{0}{\\FS}}\r\n\\newcommand{\\FlagsRLCr}[1][]{\\Flags[#1]{\\FS}{\\FS}{0}{\\FlagsFPP}{0}{\\FS}}\r\n\\newcommand{\\FlagsRLCA}[1][]{\\Flags[#1]{\\FN}{\\FN}{0}{\\FN}{0}{\\FS}}\r\n\\newcommand{\\FlagsRLD}[1][]{\\Flags[#1]{\\FS}{\\FS}{0}{\\FlagsFPP}{0}{\\FN}}\r\n\\newcommand{\\FlagsRRr}[1][]{\\Flags[#1]{\\FS}{\\FS}{0}{\\FlagsFPP}{0}{\\FS}}\r\n\\newcommand{\\FlagsRRA}[1][]{\\Flags[#1]{\\FN}{\\FN}{0}{\\FN}{0}{\\FS}}\r\n\\newcommand{\\FlagsRRCr}[1][]{\\Flags[#1]{\\FS}{\\FS}{0}{\\FlagsFPP}{0}{\\FS}}\r\n\\newcommand{\\FlagsRRCA}[1][]{\\Flags[#1]{\\FN}{\\FN}{0}{\\FN}{0}{\\FS}}\r\n\\newcommand{\\FlagsRRD}[1][]{\\Flags[#1]{\\FS}{\\FS}{0}{\\FlagsFPP}{0}{\\FN}}\r\n\\newcommand{\\FlagsRSTn}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsSBCr}[1][]{\\Flags[#1]{\\FS}{\\FS}{\\FS}{\\FlagsFPV}{1}{\\FS}}\r\n\\newcommand{\\FlagsSBCrr}[1][]{\\Flags[#1]{\\FS\\FlagsSee{1}}{\\FS\\FlagsSee{1}}{\\FS\\FlagsSee{2}}{\\FlagsFPV\\FlagsSee{1}}{1}{\\FS\\FlagsSee{1}}}\r\n\\newcommand{\\FlagsSCF}[1][]{\\Flags[#1]{\\FN}{\\FN}{0}{\\FN}{0}{1}}\r\n\\newcommand{\\FlagsSETr}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsSETAE}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsSLAr}[1][]{\\Flags[#1]{\\FS}{\\FS}{0}{\\FlagsFPP}{0}{\\FS}}\r\n\\newcommand{\\FlagsSLIr}[1][]{\\Flags[#1]{\\FS}{\\FS}{0}{\\FlagsFPP}{0}{\\FS}}\r\n\\newcommand{\\FlagsSRAr}[1][]{\\Flags[#1]{\\FS}{\\FS}{0}{\\FlagsFPP}{0}{\\FS}}\r\n\\newcommand{\\FlagsSRLr}[1][]{\\Flags[#1]{\\FS}{\\FS}{0}{\\FlagsFPP}{0}{\\FS}}\r\n\\newcommand{\\FlagsSUBr}[1][]{\\Flags[#1]{\\FS}{\\FS}{\\FS}{\\FlagsFPV}{1}{\\FS}}\r\n\\newcommand{\\FlagsSWAPNIB}[1][\\FlagsNoEffect]{\\Flags[#1]{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}{\\FN}}\r\n\\newcommand{\\FlagsTESTn}[1][]{\\Flags[#1]{\\FS}{\\FS}{1}{\\FlagsFPP}{\\FU}{0}}\r\n\\newcommand{\\FlagsXORr}[1][]{\\Flags[#1]{\\FS}{\\FS}{0}{\\FlagsFPP}{0}{0}}\r\n"
  },
  {
    "path": "ports.tex",
    "content": "% ────────────────────────────────────────────────────────────────────────────────\n% ─██████████████─██████████████─████████████████───██████████████─██████████████─\n% ─██░░░░░░░░░░██─██░░░░░░░░░░██─██░░░░░░░░░░░░██───██░░░░░░░░░░██─██░░░░░░░░░░██─\n% ─██░░██████░░██─██░░██████░░██─██░░████████░░██───██████░░██████─██░░██████████─\n% ─██░░██──██░░██─██░░██──██░░██─██░░██────██░░██───────██░░██─────██░░██─────────\n% ─██░░██████░░██─██░░██──██░░██─██░░████████░░██───────██░░██─────██░░██████████─\n% ─██░░░░░░░░░░██─██░░██──██░░██─██░░░░░░░░░░░░██───────██░░██─────██░░░░░░░░░░██─\n% ─██░░██████████─██░░██──██░░██─██░░██████░░████───────██░░██─────██████████░░██─\n% ─██░░██─────────██░░██──██░░██─██░░██──██░░██─────────██░░██─────────────██░░██─\n% ─██░░██─────────██░░██████░░██─██░░██──██░░██████─────██░░██─────██████████░░██─\n% ─██░░██─────────██░░░░░░░░░░██─██░░██──██░░░░░░██─────██░░██─────██░░░░░░░░░░██─\n% ─██████─────────██████████████─██████──██████████─────██████─────██████████████─\n% ────────────────────────────────────────────────────────────────────────────────\n\n% declares the data for specific port; used internally to simplify and unify port declaration. Parameters\n% #1 0 to return port address, 1 for name\n% #2 port address\n% #3 port name\n\\newcommand{\\PortRegisterInfo}[3]{\\ignorespaces\\IfEqCase{#1}{\n\t{0}{\\MemAddr{#2}}\n\t{1}{#3}}}\n\n% returns the data of specific port or register. Parameters:\n% #1 (optional) type of data to return, 0 = address, 1 = name\n% #2 port address\n%\n% IMPORTANT: every port/register used through commands below MUST be represented here, failure to do so, will result in compilaton errors\n\\newcommand{\\PortRegister}[2][]{\\ignorespaces\\IfEqCase{#2}{\n\t{123B}{\\PortRegisterInfo{#1}{#2}{Layer 2 Access Port}}\n\t{133B}{\\PortRegisterInfo{#1}{#2}{UART TX}}\n\t{1FFD}{\\PortRegisterInfo{#1}{#2}{+3 Memory Paging Control}}\n\t{243B}{\\PortRegisterInfo{#1}{#2}{TBBlue Register Select}}\n\t{253B}{\\PortRegisterInfo{#1}{#2}{TBBlue Register Access}}\n\t{303B}{\\PortRegisterInfo{#1}{#2}{Sprite Status/Slot Select}}\n\t{7FFD}{\\PortRegisterInfo{#1}{#2}{Memory Paging Control}}\n\t{BFFD}{\\PortRegisterInfo{#1}{#2}{Sound Chip Register Write}}\n\t{DFFD}{\\PortRegisterInfo{#1}{#2}{Next Memory Bank Select}}\n\t{FFFD}{\\PortRegisterInfo{#1}{#2}{Turbo Sound Next Control}}\n\t{xx0B}{\\PortRegisterInfo{#1}{#2}{MB02 DMA Port}}\n\t{xx57}{\\PortRegisterInfo{#1}{#2}{Sprite Attribute Upload}}\n\t{xx5B}{\\PortRegisterInfo{#1}{#2}{Sprite Pattern Upload}}\n\t{xx6B}{\\PortRegisterInfo{#1}{#2}{zxnDMA Port}}\n\t{xxFE}{\\PortRegisterInfo{#1}{#2}{ULA Control Port Read}}\n\t{xxFEWrite}{\\PortRegisterInfo{#1}{xxFE}{ULA Control Port Write}}\n\t{06}{\\PortRegisterInfo{#1}{#2}{Peripheral 2}}\n\t{08}{\\PortRegisterInfo{#1}{#2}{Peripheral 3}}\n\t{09}{\\PortRegisterInfo{#1}{#2}{Peripheral 4}}\n\t{11}{\\PortRegisterInfo{#1}{#2}{Video Timing}}\n\t{12}{\\PortRegisterInfo{#1}{#2}{Layer 2 RAM Page}}\n\t{13}{\\PortRegisterInfo{#1}{#2}{Layer 2 RAM Shadow Page}}\n\t{14}{\\PortRegisterInfo{#1}{#2}{Global Transparency}}\n\t{15}{\\PortRegisterInfo{#1}{#2}{Sprite and Layers System}}\n\t{16}{\\PortRegisterInfo{#1}{#2}{Layer 2 X Offset}}\n\t{17}{\\PortRegisterInfo{#1}{#2}{Layer 2 Y Offset}}\n\t{18}{\\PortRegisterInfo{#1}{#2}{Clip Window Layer 2}}\n\t{19}{\\PortRegisterInfo{#1}{#2}{Clip Window Sprites}}\n\t{1B}{\\PortRegisterInfo{#1}{#2}{Clip Window Tilemap}}\n\t{1C}{\\PortRegisterInfo{#1}{#2}{Clip Window Control}}\n\t{22}{\\PortRegisterInfo{#1}{#2}{Video Line Interrupt Control}}\n\t{23}{\\PortRegisterInfo{#1}{#2}{Video Line Interrupt Value}}\n\t{2F}{\\PortRegisterInfo{#1}{#2}{Tilemap Offset X MSB}}\n\t{30}{\\PortRegisterInfo{#1}{#2}{Tilemap Offset X LSB}}\n\t{31}{\\PortRegisterInfo{#1}{#2}{Tilemap Offset Y}}\n\t{34}{\\PortRegisterInfo{#1}{#2}{Sprite Port-Mirror Index}}\n\t{35}{\\PortRegisterInfo{#1}{#2}{Sprite Port-Mirror Attribute 0}}\n\t{36}{\\PortRegisterInfo{#1}{#2}{Sprite Port-Mirror Attribute 1}}\n\t{37}{\\PortRegisterInfo{#1}{#2}{Sprite Port-Mirror Attribute 2}}\n\t{38}{\\PortRegisterInfo{#1}{#2}{Sprite Port-Mirror Attribute 3}}\n\t{39}{\\PortRegisterInfo{#1}{#2}{Sprite Port-Mirror Attribute 4}}\n\t{40}{\\PortRegisterInfo{#1}{#2}{Palette Index}}\n\t{41}{\\PortRegisterInfo{#1}{#2}{Palette Value}}\n\t{42}{\\PortRegisterInfo{#1}{#2}{Enhanced ULA Ink Colour Mask}}\n\t{43}{\\PortRegisterInfo{#1}{#2}{Enhanced ULA Control}}\n\t{44}{\\PortRegisterInfo{#1}{#2}{Enhanced ULA Palette Extension}}\n\t{4A}{\\PortRegisterInfo{#1}{#2}{Transparency Colour Fallback}}\n\t{4B}{\\PortRegisterInfo{#1}{#2}{Sprites Transparency Index}}\n\t{4C}{\\PortRegisterInfo{#1}{#2}{Tilemap Transparency Index}}\n\t{50}{\\PortRegisterInfo{#1}{#2}{Memory Management Slot 0 Bank}}\n\t{51}{\\PortRegisterInfo{#1}{#2}{Memory Management Slot 1 Bank}}\n\t{52}{\\PortRegisterInfo{#1}{#2}{Memory Management Slot 2 Bank}}\n\t{53}{\\PortRegisterInfo{#1}{#2}{Memory Management Slot 3 Bank}}\n\t{54}{\\PortRegisterInfo{#1}{#2}{Memory Management Slot 4 Bank}}\n\t{55}{\\PortRegisterInfo{#1}{#2}{Memory Management Slot 5 Bank}}\n\t{56}{\\PortRegisterInfo{#1}{#2}{Memory Management Slot 6 Bank}}\n\t{57}{\\PortRegisterInfo{#1}{#2}{Memory Management Slot 7 Bank}}\n\t{60}{\\PortRegisterInfo{#1}{#2}{Copper Data}}\n\t{61}{\\PortRegisterInfo{#1}{#2}{Copper Control Low Byte}}\n\t{62}{\\PortRegisterInfo{#1}{#2}{Copper Control High Byte}}\n\t{63}{\\PortRegisterInfo{#1}{#2}{Copper Data 16-bit Write}}\n\t{64}{\\PortRegisterInfo{#1}{#2}{Vertical Video Line Offset}}\n\t{68}{\\PortRegisterInfo{#1}{#2}{ULA Control}}\n\t{69}{\\PortRegisterInfo{#1}{#2}{Display Control 1}}\n\t{6B}{\\PortRegisterInfo{#1}{#2}{Tilemap Control}}\n\t{6C}{\\PortRegisterInfo{#1}{#2}{Default Tilemap Attribute}}\n\t{6E}{\\PortRegisterInfo{#1}{#2}{Tilemap Base Address}}\n\t{6F}{\\PortRegisterInfo{#1}{#2}{Tile Definitions Base Address}}\n\t{70}{\\PortRegisterInfo{#1}{#2}{Layer 2 Control}}\n\t{71}{\\PortRegisterInfo{#1}{#2}{Layer 2 X Offset MSB}}\n\t{75}{\\PortRegisterInfo{#1}{#2}{Sprite Port-Mirror Attribute 0 (With Increment)}}\n\t{76}{\\PortRegisterInfo{#1}{#2}{Sprite Port-Mirror Attribute 1 (With Increment)}}\n\t{77}{\\PortRegisterInfo{#1}{#2}{Sprite Port-Mirror Attribute 2 (With Increment)}}\n\t{78}{\\PortRegisterInfo{#1}{#2}{Sprite Port-Mirror Attribute 3 (With Increment)}}\n\t{79}{\\PortRegisterInfo{#1}{#2}{Sprite Port-Mirror Attribute 4 (With Increment)}}\n\t{6E}{\\PortRegisterInfo{#1}{#2}{Tilemap Base Address}}\n\t{8E}{\\PortRegisterInfo{#1}{#2}{Memory Mapping}}\n\t{B0}{\\PortRegisterInfo{#1}{#2}{Extended Keys 0}}\n\t{B1}{\\PortRegisterInfo{#1}{#2}{Extended Keys 1}}\n\t{C0}{\\PortRegisterInfo{#1}{#2}{Interrupt Control}}\n\t{C2}{\\PortRegisterInfo{#1}{#2}{NMI Return Address LSB}}\n\t{C3}{\\PortRegisterInfo{#1}{#2}{NMI Return Address MSB}}\n\t{C4}{\\PortRegisterInfo{#1}{#2}{Interrupt Enable 0}}\n\t{C5}{\\PortRegisterInfo{#1}{#2}{Interrupt Enable 1}}\n\t{C6}{\\PortRegisterInfo{#1}{#2}{Interrupt Enable 2}}\n\t{C8}{\\PortRegisterInfo{#1}{#2}{Interrupt Status 0}}\n\t{C9}{\\PortRegisterInfo{#1}{#2}{Interrupt Status 1}}\n\t{CA}{\\PortRegisterInfo{#1}{#2}{Interrupt Status 2}}\n\t{CC}{\\PortRegisterInfo{#1}{#2}{DMA Interrupt Enable 0}}\n\t{CD}{\\PortRegisterInfo{#1}{#2}{DMA Interrupt Enable 1}}\n\t{CE}{\\PortRegisterInfo{#1}{#2}{DMA Interrupt Enable 2}}}}\n\n% convenience for returning formatted port address, parameter is, well the port address ¯\\_(ツ)_/¯\n\\newcommand{\\PortAddr}[1]{\\PortRegister[0]{#1}}\n% convenience for returning port name, parameter is port address\n\\newcommand{\\PortName}[1]{\\PortRegister[1]{#1}}\n% creates a reference (as used in label) to the given port or register, empty if port is not declared\n\\newcommand{\\PortReference}[1]{Port#1}\n\n% creates a nicely formatted text that includes given port name and address\n\\newcommand{\\PortText}[1]{\\textbf{\\small\\PortName{#1}} \\PortAddr{#1}}\n\n% creates a declaration of the port with the given address; only 1 declaration of each port should be made in a document. You can use `\\PortXRef{addr}' to create a cross reference to this position.\n\\newcommand{\\PortDeclaration}[1]{\\PortText{#1}\\label{\\PortReference{#1}}}\n\n% creates page number for the declaration of the given port or register\n\\newcommand{\\PortPage}[1]{\\pageref{\\PortReference{#1}}}\n% creates a cross reference to the declaration of the port with the given address that includes section and page number\n\\newcommand{\\PortXRef}[1]{\\XRef{\\PortReference{#1}}}\n% creates optional page number for given port address\n% #1 \",\" to add page after comma, \"()\" to add page within parenthesis, leave out to not add page\n% #2 port address\n\\newcommand{\\PortXRefPage}[2]{\\IfEqCase{#1}{{,}{, page \\PortPage{#2}}{()}{ (page \\PortPage{#2})}{}{}}}\n% creates a cross reference to the declaration of the given port with the given address that uses `\\PortText` as the cross reference text\n% #1 (optional): \",\" to add page after comma, \"()\" to add page within parenthesis, leave out to not add page information, just port text (clickable in PDF)\n% #2 port address\n\\NewDocumentCommand{\\PortTextXRef}{ O{()} m}{\\protect\\hyperref[\\PortReference{#2}]{\\PortText{#2}\\PortXRefPage{#1}{#2}}}\n\n% creates a longer text variant of the reference to the given port that includes chapter title and section number, mostly used for register lists when referring to previously described register. Parameters:\n% #1 section name\n% #2 port number\n\\newcommand{\\PortDeclarationXRef}[2]{\n\t\\vspace*{-2ex}\n\tSee description under #1, section \\PortXRef{#2}.\n}\n% similar to `\\PortDeclarationXRef' but allows creating a reference to single section but multiple pages\n% #1 section name\n% #2 first port number, for start page\n% #3 last port number, for last page\n\\newcommand{\\PortDeclarationXRefMultiple}[3]{\n\t\\vspace*{-2ex}\n\tSee description under #1, section \\ref{\\PortReference{#2}}, pages \\PortPage{#2}-\\PortPage{#3}.\n}\n% similar to `\\PortDeclarationXRef' but allows completely custom reference implementation\n%  #1 section name\n\\newcommand{\\PortDeclarationXRefCustom}[2]{\n\t\\vspace*{-2ex}\n\tSee description under #1, #2.\n}\n"
  },
  {
    "path": "readme.md",
    "content": "# ZX Spectrum Next Assembly Developer Guide\r\n\r\nZX Spectrum Next is the successor of the Sinclair Spectrum line from the 80-ies. With all the advanced features it truly brings Spectrum to the next millenium! On a personal note though, Next represents coming back home, to Speccy, the computer where I did my first steps into the world of programming. Steps that turned into career and a journey that still fascinates me as much as it did back then!\r\n\r\nBuilt upon Z80 processor, Next inherits its rich CISC intruction set. For assembler developer, CISC architecture means a plethora of useful instructions that would typically need to be implemented manually, combining multiple instructions on RISC side. But on the downside, it's hard to remember them all and even then, instructions require variety of CPU cycles and take different amount of bytes in RAM. While Next comes bundled with great manual, it only really covers BASIC.\r\n\r\nWhen I started learning Z80 assembly, I quickly desired for a booklet where all instructions would be listed with some basic information such as number of bytes, CPU cycles, effects on flags etc. This would allow me to quickly assess the difference between them and chose the optimal one for task at hand. There are various documents online providing this, but neither really scratched my itch. So I fell into frequent programmer trap of \"do it myself\" and set to write my own. After finding [Z80 undocumented](http://www.myquest.nl/z80undocumented/), it seemed like the perfect starting point. I updated it to be more relevant for Next developer and added many new chapters explaining different areas from the perspective of assembler developer: ULA, Layer 2, Tilemap, Sprites, Sound etc. These chapters represent my notes as I was learning those topics. The rest of the book consists of instructions lists and instructions descriptions. I did leave in existing chapter about Z80 too, I found it insightful read for Next developer too!\r\n\r\nThe book is written as introduction, however I made great effort to keep it relevant as reference as well. It's not intended as comprehensive manual though, it covers relevant areas and provides enough material to get things going. Further exploration into details and edge cases, if needed, is passed to the reader.\r\n\r\nSee introduction section in the PDF for information on the book, its history, origins, and more.\r\n\r\nThe book is available in two formats:\r\n\r\n- [Free to download PDF file](https://github.com/tomaz/zx-next-dev-guide/tags) or\r\n- [Printed coil bound book](https://bit.ly/zx-next-assembly-dev-guide), if you prefer to have physical copy\r\n\r\nNote: both books are the same apart from couple small differences:\r\n\r\n- PDF shows sub-sections in main TOC, printed book not; typically only a small portion of page is visible on screen at once and TOC is clickable, so it makes sense to allow reaching specific areas. Printable book on the other hand provides much better overview, including sub-sections would only add noise.\r\n- PDF doesn't include alphabetical instructions table; mainly because it's searchable so I felt it just adds noise\r\n- Email addresses are obfuscated in PDF, printed book uses proper `name@domain.nnn` notation\r\n\r\nYou can build printable variant yourself from sources. In fact, it's enabled by default (mainly to avoid me uploading PDF for physical book using obfuscated emails). **But please don't publish it in that form, it will make all emails much easier for bots to extract!**\r\n\r\n# Editing\r\n\r\nThis is just as suggestion to help you if you're starting with LaTeX, not a prerequisite - feel free to use whichever editor and distribution you prefer!\r\n\r\nI use VS Code with the following LaTeX plugins for editing:\r\n\r\n- https://github.com/AREA44/vscode-LaTeX-support\r\n- https://github.com/James-Yu/LaTeX-Workshop.git\r\n\r\nFor compiling LaTeX, I use https://miktex.org/\r\n\r\n# Styling guide\r\n\r\nMy main intention with this document was to have printed book, therefore PDF is styled primarily with that in mind. When editing content it's important to ensure information fits nicely. Mainly: specific topic should remain on the same even/odd page boundary as much as possible to allow user to see all relevant information with as little paging as possible. Of course larger topics will be split between multiple pages. It's fine to split individual parts from odd to even page, as both pages are visible when the book is open, but when the information is crossing from even to odd page, care should be taken. Most of the time, I opted to use small gaps so the following content is available in full on next page. Sometimes I also sacrificed order (for example instructions details section) to avoid too much gap.\r\n\r\nTo help with layout, I suggest using 2 page spread mode. If you're using LaTeX Workshop plugin, you can change preview to open in this mode with this setting:\r\n\r\n```\r\n\"latex-workshop.view.pdf.spreadMode\": 2\r\n```\r\n\r\n# Sample code\r\n\r\nSample code from the book is also included in this repository. I use VS Code for programming Next as well. I only tested the programs on Windows so while all tools should be available on Linux and macOS, some configuration may need tweaking. You can find information on setup I use in the PDF.\r\n\r\n# Todo / Ideas\r\n\r\nSee [GitHub issues](https://github.com/tomaz/zx-next-dev-guide/issues) or contact me!\r\n\r\nAlso one bigger thing: I'd prefer to have the book in smaller physical size, something between A5 and A4. It would get more pages, but would fit better in hand and on the shelf. Most of the content would hopefully flow nicely, however some will be problematic (instructions at a glance come to mind). Maybe Royal or Crown Quarto - though I don't think either is available as coil bound variant (and this type of book would benefit a lot from such binding). Also need to check if more pages will affect the price...\r\n\r\n\r\n# License\r\n\r\nZX Spectrum Next Developer Guide and companion source code are available under GNU license, please see the end of PDF document for full licence info!"
  },
  {
    "path": "samples/copper/.vscode/launch.json",
    "content": "{\r\n\t// Use IntelliSense to learn about possible attributes.\r\n\t// Hover to view descriptions of existing attributes.\r\n\t// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387\r\n\t\"version\": \"0.2.0\",\r\n\t\"configurations\": [\r\n\t\t{\r\n\t\t\t\"type\": \"dezog\",\r\n\t\t\t\"request\": \"launch\",\r\n\t\t\t\"name\": \"CSpect\",\r\n\t\t\t\"remoteType\": \"cspect\",\r\n\t\t\t\"cspect\": {\r\n\t\t\t\t\"port\": 13000,\r\n\t\t\t},\r\n\t\t\t\"sjasmplus\": [\r\n\t\t\t\t{\r\n\t\t\t\t\t\"asm\": \"sjasmplus\",\r\n\t\t\t\t\t\"useFiles\": true,\r\n\t\t\t\t\t\"mainFile\": \"${fileDirname}/main.asm\",\r\n\t\t\t\t\t\"path\": \"${workspaceRoot}/build/test.sld\"\r\n\t\t\t\t}\r\n\t\t\t],\r\n\t\t\t\"history\": {\r\n\t\t\t\t\"reverseDebugInstructionCount\": 1000000,\r\n\t\t\t\t\"spotCount\": 10,\r\n\t\t\t},\r\n\t\t\t\"commandsAfterLaunch\": [\r\n\t\t\t\t\"-logpoint enable\",\r\n\t\t\t\t//\"-wpmem enable\",\r\n\t\t\t\t//\"-sprites\",\r\n\t\t\t\t//\"-patterns\",\r\n\t\t\t],\r\n\t\t\t\"disassemblerArgs\": {\r\n\t\t\t\t\"esxdosRst\": true\r\n\t\t\t},\r\n\t\t\t// \"topOfStack\": \"stack_top\",\r\n\t\t\t\"startAutomatically\": false,\r\n\t\t\t\"preLaunchTask\": \"Build\",\r\n\t\t\t\"rootFolder\": \"${workspaceFolder}\",\r\n\t\t\t\"load\": \"${workspaceRoot}/build/test.nex\",\r\n\t\t\t\"smallValuesMaximum\": 513,\r\n\t\t\t\"tmpDir\": \".tmp\"\r\n\t\t},\r\n\r\n\t\t{\r\n\t\t\t\"type\": \"dezog\",\r\n\t\t\t\"request\": \"launch\",\r\n\t\t\t\"name\": \"ZEsarUX\",\r\n\t\t\t\"remoteType\": \"zrcp\",\r\n\t\t\t\"zrcp\": {\r\n\t\t\t\t\"hostname\": \"localhost\",\r\n\t\t\t\t\"port\": 10000,\r\n\t\t\t\t\"loadDelay\": 700,\r\n\t\t\t\t\"skipInterrupt\": true,\r\n\t\t\t\t//\"socketTimeout\": 50\r\n\t\t\t},\r\n\t\t\t\"sjasmplus\": [\r\n\t\t\t\t{\r\n\t\t\t\t\t\"asm\": \"sjasmplus\",\r\n\t\t\t\t\t\"useFiles\": true,\r\n\t\t\t\t\t\"mainFile\": \"${fileDirname}/main.asm\",\r\n\t\t\t\t\t\"path\": \"${workspaceRoot}/build/test.sld\"\r\n\t\t\t\t}\r\n\t\t\t],\r\n\t\t\t\"history\": {\r\n\t\t\t\t\"reverseDebugInstructionCount\": 1000000,\r\n\t\t\t\t\"spotCount\": 10,\r\n\t\t\t},\r\n\t\t\t\"commandsAfterLaunch\": [\r\n\t\t\t\t\"-logpoint enable\",\r\n\t\t\t\t\"-wpmem enable\",\r\n\t\t\t\t//\"-sprites\",\r\n\t\t\t\t//\"-patterns\",\r\n\t\t\t],\r\n\t\t\t\"disassemblerArgs\": {\r\n\t\t\t\t\"esxdosRst\": true\r\n\t\t\t},\r\n\t\t\t// \"topOfStack\": \"stack_top\",\r\n\t\t\t\"startAutomatically\": false,\r\n\t\t\t\"preLaunchTask\": \"Build\",\r\n\t\t\t\"rootFolder\": \"${workspaceFolder}\",\r\n\t\t\t\"load\": \"${workspaceRoot}/build/test.nex\",\r\n\t\t\t\"smallValuesMaximum\": 513,\r\n\t\t\t\"tmpDir\": \".tmp\"\r\n\t\t},\r\n\r\n\t\t{\r\n\t\t\t\"type\": \"dezog\",\r\n\t\t\t\"request\": \"launch\",\r\n\t\t\t\"name\": \"ZXNext\",\r\n\t\t\t\"remoteType\": \"zxnext\",\r\n\t\t\t\"zxnext\": {\r\n\t\t\t\t//\"port\": 13000,\r\n\t\t\t},\r\n\t\t\t\"sjasmplus\": [\r\n\t\t\t\t{\r\n\t\t\t\t\t\"asm\": \"sjasmplus\",\r\n\t\t\t\t\t\"useFiles\": true,\r\n\t\t\t\t\t\"mainFile\": \"${fileDirname}/main.asm\",\r\n\t\t\t\t\t\"path\": \"${workspaceRoot}/build/test.sld\"\r\n\t\t\t\t}\r\n\t\t\t],\r\n\t\t\t\"history\": {\r\n\t\t\t\t\"reverseDebugInstructionCount\": 1000000,\r\n\t\t\t\t\"spotCount\": 10\r\n\t\t\t},\r\n\t\t\t\"commandsAfterLaunch\": [\r\n\t\t\t\t\"-logpoint enable\",\r\n\t\t\t\t\"-assert enable\",\r\n\t\t\t],\r\n\t\t\t\"disassemblerArgs\": {\r\n\t\t\t\t\"esxdosRst\": true\r\n\t\t\t},\r\n\t\t\t\"topOfStack\": \"stack_top\",\r\n\t\t\t\"startAutomatically\": false,\r\n\t\t\t\"preLaunchTask\": \"Build\",\r\n\t\t\t\"rootFolder\": \"${workspaceFolder}\",\r\n\t\t\t\"load\": \"${workspaceRoot}/build/${fileBasenameNoExtension}.nex\",\r\n\t\t\t\"smallValuesMaximum\": 513,\r\n\t\t\t\"tmpDir\": \".tmp\"\r\n\t\t},\r\n\t]\r\n}"
  },
  {
    "path": "samples/copper/.vscode/tasks.json",
    "content": "{\n\t\"version\": \"2.0.0\",\n\t\"tasks\": [\n\t\t{\n\t\t\t\"label\": \"Build\",\n\t\t\t\"type\": \"shell\",\n\t\t\t\"command\": \"${workspaceRoot}/../Tools/sjasmplus/sjasmplus.exe\",\n\t\t\t\"args\": [\n\t\t\t\t\"--sld=${workspaceRoot}/build/test.sld\",\n\t\t\t\t\"--sym=${workspaceRoot}/build/test.labels\",\n\t\t\t\t\"--fullpath\",\n\t\t\t\t\"main.asm\"\n\t\t\t],\n\t\t\t\"problemMatcher\": {\n\t\t\t\t\"fileLocation\": [\n\t\t\t\t\t\"relative\",\n\t\t\t\t\t\"${workspaceRoot}\"\n\t\t\t\t],\n\t\t\t\t\"pattern\": {\n\t\t\t\t\t\"regexp\": \"^(.*)\\\\((\\\\d+)\\\\):\\\\s+(warning|error):\\\\s+(.*)$\",\n\t\t\t\t\t\"file\": 1,\n\t\t\t\t\t\"line\": 2,\n\t\t\t\t\t\"severity\": 3,\n\t\t\t\t\t\"message\": 4\n\t\t\t\t}\n\t\t\t},\n\t\t\t\"group\": {\n\t\t\t\t\"kind\": \"build\",\n\t\t\t\t\"isDefault\": true\n\t\t\t}\n\t\t},\n\n\t\t{\n\t\t\t\"label\": \"Launch ZEsarUX\",\n\t\t\t\"type\": \"shell\",\n\t\t\t\"command\": \"${workspaceRoot}/../Tools/ZEsarUX/ZEsarUX.exe\",\n\t\t\t\"options\": {\n\t\t\t\t\"cwd\": \"${workspaceRoot}/../Tools/ZEsarUX\"\n\t\t\t}\n\t\t},\n\n\t\t{\n\t\t\t\"label\": \"Launch CSpect\",\n\t\t\t\"type\": \"shell\",\n\t\t\t\"command\": \"${workspaceRoot}/../Tools/CSpect/CSpect.exe -debug -exit -brk -sound -tv -esc -zxnext -nextrom -mmc=./tbblue-512M.mmc > output.log\",\n\t\t\t\"options\": {\n\t\t\t\t\"cwd\": \"${workspaceRoot}/../Tools/CSpect\"\n\t\t\t}\n\t\t}\n\t]\n}\n"
  },
  {
    "path": "samples/copper/build/.gitignore",
    "content": "# Ignore everything in this directory\r\n*\r\n# Except this file\r\n!.gitignore"
  },
  {
    "path": "samples/copper/main.asm",
    "content": ";;--------------------------------------------------------------------\r\n;; sjasmplus setup\r\n;;--------------------------------------------------------------------\r\n\r\n\t; Allow Next paging and instructions\r\n\tDEVICE ZXSPECTRUMNEXT\r\n\tSLDOPT COMMENT WPMEM, LOGPOINT, ASSERTION\r\n\r\n\t; Generate a map file for use with Cspect\r\n\tCSPECTMAP \"build/test.map\"\r\n\r\n\r\n;;--------------------------------------------------------------------\r\n;; program\r\n;;--------------------------------------------------------------------\r\n\r\nL2_START_16K_BANK = 9\r\nL2_START_8K_BANK = L2_START_16K_BANK * 2\r\nL2_END_8K_BANK = L2_START_8K_BANK + 6\r\n\r\n\t; Main program will start at $8000\r\n\tORG $8000\r\nStart:\r\n\t; Run the program\r\n\tCALL InitializeLayer2\r\n\tCALL InitializeCopper\t\t; only need one...\r\n\t; CALL InitializeCopperDMA\t; ...or the other\r\n\tCALL MainLoop\r\n\r\n\t; Return from main routine (will never occur in our case)\r\n\tRET\r\n\r\nInitializeLayer2:\r\n\t; Enable Layer 2\r\n\tLD BC, $123B\r\n\tLD A, 2\r\n\tOUT (C), A\r\n\r\n\t; Setup starting Layer2 16K bank and swap corresponding 8K memory bank into screen memory $C000 where L2 will read from\r\n\tNEXTREG $12, L2_START_16K_BANK\r\n\r\n\t; We'll fill in each of 6 8K banks, bank by bank, starting with the first one\r\n\tLD A, L2_START_8K_BANK\r\n\r\n.nextBank:\r\n\t; Swap current bank into slot 6 (memory $C000-$DFFF)\r\n\tNEXTREG $56, A\r\n\r\n\t; Prepare starting address and fill in 0 to the first byte. We'll copy this value over the rest of the memory.\r\n\tLD HL, $C000\r\n\tLD (HL), 0\r\n\r\n\t; We'll use DMA to copy the first byte (we just set to 0) over remaining 8K. DMA setup will be: port A = $C000 and will remain fixed throughout the transfer, port B starts at $C001 and will be incremented after each transfer, length = 8K-1\r\n\tLD HL, .dmaProgram\t; HL = pointer to DMA program\r\n\tLD B, .dmaProgramLength\t; B = size of the code\r\n\tLD C, $6B\t\t; C = $6B (DMA port)\r\n\tOTIR\t\t\t; upload and run DMA program\r\n\r\n\t; Continue with next bank, until we fill all\r\n\tINC A\r\n\tCP A, L2_END_8K_BANK+1\r\n\tJP NZ, .nextBank\r\n\tRET\r\n\r\n.dmaProgram:\r\n\tDB %10000011\t\t; WR6 - Disable DMA\r\n\tDB %01111101\t\t; WR0 - append length + port A address, A->B\r\n\tDW $C000\t\t; WR0 par 1&2 - port A start address\r\n\tDW 8*1024-1\t\t; WR0 par 3&4 - transfer length\r\n\tDB %00100100\t\t; WR1 - A fixed, A=memory\r\n\tDB %00010000\t\t; WR2 - B incrementing, B=memory\r\n\tDB %10101101\t\t; WR4 - continuous, append port B address\r\n\tDW $C001\t\t; WR4 par 1&2 - port B address\r\n\tDB %10000010\t\t; WR5 - stop on end of block, CE only\r\n\tDB %11001111\t\t; WR6 - load addresses into DMA counters\r\n\tDB %10000111\t\t; WR6 - enable DMA\r\n.dmaProgramLength = $-.dmaProgram\r\n\r\n\r\n; Demonstrates how to initialize Copper using NEXTREG $63 directly\r\nInitializeCopper:\r\n\t; Stop copper and set data upload index to 0\r\n\tNEXTREG $61, %00000000\r\n\tNEXTREG $62, %00000000\r\n\r\n\t; Copy our copper list into copper memory\r\n\tLD HL, CopperList\t; HL now points to start of copper list\r\n\tLD DE, CopperListSize\t; DE = size of our copper list in bytes\r\n\r\n\t; Prepare counters for a fast 16-bit loop\r\n\tLD B, E\t\t\t; We need B for DJNZ\r\n\tDEC DE\t\t\t; This ensures INC D below will only be incremented if DE>255\r\n\tINC D\t\t\t; We will DEC D to exit loop below, so we need to INC it here\r\n.nextByte:\r\n\t; Note: we use $63 register which only sends the instruction to Copper memory after both bytes are written (after 2 NEXTREG $63 calls). We could also use $60 which writes bytes immediately, however this can lead to Copper executing instruction when after only single byte is written. $63 prevents that. This is not an issue in our case because we explicitly stop the Copper before uploading the program, but something to keep in mind. Also see how we use $60 in MainLoop!\r\n\tLD A, (HL)\t\t; Load current byte to A\r\n\tNEXTREG $63, A\t\t; Copy it to copper memory (this will auto-increment to next memory position)\r\n\r\n\t; Prepare for next byte\r\n\tINC HL\t\t\t; Increment HL to next byte\r\n\r\n\t; Repeat or exit\r\n\tDJNZ .nextByte\t\t; Repeat (max 256 times)\r\n\tDEC D\t\t\t; Check if we need to repeat DJNZ loop again\r\n\tJP NZ, .nextByte\t; Yes? Repeat then... :)\r\n\r\n\t; Finally start copper using mode %11\r\n\tNEXTREG $61, %00000000\r\n\tNEXTREG $62, %11000000\r\n\r\n\tRET\r\n\r\n; Demonstrates how to initialize Copper using DMA\r\nInitializeCopperDMA:\r\n\t; We simply set the parameters and let execution continue inside the reusable `InitializeCopperListDMA` routine.\r\n\tLD HL, CopperList\r\n\tLD BC, CopperListSize\r\n\r\n; This is generic reusable routine for uploading Copper list to DMA. It takes two parameters (both are destroyed):\r\n; - HL = address of the Copper list in memory\r\n; - BC = size of Copper list in bytes\r\nInitializeCopperListDMA:\r\n\t; Stop copper and set data upload index to 0\r\n\tNEXTREG $61, %00000000\r\n\tNEXTREG $62, %00000000\r\n\r\n\t; Copy parameters into DMA code\r\n\tLD (.dmaSource), HL\r\n\tLD (.dmaLength), BC\r\n\r\n\t; We want to upload to NEXTREG $63, select it with $243B port\r\n\tLD A, $63\r\n\tLD BC, $243B\r\n\tOUT (C), A\r\n\r\n\t; Upload DMA instructions to DMA memory\r\n\tLD HL, .dmaProgram\t; HL = pointer to DMA program\r\n\tLD B, .dmaProgramLength\t; B = size of the code\r\n\tLD C, $6B\t\t; C = $6B (DMA port)\r\n\tOTIR\t\t\t; upload DMA program\r\n\r\n\t; Finally start copper using mode %11\r\n\tNEXTREG $61, %00000000\r\n\tNEXTREG $62, %11000000\r\n\tRET\r\n\r\n.dmaProgram:\r\n\tDB %10000011\t\t; WR6 - Disable DMA\r\n\tDB %01111101\t\t; WR0 - append length + port A address, A->B\r\n.dmaSource:\r\n\tDW 0\t\t\t; WR0 par 1&2 - port A start address\r\n.dmaLength:\r\n\tDW 0\t\t\t; WR0 par 3&4 - transfer length\r\n\tDB %00010100\t\t; WR1 - A incr., A=memory\r\n\tDB %00101000\t\t; WR2 - B fixed, B=I/O\r\n\tDB %10101101\t\t; WR4 - continuous, append port B address\r\n\tDW $253B\t\t; WR4 par 1&2 - port B address\r\n\tDB %10000010\t\t; WR5 - stop on end of block, CE only\r\n\tDB %11001111\t\t; WR6 - load addresses into DMA counters\r\n\tDB %10000111\t\t; WR6 - enable DMA\r\n.dmaProgramLength = $-.dmaProgram\r\n\r\n\r\nMainLoop:\r\nMIN_Y = 10\t; minimum Y coordinate for animation\r\nMAX_Y = 93\t; maximum Y coordinate for animation\r\n\r\n\t; First move down the screen (aka make red area shorter)\r\n\tLD A, MIN_Y\t\t\t; Prepare starting coordinate\r\n.downTheScreen:\r\n\tCALL WaitAWhile\t\t\t; A litte delay...\r\n\tCALL UpdateCopperRedWait\t; Update copper red wait command with new one from A\r\n\tCALL UpdateCopperWindowLeftPos\t; Update Layer 2 left position\r\n\r\n\tINC A\t\t\t\t; Increment A\r\n\tCP MAX_Y\t\t\t; Did we reach the maximum coordinate?\r\n\tJP NZ, .downTheScreen\t\t; No? Repeat. Otherwise continue\r\n\r\n\t; Now move back upwards (aka make red area taller)\r\n.upTheScreen:\r\n\tCALL WaitAWhile\t\t\t; A litte delay...\r\n\tCALL UpdateCopperRedWait\t; Update copper red wait comnmand with new one from A\r\n\tCALL UpdateCopperWindowLeftPos\t; Update Layer 2 left position\r\n\r\n\tDEC A\t\t\t\t; Decrement A\r\n\tCP MIN_Y\t\t\t; Did we reach the minimum coordinate?\r\n\tJP NZ, .upTheScreen\t\t; No? Repeat. Otherwise continue\r\n\r\n\t; Repeat the whole loop again, and again, and again, and... you get the point ;)\r\n\tJP MainLoop\r\n\r\nUpdateCopperRedWait:\r\n\t; The gist of this routine is to offset current Copper PC to WAIT command that subsequently changes background colour to red. Then write updated Y coordinate from A register.\r\n\r\n\t; First prepare Copper PC to our command. This is simplified code that only works as long as the offset from the start of the list is less than 256!\r\n\t; Note we only need to update the Y position in LSB of the red wait instruction. As our label points to the MSB byte, we need to add 1.\r\n\tNEXTREG $61, CopperListRedWait\t; LSB contains the bits 7-0 of the Copper instruction offset\r\n\tNEXTREG $62, %11'000'000\t; 11=start from 0 & repeat, the rest are 0 because we never have offsets > 255\r\n\r\n\t; Now we need to write the byte that contain new WAIT Y coordinate. Again we simplify the code by relying on the fact that we never change Y above 255.\r\n\t; Note: since we only write 1 byte, we can't use $63 register. $63 expects both bytes of an instruction to be set, it only writes afterwards. But $60 writes each byte immediately.\r\n\tNEXTREG $60, A\t\t\t; A contains new Y coordinate\r\n\r\n\tRET\r\n\r\nUpdateCopperWindowLeftPos:\r\n\t; This works exactly the same as `UpdateCopperRedWait`, except we update the byte specifying Layer 2 Window left position.\r\n\r\n\t; First prepare Copper PC to our command. This is simplified code that only works as long as the offset from the start of the list is less than 256!\r\n\t; Note we only need to update the Y position in LSB of the red wait instruction. As our label points to the MSB byte, we need to add 1.\r\n\tNEXTREG $61, CopperListWindowLeftMove; LSB contains the bits 7-0 of the Copper instruction offset\r\n\tNEXTREG $62, %11'000'000\t; 11=start from 0 & repeat, the rest are 0 because we never have offsets > 255\r\n\r\n\t; Now we need to write the byte that contain new position from A.\r\n\t; Note: since we only write 1 byte, we can't use $63 register. $63 expects both bytes of an instruction to be set, it only writes afterwards. But $60 writes each byte immediately.\r\n\tNEXTREG $60, A\t\t\t; A contains new Y coordinate\r\n\r\n\tRET\r\n\r\nWaitAWhile:\r\n\tLD C, 10\r\n.cloop:\r\n\tLD B, $FF\r\n.bloop:\tNOP\r\n\tNOP\r\n\tNOP\r\n\tNOP\r\n\tDJNZ .bloop\r\n\r\n\tDEC C\r\n\tJP NZ, .cloop\r\n\tRET\r\n\r\n;;--------------------------------------------------------------------\r\n;; copper list\r\n;;--------------------------------------------------------------------\r\n\r\n; declares copper wait instruction for given horizontal (0-440) and vertical (0-311) position\r\n\tMACRO COPPER_WAIT hor, ver\r\n\tDB %10000000 | ((hor/8) << 1) | ((ver & $1FF) >> 8)\t; %1hhhhhhv (bit 9 of vertical)\r\n\tDB (ver & $FF)\t\t\t\t\t\t; %vvvvvvvv (lsb of vertical)\r\n\tENDM\r\n\r\n; declares copper move instruction for moving given value (0-255) to given Next register (0-127)\r\n\tMACRO COPPER_MOVE reg, value\r\n\tDB (reg & %01111111)\t\t\t; %0rrrrrrr\r\n\tDB (value & $FF)\t\t\t; %vvvvvvvv\r\n\tENDM\r\n\r\n; declares copper NOOP instruction\r\n\tMACRO COPPER_NOOP\r\n\tDB %00000000\r\n\tDB %00000000\r\n\tENDM\r\n\r\n; declares copper HALT instruction (for ending copper list)\r\n\tMACRO COPPER_HALT\r\n\tDB %11111111\r\n\tDB %11111111\r\n\tENDM\r\n\r\n; declares 9-bit RGB colour through double $44 reg call; red, green and blue are 0-7\r\n\tMACRO COPPER_9BIT red, green, blue\r\n\tCOPPER_MOVE $44, ((red & %111) << 5) | ((green & %111) << 2) | ((blue & %110) >> 1)\r\n\tCOPPER_MOVE $44, (blue & %1)\r\n\tENDM\r\n\r\n; a sample copper list that changes palette entry 0 colour for Layer 2 palette 4 times\r\nCopperList:\r\n\t; Wait line 0\r\n\tCOPPER_WAIT 0, 0\r\n\r\n\t; Prepare palette handling (and hope noone changes this during copper pass ¯\\_(ツ)_/¯)\r\n\tCOPPER_MOVE $43, %10010000\t; no auto-inc, L2 first palette\r\n\tCOPPER_MOVE $40, 0\t\t; colour index 0\r\n\r\n\t; Change L2 palette entry 0 to gray-ish\r\n\tCOPPER_9BIT 1, 2, 2\r\n\r\n\t; Wait line 47 and change palette entry 0 to red-ish\r\nCopperListRedWait = $ - CopperList + 1\t; we will change the LSB of the WAIT instruction below, hence +1\r\n\tCOPPER_WAIT 0, 47\t\t; we'll change this 47 to animate the offset of the red background in the main loop\r\n\tCOPPER_9BIT 4, 2, 2\r\n\r\n\t; Update Layer 2 clip window left position.\r\n\tCOPPER_MOVE $1C, 1\t\t; Reset Layer 2 clip window register index\r\nCopperListWindowLeftMove = $ - CopperList + 1; we will change the value of the MOVE below, so LSB, hence +1\r\n\tCOPPER_MOVE $18, 0\t\t; Write clip window coordinate for L2, since we reset it above, this will always be left position\r\n\r\n\t; Wait line 94 and change palette entry 0 to green-ish as well as reset window position to 0. By resetting window coordinate we effectively restrict it to the red area above\r\n\tCOPPER_WAIT 0, 94\r\n\tCOPPER_9BIT 2, 4, 2\r\n\tCOPPER_MOVE $1C, 1\r\n\tCOPPER_MOVE $18, 0\r\n\r\n\t; Wait line 141 and change palette entry 0 to blue-ish\r\n\tCOPPER_WAIT 0, 141\r\n\tCOPPER_9BIT 1, 1, 4\r\n\r\n\tCOPPER_HALT\r\nCopperListSize = $ - CopperList\r\n\r\n\r\n;;--------------------------------------------------------------------\r\n;; Set up .nex output\r\n;;--------------------------------------------------------------------\r\n\r\n\t; This sets the name of the project, the start address, \r\n\t; and the initial stack pointer.\r\n\tSAVENEX OPEN \"build/test.nex\", Start, $ff40\r\n\r\n\t; This asserts the minimum core version.  Set it to the core version \r\n\t; you are developing on.\r\n\tSAVENEX CORE 2, 0, 0\r\n\r\n\t; This sets the border colour while loading (in this case white),\r\n\t; what to do with the file handle of the nex file when starting (0 = \r\n\t; close file handle as we're not going to access the project.nex \r\n\t; file after starting.  See sjasmplus documentation), whether\r\n\t; we preserve the next registers (0 = no, we set to default), and \r\n\t; whether we require the full 2MB expansion (0 = no we don't).\r\n\tSAVENEX CFG 7, 0, 0, 0\r\n\r\n\t; Generate the Nex file automatically based on which pages you use.\r\n\tSAVENEX AUTO\r\n\r\n"
  },
  {
    "path": "samples/im1/.vscode/launch.json",
    "content": "{\r\n\t// Use IntelliSense to learn about possible attributes.\r\n\t// Hover to view descriptions of existing attributes.\r\n\t// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387\r\n\t\"version\": \"0.2.0\",\r\n\t\"configurations\": [\r\n\t\t{\r\n\t\t\t\"type\": \"dezog\",\r\n\t\t\t\"request\": \"launch\",\r\n\t\t\t\"name\": \"CSpect\",\r\n\t\t\t\"remoteType\": \"cspect\",\r\n\t\t\t\"cspect\": {\r\n\t\t\t\t\"port\": 13000,\r\n\t\t\t},\r\n\t\t\t\"sjasmplus\": [\r\n\t\t\t\t{\r\n\t\t\t\t\t\"asm\": \"sjasmplus\",\r\n\t\t\t\t\t\"useFiles\": true,\r\n\t\t\t\t\t\"mainFile\": \"${fileDirname}/main.asm\",\r\n\t\t\t\t\t\"path\": \"${workspaceRoot}/build/test.sld\"\r\n\t\t\t\t}\r\n\t\t\t],\r\n\t\t\t\"history\": {\r\n\t\t\t\t\"reverseDebugInstructionCount\": 1000000,\r\n\t\t\t\t\"spotCount\": 10,\r\n\t\t\t},\r\n\t\t\t\"commandsAfterLaunch\": [\r\n\t\t\t\t\"-logpoint enable\",\r\n\t\t\t\t//\"-wpmem enable\",\r\n\t\t\t\t//\"-sprites\",\r\n\t\t\t\t//\"-patterns\",\r\n\t\t\t],\r\n\t\t\t\"disassemblerArgs\": {\r\n\t\t\t\t\"esxdosRst\": true\r\n\t\t\t},\r\n\t\t\t// \"topOfStack\": \"stack_top\",\r\n\t\t\t\"startAutomatically\": false,\r\n\t\t\t\"preLaunchTask\": \"Build\",\r\n\t\t\t\"rootFolder\": \"${workspaceFolder}\",\r\n\t\t\t\"load\": \"${workspaceRoot}/build/test.nex\",\r\n\t\t\t\"smallValuesMaximum\": 513,\r\n\t\t\t\"tmpDir\": \".tmp\"\r\n\t\t},\r\n\r\n\t\t{\r\n\t\t\t\"type\": \"dezog\",\r\n\t\t\t\"request\": \"launch\",\r\n\t\t\t\"name\": \"ZEsarUX\",\r\n\t\t\t\"remoteType\": \"zrcp\",\r\n\t\t\t\"zrcp\": {\r\n\t\t\t\t\"hostname\": \"localhost\",\r\n\t\t\t\t\"port\": 10000,\r\n\t\t\t\t\"loadDelay\": 700,\r\n\t\t\t\t\"skipInterrupt\": true,\r\n\t\t\t\t//\"socketTimeout\": 50\r\n\t\t\t},\r\n\t\t\t\"sjasmplus\": [\r\n\t\t\t\t{\r\n\t\t\t\t\t\"asm\": \"sjasmplus\",\r\n\t\t\t\t\t\"useFiles\": true,\r\n\t\t\t\t\t\"mainFile\": \"${fileDirname}/main.asm\",\r\n\t\t\t\t\t\"path\": \"${workspaceRoot}/build/test.sld\"\r\n\t\t\t\t}\r\n\t\t\t],\r\n\t\t\t\"history\": {\r\n\t\t\t\t\"reverseDebugInstructionCount\": 1000000,\r\n\t\t\t\t\"spotCount\": 10,\r\n\t\t\t},\r\n\t\t\t\"commandsAfterLaunch\": [\r\n\t\t\t\t\"-logpoint enable\",\r\n\t\t\t\t\"-wpmem enable\",\r\n\t\t\t\t//\"-sprites\",\r\n\t\t\t\t//\"-patterns\",\r\n\t\t\t],\r\n\t\t\t\"disassemblerArgs\": {\r\n\t\t\t\t\"esxdosRst\": true\r\n\t\t\t},\r\n\t\t\t// \"topOfStack\": \"stack_top\",\r\n\t\t\t\"startAutomatically\": false,\r\n\t\t\t\"preLaunchTask\": \"Build\",\r\n\t\t\t\"rootFolder\": \"${workspaceFolder}\",\r\n\t\t\t\"load\": \"${workspaceRoot}/build/test.nex\",\r\n\t\t\t\"smallValuesMaximum\": 513,\r\n\t\t\t\"tmpDir\": \".tmp\"\r\n\t\t},\r\n\r\n\t\t{\r\n\t\t\t\"type\": \"dezog\",\r\n\t\t\t\"request\": \"launch\",\r\n\t\t\t\"name\": \"ZXNext\",\r\n\t\t\t\"remoteType\": \"zxnext\",\r\n\t\t\t\"zxnext\": {\r\n\t\t\t\t//\"port\": 13000,\r\n\t\t\t},\r\n\t\t\t\"sjasmplus\": [\r\n\t\t\t\t{\r\n\t\t\t\t\t\"asm\": \"sjasmplus\",\r\n\t\t\t\t\t\"useFiles\": true,\r\n\t\t\t\t\t\"mainFile\": \"${fileDirname}/main.asm\",\r\n\t\t\t\t\t\"path\": \"${workspaceRoot}/build/test.sld\"\r\n\t\t\t\t}\r\n\t\t\t],\r\n\t\t\t\"history\": {\r\n\t\t\t\t\"reverseDebugInstructionCount\": 1000000,\r\n\t\t\t\t\"spotCount\": 10\r\n\t\t\t},\r\n\t\t\t\"commandsAfterLaunch\": [\r\n\t\t\t\t\"-logpoint enable\",\r\n\t\t\t\t\"-assert enable\",\r\n\t\t\t],\r\n\t\t\t\"disassemblerArgs\": {\r\n\t\t\t\t\"esxdosRst\": true\r\n\t\t\t},\r\n\t\t\t\"topOfStack\": \"stack_top\",\r\n\t\t\t\"startAutomatically\": false,\r\n\t\t\t\"preLaunchTask\": \"Build\",\r\n\t\t\t\"rootFolder\": \"${workspaceFolder}\",\r\n\t\t\t\"load\": \"${workspaceRoot}/build/${fileBasenameNoExtension}.nex\",\r\n\t\t\t\"smallValuesMaximum\": 513,\r\n\t\t\t\"tmpDir\": \".tmp\"\r\n\t\t},\r\n\t]\r\n}"
  },
  {
    "path": "samples/im1/.vscode/tasks.json",
    "content": "{\n\t\"version\": \"2.0.0\",\n\t\"tasks\": [\n\t\t{\n\t\t\t\"label\": \"Build\",\n\t\t\t\"type\": \"shell\",\n\t\t\t\"command\": \"${workspaceRoot}/../Tools/sjasmplus/sjasmplus.exe\",\n\t\t\t\"args\": [\n\t\t\t\t\"--sld=${workspaceRoot}/build/test.sld\",\n\t\t\t\t\"--sym=${workspaceRoot}/build/test.labels\",\n\t\t\t\t\"--fullpath\",\n\t\t\t\t\"main.asm\"\n\t\t\t],\n\t\t\t\"problemMatcher\": {\n\t\t\t\t\"fileLocation\": [\n\t\t\t\t\t\"relative\",\n\t\t\t\t\t\"${workspaceRoot}\"\n\t\t\t\t],\n\t\t\t\t\"pattern\": {\n\t\t\t\t\t\"regexp\": \"^(.*)\\\\((\\\\d+)\\\\):\\\\s+(warning|error):\\\\s+(.*)$\",\n\t\t\t\t\t\"file\": 1,\n\t\t\t\t\t\"line\": 2,\n\t\t\t\t\t\"severity\": 3,\n\t\t\t\t\t\"message\": 4\n\t\t\t\t}\n\t\t\t},\n\t\t\t\"group\": {\n\t\t\t\t\"kind\": \"build\",\n\t\t\t\t\"isDefault\": true\n\t\t\t}\n\t\t},\n\n\t\t{\n\t\t\t\"label\": \"Launch ZEsarUX\",\n\t\t\t\"type\": \"shell\",\n\t\t\t\"command\": \"${workspaceRoot}/../Tools/ZEsarUX/ZEsarUX.exe\",\n\t\t\t\"options\": {\n\t\t\t\t\"cwd\": \"${workspaceRoot}/../Tools/ZEsarUX\"\n\t\t\t}\n\t\t},\n\n\t\t{\n\t\t\t\"label\": \"Launch CSpect\",\n\t\t\t\"type\": \"shell\",\n\t\t\t\"command\": \"${workspaceRoot}/../Tools/CSpect/CSpect.exe -debug -exit -brk -sound -tv -esc -zxnext -nextrom -mmc=./cspect-next-2gb.img > output.log\",\n\t\t\t\"options\": {\n\t\t\t\t\"cwd\": \"${workspaceRoot}/../Tools/CSpect\"\n\t\t\t}\n\t\t}\n\t]\n}\n"
  },
  {
    "path": "samples/im1/build/.gitignore",
    "content": "# Ignore everything in this directory\r\n*\r\n# Except this file\r\n!.gitignore"
  },
  {
    "path": "samples/im1/main.asm",
    "content": ";;--------------------------------------------------------------------\r\n;; sjasmplus setup\r\n;;--------------------------------------------------------------------\r\n\r\n\t; Allow Next paging and instructions\r\n\tDEVICE ZXSPECTRUMNEXT\r\n\tSLDOPT COMMENT WPMEM, LOGPOINT, ASSERTION\r\n\r\n\t; Generate a map file for use with Cspect\r\n\tCSPECTMAP \"build/test.map\"\r\n\r\n\r\n;;--------------------------------------------------------------------\r\n;; program\r\n;;--------------------------------------------------------------------\r\n\r\n; The 8K page into which out interrupt program will be compiled to. We'll page out ROM at slot 0 with this page to get our interrupt working.\r\nINTERRUPT_PAGE = 28\r\n\r\n\t; Main program will start at $8000\r\n\tORG $8000\r\nStart:\r\n\t; Try different CPU speeds (0-3) - the faster the CPU, the faster out main loop will be, therefore interrupt will occur less times and counter will not change so much between each iteration.\r\n\tNEXTREG $07, 3\r\n\r\n\t; Disable interrupts while we're paging out ROM, just in case to prevent one being raised before we're done.\r\n\tDI\r\n\r\n\t; Page out ROM in slot 0 ($0000-$1FFF). This will \"inject\" our interrupt handler to $0038 (as well as anything else we put into this page).\r\n\tNEXTREG $50, INTERRUPT_PAGE\r\n\r\n\t; Explicitly enable IM1; technically we don't have to since Next does it by default, but this ensures IM1 will be used in case another program run before ours set up IM2.\r\n\tIM 1\r\n\r\n\t; We're done with setup, enable interrupts now and let the fun begin...\r\n\tEI\r\n\r\n\t; At this point we'll start infinite loop in our main routine. The only thing it will do is read the value of the counter into A (that our interrupt handler is incrementing). You can inspect the value in debugger.\r\n.loop:\r\n\tCALL WaitALittleBitLonger\r\n\tLD HL, counter\r\n\tLD A, (HL)\r\n\r\n\t; You can set breakpoint on the following line and inspect A to see how it changes.\r\n\tJP .loop\r\n\r\n\t; Return from main routine (will never occur in our case)\r\n\tRET\r\n\r\n; Waiting routine; just chilling out, doing nothing for a while :)\r\nWaitAWhile:\r\n\tLD B, $ff\r\n.loop:\tNOP\r\n\tNOP\r\n\tNOP\r\n\tNOP\r\n\tDJNZ .loop\r\n\tRET\r\n\r\n; A longer delay...\r\nWaitALittleBitLonger:\r\n\tLD C, $40\r\n.loop:\tCALL WaitAWhile\r\n\tDEC C\r\n\tJP NZ, .loop\r\n\tRET\r\n\r\n\r\n; Counter variable\r\ncounter:\r\n\tDB 0\r\n\r\n;;--------------------------------------------------------------------\r\n;; interrupt handler\r\n;;--------------------------------------------------------------------\r\n\r\n\t; In a nutshell, the following code is compiled into selected 8K bank which is loaded into slot 6 ($C000-$DFFF). We will load this bank into slot 0 ($0000-$1FFF) at the start of the program which will effectively page out ROM at those addresses.\r\n\r\n\t; Tell sjasmplus to load given 8K page into slot 6 ($C000-$DFFF).\r\n\tSLOT 6\r\n\tPAGE INTERRUPT_PAGE\r\n\r\n\t; Tell sjasmplus to start writing code into start of slot 6 (which now has given bank loaded into - so we're effectively writing the code into selected bank).\r\n\tORG $C038\r\n\r\n; The interrupt handler itself...\r\nInterruptHandler:\r\n\t; Note: ideally we'd be exchanging registers here so they would be preserved when interrupts returns. But for this simple example, it'll do.\r\n\r\n\t; Load address of our counter and increment it\r\n\tLD HL, counter\r\n\tINC (HL)\r\n\r\n\t; Re-enable interrupts (note we don't have to call DI, system will do it for us)\r\n\tEI\r\n\r\n\t; Return from interrupt!\r\n\tRETI\r\n\r\n;;--------------------------------------------------------------------\r\n;; Set up .nex output\r\n;;--------------------------------------------------------------------\r\n\r\n\t; This sets the name of the project, the start address, \r\n\t; and the initial stack pointer.\r\n\tSAVENEX OPEN \"build/test.nex\", Start, $ff40\r\n\r\n\t; This asserts the minimum core version.  Set it to the core version \r\n\t; you are developing on.\r\n\tSAVENEX CORE 2, 0, 0\r\n\r\n\t; This sets the border colour while loading (in this case white),\r\n\t; what to do with the file handle of the nex file when starting (0 = \r\n\t; close file handle as we're not going to access the project.nex \r\n\t; file after starting.  See sjasmplus documentation), whether\r\n\t; we preserve the next registers (0 = no, we set to default), and \r\n\t; whether we require the full 2MB expansion (0 = no we don't).\r\n\tSAVENEX CFG 7, 0, 0, 0\r\n\r\n\t; Generate the Nex file automatically based on which pages you use.\r\n\tSAVENEX AUTO\r\n\r\n"
  },
  {
    "path": "samples/im2/.vscode/launch.json",
    "content": "{\r\n\t// Use IntelliSense to learn about possible attributes.\r\n\t// Hover to view descriptions of existing attributes.\r\n\t// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387\r\n\t\"version\": \"0.2.0\",\r\n\t\"configurations\": [\r\n\t\t{\r\n\t\t\t\"type\": \"dezog\",\r\n\t\t\t\"request\": \"launch\",\r\n\t\t\t\"name\": \"CSpect\",\r\n\t\t\t\"remoteType\": \"cspect\",\r\n\t\t\t\"cspect\": {\r\n\t\t\t\t\"port\": 13000,\r\n\t\t\t},\r\n\t\t\t\"sjasmplus\": [\r\n\t\t\t\t{\r\n\t\t\t\t\t\"asm\": \"sjasmplus\",\r\n\t\t\t\t\t\"useFiles\": true,\r\n\t\t\t\t\t\"mainFile\": \"${fileDirname}/main.asm\",\r\n\t\t\t\t\t\"path\": \"${workspaceRoot}/build/test.sld\"\r\n\t\t\t\t}\r\n\t\t\t],\r\n\t\t\t\"history\": {\r\n\t\t\t\t\"reverseDebugInstructionCount\": 1000000,\r\n\t\t\t\t\"spotCount\": 10,\r\n\t\t\t},\r\n\t\t\t\"commandsAfterLaunch\": [\r\n\t\t\t\t\"-logpoint enable\",\r\n\t\t\t\t//\"-wpmem enable\",\r\n\t\t\t\t//\"-sprites\",\r\n\t\t\t\t//\"-patterns\",\r\n\t\t\t],\r\n\t\t\t\"disassemblerArgs\": {\r\n\t\t\t\t\"esxdosRst\": true\r\n\t\t\t},\r\n\t\t\t// \"topOfStack\": \"stack_top\",\r\n\t\t\t\"startAutomatically\": false,\r\n\t\t\t\"preLaunchTask\": \"Build\",\r\n\t\t\t\"rootFolder\": \"${workspaceFolder}\",\r\n\t\t\t\"load\": \"${workspaceRoot}/build/test.nex\",\r\n\t\t\t\"smallValuesMaximum\": 513,\r\n\t\t\t\"tmpDir\": \".tmp\"\r\n\t\t},\r\n\r\n\t\t{\r\n\t\t\t\"type\": \"dezog\",\r\n\t\t\t\"request\": \"launch\",\r\n\t\t\t\"name\": \"ZEsarUX\",\r\n\t\t\t\"remoteType\": \"zrcp\",\r\n\t\t\t\"zrcp\": {\r\n\t\t\t\t\"hostname\": \"localhost\",\r\n\t\t\t\t\"port\": 10000,\r\n\t\t\t\t\"loadDelay\": 700,\r\n\t\t\t\t\"skipInterrupt\": true,\r\n\t\t\t\t//\"socketTimeout\": 50\r\n\t\t\t},\r\n\t\t\t\"sjasmplus\": [\r\n\t\t\t\t{\r\n\t\t\t\t\t\"asm\": \"sjasmplus\",\r\n\t\t\t\t\t\"useFiles\": true,\r\n\t\t\t\t\t\"mainFile\": \"${fileDirname}/main.asm\",\r\n\t\t\t\t\t\"path\": \"${workspaceRoot}/build/test.sld\"\r\n\t\t\t\t}\r\n\t\t\t],\r\n\t\t\t\"history\": {\r\n\t\t\t\t\"reverseDebugInstructionCount\": 1000000,\r\n\t\t\t\t\"spotCount\": 10,\r\n\t\t\t},\r\n\t\t\t\"commandsAfterLaunch\": [\r\n\t\t\t\t\"-logpoint enable\",\r\n\t\t\t\t\"-wpmem enable\",\r\n\t\t\t\t//\"-sprites\",\r\n\t\t\t\t//\"-patterns\",\r\n\t\t\t],\r\n\t\t\t\"disassemblerArgs\": {\r\n\t\t\t\t\"esxdosRst\": true\r\n\t\t\t},\r\n\t\t\t// \"topOfStack\": \"stack_top\",\r\n\t\t\t\"startAutomatically\": false,\r\n\t\t\t\"preLaunchTask\": \"Build\",\r\n\t\t\t\"rootFolder\": \"${workspaceFolder}\",\r\n\t\t\t\"load\": \"${workspaceRoot}/build/test.nex\",\r\n\t\t\t\"smallValuesMaximum\": 513,\r\n\t\t\t\"tmpDir\": \".tmp\"\r\n\t\t},\r\n\r\n\t\t{\r\n\t\t\t\"type\": \"dezog\",\r\n\t\t\t\"request\": \"launch\",\r\n\t\t\t\"name\": \"ZXNext\",\r\n\t\t\t\"remoteType\": \"zxnext\",\r\n\t\t\t\"zxnext\": {\r\n\t\t\t\t//\"port\": 13000,\r\n\t\t\t},\r\n\t\t\t\"sjasmplus\": [\r\n\t\t\t\t{\r\n\t\t\t\t\t\"asm\": \"sjasmplus\",\r\n\t\t\t\t\t\"useFiles\": true,\r\n\t\t\t\t\t\"mainFile\": \"${fileDirname}/main.asm\",\r\n\t\t\t\t\t\"path\": \"${workspaceRoot}/build/test.sld\"\r\n\t\t\t\t}\r\n\t\t\t],\r\n\t\t\t\"history\": {\r\n\t\t\t\t\"reverseDebugInstructionCount\": 1000000,\r\n\t\t\t\t\"spotCount\": 10\r\n\t\t\t},\r\n\t\t\t\"commandsAfterLaunch\": [\r\n\t\t\t\t\"-logpoint enable\",\r\n\t\t\t\t\"-assert enable\",\r\n\t\t\t],\r\n\t\t\t\"disassemblerArgs\": {\r\n\t\t\t\t\"esxdosRst\": true\r\n\t\t\t},\r\n\t\t\t\"topOfStack\": \"stack_top\",\r\n\t\t\t\"startAutomatically\": false,\r\n\t\t\t\"preLaunchTask\": \"Build\",\r\n\t\t\t\"rootFolder\": \"${workspaceFolder}\",\r\n\t\t\t\"load\": \"${workspaceRoot}/build/${fileBasenameNoExtension}.nex\",\r\n\t\t\t\"smallValuesMaximum\": 513,\r\n\t\t\t\"tmpDir\": \".tmp\"\r\n\t\t},\r\n\t]\r\n}"
  },
  {
    "path": "samples/im2/.vscode/tasks.json",
    "content": "{\n\t\"version\": \"2.0.0\",\n\t\"tasks\": [\n\t\t{\n\t\t\t\"label\": \"Build\",\n\t\t\t\"type\": \"shell\",\n\t\t\t\"command\": \"${workspaceRoot}/../Tools/sjasmplus/sjasmplus.exe\",\n\t\t\t\"args\": [\n\t\t\t\t\"--sld=${workspaceRoot}/build/test.sld\",\n\t\t\t\t\"--sym=${workspaceRoot}/build/test.labels\",\n\t\t\t\t\"--fullpath\",\n\t\t\t\t\"main.asm\"\n\t\t\t],\n\t\t\t\"problemMatcher\": {\n\t\t\t\t\"fileLocation\": [\n\t\t\t\t\t\"relative\",\n\t\t\t\t\t\"${workspaceRoot}\"\n\t\t\t\t],\n\t\t\t\t\"pattern\": {\n\t\t\t\t\t\"regexp\": \"^(.*)\\\\((\\\\d+)\\\\):\\\\s+(warning|error):\\\\s+(.*)$\",\n\t\t\t\t\t\"file\": 1,\n\t\t\t\t\t\"line\": 2,\n\t\t\t\t\t\"severity\": 3,\n\t\t\t\t\t\"message\": 4\n\t\t\t\t}\n\t\t\t},\n\t\t\t\"group\": {\n\t\t\t\t\"kind\": \"build\",\n\t\t\t\t\"isDefault\": true\n\t\t\t}\n\t\t},\n\n\t\t{\n\t\t\t\"label\": \"Launch ZEsarUX\",\n\t\t\t\"type\": \"shell\",\n\t\t\t\"command\": \"${workspaceRoot}/../Tools/ZEsarUX/ZEsarUX.exe\",\n\t\t\t\"options\": {\n\t\t\t\t\"cwd\": \"${workspaceRoot}/../Tools/ZEsarUX\"\n\t\t\t}\n\t\t},\n\n\t\t{\n\t\t\t\"label\": \"Launch CSpect\",\n\t\t\t\"type\": \"shell\",\n\t\t\t\"command\": \"${workspaceRoot}/../Tools/CSpect/CSpect.exe -debug -exit -brk -sound -tv -esc -zxnext -nextrom -mmc=./cspect-next-2gb.img > output.log\",\n\t\t\t\"options\": {\n\t\t\t\t\"cwd\": \"${workspaceRoot}/../Tools/CSpect\"\n\t\t\t}\n\t\t}\n\t]\n}\n"
  },
  {
    "path": "samples/im2/build/.gitignore",
    "content": "# Ignore everything in this directory\r\n*\r\n# Except this file\r\n!.gitignore"
  },
  {
    "path": "samples/im2/main.asm",
    "content": ";;--------------------------------------------------------------------\r\n;; sjasmplus setup\r\n;;--------------------------------------------------------------------\r\n\r\n\t; Allow Next paging and instructions\r\n\tDEVICE ZXSPECTRUMNEXT\r\n\tSLDOPT COMMENT WPMEM, LOGPOINT, ASSERTION\r\n\r\n\t; Generate a map file for use with Cspect\r\n\tCSPECTMAP \"build/test.map\"\r\n\r\n\r\n;;--------------------------------------------------------------------\r\n;; program\r\n;;--------------------------------------------------------------------\r\n\r\n\t; Main program will start at $8000\r\n\tORG $8000\r\nStart:\r\n\t; Try different CPU speeds (0-3) - the faster the CPU, the faster out main loop will be, therefore interrupt will occur less times and counter will not change so much between each iteration.\r\n\tNEXTREG $07, 3\r\n\r\n\t; Disable interrupts while we're preparing for IM2, just in case to prevent one being triggered in the middle.\r\n\tDI\r\n\r\n\t; Setup interrupt vector table.\r\n\tCALL SetupInterruptVectors\r\n\r\n\t; Enable IM2; this will disable IM1 and use our `InterruptHandler`.\r\n\tIM 2\r\n\r\n\t; We're done with setup, enable interrupts now and let the fun begin...\r\n\tEI\r\n\r\n\t; At this point we'll start infinite loop in our main routine. The only thing it will do is read the value of the counter into A (that our interrupt handler is incrementing). You can inspect the value in debugger.\r\n.loop:\r\n\tCALL WaitALittleBitLonger\r\n\tLD HL, counter\r\n\tLD A, (HL)\r\n\r\n\t; You can set breakpoint on the following line and inspect A to see how it changes.\r\n\tJP .loop\r\n\r\n\t; Return from main routine (will never occur in our case)\r\n\tRET\r\n\r\n; Waiting routine; just chilling out, doing nothing for a while :)\r\nWaitAWhile:\r\n\tLD B, $FF\r\n.loop:\tNOP\r\n\tNOP\r\n\tNOP\r\n\tNOP\r\n\tDJNZ .loop\r\n\tRET\r\n\r\n; A longer delay...\r\nWaitALittleBitLonger:\r\n\tLD C, $40\r\n.loop:\tCALL WaitAWhile\r\n\tDEC C\r\n\tJP NZ, .loop\r\n\tRET\r\n\r\n\r\n; Counter variable\r\ncounter:\r\n\tDB 0\r\n\r\n\r\n;;--------------------------------------------------------------------\r\n;; interrupt handler\r\n;;--------------------------------------------------------------------\r\n\r\n; The interrupt handler itself; it can be anywhere in the memory.\r\nInterruptHandler:\r\n\t; Note: ideally we'd be exchanging registers here so they would be preserved when interrupts returns. But for this simple example, it'll do.\r\n\r\n\t; Load address of our counter and increment it\r\n\tLD HL, counter\r\n\tINC (HL)\r\n\r\n\t; Re-enable interrupts (note we don't have to call DI, system will do it for us)\r\n\tEI\r\n\r\n\t; Return from interrupt!\r\n\tRETI\r\n\r\n;;--------------------------------------------------------------------\r\n;; interrupt vector table\r\n;;--------------------------------------------------------------------\r\n\r\n; Sets up the interrupt vectors to point to interrupt handler.\r\n; Returns most significant byte of vector table address in I register\r\nSetupInterruptVectors:\r\n\t; DE points to interrupt routine handler itself; we'll fill this address into the vector table.\r\n\tLD DE, InterruptHandler\r\n\r\n\t; HL points to interrupt vectors table we'll fill in.\r\n\tLD HL, InterruptVectorTable\r\n\r\n\t; Vector table contains 128 16-bit entries, each one points to the same routine which address we copied to DE register pair previously.\r\n\tLD B, 128\r\n.loop:\r\n\tLD (HL), E\t; Copy low byte\r\n\tINC HL\r\n\tLD (HL), D\t; Copy high byte\r\n\tINC HL\r\n\tDJNZ .loop\r\n\r\n\t; Prepare I register to point to MSB of the vector table.\r\n\tLD A, InterruptVectorTable >> 8\r\n\tLD I, A\r\n\r\n\tRET\r\n\r\n\t; 128 entry vector table must start on 256 byte boundary $xx00, each entry 16-bit address pointing to our interrupt vector. For this example we put it towards the end of the addressable memory.\r\n\t.ALIGN 256\r\nInterruptVectorTable:\r\n\tDEFS 128*2\t; 128 16-bit vectors\r\n\r\n\r\n;;--------------------------------------------------------------------\r\n;; Set up .nex output\r\n;;--------------------------------------------------------------------\r\n\r\n\t; This sets the name of the project, the start address, \r\n\t; and the initial stack pointer.\r\n\tSAVENEX OPEN \"build/test.nex\", Start, $ff40\r\n\r\n\t; This asserts the minimum core version.  Set it to the core version \r\n\t; you are developing on.\r\n\tSAVENEX CORE 2, 0, 0\r\n\r\n\t; This sets the border colour while loading (in this case white),\r\n\t; what to do with the file handle of the nex file when starting (0 = \r\n\t; close file handle as we're not going to access the project.nex \r\n\t; file after starting.  See sjasmplus documentation), whether\r\n\t; we preserve the next registers (0 = no, we set to default), and \r\n\t; whether we require the full 2MB expansion (0 = no we don't).\r\n\tSAVENEX CFG 7, 0, 0, 0\r\n\r\n\t; Generate the Nex file automatically based on which pages you use.\r\n\tSAVENEX AUTO\r\n\r\n"
  },
  {
    "path": "samples/im2hw/.vscode/launch.json",
    "content": "{\r\n\t// Use IntelliSense to learn about possible attributes.\r\n\t// Hover to view descriptions of existing attributes.\r\n\t// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387\r\n\t\"version\": \"0.2.0\",\r\n\t\"configurations\": [\r\n\t\t{\r\n\t\t\t\"type\": \"dezog\",\r\n\t\t\t\"request\": \"launch\",\r\n\t\t\t\"name\": \"CSpect\",\r\n\t\t\t\"remoteType\": \"cspect\",\r\n\t\t\t\"cspect\": {\r\n\t\t\t\t\"port\": 13000,\r\n\t\t\t},\r\n\t\t\t\"sjasmplus\": [\r\n\t\t\t\t{\r\n\t\t\t\t\t\"asm\": \"sjasmplus\",\r\n\t\t\t\t\t\"useFiles\": true,\r\n\t\t\t\t\t\"mainFile\": \"${fileDirname}/main.asm\",\r\n\t\t\t\t\t\"path\": \"${workspaceRoot}/build/test.sld\"\r\n\t\t\t\t}\r\n\t\t\t],\r\n\t\t\t\"history\": {\r\n\t\t\t\t\"reverseDebugInstructionCount\": 1000000,\r\n\t\t\t\t\"spotCount\": 10,\r\n\t\t\t},\r\n\t\t\t\"commandsAfterLaunch\": [\r\n\t\t\t\t\"-logpoint enable\",\r\n\t\t\t\t//\"-wpmem enable\",\r\n\t\t\t\t//\"-sprites\",\r\n\t\t\t\t//\"-patterns\",\r\n\t\t\t],\r\n\t\t\t\"disassemblerArgs\": {\r\n\t\t\t\t\"esxdosRst\": true\r\n\t\t\t},\r\n\t\t\t// \"topOfStack\": \"stack_top\",\r\n\t\t\t\"startAutomatically\": false,\r\n\t\t\t\"preLaunchTask\": \"Build\",\r\n\t\t\t\"rootFolder\": \"${workspaceFolder}\",\r\n\t\t\t\"load\": \"${workspaceRoot}/build/test.nex\",\r\n\t\t\t\"smallValuesMaximum\": 513,\r\n\t\t\t\"tmpDir\": \".tmp\"\r\n\t\t},\r\n\r\n\t\t{\r\n\t\t\t\"type\": \"dezog\",\r\n\t\t\t\"request\": \"launch\",\r\n\t\t\t\"name\": \"ZEsarUX\",\r\n\t\t\t\"remoteType\": \"zrcp\",\r\n\t\t\t\"zrcp\": {\r\n\t\t\t\t\"hostname\": \"localhost\",\r\n\t\t\t\t\"port\": 10000,\r\n\t\t\t\t\"loadDelay\": 700,\r\n\t\t\t\t\"skipInterrupt\": true,\r\n\t\t\t\t//\"socketTimeout\": 50\r\n\t\t\t},\r\n\t\t\t\"sjasmplus\": [\r\n\t\t\t\t{\r\n\t\t\t\t\t\"asm\": \"sjasmplus\",\r\n\t\t\t\t\t\"useFiles\": true,\r\n\t\t\t\t\t\"mainFile\": \"${fileDirname}/main.asm\",\r\n\t\t\t\t\t\"path\": \"${workspaceRoot}/build/test.sld\"\r\n\t\t\t\t}\r\n\t\t\t],\r\n\t\t\t\"history\": {\r\n\t\t\t\t\"reverseDebugInstructionCount\": 1000000,\r\n\t\t\t\t\"spotCount\": 10,\r\n\t\t\t},\r\n\t\t\t\"commandsAfterLaunch\": [\r\n\t\t\t\t\"-logpoint enable\",\r\n\t\t\t\t\"-wpmem enable\",\r\n\t\t\t\t//\"-sprites\",\r\n\t\t\t\t//\"-patterns\",\r\n\t\t\t],\r\n\t\t\t\"disassemblerArgs\": {\r\n\t\t\t\t\"esxdosRst\": true\r\n\t\t\t},\r\n\t\t\t// \"topOfStack\": \"stack_top\",\r\n\t\t\t\"startAutomatically\": false,\r\n\t\t\t\"preLaunchTask\": \"Build\",\r\n\t\t\t\"rootFolder\": \"${workspaceFolder}\",\r\n\t\t\t\"load\": \"${workspaceRoot}/build/test.nex\",\r\n\t\t\t\"smallValuesMaximum\": 513,\r\n\t\t\t\"tmpDir\": \".tmp\"\r\n\t\t},\r\n\r\n\t\t{\r\n\t\t\t\"type\": \"dezog\",\r\n\t\t\t\"request\": \"launch\",\r\n\t\t\t\"name\": \"ZXNext\",\r\n\t\t\t\"remoteType\": \"zxnext\",\r\n\t\t\t\"zxnext\": {\r\n\t\t\t\t//\"port\": 13000,\r\n\t\t\t},\r\n\t\t\t\"sjasmplus\": [\r\n\t\t\t\t{\r\n\t\t\t\t\t\"asm\": \"sjasmplus\",\r\n\t\t\t\t\t\"useFiles\": true,\r\n\t\t\t\t\t\"mainFile\": \"${fileDirname}/main.asm\",\r\n\t\t\t\t\t\"path\": \"${workspaceRoot}/build/test.sld\"\r\n\t\t\t\t}\r\n\t\t\t],\r\n\t\t\t\"history\": {\r\n\t\t\t\t\"reverseDebugInstructionCount\": 1000000,\r\n\t\t\t\t\"spotCount\": 10\r\n\t\t\t},\r\n\t\t\t\"commandsAfterLaunch\": [\r\n\t\t\t\t\"-logpoint enable\",\r\n\t\t\t\t\"-assert enable\",\r\n\t\t\t],\r\n\t\t\t\"disassemblerArgs\": {\r\n\t\t\t\t\"esxdosRst\": true\r\n\t\t\t},\r\n\t\t\t\"topOfStack\": \"stack_top\",\r\n\t\t\t\"startAutomatically\": false,\r\n\t\t\t\"preLaunchTask\": \"Build\",\r\n\t\t\t\"rootFolder\": \"${workspaceFolder}\",\r\n\t\t\t\"load\": \"${workspaceRoot}/build/${fileBasenameNoExtension}.nex\",\r\n\t\t\t\"smallValuesMaximum\": 513,\r\n\t\t\t\"tmpDir\": \".tmp\"\r\n\t\t},\r\n\t]\r\n}"
  },
  {
    "path": "samples/im2hw/.vscode/tasks.json",
    "content": "{\n\t\"version\": \"2.0.0\",\n\t\"tasks\": [\n\t\t{\n\t\t\t\"label\": \"Build\",\n\t\t\t\"type\": \"shell\",\n\t\t\t\"command\": \"${workspaceRoot}/../Tools/sjasmplus/sjasmplus.exe\",\n\t\t\t\"args\": [\n\t\t\t\t\"--sld=${workspaceRoot}/build/test.sld\",\n\t\t\t\t\"--sym=${workspaceRoot}/build/test.labels\",\n\t\t\t\t\"--fullpath\",\n\t\t\t\t\"main.asm\"\n\t\t\t],\n\t\t\t\"problemMatcher\": {\n\t\t\t\t\"fileLocation\": [\n\t\t\t\t\t\"relative\",\n\t\t\t\t\t\"${workspaceRoot}\"\n\t\t\t\t],\n\t\t\t\t\"pattern\": {\n\t\t\t\t\t\"regexp\": \"^(.*)\\\\((\\\\d+)\\\\):\\\\s+(warning|error):\\\\s+(.*)$\",\n\t\t\t\t\t\"file\": 1,\n\t\t\t\t\t\"line\": 2,\n\t\t\t\t\t\"severity\": 3,\n\t\t\t\t\t\"message\": 4\n\t\t\t\t}\n\t\t\t},\n\t\t\t\"group\": {\n\t\t\t\t\"kind\": \"build\",\n\t\t\t\t\"isDefault\": true\n\t\t\t}\n\t\t},\n\n\t\t{\n\t\t\t\"label\": \"Launch ZEsarUX\",\n\t\t\t\"type\": \"shell\",\n\t\t\t\"command\": \"${workspaceRoot}/../Tools/ZEsarUX/ZEsarUX.exe\",\n\t\t\t\"options\": {\n\t\t\t\t\"cwd\": \"${workspaceRoot}/../Tools/ZEsarUX\"\n\t\t\t}\n\t\t},\n\n\t\t{\n\t\t\t\"label\": \"Launch CSpect\",\n\t\t\t\"type\": \"shell\",\n\t\t\t\"command\": \"${workspaceRoot}/../Tools/CSpect/CSpect.exe -debug -exit -brk -sound -tv -esc -zxnext -nextrom -mmc=./cspect-next-2gb.img > output.log\",\n\t\t\t\"options\": {\n\t\t\t\t\"cwd\": \"${workspaceRoot}/../Tools/CSpect\"\n\t\t\t}\n\t\t}\n\t]\n}\n"
  },
  {
    "path": "samples/im2hw/build/.gitignore",
    "content": "# Ignore everything in this directory\r\n*\r\n# Except this file\r\n!.gitignore"
  },
  {
    "path": "samples/im2hw/main.asm",
    "content": ";;--------------------------------------------------------------------\r\n;; sjasmplus setup\r\n;;--------------------------------------------------------------------\r\n\r\n\t; Allow Next paging and instructions\r\n\tDEVICE ZXSPECTRUMNEXT\r\n\tSLDOPT COMMENT WPMEM, LOGPOINT, ASSERTION\r\n\r\n\t; Generate a map file for use with Cspect\r\n\tCSPECTMAP \"build/test.map\"\r\n\r\n;;--------------------------------------------------------------------\r\n;; program\r\n;;--------------------------------------------------------------------\r\n\r\n\t; Main program will start at $8000\r\n\tORG $8000\r\nStart:\r\n\t; Try different CPU speeds (0-3) - the faster the CPU, the faster out main loop will be, therefore interrupt will occur less times and counter will not change so much between each iteration.\r\n\tNEXTREG $07, 3\r\n\r\n\t; Disable interrupts while we're preparing for IM2, just in case to prevent one being triggered in the middle.\r\n\tDI\r\n\r\n\t; Prepare programmable portion of IM2 vector in bits 7-5 and enable IM2 mode in bit 0\r\n\t; Because we use .ALIGN 32, interrupt table already uses top 3 bits of LSB only, so we don't have to and with %11100000. But we do need to and with \"something\" in order to suppress assembler warning (vector table is 16-bit address while we need 8-bit value, so it warns us about potential data loss). We do need to set bit 0 though to enable IM2 mode!\r\n\tNEXTREG $C0, (InterruptVectorTable & %11100000) | %00000001\r\n\r\n\t; Enable expansion bus /INT (bit 7) and ULA interrupts (bit 0)\r\n\tNEXTREG $C4, %10000001\r\n\r\n\t; Disable all CTC channel interrupts\r\n\tNEXTREG $C5, %00000000\r\n\r\n\t; Disable UART0 and UART1 interrupts.\r\n\tNEXTREG $C6, %00000000\r\n\r\n\t; Prepare I register to point to MSB of the vector table. This is the same as with legacy IM2.\r\n\tLD A, InterruptVectorTable >> 8\t; prepare high byte for vector table...\r\n\tLD I, A\t\t\t\t; ...and copy it over to I\r\n\r\n\t; Enable IM2; since we switched hardware IM2 mode with nextreg $C0 above, we are in fact enabling that mode, therefore we don't need the legacy IM2 vector table.\r\n\tIM 2\r\n\r\n\t; We're done with setup, enable interrupts now and let the fun begin...\r\n\tEI\r\n\r\n\t; At this point we'll start infinite loop in our main routine. The only thing it will do is read the value of the counter into A (that our interrupt handler is incrementing). You can inspect the value in debugger.\r\n.loop:\r\n\tCALL WaitALittleBitLonger\r\n\tLD HL, counter\r\n\tLD A, (HL)\r\n\r\n\t; You can set breakpoint on the following line and inspect A to see how it changes.\r\n\tJP .loop\r\n\r\n\t; Return from main routine (will never occur in our case)\r\n\tRET\r\n\r\n; Waiting routine; just chilling out, doing nothing for a while :)\r\nWaitAWhile:\r\n\tLD B, $FF\r\n.loop:\tNOP\r\n\tNOP\r\n\tNOP\r\n\tNOP\r\n\tDJNZ .loop\r\n\tRET\r\n\r\n; A longer delay...\r\nWaitALittleBitLonger:\r\n\tLD C, $40\r\n.loop:\tCALL WaitAWhile\r\n\tDEC C\r\n\tJP NZ, .loop\r\n\tRET\r\n\r\n; Counter variable\r\ncounter:\r\n\tDB 0\r\n\r\n;;--------------------------------------------------------------------\r\n;; interrupt handler\r\n;;--------------------------------------------------------------------\r\n\r\nInterruptHandlerLine:\r\n\t; In line interrupt we reset line bit that indicates whether interrupt was generated or not. Then we process interrupt exactly the same as otherwise.\r\n\t; This is not needed for subsequent interrupts - they will be triggered again regardless of whether we do this or not. We can use it to determine whether the interrupt was triggered since last time.\r\n\tNEXTREG $C8, %00000010\r\n\tJP InterruptHandler\r\nInterruptHandlerULA:\r\n\t; In ULA interrupt we reset ULA bit that indicates whether interrupt was generated or not. Then we process interrupt exactly the same as otherwise.\r\n\t; This is not needed for subsequent interrupts - they will be triggered again regardless of whether we do this or not. We can use it to determine whether the interrupt was triggered since last time.\r\n\tNEXTREG $C8, %00000001\r\nInterruptHandlerCTC:\r\nInterruptHandler:\r\n\t; Save registers.\r\n\tEX AF, AF'\r\n\tEXX\r\n\r\n\t; Load address of our counter and increment it\r\n\tLD HL, counter\r\n\tINC (HL)\r\n\r\n\t; Restore registers.\r\n\tEXX\r\n\tEX AF, AF'\r\n\r\n\t; Re-enable interrupts (note we don't have to call DI, system will do it for us)\r\n\tEI\r\n\r\n\t; Return from interrupt!\r\n\tRETI\r\n\r\n;;--------------------------------------------------------------------\r\n;; vector table\r\n;;--------------------------------------------------------------------\r\n\r\n\t; Vector table must be aligned to %xxxxxxxx %xxx00000 address.\r\n\t.ALIGN 32\r\nInterruptVectorTable:\r\n\t; Note: I setup different interrupt vectors only to demonstrate we can have multiple handlers. In this example they all point to the same interrupt routine so all could be the same (apart from line and ULA which indeed execute additional commands).\r\n\tDW InterruptHandlerLine\t; 0 = line interrupt (highest priority)\r\n\tDW InterruptHandler\t; 1 = UART0 Rx\r\n\tDW InterruptHandler\t; 2 = UART1 Rx\r\n\tDW InterruptHandlerCTC\t; 3 = CTC channel 0\r\n\tDW InterruptHandlerCTC\t; 4 = CTC channel 1\r\n\tDW InterruptHandlerCTC\t; 5 = CTC channel 2\r\n\tDW InterruptHandlerCTC\t; 6 = CTC channel 3\r\n\tDW InterruptHandlerCTC\t; 7 = CTC channel 4\r\n\tDW InterruptHandlerCTC\t; 8 = CTC channel 5\r\n\tDW InterruptHandlerCTC\t; 9 = CTC channel 6\r\n\tDW InterruptHandlerCTC\t; 10 = CTC channel 7\r\n\tDW InterruptHandlerULA\t; 11 = ULA\r\n\tDW InterruptHandler\t; 12 = UART0 Tx\r\n\tDW InterruptHandler\t; 13 = UART1 Tx (lowest priority)\r\n\t; Not sure if the following 2 vectors are needed - I only counted 14 interrupters!? It just felt awkward to only have 14 instead of \"rounded\" 16... ¯\\_(ツ)_/¯\r\n\tDW InterruptHandler\r\n\tDW InterruptHandler\r\n\r\n;;--------------------------------------------------------------------\r\n;; Set up .nex output\r\n;;--------------------------------------------------------------------\r\n\r\n\t; This sets the name of the project, the start address, \r\n\t; and the initial stack pointer.\r\n\tSAVENEX OPEN \"build/test.nex\", Start, $ff40\r\n\r\n\t; This asserts the minimum core version.  Set it to the core version \r\n\t; you are developing on.\r\n\tSAVENEX CORE 2, 0, 0\r\n\r\n\t; This sets the border colour while loading (in this case white),\r\n\t; what to do with the file handle of the nex file when starting (0 = \r\n\t; close file handle as we're not going to access the project.nex \r\n\t; file after starting.  See sjasmplus documentation), whether\r\n\t; we preserve the next registers (0 = no, we set to default), and \r\n\t; whether we require the full 2MB expansion (0 = no we don't).\r\n\tSAVENEX CFG 7, 0, 0, 0\r\n\r\n\t; Generate the Nex file automatically based on which pages you use.\r\n\tSAVENEX AUTO\r\n\r\n"
  },
  {
    "path": "samples/im2safe/.vscode/launch.json",
    "content": "{\r\n\t// Use IntelliSense to learn about possible attributes.\r\n\t// Hover to view descriptions of existing attributes.\r\n\t// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387\r\n\t\"version\": \"0.2.0\",\r\n\t\"configurations\": [\r\n\t\t{\r\n\t\t\t\"type\": \"dezog\",\r\n\t\t\t\"request\": \"launch\",\r\n\t\t\t\"name\": \"CSpect\",\r\n\t\t\t\"remoteType\": \"cspect\",\r\n\t\t\t\"cspect\": {\r\n\t\t\t\t\"port\": 13000,\r\n\t\t\t},\r\n\t\t\t\"sjasmplus\": [\r\n\t\t\t\t{\r\n\t\t\t\t\t\"asm\": \"sjasmplus\",\r\n\t\t\t\t\t\"useFiles\": true,\r\n\t\t\t\t\t\"mainFile\": \"${fileDirname}/main.asm\",\r\n\t\t\t\t\t\"path\": \"${workspaceRoot}/build/test.sld\"\r\n\t\t\t\t}\r\n\t\t\t],\r\n\t\t\t\"history\": {\r\n\t\t\t\t\"reverseDebugInstructionCount\": 1000000,\r\n\t\t\t\t\"spotCount\": 10,\r\n\t\t\t},\r\n\t\t\t\"commandsAfterLaunch\": [\r\n\t\t\t\t\"-logpoint enable\",\r\n\t\t\t\t//\"-wpmem enable\",\r\n\t\t\t\t//\"-sprites\",\r\n\t\t\t\t//\"-patterns\",\r\n\t\t\t],\r\n\t\t\t\"disassemblerArgs\": {\r\n\t\t\t\t\"esxdosRst\": true\r\n\t\t\t},\r\n\t\t\t// \"topOfStack\": \"stack_top\",\r\n\t\t\t\"startAutomatically\": false,\r\n\t\t\t\"preLaunchTask\": \"Build\",\r\n\t\t\t\"rootFolder\": \"${workspaceFolder}\",\r\n\t\t\t\"load\": \"${workspaceRoot}/build/test.nex\",\r\n\t\t\t\"smallValuesMaximum\": 513,\r\n\t\t\t\"tmpDir\": \".tmp\"\r\n\t\t},\r\n\r\n\t\t{\r\n\t\t\t\"type\": \"dezog\",\r\n\t\t\t\"request\": \"launch\",\r\n\t\t\t\"name\": \"ZEsarUX\",\r\n\t\t\t\"remoteType\": \"zrcp\",\r\n\t\t\t\"zrcp\": {\r\n\t\t\t\t\"hostname\": \"localhost\",\r\n\t\t\t\t\"port\": 10000,\r\n\t\t\t\t\"loadDelay\": 700,\r\n\t\t\t\t\"skipInterrupt\": true,\r\n\t\t\t\t//\"socketTimeout\": 50\r\n\t\t\t},\r\n\t\t\t\"sjasmplus\": [\r\n\t\t\t\t{\r\n\t\t\t\t\t\"asm\": \"sjasmplus\",\r\n\t\t\t\t\t\"useFiles\": true,\r\n\t\t\t\t\t\"mainFile\": \"${fileDirname}/main.asm\",\r\n\t\t\t\t\t\"path\": \"${workspaceRoot}/build/test.sld\"\r\n\t\t\t\t}\r\n\t\t\t],\r\n\t\t\t\"history\": {\r\n\t\t\t\t\"reverseDebugInstructionCount\": 1000000,\r\n\t\t\t\t\"spotCount\": 10,\r\n\t\t\t},\r\n\t\t\t\"commandsAfterLaunch\": [\r\n\t\t\t\t\"-logpoint enable\",\r\n\t\t\t\t\"-wpmem enable\",\r\n\t\t\t\t//\"-sprites\",\r\n\t\t\t\t//\"-patterns\",\r\n\t\t\t],\r\n\t\t\t\"disassemblerArgs\": {\r\n\t\t\t\t\"esxdosRst\": true\r\n\t\t\t},\r\n\t\t\t// \"topOfStack\": \"stack_top\",\r\n\t\t\t\"startAutomatically\": false,\r\n\t\t\t\"preLaunchTask\": \"Build\",\r\n\t\t\t\"rootFolder\": \"${workspaceFolder}\",\r\n\t\t\t\"load\": \"${workspaceRoot}/build/test.nex\",\r\n\t\t\t\"smallValuesMaximum\": 513,\r\n\t\t\t\"tmpDir\": \".tmp\"\r\n\t\t},\r\n\r\n\t\t{\r\n\t\t\t\"type\": \"dezog\",\r\n\t\t\t\"request\": \"launch\",\r\n\t\t\t\"name\": \"ZXNext\",\r\n\t\t\t\"remoteType\": \"zxnext\",\r\n\t\t\t\"zxnext\": {\r\n\t\t\t\t//\"port\": 13000,\r\n\t\t\t},\r\n\t\t\t\"sjasmplus\": [\r\n\t\t\t\t{\r\n\t\t\t\t\t\"asm\": \"sjasmplus\",\r\n\t\t\t\t\t\"useFiles\": true,\r\n\t\t\t\t\t\"mainFile\": \"${fileDirname}/main.asm\",\r\n\t\t\t\t\t\"path\": \"${workspaceRoot}/build/test.sld\"\r\n\t\t\t\t}\r\n\t\t\t],\r\n\t\t\t\"history\": {\r\n\t\t\t\t\"reverseDebugInstructionCount\": 1000000,\r\n\t\t\t\t\"spotCount\": 10\r\n\t\t\t},\r\n\t\t\t\"commandsAfterLaunch\": [\r\n\t\t\t\t\"-logpoint enable\",\r\n\t\t\t\t\"-assert enable\",\r\n\t\t\t],\r\n\t\t\t\"disassemblerArgs\": {\r\n\t\t\t\t\"esxdosRst\": true\r\n\t\t\t},\r\n\t\t\t\"topOfStack\": \"stack_top\",\r\n\t\t\t\"startAutomatically\": false,\r\n\t\t\t\"preLaunchTask\": \"Build\",\r\n\t\t\t\"rootFolder\": \"${workspaceFolder}\",\r\n\t\t\t\"load\": \"${workspaceRoot}/build/${fileBasenameNoExtension}.nex\",\r\n\t\t\t\"smallValuesMaximum\": 513,\r\n\t\t\t\"tmpDir\": \".tmp\"\r\n\t\t},\r\n\t]\r\n}"
  },
  {
    "path": "samples/im2safe/.vscode/tasks.json",
    "content": "{\n\t\"version\": \"2.0.0\",\n\t\"tasks\": [\n\t\t{\n\t\t\t\"label\": \"Build\",\n\t\t\t\"type\": \"shell\",\n\t\t\t\"command\": \"${workspaceRoot}/../Tools/sjasmplus/sjasmplus.exe\",\n\t\t\t\"args\": [\n\t\t\t\t\"--sld=${workspaceRoot}/build/test.sld\",\n\t\t\t\t\"--sym=${workspaceRoot}/build/test.labels\",\n\t\t\t\t\"--fullpath\",\n\t\t\t\t\"main.asm\"\n\t\t\t],\n\t\t\t\"problemMatcher\": {\n\t\t\t\t\"fileLocation\": [\n\t\t\t\t\t\"relative\",\n\t\t\t\t\t\"${workspaceRoot}\"\n\t\t\t\t],\n\t\t\t\t\"pattern\": {\n\t\t\t\t\t\"regexp\": \"^(.*)\\\\((\\\\d+)\\\\):\\\\s+(warning|error):\\\\s+(.*)$\",\n\t\t\t\t\t\"file\": 1,\n\t\t\t\t\t\"line\": 2,\n\t\t\t\t\t\"severity\": 3,\n\t\t\t\t\t\"message\": 4\n\t\t\t\t}\n\t\t\t},\n\t\t\t\"group\": {\n\t\t\t\t\"kind\": \"build\",\n\t\t\t\t\"isDefault\": true\n\t\t\t}\n\t\t},\n\n\t\t{\n\t\t\t\"label\": \"Launch ZEsarUX\",\n\t\t\t\"type\": \"shell\",\n\t\t\t\"command\": \"${workspaceRoot}/../Tools/ZEsarUX/ZEsarUX.exe\",\n\t\t\t\"options\": {\n\t\t\t\t\"cwd\": \"${workspaceRoot}/../Tools/ZEsarUX\"\n\t\t\t}\n\t\t},\n\n\t\t{\n\t\t\t\"label\": \"Launch CSpect\",\n\t\t\t\"type\": \"shell\",\n\t\t\t\"command\": \"${workspaceRoot}/../Tools/CSpect/CSpect.exe -debug -exit -brk -sound -tv -esc -zxnext -nextrom -mmc=./cspect-next-2gb.img > output.log\",\n\t\t\t\"options\": {\n\t\t\t\t\"cwd\": \"${workspaceRoot}/../Tools/CSpect\"\n\t\t\t}\n\t\t}\n\t]\n}\n"
  },
  {
    "path": "samples/im2safe/build/.gitignore",
    "content": "# Ignore everything in this directory\r\n*\r\n# Except this file\r\n!.gitignore"
  },
  {
    "path": "samples/im2safe/main.asm",
    "content": ";;--------------------------------------------------------------------\r\n;; sjasmplus setup\r\n;;--------------------------------------------------------------------\r\n\r\n\t; Allow Next paging and instructions\r\n\tDEVICE ZXSPECTRUMNEXT\r\n\tSLDOPT COMMENT WPMEM, LOGPOINT, ASSERTION\r\n\r\n\t; Generate a map file for use with Cspect\r\n\tCSPECTMAP \"build/test.map\"\r\n\r\n\r\n;;--------------------------------------------------------------------\r\n;; program\r\n;;--------------------------------------------------------------------\r\n\r\n\t; Main program will start at $8000\r\n\tORG $8000\r\nStart:\r\n\t; Try different CPU speeds (0-3) - the faster the CPU, the faster out main loop will be, therefore interrupt will occur less times and counter will not change so much between each iteration.\r\n\tNEXTREG $07, 3\r\n\r\n\t; Disable interrupts while we're preparing for IM2, just in case to prevent one being triggered in the middle.\r\n\tDI\r\n\r\n\t; Setup interrupt vector table.\r\n\tCALL SetupInterruptVectors\r\n\r\n\t; Enable IM2; this will disable IM1 and use our `InterruptHandler`.\r\n\tIM 2\r\n\r\n\t; We're done with setup, enable interrupts now and let the fun begin...\r\n\tEI\r\n\r\n\t; At this point we'll start infinite loop in our main routine. The only thing it will do is read the value of the counter into A (that our interrupt handler is incrementing). You can inspect the value in debugger.\r\n.loop:\r\n\tCALL WaitALittleBitLonger\r\n\tLD HL, counter\r\n\tLD A, (HL)\r\n\r\n\t; You can set breakpoint on the following line and inspect A to see how it changes.\r\n\tJP .loop\r\n\r\n\t; Return from main routine (will never occur in our case)\r\n\tRET\r\n\r\n; Waiting routine; just chilling out, doing nothing for a while :)\r\nWaitAWhile:\r\n\tLD B, $FF\r\n.loop:\tNOP\r\n\tNOP\r\n\tNOP\r\n\tNOP\r\n\tDJNZ .loop\r\n\tRET\r\n\r\n; A longer delay...\r\nWaitALittleBitLonger:\r\n\tLD C, $40\r\n.loop:\tCALL WaitAWhile\r\n\tDEC C\r\n\tJP NZ, .loop\r\n\tRET\r\n\r\n\r\n; Counter variable\r\ncounter:\r\n\tDB 0\r\n\r\n\r\n;;--------------------------------------------------------------------\r\n;; interrupt vector table\r\n;;--------------------------------------------------------------------\r\n\r\nSetupInterruptVectors:\r\n\t; Vector table contains 257 bytes, all the same value. So we can simply setup the first, then use LDIR to fill in the rest. Since our interrupt handler is now on address where both bytes are the same, we can retrieve one and use it as the value to fill in.\r\n\tLD A, InterruptHandler >> 8\r\n\r\n\t; Fill in the whole vector table with the interrupt handler address byte (remember, both, high and low, are the same value). We could hard code interrupt address with DEFS instruction below (\"DEFS 256, $F0\" in our case) and get rid of this setup code, but then we'd have interrupt routine address hard coded in two places, making it more prone to errors when changing.\r\n\tLD HL, InterruptVectorTable\t; source\r\n\tLD DE, InterruptVectorTable+1\t; destination\r\n\tLD BC, 256\t\t\t; 256+1 times (LDI first copies, then tests)\r\n\tLD (HL), A\t\t\t; Write the first byte...\r\n\tLDIR\t\t\t\t; ...and let LDIR copy it over the other 256\r\n\r\n\t; Prepare I register to point to MSB of the vector table.\r\n\tLD A, InterruptVectorTable >> 8\t; prepare high byte for vector table...\r\n\tLD I, A\t\t\t\t; ...and copy it over to I\r\n\r\n\tRET\r\n\r\n\t; 128 entry vector table must start on 256 byte boundary $xx00, each entry 16-bit address pointing to our interrupt vector. We also add additional byte at the end in case bus will hold $FF (which means we can't use $FF00 as we'll overflow!)\r\n\t.ALIGN 256\r\nInterruptVectorTable:\r\n\tDEFS 257\t; 257 bytes are needed this time, in case data bus returns $FF. Note we could also do \"DEFS 257, $F0\" but then changes to interrupt handler will also need to be made here.\r\n\r\n\r\n;;--------------------------------------------------------------------\r\n;; interrupt handler\r\n;;--------------------------------------------------------------------\r\n\r\n\t; The interrupt handler itself; we must have it at exact address this time - both bytes must be equal. Then we can setup vector table with this byte only and it will jump to this interrupt handler regardless of whether it reads vector from odd or even byte in the table!\r\n\tORG $F0F0\r\nInterruptHandler:\r\n\t; Note: ideally we'd be exchanging registers here so they would be preserved when interrupts returns. But for this simple example, it'll do.\r\n\r\n\t; Load address of our counter and increment it\r\n\tLD HL, counter\r\n\tINC (HL)\r\n\r\n\t; Re-enable interrupts (note we don't have to call DI, system will do it for us)\r\n\tEI\r\n\r\n\t; Return from interrupt!\r\n\tRETI\r\n\r\n\r\n;;--------------------------------------------------------------------\r\n;; Set up .nex output\r\n;;--------------------------------------------------------------------\r\n\r\n\t; This sets the name of the project, the start address, \r\n\t; and the initial stack pointer.\r\n\tSAVENEX OPEN \"build/test.nex\", Start, $ff40\r\n\r\n\t; This asserts the minimum core version.  Set it to the core version \r\n\t; you are developing on.\r\n\tSAVENEX CORE 2, 0, 0\r\n\r\n\t; This sets the border colour while loading (in this case white),\r\n\t; what to do with the file handle of the nex file when starting (0 = \r\n\t; close file handle as we're not going to access the project.nex \r\n\t; file after starting.  See sjasmplus documentation), whether\r\n\t; we preserve the next registers (0 = no, we set to default), and \r\n\t; whether we require the full 2MB expansion (0 = no we don't).\r\n\tSAVENEX CFG 7, 0, 0, 0\r\n\r\n\t; Generate the Nex file automatically based on which pages you use.\r\n\tSAVENEX AUTO\r\n\r\n"
  },
  {
    "path": "samples/layer2-256x192/.vscode/launch.json",
    "content": "{\r\n\t// Use IntelliSense to learn about possible attributes.\r\n\t// Hover to view descriptions of existing attributes.\r\n\t// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387\r\n\t\"version\": \"0.2.0\",\r\n\t\"configurations\": [\r\n\t\t{\r\n\t\t\t\"type\": \"dezog\",\r\n\t\t\t\"request\": \"launch\",\r\n\t\t\t\"name\": \"CSpect\",\r\n\t\t\t\"remoteType\": \"cspect\",\r\n\t\t\t\"cspect\": {\r\n\t\t\t\t\"port\": 13000,\r\n\t\t\t},\r\n\t\t\t\"sjasmplus\": [\r\n\t\t\t\t{\r\n\t\t\t\t\t\"asm\": \"sjasmplus\",\r\n\t\t\t\t\t\"useFiles\": true,\r\n\t\t\t\t\t\"mainFile\": \"${fileDirname}/main.asm\",\r\n\t\t\t\t\t\"path\": \"${workspaceRoot}/build/test.sld\"\r\n\t\t\t\t}\r\n\t\t\t],\r\n\t\t\t\"history\": {\r\n\t\t\t\t\"reverseDebugInstructionCount\": 1000000,\r\n\t\t\t\t\"spotCount\": 10,\r\n\t\t\t},\r\n\t\t\t\"commandsAfterLaunch\": [\r\n\t\t\t\t\"-logpoint enable\",\r\n\t\t\t\t//\"-wpmem enable\",\r\n\t\t\t\t//\"-sprites\",\r\n\t\t\t\t//\"-patterns\",\r\n\t\t\t],\r\n\t\t\t\"disassemblerArgs\": {\r\n\t\t\t\t\"esxdosRst\": true\r\n\t\t\t},\r\n\t\t\t// \"topOfStack\": \"stack_top\",\r\n\t\t\t\"startAutomatically\": false,\r\n\t\t\t\"preLaunchTask\": \"Build\",\r\n\t\t\t\"rootFolder\": \"${workspaceFolder}\",\r\n\t\t\t\"load\": \"${workspaceRoot}/build/test.nex\",\r\n\t\t\t\"smallValuesMaximum\": 513,\r\n\t\t\t\"tmpDir\": \".tmp\"\r\n\t\t},\r\n\r\n\t\t{\r\n\t\t\t\"type\": \"dezog\",\r\n\t\t\t\"request\": \"launch\",\r\n\t\t\t\"name\": \"ZEsarUX\",\r\n\t\t\t\"remoteType\": \"zrcp\",\r\n\t\t\t\"zrcp\": {\r\n\t\t\t\t\"hostname\": \"localhost\",\r\n\t\t\t\t\"port\": 10000,\r\n\t\t\t\t\"loadDelay\": 700,\r\n\t\t\t\t\"skipInterrupt\": true,\r\n\t\t\t\t//\"socketTimeout\": 50\r\n\t\t\t},\r\n\t\t\t\"sjasmplus\": [\r\n\t\t\t\t{\r\n\t\t\t\t\t\"asm\": \"sjasmplus\",\r\n\t\t\t\t\t\"useFiles\": true,\r\n\t\t\t\t\t\"mainFile\": \"${fileDirname}/main.asm\",\r\n\t\t\t\t\t\"path\": \"${workspaceRoot}/build/test.sld\"\r\n\t\t\t\t}\r\n\t\t\t],\r\n\t\t\t\"history\": {\r\n\t\t\t\t\"reverseDebugInstructionCount\": 1000000,\r\n\t\t\t\t\"spotCount\": 10,\r\n\t\t\t},\r\n\t\t\t\"commandsAfterLaunch\": [\r\n\t\t\t\t\"-logpoint enable\",\r\n\t\t\t\t\"-wpmem enable\",\r\n\t\t\t\t//\"-sprites\",\r\n\t\t\t\t//\"-patterns\",\r\n\t\t\t],\r\n\t\t\t\"disassemblerArgs\": {\r\n\t\t\t\t\"esxdosRst\": true\r\n\t\t\t},\r\n\t\t\t// \"topOfStack\": \"stack_top\",\r\n\t\t\t\"startAutomatically\": false,\r\n\t\t\t\"preLaunchTask\": \"Build\",\r\n\t\t\t\"rootFolder\": \"${workspaceFolder}\",\r\n\t\t\t\"load\": \"${workspaceRoot}/build/test.nex\",\r\n\t\t\t\"smallValuesMaximum\": 513,\r\n\t\t\t\"tmpDir\": \".tmp\"\r\n\t\t},\r\n\r\n\t\t{\r\n\t\t\t\"type\": \"dezog\",\r\n\t\t\t\"request\": \"launch\",\r\n\t\t\t\"name\": \"ZXNext\",\r\n\t\t\t\"remoteType\": \"zxnext\",\r\n\t\t\t\"zxnext\": {\r\n\t\t\t\t//\"port\": 13000,\r\n\t\t\t},\r\n\t\t\t\"sjasmplus\": [\r\n\t\t\t\t{\r\n\t\t\t\t\t\"asm\": \"sjasmplus\",\r\n\t\t\t\t\t\"useFiles\": true,\r\n\t\t\t\t\t\"mainFile\": \"${fileDirname}/main.asm\",\r\n\t\t\t\t\t\"path\": \"${workspaceRoot}/build/test.sld\"\r\n\t\t\t\t}\r\n\t\t\t],\r\n\t\t\t\"history\": {\r\n\t\t\t\t\"reverseDebugInstructionCount\": 1000000,\r\n\t\t\t\t\"spotCount\": 10\r\n\t\t\t},\r\n\t\t\t\"commandsAfterLaunch\": [\r\n\t\t\t\t\"-logpoint enable\",\r\n\t\t\t\t\"-assert enable\",\r\n\t\t\t],\r\n\t\t\t\"disassemblerArgs\": {\r\n\t\t\t\t\"esxdosRst\": true\r\n\t\t\t},\r\n\t\t\t\"topOfStack\": \"stack_top\",\r\n\t\t\t\"startAutomatically\": false,\r\n\t\t\t\"preLaunchTask\": \"Build\",\r\n\t\t\t\"rootFolder\": \"${workspaceFolder}\",\r\n\t\t\t\"load\": \"${workspaceRoot}/build/${fileBasenameNoExtension}.nex\",\r\n\t\t\t\"smallValuesMaximum\": 513,\r\n\t\t\t\"tmpDir\": \".tmp\"\r\n\t\t},\r\n\t]\r\n}"
  },
  {
    "path": "samples/layer2-256x192/.vscode/tasks.json",
    "content": "{\n\t\"version\": \"2.0.0\",\n\t\"tasks\": [\n\t\t{\n\t\t\t\"label\": \"Build\",\n\t\t\t\"type\": \"shell\",\n\t\t\t\"command\": \"${workspaceRoot}/../Tools/sjasmplus/sjasmplus.exe\",\n\t\t\t\"args\": [\n\t\t\t\t\"--sld=${workspaceRoot}/build/test.sld\",\n\t\t\t\t\"--sym=${workspaceRoot}/build/test.labels\",\n\t\t\t\t\"--fullpath\",\n\t\t\t\t\"main.asm\"\n\t\t\t],\n\t\t\t\"problemMatcher\": {\n\t\t\t\t\"fileLocation\": [\n\t\t\t\t\t\"relative\",\n\t\t\t\t\t\"${workspaceRoot}\"\n\t\t\t\t],\n\t\t\t\t\"pattern\": {\n\t\t\t\t\t\"regexp\": \"^(.*)\\\\((\\\\d+)\\\\):\\\\s+(warning|error):\\\\s+(.*)$\",\n\t\t\t\t\t\"file\": 1,\n\t\t\t\t\t\"line\": 2,\n\t\t\t\t\t\"severity\": 3,\n\t\t\t\t\t\"message\": 4\n\t\t\t\t}\n\t\t\t},\n\t\t\t\"group\": {\n\t\t\t\t\"kind\": \"build\",\n\t\t\t\t\"isDefault\": true\n\t\t\t}\n\t\t},\n\n\t\t{\n\t\t\t\"label\": \"Launch ZEsarUX\",\n\t\t\t\"type\": \"shell\",\n\t\t\t\"command\": \"${workspaceRoot}/../Tools/ZEsarUX/ZEsarUX.exe\",\n\t\t\t\"options\": {\n\t\t\t\t\"cwd\": \"${workspaceRoot}/../Tools/ZEsarUX\"\n\t\t\t}\n\t\t},\n\n\t\t{\n\t\t\t\"label\": \"Launch CSpect\",\n\t\t\t\"type\": \"shell\",\n\t\t\t\"command\": \"${workspaceRoot}/../Tools/CSpect/CSpect.exe -debug -exit -brk -sound -tv -esc -zxnext -nextrom -mmc=./cspect-next-2gb.img > output.log\",\n\t\t\t\"options\": {\n\t\t\t\t\"cwd\": \"${workspaceRoot}/../Tools/CSpect\"\n\t\t\t}\n\t\t}\n\t]\n}\n"
  },
  {
    "path": "samples/layer2-256x192/build/.gitignore",
    "content": "# Ignore everything in this directory\r\n*\r\n# Except this file\r\n!.gitignore"
  },
  {
    "path": "samples/layer2-256x192/main.asm",
    "content": ";;--------------------------------------------------------------------\r\n;; sjasmplus setup\r\n;;--------------------------------------------------------------------\r\n\t\r\n\t; Allow Next paging and instructions\r\n\tDEVICE ZXSPECTRUMNEXT\r\n\tSLDOPT COMMENT WPMEM, LOGPOINT, ASSERTION\r\n\t\r\n\t; Generate a map file for use with Cspect\r\n\tCSPECTMAP \"build/test.map\"\r\n\r\n\r\n;;--------------------------------------------------------------------\r\n;; program\r\n;;--------------------------------------------------------------------\r\n\r\n\tORG $8000 \r\n\r\nSTART_16K_BANK  EQU 9\r\nSTART_8K_BANK   EQU START_16K_BANK*2\r\n\r\nstart:\r\n\r\n\t; Enable Layer 2\r\n\tLD BC, $123B\r\n\tLD A, 2\r\n\tOUT (C), A\r\n    \r\n\t; Setup starting Layer2 16K bank and swap corresponding 8K\r\n\t; memory bank into screen memory $C000 where L2 will read from\r\n\tNEXTREG $12, START_16K_BANK\r\n\r\n\tLD D, 0                   ; D=Y, start at top of the screen\r\n    \r\nnextY:\r\n\t; Calculate bank number and swap it in\r\n\tLD A, D                   ; Copy current Y to A\r\n\tAND %11100000             ; 32100000 (3MSB = bank number)\r\n\tRLCA                      ; 21000003\r\n\tRLCA                      ; 10000032\r\n\tRLCA                      ; 00000321\r\n\tADD A, START_8K_BANK      ; A=bank number to swap in\r\n\tNEXTREG $56, A            ; Swap bank\r\n\r\n\t; Convert DE (yx) to screen memory location starting at $C000\r\n\tPUSH DE                   ; (DE) will be changed to bank offset\r\n\tLD A, D                   ; Copy current Y to A\r\n\tAND %00011111             ; Discard bank number\r\n\tOR $C0                    ; Screen starts at $C000\r\n\tLD D, A                   ; D=high byte for $C000 screen memory\r\n\r\n\t; Loop X through 0..255; we don't have to deal with bank swapping\r\n\t; here because it only occurs when changing Y\r\n\tLD E, 0\r\nnextX:\r\n\tLD A, E                   ; A=current X\r\n\tLD (DE), A                ; Write X into corresponding memory\r\n\tINC E                     ; Increment to next X\r\n\tJR NZ, nextX              ; Repeat until E rolls over\r\n\r\n\t; Continue with next line or exit\r\n\tPOP DE                    ; Restore DE to coordinates\r\n\tINC D                     ; Increment to next Y\r\n\tLD A, D                   ; A=current Y\r\n\tCP 192                    ; Did we just complete last line?\r\n\tJP C, nextY               ; No, continue with next linee\r\n\r\n.infiniteLoop:\r\n\tJR .infiniteLoop\r\n\r\n\tRET\r\n\r\n;;--------------------------------------------------------------------\r\n;; Set up .nex output\r\n;;--------------------------------------------------------------------\r\n\r\n\t; This sets the name of the project, the start address, \r\n\t; and the initial stack pointer.\r\n\tSAVENEX OPEN \"build/test.nex\", start, $ff40\r\n\r\n\t; This asserts the minimum core version.  Set it to the core version \r\n\t; you are developing on.\r\n\tSAVENEX CORE 2,0,0\r\n\r\n\t; This sets the border colour while loading (in this case white),\r\n\t; what to do with the file handle of the nex file when starting (0 = \r\n\t; close file handle as we're not going to access the project.nex \r\n\t; file after starting.  See sjasmplus documentation), whether\r\n\t; we preserve the next registers (0 = no, we set to default), and \r\n\t; whether we require the full 2MB expansion (0 = no we don't).\r\n\tSAVENEX CFG 7,0,0,0\r\n\r\n\t; Generate the Nex file automatically based on which pages you use.\r\n\tSAVENEX AUTO\r\n\r\n"
  },
  {
    "path": "samples/layer2-320x256/.vscode/launch.json",
    "content": "{\r\n\t// Use IntelliSense to learn about possible attributes.\r\n\t// Hover to view descriptions of existing attributes.\r\n\t// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387\r\n\t\"version\": \"0.2.0\",\r\n\t\"configurations\": [\r\n\t\t{\r\n\t\t\t\"type\": \"dezog\",\r\n\t\t\t\"request\": \"launch\",\r\n\t\t\t\"name\": \"CSpect\",\r\n\t\t\t\"remoteType\": \"cspect\",\r\n\t\t\t\"cspect\": {\r\n\t\t\t\t\"port\": 13000,\r\n\t\t\t},\r\n\t\t\t\"sjasmplus\": [\r\n\t\t\t\t{\r\n\t\t\t\t\t\"asm\": \"sjasmplus\",\r\n\t\t\t\t\t\"useFiles\": true,\r\n\t\t\t\t\t\"mainFile\": \"${fileDirname}/main.asm\",\r\n\t\t\t\t\t\"path\": \"${workspaceRoot}/build/test.sld\"\r\n\t\t\t\t}\r\n\t\t\t],\r\n\t\t\t\"history\": {\r\n\t\t\t\t\"reverseDebugInstructionCount\": 1000000,\r\n\t\t\t\t\"spotCount\": 10,\r\n\t\t\t},\r\n\t\t\t\"commandsAfterLaunch\": [\r\n\t\t\t\t\"-logpoint enable\",\r\n\t\t\t\t//\"-wpmem enable\",\r\n\t\t\t\t//\"-sprites\",\r\n\t\t\t\t//\"-patterns\",\r\n\t\t\t],\r\n\t\t\t\"disassemblerArgs\": {\r\n\t\t\t\t\"esxdosRst\": true\r\n\t\t\t},\r\n\t\t\t// \"topOfStack\": \"stack_top\",\r\n\t\t\t\"startAutomatically\": false,\r\n\t\t\t\"preLaunchTask\": \"Build\",\r\n\t\t\t\"rootFolder\": \"${workspaceFolder}\",\r\n\t\t\t\"load\": \"${workspaceRoot}/build/test.nex\",\r\n\t\t\t\"smallValuesMaximum\": 513,\r\n\t\t\t\"tmpDir\": \".tmp\"\r\n\t\t},\r\n\r\n\t\t{\r\n\t\t\t\"type\": \"dezog\",\r\n\t\t\t\"request\": \"launch\",\r\n\t\t\t\"name\": \"ZEsarUX\",\r\n\t\t\t\"remoteType\": \"zrcp\",\r\n\t\t\t\"zrcp\": {\r\n\t\t\t\t\"hostname\": \"localhost\",\r\n\t\t\t\t\"port\": 10000,\r\n\t\t\t\t\"loadDelay\": 700,\r\n\t\t\t\t\"skipInterrupt\": true,\r\n\t\t\t\t//\"socketTimeout\": 50\r\n\t\t\t},\r\n\t\t\t\"sjasmplus\": [\r\n\t\t\t\t{\r\n\t\t\t\t\t\"asm\": \"sjasmplus\",\r\n\t\t\t\t\t\"useFiles\": true,\r\n\t\t\t\t\t\"mainFile\": \"${fileDirname}/main.asm\",\r\n\t\t\t\t\t\"path\": \"${workspaceRoot}/build/test.sld\"\r\n\t\t\t\t}\r\n\t\t\t],\r\n\t\t\t\"history\": {\r\n\t\t\t\t\"reverseDebugInstructionCount\": 1000000,\r\n\t\t\t\t\"spotCount\": 10,\r\n\t\t\t},\r\n\t\t\t\"commandsAfterLaunch\": [\r\n\t\t\t\t\"-logpoint enable\",\r\n\t\t\t\t\"-wpmem enable\",\r\n\t\t\t\t//\"-sprites\",\r\n\t\t\t\t//\"-patterns\",\r\n\t\t\t],\r\n\t\t\t\"disassemblerArgs\": {\r\n\t\t\t\t\"esxdosRst\": true\r\n\t\t\t},\r\n\t\t\t// \"topOfStack\": \"stack_top\",\r\n\t\t\t\"startAutomatically\": false,\r\n\t\t\t\"preLaunchTask\": \"Build\",\r\n\t\t\t\"rootFolder\": \"${workspaceFolder}\",\r\n\t\t\t\"load\": \"${workspaceRoot}/build/test.nex\",\r\n\t\t\t\"smallValuesMaximum\": 513,\r\n\t\t\t\"tmpDir\": \".tmp\"\r\n\t\t},\r\n\r\n\t\t{\r\n\t\t\t\"type\": \"dezog\",\r\n\t\t\t\"request\": \"launch\",\r\n\t\t\t\"name\": \"ZXNext\",\r\n\t\t\t\"remoteType\": \"zxnext\",\r\n\t\t\t\"zxnext\": {\r\n\t\t\t\t//\"port\": 13000,\r\n\t\t\t},\r\n\t\t\t\"sjasmplus\": [\r\n\t\t\t\t{\r\n\t\t\t\t\t\"asm\": \"sjasmplus\",\r\n\t\t\t\t\t\"useFiles\": true,\r\n\t\t\t\t\t\"mainFile\": \"${fileDirname}/main.asm\",\r\n\t\t\t\t\t\"path\": \"${workspaceRoot}/build/test.sld\"\r\n\t\t\t\t}\r\n\t\t\t],\r\n\t\t\t\"history\": {\r\n\t\t\t\t\"reverseDebugInstructionCount\": 1000000,\r\n\t\t\t\t\"spotCount\": 10\r\n\t\t\t},\r\n\t\t\t\"commandsAfterLaunch\": [\r\n\t\t\t\t\"-logpoint enable\",\r\n\t\t\t\t\"-assert enable\",\r\n\t\t\t],\r\n\t\t\t\"disassemblerArgs\": {\r\n\t\t\t\t\"esxdosRst\": true\r\n\t\t\t},\r\n\t\t\t\"topOfStack\": \"stack_top\",\r\n\t\t\t\"startAutomatically\": false,\r\n\t\t\t\"preLaunchTask\": \"Build\",\r\n\t\t\t\"rootFolder\": \"${workspaceFolder}\",\r\n\t\t\t\"load\": \"${workspaceRoot}/build/${fileBasenameNoExtension}.nex\",\r\n\t\t\t\"smallValuesMaximum\": 513,\r\n\t\t\t\"tmpDir\": \".tmp\"\r\n\t\t},\r\n\t]\r\n}"
  },
  {
    "path": "samples/layer2-320x256/.vscode/tasks.json",
    "content": "{\n\t\"version\": \"2.0.0\",\n\t\"tasks\": [\n\t\t{\n\t\t\t\"label\": \"Build\",\n\t\t\t\"type\": \"shell\",\n\t\t\t\"command\": \"${workspaceRoot}/../Tools/sjasmplus/sjasmplus.exe\",\n\t\t\t\"args\": [\n\t\t\t\t\"--sld=${workspaceRoot}/build/test.sld\",\n\t\t\t\t\"--sym=${workspaceRoot}/build/test.labels\",\n\t\t\t\t\"--fullpath\",\n\t\t\t\t\"main.asm\"\n\t\t\t],\n\t\t\t\"problemMatcher\": {\n\t\t\t\t\"fileLocation\": [\n\t\t\t\t\t\"relative\",\n\t\t\t\t\t\"${workspaceRoot}\"\n\t\t\t\t],\n\t\t\t\t\"pattern\": {\n\t\t\t\t\t\"regexp\": \"^(.*)\\\\((\\\\d+)\\\\):\\\\s+(warning|error):\\\\s+(.*)$\",\n\t\t\t\t\t\"file\": 1,\n\t\t\t\t\t\"line\": 2,\n\t\t\t\t\t\"severity\": 3,\n\t\t\t\t\t\"message\": 4\n\t\t\t\t}\n\t\t\t},\n\t\t\t\"group\": {\n\t\t\t\t\"kind\": \"build\",\n\t\t\t\t\"isDefault\": true\n\t\t\t}\n\t\t},\n\n\t\t{\n\t\t\t\"label\": \"Launch ZEsarUX\",\n\t\t\t\"type\": \"shell\",\n\t\t\t\"command\": \"${workspaceRoot}/../Tools/ZEsarUX/ZEsarUX.exe\",\n\t\t\t\"options\": {\n\t\t\t\t\"cwd\": \"${workspaceRoot}/../Tools/ZEsarUX\"\n\t\t\t}\n\t\t},\n\n\t\t{\n\t\t\t\"label\": \"Launch CSpect\",\n\t\t\t\"type\": \"shell\",\n\t\t\t\"command\": \"${workspaceRoot}/../Tools/CSpect/CSpect.exe -debug -exit -brk -sound -tv -esc -zxnext -nextrom -mmc=./cspect-next-2gb.img > output.log\",\n\t\t\t\"options\": {\n\t\t\t\t\"cwd\": \"${workspaceRoot}/../Tools/CSpect\"\n\t\t\t}\n\t\t}\n\t]\n}\n"
  },
  {
    "path": "samples/layer2-320x256/build/.gitignore",
    "content": "# Ignore everything in this directory\r\n*\r\n# Except this file\r\n!.gitignore"
  },
  {
    "path": "samples/layer2-320x256/main.asm",
    "content": ";;--------------------------------------------------------------------\r\n;; sjasmplus setup\r\n;;--------------------------------------------------------------------\r\n\t\r\n\t; Allow Next paging and instructions\r\n\tDEVICE ZXSPECTRUMNEXT\r\n\tSLDOPT COMMENT WPMEM, LOGPOINT, ASSERTION\r\n\t\r\n\t; Generate a map file for use with Cspect\r\n\tCSPECTMAP \"build/test.map\"\r\n\r\n\r\n;;--------------------------------------------------------------------\r\n;; program\r\n;;--------------------------------------------------------------------\r\n\r\n\tORG $8000 \r\n\r\nSTART_16K_BANK  EQU 9\r\nSTART_8K_BANK   EQU START_16K_BANK*2\r\n\r\nRESOLUTION_X    EQU 320\r\nRESOLUTION_Y    EQU 256\r\n\r\nBANK_8K_SIZE    EQU 8192\r\nNUM_BANKS       EQU RESOLUTION_X * RESOLUTION_Y / BANK_8K_SIZE\r\nBANK_X          EQU BANK_8K_SIZE / RESOLUTION_Y\r\n\r\nstart:\r\n\r\n\t; Enable Layer 2\r\n\tLD BC, $123B\r\n\tLD A, 2\r\n\tOUT (C), A\r\n\r\n\t; Setup starting Layer2 16K bank and swap corresponding 8K\r\n\t; memory bank into screen memory $C000 where L2 will read from\r\n\tNEXTREG $12, START_16K_BANK\r\n\tNEXTREG $70, %00010000    ; 320x256 256 colour mode\r\n\r\n\t; Setup window clip for 320x256 resolution\r\n\tNEXTREG $1C, 1            ; Reset Layer 2 clip window reg index\r\n\tNEXTREG $18, 0            ; X1; X2 next line\r\n\tNEXTREG $18, RESOLUTION_X / 2 - 1\r\n\tNEXTREG $18, 0            ; Y1; Y2 next line\r\n\tNEXTREG $18, RESOLUTION_Y - 1\r\n\r\n\tLD B, START_8K_BANK       ; Bank number\r\n\tLD H, 0                   ; Colour\r\n\r\nnextBank:\r\n\t; Swap to next bank, exit once all 5 are done\r\n\tLD A, B                   ; Copy current bank number to A\r\n\tNEXTREG $56, A            ; Switch to bank\r\n\r\n\t; Fill in current bank\r\n\tLD DE, $C000              ; Prepare starting address\r\n\r\nnextY:\r\n\t; Fill in 256 pixels of current line\r\n\tLD A, H                   ; Copy colour to A\r\n\tLD (DE), A                ; Write colour into memory\r\n\tINC E                     ; Increment Y\r\n\tJR NZ, nextY              ; Continue with next Y until we wrap to next X\r\n\r\n\t; Prepare for next line until bank is full\r\n\tINC H                     ; Increment colour\r\n\tINC D                     ; Increment X\r\n\tLD A, D                   ; Copy X to A\r\n\tAND %00111111             ; Clear $C0 to get pure X coordinate\r\n\tCP BANK_X                 ; Did we reach next bank?\r\n\tJP NZ, nextY              ; No, continue with next Y\r\n\r\n\t; Prepare for next bank\r\n\tINC B                     ; Increment to next bank\r\n\tLD A, B                   ; Copy bank to A\r\n\tCP START_8K_BANK+NUM_BANKS; Did we fill last bank?\r\n\tJP NZ, nextBank           ; No, proceed with next bank\r\n\r\n.infiniteLoop:\r\n\tJR .infiniteLoop\r\n\r\n\tRET\r\n\r\n;;--------------------------------------------------------------------\r\n;; Set up .nex output\r\n;;--------------------------------------------------------------------\r\n\r\n\t; This sets the name of the project, the start address, \r\n\t; and the initial stack pointer.\r\n\tSAVENEX OPEN \"build/test.nex\", start, $ff40\r\n\r\n\t; This asserts the minimum core version.  Set it to the core version \r\n\t; you are developing on.\r\n\tSAVENEX CORE 2,0,0\r\n\r\n\t; This sets the border colour while loading (in this case white),\r\n\t; what to do with the file handle of the nex file when starting (0 = \r\n\t; close file handle as we're not going to access the project.nex \r\n\t; file after starting.  See sjasmplus documentation), whether\r\n\t; we preserve the next registers (0 = no, we set to default), and \r\n\t; whether we require the full 2MB expansion (0 = no we don't).\r\n\tSAVENEX CFG 7,0,0,0\r\n\r\n\t; Generate the Nex file automatically based on which pages you use.\r\n\tSAVENEX AUTO\r\n\r\n"
  },
  {
    "path": "samples/layer2-640x256/.vscode/launch.json",
    "content": "{\r\n\t// Use IntelliSense to learn about possible attributes.\r\n\t// Hover to view descriptions of existing attributes.\r\n\t// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387\r\n\t\"version\": \"0.2.0\",\r\n\t\"configurations\": [\r\n\t\t{\r\n\t\t\t\"type\": \"dezog\",\r\n\t\t\t\"request\": \"launch\",\r\n\t\t\t\"name\": \"CSpect\",\r\n\t\t\t\"remoteType\": \"cspect\",\r\n\t\t\t\"cspect\": {\r\n\t\t\t\t\"port\": 13000,\r\n\t\t\t},\r\n\t\t\t\"sjasmplus\": [\r\n\t\t\t\t{\r\n\t\t\t\t\t\"asm\": \"sjasmplus\",\r\n\t\t\t\t\t\"useFiles\": true,\r\n\t\t\t\t\t\"mainFile\": \"${fileDirname}/main.asm\",\r\n\t\t\t\t\t\"path\": \"${workspaceRoot}/build/test.sld\"\r\n\t\t\t\t}\r\n\t\t\t],\r\n\t\t\t\"history\": {\r\n\t\t\t\t\"reverseDebugInstructionCount\": 1000000,\r\n\t\t\t\t\"spotCount\": 10,\r\n\t\t\t},\r\n\t\t\t\"commandsAfterLaunch\": [\r\n\t\t\t\t\"-logpoint enable\",\r\n\t\t\t\t//\"-wpmem enable\",\r\n\t\t\t\t//\"-sprites\",\r\n\t\t\t\t//\"-patterns\",\r\n\t\t\t],\r\n\t\t\t\"disassemblerArgs\": {\r\n\t\t\t\t\"esxdosRst\": true\r\n\t\t\t},\r\n\t\t\t// \"topOfStack\": \"stack_top\",\r\n\t\t\t\"startAutomatically\": false,\r\n\t\t\t\"preLaunchTask\": \"Build\",\r\n\t\t\t\"rootFolder\": \"${workspaceFolder}\",\r\n\t\t\t\"load\": \"${workspaceRoot}/build/test.nex\",\r\n\t\t\t\"smallValuesMaximum\": 513,\r\n\t\t\t\"tmpDir\": \".tmp\"\r\n\t\t},\r\n\r\n\t\t{\r\n\t\t\t\"type\": \"dezog\",\r\n\t\t\t\"request\": \"launch\",\r\n\t\t\t\"name\": \"ZEsarUX\",\r\n\t\t\t\"remoteType\": \"zrcp\",\r\n\t\t\t\"zrcp\": {\r\n\t\t\t\t\"hostname\": \"localhost\",\r\n\t\t\t\t\"port\": 10000,\r\n\t\t\t\t\"loadDelay\": 700,\r\n\t\t\t\t\"skipInterrupt\": true,\r\n\t\t\t\t//\"socketTimeout\": 50\r\n\t\t\t},\r\n\t\t\t\"sjasmplus\": [\r\n\t\t\t\t{\r\n\t\t\t\t\t\"asm\": \"sjasmplus\",\r\n\t\t\t\t\t\"useFiles\": true,\r\n\t\t\t\t\t\"mainFile\": \"${fileDirname}/main.asm\",\r\n\t\t\t\t\t\"path\": \"${workspaceRoot}/build/test.sld\"\r\n\t\t\t\t}\r\n\t\t\t],\r\n\t\t\t\"history\": {\r\n\t\t\t\t\"reverseDebugInstructionCount\": 1000000,\r\n\t\t\t\t\"spotCount\": 10,\r\n\t\t\t},\r\n\t\t\t\"commandsAfterLaunch\": [\r\n\t\t\t\t\"-logpoint enable\",\r\n\t\t\t\t\"-wpmem enable\",\r\n\t\t\t\t//\"-sprites\",\r\n\t\t\t\t//\"-patterns\",\r\n\t\t\t],\r\n\t\t\t\"disassemblerArgs\": {\r\n\t\t\t\t\"esxdosRst\": true\r\n\t\t\t},\r\n\t\t\t// \"topOfStack\": \"stack_top\",\r\n\t\t\t\"startAutomatically\": false,\r\n\t\t\t\"preLaunchTask\": \"Build\",\r\n\t\t\t\"rootFolder\": \"${workspaceFolder}\",\r\n\t\t\t\"load\": \"${workspaceRoot}/build/test.nex\",\r\n\t\t\t\"smallValuesMaximum\": 513,\r\n\t\t\t\"tmpDir\": \".tmp\"\r\n\t\t},\r\n\r\n\t\t{\r\n\t\t\t\"type\": \"dezog\",\r\n\t\t\t\"request\": \"launch\",\r\n\t\t\t\"name\": \"ZXNext\",\r\n\t\t\t\"remoteType\": \"zxnext\",\r\n\t\t\t\"zxnext\": {\r\n\t\t\t\t//\"port\": 13000,\r\n\t\t\t},\r\n\t\t\t\"sjasmplus\": [\r\n\t\t\t\t{\r\n\t\t\t\t\t\"asm\": \"sjasmplus\",\r\n\t\t\t\t\t\"useFiles\": true,\r\n\t\t\t\t\t\"mainFile\": \"${fileDirname}/main.asm\",\r\n\t\t\t\t\t\"path\": \"${workspaceRoot}/build/test.sld\"\r\n\t\t\t\t}\r\n\t\t\t],\r\n\t\t\t\"history\": {\r\n\t\t\t\t\"reverseDebugInstructionCount\": 1000000,\r\n\t\t\t\t\"spotCount\": 10\r\n\t\t\t},\r\n\t\t\t\"commandsAfterLaunch\": [\r\n\t\t\t\t\"-logpoint enable\",\r\n\t\t\t\t\"-assert enable\",\r\n\t\t\t],\r\n\t\t\t\"disassemblerArgs\": {\r\n\t\t\t\t\"esxdosRst\": true\r\n\t\t\t},\r\n\t\t\t\"topOfStack\": \"stack_top\",\r\n\t\t\t\"startAutomatically\": false,\r\n\t\t\t\"preLaunchTask\": \"Build\",\r\n\t\t\t\"rootFolder\": \"${workspaceFolder}\",\r\n\t\t\t\"load\": \"${workspaceRoot}/build/${fileBasenameNoExtension}.nex\",\r\n\t\t\t\"smallValuesMaximum\": 513,\r\n\t\t\t\"tmpDir\": \".tmp\"\r\n\t\t},\r\n\t]\r\n}"
  },
  {
    "path": "samples/layer2-640x256/.vscode/tasks.json",
    "content": "{\n\t\"version\": \"2.0.0\",\n\t\"tasks\": [\n\t\t{\n\t\t\t\"label\": \"Build\",\n\t\t\t\"type\": \"shell\",\n\t\t\t\"command\": \"${workspaceRoot}/../Tools/sjasmplus/sjasmplus.exe\",\n\t\t\t\"args\": [\n\t\t\t\t\"--sld=${workspaceRoot}/build/test.sld\",\n\t\t\t\t\"--sym=${workspaceRoot}/build/test.labels\",\n\t\t\t\t\"--fullpath\",\n\t\t\t\t\"main.asm\"\n\t\t\t],\n\t\t\t\"problemMatcher\": {\n\t\t\t\t\"fileLocation\": [\n\t\t\t\t\t\"relative\",\n\t\t\t\t\t\"${workspaceRoot}\"\n\t\t\t\t],\n\t\t\t\t\"pattern\": {\n\t\t\t\t\t\"regexp\": \"^(.*)\\\\((\\\\d+)\\\\):\\\\s+(warning|error):\\\\s+(.*)$\",\n\t\t\t\t\t\"file\": 1,\n\t\t\t\t\t\"line\": 2,\n\t\t\t\t\t\"severity\": 3,\n\t\t\t\t\t\"message\": 4\n\t\t\t\t}\n\t\t\t},\n\t\t\t\"group\": {\n\t\t\t\t\"kind\": \"build\",\n\t\t\t\t\"isDefault\": true\n\t\t\t}\n\t\t},\n\n\t\t{\n\t\t\t\"label\": \"Launch ZEsarUX\",\n\t\t\t\"type\": \"shell\",\n\t\t\t\"command\": \"${workspaceRoot}/../Tools/ZEsarUX/ZEsarUX.exe\",\n\t\t\t\"options\": {\n\t\t\t\t\"cwd\": \"${workspaceRoot}/../Tools/ZEsarUX\"\n\t\t\t}\n\t\t},\n\n\t\t{\n\t\t\t\"label\": \"Launch CSpect\",\n\t\t\t\"type\": \"shell\",\n\t\t\t\"command\": \"${workspaceRoot}/../Tools/CSpect/CSpect.exe -debug -exit -brk -sound -tv -esc -zxnext -nextrom -mmc=./cspect-next-2gb.img > output.log\",\n\t\t\t\"options\": {\n\t\t\t\t\"cwd\": \"${workspaceRoot}/../Tools/CSpect\"\n\t\t\t}\n\t\t}\n\t]\n}\n"
  },
  {
    "path": "samples/layer2-640x256/build/.gitignore",
    "content": "# Ignore everything in this directory\r\n*\r\n# Except this file\r\n!.gitignore"
  },
  {
    "path": "samples/layer2-640x256/main.asm",
    "content": ";;--------------------------------------------------------------------\r\n;; sjasmplus setup\r\n;;--------------------------------------------------------------------\r\n\t\r\n\t; Allow Next paging and instructions\r\n\tDEVICE ZXSPECTRUMNEXT\r\n\tSLDOPT COMMENT WPMEM, LOGPOINT, ASSERTION\r\n\t\r\n\t; Generate a map file for use with Cspect\r\n\tCSPECTMAP \"build/test.map\"\r\n\r\n\r\n;;--------------------------------------------------------------------\r\n;; program\r\n;;--------------------------------------------------------------------\r\n\r\n\tORG $8000 \r\n\r\nSTART_16K_BANK  EQU 9\r\nSTART_8K_BANK   EQU START_16K_BANK*2\r\n\r\nRESOLUTION_X    EQU 640\r\nRESOLUTION_Y    EQU 256\r\n\r\nBANK_8K_SIZE    EQU 8192\r\nNUM_BANKS       EQU RESOLUTION_X * RESOLUTION_Y / BANK_8K_SIZE / 2\r\nBANK_X          EQU BANK_8K_SIZE / RESOLUTION_Y\r\n\r\n\r\nstart:\r\n\r\n\t; Enable Layer 2\r\n\tLD BC, $123B\r\n\tLD A, 2\r\n\tOUT (C), A\r\n\r\n\t; Setup starting Layer2 16K bank and swap corresponding 8K\r\n\t; memory bank into screen memory $C000 where L2 will read from\r\n\tNEXTREG $12, START_16K_BANK\r\n\tNEXTREG $70, %00100000    ; 640x256 16 colour mode\r\n\r\n\tNEXTREG $1C, 1            ; Reset Layer 2 clip window reg index\r\n\tNEXTREG $18, 0\r\n\tNEXTREG $18, RESOLUTION_X / 4 - 1\r\n\tNEXTREG $18, 0\r\n\tNEXTREG $18, RESOLUTION_Y - 1\r\n\r\n\tLD B, START_8K_BANK       ; Bank number\r\n\tLD H, 0                   ; Colour\r\n\r\nnextBank:\r\n\t; Swap to next bank, exit once all 5 are done\r\n\tLD A, B                   ; Copy current bank number to A\r\n\tNEXTREG $56, A            ; Switch to bank\r\n\r\n\t; Fill in current bank\r\n\tLD DE, $C000              ; Prepare starting address\r\n\r\nnextY:\r\n\t; Fill in 256 pixels of current line\r\n\tLD A, H                   ; Copy colour to A\r\n\tLD (DE), A                ; Write colour into memory\r\n\tINC E                     ; Increment Y\r\n\tJR NZ, nextY              ; Continue with next Y until we wrap to next X\r\n\r\n\t; Prepare for next line until bank is full\r\n\tINC H                     ; Increment colour\r\n\tINC D                     ; Increment X\r\n\tLD A, D                   ; Copy X to A\r\n\tAND %00111111             ; Clear $C0 to get pure X coordinate\r\n\tCP BANK_X                 ; Did we reach next bank?\r\n\tJP NZ, nextY              ; No, continue with next Y\r\n\r\n\t; Prepare for next bank\r\n\tINC B                     ; Increment to next bank\r\n\tLD A, B                   ; Copy bank to A\r\n\tCP START_8K_BANK+NUM_BANKS; Did we fill last bank?\r\n\tJP NZ, nextBank           ; No, proceed with next bank\r\n\r\n.infiniteLoop:\r\n\tJR .infiniteLoop\r\n\r\n\tRET\r\n\r\n;;--------------------------------------------------------------------\r\n;; Set up .nex output\r\n;;--------------------------------------------------------------------\r\n\r\n\t; This sets the name of the project, the start address, \r\n\t; and the initial stack pointer.\r\n\tSAVENEX OPEN \"build/test.nex\", start, $ff40\r\n\r\n\t; This asserts the minimum core version.  Set it to the core version \r\n\t; you are developing on.\r\n\tSAVENEX CORE 2,0,0\r\n\r\n\t; This sets the border colour while loading (in this case white),\r\n\t; what to do with the file handle of the nex file when starting (0 = \r\n\t; close file handle as we're not going to access the project.nex \r\n\t; file after starting.  See sjasmplus documentation), whether\r\n\t; we preserve the next registers (0 = no, we set to default), and \r\n\t; whether we require the full 2MB expansion (0 = no we don't).\r\n\tSAVENEX CFG 7,0,0,0\r\n\r\n\t; Generate the Nex file automatically based on which pages you use.\r\n\tSAVENEX AUTO\r\n\r\n"
  },
  {
    "path": "samples/sound/.vscode/launch.json",
    "content": "{\r\n\t// Use IntelliSense to learn about possible attributes.\r\n\t// Hover to view descriptions of existing attributes.\r\n\t// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387\r\n\t\"version\": \"0.2.0\",\r\n\t\"configurations\": [\r\n\t\t{\r\n\t\t\t\"type\": \"dezog\",\r\n\t\t\t\"request\": \"launch\",\r\n\t\t\t\"name\": \"CSpect\",\r\n\t\t\t\"remoteType\": \"cspect\",\r\n\t\t\t\"cspect\": {\r\n\t\t\t\t\"port\": 13000,\r\n\t\t\t},\r\n\t\t\t\"sjasmplus\": [\r\n\t\t\t\t{\r\n\t\t\t\t\t\"asm\": \"sjasmplus\",\r\n\t\t\t\t\t\"useFiles\": true,\r\n\t\t\t\t\t\"mainFile\": \"${fileDirname}/main.asm\",\r\n\t\t\t\t\t\"path\": \"${workspaceRoot}/build/test.sld\"\r\n\t\t\t\t}\r\n\t\t\t],\r\n\t\t\t\"history\": {\r\n\t\t\t\t\"reverseDebugInstructionCount\": 1000000,\r\n\t\t\t\t\"spotCount\": 10,\r\n\t\t\t},\r\n\t\t\t\"commandsAfterLaunch\": [\r\n\t\t\t\t\"-logpoint enable\",\r\n\t\t\t\t//\"-wpmem enable\",\r\n\t\t\t\t//\"-sprites\",\r\n\t\t\t\t//\"-patterns\",\r\n\t\t\t],\r\n\t\t\t\"disassemblerArgs\": {\r\n\t\t\t\t\"esxdosRst\": true\r\n\t\t\t},\r\n\t\t\t// \"topOfStack\": \"stack_top\",\r\n\t\t\t\"startAutomatically\": false,\r\n\t\t\t\"preLaunchTask\": \"Build\",\r\n\t\t\t\"rootFolder\": \"${workspaceFolder}\",\r\n\t\t\t\"load\": \"${workspaceRoot}/build/test.nex\",\r\n\t\t\t\"smallValuesMaximum\": 513,\r\n\t\t\t\"tmpDir\": \".tmp\"\r\n\t\t},\r\n\r\n\t\t{\r\n\t\t\t\"type\": \"dezog\",\r\n\t\t\t\"request\": \"launch\",\r\n\t\t\t\"name\": \"ZEsarUX\",\r\n\t\t\t\"remoteType\": \"zrcp\",\r\n\t\t\t\"zrcp\": {\r\n\t\t\t\t\"hostname\": \"localhost\",\r\n\t\t\t\t\"port\": 10000,\r\n\t\t\t\t\"loadDelay\": 700,\r\n\t\t\t\t\"skipInterrupt\": true,\r\n\t\t\t\t//\"socketTimeout\": 50\r\n\t\t\t},\r\n\t\t\t\"sjasmplus\": [\r\n\t\t\t\t{\r\n\t\t\t\t\t\"asm\": \"sjasmplus\",\r\n\t\t\t\t\t\"useFiles\": true,\r\n\t\t\t\t\t\"mainFile\": \"${fileDirname}/main.asm\",\r\n\t\t\t\t\t\"path\": \"${workspaceRoot}/build/test.sld\"\r\n\t\t\t\t}\r\n\t\t\t],\r\n\t\t\t\"history\": {\r\n\t\t\t\t\"reverseDebugInstructionCount\": 1000000,\r\n\t\t\t\t\"spotCount\": 10,\r\n\t\t\t},\r\n\t\t\t\"commandsAfterLaunch\": [\r\n\t\t\t\t\"-logpoint enable\",\r\n\t\t\t\t\"-wpmem enable\",\r\n\t\t\t\t//\"-sprites\",\r\n\t\t\t\t//\"-patterns\",\r\n\t\t\t],\r\n\t\t\t\"disassemblerArgs\": {\r\n\t\t\t\t\"esxdosRst\": true\r\n\t\t\t},\r\n\t\t\t// \"topOfStack\": \"stack_top\",\r\n\t\t\t\"startAutomatically\": false,\r\n\t\t\t\"preLaunchTask\": \"Build\",\r\n\t\t\t\"rootFolder\": \"${workspaceFolder}\",\r\n\t\t\t\"load\": \"${workspaceRoot}/build/test.nex\",\r\n\t\t\t\"smallValuesMaximum\": 513,\r\n\t\t\t\"tmpDir\": \".tmp\"\r\n\t\t},\r\n\r\n\t\t{\r\n\t\t\t\"type\": \"dezog\",\r\n\t\t\t\"request\": \"launch\",\r\n\t\t\t\"name\": \"ZXNext\",\r\n\t\t\t\"remoteType\": \"zxnext\",\r\n\t\t\t\"zxnext\": {\r\n\t\t\t\t//\"port\": 13000,\r\n\t\t\t},\r\n\t\t\t\"sjasmplus\": [\r\n\t\t\t\t{\r\n\t\t\t\t\t\"asm\": \"sjasmplus\",\r\n\t\t\t\t\t\"useFiles\": true,\r\n\t\t\t\t\t\"mainFile\": \"${fileDirname}/main.asm\",\r\n\t\t\t\t\t\"path\": \"${workspaceRoot}/build/test.sld\"\r\n\t\t\t\t}\r\n\t\t\t],\r\n\t\t\t\"history\": {\r\n\t\t\t\t\"reverseDebugInstructionCount\": 1000000,\r\n\t\t\t\t\"spotCount\": 10\r\n\t\t\t},\r\n\t\t\t\"commandsAfterLaunch\": [\r\n\t\t\t\t\"-logpoint enable\",\r\n\t\t\t\t\"-assert enable\",\r\n\t\t\t],\r\n\t\t\t\"disassemblerArgs\": {\r\n\t\t\t\t\"esxdosRst\": true\r\n\t\t\t},\r\n\t\t\t\"topOfStack\": \"stack_top\",\r\n\t\t\t\"startAutomatically\": false,\r\n\t\t\t\"preLaunchTask\": \"Build\",\r\n\t\t\t\"rootFolder\": \"${workspaceFolder}\",\r\n\t\t\t\"load\": \"${workspaceRoot}/build/${fileBasenameNoExtension}.nex\",\r\n\t\t\t\"smallValuesMaximum\": 513,\r\n\t\t\t\"tmpDir\": \".tmp\"\r\n\t\t},\r\n\t]\r\n}"
  },
  {
    "path": "samples/sound/.vscode/tasks.json",
    "content": "{\n\t\"version\": \"2.0.0\",\n\t\"tasks\": [\n\t\t{\n\t\t\t\"label\": \"Build\",\n\t\t\t\"type\": \"shell\",\n\t\t\t\"command\": \"${workspaceRoot}/../Tools/sjasmplus/sjasmplus.exe\",\n\t\t\t\"args\": [\n\t\t\t\t\"--sld=${workspaceRoot}/build/test.sld\",\n\t\t\t\t\"--sym=${workspaceRoot}/build/test.labels\",\n\t\t\t\t\"--fullpath\",\n\t\t\t\t\"main.asm\"\n\t\t\t],\n\t\t\t\"problemMatcher\": {\n\t\t\t\t\"fileLocation\": [\n\t\t\t\t\t\"relative\",\n\t\t\t\t\t\"${workspaceRoot}\"\n\t\t\t\t],\n\t\t\t\t\"pattern\": {\n\t\t\t\t\t\"regexp\": \"^(.*)\\\\((\\\\d+)\\\\):\\\\s+(warning|error):\\\\s+(.*)$\",\n\t\t\t\t\t\"file\": 1,\n\t\t\t\t\t\"line\": 2,\n\t\t\t\t\t\"severity\": 3,\n\t\t\t\t\t\"message\": 4\n\t\t\t\t}\n\t\t\t},\n\t\t\t\"group\": {\n\t\t\t\t\"kind\": \"build\",\n\t\t\t\t\"isDefault\": true\n\t\t\t}\n\t\t},\n\n\t\t{\n\t\t\t\"label\": \"Launch ZEsarUX\",\n\t\t\t\"type\": \"shell\",\n\t\t\t\"command\": \"${workspaceRoot}/../Tools/ZEsarUX/ZEsarUX.exe\",\n\t\t\t\"options\": {\n\t\t\t\t\"cwd\": \"${workspaceRoot}/../Tools/ZEsarUX\"\n\t\t\t}\n\t\t},\n\n\t\t{\n\t\t\t\"label\": \"Launch CSpect\",\n\t\t\t\"type\": \"shell\",\n\t\t\t\"command\": \"${workspaceRoot}/../Tools/CSpect/CSpect.exe -debug -exit -brk -tv -esc -zxnext -nextrom -mmc=./cspect-next-2gb.img > output.log\",\n\t\t\t\"options\": {\n\t\t\t\t\"cwd\": \"${workspaceRoot}/../Tools/CSpect\"\n\t\t\t}\n\t\t}\n\t]\n}\n"
  },
  {
    "path": "samples/sound/build/.gitignore",
    "content": "# Ignore everything in this directory\r\n*\r\n# Except this file\r\n!.gitignore"
  },
  {
    "path": "samples/sound/main.asm",
    "content": ";;--------------------------------------------------------------------\r\n;; sjasmplus setup\r\n;;--------------------------------------------------------------------\r\n\t\r\n\t; Allow Next paging and instructions\r\n\tDEVICE ZXSPECTRUMNEXT\r\n\tSLDOPT COMMENT WPMEM, LOGPOINT, ASSERTION\r\n\t\r\n\t; Generate a map file for use with Cspect\r\n\tCSPECTMAP \"build/test.map\"\r\n\r\n\r\n;;--------------------------------------------------------------------\r\n;; program\r\n;;--------------------------------------------------------------------\r\n\r\n; IMPORTANT: For this program to work on CSpect, you will need to \r\n; install OpenAL. Without it, CSpect will freeze on launch.\r\n; Follow instructions from https://specnext.dev/tutorials/creating-a-z80-assembly-development-environment-on-windows/\r\n\r\n\tORG $8000 \r\n\r\nstart:\r\n\t; Setup Turbo Sound chip\r\n\tLD BC, $FFFD\t\t; Turbo Sound Next Control Register\r\n\tLD A, %11111101\t\t; Enable left+right audio, select AY2\r\n\tOUT (C), A\r\n\r\n\t; Setup mapping of chip channels to stereo channels\r\n\tNEXTREG $08, %00010010\t; Use ABC, enable internal speaker & turbosound\r\n\tNEXTREG $09, %11100000\t; Enable mono for AY0-2\r\n\r\n\t; Play the tune\r\n.infiniteLoop:\r\n\tLD HL, tune\r\n\tCALL playTune\t\r\n\tJP .infiniteLoop\r\n\r\n\tRET\r\n\r\n; HL = address in memory where tune starts\r\nplayTune:\r\n\t; Read noise/tone enable/disable\r\n\tLD A, (HL)\t; Read next byte from (HL)\r\n\tCP $FF\t\t; Is it $FF?\r\n\tRET Z\t\t; Yes, exit\r\n\r\n\t; We still have data, transfer A to D and write to AY register 7\r\n\tLD D, A\r\n\tLD A, 7\r\n\tINC HL\r\n\tCALL writeDToAYReg\r\n\r\n\t; Read tone period (regs 0 & 1)\r\n\tLD A, 0\r\n\tLD E, (HL)\r\n\tINC HL\r\n\tLD D, (HL)\r\n\tINC HL\r\n\tCALL writeDEToAYReg\r\n\r\n\t; Read noise period (reg 6)\r\n\tLD A, 6\r\n\tLD D, (HL)\r\n\tINC HL\r\n\tCALL writeDToAYReg\r\n\r\n\t; Read channel for setting up volume (0-2)\r\n\tLD A, (HL)\r\n\tINC HL\r\n\tADD 8\t\t; channel A is reg 8, B=9, C=10\r\n\r\n\t; Read and set volume to register in A\r\n\tLD D, (HL)\r\n\tINC HL\r\n\tCALL writeDToAYReg\r\n\r\n\t; Do a small pause between tones...\r\n\tLD BC, $1000\r\n.delay:\r\n\tDEC BC\r\n\tLD A, B\r\n\tOR C\r\n\tJR NZ, .delay\r\n\r\n\t; ...then continue with next tone\r\n\tJP playTune\r\n\r\ntune:\r\n\t;     Noise enable (0), disable (1)\r\n\t;     |  Tone enable (0), disable (1)\r\n\t;     |  |    Tone period ($0-$FFF)\r\n\t;     |  |    |        Noise period ($0-$1F)\r\n\t;     |  |    |        |    Channel (0=A, 1=B, 2=C)\r\n\t;     |--|--  |        |    |  Volume ($0-$F)\r\n\t;   --CBACBA  |------  |--  |  |-\r\n\tDB %00111110, $00,$3F, $00, 0, $F\r\n\tDB %00111110, $00,$97, $00, 0, $A\r\n\tDB %00111110, $01,$00, $00, 0, $6\r\n\tDB %00110110, $00,$00, $1F, 0, $4\r\n\tDB %00110110, $00,$00, $11, 0, $4\r\n\tDB %00111110, $00,$4C, $00, 0, $A\r\n\tDB %00111110, $00,$7E, $00, 0, $7\r\n\tDB %00110110, $00,$C9, $1F, 0, $4\r\n\tDB %00110110, $01,$00, $11, 0, $4\r\n\tDB %00111110, $00,$00, $00, 0, $2\r\n\tDB %00111110, $00,$00, $00, 0, $2\r\n\tDB %00111110, $01,$2E, $00, 0, $1 \r\n\tDB %00111110, $01,$60, $00, 0, $1\r\n\tDB %00111110, $01,$92, $00, 0, $1\r\n\tDB %00111110, $00,$00, $00, 0, $2\r\n\tDB %00111110, $03,$0F, $17, 0, $C\r\n\tDB %00111110, $03,$C6, $10, 0, $B\r\n\tDB %00111110, $04,$40, $0E, 0, $A\r\n\tDB %00111110, $05,$35, $10, 0, $9\r\n\tDB %00111110, $05,$EC, $13, 0, $8\r\n\tDB %00111110, $06,$E1, $11, 0, $7\r\n\tDB $FF ; $FF = end of song\r\n\r\n; Writes D to register A and E to A+1\r\n; A = Starting register number\r\n; DE = 16 bit value to write\r\nwriteDEToAYReg:\r\n\tPUSH AF\t\t; writeDToAYReg will change A\r\n\r\n\t; Write D first\r\n\tCALL writeDToAYReg\r\n\r\n\t; Swap E to D and increment A, then continue straight to writeDToAYReg\r\n\tPOP AF\t\t; Restore A\r\n\tINC A\t\t; Write to next register\r\n\tLD D, E\t\t; Prepare value to write\r\n\r\n; Note: register number (A) must have bit 7 reset, otherwise Next will use it as Turbo Sound Control! Should not be an issue as AY only uses registers 0-13\r\n; A = Register number\r\n; D = Value to write\r\nwriteDToAYReg:\r\n\t; Select desired register\r\n\tLD BC, $FFFD\r\n\tOUT (C), A\r\n\r\n\t; Write given value\r\n\tLD A, D\r\n\tLD BC, $BFFD\r\n\tOUT (C), A\r\n\r\n\tRET\r\n\r\n;;--------------------------------------------------------------------\r\n;; Set up .nex output\r\n;;--------------------------------------------------------------------\r\n\r\n\t; This sets the name of the project, the start address, \r\n\t; and the initial stack pointer.\r\n\tSAVENEX OPEN \"build/test.nex\", start, $ff40\r\n\r\n\t; This asserts the minimum core version.  Set it to the core version \r\n\t; you are developing on.\r\n\tSAVENEX CORE 2,0,0\r\n\r\n\t; This sets the border colour while loading (in this case white),\r\n\t; what to do with the file handle of the nex file when starting (0 = \r\n\t; close file handle as we're not going to access the project.nex \r\n\t; file after starting.  See sjasmplus documentation), whether\r\n\t; we preserve the next registers (0 = no, we set to default), and \r\n\t; whether we require the full 2MB expansion (0 = no we don't).\r\n\tSAVENEX CFG 7,0,0,0\r\n\r\n\t; Generate the Nex file automatically based on which pages you use.\r\n\tSAVENEX AUTO\r\n\r\n"
  },
  {
    "path": "samples/sprites/.vscode/launch.json",
    "content": "{\r\n\t// Use IntelliSense to learn about possible attributes.\r\n\t// Hover to view descriptions of existing attributes.\r\n\t// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387\r\n\t\"version\": \"0.2.0\",\r\n\t\"configurations\": [\r\n\t\t{\r\n\t\t\t\"type\": \"dezog\",\r\n\t\t\t\"request\": \"launch\",\r\n\t\t\t\"name\": \"CSpect\",\r\n\t\t\t\"remoteType\": \"cspect\",\r\n\t\t\t\"cspect\": {\r\n\t\t\t\t\"port\": 13000,\r\n\t\t\t},\r\n\t\t\t\"sjasmplus\": [\r\n\t\t\t\t{\r\n\t\t\t\t\t\"asm\": \"sjasmplus\",\r\n\t\t\t\t\t\"useFiles\": true,\r\n\t\t\t\t\t\"mainFile\": \"${fileDirname}/main.asm\",\r\n\t\t\t\t\t\"path\": \"${workspaceRoot}/build/test.sld\"\r\n\t\t\t\t}\r\n\t\t\t],\r\n\t\t\t\"history\": {\r\n\t\t\t\t\"reverseDebugInstructionCount\": 1000000,\r\n\t\t\t\t\"spotCount\": 10,\r\n\t\t\t},\r\n\t\t\t\"commandsAfterLaunch\": [\r\n\t\t\t\t\"-logpoint enable\",\r\n\t\t\t\t//\"-wpmem enable\",\r\n\t\t\t\t//\"-sprites\",\r\n\t\t\t\t//\"-patterns\",\r\n\t\t\t],\r\n\t\t\t\"disassemblerArgs\": {\r\n\t\t\t\t\"esxdosRst\": true\r\n\t\t\t},\r\n\t\t\t// \"topOfStack\": \"stack_top\",\r\n\t\t\t\"startAutomatically\": false,\r\n\t\t\t\"preLaunchTask\": \"Build\",\r\n\t\t\t\"rootFolder\": \"${workspaceFolder}\",\r\n\t\t\t\"load\": \"${workspaceRoot}/build/test.nex\",\r\n\t\t\t\"smallValuesMaximum\": 513,\r\n\t\t\t\"tmpDir\": \".tmp\"\r\n\t\t},\r\n\r\n\t\t{\r\n\t\t\t\"type\": \"dezog\",\r\n\t\t\t\"request\": \"launch\",\r\n\t\t\t\"name\": \"ZEsarUX\",\r\n\t\t\t\"remoteType\": \"zrcp\",\r\n\t\t\t\"zrcp\": {\r\n\t\t\t\t\"hostname\": \"localhost\",\r\n\t\t\t\t\"port\": 10000,\r\n\t\t\t\t\"loadDelay\": 700,\r\n\t\t\t\t\"skipInterrupt\": true,\r\n\t\t\t\t//\"socketTimeout\": 50\r\n\t\t\t},\r\n\t\t\t\"sjasmplus\": [\r\n\t\t\t\t{\r\n\t\t\t\t\t\"asm\": \"sjasmplus\",\r\n\t\t\t\t\t\"useFiles\": true,\r\n\t\t\t\t\t\"mainFile\": \"${fileDirname}/main.asm\",\r\n\t\t\t\t\t\"path\": \"${workspaceRoot}/build/test.sld\"\r\n\t\t\t\t}\r\n\t\t\t],\r\n\t\t\t\"history\": {\r\n\t\t\t\t\"reverseDebugInstructionCount\": 1000000,\r\n\t\t\t\t\"spotCount\": 10,\r\n\t\t\t},\r\n\t\t\t\"commandsAfterLaunch\": [\r\n\t\t\t\t\"-logpoint enable\",\r\n\t\t\t\t\"-wpmem enable\",\r\n\t\t\t\t//\"-sprites\",\r\n\t\t\t\t//\"-patterns\",\r\n\t\t\t],\r\n\t\t\t\"disassemblerArgs\": {\r\n\t\t\t\t\"esxdosRst\": true\r\n\t\t\t},\r\n\t\t\t// \"topOfStack\": \"stack_top\",\r\n\t\t\t\"startAutomatically\": false,\r\n\t\t\t\"preLaunchTask\": \"Build\",\r\n\t\t\t\"rootFolder\": \"${workspaceFolder}\",\r\n\t\t\t\"load\": \"${workspaceRoot}/build/test.nex\",\r\n\t\t\t\"smallValuesMaximum\": 513,\r\n\t\t\t\"tmpDir\": \".tmp\"\r\n\t\t},\r\n\r\n\t\t{\r\n\t\t\t\"type\": \"dezog\",\r\n\t\t\t\"request\": \"launch\",\r\n\t\t\t\"name\": \"ZXNext\",\r\n\t\t\t\"remoteType\": \"zxnext\",\r\n\t\t\t\"zxnext\": {\r\n\t\t\t\t//\"port\": 13000,\r\n\t\t\t},\r\n\t\t\t\"sjasmplus\": [\r\n\t\t\t\t{\r\n\t\t\t\t\t\"asm\": \"sjasmplus\",\r\n\t\t\t\t\t\"useFiles\": true,\r\n\t\t\t\t\t\"mainFile\": \"${fileDirname}/main.asm\",\r\n\t\t\t\t\t\"path\": \"${workspaceRoot}/build/test.sld\"\r\n\t\t\t\t}\r\n\t\t\t],\r\n\t\t\t\"history\": {\r\n\t\t\t\t\"reverseDebugInstructionCount\": 1000000,\r\n\t\t\t\t\"spotCount\": 10\r\n\t\t\t},\r\n\t\t\t\"commandsAfterLaunch\": [\r\n\t\t\t\t\"-logpoint enable\",\r\n\t\t\t\t\"-assert enable\",\r\n\t\t\t],\r\n\t\t\t\"disassemblerArgs\": {\r\n\t\t\t\t\"esxdosRst\": true\r\n\t\t\t},\r\n\t\t\t\"topOfStack\": \"stack_top\",\r\n\t\t\t\"startAutomatically\": false,\r\n\t\t\t\"preLaunchTask\": \"Build\",\r\n\t\t\t\"rootFolder\": \"${workspaceFolder}\",\r\n\t\t\t\"load\": \"${workspaceRoot}/build/${fileBasenameNoExtension}.nex\",\r\n\t\t\t\"smallValuesMaximum\": 513,\r\n\t\t\t\"tmpDir\": \".tmp\"\r\n\t\t},\r\n\t]\r\n}"
  },
  {
    "path": "samples/sprites/.vscode/tasks.json",
    "content": "{\n\t\"version\": \"2.0.0\",\n\t\"tasks\": [\n\t\t{\n\t\t\t\"label\": \"Build\",\n\t\t\t\"type\": \"shell\",\n\t\t\t\"command\": \"${workspaceRoot}/../Tools/sjasmplus/sjasmplus.exe\",\n\t\t\t\"args\": [\n\t\t\t\t\"--sld=${workspaceRoot}/build/test.sld\",\n\t\t\t\t\"--sym=${workspaceRoot}/build/test.labels\",\n\t\t\t\t\"--fullpath\",\n\t\t\t\t\"main.asm\"\n\t\t\t],\n\t\t\t\"problemMatcher\": {\n\t\t\t\t\"fileLocation\": [\n\t\t\t\t\t\"relative\",\n\t\t\t\t\t\"${workspaceRoot}\"\n\t\t\t\t],\n\t\t\t\t\"pattern\": {\n\t\t\t\t\t\"regexp\": \"^(.*)\\\\((\\\\d+)\\\\):\\\\s+(warning|error):\\\\s+(.*)$\",\n\t\t\t\t\t\"file\": 1,\n\t\t\t\t\t\"line\": 2,\n\t\t\t\t\t\"severity\": 3,\n\t\t\t\t\t\"message\": 4\n\t\t\t\t}\n\t\t\t},\n\t\t\t\"group\": {\n\t\t\t\t\"kind\": \"build\",\n\t\t\t\t\"isDefault\": true\n\t\t\t}\n\t\t},\n\n\t\t{\n\t\t\t\"label\": \"Launch ZEsarUX\",\n\t\t\t\"type\": \"shell\",\n\t\t\t\"command\": \"${workspaceRoot}/../Tools/ZEsarUX/ZEsarUX.exe\",\n\t\t\t\"options\": {\n\t\t\t\t\"cwd\": \"${workspaceRoot}/../Tools/ZEsarUX\"\n\t\t\t}\n\t\t},\n\n\t\t{\n\t\t\t\"label\": \"Launch CSpect\",\n\t\t\t\"type\": \"shell\",\n\t\t\t\"command\": \"${workspaceRoot}/../Tools/CSpect/CSpect.exe -debug -exit -brk -sound -tv -esc -zxnext -nextrom -mmc=./cspect-next-2gb.img > output.log\",\n\t\t\t\"options\": {\n\t\t\t\t\"cwd\": \"${workspaceRoot}/../Tools/CSpect\"\n\t\t\t}\n\t\t}\n\t]\n}\n"
  },
  {
    "path": "samples/sprites/build/.gitignore",
    "content": "# Ignore everything in this directory\r\n*\r\n# Except this file\r\n!.gitignore"
  },
  {
    "path": "samples/sprites/main.asm",
    "content": ";;--------------------------------------------------------------------\r\n;; sjasmplus setup\r\n;;--------------------------------------------------------------------\r\n\t\r\n\t; Allow Next paging and instructions\r\n\tDEVICE ZXSPECTRUMNEXT\r\n\tSLDOPT COMMENT WPMEM, LOGPOINT, ASSERTION\r\n\t\r\n\t; Generate a map file for use with Cspect\r\n\tCSPECTMAP \"build/test.map\"\r\n\r\n\r\n;;--------------------------------------------------------------------\r\n;; program\r\n;;--------------------------------------------------------------------\r\n\r\n\tORG $8000 \r\n\r\nstart:\r\n\t; Load sprite data using DMA\r\n\tLD HL, sprites\t\t\t; Sprites data source\r\n\tLD BC, 16*16*5\t\t\t; Copy 5 sprites, each 16x16 pixels\r\n\tLD A, 0\t\t\t\t; Start with first sprite\r\n\tCALL loadSprites\t\t; Load sprites to FPGA\r\n\r\n\t; Setup sprite hardware\r\n\tNEXTREG $15, %01000001\t\t; sprite 0 on top, SLU, sprites visible\r\n\r\n\t; Show single sprite 0 using pattern 0\r\n\tNEXTREG $34, 0\t\t\t; First sprite\r\n\tNEXTREG $35, 100\t\t; X=100\r\n\tNEXTREG $36, 80\t\t\t; Y=80\r\n\tNEXTREG $37, %00000000\t\t; Palette offset, no mirror, no rotation\r\n\tNEXTREG $38, %10000000\t\t; Visible, no byte 4, pattern 0\r\n\r\n\t; Show single sprite 1 using pattern 0\r\n\tNEXTREG $34, 1\t\t\t; Second sprite\r\n\tNEXTREG $35, 84\t\t\t; X=84\r\n\tNEXTREG $36, 80\t\t\t; Y=80\r\n\tNEXTREG $37, %00000000\t\t; Palette offset, no mirror, no rotation\r\n\tNEXTREG $38, %10000000\t\t; Visible, no byte 4, pattern 0\r\n\r\n\t; Show combined sprite 1-4 using patterns 1-4\r\n\tNEXTREG $34, 2\t\t\t; Select third sprite\r\n\tNEXTREG $35, 150\t\t; X=150\r\n\tNEXTREG $36, 80\t\t\t; Y=80\r\n\tNEXTREG $37, %00000000\t\t; Palette offset, no mirror, no rotation\r\n\tNEXTREG $38, %11000001\t\t; Visible, use byte 4, pattern 1\r\n\tNEXTREG $79, %00100000\t\t; Anchor with unified relatives, no scaling\r\n\r\n\tNEXTREG $35, 16\t\t\t; X=AnchorX+16\r\n\tNEXTREG $36, 0\t\t\t; Y=AnchorY+0\r\n\tNEXTREG $37, %00000000\t\t; Palette offset, no mirror, no rotation\r\n\tNEXTREG $38, %11000010\t\t; Visible, use byte 4, pattern 2\r\n\tNEXTREG $79, %01000000\t\t; Relative sprite\r\n\r\n\tNEXTREG $35, 0\t\t\t; X=AnchorX+0\r\n\tNEXTREG $36, 16\t\t\t; Y=AnchorY+16\r\n\tNEXTREG $37, %00000000\t\t; Palette offset, no mirror, no rotation\r\n\tNEXTREG $38, %11000011\t\t; Visible, use byte 4, pattern 3\r\n\tNEXTREG $79, %01000000\t\t; Relative sprite\r\n\r\n\tNEXTREG $35, 16\t\t\t; X=AnchorX+16\r\n\tNEXTREG $36, 16\t\t\t; Y=AnchorY+16\r\n\tNEXTREG $37, %00000000\t\t; Palette offset, no mirror, no rotation\r\n\tNEXTREG $38, %11000100\t\t; Visible, use byte 4, pattern 4\r\n\tNEXTREG $79, %01000000\t\t; Relative sprite\r\n\r\n\t; Wait for a while\r\n\tcall delay\r\n\r\n\t; Update our relative sprite:\r\n\t; - change position\r\n\t; - rotate\r\n\t; - scale X 2x\r\n\tNEXTREG $34, 2\t\t\t; Select third sprite\r\n\tNEXTREG $35, 200\t\t; X=200\r\n\tNEXTREG $36, 100\t\t; Y=100\r\n\tNEXTREG $37, %00000010\t\t; Palette offset, no mirror, rotate\r\n\tNEXTREG $38, %11000001\t\t; Visible, use byte 4, pattern 1\r\n\tNEXTREG $39, %00101000\t\t; Anchor with unified relatives, scale X \r\n\r\n\tcall delay\r\n\r\n\t; Update our relative sprite again:\r\n\t; - change position\r\n\t; - mirror X\r\n\t; - scale X&Y 2x\r\n\tNEXTREG $34, 2\t\t\t; Select third sprite\r\n\tNEXTREG $35, 220\t\t; X=220\r\n\tNEXTREG $36, 120\t\t; Y=120\r\n\tNEXTREG $37, %00001010\t\t; Palette offset, mirror X, rotate\r\n\tNEXTREG $38, %11000001\t\t; Visible, use byte 4, pattern 1\r\n\tNEXTREG $39, %00101010\t\t; Anchor with unified relatives, scale X&Y \r\n\r\n.infiniteLoop:\r\n\tJR .infiniteLoop\r\n\r\n\tRET\r\n\r\ndelay:\r\n\tLD B, 5\r\n.outer:\r\n\tLD HL, $FFFF\r\n.inner:\r\n\tDEC HL\r\n\tLD A, H\r\n\tOR L\r\n\tJR NZ, .inner\r\n\tDJNZ .outer\r\n\tRET\r\n\r\n;---------------------------------------------------------------------\r\n; HL = address of sprite sheet in memory\r\n; BC = number of bytes to load\r\n; A  = index of first sprite to load int5o\r\nloadSprites:\r\n\tLD (.dmaSource), HL\t; Copy sprite sheet address from HL\r\n\tLD (.dmaLength), BC\t; Copy length in bytes from BC\r\n\tLD BC, $303B\t\t; Prepare port for sprite index\r\n\tOUT (C), A\t\t; Load index of first sprite\r\n\tLD HL, .dmaProgram\t; Setup source for OTIR\r\n\tLD B, .dmaProgramLength\t; Setup length for OTIR\r\n\tLD C, $6B\t\t; Setup DMA port\r\n\tOTIR\t\t\t; Invoke DMA code\r\n\tRET\r\n.dmaProgram:\r\n\tDB %10000011\t\t; WR6 - Disable DMA\r\n\tDB %01111101\t\t; WR0 - append length + port A address, A->B\r\n.dmaSource:\r\n\tDW 0\t\t\t; WR0 par 1&2 - port A start address\r\n.dmaLength:\r\n\tDW 0\t\t\t; WR0 par 3&4 - transfer length\r\n\tDB %00010100\t\t; WR1 - A incr., A=memory\r\n\tDB %00101000\t\t; WR2 - B fixed, B=I/O\r\n\tDB %10101101\t\t; WR4 - continuous, append port B address\r\n\tDW $005B\t\t; WR4 par 1&2 - port B address\r\n\tDB %10000010\t\t; WR5 - stop on end of block, CE only\r\n\tDB %11001111\t\t; WR6 - load addresses into DMA counters\r\n\tDB %10000111\t\t; WR6 - enable DMA\r\n.dmaProgramLength = $-.dmaProgram\r\n\r\n;;--------------------------------------------------------------------\r\n;; data\r\n;;--------------------------------------------------------------------\r\n\r\nsprites:\r\n\tINCBIN \"sprites.spr\"\r\n\r\n;;--------------------------------------------------------------------\r\n;; Set up .nex output\r\n;;--------------------------------------------------------------------\r\n\r\n\t; This sets the name of the project, the start address, \r\n\t; and the initial stack pointer.\r\n\tSAVENEX OPEN \"build/test.nex\", start, $ff40\r\n\r\n\t; This asserts the minimum core version.  Set it to the core version \r\n\t; you are developing on.\r\n\tSAVENEX CORE 2,0,0\r\n\r\n\t; This sets the border colour while loading (in this case white),\r\n\t; what to do with the file handle of the nex file when starting (0 = \r\n\t; close file handle as we're not going to access the project.nex \r\n\t; file after starting.  See sjasmplus documentation), whether\r\n\t; we preserve the next registers (0 = no, we set to default), and \r\n\t; whether we require the full 2MB expansion (0 = no we don't).\r\n\tSAVENEX CFG 7,0,0,0\r\n\r\n\t; Generate the Nex file automatically based on which pages you use.\r\n\tSAVENEX AUTO\r\n\r\n"
  },
  {
    "path": "samples/tilemap/.vscode/launch.json",
    "content": "{\r\n\t// Use IntelliSense to learn about possible attributes.\r\n\t// Hover to view descriptions of existing attributes.\r\n\t// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387\r\n\t\"version\": \"0.2.0\",\r\n\t\"configurations\": [\r\n\t\t{\r\n\t\t\t\"type\": \"dezog\",\r\n\t\t\t\"request\": \"launch\",\r\n\t\t\t\"name\": \"CSpect\",\r\n\t\t\t\"remoteType\": \"cspect\",\r\n\t\t\t\"cspect\": {\r\n\t\t\t\t\"port\": 13000,\r\n\t\t\t},\r\n\t\t\t\"sjasmplus\": [\r\n\t\t\t\t{\r\n\t\t\t\t\t\"asm\": \"sjasmplus\",\r\n\t\t\t\t\t\"useFiles\": true,\r\n\t\t\t\t\t\"mainFile\": \"${fileDirname}/main.asm\",\r\n\t\t\t\t\t\"path\": \"${workspaceRoot}/build/test.sld\"\r\n\t\t\t\t}\r\n\t\t\t],\r\n\t\t\t\"history\": {\r\n\t\t\t\t\"reverseDebugInstructionCount\": 1000000,\r\n\t\t\t\t\"spotCount\": 10,\r\n\t\t\t},\r\n\t\t\t\"commandsAfterLaunch\": [\r\n\t\t\t\t\"-logpoint enable\",\r\n\t\t\t\t//\"-wpmem enable\",\r\n\t\t\t\t//\"-sprites\",\r\n\t\t\t\t//\"-patterns\",\r\n\t\t\t],\r\n\t\t\t\"disassemblerArgs\": {\r\n\t\t\t\t\"esxdosRst\": true\r\n\t\t\t},\r\n\t\t\t// \"topOfStack\": \"stack_top\",\r\n\t\t\t\"startAutomatically\": false,\r\n\t\t\t\"preLaunchTask\": \"Build\",\r\n\t\t\t\"rootFolder\": \"${workspaceFolder}\",\r\n\t\t\t\"load\": \"${workspaceRoot}/build/test.nex\",\r\n\t\t\t\"smallValuesMaximum\": 513,\r\n\t\t\t\"tmpDir\": \".tmp\"\r\n\t\t},\r\n\r\n\t\t{\r\n\t\t\t\"type\": \"dezog\",\r\n\t\t\t\"request\": \"launch\",\r\n\t\t\t\"name\": \"ZEsarUX\",\r\n\t\t\t\"remoteType\": \"zrcp\",\r\n\t\t\t\"zrcp\": {\r\n\t\t\t\t\"hostname\": \"localhost\",\r\n\t\t\t\t\"port\": 10000,\r\n\t\t\t\t\"loadDelay\": 700,\r\n\t\t\t\t\"skipInterrupt\": true,\r\n\t\t\t\t//\"socketTimeout\": 50\r\n\t\t\t},\r\n\t\t\t\"sjasmplus\": [\r\n\t\t\t\t{\r\n\t\t\t\t\t\"asm\": \"sjasmplus\",\r\n\t\t\t\t\t\"useFiles\": true,\r\n\t\t\t\t\t\"mainFile\": \"${fileDirname}/main.asm\",\r\n\t\t\t\t\t\"path\": \"${workspaceRoot}/build/test.sld\"\r\n\t\t\t\t}\r\n\t\t\t],\r\n\t\t\t\"history\": {\r\n\t\t\t\t\"reverseDebugInstructionCount\": 1000000,\r\n\t\t\t\t\"spotCount\": 10,\r\n\t\t\t},\r\n\t\t\t\"commandsAfterLaunch\": [\r\n\t\t\t\t\"-logpoint enable\",\r\n\t\t\t\t\"-wpmem enable\",\r\n\t\t\t\t//\"-sprites\",\r\n\t\t\t\t//\"-patterns\",\r\n\t\t\t],\r\n\t\t\t\"disassemblerArgs\": {\r\n\t\t\t\t\"esxdosRst\": true\r\n\t\t\t},\r\n\t\t\t// \"topOfStack\": \"stack_top\",\r\n\t\t\t\"startAutomatically\": false,\r\n\t\t\t\"preLaunchTask\": \"Build\",\r\n\t\t\t\"rootFolder\": \"${workspaceFolder}\",\r\n\t\t\t\"load\": \"${workspaceRoot}/build/test.nex\",\r\n\t\t\t\"smallValuesMaximum\": 513,\r\n\t\t\t\"tmpDir\": \".tmp\"\r\n\t\t},\r\n\r\n\t\t{\r\n\t\t\t\"type\": \"dezog\",\r\n\t\t\t\"request\": \"launch\",\r\n\t\t\t\"name\": \"ZXNext\",\r\n\t\t\t\"remoteType\": \"zxnext\",\r\n\t\t\t\"zxnext\": {\r\n\t\t\t\t//\"port\": 13000,\r\n\t\t\t},\r\n\t\t\t\"sjasmplus\": [\r\n\t\t\t\t{\r\n\t\t\t\t\t\"asm\": \"sjasmplus\",\r\n\t\t\t\t\t\"useFiles\": true,\r\n\t\t\t\t\t\"mainFile\": \"${fileDirname}/main.asm\",\r\n\t\t\t\t\t\"path\": \"${workspaceRoot}/build/test.sld\"\r\n\t\t\t\t}\r\n\t\t\t],\r\n\t\t\t\"history\": {\r\n\t\t\t\t\"reverseDebugInstructionCount\": 1000000,\r\n\t\t\t\t\"spotCount\": 10\r\n\t\t\t},\r\n\t\t\t\"commandsAfterLaunch\": [\r\n\t\t\t\t\"-logpoint enable\",\r\n\t\t\t\t\"-assert enable\",\r\n\t\t\t],\r\n\t\t\t\"disassemblerArgs\": {\r\n\t\t\t\t\"esxdosRst\": true\r\n\t\t\t},\r\n\t\t\t\"topOfStack\": \"stack_top\",\r\n\t\t\t\"startAutomatically\": false,\r\n\t\t\t\"preLaunchTask\": \"Build\",\r\n\t\t\t\"rootFolder\": \"${workspaceFolder}\",\r\n\t\t\t\"load\": \"${workspaceRoot}/build/${fileBasenameNoExtension}.nex\",\r\n\t\t\t\"smallValuesMaximum\": 513,\r\n\t\t\t\"tmpDir\": \".tmp\"\r\n\t\t},\r\n\t]\r\n}"
  },
  {
    "path": "samples/tilemap/.vscode/tasks.json",
    "content": "{\n\t\"version\": \"2.0.0\",\n\t\"tasks\": [\n\t\t{\n\t\t\t\"label\": \"Build\",\n\t\t\t\"type\": \"shell\",\n\t\t\t\"command\": \"${workspaceRoot}/../Tools/sjasmplus/sjasmplus.exe\",\n\t\t\t\"args\": [\n\t\t\t\t\"--sld=${workspaceRoot}/build/test.sld\",\n\t\t\t\t\"--sym=${workspaceRoot}/build/test.labels\",\n\t\t\t\t\"--fullpath\",\n\t\t\t\t\"main.asm\"\n\t\t\t],\n\t\t\t\"problemMatcher\": {\n\t\t\t\t\"fileLocation\": [\n\t\t\t\t\t\"relative\",\n\t\t\t\t\t\"${workspaceRoot}\"\n\t\t\t\t],\n\t\t\t\t\"pattern\": {\n\t\t\t\t\t\"regexp\": \"^(.*)\\\\((\\\\d+)\\\\):\\\\s+(warning|error):\\\\s+(.*)$\",\n\t\t\t\t\t\"file\": 1,\n\t\t\t\t\t\"line\": 2,\n\t\t\t\t\t\"severity\": 3,\n\t\t\t\t\t\"message\": 4\n\t\t\t\t}\n\t\t\t},\n\t\t\t\"group\": {\n\t\t\t\t\"kind\": \"build\",\n\t\t\t\t\"isDefault\": true\n\t\t\t}\n\t\t},\n\n\t\t{\n\t\t\t\"label\": \"Launch ZEsarUX\",\n\t\t\t\"type\": \"shell\",\n\t\t\t\"command\": \"${workspaceRoot}/../Tools/ZEsarUX/ZEsarUX.exe\",\n\t\t\t\"options\": {\n\t\t\t\t\"cwd\": \"${workspaceRoot}/../Tools/ZEsarUX\"\n\t\t\t}\n\t\t},\n\n\t\t{\n\t\t\t\"label\": \"Launch CSpect\",\n\t\t\t\"type\": \"shell\",\n\t\t\t\"command\": \"${workspaceRoot}/../Tools/CSpect/CSpect.exe -debug -exit -brk -sound -tv -esc -zxnext -nextrom -mmc=./cspect-next-2gb.img > output.log\",\n\t\t\t\"options\": {\n\t\t\t\t\"cwd\": \"${workspaceRoot}/../Tools/CSpect\"\n\t\t\t}\n\t\t}\n\t]\n}\n"
  },
  {
    "path": "samples/tilemap/build/.gitignore",
    "content": "# Ignore everything in this directory\r\n*\r\n# Except this file\r\n!.gitignore"
  },
  {
    "path": "samples/tilemap/main.asm",
    "content": ";;--------------------------------------------------------------------\r\n;; sjasmplus setup\r\n;;--------------------------------------------------------------------\r\n\t\r\n\t; Allow Next paging and instructions\r\n\tDEVICE ZXSPECTRUMNEXT\r\n\tSLDOPT COMMENT WPMEM, LOGPOINT, ASSERTION\r\n\t\r\n\t; Generate a map file for use with Cspect\r\n\tCSPECTMAP \"build/test.map\"\r\n\r\n\r\n;;--------------------------------------------------------------------\r\n;; program\r\n;;--------------------------------------------------------------------\r\n\r\n\tORG $8000 \r\n\r\nSTART_OF_BANK_5\t\tEQU $4000\r\nSTART_OF_TILEMAP\tEQU $6000\t; Just after ULA attributes\r\nSTART_OF_TILES\t\tEQU $6600\t; Just after 40x32 tilemap\r\n\r\nOFFSET_OF_MAP\t\tEQU (START_OF_TILEMAP - START_OF_BANK_5) >> 8\r\nOFFSET_OF_TILES\t\tEQU (START_OF_TILES - START_OF_BANK_5) >> 8\r\n\r\nstart:\r\n\t; Enable tilemap mode\r\n\tNEXTREG $6B, %10100001\t\t; 40x32, 8-bit entries\r\n\tNEXTREG $6C, %00000000\t\t; palette offset, visuals\r\n\r\n\t; Tell harware where to find tiles\r\n\tNEXTREG $6E, OFFSET_OF_MAP\t; MSB of tilemap in bank 5\r\n\tNEXTREG $6F, OFFSET_OF_TILES\t; MSB of tilemap definitions\r\n\r\n\t; Setup tilemap palette\r\n\tNEXTREG $43, %00110000\t\t; Auto increment, select first tilemap palette\r\n\tNEXTREG $40, 0\t\t\t; Start with first entry\r\n\r\n\t; Copy palette\r\n\tLD HL, palette\t\t\t; Address of palette data in memory\r\n\tLD B, 16\t\t\t; Copy 16 colours\r\n\tCALL copyPalette\t\t; Call routine for copying\r\n\r\n\t; Copy tile definitions to expected memory\r\n\tLD HL, tiles\t\t\t; Address of tiles in memory\r\n\tLD BC, tilesLength\t\t; Number of bytes to copy\r\n\tCALL copyTileDefinitions\t; Copy all tiles data\r\n\r\n\t; Copy tilemap to expected memory\r\n\tLD HL, tilemap\t\t\t; Addreess of tilemap in memory\r\n\tCALL copyTileMap40x32\t\t; Copy 40x32 tilemaps\r\n\r\n\t; Give it some time\r\n\tCALL delay\r\n\tCALL delay\r\n\tCALL delay\r\n\tCALL delay\r\n\r\n\t; Then use offset registers to simulate shake.\r\n\tLD A, 1\t\t\t\t; Offset by 1 pixel\r\n\tLD B, 40\t\t\t; Number of repetitions\r\n.shakeLoop:\r\n\tNEXTREG $30, A\t\t\t; Set current offset\r\n\tLD HL, 5000\r\n\tCALL customDelay\r\n\tXOR 1\t\t\t\t; Change offset: if 0 to 1, then back to 0\r\n\tDJNZ .shakeLoop\r\n\r\n\t\r\n.infiniteLoop:\r\n\tJR .infiniteLoop\r\n\r\n\tRET\r\n\r\ndelay:\r\n\tLD HL, $FFFF\r\ncustomDelay:\r\n\tPUSH AF\r\n.loop:\r\n\tDEC HL\r\n\tLD A, H\r\n\tOR L\r\n\tJR NZ, .loop\r\n\r\n\tPOP AF\r\n\tRET\r\n\r\n;;--------------------------------------------------------------------\r\n;; subroutines\r\n;;--------------------------------------------------------------------\r\n\r\n;---------------------------------------------------------------------\r\n; HL = memory location of the palette\r\ncopyPalette256:\r\n\tLD B, 0\t\t\t; This variant always starts with 0\r\n;---------------------------------------------------------------------\r\n; HL = memory location of the palette\r\n; B = number of colours to copy\r\ncopyPalette:\r\n\tLD A, (HL)\t\t; Load RRRGGGBB into A\r\n\tINC HL\t\t\t; Increment to next entry\r\n\tNEXTREG $41, A\t\t; Send entry to Next HW\r\n\tDJNZ copyPalette\t; Repeat until B=0\r\n\tRET\r\n\r\n;---------------------------------------------------------------------\r\n; HL = memory location of tile definitons\r\n; BC = size of tile defitions in bytes.\r\ncopyTileDefinitions:\r\n\tLD DE, START_OF_TILES\r\n\tLDIR\r\n\tRET\r\n\r\n;---------------------------------------------------------------------\r\n; HL = memory location of tilemap\r\ncopyTileMap40x32:\r\n\tLD BC, 40*32\t\t; This variant always load 40x32\r\n\tJR copyTileMap\r\ncopyTileMap80x32:\r\n\tLD BC, 80*32\t\t; This variant always loads 80x32\r\n;---------------------------------------------------------------------\r\n; HL = memory location of tilemap\r\n; BC = size of tilemap in bytes\r\ncopyTileMap:\r\n\tLD DE, START_OF_TILEMAP\r\n\tLDIR\r\n\tRET\r\n\r\n;;--------------------------------------------------------------------\r\n;; data\r\n;;--------------------------------------------------------------------\r\n\r\n; Note: all files created with https://zx.remysharp.com/sprites/#sprite-editor\r\n; See individual notes besides each entry below:\r\n\r\n; Tilemap settings: 8px, 40x32, disable \"include header\" when downloading, file is then usabe as is.\r\ntilemap:\r\n\tINCBIN \"tiles.map\"\r\ntilemapLength: EQU $ - tilemap\r\n\r\n; Sprite Editor settings: 4bit, after downloading manually removed empty data (with HxD) to only leave first 192 bytes.\r\ntiles:\r\n\tINCBIN \"tiles.spr\"\r\ntilesLength: EQU $ - tiles\r\n\r\n; After setting up palette, used Download button and then manually removed every second byte (with HxD) and only left 16 entries (so 16 bytes)\r\npalette:\r\n\tINCBIN \"tiles.pal\"\r\npaletteLength: EQU $-palette\r\n\r\n;;--------------------------------------------------------------------\r\n;; Set up .nex output\r\n;;--------------------------------------------------------------------\r\n\r\n\t; This sets the name of the project, the start address, \r\n\t; and the initial stack pointer.\r\n\tSAVENEX OPEN \"build/test.nex\", start, $ff40\r\n\r\n\t; This asserts the minimum core version.  Set it to the core version \r\n\t; you are developing on.\r\n\tSAVENEX CORE 2,0,0\r\n\r\n\t; This sets the border colour while loading (in this case white),\r\n\t; what to do with the file handle of the nex file when starting (0 = \r\n\t; close file handle as we're not going to access the project.nex \r\n\t; file after starting.  See sjasmplus documentation), whether\r\n\t; we preserve the next registers (0 = no, we set to default), and \r\n\t; whether we require the full 2MB expansion (0 = no we don't).\r\n\tSAVENEX CFG 7,0,0,0\r\n\r\n\t; Generate the Nex file automatically based on which pages you use.\r\n\tSAVENEX AUTO\r\n\r\n"
  },
  {
    "path": "samples/tilemap/tiles.spr",
    "content": "DDDDA\"\"3C\"\"#C333DDDD\"3A\"\"#C\"33C3UUUUUUUPUU\u0005UUUUUUUUUPU\u0005UUUUUUUUUUUUUUgUUWwwUXvwUUuUVwweUxWUUUUUUUUUUgxUXwguWwwWgwUXwwuUXvUUUUU^^UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU"
  },
  {
    "path": "setup.tex",
    "content": "% this must be included **after** defines.tex!\r\n\r\n% ▒█▀▀█ ░█▀▀█ ▒█▀▀█ ▒█░▄▀ ░█▀▀█ ▒█▀▀█ ▒█▀▀▀ ▒█▀▀▀█ \r\n% ▒█▄▄█ ▒█▄▄█ ▒█░░░ ▒█▀▄░ ▒█▄▄█ ▒█░▄▄ ▒█▀▀▀ ░▀▀▀▄▄ \r\n% ▒█░░░ ▒█░▒█ ▒█▄▄█ ▒█░▒█ ▒█░▒█ ▒█▄▄█ ▒█▄▄▄ ▒█▄▄▄█\r\n\r\n\\usetikzlibrary{\r\n\tmatrix,\r\n\tfit,\r\n\tpositioning,\r\n\tcalc,\r\n\tarrows,\r\n\tarrows.meta,\r\n\tdecorations.pathreplacing,\r\n\tshapes.multipart\r\n}\r\n\r\n\\hypersetup{\r\n\tpdftitle={\\BookTitle},\r\n\tpdfsubject={\\BookTitle},\r\n\tpdfauthor={\\AuthorNameSurname},\r\n\tpdfkeywords={\\BookKeywords},\r\n\tpdfborderstyle={/W 0},\t% don't use borders\r\n\tcolorlinks=false,\t\t% don't use colors for links\r\n\tlinktoc=all\t\t\t\t% link TOC\r\n}\r\n\r\n% ▒█▀▀█ ░█▀▀█ ▒█▀▀█ ▒█▀▀▀ 　 ▒█▀▀▀ ▒█▀▀▀█ ▒█▀▀█ ▒█▀▄▀█ ░█▀▀█ ▀▀█▀▀ ▀▀█▀▀ ▀█▀ ▒█▄░▒█ ▒█▀▀█ \r\n% ▒█▄▄█ ▒█▄▄█ ▒█░▄▄ ▒█▀▀▀ 　 ▒█▀▀▀ ▒█░░▒█ ▒█▄▄▀ ▒█▒█▒█ ▒█▄▄█ ░▒█░░ ░▒█░░ ▒█░ ▒█▒█▒█ ▒█░▄▄ \r\n% ▒█░░░ ▒█░▒█ ▒█▄▄█ ▒█▄▄▄ 　 ▒█░░░ ▒█▄▄▄█ ▒█░▒█ ▒█░░▒█ ▒█░▒█ ░▒█░░ ░▒█░░ ▄█▄ ▒█░░▀█ ▒█▄▄█\r\n\r\n% added these as compiler was complaining about too small margins; doesn't seem to change anything visually, but if compiler is happier, then I'm so too :)\r\n\\setlength{\\headheight}{14.49998pt}\r\n\\addtolength{\\topmargin}{-2.49998pt}\r\n\r\n% define default paragraph styles\r\n\\setlength{\\parindent}{0em}\r\n\\setlength{\\parskip}{1.5ex}\r\n\r\n% add sub-sub-sub-section and sub-sub-sub-sub-section commands!\r\n\\makeatletter\r\n\\newcommand\\subsubsubsection{\\@startsection{paragraph}{4}{\\z@}{-0.5ex\\@plus -0ex \\@minus -.01ex}{.01ex \\@plus .25ex}{\\normalfont\\normalsize\\bfseries}}\r\n\\newcommand\\subsubsubsubsection{\\@startsection{subparagraph}{5}{\\z@}{-0.5ex\\@plus -0ex \\@minus -.01ex}{.01ex \\@plus .25ex}{\\normalfont\\small\\bfseries}}\r\n\\makeatother\r\n\r\n% redefine the default \"plain\" pagestyle (used by chapter pages)\r\n% only show page number\r\n\\fancypagestyle{plain}{\r\n\t\\fancyhf{} \r\n\t\\fancyhead{}\r\n\t\\fancyhead[C]{\\sffamily\\footnotesize\\WorkInProgress}\r\n\t\\fancyfoot[LO,RE]{\\sffamily\\footnotesize\\thepage}\r\n\t\\fancyfoot[C]{\\sffamily\\footnotesize\\WorkInProgress}\r\n\t\\renewcommand{\\headrulewidth}{0pt}\r\n\t\\renewcommand{\\footrulewidth}{0pt}\r\n}\r\n\r\n% define style used for normal pages\r\n% odd pages (aka left) shows chapter marker\r\n% even pages (aka right) shows section name\r\n\\fancypagestyle{clean}{\r\n\t\\fancyhf{}\r\n\t\\fancyhead[RO,LE]{\\sffamily\\footnotesize\\WorkInProgress}\r\n\t\\ifdefined\\isPDF\r\n\t\t\\fancyhead[LO,RE]{\\sffamily\\footnotesize\\leftmark}\r\n\t\\else\r\n\t\t\\fancyhead[LO]{\\sffamily\\footnotesize\\leftmark}\r\n\t\t\\fancyhead[RE]{\\sffamily\\footnotesize\\rightmark}\r\n\t\\fi\r\n\t\\fancyfoot[RE,LO]{\\sffamily\\footnotesize\\thepage}\r\n\t\\fancyfoot[C]{\\sffamily\\footnotesize\\WorkInProgress}\r\n\t\\renewcommand{\\headrulewidth}{0.1pt}\r\n\t\\renewcommand{\\footrulewidth}{0pt}\r\n}\r\n\r\n% define style used for pages where section mark doesn't make sense\r\n% odd and even pages show chapter marker on the outer edge\r\n\\fancypagestyle{nosectionmarker}{\r\n\t\\fancyhf{}\r\n\t\\fancyhead[RO,LE]{\\sffamily\\footnotesize\\WorkInProgress}\r\n\t\\fancyhead[RE,LO]{\\sffamily\\footnotesize\\leftmark}\r\n\t\\fancyfoot[RE,LO]{\\sffamily\\footnotesize\\thepage}\r\n\t\\fancyfoot[C]{\\sffamily\\footnotesize\\WorkInProgress}\r\n\t\\renewcommand{\\headrulewidth}{0.1pt}\r\n\t\\renewcommand{\\footrulewidth}{0pt}\r\n}\r\n\r\n% empty pages before chapters should use empty style (aka nothing)\r\n\\let\\mtcleardoublepage\\cleardoublepage\r\n\\renewcommand{\\cleardoublepage}{\\clearpage{\\pagestyle{empty}\\mtcleardoublepage}}\r\n\r\n% section marker should only use name, without number\r\n\\renewcommand{\\sectionmark}[1]{\\uppercase{\\markright{#1}}}\r\n\r\n% -------------------------------------------------------------------------\r\n% couple main page formats - used in main tex file where needed; mainly to avoid having to implement this within individual chapter files which would be much less readable and more prone to issues should the order change in the future. But also makes main file more consistent and understandable; even though some of the macros are simple one lines\r\n\r\n% format for first couple pages\r\n\\newcommand{\\SetupPageFormattingTitle}{\r\n\t% use arabic numerals for starting pages\r\n\t\\frontmatter\r\n\r\n\t% use empty style for first couple pages (no headers or footers), until defined otherwise\r\n\t\\pagestyle{empty}\r\n}\r\n\r\n\\newcommand{\\SetupPageFormattingIntro}{\r\n\t% LaTeX assumes document starts with an odd page, however in our case the first page is an even page (the right side, then second one will be printed on the back of the same paper). This is how lulu expects it. However, since we use asymmetrical horizontal margins (to accomodate binding), leaving defaults would render the pages the other way (\"inner\" side where binding is would use smaller margin). It's interesting that only intro pages are affected, TOC and content is fine, even though pages are layed out the same ¯\\_(ツ)_/¯ I didn't figure this one out, so am using a hack in manually setting up horizontal margins for intro pages (title is fine, text is right aligned and doesn't wrap so it naturally fits to odd page). However this messes up head rules for content pages which are not rendered the whole width of the page. To compensate we must call `\\restoregeometry` before laying out the rest of the document.\r\n\t\r\n\t% Note: interestingly `\\restoregeometry` produces correct results for content pages, even though they are still odd/even in the same \"way\" as intro pages, not sure why this custom margins are needed here!?\r\n\r\n\t% Note: we could of course add an empty page in front of the title which would eliminate this whole hacking. But we'd need to remember to remove it from generated PDF before uploading to lulu. And this is something I'm afraid I would too easily forget. The result would be very bad layout in printed book. So I prefer using the hack...\r\n\r\n\t% Note: the same left/right margin works find for odd and even pages as twopage formatter reverses margins when crossing page boundaries. These margins are larger than the rest of the document, but that's fine as intro pages show very little content.\r\n\t\\newgeometry{left=3cm,right=2cm}\r\n}\r\n\r\n% format for TOC pages, after intro\r\n\\newcommand{\\SetupPageFormattingTOC}{\r\n\t% this prevents empty page from being inserted before TOC (by default LaTeX will start chapters on odd pages which is fine for all pages except TOC - we have acknowlegements here instread)\r\n\t\\let\\cleardoublepage\\clearpage\r\n\r\n\t% restore geometry to the one from `usepacakge` at the top of main file; this is needed to reset custom horizontal marings set for intro pages\r\n\t\\restoregeometry\r\n\t\r\n\t% start numbering from 1 with TOC\r\n\t\\setcounter{page}{1}\r\n\r\n\t% TOC should only display up to depth 1 (chapter+section)\r\n\t\\ifdefined\\isPDF\r\n\t\t\\setcounter{tocdepth}{2}\r\n\t\\else\r\n\t\t\\setcounter{tocdepth}{1}\r\n\t\\fi\r\n\r\n\t% use plain page style with just page number for following pages\r\n\t\\pagestyle{plain}\r\n}\r\n\r\n% foramt for the book content pages, after TOC\r\n\\newcommand{\\SetupPageFormattingBook}{\r\n\t% use arabic numerals for page numbers and clean page style for the rest of the document\r\n\t\\mainmatter\r\n\r\n\t% we should only include sections for chapter mini-TOCs; this is only needed for non-print builds where we increase tocdepth to 2 for main TOC. But it doesn't hurt to include for both builds\r\n\t\\setcounter{tocdepth}{1}\r\n\r\n\t% use default page style for all content pages\r\n\t\\pagestyle{clean}\r\n}\r\n\r\n% format for instruction pages\r\n\\newcommand{\\SetupPageFormattingInstructions}{\r\n\t% instruction pages should show chapter name on both odd & even\r\n\t\\pagestyle{nosectionmarker}\r\n}\r\n\r\n\\newcommand{\\SetupPageFormattingAppendix}{\r\n\t% all chapters from hereon should be marked as appendix\r\n\t\\appendix\r\n\r\n\t% only print chapters in appendices, not sections and subsections\r\n\t\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{0}}\r\n}\r\n\r\n\r\n% ▒█▀▀▄ ▒█▀▀▀█ ▒█▀▀█ ▒█░▒█ ▒█▀▄▀█ ▒█▀▀▀ ▒█▄░▒█ ▀▀█▀▀ 　 ▒█▀▀▄ ▒█▀▀▀ ▒█▀▀▀ ░█▀▀█ ▒█░▒█ ▒█░░░ ▀▀█▀▀ ▒█▀▀▀█ \r\n% ▒█░▒█ ▒█░░▒█ ▒█░░░ ▒█░▒█ ▒█▒█▒█ ▒█▀▀▀ ▒█▒█▒█ ░▒█░░ 　 ▒█░▒█ ▒█▀▀▀ ▒█▀▀▀ ▒█▄▄█ ▒█░▒█ ▒█░░░ ░▒█░░ ░▀▀▀▄▄ \r\n% ▒█▄▄▀ ▒█▄▄▄█ ▒█▄▄█ ░▀▄▄▀ ▒█░░▒█ ▒█▄▄▄ ▒█░░▀█ ░▒█░░ 　 ▒█▄▄▀ ▒█▄▄▄ ▒█░░░ ▒█░▒█ ░▀▄▄▀ ▒█▄▄█ ░▒█░░ ▒█▄▄▄█\r\n\r\n% don't stretch content into empty space vertically\r\n\\raggedbottom\r\n\r\n% ignore underful/overful hbox/vbox info messages. Note the values are set to suppress all messages at this point in time, but larger dimensions in the future will result in them being shown again. Each such instance should be investigated and determined if it's legit or it can be suppressed too. Not ideal, but some of these messages are really weird - PDF is rendered correctly.\r\n\\hbadness=99999\r\n\\hfuzz=140pt\r\n\\vfuzz=115pt\r\n\r\n% prevent other packages/code to change these \r\n\\newcount\\hbadness\r\n\\newdimen\\hfuzz\r\n\\newdimen\\vfuzz\r\n"
  },
  {
    "path": "tables.tex",
    "content": "% ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────\r\n% ─██████████████─██████████████─██████──────────██████─██████████████─████████████████───██████████████─██████─────────\r\n% ─██░░░░░░░░░░██─██░░░░░░░░░░██─██░░██████████──██░░██─██░░░░░░░░░░██─██░░░░░░░░░░░░██───██░░░░░░░░░░██─██░░██─────────\r\n% ─██░░██████████─██░░██████████─██░░░░░░░░░░██──██░░██─██░░██████████─██░░████████░░██───██░░██████░░██─██░░██─────────\r\n% ─██░░██─────────██░░██─────────██░░██████░░██──██░░██─██░░██─────────██░░██────██░░██───██░░██──██░░██─██░░██─────────\r\n% ─██░░██─────────██░░██████████─██░░██──██░░██──██░░██─██░░██████████─██░░████████░░██───██░░██████░░██─██░░██─────────\r\n% ─██░░██──██████─██░░░░░░░░░░██─██░░██──██░░██──██░░██─██░░░░░░░░░░██─██░░░░░░░░░░░░██───██░░░░░░░░░░██─██░░██─────────\r\n% ─██░░██──██░░██─██░░██████████─██░░██──██░░██──██░░██─██░░██████████─██░░██████░░████───██░░██████░░██─██░░██─────────\r\n% ─██░░██──██░░██─██░░██─────────██░░██──██░░██████░░██─██░░██─────────██░░██──██░░██─────██░░██──██░░██─██░░██─────────\r\n% ─██░░██████░░██─██░░██████████─██░░██──██░░░░░░░░░░██─██░░██████████─██░░██──██░░██████─██░░██──██░░██─██░░██████████─\r\n% ─██░░░░░░░░░░██─██░░░░░░░░░░██─██░░██──██████████░░██─██░░░░░░░░░░██─██░░██──██░░░░░░██─██░░██──██░░██─██░░░░░░░░░░██─\r\n% ─██████████████─██████████████─██████──────────██████─██████████████─██████──██████████─██████──██████─██████████████─\r\n% ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────\r\n\r\n\r\n% ▀▀█▀▀ ░█▀▀█ ▒█▀▀█ ▒█░░░ ▒█▀▀▀ 　 ▒█▀▀▀ ▒█▀▀▀█ ▒█▀▀█ ▒█▀▄▀█ ░█▀▀█ ▀▀█▀▀ ▀▀█▀▀ ▀█▀ ▒█▄░▒█ ▒█▀▀█ \r\n% ░▒█░░ ▒█▄▄█ ▒█▀▀▄ ▒█░░░ ▒█▀▀▀ 　 ▒█▀▀▀ ▒█░░▒█ ▒█▄▄▀ ▒█▒█▒█ ▒█▄▄█ ░▒█░░ ░▒█░░ ▒█░ ▒█▒█▒█ ▒█░▄▄ \r\n% ░▒█░░ ▒█░▒█ ▒█▄▄█ ▒█▄▄█ ▒█▄▄▄ 　 ▒█░░░ ▒█▄▄▄█ ▒█░▒█ ▒█░░▒█ ▒█░▒█ ░▒█░░ ░▒█░░ ▄█▄ ▒█░░▀█ ▒█▄▄█\r\n\r\n% couple columns for tabularx\r\n\\newcolumntype{Y}{>{\\centering\\arraybackslash}X}\t\t\t% same as X but vertically centers content in cell\r\n\\newcolumntype{C}[1]{>{\\centering\\arraybackslash}p{#1}}\t\t% same as p{size} but vertically centers content in cell\r\n\\newcolumntype{R}[1]{>{\\raggedleft\\arraybackslash}p{#1}}\t% same as p{size} but right aligned\r\n\r\n% top and bottom \"struts\" for instruction lines (note different height can be passed in via optional parameter)\r\n\\newcommand{\\instrt}[1][2.5ex]{\\rule{0pt}{#1}}\r\n\\newcommand{\\instrb}[1][-1.4ex]{\\rule[#1]{0pt}{0pt}}\r\n\r\n% top and bottom \"struts\" for note lines\r\n\\newcommand{\\notet}{\\rule{0pt}{2.4ex}}\r\n\\newcommand{\\noteb}{\\rule[-1.3ex]{0pt}{0pt}}\r\n\r\n\\newcommand{\\TableDefaultRowHeightRatio}{1.2}\r\n\r\n\r\n% ▀▀█▀▀ ░█▀▀█ ▒█▀▀█ ▒█░░░ ▒█▀▀▀ ▒█▀▀▀█ 　 ▒█░░▒█ ▀█▀ ▀▀█▀▀ ▒█░▒█ 　 ▒█░▒█ ▒█▀▀▀ ░█▀▀█ ▒█▀▀▄ ▒█▀▀▀ ▒█▀▀█ ▒█▀▀▀█ \r\n% ░▒█░░ ▒█▄▄█ ▒█▀▀▄ ▒█░░░ ▒█▀▀▀ ░▀▀▀▄▄ 　 ▒█▒█▒█ ▒█░ ░▒█░░ ▒█▀▀█ 　 ▒█▀▀█ ▒█▀▀▀ ▒█▄▄█ ▒█░▒█ ▒█▀▀▀ ▒█▄▄▀ ░▀▀▀▄▄ \r\n% ░▒█░░ ▒█░▒█ ▒█▄▄█ ▒█▄▄█ ▒█▄▄▄ ▒█▄▄▄█ 　 ▒█▄▀▄█ ▄█▄ ░▒█░░ ▒█░▒█ 　 ▒█░▒█ ▒█▄▄▄ ▒█░▒█ ▒█▄▄▀ ▒█▄▄▄ ▒█░▒█ ▒█▄▄▄█\r\n\r\n% creates a customizable tabularx with following options:\r\n% - (required) tabularx columns\r\n% - (optional) commands that should only be available to main environment block (note only \\NewExpandableDocumentCommand or \\newcommand is allowed!)\r\n% - (optional) suffix; string, default = \\hline\r\n% - (optional) table width; default = \\linewidth\r\n% - (optional) row stretch ratio; float, empty for built-in, default = \\TableDefaultRowHeightRatio\r\n\\NewDocumentEnvironment{ElegantTableX}{ m O{} O{\\hline} O{\\linewidth} O{\\TableDefaultRowHeightRatio} +!b }{\r\n\t\\begingroup\r\n\r\n\t\t% execute any group only commands\r\n\t\t#2\r\n\r\n\t\t% if row stretch ratio is given, use it\r\n\t\t\\IfEq{#5}{}{}{\\renewcommand{\\arraystretch}{#5}}\r\n\r\n\t\t\\begin{tabularx}{#4}{#1}\r\n\r\n\t\t\t\\hline\r\n\r\n\t\t\t#6\r\n\r\n\t\t\t#3\r\n\r\n\t\t\\end{tabularx}\r\n\r\n\t\\endgroup\r\n}{}\r\n% same as above except using tabular instead of tabularx\r\n\\NewDocumentEnvironment{ElegantTable}{ m O{} O{\\hline} O{\\TableDefaultRowHeightRatio} +!b }{\r\n\t\\begingroup\r\n\r\n\t\t% execute any group only commands\r\n\t\t#2\r\n\r\n\t\t% if row stretch ratio is given, use it\r\n\t\t\\IfEq{#4}{}{}{\\renewcommand{\\arraystretch}{#4}}\r\n\r\n\t\t\\begin{tabular}{#1}\r\n\r\n\t\t\t\\hline\r\n\r\n\t\t\t#5\r\n\r\n\t\t\t#3\r\n\r\n\t\t\\end{tabular}\r\n\r\n\t\\endgroup\r\n}{}\r\n\r\n% creates a header with options:\r\n% - (optional) suffix; string, empty for none, default = \\hline\r\n% - (required) headers without ending newline (\\\\)\r\n% note: this must be \"expandable\" command otherwise rowcolor will not work\r\n% https://tex.stackexchange.com/questions/176570/rowcolor-in-newdocumentcommand\r\n\\NewExpandableDocumentCommand{\\ElegantHeader}{ O{\\hline} m }{\r\n\t\\rowcolor{PrintableLightGray}\r\n\t#2\r\n\t\\\\\r\n\t#1\r\n}\r\n\r\n% creates elegant header cell\r\n% unfortunately I didn't find any simpler solution that would automatically make header text bold for the whole row...\r\n\\newcommand{\\EH}[1]{ \\textbf{#1} }\r\n\r\n% creates simple cell without vertical lines\r\n% - (optional) cell alignment; default = c\r\n% - (requires) cell contents\r\n\\newcommand{\\ES}[2][c]{ #2 }\r\n% \\newcommand{\\ES}[2][c]{ \\multicolumn{1}{#1}{#2} }\r\n\r\n% ▒█▀▀█ ▒█▀▀▀█ ▒█▀▀█ ▀▀█▀▀ 　 ▒█▀▀▄ ▒█▀▀▀ ▒█▀▀▀ ▀█▀ ▒█▄░▒█ ▀█▀ ▀▀█▀▀ ▀█▀ ▒█▀▀▀█ ▒█▄░▒█ \r\n% ▒█▄▄█ ▒█░░▒█ ▒█▄▄▀ ░▒█░░ 　 ▒█░▒█ ▒█▀▀▀ ▒█▀▀▀ ▒█░ ▒█▒█▒█ ▒█░ ░▒█░░ ▒█░ ▒█░░▒█ ▒█▒█▒█ \r\n% ▒█░░░ ▒█▄▄▄█ ▒█░▒█ ░▒█░░ 　 ▒█▄▄▀ ▒█▄▄▄ ▒█░░░ ▄█▄ ▒█░░▀█ ▄█▄ ░▒█░░ ▄█▄ ▒█▄▄▄█ ▒█░░▀█\r\n\r\n% declares the table for describing individual bits of a Next port\r\n% 2 optional parameters:\r\n% - tabular columns definitions (default `cX`)\r\n% - Title line (default `Bit & Effect`)\r\n\\NewDocumentEnvironment{NextPort}{ O{cX} O{Bit & Effect} +b }{\r\n\t\\begin{tabularx}{\\linewidth}{#1}\r\n\t\t#2 \\\\\r\n\t\t\\hline\r\n\t\t#3\r\n\t\\end{tabularx}\r\n\t\\vspace*{-1ex}\t\t% reduce spacing below tabular, it's too much by default\r\n}{}\r\n\r\n% ▒█▀▀█ ▀█▀ ▀▀█▀▀ 　 ▒█▀▀▄ ▒█▀▀▀ ▒█▀▀▀█ ▒█▀▀█ ▒█▀▀█ ▀█▀ ▒█▀▀█ ▀▀█▀▀ ▀█▀ ▒█▀▀▀█ ▒█▄░▒█ \r\n% ▒█▀▀▄ ▒█░ ░▒█░░ 　 ▒█░▒█ ▒█▀▀▀ ░▀▀▀▄▄ ▒█░░░ ▒█▄▄▀ ▒█░ ▒█▄▄█ ░▒█░░ ▒█░ ▒█░░▒█ ▒█▒█▒█ \r\n% ▒█▄▄█ ▄█▄ ░▒█░░ 　 ▒█▄▄▀ ▒█▄▄▄ ▒█▄▄▄█ ▒█▄▄█ ▒█░▒█ ▄█▄ ▒█░░░ ░▒█░░ ▄█▄ ▒█▄▄▄█ ▒█░░▀█\r\n\r\n% the main macros to use from within `NextPort`, each one for single or a group of bits\r\n\\newcommand{\\PortBits}[1]{\\tt #1\\notet &}\r\n\\newcommand{\\PortDesc}[1]{#1 \\\\}\r\n\r\n% if certain bit description extends through multiple lines, use this macro to skip bits column\r\n\\newcommand{\\PortDescOnly}[1]{& \\PortDesc{#1}}\r\n\r\n% ▒█▀▀█ ▀█▀ ▀▀█▀▀ 　 ▒█▀▀█ ▒█▀▀▀█ ▒█▀▄▀█ ▒█▀▀█ ▀█▀ ▒█▄░▒█ ░█▀▀█ ▀▀█▀▀ ▀█▀ ▒█▀▀▀█ ▒█▄░▒█ ▒█▀▀▀█ \r\n% ▒█▀▀▄ ▒█░ ░▒█░░ 　 ▒█░░░ ▒█░░▒█ ▒█▒█▒█ ▒█▀▀▄ ▒█░ ▒█▒█▒█ ▒█▄▄█ ░▒█░░ ▒█░ ▒█░░▒█ ▒█▒█▒█ ░▀▀▀▄▄ \r\n% ▒█▄▄█ ▄█▄ ░▒█░░ 　 ▒█▄▄█ ▒█▄▄▄█ ▒█░░▒█ ▒█▄▄█ ▄█▄ ▒█░░▀█ ▒█░▒█ ░▒█░░ ▄█▄ ▒█▄▄▄█ ▒█░░▀█ ▒█▄▄▄█\r\n\r\n% internal table for defining values for specific bit combinations (usually used within `PortDescOnly`)\r\n\\NewDocumentEnvironment{PortBitConfig}{ +!b }{\r\n\t{ % we are nesting this tabularx within parent tabularx, so we need to embed it within braces\r\n\t\\begin{tabularx}{\\linewidth}{lX}\r\n\t\t#1\r\n\t\\end{tabularx}\t\r\n\t}\r\n}{}\r\n\r\n% declares each line within `PortBitConfig`\r\n\\newcommand{\\PortBitLine}[2]{{\\tt #1} & \\PortDesc{#2}}\r\n\r\n\r\n% ▒█▀▀█ ▒█▀▀▀ ▒█▄░▒█ ▒█▀▀▀ ▒█▀▀█ ░█▀▀█ ▒█░░░ 　 ▒█▀▀█ ▀█▀ ▀▀█▀▀ 　 ▀▀█▀▀ ░█▀▀█ ▒█▀▀█ ▒█░░░ ▒█▀▀▀ ▒█▀▀▀█ \r\n% ▒█░▄▄ ▒█▀▀▀ ▒█▒█▒█ ▒█▀▀▀ ▒█▄▄▀ ▒█▄▄█ ▒█░░░ 　 ▒█▀▀▄ ▒█░ ░▒█░░ 　 ░▒█░░ ▒█▄▄█ ▒█▀▀▄ ▒█░░░ ▒█▀▀▀ ░▀▀▀▄▄ \r\n% ▒█▄▄█ ▒█▄▄▄ ▒█░░▀█ ▒█▄▄▄ ▒█░▒█ ▒█░▒█ ▒█▄▄█ 　 ▒█▄▄█ ▄█▄ ░▒█░░ 　 ░▒█░░ ▒█░▒█ ▒█▄▄█ ▒█▄▄█ ▒█▄▄▄ ▒█▄▄▄█\r\n\r\n\\newcommand{\\BitHead}[1]{\\footnotesize \\EH{#1}}\r\n\\newcommand{\\BitMono}[1]{\\tt #1}\r\n\\newcommand{\\BitSmall}[1]{\\small #1}\r\n\\newcommand{\\BitMulti}[2]{\\multicolumn{#1}{c|}{#2}}\r\n\\newcommand{\\BitStartMulti}[2]{\\multicolumn{#1}{|c|}{#2}}\r\n\r\n% renders 8-bit table. Parameters:\r\n% - (optional) column format; default = c\r\n\\NewDocumentEnvironment{BitTableByte}{ O{c} +b }{\r\n\t\\begin{ElegantTable}{|#1|#1|#1|#1|#1|#1|#1|#1|}\r\n\t\t\\ElegantHeader{\r\n\t\t\t\\BitHead{7} &\r\n\t\t\t\\BitHead{6} &\r\n\t\t\t\\BitHead{5} &\r\n\t\t\t\\BitHead{4} &\r\n\t\t\t\\BitHead{3} &\r\n\t\t\t\\BitHead{2} &\r\n\t\t\t\\BitHead{1} &\r\n\t\t\t\\BitHead{0}\r\n\t\t}\r\n\r\n\t\t#2\r\n\t\t\r\n\t\\end{ElegantTable}\r\n}{}\r\n\r\n% similar to BitTableByte, except it's for 16-bits. In addition to show each bit header, it also uses header row above with 2 multirow columns, one for each byte. Parmeters:\r\n% - (optional) column format; default = c\r\n% - (optional) header for high byte; default = High Byte\r\n% - (optional) header for low byte: default = Low Byte\r\n\\NewDocumentEnvironment{BitTableWord}{ O{c} O{High Byte} O{Low Byte} +b } {\r\n\t\\begin{ElegantTable}{|#1|#1|#1|#1|#1|#1|#1|#1|#1|#1|#1|#1|#1|#1|#1|#1|}\r\n\t\t\\hline\r\n\r\n\t\t\\ElegantHeader{\\multicolumn{8}{|c|}{#2} & \\multicolumn{8}{c|}{#3}}\r\n\r\n\t\t\\ElegantHeader{\r\n\t\t\t\\BitHead{15} &\r\n\t\t\t\t\\BitHead{14} &\r\n\t\t\t\t\\BitHead{13} &\r\n\t\t\t\t\\BitHead{12} &\r\n\t\t\t\t\\BitHead{11} & \r\n\t\t\t\t\\BitHead{10} &\r\n\t\t\t\t\\BitHead{9} &\r\n\t\t\t\t\\BitHead{8} &\r\n\t\t\t\\BitHead{7} &\r\n\t\t\t\t\\BitHead{6} &\r\n\t\t\t\t\\BitHead{5} &\r\n\t\t\t\t\\BitHead{4} &\r\n\t\t\t\t\\BitHead{3} &\r\n\t\t\t\t\\BitHead{2} &\r\n\t\t\t\t\\BitHead{1} &\r\n\t\t\t\t\\BitHead{0}\r\n\t\t}\r\n\t\t\r\n\t\t#4\r\n\r\n\t\\end{ElegantTable}\r\n}{}\r\n\r\n\r\n% ────────────────────────────────────────────────────────────────────────────────────\r\n% ─██████████─██████──────────██████─██████████████─██████████████─████████████████───\r\n% ─██░░░░░░██─██░░██████████──██░░██─██░░░░░░░░░░██─██░░░░░░░░░░██─██░░░░░░░░░░░░██───\r\n% ─████░░████─██░░░░░░░░░░██──██░░██─██░░██████████─██████░░██████─██░░████████░░██───\r\n% ───██░░██───██░░██████░░██──██░░██─██░░██─────────────██░░██─────██░░██────██░░██───\r\n% ───██░░██───██░░██──██░░██──██░░██─██░░██████████─────██░░██─────██░░████████░░██───\r\n% ───██░░██───██░░██──██░░██──██░░██─██░░░░░░░░░░██─────██░░██─────██░░░░░░░░░░░░██───\r\n% ───██░░██───██░░██──██░░██──██░░██─██████████░░██─────██░░██─────██░░██████░░████───\r\n% ───██░░██───██░░██──██░░██████░░██─────────██░░██─────██░░██─────██░░██──██░░██─────\r\n% ─████░░████─██░░██──██░░░░░░░░░░██─██████████░░██─────██░░██─────██░░██──██░░██████─\r\n% ─██░░░░░░██─██░░██──██████████░░██─██░░░░░░░░░░██─────██░░██─────██░░██──██░░░░░░██─\r\n% ─██████████─██████──────────██████─██████████████─────██████─────██████──██████████─\r\n% ────────────────────────────────────────────────────────────────────────────────────\r\n\r\n\r\n% ▀█▀ ▒█▄░▒█ ▒█▀▀▀█ ▀▀█▀▀ ▒█▀▀█ ▒█░▒█ ▒█▀▀█ ▀▀█▀▀ ▀█▀ ▒█▀▀▀█ ▒█▄░▒█ 　 ▀▀█▀▀ ░█▀▀█ ▒█▀▀█ ▒█░░░ ▒█▀▀▀ ▒█▀▀▀█ \r\n% ▒█░ ▒█▒█▒█ ░▀▀▀▄▄ ░▒█░░ ▒█▄▄▀ ▒█░▒█ ▒█░░░ ░▒█░░ ▒█░ ▒█░░▒█ ▒█▒█▒█ 　 ░▒█░░ ▒█▄▄█ ▒█▀▀▄ ▒█░░░ ▒█▀▀▀ ░▀▀▀▄▄ \r\n% ▄█▄ ▒█░░▀█ ▒█▄▄▄█ ░▒█░░ ▒█░▒█ ░▀▄▄▀ ▒█▄▄█ ░▒█░░ ▄█▄ ▒█▄▄▄█ ▒█░░▀█ 　 ░▒█░░ ▒█░▒█ ▒█▄▄█ ▒█▄▄█ ▒█▄▄▄ ▒█▄▄▄█\r\n\r\n% this is internal definition for instruction table that takes 2 arguments: first 2 column definitions and body. It should only be used by NewDocumentEnvironment macros, not intended as general purpose macro by itself (it could be used, but then tables would not be defined with begin/end)\r\n\\newcommand{\\InstrTableBody}[3]{\r\n\t{\r\n\t\t\\footnotesize\r\n\t\t\\setlength{\\fboxsep}{0.25mm}\r\n\t\t\\setlength{\\tabcolsep}{0.75mm}\r\n\t\r\n\t\t\\begin{tabularx}{\\textwidth}{#1ccccccp{1pt}C{2.5ex}C{3.8ex}C{3.8ex}ccp{1pt}ccp{1pt}l}\r\n\t\t\t\\hline\r\n\t\t\r\n\t\t\t% top header line\r\n\t\t\t\\notet & \r\n\t\t\tSymbolic &\r\n\t\t\t\\multicolumn{6}{c}{Flags} & &\r\n\t\t\t\\multicolumn{3}{c}{Opcode} &\r\n\t\t\t& \\\\\r\n\t\r\n\t\t\t% bottom header line\r\n\t\t\tMnemonic & \r\n\t\t\tOperation &\r\n\t\t\tSF & ZF & HF & PV & NF & CF & &\r\n\t\t\t{\\tt 76} & {\\tt 543} & {\\tt 210} & \r\n\t\t\tHex & B & & \r\n\t\t\tMc & Ts & &\r\n\t\t\tComments \\\\\r\n\t\r\n\t\t\t\\hline\r\n\t\r\n\t\t\t#2\r\n\r\n\t\t\t#3\r\n\r\n\t\t\\end{tabularx}\r\n\t}\r\n}\r\n\r\n% similar to `InstrTableBody` except that it adds bottom line\r\n\\newcommand{\\InstrTableBodyBottomLine}[2]{\r\n\t\\InstrTableBody{#1}{#2}{\r\n\t\t\\\\ % we need this newline in here otherwise \\hline below will end in error; it's because hline can only be inserted after \\\\ - even though \\\\ will be present by the time table is generated with instruction macros, compiler requires it at this point as well. Consequently, the last instruction in table should use lastinstruction macro to compensate - so far I wasn't able to get better solution (interestingly, this similar approach works for notestable ¯\\_(ツ)_/¯)\r\n\t\t\r\n\t\t\\hline\r\n\t}\r\n}\r\n\r\n% concrete environments for instruction tables (uses above 2 macros and unifies parameters)\r\n\r\n% the most generic of the tables, this should suffice for most tables, mnemonic and symbolic operation columns are same width\r\n\\NewDocumentEnvironment{instrtable}{ +b }{\\InstrTableBodyBottomLine{p{8em}X}{#1}}{}\r\n\r\n% this table doesn't use bottom line, it's mainly here for alphabetical tables use. Note it also uses less space for instruction - we don't include undocumented instructions at the moment and they do require additional space for mnemonic from `instrtable`\r\n\\NewDocumentEnvironment{instrtablesimple}{ +b }{\\InstrTableBody{p{7em}X}{#1}{}}{}\r\n\r\n\r\n% ▀█▀ ▒█▄░▒█ ▒█▀▀▀█ ▀▀█▀▀ ▒█▀▀█ ▒█░▒█ ▒█▀▀█ ▀▀█▀▀ ▀█▀ ▒█▀▀▀█ ▒█▄░▒█ ▒█▀▀▀█ \r\n% ▒█░ ▒█▒█▒█ ░▀▀▀▄▄ ░▒█░░ ▒█▄▄▀ ▒█░▒█ ▒█░░░ ░▒█░░ ▒█░ ▒█░░▒█ ▒█▒█▒█ ░▀▀▀▄▄ \r\n% ▄█▄ ▒█░░▀█ ▒█▄▄▄█ ░▒█░░ ▒█░▒█ ░▀▄▄▀ ▒█▄▄█ ░▒█░░ ▄█▄ ▒█▄▄▄█ ▒█░░▀█ ▒█▄▄▄█\r\n\r\n% defines instruction environment that embeds each instruction. Instruction mnemonic is taken as parameter, mainly to show it when environment is collapsed in editor. Note this needs to use \\xdef and be an ugly mess of oneliner otherwise mnemonic will be right aligned...\r\n\\NewDocumentEnvironment{instruction}{ m +b }{\\xdef\\instructionbody{\\unexpanded{{\\tt #1}\\instrt&}\\unexpanded\\expandafter{#2}\\unexpanded{\\instrb\\\\}}\r\n\\aftergroup\\instructionbody\r\n}{}\r\n\r\n% same as `instruction` except this should be used for last instruction in `instrtable` so that spacing below instruction and above bottom line is smaller\r\n\\NewDocumentEnvironment{lastinstruction}{ m +b }{\\xdef\\instructionbody{\\unexpanded{{\\tt #1}\\instrt&}\\unexpanded\\expandafter{#2}\\unexpanded{\\instrb}}\r\n\\aftergroup\\instructionbody\r\n}{}\r\n\r\n\r\n% ▀█▀ ▒█▄░▒█ ▒█▀▀▀█ ▀▀█▀▀ ▒█▀▀█ ▒█░▒█ ▒█▀▀█ ▀▀█▀▀ ▀█▀ ▒█▀▀▀█ ▒█▄░▒█ 　 ▒█▀▀█ ░█▀▀█ ▒█▀▀█ ▀▀█▀▀ ▒█▀▀▀█ \r\n% ▒█░ ▒█▒█▒█ ░▀▀▀▄▄ ░▒█░░ ▒█▄▄▀ ▒█░▒█ ▒█░░░ ░▒█░░ ▒█░ ▒█░░▒█ ▒█▒█▒█ 　 ▒█▄▄█ ▒█▄▄█ ▒█▄▄▀ ░▒█░░ ░▀▀▀▄▄ \r\n% ▄█▄ ▒█░░▀█ ▒█▄▄▄█ ░▒█░░ ▒█░▒█ ░▀▄▄▀ ▒█▄▄█ ░▒█░░ ▄█▄ ▒█▄▄▄█ ▒█░░▀█ 　 ▒█░░░ ▒█░▒█ ▒█░▒█ ░▒█░░ ▒█▄▄▄█\r\n\r\n% symbolic operation (for the moment nothing special, but we may change it in the future and it will automatically be applied for all items); variant with S with add 3 dots after argument and one with P will add them in front; for multiline expressions\r\n\\newcommand{\\Symbol}[1]{\\scriptsize {\\tt #1} &}\r\n\\newcommand{\\SymbolS}[1]{\\scriptsize {\\tt #1}\\ddd &}\r\n\\newcommand{\\SymbolP}[1]{\\scriptsize \\ddd{\\tt #1} &}\r\n\r\n% flags section + couple shorthands for symbolic flags; note we only really need 6 parameters in this section, but we do need all 7 later on, hence we set first one optional and not use it\r\n\\newcommand{\\Flags}[7][]{{\\tt #2} & {\\tt #3} & {\\tt #4} & {\\tt #5} & {\\tt #6} & {\\tt #7} & &}\r\n\r\n% bitwise opcodes section\r\n\\newcommand{\\OpCode}[3]{{\\tt #1} & {\\tt #2} & {\\tt #3} &}\r\n\r\n% bitwise opcode part with template; top one should be used as much as possible, it will automatically chose the type based on how many letters template has (2 letters will use as is but underline it, 1 letter will assume it's for all 3 bits and will add arrows in front and end)\r\n\\newcommand{\\OCT}[1]{\\StrLen{#1}[\\ParLen]\\IfEq{\\ParLen}{2}{\\underline{#1}}{\\LArrowLine{1ex}#1\\RArrowLine{1ex}}}\r\n% `OCTS` is exactly the same as `OCT` except it will always treat template as single letter, even if 2 letters are used - this is here to nicely wrap s' type of symbols (S=small arrows)\r\n\\newcommand{\\OCTS}[1]{\\LArrowLine{0.8ex}#1\\hspace*{-0.2ex}\\raisebox{0.2ex}{\\tiny'}\\hspace*{-0.2ex}\\RArrowLine{0.7ex}}\r\n\r\n% use `OpRange` and `OpRangeSmall` instead of `OpCode` when you want to have 8 bit \"range\" instead (for 8-bit values for example). The difference is that `OpRangeSmall` assumes parameter is multiple letters while `OpRange` works best for single letters (small = because arrows are smaller)\r\n\\newcommand{\\OpRangeTemplate}[2]{\\multicolumn{3}{l}{\\hspace*{0.25ex}\\LArrowLine{#1}[densely dashed][0.16][1.9] {\\tt #2} \\RArrowLine{#1}[densely dashed][0.16][1.9]} &}\r\n\\newcommand{\\OpRange}[1]{\\OpRangeTemplate{1.85em}{#1}}\r\n\\newcommand{\\OpRangeSmall}[1]{\\OpRangeTemplate{1.3em}{#1}}\r\n\r\n% hex opcode and number of bytes\r\n\\newcommand{\\HexBytes}[1]{\\IfEq{#1}{}{}{{\\tt #1}{\\tiny B}}}\r\n\\newcommand{\\Hex}[2]{{\\tt #1} & \\HexBytes{#2} & &}\r\n\r\n% machine cycles and T states\r\n\\newcommand{\\Cycles}[2]{{\\tt #1} & {\\tt #2} & &}\r\n\r\n% comment in the right column\r\n\\newcommand{\\Comment}[1]{\\scriptsize #1}\r\n\r\n% skips all columns from first up until symbol; for use when extending instruction into multiple lines and we want to have symbolic operation in next line as well\r\n\\newcommand{\\SkipToSymbol}{\\\\ &}\r\n\r\n% skips all columns from `Symbol` up until `OpCode` (or `OpRange`); useful when we don't have anything to write in between, but we do want to have opcode\r\n\\newcommand{\\FromSymbolToOpCode}{& \\multicolumn{6}{l}{} &}\r\n\r\n% skips all columns from first up until the opcodes part. difference between the 2 is insertion of new line before; use `StartWithOpCode` variant for empty line, the other inside instruction block\r\n% note that compiler is not happy with `StartWithOpCode` without using something in front of \\multiline hence given solution\r\n\\newcommand{\\SkipToOpCode}{\\\\ \\multicolumn{9}{l}{} &}\r\n\\newcommand{\\StartWithOpCode}{& \\multicolumn{8}{l}{} &}\r\n\r\n% adds an empty line with optional comment in the last column\r\n% note again that we need to use some char before \\multicolmn to keep compiler happy\r\n\\newcommand{\\Empty}[1]{& \\multicolumn{16}{l}{} & \\Comment{#1} \\\\}\r\n\r\n% similar to `Empty` except the gap is smaller - for creating visual separation between groups of instructions; note: this one doesn't support adding a comment (which doesn't make sense here as there's not enough space for text in this line)\r\n\\newcommand{\\EmptySeparator}{\\\\[-6px]}\r\n\r\n% writes a table break with vertical spacing so table starts at the same vertical postiion as the one on previous page\r\n\\newcommand{\\InstrTableContinue}[1][-2.5ex]{\r\n\t\\vspace*{#1}\r\n\t{\r\n\t\t\\scriptsize\r\n\t\t(continued on next page)\r\n\t}\r\n}\r\n\r\n% ▒█▄░▒█ ▒█▀▀▀█ ▀▀█▀▀ ▒█▀▀▀ ▒█▀▀▀█ 　 ▀▀█▀▀ ░█▀▀█ ▒█▀▀█ ▒█░░░ ▒█▀▀▀ ▒█▀▀▀█ \r\n% ▒█▒█▒█ ▒█░░▒█ ░▒█░░ ▒█▀▀▀ ░▀▀▀▄▄ 　 ░▒█░░ ▒█▄▄█ ▒█▀▀▄ ▒█░░░ ▒█▀▀▀ ░▀▀▀▄▄ \r\n% ▒█░░▀█ ▒█▄▄▄█ ░▒█░░ ▒█▄▄▄ ▒█▄▄▄█ 　 ░▒█░░ ▒█░▒█ ▒█▄▄█ ▒█▄▄█ ▒█▄▄▄ ▒█▄▄▄█\r\n\r\n% defines table for notes; unfortunately I wasn't able to add notes to the same table created using above macros, so we need to use separate one. \r\n% Note: you should embed both tables into minipage to keep them together; while we could create macro for that too, we'd lose ability to collapse in editor\r\n\\NewDocumentEnvironment{notestable}{ +b }{\r\n\t{\r\n\t\t\\scriptsize\r\n\t\t\\setlength{\\fboxsep}{1pt}\t% keep fboxes tight to keep notes vertically short\r\n\t\t\\renewcommand{\\arraystretch}{1}\r\n\t\t\r\n\t\t\\begin{tabularx}{\\textwidth}{lX}\r\n\t\t\tNotes:\r\n\r\n\t\t\t#1\r\n\r\n\t\t\t\\hline\r\n\r\n\t\t\\end{tabularx}\r\n\t}\r\n}{}\r\n\r\n% note item + variants where item is manually split between multiple lines (use \"cont\" variant for first and subsequent, \"end\" for last)\r\n\\newcommand{\\NoteItem}[1]{& #1 \\\\}\r\n\\newcommand{\\NoteItemCont}[1]{& #1 \\\\[-1pt]}\r\n\\newcommand{\\NoteItemEnd}[1]{& #1 \\\\[1pt]}\r\n\r\n% add this above `NoteItem` when there's only single item in the table; in such case compiler creates almost 1 item empty gap on top for some reason... I couldn't find better solution unfortunately and couldn't figure out why this happens\r\n\\newcommand{\\NoteTableSingleItemSpaceCorrection}{\r\n\t\\vspace*{-1ex}\t% single notes table results in some vertical spacing, so we need to manually move it upwards a bit...\r\n}\r\n"
  },
  {
    "path": "zx-next-dev-guide.tex",
    "content": "\\documentclass[12pt,twoside,openright,a4paper]{book}\n\n\\usepackage{fancyhdr}\n\\usepackage{a4wide}\n\\usepackage{etoc}\n\\usepackage{afterpage}\n\\usepackage{amsfonts}\n\\usepackage{anyfontsize}\n\\usepackage{url}\n\\usepackage{array}\n\\usepackage{multicol}\n\\usepackage{multirow}\n\\usepackage{parcolumns}\n\\usepackage{enumitem}\n\\usepackage{etoolbox}\n\\usepackage{mdwlist}\n\\usepackage{tabularx}\n\\usepackage{mathabx}\n\\usepackage{numprint}\n\\usepackage{bigdelim}\n\\usepackage{hhline}\n\\usepackage{xfp}\n\\usepackage{xstring}\n\\usepackage{xparse}\n\\usepackage[table]{xcolor}\n\\usepackage[bottom]{footmisc}\n\\usepackage[nottoc,numbib]{tocbibind}\n\\usepackage[xparse,breakable,skins,listings]{tcolorbox}\n\\usepackage{hyperref}\n\\usepackage{microtype}\n\\usepackage{tikz}\n\\usepackage[\n\ta4paper,\n\tlayout=a4paper,\n\tbindingoffset=0.25cm,\t% offset pages to accomodate for binding\n\twidth=17cm,\t\t\t\t% this matches original LaTeX width, geometry makes it narrower by default\n\ttop=3cm,\t\t\t\t% reduce top edge, too big on default settings\n\tbottom=2.5cm\t\t\t% page numbers should be much lower on the page\n]{geometry}\n\n% include definitions from external files (note: order of inputs is important!)\n\\input{defines}\n\\input{setup}\n\\input{tables}\n\\input{instructions}\n\\input{ports}\n\n\n% ASCII text created with https://fsymbols.com/generators/carty/\n% in case it's not obvious - these large titles are nicely visible in minimap¯\\_(ツ)_/¯\n\n\\begin{document}\n\n\t% note: each section must be `\\include{}`ed; LaTeX will do a `\\clearpage` in front which is what is desired. However if we just want to split larger section into multiple files, `\\input{}` should be used instead which imports the contents of the file as if they were typed here.\n\t% important: regardles of whether `\\include{}` or `\\input{}` is used, `.tex` extension must be ommited. Some LaTeX compilers auto-add the extension so it ends up doubled (`*.tex.tex`) and therefore file cannot be found. Works with MikTEX either way.\n\n\t% ▒█▀▀▀ ▒█▀▀█ ▒█▀▀▀█ ▒█▄░▒█ ▀▀█▀▀ \n\t% ▒█▀▀▀ ▒█▄▄▀ ▒█░░▒█ ▒█▒█▒█ ░▒█░░ \n\t% ▒█░░░ ▒█░▒█ ▒█▄▄▄█ ▒█░░▀█ ░▒█░░\n\n\t\\SetupPageFormattingTitle\n\n\t\\include{chapter-title}\n\n\t\\SetupPageFormattingIntro\n\t\n\t\\include{chapter-copyright}\n\t\\include{chapter-acknowledge}\n\n\t\\SetupPageFormattingTOC\n\n\t\\include{chapter-toc}\n\n\n\t% ▒█▀▀█ ▒█▀▀▀█ ▒█▄░▒█ ▀▀█▀▀ ▒█▀▀▀ ▒█▄░▒█ ▀▀█▀▀ \n\t% ▒█░░░ ▒█░░▒█ ▒█▒█▒█ ░▒█░░ ▒█▀▀▀ ▒█▒█▒█ ░▒█░░ \n\t% ▒█▄▄█ ▒█▄▄▄█ ▒█░░▀█ ░▒█░░ ▒█▄▄▄ ▒█░░▀█ ░▒█░░\n\n\t\\SetupPageFormattingBook\n\n\t\\include{chapter-introduction}\n\n\t\\include{chapter-z80}\n\n\t% note: for Next chapter, we use `\\include{}` for each section; we want each to be treated as its own section, with `\\clearpage` etc.\n\t\\include{chapter-next}\n\t\\include{chapter-next-ports}\n\t\\include{chapter-next-memory}\n\t\\include{chapter-next-dma}\n\t\\include{chapter-next-palette}\n\t\\include{chapter-next-ula}\n\t\\include{chapter-next-layer2}\n\t\\include{chapter-next-tilemap}\n\t\\include{chapter-next-sprites}\n\t\\include{chapter-next-copper}\n\t\\include{chapter-next-sound}\n\t\\include{chapter-next-keyboard}\n\t\\include{chapter-next-interrupts}\n\n\t\\SetupPageFormattingInstructions\n\n\t% note: we use `\\input{}` instead of `\\include{}` here; we just want to split otherwise large file into multiple files but don't want empty pages to be inserted in between. Ideally, we'd `\\input{}` inside chapter file, but LaTeX doesn't support nested inputs, so we need to do it here.\n\t\\include{chapter-instr-glance}\n\t\\input{chapter-instr-glance-8bit-arithmetic}\n\t\\input{chapter-instr-glance-16bit-arithmetic}\n\t\\input{chapter-instr-glance-8bit-load}\n\t\\input{chapter-instr-glance-general}\n\t\\input{chapter-instr-glance-16bit-load}\n\t\\input{chapter-instr-glance-stack}\n\t\\input{chapter-instr-glance-exchange}\n\t\\input{chapter-instr-glance-bit}\n\t\\input{chapter-instr-glance-rotate-shift}\n\t\\input{chapter-instr-glance-jump}\n\t\\input{chapter-instr-glance-call-return}\n\t\\input{chapter-instr-glance-block}\n\t\\input{chapter-instr-glance-input}\n\t\\input{chapter-instr-glance-output}\n\t\\input{chapter-instr-glance-next}\n\t\\input{chapter-instr-glance-alphabetical}\n\n\t\\include{chapter-instr-close}\n\n\n\t% ░█▀▀█ ▒█▀▀█ ▒█▀▀█ ▒█▀▀▀ ▒█▄░▒█ ▒█▀▀▄ ▀█▀ ▀▄▒▄▀ \n\t% ▒█▄▄█ ▒█▄▄█ ▒█▄▄█ ▒█▀▀▀ ▒█▒█▒█ ▒█░▒█ ▒█░ ░▒█░░ \n\t% ▒█░▒█ ▒█░░░ ▒█░░░ ▒█▄▄▄ ▒█░░▀█ ▒█▄▄▀ ▄█▄ ▄▀▒▀▄\n\n\t\\SetupPageFormattingAppendix\n\n\t\\include{chapter-instr-sorted-mnemonic}\n\t\\include{chapter-instr-sorted-opcode}\n\t\\include{chapter-bibliography}\n\t\\include{chapter-license}\n\n\\end{document}\n"
  }
]