storestr.asm 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. ; vim:ts=4:et:sw=4
  2. ; Stores value of current string pointed by DE register into address pointed by HL
  3. ; Returns DE = Address pointer (&a$)
  4. ; Returns HL = HL (b$ => might be needed later to free it from the heap)
  5. ;
  6. ; e.g. => HL = _variableName (DIM _variableName$)
  7. ; DE = Address into the HEAP
  8. ;
  9. ; This function will resize (REALLOC) the space pointed by HL
  10. ; before copying the content of b$ into a$
  11. ;
  12. #include once <strcpy.asm>
  13. ;
  14. __PISTORE_STR: ; Indirect assignement at (IX + BC)
  15. lda z80_ix ;- push ix
  16. pha
  17. lda z80_ix+1
  18. pha
  19. pla ;- pop hl
  20. sta z80_h
  21. pla
  22. sta z80_l
  23. lda z80_l ;- add hl,bc
  24. clc
  25. adc z80_c
  26. sta z80_l
  27. lda z80_h
  28. adc z80_b
  29. sta z80_h
  30. __ISTORE_STR: ; Indirect assignement, hl point to a pointer to a pointer to the heap!
  31. ldy #$00 ;- ld c,(hl)
  32. lda (z80_hl),y
  33. sta z80_c
  34. inc z80_l ;- inc hl
  35. bne *+4
  36. inc z80_h
  37. ldy #$00 ;- ld h,(hl)
  38. lda (z80_hl),y
  39. sta z80_h
  40. lda z80_c ;- ld l,c ; HL = (HL)
  41. sta z80_l
  42. __STORE_STR:
  43. lda z80_e ;- push de ; Pointer to b$
  44. pha
  45. lda z80_d
  46. pha
  47. lda z80_l ;- push hl ; Array pointer to variable memory address
  48. pha
  49. lda z80_h
  50. pha
  51. ldy #$00 ;- ld c,(hl)
  52. lda (z80_hl),y
  53. sta z80_c
  54. inc z80_l ;- inc hl
  55. bne *+4
  56. inc z80_h
  57. ldy #$00 ;- ld h,(hl)
  58. lda (z80_hl),y
  59. sta z80_h
  60. lda z80_c ;- ld l,c ; HL = (HL)
  61. sta z80_l
  62. jsr __STRASSIGN ;- call __STRASSIGN ; HL (a$) = DE (b$); HL changed to a new dynamic memory allocation
  63. lda z80_e ;- ex de,hl ; DE = new address of a$
  64. ldx z80_l
  65. stx z80_e
  66. sta z80_l
  67. lda z80_d
  68. ldx z80_h
  69. stx z80_d
  70. sta z80_h
  71. pla ;- pop hl ; Recover variable memory address pointer
  72. sta z80_h
  73. pla
  74. sta z80_l
  75. lda z80_e ;- ld (hl),e
  76. ldy #$00
  77. sta (z80_hl),y
  78. inc z80_l ;- inc hl
  79. bne *+4
  80. inc z80_h
  81. lda z80_d ;- ld (hl),d ; Stores a$ ptr into elemem ptr
  82. ldy #$00
  83. sta (z80_hl),y
  84. pla ;- pop hl ; Returns ptr to b$ in HL (Caller might needed to free it from memory)
  85. sta z80_h
  86. pla
  87. sta z80_l
  88. rts ;- ret