Mallard Games Posted July 18, 2019 Share Posted July 18, 2019 Hi, I'm getting the following error: Quote Illegal Addressing mode here is the code i'm using: GetRandomByte asl eor asl eor asl asl eor asl rol ; performs a series of shifts and bit operations rts the error is specifically with eor which I am trying to eor the value of the accumulator with the value itself. Is there any way to do it or must i use a RAM location? Quote Link to comment Share on other sites More sharing options...
+Andrew Davie Posted July 18, 2019 Share Posted July 18, 2019 40 minutes ago, Mallard Games said: Hi, I'm getting the following error: here is the code i'm using: GetRandomByte asl eor asl eor asl asl eor asl rol ; performs a series of shifts and bit operations rts the error is specifically with eor which I am trying to eor the value of the accumulator with the value itself. Is there any way to do it or must i use a RAM location? "eor" requires a value to use. "eor #1", "eor variable", "eor (address),y" etc. If you want to eor the accumulator with itself, the answer is of course zero so that's clearly not what you want. 1 Quote Link to comment Share on other sites More sharing options...
Mallard Games Posted July 18, 2019 Author Share Posted July 18, 2019 2 minutes ago, Andrew Davie said: "eor" requires a value to use. "eor #1", "eor variable", "eor (address),y" etc. If you want to eor the accumulator with itself, the answer is of course zero so that's clearly not what you want. What do you mean by "zero"? eor #$00 Quote Link to comment Share on other sites More sharing options...
+Andrew Davie Posted July 18, 2019 Share Posted July 18, 2019 4 minutes ago, Mallard Games said: What do you mean by "zero"? eor #$00 Any value "exclusive-or"'d with itself... results in zero. so when you write just "eor" I'm wondering what you're trying to do, and pointing out you need a value. If your intention was to "eor" the accumulator with itself, then you would end up with zero anyway, so clearly that's not what you're trying to do. Quote Link to comment Share on other sites More sharing options...
Mallard Games Posted July 18, 2019 Author Share Posted July 18, 2019 (edited) 1 hour ago, Andrew Davie said: Any value "exclusive-or"'d with itself... results in zero. so when you write just "eor" I'm wondering what you're trying to do, and pointing out you need a value. If your intention was to "eor" the accumulator with itself, then you would end up with zero anyway, so clearly that's not what you're trying to do. Portablize this modified bit of code: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Subroutine to generate a Linear-Feedback Shift Register random number ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Generate a LFSR random number ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; GetRandomByte lda Random asl eor Random asl eor Random asl asl eor Random asl rol Random ; performs a series of shifts and bit operations rts So it works with any game out of the box, without requiring an extra RAM variable. Edited July 18, 2019 by Mallard Games Quote Link to comment Share on other sites More sharing options...
+splendidnut Posted July 18, 2019 Share Posted July 18, 2019 8 hours ago, Mallard Games said: Portablize this modified bit of code: ... So it works with any game out of the box, without requiring an extra RAM variable. That code is easily usable in any 6502 program/game but it will always require a single RAM variable. The RAM variable is part of the "feedback". A linear-feedback shift register works by using the LAST random number to generate the next one. https://en.wikipedia.org/wiki/Linear-feedback_shift_register If you don't want the "extra" ram variable, you'll have to find another way to generate a random number. --- Also, here's a 6502 instruction/opcode reference guide: http://www.6502.org/tutorials/6502opcodes.html 1 Quote Link to comment Share on other sites More sharing options...
Nukey Shay Posted July 20, 2019 Share Posted July 20, 2019 ...via frame counter, delay between input, etc. Seeding with INTIM on cold start is probably the only way to arrive at something truly random, tho. Almost all games have some Ram which can be reclaimed (or that is unused) in order to store it. BTW nothing works "out of the box". Even your own subroutine implies enough Romspace and cycle time to execute (provided that the game even uses a stack). Quote Link to comment 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.