-
Notifications
You must be signed in to change notification settings - Fork 0
/
zxpand.asm
126 lines (98 loc) · 2.4 KB
/
zxpand.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
.module ZXPAND
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;
; return with z set if zxpand present
;
detectzxp:
ld bc,$e007
ld a,$55
out (c),a
ex (sp),hl
ex (sp),hl
in a,(c)
cp $0f
ret nz
ld a,$aa
out (c),a
ex (sp),hl
ex (sp),hl
in a,(c)
cp $f0
ret
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;
; set RAM low and install the zxpand joystick reading function
;
enablezxpandfeatures:
ld a,1
ld (zxpandenabled),a
ld hl,zxpdistxt+16
ld (hl),0
inc hl
ld (hl),'E'-' '
inc hl
ld (hl),'N'-' '
ld bc,$e007 ; go low, ram at 8-40k
ld a,$b2
out (c),a
ld hl,_readspandstick ; install zxpand joystick read function
ld (jsreadfn),hl
call readhi
ret
_readspandstick:
ld bc,$e007
ld a,$a0
out (c),a
ex (sp),hl
ex (sp),hl
in a,(c)
or %00000111 ; we need some 1 bits for 'no joy' test
ret
readhi:
ld a,(zxpandenabled)
or a
ret z
ld de,_ghiheader ; write the eeprom request header (offset, length)
ld l,2
ld a,1
call $1ffc
ld bc,$e007 ; read eeprom & wait for command completion
ld a,$ae
out (c),a
call $1ff6
ld de,_ghiheader ; read the eeprom data back
ld l,2+6
ld a,0
call $1ffc
ld a,(_ghiheader+2) ; if zedragon data is present then data will contain
cp $2d ; hex 2d as its first byte. 2d = ZD - geddit? ;)
ret nz
; we have hiscore data
ld hl,_ghiheader+3
ld de,hiscore
ldi
ldi
ldi
ret
writehi:
ld a,(zxpandenabled)
or a
ret z
ld a,$2d ; 2d = ZD - geddit? ;) id byte for hiscore data
ld (_ghiheader+2),a
ld hl,hiscore
ld de,_ghiheader+3
ldi
ldi
ldi
ld de,_ghiheader ; write eeprom data to zxpand
ld l,2+8
ld a,1
call $1ffc
ld bc,$e007 ; write eeprom & wait for command completion
ld a,$be
out (c),a
call $1ff6
ret
_ghiheader:
.byte 0,6,0,0,0,0,0,0