// (c) 2019 lvd
// This is system verilog classes used to parse .psg files.
/* This file is part of AY-3-8910 restoration and preservation project.
AY-3-8910 restoration and preservation project is free software: you
can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation,
either version 3 of the License, or (at your option) any later version.
AY-3-8910 restoration and preservation project is distributed in the
hope that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see .
*/
package Psg;
class psg_regs;
bit [15:0] update;
byte value [0:15];
function new();
int i;
for(i=0;i<16;i++)
begin
update[i] = 1'b0;
value [i] = 8'd0;
end
endfunction
endclass
class psg_dump;
psg_regs dump[$];
function new();
dump = {};
endfunction
extern task load_psg(string filename);
endclass
task psg_dump::load_psg(string filename);
int fd;
byte psg_array[];
int fsize,tmp,i;
byte tbyte;
psg_regs prev;
psg_regs curr;
psg_regs empty;
psg_regs clregs;
int ptr;
byte p;
bit [7:0] v;
int pause;
fd = $fopen(filename,"rb");
// get size of file
tmp=$fseek(fd,0,2);
fsize=$ftell(fd);
//$display("filesize=%d",fsize);
tmp=$rewind(fd);
//$display("filepos=%d",$ftell(fd));
// allocate an array for the given size
psg_array = new[fsize];
// read into array
for(i=0;i=fsize || (psg_array[ptr]&8'hF0) )
disable registers_loop;
p=psg_array[ptr++];
v=psg_array[ptr++];
curr.update[p] = 1'b1;
curr.value[p] = v;
end
end
// filter 'curr' over 'prev'
for(i=0;i<16;i++)
begin
if( curr.update[i] && i!=13 )
begin
if( curr.value[i]==prev.value[i] )
curr.update[i] = 1'b0;
else
begin
prev.value[i] = curr.value[i];
end
end
end
// add to dump: first pause, if it was >1, then registers
if( pause>1 )
begin
for(i=1;i