Jump to content

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

 

  • Like 1

Share this post


Link to post
Share on other sites
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

 

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Posted (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 by Mallard Games

Share this post


Link to post
Share on other sites
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

 

  • Like 1

Share this post


Link to post
Share on other sites

...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).

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...