module.z80 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. ;This is the code to open up and execute code from a module.
  2. #define binmin TempWord4
  3. #define binmax TempWord5
  4. #define baseptr TempWord2
  5. #define basepage TempWord3
  6. module:
  7. #ifndef INCLUDE_GRAMPKG
  8. bit nogrampkg,(iy+InternalFlags)
  9. jr z,skipgrampkg
  10. ld hl,s_grampkg
  11. rst rMov9ToOP1
  12. bcall(_ChkFindSym)
  13. ld a,b
  14. ld b,0
  15. call module_locate+6
  16. #else
  17. in a,(6)
  18. dec a
  19. ld hl,grampkg_start
  20. ld bc,grampkg_end-grampkg_start
  21. call module_located
  22. #endif
  23. ret c
  24. skipgrampkg:
  25. ld hl,module_count
  26. ld a,(hl)
  27. or a
  28. jr z,no_module_loc
  29. _:
  30. inc hl
  31. ld e,(hl)
  32. inc hl
  33. ld d,(hl)
  34. push hl
  35. push af
  36. ex de,hl
  37. call module_locate
  38. pop hl
  39. ld a,h
  40. pop hl
  41. ret c
  42. dec a
  43. jr nz,-_
  44. no_module_loc:
  45. jp nc,ErrPkgNotFound
  46. ret
  47. module_locate:
  48. call GetVarName_
  49. call GetVarInfo_
  50. ccf
  51. ret nc
  52. ; jp c,module_not_found
  53. call GetVarInfoVarFound
  54. ;now HL points to data, DE points to VAT entry, BC is size, A is page
  55. module_located:
  56. ;We already know the header is valid. We can advance HL by 6 then read 2 bytes
  57. ld bc,8
  58. ld de,cmdShadow
  59. call ReadArc
  60. ex de,hl
  61. ;table size. Make sure it doesn't exceed 384 entries, make sure not 0
  62. ld hl,(cmdShadow+6)
  63. ld c,a
  64. ld a,h
  65. or l
  66. ret z
  67. ld a,c
  68. ld bc,385 ;
  69. sbc hl,bc
  70. jr nc,module_not_found
  71. add hl,bc
  72. add hl,hl
  73. ld b,h
  74. ld c,l
  75. ld hl,moduleExec
  76. ld (binmin),hl
  77. ex de,hl
  78. call ReadArc
  79. ld (baseptr),hl ;This is the base address of the data
  80. ld (basepage),a ;
  81. ld (binmax),de
  82. ;Now we need to search for the string at (parsePtr)
  83. binsearchloop:
  84. ld hl,(binmax)
  85. ld de,(binmin)
  86. or a
  87. sbc hl,de
  88. jr z,nomatch
  89. rr h
  90. rr l
  91. res 0,l
  92. add hl,de
  93. push hl
  94. ld e,(hl)
  95. inc hl
  96. ld d,(hl)
  97. ld a,d
  98. rlca
  99. rlca
  100. and 3
  101. ld hl,basepage
  102. add a,(hl)
  103. ld hl,(baseptr)
  104. res 7,d
  105. res 6,d
  106. adc hl,de
  107. jp po,+_
  108. res 7,h
  109. set 6,h
  110. inc a
  111. _:
  112. call bincompare
  113. jr z,binmatch
  114. pop hl
  115. jr c,+_
  116. inc hl
  117. inc hl
  118. ld (binmin),hl
  119. jr binsearchloop
  120. _:
  121. ld (binmax),hl
  122. jr binsearchloop
  123. binmatch:
  124. ;a match was found
  125. pop bc
  126. inc de
  127. ld (parsePtr),de
  128. ld bc,3
  129. ld de,cmdShadow
  130. call ReadArc
  131. ld bc,(cmdShadow+1)
  132. ld de,moduleExec
  133. call ReadArc
  134. call moduleExec
  135. scf
  136. ret
  137. nomatch:
  138. module_not_found:
  139. or a
  140. ret
  141. #undefine binmin TempWord4
  142. #undefine binmax TempWord5
  143. #undefine baseptr TempWord2
  144. #undefine basepage TempWord3
  145. ;852 bytes left up to here