-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathupgrade.asm
182 lines (169 loc) · 3.17 KB
/
upgrade.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
receiveOS:
pcall(clearBuffer)
kld(hl, windowTitle)
xor a
corelib(drawWindow)
ld de, 0x0208
ld b, 2
kld(hl, confirmUpgradeStr)
pcall(drawStr)
xor a
kld((.cursor), a)
kcall(.invertCursor)
.loop:
pcall(fastCopy)
pcall(flushKeys)
pcall(waitKey)
cp kDown
jr z, .handleDown
cp kUp
jr z, .handleUp
cp kEnter
jr z, .handleSelect
cp k2nd
jr z, .handleSelect
cp kClear
ret z
jr .loop
.handleDown:
kld(a, (.cursor))
cp 1
jr z, .loop
kcall(.invertCursor)
inc a
kcall(.invertCursor)
kld((.cursor), a)
jr .loop
.handleUp:
kld(a, (.cursor))
or a
jr z, .loop
kcall(.invertCursor)
dec a
kcall(.invertCursor)
kld((.cursor), a)
jr .loop
.handleSelect:
kld(a, (.cursor))
or a
ret z
; Here goes nothing
kjp(bootCodeReceiveOS)
.cursor:
.db 0
.invertCursor:
push af
kld(hl, caretIcon)
ld de, 0x0220
add a, a \ ld b, a \ add a, a \ add a, b ; A *= 6
add a, e
ld e, a
ld b, 5
pcall(putSpriteXOR)
pop af
ret
; From UOSRECV
; TODO: Fully port UOSRECV including unsigned patches
bootCodeReceiveOS:
di
pcall(unlockFlash)
pcall(colorSupported)
jr nz, .notColor
pcall(getBootPage)
and 0x7F
out (0x06), a
ld a, 1
out (0x0E), a
jr .color
.notColor:
pcall(getBootPage)
out (0x06), a
.color:
kld(ix, jumpPointPattern)
ld de, 0x4000
kcall(findPattern)
jr nz, _
kld(hl, (foundAddress))
ld a, h
cp 0x80
jr nc, _
ld bc, jumpPointPatternEnd - jumpPointPattern
add hl, bc
; Off to the boot code!
jp (hl)
_: ; Error
ei
kld(hl, .errorText)
kld(de, .errorOptions)
xor a
ld b, a
corelib(showMessage)
ret
.errorText:
.db "An error occured.\n"
.db "Upgrade manually.", 0
.errorOptions:
.db 1
.db "Ok", 0
foundAddress:
.dw 0
dummyRet:
ret
jumpPointPattern:
ld hl, (0x0056)
ld bc, 0x0A55A
or a
sbc hl, bc
jp z, 0x0053
jumpPointPatternEnd:
.db 0xFF
findPattern:
;Pattern in IX, starting address in DE
;Returns NZ if pattern not found
;(foundAddress) contains the address of match found
;Search pattern: terminated by 0FFh
; 0FEh is ? (one-byte wildcard)
; 0FDh is * (multi-byte wildcard)
kld(hl, dummyRet)
push hl
dec de
searchLoopRestart:
inc de
kld((foundAddress), de)
push ix
pop hl
searchLoop:
ld b, (hl)
ld a, b
inc a
or a
ret z
inc de
inc a
jr z, matchSoFar
dec de
inc a
ld c, a
;At this point, we're either the actual byte (match or no match) (C != 0)
; or * wildcard (keep going until we find our pattern byte) (C == 0)
or a
jr nz, findByte
inc hl
ld b, (hl)
findByte:
ld a, (de)
inc de
bit 7, d
ret nz
cp b
jr z, matchSoFar
;This isn't it; do we start over at the beginning of the pattern,
; or do we keep going until we find that byte?
inc c
dec c
jr z, findByte
kld(de, (foundAddress))
jr searchLoopRestart
matchSoFar:
inc hl
jr searchLoop