/[VRac]/Galaksija.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /Galaksija.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 131 - (show annotations)
Sat Aug 4 20:50:33 2007 UTC (11 years, 10 months ago) by dpavlin
File size: 2971 byte(s)
added cpu_PC so cli j work, import all exports from Z80
1 package Galaksija;
2
3 use warnings;
4 use strict;
5
6 use Carp qw/confess/;
7 use File::Slurp;
8 use Data::Dump qw/dump/;
9 use Z80; # import
10
11 use base qw(Class::Accessor VRac Z80 Screen Prefs);
12 __PACKAGE__->mk_accessors(qw(booted));
13
14 =head1 NAME
15
16 Galaksija - Galaksija emulator
17
18 =head1 VERSION
19
20 Version 0.00
21
22 =cut
23
24 our $VERSION = '0.00';
25
26 =head1 SUMMARY
27
28 Emulator of Galaksija 8-bit Z80 machine popular in former Yugoslavia
29
30 =cut
31
32 =head1 FUNCTIONS
33
34 =head2 run
35
36 =cut
37
38 our $emu;
39
40 sub run {
41 my $self = shift;
42
43 warn "Galaksija $Galaksija::VERSION emulation starting\n";
44
45 $self->show_mem( 1 );
46 $self->trace( 1 );
47
48 $self->SUPER::init(
49 read => sub { $self->read( @_ ) },
50 write => sub { $self->write( @_ ) },
51 );
52
53 for my $a ( 0x1000 .. 0x2000 ) {
54 $mem[$a] = 0xff;
55 }
56
57 $self->open_screen;
58 $self->load_rom({
59 0x0000, 'rom/Galaksija/ROM1.BIN',
60 0x2000, 'rom/Galaksija/ROM2.BIN',
61 # 0xE000, 'rom/Galaksija/GAL_PLUS.BIN',
62 });
63
64 # keyboard
65 $mem[$_] = 0xff foreach ( 0x2000 .. 0x2800 );
66
67 # display
68 $mem[$_] = ' ' foreach ( 0x2800 .. 0x2a00 );
69
70 # 6116-ice
71 $mem[$_] = 0 foreach ( 0x2a00 .. 0x4000 );
72
73 $emu = $self;
74
75 my ( $trace, $debug ) = ( $self->trace, $self->debug );
76 $self->trace( 0 );
77 $self->debug( 0 );
78
79 warn "rendering video memory\n";
80 #$self->render_vram( @mem[ 0x2800 .. 0x2a00 ] );
81
82 #$self->sync;
83 $self->trace( $trace );
84 $self->debug( $debug );
85
86 warn "Galaksija boot finished",
87 $self->trace ? ' trace' : '',
88 $self->debug ? ' debug' : '',
89 "\n";
90
91 Z80::reset();
92
93 $self->loop( sub {
94 Z80::exec( $_[0] );
95 #$self->render_vram;
96 });
97
98 }
99
100
101 =head1 Memory management
102
103 Galaksija implements all I/O using mmap addresses. This was main reason why
104 L<Acme::6502> was just too slow to handle it.
105
106 =cut
107
108 =head2 read
109
110 Read from memory
111
112 $byte = read( $address );
113
114 =cut
115
116 my $keyboard_none = 255;
117
118 my $keyboard = {};
119
120 sub read {
121 my $self = shift;
122 my ($addr) = @_;
123 my $byte = $mem[$addr];
124 confess sprintf("can't find memory at address %04x",$addr) unless defined($byte);
125 warn sprintf("# Galaksija::read(%04x) = %02x\n", $addr, $byte) if $self->trace;
126
127 return $byte;
128 }
129
130 =head2 write
131
132 Write into emory
133
134 write( $address, $byte );
135
136 =cut
137
138 sub write {
139 my $self = shift;
140 my ($addr,$byte) = @_;
141 warn sprintf("# Galaksija::write(%04x,%02x)\n", $addr, $byte) if $self->trace;
142
143 $mem[$addr] = $byte;
144 return;
145 }
146
147 =head2 cpu_PC
148
149 Helper metod to set or get PC for current architecture
150
151 =cut
152
153 sub cpu_PC {
154 my ( $self, $addr ) = @_;
155 if ( defined($addr) ) {
156 $PC = $addr;
157 warn sprintf("running from PC %04x\n", $PC);
158 };
159 return $PC;
160 }
161
162 =head1 AUTHOR
163
164 Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
165
166 =head1 BUGS
167
168 =head1 ACKNOWLEDGEMENTS
169
170 See also L<> which is source of all
171 info about this machine (and even hardware implementation from 2007).
172
173 =head1 COPYRIGHT & LICENSE
174
175 Copyright 2007 Dobrica Pavlinusic, All Rights Reserved.
176
177 This program is free software; you can redistribute it and/or modify it
178 under the same terms as Perl itself.
179
180 =cut
181
182 1; # End of Galaksija

  ViewVC Help
Powered by ViewVC 1.1.26