You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.0 KiB

3 years ago
  1. SECTION "Utilities", ROM0
  2. ; Busy-wait until vertical blank occurs
  3. wait_for_vblank::
  4. ld a, [$ff41]
  5. and 3
  6. cp 1
  7. jr nz, wait_for_vblank
  8. ret
  9. ; Copy data between two regions (takes 40*N+12 cycles)
  10. ; @param bc Pointer to the destination region
  11. ; @param hl Pointer to the source region
  12. ; @param d Size (in bytes) to copy. Must be >0
  13. ; @destroy a, b, c, d, h, l
  14. memcpy::
  15. ld a, [hli] ; 8
  16. ld [bc], a ; 8
  17. inc bc ; 8
  18. dec d ; 4
  19. jr nz, memcpy ; 12/8
  20. ret ; 16
  21. ; Fill a memory region with a value
  22. ; @param hl Pointer to the destination region
  23. ; @param a Byte to fill with
  24. ; @param c Number of bytes to fill. Must be >0
  25. ; @destroy a, c, hl
  26. memset::
  27. ld [hli], a
  28. dec c
  29. jr nz, memset
  30. ret
  31. ; Divide a value by 10 (http://homepage.divms.uiowa.edu/~jones/bcd/decimal.html#division)
  32. ; @param b Dividend
  33. ; @return a Quotient
  34. ; @destroy b
  35. div10::
  36. ld a, b
  37. srl a
  38. srl a
  39. add b
  40. srl a
  41. add b
  42. srl a
  43. srl a
  44. srl a
  45. add b
  46. srl a
  47. add b
  48. srl a
  49. srl a
  50. srl a
  51. srl a
  52. ret