loadstr.asm 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include once <alloc.asm>
  2. ; Loads a string (ptr) from HL
  3. ; and duplicates it on dynamic memory again
  4. ; Finally, it returns result pointer in HL
  5. ;
  6. __ILOADSTR: ; This is the indirect pointer entry HL = (HL)
  7. lda z80_h ;- ld a,h
  8. sta z80_a
  9. ora z80_l ;- or l
  10. bne *+3 ;- ret z
  11. rts
  12. ldy #$00 ;- ld a,(hl)
  13. lda (z80_hl),y
  14. sta z80_a
  15. inc z80_l ;- inc hl
  16. bne *+4
  17. inc z80_h
  18. ldy #$00 ;- ld h,(hl)
  19. lda (z80_hl),y
  20. sta z80_h
  21. lda z80_a ;- ld l,a
  22. sta z80_l
  23. __LOADSTR: ; __FASTCALL__ entry
  24. lda z80_h ;- ld a,h
  25. sta z80_a
  26. ora z80_l ;- or l
  27. bne *+3 ;- ret z ; Return if NULL
  28. rts
  29. ldy #$00 ;- ld c,(hl)
  30. lda (z80_hl),y
  31. sta z80_c
  32. inc z80_l ;- inc hl
  33. bne *+4
  34. inc z80_h
  35. ldy #$00 ;- ld b,(hl)
  36. lda (z80_hl),y
  37. sta z80_b
  38. ;- dec hl ; BC = LEN(a$)
  39. inc z80_c ;- inc bc
  40. bne *+4
  41. inc z80_b
  42. inc z80_c ;- inc bc ; BC = LEN(a$) + 2 (two bytes for length)
  43. bne *+4
  44. inc z80_b
  45. lda z80_l ;- push hl
  46. pha
  47. lda z80_h
  48. pha
  49. lda z80_c ;- push bc
  50. pha
  51. lda z80_b
  52. pha
  53. jsr __MEM_ALLOC ;- call __MEM_ALLOC
  54. pla ;- pop bc ; Recover length
  55. sta z80_b
  56. pla
  57. sta z80_c
  58. pla ;- pop de ; Recover origin
  59. sta z80_d
  60. pla
  61. sta z80_e
  62. lda z80_h ;- ld a,h
  63. sta z80_a
  64. ora z80_l ;- or l
  65. bne *+3 ;- ret z ; Return if NULL (No memory)
  66. rts
  67. lda z80_e ;- ex de, hl ; ldir takes HL as source, DE as destiny, so SWAP HL,DE
  68. ldx z80_l
  69. stx z80_e
  70. sta z80_l
  71. lda z80_d
  72. ldx z80_h
  73. stx z80_d
  74. sta z80_h
  75. lda z80_e ;- push de ; Saves destiny start
  76. pha
  77. lda z80_d
  78. pha
  79. ;- ldir ; Copies string (length number included)
  80. pla ;- pop hl ; Recovers destiny in hl as result
  81. sta z80_h
  82. pla
  83. sta z80_l
  84. rts ;- ret