forked from redcode/SpecEmu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMachines.asm
289 lines (234 loc) · 10.5 KB
/
Machines.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
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
; IDM_FIRSTMACHINE & IDM_LASTMACHINE defined in SpecEmu.asm
include Machines\Spectrum_16K.asm
include Machines\Spectrum_48K.asm
include Machines\Spectrum_128K.asm
include Machines\Spectrum_Plus2.asm
include Machines\Spectrum_Plus2A.asm
include Machines\Spectrum_Plus3.asm
include Machines\Pentagon_128K.asm
include Machines\TC2048.asm
include Machines\TK90X.asm
align 16
Machine_Initialise:
invoke Init_AY
call InitPort
memcpy addr spk_mic_output_defaults, addr spk_mic_output_table, SPK_MIC_OUTPUT_SIZEOF
mov [BeepVal], BEEPERLOW ;BEEPERCENTRE
; initialise external hardware modules
invoke PLUSD_Initialise
invoke uSpeech_Initialise
call Set_Machine_Config
mov MultifacePaged, FALSE
mov Multiface_LockOut,TRUE ; Multiface locked out by default on reset
mov SoftRomPaged, FALSE
mov MicroSourcePaged, FALSE
mov PLUSD_Paged, FALSE
mov uSpeech_Paged, FALSE
mov currentMachine.nmi, FALSE
; setup display features for conventional Spectrum machines
; machines with altered display features are set in machine initialisation code
mov MACHINE.RendererEntryPoint, offset SpectrumPrepTopBorder
mov MACHINE.TopBorderLines, 24
mov MACHINE.DisplayLines, 192
mov MACHINE.BottomBorderLines, 24
mov MACHINE.DisplayWidth, 32+256+32
mov MACHINE.DisplayHeight, 24+192+24
mov MACHINE.PixelWidth, 256
mov MACHINE.BorderWidth, 32
mov MACHINE.FramesPerSecond, 50
m2m SPGfx.zxDisplayOrg, currentMachine.bank5
mov MACHINE.Plus3_Compatible, False ; +2A/+3 initialisation code will set this to True
mov MACHINE.Has_AY, TRUE
mov MACHINE.DoesSnow, TRUE
mov MACHINE.CrashesOnSnow, FALSE
mov MACHINE.HasFloatingBus, TRUE
mov MACHINE.HasLowPortContention, TRUE
mov MACHINE.Has_ULAColourArtifacts, TRUE
mov MACHINE.Has_ULAplus, TRUE
mov MACHINE.AUDIOPERIOD.SampleLoopCount, 0
mov MACHINE.REALTAPEPERIOD.SampleLoopCount, 0
mov Last7FFDWrite, 0
mov Last1FFDWrite, 0
; set all DRAMs to not have memory fade
; each machine will then set its correct values
mov eax, FALSE
mov currentMachine.DoesDRAMFade[0*4], eax
mov currentMachine.DoesDRAMFade[1*4], eax
mov currentMachine.DoesDRAMFade[2*4], eax
mov currentMachine.DoesDRAMFade[3*4], eax
mov currentMachine.DoesDRAMFade[4*4], eax
mov currentMachine.DoesDRAMFade[5*4], eax
mov currentMachine.DoesDRAMFade[6*4], eax
mov currentMachine.DoesDRAMFade[7*4], eax
switch HardwareMode
case HW_16
call Spectrum_16K_Initialise
case HW_48
call Spectrum_48K_Initialise
case HW_128
call Spectrum_128K_Initialise
case HW_PLUS2
call Spectrum_Plus2_Initialise
case HW_PLUS2A
call Spectrum_Plus2A_Initialise
case HW_PLUS3
call Spectrum_Plus3_Initialise
case HW_PENTAGON128
call Pentagon_128K_Initialise
case HW_TC2048
call TC2048_Initialise
case HW_TK90X
call TK90X_Initialise
endsw
.if CBI_Enabled == TRUE
mov CBI_Port_252, 00000000b
mov CBI_Port_255, 00001100b
wd1793_ResetDevice CBIHandle
wd1793_SetActiveCallback CBIHandle, offset AddOnFastDiskCallback
wd1793_SetDriveStepCallback CBIHandle, offset AddOnDriveStepCallback ; in Machines.asm
.endif
invoke SetSnowEffect
invoke Set_Emulate_AY
invoke InitULAplus
; clear the R refresh counters
invoke FillBuffer, addr currentMachine.refresh_counters, sizeof currentMachine.refresh_counters, 0
IFDEF WANTSOUND
call ReinitAudio ; machines can be PAL or NTSC so the audio needs reinitialising
ENDIF
invoke SetMachineStatusBar
ret
; wipes all 128K RAM banks
align 16
WipeSpeccyMem proc
ForLp eax, 0, 7
push eax
memclr [currentMachine.bank_ptrs+eax*4], 4000h
pop eax
Next eax
ret
WipeSpeccyMem endp
align 16
SetSnowEffect proc
.if Snow_Enabled == TRUE
.if MACHINE.DoesSnow == TRUE
push ebx
mov bh, z80registers.i
call Is_Contended
pop ebx
.if eax == TRUE ; does the I register address contended memory?
mov SPGfx.SnowEffect, TRUE
ret
.endif
.endif
.endif
mov SPGfx.SnowEffect, FALSE
ret
SetSnowEffect endp
align 16
Set_Emulate_AY proc
.if MACHINE.Has_AY == TRUE
mov Emulate_AY, TRUE
.else
.if AY_in_48_mode == TRUE
mov Emulate_AY, TRUE
.else
mov Emulate_AY, FALSE
mov Total_ChanA, 0
mov Total_ChanB, 0
mov Total_ChanC, 0
mov FinalChanA, 0
mov FinalChanB, 0
mov FinalChanC, 0
.endif
.endif
ret
Set_Emulate_AY endp
NO_DIVIDE macro
mov DivIDEEnabled, FALSE
endm
NO_PLUS_D macro
mov PLUSD_Enabled, FALSE
endm
NO_SOFTROM macro
mov SoftRomEnabled, FALSE
endm
NO_USPEECH macro
mov uSpeech_Enabled, FALSE
endm
NO_MICROSOURCE macro
mov MicroSourceEnabled, FALSE
endm
NO_SPECDRUM macro
mov SpecDrum_Enabled, FALSE
endm
NO_CBI macro
mov CBI_Enabled, FALSE
endm
align 16
Set_Machine_Config:
switch HardwareMode
case HW_16
case HW_48
case HW_128
NO_USPEECH
NO_MICROSOURCE
NO_SPECDRUM
NO_CBI
case HW_PLUS2
NO_USPEECH
NO_MICROSOURCE
NO_SPECDRUM
NO_CBI
case HW_PLUS2A, HW_PLUS3
NO_PLUS_D
NO_SOFTROM
NO_USPEECH
NO_MICROSOURCE
NO_SPECDRUM
NO_CBI
case HW_PENTAGON128
NO_DIVIDE
NO_PLUS_D
NO_SOFTROM
NO_USPEECH
NO_MICROSOURCE
NO_SPECDRUM
NO_CBI
case HW_TC2048
case HW_TK90X
endsw
ret
align 16
ClearContentionTable:
push edi
lea edi, ContentionTable
mov ecx, 72000
xor al, al
rep stosb
mov edi, ULAReadAddress
mov ecx, 72000
mov ax, 0FFFFh
rep stosw
pop edi
ret
align 16
AddOnFastDiskCallback:
mov trdos_active_frames, 50 ; for disk icon
.if AddOnFastDiskLoading == TRUE
mov MAXIMUMDISKSPEED, MAXIMUMDISKSPEEDFRAMES
.endif
ret
align 16
AddOnDriveStepCallback:
.if AddOnFastDiskLoading == FALSE
DSBINVOKE SetCurrentPosition, DriveStepBuffer, 0
DSBINVOKE Play, DriveStepBuffer, 0, 0, 0
.endif
ret
align 16
InstallGenie128:
invoke ZLIB_DecompressBlock, addr GenieMemDump, GENIEMEMDUMPSIZE, addr Mf128_Mem+8192, 8192
.if eax != 8192
invoke ShowMessageBox, hWnd, SADD ("Corrupted Genie data"), addr szWindowName, MB_OK or MB_ICONWARNING
.endif
ret