LCOV - code coverage report
Current view: top level - asar - libsmw.h (source / functions) Coverage Total Hit
Test: asar.info Lines: 84.8 % 66 56
Test Date: 2024-01-15 16:26:31 Functions: 100.0 % 2 2
Branches: 53.9 % 76 41

             Branch data     Line data    Source code
       1                 :             : #pragma once
       2                 :             : 
       3                 :             : #include "errors.h"
       4                 :             : #include "autoarray.h"
       5                 :             : #include <cstdint>
       6                 :             : 
       7                 :             : extern const unsigned char * romdata;
       8                 :             : extern int romlen;
       9                 :             : extern asar_error_id openromerror;
      10                 :             : bool openrom(const char * filename, bool confirm=true);
      11                 :             : uint32_t closerom(bool save = true);
      12                 :             : 
      13                 :             : enum mapper_t {
      14                 :             :         invalid_mapper,
      15                 :             :         lorom,
      16                 :             :         hirom,
      17                 :             :         sa1rom,
      18                 :             :         bigsa1rom,
      19                 :             :         sfxrom,
      20                 :             :         exlorom,
      21                 :             :         exhirom,
      22                 :             :         norom
      23                 :             : } extern mapper;
      24                 :             : 
      25                 :             : extern int sa1banks[8];//only 0, 1, 4, 5 are used
      26                 :             : 
      27                 :             : void writeromdata(int pcoffset, const void * indata, int numbytes);
      28                 :             : void writeromdata_byte(int pcoffset, unsigned char indata);
      29                 :             : void writeromdata_bytes(int pcoffset, unsigned char indata, int numbytes);
      30                 :             : 
      31                 :             : struct writtenblockdata {
      32                 :             :         int pcoffset;
      33                 :             :         int snesoffset;
      34                 :             :         int numbytes;
      35                 :             : };
      36                 :             : 
      37                 :             : extern autoarray<writtenblockdata> writtenblocks;
      38                 :             : 
      39                 :       42752 : inline int snestopc(int addr)
      40                 :             : {
      41         [ +  - ]:       42752 :         if (addr<0 || addr>0xFFFFFF) return -1;//not 24bit
      42         [ +  + ]:       42752 :         if (mapper==lorom)
      43                 :             :         {
      44                 :             :                 // randomdude999: The low pages ($0000-$7FFF) of banks 70-7D are used
      45                 :             :                 // for SRAM, the high pages are available for ROM data though
      46         [ +  - ]:       40808 :                 if ((addr&0xFE0000)==0x7E0000 ||//wram
      47         [ +  - ]:       40808 :                         (addr&0x408000)==0x000000 ||//hardware regs, ram mirrors, other strange junk
      48         [ +  - ]:       40808 :                         (addr&0x708000)==0x700000)//sram (low parts of banks 70-7D)
      49                 :             :                                 return -1;
      50                 :       40808 :                 addr=((addr&0x7F0000)>>1|(addr&0x7FFF));
      51                 :       40808 :                 return addr;
      52                 :             :         }
      53                 :             :         if (mapper==hirom)
      54                 :             :         {
      55         [ +  - ]:         582 :                 if ((addr&0xFE0000)==0x7E0000 ||//wram
      56         [ +  - ]:         582 :                         (addr&0x408000)==0x000000)//hardware regs, ram mirrors, other strange junk
      57                 :             :                                 return -1;
      58                 :         582 :                 return addr&0x3FFFFF;
      59                 :             :         }
      60                 :             :         if (mapper==exlorom)
      61                 :             :         {
      62         [ +  - ]:         577 :                 if ((addr&0xF00000)==0x700000 ||//wram, sram
      63         [ +  - ]:         577 :                         (addr&0x408000)==0x000000)//area that shouldn't be used in lorom
      64                 :             :                                 return -1;
      65         [ +  + ]:         577 :                 if (addr&0x800000)
      66                 :             :                 {
      67                 :          42 :                         addr=((addr&0x7F0000)>>1|(addr&0x7FFF));
      68                 :             :                 }
      69                 :             :                 else
      70                 :             :                 {
      71                 :         535 :                         addr=((addr&0x7F0000)>>1|(addr&0x7FFF))+0x400000;
      72                 :             :                 }
      73                 :         577 :                 return addr;
      74                 :             :         }
      75                 :             :         if (mapper==exhirom)
      76                 :             :         {
      77         [ +  - ]:         587 :                 if ((addr&0xFE0000)==0x7E0000 ||//wram
      78         [ +  - ]:         587 :                         (addr&0x408000)==0x000000)//hardware regs, ram mirrors, other strange junk
      79                 :             :                         return -1;
      80         [ +  + ]:         587 :                 if ((addr&0x800000)==0x000000) return (addr&0x3FFFFF)|0x400000;
      81                 :          50 :                 return addr&0x3FFFFF;
      82                 :             :         }
      83                 :             :         if (mapper==sfxrom)
      84                 :             :         {
      85                 :             :                 // Asar emulates GSU1, because apparently emulators don't support the extra ROM data from GSU2
      86         [ +  - ]:          29 :                 if ((addr&0x600000)==0x600000 ||//wram, sram, open bus
      87         [ +  - ]:          29 :                         (addr&0x408000)==0x000000 ||//hardware regs, ram mirrors, rom mirrors, other strange junk
      88         [ +  - ]:          29 :                         (addr&0x800000)==0x800000)//fastrom isn't valid either in superfx
      89                 :             :                                 return -1;
      90         [ -  + ]:          29 :                 if (addr&0x400000) return addr&0x3FFFFF;
      91                 :          29 :                 else return (addr&0x7F0000)>>1|(addr&0x7FFF);
      92                 :             :         }
      93                 :             :         if (mapper==sa1rom)
      94                 :             :         {
      95         [ +  - ]:          32 :                 if ((addr&0x408000)==0x008000)
      96                 :             :                 {
      97                 :          32 :                         return sa1banks[(addr&0xE00000)>>21]|((addr&0x1F0000)>>1)|(addr&0x007FFF);
      98                 :             :                 }
      99         [ #  # ]:           0 :         if ((addr&0xC00000)==0xC00000)
     100                 :             :         {
     101                 :           0 :             return sa1banks[((addr&0x100000)>>20)|((addr&0x200000)>>19)]|(addr&0x0FFFFF);
     102                 :             :         }
     103                 :             :                 return -1;
     104                 :             :         }
     105                 :             :         if (mapper==bigsa1rom)
     106                 :             :         {
     107         [ +  + ]:          53 :                 if ((addr&0xC00000)==0xC00000)//hirom
     108                 :             :                 {
     109                 :          24 :                         return (addr&0x3FFFFF)|0x400000;
     110                 :             :                 }
     111   [ +  +  +  - ]:          29 :                 if ((addr&0xC00000)==0x000000 || (addr&0xC00000)==0x800000)//lorom
     112                 :             :                 {
     113         [ +  - ]:          29 :                         if ((addr&0x008000)==0x000000) return -1;
     114                 :          29 :                         return (addr&0x800000)>>2 | (addr&0x3F0000)>>1 | (addr&0x7FFF);
     115                 :             :                 }
     116                 :             :                 return -1;
     117                 :             :         }
     118                 :             :         if (mapper==norom)
     119                 :             :         {
     120                 :          84 :                 return addr;
     121                 :             :         }
     122                 :             :         return -1;
     123                 :             : }
     124                 :             : 
     125                 :         369 : inline int pctosnes(int addr)
     126                 :             : {
     127         [ +  - ]:         369 :         if (addr<0) return -1;
     128         [ +  + ]:         369 :         if (mapper==lorom)
     129                 :             :         {
     130         [ +  - ]:         333 :                 if (addr>=0x400000) return -1;
     131                 :         333 :                 addr=((addr<<1)&0x7F0000)|(addr&0x7FFF)|0x8000;
     132                 :         333 :                 return addr|0x800000;
     133                 :             :         }
     134                 :             :         if (mapper==hirom)
     135                 :             :         {
     136         [ +  - ]:           8 :                 if (addr>=0x400000) return -1;
     137                 :           8 :                 return addr|0xC00000;
     138                 :             :         }
     139                 :             :         if (mapper == exlorom)
     140                 :             :         {
     141         [ +  - ]:          12 :                 if (addr>=0x800000) return -1;
     142         [ +  + ]:          12 :                 if (addr&0x400000)
     143                 :             :                 {
     144                 :           6 :                         addr-=0x400000;
     145                 :           6 :                         addr=((addr<<1)&0x7F0000)|(addr&0x7FFF)|0x8000;
     146                 :           6 :                         return addr;
     147                 :             :                 }
     148                 :             :                 else
     149                 :             :                 {
     150                 :           6 :                         addr=((addr<<1)&0x7F0000)|(addr&0x7FFF)|0x8000;
     151                 :           6 :                         return addr|0x800000;
     152                 :             :                 }
     153                 :             :         }
     154                 :             :         if (mapper == exhirom)
     155                 :             :         {
     156         [ +  - ]:          12 :                 if (addr>=0x800000) return -1;
     157         [ +  + ]:          12 :                 if (addr&0x400000) return addr;
     158                 :           6 :                 return addr|0xC00000;
     159                 :             :         }
     160                 :             :         if (mapper==sa1rom)
     161                 :             :         {
     162         [ +  - ]:           2 :                 for (int i=0;i<8;i++)
     163                 :             :                 {
     164         [ +  - ]:           2 :                         if (sa1banks[i]==(addr&0x700000)){ return 0x008000|(i<<21)|((addr&0x0F8000)<<1)|(addr&0x7FFF);}
     165                 :             :                 }
     166                 :             :                 return -1;
     167                 :             :         }
     168                 :             :         if (mapper==bigsa1rom)
     169                 :             :         {
     170         [ #  # ]:           0 :                 if (addr>=0x800000) return -1;
     171         [ #  # ]:           0 :                 if ((addr&0x400000)==0x400000)
     172                 :             :                 {
     173                 :           0 :                         return addr|0xC00000;
     174                 :             :                 }
     175         [ #  # ]:           0 :                 if ((addr&0x600000)==0x000000)
     176                 :             :                 {
     177                 :           0 :                         return ((addr<<1)&0x3F0000)|0x8000|(addr&0x7FFF);
     178                 :             :                 }
     179         [ #  # ]:           0 :                 if ((addr&0x600000)==0x200000)
     180                 :             :                 {
     181                 :           0 :                         return 0x800000|((addr<<1)&0x3F0000)|0x8000|(addr&0x7FFF);
     182                 :             :                 }
     183                 :             :                 return -1;
     184                 :             :         }
     185                 :             :         if (mapper==sfxrom)
     186                 :             :         {
     187         [ +  - ]:           2 :                 if (addr>=0x200000) return -1;
     188                 :           2 :                 return ((addr<<1)&0x7F0000)|(addr&0x7FFF)|0x8000;
     189                 :             :         }
     190                 :             :         if (mapper==norom)
     191                 :             :         {
     192                 :           0 :                 return addr;
     193                 :             :         }
     194                 :             :         return -1;
     195                 :             : }
     196                 :             : 
     197                 :             : int getpcfreespace(int size, bool isforcode, bool autoexpand=true, bool respectbankborders=true, bool align=false, unsigned char freespacebyte=0x00);
     198                 :             : int getsnesfreespace(int size, bool isforcode, bool autoexpand=true, bool respectbankborders=true, bool align=false, unsigned char freespacebyte=0x00);
     199                 :             : 
     200                 :             : void resizerats(int snesaddr, int newlen);
     201                 :             : void removerats(int snesaddr, unsigned char clean_byte);
     202                 :             : int ratsstart(int pcaddr);
     203                 :             : 
     204                 :             : bool goodchecksum();
     205                 :             : void fixchecksum();
     206                 :             : 
     207                 :             : void WalkRatsTags(void(*func)(int loc, int len));//This one calls func() for each RATS tag in the ROM. The pointer is SNES format.
     208                 :             : void WalkMetadata(int loc, void(*func)(int loc, char * name, int len, const unsigned char * contents));//This one calls func() for each metadata block in the RATS tag whose contents (metadata) start at loc in the ROM. Do not replace name with an invalid metadata name, and note that name is not null terminated.
        

Generated by: LCOV version 2.0-1