/[VRac]/M6502/Orao.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 /M6502/Orao.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 34 - (show annotations)
Mon Jul 30 21:34:30 2007 UTC (16 years, 8 months ago) by dpavlin
File size: 5150 byte(s)
somewhat works now...
1 package Orao;
2
3 use warnings;
4 use strict;
5
6 use Carp;
7 use lib './lib';
8 #use Time::HiRes qw(time);
9 use File::Slurp;
10 use Data::Dump qw/dump/;
11 use M6502;
12
13 use base qw(Class::Accessor M6502 Screen);
14 __PACKAGE__->mk_accessors(qw(debug trace run_for mem_dump trace));
15
16 =head1 NAME
17
18 Orao - Orao emulator
19
20 =head1 VERSION
21
22 Version 0.02
23
24 =cut
25
26 our $VERSION = '0.02';
27
28 =head1 SUMMARY
29
30 Emulator or Orao 8-bit 6502 machine popular in Croatia
31
32 =cut
33
34 =head2 init
35
36 Start emulator
37
38 =cut
39
40 our $orao;
41
42 our $PC = 0x1000;
43
44 sub init {
45 my $self = shift;
46 warn "Orao calling upstream init\n";
47 $self->SUPER::init( $self, @_ );
48
49 warn "staring Orao $Orao::VERSION emulation\n";
50
51 $self->open_screen;
52 $self->load_rom({
53 0x1000 => 'dump/SCRINV.BIN',
54 0xC000 => 'rom/BAS12.ROM',
55 0xE000 => 'rom/CRT12.ROM',
56 });
57
58 $orao = $self;
59
60 # $self->prompt( 0x1000 );
61
62 warn "rendering memory map\n";
63
64 my @mmap = (
65 0x0000, 0x03FF, 'nulti blok',
66 0x0400, 0x5FFF, 'korisnièki RAM (23K)',
67 0x6000, 0x7FFF, 'video RAM',
68 0x8000, 0x9FFF, 'sistemske lokacije',
69 0xA000, 0xAFFF, 'ekstenzija',
70 0xB000, 0xBFFF, 'DOS',
71 0xC000, 0xDFFF, 'BASIC ROM',
72 0xE000, 0xFFFF, 'sistemski ROM',
73 );
74
75 foreach my $i ( 0 .. $#mmap / 3 ) {
76 my $o = $i * 3;
77 my ( $from, $to, $desc ) = @mmap[$o,$o+1,$o+2];
78 printf "%04x - %04x - %s\n", $from, $to, $desc;
79 for my $a ( $from .. $to ) {
80 $orao->read( $a );
81 }
82 $self->sync;
83 }
84
85 warn "Orao init finished\n";
86
87 }
88
89 =head2 load_rom
90
91 called to init memory and load initial rom images
92
93 $orao->load_rom;
94
95 =cut
96
97 sub load_rom {
98 my ($self, $loaded_files) = @_;
99
100 #my $time_base = time();
101
102 foreach my $addr ( sort keys %$loaded_files ) {
103 my $path = $loaded_files->{$addr};
104 $self->load_oraoemu( $path, $addr );
105 }
106 }
107
108
109 =head2 load_oraoemu
110
111 =cut
112
113 sub load_oraoemu {
114 my $self = shift;
115 my ( $path, $addr ) = @_;
116
117 my $size = -s $path || confess "no size for $path: $!";
118
119 my $buff = read_file( $path );
120
121 if ( $size == 65538 ) {
122 $addr = 0;
123 warn sprintf "loading oraoemu 64k dump %s at %04x - %04x %02x\n", $path, $addr, $addr+$size-1, $size;
124 $self->write_chunk( $addr, substr($buff,2) );
125 return;
126 } elsif ( $size == 32800 ) {
127 $addr = 0;
128 warn sprintf "loading oraoemu 1.3 dump %s at %04x - %04x %02x\n", $path, $addr, $addr+$size-1, $size;
129 #$self->write_chunk( $addr, substr($buff,0x20) );
130 $self->poke_code( $addr, map { ord($_) } split(//,substr($buff,0x20)) );
131 return;
132 }
133 printf "loading %s at %04x - %04x %02x\n", $path, $addr, $addr+$size-1, $size;
134 return $self->poke_code( $addr, map { ord($_) } split(//,$buff) );
135 return $self->write_chunk( $addr, $buff );
136
137 my $chunk;
138
139 my $pos = 0;
140
141 while ( my $long = substr($buff,$pos,4) ) {
142 my @b = split(//, $long, 4);
143 $chunk .=
144 ( $b[3] || '' ) .
145 ( $b[2] || '' ) .
146 ( $b[1] || '' ) .
147 ( $b[0] || '' );
148 $pos += 4;
149 }
150
151 $self->write_chunk( $addr, $chunk );
152
153 };
154
155 =head2 save_dump
156
157 $orao->save_dump( 'filename', $from, $to );
158
159 =cut
160
161 sub save_dump {
162 my $self = shift;
163
164 my ( $path, $from, $to ) = @_;
165
166 $from ||= 0;
167 $to ||= 0xffff;
168
169 open(my $fh, '>', $path) || die "can't open $path: $!";
170 print $fh $self->read_chunk( $from, $to );
171 close($fh);
172
173 my $size = -s $path;
174 warn sprintf "saved %s %d %x bytes\n", $path, $size, $size;
175 }
176
177 =head2 hexdump
178
179 $orao->hexdump( $address );
180
181 =cut
182
183 sub hexdump {
184 my $self = shift;
185 my $a = shift;
186 return sprintf(" %04x %s\n", $a,
187 join(" ",
188 map {
189 sprintf( "%02x", $_ )
190 } $self->ram( $a, $a+8 )
191 )
192 );
193 }
194
195 =head2 prompt
196
197 $orao->prompt( $address, $last_command );
198
199 =cut
200
201 sub prompt {
202 my $self = shift;
203 my $a = shift;
204 my $last = shift;
205 print STDERR $self->hexdump( $a ),
206 $last ? "[$last] " : '',
207 "> ";
208 my $in = <STDIN>;
209 chomp($in);
210 $in ||= $last;
211 $last = $in;
212 return split(/\s+/, $in) if $in;
213 }
214
215 =head1 Memory management
216
217 Orao implements all I/O using mmap addresses. This was main reason why
218 L<Acme::6502> was just too slow to handle it.
219
220 =cut
221
222 =head2 read
223
224 Read from memory
225
226 $byte = read( $address );
227
228 =cut
229
230 sub read {
231 my $self = shift;
232 my ($addr) = @_;
233 my $byte = $mem[$addr];
234 warn "# Orao::read(",dump(@_),") = ",dump( $byte ),"\n" if $self->debug;
235 $self->mmap_pixel( $addr, 0, $byte, 0 );
236 return $byte;
237 }
238
239 =head2 write
240
241 Write into emory
242
243 write( $address, $byte );
244
245 =cut
246
247 sub write {
248 my $self = shift;
249 warn "# Orao::write(",dump(@_),")\n" if $self->debug;
250 my ($addr,$byte) = @_;
251
252 if ( $addr >= 0x6000 && $addr < 0x8000 ) {
253 $self->vram( $addr - 0x6000 , $byte );
254 }
255
256 if ( $addr > 0xafff ) {
257 warn sprintf "access to %04x above affff aborting\n", $addr;
258 return -1;
259 }
260 if ( $addr == 0x8800 ) {
261 warn sprintf "sound ignored: %x\n", $byte;
262 }
263
264 $self->mmap_pixel( $addr, $byte, 0, 0 );
265
266 $mem[$addr] = $byte;
267 }
268
269
270 =head1 AUTHOR
271
272 Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
273
274 =head1 BUGS
275
276 =head1 ACKNOWLEDGEMENTS
277
278 See also L<http://www.foing.hr/~fng_josip/orao.htm> which is source of all
279 info about this machine (and even hardware implementation from 2007).
280
281 =head1 COPYRIGHT & LICENSE
282
283 Copyright 2007 Dobrica Pavlinusic, All Rights Reserved.
284
285 This program is free software; you can redistribute it and/or modify it
286 under the same terms as Perl itself.
287
288 =cut
289
290 1; # End of Orao

  ViewVC Help
Powered by ViewVC 1.1.26