param.z80 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. ParamToken:
  2. ; This is a fancy routine for pushing and popping data, as well as loading parameters
  3. ; ParamA,B,... Loads parameters into these values.
  4. ; For example, if a routine is called with `prgm(Z,1,2,3` then `ParamA,B,C` will store 1->A, 2->B, 3->C
  5. ; Param'A,0,B,... acts as a push operation
  6. ; Param°A,B,... acts as a pop operation
  7. ld a,(hl)
  8. cp $AE ;'
  9. jr z,pushvars
  10. cp $0B ;°
  11. jr z,popvars
  12. ;Basically, ]?->A:]?->B:... etc.
  13. .db $FE ;start of `cp *`
  14. parse_param:
  15. inc hl
  16. ld a,(hl)
  17. inc hl
  18. call p1_VarP
  19. jr nc,+_
  20. ;Need to parse the next parameter
  21. push de
  22. push hl
  23. ld hl,qmarkVar
  24. call p1_parse_by_ptr_to_ptr
  25. pop hl
  26. ld (hl),c
  27. inc hl
  28. ld (hl),b
  29. pop hl
  30. ld a,(hl)
  31. cp 2Bh
  32. jr z,parse_param
  33. _:
  34. dec hl
  35. ld (parsePtr),hl
  36. ret
  37. pushvars:
  38. call p1_ParseNextFullArg
  39. ld a,(hl)
  40. call pushbc
  41. cp 2Bh
  42. jr z,pushvars
  43. ret
  44. popvars:
  45. inc hl
  46. ld a,(hl)
  47. inc hl
  48. call p1_VarP
  49. jr nc,+_
  50. ;Need to pop the last item off the stack and copy it to where HL points
  51. call popbc
  52. ld (hl),c
  53. inc hl
  54. ld (hl),b
  55. ex de,hl
  56. ld a,(hl)
  57. cp 2Bh
  58. jr z,popvars
  59. _:
  60. dec hl
  61. ld (parsePtr),hl
  62. ret
  63. popbc:
  64. push hl
  65. push de
  66. ; Make sure (stack_ptr)-2-(stack_base)>=0
  67. ld hl,(stack_ptr)
  68. ld de,(stack_base)
  69. dec hl
  70. scf
  71. sbc hl,de
  72. jp c,p1_ErrStackOverflow_pop
  73. add hl,de
  74. ld (stack_ptr),hl
  75. ld c,(hl)
  76. inc hl
  77. ld b,(hl)
  78. pop de
  79. pop hl
  80. ret
  81. pushbc:
  82. ld de,(stack_ptr)
  83. ld hl,(stack_top)
  84. inc de
  85. inc de
  86. or a
  87. sbc hl,de
  88. jp c,p1_ErrStackOverflow_push
  89. ex de,hl
  90. ld (stack_ptr),hl
  91. dec hl
  92. ld (hl),b
  93. dec hl
  94. ld (hl),c
  95. ret