-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathserver64.asm
More file actions
364 lines (263 loc) · 5.66 KB
/
server64.asm
File metadata and controls
364 lines (263 loc) · 5.66 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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
/* -*- mode: kasm -*- */
.import source "server.h"
.pc = cmdLineVars.get("pc").asNumber()
//------------------------------------------------------------------------------
install: {
lda #$00 // set CIA2 port B to input
sta $dd03
lda $dd02 // set CIA2 PA2 to output
ora #$04
sta $dd02
lda $dd0d // clear stale handshake
sei
lda #<irq // setup irq
ldx #>irq
sta $0314
stx $0315
cli
lda #$4c // install re-entry via "SYS1000"
sta $03e8
lda #<install
sta $03e9
lda #>install
sta $03ea
rts
}
//------------------------------------------------------------------------------
uninstall: {
lda #>sysirq
ldx #<sysirq
sta $0314
stx $0315
rts
}
//------------------------------------------------------------------------------
irq: {
lda $dd0d // check for strobe from PC
and #$10
beq done // no command
ldy $dd01 // read command
:ack()
!next: cpy #Command.load // dispatch command
bne !next+
jmp load
!next: cpy #Command.save
bne !next+
jmp save
!next: cpy #Command.peek
bne !next+
jmp peek
!next: cpy #Command.poke
bne !next+
jmp poke
!next: cpy #Command.jump
bne !next+
jmp jump
!next: cpy #Command.run
bne !next+
jmp run
!next: cpy #Command.inject
bne !next+
jmp inject
!next: cpy #Command.identify
bne !next+
jmp identify
!next:
done: jsr jiffy
jmp sysirq+3
}
//------------------------------------------------------------------------------
load: {
jsr readHeader
:screenOff()
:checkBasic()
ldy #$00
lda mem // check if specific memory config was requested
and #$7f
cmp #$37
bne slow
fast:
!loop: :wait()
lda $dd01
sta (start),y // write with normal memory config
:ack()
:next()
jmp done
slow:
!loop: :wait()
lda $dd01
ldx #$33 // write to ram with io disabled
stx $01
sta (start),y
lda #$37
sta $01
:ack()
:next()
done: :relinkBasic()
:screenOn()
jmp irq.done
}
//------------------------------------------------------------------------------
save: {
jsr readHeader
:screenOff()
:output()
ldy #$00
lda mem // check if specific memory config was requested
cmp #$37
beq fast
jmp slow
fast:
!loop: lda (start),y // read with normal memory config
:write()
:next()
jmp done
slow:
!loop: lda mem // read with requested memory config
sta $01
lda (start),y
ldx #$37
stx $01
:write()
:next()
done: lda #$00 // reset CIA2 port B to input
sta $dd03
:screenOn()
jmp irq.done
}
//------------------------------------------------------------------------------
poke: {
jsr read stx mem
jsr read stx bank
jsr read stx start
jsr read stx start+1
ldy #$00
:wait()
lda $dd01
tax :ack() txa
ldx mem
stx $01
sta (start),y
lda #$37
sta $01
jmp irq.done
}
//------------------------------------------------------------------------------
peek: {
jsr read stx mem
jsr read stx bank
jsr read stx start
jsr read stx start+1
:output()
ldy #$00
ldx mem
stx $01
lda (start),y
ldx #$37
stx $01
jsr write
done: :input()
jmp irq.done
}
//------------------------------------------------------------------------------
jump: {
jsr read stx mem
jsr read stx bank
ldx #$ff txs // reset stack pointer
lda #>repl pha // make sure the code jumped to can rts to basic
lda #[<repl-1] pha
jsr read txa pha // push high byte of jump address
jsr read txa pha // push low byte of jump address
lda mem // apply requested memory config
sta $01
lda #$00 tax tay pha // clear registers & push clean flags
rti // jump via rti
}
//------------------------------------------------------------------------------
run: {
jsr uninstall
ldx #$ff txs // reset stack pointer
lda #$01 sta cursor // cursor off
jsr insnewl // preprare run BASIC program
jsr restxtpt
lda #$00 // flag program mode
sta mode
jmp warmst
}
//------------------------------------------------------------------------------
inject: {
lda #>return pha
lda #<return pha
jsr read txa pha
jsr read txa pha
rts
return: nop
jmp irq.done
}
//------------------------------------------------------------------------------
identify: {
:output()
lda Server.size
jsr write
lda Server.id
jsr write
lda Server.id+1
jsr write
lda Server.id+2
jsr write
lda Server.id+3
jsr write
lda Server.id+4
jsr write
lda Server.version
jsr write
lda Server.machine
jsr write
lda Server.type
jsr write
lda Server.start
jsr write
lda Server.start+1
jsr write
lda Server.end
jsr write
lda Server.end+1
jsr write
lda memtop
jsr write
lda memtop+1
jsr write
done: :input()
jmp irq.done
}
//------------------------------------------------------------------------------
readHeader: {
jsr read stx mem
jsr read stx bank
jsr read stx start
jsr read stx start+1
jsr read stx end
jsr read stx end+1
rts
}
//------------------------------------------------------------------------------
read: {
:read()
rts
}
//------------------------------------------------------------------------------
write: {
:write()
rts
}
//------------------------------------------------------------------------------
Server: {
size: .byte $05
id: .byte 'X', 'L', 'I', 'N', 'K'
start: .word install
version: .byte $10
type: .byte $00 // 0 = RAM, 1 = ROM
machine: .byte $00 // 0 = C64
end: .word *+2
}
//------------------------------------------------------------------------------