--- Galaksija.pm 2007/08/04 20:34:59 130 +++ Galaksija.pm 2007/08/05 20:02:14 163 @@ -6,9 +6,9 @@ use Carp qw/confess/; use File::Slurp; use Data::Dump qw/dump/; -use Z80 qw'@mem'; +use Z80; # import -use base qw(Class::Accessor VRac Z80 Screen Prefs); +use base qw(Class::Accessor VRac Z80 Screen Prefs Session); __PACKAGE__->mk_accessors(qw(booted)); =head1 NAME @@ -17,11 +17,11 @@ =head1 VERSION -Version 0.00 +Version 0.01 =cut -our $VERSION = '0.00'; +our $VERSION = '0.01'; =head1 SUMMARY @@ -39,16 +39,17 @@ sub run { my $self = shift; - warn "Galaksija calling upstream init\n"; + + warn "Galaksija $Galaksija::VERSION emulation starting\n"; + + $self->show_mem( 1 ); + #$self->trace( 1 ); + $self->SUPER::init( read => sub { $self->read( @_ ) }, write => sub { $self->write( @_ ) }, ); - warn "Galaksija $Galaksija::VERSION emulation starting\n"; - - warn "emulating ", $#mem, " bytes of memory\n"; - for my $a ( 0x1000 .. 0x2000 ) { $mem[$a] = 0xff; } @@ -64,7 +65,7 @@ $mem[$_] = 0xff foreach ( 0x2000 .. 0x2800 ); # display - $mem[$_] = ' ' foreach ( 0x2800 .. 0x2a00 ); + $mem[$_] = 0x20 foreach ( 0x2800 .. 0x2a00 ); # 6116-ice $mem[$_] = 0 foreach ( 0x2a00 .. 0x4000 ); @@ -75,8 +76,8 @@ $self->trace( 0 ); $self->debug( 0 ); - warn "rendering video memory\n"; - #$self->render_vram( @mem[ 0x2800 .. 0x2a00 ] ); + warn "rendering memory\n"; + $self->render_mem( @mem ); #$self->sync; $self->trace( $trace ); @@ -89,9 +90,15 @@ Z80::reset(); + my $hor_pos = 0; + $self->loop( sub { Z80::exec( $_[0] ); - #$self->render_vram; + if ( $hor_pos != $mem[ 0x2ba8 ] ) { + warn "scroll 0x2ba8", $self->hexdump( 0x2ba8 ); + $hor_pos = $mem[ 0x2ba8 ]; + } + $self->render_vram; }); } @@ -99,9 +106,6 @@ =head1 Memory management -Galaksija implements all I/O using mmap addresses. This was main reason why -L was just too slow to handle it. - =cut =head2 read @@ -112,10 +116,6 @@ =cut -my $keyboard_none = 255; - -my $keyboard = {}; - sub read { my $self = shift; my ($addr) = @_; @@ -123,6 +123,7 @@ confess sprintf("can't find memory at address %04x",$addr) unless defined($byte); warn sprintf("# Galaksija::read(%04x) = %02x\n", $addr, $byte) if $self->trace; + $self->mmap_pixel( $addr, 0, $byte, 0 ) if $self->show_mem; return $byte; } @@ -139,20 +140,118 @@ my ($addr,$byte) = @_; warn sprintf("# Galaksija::write(%04x,%02x)\n", $addr, $byte) if $self->trace; + return if ( $addr > 0x4000 ); + + $self->mmap_pixel( $addr, $byte, 0, 0 ) if $self->show_mem; $mem[$addr] = $byte; return; } +=head1 Architecture specific + +=cut + +my @keymap = ( + 'a' .. 'z', + qw/up down left right space/, + '0' .. '9', + ':', '"', ',', '=', '.', '/', 'enter', 'tab', + 'left alt', 'delete', 'scroll lock', 'left shift' +); + +my $remap; +my $o = 1; + +foreach my $key ( @keymap ) { + $remap->{$key} = $o; + $o++; +} + +=head2 key_down + +=cut + +sub key_down { + my ( $self, $key ) = @_; + warn "key down: $key ", $remap->{$key}; + $self->write( 0x2000 + $remap->{$key}, 0xfe ); +} + +=head2 key_up + +=cut + +sub key_up { + my ( $self, $key ) = @_; + warn "key up: $key ", $remap->{$key}; + $self->write( 0x2000 + $remap->{$key}, 0xff ); +} + +=head2 render_vram + +Simple hex dumper of text buffer + +=cut + +my $last_dump = ''; + +sub render_vram { + my $self = shift; + + my $addr = 0x2800; + + my $dump; + + for my $y ( 0 .. 15 ) { +# $dump .= sprintf "%2d: %s\n",$y, join('', map { sprintf("%02x ",$_) } @mem[ $addr .. $addr+31 ] ); + $dump .= sprintf "%2d: %s\n",$y, join('', map { chr( $_ ) } @mem[ $addr .. $addr+31 ] ); + $addr += 32; + } + + if ( $mem[ 0x2bb0 ] ) { + warn "scroll", $self->hexdump( 0x2bb0 ); + } + + if ( $dump ne $last_dump ) { + print $dump; + $last_dump = $dump; + } +} + +=head2 cpu_PC + +Helper metod to set or get PC for current architecture + +=cut + +sub cpu_PC { + my ( $self, $addr ) = @_; + if ( defined($addr) ) { + $PC = $addr; + warn sprintf("running from PC %04x\n", $PC); + }; + return $PC; +} + +=head1 SEE ALSO + +L, L, L + =head1 AUTHOR Dobrica Pavlinusic, C<< >> =head1 BUGS +Galaksija Plus isn't emulated. I don't have additional rom, but I would +B to have support for this machine. So if you have ROM for Galaksija +Plus, get in touch! + =head1 ACKNOWLEDGEMENTS -See also L<> which is source of all -info about this machine (and even hardware implementation from 2007). +Based on Galaxy emulator L for Windows which +is in turn based on DOS version by Miodrag Jevremoviæ +L. =head1 COPYRIGHT & LICENSE