Class: AcornBASIC

Inherits:
NativeFileType show all
Defined in:
lib/native_file_types/acornbbc/AcornBASIC.rb

Overview

Constant Summary collapse

BBC_TELETEXT_TOKENS =
{
0x81=>"ALPHA RED",
0x82=>"ALPHA GREEN",
0x83=>"ALPHA YELLOW",
0x84=>"ALPHA BLUE",
0x85=>"ALPHA MAGENTA",
0x86=>"ALPHA CYAN",
0x87=>"ALPHA WHITE",
0x88=>"FLASH",
0x89=>"STEADY",
0x8C=>"NORMAL HEIGHT",
0x8D=>"DOUBLE HEIGHT",
0x91=>"GRAPHIC RED",
0x92=>"GRAPHIC GREEN",
0x93=>"GRAPHIC YELLOW",
0x94=>"GRAPHIC BLUE",
0x95=>"GRAPHIC MAGENTA",
0x96=>"GRAPHIC CYAN",
0x97=>"GRAPHIC WHITE",
0x98=>"CONCEAL DISPLAY",
0x99=>"CONTIGUOUS GRAPHICS",
0x9A=>"SEPERATED GRAPHICS",
0x9C=>"BLACK BACKGROUND",
0x9D=>"NEW BACKGROUND",
0x9E=>"HOLD GRAPHICS",
0x9F=>"RELEASE GRAPHICS",

}
BBC_BASIC_TOKENS =
{
0x80=>"AND",
0x81=>"DIV",
0x82=>"EOR",
0x83=>"MOD",
0x84=>"OR",
0x85=>"ERROR",
0x86=>"LINE",
0x87=>"OFF",
0x88=>"STEP",
0x89=>"SPC",
0x8A=>"TAB(",
0x8B=>"ELSE",
0x8C=>"THEN",
0x8E=>"OPENIN",
0x8F=>"PTR",
0x90=>"PAGE",
0x91=>"TIME",
0x92=>"LOMEM",
0x93=>"HIMEM",
0x94=>"ABS",
0x95=>"ACS",
0x96=>"ADVAL",
0x97=>"ASC",
0x98=>"ASN",
0x99=>"ATN",
0x9A=>"BGET",
0x9B=>"COS",
0x9C=>"COUNT",
0x9D=>"DEG",
0x9E=>"ERL",
0x9F=>"ERR",
0xA0=>"EVAL",
0xA1=>"EXP",
0xA2=>"EXT",
0xA3=>"FALSE",
0xA4=>"FN",
0xA5=>"GET",
0xA6=>"INKEY",
0xA7=>"INSTR(",
0xA8=>"INT",
0xA9=>"LEN",
0xAA=>"LN",
0xAB=>"LOG",
0xAC=>"NOT",
0xAD=>"OPENUP",
0xAE=>"OPENOUT",
0xAF=>"PI",
0xB0=>"POINT(",
0xB1=>"POS",
0xB2=>"RAD",
0xB3=>"RND",
0xB4=>"SGN",
0xB5=>"SIN",
0xB6=>"SQR",
0xB7=>"TAN",
0xB8=>"TO",
0xB9=>"TRUE",
0xBA=>"USR",
0xBB=>"VAL",
0xBC=>"VPOS",
0xBD=>"CHR$",
0xBE=>"GET$",
0xBF=>"INKEY$",
0xC0=>"LEFT$(",
0xC1=>"MID$(",
0xC2=>"RIGHT$(",
0xC3=>"STR$",
0xC4=>"STRING$(",
0xC5=>"EOF",
0xC6=>"SUM",
0xC7=>"WHILE",
0xC8=>"CASE",
0xC9=>"WHEN",
0xCA=>"OF",
0xCB=>"ENDCASE",
0xCC=>"OTHERWISE",
0xCD=>"ENDIF",
0xCE=>"ENDWHILE",
0xCF=>"PTR ",
0xD0=>"PAGE",
0xD1=>"TIME",
0xD2=>"LOMEM",
0xD3=>"HIMEM",
0xD4=>"SOUND",
0xD5=>"BPUT",
0xD6=>"CALL",
0xD7=>"CHAIN",
0xD8=>"CLEAR",
0xD9=>"CLOSE",
0xDA=>"CLG",
0xDB=>"CLS",
0xDC=>"DATA",
0xDD=>"DEF",
0xDE=>"DIM",
0xDF=>"DRAW",
0xE0=>"END",
0xE1=>"ENDPROC",
0xE2=>"ENVELOPE",
0xE3=>"FOR",
0xE4=>"GOSUB",
0xE5=>"GOTO",
0xE6=>"GCOL",
0xE7=>"IF",
0xE8=>"INPUT",
0xE9=>"LET",
0xEA=>"LOCAL",
0xEB=>"MODE",
0xEC=>"MOVE",
0xED=>"NEXT",
0xEE=>"ON",
0xEF=>"VDU",
0xF0=>"PLOT",
0xF1=>"PRINT",
0xF2=>"PROC",
0xF3=>"READ",
0xF4=>"REM",
0xF5=>"REPEAT",
0xF6=>"REPORT",
0xF7=>"RESTORE",
0xF8=>"RETURN",
0xF9=>"RUN",
0xFA=>"STOP",
0xFB=>"COLOUR5",
0xFC=>"TRACE",
0xFD=>"UNTIL",
0xFE=>"WIDTH",
0xFF=>"OSCLI"
}

