Matlab function for generating CAS files

Hardware Hacking, Programming and Game Solutions/Cheats
Post Reply
geirhovland
Posts: 56
Joined: Sun Aug 21, 2011 7:38 am
Location: Norway

Matlab function for generating CAS files

Post by geirhovland »

Below a Matlab function which converts raw binary data to the CAS format.
Remember to remove the first 9 header bytes of the DragonDos BIN file before
sending the data into the bin2cas function.
-Geir Hovland


--------------------------------------------------------------------------------------------------------------
function bin2cas(filename,M,start,exec)

% This function converts raw binary data to a CAS file for use with Dragon 32/64 emulators.
% Useful when *.BIN files from DragonDos have been transmitted by the serial port (RS-232)
% from a Dragon 64 to a PC.
% Geir Hovland, 2011.
%
% filename - output CAS file
% M - raw binary data
% start - start address in Dragon memory
% exec - exec address in Dragon memory
%

strName=strrep(filename,'.',''); % Remove .
if(length(strName)>8)
strName=strName(1:8);
end;
while(length(strName)<8)
strName=[strName ' '];
end;

% Create Header block
fid=fopen(filename,'w');
LL=0;
out=[hex2dec('55') hex2dec('3C') 00 LL double(strName) 02 00 00 floor(exec/256) mod(exec,256) floor(start/256) mod(start,256)];
LL=length(out)-4; %Block length
out(4)=LL;
CC=mod(sum(out(3:end)),256); %Checksum
fwrite(fid,[out CC hex2dec('55')]);

% Data-blocks
x=0; % Memory location counter
N=length(M);
while(x<N)
if(x>N-255)
LL=N-x;
else
LL=255;
end;
fwrite(fid,[hex2dec('55') hex2dec('3C') 01 LL]);
fwrite(fid,M(x+1:x+LL)); %Actual data
CC=mod(sum(M(x+1:x+LL))+1+LL,256); %Checksum
fwrite(fid,[CC hex2dec('55')]);
x=x+LL;
end;

%End of file block
fwrite(fid,[hex2dec('55') hex2dec('3C') hex2dec('FF') 00 hex2dec('FF') hex2dec('55')]);
fclose(fid);
Post Reply