home *** CD-ROM | disk | FTP | other *** search
/ Acorn User 10 / AU_CD10.iso / Updates / Perl / Non-RPC / !Perl / riscos / RISCOS / ValidateAddr.pm < prev   
Text File  |  1998-07-12  |  1KB  |  55 lines

  1. package RISCOS::ValidateAddr;
  2.  
  3. use RISCOS::SWI ':DEFAULT', '&C_Flag';
  4. require Exporter;
  5. use strict;
  6. use vars qw (@ISA @EXPORT $VERSION $os_val $mask);
  7.  
  8. @ISA = qw(Exporter);
  9. @EXPORT = qw(validate_addr);
  10. $VERSION = 0.02;    # Now does ROM too
  11.  
  12. $os_val = SWINumberFromString("XOS_ValidateAddress");
  13. $mask = ®mask([0,1],[15]);
  14.  
  15. sub validate_addr ($$) {
  16.     my ($pc, $from, $to) = ('xxxx', @_);
  17.     return undef unless defined ($from) && defined ($to);
  18.     
  19.     return 2 if $from >= 0x3800000 && $to < 0x4000000;
  20.     
  21.     return undef unless defined swix ($os_val, $mask, $from, $to, $pc);
  22.  
  23.     # Carry flag clear if range [R0,R1) is valid. Return 1 in this case.
  24.     return (unpack ('i', $pc) & &C_Flag) ? 0 : 1;
  25. }
  26.  
  27. $os_val;
  28. __END__
  29.  
  30. =head1 NAME
  31.  
  32. RISCOS::ValidateAddr -- perl module that checks an address range is valid
  33.  
  34. =head1 SYNOPSIS
  35.  
  36.     use RISCOS::ValidateAddr;
  37.     $is_valid = validate_addr ($lower_inc, $upper_exc);
  38.  
  39. =head1 DESCRIPTION
  40.  
  41. This module provides a perl interface to C<OS_ValidateAddress>. This checks the
  42. address range between the lower (inclusive) and upper (exclusive) bounds to see
  43. if the entire specified range maps into physical RAM or ROM. (The memory should
  44. actually exist unless you've been fiddling with C<OS_SetMemMapEntries>.)
  45.  
  46. Returns C<2> if the address range is in ROM,
  47. C<1> if the address range is valid as RAM,
  48. C<0> if it is not, undefined on error.
  49.  
  50. =head1 AUTHOR
  51.  
  52. Nicholas Clark <F<nick@unfortu.net>>
  53.  
  54. =cut
  55.