--- Galaksija.pm 2007/08/04 20:34:59 130 +++ Galaksija.pm 2007/08/05 01:02:59 140 @@ -6,7 +6,7 @@ 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); __PACKAGE__->mk_accessors(qw(booted)); @@ -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,8 +116,6 @@ =cut -my $keyboard_none = 255; - my $keyboard = {}; sub read { @@ -123,6 +125,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,14 +142,71 @@ 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 + +=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<< >> +Based on Galaxy Win emulator L + =head1 BUGS =head1 ACKNOWLEDGEMENTS