News:

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

Main Menu

Creating an event PLM based on the scrolling ball code

Started by Vener, November 26, 2017, 08:59:41 AM

Previous topic - Next topic

Vener

Hello ,

As the title say , i want to create a PLM which will use the 2 bytes room argument as a pointer , when touched , like the scrolling balls , but instead of running specific scrolling data format , i want to use the pointer to read basic custom codes . It'll make a PLM very versatile , capable of triggering almost everything .

After looking in the scrolling ball PLM , il got the pre instruction that use room argument :

$84:AF8C   55 8B *

*
   8B                PHB                     
   DA                PHX                     
   5A                PHY                     
   9E 17 1E       STZ,x (Variable use PLM value)
   BC C7 1D      LDY,x (PLM Room argument)
   F4 00 8F       PEA $8F00  , Which i change to the unused bank $1C0000
   AB               PLB                 
   AB               PLB                 
   A9 00 00      LDA #0000
   E2 20           SEP 
- B9 00 00      LDA,y (first byte of room argument)
   30 0C           BMI +
   AA               TAX
   B9 01 00      LDA,y (second byte of room argument)
   9F 20 CD 7E  STA,x  Scrollmap for current room
   C8                INY
   C8                INY
   80 EF            BRA -
+ C2 20           REP
   7A               PLY                     
   FA               PLX                     
   AB               PLB
 
   

But , instead of storing the arguments in the scroll map , what i have to do ? i need to store them to another RAM ? i have to skip the storing part at all ? actually , i have no idea ...

Thank you for your help .

Smiley

JSR ($1DC7, x) should work. X should hold the current PLM index.

That's an absolute indirect indexed jump, meaning it pulls the value from $1DC7+x and then jumps to the address specified by the value.

Vener

 I tested your idea (i just changed the bank value at PEA from $8F to $B8
and the STA,x 7ECD20  to  JSR,x $1DC7 + NOP ; then i writed a short code (a sound played) at $B88000 , and put the adresse 8000 in the scrolling ball argument ) , and it doesn't work . I maybe done something wrong ?

Smiley

#3
I forgot that data bank and program bank are different things. Pea : plb : plb will change the data bank, but to get to a different bank, program bank has to be changed instead, but there's no operation to do that manually. So you have to do a JML instead.
If you store the PLM argument to $12 and the desired bank to $14, then do JML [$12], then you will get the desired result. However, because JML doesn't store the result address, you have to store that manually. The easiest way to do that is to simply JSL to the JML, as silly as that seems. Something like this:

LDA !PLM_Argument : STA $12
LDA !Bank : STA $14
JSL Actual_Jump
RTS
Actual_Jump:
JML [$12]

Vener

Okay lol . Sorry but it quite confuse me . Well

Original code is :

PHB
PHX
PHY
STZ,x  $1E17  (Variable use PLM value)
LDY,x  $1DC7 (PLM Room argument)
PEA $8F00
PLB
PLB
LDA #$0000
SEP #$20
LDA,y #$0000
BMI #$0C
TAX
LDA,y #$0001
STA,x $7ECD20 (Scrollmap for current room)
INY
INY
BRA #$EF
REP #$20
PLY                   
PLX                   
PLB

so i have to change it to :

PHB
PHX
PHY
STZ,x  $1E17  (Variable use PLM value)
LDY,x  $1DC7 (PLM Room argument)
STA $12
LDA #$8F00
STA $14
JSL $xxxxxx

SEP #$20
LDA,y #$0000
BMI #$0C
TAX
LDA,y #$0001
STA,x $7ECD20 (Scrollmap for current room)
INY
INY
BRA #$EF
REP #$20

PLY                   
PLX                   
PLB

Then at $xxxxxx (In bank $8F ?):

JML $12

This is what i understand , but i'm sure it's not what you explained ....?  :pwuh:

Smiley

Almost. The JML needs the square brackets, so JML [$12] instead of JML $12.
The difference is that JML $12 jumps to $12, while JML [$12] jumps to the address specified in $12.
It also doesn't really matter what bank it's in, but I recommend $84 because that's where all the PLM data is anyway.

Vener

Okay , so
For testing , i created a new PLM at 02:7000 (so PLM $F000).
Here , i put the same main instruction pointer that the scrolling ball (which is $B371)
, for the pre PLM instructions , i used the same (Pointed at $F004) :

01 00   
62 AF   
B4 86   <Do nothing. The PLM will sit on this instruction until something else tells it to change.     
10 F0  < i changed this pointer to my new code*
24 87   < Use the address given by the argument as the next instruction. 
8A AF     

* $F010 *which is :

