8 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
9 |
use Z80; # import |
use Z80; # import |
10 |
|
|
11 |
use base qw(Class::Accessor VRac Z80 Screen Prefs); |
use base qw(Class::Accessor VRac Z80 Screen Prefs Session); |
12 |
__PACKAGE__->mk_accessors(qw(booted)); |
__PACKAGE__->mk_accessors(qw(booted)); |
13 |
|
|
14 |
=head1 NAME |
=head1 NAME |
17 |
|
|
18 |
=head1 VERSION |
=head1 VERSION |
19 |
|
|
20 |
Version 0.00 |
Version 0.01 |
21 |
|
|
22 |
=cut |
=cut |
23 |
|
|
24 |
our $VERSION = '0.00'; |
our $VERSION = '0.01'; |
25 |
|
|
26 |
=head1 SUMMARY |
=head1 SUMMARY |
27 |
|
|
43 |
warn "Galaksija $Galaksija::VERSION emulation starting\n"; |
warn "Galaksija $Galaksija::VERSION emulation starting\n"; |
44 |
|
|
45 |
$self->show_mem( 1 ); |
$self->show_mem( 1 ); |
46 |
$self->trace( 1 ); |
#$self->trace( 1 ); |
47 |
|
|
48 |
$self->SUPER::init( |
$self->SUPER::init( |
49 |
read => sub { $self->read( @_ ) }, |
read => sub { $self->read( @_ ) }, |
65 |
$mem[$_] = 0xff foreach ( 0x2000 .. 0x2800 ); |
$mem[$_] = 0xff foreach ( 0x2000 .. 0x2800 ); |
66 |
|
|
67 |
# display |
# display |
68 |
$mem[$_] = ' ' foreach ( 0x2800 .. 0x2a00 ); |
$mem[$_] = 0x20 foreach ( 0x2800 .. 0x2a00 ); |
69 |
|
|
70 |
# 6116-ice |
# 6116-ice |
71 |
$mem[$_] = 0 foreach ( 0x2a00 .. 0x4000 ); |
$mem[$_] = 0 foreach ( 0x2a00 .. 0x4000 ); |
76 |
$self->trace( 0 ); |
$self->trace( 0 ); |
77 |
$self->debug( 0 ); |
$self->debug( 0 ); |
78 |
|
|
79 |
warn "rendering video memory\n"; |
warn "rendering memory\n"; |
80 |
#$self->render_vram( @mem[ 0x2800 .. 0x2a00 ] ); |
$self->render_mem( @mem ); |
81 |
|
|
82 |
#$self->sync; |
#$self->sync; |
83 |
$self->trace( $trace ); |
$self->trace( $trace ); |
90 |
|
|
91 |
Z80::reset(); |
Z80::reset(); |
92 |
|
|
93 |
|
my $hor_pos = 0; |
94 |
|
|
95 |
$self->loop( sub { |
$self->loop( sub { |
96 |
Z80::exec( $_[0] ); |
Z80::exec( $_[0] ); |
97 |
#$self->render_vram; |
if ( $hor_pos != $mem[ 0x2ba8 ] ) { |
98 |
|
warn "scroll 0x2ba8", $self->hexdump( 0x2ba8 ); |
99 |
|
$hor_pos = $mem[ 0x2ba8 ]; |
100 |
|
} |
101 |
|
$self->render_vram; |
102 |
}); |
}); |
103 |
|
|
104 |
} |
} |
106 |
|
|
107 |
=head1 Memory management |
=head1 Memory management |
108 |
|
|
|
Galaksija implements all I/O using mmap addresses. This was main reason why |
|
|
L<Acme::6502> was just too slow to handle it. |
|
|
|
|
109 |
=cut |
=cut |
110 |
|
|
111 |
=head2 read |
=head2 read |
116 |
|
|
117 |
=cut |
=cut |
118 |
|
|
|
my $keyboard_none = 255; |
|
|
|
|
|
my $keyboard = {}; |
|
|
|
|
119 |
sub read { |
sub read { |
120 |
my $self = shift; |
my $self = shift; |
121 |
my ($addr) = @_; |
my ($addr) = @_; |
123 |
confess sprintf("can't find memory at address %04x",$addr) unless defined($byte); |
confess sprintf("can't find memory at address %04x",$addr) unless defined($byte); |
124 |
warn sprintf("# Galaksija::read(%04x) = %02x\n", $addr, $byte) if $self->trace; |
warn sprintf("# Galaksija::read(%04x) = %02x\n", $addr, $byte) if $self->trace; |
125 |
|
|
126 |
|
$self->mmap_pixel( $addr, 0, $byte, 0 ) if $self->show_mem; |
127 |
return $byte; |
return $byte; |
128 |
} |
} |
129 |
|
|
140 |
my ($addr,$byte) = @_; |
my ($addr,$byte) = @_; |
141 |
warn sprintf("# Galaksija::write(%04x,%02x)\n", $addr, $byte) if $self->trace; |
warn sprintf("# Galaksija::write(%04x,%02x)\n", $addr, $byte) if $self->trace; |
142 |
|
|
143 |
|
return if ( $addr > 0x4000 ); |
144 |
|
|
145 |
|
$self->mmap_pixel( $addr, $byte, 0, 0 ) if $self->show_mem; |
146 |
$mem[$addr] = $byte; |
$mem[$addr] = $byte; |
147 |
return; |
return; |
148 |
} |
} |
149 |
|
|
150 |
|
=head1 Architecture specific |
151 |
|
|
152 |
|
=cut |
153 |
|
|
154 |
|
my @keymap = ( |
155 |
|
'a' .. 'z', |
156 |
|
qw/up down left right space/, |
157 |
|
'0' .. '9', |
158 |
|
':', '"', ',', '=', '.', '/', 'enter', 'tab', |
159 |
|
'left alt', 'delete', 'scroll lock', 'left shift' |
160 |
|
); |
161 |
|
|
162 |
|
my $remap; |
163 |
|
my $o = 1; |
164 |
|
|
165 |
|
foreach my $key ( @keymap ) { |
166 |
|
$remap->{$key} = $o; |
167 |
|
$o++; |
168 |
|
} |
169 |
|
|
170 |
|
=head2 key_down |
171 |
|
|
172 |
|
=cut |
173 |
|
|
174 |
|
sub key_down { |
175 |
|
my ( $self, $key ) = @_; |
176 |
|
warn "key down: $key ", $remap->{$key}; |
177 |
|
$self->write( 0x2000 + $remap->{$key}, 0xfe ); |
178 |
|
} |
179 |
|
|
180 |
|
=head2 key_up |
181 |
|
|
182 |
|
=cut |
183 |
|
|
184 |
|
sub key_up { |
185 |
|
my ( $self, $key ) = @_; |
186 |
|
warn "key up: $key ", $remap->{$key}; |
187 |
|
$self->write( 0x2000 + $remap->{$key}, 0xff ); |
188 |
|
} |
189 |
|
|
190 |
|
=head2 render_vram |
191 |
|
|
192 |
|
Simple hex dumper of text buffer |
193 |
|
|
194 |
|
=cut |
195 |
|
|
196 |
|
my $last_dump = ''; |
197 |
|
|
198 |
|
sub render_vram { |
199 |
|
my $self = shift; |
200 |
|
|
201 |
|
my $addr = 0x2800; |
202 |
|
|
203 |
|
my $dump; |
204 |
|
|
205 |
|
for my $y ( 0 .. 15 ) { |
206 |
|
# $dump .= sprintf "%2d: %s\n",$y, join('', map { sprintf("%02x ",$_) } @mem[ $addr .. $addr+31 ] ); |
207 |
|
$dump .= sprintf "%2d: %s\n",$y, join('', map { chr( $_ ) } @mem[ $addr .. $addr+31 ] ); |
208 |
|
$addr += 32; |
209 |
|
} |
210 |
|
|
211 |
|
if ( $mem[ 0x2bb0 ] ) { |
212 |
|
warn "scroll", $self->hexdump( 0x2bb0 ); |
213 |
|
} |
214 |
|
|
215 |
|
if ( $dump ne $last_dump ) { |
216 |
|
print $dump; |
217 |
|
$last_dump = $dump; |
218 |
|
} |
219 |
|
} |
220 |
|
|
221 |
=head2 cpu_PC |
=head2 cpu_PC |
222 |
|
|
223 |
Helper metod to set or get PC for current architecture |
Helper metod to set or get PC for current architecture |
233 |
return $PC; |
return $PC; |
234 |
} |
} |
235 |
|
|
236 |
|
=head1 SEE ALSO |
237 |
|
|
238 |
|
L<VRac>, L<Screen>, L<Z80> |
239 |
|
|
240 |
=head1 AUTHOR |
=head1 AUTHOR |
241 |
|
|
242 |
Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >> |
Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >> |
243 |
|
|
244 |
=head1 BUGS |
=head1 BUGS |
245 |
|
|
246 |
|
Galaksija Plus isn't emulated. I don't have additional rom, but I would |
247 |
|
B<love> to have support for this machine. So if you have ROM for Galaksija |
248 |
|
Plus, get in touch! |
249 |
|
|
250 |
=head1 ACKNOWLEDGEMENTS |
=head1 ACKNOWLEDGEMENTS |
251 |
|
|
252 |
See also L<> which is source of all |
Based on Galaxy emulator L<http://emulator.galaksija.org/> for Windows which |
253 |
info about this machine (and even hardware implementation from 2007). |
is in turn based on DOS version by Miodrag Jevremoviæ |
254 |
|
L<http://solair.eunet.yu/~jovkovic/galaxy/>. |
255 |
|
|
256 |
=head1 COPYRIGHT & LICENSE |
=head1 COPYRIGHT & LICENSE |
257 |
|
|