-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstring.asm
52 lines (49 loc) · 1.22 KB
/
string.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
; module for working with strings
.macro copy (source, dest, length)
; makes a copy of string
; input:
; source - source addr indirect
; dest - destination addr indirect
; length - location with length in bytes, <256
ldy :length
dey
cp lda (:source), y
sta (:dest), y
dey
bpl cp
.endm
.macro trimZero (num, length)
; trims leading zeroes from decimal number - by relocating of number back in memory
; input: num - indirect location of num you want trim
; length - length in bytes, <256
; output: num - modified inline
; register X - 1st position after relocated number == length of new number
ldy #$ff ; before 1st digit is read
ldx #0 ; index of last relocated digit
nextZero
iny
cpy #:length
bcs endofnum
lda (:num), y
beq nextZero
copyNext
tya
pha
lda (:num), y
pha
txa
tay
pla
sta (:num), y
pla
tay
iny
inx
cpy #:length
bcc copyNext ; always jump and copy next char
endofnum
cpx #0
bne end
inx ; number was zero "00000", keeping only "0"
end
.endm