Instance Attribute Summary collapse

Attributes inherited from NativeFileType

#aux_code, #contents, #file_system_image, #file_type, #filename, #meta_data

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from NativeFileType

#<=>, #==, all_native_file_types, best_fit, code_for_tests, compatability_score, #data_without_header, file_type_matches?, #full_filename, #header_length, #initialize, is_valid_file_if, load_address, matching_score, native_file_types_possible_on_file_system, non_matching_score, #to_hex_dump, #to_info_dump, #type_description

Methods included from SubclassTracking

extended

Constructor Details

This class inherits a constructor from NativeFileType

Instance Attribute Details

#execute_addressObject

Returns the value of attribute execute_address.



11
12
13
# File 'lib/native_file_types/acornbbc/AcornBASIC.rb', line 11

def execute_address
  @execute_address
end

Class Method Details

.file_system_file_typesObject



13
14
15
16
17
# File 'lib/native_file_types/acornbbc/AcornBASIC.rb', line 13

def self.file_system_file_types
  {
    AcornDFS=>:any
  }
end

Instance Method Details

#load_addressObject



236
237
238
# File 'lib/native_file_types/acornbbc/AcornBASIC.rb', line 236

def load_address
    aux_code
end

#to_listingObject



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/native_file_types/acornbbc/AcornBASIC.rb', line 189

def to_listing
	i=0
	s=""
	begin
		raise "0x0D expected, 0x#{"%X" % contents[i]} found at offset #{i} in #{filename}" unless contents[i]==0x0D
		break if contents[i+1]==0xFF	#end of BASIC 
		line_number=contents[i+2]+contents[i+1]*0x100
		line_length=contents[i+3]
		line_tokens=contents[i+4,line_length-4]
		tokens_length=line_tokens.length
		j=0
		detokenised_line=""
		inquote=false
		begin
			token=line_tokens[j]
			inquote=!inquote if token==0x22
			if inquote then
				if token>=0x80 then
					detokenised_line+= BBC_TELETEXT_TOKENS[token].nil? ? ("{&%02X}" % token)  : ("{&%02X:#{BBC_TELETEXT_TOKENS[token]}}" % token) 
				else
					detokenised_line+= token.chr 
				end
			else
				if token==0x8d then
					high_bits=line_tokens[j+1] ^ 0x54
					lo=line_tokens[j+2]-0x40 + ((high_bits & 0b00110000)<<2)
					hi=line_tokens[j+3]-0x40 + ((high_bits & 0b00001100)<<4)
					destination_line_number=lo+(hi<<8)
#					puts "%08b %08b %08b %08b %08b #{line_number} #{destination_line_number}" % [ line_tokens[j+1],high_bits,line_tokens[j+2],line_tokens[j+3],destination_line_number]
					detokenised_line+= "#{destination_line_number}"
					j+=3

				else
					detokenised_line+= BBC_BASIC_TOKENS[token].nil? ? token.chr : BBC_BASIC_TOKENS[token]
				end
			end
			
			j+=1
		end until j>=tokens_length
		s+="#{line_number} #{detokenised_line}\n"
		i+=line_length
		
	end	until i>=contents.length
#	puts s
	s
end