save.asm 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. ; Save code "XXX" at address YYY of length ZZZ
  2. ; Parameters in the stack are XXX (16 bit) address of string name
  3. ; (only first 12 chars will be taken into account)
  4. ; YYY and ZZZ are 16 bit on top of the stack.
  5. ;
  6. #include once <error.asm>
  7. ;
  8. SAVE_CODE:
  9. ;- PROC
  10. ;- LOCAL MEMBOT
  11. ;- LOCAL SAVE_CONT
  12. ;- LOCAL ROM_SAVE
  13. ;- LOCAL __ERR_EMPTY
  14. ;- LOCAL SAVE_STOP
  15. ;- ROM_SAVE EQU 0970h
  16. MEMBOT EQU 23698 ; Use the CALC mem to store header
  17. ;- pop hl ; Return address
  18. ;- pop bc ; data length in bytes
  19. ;- pop de ; address start
  20. ;- ex (sp), hl ; CALLE => now hl = String
  21. ; This function will call the ROM SAVE CODE Routine
  22. ; Parameters in the stack are HL => String with SAVE name
  23. ; (only first 12 chars will be taken into account)
  24. ; DE = START address of CODE to save
  25. ; BC = Length of data in bytes
  26. __SAVE_CODE: ; INLINE version
  27. ;- ld a, b
  28. ora z80_c ;- or c
  29. ;- ret z ; Return if block length == 0
  30. lda z80_ix ;- push ix
  31. pha
  32. lda z80_ix+1
  33. pha
  34. lda z80_h ;- ld a,h
  35. sta z80_a
  36. ora z80_l ;- or l
  37. ;- jr z, __ERR_EMPTY ; Return if NULL STRING
  38. ;- ld ix, MEMBOT
  39. ;- ld (ix+00),3 ; CODE
  40. ;- ld (ix+11),c
  41. ;- ld (ix+12),b ; Store long in bytes
  42. ;- ld (ix+13),e
  43. ;- ld (ix+14),d ; Store address in bytes
  44. lda z80_l ;- push hl
  45. pha
  46. lda z80_h
  47. pha
  48. ;- ld bc, 9
  49. ;- ld hl,MEMBOT + 1
  50. ;- ld de,MEMBOT + 2
  51. ;- ld (hl), ' '
  52. ;- ldir ; Fill the filename with blanks
  53. pla ;- pop hl
  54. sta z80_h
  55. pla
  56. sta z80_l
  57. ldy #$00 ;- ld c,(hl)
  58. lda (z80_hl),y
  59. sta z80_c
  60. inc z80_l ;- inc hl
  61. bne *+4
  62. inc z80_h
  63. ldy #$00 ;- ld b,(hl)
  64. lda (z80_hl),y
  65. sta z80_b
  66. inc z80_l ;- inc hl
  67. bne *+4
  68. inc z80_h
  69. lda z80_b ;- ld a,b
  70. sta z80_a
  71. ora z80_c ;- or c
  72. __ERR_EMPTY:
  73. ;- ld a, ERROR_InvalidFileName
  74. jeq SAVE_STOP ;- jr z, SAVE_STOP ; Return if str len == 0
  75. lda z80_e ;- ex de, hl ; Saves HL in DE
  76. ldx z80_l
  77. stx z80_e
  78. sta z80_l
  79. lda z80_d
  80. ldx z80_h
  81. stx z80_d
  82. sta z80_h
  83. lda #<10 ;- ld hl, 10
  84. sta z80_l
  85. lda #>10
  86. sta z80_h
  87. ora z80_a ;- or a
  88. ;- sbc hl, bc ; Test BC > 10?
  89. lda z80_e ;- ex de,hl
  90. ldx z80_l
  91. stx z80_e
  92. sta z80_l
  93. lda z80_d
  94. ldx z80_h
  95. stx z80_d
  96. sta z80_h
  97. ;- jr nc,SAVE_CONT ; Ok BC <= 10
  98. ;- ld bc,10 ; BC at most 10 chars
  99. SAVE_CONT:
  100. ;- ld de, MEMBOT + 1
  101. ;- ldir ; Copy String block NAME
  102. ;- ld l,(ix+13)
  103. ;- ld h,(ix+14) ; Restores start of bytes
  104. jsr ROM_SAVE ;- call ROM_SAVE
  105. ; Recovers ECHO_E since ROM SAVE changes it
  106. ;- ld hl,1821h
  107. ;- ld (23682),hl
  108. pla ;- pop ix
  109. sta z80_ix+1
  110. pla
  111. sta z80_ix
  112. rts ;- ret
  113. SAVE_STOP:
  114. pla ;- pop ix
  115. sta z80_ix+1
  116. pla
  117. sta z80_ix
  118. jmp __STOP ;- jp __STOP
  119. ;- ENDP