2 # This file is part of Language::Befunge.
3 # Copyright (c) 2001-2009 Jerome Quelin, all rights reserved.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the same terms as Perl itself.
10 package Language
::Befunge
::lib
::ORTH
;
15 use Language
::Befunge
::Vector
;
17 sub new
{ return bless {}, shift; }
25 # push $a & $b back onto the stack (bitwise AND)
28 my ($self, $interp) = @_;
29 my $ip = $interp->get_curip();
43 # push $a ^ $b back onto the stack (bitwise XOR)
46 my ($self, $interp) = @_;
47 my $ip = $interp->get_curip();
61 # push $a | $b back onto the stack (bitwise OR)
64 my ($self, $interp) = @_;
65 my $ip = $interp->get_curip();
81 # push back value stored at coords ($x, $y). note that befunge get is g($x,$y)
82 # (ie, the arguments are reversed).
85 my ($self, $lbi) = @_;
86 my $ip = $lbi->get_curip;
90 my $v = Language
::Befunge
::Vector
->new($x,$y);
91 my $val = $lbi->get_storage->get_value( $v );
99 # store value $v at coords ($x, $y). note that befunge put is p($v,$x,$y) (ie,
100 # the coordinates are reversed).
103 my ($self, $lbi) = @_;
104 my $ip = $lbi->get_curip;
108 my $v = Language
::Befunge
::Vector
->new($x,$y);
110 $lbi->get_storage->set_value( $v, $val );
119 # print popped 0gnirts on stdout.
122 my ($self, $lbi) = @_;
123 print $lbi->get_curip->spop_gnirts;
127 # -- coordinates & velocity changes
132 # Change X coordinate of IP to $x.
135 my ($self, $lbi) = @_;
136 my $ip = $lbi->get_curip;
137 my $v = $ip->get_position;
139 $v->set_component(0,$x);
145 # Change Y coordinate of IP to $y.
148 my ($self, $lbi) = @_;
149 my $ip = $lbi->get_curip;
150 my $v = $ip->get_position;
152 $v->set_component(1,$y);
159 # Change X coordinate of IP velocity to $dx.
162 my ($self, $lbi) = @_;
163 my $ip = $lbi->get_curip;
164 my $v = $ip->get_delta;
166 $v->set_component(0,$dx);
173 # Change Y coordinate of IP velocity to $dy.
176 my ($self, $lbi) = @_;
177 my $ip = $lbi->get_curip;
178 my $v = $ip->get_delta;
180 $v->set_component(1,$dy);
189 # Test the top stack element, and if zero, skip over the next cell (i.e., add
190 # the delta twice to the current position).
193 my ($self, $lbi) = @_;
194 my $ip = $lbi->get_curip;
196 $lbi->_move_ip_once($ip) if $v == 0;
207 Language::Befunge::IP::lib::ORTH - Orthogonal easement extension
213 The ORTH fingerprint (0x4f525448) is designed to ease transition between the
214 Orthogonal programming language and Befunge-98 (or higher dimension Funges).
216 Even if transition from Orthogonal is not an issue, the ORTH library contains
217 some potentially interesting instructions not in standard Funge-98.
225 Create a new ORTH instance.
228 =head2 Bit operations
234 Push back C<$a & $b> (bitwise AND).
239 Push back C<$a | $b> (bitwise OR).
244 Push back C<$a ^ $b> (bitwise XOR).
257 Push back value stored at coords ($x, $y). Note that Befunge get is C<g($x,$y)>
258 (ie, the arguments are reversed).
261 =item P( $v, $y, $x )
263 Store value C<$v> at coords ($x, $y). Note that Befunge put is C<p($v,$x,$y)> (ie,
264 the coordinates are reversed).
277 Print popped 0gnirts on STDOUT.
283 =head2 Coordinates & velocity changes
289 Change X coordinate of IP to C<$x>.
294 Change Y coordinate of IP to C<$y>.
299 Change X coordinate of IP velocity to C<$dx>.
304 Change Y coordinate of IP velocity to C<$dy>.
316 Test the top stack element, and if zero, skip over the next cell (i.e., add
317 the delta twice to the current position).
325 L<Language::Befunge>, L<http://catseye.tc/projects/funge98/library/ORTH.html>,
326 and L<http://www.muppetlabs.com/~breadbox/orth/orth.html>.
332 Jerome Quelin, C<< <jquelin@cpan.org> >>
335 =head1 COPYRIGHT & LICENSE
337 Copyright (c) 2001-2009 Jerome Quelin, all rights reserved.
339 This program is free software; you can redistribute it and/or modify
340 it under the same terms as Perl itself.