News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: Practicality of BRL?  (Read 3029 times)

FinS

  • Full Member
  • ***
  • Posts: 192
    • View Profile
    • nothing much
Practicality of BRL?
« on: March 15, 2014, 09:50:13 am »
I was just comparing the SNES instructions "Jump" and "Branch Long" and it occurred to me there is no particular advantage for branching long. It takes 1 additional cycle and has a smaller range than the jump instruction while using the same number of bytes.

Anyone have any thoughts or examples of what purpose it might serve? Maybe it's got something to do with ease of programming.

BRPXQZME

  • Hero Member
  • *****
  • Posts: 4572
  • じー
    • View Profile
    • The BRPXQZME Network
Re: Practicality of BRL?
« Reply #1 on: March 15, 2014, 10:02:19 am »
Relative jumping is a bit more important if you have, say, an OS loading executables. It needs to be able to change the location of the code without touching its functionality. If you can start from the assumption that everything is always burned into a ROM and never ever moves, JMP as much as you need to, I guess.
we are in a horrible and deadly danger

FinS

  • Full Member
  • ***
  • Posts: 192
    • View Profile
    • nothing much
Re: Practicality of BRL?
« Reply #2 on: March 15, 2014, 03:27:26 pm »
So the instruction set must have been designed with other purposes in mind and basically on the SNES branch long doesn't have any necessary use.

FAST6191

  • Hero Member
  • *****
  • Posts: 2611
    • View Profile
Re: Practicality of BRL?
« Reply #3 on: March 15, 2014, 07:14:06 pm »
Then and now designing with a commodity processor is not a bad idea.

As for its use in the wild on the SNES.... I am sure I could cook up something with a genuine advantage to it (some kind of dynamic allocation). I have not pulled apart nearly enough SNES games to start spotting exceptions like that though. Also a bit of higher level language programming was known on the SNES so you might find something there depending upon how good compilers were.

FinS

  • Full Member
  • ***
  • Posts: 192
    • View Profile
    • nothing much
Re: Practicality of BRL?
« Reply #4 on: March 15, 2014, 08:27:11 pm »
I could almost imagine something with some code executed from ram. There doesn't seem to be any games that do that though because Snes9x does not even except BRL in relation to ram (either into, out of, or through it). Those guys would normally modify their emulator to compensate for any game that would require something like that.

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 6923
  • *sigh* A changed avatar. Big deal.
    • View Profile
Re: Practicality of BRL?
« Reply #5 on: March 15, 2014, 09:52:35 pm »
Games executing code out of WRAM?
I thought I saw Popful Mail doing that but I'm not certain.
"My watch says 30 chickens" Google, 2018

FinS

  • Full Member
  • ***
  • Posts: 192
    • View Profile
    • nothing much
Re: Practicality of BRL?
« Reply #6 on: March 15, 2014, 10:22:26 pm »
Here's what Ogre Battle does to navigate to out of bank subroutines that only have a regular return. It uses JSR and jumps but no branching. First it jumps to ram, snags the bank for safe keeping on the stack, then back out to rom then proceeds to build a return to the ram position then a return long to the original rom position then a return long to the position it wants to jump to which was inserted in the rom after the program address it came from.

