1 | unit SharpMz800;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, CpuZ80, Memory;
|
---|
7 |
|
---|
8 | type
|
---|
9 | { TSharpMz800 }
|
---|
10 |
|
---|
11 | TSharpMz800 = class
|
---|
12 | private
|
---|
13 | public
|
---|
14 | Cpu: TCpuZ80;
|
---|
15 | Memory: TMemoryData;
|
---|
16 | BaseRom: TMemoryData;
|
---|
17 | ExtendedRom: TMemoryData;
|
---|
18 | VideoRam: TMemoryData;
|
---|
19 | CharacterRom: TMemoryData;
|
---|
20 | MappedMemory: TMemoryMapped;
|
---|
21 | procedure CpuWrite(Address: Word; Data: Byte);
|
---|
22 | function CpuRead(Address: Word): Byte;
|
---|
23 | procedure PowerOn;
|
---|
24 | procedure PowerOff;
|
---|
25 | constructor Create;
|
---|
26 | destructor Destroy; override;
|
---|
27 | end;
|
---|
28 |
|
---|
29 |
|
---|
30 | implementation
|
---|
31 |
|
---|
32 | { TSharpMz800 }
|
---|
33 |
|
---|
34 | procedure TSharpMz800.CpuWrite(Address: Word; Data: Byte);
|
---|
35 | begin
|
---|
36 | MappedMemory.Write(Address, Data);
|
---|
37 | end;
|
---|
38 |
|
---|
39 | function TSharpMz800.CpuRead(Address: Word): Byte;
|
---|
40 | begin
|
---|
41 | Result := MappedMemory.Read(Address);
|
---|
42 | end;
|
---|
43 |
|
---|
44 | procedure TSharpMz800.PowerOn;
|
---|
45 | begin
|
---|
46 | Cpu.Running := True;
|
---|
47 | end;
|
---|
48 |
|
---|
49 | procedure TSharpMz800.PowerOff;
|
---|
50 | begin
|
---|
51 | Cpu.Running := False;
|
---|
52 | end;
|
---|
53 |
|
---|
54 | constructor TSharpMz800.Create;
|
---|
55 | const
|
---|
56 | RomSubDir = 'ROM';
|
---|
57 | begin
|
---|
58 | Memory := TMemoryData.Create;
|
---|
59 | Memory.Size := 65536; // $10000
|
---|
60 | BaseRom := TMemoryData.Create;
|
---|
61 | BaseRom.LoadFromFile(RomSubDir + DirectorySeparator + 'MZ700A.ROM');
|
---|
62 | ExtendedRom := TMemoryData.Create;
|
---|
63 | ExtendedRom.LoadFromFile(RomSubDir + DirectorySeparator + '9Z_504M.ROM');
|
---|
64 | CharacterRom := TMemoryData.Create;
|
---|
65 | CharacterRom.LoadFromFile(RomSubDir + DirectorySeparator + 'CGROM.ROM');
|
---|
66 | VideoRam := TMemoryData.Create;
|
---|
67 | VideoRam.Size := 4096; // $1000
|
---|
68 | MappedMemory := TMemoryMapped.Create;
|
---|
69 | MappedMemory.Size := $10000;
|
---|
70 | MappedMemory.Areas.AddNew($0, BaseRom);
|
---|
71 | MappedMemory.Areas.AddNew($1000, CharacterRom);
|
---|
72 | MappedMemory.Areas.AddNew($e000, ExtendedRom);
|
---|
73 | MappedMemory.Areas.AddNew($0, Memory);
|
---|
74 | Cpu := TCpuZ80.Create;
|
---|
75 | Cpu.Memory := MappedMemory;
|
---|
76 | Cpu.OnRead := CpuRead;
|
---|
77 | Cpu.OnWrite := CpuWrite;
|
---|
78 | end;
|
---|
79 |
|
---|
80 | destructor TSharpMz800.Destroy;
|
---|
81 | begin
|
---|
82 | FreeAndNil(Cpu);
|
---|
83 | FreeAndNil(MappedMemory);
|
---|
84 | FreeAndNil(VideoRam);
|
---|
85 | FreeAndNil(CharacterRom);
|
---|
86 | FreeAndNil(BaseRom);
|
---|
87 | FreeAndNil(ExtendedRom);
|
---|
88 | FreeAndNil(Memory);
|
---|
89 | inherited;
|
---|
90 | end;
|
---|
91 |
|
---|
92 | end.
|
---|
93 |
|
---|