Repository navigation
Expand file tree
/
Copy pathSAMDOS.asm
More file actions
211 lines (174 loc) · 6.45 KB
/
Copy pathSAMDOS.asm
File metadata and controls
211 lines (174 loc) · 6.45 KB
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
207
208
209
210
211
;/------------------------------------------------------------------------------------------\
;| SAMDOS File Routines |
;|------------------------------------------------------------------------------------------|
;| Functions to utilies SAMDos via Hooks calls. You should be free to call these functions |
;| from almost any memory page in any location, the few things that will cause problems are |
;| if you are running across the LMPR->HMPR boundry, if you are using the FARLDIR buffer or |
;| the UIFA/DIFA Space (generally dont use 00:0B00->00:0D00). or if you have corrupted the |
;| page that dos was loaded into obvioulsy. |
;|------------------------------------------------------------------------------------------|
;| PUBLIC FUNCTIONS |
;|------------------------------------------------------------------------------------------|
;| SAMDOS_LoadFile - Loads a file to its given location |
;\------------------------------------------------------------------------------------------/
;--------------------------------------------------------------------------------------------
; Loads a file where the filename is in HL
;--------------------------------------------------------------------------------------------
; INPUT:
; HL = Filename to load
; A = Load Address
; DE = Load Offset
;--------------------------------------------------------------------------------------------
SAMDOS_LoadFile:
; Remember a few details to make life easier
ld (@SDLF_SPStore + 1), sp
ld sp, _SAMDOS_StackEnd
; Remember where we want to load it
push af
push de
; Copy the filename
ld de, _SAMDOS_FilenameStore
ld bc, 14
ldir
; We need to decide if we need to call a function in LMPR to do the load
call @SDLF_CheckAddress
@SDLF_CheckAddress: pop af
and &80
jr nz, @SDLF_LoadFromHMPR
; If we are using rom + page 0 then we can just work as though its HMPR
in a, (IO_LMPR)
cp &1f
jr z, @SDLF_LoadFromHMPR
@SDLF_LoadFromLMPR:
; Need to sort this one
jr @SDLF_LoadFromLMPR
@SDLF_LoadFromHMPR:
; We are loading from HMPR - remember LMPR
in a, (IO_LMPR)
ld (@SDLF_LMPRStore + 1),a
; Page in the right LMPR
ld a, &1f
out (IO_LMPR), a
; Move our code down
call _SAMDOS_Relocate
; Now copy the filename to the UIFA
ld hl, _SAMDOS_FilenameStore
call _SAMDOS_GetFileHeader
; Now we need to setup to load
ld ix, SAMDOS_UIFA
; Setup the length of the file
ld c, (ix + UIFA_LengthPages + 80)
ld e, (ix + UIFA_LengthMod + 80 + 0)
ld d, (ix + UIFA_LengthMod + 80 + 1)
; Now get the offset into hl - but it should be &8000+ so set bit 7
pop hl
set 7, h
; Get the page
pop af
; Now do the command
ex af, af'
ld a, DOS_HLOAD
ex af, af'
call _SAMDOS_DoCommand
; Done the load - restore everything
@SDLF_LMPRStore: ld a, 0
out (IO_LMPR), a
@SDLF_Done:
; Restore HMPR
@SDLF_SPStore: ld sp, 0
ret
;--------------------------------------------------------------------------------------------
; Sets up the UIFA for getting the file header
;--------------------------------------------------------------------------------------------
; INPUT:
; HL = Filename to load
;--------------------------------------------------------------------------------------------
_SAMDOS_GetFileHeader:
ld ix, SAMDOS_UIFA
; For now we only worry about files being code
ld a, 19
ld (ix + UIFA_FileType), a
; Now we copy the filename
ld de, SAMDOS_UIFA + UIFA_FileName
ld b, 14
@SDGFH_Loop:
; Get character
ld a, (hl)
inc hl
and a
jr nz, @SDGFH_SkipSpace
; As it was a null terminator - we need to add spaces
ld a, 32
dec hl
@SDGFH_SkipSpace:
ld (de), a
inc de
djnz @SDGFH_Loop
; Now call the get header
ex af, af'
ld a, DOS_HGTHD
ex af, af'
in a, (IO_HMPR)
call _SAMDOS_DoCommand
ret
;--------------------------------------------------------------------------------------------
; Move the code into the right part of LMPR
;--------------------------------------------------------------------------------------------
_SAMDOS_Relocate:
push hl
push de
push bc
; Move it
ld hl, _SAMDOS_RelocStart
ld de, SYS_BUFF256
ld bc, _SAMDOS_RelocSizeOf
ldir
pop bc
pop de
pop hl
ret
;--------------------------------------------------------------------------------------------
; This code gets relocated to the FARLDIR Buffer so loading can occur from anywhere.
; Input:
; A' = Command to run
; A = HMPR Page for command
;--------------------------------------------------------------------------------------------
_SAMDOS_RelocStart:
; This is where it will run from
org SYS_BUFF256
_SAMDOS_DoCommand:
; Get ready to restore pages and stack
ld (@SDDC_SPStore + 1), sp
ld sp, _SAMDOS_RelocStackEnd
; Write the command and store HMPR
ex af, af'
ld (@SDDC_DOSCommand), a
in a, (IO_HMPR)
ld (@SDDC_HMPRStore + 1), a
ex af, af'
; We can now page in HMPR
out (IO_HMPR), a
; Issue the command
rst &08
@SDDC_DOSCommand: db 0
; Now restore everything
@SDDC_HMPRStore: ld a, 0
out (IO_HMPR), a
@SDDC_SPStore: ld sp, 0
ret
;--------------------------------------------------------------------------------------------
_SAMDOS_RelocStack: ds 32
_SAMDOS_RelocStackEnd:
; Calculate the size of the reloc - must be 256 or less
_SAMDOS_RelocSizeOf: EQU (_SAMDOS_RelocStackEnd - _SAMDOS_DoCommand)
ASSERT _SAMDOS_RelocSizeOf <= 256
; Put the org address back to where it should be
org _SAMDOS_RelocStart + _SAMDOS_RelocSizeOf
_SAMDOS_RelocEnd:
;--------------------------------------------------------------------------------------------
; Variables
;--------------------------------------------------------------------------------------------
_SAMDOS_Start: ds 64
_SAMDOS_StackEnd:
_SAMDOS_FilenameStore: ds 14
;--------------------------------------------------------------------------------------------