øAslickproductions.org/forum/index.php?PHPSESSID=5f0fck550j2m4m2fpbtkj2vkm1&topic=1927.msg20634e:/My Web Sites/Slick Productions - FFIV Message Board/slickproductions.org/forum/index249e.htmlslickproductions.org/forum/index.php?PHPSESSID=5f0fck550j2m4m2fpbtkj2vkm1&action=profile;area=showposts;sa=topics;u=262e:/My Web Sites/Slick Productions - FFIV Message Board/slickproductions.org/forum/index249e.html.zx’h^ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÈ0P]¿OKtext/htmlISO-8859-1gzip8:Ö¿ÿÿÿÿÿÿÿÿTue, 10 Mar 2020 22:44:57 GMT0ó°° ®0®P®€§²ð®‘h^7¿ Code improvement

Author Topic: Code improvement  (Read 1676 times)

Madsiur

  • Tunnel Armor
  • *
  • Posts: 149
  • Gender: Male
  • FF6AE coder
    • View Profile
    • Madsiur's Lair
Code improvement
« on: March 17, 2014, 01:14:22 AM »
I'm doing a new event command in FF3us and I had a question regarding my code. I was wondering if there was an ASM command to move the low byte of the A register into the high byte of the A register. Right now I'm doing a bunch of ASL but I'm sure there's a better way to code this... :isuck:

The first offset calculated is: $EB * #$0A00 + #$01C0
The second one is: $EB * #$1000

$EB will never have a value higher than #$03.

Any optimization guru could help me? Thanks

Edit: I just found that the XBA instruction does what I was searching for... Also the TDC instruction can replace the LDA #$0000. I feel kinda stupid posting this thread now...
Code: [Select]
LDA $EB
STA $4202
LDA #$0A
STA $4203
NOP
NOP
LDA $4216
REP #$20
ASL
ASL
ASL
ASL
ASL
ASL
ASL
ASL
ADC #$01C0
STA $1508
LDA #$0000
SEP #$20
LDA $EB
REP #$20
ASL
ASL
ASL
ASL
ASL
ASL
ASL
ASL
ASL
ASL
ASL
ASL
STA $150A
SEP #$20
LDA #$02
JMP $9B5C
« Last Edit: March 17, 2014, 04:37:15 AM by Madsiur »

Lenophis

  • Forum Overlord
  • *
  • Posts: 1,688
  • Gender: Male
  • I sad
    • View Profile
    • Slick Productions
Re: Code improvement
« Reply #1 on: March 17, 2014, 12:32:51 PM »
The byte is EB, and the command is XBA. It exchanges the upper and lower accumulator, whether the accumulator is 8 or 16-bit.

Also the TDC instruction can replace the LDA #$0000. I feel kinda stupid posting this thread now...
TDC in this instance will set the 16-bit accumulator to 0. It only does that because the Direct Page register is set to 0.

Also, $150A? Are you tweaking SPC loads?

119 bugs fixed and counting.

Madsiur

  • Tunnel Armor
  • *
  • Posts: 149
  • Gender: Male
  • FF6AE coder
    • View Profile
    • Madsiur's Lair
Re: Code improvement
« Reply #2 on: March 17, 2014, 04:30:56 PM »
Thank for the infos, it's been months since I had not really touched ASM. Assasin's opcodes document is also very handy.

Also, $150A? Are you tweaking SPC loads?

Well it seems I have read fast but I saw yesteday this thread mentionning possible free ram in $144n and from $1508 to $1513. But after looking again, it seems those bytes are read from on a DMA transfer...

What I'm trying to do is having multiple fonts (4) being changed by a dialogue choice. I thought you guys had a great idea doing it in PB  on a larger scale and in a better way (config menu). I wanted to find free RAM to store the low and middle byte of the offset to load the small and big font from instead of calculating it numerous times. But I guess if no sure free RAM is known I could use SRAM but I would see this as a waste.


Lenophis

  • Forum Overlord
  • *
  • Posts: 1,688
  • Gender: Male
  • I sad
    • View Profile
    • Slick Productions
Re: Code improvement
« Reply #3 on: March 17, 2014, 11:17:30 PM »
Well, since there wasn't really enough VRAM space, we had to load each font individually. We didn't have to calculate anything, since it was faster to just use a LUT.

119 bugs fixed and counting.

assassin

  • Bane of Retards
  • *
  • Posts: 1,033
  • space bears are not gentle!
    • View Profile
    • My Barren Webpage
Re: Code improvement
« Reply #4 on: March 18, 2014, 06:09:31 PM »
Well it seems I have read fast but I saw yesteday this thread mentionning possible free ram in $144n and from $1508 to $1513. But after looking again, it seems those bytes are read from on a DMA transfer...

are you sure it's not the probable false debugger alarm i mentioned in that thread?  are you checking with Geiger, or something else?

Madsiur

  • Tunnel Armor
  • *
  • Posts: 149
  • Gender: Male
  • FF6AE coder
    • View Profile
    • Madsiur's Lair
Re: Code improvement
« Reply #5 on: March 18, 2014, 09:09:11 PM »
are you sure it's not the probable false debugger alarm i mentioned in that thread? are you checking with Geiger, or something else?

After reading for the second time your initial post, yes it's the probable false debugger alarm. I understand you can never be 100% sure that a RAM address is never read or write unless you do extensive testing and research. At least I know now I can use the mentioned byte with a certain degree of confidence.

I haven't checked with Geiger, but did you mean by that to make a RAM dump before and after the C0/56B1 routine and compare both dumps?

assassin

  • Bane of Retards
  • *
  • Posts: 1,033
  • space bears are not gentle!
    • View Profile
    • My Barren Webpage
Re: Code improvement
« Reply #6 on: March 18, 2014, 09:25:55 PM »
no; i'd thought that "But after looking again" meant you tried it out, so i wanted to know which emulator.

that said, your idea about the RAM dumps is good.

Madsiur

  • Tunnel Armor
  • *
  • Posts: 149
  • Gender: Male
  • FF6AE coder
    • View Profile
    • Madsiur's Lair
Re: Code improvement
« Reply #7 on: March 29, 2014, 08:44:07 PM »
I thought I'd post my question here since it is related to coding. I have a routine in bank C0 that would be ideally accessed from other bank and from the C0 bank as well...

Is there a way to detect if I'm coming from another bank thus I could do either a RTL otherwise branch and do a RTS?


If, not I suppose I should best put my routine in a bank that it will never be used in and always finish by a RTL, since it will always be accessed from another bank?

Lenophis

  • Forum Overlord
  • *
  • Posts: 1,688
  • Gender: Male
  • I sad
    • View Profile
    • Slick Productions
Re: Code improvement
« Reply #8 on: March 29, 2014, 11:00:33 PM »
You could guess with loading from the stack, but there's no way to assure that's 100% accurate. You could do what C1 does, which has routines JSL'ed into, then JSRs to that routine, followed by an RTL. It's a mess. Alternatively, just make it a RTL and always JSL to it.

119 bugs fixed and counting.