routines.z80 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. ;mov104:
  2. ; call mov52
  3. ;mov52:
  4. ; call mov26
  5. ;mov26:
  6. ; call mov13
  7. mov15: ;250cc
  8. ldi
  9. mov14: ;234cc
  10. ldi
  11. mov13: ;218cc
  12. ldi
  13. mov12: ;202cc
  14. ldi
  15. mov11:
  16. ldi
  17. ldi
  18. mov9: ;154cc
  19. ldi
  20. mov8: ;138cc
  21. ldi
  22. ldi
  23. ldi
  24. ldi
  25. mov4_page0: ;74cc
  26. ldi
  27. mov3: ;58cc
  28. ldi
  29. ldi
  30. ldi
  31. ret
  32. NextVAT:
  33. ;VATptr is the ptr
  34. ;returns z flag if no more entries
  35. call NextVat_
  36. jp VATPtrToOP1_
  37. NextVat_:
  38. ld hl,(VATptr)
  39. ld bc,-6
  40. add hl,bc
  41. sbc a,a ;HL>6, so carry flag is set
  42. sub (hl)
  43. ld c,a
  44. add hl,bc
  45. ld a,(pTemp)
  46. cp l
  47. jr nz,+_
  48. ld a,(pTemp+1)
  49. cp h
  50. jr nz,+_
  51. ld hl,(VATptr)
  52. _:
  53. ;need to verify ptr
  54. ld (VATptr),hl
  55. ret
  56. PrevVAT_valid:
  57. ;We need to start from the bottom and search until the previous one
  58. call PrevVAT_
  59. VATPtrToOP1_:
  60. jr nz,VATPtrToOP1
  61. ld hl,0
  62. ld (OP1),hl
  63. scf
  64. ret
  65. VATPtrToOP1:
  66. ld bc,-6
  67. ld a,(hl)
  68. add hl,bc
  69. ld de,OP1
  70. ld (de),a
  71. ld b,(hl)
  72. _:
  73. dec hl
  74. inc de
  75. ld a,(hl)
  76. ld (de),a
  77. djnz -_
  78. inc de
  79. xor a
  80. ld (de),a
  81. ret
  82. PrevVAT_:
  83. ld hl,(progPtr)
  84. ld de,(VATptr)
  85. PrevVAT_valid_with_start:
  86. ;returns z flag is no variable is found.
  87. ;First, set the last valid to 0
  88. xor a
  89. ld (TempWord2),a
  90. ld (TempWord2+1),a
  91. call +_
  92. ld hl,(TempWord2)
  93. ld a,h
  94. or l
  95. ld (VATPtr),hl
  96. ret
  97. _:
  98. ;Make sure there are previous entries
  99. sbc hl,de
  100. ret z
  101. add hl,de
  102. ;Check if the first entry is valid
  103. push de
  104. push hl
  105. ld (VATPtr),hl
  106. call VATPtrToOP1
  107. call isStartMenu_valid
  108. pop hl
  109. pop de
  110. jr nz,$+5
  111. _:
  112. ld (TempWord2),hl
  113. push de
  114. call NextVAT_valid
  115. ld hl,(VATPtr)
  116. pop de
  117. or a
  118. sbc hl,de
  119. add hl,de
  120. ret z
  121. jr nc,-_
  122. ret
  123. prng16:
  124. ;collaboration by Zeda with Runer112
  125. ;160cc
  126. ;26 bytes
  127. ;cycle: 4,294,901,760 (almost 4.3 billion)
  128. ld hl,(seed1)
  129. ld b,h
  130. ld c,l
  131. add hl,hl
  132. add hl,hl
  133. inc l
  134. add hl,bc
  135. ld (seed1),hl
  136. ld hl,(seed2)
  137. add hl,hl
  138. sbc a,a
  139. and %00101101
  140. xor l
  141. ld l,a
  142. ld (seed2),hl
  143. add hl,bc
  144. ret