/[VRac]/Galaksija.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

Annotation of /Galaksija.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 139 - (hide annotations)
Sat Aug 4 23:01:25 2007 UTC (11 years, 10 months ago) by dpavlin
File size: 3451 byte(s)
dump just changed screens
1 dpavlin 130 package Galaksija;
2    
3     use warnings;
4     use strict;
5    
6     use Carp qw/confess/;
7     use File::Slurp;
8     use Data::Dump qw/dump/;
9 dpavlin 131 use Z80; # import
10 dpavlin 130
11     use base qw(Class::Accessor VRac Z80 Screen Prefs);
12     __PACKAGE__->mk_accessors(qw(booted));
13    
14     =head1 NAME
15    
16     Galaksija - Galaksija emulator
17    
18     =head1 VERSION
19    
20     Version 0.00
21    
22     =cut
23    
24     our $VERSION = '0.00';
25    
26     =head1 SUMMARY
27    
28     Emulator of Galaksija 8-bit Z80 machine popular in former Yugoslavia
29    
30     =cut
31    
32     =head1 FUNCTIONS
33    
34     =head2 run
35    
36     =cut
37    
38     our $emu;
39    
40     sub run {
41     my $self = shift;
42 dpavlin 131
43     warn "Galaksija $Galaksija::VERSION emulation starting\n";
44    
45     $self->show_mem( 1 );
46 dpavlin 137 #$self->trace( 1 );
47 dpavlin 131
48 dpavlin 130 $self->SUPER::init(
49     read => sub { $self->read( @_ ) },
50     write => sub { $self->write( @_ ) },
51     );
52    
53     for my $a ( 0x1000 .. 0x2000 ) {
54     $mem[$a] = 0xff;
55     }
56    
57     $self->open_screen;
58     $self->load_rom({
59     0x0000, 'rom/Galaksija/ROM1.BIN',
60     0x2000, 'rom/Galaksija/ROM2.BIN',
61     # 0xE000, 'rom/Galaksija/GAL_PLUS.BIN',
62     });
63    
64     # keyboard
65     $mem[$_] = 0xff foreach ( 0x2000 .. 0x2800 );
66    
67     # display
68 dpavlin 139 $mem[$_] = 0x20 foreach ( 0x2800 .. 0x2a00 );
69 dpavlin 130
70     # 6116-ice
71     $mem[$_] = 0 foreach ( 0x2a00 .. 0x4000 );
72    
73     $emu = $self;
74    
75     my ( $trace, $debug ) = ( $self->trace, $self->debug );
76     $self->trace( 0 );
77     $self->debug( 0 );
78    
79 dpavlin 137 warn "rendering memory\n";
80     $self->render_mem( @mem );
81 dpavlin 130
82     #$self->sync;
83     $self->trace( $trace );
84     $self->debug( $debug );
85    
86     warn "Galaksija boot finished",
87     $self->trace ? ' trace' : '',
88     $self->debug ? ' debug' : '',
89     "\n";
90    
91     Z80::reset();
92    
93     $self->loop( sub {
94     Z80::exec( $_[0] );
95 dpavlin 137 $self->render_vram;
96 dpavlin 130 });
97    
98     }
99    
100    
101     =head1 Memory management
102    
103     =cut
104    
105     =head2 read
106    
107     Read from memory
108    
109     $byte = read( $address );
110    
111     =cut
112    
113     my $keyboard_none = 255;
114    
115     my $keyboard = {};
116    
117     sub read {
118     my $self = shift;
119     my ($addr) = @_;
120     my $byte = $mem[$addr];
121     confess sprintf("can't find memory at address %04x",$addr) unless defined($byte);
122     warn sprintf("# Galaksija::read(%04x) = %02x\n", $addr, $byte) if $self->trace;
123    
124 dpavlin 137 $self->mmap_pixel( $addr, 0, $byte, 0 ) if $self->show_mem;
125 dpavlin 130 return $byte;
126     }
127    
128     =head2 write
129    
130     Write into emory
131    
132     write( $address, $byte );
133    
134     =cut
135    
136     sub write {
137     my $self = shift;
138     my ($addr,$byte) = @_;
139     warn sprintf("# Galaksija::write(%04x,%02x)\n", $addr, $byte) if $self->trace;
140    
141 dpavlin 137 $self->mmap_pixel( $addr, $byte, 0, 0 ) if $self->show_mem;
142 dpavlin 130 $mem[$addr] = $byte;
143     return;
144     }
145    
146 dpavlin 137 =head1 Architecture specific
147    
148     =head2 render_vram
149    
150     Simple hex dumper of text buffer
151    
152     =cut
153    
154 dpavlin 139 my $last_dump = '';
155    
156 dpavlin 137 sub render_vram {
157     my $self = shift;
158    
159     my $addr = 0x2800;
160    
161 dpavlin 139 my $dump;
162    
163 dpavlin 137 for my $y ( 0 .. 15 ) {
164 dpavlin 139 $dump .= sprintf "%2d: %s\n",$y, join('', map { sprintf("%02x ",$_) } @mem[ $addr .. $addr+31 ] );
165 dpavlin 137 $addr += 32;
166     }
167 dpavlin 139 if ( $dump ne $last_dump ) {
168     print $dump;
169     $last_dump = $dump;
170     }
171 dpavlin 137 }
172    
173 dpavlin 131 =head2 cpu_PC
174    
175     Helper metod to set or get PC for current architecture
176    
177     =cut
178    
179     sub cpu_PC {
180     my ( $self, $addr ) = @_;
181     if ( defined($addr) ) {
182     $PC = $addr;
183     warn sprintf("running from PC %04x\n", $PC);
184     };
185     return $PC;
186     }
187    
188 dpavlin 137 =head1 SEE ALSO
189    
190     L<VRac>, L<Screen>, L<Z80>
191    
192 dpavlin 130 =head1 AUTHOR
193    
194     Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
195    
196 dpavlin 137 Based on Galaxy Win emulator L<http://emulator.galaksija.org/>
197    
198 dpavlin 130 =head1 BUGS
199    
200     =head1 ACKNOWLEDGEMENTS
201    
202     See also L<> which is source of all
203     info about this machine (and even hardware implementation from 2007).
204    
205     =head1 COPYRIGHT & LICENSE
206    
207     Copyright 2007 Dobrica Pavlinusic, All Rights Reserved.
208    
209     This program is free software; you can redistribute it and/or modify it
210     under the same terms as Perl itself.
211    
212     =cut
213    
214     1; # End of Galaksija

  ViewVC Help
Powered by ViewVC 1.1.26