strarraycpy.asm 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. ; (K)opyleft - by Jose M. Rodriguez de la Rosa (a.k.a. Boriel)
  2. ; 2009 - This is Free OpenSource BSD code
  3. ; vim: et:ts=4:sw=4
  4. ; Copies a vector of strings from one place to another
  5. ; reallocating strings of the destiny vector to hold source strings.
  6. ; This is used in the following code:
  7. ; DIM a$(20) : DIM b$(20): a$ = b$
  8. ;
  9. #include once <lddede.asm>
  10. #include once <strcpy.asm>
  11. ;
  12. STR_ARRAYCOPY:
  13. ; Copies an array of string a$ = b$
  14. ; Parameters in the stack:
  15. ; a$, b$, num. of elements;
  16. pla ;- pop hl ; ret address
  17. sta z80_h
  18. pla
  19. sta z80_l
  20. pla ;- pop bc ; num of elements
  21. sta z80_b
  22. pla
  23. sta z80_c
  24. pla ;- pop de ; source array + offset to the 1st elem.
  25. sta z80_d
  26. pla
  27. sta z80_e
  28. tsx ;- ex (sp), hl ; Calle -> hl = destiny array + offset to the 1st elem.
  29. lda $0103,x
  30. ldy z80_h
  31. sta z80_h
  32. tya
  33. sta $0103,x
  34. lda $0104,x
  35. ldy z80_l
  36. sta z80_l
  37. tya
  38. sta $104,x
  39. ; FASTCALL ENTRY
  40. ; HL = a$ + offset
  41. ; DE = b$ + offset
  42. ; BC = Number of elements
  43. ;
  44. __STR_ARRAYCOPY:
  45. ;- PROC
  46. ;- LOCAL LOOP
  47. LOOP:
  48. lda z80_b ;- ld a,b
  49. sta z80_a
  50. ora z80_c ;- or c
  51. bne *+3 ;- ret z ; Done!
  52. rts
  53. ;- dec bc
  54. lda z80_c ;- push bc
  55. pha
  56. lda z80_b
  57. pha
  58. lda z80_e ;- push de
  59. pha
  60. lda z80_d
  61. pha
  62. ldy #$00 ;- ld a,(hl)
  63. lda (z80_hl),y
  64. sta z80_a
  65. inc z80_l ;- inc hl
  66. bne *+4
  67. inc z80_h
  68. ldy #$00 ;- ld c,(hl)
  69. lda (z80_hl),y
  70. sta z80_c
  71. ;- dec hl
  72. lda z80_l ;- push hl
  73. pha
  74. lda z80_h
  75. pha
  76. lda z80_c ;- ld h,c
  77. sta z80_h
  78. lda z80_a ;- ld l,a
  79. sta z80_l
  80. jsr __LOAD_DE_DE ;- call __LOAD_DE_DE
  81. jsr __STRASSIGN ;- call __STRASSIGN
  82. lda z80_e ;- ex de,hl
  83. ldx z80_l
  84. stx z80_e
  85. sta z80_l
  86. lda z80_d
  87. ldx z80_h
  88. stx z80_d
  89. sta z80_h
  90. pla ;- pop hl
  91. sta z80_h
  92. pla
  93. sta z80_l
  94. lda z80_e ;- ld (hl),e
  95. ldy #$00
  96. sta (z80_hl),y
  97. inc z80_l ;- inc hl
  98. bne *+4
  99. inc z80_h
  100. lda z80_d ;- ld (hl),d
  101. ldy #$00
  102. sta (z80_hl),y
  103. inc z80_l ;- inc hl
  104. bne *+4
  105. inc z80_h
  106. pla ;- pop de
  107. sta z80_d
  108. pla
  109. sta z80_e
  110. pla ;- pop bc
  111. sta z80_b
  112. pla
  113. sta z80_c
  114. inc z80_e ;- inc de
  115. bne *+4
  116. inc z80_d
  117. inc z80_e ;- inc de
  118. bne *+4
  119. inc z80_d
  120. jmp LOOP ;- jp LOOP
  121. ;- ENDP