News:

Don't forget to visit the main site! There's lots of helpful docs, patches, and more!

Main Menu

[SM] making the Door ASM change the tileset

Started by RealRed, June 16, 2014, 09:39:35 PM

Previous topic - Next topic

RealRed

I have absolutely no knowledge of ASM, but. Could someone help me write a door ASM that changes the tileset that a room loads?
For example, you're entering a door. The door leads to the same exact room you're already in, and the room uses tileset 10. could I make a door ASM that makes the room load tileset 1 instead upon entering?

If it would be overcomplicated, I have no issue just using a new room header. I was just hoping to do this for the purpose of recycling rooms with multiple events.

P.JBoy


LDY #$07C0
LDX #{E7A7+Tileset*2}
LDA #$0008
MVN $8F $7E
RTS


Should do it
...

RealRed

awesome. so I guess if I slap "lorom" at the top and org where I want to put it, everything should be fine to compile? Also, what are the variables? or more specifically, what value do I modify to determine what tileset is chosen? (If it's supposed to be obvious, I have no idea how the {E7A7+Tileset*2} works)

Szandor

E7A7 I think is the location of the pointer table defining the tilesets. So, if you just replace 'Tileset' with the tileset number you want, it should do what you want. The only thing, Tileset might need to be in hex.

Detailed explanation: Each pointer to the location of the tileset is 2 bytes wide. E7A7 is the location of the start of the table. So to find the location of tileset 5, it would be E7A7+5*2 = E7A7+A = E7B1. But the assembler can do the math for you, so you can just plug in the tileset number in place of Tileset and you should be good to go.

RealRed

#4
Sorry it took so long for me to test this. didn't get a chance.
So I compiled it to $8FF360. that worked out fine. unfortunately though, the code isn't actually doing anything (although it DOESN'T crash the game, which is a start!)
The string seems awfully short. I'm not sure if something was skipped. Here's what it gave me:
A0 C0 07 A9 08 00 60
this kind of begs the question... why did it skip the LDX? and the MVN?
so I went to the asm file and changed LDX #{E7A7+1*2} to simply LDX #$E7A9. Now I have...
A0 C0 A2 A9 E7 A9 08 00 60
Thanks compiler. still isn't working though.. I have no idea what MVN is or how it works, so I'm gonna need a little more help.

P.JBoy

It should assemble to A0 C0 07 A2 A9 E7 A9 08 00 54 7E 8F 60
...

Quote58

Quote from: Bloodsonic on June 19, 2014, 06:10:19 PM
I have no idea what MVN is or how it works, so I'm gonna need a little more help.
It basically moves data from a location in a bank to another in either the same, or a different bank. You specify the bank from and to (that's the $8F7E part, moving from bank 8F to ram, where the current tileset is loaded), the location to move to, and the location to move from. Those are done with Y and X registers respectively. It is an incredibly useful command, and I have found it especially useful for moving palettes (such as in my glow routine for those fusion doors) from free space, into the ram location where the current one is stored.

RealRed

Alright, the code is exactly that, but... I'm not sure what else to say. It doesn't do anything. the code is at 7F360, the door ASM is 'F360', and the door transition does absolutely nothing unusual from a normal door transition.

P.JBoy

Ah, well, it actually takes quite a bit of work then :/
...

Crashtour99

That's because all the routine is doing is moving the compressed tileset data from ROM to RAM.  It's not really doing anything.  What you'll need to do is run the decompression routine which "should" decompress the data to WRAM, then DMA it to VRAM (where the actual tiles that are displayed are stored).

Unfortunately I don't actually know anything about the decompression scheme for SM.

It would probably be easier to use event bits and room states to achieve what you're looking for.

RealRed


P.JBoy

I have little time, but if anyone wants to whip something up, here's this:

$82E424 AD C4 07    LDA $07C4  [$7E:07C4]   ;\
$82E427 85 48       STA $48    [$7E:0048]   ;|
$82E429 AD C3 07    LDA $07C3  [$7E:07C3]   ;|
$82E42C 85 47       STA $47    [$7E:0047]   ;} Decompress [$07C3..C5] to $7E2000
$82E42E 22 FF B0 80 JSL $80B0FF[$80:B0FF]   ;|
$82E432             dl 7E2000               ;/
$82E435 AD C7 07    LDA $07C7  [$7E:07C7]   ;\
$82E438 85 48       STA $48    [$7E:0048]   ;|
$82E43A AD C6 07    LDA $07C6  [$7E:07C6]   ;|
$82E43D 85 47       STA $47    [$7E:0047]   ;} Decompress [$07C6..C8] to $7EC200
$82E43F 22 FF B0 80 JSL $80B0FF[$80:B0FF]   ;|
$82E443             dl 7EC200               ;/
$82E446 20 39 E0    JSR $E039  [$82:E039]   ;\
$82E449             dx 7E2000, 0000, 2000   ;} $7E2000..3FFF -> VRAM[$0000..0FFF]


