-
Notifications
You must be signed in to change notification settings - Fork 3
/
file_load.asm
206 lines (175 loc) · 5.63 KB
/
file_load.asm
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
LOAD_FILE_DISPLAY
.as
.xs
setxl
LDA #2
STA STATE_MACHINE
; initialize the SD Card
JSL ISDOS_INIT
LOAD_DIRECTORY
; no file selected
LDA #0
STA SDOS_LINE_SELECT
; Set the pointer to the beginning of the struct array
LDA #`SDCARD_LIST
STA SDOS_FILE_REC_PTR+2
STZ SDOS_FILE_REC_PTR+1
STZ SDOS_FILE_REC_PTR
JSR LOAD_SDCARD_DATA
JSR SHOW_FILE_MENU
JSR POPULATE_FILES
setxs
RTL
; ****************************************************
; * Load SD card data at SDCARD_LIST
; ****************************************************
LOAD_SDCARD_DATA
.as
.xl
; clear 1K of RAM
LDA #0
LDY #1024 ; each struct is 18 bytes long, so this allows to load a 64 entries directory
CLEAR_FILE_AREA
STA [SDOS_FILE_REC_PTR], Y
DEY
BNE CLEAR_FILE_AREA
; check if the SD card is present
LDA SDCARD_PRSNT_MNT
BEQ LOAD_SDCARD_DATA_DONE ; if SD not present, exit
; show files from the SDRAM
JSL ISDOS_READ_MBR_AND_BOOT_SECTOR
; read the root directory
JSL ISDOS_PARSE_ROOT_DIR
setal
LDA #FAT_DATA
STA SD_DATA
LDA #0
STA SD_DATA + 2
STA SD_DATA_FAT_PAGE
JSL ISDOS_READ_FAT_SECTOR
setas
LOAD_SDCARD_DATA_DONE
RTS
; ****************************************************
; * Display the file menu box
; ****************************************************
SHOW_FILE_MENU
.as
setaxl
LDA #<>CS_TEXT_MEM_PTR ; store the initial screen buffer location
STA SCREENBEGIN
LDA #<>CS_COLOR_MEM_PTR ; store the initial colour buffer location
STA CURSORPOS
setas
LDA #`CS_TEXT_MEM_PTR
STA SCREENBEGIN+2
STA CURSORPOS+2
; copy a 20 x 40 portion of the screen into memory
LDY #SCREEN_WIDTH * 10 + 30
LDA #40 ; lines to copy
STA LINE_COPY
LDX #SCREEN_WIDTH * 11 + 31 ; initialize the cursor position for file display
STX CURSORX
LDX #0
; build the screen
COPY_LINE LDA #20 ; columns to copy
STA CHAR_COPY
COPY_CHAR LDA FILE_LOAD_SCREEN,X
STA [SCREENBEGIN],Y
LDA #$50 ; yellow
STA [CURSORPOS],Y
INY
INX
DEC CHAR_COPY
BNE COPY_CHAR
setal
TYA
CLC
ADC #SCREEN_WIDTH - 20 ; skip to next line
TAY
setas
DEC LINE_COPY
BNE COPY_LINE
RTS
; ****************************************************************
; * Populate the file menu box with the files from SDCARD_LIST
; ****************************************************************
POPULATE_FILES
.as
.xl
; reset the file pointer
STZ SDOS_FILE_REC_PTR
STZ SDOS_FILE_REC_PTR+1
LDA #`SDCARD_LIST
STA SDOS_FILE_REC_PTR+2
LDX #0
; read the record type - if zero, then we're done
PF_NEXT_FILE
LDY #11
LDA [SDOS_FILE_REC_PTR],Y
BEQ PF_DONE
JSL DISPLAY_FAT_RECORD
;JSL DISPLAY_NEXT_LINE ; Print the character
setal
LDA CURSORX
CLC
ADC #SCREEN_WIDTH - 18
STA CURSORX
LDA SDOS_FILE_REC_PTR
ADC #18
STA SDOS_FILE_REC_PTR
CMP #1152
BCS PF_DONE
INX
CPX #38
BEQ PF_DONE
setas
BRA PF_NEXT_FILE
PF_DONE
setas
; Highlight the currently selected items
LDA #5 ; Yellow Background
JSL TEXT_COLOUR_SELECTED
RTS
READ_FILE
.as
.xl
LDA #0
XBA
LDA SDOS_LINE_SELECT
setaxl
STA UNSIGNED_MULT_A
; multiply by 18
LDA #18
STA UNSIGNED_MULT_B
LDA UNSIGNED_MULT_RESULT
STA SDOS_FILE_REC_PTR
; prepare the file pointer
LDA #<>RAD_FILE_TEMP
STA SD_DATA
LDA #`RAD_FILE_TEMP
STA SD_DATA + 2
; get the cluster number
LDY #16
LDA [SDOS_FILE_REC_PTR],Y
JSL ISDOS_READ_FILE
setas
JSL OPL3_INIT
; load the song
JSL RAD_INIT_PLAYER
; close the file loading menu
JSL EXIT_FILE
RTL
; ****************************************************************
; * EXIT the Load File Screen
; ****************************************************************
EXIT_FILE
.as
.xl
JSR RESET_STATE_MACHINE
JSR DRAW_DISPLAY
JSR DISPLAY_FILENAME
JSR DISPLAY_PATTERN
JSR DISPLAY_ORDERS
JSR DISPLAY_SPEED
RTL