8B              PHB                     
DA              PHX                     
5A              PHY                     
9E 17 1E     STZ,x $1E17 (Variable use PLM value)
BC C7 1D     LDY,x $1DC7 (PLM Room argument)
85 12          STA $12
A9 00 B8      LDA #$B800
85 14           STA $14
22 3C F0 84  JSL $84F03C
7A               PLY                     
FA               PLX                     
AB               PLB
DA               PHX
BD 87 1C     LDA,x $1C87 (PLM's location in the room (nth block * 2))
AA               TAX
BF 02 00 7F  LDA,x $7F0002 (Room Tilemap)
29 FF 0F       AND #$0FFF
09 00 30       ORA #$3000
9F 02 00 7F   STA,x $7F0002 (Room Tilemap)
FA                 PLX
60                 RTS

$F03C


DC 00 12 7E   JML [$12]
6B                  RTL

And finally , i put at $B88000 a basic code just for testing the PLM :

A9 0B 00 22 C1 90 80 60 (Playing a sound)

Then in smile , i put the PLM $F000 with the high and low 00 80

And , of course ! :lol: it crash the game when i touch the PLM .

Smiley

You're loading the PLM argument to the Y register (LDY,x $1DC7), so you also have to use STY $12 instead of STA $12. Sorry for not noticing this earlier.
The RTL after JML [$12] is not needed, because that's actually never run. Remember, JSL pushes a return address to the stack, JML doesn't. So returning from the custom code will return to after the JSL.
Also, you'll have to end the code in $B8 with RTL (6B) instead of RTS (60), because you're jumping to it with a JSL.
Also try switching the PLM's arguments around if it still doesn't work (so 80 00 instead of 00 80).

Vener

I did this :

;Event PLM

org $84EFCF

dw B371
dw EFD3


org $84EFD3 ;Pre instructions

dw 0001         
dw AF62         
dw 86B4      ;Do nothing. The PLM will sit on this instruction until something else (often pre-PLM instruction) tells it to change.     
dw EFDF      ;The new code
dw 8724      ;Use the address given by the argument as the next instruction. 
dw AF8A     


org $84EFDF

PHB                   
PHX                     
PHY                     
STZ,x $1E17 ;(Variable use PLM value)
LDY,x $1DC7 ;(PLM Room argument)
STY $12
LDA #$B800
STA $14
JSL $84F00B
PLY                     
PLX                     
PLB
PHX
LDA,x $1C87 ;(PLM's location in the room (nth block * 2))
TAX
LDA,x $7F0002 ;(Room Tilemap)
AND #$0FFF
ORA #$3000
STA,x $7F0002 ;(Room Tilemap)
PLX
RTS


org $84F00B

JML [$12]

org $B8C000

LDA #$000B  ;Screw attack sound 
JSL $8090C1
RTL


and as you said , i tried C0 00 and 00 C0 , and nop ... :cry:

There is maybe a conflict with the main instruction B371 , or one of the pre instructions :|

Smiley

So after fiddling around with it a bit, I figured out the bank was being stored wrong. LDA #$B800 : STA $14 causes the bank byte to be off by one; LDA #$00B8 : STA $14 works. That's all it was.

Here's the full code, which could still be cleaned up a bit:
;Event PLM
lorom

org $84EFCF

  dw $B371
  dw MainASM


;Instruction list
MainASM:
  dw $0001, $AF62         
  dw $86B4      ;Do nothing. The PLM will sit on this instruction until something else (often pre-PLM instruction) tells it to change.     
  dw CallEvent      ;The new code
  dw $8724, $AF8A      ;Use the address given by the argument as the next instruction.   


CallEvent:
  PHB : PHX : PHY                     
  STZ $1E17,x ;(Variable use PLM value)
  LDY $1DC7,x : STY $12 ;(PLM Room argument)
  LDA #$00B8 : STA $14
  JSL GotoEvent
  PLY : PLX : PLB
  PHX
  LDA $1C87,x ;(PLM's location in the room (nth block * 2))
  TAX
  LDA $7F0002,x ;(Room Tilemap)
  AND #$0FFF : ORA #$3000
  STA $7F0002,x ;(Room Tilemap)
  PLX
  RTS


GotoEvent:
  JML [$0012]


org $B8C000

  LDA #$000B  ;Screw attack sound 
  JSL $8090C1
  RTL

If you apply this and give the PLM an argument of C0 00, you'll see the sound plays exactly as expected.

Vener

Okay man , finally , it works fine .
Congratulations , you have created a new PLM !  :grin: (And quite useful i think)

It helps a lot , thanks to you !