$82E783 08          PHP
$82E784 8B          PHB
$82E785 C2 30       REP #$30
$82E787 F4 00 8F    PEA $8F00
$82E78A AB          PLB
$82E78B AB          PLB
$82E78C 9C 16 0E    STZ $0E16  [$7E:0E16]
$82E78F A9 80 00    LDA #$0080              ;\
$82E792 8D 15 21    STA $2115  [$7E:2115]   ;|
$82E795 A9 00 B9    LDA #$B900              ;|
$82E798 85 48       STA $48    [$7E:0048]   ;|
$82E79A A9 00 80    LDA #$8000              ;|
$82E79D 85 47       STA $47    [$7E:0047]   ;} Decompress $B98000 to VRAM[$2800]
$82E79F A9 00 50    LDA #$5000              ;|
$82E7A2 85 4C       STA $4C    [$7E:004C]   ;|
$82E7A4 4A          LSR A                   ;|
$82E7A5 8D 16 21    STA $2116  [$7E:2116]   ;|
$82E7A8 22 71 B2 80 JSL $80B271[$80:B271]   ;/
$82E7AC AD C4 07    LDA $07C4  [$7E:07C4]   ;\
$82E7AF 85 48       STA $48    [$7E:0048]   ;|
$82E7B1 AD C3 07    LDA $07C3  [$7E:07C3]   ;|
$82E7B4 85 47       STA $47    [$7E:0047]   ;} Decompress [$07C3..C5] to VRAM[$0000]
$82E7B6 9C 16 21    STZ $2116  [$7E:2116]   ;|
$82E7B9 64 4C       STZ $4C    [$7E:004C]   ;|
$82E7BB 22 71 B2 80 JSL $80B271[$80:B271]   ;/
$82E7BF AD C7 07    LDA $07C7  [$7E:07C7]   ;\
$82E7C2 85 48       STA $48    [$7E:0048]   ;|
$82E7C4 AC C6 07    LDY $07C6  [$7E:07C6]   ;|
$82E7C7 84 47       STY $47    [$7E:0047]   ;} Decompress [$07C6..C8] to $7EC200
$82E7C9 22 FF B0 80 JSL $80B0FF[$80:B0FF]   ;|
$82E7CD             dl 7EC200               ;/
$82E7D0 AB          PLB
$82E7D1 28          PLP
$82E7D2 6B          RTL

$82E833 AD 9F 07    LDA $079F  [$7E:079F]   ;\
$82E836 C9 06 00    CMP #$0006              ;} If not in Ceres:
$82E839 F0 24       BEQ $24    [$E85F]      ;/
$82E83B A9 00 B9    LDA #$B900              ;\
$82E83E 85 48       STA $48    [$7E:0048]   ;|
$82E840 A9 9D A0    LDA #$A09D              ;|
$82E843 85 47       STA $47    [$7E:0047]   ;} Decompress $B9A09D to $7EA000 (standard CRE)
$82E845 22 FF B0 80 JSL $80B0FF[$80:B0FF]   ;|
$82E849             dl 7EA000               ;/
$82E84C AD C1 07    LDA $07C1  [$7E:07C1]   ;\
$82E84F 85 48       STA $48    [$7E:0048]   ;|
$82E851 AD C0 07    LDA $07C0  [$7E:07C0]   ;|
$82E854 85 47       STA $47    [$7E:0047]   ;} Decompress [$07C0..C2] to $7EA800
$82E856 22 FF B0 80 JSL $80B0FF[$80:B0FF]   ;|
$82E85A             dl 7EA800               ;/
$82E85D 80 11       BRA $11    [$E870]

$82E85F AD C1 07    LDA $07C1  [$7E:07C1]   ;\ Else (in Ceres):
$82E862 85 48       STA $48    [$7E:0048]   ;|
$82E864 AD C0 07    LDA $07C0  [$7E:07C0]   ;|
$82E867 85 47       STA $47    [$7E:0047]   ;} Decompress [$07C0..C2] to $7EA000
$82E869 22 FF B0 80 JSL $80B0FF[$80:B0FF]   ;|
$82E86D             dl 7EA000               ;/


$82EADB AD 9F 07    LDA $079F  [$7E:079F]   ;\
$82EADE C9 06 00    CMP #$0006              ;} If not in Ceres:
$82EAE1 F0 2C       BEQ $2C    [$EB0F]      ;/
$82EAE3 AD B3 07    LDA $07B3  [$7E:07B3]   ;\
$82EAE6 89 02 00    BIT #$0002              ;} If special GFX bitflag bit1 set:
$82EAE9 F0 11       BEQ $11    [$EAFC]      ;/
$82EAEB A9 00 B9    LDA #$B900              ;\
$82EAEE 85 48       STA $48    [$7E:0048]   ;|
$82EAF0 A9 9D A0    LDA #$A09D              ;|
$82EAF3 85 47       STA $47    [$7E:0047]   ;} Decompress $B9A09D to $7EA000 (standard CRE)
$82EAF5 22 FF B0 80 JSL $80B0FF[$80:B0FF]   ;|
$82EAF9             dl 7EA000               ;/
                                           
$82EAFC AD C1 07    LDA $07C1  [$7E:07C1]   ;\
$82EAFF 85 48       STA $48    [$7E:0048]   ;|
$82EB01 AD C0 07    LDA $07C0  [$7E:07C0]   ;|
$82EB04 85 47       STA $47    [$7E:0047]   ;} Decompress [$07C0..C2] to $7EA800
$82EB06 22 FF B0 80 JSL $80B0FF[$80:B0FF]   ;|
$82EB0A             dl 7EA800               ;/
$82EB0D 80 11       BRA $11    [$EB20]     
                                           
$82EB0F AD C1 07    LDA $07C1  [$7E:07C1]   ;\ Else (in Ceres):
$82EB12 85 48       STA $48    [$7E:0048]   ;|
$82EB14 AD C0 07    LDA $07C0  [$7E:07C0]   ;|
$82EB17 85 47       STA $47    [$7E:0047]   ;} Decompress [$07C0..C2] to $7EA000
$82EB19 22 FF B0 80 JSL $80B0FF[$80:B0FF]   ;|
$82EB1D             dl 7EA000               ;/
...