]> git.sur5r.net Git - cc65/blob - libsrc/runtime/lsubeq.s
Merge pull request #829 from inexorabletash/string-escapes
[cc65] / libsrc / runtime / lsubeq.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 decrement is
8 ; in ptr1, the high byte is in Y, and the decrement is in eax.
9 ;
10
11         .export         lsubeq1, lsubeqa, lsubeq
12         .importzp       sreg, ptr1
13
14         .macpack        cpu
15
16 lsubeq1:
17         lda     #$01
18
19 lsubeqa:
20         ldx     #$00
21         stx     sreg
22         stx     sreg+1
23
24 lsubeq: sty     ptr1+1                  ; Store high byte of address
25     
26         sec
27         eor     #$FF
28  .if (.cpu .bitand ::CPU_ISET_65SC02)
29         adc     (ptr1)                  ; Subtract byte 0
30         sta     (ptr1)
31         ldy     #$01                    ; Address byte 1               
32  .else
33         ldy     #$00                    ; Address low byte
34         adc     (ptr1),y                ; Subtract byte 0
35         sta     (ptr1),y
36         iny                             ; Address byte 1       
37  .endif  
38         pha                             ; Save byte 0 of result for later
39         txa
40         eor     #$FF
41         adc     (ptr1),y                ; Subtract byte 1
42         sta     (ptr1),y
43         tax
44
45         iny                             ; Address byte 2
46         lda     (ptr1),y
47         sbc     sreg
48         sta     (ptr1),y
49         sta     sreg
50
51         iny                             ; Address byte 3
52         lda     (ptr1),y
53         sbc     sreg+1
54         sta     (ptr1),y
55         sta     sreg+1
56
57         pla                             ; Retrieve byte 0 of result
58
59         rts                             ; Done
60
61
62
63