Advertisement
Stranck

Bubble sort on Pokémon Yellow via ACE

Mar 22nd, 2017
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     AceStart::
  2. WRAM1:DA7f    21 1C D3    ld hl, wNumBagItems [$D31C]
  3. WRAM1:DA82    4E          ld c, (hl)
  4. WRAM1:DA83    0D          dec c                          ;Load how many items in your bag and put it in c
  5. WRAM1:DA84    23          inc hl
  6.     .L
  7. WRAM1:DA85    E5          push hl                        ;Save the starting address
  8. WRAM1:DA86    C5          push bc                        ;Save the counter
  9. WRAM1:DA87    46          ld b, (hl)
  10. WRAM1:DA88    23          inc hl
  11. WRAM1:DA89    2A          ldi a, (hl)                    ;Load the first item as "previous item" and then increment hl
  12.     .LOOP
  13. WRAM1:DA8A    56          ld d, (hl)
  14. WRAM1:DA8B    23          inc hl
  15. WRAM1:DA8C    5E          ld e, (hl)                     ;Load the actual item as "current item"
  16. WRAM1:DA8D    BB          cp e                           ;Compare the quantity of previous and current item
  17. WRAM1:DA8E    DA 9C DA    jp c, .NO [$DA9C]              ;If current quantity < previous quantity:
  18. WRAM1:DA91    E5          push hl                        ;Save hl for easy continue later
  19. WRAM1:DA92    32          ldd (hl), a
  20. WRAM1:DA93    70          ld (hl), b
  21. WRAM1:DA94    2B          dec hl
  22. WRAM1:DA95    73          ld (hl), e
  23. WRAM1:DA96    2B          dec hl
  24. WRAM1:DA97    72          ld (hl), d                    ;Switch the current item with the previous item in ram
  25. WRAM1:DA98    E1          pop hl
  26. WRAM1:DA99    C3 9E DA    jp .CONTINUE [$DA9E]          ;Get the previous status of hl and then jump to .CONTINUE
  27.     .NO                                                 ;Else:
  28. WRAM1:DA9C    7B          ld a, e
  29. WRAM1:DA9D    42          ld b, d                       ;Set the "old item" as the "current item"
  30.     .CONTINUE
  31. WRAM1:DA9E    23          inc hl                        ;Skip to the next item
  32. WRAM1:DA9F    0D          dec c
  33. WRAM1:DAA0    C2 8A DA    jp nz, .LOOP [$DA8A]          ;If all items are done:
  34. WRAM1:DAA3    C1          pop bc
  35. WRAM1:DAA4    E1          pop hl
  36. WRAM1:DAA5    0D          dec c
  37. WRAM1:DAA6    C2 85 DA    jp nz, .L [$DA85]             ;Restart, but without doing the last item. If all items are ordered, return.
  38. WRAM1:DAA9    C9          ret
  39.  
  40.  
  41. ;******************** REGISTER ORGANIZATION ********************
  42. ;                              A  F
  43. ; Previous item quantity  ->  [ ][ ]  <- Flags
  44. ;
  45. ;                              B  C
  46. ; Previous item index id  ->  [ ][ ]  <- Counter
  47. ;
  48. ;                              D  E
  49. ; Current item index id   ->  [ ][ ]  <- Current item quantity
  50.  
  51.  
  52. ;***************** HOW POKEMON SAVE YOUR ITEMS *****************
  53. ;
  54. ; WRAM1:D31C  <-  How many items you have in your bag
  55. ; WRAM1:D31D  <-  Index id of your first item
  56. ; WRAM1:D31E  <-  Quantity of your first item
  57. ; WRAM1:D31F  <-  Index id of your second item
  58. ; WRAM1:D320  <-  Quantity of your second item
  59. ; [...]
  60. ; WRAM1:D343  <- Index id of your 20th item
  61. ; WRAM1:D344  <- Quantity of your 20th item
  62. ; WRAM1:D345 = 0xFF (Cancel button, end of list item)
  63. ; WRAM1:D346 = 0x00
  64.  
  65.  
  66. ;Raw bytes for easy paste in gbc:
  67. 21 1c d3 4e 0d 23 e5 c5 46 23 2a 56 23 5e bb da 9c da e5 32 70 2b 72 e1 c3 9e da 7b 42 23 0d c2 8a da c1 e1 0d c2 85 da c9
  68. ;NOTE: pasting this in your ram will "delete" your pc box, and maybe it will also "corrupt" your save data.
  69.  
  70. ;Used for this video: https://youtu.be/XTprmo04FKY
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement