{"id":199,"date":"2022-02-11T22:14:36","date_gmt":"2022-02-12T03:14:36","guid":{"rendered":"https:\/\/paulcarbone.com\/50days\/?p=199"},"modified":"2022-02-13T19:23:28","modified_gmt":"2022-02-14T00:23:28","slug":"day-15-ctc-subroutines","status":"publish","type":"post","link":"https:\/\/paulcarbone.com\/50days\/2022\/02\/11\/day-15-ctc-subroutines\/","title":{"rendered":"Day 15: CTC Subroutines"},"content":{"rendered":"<p>lets make a subroutine that can set or clear a selected bit in the CTC control register.\u00a0 To call the routine, we need to tell it:<br \/>\n&#8211; The CTC channel<br \/>\n&#8211; Which bit we&#8217;re adjusting<br \/>\n&#8211; If we&#8217;re setting or clearing the bit<\/p>\n<p>Lets put the CTC channel&#8217;s port on the B register, the bit we&#8217;re adjusting in the C register, and&#8230;. do we use a register or a flag for setting or changing?\u00a0\u00a0 Lets use the zero flag and see what trouble that gets us into.<\/p>\n<p>Oh snap, there&#8217;s bit setting instructions, and they work with any register!\u00a0 set n,A would set the n&#8217;th bit.\u00a0 Can the n be derived from the value of a register?\u00a0 Lets assume not.<\/p>\n<p>Actually, before we do any of that, lets see if we can get relative jumps working correctly.\u00a0 Maybe we can get the number of jumps from the B register, and have a series of SET instructions<\/p>\n<p>Using JR 01, I&#8217;m getting a compiler error &#8220;Byte out of range&#8221;.\u00a0 When I look at the listing, I see the offset listed as EE, which doesn&#8217;t make sense&#8230; AH &#8211; The assembler automatically subtracts 2 to make up for the fact that the PC has already incremented by 2! So when I was trying 1 or 2, it would fail!\u00a0 OK, but 4 fails too&#8230;<\/p>\n<p>There&#8217;s something about how this assembler handles JR that I don&#8217;t understand.<br \/>\nOK &#8211; it looks like you can only use JR with a label in assembler.\u00a0 Oh wait,\u00a0 you can&#8217;t do what I was originally thinking &#8211; you can&#8217;t get the offset of a Jump from a register??<\/p>\n<p><a href=\"http:\/\/cowlark.com\/2018-03-18-z80-arithmetic\/index.html\">From Cowlark.com<\/a> :<br \/>\n&#8220;There is no variable indexing (like the 6502&#8217;s <code>LDA <\/code><code>(ptr), <\/code><code>Y<\/code> addressing mode) at all. The index registers support a constant -128..127 displacement only.&#8221;<\/p>\n<p>WHAAAA?!\u00a0 FUUUUUU&#8230;..<\/p>\n<p>OK, well THAT&#8217;S Stupid.\u00a0 Damn.\u00a0 I thought even the lowly 6802 did that&#8230;<\/p>\n<p>so can we<br \/>\n1 &#8211; modify the operand byte after the JR Instruction?<br \/>\n2 &#8211; use one of the index registers? Does this mean 16 bit addition?<\/p>\n<p>What if you&#8230;<br \/>\n1 &#8211; jumped to a routine<br \/>\n2 &#8211; set IX to the next address<br \/>\n3 &#8211; add C\u00a0 to the IX<br \/>\n4 &#8211; JP(IX)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>lets make a subroutine that can set or clear a selected bit in the CTC control register.\u00a0 To call the routine, we need to tell it: &#8211; The CTC channel &#8211; Which bit we&#8217;re adjusting &#8211; If we&#8217;re setting or &hellip; <a href=\"https:\/\/paulcarbone.com\/50days\/2022\/02\/11\/day-15-ctc-subroutines\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":""},"categories":[5],"tags":[],"class_list":["post-199","post","type-post","status-publish","format-standard","hentry","category-blinkinglights"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/paulcarbone.com\/50days\/wp-json\/wp\/v2\/posts\/199","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/paulcarbone.com\/50days\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/paulcarbone.com\/50days\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/paulcarbone.com\/50days\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/paulcarbone.com\/50days\/wp-json\/wp\/v2\/comments?post=199"}],"version-history":[{"count":4,"href":"https:\/\/paulcarbone.com\/50days\/wp-json\/wp\/v2\/posts\/199\/revisions"}],"predecessor-version":[{"id":203,"href":"https:\/\/paulcarbone.com\/50days\/wp-json\/wp\/v2\/posts\/199\/revisions\/203"}],"wp:attachment":[{"href":"https:\/\/paulcarbone.com\/50days\/wp-json\/wp\/v2\/media?parent=199"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/paulcarbone.com\/50days\/wp-json\/wp\/v2\/categories?post=199"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/paulcarbone.com\/50days\/wp-json\/wp\/v2\/tags?post=199"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}