-
Notifications
You must be signed in to change notification settings - Fork 3
/
Startup.asm
217 lines (194 loc) · 4.76 KB
/
Startup.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
207
208
209
210
211
212
213
214
215
216
217
/*
D71 and D81 writer for Commodore 128
(C) 2018 by Wiebo de Wit
Based on sources by Ernoman. Thanks!
*/
.disk [filename="d7181_for_ult.d64"]
{
[name="D7181 FOR ULT", type="prg", segments="prg_segment" ]
}
.segment prg_segment [ outPrg="d7181_for_ult.prg" ]
.import source "c128system.asm"
.import source "c128macros.asm"
:BasicUpstart128(MAIN)
.import source "input.asm"
.import source "ultio.asm"
.import source "reu.asm"
.import source "diskio.asm"
.import source "write71.asm"
.import source "write81.asm"
.import source "write.asm"
MAIN:
:SetBankConfiguration(15)
jsr DISPLAY_WELCOME
#if !EMU
jsr DISPLAY_ULTIDOS
cpx #10 // x is incremented for each char printed
bcs !+ // =>10 chars printed, so DOS is available
jsr DISPLAY_NODOS_ERROR
rts // fail. exit.
#else
jsr DISPLAY_EMU_WARNING
#endif
!:
// todo : REU check
// set and display current DOS path. default is /usb0/
ldy #0
!:
lda str_default_path,y
beq !+
sta INPUT_BUFFER,y // force path text to input buffer space
iny
jmp !-
!:
jsr ULT_SET_PATH // set path using input buffer
MENU:
#if !EMU
jsr CLOSE_RESOURCES
#endif
jsr DISPLAY_DOS_PATH // display the current path (again)
jsr DISPLAY_MENU // ask what to do
get_option:
jsr GETIN
beq get_option
cmp #$0d // enter is exit
bne !+
rts
!:
// determine action
cmp #$31
beq MENU_CHANGE_PATH
cmp #$32
beq MENU_WRITE_FILE
jmp get_option // Unknown option
MENU_CHANGE_PATH:
jsr ENTER_DOS_PATH // ask and set new path name
jsr ULT_SET_PATH
jsr DISPLAY_ULT_STATUS // get and print status
jmp MENU
MENU_WRITE_FILE:
jsr ENTER_FILE_NAME // ask for the filename
lda INPUT_BUFFER
bne !+ // empty filename means back to // empty filename means back to menu
jmp MENU
#if !EMU // Emulator cannot open the file so just pretend here
!:
jsr ULT_OPEN_FILE_READ // attempt to open the file
jsr DISPLAY_ULT_STATUS // get and print status
jsr STATUS_OK // check status. 0=ok
beq !+
jmp MENU
#endif
!:
jsr DETERMINE_IMAGE_TYPE
lda IMAGE_TYPE
bne !+
jmp MENU // Unconfirmed image type means back to MENU
!:
// ask for the device
jsr ENTER_DEVICE // get destination id
lda device
bne !+
jmp MENU // Unconfirmed device means back to MENU
!:
jsr WRITE
bcs ERROR_OCCURRED
jmp ALL_DONE
CLOSE_RESOURCES:
jsr BUFFER_CHANNEL_CLOSE
jsr COMMAND_CHANNEL_CLOSE
jsr ULT_CLOSE_FILE
rts
DETERMINE_IMAGE_TYPE:
lda #$00
sta IMAGE_TYPE
ldx #$00
ldy INPUT_LEN
cpy #$03
bcc select_manually
dey
dey
dey
!:
lda INPUT_BUFFER,y
sta extension,x
beq !+ // Null termination
inx
iny
jmp !-
!:
lda #<extension
sta str_a
lda #>extension
sta str_a + 1
lda #<d71_extension
sta str_b
lda #>d71_extension
sta str_b + 1
jsr STRCMP
bne !+
SELECTED_D71_IMAGE:
jsr DISPLAY_SELECTED_D71
lda #$01
sta IMAGE_TYPE
rts
!: lda #<d81_extension
sta str_b
lda #>d81_extension
sta str_b + 1
jsr STRCMP
bne select_manually
SELECTED_D81_IMAGE:
jsr DISPLAY_SELECTED_D81
lda #$02
sta IMAGE_TYPE
rts
select_manually:
jmp SELECT_IMAGE_TYPE
// --------------------------------------------------
ERROR_OCCURRED:
jsr DISPLAY_FAIL
jmp MENU
ALL_DONE:
jsr DISPLAY_DONE
jmp MENU
CLOSE_APP:
jsr DISPLAY_EXIT
rts
// checks if memory buffer is empty.
// carry bit is cleared if buffer is empty, set when not.
CHECK_BUFFER_EMPTY:
ldy #0
!:
lda (buffer),y
bne !+
iny
bne !-
clc
rts
!:
sec
rts
// status read from the ultimate
extension:
.text "AAA"
.byte 0
IMAGE_TYPE:
.byte 0
status:
.byte 0, 0
status_ptr:
.byte 0
.encoding "petscii_mixed"
d71_extension:
.text "d71"
.byte 0
d81_extension:
.text "d81"
.byte 0
/*
FOR SOME REASON THE UI FUNCTIONS MUST BE AT THE END
DO NOT MOVE THESE!
*/
.import source "ui_input.asm"
.import source "ui_output.asm"