Бинарный файл в формат .scl

 На ааафоруме возник вопрос о преобразовании файла в формат .scl. sjasmplus в помощь

device zxspectrum128
macro sectors datab,datae
 IF low (datae-datab)=0
   db high (datae-datab)
 ELSE
   db (1+high (datae-datab))
 ENDIF
endm
org $8000-14*1-9
scl_b:
;header_b:
 db "SINCLAIR"
 db 1; only one file
;-1st
;    12345678t
 db "girl    C"
 dw 16384;starting address
 dw end-begin;size of file
 sectors begin,end;sectors for file
; align 256
begin
 incbin "girl.scr"
end
 align 256
scl_e:
savebin "test.scl",scl_b,scl_e-scl_b
LUA
local fp
local checksum

fp = assert(io.open("test.scl", "rb"))
checksum=0
while true do
local byte = fp:read(1)
if byte==nil then
break
end
checksum=checksum+string.byte(byte)
end
assert(fp:close())
print("writing",string.format("%08X",checksum))
fp = assert(io.open("test.scl", "a"))
for i=1,4 do
    fp:write(string.char(checksum%256))
    checksum=math.floor(checksum/256)
    end
-- assert(fp:flush())
assert(fp:close())
ENDLUA


после подготовки файла .scl добавляется  контрольная сумма.


Комментарии