Avoiding using signed multiplication while in Mode 7

Discussion of hardware and software development for Super NES and Super Famicom. See the SNESdev wiki for more information.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
psycopathicteen
Posts: 3140
Joined: Wed May 19, 2010 6:12 pm

Re: Avoiding using signed multiplication while in Mode 7

Post by psycopathicteen »

Unfortunately my sprite rotation routine happens outside of the main loop, and can be interrupted by NMI at any time, and uses multiplication registers so it needs to disable interrupts. Doing so might cause it to go into NMI pretty late, causing black bars if the DMA is also being used.
User avatar
HihiDanni
Posts: 186
Joined: Tue Apr 05, 2016 5:25 pm

Re: Avoiding using signed multiplication while in Mode 7

Post by HihiDanni »

The multiplication registers do their work in the background, and software only has to read and write them, right? I'd think that the state of those registers would survive the NMI interrupt, as long as you don't touch those registers in your interrupt routine. Let me know if I'm wrong though.
SNES NTSC 2/1/3 1CHIP | serial number UN318588627
93143
Posts: 1717
Joined: Fri Jul 04, 2014 9:31 pm

Re: Avoiding using signed multiplication while in Mode 7

Post by 93143 »

psycopathicteen wrote:uses multiplication registers so it needs to disable interrupts.
I mean, that's only a problem if the interrupt is using the multiplier too, right? I suppose one might wish to leave the option open...

Alternately, you could dedicate a couple of banks to an 8x8 multiplication table. I think the ALU should be a bit faster, especially if you use the waiting time intelligently, but you could use tabulated multiplication in interrupts without worrying about what the main code is doing, and if you wanted to waste four banks instead of two you could do 7x7 signed multiply just as easily.

Let's see:

Code: Select all

sep #$20
lda A
xba
lda B
rep #$20
asl
tax
bcs +
lda.l multable_low,x
bra ++
+ lda.l multable_high,x
++
Is there a better way to do that?

Hold on. If you split the results into low-byte and high-byte tables:

Code: Select all

sep #$20
lda A
xba
lda B
tax
lda.l multable_hib,x
xba
lda.l multable_lob,x
rep #$20
...exactly the same length (but more predictable). Huh.
Last edited by 93143 on Mon Jan 29, 2018 4:54 pm, edited 1 time in total.
psycopathicteen
Posts: 3140
Joined: Wed May 19, 2010 6:12 pm

Re: Avoiding using signed multiplication while in Mode 7

Post by psycopathicteen »

The entire game runs in the "NMI" code. All that's being done outside of NMI, is rotating sprites, and that takes many frames to finish.

I decided to check what scanline the code is on before doing the multiplication and if it is on the last 2 lines in a frame it waits for the next frame.
psycopathicteen
Posts: 3140
Joined: Wed May 19, 2010 6:12 pm

Re: Avoiding using signed multiplication while in Mode 7

Post by psycopathicteen »

Now I just need to figure out how to seamlessly switch to Mode 7 mid level. I'd have to make an alternate version of the tile-map scrolling code. I can probably limit the first area of the level to use the second 16kB chunk of VRAM, and only use the first half the Mode-7 layer's memory.
Post Reply