1;
2; Startup for Residos packages
3;
4; $Id: zxr_crt0.asm,v 1.9 2016-05-17 21:47:58 dom Exp $
5;
6
7        MODULE	zxs_crt0
8
9        org     0
10
11        INCLUDE	"zcc_opt.def"
12	INCLUDE	"zxsysvar48.def"
13
14; Define all the restarts to go to an appropriate routine
15if (ASMPC<>$0000)
16        defs    CODE_ALIGNMENT_ERROR
17endif
18restart0:
19        jp      call_rom3
20
21        defs    $0008-ASMPC
22if (ASMPC<>$0008)
23        defs    CODE_ALIGNMENT_ERROR
24endif
25restart8:
26        ret
27
28        defs    $0010-ASMPC
29if (ASMPC<>$0010)
30        defs    CODE_ALIGNMENT_ERROR
31endif
32restart16:
33        ret
34
35        defs    $0018-ASMPC
36if (ASMPC<>$0018)
37        defs    CODE_ALIGNMENT_ERROR
38endif
39restart24:
40        ret
41
42        defs    $0020-ASMPC
43if (ASMPC<>$0020)
44        defs    CODE_ALIGNMENT_ERROR
45endif
46restart32:
47        ret
48
49        defs    $0028-ASMPC
50if (ASMPC<>$0028)
51        defs    CODE_ALIGNMENT_ERROR
52endif
53restart40:
54        ret
55
56        defs    $0030-ASMPC
57if (ASMPC<>$0030)
58        defs    CODE_ALIGNMENT_ERROR
59endif
60restart48:
61        ret
62
63; Always remember to provide an IM1 routine. It should update FRAMES as with
64; the standard 48K ROM.
65
66        defs    $0038-ASMPC
67
68if (ASMPC<>$0038)
69        defs    CODE_ALIGNMENT_ERROR
70endif
71im1routine:
72        push    af
73        push    hl
74        ld      hl,(FRAMES)
75        inc     hl
76        ld      (FRAMES),hl
77        ld      a,h
78        or      l
79        jr      nz,im1end
80        ld      a,(FRAMES+2)
81        inc     a
82        ld      (FRAMES+2),a
83im1end:
84        pop     hl
85        pop     af
86        ei
87        ret
88
89
90; Always provide an NMI routine which performs a simple RETN.
91
92        defs    $0066-ASMPC
93
94if (ASMPC<>$0066)
95        defs    CODE_ALIGNMENT_ERROR
96endif
97nmiroutine:
98        retn
99
100
101; Allow the calling of a ROM3 routine
102call_rom3:
103        ex      (sp),hl          ; get return address
104        ld      c,(hl)
105        inc     hl
106        ld      b,(hl)           ; BC=BASIC address
107        inc     hl
108        ex      (sp),hl          ; restore return address
109        push    bc
110        pop     iy               ;iy=BASIC address, as needed by RESI_BASIC
111        exx                      ; switch to alternates
112        ld      b,PKG_RESIDOS    ; ResiDOS call
113        ld      hl,RESI_BASIC    ; call BASIC
114        jp      PACKAGE_CALL_PKG ; do the package call, then return
115
116; Allow calling of +3 dos routines
117dodos:
118        exx
119        ld      b,PKG_IDEDOS	 ; We want the IDEDOS package
120        push    iy               ; Get the call into iy
121        pop     hl
122        ld      iy,23610        ; Restore IY
123        jp      PACKAGE_CALL_PKG
124
125l_dcal: jp      (hl)            ;Used for function pointer calls
126
127
128
129IF NEED_floatpack
130	defs	FLOATING_POINT_NOT_SUPPORTED_FOR_RESIDOS_PACKAGES
131ENDIF
132
133	defm    "Small C+ ZXR"   ;Unnecessary file signature
134	defb    0
135        INCLUDE "crt/classic/crt_runtime_selection.asm"
136
137	INCLUDE "crt/classic/crt_section.asm"
138
139
140
141
142