aboutsummaryrefslogtreecommitdiff
path: root/loader.s
blob: 7ad31aeaeeaa052d008bdf3c75a2fc589ecd009d (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
;
; TAPE LOADER
;

.include "cpcfirm.inc"
.include "loader.opt"

loader:

.ifeq DISK
	; loading from disk

	ld hl, (#0xbe7d)	; save current drive
	ld a, (hl)
	ld (#drive+1), a
.endif ; end disk code

	ld c, #0xff
	ld hl, #start
	call mc_start_program

start:
	call kl_rom_walk

.ifeq DISK
drive:
	ld a, #0		; restore drive
	ld hl, (#0xbe7d)
	ld (hl), a
.endif ; end disk code

	ld bc, #0		; set border
	call scr_set_border

	ld bc, #0		; bg color
	xor a
	call scr_set_ink

	ld a, #1			; set mode 1
	call scr_set_mode

	ld a, #0xff
	call cas_noisy ; disable tape texts

.ifeq DISK
					; first file is the SCRX
	call load_file

.else ; tape code

	ld ix, #TMP_ADDR
	ld de, #SCRX_SIZE
	call turboload

.endif ; end tape code

					; setup the palette
	ld b, #0x10
	xor a
	ld ix, #TMP_ADDR + #4
set_palette_loop:
	push bc
	push af
	ld c, (ix)
	inc ix
	ld b, c
	call scr_set_ink
	pop af
	pop bc
	inc a
	djnz set_palette_loop

	; border is already 0

	ld hl, #0xc000	; uncompress into the screen
	push hl
	ld hl, #TMP_ADDR + #0x14 ; compressed data
	push hl
	call _ucl_uncompress
	pop af
	pop af

.ifeq DISK

	ld hl, #fname_end-#1
	inc (hl)
					; load the code
	call load_file

.else ; tape code

	ld ix, #APP_ADDR
	ld de, #APP_SIZE
	call turboload

.endif ; tape code ends

	xor	a		; set mode 0
	call scr_set_mode

	; jp to the app entry point
	.db #0xc3
	.dw #APP_EP

.ifeq DISK

load_file:
	ld hl, #fname
	ld b, #fname_end-#fname

	ld de, #0x400		; temp mem (only used in tape mode)
	call cas_in_open

	push de
	pop hl
	call cas_in_direct

	call cas_in_close
	ret

fname:
	.str "MAIN.BI0"
fname_end:

.else ; tape code

turboload:
	di
	ex af, af'
	push af
	ex af, af'
	exx
	push de
	push bc
	push hl
	exx
	xor a
	ld r, a
	dec a
	call _turboload
	jp nc, 0
	exx
	pop hl
	pop bc
	pop de
	exx
	ex af, af'
	pop af
	ex af, af'
	ei
	ret

.include "turboload.s"
.endif ; end tape code

.area _DATA