progmeta.z80 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #define label_index_size OP1
  2. ;This code sets up data for the program to execute
  3. ;It indexes labels, and sets up space for variables.
  4. progmeta:
  5. ;Set first byte to $FF to indicate the start of the labels index.
  6. ; Next two bytes are size
  7. ; Need to verify at least five bytes.
  8. ;
  9. ld hl,(OPS)
  10. ld de,(FPS)
  11. or a
  12. sbc hl,de
  13. ld de,5
  14. sbc hl,de
  15. ret c ;not enough RAM
  16. ld b,h
  17. ld c,l
  18. ld hl,(OPS)
  19. srl b
  20. rr c
  21. inc bc
  22. ;BC is the number entries available
  23. ld (hl),$FF
  24. dec hl
  25. dec hl
  26. dec hl
  27. ; ld (label_index_ptr),hl
  28. ld (label_index_size),bc
  29. ;
  30. ex de,hl ;points to where to write the pointers
  31. ld bc,(progStart)
  32. ld hl,(progEnd)
  33. xor a
  34. sbc hl,bc
  35. ld b,h
  36. ld c,l
  37. ld hl,(progStart)
  38. ;HL points to the start of the program
  39. ;BC is the size of the program
  40. call +_
  41. ;gotta update pointers and such
  42. ;((OPS)-DE-3)/2 is number of entries
  43. ld hl,(OPS)
  44. or a
  45. sbc hl,de
  46. srl h
  47. rr l
  48. dec hl
  49. ex de,hl
  50. ld hl,(OPS)
  51. dec hl
  52. ld (hl),d
  53. dec hl
  54. ld (hl),e
  55. ret
  56. _:
  57. ld a,$3A ;decimal point token
  58. cpir
  59. ret nz
  60. ret po
  61. ex de,hl
  62. ld (hl),d
  63. dec hl
  64. ld (hl),e
  65. dec hl
  66. ex de,hl
  67. push hl
  68. ld hl,(label_index_size)
  69. dec hl
  70. ld (label_index_size),hl
  71. ld a,h
  72. or l
  73. pop hl
  74. jr nz,-_
  75. ret
  76. #undefine label_index_size
  77. pushlabel:
  78. ;write the label string to the stack, null-terminated, followed by the address
  79. ret
  80. findlabel:
  81. ;Check if the next byte is "
  82. ; - if not, then just exit
  83. ; - Otherwise, look for the label in the label stack
  84. ; - if found
  85. ; - If the pointer is not zero, write to the output
  86. ; stream .db $ED \ .dw addr
  87. ; - If the pointer is zero, increment the size field
  88. ; and add the address to the list.
  89. ; - Otherwise, write the label string to the stack,
  90. ; null-terminated, followed by 0x0000, then a
  91. ; 16-bit word for the number of references (in this case,
  92. ; initialize to 0x0001 the address), followed by the
  93. ; address where to write when found
  94. ret