$:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__))) $:.unshift(File.dirname(__FILE__+"\\..")) unless $:.include?(File.dirname(__FILE__+"\\..")) || $:.include?(File.expand_path(File.dirname(__FILE__+"\\.."))) require 'HostSystem' class Zx81' ', 11=>'"', 12=>'£', 13=>'$', 14=>':', 15=>'?', 16=>'(', 17=>')', 18=>'>', 19=>'<', 20=>'=', 21=>'+', 22=>'-', 23=>'*', 24=>'/', 25=>';', 26=>',', 27=>'.', 28=>'0', 29=>'1', 30=>'2', 31=>'3', 32=>'4', 33=>'5', 34=>'6', 35=>'7', 36=>'8', 37=>'9', 38=>'A', 39=>'B', 40=>'C', 41=>'D', 42=>'E', 43=>'F', 44=>'G', 45=>'H', 46=>'I', 47=>'J', 48=>'K', 49=>'L', 50=>'M', 51=>'N', 52=>'O', 53=>'P', 54=>'Q', 55=>'R', 56=>'S', 57=>'T', 58=>'U', 59=>'V', 60=>'W', 61=>'X', 62=>'Y', 63=>'Z', 64=>'RND ', 65=>'INKEY$ ', 66=>'PI ', 112=>'', 113=>'', 114=>'', 115=>'', 116=>'GRAPHICS ', 117=>'EDIT ', 118=>'NEWLINE ', 119=>'RUBOUT ', 120=>'/', 121=>'FUNCTION ', 127=>'cursor', 128=>' ', 139=>'"', 140=>'£', 141=>'$', 142=>':', 143=>'?', 144=>'(', 145=>')', 146=>'>', 147=>'<', 148=>'=', 149=>'+', 150=>'-', 151=>'*', 152=>'/', 153=>';', 154=>',', 155=>'.', 156=>'0', 157=>'1', 158=>'2', 159=>'3', 160=>'4', 161=>'5', 162=>'6', 163=>'7', 164=>'8', 165=>'9', 166=>'A', 167=>'B', 168=>'C', 169=>'D', 170=>'E', 171=>'F', 172=>'G', 173=>'H', 174=>'I', 175=>'J', 176=>'K', 177=>'L', 178=>'M', 179=>'N', 180=>'O', 181=>'P', 182=>'Q', 183=>'R', 184=>'S', 185=>'T', 186=>'U', 187=>'V', 188=>'W', 189=>'X', 190=>'Y', 191=>'Z', 192=>'""', 193=>'AT ', 194=>'TAB ', 195=>'?', 196=>'CODE ', 197=>'VAL ', 198=>'LEN ', 199=>'SIN ', 200=>'COS ', 201=>'TAN ', 202=>'ASN ', 203=>'ACS ', 204=>'ATN ', 205=>'LN ', 206=>'EXP ', 207=>'INT ', 208=>'SQR ', 209=>'SGN ', 210=>'ABS ', 211=>'PEEK ', 212=>'USR ' , 213=>'STR$ ', 214=>'CHR$ ', 215=>'NOT ', 216=>'**', 217=>'OR ', 218=>'AND ', 219=>'<=', 220=>'>=', 221=>'<>', 222=>'THEN ', 223=>'TO ', 224=>'STEP ', 225=>'LPRINT ', 226=>'LLIST ', 227=>'STOP ', 228=>'SLOW ', 229=>'FAST ', 230=>'NEW ', 231=>'SCROLL ', 232=>'CONT ', 233=>'DIM ', 234=>'REM ', 235=>'FOR ', 236=>'GOTO ' , 237=>'GOSUB ' , 238=>'INPUT ', 239=>'LOAD ', 240=>'LIST ', 241=>'LET ', 242=>'PAUSE ', 243=>'NEXT ', 244=>'POKE ', 245=>'PRINT ', 246=>'PLOT ', 247=>'RUN ', 248=>'SAVE ', 249=>'RAND ', 250=>'IF ', 251=>'CLS ', 252=>'UNPLOT ', 253=>'CLEAR ', 254=>'RETURN ', 255=>'COPY ', } end def self.start_track 0 end def self.to_ascii(b) token=tokens[b] if (!token.nil?) && (token.length==1) then token else "." end end #decode 5 bytes as a number #A number is stored in the ZX81 in floating point binary with one exponent byte e (1 <=e <=255), & four mantissa bytes m (½ <= m <= 1). This represents the number m * 2**(e-128.) # Since ½<= m<=1, the most significant bit of the mantissa m is always 1. Therefore in actual fact we can replace it with a bit to show the sign - 0 for positive numbers, 1 for negative. #Zero has a special representation in which all 5 bytes are 0. #this is a conversion of code originally posted by Darren Salt to http://groups.google.com.au/group/comp.sys.sinclair/browse_frm/thread/37966a7bb023670d/690f27c27f48a036 def self.buffer_to_number(buffer) raise "invalid number length" unless buffer.length==5 if buffer[0]==0 then #it's an integer between -65535 & 65535 return buffer[3] * 256 + buffer[2] - (buffer[1]==0 ? 65536 : 0); else exponent=buffer[0]-128 sign = (buffer[1] >=0x80) ? -1 : 1 mantissa = ((buffer[1] | 0x80) / 256.0) + (buffer[2] / 65536.0 ) + (buffer[3] / 16777216.0) + (buffer[4] / 4294967296.0) value = sign * mantissa * (2**exponent) return value.to_i if (value.to_i.to_f==value) return value end end end # == Author # Jonno Downes (jonno@jamtronix.com) # # == Copyright # Copyright (c) 2008 Jonno Downes (jonno@jamtronix.com) # #Permission is hereby granted, free of charge, to any person obtaining #a copy of this software and associated documentation files (the #"Software"), to deal in the Software without restriction, including #without limitation the rights to use, copy, modify, merge, publish, #distribute, sublicense, and/or sell copies of the Software, and to #permit persons to whom the Software is furnished to do so, subject to #the following conditions: # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.