Class: NADOLTokenisedFile

Inherits:
NADOLFile show all
Defined in:
lib/NADOLFile.rb

Overview

file packed by the NADOL EDITOR application. format is a series of unnumbered lines, where each line has the following format:

<Length>     (8-bit: including length byte,  contents, zero>
<Tokens and/or Characters>
<Zero byte>  ($00, to mark the end of the line)

each byte in the line is interpreted as follows: $00 - end of line marker $01 - $64 - NADOL tokens $65 - $70 - ??? unknown $71 - $7f - 1 to F spaces $80 - $FF - ASCII character with high bit set

Constant Summary collapse

NADOL_EDITOR_TOKENS =
[
	"?",		#00 (so we can use token as an index in to this array)
	"READ(",	#01
	"FREE(",	#02
	"NOT(",	#03
	"LENGTH(",	#04
	"PDL(",	#05
	"SIZEOF(",	#06
	"LSCRN(",	#07
	"HSCRN(",	#08
	"CHECK(",	#09
	"MAKE(",	#0a
	"SCREEN(",	#0b
	"HEXPACK ",#0c
	"PROCEDURE ",#0d
	"ENDPROC",	#0e
	"FUNCTION ",#0f
	"ENDFUNC",	#10
	"IF ",	#11
	"ELSE",	#12
	"ENDIF",	#13
	"WHILE ",	#14
	"ENDWHILE",#15
	"DEFINE ",	#16
	"RESULT=",	#17
	"PRINT",	#18
	"PRINTHEX",#19
	"PRINTBYTE",#1a
	"LABEL ",	#1b
	"GOTO ",	#1c
	"INVERSE",	#1d
	"NORMAL",	#1e
	"FLASH",	#1f
	"CASE ",	#20
	"GOTOXY(",	#21
	"CLEAR",	#22
	"NEW",	#23
	"HOME",	#24
	"CLREOL",	#25
	"CLREOP",	#26
	"PRBLOCK(",#27
	"STOP",	#28
	"COPY(",	#29
	"FILL(",	#2a
	"MASK(",	#2b
	"RSECT(",	#2c
	"WSECT(",	#2d
	"RBLOCK(",	#2e
	"WBLOCK(",	#2f
	"WTRACK(",	#30
	"WSYNC(",	#31
	"RECAL(",	#32
	"DISPLAY(",#33
	"RTRACK(",	#34
	"RSYNC(",	#35
	"BEEP(",	#36
	"DISASM(",	#37
	"TEXT",	#38
	"FORMAT(",	#39
	"SETFORMAT(",#3a
	"WORKDRIVE ",#3b
	"INIT ",	#3c
	"LOAD ",	#3d
	"SAVE ",	#3e
	"CATALOG",	#3f
	"DELETE ",	#40
	"RENAME ",	#41
	"PACK ",	#42
	"CONVERT(",#43
	"INPUT(",	#44
	"LORES",	#45
	"PLOT(",	#46
	"HLINE(",	#47
	"VLINE(",	#48
	"COLOR=",	#49
	"FIND(",	#4a
	"HIRES",	#4b
	"HCOLOR=",	#4c
	"HPLOT",	#4d
	"CALL(",	#4e
	"PR#",	#4f
	"IN#",	#50
	"FILTER(",	#51
	"LIST",	#52
	"RUN",	#53
	"AUXMOVE(",#54
	"LCMOVE(",	#55
	"DELAY(",	#56
	"INTEGER",	#57
	"BYTE",	#58
	" AND ",	#59
	" OR ",	#5a
	" MOD ",	#5b
	" XOR ",	#5c
	" WITH ",	#5d
	" TO ",	#5e
	" AT ",	#5f
	"TAB(",	#60
	"ENDCASE",	#61
	"MON:",	#62
	"EDIT",	#63
	"SAVE@"	#64
]

Constants inherited from DSKFile

DSKFile::APPLESOFT_TOKENS

Instance Attribute Summary

Attributes inherited from DSKFile

#contents, #filename

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from NADOLFile

#catalog_filename, catalog_filename

Methods inherited from DSKFile

#==, #buffer_as_applesoft_file, #can_be_picture?, #hex_dump, #initialize, #length_in_sectors, #to_ascii

Constructor Details

This class inherits a constructor from DSKFile

Class Method Details

.can_be_nadol_tokenised_file?(buffer) ⇒ Boolean

check whether a given series of bytes can be a valid NADOL tokenised file heuristics are: that each line starts with a line length and ends with a “0”

Returns:

  • (Boolean)


170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/NADOLFile.rb', line 170

def  NADOLTokenisedFile.can_be_nadol_tokenised_file?(buffer)
	r=true
	i=0
	while i<buffer.length
		line_length=buffer[i]
		if buffer[i+line_length-1]!=0 then
			r=false
			break
		end
		i+=line_length
	end
	r
end

.tokenise(buffer) ⇒ Object



184
185
186
187
188
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
# File 'lib/NADOLFile.rb', line 184

def NADOLTokenisedFile.tokenise(buffer)
 
  s=""
  buffer.each("\n") do |line|
    #trim the trailing \n
    line.chomp!
    #first set the high bit in each char
    for i in 0..line.length-1
    line[i]=line[i]|0x80
    end

    #now replace token strings with token number
    for i in 1..0x64
      token=" "*NADOL_EDITOR_TOKENS[i].length
      for j in 0..token.length-1
        token[j]=NADOL_EDITOR_TOKENS[i][j]|0x80
      end
      line.gsub!(token,i.chr)
    end

    #replace 2 to 15 spaces with a run-length-encoding
    0x0f.downto(2) do |i|
    line.gsub!(" "*i,(0x70+i).chr)
    end

    #now add length to each line
    s+=((line.length+2).chr)+line+"\0"
  end
  
  if ! NADOLTokenisedFile.can_be_nadol_tokenised_file?(s)
    raise "tokenisation appears to have failed!"
end
s
end

Instance Method Details

#file_extensionObject



223
224
225
# File 'lib/NADOLFile.rb', line 223

def file_extension
	".nad"
end

#to_sObject



219
220
221
# File 'lib/NADOLFile.rb', line 219

def to_s
	NADOLTokenisedFile.buffer_as_tokenised_file(@contents)
end