{"id":2703,"date":"2022-12-15T08:31:48","date_gmt":"2022-12-15T08:31:48","guid":{"rendered":"https:\/\/cml-a.com\/content\/?p=2703"},"modified":"2022-12-15T08:31:48","modified_gmt":"2022-12-15T08:31:48","slug":"cursed","status":"publish","type":"post","link":"https:\/\/cml-a.com\/content\/2022\/12\/15\/cursed\/","title":{"rendered":"Cursed"},"content":{"rendered":"\n<p>Consider this 65816 program<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.cpu \"65816\"                        \n\nPUTS = $00101C                      \nPUTC = $001018                      \n* = $00FFFC\nRESET   .word &lt;>START\n\n* = $002000\nSTART   CLC                         ; Make sure we're native mode\n        XCE\n\n        REP #$30\n        .al\n        .xl\n        JSR MSG1\n\n        SEP #$30  ; Set 8bit axy\nDIV\n\n;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n; Value      ; 8bit interpretation    ; 16bit interpretation\n;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n;            ;                        ;\n.byte $A9    ; LDA #$3A               ; LDA #$3A3A                    \n.byte $3A    ;                        ;\n.byte $3A    ; DEC A                  ;       \n;            ;                        ;        \n.byte $29    ; AND #$39               ; AND #$3A39         \n.byte $39    ;                        ;   \n;            ;                        ;      \n.byte $3A    ; DEC A                  ;       \n;            ;                        ;      \n.byte $29    ; AND #$38               ; AND #$2038       \n.byte $38    ;                        ;   \n;            ;                        ;      \n.byte $20    ; JSR $20EA              ;                                    \n.byte $EA    ;                        ; NOP\n;            ;                        ;      \n.byte $20    ;                        ; JSR $20E0\n;            ;                        ;      \n.byte $E0    ; \n.byte $20    ; \n\n        TAX\n        JSR CLRB\n        JSL PUTS \n        JSR MSG2\n\nDONE    NOP         ; Spin\n        BRA DONE\n\n* = $002038\nMODE16 .null \"16\"\nPRE   .null \"This is in \"\nSUF   .null \"-bit mode.     \"\n\nCLRB    LDA #$0000\n        PHA\n        PLB\n        PLB\n        RTS\n\nMSG1    JSR CLRB\n        LDX #&lt;>PRE\n        JSL PUTS \n        RTS\n\nMSG2    JSR CLRB\n        LDX #&lt;>SUF\n        JSL PUTS \n        RTS\n\n* = $0020E0\n        RTS\n\n* = $0020EA\n        JSL PUTC\n        REP #$30\n        .al\n        .xl\n        JSR MSG2\n        JSR MSG1\n        JMP DIV<\/code><\/pre>\n\n\n\n<p> for C256 Foenix, assembled with <a href=\"https:\/\/sourceforge.net\/projects\/tass64\/\">64tass<\/a>.<\/p>\n\n\n\n<p>When run, the output looks like<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/cml-a.com\/content\/wp-content\/uploads\/2022\/12\/image-11.png\" alt=\"\" class=\"wp-image-2705\"\/><\/figure>\n\n\n\n<p>Explanation: the part of the program labeled 'DIV' will run twice, under different interpretations. First in 8bit mode, then in 16bit mode, for displaying the '8' and '16' printable characters respectively.  <\/p>\n\n\n\n<p>Normally code in 8bit is garbage when interpreted in 16bit mode and vice-versa. These ops were specially chosen so that they are valid in both with different behavior<\/p>\n\n\n\n<p>Because it's not possible to express the reinterpretation idea in an assembly language, this just dumps the code bytes in the middle of the program and there's 2 columns of commented-out language explaining what the bytes do. The 2 columns are one for 8bit and one for 16bit.<\/p>\n\n\n\n<p>I wrote it as a silly test. It's a test for the debugger. It's to see how it might display in a 'source-style' debugger. When running it I pass the debugger my source file listing. <\/p>\n\n\n\n<p>It goes... not great<\/p>\n\n\n\n<figure class=\"wp-block-video\"><video controls src=\"https:\/\/cml-a.com\/content\/wp-content\/uploads\/2022\/12\/FoenixIDEDebug2.mp4\"><\/video><\/figure>\n\n\n\n<p>'Transcript debugging' described <a href=\"https:\/\/cml-a.com\/content\/2022\/12\/14\/transcript-debugger\/\">in this earlier post<\/a> fixes it, it's 100% coherent  and matches the source. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/cml-a.com\/content\/wp-content\/uploads\/2022\/12\/image-12.png\"><img decoding=\"async\" src=\"https:\/\/cml-a.com\/content\/wp-content\/uploads\/2022\/12\/image-12-1024x382.png\" alt=\"\" class=\"wp-image-2707\"\/><\/a><\/figure>\n\n\n\n<p>So a good vote to use that kind of debugger for this type of thing.<\/p>\n\n\n\n<p>Full source code available here:<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/clandrew\/experiments\/blob\/main\/div\/div.s\">https:\/\/github.com\/clandrew\/experiments\/blob\/main\/div\/div.s<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Consider this 65816 program for C256 Foenix, assembled with 64tass. When run, the output looks like Explanation: the part of the program labeled &#8216;DIV&#8217; will run twice, under different interpretations. First in 8bit mode, then in 16bit mode, for displaying the &#8216;8&#8217; and &#8217;16&#8217; printable characters respectively. Normally code in 8bit is garbage when interpreted [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[4,178,200],"class_list":["post-2703","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-4","tag-software-development-project","tag-tools"],"_links":{"self":[{"href":"https:\/\/cml-a.com\/content\/wp-json\/wp\/v2\/posts\/2703","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cml-a.com\/content\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cml-a.com\/content\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cml-a.com\/content\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cml-a.com\/content\/wp-json\/wp\/v2\/comments?post=2703"}],"version-history":[{"count":0,"href":"https:\/\/cml-a.com\/content\/wp-json\/wp\/v2\/posts\/2703\/revisions"}],"wp:attachment":[{"href":"https:\/\/cml-a.com\/content\/wp-json\/wp\/v2\/media?parent=2703"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cml-a.com\/content\/wp-json\/wp\/v2\/categories?post=2703"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cml-a.com\/content\/wp-json\/wp\/v2\/tags?post=2703"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}