+atari2600land Posted February 10, 2021 Share Posted February 10, 2021 In Odyssey 2 and Channel F assembly, there is a function which inverts the number, so like if it was, say, 167 and you call the function, the number would change to 88. I was just wondering if there is a way to do this in Atari 2600 assembly and if so, how? Quote Link to comment https://forums.atariage.com/topic/316989-inverting-values/ Share on other sites More sharing options...
CPUWIZ Posted February 10, 2021 Share Posted February 10, 2021 Well, invert would be EOR #$FF, but 0xB0 (167) EOR 0xFF = 0x4F (79). Quote Link to comment https://forums.atariage.com/topic/316989-inverting-values/#findComment-4749274 Share on other sites More sharing options...
+Karl G Posted February 10, 2021 Share Posted February 10, 2021 I get 88. By "invert", do you mean reverse the bits, or something else? Quote Link to comment https://forums.atariage.com/topic/316989-inverting-values/#findComment-4749290 Share on other sites More sharing options...
CPUWIZ Posted February 10, 2021 Share Posted February 10, 2021 1 hour ago, Karl G said: I get 88. Spoiler. Quote Link to comment https://forums.atariage.com/topic/316989-inverting-values/#findComment-4749355 Share on other sites More sharing options...
+atari2600land Posted February 10, 2021 Author Share Posted February 10, 2021 Basically, what I need to do is get the number on the left column to get to the number on the right column (and the number on the right column to be the number on the left). 174 80 173 81 172 82 171 83 170 84 169 85 168 86 167 87 166 88 165 89 164 90 163 91 162 92 161 93 160 94 159 95 158 96 157 97 156 98 155 99 154 100 153 101 152 102 151 103 150 104 149 105 148 106 147 107 146 108 145 109 144 110 143 111 142 112 141 113 140 114 139 115 138 116 137 117 136 118 135 119 134 120 133 121 132 122 131 123 130 124 129 125 128 126 127 127 All I can tell from this is that if you add all the rows, they all equal 254. Quote Link to comment https://forums.atariage.com/topic/316989-inverting-values/#findComment-4749367 Share on other sites More sharing options...
+Andrew Davie Posted February 10, 2021 Share Posted February 10, 2021 sec lda #254 sbc value Quote Link to comment https://forums.atariage.com/topic/316989-inverting-values/#findComment-4749393 Share on other sites More sharing options...
Thomas Jentzsch Posted February 10, 2021 Share Posted February 10, 2021 lda value eor #$ff clc adc #1 Quote Link to comment https://forums.atariage.com/topic/316989-inverting-values/#findComment-4749635 Share on other sites More sharing options...
+atari2600land Posted February 10, 2021 Author Share Posted February 10, 2021 Thanks for the help, I really appreciate it. Seems like there's more than one way to do it. Quote Link to comment https://forums.atariage.com/topic/316989-inverting-values/#findComment-4749755 Share on other sites More sharing options...
+Andrew Davie Posted February 10, 2021 Share Posted February 10, 2021 5 hours ago, Thomas Jentzsch said: lda value eor #$ff clc adc #1 That negates a value. That's not what was asked for. The requirement is A+B = 254. Given A, calculate B. I don't think your example will give the results from the table shown. 1 1 Quote Link to comment https://forums.atariage.com/topic/316989-inverting-values/#findComment-4749960 Share on other sites More sharing options...
Omegamatrix Posted February 11, 2021 Share Posted February 11, 2021 I believe what Thomas meant was: eor #$FF sec sbc #1 That will fulfill the requirement is A+B = 254. Given A, calculate B. It saves a byte of ram and 1 cycle over subtracting using a ZP ram location. In the rare case that X is preloaded with #$FF there is an illegal optimization. The resulting 'B' value ends up in the X register: eor #$FF sbx #1 1 Quote Link to comment https://forums.atariage.com/topic/316989-inverting-values/#findComment-4750230 Share on other sites More sharing options...
Thomas Jentzsch Posted February 11, 2021 Share Posted February 11, 2021 9 hours ago, Andrew Davie said: That negates a value. That's not what was asked for. The requirement is A+B = 254. Given A, calculate B. I don't think your example will give the results from the table shown. You are right. Quote Link to comment https://forums.atariage.com/topic/316989-inverting-values/#findComment-4750313 Share on other sites More sharing options...
+Andrew Davie Posted February 11, 2021 Share Posted February 11, 2021 3 hours ago, Omegamatrix said: I believe what Thomas meant was: eor #$FF sec sbc #1 That will fulfill the requirement is A+B = 254. Given A, calculate B. It saves a byte of ram and 1 cycle over subtracting using a ZP ram location. Well, assuming you have the value in the accumulator to start with. That's cheating 1 Quote Link to comment https://forums.atariage.com/topic/316989-inverting-values/#findComment-4750320 Share on other sites More sharing options...
Thomas Jentzsch Posted February 11, 2021 Share Posted February 11, 2021 13 hours ago, Andrew Davie said: Well, assuming you have the value in the accumulator to start with. That's cheating He he, your code assumed the value in a variable. Quote Link to comment https://forums.atariage.com/topic/316989-inverting-values/#findComment-4750784 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.