Advertisement
luckytyphlosion

yellow map_sprites.asm

Nov 20th, 2015
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Loads tile patterns for map's sprites.
  2. ; For outside maps, it loads one of several fixed sets of sprites.
  3. ; For inside maps, it loads each sprite picture ID used in the map header.
  4. ; This is also called after displaying text because loading
  5. ; text tile patterns overwrites half of the sprite tile pattern data.
  6. ; Note on notation:
  7. ; $C1X* and $C2X* are used to denote wSpriteStateData1-wSpriteStateData1 + $ff and wSpriteStateData2 + $00-wSpriteStateData2 + $ff sprite slot
  8. ; fields, respectively, within loops. The X is the loop index.
  9. ; If there is an inner loop, Y is the inner loop index, i.e. $C1Y* and $C2Y*
  10. ; denote fields of the sprite slots interated over in the inner loop.
  11. _InitMapSprites: ; 1401b (5:401b)
  12.     call InitOutsideMapSprites
  13.     ret c ; return if the map is an outside map (already handled by above call)
  14. ; if the map is an inside map (i.e. mapID >= $25)
  15.     call Func_14061
  16.     call Func_140b7
  17.     call Func_14150
  18.     ret
  19.    
  20. ; Loads sprite set for outside maps (cities and routes) and sets VRAM slots.
  21. ; sets carry if the map is a city or route, unsets carry if not
  22. InitOutsideMapSprites: ; 14029 (5:4029)
  23.     ld a,[wCurMap]
  24.     cp a,REDS_HOUSE_1F ; is the map a city or a route (map ID less than $25)?
  25.     ret nc ; if not, return
  26.     call GetSplitMapSpriteSetID
  27. ; if so, choose the appropriate one
  28.     ld b,a ; b = spriteSetID
  29.     ld a,[wFontLoaded]
  30.     bit 0,a ; reloading upper half of tile patterns after displaying text?
  31.     jr nz,.loadSpriteSet ; if so, forcibly reload the sprite set
  32.     ld a,[wSpriteSetID]
  33.     cp b ; has the sprite set ID changed?
  34.     jr z,.skipLoadingSpriteSet ; if not, don't load it again
  35. .loadSpriteSet
  36.     ld a,b
  37.     ld [wSpriteSetID],a
  38.     dec a
  39.     ld c,a
  40.     ld b,0
  41.     ld a, (wSpriteSetID - wSpriteSet)
  42.     ld hl,SpriteSets
  43.     call AddNTimes ; get sprite set offset
  44.     ld de, wSpriteSet
  45.     ld bc, (wSpriteSetID - wSpriteSet)
  46.     call CopyData ; copy it to wSpriteSet
  47.     call Func_140b7
  48.     call Func_14150
  49.     scf
  50.     ret
  51.    
  52. Func_14061: ; 14061 (5:4061)
  53. ; This loop stores the correct VRAM tile pattern slots according the sprite
  54. ; data from the map's header. Since the VRAM tile pattern slots are filled in
  55. ; the order of the sprite set, in order to find the VRAM tile pattern slot
  56. ; for a sprite slot, the picture ID for the sprite is looked up within the
  57. ; sprite set. The index of the picture ID within the sprite set plus one
  58. ; (since the Red sprite always has the first VRAM tile pattern slot) is the
  59. ; VRAM tile pattern slot.
  60.     ld hl, wSpriteSet
  61.     ld bc, (wSpriteSetID - wSpriteSet)
  62.     xor a
  63.     call FillMemory
  64.     ld a, SPRITE_RED
  65.     ld [wSpriteSet], a
  66.     ld hl,wSpriteStateData1 + $10
  67.     ld a,$0e
  68. .storeVRAMSlotsLoop
  69.     push af
  70.     ld a, [hl] ; $C1X0 (picture ID) (zero if sprite slot is not used)
  71.     and a ; is the sprite slot used?
  72.     jr z,.continue ; if the sprite slot is not used
  73.     ld c, a
  74.     call Func_140ac
  75.     jr nc, .asm_1408a
  76.     ld de, wSpriteSet + 9
  77.     ld b, 2
  78.     call Func_1409b
  79.     jr .continue
  80. .asm_1408a
  81.     ld de, wSpriteSet
  82.     ld b, 9
  83.     call Func_1409b
  84. .continue
  85.     ld de, $10
  86.     add hl, de
  87.     pop af
  88.     dec a
  89.     jr nz, .storeVRAMSlotsLoop
  90.     ret
  91.  
  92. Func_1409b: ; 1409b (5:409b)
  93.     ld a, [de]
  94.     and a
  95.     jr z, .asm_140a7
  96.     cp c
  97.     ret z
  98.     dec b
  99.     jr z, .asm_140aa
  100.     inc de
  101.     jr Func_1409b
  102. .asm_140a7
  103.     ld a, c
  104.     ld [de], a
  105.     ret
  106. .asm_140aa
  107.     scf
  108.     ret
  109.  
  110. Func_140ac: ; 140ac (5:40ac)
  111.     cp SPRITE_BALL
  112.     ret z
  113.     cp SPRITE_LYING_OLD_MAN_UNUSED_2 ; probably PIKACHU_SPRITE
  114.     jr nc, .asm_140b5
  115.     and a
  116.     ret
  117. .asm_140b5
  118.     scf
  119.     ret
  120.  
  121. Func_140b7: ; 140b7 (5:40b7)
  122.     ld a, $0
  123. .loop
  124.     ld [hVRAMSlot], a
  125.     cp 9
  126.     jr nc, .asm_140c7
  127.     call LoadStillTilePattern
  128.     call LoadWalkingTilePattern
  129.     jr .continue
  130. .asm_140c7
  131.     call LoadStillTilePattern
  132. .continue
  133.     ld a, [hVRAMSlot]
  134.     inc a
  135.     cp 11
  136.     jr nz, .loop
  137.     ret
  138.    
  139. Func_140d2: ; 140d2 (5:40d2)
  140.     xor a
  141. .loop
  142.     ld [hVRAMSlot], a
  143.     cp 9
  144.     jr nc, .asm_140dc
  145.     call LoadWalkingTilePattern
  146. .asm_140dc
  147.     ld a, [hVRAMSlot]
  148.     inc a
  149.     cp 11
  150.     jr nz, .loop
  151.     ret
  152.    
  153. LoadStillTilePattern: ; 140e4 (5:40e4)
  154.     ld a, [wFontLoaded]
  155.     bit 0, a ; reloading upper half of tile patterns after displaying text?
  156.     ret nz ; if so, skip loading data into the lower half
  157.     call ReadSpriteSheetData
  158.     ret nc
  159.     call GetSpriteVRAMAddress
  160.     call CopyVideoDataAlternate ; new yellow function
  161.     ret
  162.    
  163. LoadWalkingTilePattern: ; 140f5 (5:40f5)
  164.     call ReadSpriteSheetData
  165.     ret nc
  166.     ld hl, $c0
  167.     add hl, de
  168.     ld d, h
  169.     ld e, l
  170.     call GetSpriteVRAMAddress
  171.     set 3, h ; add $800 to hl
  172.     call CopyVideoDataAlternate
  173.     ret
  174.    
  175. GetSpriteVRAMAddress: ; 14018 (5:4108)
  176.     push bc
  177.     ld a, [hVRAMSlot]
  178.     ld c, a
  179.     ld b, 0
  180.     ld hl, SpriteVRAMAddresses
  181.     add hl, bc
  182.     add hl, bc
  183.     ld a, [hli]
  184.     ld h, [hl]
  185.     ld l, a
  186.     pop bc
  187.     ret
  188.    
  189. SpriteVRAMAddresses: ; 14118 (5:4118)
  190. ; Equivalent to multiplying $C0 (number of bytes in 12 tiles) times the VRAM
  191. ; slot and adding the result to $8000 (the VRAM base address).
  192.     dw vChars0 + $c0
  193.     dw vChars0 + $180
  194.     dw vChars0 + $240
  195.     dw vChars0 + $300
  196.     dw vChars0 + $3c0
  197.     dw vChars0 + $480
  198.     dw vChars0 + $540
  199.     dw vChars0 + $600
  200.     dw vChars0 + $6c0
  201.     dw vChars0 + $780
  202.     dw vChars0 + $7c0
  203.    
  204. ReadSpriteSheetData: ; 1412e (5:412e)
  205.     ld a, [hVRAMSlot]
  206.     ld e, a
  207.     ld d, 0
  208.     ld hl, wSpriteSet
  209.     add hl, de
  210.     ld a, [hl]
  211.     and a
  212.     ret z
  213.  
  214.     dec a
  215.     ld l, a
  216.     ld h, 0
  217.     add hl, hl
  218.     add hl, hl
  219.     ld de, SpriteSheetPointerTable
  220.     add hl, de
  221.     ld e, [hl]
  222.     inc hl
  223.     ld d, [hl]
  224.     inc hl
  225.     ld c, [hl]
  226.     swap c ; get the number of tiles, not the raw byte length
  227.            ; this is because of the use of CopyVideoDataAlternate
  228.     inc hl
  229.     ld b, [hl]
  230.     inc hl
  231.     scf
  232.     ret
  233.    
  234. Func_14150: ; 14150 (5:4150)
  235.     ld a, $1
  236.     ld [wSpriteStateData2 + $e], a
  237.     ld a, $2
  238.     ld [wSpriteStateData2 + $fe], a
  239.     ld a, $e
  240.     ld hl, wSpriteStateData1 + $10
  241. .loop
  242.     ld [hVRAMSlot], a
  243.     ld a, [hl]
  244.     and a
  245.     jr z, .asm_1416f
  246.     call Func_14179
  247.     push hl
  248.     ld de, $10e
  249.     add hl, de
  250.     ld [hl], a
  251.     pop hl
  252. .asm_1416f
  253.     ld de, $10
  254.     add hl, de
  255.     ld a, [hVRAMSlot]
  256.     dec a
  257.     jr nz, .loop
  258.     ret
  259.    
  260. Func_14179: ; 14179 (5:4179)
  261.     push de
  262.     push bc
  263.     ld c, a
  264.     ld b, 11
  265.     ld de, wSpriteSet
  266.     ld a, [de]
  267.     cp c
  268.     jr z, .asm_1418d
  269.     inc de
  270.     dec b
  271.     jr nz, .asm_14181
  272.     ld a, $1
  273.     jr .done
  274. .asm_1418d
  275.     ld a, $d
  276.     sub b
  277. .done
  278.     pop bc
  279.     pop de
  280.     ret
  281.  
  282. GetSplitMapSpriteSetID: ; 14193 (5:4193)
  283.     ld e, a
  284.     ld d, 0
  285.     ld hl,MapSpriteSets
  286.     add hl, de
  287.     ld a,[hl] ; a = spriteSetID
  288.     cp a,$f0 ; does the map have 2 sprite sets?
  289.     ret c
  290. ; GetSplitMapSpriteSetID
  291. ; Chooses the correct sprite set ID depending on the player's position within
  292. ; the map for maps with two sprite sets.
  293.     cp a,$f8
  294.     jr z,.route20
  295.     ld hl,SplitMapSpriteSets
  296.     and a,$0f
  297.     dec a
  298.     add a
  299.     add a
  300.     add l
  301.     ld l,a
  302.     jr nc,.noCarry
  303.     inc h
  304. .noCarry
  305.     ld a,[hli] ; determines whether the map is split East/West or North/South
  306.     cp a,$01
  307.     ld a,[hli] ; position of dividing line
  308.     ld b,a
  309.     jr z,.eastWestDivide
  310. .northSouthDivide
  311.     ld a,[wYCoord]
  312.     jr .compareCoord
  313. .eastWestDivide
  314.     ld a,[wXCoord]
  315. .compareCoord
  316.     cp b
  317.     jr c,.loadSpriteSetID
  318. ; if in the East side or South side
  319.     inc hl
  320. .loadSpriteSetID
  321.     ld a,[hl]
  322.     ret
  323. ; Uses sprite set $01 for West side and $0A for East side.
  324. ; Route 20 is a special case because the two map sections have a more complex
  325. ; shape instead of the map simply being split horizontally or vertically.
  326. .route20
  327.     ld hl,wXCoord
  328.     ld a,[hl]
  329.     cp a,$2b
  330.     ld a,$01
  331.     ret c
  332.     ld a,[hl]
  333.     cp a,$3e
  334.     ld a,$0a
  335.     ret nc
  336.     ld a,[hl]
  337.     cp a,$37
  338.     ld b,$08
  339.     jr nc,.next
  340.     ld b,$0d
  341. .next
  342.     ld a,[wYCoord]
  343.     cp b
  344.     ld a,$0a
  345.     ret c
  346.     ld a,$01
  347.     ret
  348.  
  349. INCLUDE "data/sprite_sets.asm"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement