?login_element?

Subversion Repositories NedoOS

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download

  1. --[[
  2.     Lua function providing "inc_text" feature
  3.     for SjASMPlus (https://github.com/z00m128/sjasmplus)
  4.     Author: Reobne (Кузьма Е.) at https://zx-pk.ru forum
  5.     (slightly modified by Ped7g)
  6.  
  7.     Opens text file, parses it per line, emits text as bytes by default,
  8.     but any line starting with *asm_marker* is assembled (you can define
  9.     label or code with such line, code must be lead with whitespace).
  10.  
  11.     Call it in every pass of assembling in the ASM file!
  12.  
  13.     Parameters:
  14.     1 file_name: name of file to open
  15.     2 asm_marker: beginning-of-line marker of ASM line (default ">>")
  16.     3 eol_byte: byte value to emit instead of newline (default 13)
  17. ]]
  18. function inc_text(file_name, asm_marker, eol_byte)
  19.     asm_marker = asm_marker or ">>"
  20.     eol_byte = eol_byte or 13
  21.     if not sj.file_exists(file_name) then
  22.         sj.error("[inc_text]: file not found", file_name, 3)
  23.         return
  24.     end
  25.     marker_len = string.len(asm_marker)
  26.     _pl(";; inc_text ;; file \"" .. file_name .. "\", asm_marker \"" .. asm_marker ..
  27.         "\", eol_byte " .. eol_byte)
  28.     for line in io.lines(file_name) do
  29.         if string.sub(line, 1, marker_len) == asm_marker then
  30.             _pl(string.sub(line, marker_len + 1))   -- parse as assembly source line
  31.         else
  32.             for i = 1, string.len(line) do
  33.                 sj.add_byte( string.byte(line, i) )
  34.             end
  35.             sj.add_byte(eol_byte)
  36.         end
  37.     end
  38.     _pl(";; inc_text ;; end of file \"" .. file_name .. "\"")
  39. end
  40.