source: trunk/SharpMz800.pas

Last change on this file was 4, checked in by chronos, 16 months ago
  • Fixed: Memory leaks.
File size: 2.0 KB
Line 
1unit SharpMz800;
2
3interface
4
5uses
6 Classes, SysUtils, CpuZ80, Memory;
7
8type
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
30implementation
31
32{ TSharpMz800 }
33
34procedure TSharpMz800.CpuWrite(Address: Word; Data: Byte);
35begin
36 MappedMemory.Write(Address, Data);
37end;
38
39function TSharpMz800.CpuRead(Address: Word): Byte;
40begin
41 Result := MappedMemory.Read(Address);
42end;
43
44procedure TSharpMz800.PowerOn;
45begin
46 Cpu.Running := True;
47end;
48
49procedure TSharpMz800.PowerOff;
50begin
51 Cpu.Running := False;
52end;
53
54constructor TSharpMz800.Create;
55const
56 RomSubDir = 'ROM';
57begin
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;
78end;
79
80destructor TSharpMz800.Destroy;
81begin
82 FreeAndNil(Cpu);
83 FreeAndNil(MappedMemory);
84 FreeAndNil(VideoRam);
85 FreeAndNil(CharacterRom);
86 FreeAndNil(BaseRom);
87 FreeAndNil(ExtendedRom);
88 FreeAndNil(Memory);
89 inherited;
90end;
91
92end.
93
Note: See TracBrowser for help on using the repository browser.