Code: [Select]
$03/E55B 20 99 11    JSR $1199  [$03:1199]   A:0020 X:7800 Y:0080 P:envMxdizC
$03/1199 4B          PHK                     A:0020 X:7800 Y:0080 P:envMxdizC
$03/119A 5C 8E 9F 00 JMP $009F8E[$00:9F8E]   A:0020 X:7800 Y:0080 P:envMxdizC
$00/9F8E 8B          PHB                     A:0020 X:7800 Y:0080 P:envMxdizC
$00/9F8F F4 9D 11    PEA $119D               A:0020 X:7800 Y:0080 P:envMxdizC
$00/9F92 0B          PHD                     A:0020 X:7800 Y:0080 P:envMxdizC
$00/9F93 4B          PHK                     A:0020 X:7800 Y:0080 P:envMxdizC
$00/9F94 08          PHP                     A:0020 X:7800 Y:0080 P:envMxdizC
$00/9F95 C2 20       REP #$20                A:0020 X:7800 Y:0080 P:envMxdizC
$00/9F97 0B          PHD                     A:0020 X:7800 Y:0080 P:envmxdizC
$00/9F98 48          PHA                     A:0020 X:7800 Y:0080 P:envmxdizC
$00/9F99 3B          TSC                     A:0020 X:7800 Y:0080 P:envmxdizC
$00/9F9A 5B          TCD                     A:1FA7 X:7800 Y:0080 P:envmxdizC
$00/9F9B D4 0D PEI ($0D)        [$E55D]      A:1FA7 X:7800 Y:0080 P:envmxdizC
$00/9F9D A5 0B       LDA $0B    [$00:1FB2]   A:1FA7 X:7800 Y:0080 P:envmxdizC
$00/9F9F 85 0D       STA $0D    [$00:1FB4]   A:0303 X:7800 Y:0080 P:envmxdizC
$00/9FA1 68          PLA                     A:0303 X:7800 Y:0080 P:envmxdizC
$00/9FA2 85 0C       STA $0C    [$00:1FB3]   A:E55D X:7800 Y:0080 P:eNvmxdizC
$00/9FA4 E6 0C       INC $0C    [$00:1FB3]   A:E55D X:7800 Y:0080 P:eNvmxdizC
$00/9FA6 A7 0C       LDA [$0C]  [$03:E55E]   A:E55D X:7800 Y:0080 P:eNvmxdizC
$00/9FA8 E6 0C       INC $0C    [$00:1FB3]   A:A0EC X:7800 Y:0080 P:eNvmxdizC
$00/9FAA 3A          DEC A                   A:A0EC X:7800 Y:0080 P:eNvmxdizC
$00/9FAB 85 06       STA $06    [$00:1FAD]   A:A0EB X:7800 Y:0080 P:eNvmxdizC
$00/9FAD E6 0C       INC $0C    [$00:1FB3]   A:A0EB X:7800 Y:0080 P:eNvmxdizC
$00/9FAF E2 20       SEP #$20                A:A0EB X:7800 Y:0080 P:eNvmxdizC
$00/9FB1 A7 0C       LDA [$0C]  [$03:E560]   A:A0EB X:7800 Y:0080 P:eNvMxdizC
$00/9FB3 85 08       STA $08    [$00:1FAF]   A:A000 X:7800 Y:0080 P:envMxdiZC
$00/9FB5 48          PHA                     A:A000 X:7800 Y:0080 P:envMxdiZC
$00/9FB6 AB          PLB                     A:A000 X:7800 Y:0080 P:envMxdiZC
$00/9FB7 C2 20       REP #$20                A:A000 X:7800 Y:0080 P:envMxdiZC
$00/9FB9 68          PLA                     A:A000 X:7800 Y:0080 P:envmxdiZC
$00/9FBA 2B          PLD                     A:0020 X:7800 Y:0080 P:envmxdizC
$00/9FBB 28          PLP                     A:0020 X:7800 Y:0080 P:envmxdiZC
$00/9FBC 6B          RTL                     A:0020 X:7800 Y:0080 P:envMxdizC

The subroutine it wanted to access was run through here.

Afterwards the rts sends it back to the ram position where it proceeds to return long back to the original program location just after the inserted address.
Code: [Select]
$00/119E AB          PLB                     A:1120 X:0F99 Y:0080 P:envMxdizc
$00/119F 6B          RTL                     A:1120 X:0F99 Y:0080 P:envMxdizc

I rewrote this at one time so it worked more smoothly and was easier to understand but I'm not sure what I did with it.

BRPXQZME

  • Hero Member
  • *****
  • Posts: 4572
  • じー
    • View Profile
    • The BRPXQZME Network
Re: Practicality of BRL?
« Reply #7 on: March 16, 2014, 10:19:01 am »
So the instruction set must have been designed with other purposes in mind and basically on the SNES branch long doesn't have any necessary use.
The way I see it. As far as I know the architecture was largely designed with a certain <10-year-old Cupertino garage startup in mind....
we are in a horrible and deadly danger

FinS

  • Full Member
  • ***
  • Posts: 192
    • View Profile
    • nothing much
Re: Practicality of BRL?
« Reply #8 on: March 16, 2014, 11:20:43 am »
Looks like the IIGS could hold up to 8 MB of ram which could warrant some long branching for ram executions. Thanks BRP.