News: 11 March 2016 - Forum Rules

Author Topic: bSNES Issue *SOLVED*  (Read 2592 times)

justin3009

  • Hero Member
  • *****
  • Posts: 1664
  • Welp
    • View Profile
bSNES Issue *SOLVED*
« on: September 16, 2016, 02:24:48 pm »
Code: [Select]
c0f420 jsr $f430     [c0f430] A:0000 X:f6d8 Y:0420 S:01e9 D:0000 DB:83 nvmxdIZC V: 15 H: 800 F: 7
c0f430 ldx #$7000             A:0000 X:f6d8 Y:0420 S:01e7 D:0000 DB:83 nvmxdIZC V: 15 H: 840 F: 7
c0f433 stx $0002     [830002] A:0000 X:7000 Y:0420 S:01e7 D:0000 DB:83 nvmxdIzC V: 15 H: 858 F: 7
c0f436 sep #$20               A:0000 X:7000 Y:0420 S:01e7 D:0000 DB:83 nvmxdIzC V: 15 H: 892 F: 7
c0f438 rep #$10               A:0000 X:7000 Y:0420 S:01e7 D:0000 DB:83 nvMxdIzC V: 15 H: 910 F: 7

c0f43a lda $1946     [831946] A:0000 X:7000 Y:0420 S:01e7 D:0000 DB:83 nvMxdIzC V: 15 H: 928 F: 7
c0f43d sta $4204     [834204] A:0000 X:7000 Y:0420 S:01e7 D:0000 DB:83 nvMxdIZC V: 15 H: 954 F: 7
c0f440 lda #$03               A:0000 X:7000 Y:0420 S:01e7 D:0000 DB:83 nvMxdIZC V: 15 H: 978 F: 7
c0f442 sta $4206     [834206] A:0003 X:7000 Y:0420 S:01e7 D:0000 DB:83 nvMxdIzC V: 15 H: 990 F: 7
c0f445 ldx $4214     [834214] A:0003 X:7000 Y:0420 S:01e7 D:0000 DB:83 nvMxdIzC V: 15 H:1014 F: 7

c0f448 lda $c0f46b,x [c0fa1b] A:0003 X:05b0 Y:0420 S:01e7 D:0000 DB:83 nvMxdIzC V: 15 H:1044 F: 7

So, this code works JUST fine on SNES9X and ZSNES (Yes I know it's inaccurate, just wanted to test on another emulator).  But some reason when using bSNES this whole thing just comes out as a terrible, terrible mess.

What it's doing is it's loading 7E:1946 (Current Item Page) then stores it to 4204.  Then it loads 03 as a hard set value and stores it to 4206 and then X is loaded from 4214 to get the outcome but as you can see it's pulling a completely whacked out value from nowhere, yet, on SNES9X it works just fine.

Is my code just screwy?
« Last Edit: September 16, 2016, 02:41:02 pm by justin3009 »
'We have to find some way to incorporate the general civilians in the plot.'

'We'll kill off children in the Juuban district with an infection where they cough up blood and are found hanging themselves from cherry blossom trees.'

AWJ

  • Full Member
  • ***
  • Posts: 105
    • View Profile
Re: bSNES Issue
« Reply #1 on: September 16, 2016, 02:35:38 pm »
The SNES multiplier/divider isn't instantaneous. After writing the second operand and before reading the result, you have to wait 8 CPU cycles for a multiply and 16 CPU cycles for a divide. If you can't arrange your code to do useful work during the delay, you'll just have to insert 4 or 8 NOPs.

justin3009

  • Hero Member
  • *****
  • Posts: 1664
  • Welp
    • View Profile
Re: bSNES Issue
« Reply #2 on: September 16, 2016, 02:36:37 pm »
OH!  I had no idea, so THAT'S why games sometimes have those random NOPs!  That makes SO much sense now!
'We have to find some way to incorporate the general civilians in the plot.'

'We'll kill off children in the Juuban district with an infection where they cough up blood and are found hanging themselves from cherry blossom trees.'

AWJ

  • Full Member
  • ***
  • Posts: 105
    • View Profile
Re: bSNES Issue *SOLVED*
« Reply #3 on: September 16, 2016, 02:51:07 pm »
I noticed another potential problem with your code: you're only setting the lower 8 bits of the dividend ($4204). If you're only doing an 8-bit / 8-bit division, you should do a STZ $4205 to clear out the upper byte.

justin3009

  • Hero Member
  • *****
  • Posts: 1664
  • Welp
    • View Profile
Re: bSNES Issue *SOLVED*
« Reply #4 on: September 16, 2016, 02:54:16 pm »
Done and done, all set!  Thank you for the help!
'We have to find some way to incorporate the general civilians in the plot.'

'We'll kill off children in the Juuban district with an infection where they cough up blood and are found hanging themselves from cherry blossom trees.'