Class: IntegerBASIC
- Inherits:
-
NativeFileType
- Object
- NativeFileType
- IntegerBASIC
- Defined in:
- lib/native_file_types/apple2/IntegerBASIC.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from NativeFileType
#aux_code, #contents, #file_system_image, #file_type, #filename, #meta_data
Class Method Summary collapse
Instance Method Summary collapse
-
#to_listing ⇒ Object
Integer Basic file format: <Length_of_file> (16-bit little endian) <Line> .…..
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, 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
Constructor Details
This class inherits a constructor from NativeFileType
Class Method Details
.file_system_file_types ⇒ Object
4 5 6 7 8 |
# File 'lib/native_file_types/apple2/IntegerBASIC.rb', line 4 def IntegerBASIC.file_system_file_types { AppleDos=>0x01 } end |
Instance Method Details
#to_listing ⇒ Object
Integer Basic file format: <Length_of_file> (16-bit little endian) <Line> .….. <Line>
where <Line> is: 1 byte: Line length 2 bytes: Line number, binary little endian <token> <token> <token> .….. <end-of-line token>
<token> is one of: $12 - $7F: Tokens as listed below: 1 byte/token $80 - $FF: ASCII characters with high bit set $B0 - $B9: Integer constant, 3 bytes: $B0-$B9,
followed by the integer value in
2-byte binary little-endian format
(Note: a $B0-$B9 byte preceded by an
alphanumeric ASCII(hi_bit_set) byte
is not the start of an integer
constant, but instead part of a
variable name)
<end-of-line token> is: $01: One byte having the value $01
(Note: a $01 byte may also appear
inside an integer constant)
Note that the tokens $02 to $11 represent commands which can be executed as direct commands only – any attempt to enter then into an Integer Basic program will be rejected as a syntax error. Therefore, no Integer Basic program which was entered through the Integer Basic interpreter will contain any of the tokens $02 to $11. The token $00 appears to be unused and won’t appear in Integer Basic programs either. However, $00 is used as an end-of-line marker in S-C Assembler source files, which also are of DOS file type “I”.
(note here a difference from Applesoft Basic, where there are no “direct mode only” commands - any Applesoft commands can be entered into an Applesoft program as well).
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/native_file_types/apple2/IntegerBASIC.rb', line 58 def to_listing length=contents[0]+contents[1]*256 index=2 s="" while (index<length) in_REM = false in_QUOTE = false lead_SP = false last_AN = false last_TOK = false line_length=contents[index] index+=1 #skip over the "line length" field line_no=contents[index]+contents[index+1]*256 index+=2 #skip over the "line number" field s+=sprintf("%u ",line_no) done_line=false while (!done_line) lead_SP = lead_SP || last_AN b=contents[index] if (b >= 0x80 ) then if ( !in_REM && !in_QUOTE && !last_AN && (b>= 0xB0 && b <= 0xB9) ) then integer = contents[index+1]+contents[index+2]*256 index+=2 s+=sprintf( (last_TOK && lead_SP ) ? " %d" : "%d", integer ) lead_SP = true else c = b & 0x7F if (!in_REM && !in_QUOTE && last_TOK && lead_SP && is_alnum(c)) then s+=" " end if ( c >= 0x20 ) then s+=c.chr else s+="^"+(c+0x40).chr end last_AN = is_alnum(c) end last_TOK =false else token = INTEGER_BASIC_TOKENS[b] lastchar = token[token.length-1] case b when IB_REM_TOKEN then in_REM = true when IB_QUOTE_START then in_QUOTE = true when IB_QUOTE_END then in_QUOTE = false end if lead_SP && ( is_alnum(token[0]) || b == IB_UNARY_PLUS || b == IB_UNARY_MINUS || b == IB_QUOTE_START ) then s+=" " end s+=token last_AN = false lead_SP = is_alnum(lastchar) || lastchar == ')' || lastchar == '\"' last_TOK = true end index+=1 done_line=(index>length)||(contents[index]==0x01) end s+="\n" index+=1 # skip over "end of line" marker end s end |