require 'NativeFileType' #http://www.atarimax.com/jindroush.atari.org/afmtbas.html #http://www.atarimax.com/jindroush.atari.org/afmtbas1.html #http://www.atariarchives.org/dere/chapt10.php #http://users.telenet.be/kim1-6502/6502/p1.html#81 # # # PART 1 0 +----------+ # | 0 | # 2 +----------+ # | 256 | <--> The displacement of the VNT from # 4 +----------+ the beginning of part two, plus 256. # | Not Used | # 6 +----------+ # | DVVT | <--> The displacement of VNT from the # 8 +----------+ beginning of part two, plus 256. # | DST | <--> The displacement of ST from the # 10+----------+ beginning of part two, plus 256. # | Not Used | # 12+----------+ # | DEND | <--> The displacement of the end of the # ======14+==========+ file from the beginning of part two. # PART 2 0| VNT | <--> Variable Name Table # DVVT-256+----------+ # | VVT | <--> Variable Value Table # DSNT-256+----------+ # | ST | <--> Statement Table # DEND-256+----------+ class AtariBasic:any } end #tokenised BASIC files start with 00 00 ?? 01 is_valid_file_if lambda {(contents[0,2]=="\000\000") && (contents[3]==0x01)} START_OF_FILE_PART_TWO=14 ATARI_BASIC_COMMAND_TOKENS=[ 'REM', #0x0 'DATA', #0x1 'INPUT', #0x2 'COLOR', #0x3 'LIST', #0x4 'ENTER', #0x5 'LET', #0x6 'IF', #0x7 'FOR', #0x8 'NEXT', #0x9 'GOTO', #0x0A 'GO TO', #0x0B 'GOSUB', #0x0C 'TRAP', #0x0D 'BYE', #0x0E 'CONT', #0x0F 'COM', #0x10 'CLOSE', #0x11 'CLR', #0x12 'DEG', #0x13 'DIM', #0x14 'END', #0x15 'NEW', #0x16 'OPEN', #0x17 'LOAD', #0x18 'SAVE', #0x19 'STATUS', #0x1A 'NOTE', #0x1B 'POINT', #0x1C 'XIO', #0x1D 'ON', #0x1E 'POKE', #0x1F 'PRINT', #0x20 'RAD', #0x21 'READ', #0x22 'RESTORE', #0x23 'RETURN', #0x24 'RUN', #0x25 'STOP', #0x26 'POP', #0x27 '?', #0x28 'GET', #0x29 'PUT', #0x2A 'GRAPHICS', #0x2B 'PLOT', #0x2C 'POSITION', #0x2D 'DOS', #0x2E 'DRAWTO', #0x2F 'SETCOLOR', #0x30 'LOCATE', #0x31 'SOUND', #0x32 'LPRINT', #0x33 'CSAVE', #0x34 'CLOAD', #0x35 '', #0x36 - [IMPLIED LET] 'ERROR - [SYNTAX]', #0x37 ## these following tokens are from Turbo BASIC - http://www.atarimax.com/jindroush.atari.org/afmtbas1.html 'DPOKE', #38 'MOVE', #39 '-MOVE', #3A '*F', #3B 'REPEAT', #3C 'UNTIL', #3D 'WHILE', #3E 'WEND', #3F 'ELSE', #40 'ENDIF', #41 'BPUT', #42 'BGET', #43 'FILLTO', #44 'DO', #45 'LOOP', #46 'EXIT', #47 'DIR', #48 'LOCK', #49 'UNLOCK', #4A 'RENAME', #4B 'DELETE', #4C 'PAUSE', #4D 'TIME$=', #4E 'PROC', #4F 'EXEC', #50 'ENDPROC', #51 'FCOLOR', #52 '*L', #53 '------------------------------', #54 'RENUM', #55 'DEL', #56 'DUMP', #57 'TRACE', #58 'TEXT', #59 'BLOAD', #5A 'BRUN', #5B 'GO#', #5C '#', #5D '*B', #5E 'PAINT', #5F 'CLS', #60 'DSOUND', #61 'CIRCLE', #62 '%PUT', #63 '%GET', #64 ] ATARI_BASIC_OPERATORS_AND_FUNCTIONS={ 0x0D => '[NUM HEX CONST]', # from TURBO BASIC 0x0E =>'[NUM CONST]', 0x0F =>'[STR CONST]', 0x10 =>'[NOT USED]', 0x11 =>'[NOT USED]', 0x12 =>',', 0x13 =>'$', 0x14 =>':',# [STMT END] 0x15 =>';', 0x16 =>'[LINE END]', 0x17 =>'GOTO', 0x18 =>'GOSUB', 0x19 =>'TO', 0x1A =>'STEP', 0x1B =>'THEN', 0x1C =>'#', 0x1D =>'<=', #numerics 0x1E =>'<>', 0x1F =>'>=', 0x20 =>'<', 0x21 =>'>', 0x22 =>'=', 0x23 =>'', 0x24 =>'*', 0x25 =>'+', 0x26 =>'-', 0x27 =>'/', 0x28 =>'NOT', 0x29 =>'OR', 0x2A =>'AND', 0x2B =>'(', 0x2C =>')', 0x2D =>'=', # ARITHM ASSIGN 0x2E =>'=',#STRING ASSIGN 0x2F =>'<=',#STRINGS 0x30 =>'<>', 0x31 =>'>=', 0x32 =>'<', 0x33 =>'>', 0x34 =>'=', 0x35 =>'+',#unary 0x36 =>'-', 0x37 =>'(',# [STRING LEFT PAREN] 0x38 =>'(',#[ARRAY LEFT PAREN] 0x39 =>'(',# [DIM ARRAY LEFT PAREN] 0x3A =>'(',#[FUN LEFT PAREN] 0x3B =>'(',# [DIM STR LEFT PAREN] 0x3C =>',',# [ARRAY COMMA] 0x3D =>'STR$', 0x3E =>'CHR$', 0x3F =>'USR', 0x40 =>'ASC', 0x41 =>'VAL', 0x42 =>'LEN', 0x43 =>'ADR', 0x44 =>'ATN', 0x45 =>'COS', 0x46 =>'PEEK', 0x47 =>'SIN', 0x48 =>'RND', 0x49 =>'FRE', 0x4A =>'EXP', 0x4B =>'LOG', 0x4C =>'CLOG', 0x4D =>'SQR', 0x4E =>'SGN', 0x4F =>'ABS', 0x50 =>'INT', 0x51 =>'PADDLE', 0x52 =>'STICK', 0x53 =>'PTRIG', 0x54 =>'STRIG', ## these following tokens are from Turbo BASIC - http://www.atarimax.com/jindroush.atari.org/afmtbas1.html 0x55=>'DPEEK', 0x56=>'&', 0x57=>'!', 0x58=>'INSTR', 0x59=>'INKEY$', 0x5A=>'EXOR', 0x5B=>'HEX$', 0x5C=>'DEC', 0x5D=>'DIV', 0x5E=>'FRAC', 0x5F=>'TIME$', 0x60=>'TIME', 0x61=>'MOD', 0x62=>'EXEC', 0x63=>'RND', 0x64=>'RAND', 0x65=>'TRUNC', 0x66=>'%0', 0x67=>'%1', 0x68=>'%2', 0x69=>'%3', 0x6A=>'GO#', 0x6B=>'UINSTR', 0x6C=>'ERR', 0x6D=>'ERL', } def to_listing s="" variable_name_table_displacement=(contents[2]+(contents[3]<<8))-0x100 # puts "%02x %02x" % [contents[6],contents[7]] variable_value_table_displacement=(contents[6]+(contents[7]<<8))-0x100 statement_table_displacement=(contents[8]+(contents[9]<<8))-0x100 file_end_displacement=(contents[12]+(contents[13]<<8))-0x100 # puts "DVNT $#{"%02x" % variable_name_table_displacement} DVVT $#{"%02x" % variable_value_table_displacement} DST $#{"%02x" % statement_table_displacement}" #extract all the variable names variable_name_table=contents[variable_name_table_displacement+START_OF_FILE_PART_TWO,(variable_value_table_displacement-variable_name_table_displacement)] variable_names={} variable_token=0x80 current_variable_name="" variable_name_table.each_byte do |byte| if byte>=0x80 then current_variable_name+=(byte-0x80).chr variable_names[variable_token]=current_variable_name variable_token+=1 current_variable_name="" else current_variable_name+=byte.chr end end #~ variable_names.keys.sort.each do |token| #~ puts "$%02x : #{variable_names[token]}" % token #~ end statement_table=contents[statement_table_displacement+START_OF_FILE_PART_TWO,(file_end_displacement-statement_table_displacement)] p=0 s="" while p=0x80 then variable=variable_names[token] variable="[UNK VAR %02X]" % token if variable.nil? s<>4 low_nibble=b%0x10 (high_nibble*10)+low_nibble 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.