all repos — m12-patcher @ 2aaac7b27ad8359b672aaf1a66f566952a2c118d

tools/m1_new_code.asm (view raw)

  1increase_offense:
  2  push {lr}            // this function was the prank used on the live stream
  3  push {r2-r7}
  4
  5  mov  r3,r0
  6  ldr  r0,=#0x30031FA  // see if the Easy Ring is equipped on Ninten
  7  ldrb r0,[r0,#0]
  8  cmp  r0,#0x37        // if it isn't, do normal stuff
  9  bne  +               // else change enemy stats in ways I don't fully understand
 10
 11  mov  r0,r3
 12  ldr  r2,=#0xFF00
 13  orr  r0,r2
 14  mov  r3,r0
 15
 16  +
 17  mov  r0,r3
 18  and  r0,r7
 19  strh r0,[r1,#0]
 20  pop  {r2-r7}
 21  pop  {pc}
 22
 23//----------------------------------------------------------------------------------------
 24
 25increaseexp:
 26  mov  r3,r0
 27  ldr  r0,=#0x30031FA  // see if the Easy Ring is equipped on Ninten
 28  ldrb r0,[r0,#0]
 29  cmp  r0,#0x37        // if it isn't, do normal stuff
 30  bne  +               // else quadruple experience gained
 31  mov  r0,r3
 32  lsl  r3,r3,#2
 33  ldr  r0,=#0x8FFFFFF  // increase even more if debug mode is on
 34  ldrb r0,[r0,#0]
 35  cmp  r0,#0x1
 36  bne  +
 37  lsl  r3,r3,#4
 38
 39  +
 40  mov r0,r4
 41  bx  lr
 42
 43//----------------------------------------------------------------------------------------
 44
 45increasemoney:
 46  push {r1}
 47  ldr  r1,=#0x30031FA
 48  ldrb r1,[r1,#0]
 49  cmp  r1,#0x37
 50  bne  +
 51  lsl  r0,r0,#1        // double money if easy ring is equipped
 52  ldr  r1,=#0x8FFFFFF  // increase even more if debug mode is on
 53  ldrb r1,[r1,#0]
 54  cmp  r1,#0x1
 55  bne  +
 56  lsl  r0,r0,#3
 57
 58  +
 59  pop  {r1}
 60  add  r0,r3,r0
 61  strh r0,[r1,#0]
 62  bx   lr
 63
 64//----------------------------------------------------------------------------------------
 65
 66lowerencounterrate:
 67  ldr  r1,=#0x8F1BB48
 68
 69  ldr  r0,=#0x30031FA    // see if the Easy Ring is equipped on Ninten
 70  ldrb r0,[r0,#0]
 71  cmp  r0,#0x37          // if it isn't, do normal stuff
 72  bne  +                 // else do our easy-making stuff
 73  ldr  r1,=#enratetable
 74  ldr  r0,=#0x8FFFFFF    // see if debug mode is on
 75  ldrb r0,[r0,#0]        
 76  cmp  r0,#0x1           // load no-enemies data if debug mode is on
 77  bne  +
 78  ldr  r1,=#enratetable  // SCRIVERE "enratetable2" PER AZZERARE DEL TUTTO GLI INCONTRI CASUALI DURANTE LA DEBUG MODE
 79
 80  +
 81  mov r0,r13
 82  bx  lr
 83
 84enratetable:
 85  db $08,$07,$06,$06,$05,$04,$03,$02
 86enratetable2:
 87  db $00,$00,$00,$00,$00,$00,$00,$00
 88
 89//----------------------------------------------------------------------------------------
 90// Hack which changes the dollar sign's position in shops so it's after the price [merito di Lorenzooone]
 91
 92  define initial_pos $E
 93  define dollar_pos {initial_pos}+5
 94  change_dollar_sign_pos_shop:
 95  push {lr}
 96  mov  r0,#{dollar_pos}
 97  bl   $8F0CA54                // Set where to print the dollar sign
 98  ldr  r0,=#0x80A4
 99  bl   $8F0C7BC                // Print the dollar sign
100  mov  r0,#{initial_pos}
101  bl   $8F0CA54                // Set where to print the price
102  pop  {pc}
103
104//----------------------------------------------------------------------------------------
105
106producescreen1:
107  push {r6}
108  mov  r0,#0xC8
109  strb r0,[r6,#0x0D]
110  mov  r0,#0xC9
111  strb r0,[r6,#0x0E]
112  mov  r0,#0xCA
113  strb r0,[r6,#0x0F]
114  mov  r0,#0xCB
115  strb r0,[r6,#0x10]
116  mov  r0,#0xCD
117  strb r0,[r6,#0x11]
118  mov  r0,#0xCE
119  strb r0,[r6,#0x12]
120  mov  r0,#0xCF
121  strb r0,[r6,#0x13]
122//  add  r6,#0x33
123//  mov  r0,#0xDF
124//  strb r0,[r6,#0x0]
125  add  r6,#0x2D
126  mov  r0,#0xD8
127  strb r0,[r6,#0x0]
128  pop  {r6}
129  bx   lr
130
131producescreen2:
132  mov  r0,#0xE3
133  strb r0,[r1,#0]
134  add  r1,#1
135  mov  r0,#0xE4
136  strb r0,[r1,#0]
137  add  r1,#1
138  mov  r0,#0xE5
139  strb r0,[r1,#0]
140  add  r1,#1
141  mov  r0,#0xE6
142  strb r0,[r1,#0]
143  add  r1,#1
144  mov  r0,#0xE7
145  strb r0,[r1,#0]
146  add  r1,#1
147  mov  r0,#0xE8
148  strb r0,[r1,#0]
149  add  r1,#1
150  bx   lr
151
152//----------------------------------------------------------------------------------------
153
154// this determines if the game should use the original size text box or the expanded one
155
156choose_text_window_type:
157  push {lr}
158  push {r4}
159  ldr  r0,=#0x8F26D4A      // load original, small text box window
160
161  // sometimes r4 doesn't have the actual line number, usually when doing non-dialog stuff
162  // like when you use items. So we check for that now here
163  ldr  r4,=#0x2014300      // since we're doing an unusual line, let's check our custom
164  ldrh r4,[r4,#0]          // variable to see what the actual line # is
165  cmp  r4,#0
166  beq  +
167  
168
169  // if we're here, we're looking at a standard dialog line, with the line number in r4
170  // so we'll load from a custom table to see if this line needs a small window or not
171
172  .load_table_entry:
173  ldr  r1,=#0x8FED000      // this is the start of our custom table
174  add  r1,r1,r4
175  ldrb r1,[r1,#0]          // if the value in the table is 1, then use small window
176  cmp  r1,#0x1
177  beq  +
178
179  ldr  r0,=#wide_text_box  // load wide text box window
180
181  +
182  mov  r4,#0               // unset our custom "current line #" variable
183  ldr  r1,=#0x2014300
184  strh r4,[r1,#0]
185
186  pop  {r4}
187  bl   $8F0C058
188  ldr  r1,=#0x30034B0
189  mov  r0,#0x80
190  strb r0,[r1,#0]
191  pop  {r0}
192  bx   r0
193
194//----------------------------------------------------------------------------------------
195// the yes/no selection is weird, so we gotta make it fit the window size too
196
197choose_yes_no_size:
198   push {lr}
199   push {r1-r7}
200   strb r1,[r0,#0x0]
201
202   ldr  r0,=#0x8FE7140      // load small-sized yes/no window address
203   ldr  r4,=#0x2014300      // let's get the line #, making sure it's not null
204   ldrh r4,[r4,#0]
205   cmp  r4,#0
206   beq  +
207
208   // if we're here, we're looking at a standard dialog line, with the line number in r4
209   // so we'll load from a custom table to see if this line needs a small yes/no or not
210   .load_table_entry:
211   ldr  r1,=#0x8FED000      // this is the start of our custom table
212   add  r1,r1,r4
213   ldrb r1,[r1,#0]          // if the value in the table is 1, then use small window
214   cmp  r1,#0x1
215   beq  +
216
217   ldr  r0,=#0x8FE7100      // load wide yes/no window
218
219   +
220   pop  {r1-r7}
221   pop  {pc}
222
223
224//----------------------------------------------------------------------------------------
225
226// In Japanese, the word for drink is the same for swallow, which makes it weird when
227// you try to use an HP capsule or something and it says you drank it. This little hack
228// will make it say "swallow" if it's appropriate.
229
230swallow_item:
231   ldr  r1,=#0x30007D4       // this has the current item # (hopefully all the time)
232   ldrb r1,[r1,#0]           // load item #
233   cmp  r1,#0x4E             // see if the item is between 4E and 52, which are capsules
234   blt  .drink               // if not, then load the normal "drink" line
235   cmp  r1,#0x52             // if it is, then load the "swallow" line
236   bgt  .drink
237   ldr  r1,=#0x6AE
238   b    +
239
240   .drink:
241   ldr r1,=#0x6B0
242
243   +
244   bx lr
245
246//----------------------------------------------------------------------------------------
247
248// saves the current text line number to a custom area of RAM for use in other hacks here
249
250save_line_number_a:
251  ldr  r1,=#0x2014300
252  strh r0,[r1,#0]
253
254  lsl r0,r0,#0x10
255  ldr r1,=#0x30034E8
256  bx  lr
257
258//----------------------------------------------------------------------------------------
259// basic string copy, r0 is the source address, r1 is the target address, 00 = end of line
260// upon return, r0 has the number of bytes copied, r1 has the address of the end of line
261
262strcopy:
263   push {r2,r3,lr}
264   
265   -
266   ldrb r2,[r0,#0x0]
267   strb r2,[r1,#0x0]
268   add  r0,#0x1
269   add  r1,#0x1
270   cmp  r2,#0x0
271   beq  +
272   add  r3,#0x1
273   b    -
274
275   +
276   mov  r0,r3
277   pop  {r2,r3,pc}
278
279//----------------------------------------------------------------------------------------
280// copies a string (meant for battle text) to RAM, parsing control codes when possible
281// this is done so we can add in auto line breaks as necessary later on
282// r0 is source address, r1 is target address, line needs to be terminated with 00
283
284parsecopy:
285
286  push {r0-r7,lr}
287
288  .loop_start:
289  ldrb r2,[r0,#0x0]      // load character from ROM string
290  cmp  r2,#0x3           // see if it's a control code, if so, let's do control code stuff
291  bne  .copy_character
292
293  .parse_control_code:
294  ldrb r3,[r0,#0x1]      // load control code argument
295  cmp  r3,#0x10; bne +; bl control_code_10; b .loop_start
296  +
297  cmp  r3,#0x11; bne +; bl control_code_11; b .loop_start
298  +
299  cmp  r3,#0x12; bne +; bl control_code_12; b .loop_start
300  +
301  cmp  r3,#0x13; bne +; bl control_code_13; b .loop_start
302  +
303  cmp  r3,#0x16; bne +; bl control_code_16; b .loop_start
304  +
305  cmp  r3,#0x17; bne +; bl control_code_17; b .loop_start
306  +
307  cmp  r3,#0x1D; bne +; bl control_code_1D; b .loop_start
308  +
309  cmp  r3,#0x20; bne +; bl control_code_20; b .loop_start
310  +
311  cmp  r3,#0x21; bne +; bl control_code_21; b .loop_start
312  + 
313  cmp  r3,#0x22; bne +; bl control_code_22; b .loop_start
314  + 
315  cmp  r3,#0x23; bne +; bl control_code_23; b .loop_start
316  + 
317  cmp  r3,#0xF0; bne +; bl control_code_F0; b .loop_start
318  + 
319  cmp  r3,#0xF1; bne +; bl control_code_F1; b .loop_start
320  + 
321  cmp  r3,#0xF2; bne +; bl control_code_F2; b .loop_start
322  + 
323
324  .copy_control_code:
325  mov  r3,#0x3
326  strb r3,[r1,#0x0]
327  ldrb r3,[r0,#0x1]
328  strb r3,[r1,#0x1]
329  add  r0,#0x2
330  add  r1,#0x2
331  b    .loop_start
332
333  .copy_character:
334  strb r2,[r1,#0x00]
335  add  r0,#0x1
336  add  r1,#0x1
337  cmp  r2,#0x0
338  beq  +
339  b    .loop_start  
340
341  +
342  pop  {r0-r7,pc}
343
344//----------------------------------------------------------------------------------------
345
346// r0 has the text line number
347
348copy_battle_line_to_ram:
349   push {lr}
350
351   // now find the ROM address of the line in question, place in r0
352
353   lsl  r0,r0,#0x10
354   ldr  r1,=#0x30034E8
355   ldr  r1,[r1,#0x0]
356   lsr  r0,r0,#0xE
357   add  r0,r0,r1
358   ldr  r0,[r0,#0x0]
359   cmp  r0,#0x0
360   beq  +
361
362   // now we store the target in r1 and execute a custom string copy
363   ldr  r1,=#0x2014310
364   bl   parsecopy
365
366   // now we scan the final string and add [BREAK]s as necessary to create auto-wrapping
367   ldr  r0,=#0x2014310
368   bl   perform_auto_wrap
369
370   // now we send the game's display routine on its merry way
371   bl   $8F0C058
372
373   battle_calling:  // this line is referenced by the auto-indent hack
374   +
375   pop {pc}
376
377//----------------------------------------------------------------------------------------
378
379perform_auto_wrap:
380   push {r0-r7,lr}
381   mov  r2,r0      // load r2 with the start address of the string
382   mov  r1,r2      // r1 is the current character's address
383   mov  r7,r2      // r7 is last_space, the spot where the last space was
384   mov  r4,#0      // char_loc = 0
385
386   //-------------------------------------------------------------------------------
387   // Now we do the meat of the auto word wrap stuff
388   .word_wrap_loop:
389   ldrb r0,[r1,#0x0]            // load current character
390
391   cmp  r0,#0x0
392   beq  .word_wrap_end          // jump to the end if we're at the end of the string
393
394   cmp  r0,#0x1                 // is the current character a space?
395   beq  .space_found
396   cmp  r0,#0x2                 // is the current character a [BREAK]?
397   beq  .newline_found
398
399   cmp  r0,#0x03                // if r0 == 0x03, this is a CC, so skip the width adding junk
400   beq  .no_wrap_needed
401   b    .main_wrap_code
402
403   pop  {r0-r7,pc}
404
405   //-------------------------------------------------------------------------------
406   // We found a space or a space-like character, so reset some values
407
408   .newline_found:
409   mov  r4,#0                   // this was a [WAIT] or [BREAK], so reset the width
410   mov  r7,r1                   // last_space = curr_char_address
411   b    .no_wrap_needed
412
413   .space_found:
414   mov r7,r1                    // last_space = curr_char_address
415                     
416   //--------------------------------------------------------------------------------------------
417   // Here is the real meat of the auto word wrap routine
418
419   .main_wrap_code:
420   add  r4,#0x1                 // char_loc++
421   cmp  r4,#0x1B
422   blt  .no_wrap_needed         // if curr_width < box_width, go to no_wrap_needed to update the width and such
423
424   mov  r4,#0                   // if we're executing this, then width >= box_width, so do curr_width = 0 now
425
426   mov  r1,r7                   // curr_char_address = last_space_address// we're gonna recheck earlier stuff
427
428   mov  r0,#0x02
429   strb r0,[r7,#0x0]            // replace the last space-ish character with a newline code
430
431   //--------------------------------------------------------------------------------------------
432   // Get ready for the next loop iteration
433
434   .no_wrap_needed:
435   add  r1,#1                   // curr_char_address++
436   b    .word_wrap_loop         // do the next loop iteration
437
438   //--------------------------------------------------------------------------------------------
439   // Let's get out of here!
440
441   .word_wrap_end:
442   pop  {r0-r7,pc}
443
444
445//----------------------------------------------------------------------------------------
446
447control_code_10:
448  push {r0,lr}
449  ldr  r0,=#0x3003208
450  bl   strcopy
451  pop  {r0}
452  add  r0,#0x2
453  sub  r1,#1
454  pop  {pc}
455
456//----------------------------------------------------------------------------------------
457
458control_code_11:
459  push {r0,lr}
460  ldr  r0,=#0x3003288
461  bl   strcopy
462  pop  {r0}
463  add  r0,#0x2
464  sub  r1,#1
465  pop  {pc}
466
467//----------------------------------------------------------------------------------------
468
469control_code_12:
470  push {r0,lr}
471  ldr  r0,=#0x3003248
472  bl   strcopy
473  pop  {r0}
474  add  r0,#0x2
475  sub  r1,#1
476  pop  {pc}
477
478//----------------------------------------------------------------------------------------
479
480control_code_13:
481  push {r0,lr}
482  ldr  r0,=#0x30032C8
483  bl   strcopy
484  pop  {r0}
485  add  r0,#0x2
486  sub  r1,#1
487  pop  {pc}
488
489//----------------------------------------------------------------------------------------
490
491control_code_16:
492  push {lr}
493  push {r0,r2}
494  push {r1}
495  ldr  r1,=#0x3003190
496  ldrb r2,[r1,#0x8]
497  lsl  r0,r2,#0x6
498  add  r1,#0x38
499  add  r0,r0,r1
500  pop  {r1}
501  bl   strcopy
502  pop  {r0,r2}
503  add  r0,#0x2
504  sub  r1,#1
505  pop  {pc}
506
507//----------------------------------------------------------------------------------------
508// this adds "Il gruppo di " if there's more than one character in the party
509
510control_code_17:
511  push {r0,lr}
512  ldr  r0,=#0x3003190
513  ldrb r0,[r0,#0x9]
514  cmp  r0,#0x0
515  beq  +
516
517  ldr  r0,=#0x8F7E600
518  bl   strcopy
519  sub  r1,#1
520
521  +
522  pop  {r0}
523  add  r0,#0x2
524  pop  {pc}
525
526//----------------------------------------------------------------------------------------
527// this prints an item name
528
529control_code_1D:
530  push {lr}
531  push {r0,r2-r7}
532  push {r1}
533
534  ldr  r1,=#0x30007D4
535  ldrb r2,[r1,#0x0]
536  lsl  r0,r2,#0x18
537  cmp  r0,#0
538  blt  line434
539  mov  r1,r2
540  mov  r2,#0xFA
541  lsl  r2,r2,#2
542  b    line456
543
544  line434:
545  lsr  r0,r0,#0x18
546  cmp  r0,#0xBF
547  bhi  line450
548  ldr  r0,=#0x8F29EB0
549  ldrb r1,[r1,#0]
550  sub  r1,#0x80
551  lsl  r1,r1,#1
552  add  r1,r1,r0
553  ldrh r0,[r1,#0]
554  b    +
555
556  line450:
557  ldrb r1,[r1,#0]
558  mov  r2,#0xEA
559  lsl  r2,r2,#2
560  line456:
561  add  r0,r1,r2
562  lsl  r0,r0,#0x10
563  ldr  r1,=#0x30034E8
564  ldr  r1,[r1,#0]
565  lsr  r0,r0,#0xE
566  add  r0,r0,r1
567  ldr  r0,[r0,#0]
568
569  +
570  pop  {r1}
571  bl   strcopy
572  sub  r1,#1
573  pop  {r0,r2-r7}
574
575  add r0,#0x2
576  pop {pc}
577
578//----------------------------------------------------------------------------------------
579
580control_code_20:
581  push {r0,lr}
582  ldr  r0,=#0x3003640
583  bl   strcopy
584  pop  {r0}
585  add  r0,#0x2
586  sub  r1,#1
587  pop  {pc}
588
589//----------------------------------------------------------------------------------------
590
591control_code_21:
592  push {r0,lr}
593  ldr  r0,=#0x3003610
594  bl   strcopy
595  pop  {r0}
596  add  r0,#0x2
597  sub  r1,#1
598  pop  {pc}
599
600//----------------------------------------------------------------------------------------
601
602control_code_22:
603  push {r0,lr}
604  ldr  r0,=#0x30036A0
605  bl   strcopy
606  pop  {r0}
607  add  r0,#0x2
608  sub  r1,#1
609  pop  {pc}
610
611//----------------------------------------------------------------------------------------
612// this is used to display numbers
613
614control_code_23:
615  push {r0,lr}
616  push {r7}
617  mov  r7,r1
618  ldr  r0,=#0x3003708
619  ldr  r0,[r0,#0]         // r0 now has the number to be displayed, but we gotta convert it
620  mov  r5,r0              // copy number to r5 for easy retrieval
621  mov  r6,#0              // initialize counter
622  push {r4-r6}
623
624  .loop_start:
625  ldr  r0,=#0x20142F0     // this is the write address in our custom area in RAM
626  add  r4,r0,r6
627  mov  r0,r5
628  mov  r1,#0xA
629  bl   $8F15210           // calling the division routine
630  add  r0,#0xB0           // r0 now has the tile # for the digit to be printed
631  strb r0,[r4,#0x0]       // store digit tile # to RAM
632  add  r6,#1              // increment counter
633  mov  r0,r5
634  mov  r1,#0xA
635  bl   $8F15198           // call remainder routine
636  mov  r5,r0
637  cmp  r5,#0x0
638  bne  .loop_start
639
640
641  .reverse_string:        // the number string is actually stored in reverse, so we gotta fix that
642  ldr  r4,=#0x20142F0
643  mov  r1,r7              // we're gonna reverse the number string into the main string
644  cmp  r6,#0              // make sure we actually have a string to copy, this is the # of bytes
645  ble  .end_routine
646
647  sub  r6,#1              // we want to start just before the end of the string
648  .reverse_string_loop:
649  add  r5,r4,r6           // give r5 the address of the byte to load
650  ldrb r0,[r5,#0x0]       // load byte
651  strb r0,[r1,#0x0]       // store byte in main string and increment position
652  add  r1,#1
653
654  sub  r6,#1              // decrement counter, do another loop if necessary
655  cmp  r6,#0
656  blt  .end_routine
657  b    .reverse_string_loop
658
659  .end_routine:           // r1 needs to return the current address in the main string
660  pop  {r4-r6}
661  pop  {r7}
662  pop  {r0}
663  add  r0,#0x2
664  pop  {pc}
665
666//----------------------------------------------------------------------------------------
667// this is a custom battle control code that selects a/an/the for when an item is used
668
669control_code_F0:
670  push {lr}
671  push {r2-r7}
672  push {r0}
673
674  ldr  r5,=#0x8F70840
675  ldr  r4,=#0x3003690
676  ldrh r0,[r4,#0x0]
677  add  r0,#0x1
678  add  r0,r0,r5
679  ldrb r0,[r0,#0x0]      // this now has the item number being used
680  lsl  r0,r0,#0x4
681  ldr  r5,=#0x8FFE000
682  add  r0,r0,r5          // we now have the address of the custom article string to copy
683
684  bl   strcopy
685  pop  {r0}
686  add  r0,#0x2
687  sub  r1,#1
688
689  pop  {r2-r7}
690  pop  {pc}
691
692//----------------------------------------------------------------------------------------
693// this is a custom battle control code that selects a/an/the when an item is won in battle
694
695control_code_F1:
696  push {lr}
697  push {r2-r7}
698  push {r0}
699
700  ldr  r4,=#0x30007D4
701  ldrb r0,[r4,#0x0]      // this now has the item number being used
702  lsl  r0,r0,#0x4
703  ldr  r5,=#0x8FFE000
704  add  r0,r0,r5          // we now have the address of the custom article string to copy
705
706  bl   strcopy
707  pop  {r0}
708  add  r0,#0x2
709  sub  r1,#1
710
711  pop  {r2-r7}
712  pop  {pc}
713
714//----------------------------------------------------------------------------------------
715// CODICE DI CONTROLLO PER FAR APPARIRE L'ARTICOLO DAVANTI ALL'OGGETTO
716// QUANDO VIENE USATO FUORI DA UNA BATTAGLIA
717
718control_code_F2:
719  push {r0,r2,lr}
720
721  ldr  r0,=#0x30007D4       // this has the current item # (hopefully all the time)
722  ldrb r0,[r0,#0x0]         // load item #
723  lsl  r0,r0,#0x4
724  ldr  r2,=#0x8FFE000
725  add  r0,r0,r2             // we now have the address of the custom article string to copy
726
727  bl   strcopy
728  pop  {r0}
729  add  r0,#0x2
730  sub  r1,#1
731
732  pop  {r2}
733  pop  {pc}
734
735//----------------------------------------------------------------------------------------
736// if there are multiple enemies, this will add a space between the names and the end letters
737
738add_space_to_enemy_name:
739  push {lr}
740  mov  r4,#0x01
741  strb r4,[r5,#0x0]
742  sub  r0,#0x6C      // MODIFICA LA LETTERA IDENTIFICATIVA DEL NEMICO PER UTILIZZARE LA CORRISPONDENTE VARIANTE IN GRASSETTO
743  strb r0,[r5,#0x1]
744  add  r5,#0x2
745  pop  {pc}
746
747//----------------------------------------------------------------------------------------
748// only ignore auto-indenting if we're in battle
749
750possibly_ignore_auto_indents:
751   push {lr}
752   push {r2-r7}
753   mov  r0,r1
754   
755   mov  r3,sp
756   add  r3,#0x2C
757   ldr  r3,[r3,#0]
758   ldr  r2,=#battle_calling
759   add  r2,#1
760   cmp  r3,r2
761   beq  +
762
763   add  r0,#1
764
765   +
766   pop  {r2-r7}
767   strb r0,[r2,#0x0]
768   pop  {pc}
769
770//======================================================================
771// Intro screen stuff
772//======================================================================
773
774//print "Intro screen routine: ",pc
775//org $83FC600
776org $8106CAC
777intro_screen:
778push {r0-r4}
779
780// Enable VBlank interrupt crap
781ldr  r2,=#0x4000000
782mov  r0,#0xB
783strh r0,[r2,#4] // LCD control
784mov  r1,#2
785lsl  r1,r1,#8
786ldrh r0,[r2,r1]
787mov  r3,#1
788orr  r0,r3
789strh r0,[r2,r1] // Master interrupt control
790
791// Enable BG0
792ldrh r0,[r2,#0]
793mov  r1,#1
794lsl  r1,r1,#8
795orr  r0,r1
796strh r1,[r2,#0]
797
798// Set BG0 to 256-color mode; the following screen uses it anyway so we're good
799ldrh r0,[r2,#8]
800mov  r1,#0x80
801orr  r0,r1
802strh r0,[r2,#8]
803
804// Tile data
805ldr  r0,=#disclaimer_graphics
806ldr  r1,=#0x6008000
807//swi  #0x12 // LZ77UnCompVram
808 ldr  r2,=#0x1FE0
809 swi  #0xC
810
811// Fill the first row of tilemap data with the first tile in our file
812ldr  r0,=#0x6000000
813ldr  r1,=#0x200
814ldr  r3,=#0x400
815//mov  r1,#0
816mov  r2,#0
817-
818strh r1,[r0,#0]
819add  r0,#2
820add  r2,#1
821cmp  r2,r3
822bne  -
823
824
825// now we copy the actual tilemap data of our image to the tile map area
826ldr  r0,=#0x6000040
827ldr  r1,=#0x3FE
828//mov  r2,#0
829ldr  r2,=#0x200
830
831-
832mov  r3,#0x3F
833and  r3,r0
834cmp  r3,#0x3C
835bne  +
836add  r0,#4
837+
838strh r2,[r0,#0]
839add  r0,#2
840add  r2,#1
841cmp  r2,r1
842blt  -
843
844
845// load our palette
846ldr  r0,=#disclaimer_palette
847mov  r1,#5
848lsl  r1,r1,#0x18
849mov  r2,#1
850lsl  r2,r2,#8
851swi  #0xB
852
853
854// Fade in
855ldr  r2,=#0x4000050
856mov  r0,#0x81
857strh r0,[r2,#0] // Set blending mode to whiteness for BG0
858mov  r4,#0x10
859-
860strh r4,[r2,#4]
861swi  #5
862swi  #5 // 15 loops with 2 intrs each gives a total fade-in time of 0.5 seconds
863sub  r4,#1
864bpl  -
865
866// Conditional delay for ~2 seconds
867// 0x78 VBlankIntrWaits is 2 seconds
868mov  r2,#1 // set to 0 if we don't need to delay
869ldr  r4,=#0xFFFFFFFF
870ldr  r0,=#0xE000000      // check mother 1 slot 1
871ldrb r3,[r0,#0]
872cmp  r3,#0xFF
873beq  +
874mov  r2,#0
875b    delay
876
877+
878ldr  r0,=#0xE000300      // check mother 1 slot 2
879ldrb r3,[r0,#0]
880cmp  r3,#0xFF
881beq  +
882mov  r2,#0
883b    delay
884
885+
886ldr  r0,=#0xE000600      // check mother 1 slot 3
887ldrb r3,[r0,#0]
888cmp  r3,#0xFF
889beq  +
890mov  r2,#0
891b    delay
892
893+
894ldr  r0,=#0xE002000      // check mother 2 data
895ldrb r3,[r0,#0]
896cmp  r3,#0xFF
897beq  +
898mov  r2,#0
899b    delay
900
901
902+
903delay:
904cmp  r2,#0
905beq  buttonwait
906mov  r4,#0x78
907-
908swi  #5
909sub  r4,#1
910cmp  r4,#0
911bne  -
912+
913
914buttonwait:
915// Wait for any button press
916ldr  r2,=#0x4000130
917ldr  r4,=#0x3FF
918-
919swi  #5 // VBlankIntrWait
920ldrh r0,[r2,#0]
921cmp  r0,r4
922beq  -
923
924// Fade out
925ldr  r2,=#0x4000050
926mov  r0,#0x81
927strh r0,[r2,#0] // Set blending mode to whiteness for BG0
928mov  r4,#0x0
929-
930strh r4,[r2,#4]
931swi  #5
932swi  #5 // 15 loops with 2 intrs each gives a total fade-out time of 0.5 seconds
933add  r4,#1
934cmp  r4,#0x10
935bls  -
936
937// Clear the palette
938mov  r0,#1
939neg  r0,r0
940push {r0}
941mov  r0,sp
942mov  r1,#5
943lsl  r1,r1,#0x18
944mov  r2,#1
945lsl  r2,r2,#24
946add  r2,#0x80
947swi  #0xC
948add  sp,#4
949
950// ----------------------
951pop  {r0-r4}
952
953.intro_screen_end:
954push {lr}
955ldr r0,=#0x3007FFC
956str r1,[r0,#0]
957pop  {pc}
958
959//======================================================================
960
961org $8B33000;
962disclaimer_palette:
963incbin intro_screen_pal.bin
964
965disclaimer_graphics:
966incbin intro_screen_gfx.bin
967
968org $800027A; bl intro_screen