-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuNBStream.pas
461 lines (414 loc) · 10.2 KB
/
uNBStream.pas
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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
{
<Grundy NewBrain Emulator Pro Made by Despsoft>
Copyright (C) 2004 <Despinidis Chris>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
}
unit uNBStream;
interface
uses uNBtypes;
Const StreamtableL=$0B00;//Object No
StreamtableH=$0C00;//Open or Close
ObjectTableP=$0700; //Page
ObjectTableL=$0800; //Offset Low
ObjectTableH=$0900; //Offset Hi
VideoTableF=$1600; //Video Table First Addr
VideoTableL=$1680; //Video Table Last Addr
type
TNBStream=Record
StrmNo:Byte;
DrvrNO:Byte;
PortNo:Byte;
UnUsed:Byte;
Memory:TPair;
End;
PNBStream=^TNBStream;
TNBStreamManipulation=Class
Public
Current:Word;
Found:Boolean;
ISCpmVideo: Boolean;
function StartMem:TPair;
Function EndMem:TPair;
Function First:TNBStream;
Function Next:TNBStream;
Function Previous:TNBStream;
Function Last:TNBStream;
Function BOST:Boolean;
Function EOST:Boolean;
Function FindStrm(StNO,DrNO,Port:Byte):TNBStream;
Function FindStrmByMem(mem:TPair):TNBStream;
function FindStrmForGraph(DrNO,Port:Byte): TNBStream;
procedure GetCPMVideo(Var pgno:Integer;Var Offs:Word);
End;
TNBPGStreamManipulation=class
private
CurrentStream: Byte;
procedure SetStreamNo(Value: Byte);
Public
ISCpmVideo: Boolean;
Constructor Create;
Function IsStreamOpen(StNo:Byte):Boolean;
function PageNo2nd: Byte;
procedure First;
procedure Next;
procedure Previous;
procedure Last;
function ObjectNo: TpAIR;
function PageOffset2nd: TPair;
function NextOpen: Boolean;
function PageNo: Byte;
function PageOffset: TPair;
procedure ActiveVideoParams(Var pg:Integer;Var Offset:Word);
function GetVideoNoByAddress(RamAdd:TPair): Integer;
function DeviceNo: Byte;
function VideoPos: Byte;
function HasGraphStream(sg:Integer): Boolean;
procedure GetCPMVideo(Var pgno:Integer;Var Offs:Word);
function GetActiveDevice33Stream(Var pg:Integer;Var Offset:Word): Integer;
published
property StreamNo: Byte read CurrentStream write SetStreamNo;
End;
implementation
uses uNBMemory,uNbScreen;
function TNBStreamManipulation.BOST: Boolean;
begin
if current<=StartMem.w then
Result:=True
else
result:=false;
end;
function TNBStreamManipulation.EndMem: TPair;
begin
result.l:=nbmem.Rom[$64];
result.h:=nbmem.ROM[$65];
end;
function TNBStreamManipulation.EOST: Boolean;
begin
if current>=EndMem.w then
Result:=True
else
result:=false;
end;
function TNBStreamManipulation.FindStrm(StNO, DrNO, Port: Byte): TNBStream;
Var st:TNBStream;
begin
Found:=false;
st:=First;
While Not EOST do
Begin
Found:=(st.StrmNo=stno) and (st.DrvrNO=drNo) and (st.PortNo=port);
if found then
Begin
Result:=st;
break;
End
else
st:=next;
End;
end;
function TNBStreamManipulation.FindStrmByMem(mem: TPair): TNBStream;
Var st:TNBStream;
begin
Found:=false;
st:=First;
While Not EOST do
Begin
Found:=(st.Memory.w=mem.w);
if found then
Begin
Result:=st;
break;
End
else
st:=next;
End;
end;
function TNBStreamManipulation.FindStrmForGraph(DrNO,Port:Byte): TNBStream;
Var st:TNBStream;
Function GetLinkPort:Byte;
Begin
result:=nbmem.rom[st.Memory.w+46];
End;
begin
Found:=false;
st:=First;
While Not EOST do
Begin
// Found:=(st.DrvrNO=drNo) and ((GetLinkPort=port) or (st.PortNo=port));
Found:=(st.DrvrNO=drNo) and (Port=GetLinkPort);
if found then
Begin
Result:=st;
break;
End
else
st:=next;
End;
end;
function TNBStreamManipulation.First: TNBStream;
Var slt,offs:integer;
begin
current:=StartMem.w;
slt:= current div $2000;
offs:=current mod $2000;
Result:=PNBStream(@nbmem.mainslots[slt].memory[offs])^;
end;
function TNBStreamManipulation.Last: TNBStream;
Var slt,offs:integer;
begin
current:=EndMem.w-NBSLen;
slt:= current div $2000;
offs:=current mod $2000;
Result:=PNBStream(@nbmem.mainslots[slt].memory[offs])^;
// Result:=PNBStream(@rom[Current])^;
end;
function TNBStreamManipulation.Next: TNBStream;
Var slt,offs:integer;
begin
Current:=Current+NBSLen;
if current>EndMem.w then
exit;
slt:= current div $2000;
offs:=current mod $2000;
Result:=PNBStream(@nbmem.mainslots[slt].memory[offs])^;
// Result:=PNBStream(@rom[Current])^;
end;
function TNBStreamManipulation.Previous: TNBStream;
Var slt,offs:integer;
begin
Current:=Current-NBSLen;
{ if current<StartMem.w then
Current:=Current+NBSLen;}
slt:= current div $2000;
offs:=current mod $2000;
Result:=PNBStream(@nbmem.mainslots[slt].memory[offs])^;
// Result:=PNBStream(@rom[Current])^;
end;
function TNBStreamManipulation.StartMem: TPair;
begin
result.l:=nbmem.Rom[$56];
result.h:=nbmem.ROM[$57];
end;
procedure TNBStreamManipulation.GetCPMVideo(Var pgno:Integer;Var Offs:Word);
Var oldcur:Word;
st:TNBStream;
begin
oldcur:=Current;
ISCpmVideo:=false;
pgno := -1;
St:=First;
While Not EOST do
Begin
If st.DrvrNO=18 then
Begin
IsCpmVideo:=true;
pgno:=3;
offs:=200;
break;
End;
st:=next;
End;
Current:=oldcur;
end;
constructor TNBPGStreamManipulation.Create;
begin
CurrentStream:=1;
end;
function TNBPGStreamManipulation.IsStreamOpen(StNo: Byte): Boolean;
begin
result:= nbmem.rom[StreamtableH+StNo]=1;
end;
function TNBPGStreamManipulation.PageNo2nd: Byte;
begin
Result := nbmem.rom[ObjectTableP+ObjectNo.H];
end;
procedure TNBPGStreamManipulation.First;
begin
Currentstream:=0;
end;
procedure TNBPGStreamManipulation.Next;
begin
if Currentstream<255 then
inc(CurrentStream);
end;
procedure TNBPGStreamManipulation.Previous;
begin
if currentStream>0 then
Dec(CurrentStream);
end;
procedure TNBPGStreamManipulation.Last;
begin
Currentstream:=255;
end;
function TNBPGStreamManipulation.ObjectNo: TpAIR;
begin
Result.L := nbmem.rom[StreamtableL+CurrentStream];
Result.H := nbmem.rom[StreamtableH+CurrentStream];
end;
function TNBPGStreamManipulation.PageOffset2nd: TPair;
begin
Result.H := nbmem.rom[ObjectTableH+ObjectNo.H];
Result.L := nbmem.rom[ObjectTableL+ObjectNo.H];
Result.W:=result.W+Objectno.L+4;
end;
procedure TNBPGStreamManipulation.SetStreamNo(Value: Byte);
begin
if CurrentStream <> Value then
CurrentStream := Value;
end;
function TNBPGStreamManipulation.NextOpen: Boolean;
Var st:Byte;
begin
st:=CurrentStream;
result:=false;
While st<255 do
Begin
inc(St);
if IsStreamOpen(st) then
Begin
Result:=true;
CurrentStream:=st;
Break;
End;
End;
end;
function TNBPGStreamManipulation.PageNo: Byte;
Var p2nd:Byte;
begin
result:=0;
p2nd:=PageNo2nd;
if not nbmem.chipexists(p2nd) then exit;
Result := nbmem.nbpages[p2nd]^.Memory[PageOffset2nd.w] ;
end;
function TNBPGStreamManipulation.PageOffset: TPair;
Var p2nd:Byte;
begin
result.w:=0;
p2nd:=PageNo2nd;
if not nbmem.chipexists(p2nd) then exit;
Result.L :=nbmem.nbpages[p2nd]^.Memory[PageOffset2nd.w+256] ;
Result.H :=nbmem.nbpages[p2nd]^.Memory[PageOffset2nd.w+2*256] ;
end;
procedure TNBPGStreamManipulation.ActiveVideoParams(Var pg:Integer;Var
Offset:Word);
Var //VAddr:TPair;
VNo:Byte;
begin
// VAddr:=nbScreen.VideoAddr;
// Vaddr.w:=Vaddr.w-1;
//from video table
// VNo:=Byte(GetVideoNoByAddress(VAddr));
Vno:= nbmem.rom[$BA]; //=TV4
pg:=-1;
If VNo<>-1 then // always true
Begin
First;
Repeat
//from stream table
If ((DeviceNo=0) or (DeviceNo=4) )and (VideoPos=Vno) then
Begin //Stream Found for VideoAddr
pg:=PageNo;
Offset:=PageOffset.w;
Break;
End;
Until not nextopen;
End;
end;
function TNBPGStreamManipulation.GetVideoNoByAddress(RamAdd:TPair): Integer;
Var i,j:Integer;
begin
Result:=-1;
For j:=31 downto 0 do
Begin
i:=VideoTableF+(j*4);
if (RamAdd.L<>NbMem.Rom[i]+2) and
(RamAdd.H=NbMem.Rom[i+1]) then
Begin
result:=j;
Break;
End;
End;
end;
function TNBPGStreamManipulation.DeviceNo: Byte;
Var pno:Byte;
begin
result:=$ff;
pno:=Pageno;
if not nbmem.chipexists(pno) then exit;
Result := NBMem.NBPages[pno]^.Memory[PageOffset.W+4];
end;
function TNBPGStreamManipulation.VideoPos: Byte;
begin
if (DeviceNo=0) or (DeviceNo=4) then
Result := NBMem.NBPages[Pageno]^.Memory[PageOffset.W+6]
Else
IF DeviceNo=11 then
Result := NBMem.NBPages[Pageno]^.Memory[PageOffset.w+$51]
ELSE
Result:=0;
end;
function TNBPGStreamManipulation.HasGraphStream(sg:Integer): Boolean;
Var pg:Integer;
offs:Word;
sno:Byte;
begin
Result:=False;
If sg>-1 then
Begin
ActiveVideoParams(pg,Offs);
If Pg=-1 then exit;
sno:=nbmem.nbpages[pg]^.memory[offs+30];
if sno=0 then exit;
End
Else
Begin //search for 33 device
GetActiveDevice33Stream(pg,Offs);
If Pg=-1 then exit;
sno:=nbmem.nbpages[pg]^.memory[offs+53];
if sno=0 then exit;
End;
Result:=true;
CurrentStream:=sno;
end;
procedure TNBPGStreamManipulation.GetCPMVideo(Var pgno:Integer;Var Offs:Word);
begin
ISCpmVideo:=false;
pgno := -1;
First;
Repeat
If Deviceno=18 then
Begin
IsCpmVideo:=true;
pgno:=NBMEM.ALTSLOTS[1].Page;
offs:=4;
break;
End;
Until not nextopen;
end;
function TNBPGStreamManipulation.GetActiveDevice33Stream(Var pg:Integer;Var
Offset:Word): Integer;
begin
pg:=-1;
First;
Repeat
//from stream table
If (DeviceNo=33) then
Begin //Stream Found for VideoAddr
pg:=PageNo;
Offset:=PageOffset.w;
Break;
End;
Until not nextopen;
Result:=Pg;
end;
end.