aboutsummaryrefslogtreecommitdiff
path: root/game/src/crt0.z80
blob: c8bd1673c11fe0befc97e248e822b2c1d8791fc8 (plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
.module crt0

.globl  _main

.area   _HOME
.area   _CODE
.area   _INITIALIZER
.area   _GSINIT
.area   _GSFINAL

.area   _DATA
.area   _INITIALIZED
.area   _BSEG
.area   _BSS
.area   _HEAP

ENASLT = 0x0024
RSLREG = 0x0138
CLIKSW = 0xf3db

.area   _CODE
        ; ROM header
        .str "AB"
        .dw _main_init
        .db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0

        ; entry point skipping the init code that is used
        ; when starting from cassette
        jp _cas_main

_main_init::

        ; init the stack
        di
        ld sp, #0xf380
        ei

        ; setup memory
        ; ref: https://www.msx.org/forum/msx-talk/development/memory-pages-again

        call RSLREG
        rrca
        rrca
        and #3
        ld c, a
        add a, #0xc1
        ld l, a
        ld h, #0xfc
        ld a, (hl)
        and #0x80
        or c
        ld c, a
        inc l
        inc l
        inc l
        inc l
        ld a, (hl)
        and #0x0c
        or c
        ld h, #0x80
        call ENASLT

_cas_main::
        ; disable key click sound
        xor a
        ld (CLIKSW), a

        call gsinit
        call _main

halt0:
        halt
        jr halt0

.area   _GSINIT
gsinit::
        ld bc, #l__INITIALIZER
        ld a, b
        or a, c
        jr Z, gsinit_next
        ld de, #s__INITIALIZED
        ld hl, #s__INITIALIZER
        ldir
gsinit_next:

.area   _GSFINAL
        ret