Advertisement
Guest User

For the Frog the Bell Tolls - Player's name expansion

a guest
Jun 8th, 2018
532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; **************************************
  2. ; ***DEFINES AND BASE ROM PREPARATION***
  3. ; **************************************
  4.  
  5. .MEMORYMAP
  6.     DEFAULTSLOT 1
  7.     SLOTSIZE $4000
  8.     SLOT 0 $0000
  9.     SLOT 1 $4000
  10. .ENDME
  11.  
  12. .ROMBANKSIZE $4000
  13. .ROMBANKS 32
  14. .COMPUTEGBCOMPLEMENTCHECK
  15. .COMPUTEGBCHECKSUM
  16.  
  17. .BACKGROUND "kaeru.gb"
  18. .UNBACKGROUND $1320 $13FF       ; Bank $00
  19. .UNBACKGROUND $35A0 $37FF       ; Bank $00
  20. .UNBACKGROUND $3C20 $3FFF       ; Bank $00
  21. .UNBACKGROUND $7FE0 $7FFF       ; Bank $01
  22. .UNBACKGROUND $8510 $87FF       ; Bank $02
  23. .UNBACKGROUND $99B0 $AFFF       ; Bank $02
  24. .UNBACKGROUND $B9D0 $BFFF       ; Bank $02
  25. .UNBACKGROUND $E550 $F6FF       ; Bank $03
  26. .UNBACKGROUND $13A90 $13FFF     ; Bank $04
  27. .UNBACKGROUND $15940 $16FFF     ; Bank $05
  28. .UNBACKGROUND $17DA0 $17FFF     ; Bank $05
  29. .UNBACKGROUND $1B4E0 $1BFFF     ; Bank $06
  30. .UNBACKGROUND $1F950 $1FFFF     ; Bank $07
  31. .UNBACKGROUND $23780 $23FFF     ; Bank $08
  32. .UNBACKGROUND $24000 $27FFF     ; Bank $09 - The whole Bank is free
  33. .UNBACKGROUND $2BD50 $2BFFF     ; Bank $0A
  34. .UNBACKGROUND $2FF30 $2FFFF     ; Bank $0B
  35. .UNBACKGROUND $32270 $33FFF     ; Bank $0C
  36. .UNBACKGROUND $37830 $37FFF     ; Bank $0D
  37. .UNBACKGROUND $38000 $3BFFF     ; Bank $0E - The whole Bank is free
  38. .UNBACKGROUND $3C000 $3FFFF     ; Bank $0F - The whole Bank is free
  39. .UNBACKGROUND $43780 $43FFF     ; Bank $10
  40. .UNBACKGROUND $44000 $47FFF     ; Bank $11 - The whole Bank is free
  41. .UNBACKGROUND $4FA10 $4FFFF     ; Bank $13
  42. .UNBACKGROUND $53000 $53FFF     ; Bank $14
  43. .UNBACKGROUND $5C400 $5CFFF     ; Bank $17
  44. .UNBACKGROUND $5EC60 $5EFFF     ; Bank $17
  45. .UNBACKGROUND $63FC0 $63FFF     ; Bank $18
  46. .UNBACKGROUND $67FC0 $67FFF     ; Bank $19
  47. .UNBACKGROUND $6BFC0 $6BFFF     ; Bank $1A
  48. .UNBACKGROUND $6C370 $6FFFF     ; Bank $1B
  49. .UNBACKGROUND $73FF0 $73FFF     ; Bank $1C
  50. ;.UNBACKGROUND $7F6D0 $7FFFF        ; Bank $1F  ; May create a conflict with the English translation
  51.  
  52. ; Bank definitions:
  53. .define BANK_ROUTINES $09
  54. .define BANK_c1 $0E
  55. .define BANK_c2 $0F
  56. .define BANK_c3 $11
  57.  
  58. ; Routine definitions:
  59. .define COPYDATA $0E82          ; Copies BC bytes from HL to DE
  60. .define SETOFFSETCOPYDATA $0EF8 ; Prepares the destination values at $C280-$C282 and calls COPYDATA
  61. .define COPYDATAWITHBUFFER $05A1; Copies $C282* bytes from $C283 to $C280*
  62. .define SETDATA16 $0EC3         ; Writes byte A BC times to HL
  63. .define SETDATA $0EBE           ; Writes byte A B times to HL
  64. .define GETVAL $07D4            ; Loads HL (bank A) into A
  65. .define COPYTOMAP $0F11         ; COPY TO BGMAP, probably at V-Blank [Not enterly sure]
  66. .define CHANGEBANK $07A3        ; Switches ROM & RAM Bank. ROM = bits 0-4, RAM = bits 5-7
  67. .define GETFROMTABLE $101E      ; HL=HL+A*4. Used to get an item from a 4 bytes table
  68. .define GETFROMTABLEPOINTER $07E5 ; Switches to bank $FFB0, gets the table offset from HL and calls GETFROMTABLE
  69.  
  70. ; Misc.
  71. .define TEXTGFX $C477           ;
  72. .define TEXTGFXOFFSET $9600
  73. .define TEXTGFXOFFSET4 $97C0    ; This is where the graphics in the bubble are stored (4 bytes)
  74. .define TEXTGFXOFFSET1 $97B0    ; This is where the graphics in the bubble are stored (1 byte)
  75. .define ITEMSOFFSET $4958       ;
  76. .define CURRENT_BANK $FFB0      ;
  77. .define SHOWSPRITES_FLAG $C47B  ;
  78. .define BUBBLE_OFFSET $C471
  79. .define CHAR_CURPOSITION $C47F  ; Current character while reading text. Holds the text size afterwards.
  80. .define TEXT_BANK $C481         ;
  81. .define PLAYERSNAMEAUX $C3F0;$C402;$C406    ;
  82.  
  83. .define SAVEDPLAYERSNAME $CC20  ; Original offset: $CBDF
  84. .define SAVEDPLAYERSNAMESIZE $CC28  ; Used to draw only as much characters as needed
  85.  
  86. ; Flags definitions:
  87. .define INTFLAG $FFB5           ; If $FFB5=$01, [...]
  88. .define BIGTEXT_FLAG $C473
  89. .define AUXFLAG
  90.  
  91. ; Hardware definitions:
  92. .define STAT $FF41              ; LCDC Status
  93. .define VBK $FF4F               ; VRAM Bank
  94. .define SVBK $FF70              ; WRAM Bank
  95. .define BCPS $FF68              ; Background Palette Index (GBC)
  96. .define BCPD $FF69              ; Background Palette Data (GBC)
  97. .define OCPS $FF6A              ; Sprite Palette Index (GBC)
  98. .define OCPD $FF6B              ; Sprite Palette Data (GBC)
  99.  
  100. ; Main Text Routine
  101. .BANK $03 SLOT 1
  102. .ORGA $568D
  103. .SECTION "MainTextRoutine" OVERWRITE
  104.  
  105.     ld a,$03
  106.     ld ($C46E),a            ; Sets the type of text: $03=Press to continue, $02=Closes automatically, etc.
  107.  
  108.     ; Cleans letter distribution map for BGMap:
  109.     ld hl,$CAC2
  110.     ld b,$00
  111.     ld a,$FF
  112.     call SETDATA
  113.  
  114.     ; Cleans the text mask:
  115.     ld hl,$C482
  116.     ld b,$24
  117.     ld a,$FE
  118.     call SETDATA
  119.  
  120.     ; Cleans the second line of the text mask:
  121.     ld hl,$C4A6
  122.     ld b,$24
  123.     ld a,$FE
  124.     call SETDATA
  125.  
  126.     ; Cleans this unknown area:
  127.     ld hl,$C4CA
  128.     ld b,$24
  129.     xor a
  130.     call SETDATA
  131.  
  132.     ; Initializes flags (probably)
  133.     xor a
  134.     ld ($C47C),a
  135.     ld (BIGTEXT_FLAG),a
  136.     ld ($C474),a
  137.     ld ($C475),a
  138.     ld ($C534),a
  139.     ld ($C533),a
  140.     ld ($C535),a
  141.     ld ($C46C),a
  142.  
  143.     call MisteryRoutine     ; ?
  144.     call $5905              ; Prints text to RAM
  145.  
  146.     ld hl,BUBBLE_OFFSET
  147.     ldi a,(hl)
  148.     ld h,(hl)
  149.     ld l,a
  150.     ld de,$0021             ; +$0021 for the first text row
  151.     add hl,de
  152.     ld a,h
  153.     and $FB
  154.     ld h,a
  155.     ld b,$12
  156.     ld a,$B4
  157.     call COPYTOMAP          ; Cleans the first row (first text line)
  158.     ld hl,BUBBLE_OFFSET
  159.     ldi a,(hl)
  160.     ld h,(hl)
  161.     ld l,a
  162.     ld de,$0041             ; +$0041 for the second row (in-between text lines)
  163.     add hl,de
  164.     ld a,h
  165.     and $FB
  166.     ld h,a
  167.     ld b,$12
  168.     ld a,$B4
  169.     call COPYTOMAP          ; Cleans the second line
  170.     ld hl,BUBBLE_OFFSET
  171.     ldi a,(hl)
  172.     ld h,(hl)
  173.     ld l,a
  174.     ld de,$0061             ; +$0061 for the third row (second text line)
  175.     add hl,de
  176.     ld a,h
  177.     and $FB
  178.     ld h,a
  179.     ld b,$12
  180.     ld a,$B4
  181.     call COPYTOMAP
  182.  
  183.     call OutputText         ; Prints text into VRAM
  184.     call GraphicsInText     ; Routine to draw graphics on the bubble
  185.     ld a,($C474)
  186.     cp $02
  187.     call z,$59EB            ; Makes a couple of graphics blink?
  188.     ld a,(BIGTEXT_FLAG)        
  189.     and a
  190.     jp nz,$5A80             ; Print big text attributes to BGMap
  191.     jp PrintRegularText     ; Print regular text attributes to BGMap
  192. .ENDS
  193.  
  194. .ORGA $5731
  195. .SECTION "MisteryRoutine" OVERWRITE
  196. MisteryRoutine:
  197.     ld hl,CHAR_CURPOSITION
  198.     ldi a,(hl)
  199.     ld h,(hl)
  200.     ld l,a
  201.     ld a,(TEXT_BANK)
  202.     call GETVAL
  203.     inc hl
  204.     cp $F1
  205.     jr nc,SpecialChar
  206.     ld e,a
  207.     ld d,$00
  208.     ld a,($C46C)
  209.     and a
  210.     jr z,label_03.111
  211.     ld hl,$00DA
  212.     add hl,de
  213.     ld d,h
  214.     ld e,l
  215.  label_03.111:
  216.     ld hl,$CAC2
  217.     ld a,b
  218.     add a
  219.     add l
  220.     ld l,a
  221.     ld a,$00
  222.     adc h
  223.     ld h,a
  224.     ld (hl),d
  225.     inc hl
  226.     ld (hl),e
  227.     ld c,$01
  228.  
  229.  EndSpecialChar:
  230.     ld hl,CHAR_CURPOSITION
  231.     ld a,(hl)
  232.     add c
  233.     ldi (hl),a
  234.     ld a,$00
  235.     adc (hl)
  236.     ld (hl),a
  237.     ld a,b
  238.     ld hl,$C4CA
  239.     add l
  240.     ld l,a
  241.     ld a,$00
  242.     adc h
  243.     ld h,a
  244.     ld a,($C47C)
  245.     ld (hl),a
  246.     inc b
  247.     ld a,($C427)
  248.     cp $08
  249.     jr z,SavingProgress
  250.     ld a,$23
  251.     jr NotSavingProgress
  252.  SavingProgress:
  253.     ld a,$7F
  254.  NotSavingProgress:
  255.     cp b
  256.     jr nc,MisteryRoutine
  257.     ld hl,CHAR_CURPOSITION
  258.     ldi a,(hl)
  259.     ld h,(hl)
  260.     ld l,a
  261.     ld a,(TEXT_BANK)
  262.     call GETVAL
  263.     cp $FF
  264.     ret nz
  265.     ld a,$7F
  266.     ld ($C52F),a
  267.     ret
  268.  
  269.  SpecialChar:
  270.     cp $FF
  271.     jp z,$58FF
  272.     cp $FE
  273.     jp z,$58EB              ; White space
  274.     cp $FD
  275.     jp z,$58CB              ; Line break?
  276.     cp $FC
  277.     jp z,$5824
  278.     cp $FB
  279.     jr z,label_03.118
  280.     cp $FA
  281.     jp z,SpecialCharFA      ; If FA80, it prints Sable's name
  282.     cp $F9
  283.     jp z,$5877
  284.     cp $F8
  285.     jp z,$588F
  286.     cp $F7
  287.     jp z,$58C0
  288.     cp $F6
  289.     jp z,$5868
  290.     cp $F5
  291.     jp z,$58A7
  292.     cp $F4
  293.     jr z,label_03.117       ; Kanji?
  294.     cp $F3
  295.     jr z,label_03.116
  296.     cp $F2
  297.     jr z,label_03.115
  298.     cp $F1
  299.     ld a,(TEXT_BANK)
  300.     call GETVAL
  301.     ld ($C47C),a
  302.     dec b
  303.     ld c,$02
  304.     jp EndSpecialChar
  305.  label_03.115:
  306.     ld a,$01
  307.     ld ($C47A),a
  308.     dec b
  309.     ld c,$01
  310.     jp EndSpecialChar
  311.  label_03.116:
  312.     ld a,$00
  313.     ld ($C46C),a
  314.     dec b
  315.     ld c,$01
  316.     jp EndSpecialChar
  317.  label_03.117:
  318.     ld a,$01
  319.     ld ($C46C),a
  320.     dec b
  321.     ld c,$01
  322.     jp EndSpecialChar
  323.  label_03.118:
  324.     push bc
  325.     ld a,(TEXT_BANK)
  326.     call GETFROMTABLEPOINTER
  327.     call $240A
  328.     pop bc
  329.     dec b
  330.     ld c,$02
  331.     jp EndSpecialChar
  332.    
  333.  
  334.     push bc         ; $1824: $c5
  335.     ld a,($c481)        ; $1825: $fa $81 $c4
  336.     call $07d4      ; $1828: $cd $d4 $07
  337.     call $23b6      ; $182b: $cd $b6 $23
  338.     pop bc          ; $182e: $c1
  339.     dec b           ; $182f: $05
  340.     ld c,$02        ; $1830: $0e $02
  341.     jp $5761        ; $1832: $c3 $61 $57
  342.  
  343.  SpecialCharFA:
  344.     ld a,(TEXT_BANK)
  345.     call GETVAL
  346.     cp $80          ; If 80, Sable's name
  347.     push bc
  348.     call nc,$5E8b
  349.     pop bc
  350.     ld hl,$5F29
  351.     call $102d      ; $1845: $cd $2d $10
  352.     ldi a,(hl)      ; $1848: $2a
  353.     ld h,(hl)       ; $1849: $66
  354.     ld l,a          ; $184a: $6f
  355.     push bc         ; $184b: $c5
  356.     ld a,b          ; $184c: $78
  357.     add a           ; $184d: $87
  358.     ld de,$cac2     ; $184e: $11 $c2 $ca
  359.     add e           ; $1851: $83
  360.     ld e,a          ; $1852: $5f
  361.     ld a,$00        ; $1853: $3e $00
  362.     adc d           ; $1855: $8a
  363.     ld d,a          ; $1856: $57
  364.     ldi a,(hl)      ; $1857: $2a
  365.     push af         ; $1858: $f5
  366.     add a           ; $1859: $87
  367.     ld b,a          ; $185a: $47
  368.     call COPYDATA
  369.     pop af          ; $185e: $f1
  370.     dec a           ; $185f: $3d
  371.     pop bc          ; $1860: $c1
  372.     add b           ; $1861: $80
  373.     ld b,a          ; $1862: $47
  374.     ld c,$02        ; $1863: $0e $02
  375.     jp $5761        ; $1865: $c3 $61 $57
  376.     ld a,(TEXT_BANK)        ; $1868: $fa $81 $c4
  377.     call GETVAL
  378.     ld ($c477),a        ; $186e: $ea $77 $c4
  379.     dec b           ; $1871: $05
  380.     ld c,$02        ; $1872: $0e $02
  381.     jp $5761        ; $1874: $c3 $61 $57
  382.  
  383. .ENDS
  384.  
  385. .ORGA $5E94
  386. .SECTION "PlayersName" OVERWRITE
  387.  PlayersName:
  388.     ld hl,PLAYERSNAMEAUX
  389.     ld b,$08
  390.     xor a
  391.     call SETDATA
  392.     call CopyPlayersName
  393.     ;ld a,$06               ; Characters to be printed
  394.     ld a,(SAVEDPLAYERSNAMESIZE)
  395.     ;inc a
  396.     ld ($C536),a
  397.     ld hl,PLAYERSNAMEAUX
  398.     ld de,$C537
  399.     ld b,$16
  400.     call COPYDATA
  401.     jr PlayersNameEnd
  402.  
  403.  ShowCoinsCount:
  404.     ld a,($CBDB)
  405.     ldh ($8C),a
  406.     ld a,($CBDC)
  407.     ldh ($8B),a
  408.     ld a,($CBDD)
  409.     ldh ($8A),a
  410.     jr label_03.166
  411.  
  412.     ld a,($D105)
  413.     ldh ($8C),a
  414.     ld a,($D106)
  415.     ldh ($8B),a
  416.     ld a,($D107)
  417.     ldh ($8A),a
  418.    
  419.  label_03.166:
  420.     call $1F5A
  421.     xor a
  422.     ld b,a
  423.     ld c,a
  424.  label_03.167:
  425.     ld hl,$C41C
  426.     add l
  427.     ld l,a
  428.     ld a,$00
  429.     adc h
  430.     ld h,a
  431.     ld a,(hl)
  432.     cp $B7
  433.     jr z,label_03.168
  434.     add $40
  435.     push af
  436.     ld a,c
  437.     ld hl,$C537
  438.     call $102D
  439.     pop af
  440.     ld (hl),$00
  441.     inc hl
  442.     ld (hl),a
  443.     inc c
  444.  label_03.168:
  445.     inc b
  446.     ld a,b
  447.     cp $07
  448.     jr nz,label_03.167
  449.     ld a,c
  450.     ld ($C536),a
  451.  PlayersNameEnd:
  452.     xor a
  453.     ret
  454. .ENDS
  455.  
  456. .SECTION "CopyPlayersName" FREE
  457.  CopyPlayersName:
  458.     ld de,SAVEDPLAYERSNAME
  459.     ld hl,PLAYERSNAMEAUX
  460.     ld a,(de)
  461.     call PlayersNameChar
  462.     ld a,(de)
  463.     call PlayersNameChar
  464.     ld a,(de)
  465.     call PlayersNameChar
  466.     ld a,(de)
  467.     call PlayersNameChar
  468.     ld a,(de)
  469.     call PlayersNameChar
  470.     ld a,(de)
  471.  PlayersNameChar:
  472.     inc de
  473.     cp $FF
  474.     jr nz,PlayersNameKeepGoing
  475.     ld a,$FF
  476.     ldi (hl),a
  477.     ldi (hl),a
  478.     ret
  479.  PlayersNameKeepGoing:
  480.     add $50
  481.     ld (hl),$00
  482.     inc hl
  483.     ld (hl),a
  484.     inc hl
  485.     ret
  486. .ENDS
  487.  
  488. .ORGA $597E
  489. .SECTION "OutputText" OVERWRITE
  490.  OutputText:
  491.     ld a,(BIGTEXT_FLAG)
  492.     and a
  493.     jr z,RegularText
  494.     ld d,$08
  495.  LoopBigText:
  496.     push de
  497.     ld hl,$C4EE
  498.     ld a,d
  499.     dec a
  500.     call $102D
  501.     ldi a,(hl)
  502.     ld c,(hl)
  503.     ld b,a
  504.     and c
  505.     cp $FF
  506.     jr z,BigTextEnded
  507.     ld hl,$5800
  508.     call $1073
  509.     add hl,bc
  510.     push hl
  511.     ld hl,TEXTGFXOFFSET
  512.     ld c,d
  513.     ld b,$00
  514.     dec c
  515.     call $1073
  516.     add hl,bc
  517.     ld d,h
  518.     ld e,l
  519.     pop hl
  520.     ld b,$40
  521.     ld a,$14
  522.     call COPYDATA_A
  523.  BigTextEnded:
  524.     pop de
  525.     dec d
  526.     jr nz,LoopBigText
  527.     ret
  528.  
  529.  RegularText:
  530.     ld d,$20
  531.  LoopRegularText:
  532.     push de
  533.     ld hl,$C4EE
  534.     ld a,d
  535.     dec a
  536.     call $102D
  537.     ldi a,(hl)
  538.     ld c,(hl)
  539.     ld b,a
  540.     and c
  541.     cp $FF
  542.     jr z,RegularTextEnded
  543.     ld hl,$4000
  544.     call $107B
  545.     add hl,bc
  546.     push hl
  547.     ld hl,TEXTGFXOFFSET
  548.     ld a,d
  549.     dec a
  550.     call $0FFC
  551.     ld d,h
  552.     ld e,l
  553.     pop hl
  554.     ld b,$10
  555.     ld a,$14
  556.     call COPYDATA_A
  557.  RegularTextEnded:
  558.     pop de
  559.     dec d
  560.     jr nz,LoopRegularText
  561.     ret
  562. .ENDS
  563.  
  564. .ORGA $59F9
  565. .SECTION "PrintRegularText" OVERWRITE
  566.  PrintRegularText:
  567.     ld hl,BUBBLE_OFFSET
  568.     ldi a,(hl)
  569.     ld h,(hl)
  570.     ld l,a
  571.     ld de,$0021     ; First line text
  572.     add hl,de
  573.     ld a,h
  574.     and $FB
  575.     ld d,a
  576.     ld e,l
  577.     ld b,$12
  578.     ld c,$00
  579.     call label_5A22
  580.     ld hl,BUBBLE_OFFSET
  581.     ldi a,(hl)
  582.     ld h,(hl)
  583.     ld l,a
  584.     ld de,$0061     ; Second line text
  585.     add hl,de
  586.     ld a,h
  587.     and $FB
  588.     ld d,a
  589.     ld e,l
  590.     ld b,$12
  591.     ld c,$12
  592.   label_5A22:
  593.     call $5B1E
  594.     ld a,d
  595.     ld ($C280),a    ; Text VRAM offset
  596.     ld a,e
  597.     ld ($C281),a
  598.     ld a,$01
  599.     ld ($C282),a
  600.     ld a,c
  601.     ld hl,$CAC2     ; Letter distribution for BGMap
  602.     add l
  603.     ld l,a
  604.     ld a,$00
  605.     adc h
  606.     ld h,a
  607.     ld a,(hl)
  608.     add $60
  609.     cp $B4          ; If blankspace
  610.     jr nz,RegChar
  611.     call $5B0F
  612.     jr c,BlankspaceNext
  613.     xor a
  614.     ld ($C3AB),a
  615.     jr BlankspaceNext
  616.  RegChar:
  617.     ld ($C283),a
  618.     push bc
  619.     push hl
  620.     push de
  621.     ld a,$01
  622.     ldh (<INTFLAG),a
  623.     call $021F      ; Trigger for all copy data events?
  624.     ld a,($C47A)
  625.     and a
  626.     call nz,$2D54
  627.     pop de
  628.     pop hl
  629.     pop bc
  630.  BlankspaceNext:
  631.     push bc
  632.     push de
  633.     push hl
  634.     ld hl,$C4CA
  635.     ld a,c
  636.     add l
  637.     ld l,a
  638.     ld a,$00
  639.     adc h
  640.     ld h,a
  641.     ld a,(hl)
  642.     and a
  643.     call nz,$02D8
  644.     pop hl
  645.     pop de
  646.     pop bc
  647.     inc de
  648.     inc c
  649.     dec b
  650.     jr nz,label_5A22
  651.     ret
  652. .ENDS
  653.  
  654. ; Display graphics in text
  655. .BANK $03 SLOT 1
  656. .ORGA $5E10
  657. .SECTION "GraphicsInText" OVERWRITE
  658.     GraphicsInText:
  659.     ld a,(TEXTGFX)
  660.     cp $FF                      ; If TEXTGFX=$FF, no item is shown
  661.     ret z
  662.  
  663.     cp $28
  664.     jr nc,TextGFX4x4            ;
  665.     cp $24
  666.     jr nc,TextGFX1x1
  667.  TextGFX4x4:
  668.     ld hl,ITEMSOFFSET
  669.     call GETFROMTABLE
  670.     ld a,$06
  671.     call GETFROMTABLEPOINTER
  672.     ld de,TEXTGFXOFFSET4
  673.     ld b,$40
  674.     ld a,$12
  675.     call COPYDATA_A             ; Print graphics
  676.     ld a,$22
  677.     ld ($C200),a
  678.     ld hl,$C201
  679.     ld a,$7C
  680.  LoopTextGFX4x4:
  681.     ldi (hl),a
  682.     inc a
  683.     cp $80
  684.     jr nz,LoopTextGFX4x4
  685.  TextGFXFinished:
  686.     ld hl,BUBBLE_OFFSET
  687.     ldi a,(hl)
  688.     ld h,(hl)
  689.     ld l,a
  690.     ld de,$0022
  691.     add hl,de
  692.     ld a,h
  693.     and $FB
  694.     ld b,a
  695.     ld c,l
  696.     jp InputNameBuffer
  697.  
  698.  TextGFX1x1:
  699.     push af
  700.     ld hl,ITEMSOFFSET
  701.     call GETFROMTABLE
  702.     ld a,$06
  703.     call GETFROMTABLEPOINTER
  704.     ld de,TEXTGFXOFFSET1
  705.     ld b,$50
  706.     ld a,$12
  707.     call COPYDATA_A
  708.     ld a,$21
  709.     ld ($C200),a
  710.     pop af
  711.     sub $24
  712.     ld hl,$5E87
  713.     add l
  714.     ld l,a
  715.     ld a,$00
  716.     adc h
  717.     ld h,a
  718.     ld a,(hl)
  719.     ld ($C201),a
  720.     ld a,$7F
  721.     ld ($C202),a
  722.     jr TextGFXFinished
  723. .ENDS
  724.  
  725. ; It switches to Bank A, sets $C280-2, copies BC bytes from HL to DE and switches back to the original Bank
  726. .BANK 0 SLOT 0
  727. .ORG $0FC0
  728. .SECTION "COPYDATA_A" OVERWRITE
  729.     COPYDATA_A:
  730.     push bc
  731.     ld b,a                      ;
  732.     ldh a,(<CURRENT_BANK)       ;
  733.     ld c,a                      ;
  734.     ld a,b                      ; c=CURRENT_BANK
  735.     call CHANGEBANK
  736.     ld a,c                     
  737.     pop bc
  738.     push af
  739.     call SETOFFSETCOPYDATA
  740.     pop af
  741.     jp CHANGEBANK               ; Goes back to the original Bank
  742.  
  743.     ;0FD3:
  744.     push bc
  745.     ld b,a
  746.     ldh a,(<CURRENT_BANK)
  747.     ld c,a
  748.     ld a,b
  749.     call CHANGEBANK
  750.     ld a,c
  751.     pop bc
  752.     push af
  753.     call COPYDATA_C280
  754.     pop af
  755.     jp CHANGEBANK
  756.  
  757. .ENDS
  758.  
  759. .BANK 0 SLOT 0
  760. .ORG $0F2C
  761. .SECTION "COPYDATA_C280" OVERWRITE
  762. COPYDATA_C280:
  763.     push de
  764.     push hl
  765.     ld l,$40
  766.     ld a,c
  767.     sub $40
  768.     ld c,a
  769.     ld a,b
  770.     sbc $00
  771.     ld b,a                  ; BC=BC-$0040
  772.     jr nc,COPYDATA_C280_Regular
  773.     ld a,c
  774.     add $40
  775.     ld l,a
  776.     ld bc,$0000
  777. COPYDATA_C280_Regular:
  778.     push bc
  779.     ld bc,$C280
  780.     ld a,d
  781.     ld (bc),a
  782.     inc bc
  783.     ld a,e
  784.     ld (bc),a
  785.     inc bc
  786.     ld a,l
  787.     ld (bc),a
  788.     inc bc
  789.     ld d,b
  790.     ld e,c
  791.     pop bc
  792.     pop hl
  793.     push hl
  794.     push bc
  795.     ld b,$40
  796.     call COPYDATA
  797.     ld a,$01
  798.     ldh (<INTFLAG),a        ; This triggers a copy data event at $C280
  799.     call $021F              ; Trigger for all copy data events?
  800.     pop bc
  801.     pop hl
  802.     pop de
  803.     ld a,e
  804.     add $40
  805.     ld e,a
  806.     ld a,d
  807.     adc $00
  808.     ld d,a
  809.     ld a,l
  810.     add $40
  811.     ld l,a
  812.     ld a,h
  813.     adc $00
  814.     ld h,a
  815.     ld a,b
  816.     or c
  817.     jr nz,COPYDATA_C280
  818.     ret
  819. .ENDS
  820.  
  821. ; Input Sablé's name cursor position fix
  822. .BANK $02 SLOT 1
  823. .ORGA $74D8
  824. .SECTION "InputNameCursor" OVERWRITE
  825.     ;add $1C
  826.     add $4C
  827. .ENDS
  828.  
  829.  
  830. ; Input Sablé's name
  831. .BANK $02 SLOT 1
  832. .ORGA $759B
  833. .SECTION "InputNameHook" OVERWRITE
  834.     jp label_02.171
  835. .ENDS
  836.  
  837. ; Draw Input Sablé's name screen
  838. .BANK $02 SLOT 1
  839. .ORGA $75D6
  840. .SECTION "DrawInputNameHook" OVERWRITE
  841.     call InitMemory
  842.     jp label_75D6
  843. .ENDS
  844.  
  845. .SECTION "InputName" FREE
  846.  label_02.171:
  847.     cp $FF
  848.     jr nz,NotFinished
  849.     ld a,(SAVEDPLAYERSNAMESIZE)
  850.     cp $00
  851.     ret z
  852.     dec a
  853.     ld (SAVEDPLAYERSNAMESIZE),a
  854.     ld a,$06
  855.     ld ($FF8D),a
  856.     NotFinished:
  857.     ld a,$28
  858.     ld ($C3AB),a
  859.     ld hl,$77D7
  860.     ldh a,($8E)
  861.     add l
  862.     ld l,a
  863.     ld a,$00
  864.     adc h
  865.     ld h,a
  866.     ld b,(hl)
  867.     ldh a,($8D)
  868.     ld hl,SAVEDPLAYERSNAME
  869.     add l
  870.     ld l,a
  871.     ld a,$00
  872.     adc h
  873.     ld h,a
  874.     ld (hl),b
  875.     ld hl,$FF8D
  876.     inc (hl)
  877.     ld a,(hl)
  878.     ;cp $04                 ; 4 characters
  879.     cp $06
  880.     jp nz,label_75D6
  881.     dec (hl)
  882.     jp label_75D6
  883.  
  884.  label_02.172:
  885.     ld hl,$FF8D
  886.     dec (hl)
  887.     ld a,(hl)
  888.     cp $FF
  889.     ret nz
  890.     ld (hl),$00
  891.     call $0286
  892.     jp $0798
  893.  
  894.  label_75D6:
  895.     ld a,$16                    ; ld a,$14. Low nibble is how much characters would be drawn
  896.     ld ($C200),a
  897.     ld a,(SAVEDPLAYERSNAME)
  898.     call label_7605
  899.     ld ($C201),a
  900.     ld a,(SAVEDPLAYERSNAME+1)
  901.     call label_7605
  902.     ld ($C202),a
  903.     ld a,(SAVEDPLAYERSNAME+2)
  904.     call label_7605
  905.     ld ($C203),a
  906.     ld a,(SAVEDPLAYERSNAME+3)
  907.     call label_7605
  908.     ld ($C204),a
  909.     ld a,(SAVEDPLAYERSNAME+4)
  910.     call label_7605
  911.     ld ($C205),a
  912.     ld a,(SAVEDPLAYERSNAME+5)
  913.     call label_7605
  914.     ld ($C206),a
  915.  
  916.     ld bc,$986A         ; Screen position: ld bc,$9866
  917.     jp InputNameBuffer
  918.  
  919.  label_7605:
  920.     cp $FF
  921.     jr nz,NotNullChar
  922.     ld a,$DF
  923.     ret
  924.  NotNullChar:
  925.     add $20
  926.     ret
  927.  
  928.  InitMemory:
  929.     ld a,$5F
  930.     push hl
  931.     ld hl,SAVEDPLAYERSNAME
  932.     ldi (hl),a
  933.     ldi (hl),a
  934.     ldi (hl),a
  935.     ldi (hl),a
  936.     ldi (hl),a
  937.     ldi (hl),a
  938.     ldi (hl),a
  939.     pop hl
  940.     ret
  941. .ENDS
  942.  
  943. ; Sablé's name transfer from buffer
  944. .BANK 0 SLOT 0
  945. .ORG $0537
  946. .SECTION "InputNameBuffer" OVERWRITE
  947.  InputNameBuffer:
  948.     ld l,$00
  949.     ld h,$C2
  950.     ld a,c
  951.     ldh ($8A),a
  952.     ld a,b
  953.     ldh ($8B),a
  954.     ld a,(hl)
  955.     and $0F
  956.     ldh ($8C),a
  957.     ldi a,(hl)
  958.     srl a
  959.     srl a
  960.     srl a
  961.     srl a
  962.     ld b,a
  963.  label_00.040:
  964.     xor a
  965.     ldh ($B4),a
  966.     ld de,$C180
  967.     ld a,(de)
  968.     inc de
  969.     add e
  970.     ld e,a
  971.     ld a,d
  972.     adc $00
  973.     ld d,a
  974.  label_00.041:
  975.     ldh a,($8B)
  976.     ld (de),a
  977.     inc de
  978.     ldh a,($8A)
  979.     ld (de),a
  980.     inc de
  981.     ldh a,($8C)
  982.     ld c,a
  983.     ld (de),a
  984.     inc de
  985.  label_00.042:
  986.     ldi a,(hl)
  987.     ld (de),a
  988.     inc de
  989.     dec c
  990.     jr nz,label_00.042
  991.     push bc
  992.     ldh a,($8A)
  993.     add $20
  994.     ldh ($8A),a
  995.     ldh a,($8B)
  996.     ld b,a
  997.     adc $00
  998.     ldh ($8B),a
  999.     xor b
  1000.     and $04
  1001.     jr z,label_00.043
  1002.     ldh a,($8B)
  1003.     xor $04
  1004.     ldh ($8B),a
  1005.  label_00.043:
  1006.     pop bc
  1007.     dec b
  1008.     jr nz,label_00.041
  1009.     xor a
  1010.     ld (de),a
  1011.     dec de
  1012.     ld a,e
  1013.     sub $80
  1014.     ld de,$C180
  1015.     ld (de),a
  1016.     ld a,$01
  1017.     ldh ($B4),a
  1018.     ret
  1019. .ENDS
  1020.  
  1021. ; Clean underscores
  1022. .BANK $02 SLOT 1
  1023. .ORGA $7555
  1024. .SECTION "CleanUnderscoresHook" OVERWRITE
  1025.     jp CleanUnderscores
  1026. .ENDS
  1027. .SECTION "CleanUnderscores" FREE
  1028.     CleanUnderscores:
  1029.     ld a,$24
  1030.     ld ($C3AB),a
  1031.  
  1032.     ld hl,SAVEDPLAYERSNAME
  1033.  
  1034.     ldi a,(hl)
  1035.     cp $5F
  1036.     jr nz,label_02.170
  1037.  
  1038.     ldi a,(hl)
  1039.     cp $5F
  1040.     jr nz,label_02.170
  1041.    
  1042.     ldi a,(hl)
  1043.     cp $5F
  1044.     jr nz,label_02.170
  1045.    
  1046.     ldi a,(hl)
  1047.     cp $5F
  1048.     jr nz,label_02.170
  1049.  
  1050.     ldi a,(hl)
  1051.     cp $5F
  1052.     jr nz,label_02.170
  1053.  
  1054.     ldi a,(hl)
  1055.     cp $5F
  1056.  
  1057.     ret z
  1058.  
  1059.  label_02.170:
  1060.     ld hl,SAVEDPLAYERSNAME
  1061.     ld a,(hl)
  1062.     call label_7595
  1063.     ldi (hl),a
  1064.     ld a,(hl)
  1065.     call label_7595
  1066.     ldi (hl),a
  1067.     ld a,(hl)
  1068.     call label_7595
  1069.     ldi (hl),a
  1070.     ld a,(hl)
  1071.     call label_7595
  1072.     ldi (hl),a
  1073.     ld a,(hl)
  1074.     call label_7595
  1075.     ldi (hl),a
  1076.     ld a,(hl)
  1077.     call label_7595
  1078.     ldi (hl),a
  1079.     ld a,(hl)
  1080.     call label_7595
  1081.     ld a,$01
  1082.     ldh ($C8),a
  1083.     ld a,$00
  1084.     ld ($C427),a
  1085.     xor a
  1086.     ld ($C45C),a
  1087.     ret
  1088.  label_7595:
  1089.     cp $5F
  1090.     ret nz
  1091.  
  1092.     ; Perfect opportunity to set the name size:
  1093.     ld a,(SAVEDPLAYERSNAMESIZE)
  1094.     cp 0
  1095.     jr nz,NameSizeSet
  1096.     ld a,l
  1097.     sub $20
  1098.     ld (SAVEDPLAYERSNAMESIZE),a
  1099.  
  1100.     NameSizeSet:
  1101.     ld a,$FF
  1102.     ret
  1103.    
  1104. .ENDS
  1105.  
  1106. ; Input name screen tiles
  1107. .BANK $13 SLOT 1
  1108. .ORGA $755F
  1109. .SECTION "InputTiles" OVERWRITE
  1110.     .db $2F,$4F,$46,$4B,$40,$42 ; "Prince"
  1111.     .db $DF,$DF,$DF             ; "   "
  1112. .ENDS
  1113.  
  1114. ; SAVEDPLAYERSNAME read fixes
  1115. .BANK $03 SLOT 1
  1116. .ORGA $5F04
  1117. .SECTION "SAVEDPLAYERSNAMEf2Hook" SIZE $1D OVERWRITE
  1118.     jp SAVEDPLAYERSNAMEf2
  1119.     jp SAVEDPLAYERSNAMEf2b
  1120. .ENDS
  1121. .SECTION "SAVEDPLAYERSNAMEf2" FREE
  1122.  SAVEDPLAYERSNAMEf2:
  1123.     ld de,SAVEDPLAYERSNAME
  1124.  SAVEDPLAYERSNAMEf2b:
  1125.     ld hl,PLAYERSNAMEAUX
  1126.  
  1127.     .REPEAT 5
  1128.      ld a,(de)
  1129.      call Label_5F17
  1130.     .ENDR
  1131.  
  1132.     ld a,(de)
  1133.     Label_5F17:
  1134.     inc de
  1135.     cp $FF
  1136.     jp nz,$5F21
  1137.     ld a,$FF
  1138.     ldi (hl),a
  1139.     ldi (hl),a
  1140.     ret
  1141. .ENDS
  1142.  
  1143. ; Expands Diary title box
  1144. .BANK $13 SLOT 1
  1145. .ORGA $7688
  1146. .SECTION "ExpandDiary1" OVERWRITE
  1147.     .db $E9,$EA,$EB,$EC,$E9,$EA,$EB,$EC,$E9,$EA,$EB,$EC,$E9,$EA,$EB,$EC,$E9,$EA,$EB,$EC,$E0,$E1,$E6,$E6,$E6,$E6,$E6,$E6,$E6,$E6,$E6,$E6,$E6,$E6,$E6,$E6,$E6,$E6,$E2,$E0,$E0,$E7,$00,$01,$02,$03,$04,$05,$06,$07,$08,$09,$0A,$0B,$0C,$0D,$0E,$0F,$E8,$E0,$E0,$E3,$E5,$E5,$E5,$E5,$E5,$E5,$E5,$E5,$E5,$E5,$E5,$E5,$E5,$E5,$E5,$E5,$E4,$E0
  1148. .ENDS
  1149. .BANK $03 SLOT 1
  1150. .ORGA $6208
  1151. .SECTION "ExpandDiaryText1" OVERWRITE
  1152.     .db $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$00,$53,$00,$76,$00,$6E,$00,$7F,$00,$86,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
  1153. .ENDS
  1154.  
  1155. .BANK $13 SLOT 1
  1156. .ORGA $7714
  1157. .SECTION "ExpandDiary2" OVERWRITE
  1158.     .db $C6,$C4,$10,$11,$12,$13,$14,$15,$16,$C5,$D0,$2C,$2D,$2E,$2F,$30,$31,$32,$D1,$D5,$C6,$C4,$DF,$DF,$DF,$DF,$DF,$DF,$DF,$C5,$D0,$33,$34,$35,$36,$37,$38,$39,$D1,$D5,$C6,$C4,$17,$18,$19,$1A,$1B,$1C,$1D,$C5,$D0,$DF,$DF,$DF,$DF,$DF,$DF,$DF,$D1,$D5,$C6,$C4,$DF,$DF,$DF,$DF,$DF,$DF,$DF,$C5,$D0,$3A,$3B,$3C,$3D,$3E,$3F,$40,$D1,$D5,$C6,$C4,$1E,$1F,$20,$21,$22,$23,$24,$C5,$D0,$41,$42,$43,$44,$45,$46,$47,$D1,$D5,$C6,$C4,$DF,$DF,$DF,$DF,$DF,$DF,$DF,$C5,$D0,$DF,$DF,$DF,$DF,$DF,$DF,$DF,$D1,$D5,$C6,$C4,$25,$26,$27,$28,$29,$2A,$2B,$C5,$D0,$48,$49,$4A,$4B,$4C,$4D,$4E,$D1,$D5,$C6,$C4,$DF,$DF,$DF,$DF,$DF,$DF,$DF,$C5,$D0,$DF,$DF,$DF,$DF,$DF,$DF,$DF,$D1,$D5
  1159. .ENDS
  1160.  
  1161. ; Fix Diary's name load
  1162. .BANK $03 SLOT 1
  1163. .ORGA $4975
  1164. .SECTION "DiarySlot1" OVERWRITE
  1165.     ld de,$A05E
  1166.     call $5F07
  1167.     ld hl,PLAYERSNAMEAUX
  1168.     ld de,$2D32 ;ld de,$2B30
  1169. .ENDS
  1170. .ORGA $4992
  1171. .SECTION "DiarySlot2" OVERWRITE
  1172.     ld de,$B05E
  1173.     call $5F07
  1174.     ld hl,PLAYERSNAMEAUX
  1175.     ld de,$3B40 ;ld de,$393E
  1176. .ENDS
  1177.  
  1178. ; Fix expanded Diary title
  1179. .ORGA $43EC
  1180. .SECTION "DiaryTitle1" OVERWRITE
  1181.     ld hl,$6208
  1182.     ld de,$0010
  1183.     call $25F8
  1184.     ld hl,$6240
  1185.     ld de,$1029
  1186.     call $25F8
  1187.     ld hl,$63AC
  1188.     ld de,$484E
  1189. .ENDS
  1190.  
  1191. ; Slot placeholder
  1192. .ORGA $495C
  1193. .SECTION "DiarySlot0" OVERWRITE
  1194.     ld de,$2C47
  1195. .ENDS
  1196.  
  1197. .ORGA $4612
  1198. .SECTION "WriteDiary" OVERWRITE
  1199.     ld hl,$6220
  1200.     ld de,$000F
  1201.     call $25F8
  1202.  
  1203.     ld hl,$62B0
  1204.     ld de,$102B
  1205.     call $25F8
  1206.  
  1207.     ld hl,$63C8
  1208.     ld de,$2C47
  1209.     call $25F8
  1210.  
  1211.     ld hl,$63BA
  1212.     ld de,$484E
  1213.     call $25F8
  1214.     call $5F04     
  1215.  
  1216.     ld hl,PLAYERSNAMEAUX
  1217.     ld de,$0106
  1218.     call $25F8      ; Write Comal's name
  1219. .ENDS
  1220.  
  1221. .ORGA $46C9
  1222. .SECTION "WriteDiary2" OVERWRITE
  1223.     ld hl,$633C
  1224.     ld de,$102B
  1225. .ENDS
  1226.  
  1227. .ORGA $4787
  1228. .SECTION "WriteDiary3" OVERWRITE
  1229.     ld hl,$6374
  1230.     ld de,$102B
  1231.     call $25F8
  1232.     ld hl,$6400
  1233.     ld de,$2C47
  1234.     call $25F8
  1235. .ENDS
  1236.  
  1237. .ORGA $469E
  1238. .SECTION "WriteDiary4" OVERWRITE
  1239.     ld hl,$6304
  1240.     ld de,$102B
  1241.     call $25F8
  1242. .ENDS
  1243.  
  1244. .ORGA $4C76
  1245. .SECTION "WriteDiary5" OVERWRITE
  1246.     ld hl,$62BE
  1247.     ld de,$2C4E
  1248.     call $25F8
  1249. .ENDS
  1250. .ORGA $4C8D
  1251. .SECTION "WriteDiary5b" OVERWRITE
  1252.     ld d,$2E
  1253. .ENDS
  1254.  
  1255. .ORGA $471C
  1256. .SECTION "WriteDiary6" OVERWRITE
  1257.     ld hl,$62B0
  1258.     ld de,$102B
  1259.     call $25F8
  1260.  
  1261.     ld hl,$63C8
  1262.     ld de,$2C47
  1263.     call $25F8
  1264.  
  1265.     ld hl,$63BA
  1266.     ld de,$484E
  1267.     call $25F8
  1268. .ENDS
  1269.  
  1270. .ORGA $484A
  1271. .SECTION "WriteDiary7" OVERWRITE
  1272.     ld hl,$62B0
  1273.     ld de,$102B
  1274.     call $25F8
  1275.  
  1276.     ld hl,$63C8
  1277.     ld de,$2C47
  1278.     call $25F8
  1279.  
  1280.     ld hl,$63BA
  1281.     ld de,$484E
  1282.     call $25F8
  1283. .ENDS
  1284.  
  1285. .ORGA $48ED
  1286. .SECTION "WriteDiary8" OVERWRITE
  1287.     ld hl,$6220
  1288.     ld de,$000F
  1289.     call $25F8
  1290.  
  1291.     call $5F04
  1292.     ld hl,PLAYERSNAMEAUX
  1293.     ld de,$0106
  1294.     call $25F8      ; Write Prince's name
  1295.  
  1296.     ld hl,$6304
  1297.     ld de,$102B
  1298.     call $25F8
  1299.  
  1300. .ENDS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement