DASM
|
00001 #!/usr/bin/perl -w 00002 ## 00003 # Basic text emulation for the DASM assembler. 00004 # This module provides the video RAM for a simple text array chip. 00005 # 00006 # The chip is 40x25 = 1000 bytes, out of the 1024 that are mapped. 00007 # For simplicity, we use only the bottom 8 bits of the 16 bits for each 00008 # character. 00009 # 00010 # @file 00011 # @author Justin Fletcher 00012 # 00013 00014 package DExecHW::BasicVideo; 00015 00016 use Curses; 00017 00018 00019 ## 00020 # Construct a new hardware device object. 00021 # 00022 # @param[in] $proto This class object, or prototype to add to 00023 # @param[in] $object The object to proxy for 00024 # @param[in] $offset The offset this object is created for 00025 # 00026 # @return Assembler object 00027 sub new 00028 { 00029 my $proto = shift; 00030 my $object = shift; 00031 my $offset = shift || 0; 00032 my $class = ref($proto) || $proto; 00033 my $self = { 00034 'memory' => [ 00035 map { 0 } (0..0x3FF) 00036 ], 00037 }; 00038 00039 bless $self, $class; 00040 00041 00042 return $self; 00043 } 00044 00045 00046 ## 00047 # Start up the hardware. 00048 # 00049 # We perform all output through the Curses library. 00050 # 00051 # @param[in] $self Object 00052 sub start 00053 { 00054 my ($self) = @_; 00055 00056 Curses::initscr(); 00057 00058 $self->{'win'} = Curses::newwin(25, 40, 0, 0); 00059 #Curses::box( $self->{'win'}, 0,0); 00060 00061 Curses::refresh( $self->{'win'} ); 00062 } 00063 00064 00065 ## 00066 # Stop the hardware. 00067 # 00068 # @param[in] $self Object 00069 sub stop 00070 { 00071 my ($self) = @_; 00072 00073 Curses::endwin(); 00074 } 00075 00076 00077 00078 ## 00079 # Return the size of of the implementation. 00080 # 00081 # @param[in] $self Object 00082 # 00083 # @return Size of the hardware implementation in words 00084 sub window 00085 { 00086 my ($self) = @_; 00087 00088 return 0x400; 00089 } 00090 00091 00092 ## 00093 # Read value 00094 # 00095 # @param[in] $self Object 00096 # @param[in] $offset Offset of register within window 00097 # @param[in] $exec DExec object opon which this object is operating 00098 # 00099 # @return value of this register 00100 sub read 00101 { 00102 my ($self, $offset, $exec) = @_; 00103 00104 $value = $self->{'memory'}->[$offset]; 00105 00106 return $value; 00107 } 00108 00109 00110 ## 00111 # Write value 00112 # 00113 # @param[in] $self Object 00114 # @param[in] $offset Offset of register within window 00115 # @param[in] $exec DExec object upon which this object is operating 00116 # @param[in] $value Value to write 00117 # 00118 # @return ignored 00119 sub write 00120 { 00121 my ($self, $offset, $exec, $value) = @_; 00122 00123 $self->{'memory'}->[$offset] = $value; 00124 00125 my $y = int($offset / 40); 00126 my $x = int($offset % 40); 00127 00128 Curses::addch($self->{'win'}, $y, $x, $value); 00129 00130 Curses::refresh( $self->{'win'} ); 00131 00132 #print "Write $value to $x,$y\n"; 00133 } 00134 00135 00136 ## 00137 # Get the symbol name for an offset 00138 # 00139 # @param[in] $self Object 00140 # @param[in] $offset Offset of register within window 00141 # 00142 # @return symbol name to use 00143 # @retval undef for a default symbol 00144 # @retval "" for no symbol 00145 sub symbol 00146 { 00147 my ($self, $offset) = @_; 00148 00149 return ""; 00150 } 00151 00152 # Must return 1 00153 1;