precompile.z80 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. ;Put the name in OP1
  2. ld hl,GramTempName
  3. rst rMov9ToOP1
  4. ;Now we create the var
  5. ld a,16h
  6. ld hl,(TempWord4)
  7. bcall(_CreateVar)
  8. inc de
  9. inc de
  10. ;Copy the source to RAM
  11. ;If size is 0, just exit.
  12. ld bc,(TempWord4)
  13. ld a,b
  14. or c
  15. jr nz,+_
  16. pop hl
  17. ret
  18. _:
  19. ld hl,(TempWord5)
  20. ld a,(TempWord3)
  21. call nz,ReadArc
  22. ;Now we copy the temp var's name back to OP1 and call it good :)
  23. ld hl,OP4
  24. rst rMov9ToOP1
  25. ; ;Here is our pre-compiling code
  26. ; ;If the size is 0, exit
  27. ; ld hl,(TempWord4)
  28. ; ld a,h \ or l
  29. ; ret z
  30. ;
  31. ; ;Put the name in OP1
  32. ; ld hl,GramTempName
  33. ; rst rMov9ToOP1
  34. ;
  35. ; ;How much RAM do we have that we can allocate?
  36. ; bcall(_MemChk)
  37. ;
  38. ; ;Take off some bytes to make room for the VAT entry and size bytes
  39. ; ld bc,-20 ;at some point I have to actually calculate this. It might be -19.
  40. ; add hl,bc
  41. ; jp nc,err_LowMem ;Not even enough room for a new VAT pointer !
  42. ;
  43. ; ;Now we create the var, occupying all of RAM
  44. ; ld a,16h
  45. ; ld (size_of_buffer),hl
  46. ; bcall(_CreateVar)
  47. ;
  48. ; ;Keep the pointer to the start of the buffer safe
  49. ; inc de \ inc de
  50. ; ld (start_of_prog),de
  51. ;
  52. ; ;Copy the source code to the buffer
  53. ; ld a,(TempWord3)
  54. ; ld bc,(TempWord4)
  55. ; ld hl,(TempWord5)
  56. ; call ReadArc
  57. ;
  58. ; ;Now we set up for parsing
  59. ; ld (end_of_src),de
  60. ; ; ld hl,(start_of_prog)
  61. ; ; ld (in_head),hl
  62. ; ; ld (out_head),hl
  63. ; ; ex de,hl
  64. ; ld de,(start_of_prog)
  65. ; ld hl,(size_of_buffer)
  66. ; add hl,de
  67. ; ld (buffer_top),hl
  68. ; ld (data_top),hl
  69. ; ld h,d
  70. ; ld l,e
  71. ; ;HL points to the head of the input
  72. ; ;DE points to the head of the output
  73. ;
  74. ;
  75. ; ; ld de,(end_of_src)
  76. ; ; jp compile_dealloc
  77. ;
  78. ; _:
  79. ; ld a,(hl)
  80. ; call compile
  81. ;
  82. ; ;Make sure that HL<end_of_src
  83. ; ld a,(end_of_src)
  84. ; sub l
  85. ; ld a,(end_of_src+1)
  86. ; sbc a,h
  87. ; jr nc,-_
  88. ;
  89. ; ;Now we need to merge the output and data sections
  90. ; ;DE points to the top of the output
  91. ; ld hl,(buffer_top)
  92. ; ld bc,(data_top)
  93. ; or a
  94. ; sbc hl,bc
  95. ; jr z,+_
  96. ; ;Need to copy HL bytes at BC to DE.
  97. ; ;Swap HL and BC to use LDIR
  98. ; ld a,h
  99. ; ld h,b
  100. ; ld b,a
  101. ; ld a,l
  102. ; ld l,c
  103. ; ld c,a
  104. ; ldir
  105. ; _:
  106. ;
  107. ; compile_dealloc:
  108. ; ;Now we need to deallocate unused RAM
  109. ; ;DE points to the end of the parsed code
  110. ; ld hl,(start_of_prog)
  111. ; ex de,hl
  112. ; or a
  113. ; sbc hl,de
  114. ; ex de,hl
  115. ; ;DE is the actual size, HL points to the start of data
  116. ;
  117. ; ;Replace the size bytes
  118. ; dec hl
  119. ; ld b,(hl)
  120. ; ld (hl),d
  121. ; dec hl
  122. ; ld c,(hl)
  123. ; ld (hl),e
  124. ;
  125. ; ;Now we need to get rid of BC-DE bytes at HL+DE+2
  126. ; add hl,de
  127. ; inc hl
  128. ; inc hl
  129. ;
  130. ; ;Now we need to get rid of BC-DE bytes at HL
  131. ; ld a,c
  132. ; sub e
  133. ; ld e,a
  134. ; ld a,b
  135. ; sbc a,d
  136. ; ld d,a
  137. ;
  138. ; ;Now we need to get rid of DE bytes at HL
  139. ; bcall(_DelMem)
  140. ;
  141. ; ;Now we copy the temp var's name back to OP1 and call it good :)
  142. ; ld hl,OP4
  143. ; rst rMov9ToOP1