--- M6502/Orao.pm 2007/07/30 17:56:13 30 +++ M6502/Orao.pm 2007/07/30 21:53:04 35 @@ -7,6 +7,8 @@ use lib './lib'; #use Time::HiRes qw(time); use File::Slurp; +use Data::Dump qw/dump/; +use M6502; use base qw(Class::Accessor M6502 Screen); __PACKAGE__->mk_accessors(qw(debug trace run_for mem_dump trace)); @@ -35,21 +37,56 @@ =cut +our $orao; + sub init { my $self = shift; - warn "call upstream init\n"; - $self->SUPER::init( @_ ); + warn "Orao calling upstream init\n"; + $self->SUPER::init( $self, @_ ); - warn "staring Orao $ORAO::VERSION emulation\n"; + warn "staring Orao $Orao::VERSION emulation\n"; $self->open_screen; - $self->load_rom; -} + $self->load_rom({ + 0x1000 => 'dump/SCRINV.BIN', + 0xC000 => 'rom/BAS12.ROM', + 0xE000 => 'rom/CRT12.ROM', + }); + + $self->load_oraoemu( 'dump/orao-1.2' ); + $self->load_oraoemu( 'dump/SCRINV.BIN' ); + $PC = 0x1000; + + $orao = $self; + +# $self->prompt( 0x1000 ); + + warn "rendering memory map\n"; + + my @mmap = ( + 0x0000, 0x03FF, 'nulti blok', + 0x0400, 0x5FFF, 'korisnički RAM (23K)', + 0x6000, 0x7FFF, 'video RAM', + 0x8000, 0x9FFF, 'sistemske lokacije', + 0xA000, 0xAFFF, 'ekstenzija', + 0xB000, 0xBFFF, 'DOS', + 0xC000, 0xDFFF, 'BASIC ROM', + 0xE000, 0xFFFF, 'sistemski ROM', + ); -my $loaded_files = { - 0xC000 => 'rom/BAS12.ROM', - 0xE000 => 'rom/CRT12.ROM', -}; + foreach my $i ( 0 .. $#mmap / 3 ) { + my $o = $i * 3; + my ( $from, $to, $desc ) = @mmap[$o,$o+1,$o+2]; + printf "%04x - %04x - %s\n", $from, $to, $desc; + for my $a ( $from .. $to ) { + $orao->read( $a ); + } + $self->sync; + } + + warn "Orao init finished\n"; + +} =head2 load_rom @@ -60,13 +97,12 @@ =cut sub load_rom { - my ($self) = @_; + my ($self, $loaded_files) = @_; #my $time_base = time(); foreach my $addr ( sort keys %$loaded_files ) { my $path = $loaded_files->{$addr}; - printf "loading '%s' at %04x\n", $path, $addr; $self->load_oraoemu( $path, $addr ); } } @@ -80,23 +116,24 @@ my $self = shift; my ( $path, $addr ) = @_; - my $size = -s $path || die "no size for $path: $!"; + my $size = -s $path || confess "no size for $path: $!"; my $buff = read_file( $path ); if ( $size == 65538 ) { $addr = 0; - printf "loading oraoemu 64k dump %s at %04x - %04x %02x\n", $path, $addr, $addr+$size, $size; + warn sprintf "loading oraoemu 64k dump %s at %04x - %04x %02x\n", $path, $addr, $addr+$size-1, $size; $self->write_chunk( $addr, substr($buff,2) ); return; } elsif ( $size == 32800 ) { $addr = 0; - printf "loading oraoemu 1.3 dump %s at %04x - %04x %02x\n", $path, $addr, $addr+$size, $size; + warn sprintf "loading oraoemu 1.3 dump %s at %04x - %04x %02x\n", $path, $addr, $addr+$size-1, $size; #$self->write_chunk( $addr, substr($buff,0x20) ); $self->poke_code( $addr, map { ord($_) } split(//,substr($buff,0x20)) ); return; } - printf "loading %s at %04x - %04x %02x\n", $path, $addr, $addr+$size, $size; + printf "loading %s at %04x - %04x %02x\n", $path, $addr, $addr+$size-1, $size; + return $self->poke_code( $addr, map { ord($_) } split(//,$buff) ); return $self->write_chunk( $addr, $buff ); my $chunk; @@ -136,7 +173,7 @@ close($fh); my $size = -s $path; - printf "saved %s %d %x bytes\n", $path, $size, $size; + warn sprintf "saved %s %d %x bytes\n", $path, $size, $size; } =head2 hexdump @@ -167,7 +204,7 @@ my $self = shift; my $a = shift; my $last = shift; - print $self->hexdump( $a ), + print STDERR $self->hexdump( $a ), $last ? "[$last] " : '', "> "; my $in = ; @@ -177,6 +214,60 @@ return split(/\s+/, $in) if $in; } +=head1 Memory management + +Orao implements all I/O using mmap addresses. This was main reason why +L was just too slow to handle it. + +=cut + +=head2 read + +Read from memory + + $byte = read( $address ); + +=cut + +sub read { + my $self = shift; + my ($addr) = @_; + my $byte = $mem[$addr]; + warn "# Orao::read(",dump(@_),") = ",dump( $byte ),"\n" if $self->debug; + $self->mmap_pixel( $addr, 0, $byte, 0 ); + return $byte; +} + +=head2 write + +Write into emory + + write( $address, $byte ); + +=cut + +sub write { + my $self = shift; + warn "# Orao::write(",dump(@_),")\n" if $self->debug; + my ($addr,$byte) = @_; + + if ( $addr >= 0x6000 && $addr < 0x8000 ) { + $self->vram( $addr - 0x6000 , $byte ); + } + + if ( $addr > 0xafff ) { + warn sprintf "access to %04x above affff aborting\n", $addr; + return -1; + } + if ( $addr == 0x8800 ) { + warn sprintf "sound ignored: %x\n", $byte; + } + + $self->mmap_pixel( $addr, $byte, 0, 0 ); + + $mem[$addr] = $byte; +} + =head1 AUTHOR