Class: C64BasicPrg
- Inherits:
-
C64Prg
- Object
- NativeFileType
- CbmFile
- C64Prg
- C64BasicPrg
- Defined in:
- lib/native_file_types/c64/C64BasicPrg.rb
Constant Summary collapse
- CBM_BASIC_TOKENS =
tokens taken from www.zimmers.net/anonftp/pub/cbm/programming/cbm-basic-tokens.txt
{ 0x80=>"END", 0x81=>"FOR", 0x82=>"NEXT", 0x83=>"DATA", 0x84=>"INPUT#", 0x85=>"INPUT", 0x86=>"DIM", 0x87=>"READ", 0x88=>"LET", 0x89=>"GOTO", 0x8A=>"RUN", 0x8B=>"IF", 0x8C=>"RESTORE", 0x8D=>"GOSUB", 0x8E=>"RETURN", 0x8F=>"REM", 0x90=>"STOP", 0x91=>"ON", 0x92=>"WAIT", 0x93=>"LOAD", 0x94=>"SAVE", 0x95=>"VERIFY", 0x96=>"DEF", 0x97=>"POKE", 0x98=>"PRINT#", 0x99=>"PRINT", 0x9A=>"CONT", 0x9B=>"LIST", 0x9C=>"CLR", 0x9D=>"CMD", 0x9E=>"SYS", 0x9F=>"OPEN", 0xA0=>"CLOSE", 0xA1=>"GET", 0xA2=>"NEW", 0xA3=>"TAB(", 0xA4=>"TO", 0xA5=>"FN", 0xA6=>"SPC(", 0xA7=>"THEN", 0xA8=>"NOT", 0xA9=>"STEP", 0xAA=>"+", 0xAB=>"-", 0xAC=>"*", 0xAD=>"/", 0xAE=>"^", 0xAF=>"AND", 0xB0=>"OR", 0xB1=>">", 0xB2=>"=", 0xB3=>"<", 0xB4=>"SGN", 0xB5=>"INT", 0xB6=>"ABS", 0xB7=>"USR", 0xB8=>"FRE", 0xB9=>"POS", 0xBA=>"SQR", 0xBB=>"RND", 0xBC=>"LOG", 0xBD=>"EXP", 0xBE=>"COS", 0xBF=>"SIN", 0xC0=>"TAN", 0xC1=>"ATN", 0xC2=>"PEEK", 0xC3=>"LEN", 0xC4=>"STR$", 0xC5=>"VAL", 0xC6=>"ASC", 0xC7=>"CHR$", 0xC8=>"LEFT$", 0xC9=>"RIGHT$", 0xCA=>"MID$", 0xCB=>"GO", 0xCC=>'RGR', 0xCD=>'RCLR', 0xCE=>'RLUM', 0xCF=>'JOY', 0xD0=>'RDOT', 0xD1=>'DEC', 0xD2=>'HEX', 0xD3=>'ERR', 0xD4=>'INSTR', 0xD5=>'ELSE', 0xD6=>'RESUME', 0xD7=>'TRAP', 0xD8=>'TRON', 0xD9=>'TROFF', 0xDA=>'SOUND', 0xDB=>'VOL', 0xDC=>'AUTO', 0xDD=>'PUDEF', 0xDE=>'GRAPHIC', 0xDF=>'PAINT', 0xE0=>'CHAR', 0xE1=>'BOX', 0xE2=>'CIRCLE', 0xE3=>'GSHAPE', 0xE4=>'SSHAPE', 0xE5=>'DRAW', 0xE6=>'LOCATE', 0xE7=>'COLOR', 0xE8=>'SCNCLR', 0xE9=>'SCALE', 0xEA=>'HELP', 0xEB=>'DO', 0xEC=>'LOOP', 0xED=>'EXIT', 0xEE=>'DIRECTORY', 0xEF=>'DSAVE', 0xF0=>'DLOAD', 0xF1=>'HEADER', 0xF2=>'SCRATCH', 0xF3=>'COLLECT', 0xF4=>'COPY', 0xF5=>'RENAME', 0xF6=>'BACKUP', 0xF7=>'DELETE', 0xF8=>'RENUMBER', 0xF9=>'KEY', 0xFA=>'MONITOR', 0xFB=>'USING', 0xFC=>'UNTIL', 0xFD=>'WHILE', 0xFF=>"PI", }
- CBM_BASIC_EXTENDED_TOKENS =
{ 0x02=>'BANK', 0x03=>'FILTER', 0x04=>'PLAY', 0x05=>'TEMPO', 0x06=>'MOVSPR', 0x07=>'SPRITE', 0x08=>'SPRCOLOR', 0x09=>'RREG', 0x0A=>'ENVELOPE', 0x0B=>'SLEEP', 0x0C=>'CATALOG', 0x0D=>'DOPEN', 0x0E=>'APPEND', 0x0F=>'DCLOSE', 0x10=>'BSAVE', 0x11=>'BLOAD', 0x12=>'RECORD', 0x13=>'CONCAT', 0x14=>'DVERIFY', 0x15=>'DCLEAR', 0x16=>'SPRSAV', 0x17=>'COLLISION', 0x18=>'BEGIN', 0x19=>'BEND', 0x1A=>'WINDOW', 0x1B=>'BOOT', 0x1C=>'WIDTH', 0x1D=>'SPRDEF', 0x1E=>'QUIT', 0x1F=>'STASH', 0x21=>'FETCH', 0x23=>'SWAP', 0x24=>'OFF', 0x25=>'FAST', 0x26=>'SLOW', 0x27=>'TYPE', 0x28=>'BVERIFY', 0x29=>'ECTORY', 0x2A=>'ERASE', 0x2B=>'FIND', 0x2C=>'CHANGE', 0x2D=>'SET', 0x2E=>'SCREEN', 0x2F=>'POLYGON', 0x30=>'ELLIPSE', 0x31=>'VIEWPORT', 0x32=>'GCOPY', 0x33=>'PEN', 0x34=>'PALETTE', 0x35=>'DMODE', 0x36=>'DPAT', 0x37=>'PIC', 0x38=>'GENLOCK', 0x39=>'FOREGROUND', 0x3B=>'BACKGROUND', 0x3C=>'BORDER', 0x3D=>'HIGHLIGHT', }
- CBM_CHR_CODES =
the following codes have special functions in strings
{ 5=>"<WHITE>", 14=>"<LOWER CASE>", 17=>"<DOWN>", 18=>"<RVS ON>", 19=>"<CLR/HOME>", 20=>"<INST/DEL>", 28=>"<RED>", 29=>"<RIGHT>", 30=>"<GRN>", 31=>"<BLU>", 129=>"<ORANGE>", 133=>"<F1>", 134=>"<F3>", 135=>"<F5>", 136=>"<F7>", 137=>"<F2>", 138=>"<F4>", 139=>"<F6>", 140=>"<F8>", 141=>"<SHIFT RETURN>", 142=>"<UPPER CASE>", 144=>"<BLK>", 145=>"<UP>", 146=>"<RVS OFF>", 147=>"<CLR/HOME>", 148=>"<INST/DEL>", 149=>"<BROWN>", 150=>"<LT RD>", 151=>"<GREY 1>", 152=>"<GREY 2>", 153=>"<LT GREEN>", 154=>"<LT BLUE>", 155=>"<GREY 3>", 156=>"<PUR>", 157=>"<LEFT>", 158=>"<YEL>", 159=>"<CYN>" }
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
CBM Basic files have the following structure; first 2 bytes in file are mem address for file to be relocated to then come 1 or more lines.
Methods inherited from C64Prg
#header_length, #load_address, #to_disassembly
Methods inherited from CbmFile
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
11 12 13 14 15 16 |
# File 'lib/native_file_types/c64/C64BasicPrg.rb', line 11 def self.file_system_file_types { CbmDos=>:prg, C64PrgSnapshot=>:prg } end |
.list_buffer(buffer) ⇒ Object
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
# File 'lib/native_file_types/c64/C64BasicPrg.rb', line 266 def C64BasicPrg.list_buffer(buffer) s="" p=2 #skip over first 2 bytes, which are where a PRG file would get relocated to end_of_file=false # while p<buffer.length && !end_of_file do p+=2 #skip over the pointer to the next line in RAM line_number=buffer[p]+(buffer[p+1]<<8) s+=sprintf("%d ",line_number) p+=2 end_of_line=false in_quotes=false while p<buffer.length && !end_of_line do b=buffer[p] p+=1 if b==0 then end_of_line=true s+="\n" elsif in_quotes && !CBM_CHR_CODES[b].nil? then s+=CBM_CHR_CODES[b] elsif b==0x22 then in_quotes=!in_quotes s+=0x22.chr elsif b>=0x80 && !in_quotes then if b==0xfe then b=@contents[p] p+=1 token=CBM_BASIC_EXTENDED_TOKENS[b] else token=CBM_BASIC_TOKENS[b] end s+=(token.nil? ? "<UNKNOWN TOKEN $#{sprintf("%2X",b)}>": token) else s+=b.chr end end end_of_file=(buffer[p]==0 && buffer[p+1]==0) #is the address of the next line $0000? end rest_of_file=buffer[p+2,0xFFFF] s+=C64.disassemble(rest_of_file,0x801+p-2) unless rest_of_file.nil? s end |
Instance Method Details
#to_listing ⇒ Object
CBM Basic files have the following structure; first 2 bytes in file are mem address for file to be relocated to then come 1 or more lines. each line has following structure: <2 bytes start of next line in RAM> <2 bytes line number> <tokens> 0 byte
262 263 264 |
# File 'lib/native_file_types/c64/C64BasicPrg.rb', line 262 def to_listing C64BasicPrg.list_buffer(@contents) end |