]> git.sur5r.net Git - cc65/blob - libsrc/runtime/lconvert.s
This commit was generated by cvs2svn to compensate for changes in r2,
[cc65] / libsrc / runtime / lconvert.s
1 ;
2 ; Ullrich von Bassewitz, 05.08.1998
3 ;
4 ; CC65 runtime: long conversion routines
5 ;
6
7 ;
8 ; Convert TOS from long to int by cutting of the high 16bit
9 ;
10         .export         tosint, tosulong, toslong, axulong, axlong
11         .import         incsp2, decsp2
12         .importzp       sp, sreg
13
14 tosint: pha
15         ldy     #0
16         lda     (sp),y          ; sp+1
17         ldy     #2
18         sta     (sp),y
19         ldy     #1
20         lda     (sp),y
21         ldy     #3
22         sta     (sp),y
23         pla
24         jmp     incsp2          ; Drop 16 bit
25
26 ;
27 ; Convert TOS from int to long
28 ;
29
30 tosulong:
31         pha
32         jsr     decsp2          ; Make room
33         ldy     #2
34         lda     (sp),y
35         ldy     #0
36         sta     (sp),y
37         ldy     #3
38         lda     (sp),y
39         ldy     #1
40         sta     (sp),y
41         lda     #0              ; Zero extend
42 toslong2:
43         iny
44         sta     (sp),y
45         iny
46         sta     (sp),y
47         pla
48         rts
49
50 toslong:
51         pha
52         jsr     decsp2          ; Make room
53         ldy     #2
54         lda     (sp),y
55         ldy     #0
56         sta     (sp),y
57         ldy     #3
58         lda     (sp),y
59         bmi     toslong1
60         ldy     #1
61         sta     (sp),y
62         lda     #$00            ; Positive, high word is zero
63         bne     toslong2
64 toslong1:
65         ldy     #1
66         sta     (sp),y
67         lda     #$FF
68         bne     toslong2
69
70 ;
71 ; Convert AX from int to long in EAX
72 ;
73
74 axulong:
75         ldy     #0
76         sty     sreg
77         sty     sreg+1
78         rts
79
80 axlong: cpx     #$80            ; Positive?
81         bcc     axulong         ; Yes, handle like unsigned type
82         ldy     #$ff
83         sty     sreg
84         sty     sreg+1
85         rts
86
87
88