forked from gurcei/m65dbg
-
Notifications
You must be signed in to change notification settings - Fork 16
/
ftphelper.a65
166 lines (130 loc) · 2.53 KB
/
ftphelper.a65
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
; vim: set expandtab shiftwidth=2 tabstop=2:
; Little helper routine for speeding up mega65_ftp
; Basically it checks if the sector data provided matches what is on the
; SD-card at the correct address. If it matches, then it doesn't write anything.
; If it doesn't match, then it tries to write it, and indicates if the write
; was successful.
; To further help things along, we support bulk writing of sectors in this way.
; This is really just to reduce the turn-around time of commanding via the serial
; interface all the time
; Sector data starts here.
.alias sector_data $0900
; 32-bit sector number
.alias sector_number $0f00
; Single byte count of sectors
.alias sector_count $0f04
; Handshaking addresses
.alias job_done $0f05 ; set non-zero when done.
.alias sectors_written $0f06 ; set to count of sectors successfully written
.org $0c00
entry:
sei
inc $0800
; Fast CPU
lda #65
sta $0
; M65 IO
lda #$47
sta $D02f
lda #$53
sta $D02f
; Disable funny memory maps
LDA #$00
TAX
TAY
TAZ
MAP
EOM
; setup pointer to sector data
lda #<sector_data
sta $fd
lda #>sector_data
sta $fe
; Map sector buffer at $DE00-$DFFF
; Clear colour RAM at $DC00 flag, as this prevents mapping of sector buffer at $DE00
lda #$01
TRB $D030
; Actually map the sector buffer
lda #$81
sta $D680
; Set first sector address
lda sector_number+0
sta $d681
lda sector_number+1
sta $d682
lda sector_number+2
sta $d683
lda sector_number+3
sta $d684
sector_loop:
; Read sector
lda #$02
sta $d680
cardbusy:
lda $d680
and #$03
bne cardbusy
; Assume read is complete.
; Verify sector
ldy #$00
lda #<sector_data
sta $fd
lda #>sector_data
sta $fe
vloop1:
lda $de00,y
cmp ($fd),y
bne vfail
iny
bne vloop1
vloop2:
lda $df00,y
cmp ($fd),y
bne vfail
iny
bne vloop2
jmp verifyok
vfail:
; Verify failed, so write sector
lda #<sector_data
sta $fd
lda #>sector_data
sta $fe
cloop1:
lda ($fd),y
sta $de00,y
iny
bne cloop1
cloop2: inc $fe
lda ($fd),y
sta $df00,y
iny
bne cloop2
dec $fe
lda #$03
sta $d680
; Wait for write to complete
cardbusy2:
inc $d021
lda $d680
and #$03
bne cardbusy2
lda #$00
sta $d021
jmp sector_loop
verifyok:
inc sectors_written
; Advance to next sector
lda $fe
clc
adc #$02
; If there are more to do, continue
dec sector_count
bne sector_loop
; Done
lda #$01
sta job_done
endloop:
inc $d020
jmp endloop
.outfile "libexec/ftphelper.bin"