]> git.sur5r.net Git - cc65/blob - libsrc/runtime/laddeq.s
few 6502 and some 65SC02 optimizations
[cc65] / libsrc / runtime / laddeq.s
1 ;
2 ; Ullrich von Bassewitz, 07.04.2000
3 ; Christian Krueger, 12-Mar-2017, added 65SC02 optimization
4 ;
5 ; CC65 runtime: += operator
6 ;
7 ; On entry, the low byte of the address of the variable to increment is
8 ; in ptr1, the high byte is in Y, and the increment is in eax.
9 ;
10
11         .export         laddeq1, laddeqa, laddeq
12         .importzp       sreg, ptr1, tmp1
13
14         .macpack        cpu
15
16 laddeq1:
17         lda     #$01
18
19 laddeqa:
20         ldx     #$00
21         stx     sreg
22         stx     sreg+1
23
24 laddeq: sty     ptr1+1                  ; Store high byte of address
25         clc
26
27 .if (.cpu .bitand ::CPU_ISET_65SC02)
28         adc     (ptr1)
29         sta     (ptr1)
30         ldy     #$01                    ; Address byte 1
31 .else
32         ldy     #$00                    ; Address low byte
33         adc     (ptr1),y
34         sta     (ptr1),y
35         iny                             ; Address byte 1
36 .endif
37         pha                             ; Save byte 0 of result for later
38
39         txa
40         adc     (ptr1),y                ; Load byte 1
41         sta     (ptr1),y
42         tax
43
44         iny                             ; Address byte 2
45         lda     sreg
46         adc     (ptr1),y
47         sta     (ptr1),y
48         sta     sreg
49
50         iny                             ; Address byte 3
51         lda     sreg+1
52         adc     (ptr1),y
53         sta     (ptr1),y
54         sta     sreg+1
55
56         pla                             ; Retrieve byte 0 of result
57
58         rts                             ; Done
59
60
61